#include "mainMenuScreen.h"

#include "assets/home.jpg.h"

#include <algorithm>

using namespace std;
using namespace quokka_gfx;
//------------------------------------------------------------
/* Constructor */
MainMenuScreen::MainMenuScreen(Application *app)
  : Screen(app)
{
}
//------------------------------------------------------------
/* Called when the screen is entered */
void MainMenuScreen::on_enter()
{
  m_app->assetManager()->loadTexture(toID("IMG_HOME"), home_jpg);     // Load the home image texture from the embedded data

  SDL_ShowCursor(SDL_DISABLE);
}
//------------------------------------------------------------
/* Called when the screen is exited */
void MainMenuScreen::on_exit()
{
}
//------------------------------------------------------------
/* Manage events */
void MainMenuScreen::handleEvents()
{
  const auto inputManager = getInputManager();
  if (!inputManager)
    return;
}
//------------------------------------------------------------
/* Update the logic of the screen */
void MainMenuScreen::update(const double deltaTime)
{
  // Fade in effect: increase alpha until it reaches the maximum
  m_alpha += (static_cast<float>(deltaTime) / FADE_IN_DURATION) * FADE_IN_MAX_ALPHA;     // Increase alpha based on delta time
  m_alpha = std::min(m_alpha, FADE_IN_MAX_ALPHA);                                        // Clamp alpha to the maximum
}
//------------------------------------------------------------
/* Render the screen */
void MainMenuScreen::render(RendererManager *renderer)
{
  // Draw the background image
  const auto &background = m_app->assetManager()->getTexture(toID("IMG_HOME"));
  if (background)
    renderer->drawTexture(background, Rect(0, 0, 1200, 896));

  // Draw the fade-in effect
  const auto m_screenRect = getScreenRect();
  const auto color        = Color(0, 0, 0, static_cast<Uint8>(m_alpha * 255));     // Set the color with alpha for fade-in effect
  renderer->drawRect(m_screenRect, color, true);
}
//------------------------------------------------------------
