use crate::layout::LayoutItem;
use crate::model::NamedDest;

pub fn collect_named_dests_from_items(items: &[LayoutItem], page_idx: usize, dests: &mut Vec<NamedDest>) {
    for item in items {
        match item {
            LayoutItem::Text(text) => {
                if let Some(ref id) = text.id {
                    dests.push(NamedDest {
                        id: id.clone(),
                        page_index: page_idx,
                        x: text.x,
                        y: text.y,
                    });
                }
            }
            LayoutItem::Table(table) => {
                for row in &table.rows {
                    for cell in &row.cells {
                        collect_named_dests_from_items(&cell.items, page_idx, dests);
                    }
                }
            }
            LayoutItem::Columns(cols) => {
                for col in &cols.columns {
                    collect_named_dests_from_items(col, page_idx, dests);
                }
            }
            LayoutItem::List(list) => {
                for list_item in &list.items {
                    collect_named_dests_from_items(&list_item.content, page_idx, dests);
                }
            }
            _ => {}
        }
    }
}
