#include "captainWidget.h"
#include "crewMemberWidget.h"
#include <cassert>
#include "softProj\settings.h"
#include "softProj\helpers.h"

void CrewMemberWidget::addCrewButtonClickedSlot() {
	emit addCrewButtonClickedSignal();
}

void CrewMemberWidget::removeCrewButtonClickedSlot() {
	emit removeCrewButtonClickedSignal();
}

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

	bool connected = true;
	connected = connected && connect(ui_.addButton, SIGNAL(clicked(bool)), this, SLOT(addCrewButtonClickedSlot()));
	connected = connected && connect(ui_.removeButton, SIGNAL(clicked(bool)), this, SLOT(removeCrewButtonClickedSlot()));
	assert(connected && "Signals not connected");
}

void CrewMemberWidget::setName(const std::wstring & name) {
	ui_.nameButton->setText(QString::fromUtf16(name.c_str()));
}

void CrewMemberWidget::setDescription(const std::wstring & value) {
	ui_.descriptionLabel->setText(QString::fromUtf16(value.c_str()));
}

void CrewMemberWidget::setIcon(const std::string & path) {
	setButtonIconFromResources(ui_.nameButton, path, 16);
}

void CrewMemberWidget::setValues(unsigned long healthy, unsigned long injured, unsigned long total) {
	ui_.healthyValue->setText(Settings::instance().formatNumber(healthy));
	ui_.injuredValue->setText(Settings::instance().formatNumber(injured));
	ui_.totalValue->setText(Settings::instance().formatNumber(total));
}

void CaptainWidget::addCrewButtonClickedSlot() {
	emit addCrewButtonClickedSignal();
}

void CaptainWidget::removeCrewButtonClickedSlot() {
	emit removeCrewButtonClickedSignal();
}

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

	bool connected = true;
	connected = connected && connect(ui_.addButton, SIGNAL(clicked(bool)), this, SLOT(addCrewButtonClickedSlot()));
	connected = connected && connect(ui_.removeButton, SIGNAL(clicked(bool)), this, SLOT(removeCrewButtonClickedSlot()));
	assert(connected && "Signals not connected");
}

void CaptainWidget::setDescription(const std::wstring & value) {
	ui_.descriptionLabel->setText(QString::fromUtf16(value.c_str()));
}

/**< Sets captain status data */
void CaptainWidget::setStatus(unsigned long long healthy, unsigned long long wounded) {
	if (healthy > 0) {
		ui_.statusValue->setText(QString::fromUtf16(L"Nezraněný"));
		ui_.statusValue->setStyleSheet("background: transparent; padding: 3px; color: rgb(110, 155, 80); font-weight: bold; font-size: 14px; vertical-align: middle;");
	}
	else if (wounded > 0) {
		ui_.statusValue->setText(QString::fromUtf16(L"Zraněný"));
		ui_.statusValue->setStyleSheet("background: transparent; padding: 3px; color: rgb(75, 120, 175); font-weight: bold; font-size: 14px; vertical-align: middle;");
	}
	else {
		ui_.statusValue->setText(QString::fromUtf16(L"Žádný"));
		ui_.statusValue->setStyleSheet("background: transparent; padding: 3px; color: rgb(170, 45, 44); font-weight: bold; font-size: 14px; vertical-align: middle;");
	}
}