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

public class BettingSpace : MonoBehaviour
{
    public float ratio = 1;
    EventTrigger eventTrigger;
    Image image;
    Color defaultColor;
    RectTransform rect;
    void Start()
    {
        rect = GetComponent<RectTransform>();
        image = GetComponent<Image>();
        defaultColor = image.color;
        eventTrigger = GetComponent<EventTrigger>();

        EventTrigger.Entry OnEnter = new EventTrigger.Entry();
        OnEnter.eventID = EventTriggerType.PointerEnter;
        OnEnter.callback.AddListener(onEnter);

        EventTrigger.Entry OnExit = new EventTrigger.Entry();
        OnExit.eventID = EventTriggerType.PointerExit;
        OnExit.callback.AddListener(onExit);

        EventTrigger.Entry OnClick = new EventTrigger.Entry();
        OnClick.eventID = EventTriggerType.PointerClick;
        OnClick.callback.AddListener(onClick);

        eventTrigger.triggers.Add(OnEnter);
        eventTrigger.triggers.Add(OnExit);
        eventTrigger.triggers.Add(OnClick);
    }

    void onEnter(BaseEventData e){
        image.color = new Color(defaultColor.r,defaultColor.g,defaultColor.b,defaultColor.a*0.5f);
    }

    void onExit(BaseEventData e){
        image.color = defaultColor;
    }

    void onClick(BaseEventData e){
        GameObject newChip = Instantiate(RouletteManager.SelectedChipItem.gameObject, transform);
        newChip.GetComponent<RectTransform>().localPosition = Vector3.zero;
        newChip.GetComponent<RectTransform>().sizeDelta = new Vector2(50,50);

        RouletteManager.AddBet(RouletteManager.SelectedChip);
    }
    
}
