import{i as e,n as t}from"./rolldown-runtime-ConPGZeh.js";import{H as n,R as r,hn as i,mn as a}from"./api-DvJuMrZn.js";import{Co as o,Eo as s,Oo as c,To as l,wo as u}from"./dialogService-DIdX_hbW.js";async function performSubscriptionCheckout(e,t,r=!0){if(!i)return;let{getAuthHeader:a}=l(),c=await a();if(!c)throw new o(n(`toastMessages.userNotAuthenticated`));let u=getCheckoutTier(e,t),d=await fetch(`${s()}/customers/cloud-subscription-checkout/${u}`,{method:`POST`,headers:{...c,"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((()=>{c(),r(),a(),u(),getCheckoutTier=(e,t)=>t===`yearly`?`${e}-yearly`:e}));export{performSubscriptionCheckout as n,d as t};
//# sourceMappingURL=subscriptionCheckoutUtil-CYIrqReh.js.map