#include "cloakingWidget.h"
#include "softProj\settings.h"
#include <cassert>

CloakingWidget::CloakingWidget(QWidget * parent) : NotifyWidget(parent) {
	ui_.setupUi(this);

	ui_.sectionHeader->setName(L"Maskování");

	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");

	weightUnit_ = " kg";
	consumptionUnit_ = " GW";

	ui_.damageSlider->setMinimum(0);
	ui_.damageSlider->setMaximum(100);
	ui_.damageSlider->setUnit(L"%");
}

void CloakingWidget::unmountButtonClickedSlot(bool checked) {
	emit unmountSignal(PROTOCOL_HANGARS_PATTERN_ID_CLOAKING_DEVICE);
}

void CloakingWidget::setState(const cloaking_data & details) {
	ui_.consumptionValue->setText(Settings::instance().formatNumber((unsigned long) (details.consumption * 1000)) + consumptionUnit_);	
	ui_.levelValue->setText(Settings::instance().formatNumber(details.level));	
	ui_.weightValue->setText(Settings::instance().formatNumber(details.weight) + weightUnit_);	
		
	ui_.damageSlider->setValue(details.status * 100);
		
	setAvailable(details.available);

	this->state_ = details;
}

void CloakingWidget::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"));
	}
}

void CloakingWidget::notifyUpdate() {
}

CloakingWidget::~CloakingWidget() {
}