import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{a as t,o as n}from"./vendor-motion-COLzAB1Q.js";import{t as r}from"./grip-vertical-DYCE5TeG.js";import{t as i}from"./plus-CW2Xtdxx.js";import{t as a}from"./trash-2-BXiM8AOS.js";import{_ as o,c as s,r as c}from"./index-DLFWvoW-.js";import{t as l}from"./input-CQYqSHmc.js";import{t as u}from"./activity-log-BcZldPH3.js";var d=e(n(),1),f=t(),p=()=>{let[e,t]=(0,d.useState)([]),[n,p]=(0,d.useState)(!0),[m,h]=(0,d.useState)(``),g=async()=>{p(!0);let{data:e,error:n}=await s.from(`categories`).select(`*`).order(`sort_order`);n?o.error(`Failed to load categories`):t(e||[]),p(!1)};(0,d.useEffect)(()=>{g()},[]);let _=async()=>{if(!m.trim())return;let t=m.toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``),{error:n}=await s.from(`categories`).insert({name:m.trim(),slug:t,sort_order:e.length});n?o.error(n.message.includes(`duplicate`)?`Category already exists`:`Failed to add`):(o.success(`Category added`),u(`category_created`,{name:m.trim()}),h(``),g())},v=async(e,n)=>{if(!confirm(`Delete category "${n}"?`))return;let{error:r}=await s.from(`categories`).delete().eq(`id`,e);r?o.error(`Failed to delete`):(o.success(`Deleted`),u(`category_deleted`,{name:n}),t(t=>t.filter(t=>t.id!==e)))};return n?(0,f.jsx)(`div`,{className:`text-muted-foreground py-20 text-center`,children:`Loading...`}):(0,f.jsxs)(`div`,{className:`space-y-6`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`h1`,{className:`text-2xl font-bold text-foreground`,children:`Categories`}),(0,f.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage project categories`})]}),(0,f.jsxs)(`div`,{className:`flex gap-3 max-w-md`,children:[(0,f.jsx)(l,{placeholder:`New category name`,value:m,onChange:e=>h(e.target.value),onKeyDown:e=>e.key===`Enter`&&_()}),(0,f.jsxs)(c,{onClick:_,size:`sm`,children:[(0,f.jsx)(i,{className:`h-4 w-4 mr-1`}),` Add`]})]}),(0,f.jsx)(`div`,{className:`rounded-xl border border-border bg-card divide-y divide-border max-w-lg`,children:e.length===0?(0,f.jsx)(`div`,{className:`p-8 text-center text-muted-foreground`,children:`No categories`}):e.map(e=>(0,f.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 group`,children:[(0,f.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,f.jsx)(r,{className:`h-4 w-4 text-muted-foreground/40`}),(0,f.jsx)(`span`,{className:`text-sm text-foreground font-medium`,children:e.name}),(0,f.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`/`,e.slug]})]}),(0,f.jsx)(c,{variant:`ghost`,size:`icon`,className:`h-7 w-7 opacity-0 group-hover:opacity-100 text-destructive`,onClick:()=>v(e.id,e.name),children:(0,f.jsx)(a,{className:`h-3.5 w-3.5`})})]},e.id))})]})};export{p as default};