using System.Collections.Generic;
using System.Linq;
using QC.QsprTestObjects.Tests.Base;

namespace QC.QTMApplication;

public static class TreeViewNodeImageExtensions
{
	public static void ConfigureNodeImage(this BaseTest baseTest, string collapsedImageUri, string expandedImageUri)
	{
		baseTest.TestUserInterfaceProperties.NodeCollapsedImageUri = collapsedImageUri;
		baseTest.TestUserInterfaceProperties.NodeExpandedImageUri = expandedImageUri;
		baseTest.TestUserInterfaceProperties.NodeImageUri = (baseTest.Properties.Expanded ? expandedImageUri : collapsedImageUri);
	}

	public static void ClearNodeImages(this BaseTest baseTest)
	{
		baseTest.TestUserInterfaceProperties.NodeImagesUriCollection.Clear();
	}

	public static IEnumerable<BaseTest> Descendants(this BaseTest root)
	{
		Stack<BaseTest> nodes = new Stack<BaseTest>(new BaseTest[1] { root });
		while (nodes.Any())
		{
			BaseTest node = nodes.Pop();
			yield return node;
			if (!(node is FolderTest))
			{
				continue;
			}
			foreach (BaseTest test in ((FolderTest)node).TestList)
			{
				nodes.Push(test);
			}
		}
	}
}
