using System.Collections;
using Unity.VisualScripting;
using UnityEngine;

public class PressurePad : MonoBehaviour
{
    public int color;
    private Animator animator;
    private SpriteRenderer spriteRenderer;
    public bool isActivated = false;
    //button release delay
    public float relTime = 1f;
    public GameObject target;
    public bool IsThatOneFuckingGreenRampInTheFirstLevel;
    public bool TurnFanOn;


    private void Start()
    {
        animator = GetComponent<Animator>();
        spriteRenderer = GetComponent<SpriteRenderer>();
        if(!TurnFanOn){
        animator.SetInteger("Color", color);
            animator.SetBool("Press", false);
        }
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("ButtonPresser") || other.gameObject.CompareTag("Player"))
        {

            isActivated = true;
            Debug.Log("Press");
            if (IsThatOneFuckingGreenRampInTheFirstLevel)
            {
                target.transform.Rotate(0, 0, 90);
                animator.SetBool("Press", true);

            }
            else if (TurnFanOn)
            {
                target.SetActive(true);
            }
            else
            {
                target.SetActive(false);
                animator.SetBool("Press", true);

            }
        }
    }

    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("ButtonPresser") || other.gameObject.CompareTag("Player"))
        {
            StartCoroutine(releaseDelay());
        }
    }
    IEnumerator releaseDelay()
    {
        yield return new WaitForSeconds(relTime);
        isActivated = false;
        if (IsThatOneFuckingGreenRampInTheFirstLevel)
        {
            target.transform.Rotate(0, 0, -90);
            animator.SetBool("Press", false);

        }
        else if (TurnFanOn)
        {
            target.SetActive(false);
        }
        else { 
        target.SetActive(true);
            animator.SetBool("Press", false);

        }
        Debug.Log("Unpress");
    }
}
