//! Vertical label/value property form renderer.

use ratatui::layout::Rect;
use ratatui::style::{Modifier, Style};
use ratatui::widgets::Paragraph;
use ratatui::Frame;

use crate::theme;

/// Render a vertical list of label/value pairs with selection highlight.
pub fn render_props_form(frame: &mut Frame, area: Rect, fields: &[(&str, &str, bool)]) {
    let theme = theme::get();

    for (i, (label, value, selected)) in fields.iter().enumerate() {
        let y = area.y + i as u16;
        if y >= area.y + area.height {
            break;
        }

        let (label_style, value_style) = if *selected {
            (
                Style::default()
                    .fg(theme.hint.key)
                    .add_modifier(Modifier::BOLD),
                Style::default()
                    .fg(theme.ui.text_primary)
                    .bg(theme.ui.surface),
            )
        } else {
            (
                Style::default().fg(theme.ui.text_muted),
                Style::default().fg(theme.ui.text_primary),
            )
        };

        let label_area = Rect::new(area.x + 1, y, 14, 1);
        let value_area = Rect::new(area.x + 16, y, area.width.saturating_sub(18), 1);

        frame.render_widget(
            Paragraph::new(format!("{label}:")).style(label_style),
            label_area,
        );
        frame.render_widget(Paragraph::new(*value).style(value_style), value_area);
    }
}
