//
// Created by sebastian on 10.02.26.
//

#ifndef DICEWARS_SIEDLER_UICOMPONENT_H
#define DICEWARS_SIEDLER_UICOMPONENT_H
#include <memory>
#include <vector>

#include "layout/UiPositioner.h"
#include "UiRenderBundle.h"
#include "../../../renderer/model/GUITexture.h"

enum class UiState {
    NORMAL, HOVERED, PRESSED
};


class UiComponent {
public:
    UiComponent() :uiPositioner(*this) {};
    UiComponent(const LayoutStyle& layout) : uiPositioner(*this, layout) {};
    virtual ~UiComponent() = default;
    void addChild(std::unique_ptr<UiComponent> child);
    void setVisible(bool visible);
    [[nodiscard]] bool isVisible() const;
    void update(float delta);
    void collectRenderData(UiRenderBundle& uiRenderBundle);
    virtual bool isMouseOver(float mouseX, float mouseY);
    UiComponent* parent = nullptr;
    UiPositioner uiPositioner;
    std::vector<std::unique_ptr<UiComponent>> children;

    LayoutStyle& getLayoutStyle() {
        return uiPositioner.getLayout();
    }
    void setLayoutStyle(const LayoutStyle& style) {
        uiPositioner.setLayout(style);
    }

    [[nodiscard]] bool isHovered() const { return state == UiState::HOVERED; }
    virtual void onClick() {};
protected:
    bool visible = true;
    UiState state = UiState::NORMAL;

    virtual void onUpdate(float );
    virtual void onCollectRenderData(UiRenderBundle& uiRenderBundle) {}

};


#endif //DICEWARS_SIEDLER_UICOMPONENT_H