import {
  type RouteConfig,
  index,
  layout,
  prefix,
  route,
} from "@react-router/dev/routes";

export default [
  // * matches all URLs, the ? makes it optional so it will match / as well
  layout("./layouts/root.layout.tsx", [
    route("/auth/signin", "./routes/auth/signin.tsx"),
    route("/auth/setup", "./routes/auth/setup.tsx"),
    route("/auth/logout", "./routes/auth/logout.tsx"),
    route("/set-password", "./routes/auth/set-password.tsx"),
    route("/forgot-password", "./routes/auth/forgot-password.tsx"),
    route("/reset-password", "./routes/auth/reset-password.tsx"),
    // One-time sign-in links from console emails. Outside /auth so the root
    // layout doesn't redirect an already-signed-in reader away from `next`.
    route("/sso", "./routes/auth/sso.tsx"),
    // Full-bleed dashboard viewer: inside root.layout (so /admin stays auth
    // gated) but outside console.layout, so the sidebar/header don't frame it.
    route(
      "/admin/dashboard/:slug/view",
      "./routes/dashboard/$slug/view/page.tsx",
    ),
    layout("./layouts/console.layout.tsx", [
      route("/admin/dashboard", "./routes/dashboard/page.tsx"),
      // Placeholder detail target for a dashboard card; the viewer lands here.
      route("/admin/dashboard/:slug", "./routes/dashboard/$slug/page.tsx"),
      ...prefix("admin/members", [
        layout("./layouts/members.layout.tsx", [
          index("./routes/members/page.tsx"),
          // Member-module permissions, kept out of role management.
          route("/access", "./routes/members/access/page.tsx"),
          // Per-user mapping, same shape as the promo access list.
          route("/access/:userId", "./routes/members/access/$userId/page.tsx"),
        ]),
        // Contact detail sits in the same layout as the account it belongs to,
        // so it inherits the promo theme shell instead of rendering unthemed.
        layout("./layouts/account.layout.tsx", [
          route("/:accountId", "./routes/members/account/page.tsx"),
          route(
            "/:accountId/:contactId",
            "./routes/members/account/contact/page.tsx",
          ),
        ]),
      ]),
      ...prefix("admin/memberships", [
        layout("./layouts/memberships.layout.tsx", [
          index("./routes/memberships/page.tsx"),
          route(
            "/account-types",
            "./routes/memberships/account-types/page.tsx",
          ),
          route(
            "/account-types/new",
            "./routes/memberships/account-types/create-account-type/page.tsx",
          ),
          route(
            "/account-types/:id",
            "./routes/memberships/account-types/account-type/page.tsx",
          ),
          route("/clubs", "./routes/memberships/clubs/page.tsx"),
          route(
            "/charge-centers",
            "./routes/memberships/charge-centers/page.tsx",
          ),
        ]),
        route("/clubs/new", "./routes/memberships/clubs/create-club/page.tsx"),
        route("/clubs/:id", "./routes/memberships/clubs/club/page.tsx"),
        route(
          "/charge-centers/new",
          "./routes/memberships/charge-centers/create-charge-center/page.tsx",
        ),
        route(
          "/charge-centers/:id",
          "./routes/memberships/charge-centers/charge-center/page.tsx",
        ),
      ]),
      ...prefix("admin/bookings", [
        layout("./layouts/bookings.layout.tsx", [
          index("./routes/bookings/page.tsx"),
        ]),
        route("/create", "./routes/bookings/create/page.tsx"),
        route("/:bookingId", "./routes/bookings/bookingId/page.tsx"),
      ]),
      layout("./layouts/promo-codes.layout.tsx", [
        ...prefix("admin/promo-codes", [
          index("./routes/promo-codes/page.tsx"),
          /*
           * Declared before "/:code" so the literal wins the match.
           *
           * Creating a promo code was a modal holding every field at once — name,
           * code, expiry, rewards, the access list and the signup promo codes — which
           * is more than a dialog can lay out. It is a page now, and the static
           * segment has to come first or "new" would be read as a promo code named
           * "new" and try to load it.
           */
          route("/new", "./routes/promo-codes/new/page.tsx"),
          route("/:code", "./routes/promo-codes/$code/page.tsx"),
          route(
            "/:code/members/:membershipNumber",
            "./routes/promo-codes/$code/members/$membershipNumber/page.tsx",
          ),
          route(
            "/:code/members/:membershipNumber/:contactId",
            "./routes/promo-codes/$code/members/$membershipNumber/$contactId/page.tsx",
          ),
        ]),
        ...prefix("admin/promo-code-campaigns", [
          index("./routes/promo-code-campaigns/page.tsx"),
        ]),
        // Inside the promo layout so it gets the nav tabs and the promo theme.
        // Export approval queue. Inside the promo layout for the nav + theme;
        // core decides whether the caller sees the whole queue or only their own.
        // Promo access roles — created here, applied to members from their
        // Access List page.
        ...prefix("admin/promo-access-roles", [
          index("./routes/promo-access-roles/page.tsx"),
          // ":roleId" doubles as "new" — one form serves add and edit.
          route("/:roleId", "./routes/promo-access-roles/$roleId/page.tsx"),
        ]),
        ...prefix("admin/export-requests", [
          index("./routes/export-requests/page.tsx"),
        ]),
        // Retiring a member account. Inside the promo layout for the nav tab and
        // the theme; the page's own loader turns anyone but a super admin away.
        ...prefix("admin/account-deletion", [
          index("./routes/account-deletion/page.tsx"),
        ]),
        // Drill-down behind the dashboard's Contact breakdown.
        ...prefix("admin/contact-completeness", [
          index("./routes/contact-completeness/page.tsx"),
        ]),
        ...prefix("admin/promo-code-bookings", [
          index("./routes/promo-code-bookings/page.tsx"),
        ]),
        ...prefix("admin/member-referrals", [
          index("./routes/member-referrals/page.tsx"),
        ]),
        ...prefix("admin/reports", [
          index("./routes/reports/page.tsx"),
          route(
            "/members/:code/:membershipNumber",
            "./routes/reports/members/$code/$membershipNumber/page.tsx",
          ),
          route(
            "/members/:code/:membershipNumber/:contactId",
            "./routes/reports/members/$code/$membershipNumber/$contactId/page.tsx",
          ),
        ]),
        ...prefix("admin/access-list", [
          index("./routes/access-list/page.tsx"),
          route("/:userId", "./routes/access-list/$userId/page.tsx"),
        ]),
        route("/admin/kcgm", "./routes/kcgm-dashboard/page.tsx"),
      ]),
      ...prefix("admin/promo-code-campaigns", [
        route(
          "/:campaignId",
          "./routes/promo-code-campaigns/$campaignId/page.tsx",
        ),
        route(
          "/:campaignId/promo-codes/:promoCodeId",
          "./routes/promo-code-campaigns/$campaignId/promo-codes/$promoCodeId/page.tsx",
        ),
        route(
          "/:campaignId/promo-codes/:promoCodeId/members/:membershipNumber",
          "./routes/promo-code-campaigns/$campaignId/promo-codes/$promoCodeId/members/$membershipNumber/page.tsx",
        ),
        route(
          "/:campaignId/promo-codes/:promoCodeId/members/:membershipNumber/:contactId",
          "./routes/promo-code-campaigns/$campaignId/promo-codes/$promoCodeId/members/$membershipNumber/$contactId/page.tsx",
        ),
      ]),
      ...prefix("admin/edm", [
        index("./routes/edm/page.tsx"),
        route("/preview", "./routes/edm/preview/page.tsx"),
        // Declared before "/:templateId" so "import" is not matched as a
        // template id, the same reason "/preview" sits above it.
        route("/import", "./routes/edm/import/page.tsx"),
        route("/workspace", "./routes/edm/workspace/page.tsx"),
        route("/:templateId", "./routes/edm/$templateId/page.tsx"),
      ]),
      ...prefix("admin/resorts", [
        index("./routes/resorts/page.tsx"),
        route("/:resortId", "./routes/resorts/$resortId/page.tsx"),
      ]),
      ...prefix("admin/member-offers", [
        index("./routes/member-offers/page.tsx"),
        route("/:offerId", "./routes/member-offers/$offerId/page.tsx"),
      ]),
      ...prefix("admin/notifications", [
        index("./routes/notifications/page.tsx"),
        route("/:id", "./routes/notifications/details/page.tsx"),
        route("/settings", "./routes/notifications/settings/page.tsx"),
      ]),
      ...prefix("admin/chatbot", [
        layout("./layouts/chatbot.layout.tsx", [
          index("./routes/chatbot/page.tsx"),

          ...prefix("agents", [
            index("./routes/chatbot/agents/page.tsx"),
            route("/create", "./routes/chatbot/agents/create/page.tsx"),
            route("/edit/:id", "./routes/chatbot/agents/edit/$id.tsx"),
          ]),

          ...prefix("prompts", [
            index("./routes/chatbot/prompts/page.tsx"),
            route("/create", "./routes/chatbot/prompts/create/page.tsx"),
            route("/edit/:id", "./routes/chatbot/prompts/edit/$id.tsx"),
          ]),

          ...prefix("history", [index("./routes/chatbot/history/page.tsx")]),
        ]),
      ]),
      ...prefix("admin/settings", [
        layout("./layouts/settings.layout.tsx", [
          route("/users", "./routes/settings/users/page.tsx"),
          route("/users/new", "./routes/settings/users/create-user/page.tsx"),
          route("/users/:id", "./routes/settings/users/user/page.tsx"),
          route("/roles", "./routes/settings/roles/page.tsx"),
          route("/roles/new", "./routes/settings/roles/create-role/page.tsx"),
          route("/roles/:id", "./routes/settings/roles/role/page.tsx"),
          // Self-service: session-gated, no user-management role.
          route("/profile", "./routes/settings/profile/page.tsx"),
        ]),
      ]),
      route("/admin/activity-logs", "./routes/activity-logs/page.tsx"),
      route("/admin/points-transfer", "./routes/points-transfer/page.tsx"),
      route(
        "/admin/points-transfer/deactivated",
        "./routes/points-transfer/deactivated/page.tsx",
      ),
      route("/admin/event-analytics", "./routes/event-analytics/page.tsx"),
      route(
        "/admin/event-analytics/members/:memberId",
        "./routes/event-analytics/members/$memberId/page.tsx",
      ),
      route(
        "/admin/event-analytics/events/:eventType",
        "./routes/event-analytics/events/$eventType/page.tsx",
      ),
    ]),
    // ...prefix("destinations", [
    //   layout("./layouts/destination/base.tsx", [
    //     index("./routes/destinations/index.tsx"),
    //     layout("./layouts/destination/index.tsx", [
    //       route(":id/units", "./routes/destinations/units/index.tsx"),
    //       route(
    //         ":id/units/:unitId/occupancy",
    //         "./routes/destinations/units/occupancy.tsx",
    //       ),
    //       route(
    //         ":id/units/:unitId/booking-options",
    //         "./routes/destinations/units/bookingOptions.tsx",
    //       ),
    //       layout("./layouts/destination/bookingModes.tsx", [
    //         route(
    //           ":id/booking-modes/general",
    //           "./routes/destinations/bookingModes/general.tsx",
    //         ),
    //         route(
    //           ":id/booking-modes/itinerary",
    //           "./routes/destinations/bookingModes/itinerary.tsx",
    //         ),
    //         route(
    //           ":id/booking-modes/itinerary/:itineraryId",
    //           "./routes/destinations/bookingModes/edit.tsx",
    //         ),
    //       ]),
    //     ]),
    //   ]),
    // ]),
    // ...prefix("message-center", [
    //   layout("./layouts/messageCenter/index.tsx", [
    //     route("notifications", "./routes/messageCenter/notification/index.tsx"),
    //   ]),
    // ]),
    // ...prefix("settings", [
    //   layout("./layouts/settings/index.tsx", [
    //     route("roles", "./routes/settings/roles/index.tsx"),
    //     route("users", "./routes/settings/users/index.tsx"),
    //   ]),
    // ]),
    // ...prefix("account-types", [
    //   layout("./layouts/account_types/index.tsx", [
    //     index("./routes/account_types/index.tsx"),
    //   ]),
    // ]),
  ]),
  route(
    "public/edm/preview/:templateId",
    "./routes/edm/public-preview/page.tsx",
  ),
  // Public share-link viewer — outside the auth gate; the token is the credential.
  route("public/dashboards/:token", "./routes/dashboard/public/page.tsx"),
  route("api/proxy/*?", "./routes/api/proxy.$.ts"),
  route("/v1/auth/admin-console/login", "./routes/v1/auth/login.ts"),
  route("*?", "catchall.tsx"),
] satisfies RouteConfig;
