#pragma once

#include <array>
#include <memory>
#include <vector>

#include <QAction>
#include <QIcon>
#include <QMainWindow>
#include <QMenu>
#include <QSlider>
#include <QSystemTrayIcon>
#include <QThread>
#include <QTimer>

#include "monitor.hpp"
#include "sensor.hpp"

#include "ui_AdaptiveBrightness.h"

class MainWindow : public QMainWindow {
    Q_OBJECT

  public:
    MainWindow(QWidget* parent = nullptr);
    ~MainWindow();

  private:
    void closeEvent(QCloseEvent* event) override;

    void loadIcons();

    void updateState();

    void trayIconClicked(QSystemTrayIcon::ActivationReason reason);

    Ui::AdaptiveBrightnessClass m_ui;

    std::array<std::unique_ptr<QIcon>, 9> m_noSensorStateIcons;
    std::array<std::unique_ptr<QIcon>, 9> m_sensorStateIcons;
    std::unique_ptr<QIcon> m_errorIcon;

    bool m_visibility = false;
    QAction* m_showHideAction = nullptr;
    QMenu* m_trayIconMenu = nullptr;
    QSystemTrayIcon* m_trayIcon = nullptr;

    QThread* m_timerThread = nullptr;
    QTimer* m_timer = nullptr;

    QSlider* m_manualBrightnessSlider = nullptr;

    float m_brightness = 0.5f;

    std::vector<Sensor> m_sensors;
    std::vector<Monitor> m_monitors;
};
