1// services/GlobalSettingsService.js 2import { apiClient } from "./core/ApiClient.js"; 3import { GlobalSettingsMock } from "../data/mocks/GlobalSettingsMock.js"; 4import { AppConfig } from "../config/AppConfig.js"; 5import { sanitizerService } from '../services/SanitizerService.js'; 6import { i18n } from "./I18nService.js"; 7 8class GlobalSettingsService { 9 constructor(){ 10 // Aquà almacenamos la "verdad" actual de la configuración 11 this.settings = null; 12 } 13 14 /** 15 * Extrae la rama del mock según el idioma detectado por i18n 16 */ 17 _getLocalizedMock() { 18 const lang = i18n.getCurrentLocale(); // 'es', 'va' o 'en' 19 return GlobalSettingsMock[lang] || GlobalSettingsMock['es']; 20 } 21 22 /** 23 * Método de carga (se llama al arrancar la app y cada vez que cambia el idioma) 24 */ 25 async init(){ 26 const localizedData = this._getLocalizedMock(); 27 28 if (AppConfig.USE_REMOTE_API) { 29 try { 30 let response = await apiClient.get('/api/global-settings', localizedData); 31 // Guardamos y sanitizamos 32 this.settings = sanitizerService.sanitizeResponse(response); 33 } catch (error) { 34 console.error("Error cargando Global Settings desde API:", error); 35 this.settings = localizedData; 36 } 37 } else { 38 // MODO MOCK: Actualizamos la variable de clase con el idioma actual. 39 // Esto es lo que permite que el Footer cambie al cambiar de idioma. 40 this.settings = localizedData; 41 console.log(`[GlobalSettings] Datos cargados para idioma: ${i18n.getCurrentLocale()}`); 42 return Promise.resolve(this.settings); 43 } 44 } 45 46 /** 47 * Devuelve los settings actuales. 48 * Si settings es null, hace un fallback dinámico al mock. 49 */ 50 getSettings(){ 51 return this.settings || this._getLocalizedMock(); 52 } 53} 54 55export const globalSettingsService = new GlobalSettingsService();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.