using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;

namespace Scripts
{
	public class ChangeResultsMode : IScript
	{
		public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
		{
			// The name of the desired template is passed to the script as the value
			var templateName = value?.ToString();
			if (!string.IsNullOrWhiteSpace(templateName))
			{
				// Find the ticker and the desired template subwidget
				var resultsTicker = item.Theme.Widgets.Find("W_ResultsTicker");
				var template = resultsTicker.SubWidgets.Find(templateName);
				
				// Change the template
				if (template != null)
				{
					resultsTicker.Ticker.TemplateSubWidget = template;
				}
				else
				{
					Console.WriteLine("Invalid results ticker template subwidget name: " + templateName);
				}
			}
			return null;
		}
	}
}