using System.Collections;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;

public class ModalCtrl : MonoBehaviour
{
    [SerializeField] RectTransform imageMask;
    [SerializeField] RawImage suitImage;
    [SerializeField] TMP_Text suitName;
    [SerializeField] TMP_Text ownerName;
    [SerializeField] TMP_Text suitMaker;
    [SerializeField] TMP_Text debutDate;
    [SerializeField] TMP_Text suitType;
    [SerializeField] TMP_Text suitStyle;
    [SerializeField] GameObject[] colors;



    public void Set(Library library)
    {
        gameObject.SetActive(true);
        StartCoroutine(checkImageUpdate(library));
        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 / 850;
        Vector2 newSize = new Vector2(rect.sizeDelta.x / size, rect.sizeDelta.y / size);
        rect.sizeDelta = newSize;
        suitName.text = library.suit_name;
        ownerName.text = library.owner_name;
        suitMaker.text = library.maker;
        debutDate.text = library.production_date;
        suitType.text = library.suit_type;
        suitStyle.text = library.suit_style;


        
    }

    void OnDisable()
    {
        StopAllCoroutines();
    }

    IEnumerator checkImageUpdate(Library library)
    {
        while(library._suit_image == null)
        {
          yield return null;
        }

        suitImage.texture = library._suit_image;
    }
}
