1import{_ as Fe,w as ae,Q as fe,r as x,u as K,x as F,j as e,C as S,a as A,b as M,z as $e,B as l,c as C,A as q,H as v,k as I,l as _,m as ye,a4 as Te,K as P,f as Ue,g as Be,D as qe,a0 as me,E as Ne,M as Ie,i as xe,Z as Y,X as Re,N as Ke,S as _e,d as W,aU as Oe}from"./index-DD4Yu2xy.js";import{P as G}from"./progress-u95UBNt7.js";import{D as X,b as ee,c as se,d as te,e as Qe}from"./dialog-BSYV2WIS.js";import{E as ve,l as we,u as Se,a as Ce,P as Pe}from"./index-mXfSe6h5.js";import{L as $}from"./loader-circle-BWQRDiCL.js";import{P as Ye}from"./plus-DtlE8O38.js";import{S as ze}from"./star-mkcD8UBs.js";import{C as He}from"./credit-purchase-modal-D7K_8i65.js";import{B as Ve}from"./building-Ck83wl21.js";import{C as Je}from"./calendar-DphhoDcv.js";import{E as Ze}from"./external-link-DZkYUyts.js";import"./index-Lw7YEnm3.js";/** 2 * @license lucide-react v0.453.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 ue=Fe("CircleArrowUp",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 12-4-4-4 4",key:"177agl"}],["path",{d:"M12 16V8",key:"1sbj14"}]]),We=we("pk_live_51He8urDbcyUePzMcNuB8CrN47csDoJm1jrBG8C2T59Wq93DIbT2QE9STzav53RpshEYpyvIYs8jvPZnJ7VLaE5tx008xmIuFM8"),he={visa:"text-blue-600",mastercard:"text-orange-600",amex:"text-blue-700",discover:"text-orange-500",card:"text-gray-600"},Ge={visa:"Visa",mastercard:"Mastercard",amex:"American Express",discover:"Discover",card:"Card"};function Xe({clientSecret:n,onSuccess:c,onCancel:r}){const i=Se(),d=Ce(),[o,u]=x.useState(!1),[b,p]=x.useState(!0),{toast:g}=ae(),w=async N=>{if(N.preventDefault(),!(!i||!d)){u(!0);try{const{error:j,setupIntent:y}=await i.confirmSetup({elements:d,confirmParams:{return_url:window.location.origin+"/subscription"},redirect:"if_required"});j?g({title:"Error",description:j.message,variant:"destructive"}):y&&y.status==="succeeded"&&(await P("POST","/api/payment-methods/confirm",{setupIntentId:y.id,setAsDefault:b}),g({title:"Success!",description:"Payment method added successfully"}),c())}catch(j){g({title:"Error",description:j.message||"Failed to add payment method",variant:"destructive"})}finally{u(!1)}}};return e.jsxs("form",{onSubmit:w,className:"space-y-4",children:[e.jsx(Pe,{}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"setAsDefault",checked:b,onChange:N=>p(N.target.checked),className:"rounded border-gray-300"}),e.jsx("label",{htmlFor:"setAsDefault",className:"text-sm text-muted-foreground",children:"Set as default payment method"})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4",children:[e.jsx(l,{"data-testid":"button-cancel-add-card",type:"button",variant:"outline",onClick:r,disabled:o,children:"Cancel"}),e.jsx(l,{"data-testid":"button-submit-add-card",type:"submit",disabled:!i||o,className:"bg-orange-500 hover:bg-orange-600 text-white",children:o?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"mr-2 h-4 w-4 animate-spin"}),"Adding..."]}):e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"mr-2 h-4 w-4"}),"Add Card"]})})]})]})}function es(){const{toast:n}=ae(),c=fe(),[r,i]=x.useState(!1),[d,o]=x.useState(""),{data:u,isLoading:b}=K({queryKey:["/api/payment-methods"]}),p=F({mutationFn:async()=>await P("POST","/api/payment-methods/setup",{}),onSuccess:t=>{o(t.clientSecret),i(!0)},onError:t=>{n({title:"Error",description:t.message||"Failed to initialize card addition",variant:"destructive"})}}),g=F({mutationFn:async t=>{await P("DELETE",`/api/payment-methods/${t}`,{})},onSuccess:()=>{n({title:"Success",description:"Payment method removed successfully"}),c.invalidateQueries({queryKey:["/api/payment-methods"]})},onError:t=>{n({title:"Error",description:t.message||"Failed to remove payment method",variant:"destructive"})}}),w=F({mutationFn:async t=>{await P("POST",`/api/payment-methods/${t}/default`,{})},onSuccess:()=>{n({title:"Success",description:"Default payment method updated"}),c.invalidateQueries({queryKey:["/api/payment-methods"]})},onError:t=>{n({title:"Error",description:t.message||"Failed to set default payment method",variant:"destructive"})}}),N=()=>{p.mutate()},j=()=>{i(!1),o(""),c.invalidateQueries({queryKey:["/api/payment-methods"]})},y=t=>{confirm("Are you sure you want to remove this payment method?")&&g.mutate(t)},ne=t=>{w.mutate(t)};return e.jsxs(e.Fragment,{children:[e.jsxs(S,{children:[e.jsx(A,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(M,{children:"Payment Methods"}),e.jsx($e,{children:"Manage your payment methods for subscriptions and credit purchases"})]}),e.jsxs(l,{"data-testid":"button-add-payment-method",onClick:N,disabled:p.isPending,className:"bg-orange-500 hover:bg-orange-600 text-white",children:[p.isPending?e.jsx($,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Ye,{className:"mr-2 h-4 w-4"}),"Add Card"]})]})}),e.jsx(C,{children:b?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx($,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):u?.paymentMethods.length===0?e.jsxs(q,{children:[e.jsx(v,{className:"h-4 w-4"}),e.jsx(I,{children:"No payment methods on file. Add a card to manage your subscription and purchase credits."})]}):e.jsx("div",{className:"space-y-3",children:u?.paymentMethods.map(t=>e.jsxs("div",{className:"flex items-center justify-between p-4 border rounded-lg hover:bg-muted/50 transition-colors","data-testid":`payment-method-${t.id}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(_,{className:`h-8 w-8 ${he[t.brand.toLowerCase()]||he.card}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"font-medium",children:[Ge[t.brand.toLowerCase()]||"Card"," â¢â¢â¢â¢ ",t.last4]}),t.isDefault&&e.jsxs(ye,{variant:"default",className:"bg-orange-500",children:[e.jsx(ze,{className:"h-3 w-3 mr-1"}),"Default"]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Expires ",t.expMonth,"/",t.expYear]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[!t.isDefault&&e.jsx(l,{"data-testid":`button-set-default-${t.id}`,variant:"outline",size:"sm",onClick:()=>ne(t.id),disabled:w.isPending,children:"Set as Default"}),e.jsx(l,{"data-testid":`button-remove-${t.id}`,variant:"ghost",size:"sm",onClick:()=>y(t.id),disabled:g.isPending||t.isDefault,className:"text-red-600 hover:text-red-700 hover:bg-red-50",children:e.jsx(Te,{className:"h-4 w-4"})})]})]},t.id))})})]}),e.jsx(X,{open:r,onOpenChange:i,children:e.jsxs(ee,{className:"max-w-md",children:[e.jsx(se,{children:e.jsx(te,{children:"Add Payment Method"})}),d&&e.jsx(ve,{stripe:We,options:{clientSecret:d},children:e.jsx(Xe,{clientSecret:d,onSuccess:j,onCancel:()=>{i(!1),o("")}})})]})})]})}const ss=we("pk_live_51He8urDbcyUePzMcNuB8CrN47csDoJm1jrBG8C2T59Wq93DIbT2QE9STzav53RpshEYpyvIYs8jvPZnJ7VLaE5tx008xmIuFM8"),pe={free:"text-slate-500",starter:"text-blue-500",growth:"text-green-600",pro:"text-purple-600",enterprise:"text-orange-600",dfy_starter:"text-cyan-600",dfy_growth:"text-teal-600",dfy_pro:"text-indigo-600"},ge={free:"bg-slate-50 dark:bg-slate-900/50",starter:"bg-blue-50 dark:bg-blue-950/30",growth:"bg-green-50 dark:bg-green-950/30",pro:"bg-purple-50 dark:bg-purple-950/30",enterprise:"bg-orange-50 dark:bg-orange-950/30"},je={active:{label:"Active",color:"bg-green-100 text-green-700 dark:bg-green-900/50 dark:text-green-300",icon:Ne},inactive:{label:"Inactive",color:"bg-slate-100 text-slate-600 dar
6k:bg-slate-800 dark:text-slate-400",icon:me},cancelled:{label:"Cancelled",color:"bg-red-100 text-red-700 dark:bg-red-900/50 dark:text-red-300",icon:me},past_due:{label:"Past Due",color:"bg-orange-100 text-orange-700 dark:bg-orange-900/50 dark:text-orange-300",icon:v},trialing:{label:"Trial",color:"bg-blue-100 text-blue-700 dark:bg-blue-900/50 dark:text-blue-300",icon:qe},incomplete:{label:"Incomplete",color:"bg-yellow-100 text-yellow-700 dark:bg-yellow-900/50 dark:text-yellow-300",icon:v}},be=({priceInCents:n})=>{const{convertFromUSD:c,formatCurrency:r}=Oe(),[i,d]=x.useState("");return x.useEffect(()=>{(async()=>{const u=await c(n);d(r(u))})()},[n,c,r]),i?e.jsx("span",{children:i}):e.jsx("span",{className:"text-slate-400",children:"..."})},ts=({clientSecret:n,planName:c,onSuccess:r,onError:i})=>{const d=Se(),o=Ce(),[u,b]=x.useState(!1),[p,g]=x.useState(""),w=async N=>{if(N.preventDefault(),!d||!o)return;b(!0),g("");const{error:j}=await d.confirmPayment({elements:o,confirmParams:{return_url:`${window.location.origin}/subscription?success=true`},redirect:"if_required"});j?(g(j.message||"An error occurred"),i(j.message||"Payment failed"),b(!1)):r()};return e.jsxs("form",{onSubmit:w,className:"space-y-6",children:[e.jsxs("div",{className:"bg-muted/50 p-4 rounded-lg",children:[e.jsxs("h3",{className:"font-semibold text-sm mb-1",children:["Subscribing to ",c]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Enter your payment details to complete your subscription."})]}),e.jsx(Pe,{}),p&&e.jsxs(q,{variant:"destructive",children:[e.jsx(v,{className:"h-4 w-4"}),e.jsx(I,{children:p})]}),e.jsx(l,{type:"submit",className:"w-full",disabled:!d||u,children:u?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"mr-2 h-4 w-4 animate-spin"}),"Processing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"mr-2 h-4 w-4"}),"Confirm Payment"]})})]})};function as(n,c){const r=new Date(n).getTime(),i=new Date(c).getTime(),d=Date.now();return i<=r?0:Math.min(100,Math.max(0,Math.round((d-r)/(i-r)*100)))}function ns(n){const c=new Date(n).getTime()-Date.now();return Math.max(0,Math.ceil(c/(1e3*60*60*24)))}function B(n){return new Date(n).toLocaleDateString(void 0,{month:"long",day:"numeric",year:"numeric"})}function js(){const{toast:n}=ae(),{user:c}=Ue(),[,r]=Be(),i=fe(),[d,o]=x.useState(!1),[u,b]=x.useState(!1),[p,g]=x.useState(""),[w,N]=x.useState(""),[j,y]=x.useState(!1),[ne,t]=x.useState(null);x.useEffect(()=>{const s=new URLSearchParams(window.location.search);s.get("success")==="true"&&(n({title:"Payment Successful!",description:"Your subscription has been activated."}),window.history.replaceState({},"","/subscription"),i.invalidateQueries({queryKey:["/api/user/subscription"]}),i.invalidateQueries({queryKey:["/api/user"]})),s.get("canceled")==="true"&&(n({title:"Payment Cancelled",description:"No charges were made.",variant:"destructive"}),window.history.replaceState({},"","/subscription")),s.get("credits")==="1"&&(y(!0),window.history.replaceState({},"","/subscription"))},[]);const{data:a,isLoading:ke}=K({queryKey:["/api/user/subscription"]}),{data:T}=K({queryKey:["/api/user/plan"]}),{data:m}=K({queryKey:["/api/credits/status"]}),{data:ie=[],isLoading:Ee}=K({queryKey:["/api/user/payment-history"]}),z=F({mutationFn:()=>P("POST","/api/user/cancel-subscription",{}),onSuccess:()=>{n({title:"Cancellation Scheduled",description:"Your subscription will remain active until the end of the current billing period."}),i.invalidateQueries({queryKey:["/api/user/subscription"]}),o(!1)},onError:s=>{n({title:"Cancellation Failed",description:s.message||"Please try again.",variant:"destructive"})}}),H=F({mutationFn:()=>P("POST","/api/user/reactivate-subscription",{}),onSuccess:()=>{n({title:"Subscription Reactivated",description:"Your subscription will continue as normal."}),i.invalidateQueries({queryKey:["/api/user/subscription"]})},onError:s=>{n({title:"Reactivation Failed",description:s.message||"Please try again.",variant:"destructive"})}}),O=F({mutationFn:()=>P("POST","/api/user/update-payment-method",{}),onSuccess:s=>{s.authorization_url&&(window.location.href=s.authorization_url)},onError:s=>{n({title:"Update Failed",description:s.message||"Please try again.",variant:"destructive"})}});F({mutationFn:async({planId:s,planName:L})=>(t(s),{...await P("POST","/api/subscriptions/create",{planId:s,interval:"monthly"}),planName:L}),onSuccess:s=>{s.clientSecret?(g(s.clientSecret),N(s.planName),b(!0),t(null)):s.success&&(n({title:"Success",description:"Your subscription has been updated."}),i.invalidateQueries({queryKey:["/api/user"]}),i.invalidateQueries({queryKey:["/api/user/subscription"]}),t(null))},onError:s=>{n({title:"Error",description:s.message||"Failed to process subscription.",variant:"destructive"}),t(null)}});const De=()=>{b(!1),g(""),n({title:"Payment Successful!",description:"Your subscription is now active."}),i.invalidateQueries({queryKey:["/api/user"]}),i.invalidateQueries({queryKey:["/api/user/subscription"]})},Le=async s=>{window.open(s,"_blank")},f=c?.role==="super_admin",re=c?.subscriptionPlan||"free",h=re==="free"&&!f,k=a?.interval==="lifetime",Ae=!h&&!f&&a?.status==="active"&&!a?.cancelAtPeriodEnd,E=!f&&a?.cancelAtPeriodEnd===!0,le=!f&&a?.status==="cancelled",ce=a?.plan?.id||"free",V=pe[ce]||pe.free,J=je[a?.status||"active"]||je.active,Me=J.icon,de=a?as(a.currentPeriodStart,a.
6currentPeriodEnd):0,U=a?ns(a.currentPeriodEnd):0,oe=T?.sendingLimits?.monthlyUsed||0,D=T?.monthlySendingLimit||T?.sendingLimits?.monthlyLimit||0,Z=D>0?Math.min(100,Math.round(oe/D*100)):0;return ke?e.jsx("div",{className:"container mx-auto px-4 py-8 max-w-6xl",children:e.jsxs("div",{className:"animate-pulse space-y-6",children:[e.jsx("div",{className:"h-8 bg-slate-200 dark:bg-slate-700 rounded w-1/3"}),e.jsx("div",{className:"h-40 bg-slate-200 dark:bg-slate-700 rounded"}),e.jsx("div",{className:"h-48 bg-slate-200 dark:bg-slate-700 rounded"})]})}):e.jsxs("div",{className:"container mx-auto px-4 py-8 max-w-6xl",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-3xl font-bold text-slate-900 dark:text-white mb-1",children:"Subscription & Billing"}),e.jsx("p",{className:"text-slate-500 dark:text-slate-400",children:"Manage your plan, billing period, and payment details"})]}),e.jsx(S,{className:`mb-8 border-2 ${E||le?"border-orange-300 dark:border-orange-700":"border-slate-200 dark:border-slate-700"}`,children:e.jsxs(C,{className:"pt-6",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-start md:justify-between gap-6",children:[e.jsxs("div",{className:"flex items-start gap-4 flex-1",children:[e.jsx("div",{className:`p-3 rounded-xl ${ge[ce]||ge.free}`,children:h?e.jsx(Ie,{className:`h-7 w-7 ${V}`}):re.includes("dfy")?e.jsx(Ve,{className:`h-7 w-7 ${V}`}):e.jsx(xe,{className:`h-7 w-7 ${V}`})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap mb-1",children:[e.jsx("h2",{className:"text-xl font-bold text-slate-900 dark:text-white",children:a?.plan?.name||"Free Plan"}),e.jsxs("span",{className:`inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-xs font-semibold ${J.color}`,children:[e.jsx(Me,{className:"h-3.5 w-3.5"}),E?"Cancels at period end":J.label]}),f&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-xs font-semibold bg-purple-100 text-purple-700 dark:bg-purple-900/50 dark:text-purple-300",children:[e.jsx(Y,{className:"h-3.5 w-3.5"}),"Unlimited Access"]}),!h&&!f&&e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-slate-100 dark:bg-slate-800 text-slate-600 dark:text-slate-400 capitalize",children:[k?"Lifetime":a?.interval||"monthly"," billing"]})]}),!h&&!f&&a&&e.jsxs("div",{className:"text-sm text-slate-500 dark:text-slate-400 flex items-center gap-1 mb-3",children:[e.jsx(Je,{className:"h-3.5 w-3.5"}),E?`Access ends ${B(a.currentPeriodEnd)}`:k?"Never expires":`Renews ${B(a.currentPeriodEnd)}`,!k&&e.jsxs("span",{className:"ml-1 text-slate-400",children:["· ",U," day",U!==1?"s":""," remaining"]})]}),!h&&!f&&!k&&a&&e.jsxs("div",{className:"mt-2 max-w-xs",children:[e.jsxs("div",{className:"flex justify-between text-xs text-slate-400 mb-1",children:[e.jsx("span",{children:B(a.currentPeriodStart)}),e.jsxs("span",{children:[de,"% elapsed"]})]}),e.jsx(G,{value:de,className:`h-1.5 ${E?"[&>div]:bg-orange-400":"[&>div]:bg-green-500"}`})]}),h&&e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400 mt-1",children:"You're on the free plan. Upgrade to unlock more emails, campaigns, and features."})]})]}),!f&&e.jsxs("div",{className:"flex flex-col gap-2 min-w-fit",children:[h&&e.jsxs(l,{className:"bg-[#EB4C0E] hover:bg-[#c73f0b] text-white",onClick:()=>r("/pricing"),children:[e.jsx(ue,{className:"mr-2 h-4 w-4"}),"Upgrade Plan"]}),Ae&&!k&&e.jsxs(e.Fragment,{children:[e.jsx(l,{variant:"outline",onClick:()=>O.mutate(),disabled:O.isPending,children:O.isPending?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"mr-2 h-4 w-4 animate-spin"}),"Opening..."]}):e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"mr-2 h-4 w-4"}),"Manage Billing"]})}),e.jsxs(l,{variant:"outline",className:"text-red-600 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950 border-red-200 dark:border-red-800",onClick:()=>o(!0),children:[e.jsx(Re,{className:"mr-2 h-4 w-4"}),"Cancel Plan"]})]}),E&&e.jsx(l,{onClick:()=>H.mutate(),disabled:H.isPending,className:"bg-green-600 hover:bg-green-700 text-white",children:H.isPending?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"mr-2 h-4 w-4 animate-spin"}),"Reactivating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ke,{className:"mr-2 h-4 w-4"}),"Keep Subscription"]})}),le&&!h&&e.jsxs(l,{onClick:()=>r("/pricing"),className:"bg-[#EB4C0E] hover:bg-[#c73f0b] text-white",children:[e.jsx(ue,{className:"mr-2 h-4 w-4"}),"Resubscribe"]})]})]}),E&&e.jsxs(q,{className:"mt-4 border-orange-300 bg-orange-50 dark:bg-orange-950/30",children:[e.jsx(v,{className:"h-4 w-4 text-orange-600"}),e.jsxs(I,{className:"text-orange-800 dark:text-orange-300",children:[e.jsx("strong",{children:"Your subscription is scheduled to cancel."})," You'll keep access to all features until"," ",e.jsx("strong",{children:B(a.currentPeriodEnd)}),'. Click "Keep Subscription" above to undo this.']})]}),a?.status==="past_due"&&e.jsxs(q,{variant:"destructive",className:"mt-4",children:[e.jsx(v,{className:"h-4 w-4"}),e.jsxs(I,{children:[e.jsx("strong",{children:"Payment failed."})," Please update your payment method to avoid losing access."," ",e.jsx("button",{className:"underline font-medium",onClick:()=>O.mutate(),children:"Update now"})]})]})]})}),e.jsxs("div",{className:"grid gap-8 lg:grid-cols-3",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-6",children:[T&&e.jsxs(S,{children:[e.jsx(A,{children:e.jsx(M,{className:"text-base",children:h?"Email Usage (Lifetime Limit)":"Email Usage This Billing Perio
6d"})}),e.jsxs(C,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-end mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{className:"h-4 w-4 text-blue-600"}),e.jsx("span",{className:"text-sm font-medium text-slate-700 dark:text-slate-300",children:"Emails Sent"})]}),e.jsxs("span",{className:"text-sm text-slate-500",children:[oe.toLocaleString()," /"," ",D===-1?"Unlimited":D.toLocaleString()]})]}),D>0&&D!==-1&&e.jsx(G,{value:Z,className:`h-2 ${Z>=90?"[&>div]:bg-red-500":Z>=70?"[&>div]:bg-orange-400":"[&>div]:bg-blue-500"}`}),D===-1&&e.jsx("p",{className:"text-xs text-green-600 mt-1",children:"Unlimited sending on your plan"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 pt-1",children:[e.jsxs("div",{className:"p-3 bg-slate-50 dark:bg-slate-800/50 rounded-lg text-center",children:[e.jsx("div",{className:"text-lg font-bold text-slate-800 dark:text-slate-200",children:(T.campaignEmailsThisPeriod??0).toLocaleString()}),e.jsx("div",{className:"text-xs text-slate-500 mt-0.5",children:h?"Campaign emails (lifetime)":"Campaign emails this period"})]}),e.jsxs("div",{className:"p-3 bg-slate-50 dark:bg-slate-800/50 rounded-lg text-center",children:[e.jsx("div",{className:"text-lg font-bold text-slate-800 dark:text-slate-200",children:(T.newsletterEmailsThisPeriod??0).toLocaleString()}),e.jsx("div",{className:"text-xs text-slate-500 mt-0.5",children:h?"Newsletter emails (lifetime)":"Newsletter emails this period"})]})]})]})]}),m&&(()=>{const s=m.monthlyLimit===-1,L=s?0:Math.max(0,100-Math.round(m.monthlyRemaining/Math.max(1,m.monthlyLimit)*100)),R=!s&&m.monthlyRemaining<=0,Q=!s&&m.monthlyRemaining>0&&m.monthlyRemaining<m.monthlyLimit*.2;return e.jsxs(S,{className:R?"border-red-300 dark:border-red-700":Q?"border-orange-300 dark:border-orange-700":"",children:[e.jsx(A,{children:e.jsxs(M,{className:"flex items-center gap-2 text-base",children:[e.jsx(Y,{className:`h-5 w-5 ${R?"text-red-600":Q?"text-orange-600":"text-green-600"}`}),"Email Credits"]})}),e.jsxs(C,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-end mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-slate-700 dark:text-slate-300",children:"Monthly allowance"}),e.jsx("span",{className:"text-sm text-slate-500",children:s?"Unlimited":`${m.monthlyRemaining.toLocaleString()} / ${m.monthlyLimit.toLocaleString()} remaining`})]}),e.jsx(G,{value:s?0:L,className:`h-2 ${R?"[&>div]:bg-red-500":Q?"[&>div]:bg-orange-400":"[&>div]:bg-green-500"}`}),s&&e.jsx("p",{className:"text-xs text-purple-600 dark:text-purple-400 mt-1",children:"No sending limits on your account"})]}),m.addOnCredits>0&&e.jsxs("div",{className:"flex items-center justify-between p-3 bg-amber-50 dark:bg-amber-950/30 rounded-lg border border-amber-200 dark:border-amber-800",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-amber-800 dark:text-amber-300",children:"Add-on Credits"}),e.jsx("div",{className:"text-xs text-amber-600 dark:text-amber-400",children:"Never expire · roll over indefinitely"})]}),e.jsx("div",{className:"text-xl font-bold text-amber-700 dark:text-amber-300",children:m.addOnCredits.toLocaleString()})]}),R&&e.jsxs(q,{className:"border-red-300 bg-red-50 dark:bg-red-950/20",children:[e.jsx(v,{className:"h-4 w-4 text-red-600"}),e.jsxs(I,{className:"text-red-800 dark:text-red-300",children:[e.jsx("strong",{children:"Credits exhausted."})," ",m.addOnCredits>0?`Your ${m.addOnCredits.toLocaleString()} add-on credits will be used for new sends.`:"Purchase add-on credits to continue sending emails."]})]}),Q&&e.jsxs(q,{className:"border-orange-300 bg-orange-50 dark:bg-orange-950/20",children:[e.jsx(v,{className:"h-4 w-4 text-orange-600"}),e.jsxs(I,{className:"text-orange-800 dark:text-orange-300",children:[e.jsx("strong",{children:"Running low!"})," Only ",m.monthlyRemaining.toLocaleString()," credits left this month."]})]}),!f&&e.jsxs(l,{className:"w-full",size:"lg",onClick:()=>y(!0),children:[e.jsx(Y,{className:"mr-2 h-4 w-4"}),"Purchase Add-on Credits"]})]})]})})(),e.jsxs(S,{children:[e.jsx(A,{children:e.jsx(M,{className:"text-base",children:"Payment History"})}),e.jsx(C,{children:Ee?e.jsx("div",{className:"space-y-2",children:[...Array(3)].map((s,L)=>
6e.jsx("div",{className:"h-14 bg-slate-100 dark:bg-slate-800 rounded animate-pulse"},L))}):ie.length===0?e.jsxs("div",{className:"text-center py-10 text-slate-400 dark:text-slate-500",children:[e.jsx(_,{className:"h-10 w-10 mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:"No payment history yet"})]}):e.jsx("div",{className:"space-y-2",children:ie.map(s=>e.jsxs("div",{className:"flex items-center justify-between p-3.5 border border-slate-200 dark:border-slate-700 rounded-lg hover:bg-slate-50 dark:hover:bg-slate-800/50 transition-colors",children:[e.jsxs("div",{className:"flex-1 min-w-0 mr-3",children:[e.jsx("div",{className:"font-medium text-slate-900 dark:text-white text-sm truncate",children:s.description}),e.jsx("div",{className:"text-xs text-slate-400 mt-0.5",children:new Date(s.date).toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"})})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"font-semibold text-slate-900 dark:text-white text-sm",children:s.currency==="USD"||s.currency==="usd"?`$${(s.amount/100).toFixed(2)}`:`${s.currency} ${(s.amount/100).toLocaleString()}`}),e.jsx(ye,{variant:s.status==="successful"?"default":s.status==="failed"?"destructive":"secondary",className:"text-xs",children:s.status})]}),s.invoiceUrl&&e.jsx(l,{variant:"ghost",size:"sm",onClick:()=>Le(s.invoiceUrl),title:"Download invoice",children:e.jsx(Ze,{className:"h-4 w-4"})})]})]},s.id))})})]}),e.jsx(es,{})]}),e.jsxs("div",{className:"space-y-6",children:[a?.plan?.features&&a.plan.features.length>0&&e.jsxs(S,{children:[e.jsx(A,{children:e.jsx(M,{className:"text-base",children:"What's included"})}),e.jsxs(C,{children:[e.jsx("ul",{className:"space-y-2",children:a.plan.features.slice(0,7).map((s,L)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm",children:[e.jsx(Ne,{className:"h-4 w-4 text-green-600 shrink-0 mt-0.5"}),e.jsx("span",{className:"text-slate-600 dark:text-slate-400",children:s})]},L))}),a.plan.features.length>7&&e.jsx("button",{className:"text-xs text-[#EB4C0E] mt-2 hover:underline",onClick:()=>r("/pricing"),children:"View all features"})]})]}),!h&&a&&e.jsxs(S,{children:[e.jsx(A,{children:e.jsx(M,{className:"text-base",children:"Billing Details"})}),e.jsxs(C,{className:"space-y-3 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-slate-500",children:"Plan"}),e.jsx("span",{className:"font-medium text-slate-800 dark:text-slate-200",children:a.plan?.name})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-slate-500",children:"Billing cycle"}),e.jsx("span",{className:"font-medium text-slate-800 dark:text-slate-200 capitalize",children:k?"One-time":a.interval})]}),!k&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-slate-500",children:E?"Ends on":"Next renewal"}),e.jsx("span",{className:"font-medium text-slate-800 dark:text-slate-200",children:B(a.currentPeriodEnd)})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-slate-500",children:"Days remaining"}),e.jsxs("span",{className:`font-medium ${U<=7?"text-orange-600":"text-slate-800 dark:text-slate-200"}`,children:[U," day",U!==1?"s":""]})]})]}),a.interval==="monthly"&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-slate-500",children:"Amount"}),e.jsxs("span",{className:"font-medium text-slate-800 dark:text-slate-200",children:[e.jsx(be,{priceInCents:a.plan?.priceMonthly||0}),"/mo"]})]}),a.interval==="annual"&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-slate-500",children:"Amount"}),e.jsxs("span",{className:"font-medium text-slate-800 dark:text-slate-200",children:[e.jsx(be,{priceInCents:a.plan?.priceAnnual||0}),"/yr"]})]})]})]}),e.jsxs(S,{children:[e.jsx(A,{children:e.jsx(M,{className:"text-base",children:"Quick Actions"})}),e.jsxs(C,{className:"space-y-2",children:[e.jsxs(l,{variant:"outline",className:"w-full justify-between",onClick:()=>r("/pricing"),children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(xe,{className:"h-4 w-4"}),h?"Upgrade Plan":"Compare Plans"]}),e.jsx(W,{className:"h-4 w-4 text-slate-400"})]}),!f&&e.jsxs(l,{variant:"outline",className:"w-full justify-between",onClick:()=>y(!0),children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Y,{className:"h-4 w-4"}),"Buy Email Credits"]}),e.jsx(W,{className:"h-4 w-4 text-slate-400"})]}),e.jsxs(l,{variant:"outline",className:"w-full justify-between",onClick:()=>r("/help"),children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(v,{className:"h-4 w-4"}),"Billing Support"]}),e.jsx(W,{className:"h-4 w-4 text-slate-400"})]})]})]})]})]}),e.jsx(X,{open:d,onOpenChange:o,children:e.jsxs(ee,{children:[e.jsxs(se,{children:[e.jsx(te,{children:"Cancel Subscription"}),e.jsx(Qe,{children:"Your subscription will remain active until the end of your current billing period."})]}),e.jsxs("div",{className:"space-y-4",children:[a&&e.jsxs("div",{className:"p-4 bg-slate-50 dark:bg-slate-800 rounded-lg text-sm space-y-2",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-slate-500",children:"Access continues until"}),e.jsx("span",{className:"font-medium",children:B(a.currentPeriodEnd)})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-slate-500",children:"Days remaining"}),e.jsxs("span",{className:"font-medium",children:[U," days"]})]})]}
6),e.jsx("p",{className:"text-sm text-slate-600 dark:text-slate-400",children:"After that date, your account will revert to the free plan. You can reactivate at any time before then."}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(l,{variant:"outline",onClick:()=>o(!1),className:"flex-1",children:"Keep Subscription"}),e.jsx(l,{variant:"destructive",onClick:()=>z.mutate(),disabled:z.isPending,className:"flex-1",children:z.isPending?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"mr-2 h-4 w-4 animate-spin"}),"Cancelling..."]}):"Cancel at Period End"})]})]})]})}),u&&p&&e.jsx(X,{open:u,onOpenChange:b,children:e.jsxs(ee,{className:"max-w-md",children:[e.jsx(se,{children:e.jsx(te,{children:"Complete Your Subscription"})}),e.jsx(ve,{stripe:ss,options:{clientSecret:p},children:e.jsx(ts,{clientSecret:p,planName:w,onSuccess:De,onError:s=>n({title:"Payment Failed",description:s,variant:"destructive"})})})]})}),e.jsx(He,{isOpen:j,onClose:()=>y(!1)})]})}export{js 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.