using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text;
using System.Windows;
using System.Windows.Media;
using QC.QsprShared.GlobalData;

namespace QC.QsprTestObjects.Tests.Base;

public class TestUserInterfaceProperties : INotifyPropertyChanged
{
	private string nodeImageUri;

	private string nodeExpandedImageUri;

	private string nodeCollapsedImageUri;

	private string statusImageUri = "/QSPR;component/Icons/EmptyState.png";

	private bool statusSet;

	private bool isLocked;

	private FolderTest actualSequenceLoopFolder;

	private bool isDirty;

	private bool isInEditMode;

	private bool isReadOnly;

	private string backColor;

	private string foreColor;

	private FontWeight fontWeight;

	private string toolTipText;

	private Visibility tooltipVisiblility = Visibility.Collapsed;

	private int maxEditTextBoxWidth = 150;

	private int minEditTextBoxWidth = 150;

	private bool visible = true;

	public string NodeImageUri
	{
		get
		{
			return nodeImageUri;
		}
		set
		{
			nodeImageUri = value;
			if (actualSequenceLoopFolder != null)
			{
				actualSequenceLoopFolder.TestUserInterfaceProperties.NodeImageUri = value;
			}
			RaiseOnPropertyChangedEvent("NodeImageUri");
		}
	}

	public string NodeExpandedImageUri
	{
		get
		{
			return nodeExpandedImageUri;
		}
		set
		{
			nodeExpandedImageUri = value;
			if (actualSequenceLoopFolder != null)
			{
				actualSequenceLoopFolder.TestUserInterfaceProperties.NodeExpandedImageUri = value;
			}
			RaiseOnPropertyChangedEvent("NodeExpandedImageUri");
		}
	}

	public string NodeCollapsedImageUri
	{
		get
		{
			return nodeCollapsedImageUri;
		}
		set
		{
			nodeCollapsedImageUri = value;
			if (actualSequenceLoopFolder != null)
			{
				actualSequenceLoopFolder.TestUserInterfaceProperties.NodeCollapsedImageUri = value;
			}
			RaiseOnPropertyChangedEvent("NodeCollapsedImageUri");
		}
	}

	public string StatusImageUri
	{
		get
		{
			return statusImageUri;
		}
		set
		{
			if (statusImageUri != value)
			{
				if (string.IsNullOrWhiteSpace(value))
				{
					statusImageUri = "/QSPR;component/Icons/EmptyState.png";
					StatusSet = false;
				}
				else
				{
					statusImageUri = value;
					StatusSet = true;
				}
				RaiseOnPropertyChangedEvent("StatusImageUri");
			}
		}
	}

	public bool StatusSet
	{
		get
		{
			return statusSet;
		}
		set
		{
			if (statusSet != value)
			{
				statusSet = value;
				RaiseOnPropertyChangedEvent("StatusSet");
			}
		}
	}

	public bool IsLocked
	{
		get
		{
			return isLocked;
		}
		set
		{
			if (isLocked != value)
			{
				isLocked = value;
				RaiseOnPropertyChangedEvent("IsLocked");
			}
		}
	}

	public FolderTest ActualSequenceLoopFolder
	{
		get
		{
			return actualSequenceLoopFolder;
		}
		set
		{
			actualSequenceLoopFolder = value;
		}
	}

	public string OriginalTestNameBeforeEdit { get; protected set; }

	public bool IsDirty
	{
		get
		{
			return isDirty;
		}
		set
		{
			isDirty = value;
			RaiseOnPropertyChangedEvent("IsDirty");
		}
	}

	public bool IsInEditMode
	{
		get
		{
			return isInEditMode;
		}
		set
		{
			isInEditMode = value;
			if (isInEditMode)
			{
				OriginalTestNameBeforeEdit = Owner.Properties.TestName;
			}
			else
			{
				OriginalTestNameBeforeEdit = string.Empty;
			}
			RaiseOnPropertyChangedEvent("IsInEditMode");
		}
	}

	public bool IsReadOnly
	{
		get
		{
			return isReadOnly;
		}
		set
		{
			isReadOnly = value;
			RaiseOnPropertyChangedEvent("IsReadOnly");
		}
	}

	public string BackColor
	{
		get
		{
			return backColor;
		}
		set
		{
			backColor = value;
			RaiseOnPropertyChangedEvent("BackColor");
		}
	}

	public string ForeColor
	{
		get
		{
			return foreColor;
		}
		set
		{
			foreColor = value;
			RaiseOnPropertyChangedEvent("ForeColor");
		}
	}

	public FontWeight FontWeight
	{
		get
		{
			return fontWeight;
		}
		set
		{
			fontWeight = value;
			RaiseOnPropertyChangedEvent("FontWeight");
		}
	}

	public string ToolTipText
	{
		get
		{
			toolTipText = GetToolTipText(Owner);
			return toolTipText;
		}
		set
		{
			toolTipText = value;
			RaiseOnPropertyChangedEvent("ToolTipText");
		}
	}

	public Visibility ToolTipVisibility
	{
		get
		{
			if (tooltipVisiblility == Visibility.Collapsed)
			{
				tooltipVisiblility = GetToolTipVisibility();
			}
			return tooltipVisiblility;
		}
		set
		{
			tooltipVisiblility = value;
			RaiseOnPropertyChangedEvent("ToolTipVisibility");
		}
	}

	public int MaxEditTextBoxWidth
	{
		get
		{
			return maxEditTextBoxWidth;
		}
		set
		{
			maxEditTextBoxWidth = value;
			RaiseOnPropertyChangedEvent("MaxEditTextBoxWidth");
		}
	}

	public int MinEditTextBoxWidth
	{
		get
		{
			return minEditTextBoxWidth;
		}
		set
		{
			minEditTextBoxWidth = value;
			RaiseOnPropertyChangedEvent("MinEditTextBoxWidth");
		}
	}

	public bool Visible
	{
		get
		{
			return visible;
		}
		set
		{
			visible = value;
			RaiseOnPropertyChangedEvent("Visible");
		}
	}

	private QTMData qtmData => Owner.Root.Scheduler.QTMData;

	public BaseTest Owner { get; protected set; }

	public ObservableCollection<string> NodeImagesUriCollection { get; protected set; }

	public event PropertyChangedEventHandler PropertyChanged;

	public void ResetRunTimeAttributes(bool clearStatusIcon = true)
	{
		Owner.RuntimeAttributes.Reset();
		if (clearStatusIcon)
		{
			StatusImageUri = "";
		}
	}

	private Visibility GetToolTipVisibility()
	{
		if (!qtmData.WConfig.ShowToolTips)
		{
			return Visibility.Hidden;
		}
		return Visibility.Visible;
	}

	private string GetToolTipText(BaseTest test)
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.Append(test.Properties.RealName);
		if (test is FolderTest)
		{
			stringBuilder.Append(Environment.NewLine + Environment.NewLine + test.Properties.TestName);
			foreach (BaseTest test2 in ((FolderTest)test).TestList)
			{
				stringBuilder.Append(Environment.NewLine + " -- " + test2.Properties.TestName);
			}
		}
		if (test is RootTest)
		{
			stringBuilder.AppendLine(Environment.NewLine + "REGISTRATION INFORMATION");
			stringBuilder.AppendLine("   Tree Changed: " + Owner.Root.Scheduler.GlobalStatus.RegistrationStatus.TreeChanged);
			stringBuilder.AppendLine("   Parameter Attribute Changed: " + Owner.Root.Scheduler.GlobalStatus.RegistrationStatus.ParameterAttributeChanged);
			stringBuilder.AppendLine("   Tree Node Deleted: " + Owner.Root.Scheduler.GlobalStatus.RegistrationStatus.TreeNodeDeleted);
			stringBuilder.AppendLine("   Tree Selection Changed: " + Owner.Root.Scheduler.GlobalStatus.RegistrationStatus.TreeSelectionChanged);
			stringBuilder.AppendLine("   Registry Changed: " + Owner.Root.Scheduler.GlobalStatus.RegistrationStatus.RegistryChanged);
			stringBuilder.AppendLine("   Tree Syncronized: " + Owner.Root.Scheduler.GlobalStatus.RegistrationStatus.Synchronized);
			stringBuilder.AppendLine("   Plugin Data Changed: " + Owner.Root.Scheduler.GlobalStatus.RegistrationStatus.PluginDataChanged);
			stringBuilder.AppendLine("   Linked Tree Data Changed: " + Owner.Root.Scheduler.GlobalStatus.RegistrationStatus.LinkedTreeChanged);
			stringBuilder.AppendLine("   Loop Changed: " + Owner.Root.Scheduler.GlobalStatus.RegistrationStatus.LoopChanged);
			stringBuilder.AppendLine("   Loop Selection Changed: " + Owner.Root.Scheduler.GlobalStatus.RegistrationStatus.LoopSelectionChanged);
			stringBuilder.AppendLine("   Loop Row Deleted: " + Owner.Root.Scheduler.GlobalStatus.RegistrationStatus.LoopRowDeleted);
			stringBuilder.AppendLine("   Loop Value Changed: " + Owner.Root.Scheduler.GlobalStatus.RegistrationStatus.LoopValueChanged);
			stringBuilder.AppendLine("   Tree Config Changed: " + Owner.Root.Scheduler.GlobalStatus.RegistrationStatus.TreeConfigChanged);
		}
		return stringBuilder.ToString();
	}

	public TestUserInterfaceProperties(BaseTest owner)
	{
		Owner = owner;
		NodeImagesUriCollection = new ObservableCollection<string>();
		backColor = Colors.Transparent.ToString();
		foreColor = Colors.Black.ToString();
	}

	protected void RaiseOnPropertyChangedEvent(string propertyName)
	{
		if (this.PropertyChanged != null)
		{
			this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
		}
	}
}
