#ifndef INCOMING_WIDGET_H
#define INCOMING_WIDGET_H

#include <QtGui>
#include "ui_IncomingWidget.h"
#include "softProj\ChatWidget\ChatMessage.h"
#include "softProj\helpers.h"
#include <deque>

/// Represents widget for displaying messages. 
/** Represents widget for displaying messages. Its intented use is to display messages
in area of left column in mainwindow. 
*/
class IncomingWidget : public QWidget {
	Q_OBJECT
private:
	std::deque<QString> messages_;
public:
	IncomingWidget(QWidget * parent) : QWidget(parent) {
		unreadMessagesCount_ = 0;
		ui_.setupUi(this);
		setTitle();
	}

	/** Sets title of the widget */
	void setTitle() {
		ui_.incomingLabel->setText(QString::number(unreadMessagesCount_));
	}

	/** Adds received chat message as an unread message
	@param message Received message
	*/
	void addUnreadChatMessage(ChatMessage * message) {
		unreadMessagesCount_++;
		setTitle();

		QString messageString = "<p style=\"color: #eeeeee;\">" + QString::fromUtf8(message->getText().c_str()) + "</p>";
		messages_.push_back(messageString);

		if (messages_.size() > 10) {
			messages_.pop_front();
			ui_.messagesBox->clear();

			for (std::deque<QString>::const_iterator it = messages_.begin(); it != messages_.end(); ++it) {
				ui_.messagesBox->appendHtml(*it);
			}
		}
		else {	
			ui_.messagesBox->appendHtml(messageString);
		}
	}

	/** Decreases number of unread chat messages by given count
	@param count Number of messages that were read
	*/
	void removeUnreadMessages(int count) {
		unreadMessagesCount_ -= count;
		setTitle();
	}
private:
	Ui::IncomingWidget ui_;
	int unreadMessagesCount_;
};

#endif