#pragma once

#include <math/vec2.hpp>
#include <math/vec4.hpp>
#include <renderer/programs/renderer_program.hpp>
#include <span>

namespace lt {

class Shader;
class VertexBuffer;
class IndexBuffer;
class VertexLayout;
class OrthographicCamera;
class SharedContext;

class TintedTextureRendererProgram: RendererProgram
{
public:
	~TintedTextureRendererProgram() override = default;
	struct TintedTextureVertexData
	{
		math::vec4 position;

		math::vec4 tint;

		math::vec2 texcoord;
	};

	TintedTextureRendererProgram(
	    unsigned int max_vertices,
	    const Ref<SharedContext> &shared_context,
	    Ref<Shader> shader
	);

	auto advance() -> bool;

	void map() override;

	void un_map() override;

	void bind() override;

	auto get_map_current() -> TintedTextureVertexData *
	{
		return &m_map[m_idx];
	}

	[[nodiscard]] auto get_quad_count() const -> unsigned int
	{
		return m_quad_count;
	}

	[[nodiscard]] constexpr auto get_vertex_size() const -> unsigned int
	{
		return sizeof(TintedTextureVertexData);
	}

private:
	Ref<Shader> m_shader;

	Ref<VertexBuffer> m_vertex_buffer;

	Ref<IndexBuffer> m_index_buffer;

	Ref<VertexLayout> m_vertex_layout;

	std::span<TintedTextureVertexData> m_map;

	size_t m_idx {};

	unsigned int m_quad_count { 0u };

	unsigned int m_max_vertices;
};

} // namespace lt
