import { useState } from "react"; import { motion } from "framer-motion"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { useTranslation } from "@/hooks/useTranslation"; import { RoundHeader } from "./sentence-builder/RoundHeader"; import { WordDisplay } from "./sentence-builder/WordDisplay"; import { SentenceDisplay } from "./sentence-builder/SentenceDisplay"; import { InputForm } from "./sentence-builder/InputForm"; import { Button } from "@/components/ui/button"; interface SentenceBuilderProps { currentWord: string; successfulRounds: number; sentence: string[]; playerInput: string; isAiThinking: boolean; onInputChange: (value: string) => void; onSubmitWord: (e: React.FormEvent) => void; onMakeGuess: () => void; normalizeWord: (word: string) => string; onBack?: () => void; onClose: () => void; } export const SentenceBuilder = ({ currentWord, successfulRounds, sentence, playerInput, isAiThinking, onInputChange, onSubmitWord, onMakeGuess, normalizeWord, onBack, onClose, }: SentenceBuilderProps) => { const [showConfirmDialog, setShowConfirmDialog] = useState(false); const [hasMultipleWords, setHasMultipleWords] = useState(false); const [containsTargetWord, setContainsTargetWord] = useState(false); const [isTooLong, setIsTooLong] = useState(false); const t = useTranslation(); console.log("SentenceBuilder - Rendering with showConfirmDialog:", showConfirmDialog); const validateInput = (input: string) => { setHasMultipleWords(input.trim().split(/\s+/).length > 1); setContainsTargetWord( normalizeWord(input).includes(normalizeWord(currentWord)) ); setIsTooLong(input.trim().length >= 30); }; const handleInputChange = (value: string) => { validateInput(value); onInputChange(value); }; const handleSetShowConfirmDialog = (show: boolean) => { console.log("SentenceBuilder - Setting showConfirmDialog to:", show); setShowConfirmDialog(show); }; const isValidInput = !playerInput || /^[\p{L} ]+$/u.test(playerInput); return ( {t.game.leaveGameTitle} {t.game.leaveGameDescription} setShowConfirmDialog(false)}> {t.game.cancel} {t.game.confirm} ); };