#pragma once

#include "lumacs/editor_core.hpp"
#include "lumacs/window.hpp"
#include "lumacs/gtk_renderer.hpp"
#include "lumacs/keybinding.hpp"

#include <gtkmm.h>
#include <gdkmm.h>
#include <memory>

namespace lumacs {

class GtkWindowController {
public:
    GtkWindowController(EditorCore& core, GtkRenderer& renderer, std::shared_ptr<Window> window, Gtk::DrawingArea& drawing_area);

    // Event handlers
    bool on_key_pressed(guint keyval, guint keycode, Gdk::ModifierType state);
    void on_click_pressed(int n_press, double x, double y);
    void on_drag_begin(double x, double y);
    void on_drag_update(double dx, double dy);
    bool on_scroll(double dx, double dy);

    void connect_events();
    void set_cached_active_window(std::shared_ptr<Window> window);
    void set_cursor_visible(bool visible);

private:
    EditorCore& core_;
    GtkRenderer& renderer_;
    std::shared_ptr<Window> window_;
    Gtk::DrawingArea& drawing_area_;
    std::shared_ptr<Window> cached_active_window_;
    bool cursor_visible_ = true;

    std::string resolve_key(guint keyval, Gdk::ModifierType state);
};

} // namespace lumacs
