import React, { Suspense, lazy } from 'react';
import { Routes, Route, Navigate } from 'react-router-dom';
import Layout from '@/components/Layout';
import AuthLayout from '@/components/AuthLayout';
import { Loader2 } from 'lucide-react';

const FullPageLoader = () => (
    <div className="flex justify-center items-center h-screen w-full">
        <div className="text-xl font-medium flex items-center">
            <Loader2 className="mr-2 h-6 w-6 animate-spin" />
            Loading...
        </div>
    </div>
);

const HomePage = lazy(() => import('@/pages/HomePage'));
const LoginPage = lazy(() => import('@/pages/LoginPage'));
const RegisterPage = lazy(() => import('@/pages/RegisterPage'));
const ToolsPage = lazy(() => import('@/pages/ToolsPage'));
const MergePDFPage = lazy(() => import('@/pages/tools/MergePDFPage'));
const SplitPDFPage = lazy(() => import('@/pages/tools/SplitPDFPage'));
const CompressPDFPage = lazy(() => import('@/pages/tools/CompressPDFPage'));
const ConvertPage = lazy(() => import('@/pages/tools/ConvertPage'));
const AboutUsPage = lazy(() => import('@/pages/AboutUsPage'));
const PrivacyPolicyPage = lazy(() => import('@/pages/PrivacyPolicyPage'));
const TermsOfServicePage = lazy(() => import('@/pages/TermsOfServicePage'));
const ContactPage = lazy(() => import('@/pages/ContactPage'));
const SitemapPage = lazy(() => import('@/pages/SitemapPage'));
const CharacterCounterPage = lazy(() => import('@/pages/tools/text/CharacterCounterPage'));
const LineCounterPage = lazy(() => import('@/pages/tools/text/LineCounterPage'));
const RemoveExtraSpacesPage = lazy(() => import('@/pages/tools/text/RemoveExtraSpacesPage'));
const WordCounterPage = lazy(() => import('@/pages/tools/text/WordCounterPage'));
const FindAndReplacePage = lazy(() => import('@/pages/tools/text/FindAndReplacePage'));
const CaseConverterPage = lazy(() => import('@/pages/tools/text/CaseConverterPage'));
const TextReverserPage = lazy(() => import('@/pages/tools/text/TextReverserPage'));
const DashboardPage = lazy(() => import('@/pages/DashboardPage'));
const PricingPage = lazy(() => import('@/pages/PricingPage'));
const ProtectPDFPage = lazy(() => import('@/pages/tools/ProtectPDFPage'));
const RotatePDFPage = lazy(() => import('@/pages/tools/RotatePDFPage'));
const EmbedPage = lazy(() => import('@/pages/EmbedPage'));
const EditPDFPage = lazy(() => import('@/pages/tools/EditPDFPage'));
const SignPDFPage = lazy(() => import('@/pages/tools/SignPDFPage'));
const RepairPDFPage = lazy(() => import('@/pages/tools/RepairPDFPage'));
const PDFToJPGPage = lazy(() => import('@/pages/tools/convert/PDFToJPG'));
const PDFToTextPage = lazy(() => import('@/pages/tools/convert/PDFToText'));
const ImageToPDFPage = lazy(() => import('@/pages/tools/convert/ImageToPDF'));
const TextToPDFPage = lazy(() => import('@/pages/tools/convert/TextToPDF'));

function App() {
  return (
    <Suspense fallback={<FullPageLoader />}>
        <Routes>
            <Route path="/" element={<Layout><HomePage /></Layout>} />
            <Route path="/tools" element={<Layout><ToolsPage /></Layout>} />
            <Route path="/tools/merge-pdf" element={<Layout><MergePDFPage /></Layout>} />
            <Route path="/tools/split-pdf" element={<Layout><SplitPDFPage /></Layout>} />
            <Route path="/tools/compress-pdf" element={<Layout><CompressPDFPage /></Layout>} />
            <Route path="/tools/convert" element={<Layout><ConvertPage /></Layout>} />
            <Route path="/tools/protect-pdf" element={<Layout><ProtectPDFPage /></Layout>} />
            <Route path="/tools/rotate-pdf" element={<Layout><RotatePDFPage /></Layout>} />
            <Route path="/tools/edit-pdf" element={<Layout><EditPDFPage /></Layout>} />
            <Route path="/tools/sign-pdf" element={<Layout><SignPDFPage /></Layout>} />
            <Route path="/tools/repair-pdf" element={<Layout><RepairPDFPage /></Layout>} />
            <Route path="/tools/convert/pdf-to-jpg" element={<Layout><PDFToJPGPage /></Layout>} />
            <Route path="/tools/convert/pdf-to-text" element={<Layout><PDFToTextPage /></Layout>} />
            <Route path="/tools/convert/image-to-pdf" element={<Layout><ImageToPDFPage /></Layout>} />
            <Route path="/tools/convert/text-to-pdf" element={<Layout><TextToPDFPage /></Layout>} />
            <Route path="/about-us" element={<Layout><AboutUsPage /></Layout>} />
            <Route path="/privacy-policy" element={<Layout><PrivacyPolicyPage /></Layout>} />
            <Route path="/terms-of-service" element={<Layout><TermsOfServicePage /></Layout>} />
            <Route path="/contact" element={<Layout><ContactPage /></Layout>} />
            <Route path="/sitemap" element={<Layout><SitemapPage /></Layout>} />
            <Route path="/pricing" element={<Layout><PricingPage /></Layout>} />
            <Route path="/dashboard" element={<Layout><DashboardPage /></Layout>} />
            <Route path="/embed-pdf" element={<Layout><EmbedPage /></Layout>} />
            
            <Route path="/tools/character-counter" element={<Layout><CharacterCounterPage /></Layout>} />
            <Route path="/tools/line-counter" element={<Layout><LineCounterPage /></Layout>} />
            <Route path="/tools/remove-extra-spaces" element={<Layout><RemoveExtraSpacesPage /></Layout>} />
            <Route path="/tools/word-counter" element={<Layout><WordCounterPage /></Layout>} />
            <Route path="/tools/find-and-replace" element={<Layout><FindAndReplacePage /></Layout>} />
            <Route path="/tools/case-converter" element={<Layout><CaseConverterPage /></Layout>} />
            <Route path="/tools/text-reverser" element={<Layout><TextReverserPage /></Layout>} />

            <Route path="/auth" element={<AuthLayout />}>
                <Route path="login" element={<LoginPage />} />
                <Route path="register" element={<RegisterPage />} />
            </Route>
        </Routes>
    </Suspense>
  );
}

export default App;