use leptos::prelude::*;
use rustelo_content::rustelo_core_lib::i18n::use_unified_i18n;

/// Login page — renders a full-page shell with heading text.
///
/// On WASM: triggers the `LoginModal` (provided via `WriteSignal<bool>` context)
/// to open automatically so the user can sign in without needing to click anything.
/// On SSR: renders the same heading text for a structurally stable hydration target.
#[component]
pub fn UnifiedLoginPage(
    #[prop(default = rustelo_content::rustelo_core_lib::config::get_default_language().to_string())]
    _language: String,
    #[prop(optional)] lang_content: Option<std::collections::HashMap<String, String>>,
) -> impl IntoView {
    let _ = lang_content; // pre-loaded by the page wrapper; auth keys are accessed via use_unified_i18n

    let i18n = use_unified_i18n();
    let title = i18n.t("auth-otp-modal-title");
    let subtitle = i18n.t("auth-otp-modal-subtitle");

    // Auto-open the login modal as soon as this page mounts in the browser.
    #[cfg(target_arch = "wasm32")]
    {
        if let Some(set_show) = use_context::<WriteSignal<bool>>() {
            Effect::new(move |_| {
                set_show.set(true);
            });
        }
    }

    view! {
        <div class="min-h-screen ds-bg-page flex items-center justify-center py-12 px-4">
            <div class="text-center max-w-md">
                <h1 class="text-3xl font-bold ds-text mb-3">
                    {title}
                </h1>
                <p class="ds-text-secondary text-sm">
                    {subtitle}
                </p>
            </div>
        </div>
    }
}
