//
// Created by sasha on 27.11.2025.
//

#ifndef RU_DANSOFT_PUZZLE15_IWIDGET_H
#define RU_DANSOFT_PUZZLE15_IWIDGET_H

#include <SDL3/SDL.h>

#include <string>
#include <map>
#include <functional>

enum CallbackType {
    EVENT_FINGER_DOWN,
    EVENT_FINGER_UP,
    EVENT_ON_CLICK,
};


class IWidget {
    public:
        IWidget(IWidget* parent, float x,float y, float width, float height);
        virtual ~IWidget();

        SDL_FRect getScaleFRect();

        // Получение физических значений
        SDL_FRect getFRect();

        void setSize(float width, float height);
        void move(float x, float y);

        // Установить callback на событие
        void setCallback(CallbackType type,std::function<void()> func);

        void show();
        void hide();

        bool isVisible();

        void setName(const std::string &name);

        void drawAll();
        void eventAll(const SDL_Event &event);
        void iterateAll();

        void addWidget(IWidget *widget);
        void removeWidget(IWidget *widget);


    // virtual
        virtual void draw();
        virtual void event(const SDL_Event &event);
        virtual void iterate();


    protected:
        IWidget *parent;

        float x;
        float y;
        float width;
        float height;

        std::string name;

        bool visible;

        Uint32 stateClick;

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

        std::vector<IWidget*> listWidgets;

};


#endif //RU_DANSOFT_PUZZLE15_IWIDGET_H
