(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7678],{21330:(e,s,t)=>{"use strict";t.d(s,{UsersTable:()=>u});var a=t(95155),l=t(12115),n=t(56502),r=t(95088),i=t(32897),c=t(84820),o=t(89678);function u(e){let{rows:s,roles:t,canManage:u,currentUserId:d}=e,{t:m,locale:h,relative:x}=(0,n.s)(),[y,p]=(0,l.useState)(s),[v,g]=(0,l.useState)(null),[A,j]=(0,l.useState)(null),[k,N]=(0,l.useState)(null),b=async(e,s,t)=>{g(e),j(null),N(null);try{let a=await o.FH.patch("/api/users/".concat(e),s);p(e=>e.map(e=>{var s;return e.id===a.id?{...e,isActive:a.isActive,roleKey:null!=(s=a.roles[0])?s:e.roleKey}:e})),N(m(t))}catch(e){j(e instanceof o.E6?(0,o.oh)(e.failure,h):m("common.serverError"))}finally{g(null)}},f=[{key:"name",header:m("users.columns.name"),sortValue:e=>"ar"===h?e.nameAr:e.name,cell:e=>(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("p",{className:"truncate text-text",children:"ar"===h?e.nameAr:e.name}),(0,a.jsx)("p",{className:"truncate font-mono text-[11px] text-text-faint",children:e.email})]})},{key:"employeeId",header:m("users.columns.employeeId"),secondary:!0,sortValue:e=>e.employeeId,cell:e=>(0,a.jsx)("span",{className:"font-mono text-[11px] text-text-muted",children:e.employeeId})},{key:"department",header:m("users.columns.department"),secondary:!0,sortValue:e=>e.department,cell:e=>(0,a.jsx)("span",{className:"text-text-muted",children:"ar"===h?e.departmentAr:e.department})},{key:"role",header:m("users.columns.roles"),sortValue:e=>e.roleKey,cell:e=>u?(0,a.jsx)(r.l6,{"aria-label":m("users.changeRole"),value:e.roleKey,disabled:v===e.id,onChange:s=>b(e.id,{roleKey:s.target.value},"users.roleChanged"),className:"w-auto min-w-40",children:t.map(e=>(0,a.jsx)("option",{value:e.key,children:"ar"===h?e.nameAr:e.name},e.key))}):(0,a.jsx)(c.Ex,{tone:"muted",children:m("role.".concat(e.roleKey))})},{key:"status",header:m("users.columns.status"),align:"end",sortValue:e=>+!!e.isActive,cell:e=>(0,a.jsx)(c.Ex,{tone:e.isActive?"brand":"muted",children:e.isActive?m("users.active"):m("users.inactive")})},{key:"lastLogin",header:m("users.columns.lastLogin"),align:"end",secondary:!0,sortValue:e=>{var s;return null!=(s=e.lastLoginAt)?s:0},cell:e=>(0,a.jsx)("span",{className:"text-[11px] text-text-faint",children:e.lastLoginAt?x(e.lastLoginAt):m("users.never")})},{key:"actions",header:m("common.actions"),align:"end",cell:e=>u?(0,a.jsx)(r.$n,{size:"sm",variant:e.isActive?"ghost":"secondary",loading:v===e.id,disabled:e.id===d,title:e.id===d?m("common.na"):void 0,onClick:()=>b(e.id,{isActive:!e.isActive},"users.statusChanged"),children:e.isActive?m("users.deactivate"):m("users.activate")}):null}];return(0,a.jsxs)("div",{className:"space-y-3",children:[A?(0,a.jsx)(r.Notice,{tone:"danger",children:A}):null,k?(0,a.jsx)(r.Notice,{tone:"success",children:k}):null,(0,a.jsx)(i.b,{rows:y,columns:f,getRowKey:e=>e.id,searchable:e=>"".concat(e.name," ").concat(e.nameAr," ").concat(e.email," ").concat(e.employeeId),initialSort:{key:"role",direction:"asc"},caption:m("users.title"),emptyTitle:m("users.empty")})]})}},87987:(e,s,t)=>{Promise.resolve().then(t.t.bind(t,52619,23)),Promise.resolve().then(t.bind(t,21330))}},e=>{e.O(0,[2619,4909,4820,4672,2897,8441,1255,7358],()=>e(e.s=87987)),_N_E=e.O()}]);