<?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"
             xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial"
             xmlns:vm="clr-namespace:GreadyPoang.CommandClasses"
             xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
             x:Class="GreadyPoang.Views.ParticipantListView"
             x:DataType="vm:ParticipantViewModelCommands"
             x:Name="ParticipantListPage"
             Title="Deltagar Lista">

    <Border Style="{StaticResource Border.Page}"  StrokeThickness="4">
        <Grid Style="{StaticResource Grid.Page}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <partial:HeaderView Grid.Row="0"    
                Grid.ColumnSpan="2"                
                ViewTitle="Deltagare"
                ViewDescription="Lägg till deltagare här" />
            <Border  Stroke="Gold" StrokeThickness="2" BackgroundColor="LemonChiffon" Grid.Row="1">
                <StackLayout Spacing="4"  >
                    <FlexLayout  Wrap="Wrap" >
                        <Label Style="{StaticResource Label}" 
                        Text="Deltagare Förnamn:" 
                        FontAttributes="Bold"/>
                        <Entry 
                        x:Name="ParticipantFirstNameEntry"
                        Placeholder="Förnamn"
                        Text="{Binding ParticipantObject.FirstName}" />

                        <Label Style="{StaticResource Label}" 
                        Text="Deltagare Efternamn:" 
                        FontAttributes="Bold"/>
                        <Entry 
                        x:Name="ParticipantLastNameEntry"
                        Placeholder="Efternamn"
                        Text="{Binding ParticipantObject.LastName}" />

                        <Label Style="{StaticResource Label}" 
                        Text="Deltagare Email:" 
                        FontAttributes="Bold"/>
                        <Entry 
                        x:Name="ParticipantEmailEntry"
                        Placeholder="Mail adress"
                        Text="{Binding ParticipantObject.Email}" />
                        <Button Style="{StaticResource HoverButtonBlueStyle}"
                        Text="Lägg till"
                        HorizontalOptions="End"
                        Command="{Binding SaveCommand}" />
                    </FlexLayout>
                </StackLayout>
            </Border>
            <Border Grid.Row="2" Stroke="Gold" BackgroundColor="Ivory" StrokeThickness="2" Padding="5">
                <CollectionView 
                            x:Name="participants"
                            SelectionMode="Single"
                            ItemsLayout="VerticalList"
                            ItemsSource="{Binding ParticipantList}"
                            ItemsUpdatingScrollMode="KeepLastItemInView">
                    <CollectionView.ItemTemplate>
                        <DataTemplate x:DataType="model:Participant">
                            <!--Stroke="DarkGray" BackgroundColor="Cornsilk"-->
                            <Border Margin="8" Padding="12" >
                                <VerticalStackLayout Spacing="4">
                                    <HorizontalStackLayout>
                                        <Label FontAttributes="Bold" 
                                           FontSize="Title"
                                               TextColor="CadetBlue"
                                           Text="{Binding LastNameFirstName}" />
                                    </HorizontalStackLayout>
                                    <HorizontalStackLayout>
                                        <Button  Text="Edit" Style="{StaticResource HoverButtonBlueStyle}" CommandParameter="{Binding EditCommand}"/>
                                        <Button  Style="{StaticResource HoverButtonRedStyle}" Text="Delete"  />
                                    </HorizontalStackLayout>
                                </VerticalStackLayout>
                            </Border>
                        </DataTemplate>
                    </CollectionView.ItemTemplate>
                </CollectionView>
            </Border>
        </Grid>
    </Border>
</ContentPage>