#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 onKnxValue2(float value) override;
    void onKnxValue3(float value) override;
    void onKnxSwitch(bool value) override;
    void onKnxText(const char* text) override;
    bool evaluateConditions(float primaryValue, float secondaryValue, float tertiaryValue) override;

private:
    lv_obj_t* labelLabel_ = nullptr;     // Top label (title)
    lv_obj_t* middleRow_ = nullptr;      // Horizontal container for left-icon-right
    lv_obj_t* leftLabel_ = nullptr;      // Left value (secondary)
    lv_obj_t* iconLabel_ = nullptr;      // Center icon
    lv_obj_t* rightLabel_ = nullptr;     // Right value (tertiary)
    lv_obj_t* valueLabel_ = nullptr;     // Bottom value (primary)

    char labelText_[MAX_TEXT_LEN] = {0};
    char valueFormat_[MAX_TEXT_LEN] = {0};  // Format for primary/bottom value
    char leftFormat_[MAX_FORMAT_LEN] = {0};   // Format for left value
    char rightFormat_[MAX_FORMAT_LEN] = {0};  // Format for right value

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