import Log from "./Log.js"; export default class Preferences { static NAME = 'midefos-idealista'; static _current; static init() { this._current = this._getConfig(); } static get(key) { const config = this._getConfig(); const value = config[key]; if (value === undefined) return this._getFromDefault(key); return value; } static save(config) { window.localStorage.setItem(this.NAME, JSON.stringify(config)); this._current = config; Log.debug('Saved preferences') } static _getConfig() { const storageConfig = this._getFromLocalStorage(); if (!storageConfig) return this._default(); return storageConfig; } static _getFromLocalStorage() { const storageConfig = window.localStorage.getItem(this.NAME); if (!storageConfig) return null; return JSON.parse(storageConfig); } static _getFromDefault(key) { const defaultPreferences = this._default(); return defaultPreferences[key]; } static _default() { return { enabled: true, darkMode: true, enlargeImages: false, currentMoney: 0, 'max-price': 120_000, 'max-price-per-meter': 1_500, percentages: true, percentages_20: true, percentages_30: true, percentages_50: false, garage: false, exterior: true, lift: true, bus: false, train: false, supermarket: true, smoke: false, pharmacy: true, gym: false, pool: true } } }