//! Admin routes without Router wrapper (for embedding in combined apps).
//!
//! This module provides the `AdminRoutes` component which contains all admin
//! route definitions without a Router wrapper. This allows the routes to be
//! embedded in a parent Router (e.g., CombinedApp in chattyness-app).
//!
//! For standalone use (e.g., chattyness-owner), use `AdminApp` which wraps
//! these routes with a Router.

use leptos::prelude::*;
use leptos_router::{
    ParamSegment, StaticSegment,
    components::{Route, Routes},
};

use crate::components::{AuthenticatedLayout, LoginLayout};
use crate::pages::{
    AvatarsDetailPage, AvatarsNewPage, AvatarsPage, ConfigPage, DashboardPage, LoginPage,
    PropsDetailPage, PropsNewPage, PropsPage, RealmAvatarsDetailPage, RealmAvatarsNewPage,
    RealmAvatarsPage, RealmDetailPage, RealmNewPage, RealmsPage, SceneDetailPage, SceneNewPage,
    ScenesPage, StaffPage, UserDetailPage, UserNewPage, UsersPage,
};

/// Admin routes that can be embedded in a parent Router.
///
/// All paths are relative to the Router's base path. When used in:
/// - `AdminApp`: The Router is configured with base="/admin"
/// - `CombinedApp`: The Router should be configured with base="/admin"
#[component]
pub fn AdminRoutes() -> impl IntoView {
    view! {
        <Routes fallback=|| "Page not found.".into_view()>
            // Login page (no layout)
            <Route path=StaticSegment("login") view=|| view! {
                <LoginLayout>
                    <LoginPage />
                </LoginLayout>
            } />

            // Dashboard
            <Route path=StaticSegment("") view=|| view! {
                <AuthenticatedLayout current_page="dashboard">
                    <DashboardPage />
                </AuthenticatedLayout>
            } />

            // Config
            <Route path=StaticSegment("config") view=|| view! {
                <AuthenticatedLayout current_page="config">
                    <ConfigPage />
                </AuthenticatedLayout>
            } />

            // Users
            <Route path=StaticSegment("users") view=|| view! {
                <AuthenticatedLayout current_page="users">
                    <UsersPage />
                </AuthenticatedLayout>
            } />
            <Route path=(StaticSegment("users"), StaticSegment("new")) view=|| view! {
                <AuthenticatedLayout current_page="users_new">
                    <UserNewPage />
                </AuthenticatedLayout>
            } />
            <Route path=(StaticSegment("users"), ParamSegment("user_id")) view=|| view! {
                <AuthenticatedLayout current_page="users">
                    <UserDetailPage />
                </AuthenticatedLayout>
            } />

            // Staff
            <Route path=StaticSegment("staff") view=|| view! {
                <AuthenticatedLayout current_page="staff">
                    <StaffPage />
                </AuthenticatedLayout>
            } />

            // Props
            <Route path=StaticSegment("props") view=|| view! {
                <AuthenticatedLayout current_page="props">
                    <PropsPage />
                </AuthenticatedLayout>
            } />
            <Route path=(StaticSegment("props"), StaticSegment("new")) view=|| view! {
                <AuthenticatedLayout current_page="props_new">
                    <PropsNewPage />
                </AuthenticatedLayout>
            } />
            <Route path=(StaticSegment("props"), ParamSegment("prop_id")) view=|| view! {
                <AuthenticatedLayout current_page="props">
                    <PropsDetailPage />
                </AuthenticatedLayout>
            } />

            // Server Avatars
            <Route path=StaticSegment("avatars") view=|| view! {
                <AuthenticatedLayout current_page="avatars">
                    <AvatarsPage />
                </AuthenticatedLayout>
            } />
            <Route path=(StaticSegment("avatars"), StaticSegment("new")) view=|| view! {
                <AuthenticatedLayout current_page="avatars_new">
                    <AvatarsNewPage />
                </AuthenticatedLayout>
            } />
            <Route path=(StaticSegment("avatars"), ParamSegment("avatar_id")) view=|| view! {
                <AuthenticatedLayout current_page="avatars">
                    <AvatarsDetailPage />
                </AuthenticatedLayout>
            } />

            // Realms
            <Route path=StaticSegment("realms") view=|| view! {
                <AuthenticatedLayout current_page="realms">
                    <RealmsPage />
                </AuthenticatedLayout>
            } />
            <Route path=(StaticSegment("realms"), StaticSegment("new")) view=|| view! {
                <AuthenticatedLayout current_page="realms_new">
                    <RealmNewPage />
                </AuthenticatedLayout>
            } />

            // Scenes (nested under realms)
            <Route path=(StaticSegment("realms"), ParamSegment("slug"), StaticSegment("scenes")) view=|| view! {
                <AuthenticatedLayout current_page="scenes">
                    <ScenesPage />
                </AuthenticatedLayout>
            } />
            <Route path=(StaticSegment("realms"), ParamSegment("slug"), StaticSegment("scenes"), StaticSegment("new")) view=|| view! {
                <AuthenticatedLayout current_page="scenes_new">
                    <SceneNewPage />
                </AuthenticatedLayout>
            } />
            <Route path=(StaticSegment("realms"), ParamSegment("slug"), StaticSegment("scenes"), ParamSegment("scene_id")) view=|| view! {
                <AuthenticatedLayout current_page="scenes">
                    <SceneDetailPage />
                </AuthenticatedLayout>
            } />

            // Realm Avatars (nested under realms)
            <Route path=(StaticSegment("realms"), ParamSegment("slug"), StaticSegment("avatars")) view=|| view! {
                <AuthenticatedLayout current_page="realm_avatars">
                    <RealmAvatarsPage />
                </AuthenticatedLayout>
            } />
            <Route path=(StaticSegment("realms"), ParamSegment("slug"), StaticSegment("avatars"), StaticSegment("new")) view=|| view! {
                <AuthenticatedLayout current_page="realm_avatars_new">
                    <RealmAvatarsNewPage />
                </AuthenticatedLayout>
            } />
            <Route path=(StaticSegment("realms"), ParamSegment("slug"), StaticSegment("avatars"), ParamSegment("avatar_id")) view=|| view! {
                <AuthenticatedLayout current_page="realm_avatars">
                    <RealmAvatarsDetailPage />
                </AuthenticatedLayout>
            } />

            // Realm detail (must come after more specific realm routes)
            <Route path=(StaticSegment("realms"), ParamSegment("slug")) view=|| view! {
                <AuthenticatedLayout current_page="realms">
                    <RealmDetailPage />
                </AuthenticatedLayout>
            } />
        </Routes>
    }
}
