#ifndef EDITORUISYSTEM_HPP
#define EDITORUISYSTEM_HPP
#pragma once
#include <flecs.h>
#include <imgui.h>
#include <vector>
#include <memory>
#include <functional>
#include "../ui/ComponentEditorRegistry.hpp"
#include "../components/Transform.hpp"
#include "../components/Renderable.hpp"
#include "../components/EditorComponents.hpp"

class EditorUISystem {
public:
    EditorUISystem(flecs::world& world, Ogre::SceneManager* sceneMgr, Ogre::Vector3& cursorPos);
    ~EditorUISystem();

    void update();
    void setSelectedEntity(flecs::entity entity);
    void setOnCursorMoved(std::function<void(const Ogre::Vector3&)> callback);

private:
    void renderHierarchyWindow();
    void renderPropertyWindow();
    void renderEntityContextMenu(flecs::entity entity);
    void renderComponentEditors(flecs::entity entity);
    void render3DCursorControls();
    void refreshEntityList();
    void registerEditors();

    flecs::world& m_world;
    Ogre::SceneManager* m_sceneMgr;
    Ogre::Vector3& m_cursorPosition;
    flecs::entity m_selectedEntity;

    ComponentEditorRegistry m_editorRegistry;
    std::vector<flecs::entity> m_entityList;
    std::function<void(const Ogre::Vector3&)> m_onCursorMoved;

    // flecs 4.1.4 query for entities with name component
    flecs::query<EntityNameComponent> m_nameQuery;
};
#endif // EDITORUISYSTEM_HPP
