1import{f as M,u as P,r as l,j as e}from"./vendor-react-GnwsTJfO.js";import{f as o,N as m,F as d,C as h,g,Y as B,B as x,L as q,r as K,R,V as v,W as A}from"./index-Bk3sb3g_.js";import{C as F}from"./circle-check-big-CDOLBlXh.js";import{C as G}from"./circle-x-DAuLvfD-.js";import"./vendor-cjs-BcELrC9x.js";import"./vendor-supabase-BWPZKnGU.js";import"./vendor-ui-C1xCQL2z.js";import"./vendor-utils-B2rm_Apj.js";import"./vendor-query-Dp4tHR6-.js";function $(){const{slug:i,token:r}=M(),u=P(),[k,w]=l.useState(!0),[j,p]=l.useState(!1),[_,y]=l.useState(!1),[s,C]=l.useState(null),[a,E]=l.useState(null),[N,f]=l.useState(null);l.useEffect(()=>{i&&r&&D()},[i,r]);const D=async()=>{try{const{data:t,error:c}=await o.from("info_meetings").select("id, title, event_date, event_time, location_name").eq("slug",i).maybeSingle();if(c)throw c;if(!t){f("Møtet finnes ikke");return}C(t);const{data:n,error:b}=await o.from("info_meeting_registrations").select("id, name, email, meeting_id, on_waitlist").eq("cancellation_token",r).eq("meeting_id",t.id).maybeSingle();if(b)throw b;if(!n){f("Ugyldig avmeldingslenke eller påmeldingen er allerede slettet");return}E(n)}catch(t){console.error("Error loading data:",t),f("Kunne ikke laste data")}finally{w(!1)}},S=async()=>{if(!(!a||!s||!r)){p(!0);try{const t=a.on_waitlist,{data:c,error:n}=await o.rpc("delete_registration_by_token",{p_token:r});if(n)throw n;if(!c)throw new Error("Kunne ikke slette påmeldingen");t||await o.functions.invoke("process-waitlist",{body:{meeting_id:s.id}}),y(!0),v.success("Du er nå avmeldt")}catch(t){console.error("Error cancelling:",t),v.error("Kunne ikke melde deg av")}finally{p(!1)}}};return k?e.jsxs("div",{className:"min-h-screen flex flex-col bg-background",children:[e.jsx(m,{}),e.jsx("main",{className:"flex-grow flex items-center justify-center",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})}),e.jsx(d,{})]}):N?e.jsxs("div",{className:"min-h-screen flex flex-col bg-background",children:[e.jsx(m,{}),e.jsx("main",{className:"flex-grow container mx-auto px-4 py-12",children:e.jsx(h,{className:"max-w-md mx-auto",children:e.jsxs(g,{className:"pt-12 pb-12 text-center",children:[e.jsx(B,{className:"w-16 h-16 text-amber-500 mx-auto mb-6"}),e.jsx("h1",{className:"text-2xl font-serif mb-4",children:"Noe gikk galt"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:N}),e.jsx(x,{onClick:()=>u("/"),children:"Gå til forsiden"})]})})}),e.jsx(d,{})]}):_?e.jsxs("div",{className:"min-h-screen flex flex-col bg-background",children:[e.jsx(m,{}),e.jsx("main",{className:"flex-grow container mx-auto px-4 py-12",children:e.jsx(h,{className:"max-w-md mx-auto",children:e.jsxs(g,{className:"pt-12 pb-12 text-center",children:[e.jsx(F,{className:"w-16 h-16 text-green-500 mx-auto mb-6"}),e.jsx("h1",{className:"text-2xl font-serif mb-4",children:"Du er avmeldt"}),e.jsxs("p",{className:"text-muted-foreground mb-6",children:["Din påmelding til ",s==null?void 0:s.title," er nå slettet."]}),e.jsx(x,{onClick:()=>u("/"),children:"Gå til forsiden"})]})})}),e.jsx(d,{})]}):e.jsxs("div",{className:"min-h-screen flex flex-col bg-background",children:[e.jsx(m,{}),e.jsx("main",{className:"flex-grow container mx-auto px-4 py-12",children:e.jsx(h,{className:"max-w-md mx-auto",children:e.jsxs(g,{className:"pt-8 pb-8",children:[e.jsxs("div",{className:"text-center mb-6",children:[e.jsx(G,{className:"w-12 h-12 text-destructive mx-auto mb-4"}),e.jsx("h1",{className:"text-2xl font-serif mb-2",children:"Meld deg av"}),e.jsx("p",{className:"text-muted-foreground",children:"Er du sikker på at du vil melde deg av?"})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-4 mb-6",children:[e.jsx("h2",{className:"font-semibold mb-2",children:s==null?void 0:s.title}),e.jsxs("div",{className:"space-y-1 text-sm text-muted-foreground",children:[e.jsxs("p",{className:"flex items-center gap-2",children:[e.jsx(q,{className:"w-4 h-4"}),s&&K(new Date(s.event_date),"PPP",{locale:A})," kl. ",s==null?void 0:s.event_time.substring(0,5)]}),e.jsxs("p",{className:"flex items-center gap-2",children:[e.jsx(R,{className:"w-4 h-4"}),s==null?void 0:s.location_name]})]})]}),e.jsxs("div",{className:"bg-muted/30 rounded-lg p-4 mb-6",children:[e.jsxs("p",{className:"text-sm",children:[e.jsx("strong",{children:"Påmeldt:"})," ",a==null?void 0:a.name]}),e.jsxs("p",{className:"text-sm",children:[e.jsx("strong",{children:"E-post:"})," ",a==null?void 0:a.email]}
1),(a==null?void 0:a.on_waitlist)&&e.jsx("p",{className:"text-sm text-amber-600 mt-2",children:"Du står på venteliste"})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(x,{variant:"outline",className:"flex-1",onClick:()=>u(`/infomote/${i}`),children:"Avbryt"}),e.jsx(x,{variant:"destructive",className:"flex-1",onClick:S,disabled:j,children:j?"Melder av...":"Bekreft avmelding"})]})]})})}),e.jsx(d,{})]})}export{$ 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.