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

public class RitualActivationManager : MonoBehaviour 
{ 
	static RitualActivationManager _instance;

	public GameObject sacrificeRitualGO;
	public GameObject fertilityRitualGO;
	public GameObject rainRitualGO;
	public GameObject fireRitualGO;
	public GameObject divineRitualGO;

	private Button sacrificeButton;
	private Button fertilityButton;
	private Button rainButton;
	private Button fireButton;
	private Button divineButton;

	private AvailableActionsManager availabeActionInstance;

	void Awake()
	{
		_instance = this;
	}

	static public RitualActivationManager instance 
	{
		// using lazy instantiation here... 
		get
		{
			return _instance;
		}
	}
	
	// Use this for initialization
	void Start () 
	{
		availabeActionInstance = AvailableActionsManager.instance;

		sacrificeButton = sacrificeRitualGO.GetComponent<Button>();
		fertilityButton = fertilityRitualGO.GetComponent<Button>();
		rainButton = rainRitualGO.GetComponent<Button>();
		fireButton = fireRitualGO.GetComponent<Button>();
		divineButton = divineRitualGO.GetComponent<Button>();

		RefreshRitualButtonsAvailability ();
	}

	//Enable or not ritual buttons.
	public void RefreshRitualButtonsAvailability()
	{
		foreach(KeyValuePair<string,bool> element in availabeActionInstance.allowedRituals)
		{
			bool value = element.Value;	

			//Debug.Log (value + " " + element.Key);

			if (element.Key.Equals("SACRIFICE"))
			{
				SetInteractive(sacrificeRitualGO,value);
			}
			else if (element.Key.Equals("FERTILITY"))
			{
				SetInteractive(fertilityRitualGO,value);
			}
			else if (element.Key.Equals("RAIN"))
			{
				SetInteractive(rainRitualGO,value);

			}
			else if (element.Key.Equals("FIRE"))
			{
				SetInteractive(fireRitualGO,value);

			}
			else if (element.Key.Equals("DIVINE"))
			{
				SetInteractive(divineRitualGO,value);

			}
		}
	}

	private void SetInteractive(GameObject go, bool b)
	{
		go.GetComponent<Button>().interactable = b;

		if(b)
		{
			go.GetComponent<Image>().color = Color.white;
		}
		else
		{
			go.GetComponent<Image>().color = Color.gray;

		}
	}
}
