#pragma once

#include <vector>
#include <memory>

#include "core/systemevent.h"
#include "core/rectangle.h"
#include "core/time.h"

class Widget : public std::enable_shared_from_this<Widget>
{
public:
    virtual ~Widget() = default;

    virtual void input(const kku::SystemEvent& event) = 0;
    virtual void update(const kku::microsec& dt) = 0;
    virtual void display() const = 0;
    virtual void move(const kku::Vector2<float>& delta) = 0;
    virtual bool isUnderMouse(const kku::Point& position) const = 0;

    virtual void setRect(const kku::Area<float>& rect) = 0;
    virtual kku::Area<float> getRect() const = 0;

    virtual void setPosition(const kku::Point& position) = 0;
    virtual kku::Point getPosition() const = 0;

    virtual void setVisibility(bool is_visible = true);
    bool isVisible() const;

    void addChild(const std::shared_ptr<Widget>& child);
    void setParent(const std::shared_ptr<Widget>& parent);

    void blockBy(const std::shared_ptr<Widget>& blocker);
    void unblock();

protected:
    std::vector<std::shared_ptr<Widget>> _children;
    std::shared_ptr<Widget> _parent;
    std::shared_ptr<Widget> _blocker;
    bool _is_visible = true;
};

