'use client';
/**
* Territories Page — Standalone page for the Territories analytics detail view.
*
* Renders the TerritoriesTab content from the analytics detail page as its own route.
* Accessible via sidebar navigation under Analítica > Territories.
*/
import { useMemo } from 'react';
import { clientPortal } from '@/lib/mock-data';
import { useCompactCurrencyFormatter } from '@/lib/hooks/useCurrencyFormatter';
import { chartColorArray } from '@/lib/constants/theme';
import type { PortalTerritoryDetail } from '@/lib/mock-data/types';
import BarChartWidget from '@/components/charts/BarChartWidget';
// ─── Helper Components ───────────────────────────────────────────────────────
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 TerritoriesDetailView({ data }: { data: PortalTerritoryDetail[] }) {
const fmtMoney = useCompactCurrencyFormatter();
const sorted = useMemo(
() => [...data].sort((a, b) => b.currentPeriodAmount - a.currentPeriodAmount),
[data]
);
const total = sorted.reduce((sum, t) => sum + t.currentPeriodAmount, 0);
const totalLast = sorted.reduce((sum, t) => sum + t.lastPeriodAmount, 0);
const trend = totalLast > 0 ? ((total - totalLast) / totalLast) * 100 : 0;
const chartData = sorted.slice(0, 10).map((t) => ({
country: t.country,
amount: t.currentPeriodAmount,
}));
return (
Territorios Principales
{/* Left Panel */}
{sorted.slice(0, 10).map((territory, i) => (
-
{territory.country}
{fmtMoney(territory.currentPeriodAmount)}
))}
{/* Right Panel - Table */}
#
Los 32 Territorios Principales
Último Período
Período Actual
{sorted.map((territory, i) => (
{i + 1}
{territory.country}
{fmtMoney(territory.lastPeriodAmount)}
{fmtMoney(territory.currentPeriodAmount)}
))}
);
}
export default function TerritoriesPage() {
return ;
}