#ifndef TEXTINPUTNODE_H
#define TEXTINPUTNODE_H

#include "scene/gui/guinode.h"
#include <iostream>

#include "scene/textnode.h"
#include "scene/gui/callback.h"

/*
struct TextInputAction{
    int cursor_left;
    int cursor_right;
    int history_next;
    int history_previous;
};
*/

class TextInputNode : public GUINode
{
    glm::vec2 m_dimension;
    bool m_hasFocus;
    float m_font_size;

    TextNode* m_text_mesh;
    std::string m_text;
    bool m_text_updated;
    glm::vec3 m_text_color;

    MeshNode* m_cursor_mesh;
    unsigned int m_cursor_pos;
    bool m_cursor_pos_updated;

    CallBack* m_callback;
    CallBack* m_tab_callback;

    std::vector<std::string> m_history;
    unsigned int m_history_pos;

    std::vector<int> m_inputActions;

    enum TextInputAction {MOVE_CURSOR_LEFT,MOVE_CURSOR_RIGHT,HISTORY_PREVIOUS,HISTORY_NEXT};

public:
    TextInputNode(glm::vec2 dimension);
    void update();
    void updateCursorMesh();
    void updateTextMesh();
    glm::vec2 getDimension(){return m_dimension;}

    void setFocus(bool focus);
    void setTextColor(glm::vec3 color);
    void setText(std::string text);
    std::string getText();
    void setCallBack(CallBack* callback){m_callback = callback;}
    void setTabCallBack(CallBack* callback){m_tab_callback = callback;}

    void setInputs(int cursor_left, int cursor_right, int history_up, int history_down);

    void clearText();
};

#endif // TEXTINPUTNODE_H
