#ifndef RESOURCE_MINING_WIDGET_H
#define RESOURCE_MINING_WIDGET_H

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

///Displays mining resource informations.
class ResourceMiningWidget : public QWidget {
	Q_OBJECT

private:
	Ui::ResourceMiningWidget ui_;	

	bool isActuallyQuarrying_;
	QString speedUnit_;
signals:
	void changeQuarryStateSignal(bool isQuarrying);
private slots:
	void startStopButtonClickedSlot(bool checked) {
		if (isActuallyQuarrying_) {
			changeQuarryStateSignal(false);
		}
		else {
			changeQuarryStateSignal(true);
		}
	}
public:
	ResourceMiningWidget(QWidget * parent) : QWidget(parent) {
		ui_.setupUi(this);		

		bool ok = connect(ui_.startStopButton, SIGNAL(clicked(bool)), this, SLOT(startStopButtonClickedSlot(bool)));
		assert(ok && "Signals not connected");
	}

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

	void setIcon(const std::string & path) {
		QIcon icon;
		icon.addFile(QString::fromUtf8(path.c_str()));
		ui_.nameButton->setIcon(icon);
		ui_.nameButton->setIconSize(QSize(16, 16));
	} /**< Sets icon picture of the resource. */

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

	void setAsActuallyQuarrying() {
		ui_.actualLabel->setText(QString::fromUtf16(L"Probíhá těžba"));
		ui_.actualLabel->setStyleSheet("background: transparent; padding: 3px; color: rgb(110, 155, 80); font-weight: bold;");
		ui_.startStopButton->setText(QString::fromUtf16(L"Zastavit těžbu"));
		ui_.speedLabel->setText(QString::fromUtf16(L"Rychlost těžby"));
		ui_.startStopButton->setEnabled(true);		

		isActuallyQuarrying_ = true;
	} /**< Sets and displays mining status to active. */

	void setAsQuarryingEnabled() {
		ui_.actualLabel->setText(QString::fromUtf16(L"Je možné těžit"));
		ui_.actualLabel->setStyleSheet("font-weight: bold; background: transparent; color:  rgb(75, 120, 175);");
		ui_.startStopButton->setText(QString::fromUtf16(L"Zahájit těžbu"));
		ui_.speedLabel->setText(QString::fromUtf16(L"Rychlost těžby"));
		ui_.startStopButton->setEnabled(true);		

		isActuallyQuarrying_ = false;
	} /**< Sets and displays mining status to be ready to start. */

	void setAsQuarryingDisabled() {
		ui_.actualLabel->setText(QString::fromUtf16(L"Není možné těžit"));
		ui_.actualLabel->setStyleSheet("font-weight: bold; background: transparent; color: rgb(170, 45, 44);");
		ui_.startStopButton->setText(QString::fromUtf16(L"Není možné těžit"));
		ui_.speedLabel->setText(QString::fromUtf16(L"Není možné těžit"));
		ui_.speedValue->setText(QString::fromUtf16(L" "));
		ui_.startStopButton->setEnabled(false);

		isActuallyQuarrying_ = false;
	} /**< Sets and displays mining status to be unavailable to start. */

	void setSpeedUnit(const std::wstring & unit) {
		this->speedUnit_ = QString::fromUtf16(unit.c_str());
	}
};

#endif