using ActionGame.GameArtifacts.Models.Items;
using ActionGame.RawResources.Manager;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;


namespace ActionGame.UserInterface.Control
{
    public class InventoryItem : IControl
    {
        public IList<IControl> Controls { get; }
        public Rectangle Location { get; set; }
        public Boolean IsSelected { get; set; }
        public Boolean IsSelectable { get; }
        public InventorySlot InventorySlot { get; set; }
        private Texture2D textureSelected;
        private Texture2D textureDefault;
        private SpriteFont quantityFont;

        public InventoryItem(IRawContentManager rawContentManager, Int32 x, Int32 y)
        {
            this.Controls = new List<IControl>();
            this.IsSelectable = true;

            this.textureDefault = rawContentManager.TextureRepository.GetContent(@"textures\ui\itemslot-default");
            this.textureSelected = rawContentManager.TextureRepository.GetContent(@"textures\ui\itemslot-selected");
            this.quantityFont = rawContentManager.FontRepository.GetContent(@"fonts\Small");

            this.Location = new Rectangle(x, y, 90, 32);
        }


        public void Press(GameTime gameTime)
        {
            //do nothing    
        }


        public void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            //background
            if(IsSelected)
            {
                spriteBatch.Draw(textureSelected, this.Location, Color.White);
            }
            else
            {
                spriteBatch.Draw(textureDefault, this.Location, Color.White);
            }

            if (InventorySlot != null)
            {
                if (InventorySlot.Item != null)
                {
                    //item icon
                    Rectangle rect = new Rectangle(this.Location.X + 10, this.Location.Y, 32, 32);
                    spriteBatch.Draw(InventorySlot.Item.Texture, rect, Color.White);

                    //quantity
                    if (InventorySlot.Quantity != null)
                    {
                        Vector2 vector = new Vector2(this.Location.X + 40, this.Location.Y + 8);
                        spriteBatch.DrawString(quantityFont, InventorySlot.Quantity.ToString() + "\n /" + InventorySlot.Item.MaxCapacity, vector, Color.White);
                    }
                }
            }
        }


        public void Update(GameTime gameTime)
        {
            
        }


    }
}
