using System.Collections.Generic;
using ActionGame.UserInterface.Control;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace ActionGame.Tests.UserInterfaceTests.Control
{
    [TestClass]
    public class ControlCollectionTests
    {
        [TestMethod]
        public void ControlCollection_BasicInitialization()
        {
            ControlCollection collection = new ControlCollection();

            Assert.IsTrue(collection.Count == 0);
            Assert.IsTrue(collection.IndexOfSelected() == -1);
        }


        [TestMethod]
        public void ControlCollection_OneSelectableNotSelected()
        {
            ControlCollection collection = new ControlCollection();

            Button button = new Button();
            collection.Add(button);

            Assert.IsFalse(button.IsSelected);
        }


        [TestMethod]
        public void ControlCollection_OneSelectableSelected()
        {
            ControlCollection collection = new ControlCollection();

            Button button = new Button();
            collection.Add(button);

            collection.Select(button);

            Assert.IsTrue(button.IsSelected);
        }


        [TestMethod]
        public void ControlCollection_TwoSelectableSecondIsSelected()
        {
            ControlCollection collection = new ControlCollection();

            MockControl control1 = new MockControl() { IsSelectable = true };
            collection.Add(control1);
            MockControl control2 = new MockControl() { IsSelectable = true };
            collection.Add(control2);

            collection.Select(control1);
            collection.Select(control2);

            Assert.IsFalse(control1.IsSelected);
            Assert.IsTrue(control2.IsSelected);
        }


        [TestMethod]
        public void ControlCollection_Unselect()
        {
            ControlCollection collection = new ControlCollection();

            MockControl control = new MockControl() { IsSelectable = true };
            collection.Add(control);

            collection.Select(control);

            Assert.IsTrue(control.IsSelected);

            collection.UnselectAll();

            Assert.IsFalse(control.IsSelected);    
        }


        [TestMethod]
        public void ControlCollection_ThreeSelectableSelectNextFromFirst()
        {
            ControlCollection collection = new ControlCollection();

            MockControl control1 = new MockControl() { IsSelectable = true };
            collection.Add(control1);
            MockControl control2 = new MockControl() { IsSelectable = true };
            collection.Add(control2);
            MockControl control3 = new MockControl() { IsSelectable = true };
            collection.Add(control3);

            collection.Select(control1);
            Assert.IsTrue(control1.IsSelected);

            collection.SelectNext();

            Assert.IsFalse(control1.IsSelected);
            Assert.IsTrue(control2.IsSelected);
            Assert.IsFalse(control3.IsSelected);
        }


        [TestMethod]
        public void ControlCollection_ThreeSelectableSelectNextFromLast()
        {
            ControlCollection collection = new ControlCollection();

            MockControl control1 = new MockControl() { IsSelectable = true };
            collection.Add(control1);
            MockControl control2 = new MockControl() { IsSelectable = true };
            collection.Add(control2);
            MockControl control3 = new MockControl() { IsSelectable = true };
            collection.Add(control3);

            collection.Select(control3);
            Assert.IsFalse(control1.IsSelected);
            Assert.IsFalse(control2.IsSelected);
            Assert.IsTrue(control3.IsSelected);

            collection.SelectNext();

            Assert.IsTrue(control1.IsSelected);
            Assert.IsFalse(control2.IsSelected);
            Assert.IsFalse(control3.IsSelected);
        }


        [TestMethod]
        public void ControlCollection_ThreeSelectableSelectPrevFromSecond()
        {
            ControlCollection collection = new ControlCollection();

            MockControl control1 = new MockControl() { IsSelectable = true };
            collection.Add(control1);
            MockControl control2 = new MockControl() { IsSelectable = true };
            collection.Add(control2);
            MockControl control3 = new MockControl() { IsSelectable = true };
            collection.Add(control3);

            collection.Select(control2);

            Assert.IsFalse(control1.IsSelected);
            Assert.IsTrue(control2.IsSelected);
            Assert.IsFalse(control3.IsSelected);

            collection.SelectPrev();

            Assert.IsTrue(control1.IsSelected);
            Assert.IsFalse(control2.IsSelected);
            Assert.IsFalse(control3.IsSelected);
        }


        [TestMethod]
        public void ControlCollection_ThreeSelectableSelectPrevFromFirst()
        {
            ControlCollection collection = new ControlCollection();

            MockControl control1 = new MockControl() { IsSelectable = true };
            collection.Add(control1);
            MockControl control2 = new MockControl() { IsSelectable = true };
            collection.Add(control2);
            MockControl control3 = new MockControl() { IsSelectable = true };
            collection.Add(control3);

            collection.Select(control1);

            Assert.IsTrue(control1.IsSelected);
            Assert.IsFalse(control2.IsSelected);
            Assert.IsFalse(control3.IsSelected);

            collection.SelectPrev();

            Assert.IsFalse(control1.IsSelected);
            Assert.IsFalse(control2.IsSelected);
            Assert.IsTrue(control3.IsSelected);
        }


        [TestMethod]
        public void ControlCollection_ThreeControlsTwoSelectableSelectNextFromFirst()
        {
            ControlCollection collection = new ControlCollection();

            MockControl control1 = new MockControl() { IsSelectable = true };
            collection.Add(control1);
            MockControl control2 = new MockControl() { IsSelectable = false };
            collection.Add(control2);
            MockControl control3 = new MockControl() { IsSelectable = true };
            collection.Add(control3);

            collection.Select(control1);
            Assert.IsTrue(control1.IsSelected);
            Assert.IsFalse(control2.IsSelected);
            Assert.IsFalse(control3.IsSelected);

            collection.SelectNext();

            Assert.IsFalse(control1.IsSelected);
            Assert.IsFalse(control2.IsSelected);
            Assert.IsTrue(control3.IsSelected);
        }


        [TestMethod]
        public void ControlCollection_ThreeControlsTwoSelectableSelectNextFromLast()
        {
            ControlCollection collection = new ControlCollection();

            MockControl control1 = new MockControl() { IsSelectable = true };
            collection.Add(control1);
            MockControl control2 = new MockControl() { IsSelectable = false };
            collection.Add(control2);
            MockControl control3 = new MockControl() { IsSelectable = true };
            collection.Add(control3);

            collection.Select(control3);
            Assert.IsFalse(control1.IsSelected);
            Assert.IsFalse(control2.IsSelected);
            Assert.IsTrue(control3.IsSelected);

            collection.SelectNext();

            Assert.IsTrue(control1.IsSelected);
            Assert.IsFalse(control2.IsSelected);
            Assert.IsFalse(control3.IsSelected);
        }


        [TestMethod]
        public void ControlCollection_ThreeControlsTwoSelectableSelectPrevFromFirst()
        {
            ControlCollection collection = new ControlCollection();

            MockControl control1 = new MockControl() { IsSelectable = true };
            collection.Add(control1);
            MockControl control2 = new MockControl() { IsSelectable = false };
            collection.Add(control2);
            MockControl control3 = new MockControl() { IsSelectable = true };
            collection.Add(control3);

            collection.Select(control1);
            Assert.IsTrue(control1.IsSelected);
            Assert.IsFalse(control2.IsSelected);
            Assert.IsFalse(control3.IsSelected);

            collection.SelectPrev();

            Assert.IsFalse(control1.IsSelected);
            Assert.IsFalse(control2.IsSelected);
            Assert.IsTrue(control3.IsSelected);
        }


        [TestMethod]
        public void ControlCollection_ThreeControlsTwoSelectableSelectPrevFromLast()
        {
            ControlCollection collection = new ControlCollection();

            MockControl control1 = new MockControl() { IsSelectable = true };
            collection.Add(control1);
            MockControl control2 = new MockControl() { IsSelectable = false };
            collection.Add(control2);
            MockControl control3 = new MockControl() { IsSelectable = true };
            collection.Add(control3);

            collection.Select(control3);
            Assert.IsFalse(control1.IsSelected);
            Assert.IsFalse(control2.IsSelected);
            Assert.IsTrue(control3.IsSelected);

            collection.SelectPrev();

            Assert.IsTrue(control1.IsSelected);
            Assert.IsFalse(control2.IsSelected);
            Assert.IsFalse(control3.IsSelected);
        }



    }
}
