#include "lvgl/lvgl.h" // IWYU pragma: keep
#include <stdio.h>
#include <unistd.h>
#include "screen.h"

lv_display_t *display;
uint32_t idle_time;

void key_pressed(lv_event_t *event)
{
	lv_key_t key = lv_indev_get_key(lv_indev_active());
	printf("%u\n", key);
	screen_response("Testing", "$2.80", 0, 2000);
}

int main(int argc, char *argv[])
{
	lv_init();
#ifdef LV_TARGET_FB
	display = lv_linux_fbdev_create();
	lv_linux_fbdev_set_file(display, "/dev/fb0");
#else
	display = lv_x11_window_create("LVGL X11 Simulation", 800, 480);
	lv_obj_remove_flag(lv_scr_act(), LV_OBJ_FLAG_SCROLLABLE);
	lv_x11_inputs_create(display, NULL);
	lv_obj_add_event_cb(lv_screen_active(), key_pressed, LV_EVENT_KEY,
			    NULL);
#endif

	screen_create(lv_screen_active());
	lv_group_add_obj(lv_group_get_default(), lv_screen_active());

	while (true) {
		/* Returns the time to the next timer execution */
		idle_time = lv_timer_handler();
		usleep(idle_time * 1000);
	}
}
