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 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: '/',
    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>
)