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

namespace Scripts
{
	public class ResetResultsScroll : IScript
	{
		private const int ScrollAmount = -440;
	
		public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
		{
			// Find widgets
			var results = item.Theme.Widgets.Find("W_ResultsTicker");

			// Find animation item
			var anim = item.Theme.Animations.Find("A_ScrollResults");
			
			// Get the translateY animation the keyframes 
			var translate = (TranslateAnimation) anim.AnimatedProperties[0];
			var startKeyframe = (DoubleAnimationKeyFrame) translate.KeyFrames[0];
			var endKeyframe = (DoubleAnimationKeyFrame) translate.KeyFrames[1];
			
			// Reset the keyframes
			startKeyframe.Value = 0;
			endKeyframe.Value = ScrollAmount;

			// Reset current state
			results.Animation.TranslateY = 0;

			return null;
		}
	}
}