//! Shell dispatcher. Selects between the Leptos-hydration shell and the
//! HTMX-SSR shell based on the resolved [`RenderingProfile`].
//!
//! Both shells consume the common [`rustelo_seo`] layer for `<head>` SEO tags,
//! eliminating drift between renderers (every page emits the same canonical,
//! Open Graph, Twitter Card and JSON-LD payload regardless of how its body is
//! rendered).

use leptos_config::LeptosOptions;
use rustelo_server::rendering::RenderingProfile;

mod common;
pub mod htmx;
#[cfg(feature = "wasm-client")]
pub mod leptos;
mod seo;

/// Profile-aware shell entry point. Returns the full HTML document as a
/// `String`.
pub fn shell_with_path(
    options: LeptosOptions,
    path: Option<String>,
    profile: RenderingProfile,
    htmx_extensions: Vec<String>,
) -> String {
    match profile {
        RenderingProfile::HtmxSsr => htmx::render(options, path, htmx_extensions),
        #[cfg(feature = "wasm-client")]
        RenderingProfile::LeptosHydration => leptos::render(options, path),
        #[cfg(not(feature = "wasm-client"))]
        RenderingProfile::LeptosHydration => {
            tracing::warn!("LeptosHydration profile requested but wasm-client feature is disabled — falling back to htmx-ssr");
            htmx::render(options, path, htmx_extensions)
        }
    }
}

/// Fragment renderer for non-boosted `HX-Request: true` responses. Returns
/// just the `<main>` element; the shell `<head>` and `<body>` are not
/// emitted, so SEO of the current page on the client persists (correct
/// behaviour — partial swaps must not alter the document head).
pub fn fragment_with_path(path: &str, language: &str) -> String {
    htmx::main_fragment(path, language)
}
