// Home界面 - 显示JaHub背景图
// 按键导航：BOOT单击→Img，KEY2单击→配对，KEY2双击→接收，KEY2长按→分享

#include "../ui.h"
#include "../battery_ui.h"

lv_obj_t *ui_ScreenHome = NULL;
static lv_obj_t *ui_ImgHome = NULL;

// 界面加载事件：进入Home时触发电池指示器短暂显示
static void ui_event_ScreenHome(lv_event_t *e) {
    if (lv_event_get_code(e) == LV_EVENT_SCREEN_LOADED) {
        battery_ui_show_briefly();
    }
}

void ui_ScreenHome_screen_init(void) {
    ui_ScreenHome = lv_obj_create(NULL);
    lv_obj_clear_flag(ui_ScreenHome, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_set_style_bg_color(ui_ScreenHome, lv_color_hex(0x000000), LV_PART_MAIN);
    lv_obj_set_style_bg_opa(ui_ScreenHome, 255, LV_PART_MAIN);

    // JaHub背景图（360x360全屏）
    ui_ImgHome = lv_img_create(ui_ScreenHome);
    lv_img_set_src(ui_ImgHome, &ui_img_jahub360_png);
    lv_obj_set_align(ui_ImgHome, LV_ALIGN_CENTER);
    lv_obj_clear_flag(ui_ImgHome, LV_OBJ_FLAG_SCROLLABLE);

    // 电池指示器（初始隐藏，SCREEN_LOADED时显示3秒后渐隐）
    battery_ui_add_to_screen(ui_ScreenHome, 100);
    lv_obj_add_event_cb(ui_ScreenHome, ui_event_ScreenHome, LV_EVENT_ALL, NULL);
}

void ui_ScreenHome_screen_destroy(void) {
    if (ui_ScreenHome) lv_obj_del(ui_ScreenHome);
    ui_ScreenHome = NULL;
    ui_ImgHome = NULL;
}
