export class RealApi { static getBaseUrl() { // Adjust if serving from a different machine return window.location.hostname === 'localhost' ? 'http://localhost:3001/api' : `http://${window.location.hostname}:3001/api`; } static async fetchData(endpoint) { try { const response = await fetch(`${this.getBaseUrl()}${endpoint}`); if (!response.ok) throw new Error(`API Error: ${response.status}`); return await response.json(); } catch (error) { console.error(error); return null; // Handle gracefully in UI } } static async getDashboardStats() { const data = await this.fetchData('/dashboard'); return data || { totalJobs: 0, successRate: 0, totalBytes: 0, activeClients: 0, storageUsage: 0 }; } static async getRecentJobs() { const data = await this.fetchData('/jobs'); return data || []; } static async getClients() { const data = await this.fetchData('/clients'); return data || []; } static async getStorage() { const data = await this.fetchData('/storage'); return data || []; } }