using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;

namespace BS.Shared.Extensions
{
    public static class UIElementCollectionExtensions
    {
        public static void RemoveRange(this UIElementCollection pList, IEnumerable pToRemove)
        {
            foreach (UIElement iItem in pToRemove)
            {
                pList.Remove(iItem);
            }
        }

        public static void RemoveRange(this UIElementCollection pList, int pStartIndex)
        {
            if (pList.Count > pStartIndex)
            {
                pList.RemoveRange(pStartIndex, pList.Count - pStartIndex);
            }
        }

        public static void RemoveRange(this UIElementCollection pList, Predicate<UIElement> pMatch)
        {
            List<UIElement> lToDelete = new List<UIElement>();

            foreach (UIElement iElement in pList)
            {
                if (pMatch(iElement))
                {
                    lToDelete.Add(iElement);
                }
            }

            pList.RemoveRange(lToDelete);
        }
    }
}