use crate::ui::UiExt;
use egui::{Align, FontFamily, Frame, Layout, RichText, Ui};

pub fn pane_header(
    ui: &mut Ui,
    title: &str,
    icon: Option<&str>,
    top_separator: bool,
    add_contents: impl FnOnce(&mut Ui),
) {
    if top_separator {
        ui.full_span_separator();
    }

    let mut frame = Frame::new();
    frame.inner_margin.left = 8;
    frame.inner_margin.right = 8;

    frame.show(ui, |ui| {
        ui.horizontal(|ui| {
            if let Some(icon) = icon {
                ui.label(
                    RichText::new(icon)
                        .family(FontFamily::Name("icon-only".into()))
                        .strong(),
                );
            }
            ui.label(
                RichText::new(title)
                    .family(FontFamily::Name("semibold".into()))
                    .strong(),
            );

            ui.with_layout(Layout::right_to_left(Align::Center), add_contents);
        });
    });

    ui.full_span_separator();
}
