1import{c,j as e,aq as X,bF as Z,cV as U,bJ as ee}from"./vendor-1kUQ7zn2.js";import{d as te}from"./vendor-supabase-Dh2gyaRa.js";import{c as D,g as se,w as ae,s as k,V as ie,W as H,X as ne,Y as ce,D as oe,a as re,b as le,d as de,K as i,e as K,B as j,Z as I,$ as ue}from"./index--kdl1ae9.js";import{S as z}from"./license-C3P8flk1.js";import{u as R,r as he,c as Y,a as me,b as V,g as fe}from"./checkout-DROMBe3d.js";import{c as pe,i as ge,a as xe,n as ve,b as be,P as Q}from"./checkoutState-C2DchyvW.js";import{u as ye,A as O,m as T}from"./vendor-motion-BX-jsy7E.js";import"./vendor-date-en1IyhsK.js";const we=4e3,ke=2800,je=[{key:"do",i:0,dx:7,dy:7,area:"1 / 1"},{key:"schedule",i:1,dx:-7,dy:7,area:"1 / 2"},{key:"backlog",i:2,dx:-7,dy:-7,area:"2 / 2"},{key:"delegate",i:3,dx:7,dy:-7,area:"2 / 1"}],Ne=({state:d,still:s})=>{const u=c.useRef(null),[p,t]=c.useState(!1);return c.useEffect(()=>{const n=u.current;if(!n||typeof n.getAnimations!="function")return;const g=d==="pulse-fast"?we/ke:1;for(const o of n.getAnimations({subtree:!0}))o.animationName==="cs-breathe"&&o.playbackRate!==g&&(typeof o.updatePlaybackRate=="function"?o.updatePlaybackRate(g):o.playbackRate=g)},[d]),e.jsxs("div",{ref:u,className:D("cs-mark mx-auto",s&&"cs-still",p&&"cs-played"),"data-state":d,"data-testid":"checkout-mark","aria-hidden":!0,children:[e.jsx("span",{className:"cs-wash"}),e.jsx("div",{className:"cs-grid",children:je.map(n=>e.jsx("span",{className:"cs-sq",style:{gridArea:n.area,"--c":`var(--q-${n.key})`,"--cs-i":n.i,"--cs-dx":`${n.dx}px`,"--cs-dy":`${n.dy}px`},children:e.jsx("span",{className:"cs-glow",children:e.jsx("span",{className:"cs-lit"})})},n.key))}),d==="done"&&e.jsx("div",{className:"cs-done",children:e.jsx("span",{className:"cs-tile",children:e.jsx("svg",{viewBox:"0 0 24 24",children:e.jsx("path",{className:"cs-check",d:"M5.75 12.5l4 4L18.25 8"})})})}),d==="done"&&!s&&e.jsx("span",{className:"cs-ring",onAnimationEnd:n=>n.animationName==="cs-ring-out"&&t(!0)})]})},Se=({labels:d,at:s})=>e.jsx("ol",{className:"cs-steps","aria-label":"Checkout progress","data-testid":"checkout-steps","data-step":s,children:d.map((u,p)=>{const t=p<s?"done":p===s?"current":"todo";return e.jsxs("li",{className:"cs-step","data-state":t,"aria-current":t==="current"?"step":void 0,children:[e.jsxs("span",{className:"cs-dot",children:[e.jsx("span",{className:"cs-dot-halo"}),e.jsx("span",{className:"cs-dot-ring"}),e.jsx("span",{className:"cs-dot-fill"}),e.jsx(X,{"aria-hidden":!0})]}),e.jsx("span",{className:"cs-label",children:u})]},u)})}),Ce="payment_status, subscription_type, is_lifetime_purchase, subscription_expiry_date, gumroad_subscription_status",W="billing:claim-checked",Oe=()=>{const{session:d}=te.useSessionContext(),s=d?.user?.id??null,u=se(),p=ye(),{phase:t,pending:n,returned:g,paymentSeen:o,cancelReminder:h,set:m}=R(),[$,B]=c.useState(!1),P=c.useRef(!1);c.useEffect(()=>{(t==="activated"||t==="closed"||t==="slow")&&ae("checkout_result",{result:t,plan:R.getState().pending?.plan})},[t]),c.useEffect(()=>{if(s){he();try{const a=new URL(window.location.href);a.searchParams.has("checkout")&&(a.searchParams.delete("checkout"),window.history.replaceState(null,"",a.pathname+a.search+a.hash))}catch{}}},[s]);const E=c.useCallback(async(a,r)=>{if(pe(),a==="lifetime"&&ge(r)){let l=null;if(s){try{const{data:f,error:q}=await k.from("purchases").select(ie).eq("user_id",s);q||(l=f??[])}catch{l=null}H(s,a)}m({phase:"activated",cancelReminder:ne(l)});return}if(s&&ce(s,a)){window.location.reload();return}s&&H(s,a),m({phase:"activated",cancelReminder:null})},[s,m]),x=c.useCallback(async()=>{const a=R.getState();if(!(!s||!a.pending||P.current)&&["waiting","closed","activating","slow"].includes(a.phase)){P.current=!0;try{const[{data:r},l]=await Promise.all([k.from("profiles").select(Ce).eq("id",s).maybeSingle(),a.pending.ticket?k.from("checkout_tickets").select("used_at").eq("id",a.pending.ticket).maybeSingle():Promise.resolve({data:null})]),f=!!l.data?.used_at,q=xe(a.pending,r,f),w=R.getState(),L=ve(w.phase,{activated:q,ticketUsed:f,activatingSince:w.activatingSince,now:Date.now()});L==="activated"?await E(be(r)?"lifetime":"membership",a.pending):(L!==w.phase||f&&!w.paymentSeen)&&m({phase:L,paymentSeen:w.paymentSeen||f,activatingSince:L==="activating"&&w.activatingSince===null?Date.now():w.activatingSince})}catch{}finally{P.current=!1}}},[s,m,E]);c.useEffect(()=>{if(!s||!n||!["waiting","closed","activating","slow"].includes(t))return;const a=t==="activating"?Q.activatingEveryMs:Q.waitingEveryMs;x();const r=window.setInterval(()=>{x()},a),l=()=>{document.visibilityState==="visible"&&x()};return document.addEventListener("visibilitychange",l),window.addEventListener("focus",l),()=>{window.clearInterval(r),document.removeEventListener("visibilitychange",l),window.removeEventListener("focus",l)}},[s,n,t,x]),c.useEffect(()=>{if(!s||!n||!["waiting","closed","activating","slow"].includes(t))return;let a=null;try{a=k.channel(`billing-${s}`).on("postgres_changes",{event:"*",schema:"public",table:"purchases",filter:`user_id=eq.${s}`},()=>{x()}).on("postgres_changes",{event:"UPDATE",schema:"public",table:"checkout_tickets",filter:`user_id=eq.${s}`},()=>{x()}).subscribe()}catch{a=null}return()=>{a&&k.removeChannel(a)}},[s,n?.startedAt]),c.useEffect(()=>{if(t!=="waiting")return;const a=window.setInterval(()=>{const r=fe();r&&r.closed&&x().then(()=>{R.getState().phase==="waiting"&&m({phase:"closed"})})},1e3);return()=>window.clearInterval(a)},[t,x,m]),c.useEffect(()=>{if(!s)return;let a=!1;try{a=window.sessionStorage.getItem(W)===s,window.sessionStorage.setItem(W,s)}catch{}a||(async()=>{try{const{data:r,error:l}=await k.rpc("claim_my_purchases");if(l||typeof r!="number"||r<1)return;const{data:f}=await k.functions.invoke("activate-license",{body:{action:"refresh"}});f?.ok&&await E(f.plan==="lifetime"?"lifetime":"membership")}catch{}})()},[s,E]);const G=t!=="idle"&&t!=="opening",C=!!p,y=u?"min-h-11 w-full":"w-full";let v="",b="",N="rest",_=0;t==="waiting"?(v=g?i.returnTitle:i.waitingTitle,b=g?i.returnBody:i.waitingBody,N="pulse"):t==="closed"?(v=i.closedTitle,b=i.closedBody):t==="activating"?(v=o?i.activatingTitle:i.checkingTitle,b=i.activatingBody,N="pulse-fast",_=1):t==="activated"&&h?(v=I.switchedTitle,b=I.switchedBody,N="done",_=3):t==="activated"?(v=i.activatedTitle,b=i.activatedBody,N="done",_=3):t==="slow"&&(v=i.slowTitle,b=i.slowBody,N="pulse",_=1);const J=`${t}:${v}`,A=t==="activated"&&!!h,S=t==="waiting"||t==="closed"?"pay":t==="slow"?"slow":t==="activated"?"done":null,F=[.4,0,.2,1],M={initial:C?{opacity:0}
1:{opacity:0,y:4},animate:{opacity:1,y:0,transition:{duration:.28,ease:F,delay:.06}},exit:{opacity:0,transition:{duration:.16,ease:F}}};return e.jsxs(e.Fragment,{children:[e.jsx(oe,{open:G&&!$,onOpenChange:a=>{a||(t==="activated"?window.location.reload():t!=="activating"&&V())},children:e.jsx(re,{className:D("gap-0 p-0 sm:max-w-[25rem] sm:rounded-2xl","[&>button:last-child]:right-4 [&>button:last-child]:top-4 [&>button:last-child]:grid [&>button:last-child]:h-8 [&>button:last-child]:w-8 [&>button:last-child]:place-items-center [&>button:last-child]:rounded-md","[&>button:last-child]:bg-transparent [&>button:last-child]:text-muted-foreground [&>button:last-child]:opacity-100 [&>button:last-child]:transition-colors [&>button:last-child:hover]:bg-muted [&>button:last-child:hover]:text-foreground","[&>button:last-child:focus]:ring-0 [&>button:last-child:focus]:ring-offset-0 [&>button:last-child:focus-visible]:ring-2 [&>button:last-child:focus-visible]:ring-ring [&>button:last-child:focus-visible]:ring-offset-2","sm:[&>button:last-child]:right-6 sm:[&>button:last-child]:top-6"),"data-testid":"checkout-status","data-phase":t,"data-reminder":h?"cancel-monthly":void 0,children:e.jsx(_e,{still:C,children:e.jsxs("div",{className:"px-6 pb-6 pt-8 sm:px-8 sm:pb-8",children:[e.jsx(Ne,{state:N,still:C}),e.jsx("div",{className:"relative mt-4",role:"status","aria-live":"polite",children:e.jsx(O,{initial:!1,mode:"popLayout",children:e.jsx(T.div,{...M,children:e.jsxs(le,{className:"items-center space-y-2 text-center sm:text-center",children:[e.jsx(de,{className:"text-balance text-lg font-semibold leading-6 tracking-tight",children:v}),A?e.jsxs("div",{className:"!mt-4 w-full rounded-xl border border-[rgb(var(--q-focus)/0.35)] bg-[rgb(var(--q-focus)/0.08)] px-4 py-3 text-left",children:[e.jsxs("p",{className:"flex items-center gap-2 text-xs font-semibold uppercase tracking-wide text-[rgb(var(--q-focus))]",children:[e.jsx(Z,{className:"h-3.5 w-3.5","aria-hidden":!0}),i.switchReminderLabel]}),e.jsx(K,{className:"mt-1 text-sm leading-6 text-foreground",children:b})]}):e.jsx(K,{className:"mx-auto max-w-[34ch] text-pretty text-sm leading-6",children:b})]})},J)})}),e.jsx(O,{initial:!1,children:!A&&e.jsx(T.div,{layout:C?!1:"position",...M,className:"mt-6 border-t border-border/70 pt-6",children:e.jsx(Se,{labels:i.steps,at:_})},"steps")}),e.jsx("div",{className:"relative",children:e.jsx(O,{initial:!1,mode:"popLayout",children:S&&e.jsxs(T.div,{layout:C?!1:"position",...M,className:"flex flex-col gap-2 pt-6",children:[S==="done"&&A&&h&&e.jsx(j,{asChild:!0,className:y,children:e.jsxs("a",{href:h.manageUrl,target:"_blank",rel:"noopener noreferrer","data-testid":"checkout-cancel-monthly",children:[I.oldMonthlyCta,e.jsx(U,{"aria-hidden":!0})]})}),S==="done"&&e.jsx(j,{className:y,variant:h?"outline":"default","data-testid":"checkout-continue",onClick:()=>window.location.reload(),children:i.continue}),S==="pay"&&e.jsxs(e.Fragment,{children:[e.jsx(j,{className:y,"data-testid":"checkout-paid",onClick:Y,children:i.paid}),e.jsxs(j,{variant:"outline",className:y,"data-testid":"checkout-reopen",onClick:me,children:[e.jsx(U,{"aria-hidden":!0}),i.reopen]}),e.jsx(j,{variant:"ghost",className:D(y,"text-muted-foreground hover:bg-muted hover:text-foreground"),"data-testid":"checkout-cancel",onClick:V,children:i.cancel})]}),S==="slow"&&e.jsxs(e.Fragment,{children:[e.jsxs(j,{className:y,"data-testid":"checkout-enter-key",onClick:()=>B(!0),children:[e.jsx(ee,{"aria-hidden":!0}),i.enterKey]}),e.jsx(j,{variant:"outline",className:y,"data-testid":"checkout-keep-waiting",onClick:Y,children:i.keepWaiting}),e.jsxs("p",{className:"pt-2 text-center text-xs leading-4 text-muted-foreground",children:[i.help," ",e.jsx("a",{className:"rounded-sm underline underline-offset-4 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",href:`mailto:${z}?subject=${encodeURIComponent("Payment not activated")}`,children:z})]})]})]},S)})})]})})})}),e.jsx(ue,{isOpen:$,onClose:()=>B(!1)})]})},_e=({still:d,children:s})=>{const u=c.useRef(null),[p,t]=c.useState(null),[n,g]=c.useState(!1);return c.useLayoutEffect(()=>{const o=u.current;if(!o||(t(o.offsetHeight),typeof ResizeObserver>"u"))return;const h=new ResizeObserver(()=>t(o.offsetHeight));h.observe(o);const m=requestAnimationFrame(()=>requestAnimationFrame(()=>g(!0)));return()=>{h.disconnect(),cancelAnimationFrame(m)}},[]),e.jsx("div",{className:"overflow-hidden",style:{height:p??void 0,transition:n&&!
1d?"height 320ms cubic-bezier(0.4, 0, 0.2, 1)":void 0},children:e.jsx("div",{ref:u,children:s})})};export{Oe as CheckoutStatus};
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.