// src/App.js
import React from 'react';

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

import Modals from "./components/Elements/Modals";

import ShareModals from "./components/Elements/Share";


import Srr from "./pages/srr";
import { Checkbox } from "@material-tailwind/react";

import ProtectedRoute from './context/ProtectedRoute';
import GuestRoute from './context/GuestRoute';
import useAuth from './context/AuthContext';
import DetailProducts from "./pages/detailproducts";

import LandingPage from './pages/landingPage';
import axios from 'axios';
import LoginPage from './pages/loginPage';
import RegisterPage from './pages/registerPage';
import ForgotPassword from './pages/forgetPassword';
import NewPassword from './pages/newpassword';
import SeeMore from './pages/customer/seemore';
import Dashboard from './pages/customer/dasboard';
import Favorid from './pages/customer/favorid';
import Cart from './pages/customer/cart';
import DetailPrice from './pages/customer/detailprice';
import Order from './pages/customer/order';
import DashboardAdmin from './pages/admin';
import ProductAdmin from './pages/Admin/ProductAdmin';
import DetailSeller from './pages/Admin/seller';
import Checkout from './pages/customer/checkout';
import AdminChat from './pages/Admin/chatadmin'; 
import LoginAdmin from './componentchat/AdminLogin';  // Import the LoginAdmin component
import AdminRegister from './componentchat/AdminRegister';
import DashboardChat from './componentchat/dashboardchat';
import CustomerChat from './componentchat/CustomerChat';
import AddUserForm from './componentchat/AddUserForm';
axios.defaults.withCredentials = true;


function App() {
    const { isAuthenticated, userRole } = useAuth();

    const router = createBrowserRouter([
        {
            path: "/",
            element: <LandingPage/>,
        },
        {
            path: "/login",
            element: (
            <GuestRoute>
            <LoginPage />
            </GuestRoute>
            ),
        },
        {
            path: "/register",
            element: <RegisterPage />,
        },
        
        {
            path: "/forget",
            element: <ForgotPassword />,
        },
        {
            path: "/newpw",
            element: <NewPassword />,
        },
        {
            path: "/seemore",
            element: <SeeMore />,
        },
        {
            path: "/home",
            element: (
            <ProtectedRoute isAuthenticated={isAuthenticated} allowedRoles={['Admin']} userRole={userRole}>
            <Dashboard />
            </ProtectedRoute>
            ),
        },
        {
            path: "/favorid",
            element: <Favorid />,
        },
        {
            path: "/AddUserForm",
            element: <AddUserForm/>
        },
        {
            path: "/CustomerChat",
            element: <CustomerChat/>
        },
        {
            path: "/cart",
            element: <Cart />,
        },
        {
            path: "/detail",
            element: <DetailPrice />,
        },
        {
            path: "/modals",
            element: <Modals />,
        },
        {
            path: "/AdminRegister",
            element: <AdminRegister />, // Add route for RegisterAdmin
        },
        {
            path: "/LoginAdmin",
            element: <LoginAdmin />, // Add route for LoginAdmin
        },
        {
            path: "/share",
            element: <ShareModals />,
        },
        {
            path: "/order",
            element: <Order />,
        },
        {
            path: "/admin",
            element: <DashboardAdmin />,
        },
        {
            path: "/ProductAdmin",
            element: <ProductAdmin />,
        },
        {
            path: "/AdminChat",
            element: <AdminChat />,
        },
        {
            path: "/Dashboardchat",
            element: <DashboardChat />,
        },
        {
            path: "/seller",
            element: <DetailSeller />,
        },
        {
            path: "/srr",
            element: <Srr />,
        },
        {
            path: "/cekot",
            element: <Checkout />,
        },
        {
            path: "/detailproducts",
            element: <DetailProducts />,
        },
    ]);
    return (
        <RouterProvider router={router} />
    );
}

export default App;
