import { Box, TextField, Button, IconButton, Typography, Paper } from '@mui/material'; import AddIcon from '@mui/icons-material/Add'; import DeleteIcon from '@mui/icons-material/Delete'; import type { Symbol } from '../types'; interface FrequencyInputProps { symbols: Symbol[]; onSymbolsChange: (symbols: Symbol[]) => void; } export default function FrequencyInput({ symbols, onSymbolsChange }: FrequencyInputProps) { const handleAddSymbol = () => { const nextLetter = String.fromCharCode(65 + symbols.length); // A, B, C, ... const defaultColors = ['#1976d2', '#dc004e', '#9c27b0', '#f57c00', '#388e3c', '#d32f2f', '#0097a7', '#7b1fa2', '#c2185b', '#5d4037']; const newSymbol: Symbol = { name: nextLetter, frequency: 1, color: defaultColors[symbols.length % defaultColors.length], }; onSymbolsChange([...symbols, newSymbol]); }; const handleRemoveSymbol = (index: number) => { const newSymbols = symbols.filter((_, i) => i !== index); onSymbolsChange(newSymbols); }; const handleFrequencyChange = (index: number, value: string) => { const frequency = parseInt(value) || 1; const newSymbols = [...symbols]; newSymbols[index] = { ...newSymbols[index], frequency: Math.max(1, frequency) }; onSymbolsChange(newSymbols); }; const totalL = symbols.reduce((sum, s) => sum + s.frequency, 0); return ( Symbol Frequencies Configure the relative frequencies of each symbol. L = {totalL} {symbols.map((symbol, index) => ( {symbol.name} handleFrequencyChange(index, e.target.value)} size="small" inputProps={{ min: 1 }} sx={{ width: 120 }} /> handleRemoveSymbol(index)} disabled={index !== symbols.length - 1 || symbols.length <= 1} color="error" size="small" > ))} ); }