using CollaborativePlatformProject.CollaborationPlatform.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace CollaborativePlatformProject.CollaborationPlatform.Util
{
    /// <summary>
    ///
    /// <para>⽂件名(File Name):     CollaborationUtil.cs</para>
    ///
    /// <para>描述(Description):     协同工具工具类</para>
    ///
    /// <para>数据表(Tables):        nothing</para>
    ///
    /// <para>作者(Author):          Sun Zheng Ji</para>
    ///
    /// <para>⽇期(Create Date):     2024年4月18日10:06:56</para>
    ///
    /// 修改记录(Revision History):
    ///     R1:
    ///         修改作者:
    ///         修改⽇期:
    ///         修改理由:
    ///
    /// </summary>
    public static class CollaborationUtil
    {
        /// <summary>
        /// 获得指定元素的所有子元素
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static List<T> GetChildObjects<T>(DependencyObject obj) where T : FrameworkElement
        {
            DependencyObject child = null;
            List<T> childList = new List<T>();

            for (int i = 0; i <= VisualTreeHelper.GetChildrenCount(obj) - 1; i++)
            {
                child = VisualTreeHelper.GetChild(obj, i);

                if (child is T)
                {
                    childList.Add((T)child);
                }
                childList.AddRange(GetChildObjects<T>(child));
            }
            return childList;
        }



        /// <summary>
        /// 获取名字在集合中的下标
        /// </summary>
        /// <param name="name"></param>
        /// <param name="treeViews"></param>
        /// <returns></returns>
        public static int GetIndexByTreeView(string name,List<TreeViewBind> treeViews )
        {
            for (int i = 0; i < treeViews.Count; i++)
            {
                if (treeViews[i].Name.Equals(name))
                {
                    return i;
                }
                
            }

            return -1;
        }

    }
}