import { h } from 'preact'; import { useState, useEffect, useRef } from 'preact/hooks'; import styles from './NewGame.module.css'; import modalStyles from './PlayerSelectModal.module.css'; const PlayerSelectModal = ({ players, onSelect, onClose }) => (
e.stopPropagation()}>

Alle Spieler

{players.map(player => ( ))}
); /** * 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 [isModalOpen, setIsModalOpen] = useState(false); 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 handleModalSelect = (name) => { setIsModalOpen(false); handleQuickPick(name); }; const handleClear = () => { setPlayer1(''); setError(null); if (inputRef.current) inputRef.current.focus(); }; return (
Neues Spiel – Schritt 1/5
setPlayer1(e.target.value)} autoComplete="off" aria-label="Name Spieler 1" style={{ fontSize: '1.2rem', minHeight: 48, marginTop: 12, marginBottom: 12, width: '100%', paddingRight: 44 }} ref={inputRef} /> {player1 && ( )}
{filteredNames.length > 0 && (
{filteredNames.slice(0, 10).map((name, idx) => ( ))} {playerNameHistory.length > 10 && ( )}
)}
{error &&
{error}
} {isModalOpen && ( setIsModalOpen(false)} /> )}
); }; /** * 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 (
Neues Spiel – Schritt 2/5
setPlayer2(e.target.value)} autoComplete="off" aria-label="Name Spieler 2" style={{ fontSize: '1.2rem', minHeight: 48, marginTop: 12, marginBottom: 12, width: '100%', paddingRight: 44 }} ref={inputRef} /> {player2 && ( )}
{filteredNames.length > 0 && (
{filteredNames.slice(0, 10).map((name, idx) => ( ))}
)}
{error &&
{error}
}
); }; /** * 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 (
Neues Spiel – Schritt 3/5
setPlayer3(e.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) => ( ))}
)}
); }; /** * 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 [gameType, setGameType] = useState(initialValue); const gameTypes = ['8-Ball', '9-Ball', '10-Ball']; const handleSelect = (selectedType) => { setGameType(selectedType); }; const handleSubmit = (e) => { e.preventDefault(); if (gameType) { onNext(gameType); } }; return (
Neues Spiel – Schritt 4/5
{gameTypes.map(type => ( ))}
); }; /** * Race To selection step for multi-step game creation wizard. * @param {object} props * @param {Function} props.onNext * @param {Function} props.onCancel * @param {string|number} [props.initialValue] * @param {string} [props.gameType] * @returns {import('preact').VNode} */ const RaceToStep = ({ onNext, onCancel, initialValue = '', gameType }) => { const quickPicks = [1, 2, 3, 4, 5, 6, 7, 8, 9]; const defaultValue = 5; const [raceTo, setRaceTo] = useState(initialValue !== '' ? initialValue : defaultValue); useEffect(() => { if ((initialValue === '' || initialValue === undefined) && raceTo !== defaultValue) { setRaceTo(defaultValue); } if (initialValue !== '' && initialValue !== undefined && initialValue !== raceTo) { setRaceTo(initialValue); } }, [gameType, initialValue, defaultValue]); const handleQuickPick = (value) => { setRaceTo(value); }; const handleInputChange = (e) => { setRaceTo(e.target.value); }; const handleSubmit = (e) => { e.preventDefault(); onNext(parseInt(raceTo, 10) || 0); }; return (
Neues Spiel – Schritt 5/5
{quickPicks.map(value => ( ))}
); }; export { Player1Step, Player2Step, Player3Step, GameTypeStep, RaceToStep };