1import{j as e,aM as ge,aN as Ne,B as p,aO as ye,k as X,e as J,o as w,r as h,a7 as H,t as C,a5 as ve,m as Ce}from"./index-OkXy-d5Y.js";import{A as we,b as be,c as Ae,d as De,e as ke,f as Ee,g as Pe,h as Te}from"./alert-dialog-Dc3pT7KS.js";import{B as f}from"./badge-D70DEMXH.js";import{C as k,a as E,c as P,d as U,b as T}from"./card-BOYNs0rn.js";import{e as Q,f as Z,g as S,h as ee,i as se,D as ae,d as te,a as ne,b as le,c as re,j as Ie,k as ze}from"./drawer-BKNRAhtm.js";import{S as Le}from"./separator-D5JjMsAa.js";import{S as ie}from"./skeleton-CTnX7jIE.js";import{T as ce,a as de,b as z,c as b,d as oe,e as y}from"./table-B-pszi_P.js";import{a as D}from"./billing-format-CjDMm46p.js";import{f as I}from"./date-utils-BapGj4Cw.js";import{M as Me,b as B,P as Re}from"./PlanChangeConfirm-BSRFGOOM.js";import{b as Ye,c as Fe,f as Ue,d as Oe,a as He,e as Be,g as $e,h as Ke,i as _e,j as _,k as V,l as Ve,m as F,r as q}from"./subscriptionsSlice-CAeRwGnr.js";import{C as qe,a as Ge,b as We}from"./collapsible-CZUQNwDz.js";import{I as G,T as me}from"./triangle-alert-CDwBzzS8.js";import{P as Xe}from"./PlanChangeFlow-CX0DWTJb.js";import{L as Je}from"./loader-circle-Cq8KN2OP.js";import"./label-B8fcy5Qd.js";import"./PricingSection-D3y2sJL9.js";import"./alert-0QuNooNy.js";function W({tooltip:a,tooltipSide:i="top",wrapperClassName:s,...l}){return e.jsxs(ge,{children:[e.jsx(Ne,{asChild:!0,children:e.jsx("span",{className:s?`inline-flex ${s}`:"inline-flex",children:e.jsx(p,{...l})})}),e.jsx(ye,{side:i,className:"max-w-xs text-left",children:a})]})}function ue({open:a,onOpenChange:i,title:s,description:l,children:r,dismissDisabled:c=!1,contentClassName:n}){const o=X(),m=x=>{!x&&c||i(x)};return o?e.jsx(Q,{open:a,onOpenChange:m,children:e.jsxs(Z,{children:[e.jsxs(S,{children:[e.jsx(ee,{children:s}),l?e.jsx(se,{children:l}):null]}),e.jsx("div",{className:"px-4 pb-4",children:r})]})}):e.jsx(ae,{open:a,onOpenChange:m,children:e.jsxs(te,{className:n??"w-full sm:max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsxs(ne,{children:[e.jsx(le,{children:s}),l?e.jsx(re,{children:l}):null]}),r]})})}function Qe(){const a=J(),i=w(Ye),s=w(Fe),[l,r]=h.useState(10),[c,n]=h.useState(null),[o,m]=h.useState(!1);if(h.useEffect(()=>{a(Ue()),m(!0)},[a]),i||!o)return e.jsx("div",{className:"space-y-2",children:[...Array(3)].map((t,A)=>e.jsx(ie,{className:"h-12 w-full"},A))});if(!s||s.length===0)return e.jsx("p",{className:"text-sm text-muted-foreground",children:"No billing history yet"});const x=t=>{switch(t){case"PAID":return e.jsx(f,{className:"bg-green-600",children:"Paid"});case"PENDING":return e.jsx(f,{className:"bg-yellow-600",children:"Pending"});case"FAILED":return e.jsx(f,{className:"bg-red-600",children:"Failed"});default:return e.jsx(f,{variant:"outline",children:t})}},g=s.slice(0,l),N=s.length>l;return e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"space-y-3 md:hidden",children:g.map(t=>e.jsx("li",{className:"rounded-lg border p-4",children:e.jsxs(qe,{open:c===t.id,onOpenChange:A=>n(A?t.id??null:null),className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:"Date"}),e.jsx("span",{children:I(t.occurredAt,"medium",{fallback:"â"})})]}),e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:"Description"}),e.jsx("span",{children:t.description||"Subscription"})]}),e.jsxs("div",{className:"flex justify-between gap-3 items-center",children:[e.jsx("span",{className:"text-muted-foreground",children:"Amount"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:D(t.amountMinor??0,t.currency??"INR")}),e.jsx(Ge,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":"Payment details",className:"inline-flex items-center justify-center min-h-11 min-w-11 hover:bg-muted rounded",children:e.jsx(G,{className:"h-4 w-4 text-muted-foreground"})})})]})]}),e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:"Status"}),x(t.status)]}),e.jsxs(We,{className:"mt-2 pt-2 border-t space-y-1 text-sm",children:[t.id&&e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:"Payment ID"}),e.jsx("span",{className:"font-mono break-all",children:t.id})]}),t.provider&&e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:"Provider"}),e.jsx("span",{children:t.provider})]}),t.providerPaymentId&&e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:"Provider ref"}),e.jsx("span",{className:"font-mono break-all",children:t.providerPaymentId})]}),t.failureReason&&e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:"Reason"}),e.jsx("span",{children:t.failureReason})]})]})]})},t.id))}),e.jsx("div",{className:"overflow-x-auto hidden md:block",children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(z,{children:[e.jsx(b,{children:"Date"}),e.jsx(b,{children:"Description"}),e.jsx(b,{children:"Amount"}),e.jsx(b,{children:"Status"})]})}),e.jsx(oe,{children:g.map(t=>e.jsxs(h.Fragment,{children:[e.jsxs(z,{children:[e.jsx(y,{className:"text-sm",children:I(t.occurredAt,"medium",{fallback:"â"})}),e.jsx(y,{className:"text-sm",children:t.description||"Subscription"}),e.jsx(y,{className:"text-sm",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:D(t.amountMinor??0,t.currency??"INR")}),e.jsx("button",{type:"button","aria-label":"Payment details","aria-expanded":c===t.id,className:"inline-flex items-center justify-center min-h-11 min-w-11 hover:bg-muted rounded",onClick:()=>
1n(c===t.id?null:t.id??null),children:e.jsx(G,{className:"h-4 w-4 text-muted-foreground"})})]})}),e.jsx(y,{children:x(t.status)})]}),c===t.id&&e.jsx(z,{children:e.jsx(y,{colSpan:4,className:"bg-muted/30",children:e.jsxs("div",{className:"space-y-1 text-sm",children:[t.id&&e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:"Payment ID"}),e.jsx("span",{className:"font-mono",children:t.id})]}),t.provider&&e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:"Provider"}),e.jsx("span",{children:t.provider})]}),t.providerPaymentId&&e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:"Provider ref"}),e.jsx("span",{className:"font-mono",children:t.providerPaymentId})]}),t.failureReason&&e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:"Reason"}),e.jsx("span",{children:t.failureReason})]})]})})})]},t.id))})]})}),N&&e.jsx("div",{className:"flex justify-center pt-4",children:e.jsx(p,{variant:"outline",className:"min-h-11",onClick:()=>r(t=>t+10),children:"Load more"})})]})}
1function Ze({currentPlanSlug:a,billingCycle:i,triggerLabel:s="Change plan",triggerVariant:l="default",triggerClassName:r,onChanged:c}){const[n,o]=h.useState(!1),m=e.jsx(Xe,{currentPlanSlug:a,billingCycle:i,onClose:()=>{o(!1),c==null||c()}});return e.jsxs(e.Fragment,{children:[e.jsx(p,{variant:l,className:r,onClick:()=>o(!0),children:s}),e.jsx(ue,{open:n,onOpenChange:o,title:"Change your plan",description:"Pick the plan that fits your needs.",contentClassName:"w-full sm:max-w-[70vw] max-h-[90vh] overflow-y-auto",children:m})]})}function L(a){return I(a,"long",{fallback:"the end of your billing cycle"})}function Se(a,i){switch((a||"").toUpperCase()){case"ACTIVE":return{label:"Active",description:"Your subscription is active.",variant:"default"};case"PENDING_AUTH":return{label:"Awaiting authorization",description:"Complete authorization to activate your subscription.",variant:"outline"};case"AUTHENTICATED":return{label:"Authorized",description:"Mandate authorized; activating your subscription.",variant:"outline"};case"PAST_DUE":return{label:"Payment overdue",description:"Your last payment failed. Please update your payment method.",variant:"destructive"};case"PAUSED":return{label:"Paused",description:"Your subscription is paused.",variant:"secondary"};case"CANCEL_SCHEDULED":return{label:"Cancellation scheduled",description:`You keep full access until ${L(i)}.`,variant:"secondary"};case"CANCELLED":return{label:"Cancelled",description:"Your subscription has been cancelled.",variant:"destructive"};case"HALTED":return{label:"Halted",description:"Your subscription was halted after repeated failed payments.",variant:"destructive"};case"COMPLETED":return{label:"Completed",description:"Your subscription has completed its term.",variant:"secondary"};case"EXPIRED":return{label:"Expired",description:"Your subscription has expired.",variant:"destructive"};default:return{label:a||"Unknown",description:"",variant:"outline"}}}const $=new Me;function es({currentPlan:a,subscription:i,liveSubscription:s,pendingSubscription:l,autoAuthCountdown:r,onChanged:c,onCancelPendingClick:n,billingCycle:o}){const m=Ce();if(!(s!=null))return e.jsxs(k,{children:[e.jsx(E,{children:e.jsx(P,{children:"Current Plan"})}),e.jsxs(T,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"No active subscription"}),e.jsx(p,{onClick:()=>m("/dashboard/billing/plans"),className:"w-full sm:w-auto",children:"Choose a plan"})]})]});const g=()=>{const t=(i==null?void 0:i.status)??(s==null?void 0:s.status),A=(i==null?void 0:i.cancelAt)??(s==null?void 0:s.cancelAt);if(l&&t!=="ACTIVE")return e.jsx(f,{className:"bg-yellow-600",children:"Awaiting authorization"});const v=Se(t,A);return v.variant==="default"?e.jsx(f,{className:"bg-green-600",children:v.label}):e.jsx(f,{variant:v.variant,children:v.label})},N=I(s==null?void 0:s.nextChargeDate,"long",{fallback:"N/A"});return e.jsxs(k,{children:[e.jsx(E,{children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(P,{children:(a==null?void 0:a.planName)||"Free plan"}),e.jsx(U,{children:"Currently active plan"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:a!=null&&a.priceUnavailable?e.jsx("span",{className:"text-destructive",children:"Price unavailable"}):e.jsxs(e.Fragment,{children:[D((a==null?void 0:a.amountMinor)??0,(a==null?void 0:a.currency)??"")," /cycle.",(s==null?void 0:s.status)==="CANCEL_SCHEDULED"?` Access continues until ${L(s==null?void 0:s.cancelAt)}. Your plan will not renew.`:(s==null?void 0:s.status)==="ACTIVE"&&(s!=null&&s.nextChargeDate)?` Your subscription will auto-renew on ${N}.`:""]})})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-shrink-0",children:[g(),i&&e.jsx(Ze,{currentPlanSlug:i.planKey,triggerLabel:"Adjust plan",triggerVariant:"outline",onChanged:c,billingCycle:o})]})]})}),e.jsxs(T,{className:"space-y-4",children:[(s==null?void 0:s.pendingPlanKey)&&e.jsx("div",{className:"p-3 bg-blue-50 border border-blue-200 rounded-md",children:e.jsxs("p",{className:"text-sm text-blue-900",children:["Scheduled change â ",s.pendingPlanName||s.pendingPlanKey," on"," ",I(s.pendingEffectiveAt)
1]})}),l&&e.jsxs("div",{className:"space-y-3 p-3 bg-yellow-50 border border-yellow-200 rounded-md",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(me,{className:"h-4 w-4 text-yellow-600 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("p",{className:"text-sm font-medium text-yellow-900",children:["Auto-renew setup pending for ",l.pendingPlanName||l.planName||l.planKey]}),e.jsx("p",{className:"text-xs text-yellow-800 mt-1",children:"Your payment is complete. Authorize automatic renewals now to finish setting up your plan."}),e.jsx("p",{className:"text-xs text-yellow-800 mt-1",children:"You will not be charged again now. This step only enables future recurring payments."}),r!==null&&e.jsxs("p",{className:"text-xs font-medium text-yellow-900 mt-2",children:["Payment for the first cycle is done. Taking you to set up the recurring mandate",r>0?` in ${r}sâ¦`:"â¦"]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[l.needsAuthorization&&e.jsx(p,{onClick:async()=>{if(!l.provider){C({title:"Error",description:"No pending authorization found for this subscription.",variant:"destructive"});return}H("/dashboard/billing");try{await $.authorizeSubscription(B({provider:l.provider,environment:l.environment,authLink:l.pendingAuthLink||l.authLink,authSessionId:l.pendingAuthSessionId||l.authSessionId}))}catch{}},className:"w-full sm:w-auto",children:"Authorize renewals"}),e.jsx(p,{variant:"outline",onClick:n,className:"w-full sm:w-auto",children:"Cancel / Start over"})]})]})]})]})}function ss({plans:a,currentPlanAmount:i,onSelectPlan:s,loading:l,currentBillingCycle:r}){if(l)return e.jsxs(k,{children:[e.jsx(E,{children:e.jsx(P,{children:"Available Plans"})}),e.jsx(T,{children:e.jsx("div",{className:"space-y-2",children:[...Array(3)].map((n,o)=>e.jsx(ie,{className:"h-12 w-full"},o))})})]});const c=a.filter(n=>n.isExternal||n.isOrgCurrent);return e.jsxs(k,{children:[e.jsxs(E,{children:[e.jsx(P,{children:"Available Plans"}),e.jsx(U,{children:"Choose a plan that fits your needs"})]}),e.jsx(T,{children:e.jsxs("div",{className:"overflow-x-auto",children:[e.jsxs(ce,{className:"hidden md:table",children:[e.jsx(de,{children:e.jsxs(z,{children:[e.jsx(b,{children:"Plan"}),e.jsx(b,{children:"Price"}),e.jsx(b,{children:"Status"}),e.jsx(b,{className:"text-right",children:"Action"})]})}),e.jsx(oe,{children:c.map(n=>{const o=n.isOrgCurrent,m=!o&&i!==void 0&&(n.amountMinor??0)<i;return e.jsxs(z,{children:[e.jsx(y,{className:"font-medium",children:n.planName}),e.jsx(y,{children:e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("div",{children:n.priceUnavailable?e.jsx("span",{className:"text-destructive",children:"Price unavailable"}):e.jsxs(e.Fragment,{children:[D(n.amountMinor??0,n.currency??""),e.jsx("span",{className:"text-xs text-muted-foreground ml-1",children:"/mo"})]})}),e.jsx("div",{className:"text-sm text-muted-foreground",children:n.yearlyPriceUnavailable?e.jsx("span",{className:"text-destructive",children:"Yearly unavailable"}):e.jsxs(e.Fragment,{children:[D(n.yearlyAmountMinor??0,n.currency??""),e.jsx("span",{className:"text-xs ml-1",children:"/yr"})]})})]})}),e.jsx(y,{children:o?e.jsx(f,{className:"bg-blue-600",children:"Current"}):e.jsx(f,{variant:"outline",children:"Available"})}),e.jsx(y,{className:"text-right",children:o?e.jsx("span",{className:"text-sm text-muted-foreground",children:"â"}):e.jsx(p,{size:"sm",variant:"outline",className:"w-full sm:w-auto min-h-12",onClick:()=>n.planKey&&s(n.planKey,n.planName),children:m?"Downgrade":"Upgrade"})})]},n.id)})})]}),e.jsx("div",{className:"space-y-4 md:hidden",children:c.map(n=>{const o=n.isOrgCurrent,m=!o&&i!==void 0&&(n.amountMinor??0)<i;return e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Plan"}),e.jsx("p",{className:"font-medium",children:n.planName})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Price"}),e.jsx("p",{children:n.priceUnavailable?e.jsx("span",{className:"text-destructive",children:"Price unavailable"}):e.jsxs(e.Fragment,{children:[D(n.amountMinor??0,n.currency??""),e.jsx("span",{className:"text-xs text-muted-foreground ml-1",children:"/mo"})]})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n.yearlyPriceUnavailable?e.jsx("span",{className:"text-destructive",children:"Yearly unavailable"}):e.jsxs(e.Fragment,{children:[D(n.yearlyAmountMinor??0,n.currency??""),e.jsx("span",{className:"text-xs ml-1",children:"/yr"})]})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Status"}),e.jsx("div",{className:"pt-1",children:o?e.jsx(f,{className:"bg-blue-600",children:"Current"}):e.jsx(f,{variant:"outline",children:"Available"})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Action"}),e.jsx("div",{className:"pt-2",children:o?e.jsx("span",{className:"text-sm text-muted-foreground",children:"Current plan"}):e.jsx(p,{size:"sm",variant:"outline",className:"w-full sm:w-auto min-h-12",onClick:()=>n.planKey&&s(n.planKey,n.planName),children:m?"Downgrade":"Upgrade"})})]})]},n.id)})})]})})]})}function as({subscription:a,onReauthorizeClick:i,onCancelClick:s,loading:l}){if(!a)return null;const r=a.status==="CANCEL_SCHEDULED",c=L(a.cancelAt??a.nextChargeDate);return e.jsxs(k,{children:[e.jsxs(E,{children:[e.jsx(P,{children:"Manage subscription"}),e.jsx(U,{children:"Payment method and cancellation"})]}),e.jsxs(T,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold mb-4",children:"Payment method"}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Change the payment method with your bank"}),a.status==="ACTIVE"&&e.jsx(W,{onClick:i,disabled:l,tooltip:"Update the payment authorization with your bank. You can change the card, UPI or bank account there. Your plan, price and renewal date do not change, and you are not charged now.",children:"Change payment method"})]})]}),a.status!=="CANCELLED"&&e.jsxs(e.Fragment,{children:[e.jsx(Le,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold mb-4",children:"Cancellation"}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:r?`Already scheduled to end â access continues until ${c}
1`:`Current Cycle continues until ${c}`}),e.jsx(W,{variant:"destructive",onClick:s,disabled:l,tooltip:r?`Ends the subscription straight away instead of on ${c}. You lose paid access immediately and drop to the free plan.`:`Stops all future charges. You keep your current plan and limits until ${c}, then move to the free plan.`,children:r?"Cancel Immediately":"Cancel Subscription"})]})]})]})]})]})}function ts({open:a,onConfirm:i,onOpenChange:s,loading:l,status:r,cancelAt:c,nextChargeDate:n}){const o=r==="CANCEL_SCHEDULED",m=o?"Cancel Immediately":"Cancel Subscription",x=o?`Your plan is already scheduled to end on ${L(c)}. Cancel immediately instead and lose access now? No refund for the remaining days.`:`Your plan stays active until ${L(n)}. After that it won't renew.`;return e.jsx(we,{open:a,onOpenChange:s,children:e.jsxs(be,{children:[e.jsxs(Ae,{children:[e.jsx(De,{children:m}),e.jsx(ke,{children:x})]}),e.jsxs(Ee,{children:[e.jsx(Pe,{disabled:l,children:"Keep Subscription"}),e.jsx(Te,{onClick:i,disabled:l,className:"bg-destructive hover:bg-destructive/90",children:l?"Cancelling...":m})]})]})})}function ns(){const a=J(),i=X(),s=w(Oe),l=w(He),r=w(Be),c=w($e),n=w(Ke),o=w(_e),m=((c==null?void 0:c.billingCycle)??"").toString().toLowerCase()==="yearly"?"yearly":"monthly",[x,g]=h.useState(null),[N,t]=h.useState({open:!1,payload:null}),[A,v]=h.useState(!1),he=r!=null;h.useEffect(()=>{a(_()),a(V())},[a]),h.useEffect(()=>{if(!o)return;const d=setTimeout(()=>{a(Ve())},5e3);return()=>clearTimeout(d)},[o,a]);const[M,R]=h.useState(null),K=h.useRef(!1);h.useEffect(()=>{const d=new URLSearchParams(window.location.search);if(d.get("result")!=="success")return;d.delete("result"),d.delete("order_id");const j=d.toString();window.history.replaceState({},"",window.location.pathname+(j?`?${j}`:"")),R(5)},[]),h.useEffect(()=>{if(M!==null){if(M>0){const d=setTimeout(()=>R(j=>j===null?null:j-1),1e3);return()=>clearTimeout(d)}if(!K.current){if(!(r!=null&&r.needsAuthorization)||!r.provider){R(null);return}K.current=!0,H("/dashboard/billing"),$.authorizeSubscription(B({provider:r.provider,environment:r.environment,authLink:r.pendingAuthLink||r.authLink,authSessionId:r.pendingAuthSessionId||r.authSessionId})).catch(d=>{R(null),C({title:"Error",description:ve(d,"Failed to start payment authorization"),variant:"destructive"})})}}},[M,r]);const xe=(d,j)=>{g({planKey:d,planName:j})},je=async()=>{if(!l)return;const d=await a(q(l.subscriptionId));if(q.fulfilled.match(d)){const j=d.payload;j.provider?(t({open:!0,payload:B(j)}),H("/dashboard/billing")):C({title:"Error",description:"No authorization details received",variant:"destructive"})}else C({title:"Error",description:"Failed to get reauthorization link",variant:"destructive"})},u=r?l:c,fe=async()=>{if(!(u!=null&&u.subscriptionId))return;const d=await a(F(u.subscriptionId));F.fulfilled.match(d)?(C({title:"Subscription cancelled"}),v(!1)):C({title:"Error",description:"Failed to cancel subscription",variant:"destructive"})},pe=async()=>{if(!(r!=null&&r.subscriptionId))return;const d=await a(F(r.subscriptionId));F.fulfilled.match(d)?C({title:"Pending subscription cancelled"}):C({title:"Error",description:"Failed to cancel pending subscription",variant:"destructive"})},Y=s.find(d=>d.isOrgCurrent);return I(l==null?void 0:l.nextChargeDate,"long",{fallback:"end of cycle"}),e.jsxs("div",{className:"space-y-6",children:[o&&e.jsxs("div",{className:"p-4 bg-red-50 border border-red-200 rounded-md flex items-start gap-3",children:[e.jsx(me,{className:"h-5 w-5 text-red-600 mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-red-900",children:"Error"}),e.jsx("p",{className:"text-sm text-red-800 mt-1",children:o})]})]}),N.open&&(()=>{const d=e.jsx("div",{className:"py-4",children:e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"You will be redirected to complete the authorization."})}),j=e.jsxs(e.Fragment,{children:[e.jsx(p,{variant:"outline",onClick:()=>t({open:!1,payload:null}),className:"w-full sm:w-auto",children:"Cancel"}),e.jsx(p,{onClick:async()=>{if(N.payload)try{await $.authorizeSubscription(N.payload)}catch{}},className:"w-full sm:w-auto",children:"Complete Authorization"})]});return i?e.jsx(Q,{open:N.open,onOpenChange:O=>{O||t({open:!1,payload:null})},children:e.jsxs(Z,{children:[e.jsxs(S,{children:[e.jsx(ee,{children:"Re-authorization Required"}),e.jsx(se,{children:"Your payment method needs to be re-authorized to proceed with the subscription change."})]}),d,e.jsx(Ie,{children:j})]})}):e.jsx(ae,{open:N.open,onOpenChange:O=>{O||t({open:!1,payload:null})},children:e.jsxs(te,{className:"max-w-md",children:[e.jsxs(ne,{children:[e.jsx(le,{children:"Re-authorization Required"}),e.jsx(re,{children:"Your card needs to be re-authorized to proceed with the subscription change."})]}),d,e.jsx(ze,{children:j})]})})})(),he&&e.jsxs("div",{className:"flex items-start gap-3 p-4 bg-blue-50 border border-blue-200 rounded-md",children:[e.jsx(Je,{className:"h-5 w-5 text-blue-600 mt-0.5 flex-shrink-0 animate-spin"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-blue-900",children:"Activating your subscription..."}),e.jsx("p",{className:"text-xs text-blue-800 mt-1",children:"We're processing your payment authorization. This may take a few moments."})]})]}),e.jsx(es,{currentPlan:Y??null,subscription:l,liveSubscription:c,pendingSubscription:r,autoAuthCountdown:M,onChanged:()=>a(_()),onCancelPendingClick:pe,billingCycle:m}),e.jsx(ss,{plans:s,currentPlanAmount:Y==null?void 0:Y.amountMinor,onSelectPlan:xe,loading:n,currentBilling
1Cycle:m}),e.jsxs(k,{children:[e.jsxs(E,{children:[e.jsx(P,{children:"Invoices"}),e.jsx(U,{children:"Your payment history"})]}),e.jsx(T,{children:e.jsx(Qe,{})})]}),u&&e.jsx(as,{subscription:u,onReauthorizeClick:je,onCancelClick:()=>v(!0),loading:n}),e.jsx(ue,{open:x!==null,onOpenChange:d=>{d||g(null)},title:"Confirm plan change",description:"Review the details before confirming.",dismissDisabled:n,children:x?e.jsx(Re,{planKey:x.planKey,planName:x.planName,billingCycle:m,layout:"inline",showHeading:!1,onBack:()=>g(null),backLabel:"Cancel",navigateOnAppliedTo:null,onCompleted:d=>{g(null),d.kind==="applied"&&a(V())}}):null}),e.jsx(ts,{open:A,onConfirm:fe,onOpenChange:v,loading:n,status:u==null?void 0:u.status,cancelAt:u==null?void 0:u.cancelAt,nextChargeDate:u==null?void 0:u.nextChargeDate})]})}function bs(){return e.jsx(ns,{})}export{bs as BillingPage};
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.