// using FGUI.A000_common;

using System;
using FairyGUI;
using FGUI.ZM_EMail_20;
using UnityEngine;

namespace RedHotRoast
{
    public class MailViewUI : BaseUI
    {
        private MailViewUICtrl ctrl;
        private SignInViewModel model;

        private FGUI.ZM_EMail_20.com_mail ui;

        private mail_item items;

        public MailViewUI(MailViewUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.MailViewUI;
            this.ctrl = ctrl;
        }

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

        }

        #region 生命周期
        protected override void OnInit()
        {
        }

        protected override void OnClose()
        {
            GameHelper.showGameUI = true;


        }

        protected override void OnBind()
        {
            ui = baseUI as FGUI.ZM_EMail_20.com_mail;

        }

        protected override void OnOpenBefore(object args)
        {
            items = (mail_item)UIPackage.CreateObject("ZM_EMail_20", "mail_item");
            if (Screen.safeArea.y != 0)
            {
                ui.com_gold.y += Screen.safeArea.y-15;

            }

            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()
        {

            ui.com_gold.GetChild("text_gold").text = $"{DataMgr.Coin.Value:N0}";
            // items.title.text = "test";
            // items.text_content.text = "test";
            var loginModel = GameHelper.GetLoginModel();

            var timestr = loginModel.RegTime;
            DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(timestr);

            items.text_time.text = dateTimeOffset.LocalDateTime.ToString();
            items.SetClick(()=>{updateitems(items);});

            ui.list_mail.AddChild(items);
            ui.stage.selectedIndex = 1;
        }

        private void updateitems(mail_item ite){
            ite.status.selectedIndex = ite.status.selectedIndex == 0 ? 1 : 0;
        }
    }
}
