Liferay.Loader.define("commerce-frontend-js@4.0.52/components/mini_compare/MiniCompare",["module","exports","require","@frontend-taglib-clay$clayui/icon","@frontend-taglib-clay$clayui/sticker","liferay!frontend-js-react-web$classnames","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","../../utilities/cookies","../../utilities/eventsDefinitions"],(function(e,t,n){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i=f(n("@frontend-taglib-clay$clayui/icon")),r=f(n("@frontend-taglib-clay$clayui/sticker")),a=f(n("liferay!frontend-js-react-web$classnames")),l=(f(n("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 n={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){var a=i?Object.getOwnPropertyDescriptor(e,r):null;a&&(a.get||a.set)?Object.defineProperty(n,r,a):n[r]=e[r]}n.default=e,t&&t.set(e,n);return n}(n("liferay!frontend-js-react-web$react"))),c=f(n("../../utilities/cookies")),o=n("../../utilities/eventsDefinitions");function u(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return u=function(){return e},e}function f(e){return e&&e.__esModule?e:{default:e}}function s(){return(s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}const e=new c.default("COMMERCE_COMPARE_cpDefinitionIds_");function m(t,n,i){const r=e.getValue(t),a=r?r.split(":"):[];if(i)a.includes(n)||a.push(n);else{const e=a.indexOf(n);-1!==e&&a.splice(e,1)}e.setValue(t,a.join(":"))}function d(e){return l.default.createElement("div",{className:(0,a.default)("mini-compare-item",e.id&&"active")},l.default.createElement(r.default,{className:"mini-compare-thumbnail-container",size:"lg"},l.default.createElement("div",{className:"mini-compare-thumbnail",style:e.thumbnail?{backgroundImage:"url('".concat(e.thumbnail,"')")}:{}})),l.default.createElement("button",{className:"mini-compare-delete",onClick:e.onDelete},l.default.createElement(i.default,{symbol:"times"})))}function p(t){const[n,i]=(0,l.useState)(t.items);return e.setValue(t.commerceChannelGroupId,n.map((e=>e.id)).join(":")),(0,l.useEffect)((()=>{function e({id:e,thumbnail:n}){const r={id:e,thumbnail:n};i((n=>{const i=n.find((t=>t.id===e));return m(t.commerceChannelGroupId,e,!i),i?n.filter((t=>t.id!==e)):n.concat(r)}))}return Liferay.on(o.TOGGLE_ITEM_IN_PRODUCT_COMPARISON,e),()=>{Liferay.detach(o.TOGGLE_ITEM_IN_PRODUCT_COMPARISON,e)}}),[t.commerceChannelGroupId,t.itemsLimit,t.portletNamespace]),(0,l.useEffect)((()=>{Liferay.fire(o.PRODUCT_COMPARISON_TOGGLED,{disabled:n.length>=t.itemsLimit})}),[n,t.itemsLimit]),l.default.createElement("div",{className:(0,a.default)("mini-compare",!!n.length&&"active")},Array(t.itemsLimit).fill(null).map(((e,r)=>{const a=n[r]||{};return l.default.createElement(d,s({},a,{key:r,onDelete:e=>{e.preventDefault(),i(n.filter((e=>e.id!==a.id))),m(t.commerceChannelGroupId,a.id,!1),Liferay.fire(o.ITEM_REMOVED_FROM_COMPARE,a)}}))})),l.default.createElement("a",{className:"btn btn-primary",href:t.compareProductsURL},Liferay.Language.get("compare")))}p.defaultProps={items:[],itemsLimit:5};var y=p;t.default=y}}));
//# sourceMappingURL=MiniCompare.js.map