<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:common="clr-namespace:XamarinStudy.Commons;assembly=XamarinStudy"
             x:Class="XamarinStudy.Views.ToyMartPage"
             Title="Toy Mart">
    <ContentPage.Resources>
        <ResourceDictionary>
            <common:ValueConverter x:Key="cvt"/>
        </ResourceDictionary>
    </ContentPage.Resources>
    <ContentPage.ToolbarItems>
        <ToolbarItem x:Name="orderToolbarItem" Text="Order" Clicked="orderToolbarItem_Clicked"/>
        <ToolbarItem x:Name="unselectAllToolbarItem" Text="Unselect All" Clicked="unselectAllToolbarItem_Clicked"/>
    </ContentPage.ToolbarItems>
    <ContentPage.Content>
        <ListView x:Name="menuListView" ItemsSource="{Binding .}" 
                  HasUnevenRows="True" IsGroupingEnabled="True" GroupDisplayBinding="{Binding Title}"
                  IsPullToRefreshEnabled="True" Refreshing="menuListView_Refreshing"
                  ItemTapped="menuListView_ItemTapped">
            <ListView.GroupHeaderTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Horizontal" BackgroundColor="DarkSlateBlue">
                            <Label Text="{Binding Title}" HorizontalOptions="StartAndExpand" FontSize="Large" TextColor="White"/>
                            <Label Text="{Binding Count}" FontSize="Large" TextColor="White"/>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.GroupHeaderTemplate>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Horizontal" Padding="6, 6">
                            <Image Source="{Binding Image, Converter={StaticResource cvt}}" WidthRequest="50" HeightRequest="50"/>
                            <Label Text="{Binding Name}" FontSize="Large" VerticalTextAlignment="Center" HorizontalOptions="FillAndExpand"/>
                            <Label Text="{Binding Price}" FontSize="Medium" VerticalTextAlignment="Center" HorizontalOptions="FillAndExpand"/>
                            <CheckBox IsChecked="{Binding IsChecked}"/>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </ContentPage.Content>
</ContentPage>