using UnityEditor;
using AssetBank.DockableWindow;
using System.Collections.Generic;

namespace AssetBank.Editor.DockableWindow
{
    public class ProjectExporterDataHelper
    {
        public static void LoadAssetTree(Dictionary<string, AssetModel> assetTrees, ProjectExporterController controller, string tabName, bool showProgress = true)
        {
            if (showProgress)
            {
                EditorUtility.DisplayProgressBar("Loading...", $"Fetching {tabName}...", 0.5f);   
            }
            try
            {
                switch (tabName)
                {
                    case "Scenes":
                        assetTrees[tabName] = ProjectExporterController.GetAssets("t:Scene", tabName);
                        break;
                    case "Prefabs":
                        assetTrees[tabName] = ProjectExporterController.GetAssets("t:Prefab", tabName);
                        break;
                    case "Scriptable Objects":
                        assetTrees[tabName] = ProjectExporterController.GetAssets("t:ScriptableObject", tabName);
                        break;
                    case "Meta Files":
                        assetTrees[tabName] = controller.GetAllMetaFiles();
                        break;
                    case "Settings":
                        assetTrees[tabName] = controller.GetProjectSettingsFiles();
                        break;
                }
            }
            finally
            {
                if (showProgress)
                {
                    EditorUtility.ClearProgressBar();
                }
            }
        }
        
        public static void SetChildrenSelection(AssetModel parent, bool isSelected)
        {
            parent.IsSelected = isSelected;
            foreach (var child in parent.Children)
            {
                SetChildrenSelection(child, isSelected);
            }
        }
    }
}