import{e as y,r as f,q as m}from"./vue.02ad7c87.js";import{bL as h,bM as P,bN as x,bO as C,bP as F,bQ as R,S as E,N as I,bR as U,V as T,h as i,aa as n,bS as p}from"./index.f2790301.js";import{a as l}from"./sentry.13e8e62e.js";var V=Object.prototype,B=V.hasOwnProperty,O=h(function(e,t){if(P(t)||x(t)){C(t,F(t),e);return}for(var r in t)B.call(t,r)&&R(e,r,t[r])});const N=O;class a extends E{constructor(t="Server error encountered fetching subscription"){super(t)}}class c extends I{constructor(t="Subscription not found"){super(t)}}class k extends U{constructor(t="Subscription setup failed"){super(t)}}class g extends T{constructor(t="Subscription failed validation"){super(t)}}const s={createSubscriptionIntent:i("/omnis/v3/saas/stripe/subscription/intent"),processSubscriptionResponse:i("/omnis/v3/saas/stripe/subscription/subscribe"),processUpdateResponse:i("/omnis/v3/saas/stripe/subscription/update"),processPaymentMethodUpdateResponse:i("/omnis/v3/saas/stripe/subscription/update/payment-method"),getCurrentSubscription:i("/omnis/v3/saas/stripe/subscription"),updateBillingCycle:i("/omnis/v3/saas/stripe/subscription/billing-cycle"),getSubscription:i("/omnis/v3/saas/stripe/subscription"),canReceiveFreeTrial:i("/omnis/v3/saas/stripe/subscription/can-receive-free-trial")};class b{static createSubscriptionIntent(t){return n.post(s.createSubscriptionIntent,{...t}).success(r=>r).throw(404,()=>new c).throw(403,({data:r})=>new k(r==null?void 0:r.message)).throw("5xx",()=>new a("Server error encountered creating subscription intent")).throwValidation(r=>new g(r)).output()}static updateBillingCycle(t,r){return n.put(s.updateBillingCycle,{subscription_id:t,billing_cycle:r}).throw(404,()=>new c).throw("5xx",()=>new a("Server error encountered updating billing cycle")).throwValidation(S=>new g(S)).output()}static getSubscription(){return n.get(s.getSubscription).success(({subscription:t})=>({id:t.id,plan:t.plan,billingCycle:t.billing_cycle})).throw(404,()=>new c).throw("5xx",()=>new a("Server error encountered fetching subscription")).output()}static canReceiveFreeTrial(){return n.get(s.canReceiveFreeTrial).success(({can_receive_free_trial:t})=>t).output()}}const o=y({plan:"pro",origin:"unknown",billingCycle:"yearly"}),u=f(),G=()=>({upgrade:{canReceiveFreeTrial:u,checkIfCanReceiveFreeTrial:d,openPopup:$,information:o,pricing:y({yearly:v,monthly:L}),setBillingCycle:M},subscribe:{openPopup:q},update:{openPopup:Q},subscription:{changePlan:A,getSubscription:j}}),A=async({subscriptionId:e,billingCycle:t})=>{try{await b.updateBillingCycle(e,t)}catch(r){throw l(r),r}},j=async()=>{try{return await b.getSubscription()}catch(e){throw l(e),e}},v=m(()=>o.billingCycle==="yearly"?99:120),L=m(()=>{const e=v.value/12;return e%1!==0?parseFloat(e.toFixed(2)):e}),M=e=>{o.billingCycle=e},$=async e=>{e&&w(e),await d(),p.emit("open-upgrade-to-pro-popup",{title:e==null?void 0:e.title,description:e==null?void 0:e.description,image:e==null?void 0:e.image})},q=async e=>{e&&w(e),await d(),p.emit("open-pro-subscribe-popup")},Q=()=>{p.emit("open-pro-update-popup")},w=e=>{N(o,{plan:"pro",origin:"unknown",billingCycle:"yearly"},e)},d=async()=>{if(u.value===void 0)try{u.value=await b.canReceiveFreeTrial()}catch(e){l(e)}};export{q as a,$ as o,G as u};
//# sourceMappingURL=useSaas.49991e1a.js.map
