using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using PerfDiagHubXAML.Common;
using PerfDiagHubXAML.Data;
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

// The Split Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234234

namespace PerfDiagHubXAML
{
    /// <summary>
    /// A page that displays a group title, a list of items within the group, and details for
    /// the currently selected item.
    /// </summary>
    public sealed partial class SplitPage : Page
    {
        public SplitPage()
        {
            this.InitializeComponent();
        }

	    private async void pageRoot_Loaded(object sender, RoutedEventArgs e)
	    {
			ObservableCollection<SampleDataGroup> groups = await SampleDataSource.GetGroupsAsync();
            var group = groups[0];

			itemListView.ItemsSource = group.Items;
	    }

        /// <summary>
        /// Invoked when an item within the list is selected.
        /// </summary>
        /// <param name="sender">The GridView displaying the selected item.</param>
        /// <param name="e">Event data that describes how the selection was changed.</param>
        private async void ItemListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
			(App.Current as App).LogMessage("Selection Changed");

			if(e.AddedItems.Count > 0)
			{
				SampleDataItem item = (e.AddedItems[0] as SampleDataItem);
				Processed.Source = await ImageHelper.Convert(item.ImagePath);
			}
        }
    }
}