//
// Created by sebastian on 12.02.26.
//

#include "UiButton.h"

#include <utility>

#include "UiText.h"

UiButton::UiButton(const GLuint textureID, std::string label, Font &font, const LayoutStyle &style): textureID(textureID), text(std::move(label)), font(font), UiComponent(style) {
}

void UiButton::onClick() {
    if (clickListener) {
        clickListener();
    }
}

void UiButton::onCollectRenderData(UiRenderBundle &uiRenderBundle) {
    glm::vec2 position = glm::vec2(uiPositioner.screenSpace.x, uiPositioner.screenSpace.y);
    glm::vec2 size = glm::vec2(uiPositioner.screenSpace.width, uiPositioner.screenSpace.height);

    VisualStyle visualStyle = getVisualStyle();
    uiRenderBundle.addGUITexture(
        std::make_shared<GUITexture>(
            textureID,
            position,
            size,
            visualStyle.brightness,
            visualStyle.tintColor,
            visualStyle.tintStrength
        )
    );

    uiRenderBundle.addGUIText(std::make_shared<GUIText>(font, text, uiPositioner.screenSpace));
}

VisualStyle UiButton::getVisualStyle() const {
    switch (state) {
        case UiState::PRESSED:
            return {1.0f, glm::vec3(0.3, 0.6, 1.0), 0.15f};
        case UiState::HOVERED:
            return {1.15f, glm::vec3(0.0f), 0.0f};
        default:
            return {};
    }
}
