
import React from 'react';
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import { Helmet } from 'react-helmet';
import { Toaster } from '@/components/ui/toaster';
import { ThemeProvider } from '@/contexts/ThemeContext';
import AppLayout from '@/components/layout/AppLayout';

// Dashboard
import DashboardPage from '@/pages/DashboardPage';

// CRM
import ProspectsPage from '@/pages/crm/ProspectsPage';
import CreateProspectPage from '@/pages/crm/CreateProspectPage';
import ProspectDetailPage from '@/pages/crm/ProspectDetailPage';
import ClientsPage from '@/pages/crm/ClientsPage';
import ClientDetailPage from '@/pages/crm/ClientDetailPage';
import SuppliersPage from '@/pages/crm/SuppliersPage';
import OpportunitiesPipelinePage from '@/pages/crm/OpportunitiesPipelinePage';
import OpportunityDetailPage from '@/pages/crm/OpportunityDetailPage';
import ActivitiesPage from '@/pages/crm/ActivitiesPage';
import TasksPage from '@/pages/crm/TasksPage';

// Tiers (Articles & Families)
import ArticlesPage from '@/pages/tiers/ArticlesPage';
import ArticleDetailPage from '@/pages/tiers/ArticleDetailPage';
import ProductFamiliesPage from '@/pages/tiers/ProductFamiliesPage';
import ProductFamilyDetailPage from '@/pages/tiers/ProductFamilyDetailPage';

// Sales
import QuotesPage from '@/pages/sales/QuotesPage';
import QuoteDetailPage from '@/pages/sales/QuoteDetailPage';
import OrdersPage from '@/pages/sales/OrdersPage';
import OrderDetailPage from '@/pages/sales/OrderDetailPage';
import DeliveryNotesPage from '@/pages/sales/DeliveryNotesPage';
import InvoicesPage from '@/pages/sales/InvoicesPage';
import InvoiceDetailPage from '@/pages/sales/InvoiceDetailPage';
import CreditNotesPage from '@/pages/sales/CreditNotesPage';

// Purchases
import PurchaseOrdersPage from '@/pages/purchases/PurchaseOrdersPage';
import PurchaseOrderDetailPage from '@/pages/purchases/PurchaseOrderDetailPage';
import ReceptionNotesPage from '@/pages/purchases/ReceptionNotesPage';
import ReceptionNoteDetailPage from '@/pages/purchases/ReceptionNoteDetailPage';
import PurchaseInvoicesPage from '@/pages/purchases/PurchaseInvoicesPage';
import PurchaseInvoiceDetailPage from '@/pages/purchases/PurchaseInvoiceDetailPage';

// Support
import SupportDashboardPage from '@/pages/support/SupportDashboardPage';
import TicketsPage from '@/pages/support/TicketsPage';
import TicketDetailPage from '@/pages/support/TicketDetailPage';

// Documents
import DocumentsPage from '@/pages/DocumentsPage';

// Admin & User
import SettingsPage from '@/pages/admin/SettingsPage';
import UsersPage from '@/pages/admin/UsersPage';
import RolesPage from '@/pages/admin/RolesPage';
import ActivityLogPage from '@/pages/admin/ActivityLogPage';
import UserProfilePage from '@/pages/UserProfilePage';

// UI Kit
import UIKitPage from '@/pages/UIKitPage';
import SuppliersDetailPage from '@/pages/crm/SuppliersDetailPage';
import CreditNotesDetailPage from '@/pages/sales/CreditNotesDetailPage';
import DeliveryNotesDetailPage from '@/pages/sales/DeliveryNotesDetailPage';
import CreateClientPage from '@/pages/crm/CreateClientPage';
import SignatureDashboard from '@/pages/signature/SignatureDashboard';
import SignatureTracking from '@/pages/signature/SignatureTracking';
import SignatureCreditPurchase from '@/pages/signature/SignatureCreditPurchase';
import CommercialPage from '@/pages/tiers/CommercialPage';
import QuoteCreatePage from '@/pages/sales/QuoteCreate';
import InvoiceCreatePage from '@/pages/sales/InvoiceCreatePage';
import SageBuilderPage from '@/pages/SageBuilderPage';
import PaymentsPage from '@/pages/sales/PaymentsPage';
import PaymentDetailPage from '@/pages/sales/PaymentDetailPage';
import AskIaPage from '@/pages/AskIaPage';

const DatavenRoute = () => {
  return (
    
        <AppLayout>
          <Routes>
            {/* Dashboard */}
            <Route path="/" element={<DashboardPage />} />
           
            {/* CRM */}
            <Route path="/prospects" element={<ProspectsPage />} />
            <Route path="/prospects/create" element={<CreateProspectPage />} />
            <Route path="/prospects/:id" element={<ProspectDetailPage />} />

            <Route path="/clients" element={<ClientsPage />} />
            <Route path="/clients/create" element={<CreateClientPage />} />
            <Route path="/clients/:id/edit" element={<CreateClientPage />} />
            <Route path="/clients/:id" element={<ClientDetailPage />} />

            <Route path="/fournisseurs" element={<SuppliersPage />} />
            <Route path="/fournisseurs/:id" element={<SuppliersDetailPage />} />
            
            <Route path="/commercial" element={<CommercialPage />} />

            <Route path="/reglements" element={<PaymentsPage />} />
            <Route path="/reglements/:id" element={<PaymentDetailPage />} />
            
            {/* Tiers - Articles & Familles */}
            <Route path="/articles" element={<ArticlesPage />} />
            <Route path="/articles/:id" element={<ArticleDetailPage />} />
            <Route path="/familles-articles" element={<ProductFamiliesPage />} />
            <Route path="/familles-articles/:id" element={<ProductFamilyDetailPage />} />

            {/* iframe */}
            <Route path="/sage-builder" element={<SageBuilderPage />} />

            {/* ask ia */}
            <Route path="/ask-ia" element={<AskIaPage />} />

            {/* Sales */}
            <Route path="/opportunites" element={<OpportunitiesPipelinePage />} />
            <Route path="/opportunites/:id" element={<OpportunityDetailPage />} />
            <Route path="/pipeline" element={<OpportunitiesPipelinePage />} />
            <Route path="/activites" element={<ActivitiesPage />} />
            <Route path="/taches" element={<TasksPage />} />
            
            <Route path="/devis" element={<QuotesPage />} />
            <Route path="/devis/:id" element={<QuoteDetailPage />} />
            <Route path="/devis/nouveau" element={<QuoteCreatePage />} /> 

            <Route path="/commandes" element={<OrdersPage />} />
            <Route path="/commandes/:id" element={<OrderDetailPage />} />

            <Route path="/bons-livraison" element={<DeliveryNotesPage />} />
            <Route path="/bons-livraison/:id" element={<DeliveryNotesDetailPage />} />

            <Route path="/factures" element={<InvoicesPage />} />
            <Route path="/factures/:id" element={<InvoiceDetailPage />} />
            <Route path="/factures/nouveau" element={<InvoiceCreatePage />} />

            <Route path="/avoirs" element={<CreditNotesPage />} />
            <Route path="/avoirs/:id" element={<CreditNotesDetailPage />} />

             {/* Signature Électronique */}
            <Route path="/signature/dashboard" element={<SignatureDashboard />} />
            <Route path="/signature/tracking" element={<SignatureTracking />} />
            <Route path="/signature/purchase" element={<SignatureCreditPurchase />} />
            
            {/* Purchases */}
            <Route path="/bons-commande" element={<PurchaseOrdersPage />} />
            <Route path="/bons-commande/:id" element={<PurchaseOrderDetailPage />} />
            <Route path="/bons-reception" element={<ReceptionNotesPage />} />
            <Route path="/bons-reception/:id" element={<ReceptionNoteDetailPage />} />
            <Route path="/factures-achat" element={<PurchaseInvoicesPage />} />
            <Route path="/factures-achat/:id" element={<PurchaseInvoiceDetailPage />} />
            
            {/* Support */}
            <Route path="/support-dashboard" element={<SupportDashboardPage />} />
            <Route path="/tickets" element={<TicketsPage />} />
            <Route path="/tickets/:id" element={<TicketDetailPage />} />
            
            {/* Documents */}
            <Route path="/documents" element={<DocumentsPage />} />
            
            {/* Admin */}
            <Route path="/parametres" element={<SettingsPage />} />
            <Route path="/utilisateurs" element={<UsersPage />} />
            <Route path="/roles" element={<RolesPage />} />
            <Route path="/journal" element={<ActivityLogPage />} />
            
            {/* User */}
            <Route path="/profile" element={<UserProfilePage />} />
            
            {/* Dev */}
            <Route path="/ui-kit" element={<UIKitPage />} />
            
            {/* Catch all */}
            <Route path="*" element={<Navigate to="/" replace />} />
          </Routes>

          
        </AppLayout>
  );
}

export default DatavenRoute;
