#include "display/ui/components/primitives.h"

namespace hwdisplay::ui::components {

lv_obj_t* Box(lv_obj_t* parent, int x, int y, int w, int h, uint32_t color,
              int radius, lv_opa_t opacity) {
    if (!parent) return nullptr;
    lv_obj_t* obj = lv_obj_create(parent);
    if (!obj) return nullptr;
    lv_obj_remove_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_remove_flag(obj, LV_OBJ_FLAG_CLICKABLE);
    lv_obj_set_pos(obj, x, y);
    lv_obj_set_size(obj, w, h);
    lv_obj_set_style_bg_color(obj, lv_color_hex(color), 0);
    lv_obj_set_style_bg_opa(obj, opacity, 0);
    lv_obj_set_style_border_width(obj, 0, 0);
    lv_obj_set_style_pad_all(obj, 0, 0);
    lv_obj_set_style_radius(obj, radius, 0);
    lv_obj_set_style_shadow_width(obj, 0, 0);
    return obj;
}

lv_obj_t* Text(lv_obj_t* parent, int x, int y, const char* value,
               const lv_font_t* font, uint32_t color) {
    if (!parent || !font) return nullptr;
    lv_obj_t* label = lv_label_create(parent);
    if (!label) return nullptr;
    lv_obj_remove_flag(label, LV_OBJ_FLAG_CLICKABLE);
    lv_obj_set_pos(label, x, y);
    lv_obj_set_style_text_font(label, font, 0);
    lv_obj_set_style_text_color(label, lv_color_hex(color), 0);
    lv_label_set_text(label, value ? value : "");
    return label;
}

}  // namespace hwdisplay::ui::components
