using System;
using UniRx;
using UnityEngine;
using UnityEngine.UI;

public class BulkOrderIndicatorView : MonoBehaviour
{
    [SerializeField] private Button button;
    [SerializeField] private Animator phoneAnimator;
    [SerializeField] private Animator indicatorAnimator;
    [SerializeField] private GameObject titleObject;
    [SerializeField] private GameObject balloonObject;
    [SerializeField] private GameObject completedBadgeObject;

    private static readonly int Ring = Animator.StringToHash("Ring");
    private static readonly int Wait = Animator.StringToHash("Wait");
    private static readonly int Speech = Animator.StringToHash("Speech");

    public IObservable<Unit> TappedPhone => button.OnClickAsObservable().TakeUntilDestroy(this);

    public void SetIndicate(bool receive, bool achieved)
    {
        if (receive)
        {
            phoneAnimator.SetTrigger(Ring);
            indicatorAnimator.SetTrigger(Speech);
        }
        else
        {
            phoneAnimator.SetTrigger(Wait);
        }
        button.interactable = receive || !achieved;
        titleObject.SetActive(!receive && !achieved);
        balloonObject.SetActive(receive);
    }

    public void SetBadgeActive(bool active)
    {
        completedBadgeObject.SetActive(active);
    }
}
