#ifndef EDITORCAMERA_HPP
#define EDITORCAMERA_HPP
#pragma once
#include <Ogre.h>
#include <OgreInput.h>
#include <OgreCamera.h>
#include <OgreSceneNode.h>
#include <OgreSceneManager.h>
#include <OgreRenderWindow.h>
#include <memory>
#include <functional>

class EditorCamera {
public:
    EditorCamera(Ogre::SceneManager* sceneMgr, Ogre::RenderWindow* window);
    ~EditorCamera();

    void update(float deltaTime);
    void setActive(bool active);
    Ogre::Camera* getCamera() const { return mCamera; }
    Ogre::SceneNode* getCameraNode() const { return mCameraNode; }

    void handleMouseMove(const OgreBites::MouseMotionEvent& evt);
    void handleMousePress(const OgreBites::MouseButtonEvent& evt);
    void handleMouseRelease(const OgreBites::MouseButtonEvent& evt);
    void handleKeyboard(const OgreBites::KeyboardEvent& evt);

    Ogre::Vector3 getMouseRay(float screenX, float screenY);
    Ogre::Vector3 getCursorPosition() const { return mCursorPosition; }
    void setCursorPosition(const Ogre::Vector3& pos) { mCursorPosition = pos; }

    // Camera control methods
    void setPosition(const Ogre::Vector3& pos);
    void setTarget(const Ogre::Vector3& target);
    void orbit(float deltaYaw, float deltaPitch);
    void pan(const Ogre::Vector3& delta);
    void zoom(float delta);

private:
    Ogre::SceneManager* mSceneMgr;
    Ogre::Camera* mCamera;
    Ogre::SceneNode* mCameraNode;
    Ogre::SceneNode* mTargetNode;  // Node for target position
    Ogre::RenderWindow* mWindow;

    // Camera parameters
    float mYaw;
    float mPitch;
    float mDistance;
    Ogre::Vector3 mTargetPosition;
    Ogre::Vector3 mCursorPosition;

    // Input state
    bool mActive;
    bool mMiddleMouseDown;
    bool mRightMouseDown;
    int mLastMouseX;
    int mLastMouseY;

    // Control speeds
    float mMoveSpeed;
    float mRotateSpeed;
    float mZoomSpeed;

    void updateCameraTransform();
};
#endif // EDITORCAMERA_HPP
