using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using static System.Net.Mime.MediaTypeNames;

namespace ET.Client
{
	[FriendOf(typeof(UIStatsComponent))]
	public static class UIStatsComponentSystem
    {
		[ObjectSystem]
		public class UIStatsComponentAwakeSystem : AwakeSystem<UIStatsComponent>
		{
			protected override void Awake(UIStatsComponent self, params object[] param)
			{
                ReferenceCollector rc = self.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
                self.playListObj = rc.Get<GameObject>("playListObj");
                self.timeContentTxt = rc.Get<GameObject>("timeContentTxt");
                self.noStatsTxt = rc.Get<GameObject>("noStatsTxt");
                self.nextTimeBtn = rc.Get<GameObject>("nextTimeBtn");
                self.nextTimeBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnNextTimeBtn(); });
                self.preTimeBtn = rc.Get<GameObject>("preTimeBtn");
                self.preTimeBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnPreTimeBtn(); });
                self.recodeBtn = rc.Get<GameObject>("recodeBtn");
                self.recodeBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnRecodeBtn(); });
                self.selPlayBtn = rc.Get<GameObject>("selPlayBtn");
                self.selPlayBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnSelPlayBtn(); });
                self.closeBtn = rc.Get<GameObject>("closeBtn");
                self.closeBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCloseBtn(); });
                self.Init();
            }
        }

        private static void Init(this UIStatsComponent self)
        {
            self.playListObj.SetActive(false);
            self.noStatsTxt.SetActive(true);
        }

        public static async void OnNextTimeBtn(this UIStatsComponent self)
        {
            await SoundManager.Instance.PlaySound("clickbtnsound");
        }

        public static async void OnPreTimeBtn(this UIStatsComponent self)
        {
            await SoundManager.Instance.PlaySound("clickbtnsound");
        }
        public static async void OnRecodeBtn(this UIStatsComponent self)
        {
            await SoundManager.Instance.PlaySound("clickbtnsound");
        }
        public static async void OnSelPlayBtn(this UIStatsComponent self)
        {
            await SoundManager.Instance.PlaySound("clickbtnsound");
        }

        public static async void OnCloseBtn(this UIStatsComponent self)
        {
            await SoundManager.Instance.PlaySound("clickbtnsound");
            self.OnCloseAsync();
        }

        public static async void OnCloseAsync(this UIStatsComponent self)
        {
            await UIHelper.Remove(self.ClientScene(),UIType.UIStats);
        }
    }
}