1import{cV as D,u as C,r as a,j as e,aR as w,cW as F}from"./main-Bo0oayNO.js";import"./TinyMCELazy-B_0yg9nx.js";import{M}from"./MediaLibraryModal-DkZ63GDK.js";function A(t){const n=typeof t=="string"?new Date(t):t,r=n.getFullYear(),d=String(n.getMonth()+1).padStart(2,"0"),i=String(n.getDate()).padStart(2,"0");return`${r}-${d}-${i}`}function T(){const{note:t}=D.useLoaderData(),n=C(),[r,d]=a.useState(t.title),[i,N]=a.useState(t.content),[c,m]=a.useState(t.imageUrl),[u,y]=a.useState(A(t.publishedAt)),[v,l]=a.useState(!1),[x,h]=a.useState(!1),[b,p]=a.useState(!1),[g,o]=a.useState(""),[f,j]=a.useState(""),S=async s=>{if(s.preventDefault(),!r.trim()||!i.trim()){o("Title and content are required.");return}h(!0),o(""),j("");try{await F({data:{id:t.id,title:r.trim(),content:i.trim(),imageUrl:c,publishedAt:u}}),j("Note updated.")}catch{o("Failed to update note.")}finally{h(!1)}},k=async()=>{if(confirm("Delete this note? This cannot be undone.")){p(!0);try{await w({data:t.id}),n({to:"/admin/jeffs-desk",search:{page:1}})}catch{o("Failed to delete note."),p(!1)}}};return e.jsxs("div",{className:"max-w-2xl",children:[e.jsxs("div",{className:"mb-6 flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Edit Note"}),e.jsx("p",{className:"text-gray-600",children:"Update or remove this note"})]}),e.jsx("button",{onClick:k,disabled:b,className:"btn-danger",children:b?"Deleting...":"Delete Note"})]}),g&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg text-red-700",children:g}),f&&e.jsx("div",{className:"mb-6 p-4 bg-green-50 border border-green-200 rounded-lg text-green-700",children:f}),e.jsxs("form",{onSubmit:S,className:"card p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"publishedAt",className:"block text-sm font-medium text-gray-700 mb-1",children:"Date"}),e.jsx("input",{id:"publishedAt",type:"date",value:u,onChange:s=>y(s.target.value),className:"input w-auto",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"title",className:"block text-sm font-medium text-gray-700 mb-1",children:"Title *"}),e.jsx("input",{id:"title",type:"text",value:r,onChange:s=>d(s.target.value),className:"input",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"content",className:"block text-sm font-medium text-gray-700 mb-1",children:"Content *"}),e.jsx("textarea",{id:"content",value:i,onChange:s=>N(s.target.value),rows:6,className:"input",required:!0}),e.jsx("p",{className:"mt-1 text-sm text-gray-500",children:"Line breaks are preserved when displayed."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Image (optional)"}),c?e.jsxs("div",{className:"space-y-2",children:[e.jsx("img",{src:c,alt:"",className:"max-w-xs rounded-sm border border-gray-200"}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{type:"button",onClick:()=>l(!0),className:"text-sm text-primary-600 hover:underline",children:"Replace image"}),e.jsx("button",{type:"button",onClick:()=>m(null),className:"text-sm text-red-600 hover:underline",children:"Remove image"})]})]}):e.jsx("button",{type:"button",onClick:()=>l(!0),className:"btn-secondary",children:"Choose image"}),v&&e.jsx(M,{onSelect:s=>{m(s),l(!1)},onClose:()=>l(!1)})]}),e.jsxs("div",{className:"flex gap-4 pt-4 border-t",children:[e.jsx("button",{type:"submit",disabled:x,className:"btn-primary",children:x?"Saving...":"Update Note"}),e.jsx("button",{type:"button",onClick:()=>n({to:"/admin/jeffs-desk",search:{page:1}}),className:"btn-secondary",children:"Back to List"})]})]})]})}export{T 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.