#ifndef MQTTITEMSETTINGSWIDGET_H
#define MQTTITEMSETTINGSWIDGET_H

#include <QWidget>
#include <memory>
#include "../../items/mqttitem.h"

namespace Ui
{
class MqttItemSettingsWidget;
}

class MqttItemSettingsWidget : public QWidget
{
	Q_OBJECT
	std::weak_ptr<MqttItem> item_;
	bool suppressUpdates_ = false;

private slots:
	void setTopic(const QString& topic);
	void setValueKey(const QString& valueKey);
	void setValueOn(const QString& valueOn);
	void setValueOff(const QString& valueOff);
	void setValueType(int index);
	void setValueMin(int min);
	void setValueMax(int max);
	void setValueStep(int step);
	void onAutoDetectClicked();
	void onAddValueName();
	void onRemoveValueName();
	void onValueNamesChanged();

public:
	explicit MqttItemSettingsWidget(std::weak_ptr<MqttItem> item, QWidget *parent = nullptr);
	~MqttItemSettingsWidget();

private:
	Ui::MqttItemSettingsWidget *ui;
	void updateVisibility();
	void updateValueNamesFromItem();
	void syncValueNamesToItem();
};

#endif // MQTTITEMSETTINGSWIDGET_H