//
// Created by sasha on 01.12.2025.
//

#include "record_selector.h"

RecordSelector::RecordSelector(IWidget *parent, float x, float y) : IWidget (parent, x,y,328,78) {
    table = new Image(this,16,330, 328, 370,"record_table.png");

    selector = new Image(this,36,244,92, 55,"record_selector.png");

    text_3 = new Text(this,57,260);
    text_3->setCached(true);
    text_3->setCallback(CallbackType::EVENT_ON_CLICK,[this]{
        if (callbacksOnSelect){
            SDL_Log("select 3x3");
            selector->move(36,244);
            callbacksOnSelect("easy");
        }
    });
    text_3->setText("3 x 3","inter.ttf",20,{255,255,255});

    text_4 = new Text(this,155,260);
    text_4->setCached(true);
    text_4->setCallback(CallbackType::EVENT_ON_CLICK,[this]{
        if (callbacksOnSelect){
            SDL_Log("select 4x4");
            selector->move(134,244);
            callbacksOnSelect("normal");
        }
    });
    text_4->setText("4 x 4","inter.ttf",20,{255,255,255});

    text_5 = new Text(this,253,260);
    text_5->setCached(true);
    text_5->setCallback(CallbackType::EVENT_ON_CLICK,[this]{
        if (callbacksOnSelect){
            SDL_Log("select 5x5");
            selector->move(232,244);
            callbacksOnSelect("hard");
        }
    });
    text_5->setText("5 x 5","inter.ttf",20,{255,255,255});

}

RecordSelector::~RecordSelector() {
    delete table;
    delete selector;
    delete text_3;
    delete text_4;
    delete text_5;
}

void RecordSelector::onSelect(std::function<void(const std::string &type)> func) {
    callbacksOnSelect = func;
}

void RecordSelector::event(const SDL_Event &event) {
    IWidget::event(event);

    text_3->event(event);
    text_4->event(event);
    text_5->event(event);
}
