using System;
using UnityEngine;
using UnityEngine.UI;

public class HasProductItemView : MonoBehaviour
{
    private static readonly string amountFormat = "{0}個";
    [SerializeField] private Text nameText;
    [SerializeField] private Text amountText;
    [SerializeField] private Transform productTarget;
    [SerializeField] private GameObject viewObject;
    [SerializeField] private GameObject noStockObject;

    public void SetData(ProductData productData, int amount)
    {
        amountText.text = String.Format(amountFormat, amount);
        nameText.text = productData.name;
        productTarget.DestroyAllChildrens();
        Instantiate(productData.GetIconPrefab(), productTarget);
    }

    public void SetNoStock(bool active)
    {
        viewObject.SetActive(!active);
        noStockObject.SetActive(active);
    }
}
