#pragma once

#include "Widget.hpp"

class PowerNodeWidget : public Widget {
public:
    explicit PowerNodeWidget(const WidgetConfig& config);
    lv_obj_t* create(lv_obj_t* parent) override;
    void applyStyle() override;
    void onKnxValue(float value) override;
    void onKnxSwitch(bool value) override;
    void onKnxText(const char* text) override;

private:
    lv_obj_t* labelLabel_ = nullptr;
    lv_obj_t* valueLabel_ = nullptr;
    lv_obj_t* iconLabel_ = nullptr;

    char labelText_[MAX_TEXT_LEN] = {0};
    char valueFormat_[MAX_TEXT_LEN] = {0};

    void parseText();
    void updateValueText(const char* text);
    static int encodeUtf8(uint32_t codepoint, char* buf);
};
