1import{c as me,r as l,j as e,W as G,aU as ye,aV as ve,X as re,Y as ne,C as X,a4 as T,q as ie,T as q,V as Z,E as we,aW as he,a7 as Te,ak as ke,a as Ae,aX as Pe,a8 as Ee,v as Fe,U as W,o as Le,z as Ue,w as be,aY as pe,B as fe,aZ as V}from"./index-C8mv3J5_.js";import{b as J,B as k,u as _e}from"./useSubscription-Dq_5nMIC.js";import{t as le}from"./tokenService-g6P6Ikr4.js";import{L as $}from"./loader-circle-B7rSiCnE.js";import{g as Ie,E as ge,u as Me,a as Be,P as Oe,A as Re}from"./stripe-DKrUeIco.js";import{B as De}from"./building-2-993BxJTS.js";import{R as Ye}from"./rotate-ccw-ChglD6Rd.js";import{C as Ne}from"./credit-card-BRIYK8QY.js";import"./index-BZhRENN4.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Q=me("Coins",[["circle",{cx:"8",cy:"8",r:"6",key:"3yglwk"}],["path",{d:"M18.09 10.37A6 6 0 1 1 10.34 18",key:"t5s6rm"}],["path",{d:"M7 6h1v4",key:"1obek4"}],["path",{d:"m16.71 13.88.7.71-2.82 2.82",key:"1rbuyh"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const je=me("Gift",[["rect",{x:"3",y:"8",width:"18",height:"4",rx:"1",key:"bkv52"}],["path",{d:"M12 8v13",key:"1c76mn"}],["path",{d:"M19 12v7a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-7",key:"6wjy6b"}],["path",{d:"M7.5 8a2.5 2.5 0 0 1 0-5A4.8 8 0 0 1 12 8a4.8 8 0 0 1 4.5-5 2.5 2.5 0 0 1 0 5",key:"1ihvrl"}]]);/** 12 * @license lucide-react v0.462.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const de=me("Tag",[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]),$e=({isOpen:c,onClose:i,planId:a,interval:y,onSuccess:n})=>{const[s,f]=l.useState(null),[A,v]=l.useState(!0),[P,g]=l.useState(!1),[C,S]=l.useState(null),o=q[a];l.useEffect(()=>{c&&a&&(v(!0),S(null),J.previewSubscriptionChange(a,y).then(d=>{f(d)}).catch(d=>{var h,w;console.error("Preview error:",d),S(((w=(h=d.response)==null?void 0:h.data)==null?void 0:w.message)||"Failed to load upgrade preview")}).finally(()=>{v(!1)}))},[c,a,y]);const N=async()=>{var d,h;g(!0),S(null);try{await J.changeSubscription(a,y),n()}catch(w){console.error("Upgrade error:",w),S(((h=(d=w.response)==null?void 0:d.data)==null?void 0:h.message)||"Failed to upgrade subscription"),g(!1)}},b=(d,h="eur")=>new Intl.NumberFormat("en-US",{style:"currency",currency:h.toUpperCase()}).format(d),r=d=>new Date(d).toLocaleDateString("en-US",{month:"long",day:"numeric",year:"numeric"});return e.jsxs(G,{open:c,onClose:i,className:"relative z-50",children:[e.jsx(ye,{transition:!0,className:"modal-backdrop transition-opacity data-[closed]:opacity-0 data-[enter]:duration-200 data-[leave]:duration-150"}),e.jsx("div",{className:"fixed inset-0 flex-center p-4",children:e.jsx(ve,{transition:!0,className:"relative w-full max-w-md transform transition-all data-[closed]:scale-95 data-[closed]:opacity-0 data-[enter]:duration-200 data-[leave]:duration-150",children:e.jsxs("div",{className:"rounded-2xl bg-[hsl(var(--background))] border border-[hsl(var(--border-subtle))] shadow-2xl overflow-hidden",children:[e.jsxs("div",{className:"relative px-6 py-5 border-b border-[hsl(var(--border-subtle))]",children:[e.jsxs("div",{className:"pr-8",children:[e.jsxs("h2",{className:"heading-md",children:["Upgrade to ",o.name]}),e.jsx("p",{className:"text-label mt-1",children:y===k.ANNUAL?"Billed annually":"Billed monthly · Cancel anytime"})]}),e.jsx("button",{onClick:i,className:"absolute top-5 right-5 p-1.5 rounded-lg text-subtle hover:text-white hover:bg-[hsl(var(--bg-tertiary))] transition-colors",children:e.jsx(re,{className:"icon-md"})})]}),e.jsx("div",{className:"p-6",children:A?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[e.jsx($,{className:"icon-xl text-emerald-400 animate-spin mb
16-3"}),e.jsx("p",{className:"text-label",children:"Calculating your upgrade..."})]}):C?e.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[e.jsx("div",{className:"icon-3xl rounded-full bg-red-500/10 flex-center mb-4",children:e.jsx(ne,{className:"icon-lg text-red-400"})}),e.jsx("p",{className:"text-sm text-red-400 text-center mb-4",children:C}),e.jsx("button",{onClick:i,className:"px-4 py-2 text-sm font-medium text-white bg-[hsl(var(--bg-tertiary))] hover:bg-[hsl(var(--bg-elevated))] rounded-lg transition-colors",children:"Close"})]}):s?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-xl bg-[hsl(var(--bg-secondary))] border border-[hsl(var(--border-subtle))] p-5",children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-subtle mb-4",children:"Due today"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-body",children:"Subtotal"}),e.jsx("span",{className:"text-white",children:b(s.dueNowSubtotal,s.currency)})]}),s.dueNowTax>0&&e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-body",children:[s.taxName,s.taxRate>0&&` (${s.taxRate}%)`]}),e.jsx("span",{className:"text-white",children:b(s.dueNowTax,s.currency)})]}),e.jsxs("div",{className:"flex justify-between text-base font-semibold pt-2 border-t border-[hsl(var(--border-subtle))]",children:[e.jsx("span",{className:"text-white",children:"Total"}),e.jsx("span",{className:"text-white",children:b(s.dueNowTotal,s.currency)})]})]})]}),e.jsxs("div",{className:"rounded-xl bg-[hsl(var(--bg-secondary))] border border-white/[0.04] p-4",children:[e.jsxs("p",{className:"text-xs uppercase tracking-wider text-subtle mb-3",children:["Then starting ",r(s.nextBillingDate)]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-subtle",children:[o.name," (",s.recurringInterval==="annual"?"yearly":"monthly",")"]}),e.jsx("span",{className:"text-body",children:b(s.recurringSubtotal,s.currency)})]}),s.recurringTax>0&&e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-subtle",children:s.taxName}),e.jsx("span",{className:"text-body",children:b(s.recurringTax,s.currency)})]}),e.jsxs("div",{className:"flex justify-between text-sm font-medium pt-1.5 border-t border-white/[0.04]",children:[e.jsx("span",{className:"text-body",children:"Total"}),e.jsxs("span",{className:"text-white",children:[b(s.recurringTotal,s.currency),e.jsxs("span",{className:"text-subtle font-normal",children:["/",s.recurringInterval==="annual"?"yr":"mo"]})]})]})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-white mb-3",children:"What you'll get"}),e.jsxs("ul",{className:"space-y-2.5",children:[e.jsxs("li",{className:"flex items-center gap-3 text-sm",children:[e.jsx(Q,{className:"icon-sm text-emerald-400 flex-shrink-0"}),e.jsxs("span",{className:"text-body",children:[e.jsx("strong",{className:"text-white",children:o.monthlyTokens.toLocaleString()})," ","tokens per month"]})]}),e.jsxs("li",{className:"flex items-center gap-3 text-sm",children:[e.jsx(X,{className:"icon-sm text-emerald-400 flex-shrink-0"}),e.jsx("span",{className:"text-body",children:o.platforms.length===1?o.platforms[0]:`All ${o.platforms.length} AI platforms`})]})]})]}),e.jsx("button",{onClick:N,disabled:P,className:T("w-full py-3.5 rounded-xl text-sm font-semibold transition-all duration-200","bg-emerald-500 hover:bg-emerald-400 text-white","shadow-lg shadow-emerald-500/25 hover:shadow-emerald-500/40","disabled:opacity-50 disabled:cursor-not-allowed","flex-center gap-2"),children:P?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"icon-sm animate-spin"}),"Processing..."]}):e.jsxs(e.Fragment,{children:["Confirm Upgrade ·"," ",b(s.dueNowTotal,s.currency),e.jsx(ie,{className:"icon-sm"})]})}),e.jsx("p",{className:"text-caption text-center",children:"Your card on file will be charged. The prorated amount reflects the time remaining in your current billing period."}),e.jsx("button",{onClick:i,disabled:P,className:"w-full text-center text-label hover:text-white transition-colors disabled:opacity-50",children:"Cancel"})]}):null})]})})})]})},xe=(c,i)=>{const a=q[c];return(i==="annual"?a.annualPrice:a.monthlyPrice)??0},ze={AT:[{type:"eu_vat",label:"VAT Number",placeholder:"ATU12345678"}],BE:[{type:"eu_vat",label:"VAT Number",placeholder:"BE0123456789"}],DE:[{type:"eu_vat",label:"VAT Number",placeholder:"DE123456789"}],ES:[{type:"eu_vat",label:"VAT Number",placeholder:"ESX12345678"}],FR:[{type:"eu_vat",label:"VAT Number",placeholder:"FRXX123456789"}],IT:[{type:"eu_vat",label:"P.IVA (VAT)",placeholder:"IT12345678901"}],NL:[{type:"eu_vat",label:"VAT Number",placeholder:"NL123456789B01"}],PL:[{type:"eu_vat",label:"VAT Number",placeholder:"PL1234567890"}],PT:[{type:"eu_vat",label:"VAT Number",placeholder:"PT123456789"}],GB:[{type:"gb_vat",label:"VAT Number",placeholder:"GB123456789"}],CH:[{type:"ch_vat",label:"VAT Number",placeholder:"CHE-123.456.789"}],US:[{type:"us_ein",label:"EIN",placeholder:"12-3456789"}],CA:[{type:"ca_bn",label:"Business Number",placeholder:"123456789"}],AU:[{type:"au_abn",label:"ABN",placeholder:"12345678901"}]},He=({planId:c,interval:i,billingAddress:a,taxId:y,promoDiscount:n,subscriptionData:s,onSuccess:f,onClose:A,onError:v,onBack:P})=>{const g=Me(),C=Be(),[S,o]=l.useState(!1),[N,b]=l.useState(!1),r=q[c],d=s.amountDue===0,h=async E=>{if(E.preventDefault(),!(!g||!C)){o(!0);try{const{error:_}=await C.submit();if(_){v(_.message||"Payment failed"),o(!1);return}let u;s.intentType==="setup"?u=await g.confirmSetup({elements:C,confirmParams:{return_url:`${window.location.origin}/settings/subscription?success=true`},redirect:"if_required"}):u=await g.confirmPayment({elements:C,confirmParams:{return_url:`${window.location.origin}/settings/subscription?success=true`},redirect:"if_required"}),u.error?(v(u.error.message||"Payment failed"),o(!1)):f()}catch(_){v(_.message||"An unexpected error occurred"),o(!1)}}},w=(E,_="eur")=>new Intl.NumberFormat("en-US",{style:"currency",currency:_.toUpperCase()}).format(E/100),m=s.amountDue-s.tax,U=()=>
16{const E=i===k.ANNUAL?"annual":"monthly";return Math.round(xe(c,E)*100)};return e.jsxs("form",{onSubmit:h,className:"space-y-6",children:[e.jsxs("button",{type:"button",onClick:P,disabled:S,className:"flex items-center gap-1 text-label hover:text-white transition-colors disabled:opacity-50",children:[e.jsx(we,{className:"icon-sm"}),"Edit billing details"]}),d&&e.jsx("div",{className:"rounded-xl bg-gradient-to-r from-emerald-500/10 to-teal-500/10 border border-emerald-500/20 p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"icon-2xl rounded-full bg-emerald-500/20 flex-center flex-shrink-0",children:e.jsx(je,{className:"icon-md text-emerald-400"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold text-emerald-400",children:"Your first month is free!"}),e.jsx("p",{className:"text-caption mt-1",children:"We need your payment details for when your subscription renews at the regular price after the promotional period ends."})]})]})}),e.jsxs("div",{className:"rounded-xl bg-[hsl(var(--bg-secondary))] border border-[hsl(var(--border-subtle))] p-5",children:[e.jsx("div",{className:"flex justify-between items-start mb-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"heading-sm",children:r.name}),e.jsx("p",{className:"text-label mt-1",children:i===k.ANNUAL?"Annual subscription":"Monthly subscription"})]})}),e.jsxs("div",{className:"mb-4 pb-4 border-b border-[hsl(var(--border-subtle))]",children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-subtle mb-2",children:"Billing Address"}),e.jsxs("p",{className:"text-body-sm",children:[a.line1,a.line2&&`, ${a.line2}`,e.jsx("br",{}),a.city,a.state&&`, ${a.state}`," ",a.postal_code,e.jsx("br",{}),a.country]}),y&&e.jsxs("p",{className:"text-body-sm mt-2",children:[e.jsx("span",{className:"text-subtle",children:"Tax ID:"})," ",y.value]})]}),e.jsxs("div",{className:"space-y-2",children:[n&&e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-body",children:"Original price"}),e.jsx("span",{className:"text-subtle line-through",children:w(U(),s.currency)})]}),n&&e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-emerald-400 flex items-center gap-1.5",children:[e.jsx(de,{className:"w-3.5 h-3.5"}),n.name]}),e.jsx("span",{className:"text-emerald-400",children:n.percentOff?`-${n.percentOff}%`:n.amountOff?`-${w(n.amountOff,s.currency)}`:"Applied"})]}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-body",children:"Subtotal"}),e.jsx("span",{className:"text-white",children:w(m,s.currency)})]}),s.tax>0&&e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-body",children:"Tax"}),e.jsx("span",{className:"text-white",children:w(s.tax,s.currency)})]}),e.jsxs("div",{className:"flex justify-between text-base font-semibold pt-2 border-t border-[hsl(var(--border-subtle))]",children:[e.jsx("span",{className:"text-white",children:d?"Due today":"Total"}),e.jsx("span",{className:d?"text-emerald-400":"text-white",children:d?"Free":w(s.amountDue,s.currency)})]}),d&&e.jsxs("div",{className:"flex justify-between text-xs pt-1",children:[e.jsxs("span",{className:"text-subtle",children:["Then ",i===k.ANNUAL?"annually":"monthly"]}),e.jsx("span",{className:"text-subtle",children:w(U(),s.currency)})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-white mb-3",children:"Payment method"}),e.jsx("div",{className:"rounded-xl border border-[hsl(var(--border-default))] bg-[hsl(var(--bg-secondary))] p-4",children:e.jsx(Oe,{onReady:()=>b(!0),options:{layout:"tabs"}})})]}),e.jsx("button",{type:"submit",disabled:!g||!N||S,className:T("w-full py-3.5 rounded-xl text-sm font-semibold transition-all duration-200","bg-emerald-500 hover:bg-emerald-400 text-white","shadow-lg shadow-emerald-500/25 hover:shadow-emerald-500/40","disabled:opacity-50 disabled:cursor-not-allowed","flex-center gap-2"),children:S?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"icon-sm animate-spin"}),"Processing..."]}):d?e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"icon-sm"}),"Start Free Month"]}):e.jsxs(e.Fragment,{children:[e.jsx(he,{className:"icon-sm"}),"Subscribe · ",w(s.amountDue,s.currency)]})}),e.jsx("button",{type:"button",onClick:A,disabled:S,className:"w-full text-center text-label hover:text-white transition-colors disabled:opacity-50",children:"Cancel"}),e.jsxs("div",{className:"flex-center gap-2 text-caption",children:[e.jsx(he,{className:"icon-xs"}),e.jsx("span",{children:"Secured by Stripe · Cancel anytime"})]})]})},We=({planId:c,interval:i,onAddressComplete:a,onClose:y})=>{const[n,s]=l.useState(null),[f,A]=l.useState(!1),[v,P]=l.useState(!1),[g,C]=l.useState(""),[S,o]=l.useState(""),[N,b]=l.useState(""),[r,d]=l.useState(null),[h,w]=l.useState(!1),[m,U]=l.useState(!1),E=q[c],_=i===k.ANNUAL?"annual"
16:"monthly",u=xe(c,_),M=l.useMemo(()=>r!=null&&r.valid?r.percentOff?u*(1-r.percentOff/100):r.amountOff?Math.max(0,u-r.amountOff/100):u:u,[u,r]),j=n!=null&&n.country?ze[n.country]||[]:[];l.useEffect(()=>{j.length>0?o(j[0].type):(o(""),C(""),P(!1))},[n==null?void 0:n.country]);const I=p=>{if(p.complete&&p.value.address){const F=p.value.address;s({line1:F.line1||"",line2:F.line2||void 0,city:F.city||"",state:F.state||void 0,postal_code:F.postal_code||"",country:F.country||""}),A(!0)}else A(!1)},B=async()=>{var p,F;if(N.trim()){w(!0);try{const z=await J.validatePromoCode(N,c,i);d(z)}catch(z){d({valid:!1,error:((F=(p=z.response)==null?void 0:p.data)==null?void 0:F.message)||z.message||"Failed to validate code"})}finally{w(!1)}}},t=()=>{b(""),d(null)},H=()=>{if(!n)return;const p=v&&g&&S?{type:S,value:g}:null,F=r!=null&&r.valid?{name:r.name||N.toUpperCase(),percentOff:r.percentOff,amountOff:r.amountOff}:null;a(n,p,r!=null&&r.valid?r.promotionCodeId:null,F)},R=p=>new Intl.NumberFormat("en-US",{style:"currency",currency:"EUR"}).format(p),Y=j.find(p=>p.type===S),K=M===0;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-xl bg-[hsl(var(--bg-secondary))] border border-[hsl(var(--border-subtle))] p-5",children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"heading-sm",children:E.name}),e.jsx("p",{className:"text-label mt-1",children:i===k.ANNUAL?"Annual subscription":"Monthly subscription"})]}),e.jsxs("div",{className:"text-right",children:[r!=null&&r.valid&&M!==u?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-label line-through",children:R(u)}),e.jsx("p",{className:"text-2xl font-bold text-emerald-400",children:K?"Free":R(M)}),K&&e.jsx("p",{className:"text-caption",children:"first month"})]}):e.jsx("p",{className:"heading-lg",children:R(u)}),!K&&e.jsxs("p",{className:"text-caption",children:["/",i===k.ANNUAL?"year":"month"]})]})]}),(r==null?void 0:r.valid)&&e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-emerald-500/15 text-emerald-400 text-xs font-medium",children:[e.jsx(de,{className:"icon-xs"}),r.name||N.toUpperCase(),r.percentOff&&` (-${r.percentOff}%)`,r.amountOff&&` (-${R(r.amountOff/100)})`]}),e.jsx("button",{type:"button",onClick:t,className:"text-xs text-subtle hover:text-red-400 transition-colors",children:"Remove"})]}),e.jsx("div",{className:"mt-4 pt-4 border-t border-[hsl(var(--border-subtle))]",children:e.jsxs("ul",{className:"space-y-2",children:[e.jsxs("li",{className:"flex items-center gap-2 text-body-sm",children:[e.jsx(Q,{className:"icon-sm text-emerald-400"}),e.jsxs("span",{children:[e.jsx("strong",{className:"text-white",children:E.monthlyTokens.toLocaleString()})," ","tokens/month"]})]}),e.jsxs("li",{className:"flex items-center gap-2 text-body-sm",children:[e.jsx(X,{className:"icon-sm text-emerald-400"}),e.jsxs("span",{children:["Up to"," ",e.jsx("strong",{className:"text-white",children:E.maxCap.toLocaleString()})," ","max cap"]})]}),e.jsxs("li",{className:"flex items-center gap-2 text-body-sm",children:[e.jsx(X,{className:"icon-sm text-emerald-400"}),e.jsx("span",{children:E.platforms.join(", ")})]})]})})]}),e.jsx("div",{className:"space-y-3",children:!m&&!(r!=null&&r.valid)?e.jsxs("button",{type:"button",onClick:()=>U(!0),className:"flex items-center gap-2 text-body-sm hover:text-white transition-colors",children:[e.jsx(de,{className:"icon-sm"}),e.jsx("span",{children:"Have a promo code?"})]}):r!=null&&r.valid?null:e.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border-default))] bg-[hsl(var(--bg-secondary))] p-4",children:[e.jsx("label",{className:"block text-xs font-medium text-body mb-2",children:"Promo Code"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:N,onChange:p=>{b(p.target.value.toUpperCase()),r!=null&&r.error&&d(null)},placeholder:"Enter code",className:"flex-1 px-3 py-2.5 rounded-lg bg-[hsl(var(--bg-secondary))] border border-[hsl(var(--border-default))] text-white text-sm placeholder:text-[hsl(var(--text-tertiary))] focus:outline-none focus:border-emerald-500/50",onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),B())}}),e.jsx("button",{type:"button",onClick:B,disabled:!N.trim()||h,className:"px-4 py-2.5 rounded-lg bg-[hsl(var(--bg-elevated))] hover:bg-white/[0.12] text-white text-sm font-medium border border-[hsl(var(--border-default))] transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:h?e.jsx($,{className:"icon-sm animate-spin"}):"Apply"})]}),(r==null?void 0:r.error)&&e.jsx("p",{className:"mt-2 text-xs text-red-400",children:r.error}),e.jsx("button",{type:"button",onClick:()=>{U(!1),b(""),d(null)},className:"mt-2 text-xs text-subtle hover:text-white transition-colors",children:"Cancel"})]})}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-white mb-3",children:"Billing address"}),e.jsx("div",{className:"rounded-xl border border-[hsl(var(--border-default))] bg-[hsl(var(--bg-secondary))] p-4",children:e.jsx(Re,{options:{mode:"billing",fields:{ph
16one:"never"},display:{name:"split"}},onChange:I})})]}),j.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{type:"button",onClick:()=>P(!v),className:"flex items-center gap-2 text-body-sm hover:text-white transition-colors",children:[e.jsx(De,{className:"icon-sm"}),e.jsx("span",{children:"Purchasing as a business?"}),e.jsx(Te,{className:T("icon-sm transition-transform",v&&"rotate-180")})]}),v&&e.jsxs("div",{className:"rounded-xl border border-[hsl(var(--border-default))] bg-[hsl(var(--bg-secondary))] p-4 space-y-4",children:[e.jsx("p",{className:"text-caption",children:"Enter your tax ID to potentially have tax exempted or reverse-charged."}),j.length>1&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-body mb-2",children:"Tax ID Type"}),e.jsx("select",{value:S,onChange:p=>o(p.target.value),className:"w-full px-3 py-2.5 rounded-lg bg-[hsl(var(--bg-secondary))] border border-[hsl(var(--border-default))] text-white text-sm focus:outline-none focus:border-emerald-500/50",children:j.map(p=>e.jsx("option",{value:p.type,children:p.label},p.type))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-body mb-2",children:(Y==null?void 0:Y.label)||"Tax ID"}),e.jsx("input",{type:"text",value:g,onChange:p=>C(p.target.value.toUpperCase()),placeholder:(Y==null?void 0:Y.placeholder)||"Enter your tax ID",className:"w-full px-3 py-2.5 rounded-lg bg-[hsl(var(--bg-secondary))] border border-[hsl(var(--border-default))] text-white text-sm placeholder:text-[hsl(var(--text-tertiary))] focus:outline-none focus:border-emerald-500/50"})]})]})]}),e.jsx("button",{type:"button",onClick:H,disabled:!f,className:T("w-full py-3.5 rounded-xl text-sm font-semibold transition-all duration-200","bg-emerald-500 hover:bg-emerald-400 text-white","shadow-lg shadow-emerald-500/25 hover:shadow-emerald-500/40","disabled:opacity-50 disabled:cursor-not-allowed","flex-center gap-2"),children:"Continue to payment"}),e.jsx("button",{type:"button",onClick:y,className:"w-full text-center text-label hover:text-white transition-colors",children:"Cancel"})]})},Ge=({isOpen:c,onClose:i,planId:a,interval:y=k.MONTHLY,onSuccess:n})=>{const[s,f]=l.useState("collecting_address"),[A,v]=l.useState(null),[P,g]=l.useState("payment"),[C,S]=l.useState(null),[o,N]=l.useState(null),[b,r]=l.useState(null),[d,h]=l.useState(null),[w,m]=l.useState(null),[U,E]=l.useState(null),[_,u]=l.useState(null),M=q[a];l.useEffect(()=>{c&&(Ie().then(N),f("collecting_address"),r(null),v(null),S(null),h(null),m(null),E(null),u(null),g("payment"))},[c,a,y]);const j=l.useCallback(async(F,z,te,oe)=>{var ee,ae;h(F),m(z),E(te),u(oe),f("loading"),r(null);try{const L=await J.createSubscription(a,y,F,z||void 0,te||void 0);L.discount&&u(L.discount),v(L.clientSecret),g(L.intentType),S({clientSecret:L.clientSecret,amountDue:L.amountDue,tax:L.tax,currency:L.currency,intentType:L.intentType}),f("ready")}catch(L){console.error("Subscription creation error:",L),r(((ae=(ee=L.response)==null?void 0:ee.data)==null?void 0:ae.message)||L.message||"Failed to initialize checkout"),f("error")}},[a,y]),I=()=>{f("success"),setTimeout(()=>{n==null||n(),i()},2e3)},B=F=>{r(F),f("error")},t=()=>{s!=="processing"&&i()},H=()=>{f("collecting_address"),v(null),S(null)},R=()=>{d?j(d,w,U,_):f("collecting_address")},Y=A?{clientSecret:A,appearance:{theme:"night",variables:{colorPrimary:"#10b981",colorBackground:"#18181b",colorText:"#ffffff",colorTextSecondary:"#a1a1aa",colorDanger:"#ef4444",fontFamily:"Inter, system-ui, sans-serif",borderRadius:"12px",spacingUnit:"4px"},rules:{".Input":{backgroundColor:"rgba(255, 255, 255, 0.06)",border:"1px solid rgba(255, 255, 255, 0.12)",padding:"12px 14px",color:"#ffffff"},".Input:focus":{borderColor:"#10b981",boxShadow:"0 0 0 1px rgba(16, 185, 129, 0.4)"},".Label":{color:"#ffffff",fontWeight:"500",marginBottom:"8px"},".Tab":{backgroundColor:"rgba(255, 255, 255, 0.04)",border:"1px solid rgba(255, 255, 255, 0.1)",color:"#a1a1aa"},".Tab:hover":{backgroundColor:"rgba(255, 255, 255, 0.08)",color:"#ffffff"},".Tab--selected":{backgroundColor:"rgba(16, 185, 129, 0.15)",borderColor:"#10b981",color:"#ffffff"},".Tab--selected:hover":{backgroundColor:"rgba(16, 185, 129, 0.2)",color:"#ffffff"},".TabIcon":{fill:"#a1a1aa"},".TabIcon--selected":{fill:"#10b981"},".Block":{backgroundColor:"rgba(255, 255, 255, 0.04)",borderColor:"rgba(255, 255, 255, 0.1)"},".CheckboxInput":{backgroundColor:"rgba(255, 255, 255, 0.06)",borderColor:"rgba(255, 255, 255, 0.2)"},".CheckboxInput--checked":{backgroundColor:"#10b981",borderColor:"#10b981"}}}}:void 0,K={appearance:{theme:"night",variables:{colorPrimary:"#10b981",colorBackgroun
16d:"#0a0a0b",colorText:"#ffffff",colorTextSecondary:"#a1a1aa",colorDanger:"#ef4444",fontFamily:"Inter, system-ui, sans-serif",borderRadius:"12px",spacingUnit:"4px"},rules:{".Input":{backgroundColor:"rgba(255, 255, 255, 0.03)",border:"1px solid rgba(255, 255, 255, 0.1)",padding:"12px 14px"},".Input:focus":{borderColor:"rgba(16, 185, 129, 0.5)",boxShadow:"0 0 0 1px rgba(16, 185, 129, 0.25)"},".Label":{color:"#ffffff",fontWeight:"500",marginBottom:"8px"}}},mode:"subscription",currency:"eur",amount:Math.round(xe(a,y===k.ANNUAL?"annual":"monthly")*100)},p=y===k.ANNUAL?"Billed annually · Save 20%":"Billed monthly · Cancel anytime";return e.jsx(Z,{appear:!0,show:c,as:l.Fragment,children:e.jsxs(G,{as:"div",className:"relative z-50",onClose:()=>{},children:[e.jsx(Z.Child,{as:l.Fragment,enter:"ease-out duration-500",enterFrom:"opacity-0",enterTo:"opacity-100",leave:"ease-in duration-200",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:e.jsx("div",{className:"fixed inset-0 bg-black/30"})}),e.jsx("div",{className:"fixed inset-0 overflow-y-auto",children:e.jsx("div",{className:"flex min-h-full items-center justify-center p-4",children:e.jsx(Z.Child,{as:l.Fragment,enter:"ease-out duration-300",enterFrom:"opacity-0 scale-95",enterTo:"opacity-100 scale-100",leave:"ease-in duration-200",leaveFrom:"opacity-100 scale-100",leaveTo:"opacity-0 scale-95",children:e.jsxs(G.Panel,{className:"w-full max-w-md transform rounded-xl bg-[hsl(var(--bg-primary))] border border-[hsl(var(--border-subtle))] shadow-2xl transition-all",children:[e.jsxs("div",{className:"flex-between px-6 py-4 border-b border-[hsl(var(--border-subtle))]",children:[e.jsxs("div",{children:[e.jsxs(G.Title,{className:"heading-sm",children:["Subscribe to ",M.name]}),e.jsx("p",{className:"text-label",children:p})]}),s!=="processing"&&e.jsx("button",{onClick:t,className:"p-2 rounded-lg text-subtle hover:text-white hover:bg-[hsl(var(--bg-tertiary))] transition-colors",children:e.jsx(re,{className:"icon-md"})})]}),e.jsxs("div",{className:"p-6",children:[s==="collecting_address"&&o&&e.jsx(ge,{stripe:o,options:K,children:e.jsx(We,{planId:a,interval:y,onAddressComplete:j,onClose:t})}),s==="collecting_address"&&!o&&e.jsxs("div",{className:"text-center py-12",children:[e.jsx($,{className:"icon-xl text-emerald-400 animate-spin mx-auto mb-4"}),e.jsx("p",{className:"text-label",children:"Loading checkout..."})]}),s==="loading"&&e.jsxs("div",{className:"text-center py-12",children:[e.jsx($,{className:"icon-xl text-emerald-400 animate-spin mx-auto mb-4"}),e.jsx("p",{className:"text-label",children:"Calculating tax and preparing checkout..."})]}),s==="error"&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"icon-3xl rounded-full bg-red-500/10 flex-center mx-auto mb-4",children:e.jsx(ne,{className:"icon-lg text-red-400"})}),e.jsx("h3",{className:"heading-sm mb-2",children:"Something went wrong"}),e.jsx("p",{className:"text-body-sm mb-6 max-w-sm mx-auto",children:b||"Failed to load checkout. Please try again."}),e.jsxs("div",{className:"flex-center gap-3",children:[e.jsxs("button",{onClick:t,className:"px-4 py-2.5 rounded-lg text-sm font-medium bg-[hsl(var(--bg-tertiary))] hover:bg-[hsl(var(--bg-elevated))] text-white border border-[hsl(var(--border-subtle))] transition-colors flex items-center gap-2",children:[e.jsx(we,{className:"icon-sm"}),"Go Back"]}),e.jsx("button",{onClick:R,className:"px-4 py-2.5 rounded-lg text-sm font-medium bg-emerald-500 hover:bg-emerald-400 text-white transition-colors",children:"Try Again"})]})]}),s==="success"&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"icon-3xl rounded-full bg-emerald-500/10 flex-center mx-auto mb-4",children:e.jsx(X,{className:"icon-lg text-emerald-400"})}),e.jsxs("h3",{className:"heading-sm mb-2",children:["Welcome to ",M.name,"!"]}),e.jsx("p",{className:"text-body-sm",children:"Your subscription is now active."})]}),s==="ready"&&A&&Y&&C&&d&&o&&e.jsx(ge,{stripe:o,options:Y,children:e.jsx(He,{planId:a,interval:y,billingAddress:d,taxId:w,promoDiscount:_,subscriptionData:C,onSuccess:I,onClose:t,onError:B,onBack:H})})]})]})})})})]})})},Xe=({isOpen:c,onClose:i,onSuccess:a,planName:y,periodEndDate:n,isCanceling:s})=>{const[f,A]=l.useState(!1),[v,P]=l.useState(null),g=o=>o?new Date(o).toLocaleDateString("en-US",{month:"long",day:"numeric",year:"numeric"}):"",C=async()=>{var o,N;A(!0),P(null);try{await J.cancelSubscription(),a()}catch(b){P(((N=(o=b.response)==null?void 0:o.data)==null?void 0:N.message)||"Failed to cancel subscription"),A(!1)}},S=async()=>{var o,N;A(!0),P(null);try{await J.reactivateSubscription(),a()}catch(b){P(((N=(o=b.response)==null?void 0:o.data)==null?void 0:N.message)||"Failed to reactivate subscription"),A(!1)}};return e.jsxs(G,{open:c,onClose:i,className:"relative z-50",children:[e.jsx(ye,{transition:!0,className:"modal-backdrop transition-opacity data-[closed]:opacity-0 data-[enter]:duration-200 data-[leave]:duration-150"}),e.jsx("div",{className:"fixed inset-0 flex-center p-4",children:e.jsx(ve,{transition:!0,className:"relative w-full max-w-md transform transition-all data-[closed]:scale-95 data-[closed]:opacity-0 data-[enter]:duration-200 data-[leave]:duration-150",children:e.jsxs("div",{className:"rounded-2xl bg-[hsl(var(--background))] border border-[hsl(var(--border-subtle))] shadow-2xl overflow-hidden",children:[e.jsxs("div",{className:"relative px-6 py-5 border-b border-[hsl(var(--border-subtle))]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:T("icon-2xl rounded-full flex-center",s?"bg-emerald-500/15":"bg-
16amber-500/15"),children:s?e.jsx(Ye,{className:"icon-md text-emerald-400"}):e.jsx(ke,{className:"icon-md text-amber-400"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"heading-sm",children:s?"Reactivate Subscription":"Cancel Subscription"}),e.jsxs("p",{className:"text-label",children:[y," plan"]})]})]}),e.jsx("button",{onClick:i,className:"absolute top-5 right-5 p-1.5 rounded-lg text-subtle hover:text-white hover:bg-[hsl(var(--bg-tertiary))] transition-colors",children:e.jsx(re,{className:"icon-md"})})]}),e.jsxs("div",{className:"p-6",children:[s?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-body",children:["Your subscription is scheduled to end on"," ",e.jsx("span",{className:"text-white font-medium",children:g(n)}),". Would you like to continue your subscription?"]}),e.jsx("div",{className:"p-4 rounded-xl bg-emerald-500/10 border border-emerald-500/20",children:e.jsxs("p",{className:"text-sm text-emerald-400",children:["Your ",y," benefits will continue uninterrupted and you'll be billed on your next billing date."]})})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-body",children:["Are you sure you want to cancel your subscription? You'll retain access to ",y," features until"," ",e.jsx("span",{className:"text-white font-medium",children:g(n)}),"."]}),e.jsx("div",{className:"p-4 rounded-xl bg-amber-500/10 border border-amber-500/20",children:e.jsx("p",{className:"text-sm text-amber-400",children:"After this date, your account will be downgraded to the Free plan with limited features."})})]}),v&&e.jsx("div",{className:"mt-4 p-3 rounded-lg bg-red-500/10 border border-red-500/20",children:e.jsx("p",{className:"text-sm text-red-400",children:v})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-[hsl(var(--border-subtle))] flex gap-3",children:[e.jsx("button",{onClick:i,disabled:f,className:"flex-1 py-2.5 rounded-xl text-sm font-medium text-body hover:text-white hover:bg-[hsl(var(--bg-tertiary))] transition-colors disabled:opacity-50",children:s?"Keep Canceled":"Keep Subscription"}),e.jsx("button",{onClick:s?S:C,disabled:f,className:T("flex-1 py-2.5 rounded-xl text-sm font-semibold transition-all flex-center gap-2",s?"bg-emerald-500 hover:bg-emerald-400 text-white":"bg-red-500/20 hover:bg-red-500/30 text-red-400","disabled:opacity-50 disabled:cursor-not-allowed"),children:f?e.jsx($,{className:"icon-sm animate-spin"}):s?"Reactivate":"Cancel Subscription"})]})]})})})]})},Ke={topup_500:14.99,topup_1000:29.99,topup_2000:59.99,topup_3000:99.99,topup_5000:165.99,topup_10000:299.99},Ve=({isOpen:c,onClose:i,onSuccess:a})=>{const{navigate:y}=Ae(),[n,s]=l.useState("selecting"),[f,A]=l.useState([]),[v,P]=l.useState(null),[g,C]=l.useState(0),[S,o]=l.useState(null),[N,b]=l.useState(!1),[r,d]=l.useState(!0),[h,w]=l.useState(null),m=f[g]??null,U=m?Ke[m.id]??0:0;l.useEffect(()=>{c&&(s("selecting"),o(null),b(!1),C(0),w(null),d(!0),le.getPackages().then(j=>{A(j.packages),P(j.costs)}).catch(j=>{o(j.message||"Failed to load packages"),s("error")}).finally(()=>d(!1)))},[c]);const E=async()=>{var j,I,B;if(m){s("processing"),o(null),b(!1);try{const t=await le.buyTopUp(m.id);w({tokenAmount:t.tokenAmount,newBalance:t.newBalance}),s("success"),setTimeout(()=>{a(t.newBalance)},2e3)}catch(t){const H=(j=t.response)==null?void 0:j.status,R=((B=(I=t.response)==null?void 0:I.data)==null?void 0:B.message)||t.message||"Something went wrong";H===402?(o(R),b(!0)):o(R),s("error")}}},_=()=>{n!=="processing"&&i()},u=()=>C(j=>Math.max(0,j-1)),M=()=>C(j=>Math.min(f.length-1,j+1));return e.jsx(Z,{appear:!0,show:c,as:l.Fragment,children:e.jsxs(G,{as:"div",className:"relative z-50",onClose:_,children:[e.jsx(Z.Child,{as:l.Fragment,enter:"ease-out duration-300",enterFrom:"opacity-0",enterTo:"opacity-100",leave:"ease-in duration-200",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm"})}),e.jsx("div",{className:"fixed inset-0 overflow-y-auto",children:e.jsx("div",{className:"flex min-h-full items-center justify-center p-4",children:e.jsx(Z.Child,{as:l.Fragment,enter:"ease-out duration-300",enterFrom:"opacity-0 scale-95",enterTo:"opacity-100 scale-100",leave:"ease-in duration-200",leaveFrom:"opacity-100 scale-100",leaveTo:"opacity-0 scale-95",children:e.jsxs(G.Panel,{className:"w-full max-w-md transform rounded-xl bg-[hsl(var(--bg-primary))] border border-[hsl(var(--border-subtle))] shadow-2xl transition-all",children:[e.jsxs("div",{className:"flex-between px-6 py-4 border-b border-[hsl(var(--border-subtle))]",children:[e.jsxs("div",{children:[e.jsxs(G.Title,{className:"heading-sm flex items-center gap-2",children:[e.jsx(Q,{className:"icon-md text-emerald-400"}),"Buy Tokens"]}),e.jsx("p",{className:"text-label",children:"One-time purchase · Credited instantly"})]}),n!=="processing"&&e.jsx("button",{onClick:_,className:"p-2 rounded-lg text-subtle hover:text-white hover:bg-[hsl(var(--bg-tertiary))] transition-colors",children:e.jsx(re,{className:"icon-md"})})]}),e.jsxs("div",{className:"p-6",children:[(n==="selecting"||n==="confirming")&&e.jsx("div",{className:"space-y-6",children:r?e.jsx("div",{className:"flex-center py-12",children:e.jsx($,{className:"icon-lg text-emerald-400 animate-spin"})}):f.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-2xl bg-gradient-to-b from-emerald-500/[0.08] to-transparent border border-emerald-500/20 p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{className:"icon-sm text-emerald-400"}),e.jsx("span",{className:"text-sm font-medium text-white",children:"Token amount"})]}),e.jsx("span",{className:"text-xs text-subtle",children:"one-time"})]}),e.jsxs("div",{className:"flex items-center justify-center gap-4",children:[e.jsx("button",{type:"button",onClick:u,disabled:g===0||n==="confirming",className:T("w-10 h-10 rounded-xl flex-center transition-colors",g===0||n==="confirming"?"text-subtle/30 curs
16or-not-allowed":"text-white bg-[hsl(var(--bg-elevated))] hover:bg-white/[0.12] border border-[hsl(var(--border-default))]"),children:e.jsx(Pe,{className:"w-4 h-4"})}),e.jsxs("div",{className:"text-center min-w-[160px]",children:[e.jsx("span",{className:"text-4xl font-bold text-white tabular-nums",children:m==null?void 0:m.tokenAmount.toLocaleString()}),e.jsx("p",{className:"text-sm text-subtle mt-1",children:"tokens"}),U>0&&e.jsxs("div",{className:"mt-3",children:[e.jsxs("p",{className:"text-xl font-bold text-emerald-400",children:["â¬",U.toFixed(2)]}),e.jsxs("p",{className:"text-xs text-subtle mt-0.5",children:["â¬",(U/((m==null?void 0:m.tokenAmount)||1)).toFixed(3),"/token"]})]})]}),e.jsx("button",{type:"button",onClick:M,disabled:g===f.length-1||n==="confirming",className:T("w-10 h-10 rounded-xl flex-center transition-colors",g===f.length-1||n==="confirming"?"text-subtle/30 cursor-not-allowed":"text-white bg-[hsl(var(--bg-elevated))] hover:bg-white/[0.12] border border-[hsl(var(--border-default))]"),children:e.jsx(Ee,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"flex justify-center gap-1.5 mt-4",children:f.map((j,I)=>e.jsx("button",{onClick:()=>n!=="confirming"&&C(I),className:T("w-2 h-2 rounded-full transition-all",I===g?"bg-emerald-400 w-4":"bg-white/20 hover:bg-white/40")},I))})]}),n==="confirming"&&e.jsx("div",{className:"rounded-xl bg-[hsl(var(--bg-secondary))] border border-[hsl(var(--border-subtle))] p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ne,{className:"icon-md text-emerald-400 flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm text-white font-medium",children:["Your card on file will be charged â¬",U.toFixed(2)]}),e.jsxs("p",{className:"text-xs text-subtle mt-1",children:[m==null?void 0:m.tokenAmount.toLocaleString()," tokens will be credited instantly to your account."]})]})]})}),n==="selecting"&&v&&e.jsxs("div",{className:"rounded-xl bg-white/[0.03] border border-[hsl(var(--border-subtle))] p-4",children:[e.jsx("p",{className:"text-xs font-medium text-subtle mb-2",children:"Token costs per operation"}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 text-xs text-body",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Audit per platform"}),e.jsxs("span",{className:"text-white font-medium",children:[v.perPlatformDefault," token"]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Audit per platform (Claude)"}),e.jsxs("span",{className:"text-white font-medium",children:[v.perPlatformClaude," tokens"]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Content generation / optimization"}),e.jsxs("span",{className:"text-white font-medium",children:[v.perContentPiece," tokens"]})]})]})]}),n==="selecting"?e.jsxs("button",{onClick:()=>s("confirming"),className:T("w-full py-3.5 rounded-xl text-sm font-semibold transition-all duration-200","bg-emerald-500 hover:bg-emerald-400 text-white","shadow-lg shadow-emerald-500/25 hover:shadow-emerald-500/40","flex-center gap-2"),children:["Buy ",m==null?void 0:m.tokenAmount.toLocaleString()," tokens · â¬",U.toFixed(2)]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{onClick:E,className:T("w-full py-3.5 rounded-xl text-sm font-semibold transition-all duration-200","bg-emerald-500 hover:bg-emerald-400 text-white","shadow-lg shadow-emerald-500/25 hover:shadow-emerald-500/40","flex-center gap-2"),children:["Confirm · â¬",U.toFixed(2)]}),e.jsx("button",{onClick:()=>s("selecting"),className:"w-full text-center text-label hover:text-white transition-colors",children:"Cancel"})]}),n==="selecting"&&e.jsx("p",{className:"text-caption text-center",children:"Tokens are credited instantly and never expire."})]}):e.jsx("p",{className:"text-center text-body py-8",children:"No packages available."})}),n==="processing"&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx($,{className:"icon-xl text-emerald-400 animate-spin mx-auto mb-4"}),e.jsx("h3",{className:"heading-sm mb-2",children:"Processing payment..."}),e.jsx("p",{className:"text-body-sm",children:"Charging your card on file."})]}),n==="success"&&h&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"icon-3xl rounded-full bg-emerald-500/10 flex-center mx-auto mb-4",children:e.jsx(X,{className:"icon-lg text-emerald-400"})}),e.jsx("h3",{className:"heading-sm mb-2",children:"Tokens Added!"}),e.jsxs("p",{className:"text-body-sm",children:[h.tokenAmount.toLocaleStr
16ing()," tokens credited."]}),e.jsxs("p",{className:"text-sm text-white font-medium mt-2",children:["New balance: ",h.newBalance.toLocaleString()," tokens"]})]}),n==="error"&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"icon-3xl rounded-full bg-red-500/10 flex-center mx-auto mb-4",children:e.jsx(ne,{className:"icon-lg text-red-400"})}),e.jsx("h3",{className:"heading-sm mb-2",children:N?"Payment Failed":"Something went wrong"}),e.jsx("p",{className:"text-body-sm mb-6 max-w-sm mx-auto",children:S}),e.jsxs("div",{className:"flex-center gap-3",children:[N?e.jsxs("button",{onClick:()=>{i(),y("/settings/billing")},className:"px-4 py-2.5 rounded-lg text-sm font-medium bg-emerald-500 hover:bg-emerald-400 text-white transition-colors flex items-center gap-2",children:[e.jsx(Ne,{className:"icon-sm"}),"Update Payment Method"]}):e.jsx("button",{onClick:()=>s("selecting"),className:"px-4 py-2.5 rounded-lg text-sm font-medium bg-emerald-500 hover:bg-emerald-400 text-white transition-colors",children:"Try Again"}),e.jsx("button",{onClick:_,className:"px-4 py-2.5 rounded-lg text-sm font-medium bg-[hsl(var(--bg-tertiary))] hover:bg-[hsl(var(--bg-elevated))] text-white border border-[hsl(var(--border-subtle))] transition-colors",children:"Close"})]})]})]})]})})})})]})})},qe=20,ns=()=>{const{user:c,refreshUser:i}=Fe(),{subscription:a,isLoading:y,error:n,billingInterval:s}=_e(c),[f,A]=l.useState(!1),[v,P]=l.useState(!1),[g,C]=l.useState(!1),[S,o]=l.useState(!1),[N,b]=l.useState(null),[r,d]=l.useState(k.MONTHLY),[h,w]=l.useState(k.MONTHLY),[m,U]=l.useState(null),[E,_]=l.useState(null),u=(a==null?void 0:a.planId)||W.FREE,M=q[u],j=u===W.FREE,I=!!(a!=null&&a.stripeSubscriptionId),B=(a==null?void 0:a.cancelAtPeriodEnd)===!0,{t,i18n:H}=Le(),R=Ue(H.language);l.useEffect(()=>{be({eventName:"Subscription Page Viewed",distinct_id:c==null?void 0:c.email,eventArgs:{userId:c==null?void 0:c._id,current_plan:u}}).catch(console.error)},[]),l.useEffect(()=>{c&&(async()=>{try{const[O,D]=await Promise.all([le.getBalance(),le.getPackages()]);U(O),_(D.costs)}catch{}})()},[c]);const Y=(()=>{const x=pe.getUpgradeOptions(u);return I&&u!==W.FREE&&u!==W.ENTERPRISE&&s===k.MONTHLY&&h===k.ANNUAL?[u,...x]:x})(),K=x=>{if(be({eventName:"Plan Clicked",distinct_id:c==null?void 0:c.email,eventArgs:{userId:c==null?void 0:c._id,plan:x,billing_interval:h,current_plan:u}}).catch(console.error),x===W.ENTERPRISE){window.open("https://calendly.com/oltre-info/30min","_blank");return}b(x),d(h),I?P(!0):A(!0)},p=async()=>{await(i==null?void 0:i()),A(!1),b(null)},F=async()=>{await new Promise(x=>setTimeout(x,1500)),await(i==null?void 0:i()),P(!1),b(null)},z=async()=>{await new Promise(x=>setTimeout(x,1e3)),await(i==null?void 0:i()),C(!1)},te=x=>{m&&U({...m,balance:x}),o(!1)},oe=x=>{if(!x&&j)return e.jsx("span",{className:"px-3 py-1 text-xs font-medium rounded-full bg-[hsl(var(--bg-tertiary))] text-body border border-[hsl(var(--border-subtle))]",children:t("subscription.freePlan")});const O={[V.ACTIVE]:{label:t(B?"subscription.canceling":"subscription.active"),className:B?"bg-amber-500/15 text-amber-400 border-amber-500/25":"bg-emerald-500/15 text-emerald-400 border-emerald-500/25"},[V.TRIALING]:{label:t("subscription.trial"),className:"bg-blue-500/15 text-blue-400 border-blue-500/25"},[V.PAST_DUE]:{label:t("subscription.pastDue"),className:"bg-amber-500/15 text-amber-400 border-amber-500/25"},[V.CANCELED]:{label:t("subscription.canceled"),className:"bg-red-500/15 text-red-400 border-red-500/25"},[V.INCOMPLETE]:{label:t("subscription.incomplete"),className:"bg-yellow-500/15 text-yellow-400 border-yellow-500/25"},[V.INCOMPLETE_EXPIRED]:{label:t("subscription.expired"),className:"bg-red-500/15 text-red-400 border-red-500/25"},[V.UNPAID]:{label:t("subscription.unpaid"),className:"bg-red-500/15 text-red-400 border-red-500/25"}},D=x?O[x]:null;return D?e.jsx("span",{className:T("px-3 py-1 text-xs font-medium rounded-full border",D.className),children:D.label}):null},ee=x=>x?new Date(x).toLocaleDateString("en-US",{month:"long",day:"numeric",year:"numeric"}):null,ae=x=>x===null?t("subscription.custom"):x===0?t("subscription.free"):`â¬${x}`,L=x=>
16x.toLocaleString();if(y)return e.jsx("div",{className:"flex-center py-24",children:e.jsx($,{className:"icon-lg text-emerald-400 animate-spin"})});const Ce=h===k.ANNUAL?M.annualPrice:M.monthlyPrice,ue=m?Math.min(100,Math.round((m.monthlyAllowance-m.balance)/m.monthlyAllowance*100)):0;return e.jsxs("div",{className:"space-y-12",children:[N&&!I&&e.jsx(Ge,{isOpen:f,onClose:()=>{A(!1),b(null)},planId:N,interval:r,onSuccess:p}),N&&I&&e.jsx($e,{isOpen:v,onClose:()=>{P(!1),b(null)},planId:N,interval:r,onSuccess:F}),e.jsx(Xe,{isOpen:g,onClose:()=>C(!1),onSuccess:z,planName:M.name,periodEndDate:a==null?void 0:a.currentPeriodEnd,isCanceling:B}),e.jsx(Ve,{isOpen:S,onClose:()=>o(!1),onSuccess:te}),n&&e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-xl bg-red-500/10 border border-red-500/20 text-red-400 text-sm",children:[e.jsx(ne,{className:"icon-sm flex-shrink-0"}),e.jsx("span",{children:n.message})]}),e.jsxs("section",{children:[e.jsxs("div",{className:"section-header",children:[e.jsx("h2",{className:"heading-md",children:t("subscription.currentPlan")}),oe(a==null?void 0:a.status)]}),e.jsxs("div",{className:"relative overflow-hidden rounded-2xl bg-gradient-to-br from-white/[0.03] to-transparent border border-[hsl(var(--border-subtle))]",children:[e.jsx("div",{className:"absolute -top-24 -right-24 w-48 h-48 bg-emerald-500/10 rounded-full blur-3xl pointer-events-none"}),e.jsx("div",{className:"relative p-8",children:e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-start justify-between gap-6",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"flex items-baseline gap-3 mb-2",children:e.jsx("h3",{className:"heading-xl",children:M.name})}),e.jsx("p",{className:"text-lg text-body",children:j?t("subscription.free"):u===W.ENTERPRISE?t("subscription.customPricing"):e.jsxs(e.Fragment,{children:["â¬",Ce,"/",s===k.ANNUAL?t("subscription.year"):t("subscription.month"),s===k.ANNUAL&&M.annualPrice&&e.jsxs("span",{className:"text-label ml-2",children:["(â¬",Math.round(M.annualPrice/12),"/mo)"]})]})}),m&&e.jsxs("div",{className:"mt-5 p-4 rounded-xl bg-white/[0.03] border border-[hsl(var(--border-subtle))]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{className:"icon-sm text-emerald-400"}),e.jsx("span",{className:"text-sm font-medium text-white",children:t("subscription.tokenBalance")})]}),e.jsx("span",{className:"text-2xl font-bold text-white tabular-nums",children:L(m.balance)})]}),e.jsx("div",{className:"w-full h-2 rounded-full bg-white/[0.06] mb-2",children:e.jsx("div",{className:T("h-full rounded-full transition-all duration-500",ue>80?"bg-amber-500":"bg-emerald-500"),style:{width:`${Math.max(2,100-ue)}%`}})}),e.jsxs("div",{className:"flex justify-between text-xs text-subtle",children:[e.jsx("span",{children:t("subscription.monthlyAllowance",{amount:L(m.monthlyAllowance)})}),e.jsx("span",{children:t("subscription.maxCap",{amount:L(m.maxCap)})})]}),I&&e.jsx("button",{onClick:()=>o(!0),className:"mt-3 px-5 py-2 rounded-xl text-sm font-medium bg-emerald-500 hover:bg-emerald-400 text-white transition-colors",children:t("subscription.buyMoreTokens")})]}),E&&e.jsxs("div",{className:"mt-3 flex flex-wrap gap-x-5 gap-y-1.5 text-xs text-subtle",children:[e.jsx("span",{children:t("subscription.auditCost",{amount:E.perPlatformDefault})}),e.jsx("span",{children:t("subscription.auditClaudeCost",{amount:E.perPlatformClaude})}),e.jsx("span",{children:t("subscription.contentCost",{amount:E.perContentPiece})})]}),B&&(a==null?void 0:a.currentPeriodEnd)&&e.jsxs("div",{className:"mt-4 flex items-start gap-3 p-3 rounded-lg bg-amber-500/10 border border-amber-500/20",children:[e.jsx(ke,{className:"icon-sm text-amber-400 flex-shrink-0 mt-0.5"}),e.jsxs("p",{className:"text-sm text-amber-400",children:[t("subscription.endsOn")," ",ee(a.currentPeriodEnd)]})]})]}),e.jsxs("div",{className:"flex flex-col items-start lg:items-end gap-4",children:[!j&&(a==null?void 0:a.currentPeriodEnd)&&e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-subtle mb-1",children:t(B?"subscription.accessUntil":"subscription.renewsOn")}),e.jsx("p",{className:"text-sm text-white font-medium",children:ee(a==null?void 0:a.currentPeriodEnd)})]}),I&&e.jsx("button",{onClick:()=>C(!0),className:T("px-4 py-2.5 rounded-lg text-sm font-medium transition-colors",B?"bg-emerald-500/15 text-emerald-400 hover:bg-emerald-500/25":"text-subtle hover:text-red-400 hover:bg-red-500/10"),children:t(B?"subscription.reactivate":"subscription.cancelSubscription")})]})]})})]})]}),pe.canUpgrade(u)&&e.jsxs("section",{children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-end justify-between gap-4 mb-8",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"heading-md",children:t("subscription.upgradeTitle")}),e.jsx("p",{className:"mt-1 text-subtle",children:t("subscription.upgradeSubtitle")})]}),e.jsxs("div",{className:"flex items-center p-1 rounded-xl bg-[hsl(var(--bg-tertiary))] border border-[hsl(var(--border-subtle))]",children:[e.jsx("button",{onClick:()=>w(k.MONTHLY),className:T("px-4 py-2 rounded-lg text-sm font-medium transition-all",h===k.MONTHLY?"bg-[hsl(var(--bg-elevated))] text-white":"text-subtle hover:text-white"),children:t("subscription.monthly")}),e.jsxs("button",{onClick:()=>w(k.ANNUAL),className:T("px-4 py-2 rounded-lg text-sm font-medium transition-all flex items-center gap-2",h===k.ANNUAL?"bg-[hsl(var(--bg-elevated))] text-white":"text-subtle hover:text-white"),children:[t("subscription.annual"),e.jsxs("span",{className:"px-2 py-0.5 text-[10px] font-bold uppercase tracking-wide bg-emerald-500 text-white rounded-md",children:["-",qe,"%"]})]})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6",children:Y.map(x=>{const O=q[x],D=x===W.PRO,se=x===W.ENTERPRISE,ce=h===k.ANNUAL?O.annualPrice:O.monthlyPrice,Se=x===u;return e.jsxs("div",{className:T("group relative rounded-2xl transition-all duration-300 h-full",D?"bg-gradient-to-b from-emerald-500/[0.12] to-emerald-500/[0.04] border-2 border-emerald-500/40 shadow-[0_0_60px_-15px_rgba(16,185,129,0.3)]":"bg-[hsl(var(--bg-secondary))] border border-[hsl(var(--border-subtle))] hover:border-[hsl(var(--border-strong))] hover:bg-[hsl(var(--bg-tertiary))]"),children:[D&&e.jsx("div",{className:"absolute -top-4 left-1/2 -translate-x-1/2 z-10",children:e.jsx("span",{className:"px-4 py-1.5 bg-emerald-500 text-white text-xs font-bold uppercase tracking-wider rounded-full shadow-lg whitespace-nowrap",children:t("subscription.mostPopular")})}),e.jsxs("div",{className:"p-8 pt-10 h-full flex flex-col",children:[e.jsx("h3",{className:T("text-lg font-semibold mb-1",D?"text-emerald-400":"text-white"),children:O.name}),e.jsx("p",{className:"text-xs text-subtle text-white mb-3",children:t(`subscription.planTagline.${x}`)}),e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"flex items-baseline gap-1",children:[e.jsx("span",{className:"text-4xl font-bold text-white",children:ae(ce)}),!se&&e.jsxs("span",{className:"text-subtle",children:["/",h===k.ANNUAL?t("subscription.year"):t("subscription.mo")]})]}),h===k.ANNUAL&&!se&&ce!==null&&e.jsxs("p",{className:"text-caption mt-1",children:["â¬",Math.round(ce/12),t("subscription.billedAnnually")]})]}),e.jsxs("ul",{className:"space-y-3.5 mb-6 flex-grow",children:[e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx(Q,{className:T("icon-md mt-0.5 flex-shrink-0",D?"text-emerald-400":"text-emerald-400/70")}),e.jsxs("span",{className:"text-body",children:[e.jsx("strong",{className:"text-white",children:O.monthlyTokens!==null?L(O.monthlyTokens):t("subscription.custom")})," ",t("subscription.tokensPerMonth")]})]}),e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx(X,{className:T("icon-md mt-0.5 flex-shrink-0",D?"text-emerald-400":"text-emerald-400/70")}),e.jsx("span",{className:"text-body",children:O.platforms.length===1?O.platforms[0]:t("subscription.aiPlatforms",{count:O.platforms.length})})]}),!se&&e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx(X,{className:T("icon-md mt-0.5 flex-shrink-0",D?"text-emerald-400":"text-emerald-400/70")}),e.jsx("span",{className:"text-body",children:t("subscription.topUpsAvailable")})]}),se&&e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx(X,{className:"icon-md mt-0.5 flex-shrink-0 text-emerald-400/70"}),e.jsx("span",{className:"text-body",children:t("subscription.customSla")})]})]}),e.jsx("button",{onClick:()=>K(x),className:T("w-full py-3.5 rounded-xl text-sm font-semibold transition-all duration-200 flex-center gap-2 mt-auto",D?"bg-emerald-500 hover:bg-emerald-400 text-white shadow-lg shadow-emerald-500/25 hover:shadow-emerald-500/40":"bg-[hsl(var(--bg-elevated))] hover:bg-white/[0.12] text-white border border-[hsl(var(--border-default))]"),children:se?t("subscription.contactSales"):Se?e.jsxs(e.Fragment,{children:[t("subscription.switchTo")," ",h===k.ANNUAL?t("subscription.annual"):t("subscription.monthly"),e.jsx(ie,{className:"icon-sm"})]}):e.jsxs(e.Fragment,{children:[t("subscription.get")," ",O.name,e.jsx(ie,{className:"icon-sm"})]})})]})]},x)})}),e.jsx("p",{className:"text-center text-label mt-10",children:t("subscription.cancelAnytime")}),e.jsxs("p",{className:"text-center text-caption mt-3",children:[t("subscription.agreeToTerms")," ",e.jsx("a",{href:fe("terms",R),target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-white transition-colors",children:t("subscription.termsOfService")})," ",t("subscription.and")," ",e.jsx("a",{href:fe("privacy",R),target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-white transition-colors",children:t("subscription.privacyPolicy")})]})]})]})};export{ns 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.