#pragma once

#include <RmlUi/Core.h>
#include <RmlUi/Debugger.h>
#include <RmlUi_Backend.h>
#include <format>
#include <string>

namespace UI::CaptureTheFlag {

class Page {
  public:
    Rml::ElementDocument *document = nullptr;

    void initialize(Rml::Context *context) {
        document = context->LoadDocument("build/assets/ui/pages/capture_the_flag/capture_the_flag.rml");
    }

    void show() {
        document->Show();
    }

    void hide() {
        document->Hide();
    }

    void update(int current_round, int red_score, int blue_score, uint32_t flag_carrier_ship_id, float flag_position_x, float flag_position_y) {
        auto set = [&](const char *id, const std::string &text) {
            if (auto element = document->GetElementById(id)) {
                element->SetInnerRML(text);
            }
        };

        set("current-round", std::format("Round: {}", current_round));
        set("red-score", std::format("Red: {}", red_score));
        set("blue-score", std::format("Blue: {}", blue_score));
        set("flag-carrier", std::format("Carrier: {}", flag_carrier_ship_id));
        set("flag-position", std::format("Flag: {:.1f}, {:.1f}", flag_position_x, flag_position_y));
    }
};

} // namespace UI::CaptureTheFlag
