(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,19177,e=>{"use strict";var t=e.i(43476),r=e.i(71645),a=e.i(18566),s=e.i(11795);let l=e=>e.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");e.s(["default",0,function({initial:e}){let n=(0,s.createClient)(),d=(0,a.useRouter)(),[i,o]=(0,r.useState)(e),[c,u]=(0,r.useState)(""),[m,g]=(0,r.useState)("#1f9d7a"),[b,x]=(0,r.useState)(null),[p,f]=(0,r.useState)(!1);async function h(e){if(e.preventDefault(),!c.trim())return;f(!0),x(null);let{data:t,error:r}=await n.from("categories").insert({name:c.trim(),slug:l(c),color:m,sort_order:i.length+1}).select().single();(f(!1),r)?x(r.message):(o([...i,t]),u(""),d.refresh())}async function j(e){o(i.filter(t=>t.id!==e));let{error:t}=await n.from("categories").delete().eq("id",e);if(t){x(t.message),o(i);return}d.refresh()}async function N(e,t){o(i.map(r=>r.id===e?{...r,name:t}:r)),await n.from("categories").update({name:t,slug:l(t)}).eq("id",e),d.refresh()}return(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsxs)("div",{className:"grid gap-2",children:[i.map(e=>(0,t.jsxs)("div",{className:"flex items-center gap-3 rounded-lg border border-be-border bg-be-surface p-3",children:[(0,t.jsx)("span",{className:"h-5 w-5 shrink-0 rounded",style:{backgroundColor:e.color},"aria-hidden":!0}),(0,t.jsx)("input",{defaultValue:e.name,onBlur:t=>t.target.value!==e.name&&N(e.id,t.target.value),className:"flex-1 bg-transparent text-sm font-medium outline-none"}),(0,t.jsx)("span",{className:"text-xs text-be-muted",children:e.slug}),(0,t.jsx)("button",{onClick:()=>j(e.id),className:"text-xs font-medium text-red-600 hover:text-red-700",children:"Delete"})]},e.id)),!i.length&&(0,t.jsx)("p",{className:"text-sm text-be-muted",children:"No categories yet."})]}),(0,t.jsxs)("form",{onSubmit:h,className:"rounded-lg border border-be-border bg-be-surface p-4",children:[(0,t.jsx)("p",{className:"text-sm font-medium mb-3",children:"Add category"}),(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("input",{type:"color",value:m,onChange:e=>g(e.target.value),className:"h-9 w-9 cursor-pointer rounded border border-be-border","aria-label":"Category color"}),(0,t.jsx)("input",{value:c,onChange:e=>u(e.target.value),placeholder:"e.g. Gospel",className:"input flex-1"}),(0,t.jsx)("button",{type:"submit",disabled:p,className:"rounded-md bg-brand-green px-4 py-2 text-sm font-medium text-white hover:bg-brand-green-deep disabled:opacity-50",children:"Add"})]}),b&&(0,t.jsx)("p",{className:"mt-2 text-sm text-red-600",children:b})]})]})}])}]);