//! jpl-website SSR components and routing

use leptos::prelude::*;
use leptos_meta::*;
use leptos_router::*;
use jpl-website_shared::SharedComponent;

/// Main application component
#[component]
pub fn App() -> impl IntoView {
    provide_meta_context();

    view! {
        <Stylesheet id="leptos" href="/pkg/jpl-website.css"/>
        <Title text="jpl-website - Rustelo CMS"/>

        <Router>
            <main>
                <Routes>
                    <Route path="" view=HomePage/>
                    <Route path="/about" view=AboutPage/>
                    <Route path="/*any" view=NotFound/>
                </Routes>
            </main>
        </Router>
    }
}

/// Home page component
#[component]
fn HomePage() -> impl IntoView {
    view! {
        <div class="container mx-auto px-4 py-8">
            <h1 class="text-4xl font-bold text-center mb-8">
                "Welcome to jpl-website"
            </h1>
            <p class="text-lg text-center mb-8">
                "A powerful CMS built with Rustelo framework"
            </p>
            <SharedComponent/>
            <div class="text-center">
                <a href="/about" class="btn btn-primary">
                    "Learn More"
                </a>
            </div>
        </div>
    }
}

/// About page component  
#[component]
fn AboutPage() -> impl IntoView {
    view! {
        <div class="container mx-auto px-4 py-8">
            <h1 class="text-3xl font-bold mb-6">"About jpl-website"</h1>
            <p class="text-lg mb-4">
                "This is a CMS application built with the Rustelo framework."
            </p>
            <p class="mb-4">
                "Features include:"
            </p>
            <ul class="list-disc list-inside mb-6">
                <li>"Content management"</li>
                <li>"User authentication"</li>
                <li>"Admin interface"</li>
                <li>"SEO optimization"</li>
            </ul>
            <a href="/" class="btn btn-secondary">
                "Back to Home"
            </a>
        </div>
    }
}

/// 404 Not Found page
#[component]
fn NotFound() -> impl IntoView {
    #[cfg(feature = "ssr")]
    {
        let resp = expect_context::<leptos_axum::ResponseOptions>();
        resp.set_status(axum::http::StatusCode::NOT_FOUND);
    }

    view! {
        <div class="container mx-auto px-4 py-8 text-center">
            <h1 class="text-6xl font-bold text-error mb-4">"404"</h1>
            <h2 class="text-2xl mb-4">"Page Not Found"</h2>
            <p class="mb-6">"The page you're looking for doesn't exist."</p>
            <a href="/" class="btn btn-primary">
                "Go Home"
            </a>
        </div>
    }
}