#pragma once

#include "../../GAME_COMMON.h"
#include "../../render/texture_quad.h"
#include "../ecs_entity.h"

#include "../../../engine/rectangle.h"
#include "../../../engine/glyph.h"

#define COMPONENT_TEXT_LIMIT 255
#define COMPONENT_TEXT_STRING_MAX 255
#define COMPONENT_TEXT_COLOR (f32*)COLOR_OPAQUE

typedef struct ComponentText
{
	ECSComponent component;
	vec3 position;
	vec4 color;
	vec2 scale;
	vec3 offset;
	Font* font;
	Texture glyphTextures[COMPONENT_TEXT_STRING_MAX];
	char string[COMPONENT_TEXT_STRING_MAX];
	u32 length;
	s32 wrap;
} ComponentText;

static const vec2 COMPONENT_TEXT_SCALE = {1.0f, 1.0f};

void component_text_rectangle_get(ComponentText* self, Rectangle* rectangle);
void component_text_string_set(ComponentText* self, char* string, u32 length);
void component_text_add(ComponentText* self, ECS* ecs);
void component_text_delete(ComponentText* self, ECS* ecs);
void component_text_draw(ComponentText* self, ECS* ecs);

void component_text_init
(
	ComponentText* self, 
	Font* font,
	char* string,
	u32 length,
	s32 wrap,
	vec3 position,
	vec4 color
);

static const ECSComponentInfo COMPONENT_TEXT_INFO = 
{
	.system = 
	{
		.functions = 
		{ 
			(ECSFunction)component_text_add, 
			(ECSFunction)component_text_delete, 
			NULL,
			(ECSFunction)component_text_draw
		}
	},
	.type = ECS_COMPONENT_TEXT,
	.size = sizeof(ComponentText)
};
