#include "CharacterEditor.hpp"
#include <imgui.h>

bool CharacterEditor::renderComponent(flecs::entity entity,
				      CharacterComponent &cc)
{
	(void)entity;
	bool modified = false;

	if (ImGui::Checkbox("Enabled##Character", &cc.enabled))
		modified = true;

	ImGui::Separator();
	ImGui::Text("Capsule");

	if (ImGui::SliderFloat("Radius##Character", &cc.radius, 0.05f, 2.0f,
				"%.2f")) {
		modified = true;
	}
	if (ImGui::SliderFloat("Height##Character", &cc.height, 0.1f, 5.0f,
				"%.2f")) {
		modified = true;
	}

	ImGui::TextDisabled("Total: %.2f m",
			    cc.getTotalHeight());

	ImGui::Separator();
	ImGui::Text("Offset");
	float off[3] = { cc.offset.x, cc.offset.y, cc.offset.z };
	if (ImGui::InputFloat3("Position##Character", off, "%.2f")) {
		cc.offset = Ogre::Vector3(off[0], off[1], off[2]);
		modified = true;
	}

	ImGui::Separator();
	ImGui::Text("Velocity");
	float vel[3] = { cc.linearVelocity.x, cc.linearVelocity.y,
			 cc.linearVelocity.z };
	if (ImGui::InputFloat3("Linear (m/s)##Character", vel, "%.2f")) {
		cc.linearVelocity = Ogre::Vector3(vel[0], vel[1],
						  vel[2]);
		modified = true;
	}

	ImGui::Separator();
	ImGui::Text("Floor Detection");
	if (ImGui::Checkbox("Use Gravity##Character", &cc.useGravity)) {
		modified = true;
	}
	if (ImGui::Checkbox("Has Floor##Character", &cc.hasFloor)) {
		modified = true;
	}
	if (ImGui::SliderFloat("Check Distance##Character",
			       &cc.floorCheckDistance, 0.1f, 10.0f,
			       "%.2f")) {
		modified = true;
	}

	if (modified)
		cc.dirty = true;

	return modified;
}
