1import{r as x,j as e,B as p,a5 as k,Y as E,av as d,aw as N,Z as C,X as L,a_ as y,u as P,w as S,I as u}from"./index-ncH4CRZS.js";import{P as B}from"./PageActionBar-D-zJVYPa.js";import{z as n,u as I,t as U}from"./index-Z79-0VeN.js";import{T as _}from"./textarea-LTZgJtsi.js";import{F as A}from"./FormSection-BKcwndiA.js";import{F as z}from"./FormPageLayout-BgGdJxbi.js";import{c as K,d as V}from"./useDocuments-V65aHQWD.js";const q=n.object({title:n.string().min(1,"Title is required"),description:n.string().optional(),tags:n.array(n.string()).optional()}),J=({document:t,onSuccess:i,onCancel:r})=>{const[a,m]=x.useState(t.tags||[]),[l,g]=x.useState(""),{mutate:b,isPending:h}=K(),{register:j,handleSubmit:F,formState:{errors:f},setValue:c}=I({resolver:U(q),defaultValues:{title:t.title,description:t.description||"",tags:t.tags||[]}});x.useEffect(()=>{m(t.tags||[]),c("tags",t.tags||[])},[t,c]);const v=()=>{if(l.trim()&&!a.includes(l.trim())){const s=[...a,l.trim()];m(s),c("tags",s),g("")}},D=s=>{const o=a.filter(w=>w!==s);m(o),c("tags",o)},T=async s=>{b({id:t.id,title:s.title,description:s.description,tags:s.tags},{onSuccess:()=>{y.success("Document updated successfully"),i==null||i()},onError:o=>{console.error("Error updating document:",o),y.error("Failed to update document")}})};return e.jsxs("div",{className:"space-y-6",children:[e.jsx("h2",{className:"text-3xl font-semibold text-brand-dark-blue",children:"Edit Document"}),e.jsx("form",{onSubmit:F(T),children:e.jsx(z,{actions:e.jsxs(e.Fragment,{children:[e.jsx(p,{variant:"outline",type:"button",onClick:r,children:"Cancel"}),e.jsx(p,{variant:"orange",type:"submit",disabled:h,children:h?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),"Updating..."]}):"Update Document"})]}),children:e.jsxs(A,{title:"Document",icon:E,children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"title",children:"Title"}),e.jsx(N,{id:"title",...j("title"),placeholder:"Enter document title"}),f.title&&e.jsx("p",{className:"text-sm text-destructive",children:f.title.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{children:"Current File"}),e.jsxs("div",{className:"p-3 bg-muted rounded-lg",children:[e.jsx("p",{className:"text-sm font-medium",children:t.file_name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[(t.file_size/1024).toFixed(1)," KB ⢠",t.file_type]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"File cannot be changed. Upload a new document to replace this one."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"description",children:"Description"}),e.jsx(_,{id:"description",...j("description"),placeholder:"Enter document description (optional)",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{children:"Tags"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(N,{value:l,onChange:s=>g(s.target.value),placeholder:"Add a tag",onKeyPress:s=>{s.key==="Enter"&&(s.preventDefault(),v())}}),e.jsx(p,{type:"button",onClick:v,variant:"outline",children:"Add"})]}),a.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:a.map(s=>e.jsxs(C,{variant:"secondary",className:"flex items-center gap-1",children:[s,e.jsx(L,{className:"h-3 w-3 cursor-pointer hover:text-destructive",onClick:()=>D(s)})]},s))})]})]})})})]})},O=()=>{const{id:t}=P(),i=S(),{data:r,isLoading:a}=V(t);return a?e.jsx(u,{children:e.jsx("div",{className:"max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:e.jsx("div",{className:"text-center",children:"Loading document..."})})}):r?e.jsxs(u,{children:[e.jsx(B,{backTo:"/documents-links",backLabel:"Documents & Links"}),e.jsx("div",{className:"max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:e.jsx(J,{document:r,onSuccess:()=>i("/documents-links"),onCancel:()=>i("/documents-links")})})]}):e.jsx(u,{children:e.jsx("div",{className:"max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:e.jsx("div",{className:"text-center",children:"Document not found"})})})};export{O as default};
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.