using FWindSoft.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Com.FirmLib.UI
{
    /// <summary>
    /// 树形导航类扩展
    /// </summary>
    public static class TreeNavigationExtension
    {
        /// <summary>
        /// 获取指定级别的子数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="root"></param>
        /// <param name="level"></param>
        /// <returns></returns>
        public static List<TreeNavigationItem<T>> GetSpecifyLevelData<T>(this TreeNavigation<T> root,int level)
        {
            var useLevel = level;
            List<TreeNavigationItem<T>> items = root.Items.ToList();
            while (useLevel > 1)
            {
                items = items.SelectMany(i => i.Nodes).ToList();

                useLevel--;
            }
            return items;
        }
        /// <summary>
        /// 获取最底级数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="root"></param>
        /// <returns></returns>
        public static List<TreeNavigationItem<T>> GetLastLevelData<T>(this TreeNavigation<T> root)
        {
            List<TreeNavigationItem<T>> items = new List<TreeNavigationItem<T>>();
            items = root.Items.SelectMany(c => c.GetLeaves()).ToList();
            return items;
        }
    }
}
