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