"use client"; import { useEffect, useState } from "react"; import { Box, Spinner, Text, VStack, Button, HStack, Badge, } from "@chakra-ui/react"; import { useRouter } from "next/navigation"; import { useRoomGetByName } from "../../../lib/apiHooks"; import MinimalHeader from "../../../components/MinimalHeader"; interface WaitPageClientProps { params: { roomName: string; eventId: string; }; } const formatDateTime = (date: string | Date) => { const d = new Date(date); return d.toLocaleString("en-US", { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit", }); }; const formatCountdown = (startTime: string | Date) => { const now = new Date(); const start = new Date(startTime); const diff = start.getTime() - now.getTime(); if (diff <= 0) return "Meeting should start now"; const minutes = Math.floor(diff / 60000); const hours = Math.floor(minutes / 60); const days = Math.floor(hours / 24); if (days > 0) return `Starts in ${days}d ${hours % 24}h ${minutes % 60}m`; if (hours > 0) return `Starts in ${hours}h ${minutes % 60}m`; return `Starts in ${minutes} minutes`; }; export default function WaitPageClient({ params }: WaitPageClientProps) { const { roomName, eventId } = params; const router = useRouter(); const [countdown, setCountdown] = useState(""); // Fetch room data const roomQuery = useRoomGetByName(roomName); const room = roomQuery.data; // Mock event data - in a real implementation, you'd fetch the actual event const mockEvent = { id: eventId, title: "Upcoming Meeting", start_time: new Date(Date.now() + 15 * 60 * 1000), // 15 minutes from now end_time: new Date(Date.now() + 75 * 60 * 1000), // 1 hour 15 minutes from now description: "Meeting will start soon", }; // Update countdown every second useEffect(() => { const timer = setInterval(() => { setCountdown(formatCountdown(mockEvent.start_time)); }, 1000); return () => clearInterval(timer); }, [mockEvent.start_time]); // Redirect to selection if room not found useEffect(() => { if (roomQuery.isError) { router.push(`/${roomName}`); } }, [roomQuery.isError, router, roomName]); const handleJoinEarly = () => { // In a real implementation, this would create a meeting and join alert("Join early functionality not yet implemented"); }; const handleBackToSelection = () => { router.push(`/${roomName}`); }; if (roomQuery.isLoading) { return ( Loading... ); } return ( {mockEvent.title} {countdown} Meeting Details {formatDateTime(mockEvent.start_time)} -{" "} {formatDateTime(mockEvent.end_time)} {mockEvent.description && ( {mockEvent.description} )} The meeting hasn't started yet. You can wait here or come back later. ); }