//! Section header with horizontal divider for engine-view panels.

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

use crate::theme;

/// Render a section title with a horizontal divider below it.
pub fn render_section_header(frame: &mut Frame, title: &str, focused: bool, area: Rect) {
    let theme = theme::get();
    let [header_area, divider_area] =
        Layout::vertical([Constraint::Length(1), Constraint::Length(1)]).areas(area);

    let header_style = if focused {
        Style::new()
            .fg(theme.engine.header_focused)
            .add_modifier(Modifier::BOLD)
    } else {
        Style::new()
            .fg(theme.engine.header)
            .add_modifier(Modifier::BOLD)
    };

    frame.render_widget(Paragraph::new(title).style(header_style), header_area);

    let divider = "─".repeat(area.width as usize);
    frame.render_widget(
        Paragraph::new(divider).style(Style::new().fg(theme.engine.divider)),
        divider_area,
    );
}
