using UnityEngine;
using System.Collections;

public class Stir : MonoBehaviour
{

    private Animator animator;
    private SpriteRenderer spriteRenderer;

    private const string LEFT_STIR = "leftStir";
    private const string RIGHT_STIR = "rightStir";

    public Graph stateMachine;

    public Timer timer;

    // Use this for initialization
    void Start()
    {
        animator = GetComponent<Animator>();
        spriteRenderer = GetComponent<SpriteRenderer>();

        timer = GetComponent<Timer>();
    }

    // Update is called once per frame
    void Update()
    {

        setColorState();

    }

    public void LeftStir()
    {
        animator.SetBool(LEFT_STIR, true);
    }

    public void RightStir()
    {
        animator.SetBool(RIGHT_STIR, true);
    }

    public void ResetStir()
    {
        animator.SetBool(LEFT_STIR, false);
        animator.SetBool(RIGHT_STIR, false);
    }

    public void ChangeColor(Color color)
    {
        spriteRenderer.color = color;
    }

    public bool IsIdle()
    {
        if (animator.GetAnimatorTransitionInfo(0).IsName("IdlePot"))
            return true;

        return false;
    }

    public void setColorState()
    {
        if (stateMachine.currentState == stateMachine.endState)
        {
            Controller.Instance.gameState = Controller.GameState.WIN;
        }

        switch (stateMachine.currentState)
        {
            case Constants.Colors.BLUE:
                {
                    ChangeColor(Color.blue);
                    timer.SetTimer(Controller.Instance.BLUE_TIMER, stateMachine.currentState);
                    break;
                }
            case Constants.Colors.RED:
                {
                    ChangeColor(Color.red);
                    timer.SetTimer(Controller.Instance.RED_TIMER, stateMachine.currentState);
                    break;
                }
            case Constants.Colors.CYAN:
                {
                    ChangeColor(Color.cyan);
                    timer.SetTimer(Controller.Instance.CYAN_TIMER, stateMachine.currentState);
                    break;
                }
            case Constants.Colors.GREEN:
                {
                    ChangeColor(Color.green);
                    timer.SetTimer(Controller.Instance.GREEN_TIMER, stateMachine.currentState);
                    break;
                }
            case Constants.Colors.YELLOW:
                {
                    ChangeColor(Color.yellow);
                    timer.SetTimer(Controller.Instance.YELLOW_TIMER, stateMachine.currentState);
                    break;
                }
            case Constants.Colors.DARKGREEN:
                {
                    ChangeColor(new Color(0, 0.4f, 0));
                    timer.SetTimer(Controller.Instance.DARKGREEN_TIMER, stateMachine.currentState);
                    break;
                }
            case Constants.Colors.MAGENTA:
                {
                    ChangeColor(new Color(1, 0.48f, 0.8f));
                    timer.SetTimer(Controller.Instance.MAGENTA_TIMER, stateMachine.currentState);
                    break;
                }
            case Constants.Colors.MOUSTARD:
                {
                    ChangeColor(new Color(0.75f, 0.73f, 0.18f));
                    timer.SetTimer(Controller.Instance.MOUSTARD_TIMER, stateMachine.currentState);
                    break;
                }
            case Constants.Colors.PURPLE:
                {
                    ChangeColor(new Color(0.58f, 0, 0.9f));
                    timer.SetTimer(Controller.Instance.PURPLE_TIMER, stateMachine.currentState);
                    break;
                }
            case Constants.Colors.ORANGE:
                {
                    ChangeColor(new Color(1, 0.23f, 0));
                    timer.SetTimer(Controller.Instance.ORANGE_TIMER, stateMachine.currentState);
                    break;
                }
        }
    }

}