// SPDX-License-Identifier: Apache-2.0
//! Authenticated app shell: trust header, main region, bottom navigation.

use leptos::prelude::*;

use crate::components::bottom_nav::BottomPrimaryNav;
use crate::components::trust_header::TrustHeader;
use crate::state::AppState;

/// The shell wrapping every authenticated route.
#[component]
pub fn AppShell(children: Children) -> impl IntoView {
    let st = AppState::get();

    // Reflect accessibility prefs as data-* attributes on <html>.
    Effect::new(move |_| {
        let high = st.high_contrast.get();
        let large = st.large_text.get();
        let motion = st.reduced_motion.get();
        if let Some(doc) = web_sys::window().and_then(|w| w.document()) {
            if let Some(root) = doc.document_element() {
                let _ = root.set_attribute("data-contrast", if high { "high" } else { "normal" });
                let _ =
                    root.set_attribute("data-text-size", if large { "large" } else { "normal" });
                let _ =
                    root.set_attribute("data-motion", if motion { "reduced" } else { "normal" });
            }
        }
    });

    view! {
        <a href="#main" class="skip-link">"Skip to main content"</a>
        <div class="app-shell">
            <TrustHeader />
            <main id="main" class="main-region page-in" tabindex="-1">
                {children()}
            </main>
            <BottomPrimaryNav />
        </div>
    }
}
