import{c as j,d as B,p as F}from"./chunk-SPUEGBWO.js";import{k as K}from"./chunk-3JLWQSYQ.js";import{$d as d,A as a,Bd as w,Dd as O,E as b,Xd as S,Yd as T,Zd as f,_d as g,ad as v,ae as A,be as I,ce as M,de as E,ee as R,fe as L,ge as s,he as r,ie as m,je as C,ke as N,le as k,me as c,ne as n,w as y}from"./chunk-ZVAMPSQU.js";import{a as h}from"./chunk-FB5LSH2R.js";var u="preferences",Y=(()=>{let i=class i{constructor(){this.serverActionsService=a(F),this.injector=a(b),this.translate=a(v),this.events=a(B),this.preferences={preferencesVersion:0,[s.EnableSplitPane]:!1,[s.Language]:null,[s.FontSize]:S.X1_0,[s.Theme]:T.Default,[s.PreferencesSync]:f.Enabled,[s.StartPage]:E.MyRecipes,[s.OfflineModePrompt]:L.Ask,[r.EnableLabelIntersection]:!1,[r.ShowLabels]:!0,[r.ShowLabelChips]:!1,[r.ShowImages]:!0,[r.ShowSource]:!1,[r.ShowRecipeDescription]:!0,[r.ShowRating]:!1,[r.ViewType]:Math.min(window.innerWidth,window.innerHeight)<440?g.List:g.Tiles,[r.SortBy]:d.TitleAsc,[r.IncludeFriends]:A.No,[m.EnableWakeLock]:!0,[m.AutoExpandNutrition]:!1,[C.FontSize]:S.PX20,[N.ShowCreatedAt]:!0,[k.EnabledUnits]:[...w,...O],[c.ShowAddedBy]:!1,[c.ShowAddedOn]:!1,[c.StartOfWeek]:I.Monday,[c.ViewType]:M.Calendar,[n.SortBy]:R.CreatedAtDesc,[n.ShowAddedBy]:!1,[n.ShowAddedOn]:!1,[n.ShowRecipeTitle]:!0,[n.PreferDelete]:!1,[n.GroupSimilar]:!0,[n.GroupCategories]:!0,[n.IgnoreItemTitles]:""},this.load()}save(t){try{let e=JSON.stringify(this.preferences);localStorage.setItem(u,e)}catch(e){console.error(e)}t||this.preferences[s.PreferencesSync]===f.Enabled&&localStorage.getItem("token")&&this.serverActionsService.users.updatePreferences(this.preferences,{"*":()=>{}})}patchPreferences(t){let e=h({},t);e["myRecipes.sortBy"]==="-title"&&(e["myRecipes.sortBy"]=d.TitleAsc);let o=localStorage.getItem("theme");return o&&(e["global.theme"]=o,localStorage.removeItem("theme")),e}filterRemotePreferences(t){let e=h({},t);return delete e["global.preferencesSync"],delete e["myRecipes.viewType"],e}load(){try{let t=localStorage.getItem(u),e=t?JSON.parse(t)||{}:{},o=this.patchPreferences(e);Object.assign(this.preferences,o)}catch(t){console.error(t)}this.preferences[s.PreferencesSync]===f.Enabled&&localStorage.getItem("token")&&this.serverActionsService.users.getPreferences({"*":()=>{}}).then(t=>{if(t){let e=this.patchPreferences(t),o=this.filterRemotePreferences(e),z=this.preferences["global.language"],D=this.preferences["global.theme"],V=this.preferences["global.enableSplitPane"];Object.assign(this.preferences,o),this.save(!0);let l=this.injector.get(K);l.setFontSize(this.preferences["global.fontSize"]);let P=this.preferences["global.language"]||l.getAppBrowserLang();z!==this.preferences["global.language"]&&(this.translate.use(P),l.setHtmlBrowserLang(P)),D!==this.preferences["global.theme"]&&l.setAppTheme(this.preferences["global.theme"]),V!==this.preferences["global.enableSplitPane"]&&this.events.publish(j.ApplicationSplitPaneChanged)}})}resetToDefaults(){localStorage.removeItem(u),window.location.reload()}};i.\u0275fac=function(e){return new(e||i)},i.\u0275prov=y({token:i,factory:i.\u0275fac,providedIn:"root"});let p=i;return p})();export{Y as a};
