use askama::Template;

use crate::cmd::webui::project::views::TaskRow;

/// View-model for the task detail page.
pub(in crate::cmd::webui) struct TaskView {
    pub(in crate::cmd::webui) full_id: String,
    pub(in crate::cmd::webui) short_id: String,
    pub(in crate::cmd::webui) title: String,
    pub(in crate::cmd::webui) description: String,
    /// Raw markdown source for the edit form textarea.
    pub(in crate::cmd::webui) description_raw: String,
    pub(in crate::cmd::webui) task_type: String,
    pub(in crate::cmd::webui) status: String,
    pub(in crate::cmd::webui) priority: String,
    pub(in crate::cmd::webui) effort: String,
    pub(in crate::cmd::webui) created_at: String,
    pub(in crate::cmd::webui) created_at_display: String,
    pub(in crate::cmd::webui) updated_at: String,
    pub(in crate::cmd::webui) updated_at_display: String,
    /// Parent task ID (short form) for display, empty string if none.
    pub(in crate::cmd::webui) parent_id: String,
    pub(in crate::cmd::webui) labels: Vec<String>,
    pub(in crate::cmd::webui) logs: Vec<LogView>,
}

pub(in crate::cmd::webui) struct LogView {
    pub(in crate::cmd::webui) timestamp: String,
    pub(in crate::cmd::webui) timestamp_display: String,
    pub(in crate::cmd::webui) message: String,
}

/// A blocker reference for the task detail page.
pub(in crate::cmd::webui) struct BlockerRef {
    pub(in crate::cmd::webui) full_id: String,
    pub(in crate::cmd::webui) short_id: String,
}

#[derive(Template)]
#[template(path = "task.html")]
pub(super) struct TaskTemplate {
    pub(super) all_projects: Vec<String>,
    pub(super) active_project: Option<String>,
    pub(super) project_name: String,
    pub(super) task: TaskView,
    pub(super) blockers_open: Vec<BlockerRef>,
    pub(super) blockers_resolved: Vec<BlockerRef>,
    pub(super) subtasks: Vec<TaskRow>,
    /// Pre-built heading for the edit dialog, e.g. "Edit td-XXXXXXX".
    pub(super) edit_heading: String,
    /// Pre-built form action URL for the edit dialog.
    pub(super) edit_form_action: String,
}
