using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;
using System.Collections.Generic;
using System;
using GCGame.Table;
using Games.GlobeDefine;

public class RedPacketSendRankInfo
{
    public ulong PlayerGuid;
    public int PlayerPro;
    public string PlayerName;
    public int Rank;
    public int SendPacketValue;
    public int NeedValue;
    public int AwardTitleID;
    public bool IsLastMsg = false;
    public bool MyMsg = false;
}

public class RedPacketSendRankItem : UIItemSelect
{
    public Text _Rank;
    public Text _PlayerName;
    public UIContainerBase _TitleAttr;
    public Text _Title;
    public Text _SendValue;
    public Text _NeedValue;

    public Text _LastTips;

    private RedPacketSendRankInfo _PacketInfo;
    public RedPacketSendRankInfo PacketInfo
    {
        get
        {
            return _PacketInfo;
        }
    }

    public override void Show(Hashtable hash)
    {
        base.Show();

        _PacketInfo = (RedPacketSendRankInfo)hash["InitObj"];
        UpdateInfo(_PacketInfo);
    }

    public void UpdateInfo(RedPacketSendRankInfo pcaketInfo)
    {
        if (PacketInfo.NeedValue == 0)
        {
            _PlayerName.text = GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.RoleName;
            _SendValue.text = "0";
            _NeedValue.text = "";
            _Rank.text = "-";
            _Title.text = "";
            return;
        }

        if (_PacketInfo.IsLastMsg)
        {
            _PlayerName.text = "";
            _SendValue.text = "";
            _NeedValue.text = _PacketInfo.NeedValue.ToString();
            _Rank.text = StrDictionary.GetClientDictionaryString("#{40107}");
        }
        else
        {
            _Rank.text = StrDictionary.GetClientDictionaryString("#{40103}", _PacketInfo.Rank);
            if (_PacketInfo.PlayerGuid == GlobeVar.INVALID_GUID
                || string.IsNullOrEmpty(_PacketInfo.PlayerName))
            {
                if (_PacketInfo.Rank > 3)
                {
                    _SendValue.text = _PacketInfo.SendPacketValue.ToString();
                    _NeedValue.text = _PacketInfo.NeedValue.ToString();
                }
                else
                {
                    _SendValue.text = StrDictionary.GetClientDictionaryString("#{40105}", _PacketInfo.SendPacketValue);
                    _NeedValue.text = StrDictionary.GetClientDictionaryString("#{40106}", _PacketInfo.NeedValue);
                }
                _PlayerName.text = StrDictionary.GetClientDictionaryString("#{40104}");
            }
            else
            {
                if (_PacketInfo.MyMsg)
                {
                    _SendValue.text = _PacketInfo.SendPacketValue.ToString();
                    _NeedValue.text = _PacketInfo.NeedValue.ToString();
                }
                else if (_PacketInfo.Rank > 3)
                {
                    _SendValue.text = _PacketInfo.SendPacketValue.ToString();
                    _NeedValue.text = _PacketInfo.NeedValue.ToString();
                }
                else if (_PacketInfo.Rank < 0)
                {
                    _Rank.text = "-";
                    _SendValue.text = _PacketInfo.SendPacketValue.ToString();
                    _NeedValue.text = "";
                }
                else
                {
                    _SendValue.text = StrDictionary.GetClientDictionaryString("#{40105}", _PacketInfo.SendPacketValue);
                    _NeedValue.text = StrDictionary.GetClientDictionaryString("#{40106}", _PacketInfo.NeedValue);
                }
                
                _PlayerName.text = _PacketInfo.PlayerName;
            }
            
        }

        
        var titleData = TableManager.GetTitleDataByID(_PacketInfo.AwardTitleID, 0);
        if (titleData != null)
        {
            _Title.text = titleData.Name;
            if (_TitleAttr != null)
            {
                List<RoleViewAttrPair.AttrPair> attrList = new List<RoleViewAttrPair.AttrPair>();
                for (int i = 0; i < titleData.getAttrIdCount(); ++i)
                {
                    if (titleData.GetAttrIdbyIndex(i) >= 0)
                    {
                        attrList.Add(new RoleViewAttrPair.AttrPair((PropID.PropertyID)titleData.GetAttrIdbyIndex(i), titleData.GetAttrValbyIndex(i)));
                    }
                }
                _TitleAttr.InitContentItem(attrList);
            }
        }

    }

    public void OnNameClick()
    {
        PlayerTooltipsLogic.ShowPlayerTooltip(_PacketInfo.PlayerGuid, _PacketInfo.PlayerName, _PlayerName.transform.position);
    }

    public void OnGetPacket()
    { }

    public void OnDetail()
    { }
}