<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Trek_12.Views.PageBoard"
             Title="Board"
             BackgroundColor="Bisque">

    <Grid RowDefinitions="*,auto" ColumnDefinitions="auto,*,auto">
        <Frame BorderColor="DarkGray"
               HeightRequest="50"
               WidthRequest="50"
               Grid.Column="0"
               HorizontalOptions="Center"
               VerticalOptions="Center"
               Padding="0">
            <Label Text="{Binding ThePartie.Dice1.Value}"
                   FontSize="16"
                   VerticalOptions="Center"
                   HorizontalOptions="Center"
                   TextColor="Black"
                   />
        </Frame>
        <Image Source="maptest.png" Aspect="AspectFit" Grid.ColumnSpan="2" Grid.RowSpan="3"/>

        <CollectionView ItemsSource="{Binding ListMap[0].Boards}"
                            Grid.Row="1"
                            Grid.Column="1"
                            SelectionMode="Single"
                            WidthRequest="350"
                            HeightRequest="350"
                            ItemsLayout="VerticalGrid,7"
                            BackgroundColor="Aqua">
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Grid VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="50" WidthRequest="50">

                        <Frame
                            IsVisible="{Binding Valid}"
                            BorderColor="DarkGray"
                            CornerRadius="25"
                            HeightRequest="50"
                            WidthRequest="50"
                            BackgroundColor="White"
                            Opacity="0.7"
                            VerticalOptions="Center"
                            HorizontalOptions="Center"
                            Padding="0">
                            <Frame.Triggers>
                                <DataTrigger TargetType="Frame" Binding="{Binding IsDangerous}" Value="True">
                                    <Setter Property="BorderColor" Value="Black"/>
                                </DataTrigger>
                                <DataTrigger TargetType="Frame" Binding="{Binding IsDangerous}" Value="False">
                                    <Setter Property="BorderColor" Value="Transparent"/>
                                </DataTrigger>
                            </Frame.Triggers>
                        </Frame>
                    </Grid>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>

        <!-- Operation Grid -->
        <CollectionView Grid.Row="0" Grid.Column="2"
                            ItemsSource="{Binding ListMap[0].OperationGrid}"
                            ItemsLayout="VerticalGrid,4"
                            WidthRequest="200"
                            HeightRequest="250"
                            BackgroundColor="Transparent"
                            SelectionChanged="OnOperationCellSelected"
                            Margin="50">
            <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <Frame HasShadow="True"
                               BorderColor="Black"
                               BackgroundColor="Transparent"
                               CornerRadius="0"
                               HorizontalOptions="Center"
                               VerticalOptions="Center"
                               HeightRequest="50"
                               WidthRequest="50"
                               Padding="0">
                            <Image Source="checked.png"
                                   IsVisible="{Binding IsChecked}"
                                   HorizontalOptions="Center"
                                   VerticalOptions="Center"/>
                        </Frame>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>
    </Grid>
</ContentPage>