<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="CollectionViewDemos.Views.SecondPage"
             xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:controls="clr-namespace:CollectionViewDemos.Controls"
             xmlns:models="clr-namespace:CollectionViewDemos.Models"
             xmlns:viewModels="clr-namespace:CollectionViewDemos.ViewModels"
             Title="SecondPage">
    <ContentPage.BindingContext>
        <viewModels:MonkeysViewModel />
    </ContentPage.BindingContext>
    <ContentPage.Resources>
        <DataTemplate x:Key="AmericanMonkeyTemplate" x:DataType="models:Monkey">
            <Grid Padding="10"
                  ColumnDefinitions="Auto,Auto" RowDefinitions="Auto,Auto">
                <Image Grid.RowSpan="2"
                       Aspect="AspectFill" HeightRequest="60"
                       Source="{Binding ImageUrl}"
                       WidthRequest="60" />
                <Label Grid.Column="1"
                       FontAttributes="Bold"
                       Text="{Binding Name}" />
                <Label Grid.Row="1" Grid.Column="1"
                       FontAttributes="Italic"
                       Text="{Binding Location}"
                       VerticalOptions="End" />
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="OtherMonkeyTemplate" x:DataType="models:Monkey">
            <Grid Padding="10"
                  ColumnDefinitions="Auto,Auto" Opacity="0.3" RowDefinitions="Auto,Auto">
                <Image Grid.RowSpan="2"
                       Aspect="AspectFill" HeightRequest="60"
                       Source="{Binding ImageUrl}"
                       WidthRequest="60" />
                <Label Grid.Column="1"
                       FontAttributes="Bold"
                       Text="{Binding Name}" />
                <Label Grid.Row="1" Grid.Column="1"
                       FontAttributes="Italic"
                       Text="{Binding Location}"
                       VerticalOptions="End" />
            </Grid>
        </DataTemplate>
        <controls:MonkeyDataTemplateSelector x:Key="MonkeySelector"
                                             AmericanMonkey="{StaticResource AmericanMonkeyTemplate}"
                                             OtherMonkey="{StaticResource OtherMonkeyTemplate}" />
    </ContentPage.Resources>

    <VerticalStackLayout>
        <CollectionView ItemTemplate="{StaticResource MonkeySelector}" ItemsSource="{Binding Monkeys}" />
    </VerticalStackLayout>
</ContentPage>