using System;
using UnityEngine;
using UnityEngine.UI;

public class HasMaterialItemView : MonoBehaviour
{
    private static readonly string amountFormat = "{0}個";
    [SerializeField] private Text nameText;
    [SerializeField] private Text amountText;
    [SerializeField] private Transform materialTarget;
    [SerializeField] private GameObject viewObject;
    [SerializeField] private GameObject noStockObject;
    
    public void SetData(ShopData shopData, int amount)
    {
        amountText.text = String.Format(amountFormat, amount);
        nameText.text = shopData.name;
        materialTarget.DestroyAllChildrens();
        Instantiate(shopData.GetIconPrefab(), materialTarget);
    }
    
    public void SetNoStock(bool active)
    {
        viewObject.SetActive(!active);
        noStockObject.SetActive(active);
    }
}
