import{r as a,j as e}from"./vendor-react-9M-xu2bR.js";import{c as w}from"./infrastructure-n1j_TN6w.js";import{B as x,C as b,v as y,G as v}from"./ui-components-BxvihT61.js";import"./framework-BM176iet.js";import{b as n}from"./vendor-ui-utils-3tkeUVaX.js";import{a as C}from"./index-CTBPkbPG.js";import{s as k}from"./systemObjects-DSpePIIy.js";import{b4 as h,m as U,L as S,l as _}from"./vendor-icons-ndICq8DC.js";import"./vendor-i18n-E3-WitRV.js";import"./vendor-radix-C6qchjxv.js";import"./vendor-charts-BLNOCZWl.js";import"./vendor-objectstack-YKtcdalX.js";import"./vendor-zod-DxQVy2_o.js";import"./plugins-core-qwgXbAqa.js";import"./vendor-dndkit-CX1oDZqy.js";import"./plugins-views-CveFN6PV.js";import"./data-adapter-rvE3xy2B.js";import"./ui-layout-C6KWQtRO.js";const u=k.find(m=>m.name==="sys_user"),l=u.views[0].columns;function Q(){const{user:m}=w(),i=m?.role==="admin",t=C(),[d,p]=a.useState([]),[f,o]=a.useState(!0),r=a.useCallback(async()=>{if(t){o(!0);try{const s=await t.find("sys_user");p(s.data||[])}catch{n.error("Failed to load users")}finally{o(!1)}}},[t]);a.useEffect(()=>{r()},[r]);const j=a.useCallback(async()=>{if(t)try{await t.create("sys_user",{name:"New User",email:"",role:"member",status:"active"}),n.success("User created"),r()}catch{n.error("Failed to create user")}},[t,r]),g=a.useCallback(async s=>{if(t)try{await t.delete("sys_user",s),n.success("User deleted"),r()}catch{n.error("Failed to delete user")}},[t,r]);return e.jsxs("div",{className:"flex flex-col gap-4 sm:gap-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:"bg-primary/10 p-2 rounded-md shrink-0",children:e.jsx(h,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-xl sm:text-2xl font-bold tracking-tight",children:"User Management"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:"Manage system users and their roles"})]})]}),i&&e.jsxs(x,{size:"sm",className:"shrink-0 gap-2",onClick:j,children:[e.jsx(U,{className:"h-4 w-4"}),"Add User"]})]}),e.jsx(b,{children:e.jsx(y,{className:"p-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50",children:[l.map(s=>{const c=u.fields.find(N=>N.name===s);return e.jsx("th",{className:"h-10 px-3 sm:px-4 text-left font-medium text-muted-foreground whitespace-nowrap",children:c?.label??s},s)}),i&&e.jsx("th",{className:"h-10 px-3 sm:px-4 text-right font-medium text-muted-foreground",children:"Actions"})]})}),e.jsx("tbody",{children:f?e.jsx("tr",{children:e.jsx("td",{className:"p-6 text-center",colSpan:l.length+(i?1:0),children:e.jsx(S,{className:"h-6 w-6 animate-spin mx-auto text-muted-foreground"})})}):d.length===0?e.jsx("tr",{children:e.jsx("td",{className:"p-4 sm:p-6 text-center text-sm text-muted-foreground",colSpan:l.length+(i?1:0),children:e.jsxs("div",{className:"flex flex-col items-center gap-2 py-4",children:[e.jsx(h,{className:"h-8 w-8 text-muted-foreground/50"}),e.jsx("p",{children:"No users found."}),e.jsx(v,{variant:"secondary",className:"text-xs",children:"plugin-grid powered"})]})})}):d.map(s=>e.jsxs("tr",{className:"border-b hover:bg-muted/50 transition-colors",children:[l.map(c=>e.jsx("td",{className:"h-10 px-3 sm:px-4 whitespace-nowrap",children:String(s[c]??"")},c)),i&&e.jsx("td",{className:"h-10 px-3 sm:px-4 text-right",children:e.jsx(x,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>g(s.id||s._id),children:e.jsx(_,{className:"h-3.5 w-3.5 text-destructive"})})})]},s.id||s._id))})]})})})})]})}export{Q as UserManagementPage};
