#pragma once

#include "../core/Config.hpp"
#include "../ui/Button.hpp"
#include "../ui/ProgressBar.hpp"
#include "../ui/UIConstants.hpp"

#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>

#include <atomic>
#include <memory>
#include <mutex>
#include <string>
#include <thread>

namespace GModTeach {
namespace App {

class Application {
public:
    Application();
    ~Application();

    Application(const Application&) = delete;
    Application& operator=(const Application&) = delete;

    bool Initialize();
    void Shutdown();
    int Run();

private:
    void ProcessEvents();
    void Update();
    void Render();

    void CheckAndPromptConfiguration();
    void StartPipelineAsync(bool cleanAfterwards);
    void HandleActionWeb();
    void HandleActionReset();

private:
    SDL_Window* m_window = nullptr;
    SDL_Renderer* m_renderer = nullptr;
    TTF_Font* m_font = nullptr;
    SDL_Texture* m_titleTexture = nullptr;

    Core::AppConfig m_config;
    bool m_running = false;

    UI::Button m_btnOpenWeb;
    UI::Button m_btnInstall;
    UI::Button m_btnInstallClean;
    UI::Button m_btnResetConfig;

    UI::ProgressBar m_progressBar;
    SDL_Rect m_titleRect{};

    std::thread m_workerThread;
    std::atomic<bool> m_isProcessing{false};
    std::atomic<float> m_progress{0.0f};
    std::mutex m_statusMutex;
    std::string m_statusMessage;
};

} 
} 
