'use client'; /** * Income Groups Page — Standalone page for the Income Groups analytics detail view. * * Renders the IncomeTab content from the analytics detail page as its own route. * Accessible via sidebar navigation under Analítica > Income Groups. */ import { useState, useMemo } from 'react'; import { clientPortal } from '@/lib/mock-data'; import { useCompactCurrencyFormatter } from '@/lib/hooks/useCurrencyFormatter'; import { chartColorArray } from '@/lib/constants/theme'; import type { PortalIncomeGroupDetail } from '@/lib/mock-data/types'; import PieChartWidget from '@/components/charts/PieChartWidget'; // ─── Helper Components ─────────────────────────────────────────────────────── function ChevronIcon({ expanded }: { expanded: boolean }) { return ( ); } function PercentageBadge({ value }: { value: number }) { const isPositive = value >= 0; return ( {isPositive ? '+' : ''}{value.toFixed(1)}% ); } function TotalEarningsCard({ total, trend }: { total: number; trend: number }) { const fmtMoney = useCompactCurrencyFormatter(); return (

Ganancias totales

{fmtMoney(total)}

); } // ─── Main Component ────────────────────────────────────────────────────────── function IncomeDetailView({ data }: { data: PortalIncomeGroupDetail[] }) { const [expandedRows, setExpandedRows] = useState>(new Set()); const fmtMoney = useCompactCurrencyFormatter(); const sorted = useMemo( () => [...data].sort((a, b) => b.currentPeriodAmount - a.currentPeriodAmount), [data] ); const total = sorted.reduce((sum, g) => sum + g.currentPeriodAmount, 0); const totalLast = sorted.reduce((sum, g) => sum + g.lastPeriodAmount, 0); const trend = totalLast > 0 ? ((total - totalLast) / totalLast) * 100 : 0; const toggleRow = (category: string) => { setExpandedRows((prev) => { const next = new Set(prev); if (next.has(category)) next.delete(category); else next.add(category); return next; }); }; const chartData = sorted.map((g) => ({ name: g.category, value: g.currentPeriodAmount })); return (

Grupos de Ingresos Más Altos

{/* Left Panel */}
    {sorted.map((group, i) => (
  • {group.category} {fmtMoney(group.currentPeriodAmount)}
  • ))}
{/* Right Panel - Table */}
# Grupos De Ingresos Más Altos Último Período Período Actual
{sorted.map((group, i) => { const isExpanded = expandedRows.has(group.category); return (
toggleRow(group.category)} > {i + 1}
{group.category}
{fmtMoney(group.lastPeriodAmount)}
{fmtMoney(group.currentPeriodAmount)}
{isExpanded && (
{group.subCategories.map((sub) => (
{sub.name} {fmtMoney(sub.lastPeriodAmount)}
{fmtMoney(sub.currentPeriodAmount)}
))}
)}
); })}
); } export default function IncomeGroupsPage() { return ; }