#pragma once

#include "widget.h"
#include "pushbutton.h"
#include "core/corefactory.h"
#include "core/rectangle.h"
#include "core/vector.h"
#include "core/text.h"

class Window : public Widget
{
public:
    explicit Window(const std::shared_ptr<kku::CoreFactory>& factory, const std::string& title);

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

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

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

    void addBarButton(const std::string& text, kku::lambda callback);

protected:
    std::shared_ptr<kku::Rectangle> _bar;
    std::shared_ptr<kku::Rectangle> _window_content;
    std::shared_ptr<kku::Text> _bar_title;

    const std::shared_ptr<kku::CoreFactory> _core_factory;

private:
    bool _is_dragging;
    kku::Point _previous_click_position;
};

