PageSourceSearch

https://tesana.com/assets/BillingPage-D_Fe9Dq6.js

js tesana.com collected 2026-10-09 22:40:34 UTC 44,773 bytes, 1 lines download raw bytes

1import{j as e,u as X,A as Z,m as ee}from"./vendor-motion-hRg_q8lq.js";import{r as x,i as Ge}from"./vendor-react-E98sgxjj.js";import{b as ye,u as V,a as Ne}from"./vendor-query-bOUN_gKe.js";import{u as ve}from"./useLocaleNavigate-BNriJdRU.js";import{r as we,P as ze,U as Oe}from"./index-i1nPji9k.js";import{du as C}from"./vendor-fa-Bn2dnpnC.js";import{d as U,b5 as te,u as P,aI as _e,d2 as qe,d3 as Ke,b as ce,ae as M,d4 as Ve,d5 as Ye,d6 as Qe,d7 as He,d8 as re,d9 as We,da as ke,db as Ce,a6 as le,dc as Se,cJ as Je,dd as Xe,ah as Pe,ak as Ze,K as et,b0 as De,a9 as ge,de as tt,df as nt,A as se,dg as rt}from"./index-BKzE8EQ8.js";import{p as de,a as ne,P as Ee,S as st}from"./planPerks-uEcgEuVc.js";import{S as Y,C as $}from"./SettingsRowCard--YUcmpPt.js";import{D as at}from"./socialLinks-DmmZmq5v.js";import{m as it}from"./pricingExperiments-zMZby8z7.js";import"./plans-CbMJY2XS.js";import{u as lt}from"./organization-BuGhuc22.js";import{U as ot}from"./UsageBar-ChIMgZII.js";import{S as ct}from"./SettingsPageShell-wmP4-RpH.js";import"./paywall-CG7xVZtx.js";const oe=["reminder","credits","reason","discount","fixGame","confirm"];function ae(r){return oe.indexOf(r)+1}function O({eyebrow:r,eyebrowIcon:n=["far","lock"],title:t,description:s,children:i,back:d,next:a,error:o}){return e.jsxs("div",{children:[e.jsxs("p",{className:"flex items-center gap-2 pr-10 text-xs text-muted-foreground",children:[e.jsx(C,{icon:n,className:"text-[11px]","aria-hidden":!0}),r]}),e.jsx("h2",{className:"mt-2 pr-10 text-lg text-foreground font-medium",children:t}),s&&e.jsx("p",{className:"mt-1.5 text-sm text-muted-foreground",children:s}),i&&e.jsx("div",{className:"mt-6",children:i}),o&&e.jsx("p",{className:"mt-3 text-sm text-red-500",children:o}),(d||a)&&e.jsxs("div",{className:"mt-6 flex items-center justify-between gap-3 border-t border-border pt-5",children:[d?e.jsx("button",{type:"button",onClick:d.onClick,disabled:d.disabled,className:"h-9 rounded-md px-3 text-sm text-muted-foreground transition-colors hover:bg-foreground
1/6 hover:text-foreground disabled:opacity-40 cursor-pointer",children:d.label}):e.jsx("span",{}),a&&e.jsx("button",{type:"button",onClick:a.onClick,disabled:a.disabled,className:U("h-9 rounded-md px-4 text-sm transition-colors cursor-pointer disabled:cursor-not-allowed disabled:opacity-40",a.tone==="danger"?"bg-red-500/15 text-red-500 hover:bg-red-500/25":"bg-foreground/6 text-foreground hover:bg-foreground/10"),children:a.label})]})]})}function Q({children:r,onClick:n,disabled:t,busy:s,icon:i}){return e.jsx(te,{variant:"themed",onClick:n,disabled:t||s,className:"h-11 w-full rounded-md text-base font-medium",children:s?e.jsx("span",{className:"size-4 animate-spin rounded-full border-2 border-current border-t-transparent"}):e.jsxs(e.Fragment,{children:[i&&e.jsx(C,{icon:i,className:"text-sm","aria-hidden":!0}),r]})})}const dt=86400;function W(r,n,t={month:"short",day:"numeric"}){return new Date(r*1e3).toLocaleDateString(n,t)}function ut({data:r,busy:n,error:t,onRemind:s,onBack:i,onContinue:d}){const{t:a,i18n:o}=P(["cancellation","settings"]),g=r.reminder,l=g.renewal_at??r.current_period_end??null,m=g.remind_at??null,c=Math.floor(Date.now()/1e3),u=l?Math.max(1,Math.ceil((l-c)/dt)):null,f=l&&m&&l>c?Math.min(68,Math.max(42,(m-c)/(l-c)*100)):62,L=de(r.tier),p=L?ne(L,r.credits.monthly_grant).slice(0,3):[];return e.jsxs(O,{eyebrow:a("cancellation:reminder.eyebrow",{days:g.days_before??3}),title:a("cancellation:reminder.title"),description:a("cancellation:reminder.description"),error:t,back:{label:a("cancellation:common.goBack"),onClick:i,disabled:n},next:{label:a("cancellation:common.continueToCancel"),onClick:d,disabled:n},children:[e.jsxs("div",{className:"rounded-md border border-border bg-foreground
1/[0.03] p-4",children:[u!=null&&e.jsxs("p",{className:"flex items-center gap-2 text-sm text-foreground",children:[e.jsx(C,{icon:["far","clock"],className:"text-xs text-muted-foreground","aria-hidden":!0}),e.jsx("span",{children:we(a("cancellation:reminder.daysLeft",{count:u}),"font-semibold text-foreground")})]}),p.length>0&&e.jsx("ul",{className:"mt-3 grid grid-cols-1 gap-2 sm:grid-cols-3",children:p.map(N=>{const D=`settings:billingPage.highlights.${N.id}`,v=a(D,{...N.values,defaultValue:a(`settings:billingPage.perks.${N.id}.title`,N.values)}),F=N.variant?a(`${D}_${N.variant}`,{...N.values,defaultValue:v}):v;return e.jsxs("li",{className:"flex items-start gap-2 rounded-md border border-border bg-card px-3 py-2.5 text-xs leading-4 text-foreground",children:[e.jsx(C,{icon:N.icon,className:"mt-0.5 shrink-0 text-muted-foreground","aria-hidden":!0}),e.jsx("span",{className:"min-w-0",children:F})]},N.id)})})]}),l&&m&&e.jsxs("div",{className:"mt-6 px-1",children:[e.jsxs("div",{className:"relative h-1 rounded-full bg-foreground
1/10",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 w-[6%] rounded-full bg-foreground"}),e.jsx(ie,{pct:0,label:a("cancellation:reminder.markers.today"),sub:a("cancellation:reminder.markers.youStay"),tone:"strong"}),e.jsx(ie,{pct:f,label:W(m,o.language,{month:"short",day:"numeric"}),sub:a("cancellation:reminder.markers.reminder"),tone:"accent"}),e.jsx(ie,{pct:100,label:W(l,o.language,{month:"short",day:"numeric"}),sub:a("cancellation:reminder.markers.renewal"),tone:"muted"})]}),e.jsx("div",{className:"h-12"})]}),e.jsx("p",{className:"mt-2 text-center text-sm text-muted-foreground",children:m?a("cancellation:reminder.helper",{count:g.days_before??3,date:W(m,o.language)}):a("cancellation:reminder.helperNoDate")}),e.jsx("div",{className:"mt-4",children:e.jsx(Q,{onClick:s,busy:n,icon:["far","calendar"],children:m?a("cancellation:reminder.cta",{date:W(m,o.language,{month:"short",day:"numeric"})}):a("cancellation:reminder.ctaNoDate")})})]})}function ie({pct:r,label:n,sub:t,tone:s}){return e.jsxs("div",{className:"absolute top-1/2 flex -translate-x-1/2 -translate-y-1/2 flex-col items-center",style:{left:`${r}%`},children:[e.jsx("span",{className:U("size-2.5 rounded-full ring-4 ring-card",s==="strong"&&"bg-foreground",s==="accent"&&"bg-green-500",s==="muted"&&"bg-muted-foreground")}),e.jsxs("span",{className:"absolute top-4 flex w-28 flex-col items-center text-center",children:[e.jsx("span",{className:"text-xs text-foreground",children:n}),e.jsx("span",{className:U("text-[11px]",s==="accent"?"text-green-500":"text-muted-foreground"),children:t})]})]})}function mt({data:r,onKeep:n,onBack:t,onContinue:s}){const{t:i,i18n:d}=P("cancellation"),a=r.credits,o=Math.max(0,a.balance),g=r.current_period_end?new Date(r.current_period_end*1e3).toLocaleDateString(d.language,{month:"long",day:"numeric"}):null;return e.jsxs(O,{eyebrow:i("credits.eyebrow"),title:i("credits.title"),description:g?i("credits.description",{date:g}):i("credits.descriptionNoDate"),back:{label:i("common.goBack"),onClick:t},next:{label:i("common.continueToCancel"),onClick:s},children:[e.jsxs("div",{className:"rounded-md border border-border bg-card px-4 py-6 text-center",children:[e.jsx("p",{className:"text-h2-sm text-foreground tabular-nums",children:o.toLocaleString()}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:i("credits.creditsLeft")}),e.jsxs("div",{className:"mx-auto mt-5 grid max-w-sm grid-cols-2 divide-x divide-border border-t border-border pt-6",children:[e.jsx(pe,{icon:["far","wand-magic-sparkles"],value:`≈ ${a.approx_prompts.toLocaleString()}`,label:i("credits.prompts",{count:a.approx_prompts})}),e.jsx(pe,{icon:["far","coin-front"],value:`≈ ${_e(a.value_usd,"USD")}`,label:i("credits.value")})]})]}),e.jsxs("p",{className:"mt-4 flex items-start gap-2 text-xs text-muted-foreground",children:[e.jsx(C,{icon:["far","calendar"],className:"mt-1 text-xs","aria-hidden":!0}),i("credits.rollover")]}),e.jsx("div",{className:"mt-5",children:e.jsx(Q,{onClick:n,children:i("credits.cta")})})]})}function pe({icon:r,value:n,label:t}){return e.jsxs("div",{className:"px-3",children:[e.jsxs("p",{className:"flex items-center justify-center gap-1.5 text-base text-foreground tabular-nums",children:[e.jsx(C,{icon:r,className:"text-xs text-muted-foreground","aria-hidden":!0}),n]}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:t})]})}const xt=["A","B","C","D","E","F","G","H"];function gt({reasons:r=[...qe],selected:n,detail:t,minChars:s,busy:i,error:d,onSelect:a,onDetailChange:o,onBack:g,onContinue:l}){const{t:m}=P("cancellation"),c=X(),u=x.useRef(null),f=t.trim().length,L=!!n&&f>=s&&!i;return x.useEffect(()=>{if(!n)return;const p=window.setTimeout(()=>u.current?.focus(),c?0:180);return()=>window.clearTimeout(p)},[n,c]),e.jsxs(O,{eyebrow:m("reason.eyebrow"),eyebrowIcon:["far","comment"],title:m("reason.title"),description:m("reason.description"),error:d,back:{label:m("common.back"),onClick:g,disabled:i},next:{label:m("common.continueToCancel"),onClick:l,disabled:!L},children:[e.jsx("ul",{className:"flex flex-col gap-2",role:"radiogroup","aria-label":m("reason.title"),children:r.map((p,N)=>{const D=n===p;return e.jsx("li",{children:e.jsxs("button",{type:"button",role:"radio","aria-checked":D,onClick:()=>a(p),className:U("flex h-12 w-full items-center gap-3 rounded-md border px-3 text-left text-sm transition-colors cursor-pointer",D?"border-foreground bg-foreground
1/[0.04] text-foreground":"border-border bg-foreground/[0.02] text-foreground hover:border-foreground/30 hover:bg-foreground/[0.04]"),children:[e.jsx("span",{className:U("flex size-6 shrink-0 items-center justify-center rounded-sm text-xs font-medium transition-colors",D?"bg-foreground text-background":"bg-foreground/8 text-muted-foreground"),children:D?e.jsx(C,{icon:["far","check"],className:"text-[10px]","aria-hidden":!0}):xt[N]??"·"}),m(`reason.options.${p}`)]})},p)})}),e.jsx(Z,{initial:!1,children:n&&e.jsx(ee.div,{initial:c?!1:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:c?{opacity:0}:{height:0,opacity:0},transition:{duration:.25,ease:[.16,1,.3,1]},className:"overflow-hidden",children:e.jsxs("div",{className:"pt-4",children:[e.jsx("label",{htmlFor:"cancel-reason-detail",className:"text-sm text-foreground",children:m("reason.detailLabel")}),e.jsx("textarea",{id:"cancel-reason-detail",ref:u,value:t,onChange:p=>o(p.target.value),placeholder:m("reason.detailPlaceholder"),rows:3,maxLength:2e3,className:"mt-2 w-full resize-none rounded-md border border-border bg-transparent p-3 text-sm text-foreground placeholder:text-muted-foreground transition-colors focus:border-foreground
1/40 focus:outline-none"}),e.jsxs("p",{className:U("mt-1 text-right text-xs tabular-nums",f>=s?"text-muted-foreground":"text-red-500"),children:[Math.min(f,s),"/",s]})]})},"detail")})]})}function pt({data:r,busy:n,error:t,onAccept:s,onBack:i,onContinue:d}){const{t:a}=P("cancellation"),o=r.retention_discount.percent,l=r.billing_interval==="year"?"discount.periodYear":"discount.periodMonth";return e.jsx(O,{eyebrow:a("discount.eyebrow"),eyebrowIcon:["far","tag"],title:a("discount.title",{percent:o}),description:a("discount.description",{percent:o,period:a(l)}),error:t,back:{label:a("common.back"),onClick:i,disabled:n},next:{label:a("common.continueToCancel"),onClick:d,disabled:n},children:e.jsxs("div",{className:"relative rounded-lg border-2 border-transparent bg-card p-6 text-center",children:[e.jsx(Ke,{}),e.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground",children:a("discount.offerLabel")}),e.jsx("p",{className:"mt-2 text-h2-sm text-foreground",children:a("discount.offerHeadline",{percent:o,period:a(l)})}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:a("discount.offerBody")}),e.jsx("div",{className:"mt-5",children:e.jsx(Q,{onClick:s,busy:n,children:a("discount.cta")})})]})})}const ht=[{icon:["far","hand-pointer"],key:"tap"},{icon:["far","envelope"],key:"email"},{icon:["far","wand-magic-sparkles"],key:"fixed"}];function ft({busy:r,error:n,onAccept:t,onBack:s,onContinue:i}){const{t:d}=P("cancellation");return e.jsxs(O,{eyebrow:d("fixGame.eyebrow"),eyebrowIcon:["far","wand-magic-sparkles"],title:d("fixGame.title"),description:d("fixGame.description"),error:n,back:{label:d("common.back"),onClick:s,disabled:r},next:{label:d("common.cancelAnyway"),onClick:i,disabled:r},children:[e.jsx("ol",{className:"flex flex-col gap-3",children:ht.map((a,o)=>e.jsxs("li",{className:"flex items-start gap-3 rounded-md border border-border bg-foreground
1/[0.02] px-4 py-3",children:[e.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center rounded-md bg-foreground/6 text-xs text-muted-foreground",children:e.jsx(C,{icon:a.icon,"aria-hidden":!0})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm text-foreground",children:[e.jsxs("span",{className:"text-muted-foreground",children:[o+1,"."]})," ",d(`fixGame.steps.${a.key}.title`)]}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:d(`fixGame.steps.${a.key}.body`)})]})]},a.key))}),e.jsx("div",{className:"mt-5",children:e.jsx(Q,{onClick:t,busy:r,icon:["far","wand-magic-sparkles"],children:d("fixGame.cta")})}),e.jsx("p",{className:"mt-3 text-center text-xs text-muted-foreground",children:d("fixGame.footnote")})]})}function bt({data:r,planName:n,busy:t,error:s,onKeep:i,onBack:d,onConfirm:a}){const{t:o,i18n:g}=P("cancellation"),l=r.current_period_end?new Date(r.current_period_end*1e3).toLocaleDateString(g.language,{year:"numeric",month:"long",day:"numeric"}):null,m=Math.max(0,r.credits.balance),c=[m>0?o("confirm.loseCredits",{credits:m.toLocaleString()}):null,o("confirm.loseRollover"),o("confirm.loseFeatures",{plan:n}),o("confirm.toFree")].filter(u=>!!u);return e.jsxs(O,{eyebrow:o("confirm.eyebrow"),eyebrowIcon:["far","exclamation-triangle"],title:o("confirm.title",{plan:n}),description:l?o("confirm.description",{date:l}):o("confirm.descriptionNoDate"),error:s,back:{label:o("common.back"),onClick:d,disabled:t},next:{label:o(t?"common.processing":"confirm.cta"),onClick:a,disabled:t,tone:"danger"},children:[e.jsx("ul",{className:"flex flex-col gap-2.5 rounded-md border border-border bg-foreground
1/[0.02] p-4",children:c.map(u=>e.jsxs("li",{className:"flex items-start gap-2.5 text-sm text-muted-foreground",children:[e.jsx(C,{icon:["far","xmark"],className:"mt-1 w-3 shrink-0 text-xs text-red-500","aria-hidden":!0}),e.jsx("span",{children:u})]},u))}),e.jsx("div",{className:"mt-5",children:e.jsx(Q,{onClick:i,disabled:t,children:o("confirm.keep",{plan:n})})})]})}const jt=[.16,1,.3,1];function yt(r){const n=(r??"").trim();return n?n.charAt(0).toUpperCase()+n.slice(1):""}function Nt({isOpen:r,onClose:n}){const{t,i18n:s}=P("cancellation"),{refreshUser:i,user:d}=ce(),a=X(),o=ye(),[g,l]=x.useState("reminder"),[m,c]=x.useState(1),[u,f]=x.useState(null),[L,p]=x.useState(!1),[N,D]=x.useState(!1),[v,F]=x.useState(null),[I,G]=x.useState(""),[b,A]=x.useState(null),[w,R]=x.useState(null),[j,S]=x.useState(!1),[B,_]=x.useState(null),q=x.useRef(!1),z=x.useRef(new Set),h=u?.flow_id??null,K=yt(u?.tier??d?.subscription_tier),H=x.useCallback(()=>{l("reminder"),c(1),f(null),p(!1),D(!1),F(null),G(""),A(null),R(null),S(!1),_(null),q.current=!1,z.current=new Set},[]);x.useEffect(()=>{!r||q.current||(q.current=!0,p(!0),D(!1),M.cancelFlow.start().then(k=>{f(k),Ve({flow_id:k.flow_id,tier:k.tier}),k.reminder?.available||l("credits")}).catch(()=>D(!0)).finally(()=>p(!1)))},[r]),x.useEffect(()=>{!r||h===null||b||z.current.has(g)||(z.current.add(g),Ye({flow_id:h,step:ae(g)}),(g==="discount"||g==="fixGame")&&Qe({flow_id:h,reason:v??void 0,ordered_offers:[g==="discount"?"discount":"fix_my_game"],discount_available:u?.discount_available}))},[r,h,g,b,v,u?.discount_available]);const T=x.useCallback(k=>{_(null),c(oe.indexOf(k)>=oe.indexOf(g)?1:-1),l(k)},[g]),y=x.useCallback(()=>{n(),window.setTimeout(H,300)},[n,H]),E=x.useCallback(()=>{h!==null&&!b&&!j&&(He({flow_id:h,step:ae(g)}),M.cancelFlow.update(h,{outcome:`aborted_step_${ae(g)}`}).catch(()=>{})),y()},[h,b,j,g,y]),ue=x.useCallback(()=>u?.discount_available?"discount":"fixGame",[u?.discount_available]),Le=x.useCallback(()=>{h===null||j||(S(!0),_(null),re({flow_id:h,offer:"reminder"}),M.cancelFlow.remind(h).then(k=>{R(k.reminder.remind_at),A("saved_reminder")}).catch(k=>_(k?.response?.data?.error||t("errors.generic"))).finally(()=>S(!1)))},[h,j,t]),Te=x.useCallback(()=>{if(h===null||!v||j)return;const k=u?.reason_detail_min_chars??5;I.trim().length<k||(S(!0),_(null),We({flow_id:h,reason:v,has_other_text:!0}),M.cancelFlow.update(h,{cancel_reason:v,cancel_reason_other:I.trim()}).then(()=>T(ue())).catch(Ie=>_(Ie?.response?.data?.error||t("errors.generic"))).finally(()=>S(!1)))},[h,v,I,j,u?.reason_detail_min_chars,T,ue,t]),Ue=x.useCallback(()=>{h===null||j||(S(!0),_(null),re({flow_id:h,offer:"discount",reason:v??void 0}),M.cancelFlow.save(h,"discount").then(()=>{i().catch(()=>{}),A("saved_discount")}).catch(k=>_(k?.response?.data?.error||t("errors.discountUnavailable"))).finally(()=>S(!1)))},[h,j,v,i,t]),Ae=x.useCallback(()=>{h===null||j||(S(!0),_(null),re({flow_id:h,offer:"fix_my_game",reason:v??void 0}),M.cancelFlow.save(h,"fix_my_game").then(()=>A("saved_fix_my_game")).catch(k=>_(k?.response?.data?.error||t("errors.generic"))).finally(()=>S(!1)))},[h,j,v,t]),Re=x.useCallback(()=>{h===null||j||(S(!0),_(null),M.cancelFlow.confirm(h).then(()=>{i().catch(()=>{}),ke(o),o.invalidateQueries({queryKey:Ce}),A("cancelled")}).catch(k=>_(k?.response?.data?.error||t("errors.generic"))).finally(()=>S(!1)))},[h,j,i,o,t]),me=u?.current_period_end?new Date(u.current_period_end*1e3).toLocaleDateString(s.language,{year:"numeric",month:"long",day:"numeric"}):null,xe=w?new Date(w*1e3).toLocaleDateString(s.language,{month:"long",day:"numeric"}):null,Be=r&&b!==null&&b!=="cancelled",Fe=r&&b==="cancelled",Me=r&&b===null,$e=()=>{if(L)return e.jsx("div",{className:"flex h-56 items-center justify-center",children:e.jsx("span",{className:"size-7 animate-spin rounded-full border-2 border-foreground
1/30 border-t-foreground"})});if(N||!u)return e.jsxs("div",{className:"py-6 text-center",children:[e.jsx("p",{className:"text-base text-foreground",children:t("errors.generic")}),e.jsx("button",{type:"button",onClick:y,className:"mt-6 h-10 rounded-md bg-foreground px-4 text-sm text-background transition-opacity hover:opacity-85 cursor-pointer",children:t("common.close")})]});switch(g){case"reminder":return e.jsx(ut,{data:u,busy:j,error:B,onRemind:Le,onBack:E,onContinue:()=>T("credits")});case"credits":return e.jsx(mt,{data:u,onKeep:E,onBack:u.reminder?.available?()=>T("reminder"):E,onContinue:()=>T("reason")});case"reason":return e.jsx(gt,{reasons:u.reasons,selected:v,detail:I,minChars:u.reason_detail_min_chars??5,busy:j,error:B,onSelect:F,onDetailChange:G,onBack:()=>T("credits"),onContinue:Te});case"discount":return e.jsx(pt,{data:u,busy:j,error:B,onAccept:Ue,onBack:()=>T("reason"),onContinue:()=>T("fixGame")});case"fixGame":return e.jsx(ft,{busy:j,error:B,onAccept:Ae,onBack:()=>T(u.discount_available?"discount":"reason"),onContinue:()=>T("confirm")});case"confirm":return e.jsx(bt,{data:u,planName:K,busy:j,error:B,onKeep:E,onBack:()=>T("fixGame"),onConfirm:Re})}};return e.jsxs(e.Fragment,{children:[e.jsx(le,{open:Me,onClose:E,locked:j,size:"md",bodyClassName:"relative mt-0",className:"overflow-hidden",children:e.jsx(Z,{mode:"popLayout",initial:!1,custom:m,children:e.jsx(ee.div,{custom:m,initial:a?!1:{opacity:0,x:24*m},animate:{opacity:1,x:0},exit:a?{opacity:0}:{opacity:0,x:-24*m},transition:{duration:.22,ease:jt},children:$e()},L?"loading":N?"error":g)})}),e.jsx(Se,{open:Be,onClose:y,icon:b==="saved_reminder"?["far","envelope"]:b==="saved_discount"?["far","badge-percent"]:["far","wand-magic-sparkles"],title:b==="saved_reminder"?xe?t("saved.reminderTitle",{date:xe}):t("saved.reminderTitleNoDate"):b==="saved_discount"?t("saved.discountTitle",{percent:u?.retention_discount.percent??15}):t("saved.fixGameTitle"),subtitle:b==="saved_reminder"?t("saved.reminderBody",{count:u?.reminder?.days_before??3}):t(b==="saved_discount"?"saved.discountBody":"saved.fixGameBody"),ctaLabel:t(b==="saved_reminder"?"saved.reminderCta":"saved.cta")}),e.jsxs(le,{open:Fe,onClose:y,size:"sm",hideClose:!0,className:"text-center",bodyClassName:"mt-0",children:[e.jsx("div",{className:"mx-auto mb-5 flex size-16 items-center justify-center rounded-full bg-foreground
1/5",children:e.jsx(C,{icon:["far","circle-check"],className:"text-2xl text-muted-foreground","aria-hidden":!0})}),e.jsx("h2",{className:"text-lg text-foreground",children:t("cancelled.title")}),e.jsx("p",{className:"mx-auto mt-2 max-w-sm text-sm text-muted-foreground",children:me?t("cancelled.body",{plan:K||t("cancelled.yourPlan"),date:me}):t("cancelled.bodyNoDate")}),e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:t("cancelled.comeBack")}),e.jsx("button",{type:"button",onClick:y,className:"mt-6 h-10 w-full rounded-md bg-foreground text-sm text-background transition-opacity hover:opacity-85 cursor-pointer",children:t("cancelled.done")})]})]})}function vt({className:r}){const{t:n}=P("checkout"),{openAutoTopUp:t}=Je(),{data:s,isLoading:i}=Xe();if(i||!s||!s.available)return null;const d=s.enabled&&s.status==="active",a=s.status==="paused_payment_failed"||s.status==="paused_cap_reached",o=d?n("autoTopUp.rowOn",{credits:(s.reload_credits??0).toLocaleString(),threshold:(s.trigger_threshold_credits??0).toLocaleString()}):n(a?"autoTopUp.rowPaused":"autoTopUp.rowOff");return e.jsxs("div",{className:U("flex items-center justify-between gap-4 rounded-md border border-border bg-card p-6",r),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex items-center gap-2 text-base text-foreground",children:[n("autoTopUp.title"),a&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-amber-600",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-amber-500"})," ",n("autoTopUp.paused")]})]}),e.jsx("p",{className:"mt-1 max-w-[408px] text-sm text-muted-foreground",children:we(o,"font-semibold text-foreground")})]}),e.jsxs("button",{type:"button",onClick:t,className:U("inline-flex h-9 shrink-0 items-center justify-center gap-2 rounded-md px-3 text-sm transition-colors cursor-pointer",d||a?"bg-foreground
1/6 text-foreground hover:bg-foreground/10":"bg-foreground text-background hover:opacity-85"),children:[e.jsx(C,{icon:["far","gear"],className:"text-sm","aria-hidden":!0}),n(d||a?"autoTopUp.manage":"autoTopUp.setUp")]})]})}function wt({isOpen:r,onClose:n}){const{t,i18n:s}=P(["checkout","settings"]),{user:i,refreshUser:d}=ce(),a=ye(),[o,g]=x.useState(null),[l,m]=x.useState(null),c=de(i?.subscription_tier),{data:u}=V({...Pe(i?.pricing_region),enabled:r}),{data:f}=V({queryKey:["subscription-status"],queryFn:M.getSubscription,enabled:r&&!!i,staleTime:3e4}),L=c?u?.[c]?.name??c.charAt(0).toUpperCase()+c.slice(1):"",p=Number(i?.usage?.edit_limit??u?.[c??"pro"]?.credits??0),N=c?ne(c,p).slice(0,Math.min(4,Ee)):[],D=f?.interval??"month",v=f?.amount_minor!=null&&f.currency?Ze(f.amount_minor,f.currency):c&&u?.[c]?_e(D==="year"&&u[c].annual_price?Number(u[c].annual_price):Number(u[c].monthly_price??0),u?.currency??"USD"):null,F=f?.current_period_end??(i?.subscription_current_period_end?Math.floor(new Date(i.subscription_current_period_end).getTime()/1e3):null),I=F?new Date(F*1e3).toLocaleDateString(s.language,{year:"numeric",month:"long",day:"numeric"}):null,G=Ne({mutationFn:M.reactivateSubscription,onSuccess:async w=>{g(w.current_period_end??F),d().catch(()=>{}),ke(a),a.invalidateQueries({queryKey:["subscription-status"]}),a.invalidateQueries({queryKey:Ce})},onError:w=>m(w?.response?.data?.error||t("checkout:renew.error"))}),b=x.useCallback(()=>{n(),window.setTimeout(()=>{g(null),m(null)},300)},[n]),A=o?new Date(o*1e3).toLocaleDateString(s.language,{month:"long",day:"numeric"}):null;return e.jsxs(e.Fragment,{children:[e.jsxs(le,{open:r&&o===null,onClose:b,locked:G.isPending,size:"sm",bodyClassName:"mt-0",className:"text-center",children:[e.jsx("div",{className:"mx-auto flex size-12 items-center justify-center rounded-md bg-foreground
1/6 text-foreground",children:e.jsx(C,{icon:["far","gem"],className:"text-lg","aria-hidden":!0})}),e.jsx("h2",{className:"mt-5 text-balance text-lg text-foreground",children:t("checkout:renew.title")}),e.jsx("p",{className:"mt-1.5 text-sm text-muted-foreground",children:t("checkout:renew.subtitle")}),e.jsx(te,{variant:"themed",onClick:()=>G.mutate(),disabled:G.isPending,className:"mt-6 h-11 w-full rounded-md text-base font-medium",children:G.isPending?e.jsx("span",{className:"size-4 animate-spin rounded-full border-2 border-current border-t-transparent"}):t("checkout:renew.cta")}),e.jsx("p",{className:"mx-auto mt-3 max-w-[340px] text-xs text-muted-foreground",children:I?t("checkout:renew.disclaimer",{date:I}):t("checkout:renew.disclaimerNoDate")}),l&&e.jsx("p",{className:"mt-2 text-sm text-red-500",children:l}),c&&e.jsxs("div",{className:"mt-6 rounded-md border border-border bg-foreground/[0.03] p-5 text-left",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-lg text-foreground",children:L}),e.jsx(ze,{tone:"neutral",size:"sm",children:t("checkout:renew.yourPlan")})]}),v&&e.jsxs("p",{className:"mt-1 flex items-baseline gap-1.5",children:[e.jsx("span",{className:"text-h3-sm text-foreground",children:v}),e.jsx("span",{className:"text-sm text-muted-foreground",children:t(D==="year"?"checkout:renew.perYear":"checkout:renew.perMonth")})]}),e.jsx("ul",{className:"mt-4 flex flex-col gap-2.5 border-t border-border pt-4",children:N.map(w=>{const R=`settings:billingPage.highlights.${w.id}`,j=t(R,{...w.values,defaultValue:t(`settings:billingPage.perks.${w.id}.title`,w.values)}),S=w.variant?t(`${R}_${w.variant}`,{...w.values,defaultValue:j}):j;return e.jsxs("li",{className:"flex items-start gap-2 text-sm text-foreground",children:[e.jsx(C,{icon:["far","check"],className:"mt-1 w-3 shrink-0 text-xs text-green-500","aria-hidden":!0}),e.jsx("span",{children:S})]},w.id)})})]})]}),e.jsx(Se,{open:r&&o!==null,onClose:b,icon:["far","party-horn"],title:t("checkout:renew.doneTitle"),subtitle:A?t("checkout:renew.doneBody",{plan:L,date:A}):t("checkout:renew.doneBodyNoDate",{plan:L}),ctaLabel:t("checkout:renew.doneCta")})]})}function _t({plan:r,planName:n,monthlyCredits:t,status:s,cancelScheduled:i=!1,onUpgrade:d,onRenew:a}){const{t:o}=P("settings"),g=r?ne(r,t).slice(0,Ee):[];return e.jsx(Y,{className:U(i&&"border-red-500/40 shadow-[0_0_0_1px_rgba(239,68,68,0.15),0_0_32px_-8px_rgba(239,68,68,0.35)]"),title:o("billingPage.plan.title",{plan:n}),description:s,action:i&&a?e.jsx(te,{variant:"themed",onClick:a,className:"h-10 rounded-md px-4 text-sm font-medium",children:o("billingPage.plan.renew")}):e.jsx($,{tone:"primary",onClick:d,children:o(r==="ultra"?"billingPage.plan.viewPlans":"billingPage.plan.upgrade")}),children:g.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"my-4 h-px bg-border","aria-hidden":!0}),e.jsx("ul",{className:"grid grid-cols-1 gap-x-8 gap-y-4 pt-0.5 sm:grid-cols-2",children:g.map(l=>{const m=`billingPage.highlights.${l.id}`,c=o(m,{...l.values,defaultValue:o(`billingPage.perks.${l.id}.title`,l.values)}),u=l.variant?o(`${m}_${l.variant}`,{...l.values,defaultValue:c}):c;return e.jsxs("li",{className:"flex items-start gap-2 text-sm leading-5 text-muted-foreground",children:[e.jsx(C,{icon:["far","check"],className:"mt-1 w-3 shrink-0 text-xs text-green-500","aria-hidden":!0}),e.jsx("span",{className:"min-w-0",children:u})]},l.id)})})]})})}function kt({available:r,allowance:n,cadence:t,onBuyCredits:s,id:i}){const{t:d}=P("settings"),a=n>0?Math.min(100,Math.max(0,r/n*100)):0,o=r<0;return e.jsxs("div",{id:i,className:"scroll-mt-24 rounded-md border border-border bg-card p-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:d(t==="monthly"?"billingPage.credits.monthly":"billingPage.credits.daily")}),e.jsxs("p",{className:"mt-1 text-base text-foreground",children:[e.jsx("span",{className:U(o&&"text-red-500"),children:r.toLocaleStr
1ing()}),n>0&&e.jsxs("span",{className:"text-muted-foreground",children:[" / ",n.toLocaleString()]})]})]}),e.jsxs($,{tone:"secondary",onClick:s,children:[e.jsx(C,{icon:["far","plus"],className:"text-sm","aria-hidden":!0}),d("billingPage.credits.buy")]})]}),e.jsx("div",{className:"mt-5 h-1.5 overflow-hidden rounded-full bg-foreground/10",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(a),children:e.jsx("div",{className:U("h-full rounded-full transition-[width] duration-500",o?"bg-red-500":"bg-foreground"),style:{width:`${o?100:a}%`}})})]})}const J=new Intl.NumberFormat("en-US"),Ct=5;function St({rollup:r,loading:n,onOpenUsage:t,onOpenGame:s,id:i}){const{t:d}=P("settings"),a=r?r.per_game.reduce((l,m)=>l+m.charges,0):null,o=[{key:"credits",label:d("billingPage.usage.creditsUsed"),value:r?J.format(r.total_credits):null},{key:"prompts",label:d("billingPage.usage.prompts"),value:a!=null?J.format(a):null},{key:"streak",label:d("billingPage.usage.longestStreak"),value:r?d("billingPage.usage.streakDays",{count:r.streak.longest_streak}):null}],g=(r?.per_game??[]).slice(0,Ct);return e.jsxs("div",{id:i,className:"scroll-mt-24",children:[e.jsx("div",{className:"grid grid-cols-3 gap-4",children:o.map(l=>e.jsxs("div",{className:"rounded-md border border-border bg-card px-3 py-4 text-center",children:[l.value==null?e.jsx("div",{className:"mx-auto h-8 w-16 animate-pulse rounded bg-foreground
1/10"}):e.jsx("p",{className:"text-2xl leading-8 text-foreground tabular-nums",children:l.value}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:l.label})]},l.key))}),e.jsx("div",{className:"mt-4 overflow-hidden rounded-md border border-border bg-card",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-xs text-muted-foreground",children:[e.jsx("th",{className:"px-4 pb-2 pt-3 font-normal",children:d("billingPage.usage.colGame")}),e.jsx("th",{className:"px-4 pb-2 pt-3 text-right font-normal",children:d("billingPage.usage.colCredits")}),e.jsx("th",{className:"px-4 pb-2 pt-3 text-right font-normal",children:d("billingPage.usage.colPrompts")})]})}),e.jsxs("tbody",{children:[n&&Array.from({length:3}).map((l,m)=>e.jsx("tr",{className:"border-t border-border",children:e.jsx("td",{className:"px-4 py-2.5",colSpan:3,children:e.jsx("div",{className:"h-5 w-2/3 animate-pulse rounded bg-foreground/10"})})},m)),!n&&g.map((l,m)=>{const c=l.game_id!=null&&!l.deleted;return e.jsxs("tr",{onClick:c?()=>s(l.game_id):void 0,className:c?"cursor-pointer border-t border-border transition-colors hover:bg-foreground
1/[0.03]":"border-t border-border",children:[e.jsx("td",{className:"max-w-0 truncate px-4 py-2.5 text-foreground",children:l.name||d("billingPage.usage.untitled")}),e.jsx("td",{className:"px-4 py-2.5 text-right text-foreground tabular-nums",children:J.format(l.credits)}),e.jsx("td",{className:"px-4 py-2.5 text-right text-foreground tabular-nums",children:J.format(l.charges)})]},l.game_id??`deleted-${m}`)}),!n&&g.length===0&&e.jsx("tr",{className:"border-t border-border",children:e.jsx("td",{className:"px-4 py-6 text-center text-sm text-muted-foreground",colSpan:3,children:d("billingPage.usage.empty")})})]})]})}),e.jsx(Y,{className:"mt-4",title:d("billingPage.usage.fullTitle"),description:d("billingPage.usage.fullDescription"),action:e.jsx($,{tone:"quiet",onClick:t,children:d("billingPage.usage.open")})})]})}function Pt(r,n=4){return r?r.per_game.filter(t=>t.game_id!=null&&!t.deleted).slice(0,n).map(t=>({id:t.game_id,name:t.name,category:t.category??null,posterUrl:t.poster_url??t.poster_sm_url??null})):[]}const he=72;function Dt({games:r,loading:n,onOpen:t}){const{t:s}=P("settings"),i=x.useRef(null),[d,a]=x.useState(!1),[o,g]=x.useState(()=>new Set),l=x.useCallback(()=>{const c=i.current;c&&a(c.scrollLeft+c.clientWidth>=c.scrollWidth-1)},[]);x.useEffect(()=>{l();const c=i.current;if(!c)return;const u=new ResizeObserver(l);return u.observe(c),()=>u.disconnect()},[l,r.length]);const m=n?[null,null,null]:r;return e.jsx("div",{ref:i,onScroll:l,className:"scrollbar-hide -mx-4 flex gap-4 overflow-x-auto px-4 pb-1 md:mx-0 md:px-0",style:d?void 0:{maskImage:`linear-gradient(to right, black calc(100% - ${he}px), transparent)`,WebkitMaskImage:`linear-gradient(to right, black calc(100% - ${he}px), transparent)`},children:m.map((c,u)=>c?e.jsxs("button",{type:"button",onClick:()=>t(c.id),"aria-label":s("billingPage.rewind.open",{name:c.name}),className:"group relative h-[400px] w-[230px] shrink-0 overflow-hidden rounded-md border border-border bg-card text-left cursor-pointer",children:[c.posterUrl&&!o.has(c.id)?e.jsx("img",{src:c.posterUrl,alt:"",loading:"lazy",draggable:!1,onError:()=>g(f=>new Set(f).add(c.id)),className:"absolute inset-0 size-full select-none object-cover transition-transform duration-500 ease-out group-hover:scale-[1.03]"}):e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gradient-to-b from-foreground
1/10 to-foreground/[0.02]",children:e.jsx("span",{className:"text-h2-sm text-foreground/40",children:c.name.trim().charAt(0).toUpperCase()||"?"})}),e.jsx("div",{className:"absolute inset-x-0 bottom-0 h-20 bg-gradient-to-t from-black/60 to-black/0","aria-hidden":!0}),e.jsxs("div",{className:"absolute inset-x-0 bottom-0 p-4 text-white [text-shadow:0_4px_4px_rgba(0,0,0,0.25)]",children:[e.jsx("p",{className:"truncate text-base",children:c.name}),e.jsx("p",{className:U("mt-1 truncate text-sm text-white/80",!c.category&&"invisible"),children:c.category??"·"})]})]},c.id):e.jsx("div",{className:"h-[400px] w-[230px] shrink-0 animate-pulse rounded-md border border-border bg-foreground/5"},`skeleton-${u}`))})}function fe({icon:r,title:n,description:t,action:s}){return e.jsxs("li",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-md bg-foreground/6 text-sm text-muted-foreground",children:e.jsx(C,{icon:r,"aria-hidden":!0})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-base text-foreground",children:n}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:t})]}),e.jsx("div",{className:"shrink-0",children:s})]})}const Et=[.16,1,.3,1];function Lt({plan:r,monthlyCredits:n,onShow:t,manage:s}){const{t:i}=P("settings"),d=X(),[a,o]=x.useState(!1),g=ne(r,n);return e.jsxs("div",{className:"rounded-md border border-border bg-card p-6",children:[e.jsx("ul",{className:"flex flex-col gap-6",children:g.map(l=>{const m=l.variant?`_${l.variant}`:"";return e.jsx(fe,{icon:l.icon,title:i(`billingPage.perks.${l.id}.title${m}`,{...l.values,defaultValue:i(`billingPage.perks.${l.id}.title`,l.values)}),description:i(`billingPage.perks.${l.id}.description${m}`,{...l.values,defaultValue:i(`billingPage.perks.${l.id}.description`,l.values)}),action:e.jsx($,{tone:"quiet",onClick:()=>t(l),children:i("billingPage.perks.show")})},l.id)})}),s&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"my-6 h-px bg-border","aria-hidden":!0}),e.jsx("ul",{children:e.jsx(fe,{icon:["far","circle-info"],title:i("billingPage.manage.title"),description:i("billingPage.manage.description"),action:e.jsx($,{tone:"quiet",onClick:()=>o(l=>!l),"aria-expanded":a,"aria-controls":"billing-manage-subscription",children:i(a?"billingPage.manage.hide":"billingPage.perks.show")})})}),e.jsx(Z,{initial:!1,children:a&&e.jsx(ee.div,{id:"billing-manage-subscription",initial:d?!1:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:d?{opacity:0}:{height:0,opacity:0},transition:{duration:.3,ease:Et},className:"overflow-hidden",children:e.jsx("div",{className:"mt-6 rounded-md border border-border bg-foreground
1/[0.03] p-4",children:s.cancelScheduled?e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-lg text-foreground",children:i("billingPage.plan.title",{plan:s.planName})}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:s.periodEnd?i("billingPage.manage.cancelScheduled",{plan:s.planName,date:s.periodEnd}):i("billingPage.manage.cancelScheduledNoDate",{plan:s.planName})})]}),s.onRenew&&e.jsx(te,{variant:"themed",onClick:s.onRenew,className:"h-10 shrink-0 rounded-md px-4 text-sm font-medium",children:i("billingPage.plan.renew")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-start gap-3 rounded-md bg-red-500/10 px-4 py-3 text-sm text-red-500",children:[e.jsx(C,{icon:["far","exclamation-triangle"],className:"mt-0.5 shrink-0","aria-hidden":!0}),e.jsx("p",{children:i("billingPage.manage.warning")})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-lg text-foreground",children:i("billingPage.plan.title",{plan:s.planName})}),e.jsx("p",{className:U("mt-1 text-sm text-muted-foreground",!s.periodEnd&&"hidden"),children:i("billingPage.manage.activeUntil",{date:s.periodEnd??""})})]}),e.jsx("button",{type:"button",onClick:s.onCancel,className:"inline-flex h-10 shrink-0 items-center justify-center rounded-md bg-red-500/15 px-4 text-sm text-red-500 transition-colors hover:bg-red-500/25 cursor-pointer",children:i("billingPage.manage.cancel")})]})]})})},"manage")})]})]})}function Tt({threshold:r=360}){const{t:n}=P("settings"),t=X(),[s,i]=x.useState(!1);x.useEffect(()=>{let a=0;const o=()=>{a||(a=window.requestAnimationFrame(()=>{a=0,i(window.scrollY>r)}))};return o(),window.addEventListener("scroll",o,{passive:!0}),()=>{window.removeEventListener("scroll",o),a&&window.cancelAnimationFrame(a)}},[r]);const d=()=>window.scrollTo({top:0,behavior:t?"auto":"smooth"});return Ge.createPortal(e.jsx(Z,{children:s&&e.jsxs(ee.button,{type:"button",onClick:d,initial:t?!1:{opacity:0,y:12,scale:.96},animate:{opacity:1,y:0,scale:1},exit:t?{opacity:0}:{opacity:0,y:12,scale:.96},transition:{duration:.25,ease:[.16,1,.3,1]},className:"fixed bottom-6 right-6 z-40 inline-flex h-10 items-center gap-2 rounded-md bg-foreground px-4 text-sm text-background shadow-lg shadow-black/20 transition-opacity hover:opacity-85 cursor-pointer",children:[e.jsx(C,{icon:["far","arrow-up"],className:"text-sm","aria-hidden":!0}),n("billingPage.scrollUp")]},"scroll-up")}),document.body)}function Ut({orgName:r,planName:n,usage:t}){const{t:s,i18n:i}=P("company"),d=ve(),a=et(),{data:o}=lt(),g=t?Math.max(0,De(t)):null,l=o?.my_usage.monthly_cap??null,m=o?.my_usage.credits_used_this_cycle??null,c=o?.wallet.cycle_end??t?.monthly_resets_at??null,u=c?new Date(c).toLocaleDateString(i.language,{year:"numeric",month:"long",day:"numeric"}):null,f=L=>L.toLocaleString(i.language);return e.jsxs(Y,{title:s("personalBilling.title",{plan:n,org:r}),description:s("personalBilling.description",{org:r}),action:a?e.jsx($,{tone:"primary",onClick:()=>d("/settings/company/billing"),children:s("personalBilling.companyBilling")}):e.jsx($,{tone:"secondary",onClick:()=>d("/settings/company/usage"),children:s("personalBilling.companyUsage")}),children:[e.jsx("div",{className:"my-4 h-px bg-border","aria-hidden":!0}),e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("personalBilling.canUse",{org:r})}),e.jsx("p",{className:"text-base text-foreground",children:g==null?"—":s("common.creditsCount",{value:f(g)})})]}),l!=null&&m!=null&&e.jsxs(e.Fragment,{children:[e.jsx(ot,{used:m,limit:l,label:s("personalBilling.capLabel"),size:"md",className:"mt-3"}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:s("personalBilling.capLine",{used:f(m),cap:f(l)})})]}),u&&e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:s("paywall.resets",{date:u})}
1),!a&&e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:s("personalBilling.askAdmin")})]})}const be="billing-credits",je="billing-usage";function Wt(){const r=ve(),{t:n,i18n:t}=P("settings"),{user:s}=ce(),[i,d]=x.useState({open:!1,tab:"plans"}),[a,o]=x.useState(!1),[g,l]=x.useState(!1),{data:m}=V({queryKey:["user-usage"],queryFn:ge.getUsage,enabled:!!s,refetchInterval:3e4}),c=m??s?.usage,{data:u}=V(Pe(s?.pricing_region)),f=V({queryKey:["usage-rollup"],queryFn:ge.getRollup,enabled:!!s}),L=(s?.subscription_tier??"free").trim().toLowerCase()||"free",p=de(L),N=p?u?.[p]?.name??p.charAt(0).toUpperCase()+p.slice(1):n("billingPage.freeName"),D=p?Number(u?.[p]?.credits??0):0,v=it(c,D),F=De(c),I=c?.daily_credits_enabled!==!1,G=c?.daily_credits_per_day??tt,b=s?.organization?.billing_managed?s.organization:null,A=!b&&!!s?.stripe_customer_id&&s.subscription_status==="active"&&!!p,w=!!s?.subscription_cancel_at_period_end,R=x.useMemo(()=>{const y=s?.subscription_current_period_end??c?.monthly_resets_at??null;if(!y)return null;const E=new Date(y);return Number.isNaN(E.getTime())?null:E.toLocaleDateString(t.language,{year:"numeric",month:"long",day:"numeric"})},[s?.subscription_current_period_end,c?.monthly_resets_at,t.language]),j=p?w?R?n("billingPage.plan.cancelledUntil",{date:R}):n("billingPage.plan.cancelledSoon"):R?n("billingPage.plan.renewsOn",{date:R}):n("billingPage.plan.active"):n("billingPage.plan.freeStatus"),S=x.useMemo(()=>Pt(f.data),[f.data]),B=S[0]??null,_=x.useCallback(y=>d({open:!0,tab:y}),[]),q=x.useCallback(()=>d(y=>({...y,open:!1})),[]),z=Ne({mutationFn:()=>M.getBillingPortalUrl(rt(),"manage"),onSuccess:y=>{nt(),se(y.url)},onError:y=>{alert(y.response?.data?.error||n("billing.portalFailed"))}}),h=x.useCallback(y=>r(`/studio/${y}`),[r]),K=x.useCallback(y=>{document.getElementById(y)?.scrollIntoView({behavior:"smooth",block:"start"})},[]),H=x.useCallback(y=>{const E=y.action;switch(E.kind){case"scroll":K(E.target==="credits"?be:je);return;case"usage":r("/settings/usage");return;case"upgrade":_(E.tab);return;case"dashboard":r("/dashboard",E.runMode?{state:{runMode:E.runMode}}:void 0);return;case"studio":r(B?`/studio/${B.id}`:"/dashboard");return;case"gameSettings":r(B?`/studio/${B.id}/settings/${E.section}`:"/dashboard");return;case"support":p==="pro"?window.location.href=`mailto:${st}`:se(at);return;case"external":se(E.url);return}},[r,_,p,K,B]),T=A?{planName:N,periodEnd:R,cancelScheduled:w,onCancel:()=>o(!0),onRenew:()=>l(!0)}:void 0;return e.jsxs(ct,{title:n("pages.billing.pageTitle","Billing | Tesana"),heading:n("pages.billing.heading","Billing"),subtitle:n("pages.billing.subtitle","Your subscription, invoices, and payment methods."),children:[e.jsx("section",{className:"mb-8",children:b?e.jsx(Ut,{orgName:b.name,planName:N,usage:c}):e.jsx(_t,{plan:p,planName:N,monthlyCredits:v,status:j,cancelScheduled:A&&w,onUpgrade:()=>_("plans"),onRenew:()=>l(!0)})}),!b&&e.jsxs("section",{className:"mb-8",children:[e.jsx("h2",{className:"mb-4 text-lg text-foreground",children:n("billingPage.sections.credits")}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(kt,{id:be,available:F,allowance:p?v:I?G:0,cadence:p?"monthly":"daily",onBuyCredits:()=>_("topup")}),e.jsx(vt,{})]})]}),e.jsxs("section",{className:"mb-8",children:[e.jsx("h2",{className:"mb-4 text-lg text-foreground",children:n("billingPage.sections.usage")}),e.jsx(St,{id:je,rollup:f.data,loading:f.isLoading,onOpenUsage:()=>r("/settings/usage"),onOpenGame:h})]}),!b&&e.jsxs("section",{className:"mb-8",children:[e.jsx("h2",{className:"mb-4 text-lg text-foreground",children:n("billingPage.sections.billing")}),e.jsx(Y,{title:n("billingPage.billingInfo.title"),description:s?.stripe_customer_id?n("billingPage.billingInfo.description"):n("billing.noBillingAccount"),action:s?.stripe_customer_id?e.jsx($,{tone:"quiet",onClick:()=>z.mutate(),disabled:z.isPending,children:z.isPending?n("billing.opening"):n("billingPage.billingInfo.manage")}):e.jsx($,{tone:"quiet",onClick:()=>_("plans"),children:n("billing.viewPlans")})})]}),(f.isLoading||S.length>0)&&e.jsxs("section",{className:"mb-8",children:[e.jsx("h2",{className:"mb-4 text-lg text-foreground",children:n("billingPage.sections.rewind")}),e.jsx(Dt,{games:S,loading:f.isLoading,onOpen:h})]}),e.jsxs("section",{children:[e.jsx("h2",{className:"mb-4 text-lg text-foreground",children:n("billingPage.sections.plan")}),p?e.jsx(Lt,{plan:p,monthlyCredits:v,onShow:H,manage:T}):e.jsx(Y,{title:n("billingPage.plan.title",{plan:N}),description:n("billingPage.plan.freePitch"),action:e.jsx($,{tone:"primary",onClick:()=>_("plans"),children:n("billingPage.plan.upgrade")})})]}),e.jsx(Tt,{}),e.jsx(Oe,{isOpen:i.open,onClose:q,context:"general",initialTab:i.tab}),e.jsx(Nt,{isOpen:a,onClose:()=>o(!1)}),e.jsx(wt,{isOpen:g,onClose:()=>l(!1)})]})}export{Wt 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.