#pragma once

#include "../application.h"
#include "../events/eventBus.h"
#include "../events/inputManager.h"
#include "quokka_gfx/utils/rect.h"

namespace quokka_gfx
{
class RendererManager;
//------------------------------------------------------------
class Screen : public Listener
{
  public:
  Screen()                             = delete;      // Default constructor
  virtual ~Screen()                    = default;     // Default destructor
  Screen(const Screen &obj)            = delete;      // Copy constructor
  Screen(Screen &&obj)                 = delete;      // Move constructor
  Screen &operator=(const Screen &obj) = delete;      // Copy assignment operator
  Screen &operator=(Screen &&obj)      = delete;      // Move assignment operator

  explicit Screen(Application *app);     // Constructor

  virtual void on_enter()                        = 0;     // Called when the screen is entered
  virtual void on_exit()                         = 0;     // Called when the screen is exited
  virtual void handleEvents()                    = 0;     // Manage events
  virtual void update(const double deltaTime)    = 0;     // Update the logic of the screen
  virtual void render(RendererManager *renderer) = 0;     // Render the screen

  [[nodiscard]] InputManager *getInputManager() const;     // Get the input manager for handling events

  Rect getScreenRect() const;     // Return the window size as a rectangle for easy rendering and event handling

  protected:
  Application *m_app = nullptr;     // Pointer to the application
};
//------------------------------------------------------------
/* Constructor */
inline Screen::Screen(Application *app)
{
  m_app = app;
}
//------------------------------------------------------------
/* Get the input manager for handling events */
inline InputManager *Screen::getInputManager() const
{
  return m_app->m_inputManager.get();
}
//------------------------------------------------------------
/* Return the window size as a rectangle for easy rendering and event handling */
inline Rect Screen::getScreenRect() const
{
  if (!m_app || !m_app->m_window)
    return {};

  int width, height;
  SDL_GetWindowSize(m_app->m_window, &width, &height);
  return Rect(0, 0, width, height);
}
//------------------------------------------------------------
}     // namespace quokka_gfx
