using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using QC.QsprShared.Dialogs;
using QC.QTMInterface;

namespace QC.QTMApplication;

public class UserWindowColl : UserControl
{
	private Container components;

	private TabControl tabControl;

	private Hashtable winCollection = new Hashtable();

	public QSPRMainWindow QSPRWindow { get; set; }

	public UserWindowColl()
	{
		InitializeComponent();
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.tabControl = new System.Windows.Forms.TabControl();
		base.SuspendLayout();
		this.tabControl.Dock = System.Windows.Forms.DockStyle.Fill;
		this.tabControl.Location = new System.Drawing.Point(0, 0);
		this.tabControl.Name = "tabControl";
		this.tabControl.SelectedIndex = 0;
		this.tabControl.Size = new System.Drawing.Size(1056, 528);
		this.tabControl.TabIndex = 0;
		base.Controls.Add(this.tabControl);
		base.Name = "UserWindowColl";
		base.Size = new System.Drawing.Size(1056, 528);
		base.Enter += new System.EventHandler(UserWindowColl_Enter);
		base.Leave += new System.EventHandler(UserWindowColl_Leave);
		base.ResumeLayout(false);
	}

	public void AddDebugWindowPlugIn(UserWindows dWin)
	{
		try
		{
			SuspendLayout();
			TabPage tabPage = new TabPage();
			tabPage.Text = dWin.Name;
			winCollection.Add(dWin.Name, dWin);
			tabControl.Controls.Add(tabPage);
			tabPage.Controls.Add(dWin);
			dWin.Dock = DockStyle.Fill;
			tabPage.Name = "tabWinView";
			tabPage.TabIndex = 0;
			dWin.OnUserPluginHandler = OnUserPluginHandler;
			ResumeLayout(performLayout: false);
		}
		catch (Exception ex)
		{
			AppMessageDialog.Show("AddDebugWindowPlugIn: " + ex.Message, DialogResult.OK, MessageDialogType.Exception);
		}
	}

	private CallbackResultInfo OnUserPluginHandler(object sender, TTDPluginEventArgs e)
	{
		CallbackResultInfo result = default(CallbackResultInfo);
		try
		{
			switch (e.MessageCategory)
			{
			case CallbackCategory.SPECIAL_MESSAGE:
				ProcessSpecialMessage(e);
				break;
			case CallbackCategory.MENU_MESSAGE:
				break;
			}
		}
		catch (Exception ex)
		{
			result.Message = ex.Message;
			result.Result = false;
		}
		return result;
	}

	private CallbackResultInfo ProcessSpecialMessage(TTDPluginEventArgs e)
	{
		CallbackResultInfo result = default(CallbackResultInfo);
		result.Result = false;
		try
		{
			string key;
			if ((key = e.Key) != null && key == "Update Global Variables with Tester Config")
			{
				QSPRWindow.UpdateGlobalVble(GetFromTesterConfig: true);
				result.Result = true;
			}
		}
		catch (Exception ex)
		{
			result.Message = ex.Message;
			result.Result = false;
		}
		return result;
	}

	private void UserWindowColl_Enter(object sender, EventArgs e)
	{
	}

	private void UserWindowColl_Leave(object sender, EventArgs e)
	{
	}
}
