#pragma once
#include "node.h"
#include "node_border.h"
#include "node_slider.h"
#include "node_colorwheel.h"
#include "node_button.h"

class NodeColorPicker : public NodeBorder
{
public:
    std::function<void(Node* target)> on_popup_close;
    std::function<void(Node* target, glm::vec3 rgb)> on_color_change;
    
    bool m_interacted = false;
    bool m_autohide = true;
    NodeSliderH* m_slider_h;
    NodeSliderH* m_slider_s;
    NodeSliderH* m_slider_v;
    NodeSliderH* m_slider_r;
    NodeSliderH* m_slider_g;
    NodeSliderH* m_slider_b;
    NodeColorWheel* m_wheel;
    NodeBorder* m_color_cur;
    NodeBorder* m_color_old;
    NodeBorder* m_color_old1;
    NodeBorder* m_color_old2;
    NodeButton* m_btn_copy;
    NodeButton* m_btn_paste;
    NodeText* m_txt_hex;
    glm::vec3 m_rgb;
    glm::vec3 m_hsv;

    virtual Node* clone_instantiate() const override;
    //virtual void clone_copy(Node* dest) const override;
    virtual void clone_finalize(Node* dest) const override;
    virtual void init() override;
    virtual void draw() override;
    virtual kEventResult handle_event(Event* e) override;
    virtual void added(Node* parent) override;
    void init_controls();
    void update_hex(glm::vec3 rgb);
    void set_color(glm::vec3 rgb);
    glm::vec3 get_hsv() const;
    glm::vec3 get_rgb() const;
};
