import React from 'react';
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import { AppShell } from '@/components/layout/AppShell';
import { ProtectedRoute } from './ProtectedRoute';
import { LoginPage } from '@/pages/Login';
import { PasswordResetRequestPage } from '@/pages/PasswordResetRequest';
import { PasswordResetConfirmPage } from '@/pages/PasswordResetConfirm';
import { DashboardPage } from '@/pages/Dashboard';
import { ContactsListPage } from '@/pages/ContactsList';
import { AuditLogPage } from '@/pages/AuditLog';
import { GlobalSearchResultsPage } from '@/pages/GlobalSearchResults';
import { SettingsPage } from '@/pages/Settings';
import { SettingsProfilePage } from '@/pages/SettingsProfile';
import { SettingsRolesPage } from '@/pages/SettingsRoles';
import { SettingsUsersPage } from '@/pages/SettingsUsers';
import { SettingsGroupsPage } from '@/pages/SettingsGroups';
import { SettingsPluginsPage } from '@/pages/SettingsPlugins';
import { SettingsSystemPage } from '@/pages/SettingsSystem';
import { SettingsCurrenciesPage } from '@/pages/SettingsCurrencies';
import { SettingsTaxesPage } from '@/pages/SettingsTaxes';
import { SettingsSequencesPage } from '@/pages/SettingsSequences';
import { CalendarPage } from '@/pages/Calendar';
import { CalendarKanbanPage } from '@/pages/CalendarKanban';
import { DmsPage } from '@/pages/Dms';
import { DmsTrashPage } from '@/pages/DmsTrash';
import { MailPage } from '@/pages/Mail';
import { MailSettingsPage } from '@/pages/MailSettings';
import { SettingsNotificationsPage } from '@/pages/SettingsNotifications';
import { AIAssistantPage } from '@/pages/AIAssistant';
import { AISettingsPage } from '@/pages/AISettings';
import { ProactiveAISettings } from '@/pages/ProactiveAISettings';

const router = createBrowserRouter([
  {
    path: '/login',
    element: <LoginPage />,
  },
  {
    path: '/password-reset',
    element: <PasswordResetRequestPage />,
  },
  {
    path: '/password-reset/confirm',
    element: <PasswordResetConfirmPage />,
  },
  {
    element: (
      <ProtectedRoute>
        <AppShell />
      </ProtectedRoute>
    ),
    children: [
      { path: '/', element: <DashboardPage /> },
      { path: '/dashboard', element: <DashboardPage /> },
      { path: '/contacts', element: <ContactsListPage /> },
      { path: '/audit-log', element: <AuditLogPage /> },
      { path: '/search', element: <GlobalSearchResultsPage /> },
      { path: '/calendar', element: <CalendarPage /> },
      { path: '/calendar/kanban', element: <CalendarKanbanPage /> },
      { path: '/dms', element: <DmsPage /> },
      { path: '/dms/trash', element: <DmsTrashPage /> },
      { path: '/mail', element: <MailPage /> },
      { path: '/mail/settings', element: <MailSettingsPage /> },
      { path: '/ai-assistant', element: <AIAssistantPage /> },
      {
        path: '/settings',
        element: <SettingsPage />,
        children: [
          { path: 'profile', element: <SettingsProfilePage /> },
          { path: 'roles', element: <SettingsRolesPage /> },
          { path: 'users', element: <SettingsUsersPage /> },
          { path: 'groups', element: <SettingsGroupsPage /> },
          { path: 'plugins', element: <SettingsPluginsPage /> },
          { path: 'system', element: <SettingsSystemPage /> },
          { path: 'currencies', element: <SettingsCurrenciesPage /> },
          { path: 'taxes', element: <SettingsTaxesPage /> },
          { path: 'sequences', element: <SettingsSequencesPage /> },
          { path: 'mail', element: <MailSettingsPage /> },
          { path: 'notifications', element: <SettingsNotificationsPage /> },
          { path: 'ai', element: <AISettingsPage /> },
          { path: 'ai-proactive', element: <ProactiveAISettings /> },
        ],
      },
    ],
  },
]);

export function AppRouter() {
  return <RouterProvider router={router} />;
}
