import{i as e,n as t}from"./rolldown-runtime-BKYq3fBv.js";import{H as n,R as r,hn as i,mn as a}from"./api-D3NfSChA.js";import{Fo as o,Io as s,Lo as c,Ro as l,zo as u}from"./dialogService-BWZ1IAoU.js";async function performSubscriptionCheckout(e,t,r=!0){if(!i)return;let{getFirebaseAuthHeader:a}=c(),s=await a();if(!s)throw new o(n(`toastMessages.userNotAuthenticated`));let u=getCheckoutTier(e,t),d=await fetch(`${l()}/customers/cloud-subscription-checkout/${u}`,{method:`POST`,headers:{...s,"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 o(n(`toastMessages.failedToInitiateSubscription`,{error:e}))}let f=await d.json();f.checkout_url&&(r?window.open(f.checkout_url,`_blank`):globalThis.location.href=f.checkout_url)}var getCheckoutTier,d=t((()=>{u(),r(),a(),s(),getCheckoutTier=(e,t)=>t===`yearly`?`${e}-yearly`:e}));export{performSubscriptionCheckout as n,d as t};
//# sourceMappingURL=subscriptionCheckoutUtil-Dyqs_y-n.js.map