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 // Reset time when modal opens setTimeLeft(timeLimit) const timer = setInterval(() => { setTimeLeft(prev => { if (prev <= 1) { clearInterval(timer) handleTimeout() return 0 } return prev - 1 }) }, 1000) return () => clearInterval(timer) }, [isOpen]) // Remove timeLimit from dependencies to prevent timer reset const handleTimeout = () => { if (onSubmitPrediction && !isProcessing) { 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) // Backend formula: currentPosition + (stepValue × dice) + patternModifier const movement = fieldStepValue * diceRoll const calculatedPosition = currentPosition + movement + 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}

{/* Step-by-Step Calculation Helper */}

🧮 Számítási Adatok

{/* Visual calculation steps */}
Kezdő pozíció: {currentPosition}
Mező érték: {fieldStepValue}
Dobás: {diceRoll}
{/* Pattern Modifier Info Box */}
ℹ️

Zóna módosító szabályok:

  • 0-ra végződik (10, 20...): nincs módosító
  • 5-re végződik (15, 25...): ±3 módosító
  • 3-mal osztható (9, 12, 21...): ±2 módosító
  • Páratlan (1, 7, 11...): ±1 módosító
  • Egyéb páros: nincs módosító

A módosító előjele a mező típusától függ (+ pozitív, - negatív mező)

{/* Formula hint without answer */}

💡 Képlet: Kezdő + (Mező × Dobás) + Zóna módosító

{/* Position Input */}

✍️ Írd be a tippelt pozíciót:

setPrediction(e.target.value)} onKeyPress={(e) => e.key === 'Enter' && handleSubmit()} disabled={isProcessing} placeholder={`Pl.: ${Math.floor(currentPosition + diceRoll * 1.5)}`} 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={0} max={100} />
{/* Show entered prediction */} {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