using System;
using BM;
using UnityEngine;

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

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