using Chernobyl.Collections.Generic.Event;
using Chernobyl.Graphics.Drawing;
using Chernobyl.Graphics.Texture;
using Chernobyl.Mathematics.Geometry;
using Chernobyl.Mathematics.Movement;

namespace Chernobyl.Interface.Utility
{
    /// <summary>
    /// A simple 2D menu interface that is used to give <see cref="IShape"/> 
    /// derived instances a background. Typically this is used to hold other menu
    /// items like buttons, labels, input boxes, etc. The background will expand 
    /// to fit the shape you give it and will continue to expand and contract 
    /// to ensure the shape fit inside it's borders (even if that shape 
    /// expands, contracts, or moves).
    /// </summary>
    public class Background : Sprite
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Background"/> class.
        /// </summary>
        /// <param name="services">The service holder instance that takes
        /// services and gives them out.</param>
        /// <param name="texture">The texture to use as the background.</param>
        /// <param name="shape">The shape that will be on this 
        /// <see cref="Background"/>. This class will create a 
        /// <see cref="ShapeCollection"/> to store the <see cref="IShape"/> 
        /// instances in (using a <see cref="ShapeCollection.WidthModifier"/> 
        /// and <see cref="ShapeCollection.HeightModifier"/> of 25) . If the passed in 
        /// <see cref="IShape"/> is a <see cref="ShapeCollection"/> then that 
        /// collection will be used instead.</param>
        public Background(IEventCollection<object> services, ITexture texture, IShape shape)
            : base(services, texture)
        {
            Shapes = shape as ShapeCollection ?? new ShapeCollection(new[] { shape }) { WidthModifier = 25, HeightModifier = 25 };
            Transform.MakeParentChild(Shapes, this.Render);
        }

        /// <summary>
        /// The start of the transform chain of this entity. If there is only 
        /// one transform in the chain, then the TransformStart will equal the
        /// TransformEnd.
        /// </summary>
        protected override ITransform TransformStart { get { return Shapes; } }

        /// <summary>
        /// The <see cref="ShapeCollection"/> that ensures this <see cref="Background"/> 
        /// is properly adjusting to the size of the contained <see cref="IShape"/>s.
        /// </summary>
        ShapeCollection Shapes { get; set; }
    }
}