1import{A as P,u as T,r,j as e,B as U,C as $,D as z}from"./main-Bo0oayNO.js";import{s as k}from"./index-ThM9GGfP.js";function J(){const{categories:x}=P.useLoaderData(),l=T(),[d,g]=r.useState(""),[p,n]=r.useState(""),[u,m]=r.useState(""),[y,h]=r.useState(0),[b,N]=r.useState(!1),[i,o]=r.useState(null),[c,j]=r.useState(""),[v,f]=r.useState(""),[I,F]=r.useState(""),[S,C]=r.useState(0),[w,D]=r.useState(!1),[A,E]=r.useState(null),[O,s]=r.useState(""),K=async t=>{if(t.preventDefault(),!!d.trim()){N(!0),s("");try{await U({data:{name:d,slug:p||k(d),description:u||void 0,sortOrder:y}}),g(""),n(""),m(""),h(0),l({to:"/admin/kb-categories",reloadDocument:!0})}catch{s("Failed to create category.")}finally{N(!1)}}},B=t=>{o(t.id),j(t.name),f(t.slug),F(t.description||""),C(t.sortOrder)},R=async()=>{if(!(!i||!c.trim())){D(!0),s("");try{await $({data:{id:i,name:c,slug:v,description:I||void 0,sortOrder:S}}),o(null),l({to:"/admin/kb-categories",reloadDocument:!0})}catch{s("Failed to update category.")}finally{D(!1)}}},q=async(t,a)=>{const L=a>0?`This category has ${a} article(s). Deleting it will also delete all its articles. Continue?`:"Are you sure you want to delete this category?";if(confirm(L)){E(t);try{await z({data:t}),l({to:"/admin/kb-categories",reloadDocument:!0})}catch{s("Failed to delete category.")}finally{E(null)}}};return e.jsxs("div",{className:"space-y-6",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-100",children:"KB Categories"}),O&&e.jsx("div",{className:"p-3 bg-red-500/10 border border-red-500/20 rounded-lg text-red-400 text-sm",children:O}),e.jsxs("form",{onSubmit:K,className:"bg-gray-900 rounded-lg border border-gray-800 p-4 space-y-3",children:[e.jsx("h2",{className:"text-sm font-medium text-gray-300",children:"Add New Category"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx("input",{type:"text",value:d,onChange:t=>{g(t.target.value),n(k(t.target.value))},placeholder:"Name",className:"px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-gray-200 text-sm placeholder-gray-500",required:!0}),e.jsx("input",{type:"text",value:p,onChange:t=>n(t.target.value),placeholder:"Slug",className:"px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-gray-200 text-sm placeholder-gray-500"})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[e.jsx("input",{type:"text",value:u,onChange:t=>m(t.target.value),placeholder:"Description (optional)",className:"col-span-3 px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-gray-200 text-sm placeholder-gray-500"}),e.jsx("input",{type:"number",value:y,onChange:t=>h(parseInt(t.target.value)||0),placeholder:"Order",className:"px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-gray-200 text-sm"})]}),e.jsx("button",{type:"submit",disabled:b,className:"px-4 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 text-sm font-medium disabled:opacity-50",children:b?"Adding...":"Add Category"})]}),e.jsx("div",{className:"bg-gray-900 rounded-lg border border-gray-800 overflow-hidden",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-800",children:[e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase",children:"Name"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase",children:"Slug"}),e.jsx("th",{className:"px-4 py-3 text-center text-xs font-medium text-gray-400 uppercase",children:"Order"}),e.jsx("th",{className:"px-4 py-3 text-center text-xs font-medium text-gray-400 uppercase",children:"Articles"}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-400 uppercase",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-800",children:x.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-4 py-8 text-center text-gray-500",children:"No categories yet."})}):x.map(t=>e.jsx("tr",{className:"hover:bg-gray-800/50",children:i===t.id?e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-4 py-2",children:e.jsx("input",{type:"text",value:c,onChange:a=>j(a.target.value),className:"w-full px-2 py-1 bg-gray-800 border border-gray-600 rounded-sm text-gray-200 text-sm"})}),e.jsx("td",{className:"px-4 py-2",children:e.jsx("input",{type:"text",value:v,onCh
1ange:a=>f(a.target.value),className:"w-full px-2 py-1 bg-gray-800 border border-gray-600 rounded-sm text-gray-200 text-sm"})}),e.jsx("td",{className:"px-4 py-2 text-center",children:e.jsx("input",{type:"number",value:S,onChange:a=>C(parseInt(a.target.value)||0),className:"w-16 px-2 py-1 bg-gray-800 border border-gray-600 rounded-sm text-gray-200 text-sm text-center"})}),e.jsx("td",{className:"px-4 py-2 text-center text-sm text-gray-400",children:t.articleCount}),e.jsx("td",{className:"px-4 py-2 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:R,disabled:w,className:"text-xs text-green-400 hover:text-green-300",children:w?"Saving...":"Save"}),e.jsx("button",{onClick:()=>o(null),className:"text-xs text-gray-400 hover:text-gray-300",children:"Cancel"})]})})]}):e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-4 py-3 text-sm font-medium text-gray-200",children:t.name}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-400",children:t.slug}),e.jsx("td",{className:"px-4 py-3 text-center text-sm text-gray-400",children:t.sortOrder}),e.jsx("td",{className:"px-4 py-3 text-center text-sm text-gray-400",children:t.articleCount}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>B(t),className:"text-xs text-primary-400 hover:text-primary-300",children:"Edit"}),e.jsx("button",{onClick:()=>q(t.id,t.articleCount),disabled:A===t.id,className:"text-xs text-red-400 hover:text-red-300 disabled:opacity-50",children:A===t.id?"...":"Delete"})]})})]})},t.id))})]})})]})}export{J as component};
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.