#ifndef EDITSCENE_CAMERASYSTEM_HPP
#define EDITSCENE_CAMERASYSTEM_HPP
#pragma once

#include <flecs.h>
#include <Ogre.h>

// Forward declaration
namespace Ogre {
	class RenderWindow;
}

/**
 * Camera system - manages Ogre::Camera objects for entities with CameraComponent
 */
class EditorCameraSystem {
public:
	EditorCameraSystem(flecs::world& world, Ogre::SceneManager* sceneMgr, 
	                   Ogre::RenderWindow* renderWindow = nullptr);
	~EditorCameraSystem();

	// Update cameras (process dirty components)
	void update();

	// Process all cameras immediately (e.g., after scene load)
	void processAllCameras();

	// Get the active editor camera (first camera found, or nullptr)
	Ogre::Camera* getActiveCamera() const;
	
	// Set the camera to use for the main viewport (nullptr to reset to default)
	void setViewportCamera(Ogre::Camera* camera);
	
	// Get the currently assigned viewport camera
	Ogre::Camera* getViewportCamera() const { return m_viewportCamera; }
	
	// Restore the original camera (before any setViewportCamera calls)
	void restoreOriginalCamera();

private:
	// Create/update a camera from component
	void updateCamera(flecs::entity entity, class CameraComponent& camera, 
	                  class TransformComponent& transform);

	// Remove a camera
	void removeCamera(CameraComponent& camera);

	flecs::world& m_world;
	Ogre::SceneManager* m_sceneMgr;
	
	// Query for entities with Camera and Transform
	flecs::query<class CameraComponent, class TransformComponent> m_cameraQuery;
	
	// Currently assigned viewport camera (nullptr = use default)
	Ogre::Camera* m_viewportCamera = nullptr;
	
	// Store the original camera to restore later
	Ogre::Camera* m_originalCamera = nullptr;
	
	// Render window for viewport access
	Ogre::RenderWindow* m_renderWindow = nullptr;
};

#endif // EDITSCENE_CAMERASYSTEM_HPP
