#ifndef WINDOW_H
#define WINDOW_H

#include <memory>
#include <utility>
#include "Font.h"
#include "Buffer.h"
#include "GL.h"
#include "EncodedString.h"
#include "CommandParser.h"
#include "Jtk.h"

class BufferPane;

class Window
{
public:
    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(Jtk_Event & event);
    void handle_keypress(uint32_t keyval);
#if 0
    uint32_t get_keyval(SDL_Keycode keysym);
    uint32_t get_shifted(uint32_t keysym);
#endif
    void change_focus(std::shared_ptr<BufferPane> buffer_pane);
#if 0
    void set_window_icon();
#endif
    void handle_command(const EncodedString & command);

    void command_write_file(const CommandParser & cp);
    void command_quit(const CommandParser & cp);

    void * m_window;
    bool m_exit_requested;
    bool m_redraw_requested;
    int m_width;
    int m_height;
    int m_command_buffer_screen_rows;

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

    std::shared_ptr<GL> m_gl;

    std::shared_ptr<BufferPane> m_buffer_pane;
    std::shared_ptr<BufferPane> m_focused_buffer_pane;
    std::shared_ptr<Buffer> m_command_buffer;
    std::shared_ptr<BufferPane> m_command_buffer_pane;
};

#endif
