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 (
); }; /** * Player 2 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 Player2Step = ({ playerNameHistory, onNext, onCancel, initialValue = '' }) => { const [player2, setPlayer2] = useState(initialValue); const [error, setError] = useState(null); const [filteredNames, setFilteredNames] = useState(playerNameHistory); const inputRef = useRef(null); useEffect(() => { if (!player2) { setFilteredNames(playerNameHistory); } else { setFilteredNames( playerNameHistory.filter(name => name.toLowerCase().includes(player2.toLowerCase()) ) ); } }, [player2, playerNameHistory]); const handleSubmit = (e) => { e.preventDefault(); if (!player2.trim()) { setError('Bitte Namen für Spieler 2 eingeben'); return; } setError(null); onNext(player2.trim()); }; const handleQuickPick = (name) => { setError(null); onNext(name); }; const handleClear = () => { setPlayer2(''); setError(null); if (inputRef.current) inputRef.current.focus(); }; return ( ); }; /** * Player 3 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 Player3Step = ({ playerNameHistory, onNext, onCancel, initialValue = '' }) => { const [player3, setPlayer3] = useState(initialValue); const [filteredNames, setFilteredNames] = useState(playerNameHistory); const inputRef = useRef(null); useEffect(() => { if (!player3) { setFilteredNames(playerNameHistory); } else { setFilteredNames( playerNameHistory.filter(name => name.toLowerCase().includes(player3.toLowerCase()) ) ); } }, [player3, playerNameHistory]); const handleSubmit = (e) => { e.preventDefault(); // Player 3 is optional, so always allow submission onNext(player3.trim()); }; const handleQuickPick = (name) => { onNext(name); }; const handleClear = () => { setPlayer3(''); if (inputRef.current) inputRef.current.focus(); }; const handleSkip = (e) => { e.preventDefault(); onNext(''); }; return ( ); }; /** * Game Type selection step for multi-step game creation wizard. * @param {object} props * @param {Function} props.onNext * @param {Function} props.onCancel * @param {string} [props.initialValue] * @returns {import('preact').VNode} */ const GameTypeStep = ({ onNext, onCancel, initialValue = '' }) => { const gameTypes = ['8-Ball', '9-Ball', '10-Ball', '14/1 endlos']; const handleSelect = (gameType) => { onNext(gameType); }; return (