//
// Created by slinky on 5/11/26.
//

#ifndef B_ENGINE_UIMANAGER_H
#define B_ENGINE_UIMANAGER_H

#include <vector>
#include <memory>
#include <unordered_map>
#include <functional>

#include "EditorContext.h"
#include "GLFW/glfw3.h"
#include "ui/IUIPanel.h"

class UIManager {
public:
    static void init(GLFWwindow* _window);
    static void update(EditorContext& ctx);
    static void draw();

    template<typename T = IUIPanel, typename... Args>
    static T* add_ui_panel(std::string_view id, Args &&... args) {
        uiPanels[std::string(id)] = std::make_shared<T>(std::forward<Args>(args)...);
        return dynamic_cast<T*>(uiPanels[std::string(id)].get());
    }

    static std::shared_ptr<IUIPanel> get_ui_panel(std::string_view id) {
        if (const auto it = uiPanels.find(std::string(id)); it != uiPanels.end()) {
            return it->second;
        }
        return nullptr;
    }
private:
    static bool updateDockspace;
    static GLFWwindow* window;
    static std::unordered_map<std::string, std::shared_ptr<IUIPanel>> uiPanels;
};


#endif //B_ENGINE_UIMANAGER_H
