import "./css/globals.css";
import React from "react";
import ReactDOM from "react-dom/client";
import {
  BrowserRouter as Router,
  Routes,
  Route,
  Navigate,
} from "react-router-dom";
import RootLayout from "./app/layout";
import PublicLayout from "./app/(public)/layout";
import HomePage from "./app/(public)/page";
import AboutPage from "./app/(public)/about/page";
import ContactPage from "./app/(public)/contact-us/page";
import KomTokenPage from "./app/(public)/kom-token/page";
import TermsOfServicePage from "./app/(public)/terms-of-service/page";
import WhitePaperPage from "./app/(public)/white-paper/page";
import PrivacyPolicyPage from "./app/(public)/privacy-policy/page";
import SearchPage from "./app/(public)/search/page";
import SingleQuestionPage from "./app/(public)/search/[questionId]/page";
import PublicProfilePage from "./app/(public)/profile/[userId]/page";
import FollowsPage from "./app/(public)/follows/[userId]/page";
import AuthLayout from "./app/(public)/(auth)/layout";

import LoginPage from "./app/(public)/(auth)/auth/login/page";
import Verify2FAPage from "./app/(public)/(auth)/auth/verify-2fa/page";
import PasswordLayout from "./app/(public)/(password)/layout";
import RegisterPage from "./app/(public)/(auth)/auth/register/page";
import DashboardLayout from "./app/dashboard/layout";
import DashboardOverview from "./app/dashboard/overview/page";
import DashboardActivity from "./app/dashboard/activity/page";
import DashboardEarnings from "./app/dashboard/earnings/page";
import DashboardReferrals from "./app/dashboard/referrals/page";
import DashboardSupport from "./app/dashboard/support/page";
import DashboardMessages from "./app/dashboard/messages/page";
import DashboardNotifications from "./app/dashboard/notifications/page";
import DashboardProfile from "./app/dashboard/profile/page";
import NewQuestionPage from "./app/dashboard/questions/new/page";
import Error401Page from "./app/401/page";
import Error403Page from "./app/403/page";
import DashboardLogout from "./app/dashboard/logout/page";
import PasswordResetPage from "./app/(public)/password/reset/page";
import NotFoundPage from "./app/404/page";
import DashboardWallet from "./app/dashboard/wallet/page";
import FAQ from "./app/(public)/faq/page";
import ScrollToTop from "./components/custom/ScrollToTop";

const App = () => {
  return (
    <Router>
      <ScrollToTop />

      <Routes>
        {/* Root layout wrapper */}
        <Route element={<RootLayout />}>
          {/* Public routes with public layout */}
          <Route element={<PublicLayout />}>
            {/* Home page */}
            <Route path="/" element={<HomePage />} />

            {/* Public pages */}
            <Route path="/faq" element={<FAQ />} />
            <Route path="/about" element={<AboutPage />} />

            <Route path="/privacy-policy" element={<PrivacyPolicyPage />} />

            <Route path="/contact-us" element={<ContactPage />} />
            <Route path="/kom-token" element={<KomTokenPage />} />
            <Route path="/terms-of-service" element={<TermsOfServicePage />} />
            <Route path="/white-paper" element={<WhitePaperPage />} />

            {/* Search routes */}
            <Route path="/search" element={<SearchPage />} />
            <Route
              path="/search/:questionId"
              element={<SingleQuestionPage />}
            />

            {/* Public profile */}
            <Route path="/profile/:userId" element={<PublicProfilePage />} />
            <Route path="/follows/:userId" element={<FollowsPage />} />
          </Route>

          {/* Auth + password routes: bare page only (no site header/footer),
              exactly like komundad-auth.html split layout */}
          <Route element={<AuthLayout />}>
            <Route path="/auth/login" element={<LoginPage />} />
            <Route path="/auth/register" element={<RegisterPage />} />
            <Route path="/auth/verify-2fa" element={<Verify2FAPage />} />
          </Route>

          <Route element={<PasswordLayout />}>
            <Route path="/password/reset" element={<PasswordResetPage />} />
          </Route>

          {/* Dashboard routes with dashboard layout */}
          <Route element={<DashboardLayout />}>
            <Route path="/dashboard" element={<DashboardOverview />} />
            <Route path="/dashboard/activity" element={<DashboardActivity />} />
            <Route path="/dashboard/earnings" element={<DashboardEarnings />} />
            <Route path="/dashboard/referrals" element={<DashboardReferrals />} />
            <Route path="/dashboard/support" element={<DashboardSupport />} />
            {/* <Route
              path="/dashboard/broadcast"
              element={<DashboardBroadcasts />}
            /> */}
            {/* <Route path="/dashboard/feedback" element={<DashboardFeedback />} /> */}
            <Route path="/dashboard/logout" element={<DashboardLogout />} />
            <Route path="/dashboard/messages" element={<DashboardMessages />} />
            <Route
              path="/dashboard/notifications"
              element={<DashboardNotifications />}
            />
            <Route path="/dashboard/wallet" element={<DashboardWallet />} />
            <Route
              path="/dashboard/rewards"
              element={<Navigate to="/dashboard/earnings" replace />}
            />
            <Route path="/dashboard/profile" element={<DashboardProfile />} />

            <Route
              path="/dashboard/questions/new"
              element={<NewQuestionPage />}
            />
          </Route>

          {/* Error pages */}
          <Route path="/401" element={<Error401Page />} />
          <Route path="/403" element={<Error403Page />} />
          <Route path="*" element={<NotFoundPage />} />
        </Route>
      </Routes>
    </Router>
  );
};

const root = ReactDOM.createRoot(document.getElementById("root")!);
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
);
