Liferay.Loader.define("commerce-frontend-js@4.0.75/components/account_selector/AccountSelector",["module","exports","require","@frontend-taglib-clay$clayui/drop-down","frontend-js-web","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=_interopRequireDefault(r("@frontend-taglib-clay$clayui/drop-down")),o=r("frontend-js-web"),c=(_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={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var c=n?Object.getOwnPropertyDescriptor(e,o):null;c&&(c.get||c.set)?Object.defineProperty(r,o,c):r[o]=e[o]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react"))),i=r("../../utilities/eventsDefinitions"),a=r("../../utilities/notifications"),u=_interopRequireDefault(r("./Trigger")),l=r("./util/constants"),s=r("./util/index"),d=_interopRequireDefault(r("./views/AccountsListView")),f=_interopRequireDefault(r("./views/OrdersListView"));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 n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}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="/o/headless-admin-user/v1.0/accounts",y=new URL("".concat(themeDisplay.getPathContext()).concat(e),themeDisplay.getPortalURL());function AccountSelector({accountEntryAllowedTypes:e,alignmentPosition:t,commerceChannelId:r,createNewOrderURL:p,currentCommerceAccount:O,currentCommerceOrder:w,refreshPageOnAccountSelected:b,selectOrderURL:_,setCurrentAccountURL:g,showOrderTypeModal:S}){const[m,R]=(0,c.useState)(!1),[j,h]=(0,c.useState)(O),[E,P]=(0,c.useState)(_objectSpread(_objectSpread({},w),{},{id:(null==w?void 0:w.orderId)||0})),[D,v]=(0,c.useState)(O?l.VIEWS.ORDERS_LIST:l.VIEWS.ACCOUNTS_LIST),[A,C]=(0,c.useState)({});(0,c.useEffect)((()=>{(0,o.fetch)(y.toString()).then((e=>e.json())).then((e=>C(e))).catch((e=>(0,a.showErrorNotification)(e.message)))}),[]);const L=(0,c.useCallback)((({order:e})=>{E&&E.id===e.id||P((t=>_objectSpread(_objectSpread({},t),e)))}),[E,P]);return(0,c.useEffect)((()=>(Liferay.on(i.CURRENT_ORDER_UPDATED,L),()=>{Liferay.detach(i.CURRENT_ORDER_UPDATED,L)})),[L]),c.default.createElement(n.default,{active:m,alignmentPosition:t,className:"account-selector account-selector-dropdown",menuElementAttrs:{className:"account-selector-dropdown-menu"},onActiveChange:R,trigger:c.default.createElement(u.default,{active:m,currentAccount:j,currentOrder:E})},D===l.VIEWS.ACCOUNTS_LIST&&c.default.createElement(d.default,{accountEntryAllowedTypes:e?JSON.parse(e):"",changeAccount:e=>{(0,s.selectAccount)(e.id,g).then((()=>{b?window.location.reload():(Liferay.fire(i.CURRENT_ACCOUNT_UPDATED,{id:e.id}),h(e),v(l.VIEWS.ORDERS_LIST),P(null))})).catch(a.showErrorNotification)},currentAccount:j,currentUser:A,disabled:!m,setCurrentView:v}),D===l.VIEWS.ORDERS_LIST&&c.default.createElement(f.default,{commerceChannelId:r,createOrderURL:p,currentAccount:j,disabled:!m,selectOrderURL:_,setCurrentView:v,showOrderTypeModal:S}))}AccountSelector.defaultProps={alignmentPosition:3,currentCommerceOrder:{orderId:0},refreshPageOnAccountSelected:!1};var p=AccountSelector;t.default=p}}));
//# sourceMappingURL=AccountSelector.js.map