using ActionGame.GameArtifacts.Models.Characters;
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 PlayerHud : IControl
    {
        public IList<IControl> Controls { get; set; }
        public Rectangle Location { get; set; }
        public bool IsSelected { get; set; }
        public bool IsSelectable { get; }
        public Player Player { get; set; }
        private readonly IRawContentManager rawContentManager;

        private Int32 barHeight;
        private Int32 barWidth;
        private Int32 x;
        private Int32 y;
        private InventoryItem slot1;
        private InventoryItem slot2;


        public PlayerHud(IRawContentManager rawContentManager, Int32 x, Int32 y, Int32 w, Int32 h)
        {
            this.Controls = new List<IControl>();
            IsSelectable = false;
            IsSelected = false;

            this.rawContentManager = rawContentManager;

            this.x = x;
            this.y = y;
            this.barWidth = w;
            this.barHeight = h;

            this.slot1 = new InventoryItem(rawContentManager, x + 30, y + 0)
            {
                IsSelected = true
            };
            this.slot2 = new InventoryItem(rawContentManager, x + 180, y + 0)
            {
                IsSelected = true
            };

            this.Controls.Add(this.slot1);
            this.Controls.Add(this.slot2);
        }


        public void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            Vector2 vector = default(Vector2);
            Texture2D backgroundTexture = rawContentManager.TextureRepository.GetContent(@"textures\ui\hud");
            spriteBatch.Draw(backgroundTexture, new Rectangle(x, y, this.barWidth, this.barHeight), Color.White);

            if(Player != null)
            {
                SpriteFont font = rawContentManager.FontRepository.GetContent(@"fonts\Normal");
                String text = Player.CharacterStats.Health + " / " + Player.CharacterStats.MaximumHealth;
                
                vector = new Vector2(this.barWidth - 200, y + 8);
                spriteBatch.DrawString(font, text, vector, Color.White);

                vector = new Vector2(10, y + 5);
                spriteBatch.DrawString(font, "X", vector, Color.White);

                vector = new Vector2(160, y + 5);
                spriteBatch.DrawString(font, "W", vector, Color.White);

                foreach (IControl control in Controls)
                {
                    control.Draw(spriteBatch, gameTime);
                }
            }
        }


        public void Update(GameTime gameTime)
        {
            if(Player != null)
            {
                slot1.InventorySlot = Player.Inventory.Slot1;
                slot2.InventorySlot = Player.Inventory.Slot2;
            }
        }

        public void Press(GameTime gameTime)
        {
            
        }


    }
}
