#pragma once
#include <functional>

#include "Label.h"
#include "SFML/Graphics/RectangleShape.hpp"
#include "SFML/Graphics/RenderWindow.hpp"

class Button {
private:
    sf::RectangleShape buttonRect;
    Label label;
    bool selected = false;

    std::function<void()> onClick;
public:
    Button(const std::string &labelString, sf::Vector2f position, const std::function<void()>& _onClick = []() {});

    void setText(const std::string &labelString);
    void render(sf::RenderWindow& window) const;
    void update(const float deltaTime);
    void eventHandler(const sf::Event& event);

    void setOnClick(const std::function<void()>& _onClick) { onClick = _onClick; }

    void setSelected(const bool _selected) {
        if (_selected == selected) return;
        selected = _selected;
        label.setDarkMode(selected);

        if (selected) buttonRect.setFillColor({255, 255, 255});
        else buttonRect.setFillColor({0, 0, 0, 64});
    };
};
