import React, { useState } from 'react';
interface LegendProps {
thresholds: number[];
circleColor: string;
biasMotivations: string[];
selectedBiases: string[];
onBiasChange: (biases: string[]) => void;
}
export default function Legend({
thresholds,
circleColor,
biasMotivations,
selectedBiases,
onBiasChange,
}: LegendProps) {
const [isFilterOpen, setIsFilterOpen] = useState(false);
const toggleBias = (bias: string) => {
if (selectedBiases.includes(bias)) {
onBiasChange(selectedBiases.filter((b) => b !== bias));
} else {
onBiasChange([...selectedBiases, bias]);
}
};
return (
{!isFilterOpen && (
<>
Number of reported crimes
Since 2016
{selectedBiases.length > 0 && (
{selectedBiases.length === 1
? ` - ${selectedBiases[0]}`
: ` - ${selectedBiases.length} selected biases`}
)}
{thresholds.map((threshold, i) => {
const size = i === 0 ? 8 : i === 1 ? 12 : i === 2 ? 16 : i === 3 ? 24 : i === 4 ? 32 : 48;
return (
{i === 0
? `< ${threshold}`
: i === thresholds.length - 1
? `> ${thresholds[i - 1]}`
: `${thresholds[i - 1]} - ${threshold}`}
);
})}
>
)}
);
}