1import{a as l,z as u,r as t,j as e,L as d,B as m}from"./index-Dm7-BJWq.js";import{s as b}from"./client-DtbezEGs.js";const h="https://ohekmhnluhxptsmezxes.supabase.co",x="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9oZWttaG5sdWh4cHRzbWV6eGVzIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzU1NjczNzQsImV4cCI6MjA5MTE0MzM3NH0.mTV37PuJ1x7YONt2Yrvx-XYBYXzBFqI-rHfwG83orYQ";function g(){l({title:"Unsubscribe",description:"Unsubscribe from KOPE emails.",path:"/unsubscribe"});const[c]=u(),a=c.get("token"),[i,s]=t.useState("loading");t.useEffect(()=>{if(!a){s("invalid");return}(async()=>{try{const r=await fetch(`${h}/functions/v1/handle-email-unsubscribe?token=${encodeURIComponent(a)}`,{headers:{apikey:x}}),n=await r.json();r.ok&&n.valid?s("valid"):(n==null?void 0:n.reason)==="already_unsubscribed"?s("already"):s("invalid")}catch{s("error")}})()},[a]);const o=async()=>{if(a){s("submitting");try{const{data:r,error:n}=await b.functions.invoke("handle-email-unsubscribe",{body:{token:a}});if(n)throw n;r!=null&&r.success||(r==null?void 0:r.reason)==="already_unsubscribed"?s("done"):s("error")}catch{s("error")}}};return e.jsx(d,{children:e.jsx("section",{className:"bg-background pt-32 pb-32 min-h-[60vh]",children:e.jsxs("div",{className:"container max-w-xl",children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight mb-6",children:"Email preferences"}),i==="loading"&&e.jsx("p",{className:"text-muted-foreground",children:"Checking your linkâ¦"}),i==="valid"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-base mb-6",children:"Click below to unsubscribe from KOPE emails. You won't receive further messages from us."}),e.jsx(m,{onClick:o,variant:"outline",children:"Confirm unsubscribe"})]}),i==="submitting"&&e.jsx("p",{className:"text-muted-foreground",children:"Processingâ¦"}),i==="done"&&e.jsx("p",{className:"text-base",children:"You've been unsubscribed. Sorry to see you go."}),i==="already"&&e.jsx("p",{className:"text-base",children:"This address is already unsubscribed."}),i==="invalid"&&e.jsx("p",{className:"text-base",children:"This unsubscribe link is invalid or has expired."}),i==="error"&&e.jsx("p",{className:"text-base",children:"Something went wrong. Please try again later."})]})})})}export{g 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.