import{s as _,E as A,G as C,f as m,ag as j,cU as U,cV as x,z as b,P as E,Q as p,aX as N,bk as R,y as T,X as P,a3 as k,aA as D,ah as H}from"./index-DT8qTvyx.js";var M=function(y){_(o,y);function o(t){return y.call(this,t)||this}return o.prototype.componentWillUnmount=function(){this.unHook&&this.unHook()},o.prototype.onSearch=function(t,e,n){return A(this,void 0,void 0,function(){var a,l,s,i,d,c,u,r,f,h;return C(this,function(v){switch(v.label){case 0:if(a=this.props,l=a.searchApi,s=a.setLoading,i=a.env,l=(n==null?void 0:n.searchApi)||l,d=(n==null?void 0:n.searchTerm)||this.props.searchTerm||"term",c=(n==null?void 0:n.searchParam)||this.props.searchParam||{},u=T((h={},h[d]=t,h),c),!P(l,u))return[2,Promise.resolve([])];s(!0),v.label=1;case 1:return v.trys.push([1,,3,4]),[4,i.fetcher(l,u,{cancelExecutor:e,autoAppend:!0})];case 2:return r=v.sent(),f=r.data&&r.data.options||r.data||[],[2,f];case 3:return s(!1),[7];case 4:return[2]}})})},o.prototype.deferLoad=function(t,e,n){return A(this,void 0,void 0,function(){var a,l,s,i,d,c,u;return C(this,function(r){switch(r.label){case 0:if(a=this.props,l=a.env,s=a.deferApi,i=a.setLoading,a.formInited,a.addHook,s=(n==null?void 0:n.deferApi)||s,!l||!l.fetcher)throw new Error("fetcher is required");if(d=k(t,{}),!P(s,d))return[2,Promise.resolve([])];r.label=1;case 1:return r.trys.push([1,,3,4]),[4,l.fetcher(s,d)];case 2:return c=r.sent(),u=c.data&&c.data.options||c.data||[],e&&u.forEach(function(f){f.isRef=!0}),[2,u];case 3:return i(!1),[7];case 4:return[2]}})})},o.prototype.changeValue=function(t){return A(this,void 0,void 0,function(){var e,n,a,l,s,i,d,c,u,r,f,h;return C(this,function(v){switch(v.label){case 0:return e=this.props,n=e.joinValues,a=e.extractValue,l=e.delimiter,s=e.multiple,i=e.valueField,d=e.onChange,c=e.options,e.setOptions,e.data,u=e.dispatchEvent,r=t,f=[],(Array.isArray(t)?t:t?[t]:[]).forEach(function(g){var S=D(c,function(F){return F[i||"value"]==g[i||"value"]});S||f.push(g)}),n?s?r=Array.isArray(t)?t.map(function(g){return g[i||"value"]}).join(l):t?t[i||"value"]:"":r=r?r[i||"value"]:"":a&&(s?r=Array.isArray(t)?t.map(function(g){return g[i||"value"]}):t?[t[i||"value"]]:[]:r=r?r[i||"value"]:""),[4,u("change",H(this.props,{value:r,options:c,items:c}))];case 1:return h=v.sent(),h!=null&&h.prevented?[2]:(d(r),[2])}})})},o.prototype.renderStatic=function(){var t=this.props,e=t.selectedOptions,n=t.labelField,a=n===void 0?"label":n,l=t.classnames;return a==="avatar"?e.map(function(s,i){return m.createElement("img",{key:i,className:l("UserSelect-avatar-img"),src:s[a],alt:""})}):e.map(function(s){return s[a]}).join(",")},o.prototype.render=function(){var t=this,e=this.props,n=e.showNav,a=e.navTitle,l=e.searchable,s=e.options,i=e.className;e.style;var d=e.selectedOptions,c=e.tabOptions,u=e.multi,r=e.multiple,f=e.isDep,h=e.isRef,v=e.placeholder,g=e.searchPlaceholder,S=e.tabMode,F=e.data,L=e.displayFields,w=e.labelField,V=e.loadingConfig;return c==null||c.forEach(function(O){O.deferLoad=t.deferLoad,O.onChange=t.changeValue,O.onSearch=t.onSearch}),m.createElement("div",{className:j("UserSelectControl",i)},S?m.createElement(U,{selection:d,tabOptions:c,multiple:r,displayFields:L,onChange:this.changeValue,onSearch:this.onSearch,deferLoad:this.deferLoad,data:F}):m.createElement(x,{loadingConfig:V,showNav:n,navTitle:a,selection:d,options:s,multi:u,multiple:r,searchable:l,placeholder:v,searchPlaceholder:g,deferLoad:this.deferLoad,onChange:this.changeValue,onSearch:this.onSearch,displayFields:L,labelField:w,isDep:f,isRef:h}))},o.defaultProps={showNav:!0},b([E,p("design:type",Function),p("design:paramtypes",[String,Function,Object]),p("design:returntype",Promise)],o.prototype,"onSearch",null),b([E,p("design:type",Function),p("design:paramtypes",[Object,Boolean,Object]),p("design:returntype",Promise)],o.prototype,"deferLoad",null),b([E,p("design:type",Function),p("design:paramtypes",[Object]),p("design:returntype",Promise)],o.prototype,"changeValue",null),b([N(),p("design:type",Function),p("design:paramtypes",[]),p("design:returntype",void 0)],o.prototype,"render",null),o}(m.Component),$=function(y){_(o,y);function o(){return y!==null&&y.apply(this,arguments)||this}return o=b([R({type:"users-select"})],o),o}(M);export{$ as UserSelectControlRenderer,M as default};
