using Otter;
using System;

namespace SuperRefluxPowergridDefense_.entities
{
    class NoSound : Entity
    {
        private Spritemap<string> _spriteMap;
        private bool isOn = false;
        private Rectangle rect;
        //public Music music = new Music(Assets.BACKGROUND_MUSIC); todo of course.

        public NoSound(float x, float y)
        {
            X = x; Y = y;
            SetHitbox(20, 20, (int)Global.Type.NOSOUND);
            rect = new Rectangle((int)X, (int)Y, 20, 20);
            _spriteMap = new Spritemap<string>(Assets.NOSOUND, 20,20);
            _spriteMap.Add("on", new int[] { 0 }, new float[] { 10f, 10f });
            _spriteMap.Add("off", new int[] { 1 }, new float[] { 10f, 10f });
            _spriteMap.Play("on");
            Graphic = _spriteMap;
            Layer = -100;
        }

        public override void Update()
        {
            base.Update();
            X = Scene.CameraX;
            Y = Scene.CameraY;
            rect.X = (int)Scene.CameraX;
            rect.Y = (int)Scene.CameraY;

            var mouseLocation = new Vector2((int)Scene.MouseX, (int)Scene.MouseY);
            if (Util.InRect(mouseLocation, rect))
            {
                if (Global.PlayerSession.Controller.Button("LeftMouseClick").Pressed)
                    TriggerSoundChange();
            }

            if (Global.PlayerSession.Controller.Button("M").Pressed)
                TriggerSoundChange();
        }

        public void TriggerSoundChange()
        {
            SoundManager.PlayRequestedSound("_realClickyClick");
            if (isOn)
            {
                ChangeAnimTo("off");
                isOn = false;
                //SoundManager.isSoundEnabled = false;
                //music.Pause();
            }
            else
            {
                ChangeAnimTo("on");
                isOn = true;
                //music.Play();//todo
                //SoundManager.isSoundEnabled = true;
            }
        }

        public void ChangeAnimTo(string desiredAnimation)
        {
            if (_spriteMap.CurrentAnim != desiredAnimation)
                _spriteMap.Play(desiredAnimation);
        }

        public override void Render()//mainly for testing colliders :D
        {
            base.Render();
            //Collider.Render();
        }

        public void Destroy()
        {
            RemoveSelf();
            Scene.Add(new PlayerDeath(X, Y));
        }
    }
}

