Liferay.Loader.define("commerce-frontend-js@4.0.52/components/account_selector/AccountSelector",["module","exports","require","@frontend-taglib-clay$clayui/drop-down","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","../../utilities/eventsDefinitions","../../utilities/notifications","./Trigger","./util/constants","./util/index","./views/AccountsListView","./views/OrdersListView"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=p(r("@frontend-taglib-clay$clayui/drop-down")),c=(p(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=f();if(t&&t.has(e))return t.get(e);var r={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var c in e)if(Object.prototype.hasOwnProperty.call(e,c)){var o=n?Object.getOwnPropertyDescriptor(e,c):null;o&&(o.get||o.set)?Object.defineProperty(r,c,o):r[c]=e[c]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react"))),o=r("../../utilities/eventsDefinitions"),i=r("../../utilities/notifications"),a=p(r("./Trigger")),u=r("./util/constants"),l=r("./util/index"),s=p(r("./views/AccountsListView")),d=p(r("./views/OrdersListView"));function f(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return f=function(){return e},e}function p(e){return e&&e.__esModule?e:{default:e}}function O(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function y(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?O(Object(r),!0).forEach((function(t){w(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):O(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function w(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function b({accountEntryAllowedTypes:e,alignmentPosition:t,commerceChannelId:r,createNewOrderURL:f,currentCommerceAccount:p,currentCommerceOrder:O,refreshPageOnAccountSelected:w,selectOrderURL:b,setCurrentAccountURL:m,showOrderTypeModal:g}){const[E,S]=(0,c.useState)(!1),[j,v]=(0,c.useState)(p),[P,A]=(0,c.useState)(y(y({},O),{},{id:(null==O?void 0:O.orderId)||0})),[R,T]=(0,c.useState)(p?u.VIEWS.ORDERS_LIST:u.VIEWS.ACCOUNTS_LIST),C=(0,c.useCallback)((({order:e})=>{P&&P.id===e.id||A((t=>y(y({},t),e)))}),[P,A]);return(0,c.useEffect)((()=>(Liferay.on(o.CURRENT_ORDER_UPDATED,C),()=>{Liferay.detach(o.CURRENT_ORDER_UPDATED,C)})),[C]),c.default.createElement(n.default,{active:E,alignmentPosition:t,className:"account-selector account-selector-dropdown",menuElementAttrs:{className:"account-selector-dropdown-menu"},onActiveChange:S,trigger:c.default.createElement(a.default,{active:E,currentAccount:j,currentOrder:P})},R===u.VIEWS.ACCOUNTS_LIST&&c.default.createElement(s.default,{accountEntryAllowedTypes:e?JSON.parse(e):"",changeAccount:e=>{(0,l.selectAccount)(e.id,m).then((()=>{w?window.location.reload():(Liferay.fire(o.CURRENT_ACCOUNT_UPDATED,{id:e.id}),v(e),T(u.VIEWS.ORDERS_LIST),A(null))})).catch(i.showErrorNotification)},currentAccount:j,disabled:!E,setCurrentView:T}),R===u.VIEWS.ORDERS_LIST&&c.default.createElement(d.default,{commerceChannelId:r,createOrderURL:f,currentAccount:j,disabled:!E,selectOrderURL:b,setCurrentView:T,showOrderTypeModal:g}))}b.defaultProps={alignmentPosition:3,currentCommerceOrder:{orderId:0},refreshPageOnAccountSelected:!1};var m=b;t.default=m}}));
//# sourceMappingURL=AccountSelector.js.map