#ifndef SKYBOX_EDITOR_HPP
#define SKYBOX_EDITOR_HPP
#pragma once

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

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

		ImGui::Text("Procedural Skybox");
		ImGui::Separator();

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

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

		ImGui::Separator();
		ImGui::Text("Day Colors");

		float dayTop[3] = { component.dayTopColor.r, component.dayTopColor.g,
				    component.dayTopColor.b };
		if (ImGui::ColorEdit3("Day Top", dayTop)) {
			component.dayTopColor = Ogre::ColourValue(dayTop[0], dayTop[1],
							  dayTop[2]);
			changed = true;
		}

		float dayBot[3] = { component.dayBottomColor.r,
				    component.dayBottomColor.g,
				    component.dayBottomColor.b };
		if (ImGui::ColorEdit3("Day Bottom", dayBot)) {
			component.dayBottomColor = Ogre::ColourValue(
				dayBot[0], dayBot[1], dayBot[2]);
			changed = true;
		}

		ImGui::Separator();
		ImGui::Text("Night Colors");

		float nightTop[3] = { component.nightTopColor.r,
				      component.nightTopColor.g,
				      component.nightTopColor.b };
		if (ImGui::ColorEdit3("Night Top", nightTop)) {
			component.nightTopColor = Ogre::ColourValue(
				nightTop[0], nightTop[1], nightTop[2]);
			changed = true;
		}

		float nightBot[3] = { component.nightBottomColor.r,
				      component.nightBottomColor.g,
				      component.nightBottomColor.b };
		if (ImGui::ColorEdit3("Night Bottom", nightBot)) {
			component.nightBottomColor = Ogre::ColourValue(
				nightBot[0], nightBot[1], nightBot[2]);
			changed = true;
		}

		ImGui::Separator();
		ImGui::Text("Horizon Glow");

		float sunrise[3] = { component.sunriseColor.r,
				     component.sunriseColor.g,
				     component.sunriseColor.b };
		if (ImGui::ColorEdit3("Sunrise", sunrise)) {
			component.sunriseColor = Ogre::ColourValue(
				sunrise[0], sunrise[1], sunrise[2]);
			changed = true;
		}

		float sunset[3] = { component.sunsetColor.r,
				    component.sunsetColor.g,
				    component.sunsetColor.b };
		if (ImGui::ColorEdit3("Sunset", sunset)) {
			component.sunsetColor = Ogre::ColourValue(
				sunset[0], sunset[1], sunset[2]);
			changed = true;
		}

		ImGui::Separator();
		ImGui::Text("Celestial Bodies");

		if (ImGui::SliderFloat("Sun Size", &component.sunSize, 0.01f, 0.2f,
				       "%.3f")) {
			changed = true;
		}
		if (ImGui::SliderFloat("Moon Size", &component.moonSize, 0.01f, 0.2f,
				       "%.3f")) {
			changed = true;
		}
		if (ImGui::Checkbox("Stars Enabled", &component.starsEnabled)) {
			changed = true;
		}

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

		return changed;
	}

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

#endif // SKYBOX_EDITOR_HPP
