use seed::{prelude::*, *};

use crate::{
    state::{Context, Model, Msg},
    view::{self, view_header, view_search_results},
};

pub(super) fn view(model: &Model) -> Node<Msg> {
    log::info!("tablet::view");
    let show_icon_text = false;
    // Do two queries, one without `unread` so it loads fast, then a second with unread.
    let content = match &model.context {
        Context::None => div![h1!["Loading"]],
        Context::ThreadResult {
            thread,
            open_messages,
        } => view::thread(thread, open_messages, show_icon_text),
        Context::SearchResult {
            query,
            results,
            count,
            pager,
            selected_threads,
        } => view_search_results(
            &query,
            results.as_slice(),
            *count,
            pager,
            selected_threads,
            show_icon_text,
        ),
    };
    div![
        C!["main-content"],
        div![
            view_header(&model.query, &model.refreshing_state),
            content,
            view_header(&model.query, &model.refreshing_state),
        ]
    ]
}
