"use strict";var a=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var u=(e,t)=>a(e,"name",{value:t,configurable:true});var f=(e,t)=>{for(var i in t)a(e,i,{get:t[i],enumerable:true})};var j=(e,t,i,r)=>{if(t&&typeof t==="object"||typeof t==="function"){for(let s of y(t))if(!m.call(e,s)&&s!==i)a(e,s,{get:()=>t[s],enumerable:!(r=c(t,s))||r.enumerable})}return e};var S=e=>j(a({},"__esModule",{value:true}),e);var d=(e,t,i,r)=>{var s=r>1?void 0:r?c(t,i):t;for(var l=e.length-1,g;l>=0;l--)if(g=e[l])s=(r?g(t,i,s):g(s))||s;if(r&&s)a(t,i,s);return s};var F={};f(F,{default:()=>n});module.exports=S(F);var o=require("fs-extra");var h=require("mobx");var b=require("../environment-remote");const p=require("../preload-safe-debug")("Ferdium:Settings");class n{type="";defaultState;store={};constructor(t,i={}){(0,h.makeObservable)(this);this.type=t;this.store=i;this.defaultState=i;if((0,o.pathExistsSync)(this.settingsFile)){this._hydrate()}else{this._writeFile()}}set(t){this.store=this._merge(t);this._writeFile()}get all(){return this.store}get allSerialized(){return(0,h.toJS)(this.store)}get(t){return this.store[t]}_merge(t){return Object.assign(this.defaultState,this.store,t)}_hydrate(){this.store=this._merge((0,o.readJsonSync)(this.settingsFile));p("Hydrate store",this.type,this.allSerialized)}_writeFile(){(0,o.outputJsonSync)(this.settingsFile,this.store,{spaces:2});p("Write settings file",this.type,this.allSerialized)}get settingsFile(){return(0,b.userDataPath)("config",`${this.type==="app"?"settings":this.type}.json`)}}u(n,"Settings");d([h.observable],n.prototype,"store",2);
