import { useState } from 'react' import { useTranslation } from 'react-i18next' import { motion, AnimatePresence } from 'motion/react' import { IconConfettiFilled, IconCopyFilled, IconCircleFilled, IconPlayerPlayFilled, IconX } from '@tabler/icons-react' import { useStore } from '../store' import PartyGame from './PartyGame' export default function PartyPage() { const { t } = useTranslation() const SUB_LABELS = { wrong: t('party.subModes.wrong'), bluff: t('party.subModes.bluff'), reverse: t('party.subModes.reverse'), speed: t('party.subModes.speed'), roulette: t('party.subModes.roulette'), } const subLabelFor = (labels: Record, mode: string): string => { return labels[mode] ?? labels.wrong } const mpRoomCode = useStore(s => s.mpRoomCode) const mpPlayers = useStore(s => s.mpPlayers) const mpStarted = useStore(s => s.mpStarted) const mpMyId = useStore(s => s.mpMyId) const mpIsCreator = useStore(s => s.mpIsCreator) const mpStartGame = useStore(s => s.mpStartGame) const mpLeaveRoom = useStore(s => s.mpLeaveRoom) const partySubMode = useStore(s => s.partySubMode) const partyPhase = useStore(s => s.partyPhase) const partyScores = useStore(s => s.partyScores) const [copied, setCopied] = useState(false) const [confirmLeave, setConfirmLeave] = useState(false) const copyCode = () => { if (!mpRoomCode) return navigator.clipboard.writeText(mpRoomCode) setCopied(true) setTimeout(() => setCopied(false), 1500) } const handleLeave = () => { if (mpStarted && partyPhase !== 'finished') { setConfirmLeave(true) } else { mpLeaveRoom() } } const confirmAndLeave = () => { if (partyScores.length > 0 && partyPhase !== 'finished') { useStore.setState({ partyPhase: 'finished' }) setTimeout(() => mpLeaveRoom(), 3000) } else { mpLeaveRoom() } setConfirmLeave(false) } if (mpStarted) { return (
{mpPlayers.map(p => ( ))} {mpPlayers.length}p
{confirmLeave && ( setConfirmLeave(false)} initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} transition={{ duration: 0.15 }}> e.stopPropagation()} initial={{ opacity: 0, scale: 0.96, y: 10 }} animate={{ opacity: 1, scale: 1, y: 0 }} exit={{ opacity: 0, scale: 0.96, y: 10 }} transition={{ duration: 0.2 }}>

{mpIsCreator ? t('party.leaveEndGame') : t('party.leaveConfirm')}

)}
) } return (
) }