import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom'
import { Toaster } from 'sonner'
import { AuthProvider } from '@/contexts/AuthContext'
import { ProtectedRoute } from '@/components/ProtectedRoute'
import { Layout } from '@/components/Layout'
import { LoginPage } from '@/pages/LoginPage'
import { UserDashboardPage } from '@/pages/UserDashboardPage'
import { InboxPage } from '@/pages/InboxPage'
import { SuppliersPage } from '@/pages/master/SuppliersPage'
import { ProjectsPage } from '@/pages/master/ProjectsPage'
import { DepartmentsPage } from '@/pages/master/DepartmentsPage'
import { CatalogsPage } from '@/pages/master/CatalogsPage'
import { ContractCreatePage } from '@/pages/contracts/ContractCreatePage'
import { ContractDetailPage } from '@/pages/contracts/ContractDetailPage'
import { MyContractsPage } from '@/pages/contracts/MyContractsPage'
import { PurchaseEvaluationsListPage, PurchaseEvaluationDetailPage } from '@/pages/pe/PurchaseEvaluationsListPage'
import { PurchaseEvaluationCreatePage } from '@/pages/pe/PurchaseEvaluationCreatePage'
import { PurchaseEvaluationWorkspacePage } from '@/pages/pe/PurchaseEvaluationWorkspacePage'
import { WorkflowMatrixViewPage } from '@/pages/pe/WorkflowMatrixViewPage'
import { EmployeesListPage } from '@/pages/hrm/EmployeesListPage'
import { EmployeeCreatePage } from '@/pages/hrm/EmployeeCreatePage'
import { HrmConfigsPage } from '@/pages/hrm/HrmConfigsPage'
import { InternalDirectoryPage } from '@/pages/office/InternalDirectoryPage'
import { MeetingCalendarPage } from '@/pages/office/MeetingCalendarPage'
import { MeetingRoomsPage } from '@/pages/office/MeetingRoomsPage'
import { ProposalCreatePage } from '@/pages/office/ProposalCreatePage'
import { ProposalDetailPage } from '@/pages/office/ProposalDetailPage'
import { ProposalsListPage } from '@/pages/office/ProposalsListPage'
import { WorkflowAppsListPage } from '@/pages/office/WorkflowAppsListPage'
import { WorkflowAppDetailPage } from '@/pages/office/WorkflowAppDetailPage'
import { ItTicketsPage } from '@/pages/office/ItTicketsPage'
import { MyAttendancePage } from '@/pages/office/MyAttendancePage'
import { OfficeDashboardPage } from '@/pages/office/OfficeDashboardPage'
import { HrmDashboardPage } from '@/pages/hrm/HrmDashboardPage'

function App() {
  return (
    <BrowserRouter>
      <AuthProvider>
        <Routes>
          <Route path="/login" element={<LoginPage />} />
          <Route
            element={
              <ProtectedRoute>
                <Layout />
              </ProtectedRoute>
            }
          >
            <Route path="/dashboard" element={<UserDashboardPage />} />
            <Route path="/inbox" element={<InboxPage />} />
            <Route path="/master/suppliers" element={<SuppliersPage />} />
            <Route path="/master/projects" element={<ProjectsPage />} />
            <Route path="/master/departments" element={<DepartmentsPage />} />
            <Route path="/master/catalogs" element={<Navigate to="/master/catalogs/units" replace />} />
            <Route path="/master/catalogs/:kind" element={<CatalogsPage />} />
            <Route path="/contracts/new" element={<ContractCreatePage />} />
            <Route path="/contracts/:id" element={<ContractDetailPage />} />
            <Route path="/my-contracts" element={<MyContractsPage />} />
            <Route path="/purchase-evaluations" element={<PurchaseEvaluationsListPage />} />
            <Route path="/purchase-evaluations/workflow-matrix" element={<WorkflowMatrixViewPage />} />
            <Route path="/purchase-evaluations/workspace" element={<PurchaseEvaluationWorkspacePage />} />
            <Route path="/purchase-evaluations/new" element={<PurchaseEvaluationCreatePage />} />
            <Route path="/purchase-evaluations/:id" element={<PurchaseEvaluationDetailPage />} />
            {/* Hồ sơ Nhân sự (Phase 10.1 G-H1 — Mig 34) */}
            <Route path="/employees" element={<EmployeesListPage />} />
            <Route path="/employees/new" element={<EmployeeCreatePage />} />
            {/* Cấu hình HRM (Phase 10.2 G-H2 — Mig 35) */}
            <Route path="/hrm/configs" element={<Navigate to="/hrm/configs/leave-types" replace />} />
            <Route path="/hrm/configs/:kind" element={<HrmConfigsPage />} />
            {/* Văn phòng số — Bảng điều khiển (landing dashboard, Off_Dashboard) */}
            <Route path="/office/dashboard" element={<OfficeDashboardPage />} />
            {/* Văn phòng số — Danh bạ nội bộ (Phase 10.2 G-O1) */}
            <Route path="/directory" element={<InternalDirectoryPage />} />
            {/* Văn phòng số — Phòng họp Booking + Catalog (Phase 10.2 G-O2 — Mig 36 S36) */}
            <Route path="/meeting-calendar" element={<MeetingCalendarPage />} />
            <Route path="/meeting-rooms" element={<MeetingRoomsPage />} />
            <Route path="/proposals" element={<ProposalsListPage />} />
            <Route path="/proposals/new" element={<ProposalCreatePage />} />
            <Route path="/proposals/:id" element={<ProposalDetailPage />} />
            <Route path="/workflow-apps/:kind" element={<WorkflowAppsListPage />} />
            <Route path="/workflow-apps/:kind/:id" element={<WorkflowAppDetailPage />} />
            <Route path="/it-tickets" element={<ItTicketsPage />} />
            <Route path="/attendance" element={<MyAttendancePage />} />
            <Route path="/hr/dashboard" element={<HrmDashboardPage />} />
            <Route path="/" element={<Navigate to="/dashboard" replace />} />
            <Route
              path="*"
              element={
                <div className="p-8 text-slate-500">
                  Trang này chưa được build.
                </div>
              }
            />
          </Route>
        </Routes>
        <Toaster richColors position="top-right" />
      </AuthProvider>
    </BrowserRouter>
  )
}

export default App
