using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using vclass.network.client;
using vclass.chat;
using vclass.chat.client;

namespace vclass.util
{
	/// <summary>
	/// Summary description for userList.
	/// </summary>
	public class userList : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ListBox LBList;
		private MainForm mainform = null;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
//		private chatPanel chatpanel = null;

		public userList(MainForm mf)
		{
			this.mainform = mf;
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}
		
		public void setUserHeader(string username)
		{
		this.Text = username;
		}

		public int add(string username)
		{
		//  FindStringExact(username,0)== -1
				if(!LBList.Items.Contains(username))
				{
					LBList.Items.Add(username);
			//		Console.WriteLine("ListBox->add "+username+" is added");
				}
			return 1;
		}

		public int remove(string username)
		{
			if(LBList.Items.Contains(username))
			{
				LBList.Items.Remove(username);
				
			}
			return 1;
		}
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.LBList = new System.Windows.Forms.ListBox();
			this.SuspendLayout();
			// 
			// LBList
			// 
			this.LBList.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.LBList.Location = new System.Drawing.Point(0, 0);
			this.LBList.Name = "LBList";
			this.LBList.ScrollAlwaysVisible = true;
			this.LBList.Size = new System.Drawing.Size(152, 277);
			this.LBList.Sorted = true;
			this.LBList.TabIndex = 0;
			this.LBList.DoubleClick += new System.EventHandler(this.LBList_DoubleClick);
			// 
			// userList
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(152, 278);
			this.Controls.Add(this.LBList);
			this.Name = "userList";
			this.Text = "userList";
			this.ResumeLayout(false);

		}
		#endregion
		

		private void LBList_DoubleClick(object sender, System.EventArgs e)
		{
			chatPanel chatpanel = ((MainForm)(this.MdiParent)).getChatPanel();
			ChatClient chatclient = ((MainForm)(this.MdiParent)).getChatClient();
			if(chatpanel == null)
			{
				Console.WriteLine("userlist->doubleclick: chatpanel is null");
				chatpanel = new chatPanel();
				chatpanel.MdiParent = this.mainform;
				((MainForm)(this.MdiParent)).setChatPanel(chatpanel);
				//this sets tha chatpanel into chatclient
				// so it is possible to reach the chatpanel.append from chatclient
				chatclient.setChatpanel(chatpanel);
				chatpanel.Show();
		//	Console.WriteLine("Listbox->event: entered ");
			}
	//		Console.WriteLine("userlist->doubleclick: public eklenmeli1");
			chatpanel.addTab("Public");
	//		Console.WriteLine("userlist->doubleclick: public eklenmeli2");
		//	Console.WriteLine("Listbox->event: "+LBList.SelectedItem.ToString());
			chatpanel.addTab(LBList.SelectedItem.ToString());
		}

		
	}
}
