import { RouteObject } from "react-router-dom";
import { EventsPage } from "src/pages/events";
import { AuthenticationGateway } from "../components/AuthenticationGateway";
import { EventModal } from "../components/EventModal";
import { Layout } from "../components/Layout";
import { ProtectedRoute } from "../components/ProtectedRoute";
import { AvailabilitiesPage } from "../pages/availabilities";
import { ChantiersPage } from "../pages/chantiers";
import { ChatPage } from "../pages/chat";
import { ConfirmEmailPage } from "../pages/confirm-email";
import { FeedbackPage } from "../pages/feedback";
import { FilesPage } from "../pages/files";
import { JoinPage } from "../pages/join";
import { LegalNoticePage } from "../pages/legal-notice";
import { LoginPage } from "../pages/login";
import { LoginV2Page } from "../pages/login-v2";
import { NotFoundPage } from "../pages/NotFoundPage";
// import NotesPage from "../pages/notes"; // Notes feature temporarily hidden
import { OAuthSigninPage } from "../pages/oauth-signin";
import { PlanningPage } from "../pages/planning";
import { PrivacyPolicyPage } from "../pages/privacy-policy";
import { ResetPasswordPage } from "../pages/reset-password";
import SettingsPage from "../pages/settings";
import { SignUpPage } from "../pages/signup";
import { SignUpV2Page } from "../pages/signup-v2";
import { TabloPage } from "../pages/tablo";
import { TabloDetailsPage } from "../pages/tablo-details";
import { TablosPage } from "../pages/tablos";
import { TasksPage } from "../pages/tasks";
import { UpdatePasswordPage } from "../pages/update-password";
import ChatProvider from "../providers/ChatProvider";

export const routes: RouteObject[] = [
  // Protected routes
  {
    path: "/",
    element: <ProtectedRoute fallback="/login" />,
    children: [
      {
        path: "",
        element: <Layout />,
        children: [
          {
            path: "tablos/:tabloId",
            element: <TabloDetailsPage />,
          },
          {
            index: true,
            element: <TabloPage />,
          },
          {
            path: "tablo",
            element: <TabloPage />,
          },
          {
            path: "planning",
            element: <PlanningPage />,
            children: [
              { index: true },
              {
                path: ":tablo_id/events/:event_id/edit",
                element: <EventModal mode="edit" />,
              },
              { path: "create", element: <EventModal mode="create" /> },
            ],
          },
          {
            path: "kanban",
            element: <NotFoundPage />,
            children: [{ index: true }, { path: ":tablo_id" }],
          },
          {
            path: "chantiers",
            element: <ChantiersPage />,
          },
          {
            path: "chat",
            element: (
              <ChatProvider>
                <ChatPage />
              </ChatProvider>
            ),
            children: [{ index: true }, { path: ":channelId" }],
          },
          // Notes feature temporarily hidden
          // {
          //   path: "notes",
          //   children: [
          //     { index: true, element: <NotesPage mode="create" /> },
          //     { path: ":noteId", element: <NotesPage mode="edit" /> },
          //     { path: "create", element: <NotesPage mode="create" /> },
          //   ],
          // },
          {
            path: "availabilities",
            element: <AvailabilitiesPage />,
          },
          {
            path: "events",
            element: <EventsPage />,
            children: [{ index: true }, { path: "create", element: <EventModal mode="create" /> }],
          },
          {
            path: "tasks",
            element: <TasksPage />,
          },
          {
            path: "files",
            element: <FilesPage />,
          },
          {
            path: "tablos",
            element: <TablosPage />,
          },
          {
            path: "feedback",
            element: <FeedbackPage />,
          },
          {
            path: "settings",
            element: <SettingsPage />,
          },
        ],
      },
    ],
  },
  // Protected routes with redirect to current page
  {
    path: "/join-tablo",
    element: <ProtectedRoute fallback="/login" shouldRedirectToCurrentPage />,
    children: [
      {
        path: "",
        element: <Layout />,
        children: [
          {
            index: true,
            element: <JoinPage />,
          },
        ],
      },
    ],
  },
  // OAuth signin route
  {
    path: "/login-with-oauth",
    element: <OAuthSigninPage />,
  },
  // Update password route (public, for password reset links)
  {
    path: "/update-password",
    element: <UpdatePasswordPage />,
  },
  // Email confirmation waiting page (public)
  {
    path: "/confirm-email",
    element: <ConfirmEmailPage />,
  },
  // Authentication pages (redirected to "/" if user is authenticated)
  {
    path: "/",
    element: <AuthenticationGateway />,
    children: [
      {
        path: "login",
        element: <LoginPage />,
      },
      {
        path: "login-v2",
        element: <LoginV2Page />,
      },
      {
        path: "signup",
        element: <SignUpPage />,
      },
      {
        path: "signup-v2",
        element: <SignUpV2Page />,
      },
      {
        path: "reset-password",
        element: <ResetPasswordPage />,
      },
    ],
  },
  // Public legal pages
  {
    path: "/legal-notice",
    element: <LegalNoticePage />,
  },
  {
    path: "/privacy-policy",
    element: <PrivacyPolicyPage />,
  },
];
