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

namespace Scripts
{
	public class ResetGridScroll : IScript
	{
		private const int ScrollAmount = -480;
	
		public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
		{
			// Find widgets
			var left = item.Theme.Widgets.Find("W_GridLeft");
			var right = item.Theme.Widgets.Find("W_GridRight");

			// Find animation item
			var anim = item.Theme.Animations.Find("A_ScrollGrid");
			
			// 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
			left.Animation.TranslateY = 0;
			right.Animation.TranslateY = 0;

			return null;
		}
	}
}