#ifndef WATER_PLANE_EDITOR_HPP
#define WATER_PLANE_EDITOR_HPP
#pragma once

#include "ComponentEditor.hpp"
#include "../components/WaterPlane.hpp"

/**
 * Editor for WaterPlane component
 */
class WaterPlaneEditor : public ComponentEditor<WaterPlane> {
public:
	bool renderComponent(flecs::entity entity,
			     WaterPlane &component) override
	{
		bool changed = false;

		ImGui::PushID("WaterPlane");
		ImGui::Text("Water Surface");
		ImGui::Separator();

		if (ImGui::Checkbox("Enabled", &component.enabled)) {
			changed = true;
			component.markDirty();
		}

		if (ImGui::Checkbox("Auto-update from Water Physics",
				    &component.autoUpdateFromWaterPhysics)) {
			changed = true;
		}

		if (!component.autoUpdateFromWaterPhysics) {
			if (ImGui::SliderFloat("Water Surface Y",
					       &component.waterSurfaceY, -10.0f,
					       10.0f, "%.2f")) {
				changed = true;
				component.markDirty();
			}
		} else {
			ImGui::Text(
				"Water Surface Y: %.2f (from Water Physics)",
				component.waterSurfaceY);
		}

		if (ImGui::SliderFloat("Plane Size", &component.planeSize,
				       100.0f, 2000.0f, "%.0f")) {
			changed = true;
			component.markDirty();
		}

		if (ImGui::SliderInt("RTT Size", &component.renderTextureSize,
				     128, 1024)) {
			changed = true;
			component.markDirty();
		}

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

		float color[4] = { component.waterColor.r, component.waterColor.g,
				   component.waterColor.b, component.waterColor.a };
		if (ImGui::ColorEdit4("Water Color", color,
				      ImGuiColorEditFlags_AlphaBar)) {
			component.waterColor = Ogre::ColourValue(
				color[0], color[1], color[2], color[3]);
			changed = true;
		}

		if (ImGui::SliderFloat("Reflectivity", &component.reflectivity,
				       0.0f, 1.0f, "%.2f")) {
			changed = true;
		}

		if (ImGui::SliderFloat("Wave Speed", &component.waveSpeed, 0.0f,
				       5.0f, "%.2f")) {
			changed = true;
		}

		if (ImGui::SliderFloat("Wave Scale", &component.waveScale, 0.0f,
				       0.2f, "%.3f")) {
			changed = true;
		}

		if (ImGui::SliderFloat("Tiling", &component.tiling, 0.001f,
				       0.1f, "%.3f")) {
			changed = true;
		}

		ImGui::Separator();
		if (ImGui::Button("Reset to Defaults")) {
			component = WaterPlane();
			changed = true;
			component.markDirty();
		}
		ImGui::PopID();

		return changed;
	}

	const char *getName() const override
	{
		return "Water Plane";
	}
};

#endif // WATER_PLANE_EDITOR_HPP
