Liferay.Loader.define("commerce-frontend-js@4.0.52/components/item_finder/ItemFinder",["module","exports","require","frontend-js-web","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","../../utilities/eventsDefinitions","../../utilities/index","../../utilities/notifications","./AddOrCreate"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=r("frontend-js-web"),i=(l(r("liferay!frontend-js-react-web$prop-types")),function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=u();if(t&&t.has(e))return t.get(e);var r={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)){var a=n?Object.getOwnPropertyDescriptor(e,i):null;a&&(a.get||a.set)?Object.defineProperty(r,i,a):r[i]=e[i]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react"))),a=r("../../utilities/eventsDefinitions"),o=r("../../utilities/index"),c=r("../../utilities/notifications"),s=l(r("./AddOrCreate"));function u(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return u=function(){return e},e}function l(e){return e&&e.__esModule?e:{default:e}}function f(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 d(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?f(Object(r),!0).forEach((function(t){p(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):f(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function p(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function m(e){const[t,r]=(0,i.useState)([]),[u,l]=(0,i.useState)(e.pageSize),[f,p]=(0,i.useState)(e.currentPage),[m,b]=(0,i.useState)(""),[g,y]=(0,i.useState)(e.itemsCount||0),[h,O]=(0,i.useState)([]);return(0,i.useEffect)((()=>{if(!m)return r(null),void y(0);(0,n.fetch)("".concat(e.apiUrl).concat(e.apiUrl.includes("?")?"&":"?","pageSize=").concat(u,"&page=").concat(f,"&search=").concat(encodeURIComponent(m)),d(d({},o.fetchParams),{},{method:"GET"})).then((e=>e.json())).then((e=>{r(e.items),y(e.totalCount)})).catch(c.showErrorNotification)}),[u,f,m,r,y,e.apiUrl]),(0,i.useEffect)((()=>{function t(t){e.linkedDatasetsId.includes(t.id)&&e.getSelectedItems().then(((e=[])=>O(e)))}return e.getSelectedItems().then(((e=[])=>O(e))),Liferay.on(a.DATASET_ACTION_PERFORMED,t),()=>Liferay.detach(a.DATASET_ACTION_PERFORMED,t)}),[e,e.getSelectedItems]),i.default.createElement(s.default,{createNewItemLabel:e.createNewItemLabel,currentPage:f,inputPlaceholder:e.inputPlaceholder,inputSearchValue:m,itemCreation:e.itemCreation,items:t,itemsCount:g,itemsKey:e.itemsKey,onInputSearchChange:b,onItemCreated:function(){e.onItemCreated(m).then((t=>{(0,c.showNotification)(e.itemCreatedMessage),b(""),t&&O((e=>[...e,t]))})).catch(c.showErrorNotification)},onItemSelected:function(r){const n=t.find((t=>t[e.itemsKey]===r));e.onItemSelected(n).then((()=>{e.multiSelectableEntries?(0,c.showNotification)(e.itemSelectedMessage):O((e=>[...e,r]))})).catch(c.showErrorNotification)},pageSize:u,panelHeaderLabel:e.panelHeaderLabel,schema:e.schema,searchInputValue:m,selectedItems:h,titleLabel:e.titleLabel,updateCurrentPage:p,updatePageSize:l})}m.defaultProps={currentPage:1,itemCreatedMessage:Liferay.Language.get("item-created"),itemCreation:!0,itemSelectedMessage:Liferay.Language.get("item-selected"),multiSelectableEntries:!1,pageSize:5,selectedItems:[]};var b=m;t.default=b}}));
//# sourceMappingURL=ItemFinder.js.map