#pragma once

#include "RmlUi/Core/Element.h"
#include "RmlUi/Core/EventListener.h"

namespace UI::FieldSelectOption {

class Component;

class OptionClickListener : public Rml::EventListener {
  public:
    OptionClickListener(Component *component) : component(component) {}

    void ProcessEvent(Rml::Event &) override;

  private:
    Component *component = nullptr;
};

class Component : public Rml::Element {
  public:
    int option_value = 0;

    Component(const Rml::String &tag) : Rml::Element(tag) {}

    void on_click_option(int idx);

  protected:
    void OnAttributeChange(const Rml::ElementAttributes &changed) override;

  private:
    bool built = false;

    OptionClickListener *click_listener = nullptr;

    void Build();
    void Update();
};

} // namespace UI::FieldSelectOption
