#ifndef MACHINE_MINING_WIDGET_H
#define MACHINE_MINING_WIDGET_H

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

///Mining machine widgets displays mining data.
class MachineMiningWidget : public QWidget {
	Q_OBJECT

private:
	Ui::MachineMiningWidget ui_;

	QString speedUnit_;
	QString rangeUnit_;

	QString availableButtonStyle_;
	QString unavailableButtonStyle_;

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

		speedUnit_ = " ? / ?";

		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 mining machine. */

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

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

	void setRangeUnit(const std::wstring & unit) {
		rangeUnit_ = " " + QString::fromUtf16(unit.c_str());
	} /**< Sets range of the mining machine. */

	void setSpeed(unsigned long value) {
		ui_.speedValue->setText(Settings::instance().formatNumber(value) + speedUnit_);
	} /**< Sets speed of the mining machine. */

	void setRange(unsigned long value) {
		ui_.rangeValue->setText(Settings::instance().formatNumber(value) + rangeUnit_);
	} /**< Sets range of the mining machine. */

	void setTotalCount(unsigned long value) {
		ui_.countValue->setText(Settings::instance().formatNumber(value));
	} /**< Sets count number of the mining machine. */

	void setDamageStatus(unsigned long long working, unsigned long long damaged) {
		ui_.damageSlider->setWorkingAndDamaged(working, damaged);
	}

	void setAvailable(bool available) {
		if (available) {
			ui_.nameButton->setStyleSheet(availableButtonStyle_);
			ui_.valuesFrame->setVisible(true);
			ui_.unmountButton->setEnabled(true);
			ui_.unmountButton->setText(QString::fromUtf16(L"Odmontovat"));
		}
		else {
			ui_.nameButton->setStyleSheet(unavailableButtonStyle_);
			ui_.valuesFrame->setVisible(false);
			ui_.unmountButton->setEnabled(false);
			ui_.unmountButton->setText(QString::fromUtf16(L"Nenamontováno"));
		}
	}
};

#endif