const API_URL = `${import.meta.env.VITE_API_URL}/dashboard`;

export const dashboardService = {
  getStats: async (start?: string, end?: string) => {
    const token = localStorage.getItem('token');
    const params = new URLSearchParams();
    if (start) params.append('start', start);
    if (end) params.append('end', end);

    const response = await fetch(`${API_URL}/stats?${params.toString()}`, {
      headers: {
        'Authorization': `Bearer ${token}`
      }
    });

    if (!response.ok) throw new Error('Error al cargar estadísticas');
    return await response.json();
  },

  // Obtiene analítica avanzada para reportes gerenciales detallados
  getAdvancedAnalytics: async (start?: string, end?: string) => {
    const token = localStorage.getItem('token');
    const params = new URLSearchParams();
    if (start) params.append('start', start);
    if (end) params.append('end', end);

    const response = await fetch(`${API_URL}/analytics?${params.toString()}`, {
      headers: {
        'Authorization': `Bearer ${token}`
      }
    });

    if (!response.ok) throw new Error('Error al cargar analítica avanzada');
    return await response.json();
  }
};
