#pragma once

#include "DisplayConfig.hpp"
#include "settings/SettingsManager.hpp"
#include "ble/ThermoproBLE.hpp"
#include <array>

namespace cyd {

// Simple touch dashboard for the CYD: status bar + four probe tiles + footer.
class Dashboard {
public:
    Dashboard(CYD_Display& display, SettingsManager& settings, ThermoproBLE& bleClient);

    // Initialize display and draw the static chrome.
    void begin();

    // Refresh dynamic content. Call at most a few times per second.
    void update(bool force = false);

    // Check for touch events and return true if the settings "button" was hit.
    bool checkTouch();

    // Draw a full-screen message (used during setup/error states).
    void showMessage(const String& title, const String& line2 = "", const String& line3 = "");

private:
    CYD_Display& display_;
    SettingsManager& settings_;
    ThermoproBLE& bleClient_;

    bool lastBleConnected_ = false;
    uint8_t lastBattery_ = 0;
    std::array<float, 4> lastTemps_ = { -9999.0f, -9999.0f, -9999.0f, -9999.0f };
    std::array<bool, 4> lastConnected_ = { false, false, false, false };
    unsigned long lastUpdateMillis_ = 0;

    void drawStatusBar_();
    void drawProbeTile_(size_t index, int x, int y, int w, int h);
    void drawFooter_(const String& message);

    static String formatTemperature_(float temp);
};

} // namespace cyd
