using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Threading.Tasks;

using Xamarin.Forms;

using MasterDet.Models;
using MasterDet.Views;
using System.Windows.Input;

namespace MasterDet.ViewModels
{
    public class ItemsViewModel : BaseViewModel
    {
        public ICommand ShowLoadingCommand => new Command(async () => await ShowLoading());

        private async Task ShowLoading()
        {
            IsBusy = true;
            await Task.Delay(5000);
            IsBusy = false;
        }

        //public ObservableCollection<Item> Items { get; set; }
        //public Command LoadItemsCommand { get; set; }

        //public ItemsViewModel()
        //{
        //    Title = "Browse";
        //    Items = new ObservableCollection<Item>();
        //    LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommand());

        //    MessagingCenter.Subscribe<NewItemPage, Item>(this, "AddItem", async (obj, item) =>
        //    {
        //        var newItem = item as Item;
        //        Items.Add(newItem);
        //        await DataStore.AddItemAsync(newItem);
        //    });
        //}

        //async Task ExecuteLoadItemsCommand()
        //{
        //    if (IsBusy)
        //        return;

        //    IsBusy = true;

        //    try
        //    {
        //        Items.Clear();
        //        var items = await DataStore.GetItemsAsync(true);
        //        foreach (var item in items)
        //        {
        //            Items.Add(item);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Debug.WriteLine(ex);
        //    }
        //    finally
        //    {
        //        IsBusy = false;
        //    }
        //}
    }
}