using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SFML.Graphics;
using SFML.Window;
using YourBeatingHeart.Main.Helper;
using YourBeatingHeart.Main.Graphics;
using YourBeatingHeart.Main.States.Play.Collision;
using YourBeatingHeart.Main.States.Play.Data;

namespace YourBeatingHeart.Main.States.Play.Entities
{
    public class Heart : AnimatedItem
    {
        private PlayerHeart playerHeart;

        public Heart(PlayState playState, Vector2f position, PlayerHeart playerHeart)
            : base(playState, position, "heart_beating.xml", 40, 40, ItemType.Heart)
        {
            Console.Out.WriteLine("spawning heart at " + position.X + " / " + position.Y);
            this.playerHeart = playerHeart;
            Sprite.Origin = new Vector2f(64, 75);
            Sprite.Play("heart_beating");
        }

        public PlayerHeart PlayerHeart
        {
            get { return playerHeart; }
        }

        public override void OnPlayerCollision(Player player)
        {
            /*
            if (player.Position.X > Position.X)
            {
                player.GainHeart(playerHeart);
                playState.RemoveEntity(this);
            }
             */
        }

        public override void Update(float elapsedTime)
        {
            if (playState.CollisionManager.inTouchDownArea(CollisionRect.GetCenter()))
            {
                playState.PlayerScored(owner, Constants.SCORE_PER_THROW);
                playState.RemoveEntity(this);
                playerHeart.Destroy();
            }
            else
            {
                playerHeart.Update(elapsedTime);
                if (!playerHeart.Alive)
                    playState.RemoveEntity(this);
                base.Update(elapsedTime);
            }
        }
    }
}
