using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class NarrativeManager : MonoBehaviour
{
    private bool m_ContinueText = false;
    private bool m_EndText = false;
    [SerializeField]
    private GameObject m_TextBackground;
    [SerializeField]
    private GameObject m_Text1;
    [SerializeField]
    private GameObject m_Text2;
    [SerializeField]
    private GameObject m_Text3;
    [SerializeField]
    private GameObject m_Text4;
    [SerializeField]
    private GameObject m_Text5;
    [SerializeField]
    private GameObject m_Text6;
    [SerializeField]
    private GameObject m_FeatureListGiven;
    [SerializeField]
    private GameObject m_ScriptMovement;
    public GameObject m_HelpTextBackground;
    [SerializeField]
    private GameObject m_HelpTextFeature;
    [SerializeField]
    private GameObject m_HelpFeatureMove;
    public GameObject m_HelpFeatureSprint;
    [SerializeField]
    private GameObject m_HelpFeatureHP;
    [SerializeField]
    private GameObject m_HelpFeatureJump;
    [SerializeField]
    private GameObject m_HelpFeatureSpawn;
    [SerializeField]
    private GameObject m_HelpFeatureInteraction;

    private bool m_FirstConv = true;
    public bool SecondConv = false;
    public bool ThirdConv = false;
    public bool FourthConv = false;
    public bool FifthConv = false;
    public bool SixthConv = false;
    public bool SeventhConv = false;
    public bool EightConv = false;
    private void Start()
    {
        m_TextBackground.SetActive(true);
        m_Text1.SetActive(true);
    }
    void Update()
    {
        if (m_FirstConv)
        {
            FirstConversation();
        }
        
        if (SecondConv)
        {
            SecondConversation();
        }

        if (ThirdConv)
        {
            ThirdConversation(); 
        }

        if (FourthConv)
        {
            FourthConversation();
        }

        if (FifthConv)
        {
            FifthConversation();
        }

        if (SixthConv)
        {
            SixthConversation();
        }

        if (SeventhConv)
        {
            SeventhConversation();
        }

        if (EightConv)
        {
            EightConversation();
        }
    }

    private void FirstConversation()
    {
        if (Input.GetKeyDown(KeyCode.Mouse0) && m_EndText)
        {
            m_Text3.SetActive(false);
            m_TextBackground.SetActive(false);
            m_ScriptMovement.SetActive(true);
            m_HelpFeatureMove.SetActive(false);
            m_HelpTextBackground.SetActive(false);
            m_FirstConv = false;
        }
        else if (Input.GetKeyDown(KeyCode.Mouse0) && m_ContinueText)
        {
            m_Text2.SetActive(false);
            m_Text3.SetActive(true);
            m_EndText = true;
            m_HelpTextFeature.SetActive(false);
            m_HelpFeatureMove.SetActive(true);
        }
        else if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            m_Text1.SetActive(false);
            m_Text2.SetActive(true);
            m_FeatureListGiven.SetActive(true);
            m_ContinueText = true;
            m_HelpTextBackground.SetActive(true);
            m_HelpTextFeature.SetActive(true);
        }
    }

    public void SecondConversation()
    {
        m_TextBackground.SetActive(true);
        m_HelpTextBackground.SetActive(true);
        m_HelpFeatureHP.SetActive(true);
        m_Text4.SetActive(true);

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            m_TextBackground.SetActive(false);
            m_HelpFeatureHP.SetActive(false);
            m_Text4.SetActive(false);
            m_HelpTextBackground.SetActive(false);
            SecondConv = false;
        }
    }

    public void ThirdConversation()
    {
        m_HelpTextBackground.SetActive(true);
        m_HelpFeatureSprint.SetActive(true);

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            m_HelpTextBackground.SetActive(false);
            m_HelpFeatureSprint.SetActive(false);
            ThirdConv = false;
        }
    }

    private void FourthConversation()
    {
        m_HelpTextBackground.SetActive(true);
        m_HelpFeatureJump.SetActive(true);

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            m_HelpFeatureJump.SetActive(false);
            m_HelpTextBackground.SetActive(false);
            FourthConv = false;
        }
    }

    private void FifthConversation()
    {
        m_TextBackground.SetActive(true);
        m_Text5.SetActive(true);

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            m_TextBackground.SetActive(false);
            m_Text5.SetActive(false);
            FifthConv = false;
        }
    }

    private void SixthConversation()
    {
        m_HelpTextBackground.SetActive(true);
        m_HelpFeatureSpawn.SetActive(true);

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            m_HelpFeatureSpawn.SetActive(false);
            m_HelpTextBackground.SetActive(false);
            SixthConv = false;
        }
    }

    private void SeventhConversation()
    {
        m_HelpTextBackground.SetActive(true);
        m_HelpFeatureInteraction.SetActive(true);

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            m_HelpFeatureInteraction.SetActive(false);
            m_HelpTextBackground.SetActive(false);
            SeventhConv = false;
        }
    }

    private void EightConversation()
    {
        m_TextBackground.SetActive(true);
        m_Text6.SetActive(true);

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            m_TextBackground.SetActive(false);
            m_Text6.SetActive(false);
            EightConv = false;
            SceneManager.LoadScene("Tutorial");
        }
    }
}
