#pragma once
#include "Eigen/Eigen"
#include "GLFW/glfw3.h"

class renderer_window {
    friend class window_manager;
public:
    const float clear_color[4] = {1.f, 1.f, 1.f, 1.f};

    virtual ~renderer_window();

    virtual bool init(const Eigen::Vector2i& in_size, const std::string& in_title);

    virtual void begin_frame() = 0;
    virtual void end_frame() = 0;

    void resize(const Eigen::Vector2i& in_size) {
        if (in_size == get_window_size()) return;
        on_resize(in_size);
    }

    [[nodiscard]] Eigen::Vector2i get_window_size() const {
        int w, h;
        glfwGetWindowSize(window, &w, &h);
        return { w, h };
    }

    [[nodiscard]] Eigen::Vector2i get_framebuffer_size() const {
        int w, h;
        glfwGetFramebufferSize(window, &w, &h);
        return { w, h };
    }
    [[nodiscard]] Eigen::Matrix4f get_projection_matrix() const;

    [[nodiscard]] void* get_window_handle() const;
    [[nodiscard]] GLFWwindow* get_glfw_window() const { return window; }
protected:
    virtual bool create_surface(GLFWwindow* in_window) = 0;
    virtual void on_resize(const Eigen::Vector2i& in_size) = 0;
private:
    GLFWwindow* window = nullptr;
};
