import { lazy } from 'react';
import { Navigate } from 'react-router-dom';
import AdminLayout from '@/components/layouts/AdminLayout';

const Home = lazy(() => import('@/pages/Home'));
const CreateTrip = lazy(() => import('@/pages/CreateTrip'));
const PlannerWrapper = lazy(() => import('@/pages/PlannerWrapper'));
const Journal = lazy(() => import('@/pages/Journal'));
const Explore = lazy(() => import('@/pages/Explore'));
const Bookmarks = lazy(() => import('@/pages/Bookmarks'));
const MyTrips = lazy(() => import('@/pages/MyTrips'));
const NotFound = lazy(() => import('@/pages/NotFound'));
const PublicTrip = lazy(() => import('@/pages/PublicTrip'));
const PrivacyPolicy = lazy(() => import('@/pages/PrivacyPolicy'));
const TermsOfService = lazy(() => import('@/pages/TermsOfService'));

const Profile = lazy(() => import('@/pages/Profile'));

// Admin pages
const AdminDashboard = lazy(() => import('@/pages/admin/Dashboard'));
const AdminUsers = lazy(() => import('@/pages/admin/Users'));
const AdminTrips = lazy(() => import('@/pages/admin/Trips'));
const AdminPlaces = lazy(() => import('@/pages/admin/Places'));
const AdminSettings = lazy(() => import('@/pages/admin/Settings'));
const AdminProviders = lazy(() => import('@/pages/admin/Providers'));
const AdminLeads = lazy(() => import('@/pages/admin/Leads'));
const AdminProvidersManagement = lazy(() => import('@/pages/admin/ProvidersManagement'));
const AdminAISearch = lazy(() => import('@/pages/admin/AISearch'));
const AdminImages = lazy(() => import('@/pages/admin/Images'));
const AdminAnalytics = lazy(() => import('@/pages/admin/Analytics'));
const AdminLogs = lazy(() => import('@/pages/admin/Logs'));
const AdminTours = lazy(() => import('@/pages/AdminTours'));
const AdminSEOSettings = lazy(() => import('@/pages/admin/SEOSettings'));
const AdminPageSEO = lazy(() => import('@/pages/admin/PageSEO'));
const AdminURLRedirects = lazy(() => import('@/pages/admin/URLRedirects'));
const AdminRateLimits = lazy(() => import('@/pages/admin/RateLimits'));
const AdminPricing = lazy(() => import('@/pages/admin/Pricing'));
const AdminPersonaAnalytics = lazy(() => import('@/pages/admin/PersonaAnalytics'));
const AdminNotifications = lazy(() => import('@/pages/admin/Notifications'));
const AdminEmailTemplates = lazy(() => import('@/pages/admin/EmailTemplates'));
const AdminAPIKeys = lazy(() => import('@/pages/admin/APIKeys'));
const AdminWebhooks = lazy(() => import('@/pages/admin/Webhooks'));
const AdminSystemHealth = lazy(() => import('@/pages/admin/SystemHealth'));

// Business pages
const BusinessRegister = lazy(() => import('@/pages/business/BusinessRegister'));
const BusinessDashboard = lazy(() => import('@/pages/business/BusinessDashboard'));
const BusinessPlaces = lazy(() => import('@/pages/business/BusinessPlaces'));
const AddPlace = lazy(() => import('@/pages/business/AddPlace'));

// Provider pages
const ProviderDashboard = lazy(() => import('@/pages/ProviderDashboard'));
const ProviderSettings = lazy(() => import('@/pages/ProviderSettings'));
const ProviderInfo = lazy(() => import('@/pages/ProviderInfo'));
const SignIn = lazy(() => import('@/pages/SignIn'));
const SignUp = lazy(() => import('@/pages/SignUp'));
const DashboardRedirect = lazy(() => import('@/pages/DashboardRedirect'));
const Dashboard = lazy(() => import('@/pages/Dashboard'));

export interface RouteConfig {
  path: string;
  element: React.ReactNode;
  children?: RouteConfig[];
  index?: boolean;
}

const routes: RouteConfig[] = [
  {
    path: '/',
    element: <Home />,
  },
  {
    path: '/create-trip',
    element: <CreateTrip />,
  },
  {
    path: '/planner',
    element: <PlannerWrapper />,
  },
  {
    path: '/journal',
    element: <Journal />,
  },
  {
    path: '/explore',
    element: <Explore />,
  },
  {
    path: '/bookmarks',
    element: <Bookmarks />,
  },
  {
    path: '/my-trips',
    element: <MyTrips />,
  },
  {
    path: '/trip/:slug',
    element: <PublicTrip />,
  },
  {
    path: '/privacy',
    element: <PrivacyPolicy />,
  },
  {
    path: '/terms',
    element: <TermsOfService />,
  },
  {
    path: '/sign-in/*',
    element: <SignIn />,
  },
  {
    path: '/sign-up/*',
    element: <SignUp />,
  },
  {
    path: '/dashboard',
    element: <DashboardRedirect />,
  },
  {
    path: '/profile',
    element: <Profile />,
  },
  {
    path: '/user-profile',
    element: <Navigate to="/profile" replace />,
  },
  {
    path: '/admin/*',
    element: <AdminLayout />,
    children: [
      {
        path: '',
        element: <AdminDashboard />,
        index: true,
      },
      {
        path: 'users',
        element: <AdminUsers />,
      },
      {
        path: 'trips',
        element: <AdminTrips />,
      },
      {
        path: 'places',
        element: <AdminPlaces />,
      },
      {
        path: 'providers',
        element: <AdminProviders />,
      },
      {
        path: 'leads',
        element: <AdminLeads />,
      },
      {
        path: 'persona-analytics',
        element: <AdminPersonaAnalytics />,
      },
      {
        path: 'providers-management',
        element: <AdminProvidersManagement />,
      },
      {
        path: 'tours',
        element: <AdminTours />,
      },
      {
        path: 'ai-search',
        element: <AdminAISearch />,
      },
      {
        path: 'images',
        element: <AdminImages />,
      },
      {
        path: 'analytics',
        element: <AdminAnalytics />,
      },
      {
        path: 'logs',
        element: <AdminLogs />,
      },
      {
        path: 'seo-settings',
        element: <AdminSEOSettings />,
      },
      {
        path: 'page-seo',
        element: <AdminPageSEO />,
      },
      {
        path: 'url-redirects',
        element: <AdminURLRedirects />,
      },
      {
        path: 'rate-limits',
        element: <AdminRateLimits />,
      },
      {
        path: 'pricing',
        element: <AdminPricing />,
      },
      {
        path: 'settings',
        element: <AdminSettings />,
      },
      {
        path: 'notifications',
        element: <AdminNotifications />,
      },
      {
        path: 'email-templates',
        element: <AdminEmailTemplates />,
      },
      {
        path: 'api-keys',
        element: <AdminAPIKeys />,
      },
      {
        path: 'webhooks',
        element: <AdminWebhooks />,
      },
      {
        path: 'system-health',
        element: <AdminSystemHealth />,
      },
    ],
  },
  {
    path: '/business/register',
    element: <BusinessRegister />,
  },
  {
    path: '/business/dashboard',
    element: <BusinessDashboard />,
  },
  {
    path: '/business/places',
    element: <BusinessPlaces />,
  },
  {
    path: '/business/add-place',
    element: <AddPlace />,
  },
  {
    path: '/provider/info',
    element: <ProviderInfo />,
  },
  {
    path: '/provider/dashboard',
    element: <ProviderDashboard />,
  },
  {
    path: '/provider/settings',
    element: <ProviderSettings />,
  },
  {
    path: '/provider-dashboard',
    element: <Navigate to="/provider/dashboard" replace />,
  },
  {
    path: '/provider-settings',
    element: <Navigate to="/provider/settings" replace />,
  },
  {
    path: '/404',
    element: <NotFound />,
  },
  {
    path: '*',
    element: <Navigate to="/404" replace />,
  },
];

export default routes;
