import{r as e}from"./rolldown-runtime-DCMCV6zW.js";import{$ as t,Bt as n,Et as r,Ft as i,J as a,L as o,Lt as s,O as c,P as l,ft as u,ht as d,zt as f}from"./vendor-vue-core-D3IvUUeM.js";import{t as p}from"./types-0oh-UGWL.js";import{t as m}from"./src-ByuP5s1t.js";import{t as h}from"./Button-mG8zDgxj.js";import{V as g,_n as _}from"./dialogService-BC0EXJA5.js";var v=3e3,y=300*1e3,b=o({__name:`SubscribeButton`,props:{label:{},size:{default:`lg`},variant:{default:`default`},fluid:{type:Boolean,default:!0},disabled:{type:Boolean,default:!1}},emits:[`subscribed`],setup(e,{emit:o}){let b=o,{subscribe:x,isActiveSubscription:S,fetchStatus:C,showSubscriptionDialog:w}=_(),T=g(),E=r(!1),D=r(!1),O=null,k=r(!1),startPollingSubscriptionStatus=()=>{D.value=!0,E.value=!0;let e=Date.now(),poll=async()=>{try{if(Date.now()-e>y){stopPolling();return}await C(),S.value&&(stopPolling(),T?.trackMonthlySubscriptionSucceeded(),b(`subscribed`))}catch(e){console.error(`[SubscribeButton] Error polling subscription status:`,e)}};poll(),O=window.setInterval(poll,v)},stopPolling=()=>{O&&=(clearInterval(O),null),D.value=!1,E.value=!1};u([k,S],([e,t])=>{p&&e&&t&&(b(`subscribed`),k.value=!1)});let handleSubscribe=async()=>{if(p){g()?.trackSubscription(`subscribe_clicked`),k.value=!0,w();return}E.value=!0;try{await x(),startPollingSubscriptionStatus()}catch(e){console.error(`[SubscribeButton] Error initiating subscription:`,e),E.value=!1}};return a(()=>{stopPolling(),k.value=!1}),(e,r)=>(t(),c(h,{size:e.size,loading:E.value,disabled:e.disabled||D.value,variant:`primary`,style:f(e.variant===`gradient`?{background:`var(--color-subscription-button-gradient)`,color:`var(--color-white)`}:void 0),class:s(i(m)(`font-bold`,e.fluid&&`w-full`)),onClick:handleSubscribe},{default:d(()=>[l(n(e.label||e.$t(`subscription.required.subscribe`)),1)]),_:1},8,[`size`,`loading`,`disabled`,`style`,`class`]))}});export{b as t};
//# sourceMappingURL=SubscribeButton-BzxsFjxi.js.map