1import{l as s,m as r,q as t,B as b,u as d,K as o,p as i,F as p,v as ce,y as B,z as ye,J as x,Y as ge,aa as me,ac as be,D as F,W as xe,X as ve,r as v,e as g,_ as fe}from"./vue-vendor-B52ivs5F.js";import{b as pe,c as _e,a as he}from"./query-vendor-Ab0nfCYP.js";import{A as ke}from"./AddCardModal-C6AsTDfe.js";import{n as we,o as Pe,f as Ce,p as Se,q as Ae}from"./index-CEp9VCc9.js";import{_ as je,u as De,t as E}from"./index-NM9cAr_v.js";import{C as Te,R as O,X as ze,ah as Me,c as Ne,ak as Ie,i as Ue,L as Le,w as Ve,ai as Ye}from"./ui-vendor-D-1UBobO.js";import"./useCardsQuery-BBbOJ3Hx.js";import"./rewardful-2QOTUYRt.js";import"./date-vendor-HBGOQ70J.js";import"./twilio-DAuME2Y9.js";import"./charts-D4hDxUnJ.js";import"./socket-CzTGKfeH.js";const Be={key:0,class:"mb-6 rounded-lg border-2 border-teal-500 bg-teal-50 p-4 dark:border-teal-500/50 dark:bg-teal-900/20"},Fe={class:"flex flex-wrap items-center justify-between gap-4"},Ee={class:"flex items-center gap-3"},Oe={class:"ml-2 font-bold text-gray-900 dark:text-white"},Re={class:"font-bold text-gray-900 dark:text-white"},$e={key:1,class:"flex items-center justify-center rounded-lg border border-gray-200 bg-white py-12 dark:border-gray-700 dark:bg-gray-800"},qe={key:2,class:"rounded-lg border border-red-200 bg-red-50 p-4 dark:border-red-900/50 dark:bg-red-900/20"},Ge={class:"text-red-700 dark:text-red-400"},Ke={key:3,class:"grid gap-4 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"},We={key:0,class:"absolute top-4 right-0 -mr-8 rotate-45 bg-teal-500 px-10 py-1 text-xs font-bold text-white"},Xe={key:1,class:"absolute top-4 right-0 -mr-8 rotate-45 bg-amber-500 px-10 py-1 text-xs font-bold text-white"},Je={class:"text-lg font-bold text-gray-900 dark:text-white"},Qe={class:"mt-2"},He={class:"text-2xl font-bold text-gray-900 dark:text-white"},Ze={key:2,class:"mt-3 text-sm text-gray-600 dark:text-gray-400"},et={class:"mt-4 space-y-2 border-t border-gray-200 pt-4 dark:border-gray-700"},tt={class:"flex items-center gap-2"},at={class:"text-sm text-gray-700 dark:text-gray-300"},st={key:0,class:"flex items-center gap-2"},rt={class:"text-sm text-gray-700 dark:text-gray-300"},lt={key:3,class:"mt-3 text-xs font-medium text-amber-600 dark:text-amber-400"},ot={key:4,class:"mt-3 text-xs font-medium text-red-600 dark:text-red-400"},nt=["onClick","disabled","title"],dt={key:0,class:"fixed inset-0 z-50 flex justify-end"},it={class:"relative z-10 w-full max-w-md overflow-y-auto bg-white shadow-xl dark:bg-gray-800"},ut={class:"sticky top-0 z-10 flex items-center justify-between border-b border-gray-200 bg-white p-4 dark:border-gray-700 dark:bg-gray-800"},ct={class:"p-4"},yt={key:0,class:"mb-4 rounded-lg border border-gray-200 bg-gray-50 p-4 dark:border-gray-700 dark:bg-gray-700/50"},gt={class:"mt-1 text-sm text-gray-600 dark:text-gray-400"},mt={key:1,class:"mb-4 rounded-lg border border-yellow-200 bg-yellow-50 p-4 dark:border-yellow-900/50 dark:bg-yellow-900/20"},bt={class:"flex items-start gap-3"},xt={key:2,class:"flex items-center justify-center py-8"},vt={class:"rounded-lg border border-gray-200 bg-gray-50 p-4 dark:border-gray-700 dark:bg-gray-700/50"},ft={class:"space-y-3"},pt={class:"flex justify-between"},_t={class:"font-medium text-gray-900 dark:text-white"},ht={class:"flex justify-between"},kt={class:"font-medium text-gray-900 dark:text-white"},wt={key:0,class:"flex justify-between"},Pt={class:"font-medium text-gray-900 dark:text-white"},Ct={class:"rounded-lg bg-amber-50 p-3 text-sm text-amber-700 dark:bg-amber-900/20 dark:text-amber-400"},St={class:"flex justify-between"},At={class:"text-lg font-bold text-teal-600 dark:text-teal-400"},jt={class:"flex justify-between"},Dt={class:"text-sm text-gray-600 dark:text-gray-400"},Tt={class:"font-medium text-gray-900 dark:text-white"},zt={key:0,class:"flex justify-between"},Mt={class:"font-medium text-gray-900 dark:text-white"},Nt={class:"flex justify-between"},It={class:"text-lg font-bold text-teal-600 dark:text-teal-400"},Ut={class:"flex justify-between"},Lt={class:"font-medium text-gray-900 dark:text-white"},Vt={key:0,class:"flex justify-between"},Yt={class:"text-sm text-emerald-600 dark:text-emerald-400"},Bt={key:0},Ft={class:"font-medium text-emerald-600 dark:text-emerald-400"},Et={key:1,class:"flex justify-between"},Ot={class:"font-medium text-gray-900 dark:text-white"},Rt={class:"flex justify-between"},$t={class:"font-medium text-gray-900 dark:text-white"}
1,qt={class:"text-lg font-bold text-teal-600 dark:text-teal-400"},Gt={key:0,class:"mt-4"},Kt={key:0,class:"mb-3 rounded-lg bg-red-50 p-3 text-sm text-red-600 dark:bg-red-950/30 dark:text-red-400"},Wt={key:1,class:"rounded-lg bg-green-50 p-3 dark:bg-green-950/30"},Xt={class:"flex items-center justify-between"},Jt={class:"flex items-center gap-2"},Qt={class:"text-sm font-medium text-green-800 dark:text-green-400"},Ht=["disabled"],Zt={key:1},ea={key:1,class:"mt-4 text-sm text-gray-600 dark:text-gray-400"},ta=["disabled"],aa={__name:"SubscriptionPlans",props:{currentPlan:Object,agency:Object,user:Object,redirectAfter:{type:Object,default:()=>({name:"agency-dashboard"})}},emits:["saved"],setup(f,{emit:J}){const u=f,Q=J,H=fe(),R=De(),_=v(null),T=v(!1),z=v(!1),c=v(null),k=v(null),C=v(!1),h=v(""),A=v(!1),S=v(null),y=v(null),{isPending:Z,isError:ee,error:te,data:$}=pe({queryKey:["agency","packages"],queryFn:Ce}),q=g(()=>u.agency?.trial&&!u.agency?.trial_activated_at),n=g(()=>$.value?.results?.find(a=>a._id===_.value)),w=g(()=>n.value?.trial&&q.value),j=g(()=>!!u.user?.stripe_detail?.customer_id&&u.user?.stripe_detail?.cards?.length>0),ae=g(()=>{const a=u.user?.stripe_detail?.cards;return a?.length?a.find(e=>e.default)||a[a.length-1]:null}),M=g(()=>{if(!y.value||!n.value)return 0;const a=n.value.amount||0;return y.value.percent_off?a*(y.value.percent_off/100):y.value.amount_off?y.value.amount_off/100:0}),se=g(()=>{const a=n.value?.amount||0;return Math.max(0,a-M.value)}),re=g(()=>!!c.value?.scheduled),G=g(()=>{const a=c.value?.effective_at;if(!a)return"";const e=new Date(a);return Number.isNaN(e.getTime())?"":e.toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"})}),le=g(()=>!!u.agency?.subscription?.is_trial),N=g(()=>Math.max(0,(u.agency?.total_sub_accounts||0)-(u.agency?.available_sub_accounts||0))),I=a=>(a?.sub_accounts??0)<N.value,U=g(()=>{const a=u.agency?.subscription?.new_package_id;return a?._id||a||null}),L=a=>!!U.value&&U.value===a,K=g(()=>{const a=u.agency?.subscription?.expiry_date;if(!U.value||!a)return"";const e=new Date(a);return Number.isNaN(e.getTime())?"":e.toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"})}),oe=async()=>{if(h.value){A.value=!0,S.value=null;try{const a=await he.get(`/package/promo/${h.value}`);y.value=a.data,E.success("Promo code applied!")}catch(a){S.value=a.response?.data?.message||"Invalid promo code",y.value=null}finally{A.value=!1}}},W=()=>{y.value=null,h.value="",S.value=null},D=a=>(u.agency?.subscription?.package_id?._id||u.agency?.subscription?.package_id)===a,{mutate:ne,isPending:V}=_e({mutationFn:async({packageId:a,isTrial:e,isChangePlan:l})=>{const P={package_id:a,trial:e};return y.value&&!l&&(P.promo_code=h.value),l?Se(P):Ae(P)},onSuccess:(a,{isTrial:e,isChangePlan:l})=>{const P=!!a?.scheduled;E.success(P?a?.message||"Downgrade scheduled for the end of your billing cycle":e?"Trial activated":l?"Plan changed":"Subscribed successfully"),Y(),u.redirectAfter&&H.push(u.redirectAfter),R.loadUserInfo(),Q("saved")},onError:a=>E.error(a.response?.data?.message||"Failed")}),de=async a=>{if(_.value=a._id,c.value=null,k.value=null,T.value=!0,u.currentPlan){C.value=!0;try{c.value=await we(a._id)}catch(e){console.error(e)}finally{C.value=!1}}else if(j.value){C.value=!0;try{k.value=await Pe(a._id)}catch(e){console.error(e)}finally{C.value=!1}}},Y=()=>{T.value=!1,_.value=null,c.value=null,k.value=null,W()},ie=()=>{!_.value||!j.value||ne({packageId:_.value,isTrial:w.value,isChangePlan:!!u.currentPlan})},m=(a,e="USD")=>!a&&a!==0?"-":new Intl.NumberFormat("en-US",{style:"currency",currency:e||"USD"}).format(a),X=a=>m(Number(a||0)/100,"USD"),ue=()=>{R.loadUserInfo()};return(a,e)=>(s(),r("div",null,[f.currentPlan?(s(),r("div",Be,[t("div",Fe,[t("div",Ee,[b(d(Te),{size:20,class:"text-teal-500"}),t("div",null,[e[3]||(e[3]=t("span",{class:"text-sm font-medium text-teal-600 dark:text-teal-400"}," Current Plan: ",-1)),t("span",Oe,o(f.currentPlan.name),1)])]),t("div",Re,o(m(f.currentPlan.amount,f.currentPlan.currency))+"/month ",1)])])):i("",!0),d(Z)?(s(),r("div",$e,[b(d(O),{size:32,class:"animate-spin text-gray-400 dark:text-gray-600"})])):d(ee)?(s(),r("div",qe,[t("p",Ge,o(d(te)?.message||"Failed to load plans"),1)])):(s(),r("div",Ke,[(s(!0),r(p,null,ce(d($)?.results,l=>(s(),r("div",{key:l._id,class:F(["relative overflow-hidden rounded-xl border-2 p-6 transition-all",D(l._id)?"border-teal-500 bg-teal-50 dark:bg-teal-900/20":L(l._id
1)?"border-amber-400 bg-amber-50 dark:bg-amber-900/20":_.value===l._id?"border-teal-400 bg-white dark:bg-gray-800":"border-gray-200 bg-white hover:border-gray-300 dark:border-gray-700 dark:bg-gray-800 dark:hover:border-gray-600"])},[D(l._id)?(s(),r("div",We," Current ")):L(l._id)?(s(),r("div",Xe," Scheduled ")):i("",!0),t("h3",Je,o(l.name),1),t("div",Qe,[t("span",He,o(m(l.amount,l.currency)),1),e[4]||(e[4]=t("span",{class:"text-sm text-gray-600 dark:text-gray-400"},"/month",-1))]),l.description?(s(),r("p",Ze,o(l.description),1)):i("",!0),t("div",et,[t("div",tt,[b(d(Ve),{size:16,class:"text-gray-500 dark:text-gray-400"}),t("span",at,o(l.sub_accounts||0)+" Sub-Accounts ",1)]),l.monthly_wallet_credits>0?(s(),r("div",st,[b(d(Ye),{size:16,class:"text-gray-500 dark:text-gray-400"}),t("span",rt,[x(o(X(l.monthly_wallet_credits))+" AI wallet / month ",1),e[5]||(e[5]=t("span",{class:"text-xs text-gray-500 dark:text-gray-400"},"(no rollover)",-1))])])):i("",!0)]),L(l._id)?(s(),r("p",lt,[e[6]||(e[6]=x(" Your subscription switches to this plan",-1)),K.value?(s(),r(p,{key:0},[x(" on "+o(K.value),1)],64)):i("",!0),e[7]||(e[7]=x(". ",-1))])):i("",!0),!D(l._id)&&I(l)?(s(),r("p",ot," You're using "+o(N.value)+" sub-accounts. Remove some to "+o(l.sub_accounts)+" or fewer before switching to this plan. ",1)):i("",!0),D(l._id)?i("",!0):(s(),r("button",{key:5,onClick:P=>de(l),disabled:d(V)||I(l),title:I(l)?`You're using ${N.value} sub-accounts; this plan allows ${l.sub_accounts}.`:"",class:F(["mt-4 w-full rounded-lg px-4 py-2.5 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50",_.value===l._id?"bg-teal-600 text-white hover:bg-teal-700":"bg-gray-100 text-gray-700 hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600"])},o(l.trial&&q.value?"Start Trial":f.currentPlan?"Change Plan":"Subscribe"),11,nt))],2))),128))])),(s(),B(ve,{to:"body"},[b(xe,{name:"slide"},{default:ye(()=>[T.value?(s(),r("div",dt,[t("div",{class:"absolute inset-0 bg-black/50",onClick:Y}),t("div",it,[t("div",ut,[e[8]||(e[8]=t("h3",{class:"text-lg font-semibold text-gray-900 dark:text-white"},"Order Summary",-1)),t("button",{onClick:Y,class:"rounded-full p-1 hover:bg-gray-100 dark:hover:bg-gray-700"},[b(d(ze),{size:20,class:"text-gray-500 dark:text-gray-400"})])]),t("div",ct,[j.value?(s(),r("div",yt,[e[9]||(e[9]=t("p",{class:"text-sm font-medium text-gray-700 dark:text-gray-300"},"Payment Method",-1)),t("p",gt,[b(d(Me),{size:14,class:"mr-1 inline"}),x(" Card ending in "+o(ae.value?.ccard_last4),1)])])):(s(),r("div",mt,[t("div",bt,[b(d(Ne),{size:20,class:"shrink-0 text-yellow-500"}),t("div",null,[e[11]||(e[11]=t("p",{class:"text-sm font-medium text-yellow-700 dark:text-yellow-400"}," No Payment Method ",-1)),e[12]||(e[12]=t("p",{class:"mt-1 text-sm text-yellow-600 dark:text-yellow-400/80"}," Please add a payment method before subscribing. ",-1)),t("button",{onClick:e[0]||(e[0]=l=>z.value=!0),class:"mt-2 inline-flex items-center gap-1.5 text-sm font-medium text-teal-600 transition-colors hover:text-teal-700 dark:text-teal-400 dark:hover:text-teal-300"},[b(d(Ie),{size:16}),e[10]||(e[10]=x(" Add Payment Method ",-1))])])])])),C.value?(s(),r("div",xt,[b(d(O),{size:24,class:"animate-spin text-gray-400 dark:text-gray-600"})])):(s(),r(p,{key:3},[t("div",vt,[t("div",ft,[t("div",pt,[e[13]||(e[13]=t("span",{class:"text-sm text-gray-600 dark:text-gray-400"},"Package",-1)),t("span",_t,o(n.value?.name),1)]),t("div",ht,[e[14]||(e[14]=t("span",{class:"text-sm text-gray-600 dark:text-gray-400"},"Sub-Accounts",-1)),t("span",kt,o(n.value?.sub_accounts||1),1)]),n.value?.monthly_wallet_credits>0?(s(),r("div",wt,[e[16]||(e[16]=t("span",{class:"text-sm text-gray-600 dark:text-gray-400"}," Monthly AI wallet ",-1)),t("span",Pt,[x(o(X(n.value.monthly_wallet_credits))+" ",1),e[15]||(e[15]=t("span",{class:"text-xs font-normal text-gray-500 dark:text-gray-400"}," / mo, no rollover ",-1))])])):i("",!0),e[27]||(e[27]=t("div",{class:"border-t border-gray-200 dark:border-gray-600"},null,-1)),c.value?(s(),r(p,{key:1},[c.value.scheduled?(s(),r(p,{key:0},[t("div",Ct,[x(" Your plan will change to "+o(n.value?.name)+" at the end of your current billing cycle",1),G.value?(s(),r(p,{key:0},[x(" on "+o(G.value),1)],64)):i("",!0),e[17]||(e[17]=x(". You keep your current plan until then, with no charge today. ",-1))]),e[19]||(e[19]=t("div",{class:"border-t border-gray-200 dark:border-gray-600"},null,-1)),t("div",St,[e[18]||(e[18]=t("span",{class:"font-medium text-gray-900 dark:text-white"},"Due Today",-1)),t("span",At,o(m(0,n.value?.currency)),1)])],64)):(s(),r(p,{key:1},[t("div",jt,[t("span",Dt,o(le.value?"Plan Price":"Prorated Amount"),1),t("span",Tt,o(m(c.value.amount_to_be_charged,n.value?.currency)),1)]),c.value.gst?(s(),r("div",zt,[e[20]||(e[20]=t("span",{class:"text-sm text-gray-600 dark:text-gray-400"},"GST",-1)),t("span",Mt,o(m(c.value.gst,n.value?.currency)),1)])):i("",!0),e[22]||(e[22]=t("div",{class:"border-t border-gray-200 dark:border-gray-600"},null,-1)),t("div",Nt,[e[21]||(e[21]=t("span",{class:"font-medium text-gray-900 dark:text-white"},"Total Due",-1)),t("span",It,o(m((c.value.amount_to_be_charged||0)+(c.value.gst||0),n.value?.currency)),1)])],64))],64)):(s(),r(p,{key:2},[t("div",Ut,[e[23]||(e[23]=t("span",{class:"text-sm text-gray-600 dark:text-gray-400"},"Monthly Price",-1)),t("span",Lt,o(m(n.value?.amount,n.value?.currency)),1)]),M.value>0?(s(),r("div",Vt,[t("span",Yt,[e[24]||(e[24]=x(" Discount ",-1)),y.value?.percent_off?(s(),r("span",Bt,"("+o(y.value.percent_off)+"% off)",1)):i("",!0)]),t("span",Ft," -"+o(m(M.value,n.value?.currency)),1)])):i("",!0),!w.value&&k.value?.gst?(s(),r("div",Et,[e[25]||(e[25]=t("span",{class:"text-sm text-gray-600 dark:text-gray-400"},"GST",-1)),t("span",Ot,o(m(k.value.gst,n.value?.currency)),1)])):i("",!0),e[26]||(e[26]=t("div",{class:"border-t border-gray-200 dark:border-gray-600"},null,-1)),t("div",Rt,[t("span",$t,o(w.value?"Due Today":"Total Due"),1),t("span",qt,o(w.value?m(0,n.value?.currency):m(se.value+(k.value?.gst||0),n.value?.currency)),1)])],64))])]),c.value?i("",!0):(s(),r("div",Gt,[S.value?(s(),r("div",Kt,o(S.value),1)):i("",!0),y.value?(s(),r("div",Wt,[t("div",Xt,[t("div",Jt,[b(d(Ue),{size:16,class:"text-green-600"}),t("span",Qt,o(y.value.name)+" applied! ",1)]),t("button",{onClick:W,class:"text-sm font-medium text-green-600 hover:text-green-700"}," Remove ")])])):(s(),r("form",{key:2,onSubmit:ge(oe,["prevent"]),class:"flex gap-2"},[me(t("input",{"onUpdate:modelValue":e[1]||(e[1]=l=>h.value=l),type:"text",placeholder:"Enter promo code",class:"flex-1 rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 outline-none placeholder:text-gray-400 focus:border-teal-500 focus:ring-1 focus:ring-teal-500 dark:border-gray-600 dark:bg-gray-900 dark:text-white dark:placeholder:text-gray-500"},null,512),[[be,h.value]]),t("button",{type:"submit",disabled:A.value||!h.value,class:"rounded-lg bg-teal-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-teal-700 disabled:cursor-not-allowed disabled:opacity-50"},[A.value?(s(),B(d(Le),{key:0,size:16,class:"animate-spin"})):(s(),r("span",Zt,"Apply"))],8,Ht)],32))])),w.value?(s(),r("p",ea," Your "+o(f.agency?.trial_duration||14)+"-day trial starts today. You won't be charged until the trial ends. ",1)):i("",!0),t("button",{onClick:ie,disabled:d(V)||!j.value,class:F(["mt-4 w-full rounded-lg px-4 py-3 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50","bg-teal-600 text-white hover:bg-teal-700"])},[d(V)?(s(),B(d(O),{key:0,size:16,class:"mr-2 inline animate-spin"})):i("",!0),x(" "+o(w.value?"Start Trial":re.value?"Schedule Downgrade":f.currentPlan?"Change Plan":"Subscribe"),1)],8,ta)],64))])])])):i("",!0)]),_:1})])),b(ke,{modelValue:z.value,"onUpdate:modelValue":e[2]||(e[2]=l=>z.value=l),onCardAdded:ue},null,8,["modelValue"])]))}}
1,ba=je(aa,[["__scopeId","data-v-1b201c6b"]]);export{ba 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.