Liferay.Loader.define("commerce-frontend-js@4.0.75/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=(_interopRequireDefault(r("liferay!frontend-js-react-web$prop-types")),function _interopRequireWildcard(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache();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=_interopRequireDefault(r("./AddOrCreate"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}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}function ItemFinder(e){const[t,r]=(0,i.useState)([]),[u,l]=(0,i.useState)(e.pageSize),[d,f]=(0,i.useState)(e.currentPage),[p,m]=(0,i.useState)(""),[b,y]=(0,i.useState)(e.itemsCount||0),[g,h]=(0,i.useState)([]);return(0,i.useEffect)((()=>{if(!p)return r(null),void y(0);(0,n.fetch)("".concat(e.apiUrl).concat(e.apiUrl.includes("?")?"&":"?","pageSize=").concat(u,"&page=").concat(d,"&search=").concat(encodeURIComponent(p)),_objectSpread(_objectSpread({},o.fetchParams),{},{method:"GET"})).then((e=>e.json())).then((e=>{r(e.items),y(e.totalCount)})).catch(c.showErrorNotification)}),[u,d,p,r,y,e.apiUrl]),(0,i.useEffect)((()=>{function handleDatasetActions(t){e.linkedDatasetsId.includes(t.id)&&e.getSelectedItems().then(((e=[])=>h(e)))}return e.getSelectedItems().then(((e=[])=>h(e))),Liferay.on(a.DATASET_ACTION_PERFORMED,handleDatasetActions),()=>Liferay.detach(a.DATASET_ACTION_PERFORMED,handleDatasetActions)}),[e,e.getSelectedItems]),i.default.createElement(s.default,{createNewItemLabel:e.createNewItemLabel,currentPage:d,inputPlaceholder:e.inputPlaceholder,inputSearchValue:p,itemCreation:e.itemCreation,items:t,itemsCount:b,itemsKey:e.itemsKey,onInputSearchChange:m,onItemCreated:function createItem(){e.onItemCreated(p).then((t=>{(0,c.showNotification)(e.itemCreatedMessage),m(""),t&&h((e=>[...e,t]))})).catch(c.showErrorNotification)},onItemSelected:function selectItem(r){const n=t.find((t=>t[e.itemsKey]===r));e.onItemSelected(n).then((()=>{e.multiSelectableEntries?(0,c.showNotification)(e.itemSelectedMessage):h((e=>[...e,r]))})).catch(c.showErrorNotification)},pageSize:u,panelHeaderLabel:e.panelHeaderLabel,schema:e.schema,searchInputValue:p,selectedItems:g,titleLabel:e.titleLabel,updateCurrentPage:f,updatePageSize:l})}ItemFinder.defaultProps={currentPage:1,itemCreatedMessage:Liferay.Language.get("item-created"),itemCreation:!0,itemSelectedMessage:Liferay.Language.get("item-selected"),multiSelectableEntries:!1,pageSize:5,selectedItems:[]};var u=ItemFinder;t.default=u}}));
//# sourceMappingURL=ItemFinder.js.map