document.body.insertAdjacentHTML('beforeend', ` `); class VodiaIdentitySwitcher { // --- Configuration --- API_BASE_URL = window.baseurl || '/'; CACHE_DURATION_MS = 60000; // 60 seconds LOCK_TIMEOUT_MS = 5000; // 5 seconds for a request to complete CACHE_KEY = 'vodiaIdentityCache'; LOCK_KEY = 'vodiaIdentityCache_lock'; TEXT = { checking: "Prüfe...", setting: "Ändere...", dropdownTitle: "Ausgehende Identität wählen:", ownExtension: "Eigene Nummer", customIdentity: "Andere Nummer", noActiveCall: "Kein aktiver Anruf gefunden.", lookupError: "Fehler bei der Anrufabfrage.", fetchError: "Fehler" }; // --- State --- elements = {}; templates = {}; constructor(parentElement) { if (!parentElement) return; this._initializeTemplates(); if (!this.templates.main || !this.templates.listItem) return; this._createSwitcherUI(parentElement); this._addEventListeners(); // Initial load if tab is already visible if (document.visibilityState === 'visible') { this.loadIdentity(); } } // --- Private Methods: Initialization --- _initializeTemplates() { this.templates.main = document.getElementById('vodia-identity-template'); this.templates.listItem = document.getElementById('vodia-list-item-template'); if (!this.templates.main || !this.templates.listItem) { console.error("Vodia Switcher Error: Required HTML