import Link from 'next/link'; import { getLeads, getResumen, type LeadFiltro } from '@/db/queries'; import { ESTADOS, ESTADO_BADGE, ESTADO_LABEL, PIPELINE_LABEL, PIPELINE_NEXT, formatEuros, formatFecha, } from '@/lib/funnel'; export const dynamic = 'force-dynamic'; const FILTROS: { value: LeadFiltro; label: string }[] = [ { value: 'todos', label: 'Todos' }, ...ESTADOS.map((e) => ({ value: e as LeadFiltro, label: ESTADO_LABEL[e] })), ]; export default async function PanelPage({ searchParams, }: { searchParams: Promise<{ estado?: string }>; }) { const { estado } = await searchParams; const filtro: LeadFiltro = (FILTROS.find((f) => f.value === estado)?.value ?? 'todos') as LeadFiltro; const [leads, resumen] = await Promise.all([getLeads(filtro), getResumen()]); return (

Leads

{resumen.total} leads en total ยท {resumen.porEstado['nuevo'] ?? 0} sin contactar

{/* Filtros por estado */}
{FILTROS.map((f) => { const active = f.value === filtro; const count = f.value === 'todos' ? resumen.total : resumen.porEstado[f.value] ?? 0; return ( {f.label} {count} ); })}
{/* Tabla (desktop) */}
{leads.map((l) => ( ))}
Render Cliente Fecha Estado Presupuesto Siguiente paso
{l.renderUrl ? ( // eslint-disable-next-line @next/next/no-img-element ) : ( sin render )} {l.nombre}
{l.telefono}
{formatFecha(l.createdAt)} {ESTADO_LABEL[l.estado]} {formatEuros(l.presupuestoEstimado)}
{PIPELINE_LABEL[l.pipelineStage]}
{PIPELINE_NEXT[l.pipelineStage]}
{leads.length === 0 && (
No hay leads con este estado.
)}
{/* Cards (mobile) */}
{leads.map((l) => (
{l.renderUrl ? ( // eslint-disable-next-line @next/next/no-img-element ) : null}
{l.nombre} {ESTADO_LABEL[l.estado]}
{l.telefono}
{formatEuros(l.presupuestoEstimado)} {formatFecha(l.createdAt)}
{PIPELINE_NEXT[l.pipelineStage]}
))} {leads.length === 0 && (
No hay leads con este estado.
)}
); }