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

public class MotherShip : MonoBehaviour {

    public float repairDistance = 7f;

    public int neededRepairs = 4;
    private int repairs = 0;

    public Text text;

    public List<GameObject> phases = new List<GameObject>();

    void Start() {
        SetText();
    }

    public void PlaceItem(int amount) {
        phases[repairs].SetActive(false);
        repairs += (IsRepaired()) ? 0 : amount;
        if (repairs >= phases.Count)
            repairs = phases.Count - 1;
        phases[repairs].SetActive(true);

        Debug.Log("Repaired");

        SetText();

        if (IsRepaired())
            FindObjectOfType<GameManager>().FinishShip();
            
    }

    void OnTriggerEnter(Collider collider) {
        if (collider.tag == "Item")
            Debug.Log(collider);
    }

    public float GetRepairDistance() {
        return repairDistance;
    }
    
    public bool IsRepaired() {
        return repairs >= neededRepairs;
    }

    void SetText() {
        text.text = repairs + "/" + neededRepairs;
    }

    public int GetRepairs() {
        return repairs;
    }

    public int GetMaxRepairs() {
        return neededRepairs;
    }
}
