using XGame.Framework.Asset.Addressable;
using UnityEditor;
using UnityEngine;

namespace XGame.Editor.Asset
{
    public class AddressableAssetsWindow : EditorWindow
    {
        [MenuItem("Build/CollectAddressableAssets", priority = 20)]
        private static void CreateWindow()
        {
            (new AddressableBuildTask()).Run();
            var window = EditorWindow.GetWindow<AddressableAssetsWindow>(true, "AddressableAssetsWindow");
            window.Show();
        }

        private string[] labels = { "项目资源", "内置资源", "测试资源" };
        private int selected = 0;
        private AddressableInfoManifestTab[] manifestTabs;
        private void OnEnable()
        {
            manifestTabs = new AddressableInfoManifestTab[3];
            manifestTabs[0] = new AddressableInfoManifestTab(AddressableClassify.Product);
            manifestTabs[1] = new AddressableInfoManifestTab(AddressableClassify.BuiltIn);
            manifestTabs[2] = new AddressableInfoManifestTab(AddressableClassify.Tests);
        }

        private void OnDisable()
        {
            if (manifestTabs != null)
            {
                foreach (var manifest in manifestTabs)
                {
                    manifest?.Close();
                }
            }
        }


        private Vector2 scrollPosition;
        private void OnGUI()
        {
            int lastSelected = selected;
            selected = GUILayout.Toolbar(selected, labels, "LargeButton", GUILayout.Width(500));
            if (manifestTabs != null)
            {
                manifestTabs[selected].OnGUI();
            }

        }
    }

}
