use crate::{backend::Contact, prelude::*};

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

impl ContactItemCompact {
    pub fn new(contact: Contact) -> Self {
        log::trace!("Initializing `ContactItemCompact`");
        Object::builder::<Self>()
            .property("contact", contact)
            .build()
    }
}

pub mod imp {
    use crate::prelude::*;

    use glib::subclass::InitializingObject;
    use gtk::{CompositeTemplate, Widget};

    use crate::backend::Contact;

    #[derive(CompositeTemplate, Default, glib::Properties)]
    #[properties(wrapper_type = super::ContactItemCompact)]
    #[template(resource = "/ui/contact_item_compact.ui")]
    pub struct ContactItemCompact {
        #[property(get, set)]
        contact: RefCell<Option<Contact>>,
        #[property(get, set)]
        suffix: RefCell<Option<Widget>>,
    }

    #[glib::object_subclass]
    impl ObjectSubclass for ContactItemCompact {
        const NAME: &'static str = "FlContactItemCompact";
        type Type = super::ContactItemCompact;
        type ParentType = gtk::Box;

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

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

    #[glib::derived_properties]
    impl ObjectImpl for ContactItemCompact {}

    impl WidgetImpl for ContactItemCompact {}
    impl BoxImpl for ContactItemCompact {}
}
