import { Treemap, ResponsiveContainer, Tooltip } from 'recharts'; export type ReadinessCategory = 'automate_now' | 'assist_copilot' | 'optimize_first'; export interface TreemapData { name: string; value: number; // Savings potential (determines size) category: ReadinessCategory; skill: string; score: number; // Agentic readiness score 0-10 volume?: number; } export interface OpportunityTreemapProps { data: TreemapData[]; title?: string; height?: number; onItemClick?: (item: TreemapData) => void; } const CATEGORY_COLORS: Record = { automate_now: '#059669', // emerald-600 assist_copilot: '#6D84E3', // primary blue optimize_first: '#D97706' // amber-600 }; const CATEGORY_LABELS: Record = { automate_now: 'Automatizar Ahora', assist_copilot: 'Asistir con Copilot', optimize_first: 'Optimizar Primero' }; interface TreemapContentProps { x: number; y: number; width: number; height: number; name: string; category: ReadinessCategory; score: number; value: number; } const CustomizedContent = ({ x, y, width, height, name, category, score, value }: TreemapContentProps) => { const showLabel = width > 60 && height > 40; const showScore = width > 80 && height > 55; const showValue = width > 100 && height > 70; const baseColor = CATEGORY_COLORS[category] || '#94A3B8'; return ( {showLabel && ( {name.length > 15 && width < 120 ? `${name.slice(0, 12)}...` : name} )} {showScore && ( Score: {score.toFixed(1)} )} {showValue && ( €{(value / 1000).toFixed(0)}K )} ); }; interface TooltipPayload { payload: TreemapData; } const CustomTooltip = ({ active, payload }: { active?: boolean; payload?: TooltipPayload[] }) => { if (active && payload && payload.length) { const data = payload[0].payload; return (

{data.name}

{data.skill}

Readiness Score: {data.score.toFixed(1)}/10
Ahorro Potencial: €{data.value.toLocaleString()}
{data.volume && (
Volumen: {data.volume.toLocaleString()}/mes
)}
Categoría: {CATEGORY_LABELS[data.category]}
); } return null; }; export function OpportunityTreemap({ data, title, height = 350, onItemClick }: OpportunityTreemapProps) { // Group data by category for treemap const treemapData = data.map(item => ({ ...item, size: item.value })); return (
{title && (

{title}

)} } onClick={onItemClick ? (node) => onItemClick(node as unknown as TreemapData) : undefined} > } /> {/* Legend */}
{Object.entries(CATEGORY_COLORS).map(([category, color]) => (
{CATEGORY_LABELS[category as ReadinessCategory]}
))}
); } export default OpportunityTreemap;