#pragma once

#include <map>
#include <set>
#include <string>
#include <vector>
#include "../interface.h"

#define NUM_MAX_CHAT_WINDOWS			10
#define UIEVENT_UPDATE_CHAT_FRAMES		"UPDATE_CHAT_FRAMES"
#define UIEVENT_CHAT_MSG_CHANNEL_JOIN	"CHAT_MSG_CHANNEL_JOIN"
#define UIEVENT_CHAT_MSG_CHANNEL_LEAVE	"CHAT_MSG_CHANNEL_LEAVE"

enum {
	eChatGroup_System					= 0,
	eChatGroup_Say,
	eChatGroup_Yell,
	eChatGroup_Whisper,
	eChatGroup_Party,
	eChatGroup_Raid,
	eChatGroup_Guild,
	eChatGroup_LFG,
	eChatGroup_Sale,
	eChatGroup_Loot,
	eChatGroup_Combat,
};

#define MESSAGE_TYPE_SYSTEM				"SYSTEM"
#define MESSAGE_TYPE_SAY				"SAY"
#define MESSAGE_TYPE_YELL				"YELL"
#define MESSAGE_TYPE_WHISPER			"WHISPER"
#define MESSAGE_TYPE_PARTY				"PARTY"
#define MESSAGE_TYPE_RAID				"RAID"
#define MESSAGE_TYPE_GUILD				"GUILD"
#define MESSAGE_TYPE_LFG				"LFG"
#define MESSAGE_TYPE_SALE				"SALE"
#define MESSAGE_TYPE_LOOT				"LOOT"
#define MESSAGE_TYPE_COMBAT				"COMBAT"

#define	CHAT_MSG_SYSTEM					"CHAT_MSG_SYSTEM"
#define	CHAT_MSG_SAY					"CHAT_MSG_SAY"
#define	CHAT_MSG_YELL					"CHAT_MSG_YELL"
#define	CHAT_MSG_WHISPER				"CHAT_MSG_WHISPER"
#define	CHAT_MSG_WHISPER_INFORM			"CHAT_MSG_WHISPER_INFORM"
#define	CHAT_MSG_PARTY					"CHAT_MSG_PARTY"
#define	CHAT_MSG_RAID					"CHAT_MSG_RAID"
#define	CHAT_MSG_GUILD					"CHAT_MSG_GUILD"
#define	CHAT_MSG_LFG					"CHAT_MSG_LFG"
#define	CHAT_MSG_SALE					"CHAT_MSG_SALE"
#define	CHAT_MSG_LOOT					"CHAT_MSG_LOOT"
#define	CHAT_MSG_COMBAT					"CHAT_MSG_COMBAT"

class CChatFrame;
extern CChatFrame*				g_pChatFrame;

using namespace std;

struct ChatWindowInfo
{	
	vector<int>					typeList;
	set<int>					channelList;
	string						name;
	CUiColor					color;
	bool						isLocked;
	bool						isVisible;
	int							docked;
	int							fontSize;

	static int					GetTypeListNum(const char* type)
	{
		if ( strcmp(type, MESSAGE_TYPE_SYSTEM) == 0 )
			return eChatGroup_System;
		else if ( strcmp(type, MESSAGE_TYPE_SAY) == 0 )
			return eChatGroup_Say;
		else if ( strcmp(type, MESSAGE_TYPE_YELL) == 0 )
			return eChatGroup_Yell;
		else if ( strcmp(type, MESSAGE_TYPE_WHISPER) == 0 )
			return eChatGroup_Whisper;
		else if ( strcmp(type, MESSAGE_TYPE_PARTY) == 0 )
			return eChatGroup_Party;
		else if ( strcmp(type, MESSAGE_TYPE_RAID) == 0 )
			return eChatGroup_Raid;
		else if ( strcmp(type, MESSAGE_TYPE_GUILD) == 0 )
			return eChatGroup_Guild;
		else if ( strcmp(type, MESSAGE_TYPE_LFG) == 0 )
			return eChatGroup_LFG;
		else if ( strcmp(type, MESSAGE_TYPE_SALE) == 0 )
			return eChatGroup_Sale;
		else if ( strcmp(type, MESSAGE_TYPE_LOOT) == 0 )
			return eChatGroup_Loot;
		else if ( strcmp(type, MESSAGE_TYPE_COMBAT) == 0 )
			return eChatGroup_Combat;
		return -1;
	}
	static const char*			GetTypeListText(int type)
	{
		switch (type)
		{
		case eChatGroup_System:
			return MESSAGE_TYPE_SYSTEM;
		case eChatGroup_Say:
			return MESSAGE_TYPE_SAY;
		case eChatGroup_Yell:
			return MESSAGE_TYPE_YELL;
		case eChatGroup_Whisper:
			return MESSAGE_TYPE_WHISPER;
		case eChatGroup_Party:
			return MESSAGE_TYPE_PARTY;
		case eChatGroup_Raid:
			return MESSAGE_TYPE_RAID;
		case eChatGroup_Guild:
			return MESSAGE_TYPE_GUILD;
		case eChatGroup_LFG:
			return MESSAGE_TYPE_LFG;
		case eChatGroup_Sale:
			return MESSAGE_TYPE_SALE;
		case eChatGroup_Loot:
			return MESSAGE_TYPE_LOOT;
		case eChatGroup_Combat:
			return MESSAGE_TYPE_COMBAT;
		}
		return "";
	}
};

// ----------------------------------------------------------------------------
class CChatFrame : public CInterfaceBase
{
public:
	CChatFrame(CInterface* object);
	virtual ~CChatFrame();	
	
	virtual	void				RegisterFunc();
	virtual	void				BuildFrames();
	virtual	void				SendMsgEvent(const char* type, const char* msg, const char* name);
	virtual	void				AddMessage(int channel, const char* text);
	virtual	ChatWindowInfo*		GetChatWindowInfo(int id);	
	virtual	int					JoinChannelByName(const char* name, const char* password, bool isCreate);
	virtual	int					LeaveChannelByID(int id);
	virtual	int					LeaveChannelByName(const char* name);
	virtual	const char*			GetChannelName(int id);
	virtual	int					GetChannelID(const char* name);
	virtual	bool				SendChannelMsg(int id, const char* playerName, const char* msg);
	virtual	map<int, string>&	GetChannelList()							{ return m_channel; }

protected:
	ChatWindowInfo				m_windowInfo[NUM_MAX_CHAT_WINDOWS];
	map<int, string>			m_channel;
};