using System;
using BM;
using UnityEngine;

namespace ET
{
	[UIEvent(UIType.UIHelp)]
    public class UIHelpEvent: AUIEvent
    {
        public override async ETTask<UI> OnCreate(UIComponent uiComponent, UILayer uiLayer)
        {
	        try
	        {
		        GameObject bundleGameObject = await AssetComponent.LoadAsync<GameObject>(out LoadHandler handler, "Assets/Bundles/UI/" + UIType.UIHelp + ".prefab");
		        GameObject gameObject = UnityEngine.Object.Instantiate(bundleGameObject, UIEventComponent.Instance.UILayers[(int)uiLayer]);
		        UI ui = uiComponent.AddChild<UI, string, GameObject>(UIType.UIHelp, gameObject);
		        ui.LoadHandler = handler;
				ui.AddComponent<UIHelpComponent>();
				return ui;
	        }
	        catch (Exception e)
	        {
				Log.Error(e);
		        return null;
	        }
		}

        public override void OnRemove(UIComponent uiComponent)
        {
	        uiComponent.Get(UIType.UIHelp).LoadHandler.UnLoad();
        }
    }
}