//! Results column component — renders one text widget per editor line,
//! aligned vertically so each result sits beside its input line.

use crate::evaluator::LineResult;
use crate::theme;
use iced::widget::{column, scrollable, text, Column};
use iced::{Element, Font, Length};

/// Build the scrollable results column from a slice of `LineResult`s.
///
/// Each result occupies exactly one line-height so it aligns with the
/// corresponding editor line on the left.
pub fn view<'a, Message: 'a>(results: &[LineResult]) -> Element<'a, Message> {
    let items: Vec<Element<'a, Message>> = if results.is_empty() {
        vec![text("").font(Font::MONOSPACE).into()]
    } else {
        results
            .iter()
            .map(|r| {
                let color = if r.is_error {
                    theme::ERROR_TEXT
                } else {
                    theme::RESULT_TEXT
                };
                text(r.display.clone())
                    .font(Font::MONOSPACE)
                    .color(color)
                    .into()
            })
            .collect()
    };

    scrollable(
        Column::with_children(items).padding([7, 10]),
    )
    .height(Length::Fill)
    .into()
}
