import React from "react";
import {
    ResponsiveContainer,
    LineChart as LC,
    CartesianGrid,
    XAxis,
    YAxis,
    Tooltip,
    Legend,
    Line,
} from "recharts";
import { ChartProps } from "../types";

export default function LineChart(props: ChartProps) {
    return (
        <ResponsiveContainer height={300}>
            <LC
                width={600}
                height={300}
                data={props.data.map((d) => {
                    return {
                        name: d.name,
                        ...d.values,
                    };
                })}
            >
                {Object.keys(props.data[0].values).map((k, i) => (
                    <Line
                        type="monotone"
                        key={i}
                        dataKey={k}
                        stroke="#8884d8"
                        name={k}
                        dot={false}
                    />
                ))}
                <CartesianGrid stroke="#ccc" />
                <XAxis dataKey="name" />
                <YAxis scale={props.scale ?? "auto"} />
                <Tooltip />
                <Legend verticalAlign="top" />
            </LC>
        </ResponsiveContainer>
    );
}
