// Modules
import { Routes, Route } from "react-router-dom";
import { useState, useMemo } from "react";
import { EventContext } from "./context/LoaderContext";

// Styles
import "./styles/style.scss";
import "react-loading-skeleton/dist/skeleton.css";

// Components
import Nav from "./components/global/Nav";
import Footer from "./components/global/Footer";
import Burger from "./components/global/Burger";

// Type
import { loaderType } from "./types/contextType";

// Pages
import Main from "./pages/Main";
import Events from "./pages/Events";
import Rating from "./pages/Rating";
import Profile from "./pages/Profile";
import EventItem from "./pages/EventItem";
import Structure from "./pages/Structure";
import Contacts from "./pages/Contact";
import AboutUs from "./pages/AboutUs";
import Tournaments from "./pages/Tournaments";
import PlayerProfile from "./pages/PlayerProfile";

const App = () => {
  // Types
  type drop = [boolean, React.Dispatch<React.SetStateAction<boolean>>];

  // State
  const [dropdownBurger, setDropdownBurger] = useState(false);
  const [dropdown, setDropdown]: drop = useState(false);
  const [burgerOpen, setBurgerOpen]: drop = useState(false);
  const [eventData, setEventData]: loaderType = useState(null);

  // Stack state into Memo
  const loaderValue = useMemo(
    () => ({ eventData, setEventData }),
    [eventData, setEventData]
  );

  return (
    <EventContext.Provider value={loaderValue}>
      <div className="App">
        <Nav
          dropdown={dropdown}
          setDropdown={setDropdown}
          burgerOpen={burgerOpen}
          setBurgerOpen={setBurgerOpen}
        />
        <Burger
          burgerOpen={burgerOpen}
          setBurgerOpen={setBurgerOpen}
          dropdownBurger={dropdownBurger}
          setDropdownBurger={setDropdownBurger}
        />
        <div className="inner-body">
          <Routes>
            <Route path="/" element={<Main />} />
            <Route path="/news" element={<Events />} />
            <Route path="/rating" element={<Rating />} />
            <Route path="/profile" element={<Profile />} />
            <Route path="/event/:eventId" element={<EventItem />} />
            <Route path="/structure" element={<Structure />} />
            <Route path="/contact" element={<Contacts />} />
            <Route path="/about-us" element={<AboutUs />} />
            <Route path="/tournaments" element={<Tournaments />} />
            <Route path="/player/:playerId" element={<PlayerProfile />} />
          </Routes>
        </div>
        <Footer
          burgerOpen={burgerOpen}
          setBurgerOpen={setBurgerOpen}
          dropdown={dropdown}
          setDropdown={setDropdown}
          dropdownBurger={dropdownBurger}
          setDropdownBurger={setDropdownBurger}
        />
      </div>
    </EventContext.Provider>
  );
};

export default App;
