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

namespace Scripts
{
	public class UpdateGridScrollAnimation : IScript
	{
		private const int ScrollAmount = -480;
	
		public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
		{			
			// 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];
			
			// Add 'ScrollAmount' to the start and end keyframes
			startKeyframe.Value += ScrollAmount;
			endKeyframe.Value += ScrollAmount;
			
			return null;
		}
	}
}