#ifndef EDITSCENE_CAMERAEDITOR_HPP
#define EDITSCENE_CAMERAEDITOR_HPP
#pragma once

#include "ComponentEditor.hpp"
#include "../components/Camera.hpp"
#include <OgreSceneManager.h>

/**
 * Editor for CameraComponent with preview functionality
 */
class CameraEditor : public ComponentEditor<CameraComponent> {
public:
	CameraEditor(Ogre::SceneManager* sceneMgr, Ogre::RenderWindow* renderWindow = nullptr);
	bool renderComponent(flecs::entity entity, CameraComponent &camera) override;
	const char *getName() const override { return "Camera"; }

private:
	void updatePreviewTexture(CameraComponent& camera);
	void renderPreview(CameraComponent& camera);
	
	// Viewport camera switching for preview
	bool isCameraActiveInViewport(CameraComponent* camera);
	void activateCamera(CameraComponent* camera);
	void restoreEditorCamera();
	
	Ogre::SceneManager* m_sceneMgr;
	Ogre::RenderWindow* m_renderWindow = nullptr;
	Ogre::Camera* m_originalCamera = nullptr;  // Store original to restore later
	// Track last rendered frame to avoid flickering
	unsigned long m_lastFrame = 0;
};

#endif // EDITSCENE_CAMERAEDITOR_HPP
