using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

using Navigator.Models;
using Navigator.Views;
using Navigator.ViewModels;
using Navigator.Core;

namespace Navigator.Views
{
    // Learn more about making custom code visible in the Xamarin.Forms previewer
    // by visiting https://aka.ms/xamarinforms-previewer
 //   [DesignTimeVisible(false)]
    public partial class ItemsPage : ContentPage
    {
        private ItemsViewModel viewModel;

        public ItemsPage()
        {
            InitializeComponent();
            BindingContext = viewModel = new ItemsViewModel(Navigation);
        }
// This is where the new page and view model are connected.
// Navigation.PushAsync
//        async void OnItemSelected(object sender, EventArgs args)
        void OnItemSelected(object sender, EventArgs args)
        {
          BindableObject layout = (BindableObject)sender;
          CommandViewModel commandViewModel=(CommandViewModel)layout.BindingContext;
					commandViewModel.Command.Execute(null);
			}

		//async void AddItem_Clicked(object sender, EventArgs e)
		//{
		//    await Navigation.PushModalAsync(new NavigationPage(new NewItemPage()));
		//}

		protected override void OnAppearing()
        {
      base.OnAppearing();
      if (viewModel.Commands.Count == 0) viewModel.IsBusy = true;

      //if (viewModel.Items.Count == 0)
      //  viewModel.IsBusy = true;
    }
    }
}