import React, { ReactNode } from "react";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import MainPage from "./MainPage";
import {
  StorePrototype,
  getLocalToken,
  loadLanguage,
  store,
} from "../config/store";
import DashboardPage from "./DashboardPage";
import PropTypes from "prop-types";
import { useSelector } from "react-redux";
import NotFoundPage from "./NotFoundPage";

const AppRoutes = ({ children }: { children: ReactNode }) => {
  store.dispatch(getLocalToken());
  store.dispatch(loadLanguage());

  return (
    <BrowserRouter>
      {children}
      <Routes>
        <Route path="/" element={<MainPage />} />
        <Route path="/dashboard" element={<DashboardPage />} />
        <Route path="*" element={<NotFoundPage />} />
      </Routes>
    </BrowserRouter>
  );
};
AppRoutes.propTypes = {
  children: PropTypes.node,
};
export default AppRoutes;
