using System.Windows;
using System.IO;
using System.Reflection;
using System.Windows.Input;
using System.Collections.Generic;
using System.Windows.Media.Media3D;

namespace AvengersUtd.Test
{
    public partial class TestWindow : Window
    {
        
        private int index;
        private readonly List<Cover> coverList = new List<Cover>();
       
        private void RotateCover(int pos)
        {
            coverList[pos].Animate(index);
        }

        private void UpdateIndex(int newIndex)
        {
            if (index != newIndex)
            {
                int oldIndex = index;
                index = newIndex;
                RotateCover(oldIndex);
                RotateCover(index);
                camera.Position = new Point3D(.2 * index, camera.Position.Y, camera.Position.Z);
            }
        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            int newIndex = index;
            switch (e.Key)
            {
                case Key.Right:
                    if (newIndex < coverList.Count - 1)
                        newIndex++;
                    break;
                case Key.Left:
                    if (newIndex > 0)
                        newIndex--;
                    break;
            }
            UpdateIndex(newIndex);
        }

        public TestWindow()
        {
            InitializeComponent();
            FileInfo assembly = new FileInfo(Assembly.GetExecutingAssembly().Location);
            FileInfo[] imageList = {
                                       new FileInfo(Path.Combine(assembly.Directory.FullName, "Katy Perry.jpg")),
                                       new FileInfo(Path.Combine(assembly.Directory.FullName, "Resistance.png")),
                                       new FileInfo(Path.Combine(assembly.Directory.FullName, "fatLand.jpg")),
                                       new FileInfo(Path.Combine(assembly.Directory.FullName, "daftpunk.jpg")),
                                       new FileInfo(Path.Combine(assembly.Directory.FullName, "deandre.jpg")),
                                   };

            for (int i = 0; i < 5; i++)
            {
                Cover cover = new Cover(imageList[i].FullName, i);
                coverList.Add(cover);
                visualModel.Children.Add(cover);
            }
        }
    }
}
