#ifndef QUARK_GLUON_CORE_WIDGET_H
#define QUARK_GLUON_CORE_WIDGET_H

#include <QtGui>
#include <cassert>
#include "ui_quarkGluonCoreWidget.h"
#include "softProj\clientServer\structs.h"
#include "softProj\settings.h"

///Manages and displays QuarkGluonCore issues.
class QuarkGluonCoreWidget : public QWidget {
	Q_OBJECT

private:
	Ui::QuarkGluonCoreWidget ui_;

	QString consumptionUnit_;
	QString speedUnit_;

	QString availableButtonStyle_;
	QString unavailableButtonStyle_;

	QString availableDamageStyle_;
	QString unavailableDamageStyle_;
signals:
	void unmountButtonClickedSignal(bool checked);
private slots:
	void unmountButtonClickedSlot(bool checked) {
		emit unmountButtonClickedSignal(checked);
	}
public:
	QuarkGluonCoreWidget(QWidget * parent) : QWidget(parent) {
		ui_.setupUi(this);

		ui_.damageSlider->setMinimum(0);
		ui_.damageSlider->setMaximum(100);

		ui_.damageSlider->setUnit(L"%");

		availableButtonStyle_ = Settings::instance().getStyle(STYLE_AVAILABLE_DEVICE_BUTTON);
		unavailableButtonStyle_ = Settings::instance().getStyle(STYLE_UNAVAILABLE_DEVICE_BUTTON	);
		availableDamageStyle_ = Settings::instance().getStyle(STYLE_AVAILABLE_DEVICE_DAMAGE_LABEL);
		unavailableDamageStyle_ = Settings::instance().getStyle(STYLE_UNAVAILABLE_DEVICE_DAMAGE_LABEL);

		bool connected = true;
		connected = connected && connect(ui_.unmountButton, SIGNAL(clicked(bool)), this, SLOT(unmountButtonClickedSlot(bool)));
		assert(connected && "Signals not connected");
	}

	void setName(const std::wstring & name) {
		ui_.nameButton->setText(QString::fromUtf16(name.c_str()));
	} /**< Sets title name of the  quark gluon core widget. */

	void setDescription(const std::wstring & name) {
		ui_.descriptionLabel->setText(QString::fromUtf16(name.c_str()));
	} /**< Sets description text of the quark gluon core widget. */

	void setConsumptionUnit(const std::wstring & unit) {
		consumptionUnit_ = " " + QString::fromUtf16(unit.c_str());
	} /**< Sets consumption unit of the quark qluom core widget. */

	void setSpeedUnit(const std::wstring & unit) {
		speedUnit_ = " " + QString::fromUtf16(unit.c_str());
	} /**< Sets speed unit of the quark qluom core widget. */

	void setConsumption(unsigned long value) {
		ui_.consumptionValue->setText(Settings::instance().formatNumber(value) + consumptionUnit_);
	} /**< Sets current consumption of the quark qluom core widget. */

	void setSpeed(unsigned long value) {
		ui_.speedValue->setText(Settings::instance().formatNumber(value) + speedUnit_);
	} /**< Sets current speed unit of the quark qluom core widget. */

	void setDamageStatus(unsigned long value) {
		ui_.damageSlider->setValue(value);		
	} /**< Sets damages status of the quark qluom core widget. */

	void setAvailable(bool available) {
		if (available) {
			ui_.nameButton->setStyleSheet(availableButtonStyle_);
			ui_.damageLabel->setStyleSheet(availableDamageStyle_);
			ui_.damageLabel->setText(QString::fromUtf16(L"Stav zařízení"));
			ui_.damageSlider->setVisible(true);
			ui_.valuesFrame->setVisible(true);
			ui_.unmountButton->setEnabled(true);
			ui_.unmountButton->setText(QString::fromUtf16(L"Odmontovat"));
		}
		else {
			ui_.nameButton->setStyleSheet(unavailableButtonStyle_);
			ui_.damageLabel->setStyleSheet(unavailableDamageStyle_);
			ui_.damageLabel->setText(QString::fromUtf16(L"Zařízení není k dispozici"));
			ui_.damageSlider->setVisible(false);
			ui_.valuesFrame->setVisible(false);
			ui_.unmountButton->setEnabled(false);
			ui_.unmountButton->setText(QString::fromUtf16(L"Nenamontováno"));
		}
	}
};

#endif