import{r as j,j as e}from"./react-vendor-MPLM8hiW.js";import{c as k,u as P,d as S}from"./tanstack-vendor-Dk_RmDT8.js";import{a as $,u as q,k as B,P as z,C as g,g as c,m as D,e as E,X as F,aj as M,a7 as y}from"./index-saDuzM6I.js";import{L as O,a$ as T,P as N,ak as Q,f as R,H as C}from"./icons-vendor-H2PpUqT3.js";import{L as h}from"./vendor-CwCtuXvS.js";import"./radix-vendor-aVdTdbL0.js";const _="text-xs text-text-secondary border-border/70 bg-surface-hover/60 dark:bg-surface-active/40";function V(){const v=k(),[m,b]=j.useState("all"),[l,d]=j.useState(null),{t:a}=$(),n=q(s=>s.user),o=(n==null?void 0:n.role)==="super-admin"||(n==null?void 0:n.role)==="admin"||B(n,"admin:schemas:write"),{data:r,isLoading:w}=P({queryKey:["components"],queryFn:()=>y.list()}),x=S({mutationFn:s=>y.delete(s),onSuccess:()=>{v.invalidateQueries({queryKey:["components"]}),d(null)}}),A=()=>{!l||!o||x.mutate(l.uid)};if(w)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(O,{className:"h-8 w-8 animate-spin text-text-secondary"})});const u=(r==null?void 0:r.data)||[],p=(r==null?void 0:r.categories)||[],f=u.filter(s=>m==="all"?!0:s.category===m).reduce((s,i)=>{const t=i.category;return s[t]||(s[t]=[]),s[t].push(i),s},{});return e.jsxs(z,{title:a("components.title"),description:a("components.description"),actions:e.jsxs("div",{className:"flex items-center gap-2",children:[p.length>0&&e.jsx(M,{options:[{value:"all",label:`${a("common.all")} (${u.length})`},...p.map(s=>({value:s,label:`${s} (${u.filter(i=>i.category===s).length})`}))],value:m,onChange:s=>b(s)}),o&&e.jsx(h,{to:"/components/new",children:e.jsxs(c,{children:[e.jsx(C,{className:"h-4 w-4"}),a("components.create")]})})]}),children:[Object.keys(f).length>0?e.jsx("div",{className:"space-y-8",children:Object.entries(f).map(([s,i])=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(T,{className:"h-5 w-5 text-text-secondary"}),e.jsx("h2",{className:"text-lg font-semibold",children:s}),e.jsxs("span",{className:"text-sm text-text-secondary",children:["(",i.length,")"]})]}),e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:i.map(t=>{const L=Object.keys(t.attributes).length;return e.jsxs(g,{variant:"interactive",className:"group p-4 flex flex-col",children:[e.jsxs("div",{className:"flex items-start gap-3 mb-8",children:[e.jsx("div",{className:"w-11 h-11 rounded-lg bg-primary-lighter flex items-center justify-center flex-shrink-0",children:t.info.icon?e.jsx("span",{className:"text-xl",children:t.info.icon}):e.jsx(N,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-semibold truncate",children:t.info.displayName}),e.jsx("p",{className:"text-sm text-text-secondary truncate",children:t.uid})]}),e.jsxs("div",{className:"flex gap-0.5 flex-shrink-0 -mr-1 opacity-100 md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100 transition-opacity",children:[e.jsx(h,{to:`/components/${encodeURIComponent(t.uid)}`,children:e.jsx(c,{variant:"ghost",size:"icon",className:"h-7 w-7","aria-label":a("components.editAction",{name:t.info.displayName}),children:e.jsx(Q,{className:"h-3.5 w-3.5"})})}),o&&e.jsx(c,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>d(t),disabled:x.isPending,"aria-label":a("components.deleteAction",{name:t.info.displayName}),children:e.jsx(R,{className:"h-3.5 w-3.5 text-error"})})]})]}),t.info.description&&e.jsx("p",{className:"text-xs text-text-secondary line-clamp-2 mb-2.5",children:t.info.description}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-auto",children:e.jsx(D,{variant:"outline",className:_,children:a("schemas.fieldsCount",{count:L})})})]},t.uid)})})]},s))}):e.jsx(g,{children:e.jsxs(E,{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(N,{className:"h-12 w-12 text-text-secondary/50 mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:a("components.noComponents")}),e.jsx("p",{className:"text-text-secondary text-center mb-4",children:a("components.createFirst")}),o&&e.jsx(h,{to:"/components/new",children:e.jsxs(c,{children:[e.jsx(C,{className:"h-4 w-4"}),a("components.create")]})})]})}),e.jsx(F,{open:!!l,onClose:()=>d(null),onConfirm:A,title:a("components.deleteConfirmTitle"),description:a("components.deleteConfirm",{name:(l==null?void 0:l.info.displayName)??""}),variant:"danger",confirmLabel:a("common.delete"),cancelLabel:a("common.cancel"),loading:x.isPending})]})}export{V as ComponentListPage};
