Liferay.Loader.define("commerce-frontend-js@4.0.52/components/add_to_cart/AddToCartButton",["module","exports","require","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/icon","@liferay/frontend-js-react-web","liferay!frontend-js-react-web$classnames","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","../../utilities/atoms/cartAtom","../../utilities/notifications","./data","./add_to_cart.scss"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=f(a("@frontend-taglib-clay$clayui/button")),r=f(a("@frontend-taglib-clay$clayui/icon")),o=a("@liferay/frontend-js-react-web"),i=f(a("liferay!frontend-js-react-web$classnames")),c=(f(a("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 a={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){var o=n?Object.getOwnPropertyDescriptor(e,r):null;o&&(o.get||o.set)?Object.defineProperty(a,r,o):a[r]=e[r]}a.default=e,t&&t.set(e,a);return a}(a("liferay!frontend-js-react-web$react"))),l=f(a("../../utilities/atoms/cartAtom")),d=a("../../utilities/notifications"),s=a("./data");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 y({accountId:e,cartId:t,channel:a,className:u,cpInstances:f,disabled:y,hideIcon:p,notAllowed:b,onAdd:g,onClick:m,onError:w,settings:j}){const[h,O]=(0,o.useLiferayState)(l.default),[_,$]=(0,c.useState)(!1),v=(0,o.useIsMounted)();return c.default.createElement(n.default,{block:"full-width"===j.alignment,className:(0,i.default)(u,{["btn-".concat(j.size)]:j.size,"btn-add-to-cart":!0,"icon-only":j.iconOnly,"is-added":1===f.length&&f[0].inCart,"not-allowed":b||h.updating&&!_}),disabled:y,displayType:"primary",monospaced:j.iconOnly&&j.inline,onClick:n=>{if(!h.updating)return m?m(n,f,t,a,e):($(!0),O({updating:!0}),(0,s.addToCart)(f,t,a,e).then(g).catch((e=>{let t;console.error(e),t=e.message?e.message:f.length>1?Liferay.Language.get("unable-to-add-products-to-the-cart"):Liferay.Language.get("unable-to-add-product-to-the-cart"),(0,d.showErrorNotification)(t),w(e)})).finally((()=>{v()&&(O({updating:!1}),$(!1))})))}},!j.iconOnly&&c.default.createElement("span",{className:"text-truncate-inline"},c.default.createElement("span",{className:"text-truncate"},j.buttonText||Liferay.Language.get("add-to-cart"))),!p&&c.default.createElement("span",{className:"cart-icon"},c.default.createElement(r.default,{symbol:"shopping-cart"})))}a("./add_to_cart.scss"),y.defaultProps={accountId:null,cartId:0,cpInstances:[{inCart:!1,skuOptions:"[]"}],hideIcon:!1,onAdd:()=>{},onError:()=>{},settings:{iconOnly:!1,inline:!1}};var p=y;t.default=p}}));
//# sourceMappingURL=AddToCartButton.js.map