// SPDX-License-Identifier: Apache-2.0
//! Toast stack — non-blocking transient feedback. Uses `aria-live="polite"`
//! so screen readers announce messages without preempting other speech.

use leptos::prelude::*;

use crate::state::{AppState, ToastKind};

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

    view! {
        <div class="toast-stack" role="status" aria-live="polite" aria-atomic="false">
            <For
                each=move || toasts.get()
                key=|t| t.id
                children=|t| {
                    let cls = match t.kind {
                        ToastKind::Success => "toast toast--sage",
                        ToastKind::Neutral => "toast",
                    };
                    view! {
                        <div class=cls role="status">{t.message}</div>
                    }
                }
            />
        </div>
    }
}
