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

public class ControlsUI : MonoBehaviour
{
    [Header("Control Text Elements")]

    public TextMeshProUGUI forward;
    public TextMeshProUGUI backward;
    public TextMeshProUGUI rotateLeft;
    public TextMeshProUGUI rotateRight;
    public TextMeshProUGUI shoot;
    public TextMeshProUGUI HUD;
    public TextMeshProUGUI dash;
    public TextMeshProUGUI pause;


    [Header("Controller Input Text")]

    public string controllerForward;
    public string controllerBackward;
    public string controllerRotateLeft;
    public string controllerRotateRight;
    public string controllerShoot;
    public string controllerDash;
    public string controllerHUD;
    public string controllerPause;

    [Header("Controller Input Text")]

    public string keyboardForward;
    public string keyboardBackward;
    public string keyboardRotateLeft;
    public string keyboardRotateRight;
    public string keyboardShoot;
    public string keyboardDash;
    public string keyboardHUD;
    public string keyboardPause;

    public static ControlsUI instance;

    private void Awake()
    {
        instance = this;
    }

    private void Start()
    {
        // If a controller is detected (Feel free to add additional custom logic here)
        if (ControllerDetector.IsControllerConnected())
        {
            // Unity is silly and is mismapping my controller buttons to the input manager buttons, so I had to manually set them.
            // Feel free to change this for any other custom system

            forward.text = controllerForward;
            backward.text = controllerBackward;
            rotateLeft.text = controllerRotateLeft;
            rotateRight.text = controllerRotateRight;
            shoot.text = controllerShoot;
            dash.text = controllerDash;
            pause.text = controllerPause;
            HUD.text = controllerHUD;
        }
        else
        {
            // If no controller is detected, set the keyboard inputs
            // Again, feel free to use a custom system with the Controls class

            forward.text = keyboardForward;
            backward.text = keyboardBackward;
            rotateLeft.text = keyboardRotateLeft;
            rotateRight.text = keyboardRotateRight;
            shoot.text = keyboardShoot;
            HUD.text = keyboardHUD;
            dash.text = keyboardDash;
            pause.text = keyboardPause;
        }
    }
}
