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

public class RecipeView : MonoBehaviour
{
    [SerializeField] private GameObject lockPanel;
    [SerializeField] private Button detailButton;
    [SerializeField] private Text flavorName;
    [SerializeField] private Text flavorPrice;
    [SerializeField] private Text cornAmountText;
    [SerializeField] private Text flavor1AmountText;
    [SerializeField] private Text flavor2AmountText;
    [SerializeField] private GameObject flavor2View;
    private static readonly string amountFormat = "x{0}";
    public IObservable<Unit> RecipeClickObservable => detailButton.OnClickAsObservable().TakeUntilDestroy(this);

    private void Start()
    {
    }

    public void SetRecipe(RecipeData data)
    {
        flavorName.text = data.Name;
        flavorPrice.text = data.Price.ToString();
        cornAmountText.text = string.Format(amountFormat, data.CornAmount);
        flavor1AmountText.text = string.Format(amountFormat, data.Flavors[0].amount);
        if (data.Flavors.Count == 2)
        {
            flavor2View.SetActive(true);
            flavor2AmountText.text = string.Format(amountFormat, data.Flavors[1].amount);
        }
        else
        {
            flavor2View.SetActive(false);
        }
    }

    public void SetLockPanel(bool hasRecipe)
    {
        lockPanel.SetActive(hasRecipe);
    }
}
