using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

public class UI_MessagePanel : BasePanel
{
    /// <summary>
    /// 确定委托
    /// </summary>
    private UnityAction sureAction;

    /// <summary>
    /// 取消委托
    /// </summary>
    private UnityAction cancelAction;

    /// <summary>
    /// 初始化
    /// </summary>
    /// <param name="title"></param>
    /// <param name="content"></param>
    /// <param name="type"></param>
    /// <param name="action"></param>
    public void Init(string title,string content, E_MessageType type,UnityAction sureAction = null, UnityAction cancelAction = null)
    {
        GetControl<TextMeshProUGUI>("Text_title").text = title;
        GetControl<TextMeshProUGUI>("Text_Content").text = content;
        SelectPromptMode(type);
        this.sureAction = sureAction;
        this.cancelAction = cancelAction;
    }

    /// <summary>
    /// 选择提示模式
    /// </summary>
    /// <param name="type"></param>
    public void SelectPromptMode(E_MessageType type)
    {
        switch (type)
        {
            case E_MessageType.Normal:
                GetControl<Image>("Image_NormalBackGround").gameObject.SetActive(true);
                GetControl<Button>("Button_NormalConfirm").gameObject.SetActive(true);
                GetControl<Image>("Image_WarnBackGround").gameObject.SetActive(false);
                GetControl<Button>("Button_NormalCancel").gameObject.SetActive(false);
                GetControl<Button>("Button_WarmConfirm").gameObject.SetActive(false);
                break;
            case E_MessageType.Error:
                GetControl<Image>("Image_NormalBackGround").gameObject.SetActive(true);
                GetControl<Button>("Button_NormalConfirm").gameObject.SetActive(true);
                GetControl<Image>("Image_WarnBackGround").gameObject.SetActive(false);
                GetControl<Button>("Button_NormalCancel").gameObject.SetActive(true);
                GetControl<Button>("Button_WarmConfirm").gameObject.SetActive(false);
                break;
            case E_MessageType.Warning:
                GetControl<Image>("Image_NormalBackGround").gameObject.SetActive(false);
                GetControl<Button>("Button_NormalConfirm").gameObject.SetActive(false);
                GetControl<Image>("Image_WarnBackGround").gameObject.SetActive(true);
                GetControl<Button>("Button_NormalCancel").gameObject.SetActive(false);
                GetControl<Button>("Button_WarmConfirm").gameObject.SetActive(true);
                break;
        }



    }

    /// <summary>
    /// 点击按钮
    /// </summary>
    /// <param name="btnName"></param>
    protected override void OnClick(string btnName)
    {
        switch (btnName)
        {
            case "Button_WarmConfirm":
                sureAction?.Invoke();
                
                break;
            case "Button_NormalConfirm":
                sureAction?.Invoke();
                
                break;
            case "Button_NormalCancel":
                cancelAction?.Invoke();
                
                break;
        }
        GameManager.UIMgr.HidePanel<UI_MessagePanel>();
    }
}