using FairyGUI;
using FGUI.G007_makeup;
using System.Collections.Generic;
using UnityEngine;

namespace ScrewsMaster
{
    public class MakeupRecordUI : BaseUI
    {
        private MakeupRecordUICtrl ctrl;
        private MakeupRecordModel model;
        private com_record ui;

        public MakeupRecordUI(MakeupRecordUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.MakeupRecordUI;
            this.ctrl = ctrl;
        }

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

        #region 生命周期

        protected override void OnInit()
        {

        }

        protected override void OnClose()
        {
        }

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

        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 List<MakeupTaskData> makeupdataList = new List<MakeupTaskData>();

        private void InitView()
        {
            // if (Screen.safeArea.y != 0)
            // {//刘海屏
            //     ui.group_.y += Screen.safeArea.y;
            // }
            makeupdataList.Clear();

            foreach (var makeupTaskData in PreferencesMgr.Instance.MakeupTaskHistory)
            {
                if (makeupTaskData.status != MakeupTaskStatus.Inline)
                {
                    continue;
                }

                makeupdataList.Add(makeupTaskData);
            }

            if (makeupdataList.Count == 0)
            {
                ui.cont_show.selectedIndex = ui._Show_none;
            }
            else
            {
                ui.cont_show.selectedIndex = ui._Show_list;
                ui.list_record.itemRenderer = ItemRenderer;
                ui.list_record.numItems = makeupdataList.Count;
            }

            ui.closeButton.SetClick(CtrlCloseUI);
            ui.btn_help.SetClick(() => { UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.RegulationUI_Open); });
        }

        private void ItemRenderer(int index, GObject gObject)
        {
            var data = makeupdataList[index];
            var item = gObject as com_cord;
            if (data == null || item == null)
            {
                return;
            }

            TextureHelper.GetCardIcon(true, spr => { item.loader_logo.texture = spr; });
            // item.text_name.SetVar("cur", data.inlineNum.ToString()).SetVar("tol", data.inlineInitNum.ToString())
            //     .FlushVars();
            item.text_amt.text = "+" + GameHelper.GetPaymentTypeVO().payicon + (int)data.amount;
            item.email_text.text = PreferencesMgr.Instance.ExchangeAccount;
            item.number_text.text = data.inlineNum + "/" + data.inlineInitNum;
            item.time_text.text = DateTimeManager.Instance.TimestampToString(data.order_time);

        }
    }
}