1import{b as se,r as i,j as e,B as t,L as ae,t as u}from"./index-BI34Wull.js";import{A as re,b as te,c as ne,d as ie,e as le,f as oe,g as ce,h as de}from"./alert-dialog-Cc_m8zpJ.js";import{u as me}from"./useSubscription-D2JLxCI-.js";import{u as ue,T as D}from"./tier-access-BdUYHXyh.js";import{u as xe,M as x,P as w,c as I,a as pe}from"./seats-Cbh6u8yb.js";import{g as he,c as fe,r as ge,a as be}from"./payments.functions-CZi9RQ9j.js";import{i as z,g as O}from"./stripe-Css1BWh0.js";import{L as o}from"./loader-circle-RJ_lzir4.js";import{E as q}from"./external-link-Bxe1ZwP_.js";import{C as je}from"./credit-card-gu7a94JO.js";import{C as X}from"./calendar-clock-BTGGiyAf.js";import{R as ye}from"./rotate-ccw-BiS5I307.js";import{c as we}from"./createLucideIcon-4AT48GiE.js";import{U as Ne}from"./users-CtTNFSDb.js";import{C as ve}from"./check-k473LBdN.js";import{A as _e}from"./arrow-right-Bz8PyTzT.js";import{S as Ce}from"./sparkles-5BKEcR93.js";import"./index-DYIppBmS.js";import"./index-CneZgM9-.js";import"./Combination-BhuTL0bJ.js";import"./index-Bv6t4qTQ.js";import"./index-B4j4u9tl.js";import"./index-Dx9TEr1Q.js";const ke=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],Ee=we("circle-x",ke),H=["playmaker","pro_team","performance_system"],N={playmaker:{monthlyId:"playmaker_monthly",yearlyI
1d:"playmaker_yearly",blurb:"For individual sellers and founders â 1 to 4 licenses. Every call scored, every gap fixed."},pro_team:{monthlyId:"pro_team_monthly",yearlyId:"pro_team_yearly",blurb:"For small sales teams â 5 license minimum, with team dashboards."},performance_system:{monthlyId:"performance_system_monthly",yearlyId:"performance_system_yearly",blurb:"For growing sales orgs â 10 license minimum, with human onboarding."}};function Qe(){const{user:R}=se(),{subscription:n,isActive:K,loading:V,refetch:P,licenses:F}=me(),{tier:a}=ue(),{openCheckout:G,checkoutElement:J}=xe(),[c,$]=i.useState({playmaker:x.playmaker,pro_team:x.pro_team,performance_system:x.performance_system}),[d,M]=i.useState(!1),[p,v]=i.useState(null),[Q,T]=i.useState(!1),[l,g]=i.useState(!1),[h,b]=i.useState(null),j=O(),U=i.useCallback(async()=>{if(!(!n||!z())){T(!0);try{const s=await he({data:{environment:j}});"error"in s||v(s)}catch{}finally{T(!1)}}},[n?.id,j]);i.useEffect(()=>{U()},[U]);const _=p?.cancel_at_period_end??n?.cancel_at_period_end??!1,C=p?.current_period_end??n?.current_period_end??null,W=p?.cancel_at??C,Y=p?.trial_end??null,y=p?.status??n?.status??"",m=s=>s?new Date(s).toLocaleDateString(void 0,{month:"long",day:"numeric",year:"numeric"}):"â",Z=async s=>{g(!0);try{const r=await be({data:{environment:j,immediate:s}});if("error"in r)throw new Error(r.error);v(r),await P(),u.success(s?"Your subscription was canceled.":`Your plan will end on ${m(r.cancel_at??r.current_period_end)}.`)}catch(r){u.error(r instanceof Error?r.message:"Could not cancel your subscription.")}finally{g(!1),b(null)}},ee=async()=>{g(!0);try{const s=await ge({data:{environment:j}});if("error"in s)throw new Error(s.error);v(s),await P(),u.success(`Renewal restored â next charge on ${m(s.current_period_end)}.`)}catch(s){u.error(s instanceof Error?s.message:"Could not resume your subscription.")}finally{g(!1)}},k=a?H.indexOf(a):-1,E=async()=>{if(!z()){u.error("Payments are not configured for this build yet.");return}M(!0);try{const s=await fe({data:{environment:O(),returnUrl:window.location.href}});if("error"in s)throw new Error(s.error);window.open(s.url,"_blank","noopener,noreferrer")}catch(s){u.error(s instanceof Error?s.message:"Could not open the billing portal.")}finally{M(!1)}},B=(s,r)=>{const L=r==="monthly"?N[s].monthlyId:N[s].yearlyId;G({priceId:L,quantity:I(s,c[s]),email:R?.email,userId:R?.id})};return e.jsxs("div",{className:"mx-auto max-w-5xl px-6 py-10",children:[e.jsx("div",{className:"mb-8 flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight",children:"Billing"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Manage your plan, payment method, and invoices."})]})}),e.jsx("section",{className:"rounded-2xl border border-border bg-card/70 p-6 shadow-sm backdrop-blur",children:V?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(o,{className:"h-4 w-4 animate-spin"})," Loading your planâ¦"]}):n&&a?e.jsxs("div",{className:"flex flex-col gap-6 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Current plan"}),e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-2xl font-semibold",children:[D[a],e.jsx("span",{className:`rounded-full px-2 py-0.5 text-[10px] font-semibold uppercase tracking-widest ${K?"bg-emerald-500/15 text-emerald-500":"bg-amber-500/15 text-amber-500"}`,children:n.status})]}),e.jsx("div",{className:"mt-2 text-sm text-muted-foreground",children:N[a].blurb}),n.current_period_end&&e.jsxs("div",{className:"mt-3 text-xs text-muted-foreground",children:[n.cancel_at_period_end?"Cancels":"Renews"," on ",new Date(n.current_period_end).toLocaleDateString()]})]}),e.jsx("div",{className:"flex flex-col gap-2 sm:flex-row",children:e.jsxs(t,{onClick:E,disabled:d,variant:"outline",children:[d?e.jsx(o,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(q,{className:"mr-2 h-4 w-4"}),"Manage subscription"]})})]}):e.jsxs("div",{className:"flex flex-col gap-6 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Current plan"}),e.jsx("div",{className:"mt-1 text-2xl font-semibold",children:"No active subscription"}),e.jsx("div",{className:"mt-2 text-sm text-muted-foreground",children:"Pick a plan below to unlock the full Bizware AI system."})]}),e.jsx(ae,{to:"/pricing",children:e.jsxs(t,{variant:"outline",children:[e.jsx(je,{className:"mr-2 h-4 w-4"})," View pricing page"]})})]})}),a&&e.jsx("section",{className:"mt-6 rounded-2xl border border-border bg-card/70 p-6 shadow-sm backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(X,{className:"mt-0.5 h-5 w-5 text-primary"}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold",children:[_||y==="canceled"?"Cancellation scheduled":"Renewal",Q&&e.jsx(o,{className:"ml-2 inline h-3.5 w-3.5 animate-spin text-muted-foreground"})]}),e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:y==="canceled"?e.jsx(e.Fragment,{children:"This subscription has ended. Choose a plan below to start again."}):_?e.jsxs(e.Fragment,{children:["Your plan stays active until"," ",e.jsx("span",{className:"font-medium text-foreground",children:m(W)}),", then it will not renew."]}):y==="trialing"&&Y?e.jsxs(e.Fragment,{children:["Legacy billing trial ends"," ",e.jsx("span",{className:"font-medium text-foreground",children:m(Y)})," â you won't be charged until then."]}):e.jsxs(e.Fragment,{children:["Renews automatically on"," ",e.jsx("span",{className:"font-medium text-foreground",children:m(C)})]})})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:y!=="canceled"&&(_?e.jsxs(t,{onClick:ee,disabled:l,children:[l?e.jsx(o,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(ye,{className:"mr-2 h-4 w-4"}),"Resume renewal"]}):e.jsxs(e.Fragment,{children:[e.jsxs(t,{variant:"outline",onClick:()=>b("period_end"),disabled:l,children:[e.jsx(X,{className:"mr-2 h-4 w-4"})," Cancel at renewal"]}),e.jsxs(t,{variant:"ghost",className:"text-destructive hover:text-destructive",onClick:()=>b("immediate"),disabled:l,children:[e.jsx(Ee,{className:"mr-2 h-4 w-4"})," Cancel now"]})]}))})]})}),a&&e.jsx("section",{className:"mt-6 rounded-2xl border border-border bg-card/70 p-6 shadow-sm backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ne,{className:"mt-0.5 h-5 w-5 text-primary"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:"Licenses"}),e.jsxs("div",{className:"mt-1 text-sm text-muted-foreground",children:[D[a]," at $",w[a]," per user / month ·"," ",e.jsx("span",{className:"font-medium text-foreground",children:F??x[a]})," ",(F??x[a])===1?"license":"licenses",". Add or remove licenses anytime."]})]})]}),e.jsxs(t,{variant:"outline",onClick:E,disabled:d,children:[d?e.jsx(o,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(q,{className:"mr-2 h-4 w-4"}),"Manage licenses"]})]})}),e.jsxs("section",{className:"mt-10",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsx("h2",{className:"text-xl font-semibold",children:a?"Change your plan":"Cho
1ose a plan"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Upgrades take effect immediately. Downgrades apply at renewal."})]}),e.jsx("div",{className:"grid gap-4 md:grid-cols-3",children:H.map((s,r)=>{const L=N[s],S=a===s,A=k===-1?"select":r>k?"upgrade":r<k?"downgrade":"current";return e.jsxs("article",{className:`flex flex-col rounded-2xl border p-5 ${S?"border-primary/60 shadow-md":"border-border"}`,style:{background:"var(--gradient-card)"},children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-lg font-semibold",children:D[s]}),S&&e.jsx("span",{className:"rounded-full bg-primary/15 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-widest text-primary",children:"Current"})]}),e.jsx("div",{className:"mt-2 text-sm text-muted-foreground",children:L.blurb}),e.jsxs("div",{className:"mt-4 flex items-baseline gap-2",children:[e.jsxs("span",{className:"text-3xl",children:["$",w[s]]}),e.jsx("span",{className:"text-xs uppercase tracking-widest text-muted-foreground",children:"/ user / month"})]}),e.jsxs("div",{className:"mt-1 text-xs text-muted-foreground",children:[s==="playmaker"?"1â4 licenses":s==="pro_team"?"5 license minimum":"10 license minimum"," · annual saves 20%"]}),e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 rounded-lg border border-border bg-background/40 p-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(t,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>$(f=>({...f,[s]:I(s,f[s]-1)})),disabled:c[s]<=x[s],children:"â"}),e.jsx("span",{className:"w-8 text-center text-sm font-medium",children:c[s]}),e.jsx(t,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>$(f=>({...f,[s]:I(s,f[s]+1)})),disabled:c[s]>=pe[s],children:"+"})]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[c[s]," à $",w[s]," ="," ",e.jsxs("span",{className:"font-medium text-foreground",children:["$",(c[s]*w[s]).toLocaleString()]}),"/mo"]})]}),S?e.jsxs("div",{className:"mt-5 flex items-center gap-2 rounded-lg border border-border bg-background/40 p-3 text-sm text-muted-foreground",children:[e.jsx(ve,{className:"h-4 w-4 text-primary"})," You're on this plan"]}):A==="downgrade"?e.jsxs(t,{className:"mt-5",variant:"outline",onClick:E,disabled:d,children:[d?e.jsx(o,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Downgrade in portal"]}):e.jsxs("div",{className:"mt-5 flex flex-col gap-2",children:[e.jsxs(t,{onClick:()=>B(s,"monthly"),style:{background:"var(--gradient-primary)"},children:[A==="upgrade"?"Upgrade â monthly":"Start monthly"," ",e.jsx(_e,{className:"ml-1.5 h-4 w-4"})]}),e.jsxs(t,{onClick:()=>B(s,"yearly"),variant:"outline",children:[A==="upgrade"?"Upgrade â annual":"Start annual"," ",e.jsx(Ce,{className:"ml-1.5 h-4 w-4"})]})]})]},s)})})]}),J,e.jsx(re,{open:h!==null,onOpenChange:s=>{s||b(null)},children:e.jsxs(te,{children:[e.jsxs(ne,{children:[e.jsx(ie,{children:h==="immediate"?"Cancel immediately?":"Cancel at renewal?"}),e.jsx(le,{children:h==="immediate"?"Your subscription ends right away and you lose access to the app immediately. This cannot be undone â you would need to start a new plan.":`You keep full access until ${m(C)}. After that your plan will not renew and you won't be charged again. You can resume renewal any time before then.`})]}),e.jsxs(oe,{children:[e.jsx(ce,{disabled:l,children:"Keep my plan"}),e.jsxs(de,{onClick:s=>{s.preventDefault(),Z(h==="immediate")},disabled:l,children:[l&&e.jsx(o,{className:"mr-2 h-4 w-4 animate-spin"}),h==="immediate"?"Cancel now":"Confirm cancellation"]})]})]})})]})}export{Qe as component};
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.