Liferay.Loader.define("commerce-frontend-taglib@19.1.14/user_utils/UserInvitation.es",["module","exports","require","frontend-js-web","frontend-js-metal-web$metal-component","frontend-js-metal-web$metal-soy","./UserInvitation.soy","frontend-taglib-clay$clay-modal","./UserListItem.es","./UserInputItem.es"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=t.UserInvitation=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("./UserInvitation.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("./UserListItem.es"),r("./UserInputItem.es");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 UserInvitation extends i.default{attached(){this._debouncedFetchUsers=(0,s.debounce)(this._fetchUsers.bind(this),300)}created(){this._fetchUsers()}shouldUpdate(e){return!e.events}testAddedUsers(e){const t=this.element.querySelector(".autocomplete-input__content");return this.element.querySelector(".autocomplete-input__box").focus(),t.scrollTo&&t.scrollTo(0,t.offsetHeight),this.emit("updateUsers",this.addedUsers)}testQuery(){return this._loading=!0,this._debouncedFetchUsers()}_handleFormSubmit(t){return t.preventDefault(),!!this.query.match(e)&&(this.addedUsers=[...this.addedUsers,{email:this.query}],this.query="",this.testAddedUsers(),this.testQuery(),!0)}_handleInputBox(e){return e.preventDefault(),8!==e.keyCode||this.query.length?(this.query=e.target.value,this.testQuery(),!0):(this.addedUsers=this.addedUsers.slice(0,-1),this.testAddedUsers(),!1)}_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.testAddedUsers(),this.addedUsers}_fetchUsers(){return(0,s.fetch)(this.usersAPI+"&q="+this.query).then((e=>e.json())).then((e=>(this._loading=!1,this.users=e.users,this.users)))}}t.UserInvitation=UserInvitation,n.default.register(UserInvitation,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.number(),n.Config.string()]).required()});UserInvitation.STATE={_loading: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=UserInvitation;t.default=o}}));
//# sourceMappingURL=UserInvitation.es.js.map