mod imp;


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


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

impl CardDisplay {
    pub fn new(image_path: &String, hieroglyph: &String, reading: Option<&String>, translation: &String) -> Self {
        Object::builder()
            .property("imagepath", image_path)
            .property("translation", translation)
            .property("reading", reading)
            .property("hieroglyph", hieroglyph)
            .build()
    }

    pub fn update_file_for_image(&self) {
        let image_binding: &Image = self.imp().image.as_ref();
        let path: &str = &*self.imp().imagepath.borrow().clone().to_string();
        if path == "" {
            self.imp().error_message.set_visible(true);
            return;
        }
        image_binding.set_file(Some(&path));
    }

    pub fn get_answer_entry(&self) -> &Entry {
        self.imp().answer_entry.as_ref()
    }
}
