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

public class GUIInputs : MonoBehaviour {

	//STATUS
	public void buttonClickEMCON() {
		DeployedUnit selected = GameController.getInfoSelectedUnit();
		if (selected != null) {
			if (!selected.isEMCON() || selected.canSafelyTurnOffMissileControl()) {
				GameController.switchEMCONSelectedUnit();
			}
			else {
				GameController.showPopUp();
			}
		}
	}

	public void buttonClickDisplayRadar() {
		GameController.switchDisplayRadarSelectedUnit();
	}

	public void buttonClickStop() {
		GameController.stopSelectedUnit();
	}

	public void buttonClickOneThird() {
		GameController.setTargetSpeedSelectedUnit(0.33f, 0);
	}

	public void buttonClickTwoThird() {
		GameController.setTargetSpeedSelectedUnit(0.66f, 1);
	}

	public void buttonClickFull() {
		GameController.setTargetSpeedSelectedUnit(0.8f, 2);
	}

	public void buttonClickFlank() {
		GameController.setTargetSpeedSelectedUnit(1f, 3);
	}

	//SAM
	public void buttonClick1(Button button) {
		SAMBehaviour behaviour = button.transform.parent.parent.gameObject.GetComponent<SAMBehaviour>();
		GameController.setAntimissileSalvoSelectedUnit(behaviour.missile, 1);
	}

	public void buttonClick2(Button button) {
		SAMBehaviour behaviour = button.transform.parent.parent.gameObject.GetComponent<SAMBehaviour>();
		GameController.setAntimissileSalvoSelectedUnit(behaviour.missile, 2);
	}

	public void buttonClick3(Button button) {
		SAMBehaviour behaviour = button.transform.parent.parent.gameObject.GetComponent<SAMBehaviour>();
		GameController.setAntimissileSalvoSelectedUnit(behaviour.missile, 3);
	}

	public void buttonClick4(Button button) {
		SAMBehaviour behaviour = button.transform.parent.parent.gameObject.GetComponent<SAMBehaviour>();
		GameController.setAntimissileSalvoSelectedUnit(behaviour.missile, 4);
	}

	//STRIKE
	public void showMissileRange(MissileStrikeBehaviour behaviour) {
		GameController.showRangeSelected(behaviour.missile.getOptimalRange());
	}

	public void unshowMissileRange() {
		GameController.unshowRangeSelected();
	}

	public void buttonClickMinus(Button button) {
		if (!button.interactable) {
			return;
		}
		MissileStrikeBehaviour behaviour = button.transform.parent.parent.gameObject.GetComponent<MissileStrikeBehaviour>();
		behaviour.currentNumber --;
	}

	public void buttonClickPlus(Button button) {
		if (!button.interactable) {
			return;
		}

		MissileStrikeBehaviour behaviour = button.transform.parent.parent.gameObject.GetComponent<MissileStrikeBehaviour>();
		behaviour.currentNumber ++;

	}

	public void buttonClickFire(Button button) {
		if (!button.interactable) {
			return;
		}

		MissileStrikeBehaviour behaviour = button.transform.parent.gameObject.GetComponent<MissileStrikeBehaviour>();

		GameController.fireMissilesSelectedUnit(behaviour.missile, behaviour.currentNumber);
	}

	//HELO
	/*public void buttonClickLaunch(Button button) {
		if (!button.interactable) {
			return;
		}

		LaunchBehaviour behaviour = button.transform.parent.gameObject.GetComponent<LaunchBehaviour>();

		GameController.launchSelectedUnit(behaviour.launchedClass, behaviour.currentNumber, behaviour.loadout);
	}*/

	public void buttonClickMinusLaunch(Button button) {
		if (!button.interactable) {
			return;
		}
		LaunchBehaviour behaviour = button.transform.parent.parent.gameObject.GetComponent<LaunchBehaviour>();
		behaviour.currentNumber --;
	}

	public void buttonClickPlusLaunch(Button button) {
		if (!button.interactable) {
			return;
		}

		LaunchBehaviour behaviour = button.transform.parent.parent.gameObject.GetComponent<LaunchBehaviour>();
		behaviour.currentNumber ++;

	}

	public void buttonClickPrepare(Button button) {
		if (!button.interactable) {
			return;
		}

		LaunchBehaviour behaviour = button.transform.parent.gameObject.GetComponent<LaunchBehaviour>();

		GameController.prepareSelectedUnit(behaviour.launchedClass, behaviour.currentNumber, behaviour.loadout);
	}

	public void buttonClickTakeOff(Button button) {
		if (!button.interactable) {
			return;
		}

		SingleLaunchBehaviour behaviour = button.transform.parent.gameObject.GetComponent<SingleLaunchBehaviour>();

		GameController.takeOffSelectedUnit(behaviour.stored);
	}

	public void showVehicleRange(LaunchBehaviour behaviour) {
		GameController.showRangeSelected(behaviour.launchedClass.getOptimalRange());
	}

	public void unshowVehicleRange() {
		GameController.unshowRangeSelected();
	}

	public void buttonLand() {
		GameController.landSelectedUnit();
	}
}
