using System.Collections.Generic;
using BingoBrain.Core;
using BingoBrain.HotFix;
using FairyGUI;
using FGUI.ACommon;
using FGUI.JMain;
using UnityEngine;

namespace BingoBrain
{
    public class FaqUIUI : BaseUI
    {
        private FaqUIUICtrl ctrl;
        private FaqUIModel model;
        private FGUI.JMain.com_faq ui;
        private int seleindex = 1;
        private List<string> config_name_list;
        private List<string> config_money_list;
        private List<string> old_timelist;
        private List<string> new_timelist;
        public FaqUIUI(FaqUIUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.FaqUIUI;
            this.ctrl = ctrl;
        }

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

        #region 生命周期
        protected override void OnInit()
        {
            //model = ModuleManager.Instance.GetModel(ModelConst.FaqUIModel) as FaqUIModel; 
        }

        protected override void OnClose()
        {
            Hall.Instance.UpdateSecondEvent -= scroll;
        }

        protected override void OnBind()
        {
            ui = baseUI as FGUI.JMain.com_faq;
        }

        protected override void OnOpenBefore(object args)
        {
            InitView();
        }

        protected override void OnOpen(object args)
        {
        }

        protected override void OnHide()
        {
        }

        protected override void OnDisplay(object args)
        {
        }
        #endregion

        #region 消息
        protected override void AddListener()
        {

        }
        protected override void RemoveListener()
        {

        }
        #endregion

        //初始化页面逻辑
        private void InitView()
        {
            exBrPoolModel.getFaqData();
            config_name_list = exBrPoolModel.config_name_list;
            config_money_list = exBrPoolModel.config_money_list;
            old_timelist = exBrPoolModel.old_time_list;
            new_timelist = exBrPoolModel.new_time_list;
            ui.btn_close.SetClick(() =>
            {
                UICtrlDispatcher.Instance.Dispatch(SkinInfo.FaqUIUI_Close);
            });
            ui.list_.SetVirtualAndLoop();
            ui.list_.itemRenderer = RendererList;
            ui.list_.numItems = 35;

            Hall.Instance.UpdateSecondEvent += scroll;
        }
        void scroll()
        {
            if (seleindex > 30)
            {
                seleindex = 0;
                ui.list_.ScrollToView(seleindex, false);
                ui.list_.ScrollToView_UseAnim(1, true, 1);
                seleindex = 2;
            }
            else
            {
                ui.list_.ScrollToView_UseAnim(seleindex, true, 1);
                seleindex++;
            }


        }

        void RendererList(int index, GObject obj)
        {
            var a = obj as com_list_main;
            a.name_.text = config_name_list[index % 30];
            a.money.text = "$" + config_money_list[index % 30];
            a.time1.text = old_timelist[index % 30];
            a.time2.text = new_timelist[index % 30];

        }
    }
}