using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using Pixiview.Utils;

namespace Pixiview.Illust
{
    public partial class FavoritesPage : FavoriteIllustCollectionPage
    {
        public FavoritesPage()
        {
            Resources.Add("cardView", GetCardViewTemplate());
            InitializeComponent();
        }

        protected override bool IsFavoriteVisible => false;

        protected override void OnAppearing()
        {
            //base.OnAppearing();
            loaded = false;
            StartLoad();
        }

        protected override IEnumerable<IllustItem> DoGetIllustList(IllustItem[] data, ICommand command)
        {
            return data.Select(i =>
            {
                i.IllustTapped = command;
                return i;
            });
        }

        protected override IllustItem[] DoLoadIllustData(bool force)
        {
            var favorites = Stores.FavoriteObject;
            if (favorites == null)
            {
                return null;
            }
            return favorites.Illusts.ToArray();
        }
    }
}
