<?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="GameAtlas.Views.PageProfil"
             Title="PageProfil">

    <Grid x:Name="outerGrid" RowDefinitions="50,35,*" ColumnDefinitions="70,*,70" ColumnSpacing="15" RowSpacing="30" Padding="10,20,10,0">

        <Grid.Background>
            <LinearGradientBrush EndPoint="1,0">
                <GradientStop Color="#DFE4FF"
                          Offset="0.1" />
                <GradientStop Color="#FDF7E6"
                          Offset="1.0" />
            </LinearGradientBrush>
        </Grid.Background>

        <Grid RowDefinitions="50" ColumnDefinitions="50" HorizontalOptions="End" >
            <Frame Grid.Row="0" WidthRequest="50" HeightRequest="50" CornerRadius="25" VerticalOptions="Start" >
                <Frame.Background>
                    <LinearGradientBrush EndPoint="1,0">
                        <GradientStop Color="#C57CFF"
                                  Offset="0.1" />
                        <GradientStop Color="#8F00FF"
                                  Offset="1.0" />
                    </LinearGradientBrush>
                </Frame.Background>
                <Frame HeightRequest="48" WidthRequest="48" CornerRadius="24" VerticalOptions="Center" HorizontalOptions="Center" IsClippedToBounds="True">
                    <Image Source="default_user.png" Aspect="AspectFill"/>
                </Frame>
            </Frame>
        </Grid>

        <VerticalStackLayout Grid.Column="1" VerticalOptions="Center" Spacing="3">
            <Label Text="{Binding ConnectedUser.Pseudo}" FontSize="20" FontFamily="AladinRegular" TextColor="{StaticResource Black}"/>
            <Label FontSize="12" FontFamily="RobotoRegular" TextColor="{StaticResource Black}">
                <Label.FormattedText>
                    <FormattedString>
                        <Span Text="Compte créer le "/>
                        <Span Text="{Binding ConnectedUser.DateCreation}"/>
                    </FormattedString>
                </Label.FormattedText>
            </Label>
        </VerticalStackLayout>

        <Image Source="logout.png" Grid.Column="2">
            <Image.GestureRecognizers>
                <TapGestureRecognizer Tapped="OnDisconnect_Tapped"/>
            </Image.GestureRecognizers>
        </Image>

        <Grid Grid.Row="0" Grid.Column="2" RowDefinitions="50" ColumnDefinitions="50" HorizontalOptions="Start">
            <Frame IsVisible="{Binding ConnectedUser.EstAdmin}" WidthRequest="50" HeightRequest="50" CornerRadius="25" VerticalOptions="Start" IsClippedToBounds="True" BackgroundColor="{StaticResource Tertiary}">
                <Image Source="shieldperson" HeightRequest="40"/>

                <Frame.GestureRecognizers>
                    <TapGestureRecognizer Tapped="OnAdmin_Tapped"/>
                </Frame.GestureRecognizers>
            </Frame>
        </Grid>

        <Grid Grid.Row="1" Grid.ColumnSpan="3" RowDefinitions="35" ColumnDefinitions="*,1,*,1,*" Padding="30,0" Margin="0,0,0,0">
            
            <Label FontSize="12" FontFamily="RobotoRegular" TextColor="{StaticResource Black}" VerticalOptions="Center" HorizontalOptions="Center" HorizontalTextAlignment="Start" LineHeight="1.2">
                <Label.FormattedText>
                    <FormattedString>
                        <Span Text="{Binding ConnectedUser.ListeFavoris.Count}" />
                        <Span Text="&#x0a;Favoris" />
                    </FormattedString>
                </Label.FormattedText>
            </Label>

            <BoxView Grid.Column="1" Color="{StaticResource Black}" WidthRequest="1"/>

            <Label Grid.Column="2" FontSize="12" FontFamily="RobotoRegular" TextColor="{StaticResource Black}" VerticalOptions="Center" HorizontalOptions="Center" HorizontalTextAlignment="Start" LineHeight="1.2">
                <Label.FormattedText>
                    <FormattedString>
                        <Span Text="{Binding ConnectedUser.ListePossedes.Count}" />
                        <Span Text="&#x0a;Possédé" />
                    </FormattedString>
                </Label.FormattedText>
            </Label>
                        
            <BoxView Grid.Column="3" Color="{StaticResource Black}" WidthRequest="1"/>

            <Label Grid.Column="4" Text="0&#x0a;Avis" FontSize="12" FontFamily="RobotoRegular" TextColor="{StaticResource Black}" VerticalOptions="Center" HorizontalOptions="Center" HorizontalTextAlignment="Start" LineHeight="1.15"/>

        </Grid>

        <Border Grid.Row="2" Grid.ColumnSpan="3" StrokeShape="RoundRectangle 20,20,0,0" StrokeThickness="0" Margin="-10,0" BackgroundColor="{StaticResource Secondary}">
            <StackLayout Padding="30,12,30,0">

                <Label Text="Liste de profil" FontFamily="PTSansCBold" FontSize="24" TextColor="{StaticResource Black}" HorizontalOptions="Center"/>

                <Grid>
                    <CollectionView ItemsSource="{Binding ConnectedUser.ListeFavoris}" Margin="0,10,0,0" VerticalScrollBarVisibility="Never">
                        <CollectionView.ItemTemplate>
                            <DataTemplate>
                                <Border HeightRequest="97.5" StrokeShape="RoundRectangle 5" VerticalOptions="Start" HorizontalOptions="Center">
                                    <Border.Shadow>
                                        <Shadow Brush="Black" Offset="0,4" Radius="4" Opacity="0.4" />
                                    </Border.Shadow>
                                    <Frame HasShadow="False" HeightRequest="97.5" CornerRadius="5" IsClippedToBounds="True">
                                        <ImageButton HeightRequest="97.5" Source="{Binding Image}" Aspect="AspectFill" Clicked="OnGame_Tapped"/>
                                    </Frame>
                                </Border>
                            </DataTemplate>
                        </CollectionView.ItemTemplate>
                        <CollectionView.ItemsLayout>
                            <GridItemsLayout Span="2" Orientation="Vertical" VerticalItemSpacing="30" HorizontalItemSpacing="15"/>
                        </CollectionView.ItemsLayout>
                    </CollectionView>
                </Grid>

            </StackLayout>
        </Border>
    </Grid>

</ContentPage>
