#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "flowlayout.h"
#include "sensorwidget.h"
#include "sensorservice.h"
#include "httpclient.h"
#include "alarmsservice.h"
#include "journalservice.h"

#include <QMainWindow>
#include <QPixmap>
#include <QVBoxLayout>
#include <QTreeWidget>
#include <QMap>

#ifdef Q_OS_WIN
#include <Qlabel>
#elif defined(Q_OS_LINUX)
#include <QLabel>
#endif

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

struct TabImageData
{
    QLabel *label;
    QPixmap pixmap;
    QSize originalSize;
};

class MainWindow : public QMainWindow
{
    Q_OBJECT

private slots:
    void onIncidentsPageChanged(int page);
    void onJournalPageChanged(int page);

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

private:
    Ui::MainWindow *ui;

private:
    AlarmsService *asr;
    JournalService *jsr;
    HttpClient *httpClient;
    QWidget *widgetContainer;
    FlowLayout *layout;
    SensorService *sensorService;
    QMap<QString, QString> nameToId;


private:
    //COMMON------------------------------------------------------
    void loadSenorsTree(QTreeWidget* tree);
    //------------------------------------------------------------

    //SENSOR------------------------------------------------------
    //dialog windows
    void showSensorDialog(SensorWidget *sensor);
    void onSensorDialogFinished(int result);
    //api requests
    void loadSensors(const QString& group);
    void loadSensorGroups();
    //update widgets
    void updateDisplayedWidgets();
    void onSearchTextChanged(const QString &text);
    void onGroupSelected(int index);
    void onShowHiddenSelected(int index);
    //utility
    void startSensorTabRefreshTimer();
    void SetupSensorTab();
    //------------------------------------------------------------

    //INCEDENTS---------------------------------------------------
    //update widgets
    void onSearchIncedentsTextChanged(const QString &text);
    void onTreeIncidentsChanged(QTreeWidgetItem *item, int column);
    //------------------------------------------------------------

    //JOURNAL-----------------------------------------------------
    //update widgets
    void onSearchJournalTextChanged(const QString &text);
    void onTreeJournalChanged(QTreeWidgetItem *item, int column);
    //------------------------------------------------------------

};
#endif // MAINWINDOW_H
