use super::control_panel::ControlPanelModel;
use gtk::prelude::{
    ApplicationExt, ButtonExt, DialogExt, GtkWindowExt, ToggleButtonExt, WidgetExt,
};
use relm4::*;

#[derive(Debug)]
pub enum AppMode {
    View,
    Edit,
    Export,
}

#[derive(Debug)]
pub enum AppMsg {
    SetMode(AppMode),
    CloseRequest,
    Close,
}

pub struct AppModel {
    mode: AppMode,
    control: Controller<ControlPanelModel>,
}

#[relm4::component(pub)]
impl SimpleComponent for AppModel {
    type Init = AppMode;
    type Input = AppMsg;
    type Output = ();

    view! {
        main_window = gtk::Window {
            set_default_width: 500,
            set_default_height: 250,
            set_titlebar: Some(&gtk::HeaderBar::new()),
            connect_close_request[sender] => move |_| {
                sender.input(AppMsg::CloseRequest);
                gtk::Inhibit(true)
            }
        }
    }

    fn init(
        params: Self::Init,
        root: &Self::Root,
        sender: ComponentSender<Self>,
    ) -> ComponentParts<Self> {
        let control = ControlPanelModel::builder()
            .launch(0)
            .forward(sender.input_sender(), |msg| AppMsg::Close);
        let model = AppModel {
            mode: AppMode::View,
            control: control,
        };
        let widgets = view_output!();
        ComponentParts { model, widgets }
    }

    fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {}
}
