import{b as p}from"./chunk-ZBFZUD3Q.js";import{d as u}from"./chunk-P2FS3V6A.js";import{_ as h}from"./chunk-LLYDPG5N.js";import{G as d,ca as c,g as i,ha as a,q as o,t as l}from"./chunk-2BMUMDG3.js";import{i as n}from"./chunk-2AVGQ2MQ.js";var I=(()=>{class e{constructor(r,t,s){this.apiService=r,this.toastr=t,this.translate=s,this.paddleUrlSource=new i(""),this.customerIdSource=new i(""),this.paddleUrl$=this.paddleUrlSource.asObservable(),this.customerId$=this.customerIdSource.asObservable()}getPaddlePortalSession(){this.apiService.getPaddlePortalSession().pipe(d(r=>(this.handleError(r),o(()=>r)))).subscribe(r=>{try{let t=r?.body?.data?.data;t?.urls?.general?.overview?(this.paddleUrlSource.next(t.urls.general.overview),this.customerIdSource.next(t.customer_id)):this.toastr.warning(this.translate.instant("Invalid response from Paddle API."),this.translate.instant("Warning"))}catch(t){console.error("Failed to parse Paddle response:",t),this.toastr.error(this.translate.instant("Unable to process Paddle session data."),this.translate.instant("Error"))}})}fetchAndSetPaddlePortalSession(){return n(this,null,function*(){try{let t=(yield l(this.apiService.getPaddlePortalSession()))?.body?.data?.data;if(t?.urls?.general?.overview){let s=t.urls.general.overview;return this.paddleUrlSource.next(s),this.customerIdSource.next(t.customer_id),s}else return this.toastr.warning(this.translate.instant("Invalid response from Paddle API."),this.translate.instant("Warning")),""}catch(r){return this.handleError(r),""}})}handleError(r){switch(r.status){case 400:this.toastr.error(this.translate.instant("Bad Request"),this.translate.instant("Error"));break;case 401:this.toastr.error(this.translate.instant("Unauthorized"),this.translate.instant("Error"));break;case 403:this.toastr.error(this.translate.instant("Forbidden"),this.translate.instant("Error"));break;case 404:this.toastr.info(this.translate.instant("Not Found"),this.translate.instant("Info"));break;case 500:case 503:this.toastr.error(this.translate.instant("Server Error"),this.translate.instant("Error"));break;default:break}}getCurrentPaddleUrl(){return this.paddleUrlSource.value}static{this.\u0275fac=function(t){return new(t||e)(a(u),a(p),a(h))}}static{this.\u0275prov=c({token:e,factory:e.\u0275fac,providedIn:"root"})}}return e})();export{I as a};
