import{r as e}from"./rolldown-runtime-DCMCV6zW.js";import{l as t}from"./vendor-vue-core-X6q-rGJs.js";import{t as n}from"./types-DW97iHDr.js";import{o as r}from"./i18n-DjV_9lZM.js";import{t as i}from"./telemetry-KciZP3tz.js";import{ar as a,or as o,sr as s}from"./dialogService-Cqui0UMO.js";var getCheckoutTier=(e,t)=>t===`yearly`?`${e}-yearly`:e,getCheckoutAttributionForCloud=async()=>({});async function performSubscriptionCheckout(e,c,l=!0){if(!n)return;let u=o(),{userId:d}=t(u),f=i(),p=await u.getAuthHeader();if(!p)throw new a(r(`toastMessages.userNotAuthenticated`));let m=getCheckoutTier(e,c),h={};try{h=await getCheckoutAttributionForCloud()}catch(e){console.warn(`[SubscriptionCheckout] Failed to collect checkout attribution`,e)}let g={...h},_=await fetch(`${s()}/customers/cloud-subscription-checkout/${m}`,{method:`POST`,headers:{...p,"Content-Type":`application/json`},body:JSON.stringify(g)});if(!_.ok){let e=`Failed to initiate checkout`;try{e=(await _.json()).message||e}catch{try{e=await _.text()||`HTTP ${_.status} ${_.statusText}`}catch{e=`HTTP ${_.status} ${_.statusText}`}}throw new a(r(`toastMessages.failedToInitiateSubscription`,{error:e}))}let v=await _.json();v.checkout_url&&(d.value&&f?.trackBeginCheckout({user_id:d.value,tier:e,cycle:c,checkout_type:`new`,...h}),l?window.open(v.checkout_url,`_blank`):globalThis.location.href=v.checkout_url)}export{performSubscriptionCheckout as t};
//# sourceMappingURL=subscriptionCheckoutUtil-CGin9rh7.js.map