<?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:local="clr-namespace:Banquale.Views"
             xmlns:model="clr-namespace:Banquale.Model"
             x:Class="Banquale.Views.BalancePage"
             Title="BalancePage"
             Shell.NavBarIsVisible="False">
    
    <Grid RowDefinitions="auto, *">

        <Grid BackgroundColor="Beige"
              HorizontalOptions="Center"
              HeightRequest="100"
              MaximumHeightRequest="150"
              WidthRequest="230"
              RowDefinitions="auto, 35, *"
              ColumnDefinitions="250, auto"
              Grid.Row="0"
              Margin="30">

            <Grid.GestureRecognizers>
                <TapGestureRecognizer
                                  Tapped="Balance_Clicked"
                                  NumberOfTapsRequired="1" />
            </Grid.GestureRecognizers>

            <Label
                Text="Compte Professionnel"
                HorizontalOptions="Center"
                Margin="0, 15, 0, 0"/>

            <HorizontalStackLayout
                Grid.Row="1"
                HorizontalOptions="Center">

                <Label
                    Text="{Binding Name}"
                    Margin="0, 0, 5, 0"/>

                <Label
                    Text="{Binding FirstName}"
                    Margin="5, 0, 0, 0"/>

            </HorizontalStackLayout>

            <Grid ColumnDefinitions="auto, auto, auto"
                  Grid.Row="2"
                  HorizontalOptions="Center">

                <Label
                    Text="Solde"
                    Margin="0, 0, 50, 0"/>
                <Label
                    Text="{Binding Balance, StringFormat='{0} €'}"
                    Grid.Column="1"
                    Margin="50, 0, 5, 0"/>

            </Grid>
        </Grid>

        <ListView ItemsSource="{Binding TransactionsList}" Grid.Row="1"
                  SelectionMode="None">

            <ListView.ItemTemplate>

                <DataTemplate>

                    <ViewCell>

                        <Grid
                        ColumnDefinitions="40, 3*, *"
                        Margin="20, 5, 20, 5"
                        HorizontalOptions="Fill">

                        <Grid.GestureRecognizers>
                            <TapGestureRecognizer
                                Tapped="Transaction_Clicked"
                                NumberOfTapsRequired="1" />

                        </Grid.GestureRecognizers>

                            <Image Source="dotnet_bot.png"
                                   Grid.Column="0"
                                   MaximumHeightRequest="30"/>
                            <Label
                                    Text="{Binding Date, StringFormat='{0:ddd dd MMM yyyy}'}"
                                    Grid.Column="1"
                                    VerticalOptions="Center"
                                    Margin="10, 0, 0, 0"/>
                            <Label
                                    Text="{Binding Sum, StringFormat='{0} €'}"
                                    Grid.Column="2"
                                    VerticalOptions="Center"
                                    HorizontalOptions="End"
                                    Margin="0, 0, 20, 0"/>

                        </Grid>

                    </ViewCell>

                </DataTemplate>

            </ListView.ItemTemplate>

        </ListView>

    </Grid>
</ContentPage>
