"use client";
import { useState } from "react";
import type { Room } from "../api/rooms/route";
type LobbyScreenProps = {
room: Room;
playerId: string;
error: string | null;
setError: (v: string | null) => void;
loading: boolean;
onLeave: () => void;
onStart: () => void;
onReset: () => void;
maxPlayers: number;
setMaxPlayers: (v: number) => void;
totalRounds: number;
setTotalRounds: (v: number) => void;
gameMode: Room["gameMode"];
setGameMode: (v: Room["gameMode"]) => void;
onSetGameMode: (v: Room["gameMode"]) => void;
onSetTotalRounds: (v: number) => void;
onSetSearchAllowed: (v: boolean) => void;
onSetTimeLimit: (v: number) => void;
};
export function LobbyScreen({
room,
playerId,
error,
setError,
loading,
onLeave,
onStart,
onReset,
maxPlayers,
setMaxPlayers,
totalRounds,
setTotalRounds,
gameMode,
setGameMode,
onSetGameMode,
onSetTotalRounds,
onSetSearchAllowed,
onSetTimeLimit,
}: LobbyScreenProps) {
const isHost = room.players.find((p) => p.id === playerId)?.isHost ?? false;
const [copied, setCopied] = useState(false);
const [blurred, setBlurred] = useState(true);
function copyCode() {
navigator.clipboard.writeText(room.code).then(() => {
setCopied(true);
setTimeout(() => setCopied(false), 2000);
});
}
const btnGhost =
"w-full min-h-11 px-5 rounded-xl text-sm font-semibold bg-[#242424] border border-[#2e2e2e] text-[#f0f0f0] hover:bg-[#1a1a1a] cursor-pointer transition-colors";
const btnPrimary =
"w-full min-h-11 px-5 rounded-xl text-sm font-semibold bg-[#7c3aed] text-white hover:bg-[#6d28d9] disabled:opacity-50 cursor-pointer transition-colors";
return (
{/* Code */}
Code de la salle
{copied ? "Copié !" : "Clique pour copier"}
{error && (
{error}
)}
{/* Players */}
Joueurs ({room.players.length}/{room.maxPlayers})
{room.players.map((p) => (
-
{p.name}
{p.isHost && (
Hôte
)}
{p.id === playerId && (
Toi
)}
{p.score} pts
))}
{isHost && (
Paramètres
Mode de jeu
Joueurs max
Manches
Temps par manche
)}
{!isHost && (
🔍 Recherche Ctrl+F
{room.searchAllowed ? "Autorisée" : "Bloquée"}
)}
{room.round > 0 && (
Manche {room.round} terminée
)}
{isHost ? (
{room.round > 0 && (
)}
) : (
En attente que l'hôte démarre...
)}
);
}