use eframe::{egui, epi};

use crate::app;
use crate::core::irc::ConnectionStatus;

pub struct Menu {}

impl Default for Menu {
    fn default() -> Self {
        Self {}
    }
}

impl Menu {
    fn show_connection_button(app: &mut app::Steel, ui: &mut eframe::egui::Ui) {
        let (action, enabled) = match app.connection() {
            ConnectionStatus::Disconnected => ("connect", true),
            ConnectionStatus::InProgress => ("connecting...", false),
            ConnectionStatus::Connected => ("disconnect", true),
        };
        if ui.add_enabled(enabled, egui::Button::new(action)).clicked() {
            match app.connection() {
                ConnectionStatus::Disconnected => app.connect(),
                ConnectionStatus::InProgress => (),
                ConnectionStatus::Connected => app.disconnect(),
            }
        }
    }

    pub fn show_with_dependencies(
        &mut self,
        app: &mut app::Steel,
        ctx: &egui::CtxRef,
        _frame: &epi::Frame,
        show_settings: &mut bool,
        show_logviewer: &mut bool,
    ) {
        egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
            egui::menu::bar(ui, |ui| {
                if ui.button("settings").clicked() {
                    *show_settings = !*show_settings;
                }
                Self::show_connection_button(app, ui);
                if ui.button("log viewer").clicked() {
                    *show_logviewer = !*show_logviewer;
                }
            });
        });
    }
}
