import { h } from 'preact'; import { useState, useEffect, useRef } from 'preact/hooks'; import styles from './NewGame.module.css'; /** * Player 1 input step for multi-step game creation wizard. * @param {object} props * @param {string[]} props.playerNameHistory * @param {Function} props.onNext * @param {Function} props.onCancel * @param {string} [props.initialValue] * @returns {import('preact').VNode} */ const Player1Step = ({ playerNameHistory, onNext, onCancel, initialValue = '' }) => { const [player1, setPlayer1] = useState(initialValue); const [error, setError] = useState(null); const [filteredNames, setFilteredNames] = useState(playerNameHistory); const inputRef = useRef(null); useEffect(() => { if (!player1) { setFilteredNames(playerNameHistory); } else { setFilteredNames( playerNameHistory.filter(name => name.toLowerCase().includes(player1.toLowerCase()) ) ); } }, [player1, playerNameHistory]); const handleSubmit = (e) => { e.preventDefault(); if (!player1.trim()) { setError('Bitte Namen für Spieler 1 eingeben'); return; } setError(null); onNext(player1.trim()); }; const handleQuickPick = (name) => { setError(null); onNext(name); }; const handleClear = () => { setPlayer1(''); setError(null); if (inputRef.current) inputRef.current.focus(); }; return (
); }; export default Player1Step;