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