/* ESPILON C2 — Alpine.js global store */ document.addEventListener('alpine:init', () => { Alpine.store('app', { devices: [], stats: { connected_devices: 0, active_cameras: 0, multilateration_scanners: 0 }, serverOnline: true, sidebarCollapsed: localStorage.getItem('espilon_sidebar') === '1', async fetchDevices() { try { const res = await fetch('/api/devices'); if (!res.ok) throw new Error(res.status); const data = await res.json(); this.devices = data.devices || []; this.serverOnline = true; } catch (e) { this.serverOnline = false; } }, async fetchStats() { try { const res = await fetch('/api/stats'); if (!res.ok) throw new Error(res.status); this.stats = await res.json(); this.serverOnline = true; } catch (e) { this.serverOnline = false; } }, toggleSidebar() { this.sidebarCollapsed = !this.sidebarCollapsed; localStorage.setItem('espilon_sidebar', this.sidebarCollapsed ? '1' : '0'); }, connectedDevices() { return this.devices.filter(d => d.status === 'Connected'); }, offlineDevices() { return this.devices.filter(d => d.status !== 'Connected'); }, deviceIds() { return this.connectedDevices().map(d => d.id); }, init() { this.fetchDevices(); this.fetchStats(); setInterval(() => this.fetchDevices(), 5000); setInterval(() => this.fetchStats(), 10000); } }); });