mod imp;

use glib::Object;
use gtk::{
    gio,
    glib::{self, subclass::types::ObjectSubclassIsExt},
    prelude::*,
    Application, Button,
};

glib::wrapper! {
    pub struct MemoryCardsGameScene(ObjectSubclass<imp::MemoryCardsGameScene>)
        @extends gtk::ApplicationWindow, gtk::Window, gtk::Widget,
        @implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable,
                    gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager;
}

impl MemoryCardsGameScene {
    pub fn new(app: &Application) -> Self {
        Object::builder().property("application", app).build()
    }

    pub fn update_stats(&self) {
        self.imp().stats_label.set_text(&format!(
            "Correct|Incorrect: {}|{} ({:.2}%)",
            self.imp().correct.borrow(),
            self.imp().incorrect.borrow(),
            100.0 * f64::from(*self.imp().correct.borrow() as i32) / f64::from((*self.imp().incorrect.borrow() + *self.imp().correct.borrow()) as i32)
        ));
    }

    pub fn get_back_button(&self) -> &Button {
        self.imp().back_button.as_ref()
    }

    pub fn show_no_cards_msg(&self) {
        self.imp().card_display.set_visible(false);
        self.imp().stats_label.set_visible(false);
        self.imp().no_cards_label.set_visible(true);
    }
    pub fn hide_no_cards_msg(&self) {
        self.imp().card_display.set_visible(true);
        self.imp().stats_label.set_visible(true);
        self.imp().no_cards_label.set_visible(false);
    }
}
