#pragma once

#include "../../../GAME_COMMON.h"
#include "../../../input/input.h"
#include "../../ecs_entity.h"

#include "../component_text.h"
#include "../component_game_object.h"
#include "../animation/component_animation_color_change.h"

#include "../../entity/play/entity_streak.h"
#include "../../entity/play/entity_icon.h"

#define COMPONENT_STAT_DISPLAY_ANIMATION_COLOR_CHANGE_TIMER 30
#define COMPONENT_STAT_DISPLAY_ICON_X_OFFSET -32.0f
#define COMPONENT_STAT_DISPLAY_ICON_Z_OFFSET -0.01f
#define COMPONENT_STAT_DISPLAY_INACTIVE_TIMER 300
#define COMPONENT_STAT_DISPLAY_STREAK_Z_OFFSET 0.0f
#define COMPONENT_STAT_DISPLAY_STRING_FORMAT "%i/%i"
#define COMPONENT_STAT_DISPLAY_TEXT_COLOR (f32*)COLOR_OPAQUE
#define COMPONENT_STAT_DISPLAY_TEXT_FONT FONT_STAT_DISPLAY
#define COMPONENT_STAT_DISPLAY_TEXT_LENGTH_MAX 255
#define COMPONENT_STAT_DISPLAY_TEXT_X_OFFSET -8.0f
#define COMPONENT_STAT_DISPLAY_TEXT_Y_OFFSET -16.0f
#define COMPONENT_STAT_DISPLAY_TEXT_Z_OFFSET -0.02f
#define COMPONENT_STAT_DISPLAY_Z_OFFSET 0.1f

static const vec2 STAT_DISPLAY_ICON_SIZE = {40.0f, 40.0f};

typedef struct Stat
{
	ECSComponent component;
	s32 value;
	s32 max;
} Stat;

typedef struct ComponentStatDisplay
{
	ECSComponent component;
	ECSComponentType type;
	Stat previousStat;
	vec3 offset;
	vec3 position;
	u32 gameObjectID;
	u32 streakID;
	u32 iconID;
	u32 activeTimer;
	bool isInactive;
} ComponentStatDisplay;

void
component_stat_display_init
(
	ComponentStatDisplay* self, 
	ECS* ecs,
	vec3 offset,
	ECSComponentType type,
	u32 gameObjectID,
	IconType icon
);

static const vec2 STAT_DISPLAY_STREAK_SIZE = {128.0f, 32.0f};

void component_stat_display_add(ComponentStatDisplay* self, ECS* ecs);
void component_stat_display_delete(ComponentStatDisplay* self, ECS* ecs);
void component_stat_display_tick(ComponentStatDisplay* self, ECS* ecs);

static const ECSComponentInfo COMPONENT_STAT_DISPLAY_INFO = 
{
	.system = 
	{
		.functions = 
		{ 
			(ECSFunction)component_stat_display_add, 
			(ECSFunction)component_stat_display_delete, 
			(ECSFunction)component_stat_display_tick, 
			NULL
		}
	},
	.type = ECS_COMPONENT_STAT_DISPLAY,
	.size = sizeof(ComponentStatDisplay)
};


