// SPDX-License-Identifier: Apache-2.0
//! Top header: brand mark, current privacy state, offline indicator,
//! account menu. Not aggressive — just consistent reassurance.

use leptos::prelude::*;

use crate::components::icons::{IconShield, IconUsers};
use crate::i18n::{Lang, t};
use crate::state::AppState;

#[component]
pub fn TrustHeader() -> impl IntoView {
    let st = AppState::get();
    let lang = st.lang;
    let offline = st.offline;

    view! {
        <header class="trust-header" role="banner">
            <div class="trust-header__inner">
                <a class="brand" href="/" aria-label="hejpics — home">
                    <span class="brand__dot" aria-hidden="true"></span>
                    <span>{t("brand")}</span>
                </a>

                <div class="trust-strip" role="status">
                    <span class="privacy-badge" title=t("trust.private_default")>
                        <IconShield size=14 />
                        <span class="label">{t("trust.private_default")}</span>
                    </span>

                    <span
                        class="offline-dot"
                        attr:data-offline=move || offline.get().to_string()
                        aria-live="polite"
                    >
                        <span class="offline-dot__pip" aria-hidden="true"></span>
                        <span>
                            {move || if offline.get() { "Offline" } else { "Online" }}
                        </span>
                    </span>

                    <span class="lang-switch" role="group" aria-label="Language">
                        <button
                            type="button"
                            aria-pressed=move || (lang.get() == Lang::En).to_string()
                            on:click=move |_| lang.set(Lang::En)
                        >"EN"</button>
                        <button
                            type="button"
                            aria-pressed=move || (lang.get() == Lang::Ja).to_string()
                            on:click=move |_| lang.set(Lang::Ja)
                        >"日本語"</button>
                    </span>

                    <a class="btn btn--ghost btn--sm" href="/settings" aria-label="Account & settings">
                        <IconUsers size=16 />
                        <span class="sr-only">"Account"</span>
                    </a>
                </div>
            </div>
        </header>
    }
}

/// Minimal header used by public (non-account) share pages. Shows only
/// brand and the privacy-by-default badge. No account menu, no nav.
#[component]
pub fn PublicShellHeader() -> impl IntoView {
    view! {
        <header class="trust-header trust-header--public" role="banner">
            <div class="trust-header__inner">
                <a class="brand" href="https://hejpics.app" aria-label="hejpics">
                    <span class="brand__dot" aria-hidden="true"></span>
                    <span>"hejpics"</span>
                </a>
                <div class="trust-strip" role="status">
                    <span class="privacy-badge">
                        <IconShield size=14 />
                        <span class="label">"Private link · not public"</span>
                    </span>
                </div>
            </div>
        </header>
    }
}
