#ifndef WINDOW_H
#define WINDOW_H

#include <memory>
#include <utility>
#include <SDL.h>
#include "Font.h"
#include "Buffer.h"
#include "GL.h"

class BufferPane;

class Window
{
public:
    class Keymod
    {
    public:
        enum : uint32_t
        {
            CTRL  = 0x10000,
            ALT   = 0x20000,
            SHIFT = 0x40000,
            GUI   = 0x80000,
        };
    };

    enum class CursorMovement : uint8_t
    {
        LEFT,
        RIGHT,
        UP,
        DOWN,
        SOL,
        EOL,
        FIRST_LINE,
        LAST_LINE,
        SCREEN_ROW_UP,
        SCREEN_ROW_DOWN,
    };

    enum class ScrollMode : uint8_t
    {
        ONE_LINE,
        WHEEL,
        HALF_SCREEN,
        WHOLE_SCREEN,
    };

    enum class EnterInsertModeMode : uint8_t
    {
        START_OF_CHAR,
        END_OF_CHAR,
        START_OF_LINE,
        END_OF_LINE,
        NEW_LINE_BEFORE,
        NEW_LINE_AFTER,
    };

    bool create(std::shared_ptr<Buffer> buffer);
    void run_event_loop();
    void request_redraw() { m_redraw_requested = true; }
    std::shared_ptr<Font> font() const { return m_font; }
    std::shared_ptr<GL> gl() const { return m_gl; }

protected:

    void resize();
    void redraw();
    void handle_event(SDL_Event & event);
    void handle_keysym(uint32_t keysym);
    void handle_keyval(uint32_t keyval);
    uint32_t get_keyval(SDL_Keycode keysym);
    uint32_t get_shifted(uint32_t keysym);

    SDL_Window * m_window;
    bool m_exit_requested;
    bool m_redraw_requested;
    int m_width;
    int m_height;

    std::shared_ptr<Font> m_font;
    uint32_t m_target_column;

    std::shared_ptr<GL> m_gl;

    std::shared_ptr<BufferPane> m_buffer_pane;

    Uint16 m_keymod;
};

#endif
