#ifndef EDITSCENE_WATERPLANE_HPP
#define EDITSCENE_WATERPLANE_HPP
#pragma once

#include <Ogre.h>

/**
 * WaterPlane component
 * Visual water surface with reflection/refraction
 * for the editScene editor. Lightweight and OpenGL ES 2.0 compatible.
 */
struct WaterPlane {
	// Enable/disable water
	bool enabled = true;

	// Water surface Y level (world space)
	float waterSurfaceY = -0.1f;

	// Plane size (width and depth)
	float planeSize = 500.0f;

	// Whether to update waterSurfaceY from WaterPhysics component
	bool autoUpdateFromWaterPhysics = true;

	// Visual settings
	Ogre::ColourValue waterColor = Ogre::ColourValue(0.0f, 0.3f, 0.5f,
							 0.8f);
	float reflectivity = 0.5f;
	float waveSpeed = 1.0f;
	float waveScale = 0.02f;
	float tiling = 0.012f;

	// Render texture size (power of two recommended)
	int renderTextureSize = 512;

	// Runtime objects (managed by EditorWaterPlaneSystem)
	Ogre::SceneNode *sceneNode = nullptr;
	Ogre::ManualObject *manualObject = nullptr;

	// Render-to-texture resources
	Ogre::TexturePtr renderTexture;
	Ogre::Camera *reflectionCamera = nullptr;
	Ogre::Camera *refractionCamera = nullptr;
	Ogre::Viewport *reflectionViewport = nullptr;
	Ogre::Viewport *refractionViewport = nullptr;
	Ogre::RenderTarget *renderTarget = nullptr;

	// Clip planes
	Ogre::Plane reflectionPlane;
	Ogre::Plane reflectionClipPlane;
	Ogre::Plane refractionClipPlane;

	// Camera following state
	Ogre::Vector3 lastCameraPos = Ogre::Vector3::ZERO;
	float positionUpdateTimer = 0.0f;
	static constexpr float POSITION_UPDATE_INTERVAL = 0.3f;

	// Which viewport to update this frame (0=reflection, 1=refraction)
	int updateViewportIndex = 0;

	// Time accumulator for shader
	float shaderTime = 0.0f;

	// Dirty flag
	bool dirty = true;

	void markDirty()
	{
		dirty = true;
	}
};

#endif // EDITSCENE_WATERPLANE_HPP
