import{a as u}from"./chunk-KNMWXIQN.js";import{c as y,d as b,g as S,n as a}from"./chunk-SPUEGBWO.js";import{D as d}from"./chunk-GQP2MJQK.js";import{A as n,Mc as w,ad as g,fe as f,ge as p,w as h}from"./chunk-ZVAMPSQU.js";import{j as o}from"./chunk-FB5LSH2R.js";var v="https://docs.recipesage.com/docs/tutorials/settings/settings#enable-offline-mode",N=(()=>{let i=class i{constructor(){this.preferencesService=n(u),this.syncService=n(S),this.alertCtrl=n(w),this.translate=n(g),this.events=n(b),this.promptedThisSession=!1,this.isPromptOpen=!1,this.isBlockedAlertOpen=!1,a.registerHooks({notifySlowRead:()=>{this.promptSlowRead()},showBlockedError:()=>{this.presentBlocked()},notifyEnabledChanged:()=>this.events.publish(y.ApplicationOfflineModeChanged)})}get enabled(){return a.enabled}setEnabled(t){return o(this,null,function*(){if(t){if(!(yield d.getLastSync())){yield this.presentSyncRequired();return}a.enable(),yield this.presentEnabledInfo();return}let e=a.enabled;a.disable(),e&&this.syncService.syncAll()})}presentEnabledInfo(){return o(this,null,function*(){let t=yield this.translate.get("offlineMode.enabled.header").toPromise(),e=yield this.translate.get("offlineMode.enabled.message").toPromise(),r=yield this.translate.get("generic.moreInfo").toPromise(),s=yield this.translate.get("generic.close").toPromise(),l=yield this.alertCtrl.create({header:t,message:e,cssClass:"alert-preline",buttons:[{text:r,handler:()=>{window.open(v,"_blank",'rel="noopener"')}},{text:s,role:"cancel"}]});yield l.present(),yield l.onDidDismiss()})}presentSyncRequired(){return o(this,null,function*(){let t=yield this.translate.get("offlineMode.syncRequired.header").toPromise(),e=yield this.translate.get("offlineMode.syncRequired.message").toPromise(),r=yield this.translate.get("generic.okay").toPromise(),s=yield this.alertCtrl.create({header:t,message:e,cssClass:"alert-preline",buttons:[{text:r,role:"cancel"}]});yield s.present(),yield s.onDidDismiss()})}promptSlowRead(){return o(this,null,function*(){if(!(a.enabled||this.promptedThisSession||this.isPromptOpen||this.preferencesService.preferences[p.OfflineModePrompt]===f.Never||!(yield d.getLastSync()))){this.promptedThisSession=!0,this.isPromptOpen=!0;try{let e=yield this.translate.get("offlineMode.prompt.header").toPromise(),r=yield this.translate.get("offlineMode.prompt.message").toPromise(),s=yield this.translate.get("offlineMode.prompt.enable").toPromise(),l=yield this.translate.get("offlineMode.prompt.notNow").toPromise(),P=yield this.translate.get("offlineMode.prompt.neverAsk").toPromise(),m=yield this.alertCtrl.create({header:e,message:r,cssClass:"alert-preline",buttons:[{text:P,handler:()=>{this.preferencesService.preferences[p.OfflineModePrompt]=f.Never,this.preferencesService.save()}},{text:l,role:"cancel"},{text:s,handler:()=>{a.enable()}}]});yield m.present(),yield m.onDidDismiss()}finally{this.isPromptOpen=!1}}})}presentBlocked(){return o(this,null,function*(){if(!this.isBlockedAlertOpen){this.isBlockedAlertOpen=!0;try{let t=yield this.translate.get("offlineMode.blocked.header").toPromise(),e=yield this.translate.get("offlineMode.blocked.message").toPromise(),r=yield this.translate.get("generic.okay").toPromise(),s=yield this.alertCtrl.create({header:t,message:e,buttons:[{text:r,role:"cancel"}]});yield s.present(),yield s.onDidDismiss()}finally{this.isBlockedAlertOpen=!1}}})}};i.\u0275fac=function(e){return new(e||i)},i.\u0275prov=h({token:i,factory:i.\u0275fac,providedIn:"root"});let c=i;return c})();export{N as a};
