1import{f as D,g as M,r as n,c as Y,h as C,j as e,m as b,L as z,B as c,X as y}from"./index-DaVPQP0x.js";import{I as d}from"./input-WdUx6-3x.js";import{T as I}from"./textarea-CnxJG0Yo.js";import{A as Q}from"./arrow-left-CTaEgLQE.js";import{S as q}from"./search-CLs4IQrT.js";import{L as j}from"./loader-circle-DxAvfFXT.js";import{C as F}from"./check-FpSFvFq_.js";import{P as B}from"./pencil-Dgbt9TrT.js";import{T as K}from"./trash-2-DYrQxw0J.js";import{f as W}from"./format-U4cbpK5f.js";function ee(){const{toast:m}=D(),N=M(),E=new Date().getFullYear(),[h,P]=n.useState(E),[l,S]=n.useState(""),[x,u]=n.useState(null),[i,r]=n.useState({}),[L,g]=n.useState(null),{data:o=[],isLoading:v}=Y({queryKey:["/api/guestbook"]}),p=C({mutationFn:async({id:t,data:s})=>{const a=await fetch(`/api/guestbook/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!a.ok)throw new Error("Failed to update");return a.json()},onSuccess:()=>{N.invalidateQueries({queryKey:["/api/guestbook"]}),u(null),m({title:"Entry updated"})},onError:()=>{m({title:"Failed to update entry",variant:"destructive"})}}),w=C({mutationFn:async t=>{const s=await fetch(`/api/guestbook/${t}`,{method:"DELETE"});if(!s.ok)throw new Error("Failed to delete");return s.json()},onSuccess:()=>{N.invalidateQueries({queryKey:["/api/guestbook"]}),g(null),m({title:"Entry deleted"})},onError:()=>{m({title:"Failed to delete entry",variant:"destructive"})}}),k=n.useMemo(()=>{const t=new Set;return o.forEach(s=>{const a=new Date(s.submittedAt).getFullYear();isNaN(a)||t.add(a)}),Array.from(t).sort((s,a)=>a-s)},[o]),f=n.useMemo(()=>
1{let t=o;if(l.trim()){const s=l.toLowerCase();t=o.filter(a=>a.name.toLowerCase().includes(s)||a.whereFrom.toLowerCase().includes(s)||a.reflections&&a.reflections.toLowerCase().includes(s)||a.email&&a.email.toLowerCase().includes(s)||a.homePage&&a.homePage.toLowerCase().includes(s))}else t=o.filter(s=>new Date(s.submittedAt).getFullYear()===h);return[...t].sort((s,a)=>new Date(a.submittedAt).getTime()-new Date(s.submittedAt).getTime())},[o,h,l]),T=t=>{u(t.id),r({name:t.name,email:t.email,whereFrom:t.whereFrom,homePage:t.homePage,reflections:t.reflections})},$=()=>{x&&p.mutate({id:x,data:i})},A=n.useMemo(()=>{const t={};return o.forEach(s=>{const a=new Date(s.submittedAt).getFullYear();isNaN(a)||(t[a]=(t[a]||0)+1)}),t},[o]);return e.jsx("div",{className:"min-h-screen bg-background p-4 md:p-8",children:e.jsxs("div",{className:"max-w-6xl mx-auto space-y-6",children:[e.jsxs(b.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},children:[e.jsxs(z,{href:"/backstage",className:"inline-flex items-center gap-1 text-white/50 hover:text-white text-sm font-mono mb-4 transition-colors","data-testid":"link-back-admin",children:[e.jsx(Q,{className:"w-4 h-4"})," Back to Home"]}),e.jsx("h1",{className:"text-3xl md:text-4xl font-display mb-2","data-testid":"text-page-title",style:{background:"linear-gradient(90deg, #ccff00, #00ffff)",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent"},children:"Guestbook Manager"}),e.jsxs("p",{className:"text-white/50 font-mono text-sm",children:[o.length," total entries · ",f.length," shown"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(q,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-white/40"}),e.jsx(d,{value:l,onChange:t=>S(t.target.value),placeholder:"Search by name, location, reflection...",className:"pl-10 bg-black/30 border-white/20 text-white placeholder:text-white/30","data-testid":"input-guestbook-search"})]}),!l.trim()&&e.jsx(b.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.2},className:"flex flex-wrap gap-1.5",children:v?e.jsx("p",{className:"text-white/40 font-mono text-sm",children:"Loading..."}):k.length===0?e.jsx("p",{className:"text-white/40 font-mono text-sm",children:"No entries yet"}):k.map(t=>e.jsxs("button",{onClick:()=>P(t),"data-testid":`nav-year-${t}`,className:`px-3 py-1.5 rounded font-mono text-sm font-bold transition-all duration-200 ${h===t?"bg-accent text-black shadow-[0_0_12px_rgba(0,255,255,0.4)]":"bg-white/5 text-white/60 hover:bg-white/10 hover:text-white"}`,children:[t,e.jsxs("span",{className:"ml-1 text-xs opacity-60",children:["(",A[t]||0,")"]})]},t))}),e.jsx("div",{className:"space-y-3",children:v?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(j,{className:"w-8 h-8 text-primary animate-spin"})}):f.length===0?e.jsx("div",{className:"text-center py-20 text-white/40 font-mono",children:l?"No entries match your search":"No entries for this year"}):f.map(t=>e.jsx(b.div,{layout:!0,initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"bg-black/20 border border-white/10 rounded-lg p-4 hover:border-white/20 transition-colors","data-testid":`card-guestbook-${t.id}`,children:x===t.id?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-white/50 text-xs font-mono mb-1 block",children:"Name"}),e.jsx(d,{value:i.name||"",onChange:s=>r({...i,name:s.target.value}),className:"bg-black/30 border-white/20 text-white text-sm","data-testid":"input-edit-name"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-white/50 text-xs font-mono mb-1 block",children:"Where From"}),e.jsx(d,{value:i.whereFrom||"",onChange:s=>r({...i,whereFrom:s.target.value}),className:"bg-black/30 border-white/20 text-white text-sm","data-testid":"input-edit-wherefrom"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-white/50 text-xs font-mono mb-1 block",children:"Email"}),e.jsx(d,{value:i.email||"",onChange:s=>r({...i,email:s.target.value}),className:"bg-black/30 border-white/20 text-white text-sm","data-testid":"input-edit-email"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-white/50 text-xs font-mono mb-1 block",children:"Home Page"}),e.jsx(d,{value:i.homePage||"",onChange:s=>r({...i,homePage:s.target.value}),className:"bg-black/30 border-white/20 text-white text-sm","data-testid":"input-edit-homepage"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-white/50 text-xs font-mono mb-1 block",children:"Reflections"}),e.jsx(I,{value:i.reflections||"",onChange:s=>r({...i,reflections:s.target.value}),className:"bg-black/30 border-white/20 text-white text-sm min-h-[80px]","data-testid":"input-edit-reflections"})]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsxs(c,{variant:"ghost",size:"sm",onClick:()=>u(null),className:"text-white/60 hover:text-white","data-testid":"button-cancel-edit",children:[e.jsx(y,{className:"w-4 h-4 mr-1"})," Cancel"]}),e.jsxs(c,{size:"sm",onClick:$,disabled:p.isPending,className:"bg-accent text-black hover:bg-accent/80","data-testid":"button-save-edit",children:[p.isPending?e.jsx(j,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(F,{className:"w-4 h-4 mr-1"}),"Save"]})]})]}):e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("span",{className:"text-white font-semibold","data-testid":`text-name-${t.id}`,children:t.name}),e.jsx("span",{className:"text-white/30 text-xs font-mono",children:t.whereFrom}),e.jsx("span",{className:"text-white/20 text-xs font-mono",children:W(new Date(t.submittedAt),"MMM d, yyyy")})]}),t.reflections&&e.jsx("p",{className:"text-white/50 text-sm mt-1 line-clamp-2","data-testid":`text-reflection-${t.id}`,children:t.reflections}),(t.email||t.homePage)&&e.jsxs("div",{className:"flex gap-3 mt-1 text-xs text-white/30 font-mono",children:[t.email&&e.jsx("span",{children:t.email}),t.homePage&&e.jsx("span",{children:t.homePage})]})]}),e.jsx("div",{className:"flex gap-1 flex-shrink-0",children:L===t.id?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-red-400 text-xs font-mono mr-1",children:"Delete?"}),e.jsx(c,{variant:"ghost",size:"sm",onClick:()=>g(null),className:"text-white/60 hover:text-white h-8 w-8 p-0","data-testid":`button-cancel-delete-${t.id}`,children:e.jsx(y,{className:"w-4 h-4"})}),e.jsx(c,{variant:"ghost",size:"sm",onClick:()=>w.mutate(t.id),disabled:w.isPending,className:"text-red-400 hover:text-red-300 hover:bg-red-500/10 h-8 w-8 p-0","data-testid":`button-confirm-delete-${t.id}`,children:w.isPending?e.jsx(j,{className:"w-4 h-4 animate-spin"}):e.jsx(F,{className:"w-4 h-4"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(c,{variant:"ghost",size:"sm",onClick:()=>T(t),className:"text-white/40 hover:text-accent h-8 w-8 p-0","data-testid":`button-edit-${t.id}`,children:e.jsx(B,{className:"w-4 h-4"})}),e.jsx(c,{variant:"ghost",size:"sm",onClick:()=>g(t.id),className:"text-white/40 hover:text-red-400 h-8 w-8 p-0","data-testid":`button-delete-${t.id}`,children:e.jsx(K,{className:"w-4 h-4"})})]})})]})},t.id))})]})})}export{ee 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.