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

// The drink holder is responsible for
// 1. Toggline geometry
// 2. Setting up the drink visualization for the held drink

public class DrinkHolder : MonoBehaviour
{

    private Drink currentlyHeldDrink = null;

    [SerializeField]
    public GameObject HeldDrinkSubOject;

    [SerializeField]
    public GameObject SealedHeldDrinkSubOject;

    public bool CurrentlyHoldingADrink
    {
        get { return currentlyHeldDrink != null; }
    }

    // Start is called before the first frame update
    void Start()
    {
        UpdateSubObjectState();
    }

    public void UpdateSubObjectState()
    {
        if (SealedHeldDrinkSubOject != null)
        {
            SealedHeldDrinkSubOject.SetActive(CurrentlyHoldingADrink && currentlyHeldDrink.Sealed);
        }

        if (HeldDrinkSubOject != null)
        {
            HeldDrinkSubOject.SetActive(CurrentlyHoldingADrink && (!currentlyHeldDrink.Sealed || SealedHeldDrinkSubOject == null));
        }
    }

    public Drink GetHeldDrink()
    {
        return currentlyHeldDrink;
    }

    public void SetHeldDrink(Drink drink)
    {
        if (drink != null)
        {
            currentlyHeldDrink = drink;
            UpdateSubObjectState();

            DrinkManager.Instance.SetDrinkRendererAnchor(drink, gameObject, "HP_DrinkRender");
        }
    }

    public Drink ReleaseHeldDrink()
    {
        Drink result = currentlyHeldDrink;

        currentlyHeldDrink = null;
        UpdateSubObjectState();

        return result;
    }
}
