import React, {MouseEvent, useState} from 'react';
import {Button, Card, Col, Divider, Form, Input, InputNumber, Row, Select} from "antd"
import {red} from '@ant-design/colors';
import connection, {useConfig, useIsConnected, useRoom} from "../lib/Connection";
import "../css/lobby.sass";
import beer from "../img/beer.png"
import {RoomOptions} from "../types/types";
const {Option} = Select;
const Lobby = (props: any) => {
// Form/control states.
const [selectedRoomId, setSelectedRoomId] = useState(1);
const [seekTime, setSeekTime] = useState(0);
const [timelineName, setTimelineName] = useState(null);
const [joiningLobby, setJoiningLobby] = useState(false);
const [joinLobbyError, setJoinLobbyError] = useState(false);
// Room and logic states.
const isConnected = useIsConnected();
const room = useRoom();
const config = useConfig();
// @ts-ignore
const connectionType = connection.socket.io.engine.transport.name;
let isLeader = room?.isLeader || false;
let userCount = room?.userCount || 0;
function handleRequestStartClicked(e: MouseEvent) {
connection.requestStart(seekTime * 1000);
}
function handleJoin(e: MouseEvent) {
connection.requestReady();
}
function applyRoomId(v: number) {
connection.requestJoin(v).then(v => {
setJoiningLobby(false);
setJoinLobbyError(!v);
})
setJoiningLobby(true)
}
function handleJoinRandomLobby() {
connection.requestJoinRandom()
setJoinLobbyError(false);
}
function handleTimelineNameSet(timelineName: any) {
setTimelineName(timelineName);
connection.setRoomOptions(new RoomOptions(
seekTime || 0,
timelineName || room?.timelineName || ''))
}
function handleSetSeekTime(seekTime: number) {
setSeekTime(seekTime);
connection.setRoomOptions(new RoomOptions(
seekTime * 1000 || 0,
timelineName || room?.timelineName || ''))
}
let leaderConfig = (
We gaan luisteren naar {room && room.timelineName} en
{room?.running && zijn al gestart!}
{!room?.running && starten op {(room?.seekTime || 0) / 1000} seconden}
Er is één gebruiker aanwezig.
:Er zijn {userCount} gebruikers aanwezig.
} } {room && Deel de link met je vrienden om mee te doen! }