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

#include "setupscreen.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"

SetupScreen::SetupScreen() : IScreen("setup") {
    SDL_Log("=> SetupScreen::SetupScreen");

    Locale *locale = Locale::getInstance();

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

    auto button_back = new Image(this,16,34,57,32,"button_back_blue.png");
    button_back->setCallback(CallbackType::EVENT_FINGER_UP,[]{
        AudioEffect::click();
        Engine::setActiveScreen("main");
    });

    auto text_setup = new Text(this,16,115);
    text_setup->setCached(true);
    text_setup->setText(locale->tr("Setup"),"inter.ttf",40,{255,255,255});

    // "звук"
    image_button_sound = new Image(this,16,257,328,78,"background_button_setup.png");
    image_button_sound->setCallback(CallbackType::EVENT_ON_CLICK,[this]{
        if (AudioEffect::sound_enable){
            image_button_setup_sound->setTexture("button_setup_off.png");
            AudioEffect::sound_enable=false;
            config.setStatusSound(false);
        }else{
            image_button_setup_sound->setTexture("button_setup_on.png");
            AudioEffect::sound_enable=true;
            config.setStatusSound(true);
        }
    });

    auto text_sound = new Text(this,image_button_sound->getFRect().x+20,image_button_sound->getFRect().y+27);
    text_sound->setCached(true);
    text_sound->setText(locale->tr("Sound"),"inter.ttf",20,{255,255,255});

    if (AudioEffect::sound_enable) {
        image_button_setup_sound = new Image(this,image_button_sound->getFRect().x + 248,
                                             image_button_sound->getFRect().y + 19, 60, 40,
                                             "button_setup_on.png");
    }else{
        image_button_setup_sound = new Image(this,image_button_sound->getFRect().x + 248,
                                             image_button_sound->getFRect().y + 19, 60, 40,
                                             "button_setup_off.png");
    }
    image_button_setup_sound->setCallback(CallbackType::EVENT_FINGER_UP,[]{
        //
    });


    // "Авторы"
    auto image_button_author = new Image(this,16,356,328,78,"background_button_setup.png");
    image_button_author->setCallback(CallbackType::EVENT_FINGER_UP,[]{
        AudioEffect::click();
        Engine::setActiveScreen("author");
    });

    auto text_author = new Text(this,image_button_author->getFRect().x+20,image_button_author->getFRect().y+27);
    text_author->setCached(true);
    text_author->setText(locale->tr("Authors"),"inter.ttf",20,{255,255,255});

}
