using FairyGUI;
using FGUI.JBingoPlay;
using BingoBrain.Core;
using BingoBrain.HotFix;
using UnityEngine;

namespace BingoBrain
{
    public class LeaveBingoUI : BaseUI
    {
        private LeaveBingoUICtrl ctrl;
        private LeaveBingoModel model;
        private com_leavegame ui;

        private bool isExit = false;

        public LeaveBingoUI(LeaveBingoUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.LeaveBingoUI;
            this.ctrl = ctrl;
        }

        protected override void SetUIInfo(UIInfo uiInfo)
        {
            uiInfo.packageName = "JBingoPlay";
            uiInfo.assetName = "com_leavegame";
            uiInfo.layerType = UILayerType.Popup;
            uiInfo.isNeedOpenAnim = true;
            uiInfo.isNeedCloseAnim = true;
            uiInfo.isNeedUIMask = true;
        }

        #region 生命周期

        protected override void OnInit()
        {
        }

        protected override void OnClose()
        {
            ui?.FadeOut();
        }

        protected override void OnBind()
        {
            ui = baseUI as com_leavegame;
        }

        protected override void OnOpenBefore(object args)
        {
            Audio.Instance.PlayDynamicEffect("pop_open");
        }

        protected override void OnOpen(object args)
        {
            ui?.FadeIn();
            ui.closeButton.onClick.Set(CloseClickUI);
            ui.btn_stay.onClick.Set(CloseClickUI);
            ui.btn_leave.onClick.Set(OnBtnCloseClick);
        }

        private void CloseClickUI()
        {
            CtrlCloseUI();
        }

        private void OnBtnCloseClick(EventContext context)
        {
            GameDispatcher.Instance.Dispatch(BingoInfo.EndBingoGame, true);
            CloseClickUI();
        }

        #endregion
    }
}