#include "wlvgl.h"
#include <vector>

/// A table that maps an incrementing integer to a style reference
static std::vector<lv_style_t*> style_table;

/// A table that maps an incrementing integer to a style reference
static std::vector<lv_obj_t*> obj_table;

static int index_of_style(lv_style_t* style) {
    for (size_t i = 0; i < style_table.size(); i++) {
        if (style_table[i] == style) {
            return i;
        }
    }
    return -1;
}

static int index_of_obj(lv_obj_t* obj) {
    for (size_t i = 0; i < obj_table.size(); i++) {
        if (obj_table[i] == obj) {
            return i;
        }
    }
    return -1;
}


void reset_wlv_tables() {
    style_table.clear();
    obj_table.clear();
}

lv_obj_t * wlv_obj_create(lv_obj_t* parent) {
    // initialize the obj
    lv_obj_t* value = lv_obj_create(parent);
    
    if (is_state_tracking()) {
        // add the style to the table
        obj_table.push_back(value);
        size_t obj_index = obj_table.size();

		char buf[8];
		sprintf(buf, "%d", obj_index);
		event_occured("lv_obj_create", buf);
	}
    return value;
}

void wlv_style_init(lv_style_t* style) {
    // initialize the style
    lv_style_init(style);

    if (is_state_tracking()) {
        // add the style to the table
        style_table.push_back(style);
        size_t style_index = style_table.size();

		char buf[8];
		sprintf(buf, "%d", style_index);
		event_occured("lv_style_init", buf);
	}
}

void wlv_obj_set_style_bg_color(lv_obj_t* obj, lv_color_t value, lv_style_selector_t selector) {
    lv_obj_set_style_bg_color(obj, value, selector);

    if (is_state_tracking()) {
        int obj_index = index_of_obj(obj);
		char buf[64];
		sprintf(buf, "%d,%d,%ld", obj_index, value.full, selector);
		event_occured("lv_obj_set_style_bg_color", buf);
	}
}


void wlv_style_set_text_color() {
    
}

void wlv_style_set_text_align() {

}

void wlv_obj_align() {

}

void wlv_obj_set_size() {

}

void wlv_obj_add_style() {

}

void wlv_obj_set_style_text_align() {

}

void wlv_label_set_text() {

}

void wlv_scr_load() {

}

void wlv_scr_act() {

}

void wlv_style_set_bg_color() {

}

void wlv_style_set_bg_opa() {

}

void wlv_obj_set_width() {

}

void wlv_style_set_text_font() {
    
}

void wlv_label_create() {

}

void wlv_obj_del() {

}

void wlv_obj_center() {

}

void wlv_obj_remove_style() {

}

void wlv_obj_add_flag() {

}

void wlv_obj_clear_flag() {

}

