import React from 'react'
import ReactDOM from 'react-dom/client'
import { createBrowserRouter, Navigate, RouterProvider } from 'react-router-dom'
import Products from "./routes/products/products";
import Product from "./routes/products/product";
import Companies from "./routes/companies/companies";
import Layout from "./components/layout";
import { loader, productLoader } from "./clients/loaders"; 
import './index.css';

const routes = [
  {
    path: '/products',
    loader: loader,
    element: <Products/>
  },
  {
    path: "products/:productId",
    loader: productLoader,
    element: <Product/>
  },
  {
    path: "/companies",
    loader: loader,
    element: <Companies/>
  },
  {
    path: '/',
    element: <Navigate to='/products'/>
  }
];

const router = createBrowserRouter(routes);

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
  <React.StrictMode>
    <Layout>
      <RouterProvider router={router}/>
    </Layout>
  </React.StrictMode>
)