// SPDX-License-Identifier: Apache-2.0
//! Shared inbox — albums others have shared with you.
//!
//! RFC 006: each row shows title + sender + new-photo dot.
//! Counts, expiry, and timestamps are on the album's own screen.

use leptos::prelude::*;

use crate::mock::{SharedWithMe, seed_shared_with_me};

#[component]
pub fn SharedInboxPage() -> impl IntoView {
    let items = RwSignal::new(seed_shared_with_me());

    view! {
        <Show
            when=move || items.with(|v| !v.is_empty())
            fallback=|| view! { <SharedEmpty /> }
        >
            <ul class="inbox-list" role="list">
                <For
                    each=move || items.get()
                    key=|i| i.id
                    children=|item| view! { <InboxRow item=item /> }
                />
            </ul>
        </Show>
    }
}

// ── Row: thumbnail + title + sender ──────────────────────────────────────────
// RFC 006: three elements only. New indicator = dot on thumbnail, no count.

#[component]
fn InboxRow(item: SharedWithMe) -> impl IntoView {
    let href = format!("/albums/{}", item.album_id);
    let bg = format!(
        "background:linear-gradient(135deg,{} 0%,{} 100%);",
        item.cover_palette.0, item.cover_palette.1
    );
    let has_new = item.new_count > 0;

    view! {
        <li class=if has_new { "inbox-row inbox-row--unread" } else { "inbox-row" }>
            <a href=href class="inbox-row__link">
                <div class="inbox-row__thumb" style=bg aria-hidden="true">
                    <Show when=move || has_new>
                        <span class="inbox-row__dot" aria-label="New photos"></span>
                    </Show>
                </div>
                <div class="inbox-row__text">
                    <div class="inbox-row__title">{item.album_title}</div>
                    <div class="inbox-row__sender">{item.sender_name}</div>
                </div>
            </a>
        </li>
    }
}

// ── Empty ─────────────────────────────────────────────────────────────────────

#[component]
fn SharedEmpty() -> impl IntoView {
    view! {
        <div class="empty">
            <p class="empty__body">
                "When someone shares an album with you it will appear here."
            </p>
        </div>
    }
}
