1import{R as o,r as a,j as e}from"./index-BA5ELD1M.js";function l(){const{token:i}=o.useSearch(),[n,s]=a.useState({kind:"loading"});a.useEffect(()=>{if(!i){s({kind:"invalid"});return}fetch(`/email/unsubscribe?token=${encodeURIComponent(i)}`).then(async r=>{const t=await r.json().catch(()=>({}));if(!r.ok){s({kind:"invalid"});return}t?.valid?s({kind:"valid"}):t?.reason==="already_unsubscribed"?s({kind:"already"}):s({kind:"invalid"})}).catch(()=>s({kind:"error",message:"Network error"}))},[i]);const d=async()=>{if(i){s({kind:"submitting"});try{const r=await fetch("/email/unsubscribe",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({token:i})}),t=await r.json().catch(()=>({}));r.ok&&(t?.success||t?.reason==="already_unsubscribed")?s({kind:"done"}):s({kind:"error",message:t?.error??"Could not unsubscribe"})}catch(r){s({kind:"error",message:r.message})}}};return e.jsx("main",{className:"min-h-screen flex items-center justify-center px-6 py-16 bg-background",children:e.jsxs("div",{className:"max-w-md w-full text-center space-y-6",children:[e.jsx("p",{className:"text-xs tracking-widest uppercase text-muted-foreground",children:"My Daily Read"}),n.kind==="loading"&&e.jsx("p",{className:"text-muted-foreground",children:"Checking your linkâ¦"}),n.kind==="invalid"&&e.jsxs(e.Fragment,{children:[e.jsx("h1",{className:"text-3xl font-serif",children:"Link not valid"}),e.jsx("p",{className:"text-muted-foreground",children:"This unsubscribe link is invalid or has expired."})]}),n.kind==="already"&&e.jsxs(e.Fragment,{children:[e.jsx("h1",{className:"text-3xl font-serif",children:"You're already unsubscribed"}),e.jsx("p",{className:"text-muted-foreground",children:"You won't receive any more daily digests at this address."})]}),n.kind==="valid"&&e.jsxs(e.Fragment,{children:[e.jsx("h1",{className:"text-3xl font-serif",children:"Unsubscribe from the daily digest?"}),e.jsx("p",{className:"text-muted-foreground",children:"You can re-enable it any time from your settings."}),e.jsx("button",{onClick:d,className:"inline-flex items-center px-6 py-3 rounded-md bg-foreground text-background hover:opacity-90 transition",children:"Confirm unsubscribe"})]}),n.kind==="submitting"&&e.jsx("p",{className:"text-muted-foreground",children:"Unsubscribingâ¦"}),n.kind==="done"&&e.jsxs(e.Fragment,{children:[e.jsx("h1",{className:"text-3xl font-serif",children:"You're unsubscribed"}),e.jsxs("p",{className:"text-muted-foreground",children:["Sorry to see you go. Change your mind?"," ",e.jsx("a",{href:"/settings",className:"underline",children:"Re-enable in settings"}),"."]})]}),n.kind==="error"&&e.jsxs(e.Fragment,{children:[e.jsx("h1",{className:"text-3xl font-serif",children:"Something went wrong"}),e.jsx("p",{className:"text-muted-foreground",children:n.message})]})]})})}export{l 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.