import{i as e,n as t}from"./rolldown-runtime-BKYq3fBv.js";import{on as n,sn as r}from"./api-z_dXWY_S.js";import{r as i,s as a}from"./i18n-ZU7-AXHi.js";import{Bo as o,Ho as s,Uo as c,Vo as l,zo as u}from"./dialogService-Cr3DyAja.js";async function performSubscriptionCheckout(e,t,n=!0){if(!r)return;let{getFirebaseAuthHeader:i}=l(),o=await i();if(!o)throw new u(a(`toastMessages.userNotAuthenticated`));let c=getCheckoutTier(e,t),d=await fetch(`${s()}/customers/cloud-subscription-checkout/${c}`,{method:`POST`,headers:{...o,"Content-Type":`application/json`}});if(!d.ok){let e=`Failed to initiate checkout`;try{e=(await d.json()).message||e}catch{try{e=await d.text()||`HTTP ${d.status} ${d.statusText}`}catch{e=`HTTP ${d.status} ${d.statusText}`}}throw new u(a(`toastMessages.failedToInitiateSubscription`,{error:e}))}let f=await d.json();f.checkout_url&&(n?window.open(f.checkout_url,`_blank`):globalThis.location.href=f.checkout_url)}var getCheckoutTier,d=t((()=>{c(),i(),n(),o(),getCheckoutTier=(e,t)=>t===`yearly`?`${e}-yearly`:e}));export{performSubscriptionCheckout as n,d as t};
//# sourceMappingURL=subscriptionCheckoutUtil-DCWhQWaM.js.map