use crate::util::constants;
use glib::{Object, Properties, prelude::*, subclass};
use gtk4::{Accessible, Buildable, CompositeTemplate, ConstraintTarget, Widget, subclass::prelude::*};
use libadwaita::{Bin, subclass::prelude::*};
use std::cell::Cell;

mod imp {

    use super::*;

    #[derive(Debug, Default, CompositeTemplate, Properties)]
    #[properties(wrapper_type = super::Selectable)]
    #[template(file = "data/resources/ui_templates/article_view/selectable.blp")]
    pub struct Selectable {
        #[property(get, set, default = constants::DEFAULT_ARTICLE_SELECTABLE_TEXT)]
        pub selectable: Cell<bool>,
    }

    #[glib::object_subclass]
    impl ObjectSubclass for Selectable {
        const NAME: &'static str = "Selectable";
        type Type = super::Selectable;
        type ParentType = Bin;

        fn class_init(klass: &mut Self::Class) {
            klass.bind_template();
        }

        fn instance_init(obj: &subclass::InitializingObject<Self>) {
            obj.init_template();
        }
    }

    #[glib::derived_properties]
    impl ObjectImpl for Selectable {
        fn constructed(&self) {
            self.parent_constructed();
        }
    }

    impl WidgetImpl for Selectable {}

    impl BinImpl for Selectable {}

    impl Selectable {}
}

glib::wrapper! {
    pub struct Selectable(ObjectSubclass<imp::Selectable>)
        @extends Widget, Bin,
        @implements Accessible, Buildable, ConstraintTarget;
}

impl Default for Selectable {
    fn default() -> Self {
        Object::new()
    }
}
