using UnityEngine;
using System.Collections;

public class SpotlightControl : MonoBehaviour {

	#region Private Variables
	private SpotlightColor _spotlightColor = SpotlightColor.Red;

	[SerializeField]
	private SpriteRenderer _lightRenderer;

	[SerializeField]
	private MergeLightControl _mergeLight;

	private bool _enabled = true;
	#endregion


	#region Getters and Setters
	public SpotlightColor color {
		get {
			return _spotlightColor;
		}
	}
	#endregion


	#region Events
	void Start () {

		ChangeColor ();

	}

	void OnMouseDown () {

		if (!_enabled) return;

		int index = (int) _spotlightColor;
		int length = (int) SpotlightColor.Length;

		index = (index + 1) % length;

		_spotlightColor = (SpotlightColor) index;
		ChangeColor ();
		_mergeLight.UpdateColor ();
		
	}
	#endregion


	#region Methods
	void ChangeColor () {

		switch (_spotlightColor) {

			case SpotlightColor.Red:
				_lightRenderer.color = new Color (1f, 0f, 0f, 0.3f);
				break;

			case SpotlightColor.Green:
				_lightRenderer.color = new Color (0f, 1f, 0f, 0.3f);
				break;

			case SpotlightColor.Blue:
				_lightRenderer.color = new Color (0f, 0f, 1f, 0.3f);
				break;

			case SpotlightColor.None:
				_lightRenderer.color = new Color (1f, 1f, 1f, 0f);
				break;

		}

	}

	public void Disable () {

		_enabled = false;

	}
	#endregion
	
}
