#pragma once
#include "NewAccountWindow.h"
#include "LoginWindow.h"
#include "ChatWindow.h"
#include "ChatRoom.h"
#include "MapWindow.h"
#include "BuddyList.h"
#include "GroupList.h"
#include "LocationList.h"
#include "EventList.h"
#include "AboutWindow.h"
#include "EditProfileWindow.h"
#include "ViewProfileWindow.h"
#include "AlertWindow.h"
#include "CreateGroupWindow.h"
#include "EditGroupWindow.h"
#include "ViewGroupWindow.h"
#include "EditEventWindow.h"
#include "CreateEventWindow.h"
#include "ViewEventWindow.h"
#include "SetPasswordWindow.h"
#include "NewAccountWindow.h"
#include "NetworkInfoWindow.h"
#include "NetCard.h"
#include "SideBarWindow.h"
#include "AwayWindow.h"
#include "NewsWindow.h"

class MainWindow :
	public SkinnableWindow
{
public:
	MainWindow(void);
	~MainWindow(void);

	virtual int Create();
	void Activate();

	// messages from the taskbar
	virtual void OnRButtonDown();
	virtual void OnLButtonDown();
	virtual void OnLButtonDblClk();
	virtual void OnDestroy();
	virtual void OnAbout();
	virtual void OnOrganizeLists();
	virtual void OnTimer();

	// alert messages 
	void Alert(const TCHAR * msg, int x, int y);

	// messages from the server
	void OnChatMessage(ChatMessage * msg);
	void OnGroupMessage(ChatMessage * msg);
	void OnCustomNotify(int id, Notification& n);

	void PostServerNotify(int type, int theId, int reason, int param);
	void SendServerNotify(ServerNotifyMessage * p);

	static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

	void StartLogOn();
	void LogOn(const TCHAR * username, const TCHAR * password);
	void LogOff();

	// the application's child windows
	NewAccountWindow newaccount;
	LoginWindow loginwindow;
	MapWindow mapwindow;
	SideBarWindow sidebar;
	BuddyList buddylist;
	GroupList grouplist;
	LocationList locationlist;
	EventList eventlist;
	AboutWindow about;
	EditProfileWindow editprofile;
	ViewProfileWindow viewprofile;
	AlertWindow alert;
	CreateGroupWindow creategroup;
	EditGroupWindow editgroup;
	ViewGroupWindow viewgroup;
	EditEventWindow editevent;
	ViewEventWindow viewevent;
	CreateEventWindow createevent;
	SetPasswordWindow setpassword;
	NetworkInfoWindow networkinfo;
	AwayWindow awaywindow;
	NewsWindow newswindow;

	// the list of chat windows and their routines
	// everything is indexed by the recipient of the chat messages
	std::list<ChatWindow*> chatwindows;
	ChatWindow * NewChatWindow(int id, const TCHAR * recipient);
	ChatWindow * FindChatWindow(int id);
	ChatWindow * FindChatWindow(const TCHAR * recipient);
	ChatWindow * OpenChatWindow(int id, const TCHAR * recipient);
	int CloseChatWindow(int id);
	int CloseChatWindow(const TCHAR * recipient);
	void CloseAllChatWindows();

	// the list of chat rooms and their routines
	// everything is indexed by the recipient (a group) of the chat messages
	std::list<ChatRoom*> chatrooms;
	ChatRoom * NewChatRoom(int id, const TCHAR * recipient);
	ChatRoom * FindChatRoom(int id);
	ChatRoom * FindChatRoom(const TCHAR * recipient);
	ChatRoom * OpenChatRoom(int id, const TCHAR * recipient);
	int CloseChatRoom(int id);
	int CloseChatRoom(const TCHAR * recipient);
	void CloseAllChatRooms();

	int ChatFlashPeriod;

	// start a chat session with a user
	void ChatWithUser(int id, const TCHAR * name);
	void BeginDiscussion(int id, const TCHAR * name);
	void JoinDiscussion(int id, const TCHAR * name);

	// create/edit users, events, and groups
	void NewAccount();
	void EditProfile();
	void ViewProfile(int id = -1);
	
	void CreateGroup(const TCHAR * name);
	void EditGroup(int groupId);
	void ViewGroup(int groupId);

	void CreateEvent(const TCHAR * name);
	void EditEvent(int eventId);
	void ViewEvent(int eventId);

	// common map routines
	void ShowUserOnMap(int id);

	// set away status and privacy level
	void SetAwayStatus(int away = -1, const TCHAR * message = L"");	// call with no args to show window
	void SetPrivacyLevel(int privacy = -1);

	// toggle help balloons
	int HelpBalloonsEnabled;
	void ToggleHelpBalloons();

	// Location Editor routines
	void AddLocationSignature(int locationId);

	// network info
	int HaveNetwork;
	std::string NetworkAdapter;
	int Wireless;
	Vector<unsigned char> MacAddress;
	std::wstring IPAddress;
	int UpdateNetworkInfo(); // returns 1 if the info has changed

	// Taskbar related data and methods
	int LoadTaskbar();
	void SetTaskbarIcon(HICON hIcon = NULL);
	void SetTaskbarText(const TCHAR * text = NULL);
	void UnloadTaskbar();
	void UpdateTaskbar(); // call everytime user state changes
	LRESULT DisplayTaskbarMenu();
	NOTIFYICONDATA taskbar;
	HMENU hTaskbarMenu, hPrivacyMenu;
	HICON NormalIcon, LoggedOffIcon, AwayIcon, VisibleToBuddiesIcon, IdleIcon;

	// The current user
	UserRecord user;

	// location info
	LocationRecord CurrentLocation;
	MACADDR HubMAC;
	int SignalStrength;
	int UpdateLocation(); // returns 1 if the info has changed

	// returns the display string for a specific location
	const TCHAR * GetDisplayName(LocationRecord & record);


	TCHAR DateFormat[255]; // the universal date format

	// demo mode
	int DemoMode;
	int DemoLocationId;
	int DemoIdle;
};

// BridgeClient-specific Messages
#define ID_ONNOTIFY				(ID_BASE_B+1)
#define ID_ONCHATMESSAGE		(ID_BASE_B+6)
#define ID_ONGROUPMESSAGE		(ID_BASE_B+7)
#define ID_ORGANIZELISTS		(ID_BASE_B+8)
#define ID_SENDSERVERNOTIFY		(ID_BASE_B+9)
#define ID_APPLICATION_ACTIVATE (ID_BASE_B+10)




