import{i as e,n as t}from"./rolldown-runtime-BKYq3fBv.js";import{Cr as n,Fr as r,Nn as i,Qn as a,Rr as o,Xr as s,ai as c,ir as l,li as u,si as d,sr as f,ui as p,vr as m}from"./vendor-primevue-D50rA9nL.js";import{on as h,sn as g}from"./api-z_dXWY_S.js";import{n as _,t as v}from"./tailwindUtil-CORTPblY.js";import{n as y,t as b}from"./Button-DzMg17Os.js";import{Ao as x,in as S,jo as C,rn as w}from"./dialogService-Cr3DyAja.js";var T,E,D,O=t((()=>{i(),y(),x(),h(),w(),v(),T=3e3,E=300*1e3,D=f({__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:t}){let i=t,{subscribe:f,isActiveSubscription:h,fetchStatus:v,showSubscriptionDialog:y}=C(),x=S(),w=s(!1),D=s(!1),O=null,k=s(!1),startPollingSubscriptionStatus=()=>{D.value=!0,w.value=!0;let e=Date.now(),poll=async()=>{try{if(Date.now()-e>E){stopPolling();return}await v(),h.value&&(stopPolling(),x?.trackMonthlySubscriptionSucceeded(),i(`subscribed`))}catch(e){console.error(`[SubscribeButton] Error polling subscription status:`,e)}};poll(),O=window.setInterval(poll,T)},stopPolling=()=>{O&&=(clearInterval(O),null),D.value=!1,w.value=!1};r([k,h],([e,t])=>{g&&e&&t&&(i(`subscribed`),k.value=!1)});let handleSubscribe=async()=>{if(g){S()?.trackSubscription(`subscribe_clicked`),k.value=!0,y();return}w.value=!0;try{await f(),startPollingSubscriptionStatus()}catch(e){console.error(`[SubscribeButton] Error initiating subscription:`,e),w.value=!1}};return m(()=>{stopPolling(),k.value=!1}),(e,t)=>(n(),a(b,{size:e.size,loading:w.value,disabled:e.disabled||D.value,variant:`primary`,style:u(e.variant===`gradient`?{background:`var(--color-subscription-button-gradient)`,color:`var(--color-white)`}:void 0),class:d(c(_)(`font-bold`,e.fluid&&`w-full`)),onClick:handleSubscribe},{default:o(()=>[l(p(e.label||e.$t(`subscription.required.subscribe`)),1)]),_:1},8,[`size`,`loading`,`disabled`,`style`,`class`]))}})})),k,A=t((()=>{O(),O(),k=D}));export{A as n,k as t};
//# sourceMappingURL=SubscribeButton-BB9GpVvD.js.map