Liferay.Loader.define("commerce-frontend-taglib@19.1.14/user_invitation_modal/UserInvitationModal.es",["module","exports","require","frontend-js-web","frontend-js-metal-web$metal-component","frontend-js-metal-web$metal-soy","./UserInvitationModal.soy","frontend-taglib-clay$clay-modal","../user_utils/UserListItem.es","../user_utils/UserInputItem.es","../css/main.scss"],(function(e,t,s){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=t.UserInvitationModal=void 0;var r=s("frontend-js-web"),i=_interopRequireDefault(s("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 s={},r=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)){var n=r?Object.getOwnPropertyDescriptor(e,i):null;n&&(n.get||n.set)?Object.defineProperty(s,i,n):s[i]=e[i]}s.default=e,t&&t.set(e,s);return s}(s("frontend-js-metal-web$metal-soy")),a=_interopRequireDefault(s("./UserInvitationModal.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}}s("frontend-taglib-clay$clay-modal"),s("../user_utils/UserListItem.es"),s("../user_utils/UserInputItem.es"),s("../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 UserInvitationModal extends i.default{created(){this._debouncedFetchUser=(0,r.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){e.preventDefault(),this._modalVisible=!1}syncQuery(){return this._loading=!0,this._debouncedFetchUser()}_handleFormSubmit(t){return t.preventDefault(),this.query.match(e)&&(this.addedUsers=[...this.addedUsers,{email:this.query}],this.query=""),this.query}_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,s)=>t||s.email===e.email),!1);return this.addedUsers=t?this.addedUsers.filter((t=>t.email!==e.email)):[...this.addedUsers,e],this.addedUsers}_fetchUsers(){return(0,r.fetch)(this.usersAPI+"?groupId="+themeDisplay.getScopeGroupId()+"&q="+this.query).then((e=>e.json())).then((e=>(this._loading=!1,this.users=e.users,this.users)))}_sendInvitations(){return this.addedUsers.length&&this.emit("inviteUserToAccount",this.addedUsers),this.addedUsers}toggle(){return this._modalVisible=!this._modalVisible,this._modalVisible}open(){return this._modalVisible=!0,this._modalVisible}close(){return this._modalVisible=!1,this._modalVisible}}t.UserInvitationModal=UserInvitationModal,n.default.register(UserInvitationModal,a.default);const d=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()});UserInvitationModal.STATE={_loading:n.Config.bool().internal().value(!1),_modalVisible:n.Config.bool().internal().value(!1),addedUsers:n.Config.array(d).value([]),query:n.Config.string().value(""),spritemap:n.Config.string(),users:n.Config.array(d).value([]),usersAPI:n.Config.string().value("")};var o=UserInvitationModal;t.default=o}}));
//# sourceMappingURL=UserInvitationModal.es.js.map