using System;
using System.ComponentModel;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace QC.QTMToolKit;

public class InputForm : Form
{
	public enum InputDataTypes
	{
		StringType,
		IntType,
		DoubleType
	}

	private InputDataTypes dType;

	private int intData;

	private double doubleData;

	private string stringData;

	private string regularExpression = "";

	private RegexOptions regExOption = RegexOptions.None;

	private IContainer components = null;

	private Button btnOk;

	public Label lblMessage;

	public TextBox txtInput;

	private ErrorProvider errorProvider;

	public InputDataTypes DataType
	{
		get
		{
			return dType;
		}
		set
		{
			dType = value;
		}
	}

	public int IntData
	{
		get
		{
			return intData;
		}
		set
		{
			intData = value;
		}
	}

	public double DoubleData
	{
		get
		{
			return doubleData;
		}
		set
		{
			doubleData = value;
		}
	}

	public string StringData
	{
		get
		{
			return stringData;
		}
		set
		{
			stringData = value;
		}
	}

	public string RegularExpression
	{
		get
		{
			return regularExpression;
		}
		set
		{
			regularExpression = value;
		}
	}

	public RegexOptions RegexOption
	{
		get
		{
			return regExOption;
		}
		set
		{
			regExOption = value;
		}
	}

	public InputForm()
	{
		InitializeComponent();
	}

	private void btnOk_Click(object sender, EventArgs e)
	{
		switch (dType)
		{
		case InputDataTypes.StringType:
		{
			if (regularExpression.Length <= 0)
			{
				stringData = txtInput.Text;
				break;
			}
			Regex regex = new Regex(regularExpression, regExOption);
			Match match = regex.Match(txtInput.Text);
			if (!match.Success)
			{
				errorProvider.SetError(txtInput, $"The input did not match the regular expression {regularExpression}");
				return;
			}
			if (match.Value != txtInput.Text)
			{
				errorProvider.SetError(txtInput, $"The input is not a exact match for the regular expression {regularExpression}");
				return;
			}
			errorProvider.Clear();
			break;
		}
		case InputDataTypes.IntType:
			if (!int.TryParse(txtInput.Text, out intData))
			{
				MessageBox.Show("Input should be  Int data type");
				return;
			}
			break;
		case InputDataTypes.DoubleType:
			if (!double.TryParse(txtInput.Text, out doubleData))
			{
				MessageBox.Show("Input should be  double data type");
				return;
			}
			break;
		}
		base.DialogResult = DialogResult.OK;
	}

	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.lblMessage = new System.Windows.Forms.Label();
		this.txtInput = new System.Windows.Forms.TextBox();
		this.btnOk = new System.Windows.Forms.Button();
		this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components);
		((System.ComponentModel.ISupportInitialize)this.errorProvider).BeginInit();
		base.SuspendLayout();
		this.lblMessage.Location = new System.Drawing.Point(19, 18);
		this.lblMessage.Name = "lblMessage";
		this.lblMessage.Size = new System.Drawing.Size(371, 43);
		this.lblMessage.TabIndex = 2;
		this.lblMessage.Text = "lblMessage";
		this.lblMessage.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
		this.txtInput.Location = new System.Drawing.Point(22, 71);
		this.txtInput.Name = "txtInput";
		this.txtInput.Size = new System.Drawing.Size(368, 20);
		this.txtInput.TabIndex = 0;
		this.btnOk.Location = new System.Drawing.Point(321, 102);
		this.btnOk.Name = "btnOk";
		this.btnOk.Size = new System.Drawing.Size(75, 23);
		this.btnOk.TabIndex = 1;
		this.btnOk.Text = "OK";
		this.btnOk.UseVisualStyleBackColor = true;
		this.btnOk.Click += new System.EventHandler(btnOk_Click);
		this.errorProvider.ContainerControl = this;
		base.AcceptButton = this.btnOk;
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(408, 131);
		base.Controls.Add(this.btnOk);
		base.Controls.Add(this.txtInput);
		base.Controls.Add(this.lblMessage);
		base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
		base.MaximizeBox = false;
		base.MinimizeBox = false;
		base.Name = "InputForm";
		base.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
		this.Text = "InputForm";
		base.TopMost = true;
		((System.ComponentModel.ISupportInitialize)this.errorProvider).EndInit();
		base.ResumeLayout(false);
		base.PerformLayout();
	}
}
