using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;

public class Player : MonoBehaviour
{
    [SerializeField] private Transform m_cameraPivot = default;
    [SerializeField] private Camera m_camera = default;
    [SerializeField] private Movement m_movement = default;
    [SerializeField] private Rigidbody m_rigidbody = default;
    [SerializeField] private Animator m_animator;

    public ushort CurrentItem = 0;
    
    public Movement Movement => m_movement;
    public Rigidbody Rigidbody => m_rigidbody;
    public Camera Camera => m_camera;
    public Animator Animator => m_animator;

    private Coroutine m_fovCoroutine;
    private Coroutine m_rotationCoroutine;

    private void Awake()
    {
        m_movement.Initialise(this);
    }

    public void StopMove(int move)
    {
        if (move == 0)
            m_movement.enabled = false;
        else
            m_movement.enabled = true;
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.GetComponent<CameraTransitionCollider>())
        {
            if (m_fovCoroutine != null)
            {
                StopCoroutine(m_fovCoroutine);
                m_fovCoroutine = null;
            }

            if (m_rotationCoroutine != null)
            {
                StopCoroutine(m_rotationCoroutine);
                m_rotationCoroutine = null;
            }
            StartCoroutine(other.GetComponent<CameraTransitionCollider>().SetCameraFOV(m_camera));
            StartCoroutine(other.GetComponent<CameraTransitionCollider>().SetCameraRotation(m_cameraPivot));
        }
    }
}
