using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

public class ShipMenuOption : MonoBehaviour
{
    [System.Serializable]
    public class StarshipSprite
    {
        public string name;
        public Sprite sprite;
    }

    public StarshipSprite[] starships;
    public string shipName;

    public Text shipButtonText;
    public Image shipButtonImg;
    public Image shipSelectionBg;

    public ProgressBar speedBar;
    public ProgressBar rotationBar;
    public ProgressBar thrustBar;
    public Text weaponName;

    public UnityEvent<string> onShipSelected;

    void Start()
    {
        foreach (StarshipSprite obj in starships)
        {
            if (obj.name == shipName)
            {
                shipButtonImg.sprite = obj.sprite;
                shipButtonText.text = obj.name;
                break;
            }
        }
    }

    public void SetSpeedStat(int current, int max)
    {
        speedBar.SetFill(current, max);
    }

    public void SetRotationStat(int current, int max)
    {
        rotationBar.SetFill(current, max);
    }

    public void SetThrustStat(int current, int max)
    {
        thrustBar.SetFill(current, max);
    }

    public void SetWeaponName(string name)
    {
        weaponName.text = name;
    }

    public void Deselect()
    {
        // Hide selection
        shipSelectionBg.enabled = false;
    }

    public void OnButtonClick()
    {
        // Show selection
        shipSelectionBg.enabled = true;

        // Fire event
        onShipSelected.Invoke(shipName);
    }
}
