import { h } from 'preact'; import { useEffect, useRef, useState } from 'preact/hooks'; import styles from '../NewGame.module.css'; interface PlayerStepProps { playerNameHistory: string[]; onNext: (name: string) => void; onCancel: () => void; initialValue?: string; } export const Player3Step = ({ playerNameHistory, onNext, onCancel, initialValue = '' }: PlayerStepProps) => { const [player3, setPlayer3] = useState(initialValue); const [filteredNames, setFilteredNames] = useState(playerNameHistory); const inputRef = useRef(null); useEffect(() => { const el = inputRef.current; if (el) { el.focus(); } }, []); useEffect(() => { if (!player3) { setFilteredNames(playerNameHistory); } else { setFilteredNames( playerNameHistory.filter(name => name.toLowerCase().includes(player3.toLowerCase()) ) ); } }, [player3, playerNameHistory]); const handleSubmit = (e: Event) => { e.preventDefault(); onNext(player3.trim()); }; const handleQuickPick = (name: string) => { onNext(name); }; const handleClear = () => { setPlayer3(''); if (inputRef.current) inputRef.current.focus(); }; const handleSkip = (e: Event) => { e.preventDefault(); onNext(''); }; return (
Name Spieler 3 (optional)
{ const target = e.target as HTMLInputElement; setPlayer3(target.value); }} autoComplete="off" aria-label="Name Spieler 3" style={{ fontSize: '1.2rem', minHeight: 48, marginTop: 12, marginBottom: 12, width: '100%', paddingRight: 44 }} ref={inputRef} /> {player3 && ( )}
{filteredNames.length > 0 && (
{filteredNames.slice(0, 10).map((name, idx) => ( ))}
)}
); };