using System;
using System.Collections;
using System.Collections.Generic;
using SC.XR.Unity;
using UnityEngine;
using UnityEngine.UI;
using XRTool.Util;
using TMPro;

public class PopUpInfo : RemoteSingleton<PopUpInfo>
{
    public GameObject NetErrorPanel;
    public enum PopType
    {
        Tip=1,
        Pop = 2,
        PopOk = 3,
        ListenDlg=4
    }

    public void Start()
    {
        NetErrorPanel.SetActive(false);
        Tip.SetActive(false);
        Pop.SetActive(false);
        PopOk.SetActive(false);
        ListenDlg.SetActive(false);
    }


    public GameObject Tip;
    public GameObject Pop;
    public GameObject PopOk;
    public GameObject ListenDlg;

    private PopType pType;

    public void showPublic(PopType popType)
    {
        pType = popType;
        switch (popType)
        {
            case PopType.Tip:
                showTip();
                break;
            case PopType.Pop:
                showPop();
                break;
            case PopType.PopOk:
                showPopOk();
                break;
            case PopType.ListenDlg:
                showListenDlg();
                break;
        }
    }

    public void showPublic(PopType popType,string msg, string b1 = "确定", Action ok = null, string b2 = "取消", Action cancel = null)
    {
        btn1OK.onClick.RemoveAllListeners();
        btn2Cancel.onClick.RemoveAllListeners();
        pType = popType;
        msgText.text = msg;
        btn1Text.text = b1;
        btn2Text.text = b2;
        btn1OK.onClick.AddListener(() => {
            close();
            if (ok!=null)
            ok.Invoke();
        }
        );
        btn2Cancel.onClick.AddListener(() => {
            close();
            if (cancel!=null)
            cancel.Invoke();

        });
        switch (popType)
        {
            case PopType.Tip:
                showTip();
                break;
            case PopType.Pop:
                showPop();
                break;
            case PopType.PopOk:
                showPopOk();
                break;
        }
    }
    private TMP_Text msgText
    {
        get
        {
            switch (pType)
            {
                case PopType.Tip:
                    return UnityUtil.GetDepthChild<TMP_Text>(Tip.transform, "msgText");
                case PopType.Pop:
                    return UnityUtil.GetDepthChild<TMP_Text>(Pop.transform, "msgText");
                case PopType.PopOk:
                    return UnityUtil.GetDepthChild<TMP_Text>(PopOk.transform, "msgText");
            }
            return null;
        }
    }
    private TMP_Text btn1Text
    {
        get
        {
            switch (pType)
            {
                case PopType.Pop:
                    return UnityUtil.GetDepthChild<TMP_Text>(Pop.transform, "btn1Text");
                case PopType.PopOk:
                    return UnityUtil.GetDepthChild<TMP_Text>(PopOk.transform, "btn1Text");
            }
            return UnityUtil.GetDepthChild<TMP_Text>(Pop.transform, "btn1Text");
        }
    }
    private TMP_Text btn2Text
    {
        get
        {
            return UnityUtil.GetDepthChild<TMP_Text>(Pop.transform, "btn2Text");
        }
    }
    private Button btn1OK
    {
        get
        {
            switch (pType)
            {
                case PopType.Pop:
                    return UnityUtil.GetDepthChild<Button>(Pop.transform, "btn1OK");
                case PopType.PopOk:
                    return UnityUtil.GetDepthChild<Button>(PopOk.transform, "btn1OK");
            }
            return UnityUtil.GetDepthChild<Button>(Pop.transform, "btn1OK");
        }
    }
    private Button btn2Cancel
    {
        get
        {
            return UnityUtil.GetDepthChild<Button>(Pop.transform, "btn2Cancel");
        }
    }

    public void close()
    {

        Tip.SetActive(false);
        Pop.SetActive(false);
        PopOk.SetActive(false);
    }


    public void showTip()
    {
        Tip.SetActive(true);
        Pop.SetActive(false);
        PopOk.SetActive(false);
        ListenDlg.SetActive(false);
        TimerMgr.Instance.CreateTimer(()=> { Tip.SetActive(false); },2f);
    }

    public void showPop()
    {
        Tip.SetActive(false);
        PopOk.SetActive(false);
        Pop.SetActive(true);
        ListenDlg.SetActive(false);
    }

    public void showPopOk()
    {
        Tip.SetActive(false);
        Pop.SetActive(false);
        PopOk.SetActive(true);
        ListenDlg.SetActive(false);
    }

    public void showListenDlg()
    {
        Tip.SetActive(false);
        Pop.SetActive(false);
        PopOk.SetActive(false);
        ListenDlg.SetActive(true);
    }

    public void ShowNetErrorPanel()
    {
        NetErrorPanel.SetActive(true);
    }

    public void HideNetErrorPanel()
    {
        NetErrorPanel.SetActive(false);
    }
}