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

namespace QC.QMSCT;

public class InputForm : Form
{
	public delegate bool IsValidInput(string input);

	public IsValidInput ValidFunction;

	private IContainer components;

	private TextBox txtInput;

	private Label lblTitle;

	private Button btnOK;

	private Button btnCancel;

	public string InputText
	{
		get
		{
			return txtInput.Text;
		}
		set
		{
			txtInput.Text = value;
		}
	}

	public InputForm()
	{
		InitializeComponent();
	}

	public DialogResult ShowUserInput(string title = "Input")
	{
		lblTitle.Text = title;
		return ShowDialog();
	}

	private void btnOK_Click(object sender, EventArgs e)
	{
		if (ValidFunction != null && !ValidFunction(InputText))
		{
			txtInput.Focus();
		}
		else
		{
			base.DialogResult = DialogResult.OK;
		}
	}

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

	private void InitializeComponent()
	{
		this.txtInput = new System.Windows.Forms.TextBox();
		this.lblTitle = new System.Windows.Forms.Label();
		this.btnOK = new System.Windows.Forms.Button();
		this.btnCancel = new System.Windows.Forms.Button();
		base.SuspendLayout();
		this.txtInput.Location = new System.Drawing.Point(32, 55);
		this.txtInput.Name = "txtInput";
		this.txtInput.Size = new System.Drawing.Size(412, 20);
		this.txtInput.TabIndex = 0;
		this.lblTitle.AutoSize = true;
		this.lblTitle.Location = new System.Drawing.Point(29, 25);
		this.lblTitle.Name = "lblTitle";
		this.lblTitle.Size = new System.Drawing.Size(27, 13);
		this.lblTitle.TabIndex = 1;
		this.lblTitle.Text = "Title";
		this.btnOK.Location = new System.Drawing.Point(119, 94);
		this.btnOK.Name = "btnOK";
		this.btnOK.Size = new System.Drawing.Size(97, 27);
		this.btnOK.TabIndex = 2;
		this.btnOK.Text = "OK";
		this.btnOK.UseVisualStyleBackColor = true;
		this.btnOK.Click += new System.EventHandler(btnOK_Click);
		this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
		this.btnCancel.Location = new System.Drawing.Point(261, 94);
		this.btnCancel.Name = "btnCancel";
		this.btnCancel.Size = new System.Drawing.Size(97, 27);
		this.btnCancel.TabIndex = 3;
		this.btnCancel.Text = "Cancel";
		this.btnCancel.UseVisualStyleBackColor = true;
		base.AcceptButton = this.btnOK;
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.CancelButton = this.btnCancel;
		base.ClientSize = new System.Drawing.Size(477, 134);
		base.Controls.Add(this.btnCancel);
		base.Controls.Add(this.btnOK);
		base.Controls.Add(this.lblTitle);
		base.Controls.Add(this.txtInput);
		base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
		base.MaximizeBox = false;
		base.MinimizeBox = false;
		base.Name = "InputForm";
		this.Text = "QMSCT";
		base.ResumeLayout(false);
		base.PerformLayout();
	}
}
