using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace QC.QMSCT;

public class DebugPanel : Form
{
	public delegate void PanelCheckBoxClicked();

	private DetectionEventMode eventMode = DetectionEventMode.DETECT_MODE_TIMER;

	private GroupBox groupBox1;

	private List<CheckBox> checkPorList = new List<CheckBox>();

	private int uiMaxCheckBoxNo = 16;

	private Container components;

	public DetectionEventMode SetEventMode
	{
		set
		{
			eventMode = value;
		}
	}

	public event PanelCheckBoxClicked OnPanelCheckBoxClicked;

	public DebugPanel()
	{
		InitializeComponent();
	}

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

	private void InitializeComponent()
	{
		this.groupBox1 = new System.Windows.Forms.GroupBox();
		this.groupBox1.SuspendLayout();
		base.SuspendLayout();
		this.groupBox1.Location = new System.Drawing.Point(8, 8);
		this.groupBox1.Name = "groupBox1";
		this.groupBox1.Size = new System.Drawing.Size(157, 216);
		this.groupBox1.TabIndex = 0;
		this.groupBox1.TabStop = false;
		this.groupBox1.Text = "Unit Connections";
		for (int i = 0; i < this.uiMaxCheckBoxNo; i++)
		{
			System.Windows.Forms.CheckBox checkBox = new System.Windows.Forms.CheckBox();
			this.groupBox1.Controls.Add(checkBox);
			int num = 18;
			int num2 = 18;
			int num3 = 65;
			int num4 = 24;
			int num5 = i / (this.uiMaxCheckBoxNo / 2) * num3 + num;
			int num6 = i % (this.uiMaxCheckBoxNo / 2) * num4 + num2;
			checkBox.Location = new System.Drawing.Point(num5, num6);
			checkBox.Name = "checkPort" + (i + 1);
			checkBox.Size = new System.Drawing.Size(num3, num4);
			checkBox.TabIndex = 7;
			checkBox.Text = "Port " + (i + 1);
			checkBox.CheckedChanged += new System.EventHandler(checkPort_CheckedChanged);
			this.checkPorList.Add(checkBox);
		}
		this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
		base.ClientSize = new System.Drawing.Size(169, 227);
		base.ControlBox = false;
		base.Controls.Add(this.groupBox1);
		base.Name = "DebugPanel";
		this.Text = "Debug Panel";
		this.groupBox1.ResumeLayout(false);
		base.ResumeLayout(false);
	}

	private void checkPort_CheckedChanged(object sender, EventArgs e)
	{
		if (eventMode == DetectionEventMode.DETECT_MODE_EVENT)
		{
			this.OnPanelCheckBoxClicked();
		}
	}

	public bool GetPortStatus(int panel)
	{
		return checkPorList[panel].Checked;
	}

	public void ClearAll(int panelNo)
	{
		for (int i = 0; i < uiMaxCheckBoxNo; i++)
		{
			checkPorList[i].Checked = false;
			if (i < panelNo)
			{
				checkPorList[i].Enabled = true;
			}
			else
			{
				checkPorList[i].Enabled = false;
			}
		}
	}
}
