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

public class JokeManager : MonoBehaviour
{
    [SerializeField]
    private GameObject fullScreenJokeBubble;

    [SerializeField]
    private GameObject fullScreenJoke;

    [SerializeField]
    private GameObject normaJokeBubble;

    [SerializeField]
    private GameObject normaJoke;

    private TMP_Text fullScreenJokeText;
    private TMP_Text normaJokeText;
    private List<string> shuffledJokes;
    private int lastJoke;
    private List<string> fullScreenJokes = new List<string>()
    {
        "I don't trust stairs.\nThey are always up to something.",
        "Scientist don't trust atoms.\nThey make up\neverything.",
        "I'm afraid for the calendar.\nIts days are numbered.",
        "Singing in the shower\nis fun until you get\nsoap in your mouth.\nThen it's a soap opera.",
        "I asked my dog what's\n two minus two.\n He said nothing.",
        "I don't trust those\n trees. They seem\n kind of shady.",
        "How do you make 7 even?\nTake away the s.",
        "What is pirate's favorite letter?\nHis true love is the sea."
    };

    // Start is called before the first frame update
    void Start()
    {
        fullScreenJokeText = fullScreenJokeBubble.GetComponent<TMP_Text>();
        normaJokeText = normaJoke.GetComponent<TMP_Text>();

        shuffledJokes = fullScreenJokes.OrderBy(_ => Random.Range(0, 1)).ToList();
        lastJoke = 0;
    }

    public void ShowFullScreenJoke()
    {
        fullScreenJoke.GetComponent<TMP_Text>().text = shuffledJokes[lastJoke];
        lastJoke++;
        if (lastJoke == shuffledJokes.Count)
        {
            lastJoke = 0;
        }

        StartCoroutine(DisplayFullScreenJoke());
    }

    public void ShowNormaJoke(string text)
    {
        normaJoke.GetComponent<TMP_Text>().text = text;
        StartCoroutine(DisplayNormaJoke());
    }

    IEnumerator DisplayFullScreenJoke()
    {
        fullScreenJokeBubble.SetActive(true);
        yield return new WaitForSeconds(5);
        fullScreenJokeBubble.SetActive(false);
    }

    IEnumerator DisplayNormaJoke()
    {
        normaJokeBubble.SetActive(true);
        yield return new WaitForSeconds(5);
        normaJokeBubble.SetActive(false);
    }

    public void OnFire()
    {
        //Debug.Log("Joke");
        //ShowNormaJoke("Not my anime figurines!");
        ShowFullScreenJoke();
    }

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