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

namespace Mono
{
    [UIBinding(prefab = "RegionItem")]
    public class RegionItem : UICom
    {
        public Button Btn_Region;

        public Text Text_RegionName;

        public RectTransform PoetryItemRoot;


        public List<PoetryItem> CurPoetryItems = new List<PoetryItem>();

        public override void GetUIData()
        {
            Btn_Region = UIData.Get<Button>("Btn_Region");
            Text_RegionName = UIData.Get<Text>("Text_RegionName");
            PoetryItemRoot = UIData.Get<RectTransform>("PoetryItemRoot");
        }

        public override void AddButtonEvent()
        {
            Btn_Region.onClick.AddListener(() => { CreatPoetryItem(); });
        }

        public void CreatPoetryItem()
        {
            if (CurPoetryItems.Count > 0)
            {
                for (var i = 0; i < CurPoetryItems.Count; i++)
                {
                    UIManager.Instance.RecUICom(this, CurPoetryItems[i]);
                }

                CurPoetryItems.Clear();
                return;
            }

            for (var i = 0; i < RegionConfig.Poets.Length; i++)
            {
                PoetConfig poetConfig = ConfigComponent.Instance.Get<PoetConfig>(RegionConfig.Poets[i]);

                PoetryItem poetryItem = UIManager.Instance.CreatUICom<PoetryItem>(this, PoetryItemRoot);
                poetryItem.CustomInit(poetConfig);
                 CurPoetryItems.Add(poetryItem);
            }

            // PoetryItem poetryItem = UIManager.Instance.CreatUICom<PoetryItem>(this, PoetryItemRoot);
            // poetryItem.CustomInit("白帝");
            // CurPoetryItems.Add(poetryItem);
            // PoetryItem poetryItem1 = UIManager.Instance.CreatUICom<PoetryItem>(this, PoetryItemRoot);
            // poetryItem1.CustomInit("黑帝");
            // CurPoetryItems.Add(poetryItem1);
            // PoetryItem poetryItem2 = UIManager.Instance.CreatUICom<PoetryItem>(this, PoetryItemRoot);
            // poetryItem2.CustomInit("金帝");
            // CurPoetryItems.Add(poetryItem2);
        }

        public override void Show()
        {
            base.Show();
        }

        public RegionConfig RegionConfig;

        public void CustomInit(RegionConfig regionConfig)
        {
            RegionConfig = regionConfig;
            Text_RegionName.text = regionConfig.name;
        }
    }
}