1import{cS as D,u as I,r,j as e,aP as E,cT as T}from"./main-Bo0oayNO.js";function K(){const{article:s,categories:f}=D.useLoaderData(),o=I(),[l,v]=r.useState(s.title),[n,j]=r.useState(s.slug),[d,N]=r.useState(s.content),[i,S]=r.useState(s.categoryId),[c,w]=r.useState(s.status),[u,C]=r.useState(s.sortOrder),[g,x]=r.useState(!1),[m,b]=r.useState(!1),[y,a]=r.useState(""),[p,h]=r.useState(""),k=async t=>{if(t.preventDefault(),!l.trim()||!d.trim()||!i){a("Title, content, and category are required.");return}x(!0),a(""),h("");try{await T({data:{id:s.id,title:l,slug:n,content:d,categoryId:i,status:c,sortOrder:u}}),h("Article updated successfully.")}catch{a("Failed to update article.")}finally{x(!1)}},A=async()=>{if(confirm("Are you sure you want to delete this article?")){b(!0);try{await E({data:s.id}),o({to:"/admin/kb"})}catch{a("Failed to delete article."),b(!1)}}};return e.jsxs("div",{className:"max-w-4xl space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-100",children:"Edit KB Article"}),e.jsx("button",{onClick:A,disabled:m,className:"px-3 py-1.5 text-sm text-red-400 hover:text-red-300 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:m?"Deleting...":"Delete Article"})]}),y&&e.jsx("div",{className:"p-3 bg-red-500/10 border border-red-500/20 rounded-lg text-red-400 text-sm",children:y}),p&&e.jsx("div",{className:"p-3 bg-green-500/10 border border-green-500/20 rounded-lg text-green-400 text-sm",children:p}),e.jsxs("form",{onSubmit:k,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-1",children:"Title"}),e.jsx("input",{type:"text",value:l,onChange:t=>v(t.target.value),className:"w-full px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-gray-200 text-sm focus:ring-1 focus:ring-primary-500 focus:border-primary-500",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-1",children:"Slug"}),e.jsx("input",{type:"text",value:n,onChange:t=>j(t.target.value),className:"w-full px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-gray-200 text-sm focus:ring-1 focus:ring-primary-500 focus:border-primary-500"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-1",children:"Category"}),e.jsx("select",{value:i,onChange:t=>S(t.target.value),className:"w-full px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-gray-200 text-sm",required:!0,children:f.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-1",children:"Status"}),e.jsxs("select",{value:c,onChange:t=>w(t.target.value),className:"w-full px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-gray-200 text-sm",children:[e.jsx("option",{value:"published",children:"Published"}),e.jsx("option",{value:"draft",children:"Draft"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-1",children:"Sort Order"}),e.jsx("input",{type:"number",value:u,onChange:t=>C(parseInt(t.target.value)||0),className:"w-24 px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-gray-200 text-sm focus:ring-1 focus:ring-primary-500 focus:border-primary-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-1",children:"Content (HTML)"}),e.jsx("textarea",{value:d,onChange:t=>N(t.target.value),rows:12,className:"w-full px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-gray-200 text-sm font-mono focus:ring-1 focus:ring-primary-500 focus:border-primary-500",required:!0})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{type:"submit",disabled:g,className:"px-4 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 transition-colors text-sm font-medium disabled:opacity-50",children:g?"Saving...":"Update Article"}),e.jsx("button",{type:"button",onClick:()=>o({to:"/admin/kb"}),className:"px-4 py-2 bg-gray-700 text-gray-300 rounded-lg hover:bg-gray-600 text-sm",children:"Back to List"})]})]})]})}export{K 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.