import{a as n}from"./chunk-AAHKRPJ3.js";import{ea as I}from"./chunk-Q232IBQN.js";import{a as v}from"./chunk-WWNBTMQ7.js";import{Ic as R,Ob as d,Oc as _,Pc as f,Qc as g,Ta as m,cd as y,dd as C,ed as b,ld as S,qc as p,rc as u,sc as h,v as a,xa as c}from"./chunk-O7RN3KYY.js";import{a as r}from"./chunk-ZE2KCNEA.js";r();var W=(()=>{class l{constructor(){this.userService=c(I),this.placeholder=$localize`Search roles`,this.showInternal=!1,this.singleSelection=!1,this.nonRemovableRoles=[],this._selectedRoles=[],this._nonRemovableRoles=[],this.onChange=()=>{},this.onTouched=()=>{}}ngOnChanges(t){if(t.nonRemovableRoles){let o=t.nonRemovableRoles.currentValue;Array.isArray(o)&&(this._nonRemovableRoles=o.map(e=>({name:e,description:""})))}}displayRole(t){return{label:t.name}}writeValue(t){Array.isArray(t)&&(this._selectedRoles=t.map(o=>({name:o,description:""})))}registerOnChange(t){this.onChange=t}registerOnTouched(t){this.onTouched=t}setDisabledState(t){this._disabled=t}emitChange(){this.onChange(this._selectedRoles.map(t=>t.name))}searchRoles(t,o){return this.userService.getRoles(t,{search:o,is_internal:this.showInternal?void 0:!1,has_permission:this.permissionFilter,field:["name","description"]}).pipe(a(e=>this.roleFilter?e.results.filter(this.roleFilter):e.results))}focus(){this.autocomplete.focus()}static{this.\u0275fac=function(o){return new(o||l)}}static{this.\u0275cmp=d({type:l,selectors:[["role-select"]],viewQuery:function(o,e){if(o&1&&_(n,5),o&2){let s;f(s=g())&&(e.autocomplete=s.first)}},inputs:{inputId:"inputId",placeholder:"placeholder",permissionFilter:"permissionFilter",showInternal:"showInternal",singleSelection:"singleSelection",describedBy:"describedBy",roleFilter:"roleFilter",nonRemovableRoles:"nonRemovableRoles"},features:[S([{provide:v,useExisting:l,multi:!0}]),m],decls:1,vars:9,consts:[["matchKey","name",3,"selectedItemsChange","blurred","inputId","searchFn","displayFn","singleSelection","describedBy","nonRemovableItems","placeholder","disabled","selectedItems"]],template:function(o,e){o&1&&(u(0,"autocomplete-select",0),b("selectedItemsChange",function(i){return C(e._selectedRoles,i)||(e._selectedRoles=i),i}),R("selectedItemsChange",function(){return e.emitChange()})("blurred",function(){return e.onTouched()}),h()),o&2&&(p("inputId",e.inputId)("searchFn",e.searchRoles.bind(e))("displayFn",e.displayRole)("singleSelection",e.singleSelection)("describedBy",e.describedBy)("nonRemovableItems",e._nonRemovableRoles)("placeholder",e.placeholder)("disabled",e._disabled),y("selectedItems",e._selectedRoles))},dependencies:[n],encapsulation:2})}}return l})();export{W as a};