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

public class TeamInvateTips : UIControllerBase<TeamInvateTips>
{
    void Awake()
    {
        SetInstance(this);
    }

    void OnEnable()
    {
        SetInstance(this);
        UpdateInvate();
    }

    void OnDisable()
    {

        SetInstance(null);
    }

    public void OnBtnClose()
    {
        UIManager.CloseUI(UIInfo.TeamInvateTips);
    }

    public static void ShowTeamInvate()
    {
        UIManager.ShowUI(UIInfo.TeamInvateTips);
    }
    #region team tips

    public Text _TeamInvateMsg;

    private TeamInvater _ShowInvate;
    public void UpdateInvate()
    {
        if (GameManager.gameManager.PlayerDataPool.TeamInfo.InvaterList.Count == 0)
        {
            OnBtnClose();
            return;
        }

        _ShowInvate = GameManager.gameManager.PlayerDataPool.TeamInfo.InvaterList[0];
        _TeamInvateMsg.text = StrDictionary.GetClientDictionaryString("#{5121}", _ShowInvate.InvaterName, _ShowInvate.TeamLeaderName);

    }


    public void OnBtnInvateOk()
    {
        CG_JOIN_TEAM_INVITE_RESULT pak = (CG_JOIN_TEAM_INVITE_RESULT)PacketDistributed.CreatePacket(MessageID.PACKET_CG_JOIN_TEAM_INVITE_RESULT);
        pak.InviterGuid = _ShowInvate.InvaterGuid;
        pak.Result = 1;
        pak.SendPacket();

        RemoveInvate();
    }

    public void OnBtnInvateCancel()
    {
        CG_JOIN_TEAM_INVITE_RESULT pak = (CG_JOIN_TEAM_INVITE_RESULT)PacketDistributed.CreatePacket(MessageID.PACKET_CG_JOIN_TEAM_INVITE_RESULT);
        pak.InviterGuid = _ShowInvate.InvaterGuid;
        pak.Result = 0;
        pak.SendPacket();

        RemoveInvate();
    }

    private void RemoveInvate()
    {
        GameManager.gameManager.PlayerDataPool.TeamInfo.InvaterList.Remove(_ShowInvate);
        UpdateInvate();
    }
    #endregion
}