Liferay.Loader.define("portal-search-web@6.0.114/js/shared/input_sets/useInputSets",["module","exports","require","liferay!frontend-js-react-web$react"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.useInputSets=function useInputSets(t){const r=(0,n.useMemo)((()=>prepareInitialValue(t)),[t]),o=(0,n.useRef)(r.length),[a,p]=(0,n.useState)(r),_getInputSetItemId=t=>t[e],_handleInputSetItemDelete=e=>()=>{p(a.filter(((t,r)=>r!==e)))},_handleInputSetItemMove=(e,t)=>{p(function move(e,t,r){const n=[...e.slice(0,r),e[t],...e.slice(r,e.length)],o=t>r?t+1:t;return n.filter(((e,t)=>t!==o))}(a,e,t))};return{getInputSetItemId:_getInputSetItemId,getInputSetItemProps:(e,t)=>({index:t,isLastItem:a.length-1===t,key:_getInputSetItemId(e),onInputSetItemDelete:_handleInputSetItemDelete,onInputSetItemMove:_handleInputSetItemMove}),onInputSetItemChange:(e,t)=>{if("string"==typeof t)return r=>{p(a.map(((n,o)=>o===e?_objectSpread(_objectSpread({},n),{},{[t]:r.target.value}):n)))};p(a.map(((r,n)=>n===e?_objectSpread(_objectSpread({},r),t):r)))},onInputSetItemDelete:_handleInputSetItemDelete,onInputSetItemMove:_handleInputSetItemMove,onInputSetItemReplace:(t,r)=>()=>{p(a.map(((n,o)=>o===t?_objectSpread({[e]:n[e]},r):n)))},onInputSetsAdd:(t={})=>{p([...a,_objectSpread(_objectSpread({},t),{},{[e]:o.current++})])},onInputSetsChange:e=>{const t=prepareInitialValue(e);p(t),o.current=t.length},value:a}},t.ITEM_ID_PROPERTY=void 0;var n=r("liferay!frontend-js-react-web$react");function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const e="_inputSetItemId";function prepareInitialValue(t){let r=t;if("string"==typeof t||t instanceof String)try{r=JSON.parse(t)}catch(e){return[]}return Array.isArray(r)?r.map(((t,r)=>_objectSpread({[e]:r},t))):[]}t.ITEM_ID_PROPERTY=e}}));
//# sourceMappingURL=useInputSets.js.map