#pragma once
#include "GLFW/glfw3.h"
#include "misc/singleton/singleton.h"
#include <unordered_map>
#include <memory>
#include <thread>

class plugin_host;

class CORE_API window_manager : public singleton_t<window_manager> {
public:
    void init(singleton_initliazer& initliazer) override;
    void release(singleton_release_guard& release_guard) override;

    std::shared_ptr<GLFWwindow> create_window(int width, int height, const char* title);
    void* create_plugin_window(plugin_host* host);
    void destroy_plugin_window(plugin_host* host);
    void resize_plugin_window(plugin_host* host, int width, int height);
    const char* get_name() override { return "window_manager"; }
    void update();
private:
    std::vector<std::weak_ptr<GLFWwindow>> windows_;

    struct host_info {
        int32_t x;
        int32_t y;
        std::shared_ptr<GLFWwindow> window;
    };
    void on_host_window_close(GLFWwindow* window);
    std::unordered_map<plugin_host*, host_info> host_infos_;
};

DEFINE_SINGLETON_INSTANCE(window_manager)