Liferay.Loader.define("commerce-frontend-taglib@19.1.14/add_account_modal/AddAccountModal.es",["module","exports","require","frontend-js-web","frontend-js-metal-web$metal-component","frontend-js-metal-web$metal-soy","./AddAccountModal.soy","frontend-taglib-clay$clay-modal","../user_utils/UserListItem.es","../user_utils/UserInputItem.es","../css/main.scss"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=t.AddAccountModal=void 0;var s=r("frontend-js-web"),i=_interopRequireDefault(r("frontend-js-metal-web$metal-component")),n=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={},s=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)){var n=s?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("frontend-js-metal-web$metal-soy")),a=_interopRequireDefault(r("./AddAccountModal.soy"));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}}r("frontend-taglib-clay$clay-modal"),r("../user_utils/UserListItem.es"),r("../user_utils/UserInputItem.es"),r("../css/main.scss");const e=/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;class AddAccountModal extends i.default{created(){this._debouncedFetchUser=(0,s.debounce)(this._fetchUsers.bind(this),300)}attached(){this._fetchUsers()}syncAddedUsers(){const e=this.element.querySelector(".autocomplete-input__content");this.element.querySelector(".autocomplete-input__box").focus(),e.scrollTo&&e.scrollTo(0,e.offsetHeight)}_handleCloseModal(e){return e.preventDefault(),this._modalVisible=!1,e}syncQuery(){return this._loading=!0,this._debouncedFetchUser()}_handleFormSubmit(t){t.preventDefault();let r=!1;return this.query.match(e)&&(this.addedUsers=[...this.addedUsers,{email:this.query}],this.query="",r=!0),r}_handleInputBox(e){return 8!==e.keyCode||this.query.length?this.query=e.target.value:this.addedUsers=this.addedUsers.slice(0,-1),e}_handleInputName(e){return this.accountName=e.target.value,e}_toggleInvitation(e){e.id||(this.query="");const t=this.addedUsers.reduce(((t,r)=>t||r.email===e.email),!1);return this.addedUsers=t?this.addedUsers.filter((t=>t.email!==e.email)):[...this.addedUsers,e],this.addedUsers}_fetchUsers(){return(0,s.fetch)(this.usersAPI+"?groupId="+themeDisplay.getScopeGroupId()+"&q="+this.query).then((e=>e.json())).then((e=>(this._loading=!1,this.users=e.users,this.users)))}_handleCreateAccount(){if(!this.addedUsers.length||!this.accountName)return!1;const e={accountName:this.accountName,administratorsEmail:this.addedUsers};return this.emit("AddAccountModalSave",e)}toggle(){return this._modalVisible=!this._modalVisible,this._modalVisible}open(){return this._modalVisible=!0,this._modalVisible}close(){return this._modalVisible=!1,this._modalVisible}}t.AddAccountModal=AddAccountModal,n.default.register(AddAccountModal,a.default);const o=n.Config.shapeOf({email:n.Config.string().required(),name:n.Config.string().required(),thumbnail:n.Config.string().required(),userId:n.Config.oneOfType([n.Config.string(),n.Config.number()]).required()});AddAccountModal.STATE={_loading:n.Config.bool().internal().value(!1),_modalVisible:n.Config.bool().internal().value(!1),accountName:n.Config.string().value(""),addedUsers:n.Config.array(o).value([]),query:n.Config.string().value(""),spritemap:n.Config.string(),users:n.Config.array(o).value([]),usersAPI:n.Config.string().value("")};var d=AddAccountModal;t.default=d}}));
//# sourceMappingURL=AddAccountModal.es.js.map