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

bool BuoyancyInfoEditor::renderComponent(flecs::entity entity,
					 BuoyancyInfo &buoyancyInfo)
{
	bool modified = false;

	if (ImGui::CollapsingHeader("Buoyancy Info",
				    ImGuiTreeNodeFlags_DefaultOpen)) {
		ImGui::Indent();

		// Enabled checkbox
		if (ImGui::Checkbox("Enabled", &buoyancyInfo.enabled)) {
			buoyancyInfo.markDirty();
			modified = true;
		}
		if (ImGui::IsItemHovered()) {
			ImGui::SetTooltip(
				"Enable or disable buoyancy for this entity");
		}

		ImGui::Separator();

		// Buoyancy strength
		if (ImGui::DragFloat("Buoyancy Strength",
				     &buoyancyInfo.buoyancy, 0.01f, 0.0f,
				     5.0f)) {
			buoyancyInfo.markDirty();
			modified = true;
		}
		if (ImGui::IsItemHovered()) {
			ImGui::SetTooltip(
				"0 = no buoyancy, 1 = neutral buoyancy, >1 = floats");
		}

		// Linear drag
		if (ImGui::DragFloat("Linear Drag", &buoyancyInfo.linearDrag,
				     0.01f, 0.0f, 1.0f)) {
			buoyancyInfo.markDirty();
			modified = true;
		}
		if (ImGui::IsItemHovered()) {
			ImGui::SetTooltip(
				"Drag force applied to linear movement when submerged (0-1)");
		}

		// Angular drag
		if (ImGui::DragFloat("Angular Drag", &buoyancyInfo.angularDrag,
				     0.01f, 0.0f, 1.0f)) {
			buoyancyInfo.markDirty();
			modified = true;
		}
		if (ImGui::IsItemHovered()) {
			ImGui::SetTooltip(
				"Drag force applied to rotation when submerged (0-1)");
		}

		// Submerged threshold
		if (ImGui::DragFloat("Submerged Threshold",
				     &buoyancyInfo.submergedThreshold, 0.01f,
				     0.0f, 1.0f)) {
			buoyancyInfo.markDirty();
			modified = true;
		}
		if (ImGui::IsItemHovered()) {
			ImGui::SetTooltip(
				"How much of the body must be submerged before buoyancy applies (0-1)");
		}

		ImGui::Separator();

		// Custom water level
		if (ImGui::Checkbox("Use Custom Water Level",
				    &buoyancyInfo.useCustomWaterLevel)) {
			buoyancyInfo.markDirty();
			modified = true;
		}
		if (ImGui::IsItemHovered()) {
			ImGui::SetTooltip(
				"Use custom water surface level for this entity instead of global");
		}

		if (buoyancyInfo.useCustomWaterLevel) {
			if (ImGui::DragFloat("Water Surface Y",
					     &buoyancyInfo.waterSurfaceY, 0.1f,
					     -100.0f, 100.0f)) {
				buoyancyInfo.markDirty();
				modified = true;
			}
			if (ImGui::IsItemHovered()) {
				ImGui::SetTooltip(
					"Water surface Y coordinate in world space");
			}
		} else {
			ImGui::Text("Using global water level");
		}

		ImGui::Unindent();
	}

	return modified;
}