#pragma once

#include "../WidgetConfig.hpp"
#include "lvgl.h"
#include <ctime>

class Widget {
public:
    explicit Widget(const WidgetConfig& config);
    virtual ~Widget();

    // Delete copy/move
    Widget(const Widget&) = delete;
    Widget& operator=(const Widget&) = delete;

    // Destroy LVGL object
    void destroy();

    // Access to LVGL object
    lv_obj_t* getLvglObject() const { return obj_; }
    lv_obj_t* getObj() const { return obj_; } // Alias

    // Widget ID
    uint8_t getId() const { return config_.id; }

    // KNX group address for read binding
    uint16_t getKnxAddress() const { return config_.knxAddress; }

    // TextSource for KNX callback filtering
    TextSource getTextSource() const { return config_.textSource; }

    // Widget type
    WidgetType getType() const { return config_.type; }

    // Config access (for button action handling)
    const WidgetConfig& getConfig() const { return config_; }

    // Create LVGL widget on parent - must be implemented by subclasses
    virtual lv_obj_t* create(lv_obj_t* parent) = 0;

    // Apply styling after create() - can be overridden
    virtual void applyStyle();

    // KNX callbacks - default implementations do nothing
    virtual void onKnxValue(float value);
    virtual void onKnxSwitch(bool value);
    virtual void onKnxText(const char* text);
    virtual void onKnxTime(const struct tm& value, TextSource source);
    virtual void onHistoryUpdate();

protected:
    // Common style helper functions
    void applyCommonStyle();
    void applyShadowStyle();
    static const lv_font_t* getFontBySize(uint8_t sizeIndex);

    const WidgetConfig& config_;
    lv_obj_t* obj_ = nullptr;
};
