use super::protocol;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PickerRenderRow {
    pub node_id: String,
    pub title: String,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PickerRenderResult {
    pub root_test_id: &'static str,
    pub item_count: usize,
    pub allow_root_pick: bool,
}

pub fn build_picker_render_result(
    rows: &[PickerRenderRow],
    allow_root_pick: bool,
) -> PickerRenderResult {
    PickerRenderResult {
        root_test_id: protocol::TEST_ID_TREE_PICKER_ROOT,
        item_count: rows.len(),
        allow_root_pick,
    }
}

#[cfg(test)]
mod tests {
    use super::super::filetree_renderer::{build_filetree_testids, FileTreeRenderRow};
    use super::{build_picker_render_result, PickerRenderRow};

    #[test]
    fn tree_shell_filetree_picker_builds_file_rows_and_picker_mode() {
        let file_rows = build_filetree_testids(&[
            FileTreeRenderRow {
                row_id: "doc:page_root".into(),
                row_kind: "document".into(),
                title: "首页".into(),
            },
            FileTreeRenderRow {
                row_id: "asset:asset_1".into(),
                row_kind: "asset".into(),
                title: "附件".into(),
            },
        ]);
        let picker = build_picker_render_result(
            &[PickerRenderRow {
                node_id: "page_root".into(),
                title: "首页".into(),
            }],
            true,
        );

        assert_eq!(file_rows[0].0, "filetree-doc-row");
        assert_eq!(file_rows[1].0, "filetree-asset-row");
        assert_eq!(picker.root_test_id, "tree-picker-root");
        assert!(picker.allow_root_pick);
    }
}
