1import{c as i,j as e,aT as j,aY as b,Y as w}from"./vendor-1kUQ7zn2.js";import{F as N}from"./vendor-supabase-Dh2gyaRa.js";import{w as k,D as C,a as E,b as D,d as S,e as T,N as L,M as R,B as _,s as g,W as A}from"./index--kdl1ae9.js";import{a as I,S as X,c as F,b as P,t as d}from"./license-C3P8flk1.js";import{c as G}from"./checkoutState-C2DchyvW.js";import"./vendor-date-en1IyhsK.js";import"./vendor-motion-BX-jsy7E.js";const z=({isOpen:r,onClose:y})=>{const[h,x]=i.useState(""),[u,n]=i.useState({kind:"idle"}),m=i.useRef(null);i.useEffect(()=>{r&&k("license_dialog_opened")},[r]),i.useEffect(()=>{r||(n({kind:"idle"}),x(""))},[r]),i.useEffect(()=>()=>{m.current&&window.clearTimeout(m.current)},[]);const o=u.kind==="verifying",t=u.kind==="done"?u.result:null,f=t?.ok===!0,v=async()=>{const s=F(h);if(!s){n({kind:"done",result:P("missing_key")});return}n({kind:"verifying"});let a;try{const{data:p,error:l}=await g.functions.invoke("activate-license",{body:{license_key:s}});if(l)if(l instanceof N){const c=await l.context.json().catch(()=>null);a=d(c)}else a=d(null,!0);else a=d(p)}catch{a=d(null,!0)}if(n({kind:"done",result:a}),a.ok){k("license_activated",{plan:a.plan}),G();const p=a.plan;g.auth.getSession().then(({data:l})=>{const c=l.session?.user?.id;c&&A(c,p==="lifetime"?"lifetime":"membership")}),m.current=window.setTimeout(()=>window.location.reload(),2200)}};return e.jsx(C,{open:r,onOpenChange:s=>!s&&!o&&y(),children:e.jsxs(E,{className:"max-w-md","data-testid":"license-dialog",children:[e.jsxs(D,{children:[e.jsx(S,{children:f?"You're all set":"Enter your license key"}),e.jsx(T,{children:f?"Thanks for your purchase.":"Paste the key from your Gumroad receipt email. It works for every plan."})]}),f?e.jsxs("div",{className:"space-y-4",role:"status","data-testid":"license-success",children:[e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-emerald-500/30 bg-emerald-500/10 p-3 text-sm",children:[e.jsx(j,{className:"mt-0.5 h-4 w-4 shrink-0 text-emerald-600 dark:text-emerald-400","aria-hidden":!0}),e.jsx("p",{className:"text-foreground",children:I(t)})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Reloading the appâ¦"})]}):e.jsxs("form",{className:"space-y-4",onSubmit:s=>{s.preventDefault(),o||v()},children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{htmlFor:"license-key",children:"License key"}),e.jsx(R,{id:"license-key","data-testid":"license-input",placeholder:"XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX",value:h,onChange:s=>{x(s.target.value),t&&!t.ok&&n({kind:"idle"})},autoComplete:"off",autoCapitalize:"characters",autoCorrect:"off",spellCheck:!1,inputMode:"text",className:"font-mono text-sm",disabled:o,"aria-invalid":!!t&&!t.ok,"aria-describedby":t&&!t.ok?"license-error":void 0})]}),t&&!t.ok&&e.jsxs("div",{id:"license-error",role:"alert","data-testid":"license-error","data-code":t.code,className:"flex items-start gap-3 rounded-lg border border-destructive/30 bg-destructive/10 p-3 text-sm",children:[e.jsx(b,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive","aria-hidden":!0}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("p",{className:"font-medium text-foreground",children:t.title}),e.jsx("p",{className:"text-muted-foreground",children:t.message}),t.contactSupport&&e.jsxs("a",{href:`mailto:${X}?subject=${encodeURIComponent("License key help")}`,className:"inline-block font-medium text-foreground underline underline-offset-4",children:["Email ",X]})]})]}),e.jsx(_,{type:"submit",className:"w-full",disabled:o,"data-testid":"license-submit",children:o?e.jsxs(e.Fragment,{children:[e.jsx(w,{className:"mr-2 h-4 w-4 animate-spin","aria-hidden":!0}),"Checking with Gumroadâ¦"]}):t&&!t.ok&&t.retryable?"Try again":"Activate"})]})]})})};export{z as GumroadLicenseDialog};
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.