#ifndef IMPULS_DRIVE_WIDGET_H
#define IMPULS_DRIVE_WIDGET_H

#include <QtGui>
#include "ui_impulsDriveWidget.h"
#include "softProj\DetailsWidget\ParamDetailsWidget.h"
#include "softProj\clientServer\structs.h"
#include "softProj\Main\INotifyUpdate.h"

///This widget manages and displays impulse drive.
class ImpulsDriveWidget : public NotifyWidget {
	Q_OBJECT

private:
	Ui::ImpulsDriveWidget ui_;

	QString consumptionUnit_;
	QString forceUnit_;
signals:
	/** Signals that user wants to unmount items
	@param patternName Name of pattern for device to unmount
	*/
	void unmountSignal(const std::string & patternName);
private slots:
	void impulsDriveEngineUnmountButtonClickedSlot() {
		emit unmountSignal(PROTOCOL_HANGARS_PATTERN_ID_IMPULS_JET_ENGINE);
	}

	void mechanicalDampersUnmountButtonClickedSlot() {
		emit unmountSignal(PROTOCOL_HANGARS_PATTERN_ID_MECHANICAL_DAMPERS);
	}
public:
	ImpulsDriveWidget(QWidget * parent) : NotifyWidget(parent) {
		ui_.setupUi(this);
		
		ui_.impulsDriveSection->setName(L"Impulsní pohon");

		ui_.impulsDriveEngine->setConsumptionUnit(L"kg/s");
		ui_.impulsDriveEngine->setForceUnit(L"GN");
		
		ui_.mechanicalDampers->setAccelerationUnit(L"ms^2");

		consumptionUnit_ = " kg/s";
		forceUnit_ = " TN";

		bool connected = true;
		connected = connected && connect(ui_.impulsDriveEngine, SIGNAL(unmountButtonClickedSignal(bool)), this, SLOT(impulsDriveEngineUnmountButtonClickedSlot()));
		connected = connected && connect(ui_.mechanicalDampers, SIGNAL(unmountButtonClickedSignal(bool)), this, SLOT(mechanicalDampersUnmountButtonClickedSlot()));		
		assert(connected && "Signals not connected");
	}

	void setState(impulse_drive_status & details) {
		this->rememberUpdateTime();

		ui_.consumptionValue->setText(Settings::instance().formatNumber(details.actualConsumption) + consumptionUnit_);
		ui_.forceValue->setText(Settings::instance().formatNumber(details.actualJetForce) + forceUnit_);

		if (details.impulse_jet_engine_available) {
			ui_.impulsDriveEngine->setAvailable(true);
			ui_.impulsDriveEngine->setConsumption(details.impulse_jet_engine_actual_consumption);	
			ui_.impulsDriveEngine->setForce(details.impulse_jet_engine_actual_force);	
			ui_.impulsDriveEngine->setDamageStatus(details.impulse_jet_engine_status * 100);
		}
		else {
			ui_.impulsDriveEngine->setAvailable(false);
		}

		if (details.mechanical_dampers_available) {
			ui_.mechanicalDampers->setAvailable(true);
			ui_.mechanicalDampers->setAcceleration(details.mechanical_dampers_max_acceleration);			
			ui_.mechanicalDampers->setDamageStatus(details.mechanical_dampers_status * 100);
		}
		else {
			ui_.mechanicalDampers->setAvailable(false);
		}
	} /**< Sets and displayes impuls drive engine params. */

	void notifyUpdate() {}
};

#endif