import React from "react";
import { BrowserRouter as Router, Route, Routes, Navigate } from "react-router-dom";
import { Layout } from "antd";
import LoginPage from "./components/Auth/LoginPage";
import ResetPasswordRequest from "./components/Auth/ResetPasswordRequest";
import AdminDashboard from "./pages/AdminDashboard";
import EmployeeDashboard from "./pages/EmployeeDashboard";
import CustomerList from "./components/customer/CustomerList";
import AddCustomer from "./components/customer/AddCustomer";
import Sidebar from "./components/sidebar/Sidebar";
import CustomerMeasurements from "./components/customer/CustomerMeasurements";
import { AuthProvider, AuthContext } from "./contexts/AuthContext";
import EmployeeList from "./components/admin/EmployeeList";
import AddEmployee from "./components/admin/AddEmployee";
import EmployeeProfile from "./components/admin/EmployeeProfile";
import { Refine } from "@refinedev/core";
import { RefineKbarProvider } from "@refinedev/kbar";
import { ToastContainer, toast } from "react-toastify"; 
import 'react-toastify/dist/ReactToastify.css'; 

const { Content } = Layout;

const App = () => {
  const { user } = { name: "Suraj" }; // useContext(AuthContext);

  return (
    <Router>
      <RefineKbarProvider>
        <Refine>
          <AuthProvider>
            <div className="min-h-screen flex w-full">
              <Content className="flex-1 text-white">
                <Routes>
                  <Route exact path="/" element={<LoginPage />} />
                  <Route path="/reset-password" element={<ResetPasswordRequest />} />
                  <Route path="/employee/home" element={<EmployeeDashboard />} />
                  <Route path="/admin" element={<PrivateRoute><AdminDashboard /></PrivateRoute>} />
                  <Route path="/employee" element={<PrivateRoute><EmployeeDashboard /></PrivateRoute>} />
                  <Route path="/customers" element={<PrivateRoute><CustomerList /></PrivateRoute>} />
                  <Route path="/add-customer" element={<PrivateRoute><AddCustomer /></PrivateRoute>} />
                  <Route path="/employee/create-order" element={<CustomerList />} />
                  <Route path="/measurements" element={<CustomerMeasurements />} />
                  <Route path="/employees" element={<PrivateRoute><EmployeeList /></PrivateRoute>} />
                  <Route path="/add-employee" element={<PrivateRoute><AddEmployee /></PrivateRoute>} />
                  <Route path="/employee-profile" element={<PrivateRoute><EmployeeProfile /></PrivateRoute>} />
                </Routes>
              </Content>
            </div>
          </AuthProvider>
        </Refine>
      </RefineKbarProvider>
      <ToastContainer /> {/* Added ToastContainer for displaying notifications */}
    </Router>
  );
};

const PrivateRoute = ({ children }) => {
  // const { user } = useContext(AuthContext);

  // if (!user) {
  //   return <Navigate to="/" />;
  // }

  return children;
};

export default App;
