import{La as c,V as u,wd as l}from"./chunk-5MX6LZUO.js";import{b as r}from"./chunk-HYAFJ65M.js";import{i as o}from"./chunk-QPETXDFF.js";var p=["app.independo.calendar.single.monthly","app.independo.calendar.single.yearly"],h=["app.independo.calendar.single.monthly","app.independo.calendar.single.yearly"],n=[];var _=(()=>{let a=class a{get processingState(){return this._processingState.asReadonly();}get activeSubscription(){return this._activeSubscription.asReadonly();}get availableProducts(){return this._availableProducts.asReadonly();}constructor(){this._processingState=c(void 0),this._activeSubscription=c(void 0),this._availableProducts=c([]);}initialize(){return o(this,null,function*(){if(this.isInitialized()){console.warn("IAP already initialized");return;}if(!(!r.isNativePlatform()&&n.length<1))try{yield this.initializeInternal();}catch(t){console.error("Failed to initialize IAP",t);}});}isInitialized(){return!!this.store;}initializeInternal(){return o(this,null,function*(){this._processingState.set({state:"initializing",text:"Initializing"}),this.store=CdvPurchase.store;let t=[];r.getPlatform()==="ios"&&t.push(...p.map(s=>({id:s,platform:CdvPurchase.Platform.APPLE_APPSTORE,type:CdvPurchase.ProductType.PAID_SUBSCRIPTION,group:"default"}))),r.getPlatform()==="android"&&t.push(...h.map(s=>({id:s,platform:CdvPurchase.Platform.GOOGLE_PLAY,type:CdvPurchase.ProductType.PAID_SUBSCRIPTION,group:"default"}))),n.length>0&&(t.push(...n.map(s=>({id:s,platform:CdvPurchase.Platform.TEST,type:CdvPurchase.ProductType.PAID_SUBSCRIPTION,group:"default"}))),console.log("Test products:",n)),this.store.register(t);let e=new CdvPurchase.Iaptic(l.iapticConfig);this.store.validator=e.validator,l.isProduction?this.store.verbosity=CdvPurchase.LogLevel.ERROR:this.store.verbosity=CdvPurchase.LogLevel.DEBUG,this.setupEventHandlers(this.store);let i=[];r.getPlatform()==="android"&&i.push(CdvPurchase.Platform.GOOGLE_PLAY),r.getPlatform()==="ios"&&i.push(CdvPurchase.Platform.APPLE_APPSTORE),l.isProduction||i.push(CdvPurchase.Platform.TEST),yield this.store.initialize(i),this.updateState(this.store),this._processingState.set(void 0);});}setupEventHandlers(t){t.when().productUpdated(e=>{this.updateState(t);}).receiptsVerified(()=>{this.updateState(t);}).receiptUpdated(e=>{this.updateState(t);}).approved(e=>{this._processingState.set({text:"Verifying",state:"verifying"}),e.verify();}).verified(e=>{e.sourceReceipt.transactions.filter(i=>i.state!==CdvPurchase.TransactionState.FINISHED).length>0&&(this._processingState.set({text:"Finishing",state:"finishing"}),e.finish());}).unverified(e=>{this.updateState(t),this._processingState.set(void 0);}).finished(e=>{this.updateState(t),this._processingState.set(void 0);}),t.error(e=>{if(this._processingState.set(void 0),e.code===CdvPurchase.ErrorCode.PAYMENT_CANCELLED){console.log("The user cancelled the purchase flow");return;}console.log("IAP error:",e);});}updateState(t){this._availableProducts.set(t.products);let e=t.verifiedPurchases.find(s=>!!(t.get(s.id,s.platform)?.owned&&!s.isExpired)),i=e?t.get(e.id,e.platform):void 0;i&&e?(this._activeSubscription.set({product:i,subscription:e}),this.activeSubscriptionCallback&&this.activeSubscriptionCallback({product:i,subscription:e})):this._activeSubscription.set(void 0);}initiatePurchase(t,e){return o(this,null,function*(){if(!this.store)return;this._processingState.set({text:"Preparing purchase",state:"ordering"});let i={applicationUsername:e};yield this.store.get(t,this.getPlatform())?.getOffer()?.order(i);});}manageSubscriptions(){return o(this,null,function*(){this.store&&(yield this.store.manageSubscriptions(this.getPlatform()));});}restorePurchases(){return o(this,null,function*(){this.store&&(this._processingState.set({text:"Restoring",state:"restoring"}),yield this.store.restorePurchases(),this._processingState.set(void 0));});}getPlatform(){switch(r.getPlatform()){case"ios":return CdvPurchase.Platform.APPLE_APPSTORE;case"android":return CdvPurchase.Platform.GOOGLE_PLAY;default:return CdvPurchase.Platform.TEST;}}setUserCallback(t){this.store&&(this.store.applicationUsername=t);}setActiveSubscriptionCallback(t){this.activeSubscriptionCallback=t;}};a.ɵfac=function(e){return new(e||a)();},a.ɵprov=u({token:a,factory:a.ɵfac,providedIn:"root"});let d=a;return d;})();export{_ as a};/**i18n:5f654067edd882b38c3bfd0b338f4ed4ade1468ece5f29e016ed1fc932d61364*/