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

namespace QDART_MFG_CfgEditor;

public class RoutingCfgEditPorts : Form
{
	private string initStr;

	private string initStrBands;

	private InfoItem[] info;

	private bool beNew;

	private IContainer components;

	private TextBox tbView;

	private Label label1;

	private Button btnSave;

	private Button btnCancel;

	private QualTreeView portTree;

	private QualTreeView bandTree;

	private Label label2;

	private Label label3;

	private ToolTip toolTip1;

	public RoutingCfgEditPorts(string strPorts, string strBands, InfoItem[] infoItem, bool bNew)
	{
		InitializeComponent();
		initStr = strPorts;
		initStrBands = strBands;
		info = infoItem;
		beNew = bNew;
		PopulateTree();
	}

	private void btnSave_Click(object sender, EventArgs e)
	{
		string text = "";
		foreach (TreeNode node in portTree.Nodes)
		{
			foreach (TreeNode node2 in node.Nodes)
			{
				if (node2.Checked)
				{
					text = text + node2.Name + ",";
				}
			}
		}
		text = text.Substring(0, text.Length - 1);
		text += ";";
		foreach (TreeNode node3 in bandTree.Nodes)
		{
			foreach (TreeNode node4 in node3.Nodes)
			{
				if (node4.Checked)
				{
					text = text + node4.Name + ",";
				}
			}
		}
		if (string.IsNullOrEmpty(text))
		{
			MessageBox.Show("At least one item selectecd!");
			return;
		}
		base.Tag = text.Substring(0, text.Length - 1);
		base.DialogResult = DialogResult.OK;
	}

	private void btnCancel_Click(object sender, EventArgs e)
	{
		Close();
	}

	private void PopulateTree()
	{
		try
		{
			portTree.Nodes.Clear();
			bandTree.Nodes.Clear();
			portTree.CheckBoxes = true;
			bandTree.CheckBoxes = true;
			List<TreeNode> list = new List<TreeNode>();
			List<TreeNode> list2 = new List<TreeNode>();
			string[] array = null;
			if (!string.IsNullOrEmpty(initStr))
			{
				array = initStr.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
			}
			string[] array2 = null;
			if (!string.IsNullOrEmpty(initStrBands))
			{
				array2 = initStrBands.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
			}
			InfoItem[] array3 = info;
			foreach (InfoItem infoItem in array3)
			{
				if (!infoItem.Name.Contains("_B"))
				{
					List<TreeNode> list3 = new List<TreeNode>();
					string[] array4 = infoItem.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
					string[] array5 = array4;
					foreach (string text in array5)
					{
						TreeNode treeNode = new TreeNode(text);
						treeNode.Name = text;
						treeNode.Text = text;
						if (array != null && Common.InArray(text, array))
						{
							treeNode.Checked = true;
						}
						list3.Add(treeNode);
					}
					TreeNode treeNode2 = new TreeNode(infoItem.Name, list3.ToArray());
					treeNode2.Name = infoItem.Name;
					treeNode2.Text = infoItem.Name;
					list.Add(treeNode2);
					continue;
				}
				List<TreeNode> list4 = new List<TreeNode>();
				string[] array6 = infoItem.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
				string[] array7 = array6;
				foreach (string text2 in array7)
				{
					TreeNode treeNode3 = new TreeNode(text2);
					treeNode3.Name = infoItem.Name + text2;
					treeNode3.Text = infoItem.Name + text2;
					if (array2 != null && Common.InArray(infoItem.Name + text2, array2))
					{
						treeNode3.Checked = true;
					}
					list4.Add(treeNode3);
				}
				TreeNode treeNode4 = new TreeNode(infoItem.Name, list4.ToArray());
				treeNode4.Name = infoItem.Name.Replace("_B", "");
				treeNode4.Text = infoItem.Name.Replace("_B", "");
				list2.Add(treeNode4);
			}
			portTree.Nodes.AddRange(list.ToArray());
			bandTree.Nodes.AddRange(list2.ToArray());
			portTree.NoEventWhenInit(bfirstInit: true);
			bandTree.NoEventWhenInit(bfirstInit: true);
			foreach (TreeNode node in portTree.Nodes)
			{
				foreach (TreeNode node2 in node.Nodes)
				{
					if (node2.Checked)
					{
						portTree.SetState(node2, 1);
					}
					else
					{
						portTree.SetState(node2, 0);
					}
				}
			}
			portTree.NoEventWhenInit(bfirstInit: false);
			portTree.Refresh();
			foreach (TreeNode node3 in bandTree.Nodes)
			{
				foreach (TreeNode node4 in node3.Nodes)
				{
					if (node4.Checked)
					{
						bandTree.SetState(node4, 1);
					}
					else
					{
						bandTree.SetState(node4, 0);
					}
				}
			}
			bandTree.NoEventWhenInit(bfirstInit: false);
			bandTree.Refresh();
		}
		catch
		{
		}
	}

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

	private void InitializeComponent()
	{
		this.components = new System.ComponentModel.Container();
		this.tbView = new System.Windows.Forms.TextBox();
		this.label1 = new System.Windows.Forms.Label();
		this.btnSave = new System.Windows.Forms.Button();
		this.btnCancel = new System.Windows.Forms.Button();
		this.portTree = new QDART_MFG_CfgEditor.QualCtrl.QualTreeView();
		this.bandTree = new QDART_MFG_CfgEditor.QualCtrl.QualTreeView();
		this.label2 = new System.Windows.Forms.Label();
		this.label3 = new System.Windows.Forms.Label();
		this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
		base.SuspendLayout();
		this.tbView.Location = new System.Drawing.Point(343, 334);
		this.tbView.Multiline = true;
		this.tbView.Name = "tbView";
		this.tbView.ReadOnly = true;
		this.tbView.Size = new System.Drawing.Size(367, 69);
		this.tbView.TabIndex = 1;
		this.label1.AutoSize = true;
		this.label1.Location = new System.Drawing.Point(340, 318);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(93, 13);
		this.label1.TabIndex = 2;
		this.label1.Text = "PORTS overview:";
		this.btnSave.Location = new System.Drawing.Point(107, 241);
		this.btnSave.Name = "btnSave";
		this.btnSave.Size = new System.Drawing.Size(91, 42);
		this.btnSave.TabIndex = 3;
		this.btnSave.Text = "Save";
		this.btnSave.UseVisualStyleBackColor = true;
		this.btnSave.Click += new System.EventHandler(btnSave_Click);
		this.btnCancel.Location = new System.Drawing.Point(293, 241);
		this.btnCancel.Name = "btnCancel";
		this.btnCancel.Size = new System.Drawing.Size(91, 42);
		this.btnCancel.TabIndex = 3;
		this.btnCancel.Text = "Cancel";
		this.btnCancel.UseVisualStyleBackColor = true;
		this.btnCancel.Click += new System.EventHandler(btnCancel_Click);
		this.portTree.Location = new System.Drawing.Point(36, 33);
		this.portTree.Name = "portTree";
		this.portTree.Size = new System.Drawing.Size(192, 179);
		this.portTree.TabIndex = 4;
		this.bandTree.Location = new System.Drawing.Point(265, 33);
		this.bandTree.Name = "bandTree";
		this.bandTree.Size = new System.Drawing.Size(192, 179);
		this.bandTree.TabIndex = 5;
		this.label2.AutoSize = true;
		this.label2.Location = new System.Drawing.Point(33, 17);
		this.label2.Name = "label2";
		this.label2.Size = new System.Drawing.Size(108, 13);
		this.label2.TabIndex = 6;
		this.label2.Text = "PORTS ( RF Chains )";
		this.label3.AutoSize = true;
		this.label3.Location = new System.Drawing.Point(262, 17);
		this.label3.Name = "label3";
		this.label3.Size = new System.Drawing.Size(105, 13);
		this.label3.TabIndex = 6;
		this.label3.Text = "* BANDS ( Optional )";
		this.toolTip1.SetToolTip(this.label3, "Advanced usage:\r\nOnly  for more than one RF connector of phone used for one technology.\r\n\r\nFor example:\r\nLTE BC1 and BC39 using 2 seperate RF connectors.");
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(501, 308);
		base.Controls.Add(this.label3);
		base.Controls.Add(this.label2);
		base.Controls.Add(this.bandTree);
		base.Controls.Add(this.portTree);
		base.Controls.Add(this.btnCancel);
		base.Controls.Add(this.btnSave);
		base.Controls.Add(this.label1);
		base.Controls.Add(this.tbView);
		base.MaximizeBox = false;
		base.Name = "RoutingCfgEditPorts";
		base.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
		this.Text = "PORTS/BANDS Configuration";
		base.ResumeLayout(false);
		base.PerformLayout();
	}
}
