import { conAuth, manejar401 } from './auth' const API_URL = import.meta.env.VITE_API_URL || '/api' async function fetchJson(path: string, init: RequestInit = {}): Promise { const res = await fetch(`${API_URL}${path}`, conAuth(init)) manejar401(res) if (!res.ok) { const body = (await res.json().catch(() => null)) as { error?: string } | null throw new Error(body?.error ?? `Error ${res.status}`) } return (await res.json()) as T } // ---------- Interfaces ---------- export interface MiTablero { generadoEn: string leadsPorDia: { fecha: string; cantidad: number }[] conversion: { leads: number oportunidades: number apartados: number vendidos: number } ventasMes: { monto: number unidades: number } porOrigen: { origen: string total: number convertidos: number }[] porDesarrollo: { desarrollo: string ventas: number }[] actividadesHoy: number actividadesPendientes: number } // ---------- Fetch ---------- export function fetchMiTablero(): Promise { return fetchJson('/reportes/mi-tablero') }