import React, { useState, useEffect } from "react" import { motion, AnimatePresence } from "framer-motion" /** * StepPredictionModal - Pozíció tippelés (Position Guessing) * * A dokumentáció szerint: A játékosnak meg kell tippelnie a VÉGLEGES POZÍCIÓT, * nem a lépésszámot! * * Számítás: finalPosition = currentPosition + diceRoll + fieldStepValue + patternModifier * * @param {Object} props * @param {boolean} props.isOpen - Modal megjelenítése * @param {Function} props.onClose - Modal bezárása * @param {Function} props.onSubmitPrediction - Tipp beküldése * @param {number} props.currentPosition - Jelenlegi pozíció * @param {number} props.diceRoll - Dobás értéke * @param {number} props.fieldStepValue - Mező lépés értéke * @param {number} props.patternModifier - Zóna alapú módosító * @param {string} props.cardText - Kártya szövege * @param {Array} props.hints - Segédletek tömbje * @param {number} props.timeLimit - Időkorlát másodpercben (default: 30) */ const StepPredictionModal = ({ isOpen, onClose, onSubmitPrediction, currentPosition = 0, diceRoll = 0, fieldStepValue = 0, patternModifier = 0, cardText = "Tippeld meg, melyik pozícióra fogsz lépni!", hints = [], timeLimit = 30 }) => { const [prediction, setPrediction] = useState("") const [showHints, setShowHints] = useState(false) const [isProcessing, setIsProcessing] = useState(false) const [timeLeft, setTimeLeft] = useState(timeLimit) // Timer countdown useEffect(() => { if (!isOpen) return setTimeLeft(timeLimit) const timer = setInterval(() => { setTimeLeft(prev => { if (prev <= 1) { clearInterval(timer) handleTimeout() return 0 } return prev - 1 }) }, 1000) return () => clearInterval(timer) }, [isOpen, timeLimit]) const handleTimeout = () => { if (onSubmitPrediction) { onSubmitPrediction(null) // null = timeout } } const handleSubmit = async () => { if (!prediction || prediction === "" || isProcessing) return const guessedPosition = parseInt(prediction) if (isNaN(guessedPosition)) return setIsProcessing(true) try { await onSubmitPrediction(guessedPosition) } catch (error) { console.error("Tipp küldési hiba:", error) setIsProcessing(false) } } // Reset amikor megnyílik useEffect(() => { if (isOpen) { setPrediction("") setShowHints(false) setIsProcessing(false) } }, [isOpen]) // Számított végső pozíció (helyes válasz) const calculatedPosition = currentPosition + diceRoll + fieldStepValue + patternModifier const formatTime = (seconds) => { return `0:${seconds.toString().padStart(2, '0')}` } const getTimeColor = () => { if (timeLeft > 15) return "text-green-400" if (timeLeft > 5) return "text-yellow-400" return "text-red-400 animate-pulse" } if (!isOpen) return null return ( {isOpen && (
{/* Backdrop */} {/* Modal Content */} {/* Header */}
🎯

Pozíció Tippelés

Melyik pozícióra lépsz?

{/* Timer */}
⏱️ {formatTime(timeLeft)}
{/* Content */}
{/* Card Text / Instructions */}
📝

{cardText}

{/* Calculation Info */}

📊 Számítási Adatok

Jelenlegi pozíció

{currentPosition}

Dobás (kocka)

+{diceRoll}

Mező lépés

+{fieldStepValue}

Zóna módosító

= 0 ? 'text-green-400' : 'text-red-400'}`}> {patternModifier >= 0 ? '+' : ''}{patternModifier}

Számítsd ki: {currentPosition} + {diceRoll} + {fieldStepValue} {patternModifier >= 0 ? '+' : ''} {patternModifier} = ?

{/* Position Input */}

Írd be a tippelt pozíciót:

setPrediction(e.target.value)} onKeyPress={(e) => e.key === 'Enter' && handleSubmit()} disabled={isProcessing} placeholder="Pl: 28" className="w-full bg-gray-800 border-2 border-yellow-600 rounded-xl px-4 py-3 text-white text-center text-2xl font-bold focus:border-yellow-400 focus:outline-none disabled:opacity-50" min={currentPosition} max={100} />
{/* Prediction Info */} {prediction && prediction !== "" && (

A tipped: {prediction} pozíció

)} {/* Hints Section */} {hints && hints.length > 0 && (
{showHints && ( {hints.map((hint, index) => (

#{index + 1}: {hint}

))}
)}
)} {/* Risk/Reward Info */}

Ha eltalálod

Lépsz az új pozícióra!

Ha nem találod el

-2 büntetés + nem lépsz!

{/* Submit Button */} {/* Warning */} {(!prediction || prediction === "") && (

⚠️ Írd be a tippelt pozíciót a beküldéshez!

)}
)} ) } export default StepPredictionModal