using System;
using BM;
using UnityEngine;

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

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