#ifndef OTHERVIEW_WIDGET_H
#define OTHERVIEW_WIDGET_H

#include <string>
#include <vector>
#include <map>
#include <qobject.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qevent.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include "ui_OtherviewWidget.h"
#include "softProj\render\SpaceStructures.h"
#include "softProj/clientServer/datetime.h"
#include "selectionWidget.h"
#include "softProj\commonTypes.h"

///This widgets shows your ships in Space map mode.
class OtherviewWidget: public QGroupBox
{
	Q_OBJECT

private:
	SelectionWidget *shipSelectionWidget;

public:
	OtherviewWidget(  QWidget *parent );

private:
signals:
	void setLifeSignal( unsigned int );
	void setShieldSignal( unsigned int );


public:
signals:
	void setWarpSignal( bool useWarp );
	void setIgnationTimeSignal ( double dayTime );

public:
	Ui_OtherviewPanelWidget ui_;
	MyPushButton *activeObjectPicture;

public slots:
	void setLifeSlot( unsigned int percentage ); /**< Life percentage ( 0% - 100% ) */
	void setShieldSlot( unsigned int percentage ); /**< Shield percentage ( 0% - 100% ) */
	void setActiveObject( const QIcon & iconPicture, const QString &text, unsigned long shipId ); /**< Sets active object picture, text and id */
	
	void setWarpSlot( int useWarp );	/**< Sets warp engine mode. */
	void setIgnationTimeSlot( void ); /**< Reads text boxes values and sets ignation engine tim according them. */


	/**< Returns t reference to required slot index, 
	return value is NULL if slot with required index 
	is not available */
	MyPushButton*  getShipSlot( unsigned int id );
	const SelectionWidget * getShipSelectionWidget( void );
};

struct ShipIconSet
{
	QIcon smallIcon;
	QIcon bigIcon;
};
typedef std::map< ShipType, ShipIconSet > ShipIcon;

struct ShipInfo
{
	//string shipName;
	unsigned long shipId;
};

class SelectionLogic : public QObject
{
	Q_OBJECT
		 
private:

	static const unsigned int ARRAY_SIZE = 7;
	OtherviewWidget &otherviewWidget;
	ShipInfo shipIdArray[ ARRAY_SIZE ];
	int activeSlotIdx;
	
private slots:
	void attackButtonSlot(void);
	void radarButtonSlot(void);
	void settingsButtonSlot(void);
	void navigationButtonSlot(void);
	void weaponsButtonSlot(void);
	void ignationChangedSlot( double dayLimit );
	void warpChangeSlot( bool useWarp );

public slots:
	void selectedShipSlot( unsigned int idx, bool callSelectionCallback = true ); /**< Select ship on given slot position and call newSelectionCallback function if reqested */
	void microMacroButtonSlot( void);	/**< Callback function which is called when user select some slot */

signals:
	void attackButtonSignal( unsigned long activeShipId ); /**< Emits signal with active ship id when attack button is pressed */
	void radarButtonSignal( unsigned long activeShipId) ; /**< Emits signal with active ship id when radar button is pressed */
	void settingButtonSignal(unsigned long activeShipId) ; /**< Emits signal with active ship id when settings button is pressed */
	void navigationButtonSignal(unsigned long activeShipId); /**< Emits signal with active ship id when navigation button is pressed */
	void weaponsButtonSignal(unsigned long activeShipId); /**< Emits signal with active ship id when weapons button is pressed */
public:

	bool useWarp;
	long long ignationTimeSec;

	ShipIcon shipIcon; //icon patterns for ships

	SelectionLogic( OtherviewWidget &otherviewWidget );
	
	void refreshShipState( ShipType shipType, unsigned int lifePercentage, unsigned int shieldPercentage, const QString& shipName );

	int getActiveIdx(void) { return activeSlotIdx; };

	bool insertShip( unsigned long shipId, const string &shipName, ShipType shipType );
	bool getShipId( unsigned int idx, unsigned long &dstShipId);
	bool isFullShipArray( void );
	void removeShip( unsigned int idx );
	void clearShips(void);

	void (*newMacroMicroCallback)( void );
	void (*newSelectionCallback)( unsigned int idx );
	void (*newRadarCallback)( void );
};

#endif
