import React, { lazy } from "react";
import { Outlet, RouterProvider, createBrowserRouter } from "react-router-dom";

import { ErrorBoundary } from "../components/ErrorBoundary";
import Dashboard from "./Dashboard";

const Layout: React.FC = () => {
  return (
    <ErrorBoundary>
      <Outlet />
    </ErrorBoundary>
  );
};

const NotFound = lazy(() => import("./NotFound"));

const router = createBrowserRouter([
  {
    path: "/",
    element: <Layout />,
    children: [
      {
        index: true,
        element: <Dashboard />,
      },
      {
        path: "*",
        element: <NotFound />,
      },
    ],
  },
]);

const Router = (): JSX.Element => {
  return <RouterProvider router={router} />;
};

export default Router;
