using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;

namespace MyGame.Scenes.MiniGame.Scripts
{
    public class StageSelectView : MonoBehaviour
    {
        [SerializeField] private Text titleText;
        [SerializeField] private Text itemText;
        [SerializeField] private Text recipeText;
        // [SerializeField] private Text itemNeedScoreText;
        [SerializeField] private Text recipeNeedScoreText;
        [SerializeField] private Text totalScore;
        [SerializeField] private GameObject recipeObject;
        [SerializeField] private ScrollRect scrollRect;
        [SerializeField] private StageSelectItemView[] itemViewList;

        public ScrollRect ScrollRect => scrollRect;
        public StageSelectItemView[] ItemViewList => itemViewList;

        public void SetScore(int num) => totalScore.text = $"累計スコア：{num}";

        public void SetPlaceData(ScrollGamePlaceData[] placeDataList)
        {
            // titleText.text = placeDataList[0].placeId.ToString();
            var shopDataList = SpreadsheetDataManager.Instance.GetBaseDataList<ShopData>(Const.ShopDataSheet);
            var productDataList = SpreadsheetDataManager.Instance.GetBaseDataList<ProductData>(Const.ProductDataSheet);
            foreach (var placeData in placeDataList)
            {
                if (placeData.itemId != 0)
                {
                    var shopData = shopDataList.FirstOrDefault(data => data.itemId == placeData.itemId && data.Category == ItemCategory.Material);
                    itemText.text = $"貰える材料：　{shopData.Name}";
                    // itemNeedScoreText.text = placeData.needScore.ToString();
                }else if (placeData.recipeId != 0)
                {
                    var productData = productDataList.FirstOrDefault(data => data.id == placeData.recipeId);
                    recipeText.text = $"達成報酬：　{productData.Name}";
                    recipeNeedScoreText.text = $"必要スコア：{placeData.needScore}";
                }
            }
        }
    }
}