//
// Created by sasha on 28.11.2025.
//

#ifndef RU_DANSOFT_PUZZLE15_BOARD_H
#define RU_DANSOFT_PUZZLE15_BOARD_H

#include <vector>

#include "engine/widgets/iwidget.h"
#include "engine/widgets/image.h"
#include "cube.h"

class Board : public IWidget {
    public:
        Board(IWidget *parent, float x, float y);
        ~Board();

        bool createBoard(const std::string &type);
        bool intermix();

        void event(const SDL_Event &event) override;

        void onTurn(std::function<void()> func);
        void onWon(std::function<void()> func);

    private:
        Image *background;

        std::string type;
        std::vector<Cube*> listCubes;

        void onClickCube(Cube *cube);
        bool cubeMove(Cube *cube);
        bool isExistCube(int pos_x, int pos_y);
        Cube* searchCube(int pos_x, int pos_y);

        int board_size=3;
        float board_size_cube = 92;
        float board_spacing = 6;

        bool isWon();

        std::map<std::string,std::function<void()>> callbacks;
};


#endif //RU_DANSOFT_PUZZLE15_BOARD_H
