import{a as p}from"./chunk-77YMVDAC.js";import{a as d}from"./chunk-ORHSDUMX.js";import{Ha as e,e as t,l as s,o as n,x as r}from"./chunk-LH5Z5GGI.js";import{e as c}from"./chunk-C6Q5SG76.js";var u=c(p(),1);var l=class o{api=n(d);_subscription=r(null);subscription=this._subscription.asReadonly();_creditBalance=r(null);_usage=r(null);creditBalance=this._creditBalance.asReadonly();usage=this._usage.asReadonly();_error=r(null);error=this._error.asReadonly();hasSubscription=e(()=>this._subscription()!==null);planId=e(()=>this._subscription()?.plan??"starter");plan=e(()=>(0,u.planById)(this.planId()));status=e(()=>this._subscription()?.status??"active");periodEnd=e(()=>this._subscription()?.periodEnd??null);constructor(){this.reload()}async reload(){this._error.set(null),await Promise.all([this.load(),this.refresh()])}async load(){try{let i=(await t(this.api.orgs()))[0]?.id;if(!i)return;this._subscription.set(await t(this.api.subscription(i)))}catch{this._error.set("No se pudo cargar la suscripci\xF3n.")}}async refresh(){try{let a=await t(this.api.dashboard());this._creditBalance.set(a.creditBalance),this._usage.set(a.usage)}catch{this._error.set("No se pudo cargar el saldo de cr\xE9ditos.")}}static \u0275fac=function(i){return new(i||o)};static \u0275prov=s({token:o,factory:o.\u0275fac,providedIn:"root"})};export{l as a};
