#pragma once

#include <glm/glm.hpp>
#include <memory>
#include "loader/GLLoader.h"
#include "render/shaders/WorldShader.h"
#include "render/shaders/EntityShader.h"

namespace td {
namespace render {

class Renderer {
public:
    static constexpr float m_AnimationSpeed = 2.0f;

    struct Model {
        GL::VertexArray* vao;
        glm::vec2 positon;
    };
private:
    std::unique_ptr<shader::WorldShader> m_WorldShader;
    std::unique_ptr<shader::EntityShader> m_EntityShader;

    glm::vec3 m_BackgroundColor;

    bool m_IsometricView = true;
    float m_IsometricShade = m_IsometricView;
    glm::vec2 m_CamPos{};
public:
    Renderer();
    ~Renderer();

    bool Init();

    void Prepare();
    void Resize(const int width, const int height);

    void RenderVAO(const GL::VertexArray& vao);
    void RenderModel(const Model& model);

    void SetZoom(float zoom);
    void SetCamMovement(const glm::vec2& mov);
    void SetCamPos(const glm::vec2& newPos);
    void SetIsometricView(bool isometric); // false = 2D       true = Isometric

    void SetBackgroundColor(const glm::vec3& color) { m_BackgroundColor = color; }

    glm::vec2 GetCursorWorldPos(const glm::vec2& cursorPos, float aspectRatio, float zoom, float windowWidth, float windowHeight);
private:
    void UpdateIsometricView();
    void UpdateIsometricFade();
    void InitShaders();
};

} // namespace render
} // namespace td
