//! Bottom-bar keyboard hint renderer.

use ratatui::text::{Line, Span};
use ratatui::style::Style;

use crate::theme;

/// Build a styled line of key/action pairs for the hint bar.
pub fn hint_line(pairs: &[(&str, &str)]) -> Line<'static> {
    let theme = theme::get();
    let key_style = Style::default().fg(theme.hint.key);
    let text_style = Style::default().fg(theme.hint.text);

    let spans: Vec<Span> = pairs
        .iter()
        .enumerate()
        .flat_map(|(i, (key, action))| {
            let mut s = vec![
                Span::styled(key.to_string(), key_style),
                Span::styled(format!(" {action}"), text_style),
            ];
            if i + 1 < pairs.len() {
                s.push(Span::styled("  ", text_style));
            }
            s
        })
        .collect();

    Line::from(spans)
}
