use glib::Object;
use gtk::{prelude::*, subclass::prelude::*};

#[derive(Default)]
pub struct LabeledFieldPrivate {
    value: gtk::Label,
}

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

impl ObjectImpl for LabeledFieldPrivate {}
impl WidgetImpl for LabeledFieldPrivate {}
impl BoxImpl for LabeledFieldPrivate {}

glib::wrapper! {
    pub struct LabeledField(ObjectSubclass<LabeledFieldPrivate>) @extends gtk::Box, gtk::Widget;
}

impl LabeledField {
    pub fn new(label: &str, default_value: &str) -> Self {
        let field: Self = Object::builder().build();
        field.set_hexpand(true);
        field.set_spacing(8);
        field.set_homogeneous(true);
        field.append(&gtk::Label::new(Some(label)));
        field.append(&field.imp().value);
        field.imp().value.set_label(default_value);
        field
    }

    pub fn set_value(&self, value: &str) {
        self.imp().value.set_label(value);
    }
}
