using UnityEngine;

public class TooltipManager : MonoBehaviour
{
    private static TooltipManager instance;
    private GameObject currentTooltip;
    private ShowOnClickWithManager currentSource;

    void Awake()
    {
        // Синглтон паттерн
        if (instance == null)
        {
            instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
        }
    }

    public static void ShowTooltip(GameObject tooltip, ShowOnClickWithManager source, Vector3 position)
    {
        if (instance == null)
        {
            Debug.LogError("TooltipManager instance not found!");
            return;
        }

        instance.ShowTooltipInternal(tooltip, source, position);
    }

    public static void CloseCurrentTooltip()
    {
        if (instance != null)
        {
            instance.CloseCurrentTooltipInternal();
        }
    }

    public static bool IsTooltipActive()
    {
        return instance != null && instance.currentTooltip != null;
    }

    private void ShowTooltipInternal(GameObject tooltip, ShowOnClickWithManager source, Vector3 position)
    {
        // Закрываем текущую подсказку
        CloseCurrentTooltipInternal();

        // Показываем новую
        currentTooltip = tooltip;
        currentSource = source;
        tooltip.SetActive(true);
    }

    private void CloseCurrentTooltipInternal()
    {
        if (currentTooltip != null)
        {
            currentTooltip.SetActive(false);
            currentTooltip = null;
            currentSource = null;
        }
    }
}