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