using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Player: Singleton<Player> {

    public bool IsAlive { get; set; }

    [SerializeField]
    Image currentBullet;

    [SerializeField]
    Sprite imageLight;
    [SerializeField]
    Sprite imageSound;
    [SerializeField]
    Sprite imageElectric;


    [SerializeField]
    Gun gun;



    [SerializeField]
    Sprite electricGun;

    [SerializeField]
    Sprite soundGun;

    [SerializeField]
    Sprite lightGun;


    void Start() {
        UpdateImage();
        IsAlive = true;
    }

    void Update() {
        if(Input.GetMouseButtonDown(1)) {
        //    Debug.Log(gun.Type);
            gun.Type = (AbilityType) (((int) gun.Type + 1 > Enum.GetNames(typeof(AbilityType)).Length - 1) ? 0 : gun.Type + 1);
            UpdateImage();
        }
    }

    void UpdateImage() {
        SelectImage();
        gun.ChangeSprite();
    }

    void SelectImage() {
        switch(gun.Type) {
            case AbilityType.Electricity:
                gun.CurrentSprite = electricGun;

                    currentBullet.sprite = imageElectric;
                break;
            case AbilityType.Sound:
                gun.CurrentSprite = soundGun;

                    currentBullet.sprite = imageSound;
                break;
            case AbilityType.Light:
                gun.CurrentSprite = lightGun;

                    currentBullet.sprite = imageLight;
                break;
            default:
                break;
        }
    }


    public void Hurt() {
        IsAlive = false;
        GameManager.Instance.Reload();
    }

}
