import{o as U,es as f,j as r,cn as E,g as y,dv as L,h as o,i as c,Y as R,aL as S,bV as T,bT as d}from"./app-BgLa5dit.js";function i(e){return{application:c.USERS,action:o.Users.EDIT_USER,args:[e.id],params:{userType:e.userType}}}function k(e){if(S.getUserRole(e)===T.Admin)return"Administrator";const a=S.getUserType(e);if(a===d.Unknown)return"Unknown";if(a===d.Learner)return"Student";if(a===d.Staff)return"Staff"}function A(e){return{application:c.CUSTOMERS,action:o.Customers.MANAGE_CUSTOMER,args:[e.id]}}function q(e){y.trigger({application:c.USERS,action:o.Users.HOME,params:{query:e}})}function b(e){var a,t;return U(!!((t=(a=e.data)==null?void 0:a.data)!=null&&t.length)&&f.getById(e.data.data.map(u=>u.id)))}function $(e){var p,m;const a=U(!!e.query&&f.searchUsers(e.query,e.cursor,!0)),t=b(a),u=(m=(p=a.data)==null?void 0:p.data)!=null&&m.length?t.hasCompleted:a.hasCompleted;return r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"pb-3 w-50",children:r.jsx(E,{initialQuery:e.query,placeholder:"Search for a user by name, username or email...",onSuggestionSelected:s=>y.trigger(i(s)),onSubmit:q})}),u&&(a.data.data.length?r.jsx(L,{collection:a.data,columns:[{header:"Name",accessor:s=>`${s.name} ${s.surname}`,appLink:i},{header:"Username",accessor:"username",appLink:i},{header:"Email",accessor:"email",appLink:i},{header:"Type - Customer",accessor:s=>{var h;const x=((h=s.customers)==null?void 0:h.data)??[];return r.jsx("ul",{className:"list-unstyled",children:x.map((n,j)=>{var g;const l=(g=s.userProfiles)==null?void 0:g.data.find(C=>C.customer.id===n.id);return r.jsx("li",{children:r.jsxs(R,{appLink:A(n),children:[r.jsx("strong",{children:`${l!=null&&l.role?`${k(s)} - `:""}`}),`${n.name} - ${n.crmId}`]})},j)})})}}],collectionAppLink:{application:c.USERS,action:o.Users.HOME,params:{query:e.query}}}):r.jsx("p",{children:"No users found, please try a different search query."}))]})}export{$ as UserSearchView};
//# sourceMappingURL=DxUaeluX.chunk.js.map
