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

namespace QC.CorpTest.Libraries.QsprSchemaLibrary;

public class QSPRLoopConditionsConfigurator : Form
{
	private IContainer components;

	private Button btnCancel;

	private ListBox lstLoopConditions;

	private TextBox txtNewLoopCondition;

	private Button btnAdd;

	private Button btnRemove;

	private Button btnSave;

	private string loopConditionsSeperator = ",";

	private bool isLoopConditionsChanged;

	private string currentLoopConditions = string.Empty;

	public string ConfiguredLoopConditions
	{
		get
		{
			if (isLoopConditionsChanged)
			{
				currentLoopConditions = GetCurrentConfigureLoopConditions();
			}
			return currentLoopConditions;
		}
	}

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

	private void InitializeComponent()
	{
		this.btnCancel = new System.Windows.Forms.Button();
		this.lstLoopConditions = new System.Windows.Forms.ListBox();
		this.txtNewLoopCondition = new System.Windows.Forms.TextBox();
		this.btnAdd = new System.Windows.Forms.Button();
		this.btnRemove = new System.Windows.Forms.Button();
		this.btnSave = new System.Windows.Forms.Button();
		base.SuspendLayout();
		this.btnCancel.Location = new System.Drawing.Point(169, 183);
		this.btnCancel.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
		this.btnCancel.Name = "btnCancel";
		this.btnCancel.Size = new System.Drawing.Size(62, 19);
		this.btnCancel.TabIndex = 0;
		this.btnCancel.Text = "Cancel";
		this.btnCancel.UseVisualStyleBackColor = true;
		this.btnCancel.Click += new System.EventHandler(btnCancel_Click);
		this.lstLoopConditions.FormattingEnabled = true;
		this.lstLoopConditions.Location = new System.Drawing.Point(9, 36);
		this.lstLoopConditions.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
		this.lstLoopConditions.Name = "lstLoopConditions";
		this.lstLoopConditions.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
		this.lstLoopConditions.Size = new System.Drawing.Size(223, 134);
		this.lstLoopConditions.TabIndex = 1;
		this.lstLoopConditions.SelectedValueChanged += new System.EventHandler(lstLoopConditions_SelectedValueChanged);
		this.txtNewLoopCondition.Location = new System.Drawing.Point(9, 8);
		this.txtNewLoopCondition.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
		this.txtNewLoopCondition.Name = "txtNewLoopCondition";
		this.txtNewLoopCondition.Size = new System.Drawing.Size(143, 20);
		this.txtNewLoopCondition.TabIndex = 2;
		this.txtNewLoopCondition.TextChanged += new System.EventHandler(txtNewLoopCondition_TextChanged);
		this.btnAdd.Enabled = false;
		this.btnAdd.Location = new System.Drawing.Point(155, 8);
		this.btnAdd.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
		this.btnAdd.Name = "btnAdd";
		this.btnAdd.Size = new System.Drawing.Size(76, 19);
		this.btnAdd.TabIndex = 3;
		this.btnAdd.Text = "Add";
		this.btnAdd.UseVisualStyleBackColor = true;
		this.btnAdd.Click += new System.EventHandler(btnAdd_Click);
		this.btnRemove.Enabled = false;
		this.btnRemove.Location = new System.Drawing.Point(9, 183);
		this.btnRemove.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
		this.btnRemove.Name = "btnRemove";
		this.btnRemove.Size = new System.Drawing.Size(74, 19);
		this.btnRemove.TabIndex = 4;
		this.btnRemove.Text = "Remove";
		this.btnRemove.UseVisualStyleBackColor = true;
		this.btnRemove.Click += new System.EventHandler(btnRemove_Click);
		this.btnSave.Location = new System.Drawing.Point(89, 183);
		this.btnSave.Name = "btnSave";
		this.btnSave.Size = new System.Drawing.Size(74, 19);
		this.btnSave.TabIndex = 5;
		this.btnSave.Text = "Save";
		this.btnSave.UseVisualStyleBackColor = true;
		this.btnSave.Click += new System.EventHandler(btnSave_Click);
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(241, 211);
		base.Controls.Add(this.btnSave);
		base.Controls.Add(this.btnRemove);
		base.Controls.Add(this.btnAdd);
		base.Controls.Add(this.txtNewLoopCondition);
		base.Controls.Add(this.lstLoopConditions);
		base.Controls.Add(this.btnCancel);
		base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
		base.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
		base.MaximizeBox = false;
		base.MinimizeBox = false;
		base.Name = "QSPRLoopConditionsConfigurator";
		base.ShowIcon = false;
		base.ShowInTaskbar = false;
		base.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
		this.Text = "Configure QSPR Loop Conditons";
		base.ResumeLayout(false);
		base.PerformLayout();
	}

	private string GetCurrentConfigureLoopConditions()
	{
		string[] array = new string[lstLoopConditions.Items.Count];
		for (int i = 0; i < lstLoopConditions.Items.Count; i++)
		{
			array[i] = lstLoopConditions.Items[i].ToString();
		}
		return string.Join(loopConditionsSeperator, array);
	}

	public QSPRLoopConditionsConfigurator(string loopConditionsList)
	{
		InitializeComponent();
		currentLoopConditions = loopConditionsList;
		AddToListBox(loopConditionsList);
	}

	private void AddToListBox(string loopConditionsList)
	{
		lstLoopConditions.Items.AddRange(loopConditionsList.Split(new string[1] { loopConditionsSeperator }, StringSplitOptions.RemoveEmptyEntries));
	}

	private void btnAdd_Click(object sender, EventArgs e)
	{
		if (!lstLoopConditions.Items.Contains(txtNewLoopCondition.Text))
		{
			lstLoopConditions.Items.Insert(0, txtNewLoopCondition.Text);
		}
		txtNewLoopCondition.Text = string.Empty;
	}

	private void txtNewLoopCondition_TextChanged(object sender, EventArgs e)
	{
		btnAdd.Enabled = txtNewLoopCondition.Text.Length > 0;
	}

	private void lstLoopConditions_SelectedValueChanged(object sender, EventArgs e)
	{
		btnRemove.Enabled = lstLoopConditions.SelectedIndices.Count > 0;
	}

	private void btnRemove_Click(object sender, EventArgs e)
	{
		lstLoopConditions.BeginUpdate();
		object[] array = new object[lstLoopConditions.SelectedItems.Count];
		lstLoopConditions.SelectedItems.CopyTo(array, 0);
		for (int i = 0; i < array.Length; i++)
		{
			lstLoopConditions.Items.Remove(array[i]);
		}
		lstLoopConditions.EndUpdate();
	}

	private void btnSave_Click(object sender, EventArgs e)
	{
		isLoopConditionsChanged = true;
		Close();
	}

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