use crate::emulator::ui::interface::{Category, EmulatorUI};

pub fn render_menu(state: &mut EmulatorUI, ui: &mut egui::Ui, _ctx: &egui::Context) {
    ui.with_layout(
        egui::Layout::top_down_justified(egui::Align::Center),
        |ui| {
            ui.set_max_width(300.0);
            ui.set_min_width(300.0);
            ui.spacing_mut().button_padding = egui::vec2(10.0, 5.0);

            for cat in Category::list() {
                ui.add_space(10.0);
                ui.heading(cat.as_str());
                ui.add_space(10.0);

                for comp in &mut state.components {
                    let name = comp.name();
                    if comp.category() == cat {
                        ui.toggle_value(comp.visible(), name);
                    }
                }

                ui.add_space(10.0);
                ui.separator();
            }

            ui.add_space(10.0);
        },
    );
}
