using Cysharp.Threading.Tasks;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class ItemPrefab : MonoBehaviour, System.IEquatable<ItemPrefab>
{
    public Library Library;
    [SerializeField] TMP_Text suitName;
    [SerializeField] TMP_Text ownerName;
    [SerializeField] RawImage suitImage;

    public void Set(Library library)
    {
        this.Library = library;
        suitName.text = library.suit_name;
        ownerName.text = library.owner_name;
    }
    public void ImageSet()
    {
        suitImage.texture = Library._suit_image;
        suitImage.SetNativeSize();
        RectTransform rect = suitImage.gameObject.GetComponent<RectTransform>();
        rect.anchorMin = new Vector2(0.5f, 0.5f);
        rect.anchorMax = new Vector2(0.5f, 0.5f);
        float size = rect.sizeDelta.y / 500;
        Vector2 newSize = new Vector2(rect.sizeDelta.x / size, rect.sizeDelta.y /size);
        rect.sizeDelta = newSize;
    }

    public void Button()
    {
        SearchCtrl.Instance.ModelSet(Library);
    }

    public bool Equals(ItemPrefab other)
    {
        return (Library?.Equals(other?.Library) == true) && System.Object.ReferenceEquals(this, other);
    }
}
