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

//# sourceMappingURL=src_app_admin_categories_category-manager_tsx_15j2efl._.js.map