using Core;
using UnityEngine;
using Script.Gameplay.Player;
using TMPro;
using System.Collections.Generic;

namespace UI
{
    public class PlayerGazeReminder : UIBase
    {
        [SerializeField] private GameObject reminderInteractPrefab;
        [SerializeField] private GameObject reminderConnectPrefab;
        [SerializeField] private GameObject reminderSetPointPrefab;
        private PlayerInteractorController playerInteractorController;
        private PlayerConnectController playerConnectController;

        protected override void Awake()
        {
            base.Awake();
            ControllerLocator.Instance.TryGetWait<PlayerInteractorController>(OnGetInteractorController);
            ControllerLocator.Instance.TryGetWait<PlayerConnectController>(OnGetConnectController);
        }

        private void OnGetInteractorController(PlayerInteractorController controller)
        {
            playerInteractorController = controller;
            playerInteractorController.OnGazeEnter += HandleInteractGazeEnter;
            playerInteractorController.OnGazeExit += HandleInteractGazeExit;
        }

        private void HandleInteractGazeEnter(GameObject obj)
        {
            reminderInteractPrefab.SetActive(true);
        }

        private void HandleInteractGazeExit(GameObject obj)
        {
            reminderInteractPrefab.SetActive(false);
        }

        private void OnGetConnectController(PlayerConnectController controller)
        {
            playerConnectController = controller;
            playerConnectController.OnGazeEnter += HandleConnectGazeEnter;
            playerConnectController.OnGazeExit += HandleConnectGazeExit;
        }

        private void HandleConnectGazeEnter(GameObject obj)
        {
            reminderConnectPrefab.SetActive(true);
            reminderSetPointPrefab.SetActive(true);
        }

        private void HandleConnectGazeExit(GameObject obj)
        {
            reminderConnectPrefab.SetActive(false);
            reminderSetPointPrefab.SetActive(false);
        }
    }
}