1import{c as U,r as i,j as e,am as o,aA as B,Q as w,R as z,J as x,at as h,au as f,U as H,K as u,aG as k,I as E,ax as j}from"./index-A3FuQDYt.js";import{u as F}from"./useAdminAuth-Clekj91V.js";import{A as D}from"./AdminShell-DgkNfpuj.js";import{L as v}from"./loader-circle-CBfn6mAQ.js";import"./gauge-BMhIb7vc.js";import"./activity-BfSXTgiG.js";/** 2 * @license lucide-react v0.462.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 S=U("ShieldOff",[["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71",key:"1jlk70"}],["path",{d:"M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264",key:"18rp1v"}]]),_=i.forwardRef(({className:t,...a},r)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:r,className:o("w-full caption-bottom text-sm",t),...a})}));_.displayName="Table";const L=i.forwardRef(({className:t,...a},r)=>e.jsx("thead",{ref:r,className:o("[&_tr]:border-b",t),...a}));L.displayName="TableHeader";const $=i.forwardRef(({className:t,...a},r)=>e.jsx("tbody",{ref:r,className:o("[&_tr:last-child]:border-0",t),...a}));$.displayName="TableBody";const M=i.forwardRef(({className:t,...a},r)=>e.jsx("tfoot",{ref:r,className:o("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",t),...a}));M.displayName="TableFooter";const y=i.forwardRef(({className:t,...a},r)=>e.jsx("tr",{ref:r,className:o("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",t),...a}));y.displayName="TableRow";const l=i.forwardRef(({className:t,...a},r)=>e.jsx("th",{ref:r,className:o("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",t),...a}));l.displayName="TableHead";const c=i.forwardRef(({className:t,...a},r)=>e.jsx("td",{ref:r,className:o("p-4 align-middle [&:has([role=checkbox])]:pr-0",t),...a}));c.displayName="TableCell";const I=i.forwardRef(({className:t,...a},r)=>e.jsx("caption",{ref:r,className:o("mt-4 text-sm text-muted-foreground",t),...a}));I.displayName="TableCaption";function P(){F();const{toast:t}=B(),[a,r]=i.useState([]),[g,R]=i.useState(!0),[m,T]=i.useState(null),p=async()=>{R(!0);try{const{data:{session:s}}=await j.auth.getSession();if(!(s!=null&&s.access_token))throw new Error("No session");const d=await j.functions.invoke("list-users",{headers:{Authorization:`Bearer ${s.access_token}`}});if(d.error)throw new Error(d.error.message);r(d.data.users||[])}catch(s){console.error("Error fetching users:",s),t({title:"Erro ao carregar usuários",description:s.message,variant:"destructive"})}finally{R(!1)}};i.useEffect(()=>{p()},[]);const C=async(s,d,N)=>{T(`${s}-${N}`);try{const{data:{session:n}}=await j.auth.getSession();if(!(n!=null&&n.access_token))throw new Error("No session");const b=await j.functions.invoke("manage-user-role",{headers:{Authorization:`Bearer ${n.access_token}`},body:{user_id:s,role:d,action:N}});if(b.error)throw new Error(b.error.message);t({title:N==="add"?"Role adicionada":"Role removida",description:b.data.message}),await p()}catch(n){console.error("Error managing role:",n),t({title:"Erro ao gerenciar role",description:n.message,variant:"destructive"})}finally{T(null)}},A=s=>s?new Date(s).toLocaleDateString("pt-BR",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}):"Nunca";return e.jsx(D,{title:"Usuários e acessos",description:"Quem pode entrar no CMS e quem tem permissão de administrador.",actions:e.jsxs(w,{variant:"outline",size:"sm",onClick:p,disabled:g,children:[e.jsx(z,{className:`h-4 w-4 mr-2 ${g?"animate-spin":""}`}),"Atualizar"]}),children:e.jsxs("div",{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-8",children:[e.jsxs(x,{children:[e.jsxs(h,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(f,{className:"text-sm font-medium text-muted-foreground",children:"Total de Usuários"}),e.jsx(H,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(u,{children:e.jsx("div",{className:"text-2xl font-bold",children:a.length})})]}),e.jsxs(x,{children:[e.jsxs(h,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(f,{className:"text-sm font-medium text-muted-foreground",children:"Administradores"}),e.jsx(k,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(u,{children:e.jsx("div",{className:"text-2xl font-bold",children:a.filter(s=>s.roles.includes("admin")).length})})]}),e.jsxs(x,{children:[e.jsxs(h,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(f,{className:"text-sm font-medium text-muted-foreground",children:"Sem Roles"}),e.jsx(S,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(u,{children:e.jsx("div",{className:"text-2xl font-bold",children:a.filter(s=>s.roles.length===0).length})})]})]}),e.jsxs(x,{children:[e.jsx(h,{children:e.jsx(f,{children:"Usuários Cadastrados"})}),e.jsx(u,{children:g?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(v,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):a.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"Nenhum usuário cadastrado."}):e.jsxs(_,{children:[e.jsx(L,{children:e.jsxs(y,{children:[e.jsx(l,{children:"Email"}),e.jsx(l,{children:"Roles"}),e.jsx(l,{children:"Cadastro"}),e.jsx(l,{children:"Ãltimo Login"}),e.jsx(l,{className:"text-right",children:"Ações"})]})}),e.jsx($,{children:a.map(s=>e.jsxs(y,{children:[e.jsx(c,{className:"font-medium",children:s.email}),e.jsx(c,{children:e.jsx("div",{className:"flex gap-1 flex-wrap",children:s.roles.length===0?e.jsx(E,{variant:"outline",className:"text-muted-foreground",children:"Sem roles"}):s.roles.map(d=>e.jsx(E,{variant:d==="admin"?"default":"secondary",children:d},d))})}),e.jsx(c,{children:A(s.created_at)}),e.jsx(c,{children:A(s.last_sign_in_at)}),e.jsx(c,{className:"text-right",children:e.jsx("div",{className:"flex gap-2 justify-end",children:s.roles.includes("admin")?e.jsx(w,{size:"sm",variant:"destructive",onClick:()=>C(s.id,"admin","remove"),disabled:m===`${s.id}-remove`,children:m===`${s.id}-remove`?e.jsx(v,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(S,{className:"h-4 w-4 mr-1"}),"Remover Admin"]})}):e.jsx(w,{size:"sm",variant:"default",onClick:()=>C(s.id,"admin","add"),disabled:m===`${s.id}-add`,children:m===`${s.id}-add`?e.jsx(v,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"h-4 w-4 mr-1"}),"Tornar Admin"]})})})})]},s.id))})]})})]})]})})}export{P 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.