using System;
using UnityEditor.Timeline.Actions;
using UnityEngine;
using UnityEngine.UI;

namespace Mono
{
    [UIBinding(prefab = "StartPanel")]
    public class StartPanel : UIPanel
    {
        public Button Btn_Start;
        public Animator StartPanelAni;

        public override void GetUIData()
        {
            Btn_Start = UIData.Get<Button>(nameof(Btn_Start));
            StartPanelAni = UIData.Get<Animator>(nameof(StartPanelAni));
        }

        private float _timer;
        private bool _isEnable;

        public override void AddButtonEvent()
        {
            Btn_Start.onClick.AddListener(() =>
            {
                if (!_isEnable)
                {
                    _isEnable = true;
                    StartPanelAni.Play("starBtnOpen");
                }
            });
        }

        public void Update()
        {
            if (_isEnable)
            {
                _timer += Time.deltaTime;
                if (_timer >= 0.5f)
                {
                    OpenMainScenePanel();
                    _isEnable = false;
                    _timer = 0;
                }
            }
        }

        public void OpenMainScenePanel()
        {
            UIManager.Instance.HideUIPanel<StartPanel>();
            UIManager.Instance.LoadAndOpenPanel<MainScenePanel>(UIManager.UILayer.Middle);
        }
    }
}