#include <Widget/Portal/Portal.hpp>

Portal::Portal(GetWidgetCallback getCurrentWidget) : getCurrentWidget(getCurrentWidget) {}

void Portal::draw(GraphicsContext &context)
{
    Widget *currentWidget = getCurrentWidget();
    if (currentWidget != nullptr)
    {
        currentWidget->widgetAbsPos = widgetAbsPos;
        currentWidget->draw(context);
    }
}

glm::ivec2 Portal::getMinSize()
{
    Widget *currentWidget = getCurrentWidget();
    if (currentWidget != nullptr)
    {
        return currentWidget->getMinSize();
    }
    
    return glm::ivec2(0);
}

void Portal::onResize(glm::ivec2 newSize)
{
    Widget::onResize(newSize);

    Widget *currentWidget = getCurrentWidget();
    if (currentWidget != nullptr)
    {
        currentWidget->onResize(newSize);
    }
}

void Portal::onMouseMoved(glm::ivec2 pos)
{
    Widget::onMouseMoved(pos);

    Widget *currentWidget = getCurrentWidget();
    if (currentWidget != nullptr)
    {
        currentWidget->onMouseMoved(pos);
    }
}

void Portal::onMouseDown(Uint8 button)
{
    Widget::onMouseDown(button);

    Widget *currentWidget = getCurrentWidget();
    if (currentWidget != nullptr)
    {
        currentWidget->onMouseDown(button);
    }
}

void Portal::onMouseUp(Uint8 button)
{
    Widget::onMouseUp(button);

    Widget *currentWidget = getCurrentWidget();
    if (currentWidget != nullptr)
    {
        currentWidget->onMouseUp(button);
    }
}

void Portal::onScroll(int delta)
{
    Widget::onScroll(delta);

    Widget *currentWidget = getCurrentWidget();
    if (currentWidget != nullptr)
    {
        currentWidget->onScroll(delta);
    }
}

void Portal::getInternalTabOrder(std::vector<Widget*> &tabOrder)
{
    Widget *currentWidget = getCurrentWidget();
    if (currentWidget != nullptr)
    {
        currentWidget->getInternalTabOrder(tabOrder);
    }
}