using FoxTube.Controls;
using FoxTube.Controls.Adverts;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace FoxTube.Pages
{
    /// <summary>
    /// Items cards container
    /// </summary>
    public sealed partial class VideoGrid : Page
    {
        public int Count => list.Items.Count;
        public ItemCollection Children => list.Items;
        private int ItemsCount => Children.FindAll(i => i is VideoCard).Count + Children.FindAll(i => i is ChannelCard).Count + Children.FindAll(i => i is PlaylistCard).Count + Children.FindAll(i => i is CardAdvert).Count;

        public VideoGrid()
        {
            InitializeComponent();
        }

        public void Add(UIElement card)
        {
            list.Items.Add(card);
            if ((list.Items.Count - 5) % 25 == 0)
                list.Items.Add(new CardAdvert());
            empty.Visibility = Visibility.Collapsed;
        }

        public void Clear()
        {
            list.Items.Clear();
            empty.Visibility = Visibility.Visible;
        }

        public void DeleteItem(FrameworkElement item)
        {
            Children.Remove(item);
        }
    }
}
