#include "field_select_button.h"

#include "RmlUi/Core/Factory.h"

namespace UI::FieldSelectButton {

void Component::OnAttributeChange(const Rml::ElementAttributes &changed) {
    Rml::Element::OnAttributeChange(changed);

    if (!built) {
        built = true;
        Build();
    }

    if (auto it = changed.find("value"); it != changed.end() && value_display) {
        value_display->SetInnerRML(it->second.Get<Rml::String>());
    }
}

void Component::Build() {
    Rml::XMLAttributes attrs;
    auto child = Rml::Factory::InstanceElement(this, "div", "div", attrs);
    value_display = child.get();
    AppendChild(std::move(child));
}

} // namespace UI::FieldSelectButton
