#pragma once

#include "Widget.h"
#include "Color.h"

#include <functional>
#include <string>

class PaintEvent;
class MouseEvent;
class TextNode;

class Button : public Widget
{
public:
    using clickFunc = std::function<void(Widget* self)>;

    Button();

    ~Button();

    static std::unique_ptr<Button> Create();

    void setLabel(const std::string& text);

    void setOnClickFunction(clickFunc func);

protected:
    void onMyMouseEvent(const MouseEvent* event) override;

    bool isDirty() const override;
    void doPaint(const PaintEvent* event) override;

    void updateLabel(const PaintEvent* event);

private:
    std::string mLabel;
    clickFunc mClickFunc;
    Color mCachedColor;
    Color mClickedColor;

    std::unique_ptr<TextNode> mTextNode;
    bool mContentDirty{true};
};

using ButtonUPtr = std::unique_ptr<Button>;
