#pragma once

#include "display/ui/flow/flow_model.h"
#include "display/ui/home/home_view.h"
#include "lvgl.h"

#include <cstdint>
#include <vector>

namespace hwdisplay::ui {

// Owns child-facing LVGL objects only. Media decoding and camera input live outside.
class FlowView {
public:
    bool Create(lv_obj_t* parent);
    void Render(const FlowModel& model);
    void UpdateHandFeedback(const FlowModel& model);
    void UpdateGuideCountdown(uint64_t elapsed_ms, uint64_t duration_ms);
    void ShowVideoFrame(const uint8_t* bgra, size_t bytes);
    void ShowCameraFrame(const uint8_t* bgra, size_t bytes);
    void ShowFaceFrame(const uint8_t* bgra, size_t bytes);
    void SetFaceFrameBuffer(uint8_t* pixels, size_t bytes) {
        home_.SetFaceFrameBuffer(pixels, bytes);
    }
    void UpdateHome(const HomeModel& model);
    void Destroy();

    static constexpr int kVideoWidth = 394;
    static constexpr int kVideoHeight = 260;
    static constexpr int kCameraWidth = 296;
    static constexpr int kCameraHeight = 196;

private:
    lv_obj_t* parent_ = nullptr;
    lv_obj_t* root_ = nullptr;
    lv_obj_t* video_ = nullptr;
    lv_obj_t* video_hint_ = nullptr;
    lv_obj_t* camera_ = nullptr;
    lv_obj_t* camera_hint_ = nullptr;
    lv_obj_t* feedback_card_ = nullptr;
    lv_obj_t* feedback_icon_box_ = nullptr;
    lv_obj_t* feedback_icon_ = nullptr;
    lv_obj_t* feedback_main_ = nullptr;
    lv_obj_t* feedback_detail_ = nullptr;
    lv_obj_t* countdown_label_ = nullptr;
    lv_obj_t* countdown_fill_ = nullptr;
    bool camera_has_frame_ = false;
    HandFeedback hand_feedback_ = HandFeedback::Observing;
    std::vector<uint8_t> frame_buffer_;
    std::vector<uint8_t> camera_buffer_;
    HomeView home_;
};

}  // namespace hwdisplay::ui
