Liferay.Loader.define("commerce-frontend-js@4.0.52/components/mini_cart/MiniCart",["module","exports","require","liferay!frontend-js-react-web$classnames","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","../../ServiceProvider/index","../../utilities/eventsDefinitions","../../utilities/notifications","./MiniCartContext","./util/constants","./util/index","./util/labels","./util/views"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var a=y(r("liferay!frontend-js-react-web$classnames")),n=(y(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=p();if(t&&t.has(e))return t.get(e);var r={},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var i=a?Object.getOwnPropertyDescriptor(e,n):null;i&&(i.get||i.set)?Object.defineProperty(r,n,i):r[n]=e[n]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react"))),i=y(r("../../ServiceProvider/index")),o=r("../../utilities/eventsDefinitions"),s=r("../../utilities/notifications"),l=y(r("./MiniCartContext")),u=r("./util/constants"),c=r("./util/index"),f=r("./util/labels"),d=r("./util/views");function p(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return p=function(){return e},e}function y(e){return e&&e.__esModule?e:{default:e}}function m(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function b(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?m(Object(r),!0).forEach((function(t){D(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):m(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function D(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=i.default.DeliveryCartAPI("v1");function O({cartActionURLs:t,cartViews:r,displayDiscountLevels:i,displayTotalItemsQuantity:p,itemsQuantity:y,labels:m,onAddToCart:D,orderId:O,productURLSeparator:v,summaryDataMapper:w,toggleable:C}){const[E,U]=(0,n.useState)(!C),[j,L]=(0,n.useState)(!1),[P,g]=(0,n.useState)(t),[R,T]=(0,n.useState)({}),[_,A]=(0,n.useState)({id:O,summary:{itemsQuantity:y}}),S=(0,n.useCallback)((({accountId:e=0})=>A({accountId:e,id:0,summary:{itemsQuantity:0}})),[A]),I=(0,n.useCallback)((async({order:t})=>{try{const r=t.orderUUID?t:await e.getCartByIdWithItems(t.id);let a,n;g((e=>{const t=e.orderDetailURL;return a=b(b({},e),{},{orderDetailURL:t?new URL(t):(0,c.regenerateOrderDetailURL)(r.orderUUID,e.siteDefaultURL)}),a})),A((e=>(n=b(b({},e),r),n))),D(a,n)}catch(e){(0,s.showErrorNotification)(e)}}),[D]);return(0,n.useEffect)((()=>{(0,d.resolveCartViews)(r).then((e=>T(e)))}),[r]),(0,n.useEffect)((()=>(Liferay.on(o.CURRENT_ORDER_UPDATED,I),()=>{Liferay.detach(o.CURRENT_ORDER_UPDATED,I)})),[I]),(0,n.useEffect)((()=>{O&&I({order:{id:O}})}),[O,I]),(0,n.useEffect)((()=>(Liferay.on(o.CURRENT_ACCOUNT_UPDATED,S),()=>{Liferay.detach(o.CURRENT_ACCOUNT_UPDATED,S)})),[S]),n.default.createElement(l.default.Provider,{value:{CartViews:R,actionURLs:P,cartState:_,closeCart:()=>U(!1),displayDiscountLevels:i,displayTotalItemsQuantity:p,isOpen:E,isUpdating:j,labels:b(b({},f.DEFAULT_LABELS),m),openCart:()=>U(!0),productURLSeparator:v,setCartState:A,setIsUpdating:L,summaryDataMapper:w,toggleable:C,updateCartModel:I}},!!R[u.CART]&&n.default.createElement("div",{className:(0,a.default)({"is-open":E||!C,"mini-cart":!0})},C&&n.default.createElement(n.default.Fragment,null,n.default.createElement("div",{className:"mini-cart-overlay",onClick:()=>U(!1)}),n.default.createElement(R.Opener,null)),n.default.createElement(R.Cart,null)))}O.defaultProps={cartViews:{},displayDiscountLevels:!1,displayTotalItemsQuantity:!1,itemsQuantity:0,labels:f.DEFAULT_LABELS,onAddToCart:()=>{},orderId:0,summaryDataMapper:c.summaryDataMapper,toggleable:!0};var v=O;t.default=v}}));
//# sourceMappingURL=MiniCart.js.map