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

public class Tile : MonoBehaviour, IDropHandler {
    [SerializeField] Color baseColor, offsetColor;
    [SerializeField] GameObject hilight;


    public void Init(bool isOffset) {
        GetComponent<SpriteRenderer>().color = isOffset ? offsetColor : baseColor;
    }

    private void OnMouseExit() {
        hilight.SetActive(false);
    }

    private void OnMouseEnter() {
        hilight.SetActive(true);
    }

    private void OnMouseOver() {
        if (Input.GetMouseButtonUp(0)) {
            CinemachineVirtualCamera vcam = GameManagerScript.getInstance().getActiveCamera().GetComponent<CinemachineVirtualCamera>();
            vcam.Follow = transform;
        } else if (Input.GetMouseButtonUp(1)) {
            CinemachineVirtualCamera vcam = GameManagerScript.getInstance().getActiveCamera().GetComponent<CinemachineVirtualCamera>();
            vcam.Follow = GameManagerScript.getInstance().getGridTargetGroup().transform;
        }
    }

    public void OnDrop(PointerEventData eventData) {
        Debug.Log("OnDrop Called");
        if (eventData.pointerDrag != null) {
            eventData.pointerDrag.GetComponent<RectTransform>().anchoredPosition = GetComponent<RectTransform>().anchoredPosition;
        }
    }
}
