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

#include "UiComponent.h"

void UiComponent::addChild(std::unique_ptr<UiComponent> child) {
    child->parent = this;
    children.emplace_back(std::move(child));
}

void UiComponent::setVisible(const bool v) {
    this->visible = v;
}

bool UiComponent::isVisible() const {
    return visible;
}

void UiComponent::update(float delta) {
    if (!visible) return;

    onUpdate(delta);

    for (const auto &child : children) {
        child->update(delta);
    }
}

void UiComponent::collectRenderData(UiRenderBundle& uiRenderBundle) {
    if (!visible) return;

    onCollectRenderData(uiRenderBundle);

    for (const auto &child : children) {
        child->collectRenderData(uiRenderBundle);
    }
}

bool UiComponent::isMouseOver(float mouseX, float mouseY) {
    if (!visible) return false;
    return uiPositioner.screenSpace.contains(mouseX, mouseY);
}
