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

public class ScriptsItem : MonoBehaviour
{
    private float Timer = 3f;
    private bool StartTimer = false;
    private bool stopDerping = true;
    Vector3 m_SpawnPoint = new Vector3(3f, 0.5f, 2.5f);
    [SerializeField]
    private TrapDoor m_TrapDoor;
    [SerializeField]
    private NarrativeManager m_NarrativeManager;
    [SerializeField]
    private GameObject m_ControlWMovement;
    [SerializeField]
    private GameObject m_ControlSMovement;
    [SerializeField]
    private GameObject m_ControlAMovement;
    [SerializeField]
    private GameObject m_ControlDMovement;
    [SerializeField]
    private GameObject m_LineMovement;
    [SerializeField]
    private GameObject m_LineHP;
    [SerializeField]
    private GameObject m_LineSprint;
    [SerializeField]
    private GameObject m_LineInteraction;
    [SerializeField]
    private GameObject m_LineJump;
    [SerializeField]
    private GameObject m_LineSpawn;
    [SerializeField]
    private GameObject m_ControlSprint;
    [SerializeField]
    private GameObject m_ControlInteraction;
    [SerializeField]
    private GameObject m_ControlJump;
    [SerializeField]
    private GameObject m_ControlReload;
    [SerializeField]
    private GameObject m_ControlSpawn;
    [SerializeField]
    private PlayerController m_PlayerController;
    [SerializeField]
    private GameObject m_ScriptMovement;
    [SerializeField]
    private GameObject m_HealthBar;
    [SerializeField]
    private GameObject m_ScriptHP;
    [SerializeField]
    private GameObject m_ScriptSprint;
    [SerializeField]
    private GameObject m_ScriptJump;
    [SerializeField]
    private GameObject m_ScriptSpawn;
    [SerializeField]
    private GameObject m_TriggerZone;
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Movement" )
        {
            m_ControlWMovement.SetActive(true);
            m_ControlSMovement.SetActive(true);
            m_ControlAMovement.SetActive(true);
            m_ControlDMovement.SetActive(true);
            m_LineMovement.SetActive(true);
            m_PlayerController.PlayerCanMove();
            m_ScriptMovement.SetActive(false);

        }
        else if (other.tag == "HP")
        {
            StartTimer = true;
            m_LineHP.SetActive(true);
            m_HealthBar.SetActive(true);
            m_NarrativeManager.SecondConv = true;
            m_ScriptHP.SetActive(false);
            m_ScriptSprint.SetActive(true);
            if (Timer <= 0f)
            {
                transform.position = m_SpawnPoint;
                m_TrapDoor.reset = true;
            }
        }
        else if (other.tag == "Sprint")
        {
            m_LineSprint.SetActive(true);
            m_ControlSprint.SetActive(true);
            m_PlayerController.PlayerCanSprint();
            m_ScriptSprint.SetActive(false);
            m_ScriptJump.SetActive(true);
            m_NarrativeManager.ThirdConv = true;
        }
        else if (other.tag == "Interaction")
        {
            m_LineInteraction.SetActive(true);
            m_ControlInteraction.SetActive(true);
            m_PlayerController.PlayerCanInteract();
            m_NarrativeManager.SeventhConv = true;
        }
        else if (other.tag == "Jump")
        {
            m_LineJump.SetActive(true);
            m_ControlJump.SetActive(true);
            m_PlayerController.PlayerCanJump();
            m_ScriptJump.SetActive(false);
            m_NarrativeManager.FourthConv = true;
        }
        else if (other.tag == "Spawn")
        {
            m_LineSpawn.SetActive(true);
            m_ControlSpawn.SetActive(true);
            m_PlayerController.PlayerCanMoveObject();
            m_ScriptSpawn.SetActive(false);
            m_TriggerZone.SetActive(false);
            m_NarrativeManager.SixthConv = true;
        }
        else if (other.tag == "Checkpoint")
        {
            m_ControlReload.SetActive(true);
        }
        else if (other.tag == "Trigger")
        {
            m_ScriptSpawn.SetActive(true);
            m_NarrativeManager.FifthConv = true;
        }
    }

    private void Update()
    {
        if (StartTimer)
        {
            Timer -= Time.deltaTime;
        }
        if (Timer <= 0f && stopDerping)
        {
            transform.position = m_SpawnPoint;
            m_TrapDoor.reset = true;
            stopDerping = false;
        }
    }
}
