/main/gfx.h
#pragma once

#include <stdbool.h>
#include "u8g2_esp32_hal.h"
#include "u8g2.h"

#include "battery.h"
#include "bt.h"
#include "play.h"

#define META_STR_MAX 32

typedef enum {
	SCENE_CLOCK,
	SCENE_MENU,
	SCENE_PLAY,
	SCENE_BT,
	SCENE_BROWSE,
	SCENE_NO_CHANGE,
} scene_t;

typedef struct {
	char title[META_STR_MAX];
	char artist[META_STR_MAX];
	time_t track_position;
	time_t track_length;
} playing_metadata_t;

typedef struct {
	const char *label;
	void (*func)();
} menu_def_t;

typedef struct {
	time_t time;
} clock_scene_t;

typedef struct {
	const char *title;
	int n_items;
	menu_def_t items[5];
} menu_scene_t;

typedef struct {
	play_state_t play_state;
} play_scene_t;

#define BROWSE_NONE      0
#define BROWSE_AT_TOP    1
#define BROWSE_AT_BOTTOM 2

typedef struct {
	char* names[4];
	unsigned char types[4];
	uint8_t state;
} browse_scene_t;

typedef struct {
	bt_mode mode;
	uint32_t confirm;
} bt_info_t;

typedef struct {
	scene_t scene;
	bt_info_t bt;
	battery_info_t battery;
	playing_metadata_t playing_meta;
	union {
		clock_scene_t clock;
		menu_scene_t menu;
		play_scene_t play;
		browse_scene_t browse;
	};
} gfx_data_t;

extern u8g2_t u8g2;

int gfx_init();
gfx_data_t * gfx_acquire_data(scene_t scene);
void gfx_release_data();
void gfx_set_power(int on);
void gfx_message(const char *str);
void gfx_set_enabled(bool v);