using UnityEngine;
using TMPro;

public class KickBall : MonoBehaviour
{
    private Rigidbody rb;

    public float lowSpeedForce = 200f;
    public float mediumSpeedForce = 500f;
    public float highSpeedForce = 800f;

    private int currentSpeedLevel = 0;

    public TextMeshProUGUI speedText; // 🆕 Reference to TMP UI Text

    void Start()
    {
        rb = GetComponent<Rigidbody>();
        UpdateSpeedText(); // Set initial speed text
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Kick();
        }

        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            currentSpeedLevel = 0;
            UpdateSpeedText();
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            currentSpeedLevel = 1;
            UpdateSpeedText();
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            currentSpeedLevel = 2;
            UpdateSpeedText();
        }
    }

    void Kick()
    {
        rb.velocity = Vector3.zero;

        Vector3 kickDirection = transform.forward + transform.up * 0.5f;
        float force = 0;

        switch (currentSpeedLevel)
        {
            case 0:
                force = lowSpeedForce;
                break;
            case 1:
                force = mediumSpeedForce;
                break;
            case 2:
                force = highSpeedForce;
                break;
        }

        rb.AddForce(kickDirection.normalized * force);
    }

    void UpdateSpeedText()
    {
        if (speedText != null)
        {
            switch (currentSpeedLevel)
            {
                case 0:
                    speedText.text = "Speed: Low";
                    break;
                case 1:
                    speedText.text = "Speed: Medium";
                    break;
                case 2:
                    speedText.text = "Speed: High";
                    break;
            }
        }
    }
}
