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

[RequireComponent(typeof(FactWrapper))]
public class OpenFactExplorer : MonoBehaviour, IPointerClickHandler
{
    public GameObject factExplorerPrefab;

    private static Transform factExplorer;

    public void OnPointerClick(PointerEventData eventData)
    {
        // TODO: add support for other input systems
        if (eventData.button == PointerEventData.InputButton.Right)
        {
            Destroy(factExplorer != null ? factExplorer.gameObject : null);

            var parent = transform.GetComponentInParent<Canvas>().transform;
            var fact = transform.GetComponent<FactWrapper>().fact;

            factExplorer = Instantiate(factExplorerPrefab.transform, Input.mousePosition, Quaternion.identity, parent);
            factExplorer.GetComponent<FactExplorer>().Initialize(fact);
        }
    }
}