1import{f as b,r as U,l as w,m as S,e as c,j as e,B as h,k as L,L as T,c as I,g as A}from"./index-BmBL1DE3.js";import{u as k}from"./useMutation-g741X-gg.js";import{t as n}from"./index-Bdh9GbUD.js";import{A as E}from"./AdminLayout-DlGmnOt6.js";import{I as B}from"./input-Bi5fa4uZ.js";import{C as x,b as p,a as M,c as Q}from"./card-CsVXTXhb.js";import{B as m}from"./badge-DRM7RRJz.js";import{d as R,T as _,a as o,e as l,b as q,c as t}from"./table-y-2qhrvE.js";import{S as F,a as H,b as K,c as V,d as j}from"./select-BaRCnja6.js";import{u as $}from"./useConfirmDialog-CCfC5GFF.js";import{S as z}from"./search-_ini6S0t.js";import{U as D}from"./upload-DUGpmUYE.js";import"./popover-DgQUpQaN.js";import"./index-BJhajFrD.js";import"./proxy-DeN1UoZf.js";import"./bell-BXDyRmdQ.js";import"./trash-2-DtvWxl3o.js";import"./circle-check-C6H94GUj.js";import"./triangle-alert-D7S2pcCu.js";import"./circle-x-xAGDVJqB.js";import"./ticket-DSHsf-rg.js";import"./message-square-BP_-ysRO.js";import"./user-cog-D2zjtRyu.js";import"./bus-hd_Pj0K9.js";import"./format-DM3O-sLJ.js";import"./index-BdQq_4o_.js";import"./index-E9NfRJGk.js";import"./index-B1whbNJD.js";/** 2 * @license lucide-react v0.475.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const P=[["path",{d:"M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z",key:"1vdc57"}],["path",{d:"M5 21h14",key:"11awu3"}]],G=b("Crown",P);function Ce(){const{confirm:f,ConfirmDialog:g}=$(),[i,y]=U.useState(""),d=w(),{data:N=[],isLoading:v}=S({queryKey:["all-users"],queryFn:async()=>{try{return await c.asServiceRole.entities.User.list()}catch(s){return console.error("Error fetching users:",s),[]}}}),C=k({mutationFn:async({userId:s,role:r})=>await c.functions.invoke("updateUserRole",{userId:s,role:r}),onSuccess:()=>{d.invalidateQueries({queryKey:["all-users"]}),n.success("User role updated")},onError:s=>{var r,a;n.error("Failed to update role: "+(((a=(r=s==null?void 0:s.response)==null?void 0:r.data)==null?void 0:a.error)||(s==null?void 0:s.message)||"Unauthorized"))}}),u=N.filter(s=>{var r,a;return i===""||((r=s.email)==null?void 0:r.toLowerCase().includes(i.toLowerCase()))||((a=s.full_name)==null?void 0:a.toLowerCase().includes(i.toLowerCase()))});return e.jsxs(E,{title:"User Management",currentPage:"AdminUsers",children:[e.jsx(x,{className:"mb-6",children:e.jsx(p,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(z,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx(B,{placeholder:"Search by name or email...",className:"pl-10",value:i,onChange:s=>y(s.target.value)})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(h,{onClick:()=>{const s=prompt("Enter user email:"),r=s?prompt("Enter user full name:"):null;s&&r&&c.users.inviteUser(s,"user").then(()=>{n.success(`Invitation sent to ${s}`),d.invalidateQueries({queryKey:["all-users"]})}).catch(a=>n.error("Failed to invite user: "+a.message))},className:"bg-blue-600 hover:bg-blue-700",children:[e.jsx(L,{className:"w-4 h-4 mr-2"}),"Invite User"]}),e.jsx(T,{to:I("AdminUserImport"),children:e.jsxs(h,{className:"bg-emerald-600 hover:bg-emerald-700",children:[e.jsx(D,{className:"w-4 h-4 mr-2"}),"Bulk Import CSV"]})})]})]})})}),e.jsxs(x,{children:[e.jsx(M,{children:e.jsx(Q,{children:"All Users"})}),e.jsx(p,{className:"p-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(R,{children:[e.jsx(_,{children:e.jsxs(o,{children:[e.jsx(l,{children:"Name"}),e.jsx(l,{children:"Email"}),e.jsx(l,{children:"Current Role"}),e.jsx(l,{children:"User Type"}),e.jsx(l,{children:"Change Role"})]})}),e.jsx(q,{children:v?e.jsx(o,{children:e.jsx(t,{colSpan:"5",className:"text-center py-12",children:"Loading users..."})}):u.length===0?e.jsx(o,{children:e.jsx(t,{colSpan:"5",className:"text-center py-12 text-gray-500",children:"No users found"})}):u.map(s=>e.jsxs(o,{children:[e.jsx(t,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 bg-emerald-100 rounded-full flex items-center justify-center",children:e.jsx(A,{className:"w-4 h-4 text-emerald-600"})}),e.jsx("span",{className:"font-medium",children:s.full_name||"No Name"})]})}),e.jsx(t,{children:s.email}),e.jsx(t,{children:s.role==="admin"?e.jsxs(m,{className:"bg-purple-100 text-purple-700",children:[e.jsx(G,{className:"w-3 h-3 mr-1"}),"Admin"]}):e.jsx(m,{variant:"outline",children:"User"})}),e.jsx(t,{children:e.jsx(m,{variant:"secondary",children:s.user_type||"customer"})}),e.jsx(t,{children:e.jsxs(F,{value:s.role||"user",onValueChange:async r=>{await f(`Change ${s.full_name||s.email} to ${r}?`)&&C.mutate({userId:s.id,role:r})},children:[e.jsx(H,{className:"w-32",children:e.jsx(K,{})}),e.jsxs(V,{children:[e.jsx(j,{value:"user",children:"User"}),e.jsx(j,{value:"admin",children:"Admin"})]})]})})]},s.id))})]})})})]}),g]})}export{Ce as default};
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.