<?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:Gready_Poang.ViewsPartial"
             xmlns:vm="clr-namespace:Gready_Poang.CommandClasses"
             xmlns:model="clr-namespace:Gready_Poang.EntityLayer;assembly=Gready_Poang.EntityLayer"
             x:Class="Gready_Poang.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">
                <VerticalStackLayout Spacing="4"  >
                    <Label Style="{StaticResource Label}" 
                        Text="Deltagare " 
                        FontAttributes="Bold" FontSize="Large"/>
                    <Grid ColumnDefinitions="Auto,Auto,*" RowDefinitions="Auto,auto,auto,auto"
                          Padding="10" RowSpacing="8">
                        <Label Grid.Row="0" Grid.Column="0" Style="{StaticResource Label}" 
                            Text="Förnamn:" 
                            FontAttributes="Bold"/>
                        <Entry Grid.Row="0" Grid.Column="1"
                            x:Name="ParticipantFirstNameEntry"
                            Placeholder="Förnamn"
                                FontSize="15"
                            Text="{Binding ParticipantObject.FirstName}" TextColor="Black"/>
                        <Label Grid.Row="1" Grid.Column="0" Style="{StaticResource Label}" 
                            Text="Efternamn:" 
                            FontAttributes="Bold"/>
                        <Entry Grid.Row="1" Grid.Column="1"
                            x:Name="ParticipantLastNameEntry"
                            Placeholder="Efternamn"
                                FontSize="15"
                            Text="{Binding ParticipantObject.LastName}" TextColor="Black"/>
                        <Label Grid.Row="2" Grid.Column="0" Style="{StaticResource Label}" 
                            Text="Email" 
                            FontAttributes="Bold"/>
                        <Entry Grid.Row="2" Grid.Column="1"
                            x:Name="ParticipantEmailEntry"
                            Placeholder="Mail adress"
                                FontSize="15"
                            Text="{Binding ParticipantObject.Email}" TextColor="Black"/>
                        <Button Grid.Row="3" Grid.Column="1" Style="{StaticResource HoverButtonBlueStyle}"
                        Text="Lägg till"
                        HorizontalOptions="End"
                        Command="{Binding SaveCommand}" />
                    </Grid>
                </VerticalStackLayout>
            </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">
                                    <Label FontAttributes="Bold" 
                                           FontSize="Title"
                                           TextColor="CadetBlue"
                                           Text="{Binding LastNameFirstName}" />
                                    <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>