import React, {useEffect, useState} from 'react';
import './App.css';
import logo from "./via-logo.svg"
import {Row} from "antd"
import socket, { emit } from "./util/socket";
import NextShot from "./components/NextShot";
import ShotsTaken from "./components/ShotsTaken";
import Feed from "./components/Feed";
import Lobby from "./components/Lobby";


const App = () => {
    const [started, setStarted] = useState(false);

    useEffect(() => {
        socket.on('started', async () => {
            setStarted(true);
            console.log('ffin started')
        });

        return () => {
            socket.off("started");
        }
    });

    const feedContent = (
        <Row>
            <NextShot/>
            <Feed/>
            <ShotsTaken/>
        </Row>
    );

    const lobbyContent = (
        <Lobby/>
    );

    const content = started ? feedContent : lobbyContent;

    return (
        <>
            <section className="content">
                {content}
            </section>
            <footer>
                <img src={logo} className="via-logo" alt="logo"/>
            </footer>
        </>
    );
};

export default App;
