using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class TeleportGate : MonoBehaviour
{
    public PossibleLocations[] possibleLocations;
    [Header("Animator Components")]
    public KeyCode interactButton;
    public Animator mapAnimator;
    public string openMap;
    public string closeMap;
    public Animator questionAnimator;
    public string openQuestion;
    public string closeQuestion;
    public TextMeshProUGUI questionText;
    public TextMeshProUGUI movingToText;

    private int moveToPos;

    public void SetMoveToPos(int i)
    {
        moveToPos = i;
    }

    public void TeleportPlayer()
    {
        questionText.gameObject.SetActive(false);
        movingToText.gameObject.SetActive(true);
        movingToText.text = "Moving to " + possibleLocations[moveToPos].locationName;
        GameObject player = GameObject.FindGameObjectWithTag("Player");
        player.transform.position = possibleLocations[moveToPos].teleportPosition.transform.position;
        FindObjectOfType<CameraFollow>().SetClampFloats(
            possibleLocations[moveToPos].minX, 
            possibleLocations[moveToPos].maxX, 
            possibleLocations[moveToPos].minY, 
            possibleLocations[moveToPos].maxY);
        CloseAnim();
        CloseMapQuestionUi();
        if (possibleLocations[moveToPos].audioFileToPlay != null)
        {
            AudioManager.instance.StopAll();
            AudioManager.instance.PlaySounds(possibleLocations[moveToPos].audioFileToPlay);
        }
        
    }
    

    public void OpenMapQuestionUi()
    {
        questionText.gameObject.SetActive(true);
        movingToText.gameObject.SetActive(false);
        questionText.text = "Would you like to move to " + possibleLocations[moveToPos].locationName;
        questionAnimator.SetTrigger(openQuestion);
    }
    
    public void CloseMapQuestionUi()
    {
        questionAnimator.SetTrigger(closeQuestion);
    }
    
    
    public void CloseAnim()
    {
        mapAnimator.SetTrigger(closeMap);
    }
}

[System.Serializable]
public class PossibleLocations
{
    public string locationName;
    public Transform teleportPosition;
    public string audioFileToPlay;
    public float minX;
    public float maxX;
    public float minY;
    public float maxY;
}
