#include "treeview.h"
#include "japi/draw.h"
#include "japi/font.h"
#include "japi/input.h"

namespace treeview
{
    int width = 200;
    int scroll = 0;
    int current = -1;
    int selected = -1;

    void start()
    {
        draw::setColor(0xff181818);
        draw::fillrect(0,48,treeview::width, draw::getWindowSize().y-48);
        current = 0;
    }

    bool option(const char* label, const int level)
    {
        int mx = input::mouseX();
        int my = input::mouseY();
        const int opt_y = (48+current*24);
        if (mx>=0 && my>=opt_y && mx<treeview::width && my<opt_y+24) {
            if (input::mouseClk(input::mouse::button::left)) {
                input::mouseDiscard();
                selected = current;
            }
            draw::setColor(selected==current ? 0xff37373d : 0xff2a2d2e);
            draw::fillrect(0, opt_y, treeview::width, 24);
        }
        font::print(label, 8+16*level, opt_y+8);
        current++;

        return selected==current;
    }

    void end()
    {

    }

}
