import React from 'react';
import { ResponsiveContainer, RadarChart, PolarGrid, PolarAngleAxis, PolarRadiusAxis, Radar, Tooltip, Legend } from 'recharts';

export interface RadarMetric {
    label: string;
    value: number; // 0-100
    max?: number;
}

interface Props {
    title?: string;
    data: RadarMetric[];
    height?: number;
    color?: string;
}

const RadarPerformanceChart: React.FC<Props> = ({ title, data, height = 320, color = '#3b82f6' }) => {
    const chartData = data.map(d => ({ subject: d.label, A: d.value, fullMark: d.max ?? 100 }));
    return (
        <div className="w-full h-full">
            {title && <h4 className="text-sm font-medium text-[--text-secondary] mb-2">{title}</h4>}
            <div style={{ width: '100%', height }}>
                <ResponsiveContainer>
                    <RadarChart data={chartData} margin={{ top: 10, right: 30, bottom: 10, left: 10 }}>
                        <PolarGrid stroke="var(--border-color)" />
                        <PolarAngleAxis dataKey="subject" tick={{ fill: 'var(--text-secondary)', fontSize: 11 }} />
                        <PolarRadiusAxis angle={30} domain={[0, 100]} tick={{ fill: 'var(--text-secondary)', fontSize: 10 }} />
                        <Radar name={title || 'Score'} dataKey="A" stroke={color} fill={color} fillOpacity={0.35} />
                        <Tooltip wrapperStyle={{ fontSize: 12 }} contentStyle={{ background: 'var(--background-secondary)', border: '1px solid var(--border-color)' }} />
                        <Legend wrapperStyle={{ fontSize: 12 }} />
                    </RadarChart>
                </ResponsiveContainer>
            </div>
        </div>
    );
};

export default RadarPerformanceChart;
