<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="TripLog.Views.MainPage"
    xmlns:vm="clr-namespace:TripLog.ViewModels"
    Title="TripLog">
    <ContentPage.ToolbarItems>
        <ToolbarItem Text="New" Command="{Binding NewCommand}" />
    </ContentPage.ToolbarItems>
    <ContentPage.Content>
        <RefreshView IsRefreshing="{Binding IsBusy, Mode=OneWay}"
                     Command="{Binding RefreshCommand}">
            <CollectionView x:Name="trips"
                            SelectionMode="Single"
                            ItemsSource="{Binding LogEntries}">
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <Grid Padding="10">
                            <Grid.GestureRecognizers>
                                <TapGestureRecognizer Command="{Binding Source={RelativeSource AncestorType={x:Type vm:MainViewModel}}, Path=ViewCommand}"
                                                      CommandParameter="{Binding}" />
                            </Grid.GestureRecognizers>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="1*" />
                                <ColumnDefinition Width="3*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Label Grid.RowSpan="2"
                                   Text="{Binding Date, StringFormat='{0:MMM d}'}" />
                            <Label Grid.Column="1"
                                   Text="{Binding Title}"
                                   FontAttributes="Bold" />
                            <Label Grid.Column="1"
                                   Grid.Row="1"
                                   Text="{Binding Notes}" />
                        </Grid>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>
        </RefreshView>
    </ContentPage.Content>
</ContentPage>