#pragma once
#include "../defs.h"
#include "../../utils/color.h"
#include "../../utils/point.h"
#include "../../utils/rect.h"

#include <SDL2/SDL.h>
#include <string>

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

  explicit RendererManager(Application *app);     // Constructor

  [[nodiscard]] SDL_Renderer *getSDLRenderer() const;     // Get the underlying SDL_Renderer

  void present() const;     // Present the rendered content to the screen

  void clear(const Color &color = Black) const;     // Clear the renderer with a specific color

  // Drawing primitives
  void drawRect(const Rect &rect, const Color &color, bool filled = false) const;     // Draw a rectangle
  void drawLine(const Point &start, const Point &end, const Color &color) const;      // Draw a line between two points
  void drawPoint(const Point &point, const Color &color) const;                       // Draw a single point

  // Text rendering
  void drawText(const std::string &text,     // Draw text at a specific position
                const HashID      &fontID,
                const Point       &point,
                const Color       &color    = White,
                int                fontSize = 24) const;
  void drawTextCentered(const std::string &text,     // Draw text centered within a rectangle
                        const HashID      &fontID,
                        const Rect        &rect,
                        const Color       &color    = White,
                        int                fontSize = 24) const;

  // Texture management
  void drawTexture(SDL_Texture *texture, const Rect &dest, const Rect &source = {}) const;     // Draw a texture at a specific position and size

  // Utilities
  void                    setDrawColor(const Color &color) const;     // Set the current drawing color
  void                    setClipRect(const Rect *rect) const;        // Set the clipping rectangle (nullptr to disable)
  [[nodiscard]] SDL_Point getWindowSize() const;                      // Get the current window size in pixels

  protected:
  Application *m_app = nullptr;

  private:
  Texture renderTextTexture(const std::string &text, TTF_Font *font, const Color &color) const;     // Render text to a texture for drawing
};
//------------------------------------------------------------
}     // namespace quokka_gfx
