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

#include "mainscreen.h"

#include "engine/engine.h"
#include "engine/widgets/image.h"
#include "engine/widgets/text.h"
#include "config_storage.h"

#include "audio_effect.h"
#include "engine/locale.h"

MainScreen::MainScreen() : IScreen("main") {
    this->setName("MainScreen");
    SDL_Log("=> MainScreen::MainScreen");

    ConfigStorage config;
    AudioEffect::sound_enable = config.statusSound();

    Locale *locale = Locale::getInstance();

    this->setBackgroundColor(0x57,0x74,0xD9);

    auto button_play = new Image(this,64,335,232,76,"button_play.png");
    button_play->setName("button_play");
    button_play->setCallback(CallbackType::EVENT_ON_CLICK,[]{
        AudioEffect::click();
        Engine::setActiveScreen("level_selection");
    });
    auto text_play = new Text(this,button_play->getFRect().x+99,button_play->getFRect().y+27);
    text_play->setCached(true);
    text_play->setText(locale->tr("Play"),"inter.ttf",18,{255,255,255});

    auto button_records = new Image(this,64,428,232,76,"button_records.png");
    button_records->setCallback(CallbackType::EVENT_ON_CLICK,[]{
        AudioEffect::click();
        Engine::setActiveScreen("records");
    });
    auto text_records = new Text(this,button_records->getFRect().x+92.5,button_records->getFRect().y+27);
    text_records->setCached(true);
    text_records->setText(locale->tr("Records"),"inter.ttf",18,{255,255,255});


    auto button_setup = new Image(this,153,544,55,55,"button_setup.png");
    button_setup->setCallback(CallbackType::EVENT_ON_CLICK,[]{
        AudioEffect::click();
        Engine::setActiveScreen("setup");
    });

    auto logo_circle = new Image(this,97.5,91,166,166,"image_circle.png");

    auto text_15 = new Text(this,79.5,142);
    text_15->setCached(true);
    text_15->setText(locale->tr("Puzzle-15"),"inter.ttf",40,{255,255,255});

    auto label2 = new Text(this,79.5,190);
    label2->setCached(true);
    label2->setText(locale->tr("Classic game"),"inter.ttf",12,{255,255,255});
    SDL_FRect rect = label2->getFRect();
    SDL_FRect rect_window = Engine::getTemplateWindowSize();
    label2->move((rect_window.w-rect.w)/2,rect.y);
}

void MainScreen::onActive(const VariantMap &args) {
    ConfigStorage config;
    statusSound = config.statusSound();
}
