Liferay.Loader.define("commerce-frontend-taglib@19.1.14/user_roles_modal/UserRolesModal.es",["module","exports","require","frontend-js-metal-web$metal-component","frontend-js-metal-web$metal-soy","./UserRolesModal.soy","frontend-taglib-clay$clay-modal","./RoleInputItem.es","./RoleListItem.es","../css/main.scss"],(function(e,t,l){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=t.UserRolesModal=void 0;var o=_interopRequireDefault(l("frontend-js-metal-web$metal-component")),s=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 l={},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var s in e)if(Object.prototype.hasOwnProperty.call(e,s)){var r=o?Object.getOwnPropertyDescriptor(e,s):null;r&&(r.get||r.set)?Object.defineProperty(l,s,r):l[s]=e[s]}l.default=e,t&&t.set(e,l);return l}(l("frontend-js-metal-web$metal-soy")),r=_interopRequireDefault(l("./UserRolesModal.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}}l("frontend-taglib-clay$clay-modal"),l("./RoleInputItem.es"),l("./RoleListItem.es"),l("../css/main.scss");class UserRolesModal extends o.default{syncSelectedRoles(){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._filterRoles()}_handleFormSubmit(e){e.preventDefault();let t=!1;return this.filteredRoles.length&&(this._toggleItem(this.filteredRoles[0]),this.query="",t=!0),t}_handleInputBox(e){return 8!==e.keyCode||this.query.length?this.query=e.target.value:this.selectedRoles=this.selectedRoles.slice(0,-1),e}_toggleItem(e){e.id||(this.query="");const t=this.selectedRoles.reduce(((t,l)=>t||l.id===e.id),!1);return this.selectedRoles=t?this.selectedRoles.filter((t=>t.id!==e.id)):[...this.selectedRoles,e],this.selectedRoles}_filterRoles(){return this.filteredRoles=this.roles.filter((e=>e.name.toLowerCase().indexOf(this.query.toLowerCase())>-1)),this.filteredRoles}_updateRoles(){this.emit("updateRoles",this.selectedRoles)}toggle(){return this._modalVisible=!this._modalVisible,this._modalVisible}open(){return this._modalVisible=!0,this._modalVisible}close(){return this._modalVisible=!1,this._modalVisible}}t.UserRolesModal=UserRolesModal,s.default.register(UserRolesModal,r.default);const e=s.Config.shapeOf({id:s.Config.oneOfType([s.Config.number(),s.Config.string()]).required(),name:s.Config.string().required()});UserRolesModal.STATE={_modalVisible:s.Config.bool().internal().value(!1),filteredRoles:s.Config.array(e).value([]),query:s.Config.string().value(""),roles:s.Config.array(e).value([]),selectedRoles:s.Config.array(e).value([]),spritemap:s.Config.string()};var i=UserRolesModal;t.default=i}}));
//# sourceMappingURL=UserRolesModal.es.js.map