import Layout from "./Layout.jsx";

import Dashboard from "./Dashboard";

import StaffDirectory from "./StaffDirectory";

import AddStaff from "./AddStaff";

import EditStaff from "./EditStaff";

import Events from "./Events";

import CreateEvent from "./CreateEvent";

import EditEvent from "./EditEvent";

import EventDetail from "./EventDetail";

import Business from "./Business";

import Invoices from "./Invoices";

import Payroll from "./Payroll";

import Certification from "./Certification";

import Support from "./Support";

import Reports from "./Reports";

import Settings from "./Settings";

import ActivityLog from "./ActivityLog";

import AddBusiness from "./AddBusiness";

import EditBusiness from "./EditBusiness";

import ProcurementDashboard from "./ProcurementDashboard";

import OperatorDashboard from "./OperatorDashboard";

import VendorDashboard from "./VendorDashboard";

import WorkforceDashboard from "./WorkforceDashboard";

import Messages from "./Messages";

import ClientDashboard from "./ClientDashboard";

import Onboarding from "./Onboarding";

import ClientOrders from "./ClientOrders";

import ClientInvoices from "./ClientInvoices";

import VendorOrders from "./VendorOrders";

import VendorStaff from "./VendorStaff";

import VendorInvoices from "./VendorInvoices";

import VendorPerformance from "./VendorPerformance";

import WorkforceShifts from "./WorkforceShifts";

import WorkforceEarnings from "./WorkforceEarnings";

import WorkforceProfile from "./WorkforceProfile";

import UserManagement from "./UserManagement";

import Home from "./Home";

import VendorRateCard from "./VendorRateCard";

import Permissions from "./Permissions";

import WorkforceCompliance from "./WorkforceCompliance";

import Teams from "./Teams";

import CreateTeam from "./CreateTeam";

import TeamDetails from "./TeamDetails";

import VendorManagement from "./VendorManagement";

import PartnerManagement from "./PartnerManagement";

import EnterpriseManagement from "./EnterpriseManagement";

import VendorOnboarding from "./VendorOnboarding";

import SectorManagement from "./SectorManagement";

import AddEnterprise from "./AddEnterprise";

import AddSector from "./AddSector";

import AddPartner from "./AddPartner";

import EditVendor from "./EditVendor";

import SmartVendorOnboarding from "./SmartVendorOnboarding";

import InviteVendor from "./InviteVendor";

import VendorCompliance from "./VendorCompliance";

import EditPartner from "./EditPartner";

import EditSector from "./EditSector";

import EditEnterprise from "./EditEnterprise";

import VendorRates from "./VendorRates";

import VendorDocumentReview from "./VendorDocumentReview";

import VendorMarketplace from "./VendorMarketplace";

import RapidOrder from "./RapidOrder";

import SmartScheduler from "./SmartScheduler";

import StaffOnboarding from "./StaffOnboarding";

import NotificationSettings from "./NotificationSettings";

import TaskBoard from "./TaskBoard";

import { BrowserRouter as Router, Route, Routes, useLocation } from 'react-router-dom';

const PAGES = {
    
    Dashboard: Dashboard,
    
    StaffDirectory: StaffDirectory,
    
    AddStaff: AddStaff,
    
    EditStaff: EditStaff,
    
    Events: Events,
    
    CreateEvent: CreateEvent,
    
    EditEvent: EditEvent,
    
    EventDetail: EventDetail,
    
    Business: Business,
    
    Invoices: Invoices,
    
    Payroll: Payroll,
    
    Certification: Certification,
    
    Support: Support,
    
    Reports: Reports,
    
    Settings: Settings,
    
    ActivityLog: ActivityLog,
    
    AddBusiness: AddBusiness,
    
    EditBusiness: EditBusiness,
    
    ProcurementDashboard: ProcurementDashboard,
    
    OperatorDashboard: OperatorDashboard,
    
    VendorDashboard: VendorDashboard,
    
    WorkforceDashboard: WorkforceDashboard,
    
    Messages: Messages,
    
    ClientDashboard: ClientDashboard,
    
    Onboarding: Onboarding,
    
    ClientOrders: ClientOrders,
    
    ClientInvoices: ClientInvoices,
    
    VendorOrders: VendorOrders,
    
    VendorStaff: VendorStaff,
    
    VendorInvoices: VendorInvoices,
    
    VendorPerformance: VendorPerformance,
    
    WorkforceShifts: WorkforceShifts,
    
    WorkforceEarnings: WorkforceEarnings,
    
    WorkforceProfile: WorkforceProfile,
    
    UserManagement: UserManagement,
    
    Home: Home,
    
    VendorRateCard: VendorRateCard,
    
    Permissions: Permissions,
    
    WorkforceCompliance: WorkforceCompliance,
    
    Teams: Teams,
    
    CreateTeam: CreateTeam,
    
    TeamDetails: TeamDetails,
    
    VendorManagement: VendorManagement,
    
    PartnerManagement: PartnerManagement,
    
    EnterpriseManagement: EnterpriseManagement,
    
    VendorOnboarding: VendorOnboarding,
    
    SectorManagement: SectorManagement,
    
    AddEnterprise: AddEnterprise,
    
    AddSector: AddSector,
    
    AddPartner: AddPartner,
    
    EditVendor: EditVendor,
    
    SmartVendorOnboarding: SmartVendorOnboarding,
    
    InviteVendor: InviteVendor,
    
    VendorCompliance: VendorCompliance,
    
    EditPartner: EditPartner,
    
    EditSector: EditSector,
    
    EditEnterprise: EditEnterprise,
    
    VendorRates: VendorRates,
    
    VendorDocumentReview: VendorDocumentReview,
    
    VendorMarketplace: VendorMarketplace,
    
    RapidOrder: RapidOrder,
    
    SmartScheduler: SmartScheduler,
    
    StaffOnboarding: StaffOnboarding,
    
    NotificationSettings: NotificationSettings,
    
    TaskBoard: TaskBoard,
    
}

function _getCurrentPage(url) {
    if (url.endsWith('/')) {
        url = url.slice(0, -1);
    }
    let urlLastPart = url.split('/').pop();
    if (urlLastPart.includes('?')) {
        urlLastPart = urlLastPart.split('?')[0];
    }

    const pageName = Object.keys(PAGES).find(page => page.toLowerCase() === urlLastPart.toLowerCase());
    return pageName || Object.keys(PAGES)[0];
}

// Create a wrapper component that uses useLocation inside the Router context
function PagesContent() {
    const location = useLocation();
    const currentPage = _getCurrentPage(location.pathname);
    
    return (
        <Layout currentPageName={currentPage}>
            <Routes>            
                
                    <Route path="/" element={<Dashboard />} />
                
                
                <Route path="/Dashboard" element={<Dashboard />} />
                
                <Route path="/StaffDirectory" element={<StaffDirectory />} />
                
                <Route path="/AddStaff" element={<AddStaff />} />
                
                <Route path="/EditStaff" element={<EditStaff />} />
                
                <Route path="/Events" element={<Events />} />
                
                <Route path="/CreateEvent" element={<CreateEvent />} />
                
                <Route path="/EditEvent" element={<EditEvent />} />
                
                <Route path="/EventDetail" element={<EventDetail />} />
                
                <Route path="/Business" element={<Business />} />
                
                <Route path="/Invoices" element={<Invoices />} />
                
                <Route path="/Payroll" element={<Payroll />} />
                
                <Route path="/Certification" element={<Certification />} />
                
                <Route path="/Support" element={<Support />} />
                
                <Route path="/Reports" element={<Reports />} />
                
                <Route path="/Settings" element={<Settings />} />
                
                <Route path="/ActivityLog" element={<ActivityLog />} />
                
                <Route path="/AddBusiness" element={<AddBusiness />} />
                
                <Route path="/EditBusiness" element={<EditBusiness />} />
                
                <Route path="/ProcurementDashboard" element={<ProcurementDashboard />} />
                
                <Route path="/OperatorDashboard" element={<OperatorDashboard />} />
                
                <Route path="/VendorDashboard" element={<VendorDashboard />} />
                
                <Route path="/WorkforceDashboard" element={<WorkforceDashboard />} />
                
                <Route path="/Messages" element={<Messages />} />
                
                <Route path="/ClientDashboard" element={<ClientDashboard />} />
                
                <Route path="/Onboarding" element={<Onboarding />} />
                
                <Route path="/ClientOrders" element={<ClientOrders />} />
                
                <Route path="/ClientInvoices" element={<ClientInvoices />} />
                
                <Route path="/VendorOrders" element={<VendorOrders />} />
                
                <Route path="/VendorStaff" element={<VendorStaff />} />
                
                <Route path="/VendorInvoices" element={<VendorInvoices />} />
                
                <Route path="/VendorPerformance" element={<VendorPerformance />} />
                
                <Route path="/WorkforceShifts" element={<WorkforceShifts />} />
                
                <Route path="/WorkforceEarnings" element={<WorkforceEarnings />} />
                
                <Route path="/WorkforceProfile" element={<WorkforceProfile />} />
                
                <Route path="/UserManagement" element={<UserManagement />} />
                
                <Route path="/Home" element={<Home />} />
                
                <Route path="/VendorRateCard" element={<VendorRateCard />} />
                
                <Route path="/Permissions" element={<Permissions />} />
                
                <Route path="/WorkforceCompliance" element={<WorkforceCompliance />} />
                
                <Route path="/Teams" element={<Teams />} />
                
                <Route path="/CreateTeam" element={<CreateTeam />} />
                
                <Route path="/TeamDetails" element={<TeamDetails />} />
                
                <Route path="/VendorManagement" element={<VendorManagement />} />
                
                <Route path="/PartnerManagement" element={<PartnerManagement />} />
                
                <Route path="/EnterpriseManagement" element={<EnterpriseManagement />} />
                
                <Route path="/VendorOnboarding" element={<VendorOnboarding />} />
                
                <Route path="/SectorManagement" element={<SectorManagement />} />
                
                <Route path="/AddEnterprise" element={<AddEnterprise />} />
                
                <Route path="/AddSector" element={<AddSector />} />
                
                <Route path="/AddPartner" element={<AddPartner />} />
                
                <Route path="/EditVendor" element={<EditVendor />} />
                
                <Route path="/SmartVendorOnboarding" element={<SmartVendorOnboarding />} />
                
                <Route path="/InviteVendor" element={<InviteVendor />} />
                
                <Route path="/VendorCompliance" element={<VendorCompliance />} />
                
                <Route path="/EditPartner" element={<EditPartner />} />
                
                <Route path="/EditSector" element={<EditSector />} />
                
                <Route path="/EditEnterprise" element={<EditEnterprise />} />
                
                <Route path="/VendorRates" element={<VendorRates />} />
                
                <Route path="/VendorDocumentReview" element={<VendorDocumentReview />} />
                
                <Route path="/VendorMarketplace" element={<VendorMarketplace />} />
                
                <Route path="/RapidOrder" element={<RapidOrder />} />
                
                <Route path="/SmartScheduler" element={<SmartScheduler />} />
                
                <Route path="/StaffOnboarding" element={<StaffOnboarding />} />
                
                <Route path="/NotificationSettings" element={<NotificationSettings />} />
                
                <Route path="/TaskBoard" element={<TaskBoard />} />
                
            </Routes>
        </Layout>
    );
}

export default function Pages() {
    return (
        <Router>
            <PagesContent />
        </Router>
    );
}