import{r as e}from"./rolldown-runtime-DCMCV6zW.js";import{t}from"./types-0oh-UGWL.js";import{o as n}from"./i18n-DjEVEIh2.js";import{Cr as r,Dr as i,wr as a}from"./dialogService-BC0EXJA5.js";var getCheckoutTier=(e,t)=>t===`yearly`?`${e}-yearly`:e;async function performSubscriptionCheckout(e,o,s=!0){if(!t)return;let{getFirebaseAuthHeader:c}=a(),l=await c();if(!l)throw new r(n(`toastMessages.userNotAuthenticated`));let u=getCheckoutTier(e,o),d=await fetch(`${i()}/customers/cloud-subscription-checkout/${u}`,{method:`POST`,headers:{...l,"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 r(n(`toastMessages.failedToInitiateSubscription`,{error:e}))}let f=await d.json();f.checkout_url&&(s?window.open(f.checkout_url,`_blank`):globalThis.location.href=f.checkout_url)}export{performSubscriptionCheckout as t};
//# sourceMappingURL=subscriptionCheckoutUtil-B_HowdP4.js.map