#pragma once
#include <QTreeWidget>
#include <vector>
#include "sensors/sensor.h"

class SensorListItem : public QTreeWidgetItem
{
	Sensor sensor;

public:
	const Sensor& getSensor();
	SensorListItem(const QString& text, const Sensor& sensor);
};

class SensorListWidget : public QTreeWidget
{
	Q_OBJECT

	bool showHidden_;
	QString savedSelectedGroup_;
	QMap<QString, bool> pendingGroupExpandedStates_;

public:

	SensorListWidget(const bool showHidden = true, QWidget* parent = nullptr);
	SensorListWidget(SensorStore& sensorStore, const bool showHidden = true, QWidget* parent = nullptr);
	virtual ~SensorListWidget() {}

	const Sensor& getSensorForIndex(const QModelIndex &index);

	void store(QJsonObject& json) const;
	void load(const QJsonObject& json);

public slots:

	void setShowHidden(const bool showHidden);
	void sensorsChanged(std::vector<Sensor> sensors);

private slots:
	void onDoubleClick(QTreeWidgetItem *item, int column);
};
