using System;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
using QCRPG.TSL.BT.Packets;

namespace QCRPG.TSL.BT;

public class ContinuousModeOption : Form
{
	private byte ContinuousPower;

	private int ContinuousChannel;

	private ProdTestTxContinuous.UserFieldsWrapper.TransmitTypeEnum TransmitType;

	private byte PatternLength;

	private string Pattern = "00000000";

	private IContainer components;

	private GroupBox groupBox1;

	private Label label5;

	private TextBox patternTextBox;

	private Label label4;

	private TextBox patternLengthTextBox;

	private Label label3;

	private ComboBox testTypeComboBox;

	private Label label2;

	private TextBox continuousTransmitChannelTextBox;

	private Label label1;

	private TextBox continuousPowerTextBox;

	private Button okButton;

	private Button cancelButton;

	public byte continuousPower
	{
		get
		{
			return ContinuousPower;
		}
		set
		{
			ContinuousPower = value;
		}
	}

	public int continuousChannel
	{
		get
		{
			return ContinuousChannel;
		}
		set
		{
			ContinuousChannel = value;
		}
	}

	public ProdTestTxContinuous.UserFieldsWrapper.TransmitTypeEnum transmitType
	{
		get
		{
			return TransmitType;
		}
		set
		{
			TransmitType = value;
		}
	}

	public byte patternLength
	{
		get
		{
			return PatternLength;
		}
		set
		{
			PatternLength = value;
		}
	}

	public string pattern
	{
		get
		{
			return Pattern;
		}
		set
		{
			Pattern = value;
		}
	}

	public ContinuousModeOption()
	{
		InitializeComponent();
	}

	private void ContinuousTest_Load(object sender, EventArgs e)
	{
		testTypeComboBox.DataSource = Enum.GetValues(typeof(ProdTestTxContinuous.UserFieldsWrapper.TransmitTypeEnum));
		UpdateTestGUIParas(ContinuousPower, ContinuousChannel, TransmitType, PatternLength, Pattern);
	}

	private void UpdateTestGUIParas(byte ContinuousPower, int ContinuousChannel, ProdTestTxContinuous.UserFieldsWrapper.TransmitTypeEnum TransmitType, byte PatternLength, string Pattern)
	{
		continuousPowerTextBox.Text = ContinuousPower.ToString();
		continuousTransmitChannelTextBox.Text = ContinuousChannel.ToString();
		testTypeComboBox.SelectedIndex = (int)TransmitType;
		patternLengthTextBox.Text = PatternLength.ToString();
		patternTextBox.Text = Pattern;
	}

	private void patternTextBox_TextChanged(object sender, EventArgs e)
	{
		string s = patternTextBox.Text;
		long result = 0L;
		if (!long.TryParse(s, NumberStyles.HexNumber, null, out result))
		{
			patternTextBox.Text = "000000000";
			Pattern = "00000000";
			MessageBox.Show("Hex value is required.");
		}
	}

	private void testTypeComboBox_SelectedIndexChanged(object sender, EventArgs e)
	{
		if (testTypeComboBox.Text == "ONE_PATTERN_GFSK" || testTypeComboBox.Text == "TWO_PATTERN_PI_DIV_4_DQPSK" || testTypeComboBox.Text == "THREE_PATTERN_8DPSK")
		{
			patternLengthTextBox.Enabled = true;
			patternTextBox.Enabled = true;
		}
		else
		{
			patternLengthTextBox.Enabled = false;
			patternTextBox.Enabled = false;
		}
	}

	private void okButton_Click(object sender, EventArgs e)
	{
		byte.TryParse(continuousPowerTextBox.Text.ToString(), out ContinuousPower);
		int.TryParse(continuousTransmitChannelTextBox.Text.ToString(), out ContinuousChannel);
		TransmitType = (ProdTestTxContinuous.UserFieldsWrapper.TransmitTypeEnum)testTypeComboBox.SelectedIndex;
		byte.TryParse(patternLengthTextBox.Text.ToString(), out PatternLength);
		Pattern = patternTextBox.Text.ToString();
		Hide();
	}

	private void cancelButton_Click(object sender, EventArgs e)
	{
		Hide();
	}

	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.label5 = new System.Windows.Forms.Label();
		this.patternTextBox = new System.Windows.Forms.TextBox();
		this.label4 = new System.Windows.Forms.Label();
		this.patternLengthTextBox = new System.Windows.Forms.TextBox();
		this.label3 = new System.Windows.Forms.Label();
		this.testTypeComboBox = new System.Windows.Forms.ComboBox();
		this.label2 = new System.Windows.Forms.Label();
		this.continuousTransmitChannelTextBox = new System.Windows.Forms.TextBox();
		this.label1 = new System.Windows.Forms.Label();
		this.continuousPowerTextBox = new System.Windows.Forms.TextBox();
		this.okButton = new System.Windows.Forms.Button();
		this.cancelButton = new System.Windows.Forms.Button();
		this.groupBox1.SuspendLayout();
		base.SuspendLayout();
		this.groupBox1.Controls.Add(this.label5);
		this.groupBox1.Controls.Add(this.patternTextBox);
		this.groupBox1.Controls.Add(this.label4);
		this.groupBox1.Controls.Add(this.patternLengthTextBox);
		this.groupBox1.Controls.Add(this.label3);
		this.groupBox1.Controls.Add(this.testTypeComboBox);
		this.groupBox1.Controls.Add(this.label2);
		this.groupBox1.Controls.Add(this.continuousTransmitChannelTextBox);
		this.groupBox1.Controls.Add(this.label1);
		this.groupBox1.Controls.Add(this.continuousPowerTextBox);
		this.groupBox1.Location = new System.Drawing.Point(13, 13);
		this.groupBox1.Name = "groupBox1";
		this.groupBox1.Size = new System.Drawing.Size(267, 208);
		this.groupBox1.TabIndex = 0;
		this.groupBox1.TabStop = false;
		this.label5.AutoSize = true;
		this.label5.Location = new System.Drawing.Point(112, 173);
		this.label5.Name = "label5";
		this.label5.Size = new System.Drawing.Size(113, 13);
		this.label5.TabIndex = 19;
		this.label5.Text = "Pattern (Hex: UINT32)";
		this.patternTextBox.Enabled = false;
		this.patternTextBox.Location = new System.Drawing.Point(6, 170);
		this.patternTextBox.MaxLength = 8;
		this.patternTextBox.Name = "patternTextBox";
		this.patternTextBox.Size = new System.Drawing.Size(100, 20);
		this.patternTextBox.TabIndex = 18;
		this.patternTextBox.TextChanged += new System.EventHandler(patternTextBox_TextChanged);
		this.label4.AutoSize = true;
		this.label4.Location = new System.Drawing.Point(112, 138);
		this.label4.Name = "label4";
		this.label4.Size = new System.Drawing.Size(149, 13);
		this.label4.TabIndex = 17;
		this.label4.Text = "Pattern Length (decimal: 1-32)";
		this.patternLengthTextBox.Enabled = false;
		this.patternLengthTextBox.Location = new System.Drawing.Point(6, 135);
		this.patternLengthTextBox.MaxLength = 2;
		this.patternLengthTextBox.Name = "patternLengthTextBox";
		this.patternLengthTextBox.Size = new System.Drawing.Size(100, 20);
		this.patternLengthTextBox.TabIndex = 16;
		this.label3.AutoSize = true;
		this.label3.Location = new System.Drawing.Point(153, 97);
		this.label3.Name = "label3";
		this.label3.Size = new System.Drawing.Size(55, 13);
		this.label3.TabIndex = 15;
		this.label3.Text = "Test Type";
		this.testTypeComboBox.FormattingEnabled = true;
		this.testTypeComboBox.Location = new System.Drawing.Point(6, 94);
		this.testTypeComboBox.Name = "testTypeComboBox";
		this.testTypeComboBox.Size = new System.Drawing.Size(141, 21);
		this.testTypeComboBox.TabIndex = 14;
		this.testTypeComboBox.SelectedIndexChanged += new System.EventHandler(testTypeComboBox_SelectedIndexChanged);
		this.label2.AutoSize = true;
		this.label2.Location = new System.Drawing.Point(112, 58);
		this.label2.Name = "label2";
		this.label2.Size = new System.Drawing.Size(145, 13);
		this.label2.TabIndex = 13;
		this.label2.Text = "Continuous Transmit Channel";
		this.continuousTransmitChannelTextBox.Location = new System.Drawing.Point(6, 55);
		this.continuousTransmitChannelTextBox.MaxLength = 2;
		this.continuousTransmitChannelTextBox.Name = "continuousTransmitChannelTextBox";
		this.continuousTransmitChannelTextBox.Size = new System.Drawing.Size(100, 20);
		this.continuousTransmitChannelTextBox.TabIndex = 12;
		this.label1.AutoSize = true;
		this.label1.Location = new System.Drawing.Point(112, 22);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(61, 13);
		this.label1.TabIndex = 11;
		this.label1.Text = "Power (0-9)";
		this.continuousPowerTextBox.Location = new System.Drawing.Point(6, 19);
		this.continuousPowerTextBox.MaxLength = 2;
		this.continuousPowerTextBox.Name = "continuousPowerTextBox";
		this.continuousPowerTextBox.Size = new System.Drawing.Size(100, 20);
		this.continuousPowerTextBox.TabIndex = 10;
		this.okButton.Location = new System.Drawing.Point(44, 227);
		this.okButton.Name = "okButton";
		this.okButton.Size = new System.Drawing.Size(75, 23);
		this.okButton.TabIndex = 1;
		this.okButton.Text = "OK";
		this.okButton.UseVisualStyleBackColor = true;
		this.okButton.Click += new System.EventHandler(okButton_Click);
		this.cancelButton.Location = new System.Drawing.Point(176, 227);
		this.cancelButton.Name = "cancelButton";
		this.cancelButton.Size = new System.Drawing.Size(75, 23);
		this.cancelButton.TabIndex = 2;
		this.cancelButton.Text = "Cancel";
		this.cancelButton.UseVisualStyleBackColor = true;
		this.cancelButton.Click += new System.EventHandler(cancelButton_Click);
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(292, 272);
		base.Controls.Add(this.cancelButton);
		base.Controls.Add(this.okButton);
		base.Controls.Add(this.groupBox1);
		base.Name = "ContinuousModeOption";
		base.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
		this.Text = "Continuous Mode Option";
		base.Load += new System.EventHandler(ContinuousTest_Load);
		this.groupBox1.ResumeLayout(false);
		this.groupBox1.PerformLayout();
		base.ResumeLayout(false);
	}
}
