1import{a as fe,r as j,j as e,s as Z,I as N,B as $,m as q,u as me,d as ee,e as se,t as F,g as A,k as xe,aI as je,aJ as ve,aK as we,aL as Ne,aR as be,aU as Ie,W as re,aS as Pe}from"./index-DHw9oA_9.js";import{P as Se}from"./project-guard-BAQgFXYF.js";import{R as Ce}from"./route-guard-CtrCsKlk.js";import{u as ye}from"./use-pagination-search-Bvdj626l.js";import{u as pe}from"./usePermissions-DSf1KNJ8.js";import{H as De}from"./header-Cv8cqG2Q.js";import{M as Ue}from"./main-DVTNl6i5.js";import{B as D}from"./badge-B6qX-S9N.js";import{C as W}from"./checkbox-T9BQO82N.js";import{L as Q}from"./long-text-DpFELbfV.js";import{i as Re,f as Fe}from"./react-icons.esm-CVQ9FCrM.js";import{D as Ae,a as Te,b as Oe,c as ne,d as Ee}from"./dropdown-menu-CYcatU4d.js";import{u as ke}from"./use-dialog-state-CL-YPIVC.js";import{I as Me}from"./IconEdit-DfkT1ltp.js";import{b as Ve}from"./index.esm-BEcYT0NX.js";import{a as $e}from"./zod-D6B7TXOx.js";import{R as qe,I as Le}from"./roles-D4eApQGW.js";import{c as _e,S as Ke}from"./scopes-select-DqQ2_1t9.js";import{F as ze,a as B,b as X,c as H,d as G,f as ie}from"./form-CDfn-5e9.js";import{S as He,a as We,b as Je,c as Qe,d as Be}from"./select-GjCTOyyM.js";import{u as L}from"./use-error-handler-DNWpwRYc.js";import{u as Xe}from"./useRequestPermissions-DXNh56QQ.js";import{p as Ge}from"./pagination-A-lnj4Ev.js";import{e as Ye,o as f,d as v,s as o,b as y,f as Ze}from"./schemas-Dk9VIjIk.js";import{A as es,a as ss,b as rs}from"./alert-CDypPSvf.js";import{L as ts}from"./label-B1Snm1HL.js";import{C as os}from"./confirm-dialog-BSfgJrJZ.js";import{I as as}from"./IconAlertTriangle-ByVA5V6o.js";import{P as ns}from"./permission-guard-CTE2kIhR.js";import{u as is,g as ls,a as cs,d as ds,f as le,T as us}from"./table-skeleton-B-H-uQPY.js";import{a as ms,b as ps,T as Y,c as hs,d as gs,e as ce}from"./table-B8uNf2eO.js";import{S as fs}from"./server-side-pagination-DHwf_SNl.js";import{D as xs}from"./data-table-faceted-filter-0DJuE9YU.js";import"./projects-BI7BU8R_.js";import"./coerce-CPg-xoCJ.js";import"./index-OHEQoLNU.js";import"./index-CYhYchP8.js";import"./check-9LYngghg.js";import"./popover-BsOz1jcH.js";import"./index-CPF_HSnu.js";import"./tooltip-DrbA_q--.js";import"./index-y6pprLpS.js";import"./index-DkWmRZBc.js";import"./index-B2zW4HOT.js";import"./chevron-right-Cda121HX.js";import"./chevrons-up-down-DXwgQkLi.js";import"./chevron-down-DXGKvrGC.js";import"./chevron-up-BFohDdsk.js";import"./alert-dialog-B3xsagxE.js";import"./separator-Dr0amUq4.js";const js=[["path",{d:"M8 7a4 4 0 1 0 8 0a4 4 0 0 0 -8 0",key:"svg-0"}],["path",{d:"M6 21v-2a4 4 0 0 1 4 -4h4c.348 0 .686 .045 1.009 .128",key:"svg-1"}],["path",{d:"M16 19h6",key:"svg-2"}]],vs=fe("outline","user-minus","UserMinus",js),he=Z.createContext(null);function ws({children:s}){const[i,n]=ke(null),[t,r]=j.useState(null);return e.jsx(he,{value:{open:i,setOpen:n,currentRow:t,setCurrentRow:r},children:s})}const te=()=>{const s=Z.useContext(he);if(!s)throw new Error("useUsers has to be used within <UsersContext>");return s};function Ns({row:s}){const{t:i}=N(),{setOpen:n,setCurrentRow:t}=te(),{userPermissions:r}=pe();return r.canWrite?e.jsx(e.Fragment,{children:e.jsxs(Ae,{modal:!1,children:[e.jsx(Te,{asChild:!0,children:e.jsxs($,{variant:"ghost",className:"data-[state=open]:bg-muted flex h-8 w-8 p-0",children:[e.jsx(Re,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:i("common.actions.openMenu")})]})}),e.jsxs(Oe,{align:"end",className:"w-[160px]",children:[r.canEdit&&e.jsxs(ne,{onClick:()=>{t(s.original),n("edit")},children:[e.jsx(Me,{size:16,className:"mr-2"}),i("common.actions.edit")]}),r.canEdit&&r.canWrite&&e.jsx(Ee,{}),r.canWrite&&e.jsxs(ne,{onClick:()=>{t(s.original),n("remove")},className:"text-red-500!",children:[e.jsx(vs,{size:16,className:"mr-2"}),i("users.actions.removeFromProject")]})]})]})}):null}const bs=(s,i=!1,n=!1)=>{const t=[];return i&&t.push({id:"select",header:({table:r})=>e.jsx(W,{checked:r.getIsAllPageRowsSelected()||r.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:l=>r.toggleAllPageRowsSelected(!!l),"aria-label":"Select all"}),cell:({row:r})=>e.jsx(W,{checked:r.getIsSelected(),onCheckedChange:l=>r.toggleSelected(!!l),"aria-label":"Select row"}),enableSorting:!1,enableHiding:!1}),t.push({accessorKey:"firstName",header:s("users.columns.firstName"),cell:({row:r})=>e.jsx(Q,{children:r.getValue("firstName")}
1)},{accessorKey:"lastName",header:s("users.columns.lastName"),cell:({row:r})=>e.jsx(Q,{children:r.getValue("lastName")})},{accessorKey:"email",header:s("users.columns.email"),cell:({row:r})=>e.jsx(Q,{children:r.getValue("email")})},{accessorKey:"isOwner",header:s("users.columns.projectOwner"),cell:({row:r})=>r.getValue("isOwner")?e.jsx(D,{variant:"default",children:s("users.badges.projectOwner")}):e.jsx(D,{variant:"secondary",children:s("users.badges.member")})}),n&&t.push({accessorKey:"roles",header:s("users.columns.projectRoles"),cell:({row:r})=>{const c=r.original.roles?.edges;return!c||c.length===0?e.jsx("span",{className:"text-muted-foreground",children:s("users.badges.noRoles")}):e.jsxs("div",{className:"flex flex-wrap gap-1",children:[c.slice(0,2).map((h,d)=>e.jsx(D,{variant:"default",children:h.node.name},d)),c.length>2&&e.jsxs(D,{variant:"secondary",children:["+",c.length-2]})]})}}),t.push({accessorKey:"scopes",header:s("users.columns.projectScopes"),cell:({row:r})=>{const c=r.original.scopes;return!c||c.length===0?e.jsx("span",{className:"text-muted-foreground",children:s("users.badges.noScopes")}):e.jsxs("div",{className:"flex flex-wrap gap-1",children:[c.slice(0,3).map((h,d)=>e.jsx(D,{variant:"outline",children:h},d)),c.length>3&&e.jsxs(D,{variant:"secondary",children:["+",c.length-3]})]})}},{accessorKey:"status",header:s("common.columns.status"),cell:({row:r})=>{const l=r.getValue("status");return e.jsx(D,{variant:l==="activated"?"default":"secondary",children:s(l==="activated"?"users.status.activated":"users.status.deactivated")})}},{accessorKey:"createdAt",header:s("common.columns.createdAt"),cell:({row:r})=>new Date(r.getValue("createdAt")).toLocaleDateString()},{accessorKey:"updatedAt",header:s("common.columns.updatedAt"),cell:({row:r})=>new Date(r.getValue("updatedAt")).toLocaleDateString()},{id:"actions",cell:({row:r})=>e.jsx(Ns,{row:r})}),t},ge=Ye(["activated","deactivated"]),Is=f({id:o(),userID:o(),projectID:o(),isOwner:y(),scopes:v(o()).optional().nullable(),user:f({id:o(),createdAt:o(),updatedAt:o(),email:o(),status:ge,preferLanguage:o().optional(),firstName:o().optional(),lastName:o().optional(),roles:f({edges:v(f({node:f({id:o(),name:o(),code:o().optional(),level:o().optional()})}))}).optional()})}),Ps=f({id:o(),createdAt:o(),updatedAt:o(),email:o(),status:ge,preferLanguage:o().optional(),firstName:o().optional(),lastName:o().optional(),isOwner:y().optional(),scopes:v(o()).optional().nullable(),projectUserId:o().optional(),roles:f({edges:v(f({node:f({id:o(),name:o(),code:o().optional(),level:o().optional()})}))}).optional()});f({edges:v(f({node:Ps})),pageInfo:Ge});f({createdAt:o().optional(),updatedAt:o().optional(),email:Ze("Invalid email address"),firstName:o().optional(),lastName:o().optional(),password:o().min(6,"Password must be at least 6 characters"),confirmPassword:o(),isOwner:y().optional(),scopes:v(o()).optional(),roleIDs:v(o()).optional()}).refine(s=>s.password===s.confirmPassword,{message:"Passwords don't match",path:["confirmPassword"]});f({createdAt:o().optional(),updatedAt:o().optional(),email:o().email("Invalid email address"),firstName:o().optional(),lastName:o().optional(),password:o().min(6,"Password must be at least 6 characters"),isOwner:y().optional(),scopes:v(o()).optional(),roleIDs:v(o()).optional()});f({newPassword:o().min(6,"Password must be at least 6 characters")});f({updatedAt:o().optional(),email:o().email("Invalid email address").optional(),firstName:o().optional(),lastName:o().optional(),isOwner:y().optional(),scopes:v(o()).optional(),appendScopes:v(o()).optional(),clearScopes:y().optional(),addRoleIDs:v(o()).optional(),removeRoleIDs:v(o()).optional(),clearRoles:y().optional()});function Ss(s){return` 2 query ProjectUsers($projectId: ID!) { 3 node(id: $projectId) { 4 ... on Project { 5 id 6 name 7 projectUsers { 8 id 9 userID 10 projectID 11 isOwner 12 scopes 13 user { 14 id 15 createdAt 16 updatedAt 17 email 18 status 19 firstName 20 lastName 21 preferLanguage${s.canViewRoles?` 22 roles(where: { projectID: $projectId }) { 23 edges { 24 node { 25 id 26 name 27 level 28 } 29 } 30 }`:""} 31 } 32 } 33 } 34 } 35 } 36 `}const Cs=` 37 mutation AddUserToProject($input: AddUserToProjectInput!) { 38 addUserToProject(input: $input) { 39 id 40 userID 41 projectID 42 isOwner 43 scopes 44 } 45 } 46`,ys=` 47 mutation RemoveUserFromProject($input: RemoveUserFromProjectInput!) { 48 removeUserFromProject(input: $input) 49 } 50`,Ds=` 51 mutation UpdateProjectUser($input: UpdateProjectUserInput!) { 52 updateProjectUser(input: $input) { 53 id 54 userID 55 projectID 56 isOwner 57 scopes 58 } 59 } 60`,Us=` 61 query AllUsers($first: Int, $after: Cursor, $where: UserWhereInput) { 62 users(first: $first, after: $after, where: $where) { 63 edges { 64 node { 65 id 66 email 67 firstName 68 lastName 69 status 70 } 71 } 72 pageInfo { 73 hasNextPage 74 hasPreviousPage 75 startCursor 76 endCursor 77 } 78 } 79 } 80`;function Rs(s,i){const{t:n}=N(),{handleError:t}=L(),r=Xe(),l=q();return me({queryKey:["project-users",l,s,r],queryFn:async()=>{try{if(!l)throw new Error("No project selected");const c=Ss(r),b=((await A(c,{projectId:l},{"X-Project-ID":l})).node.projectUsers||[]).map(g=>{const u=Is.parse(g);return{id:u.user.id,createdAt:u.user.createdAt,updatedAt:u.user.updatedAt,email:u.user.email,status:u.user.status,firstName:u.user.firstName,lastName:u.user.lastName,preferLanguage:u.user.preferLanguage,isOwner:u.isOwner,scopes:u.scopes,roles:u.user.roles,projectUserId:u.id}});return b.sort((g,u)=>new Date(u.createdAt).getTime()-new Date(g.createdAt).getTime()),{edges:b.map(g=>({node:g})),pageInfo:{hasNextPage:!1,hasPreviousPage:!1,startCursor:null,endCursor:null}}}catch(c){throw t(c,n("common.errors.loadFailed")),c}},enabled:!i?.disableAutoFetch&&!!l})}function Fs(){const{t:s}=N(),i=ee(),n=q(),{handleError:t}=L();return se({mutationFn:async r=>{try{if(!n)throw new Error("No project selected");const l={"X-Project-ID":n};return(await A(Cs,{input:{projectId:n,userId:r.userId,isOwner:r.isOwner,scopes:r.scopes,roleIDs:r.roleIDs}},l)).addUserToProject}catch(l){throw t(l,{context:"Add User to Project"}),l}},onSuccess:()=>{i.invalidateQueries({queryKey:["project-users",n]}),F.success(s("users.messages.addToProjectSuccess"))}})}function As(){const{t:s}=N(),i=ee(),n=q(),{handleError:t}=L();return se({mutationFn:async r=>{try{if(!n)throw new Error("No project selected");return(await A(ys,{input:{projectId:n,userId:r}},{"X-Project-ID":n})).removeUserFromProject}catch(l){throw t(l,{context:"Remove User from Project"}),l}},onSuccess:()=>{i.invalidateQueries({queryKey:["project-users",n]}),F.success(s("users.messages.removeFromProjectSuccess"))}})}function Ts(){const{t:s}=N(),i=ee(),n=q(),{handleError:t}=L();return se({mutationFn:async r=>{try{if(!n)throw new Error("No project selected");const l={"X-Project-ID":n};return(await A(Ds,{input:{projectId:n,userId:r.userId,isOwner:r.isOwner,scopes:r.scopes,addRoleIDs:r.addRoleIDs,removeRoleIDs:r.removeRoleIDs}},l)).updateProjectUser}catch(l){throw t(l,{context:"Update Project User"}),l}},onSuccess:()=>{i.invalidateQueries({queryKey:["project-users",n]}),F.success(s("users.messages.updateSuccess"))}})}function Os(s,i){const{t:n}=N(),{handleError:t}=L();return me({queryKey:["all-users",s],queryFn:async()=>{try{return(await A(Us,s)).users}catch(r){throw t(r,n("common.errors.loadFailed")),r}},enabled:i?.enabled??!0})}const de=f({userId:o().optional(),isOwner:y().optional(),roleIDs:v(o()).optional(),scopes:v(o()).optional()});function ue({currentRow:s,open:i,onOpenChange:n}){const{t}=N(),r=xe(a=>a.auth.user),l=q(),c=!!s,[h,d]=j.useState([]),[x,b]=j.useState(!1),[g,u]=j.useState(""),[U,T]=j.useState(!0),[O,S]=j.useState(null),E=Fs(),k=Ts(),J=j.useMemo(()=>c?de:de.extend({userId:o().min(1,t("users.validation.userRequired"))}),[c,t]),{data:_,isLoading:K}=Os({first:100,where:g?{emailContainsFold:g}:void 0},{enabled:i}),w=Ve({resolver:$e(J),defaultValues:c?{userId:s.id,isOwner:s.isOwner,roleIDs:s.roles?.edges?.map(a=>a.node.id)||[],scopes:s.scopes||[]}:{userId:"",isOwner:!1,roleIDs:[],scopes:[]}}),z=j.useCallback(async()=>
80{if(l){b(!0);try{const m=await A(qe,{first:100,where:{projectID:l}});if(d(m.roles.edges.map(I=>I.node)),c&&s){const I=s.scopes||[],P=_e(r,I,s.isOwner||!1,l);T(P)}}catch{F.error(t("common.errors.loadFailed"))}finally{b(!1)}}},[t,l,c,s,r]);j.useEffect(()=>{i&&z()},[i,z]);const oe=async a=>{if(c&&s){const m=s.roles?.edges?.map(C=>C.node.id)||[],I=a.roleIDs||[],P=I.filter(C=>!m.includes(C)),M=m.filter(C=>!I.includes(C));await k.mutateAsync({userId:s.id,isOwner:a.isOwner,scopes:a.scopes,addRoleIDs:P.length>0?P:void 0,removeRoleIDs:M.length>0?M:void 0}),w.reset(),n(!1)}else await E.mutateAsync({userId:a.userId||"",isOwner:a.isOwner,scopes:a.scopes,roleIDs:a.roleIDs}),w.reset(),n(!1)},R=a=>{const m=w.getValues("roleIDs")||[],I=m.includes(a)?m.filter(P=>P!==a):[...m,a];w.setValue("roleIDs",I)},p=_?.edges?.map(a=>a.node)||[];return e.jsx(je,{open:i,onOpenChange:a=>{a||(w.reset(),u("")),n(a)},children:e.jsxs(ve,{className:"sm:max-w-2xl",ref:S,children:[e.jsxs(we,{className:"text-left",children:[e.jsx(Ne,{children:t(c?"users.dialogs.edit.title":"users.dialogs.addToProject.title")}),e.jsx(be,{children:t(c?"users.dialogs.edit.description":"users.dialogs.addToProject.description")})]}),e.jsx("div",{className:"max-h-[60vh] overflow-y-auto",children:e.jsx(ze,{...w,children:e.jsxs("form",{id:"user-form",onSubmit:w.handleSubmit(oe),className:"space-y-6",children:[!c&&e.jsx(B,{control:w.control,name:"userId",render:({field:a})=>e.jsxs(X,{children:[e.jsx(H,{children:t("users.form.selectUser")}),e.jsxs(He,{onValueChange:a.onChange,value:a.value,children:[e.jsx(G,{children:e.jsx(We,{children:e.jsx(Je,{placeholder:t("users.form.selectUserPlaceholder")})})}),e.jsxs(Qe,{children:[e.jsxs("div",{className:"flex items-center border-b px-3 pb-2",children:[e.jsx(Ie,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(re,{placeholder:t("users.form.searchUsers"),value:g,onChange:m=>u(m.target.value),className:"h-8 border-0 p-0 focus-visible:ring-0"})]}),K?e.jsx("div",{className:"text-muted-foreground p-2 text-center text-sm",children:t("common.loading")}):p.length===0?e.jsx("div",{className:"text-muted-foreground p-2 text-center text-sm",children:t("users.form.noUsersFound")}):p.map(m=>e.jsxs(Be,{value:m.id,children:[m.firstName," ",m.lastName," (",m.email,")"]},m.id))]})]}),e.jsx(ie,{})]})}),e.jsx(B,{control:w.control,name:"isOwner",render:({field:a})=>e.jsxs(X,{className:"flex flex-row items-start space-y-0 space-x-3",children:[e.jsx(G,{children:e.jsx(W,{checked:a.value,onCheckedChange:a.onChange})}),e.jsxs("div",{className:"space-y-1 leading-none",children:[e.jsx(H,{children:t("users.form.isOwner")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("users.form.ownerDescription")})]})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(H,{children:t("users.form.projectRoles")}),x?e.jsx("div",{children:t("users.form.loadingRoles")}):h.length===0?e.jsx("div",{className:"text-muted-foreground text-sm",children:t("users.form.noProjectRoles")}):e.jsx("div",{className:"grid grid-cols-2 gap-2",children:h.map(a=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(W,{id:`role-${a.id}`,checked:(w.watch("roleIDs")||[]).includes(a.id),onCheckedChange:()=>R(a.id)}),e.jsx("label",{htmlFor:`role-${a.id}`,className:"text-sm leading-none font-medium peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:a.name})]},a.id))})]}),e.jsx(B,{control:w.control,name:"scopes",render:({field:a})=>e.jsxs(X,{children:[e.jsx(H,{children:t("users.form.projectScopes")}),e.jsx(G,{children:e.jsx(Ke,{value:a.value||[],onChange:a.onChange,portalContainer:O})}),e.jsx(ie,{})]})})]})})}),e.jsxs(Pe,{children:[c&&!U&&e.jsx("p",{className:"text-destructive mr-auto text-sm",children:t("users.errors.insufficientPermissions")}),e.jsx($,{variant:"outline",onClick:()=>{w.reset(),n(!1)},children:t("common.buttons.cancel")}),e.jsx($,{type:"submit",form:"user-form",disabled:E.isPending||k.isPending||c&&!U,children:E.isPending||k.isPending?t("users.buttons.adding"):t(c?"common.buttons.saveChanges":"users.buttons.addToProject")})]})]})})}function Es({open:s,onOpenChange:i,currentRow:n}){const{t}=N(),[r,l]=j.useState(""),c=As(),h=`${n.firstName} ${n.lastName}`,d=async()=>
80{if(r.trim()===h)try{await c.mutateAsync(n.id),F.success(t("users.messages.removeFromProjectSuccess")),i(!1),l("")}catch{F.error(t("common.errors.somethingWentWrong"))}};return e.jsx(os,{open:s,onOpenChange:x=>{i(x),x||l("")},handleConfirm:d,disabled:r.trim()!==h||c.isPending,title:e.jsxs("span",{className:"text-destructive",children:[e.jsx(as,{className:"stroke-destructive mr-1 inline-block",size:18})," ",t("users.dialogs.remove.title")]}),desc:e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"mb-2",children:t("users.dialogs.remove.description",{name:h})}),e.jsxs(ts,{className:"my-2",children:[t("users.dialogs.remove.confirmLabel"),e.jsx(re,{value:r,onChange:x=>l(x.target.value),placeholder:t("users.dialogs.remove.confirmPlaceholder"),"data-testid":"remove-confirmation-input"})]}),e.jsxs(es,{variant:"destructive",children:[e.jsx(ss,{children:t("users.dialogs.remove.warningTitle")}),e.jsx(rs,{children:t("users.dialogs.remove.warningDescription")})]})]}),confirmText:c.isPending?t("users.buttons.removing"):t("users.buttons.remove"),destructive:!0,"data-testid":"remove-dialog"})}function ks(){const{open:s,setOpen:i,currentRow:n,setCurrentRow:t}=te();return e.jsxs(e.Fragment,{children:[e.jsx(ue,{open:s==="add",onOpenChange:()=>i("add")},"user-add"),n&&e.jsxs(e.Fragment,{children:[e.jsx(ue,{open:s==="edit",onOpenChange:()=>{i("edit"),setTimeout(()=>{t(null)},500)},currentRow:n},`user-edit-${n.id}`),e.jsx(Es,{open:s==="remove",onOpenChange:()=>{i("remove"),setTimeout(()=>{t(null)},500)},currentRow:n},`user-remove-${n.id}`)]})]})}function Ms(){const{t:s}=N(),{setOpen:i}=te();return e.jsx("div",{className:"flex gap-2",children:e.jsx(ns,{requiredSystemScope:"read_users",requiredScope:"write_users",children:e.jsxs($,{className:"space-x-1",onClick:()=>i("add"),children:[e.jsx("span",{children:s("users.addUser")})," ",e.jsx(Le,{size:18})]})})})}function Vs({table:s}){const{t:i}=N(),n=s.getState().columnFilters.length>0;return e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex flex-1 flex-col-reverse items-start gap-y-2 sm:flex-row sm:items-center sm:space-x-2",children:[e.jsx(re,{placeholder:i("users.filterUsers"),value:s.getColumn("firstName")?.getFilterValue()??"",onChange:t=>s.getColumn("firstName")?.setFilterValue(t.target.value),className:"h-8 w-[150px] lg:w-[250px]"}),e.jsx("div",{className:"flex gap-x-2",children:s.getColumn("status")&&e.jsx(xs,{column:s.getColumn("status"),title:i("users.filters.status"),options:[{label:i("users.status.activated"),value:"activated"},{label:i("users.status.deactivated"),value:"deactivated"}]})}),n&&e.jsxs($,{variant:"ghost",onClick:()=>s.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:[i("common.filters.reset"),e.jsx(Fe,{className:"ml-2 h-4 w-4"})]})]})})}function $s({columns:s,data:i,loading:n,pageInfo:t,pageSize:r,totalCount:l,onNextPage:c,onPreviousPage:h,onPageSizeChange:d,nameFilter:x,statusFilter:b,roleFilter:g,onNameFilterChange:u,onStatusFilterChange:U,onRoleFilterChange:T}){const{t:O}=N(),[S,E]=j.useState({}),[k,J]=j.useState({}),[_,K]=j.useState([]),[w,z]=j.useState([]);Z.useEffect(()=>{const p=[];x&&p.push({id:"firstName",value:x}),b.length>0&&p.push({id:"status",value:b}),g.length>0&&p.push({id:"role",value:g}),K(p)},[x,b,g]);const R=is({data:i,columns:s,state:{sorting:w,columnVisibility:k,rowSelection:S,columnFilters:_},enableRowSelection:!0,onRowSelectionChange:E,onSortingChange:z,onColumnFiltersChange:p=>{const a=typeof p=="function"?p(_):p;K(a);const m=a.find(V=>V.id==="firstName")?.value,I=a.find(V=>V.id==="status")?.value,P=a.find(V=>V.id==="role")?.value,M=typeof m=="string"?m:"";M!==x&&u(M);const C=Array.isArray(I)?I:[];JSON.stringify(C.sort())!==JSON.stringify(b.sort())&&U(C);const ae=Array.isArray(P)?P:[];JSON.stringify(ae.sort())!==JSON.stringify(g.sort())&&T(ae)},onColumnVisibilityChange:J,getCoreRowModel:ds(),manualFiltering:!0,manualPagination:!0,getFacetedRowModel:cs(),getFacetedUniqueValues:ls()});return e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden","data-testid":"users-table",children:[e.jsx(Vs,{table:R}),e.jsx("div",{className:"shadow-soft relative mt-4 flex-1 overflow-auto overflow-x-hidden rounded-2xl border border-[var(--table-border)]",children:e.jsxs(ms,{className:"border-separate border-spacing-0 rounded-2xl bg-[var(--table-background)]",children:[e.jsx(ps,{className:"sticky top-0 z-20 bg-[var(--table-header)] shadow-sm",children:R.getHeaderGroups().map(p=>e.jsx(Y,{className:"group/row border-0",children:p.headers.map(a=>e.jsx(hs,{colSpan:a.colSpan,className:`${a.column.columnDef.meta?.className??""} text-muted-foreground border-0 text-xs font-semibold tracking-wider up
80percase`,children:a.isPlaceholder?null:le(a.column.columnDef.header,a.getContext())},a.id))},p.id))}),e.jsx(gs,{className:"space-y-1 !bg-[var(--table-background)] p-2",children:n?e.jsx(us,{rows:r||10,columns:s.length}):R.getRowModel().rows?.length?R.getRowModel().rows.map(p=>e.jsx(Y,{"data-state":p.getIsSelected()&&"selected",className:"group/row table-row-hover rounded-xl border-0 !bg-[var(--table-background)] transition-all duration-200 ease-in-out",children:p.getVisibleCells().map(a=>e.jsx(ce,{className:`${a.column.columnDef.meta?.className??""} border-0 bg-inherit px-4 py-3`,children:le(a.column.columnDef.cell,a.getContext())},a.id))},p.id)):e.jsx(Y,{className:"!bg-[var(--table-background)]",children:e.jsx(ce,{colSpan:s.length,className:"h-24 !bg-[var(--table-background)] text-center",children:O("common.noData")})})})]})}),t&&r&&c&&h&&d&&e.jsx("div",{className:"mt-4 flex-shrink-0",children:e.jsx(fs,{pageInfo:t,pageSize:r,dataLength:i.length,totalCount:l,selectedRows:Object.keys(S).length,onNextPage:c,onPreviousPage:h,onPageSizeChange:d,"data-testid":"pagination"})})]})}function qs(){const{t:s}=N(),{userPermissions:i,rolePermissions:n}=pe(),{pageSize:t,setCursors:r,setPageSize:l,paginationArgs:c}=ye({defaultPageSize:20,pageSizeStorageKey:"project-users-table-page-size"}),h=j.useMemo(()=>bs(s,i.canWrite,n.canRead),[s,i.canWrite,n.canRead]),{data:d,isLoading:x,error:b}=Rs({...c}),g=d?.edges?.map(S=>S.node)||[],u=d?.pageInfo,U=()=>{d?.pageInfo?.hasNextPage&&d?.pageInfo?.endCursor&&r(d.pageInfo.startCursor??void 0,d.pageInfo.endCursor??void 0,"after")},T=()=>{d?.pageInfo?.hasPreviousPage&&r(d.pageInfo.startCursor??void 0,d.pageInfo.endCursor??void 0,"before")},O=S=>{l(S)};return e.jsx("div",{className:"flex flex-1 flex-col overflow-hidden",children:e.jsx($s,{data:g,columns:h,loading:x,pageInfo:u,pageSize:t,onNextPage:U,onPreviousPage:T,onPageSizeChange:O,nameFilter:"",statusFilter:[],roleFilter:[],onNameFilterChange:()=>{},onStatusFilterChange:()=>{},onRoleFilterChange:()=>{}})})}function Ls(){const{t:s}=N();return e.jsxs(ws,{children:[e.jsx(De,{fixed:!0,children:e.jsxs("div",{className:"flex flex-1 items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold tracking-tight",children:s("projectUsers.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("projectUsers.description")})]}),e.jsx(Ms,{})]})}),e.jsx(Ue,{fixed:!0,children:e.jsx(qs,{})}),e.jsx(ks,{})]})}function Vr(){return e.jsx(Se,{children:e.jsx(Ce,{requiredScopes:["read_users"],children:e.jsx(Ls,{})})})}export{Vr as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.