#include "field_select.h"

#include "RmlUi/Core/Event.h"
#include "spdlog/spdlog.h"

namespace UI::FieldSelect {

void ClickListener::ProcessEvent(Rml::Event &) {
    component->is_open = !component->is_open;

    SPDLOG_INFO("field-select clicked, is_open: {}", component->is_open);

    component->SetClass("field-select-expanded", component->is_open);
}

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

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

    Update();
}

void Component::Build() {
    click_listener = new ClickListener(this);
    AddEventListener("click", click_listener);

    SetAttribute("class", "field-select");
}

void Component::Update() {
}

} // namespace UI::FieldSelect
