<?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:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             xmlns:view="clr-namespace:LivreLand.View"
             xmlns:contentView="clr-namespace:LivreLand.View.ContentViews"
             xmlns:viewModel="clr-namespace:ViewModels;assembly=ViewModels"
             xmlns:model="clr-namespace:Model;assembly=Model"
             x:Class="LivreLand.View.DetailsLivreView"
             Title="DetailsLivreView">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="10"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <VerticalStackLayout Grid.Row="0">
            <view:HeaderPage HeaderTitle="Détails du livre"
                             HeaderBackButtonText="Tous"
                             HeaderPlusButtonVisible="False"
                             HeaderSwitchButtonVisible="False"
                             HeaderColor="{StaticResource HeaderGray}"
                             ButtonPlusTappedCommand="{Binding DetailsLivreVM.Navigator.PopupHomePlusNavigationCommand}"
                             ButtonBackTappedCommand="{Binding DetailsLivreVM.BackButtonCommand}"/>
            <contentView:SeparatorEntireView/>
        </VerticalStackLayout>

        <ScrollView Grid.Row="2">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="100"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>

                <VerticalStackLayout Grid.Row="0">
                    <!--Informations générales-->
                    <Grid Margin="10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto"/>
                            <ColumnDefinition Width="10"/>
                            <ColumnDefinition Width="auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>

                        <Grid Grid.Column="0"
                              Grid.RowSpan="3">
                            <Border Padding="-5,-5,-5,1"
                                    Margin="10,0,0,0"
                                    HeightRequest="100"
                                    WidthRequest="62"
                                    HorizontalOptions="Center"
                                    Stroke="{StaticResource Gray}"
                                    StrokeShape="RoundRectangle 3"
                                    StrokeThickness="3">
                                <Border HorizontalOptions="Center"
                                        Stroke="{StaticResource Gray}"
                                        StrokeShape="RoundRectangle 3"
                                        StrokeThickness="3">
                                    <Image Source="{Binding DetailsLivreVM.Book.ImageSmall}"
                                           Aspect="AspectFill"
                                           Grid.Column="0"
                                           Grid.RowSpan="5"/>
                                </Border>
                            </Border>
                            <Image Source="bookmark_red.png"
                                   HeightRequest="10"
                                   WidthRequest="10"
                                   Margin="0,97,20,0"
                                   VerticalOptions="End"/>
                        </Grid>
                        <Label Text="{Binding DetailsLivreVM.Book.Title}"
                               Grid.Column="2"
                               Grid.Row="0"/>
                        <contentView:StarNotationView Grid.Column="2"
                                                      Grid.Row="2"/>
                    </Grid>

                    <contentView:SeparatorCutStartView/>

                    <!--Informations en ligne-->
                    <Grid Margin="10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="auto"/>
                        </Grid.ColumnDefinitions>
                        <Label Text="Infos en ligne"
                               FontAttributes="Bold"
                               VerticalOptions="Center"
                               Grid.Column="0"/>
                        <Image Source="chevron_right.png"
                               MaximumHeightRequest="20"
                               MaximumWidthRequest="20"
                               Grid.Column="2">
                            <Image.Behaviors>
                                <toolkit:IconTintColorBehavior TintColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}"/>
                            </Image.Behaviors>
                        </Image>
                    </Grid>

                    <contentView:SeparatorCutStartView/>

                    <!--Auteur-->
                    <Grid Margin="10">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>

                        <Label Text="Auteur"
                               Style="{StaticResource DetailsLivreTitle}"
                               Grid.Row="0"/>
                        <CollectionView ItemsSource="{Binding DetailsLivreVM.Book.Authors}"
                                        Grid.Row="1">
                            <CollectionView.ItemsLayout>
                                <LinearItemsLayout Orientation="Horizontal" />
                            </CollectionView.ItemsLayout>
                            <CollectionView.ItemTemplate>
                                <DataTemplate x:DataType="viewModel:AuthorVM">
                                    <Label Text="{Binding Name}"
                                           Style="{StaticResource DetailsLivreBody}"
                                           Margin="0,0,1,0"
                                           Grid.Row="1"/>
                                </DataTemplate>
                            </CollectionView.ItemTemplate>
                        </CollectionView>
                    </Grid>

                    <contentView:SeparatorCutStartView/>

                    <!--Maison d'édition-->
                    <Grid Margin="10">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>

                        <Label Text="Maison d'édition"
                               Style="{StaticResource DetailsLivreTitle}"
                               Grid.Row="0"/>
                        <Grid Grid.Row="1">
                            <HorizontalStackLayout>
                                <CollectionView ItemsSource="{Binding DetailsLivreVM.Book.Publishers}"
                                                Grid.Column="0">
                                    <CollectionView.ItemsLayout>
                                        <LinearItemsLayout Orientation="Horizontal" />
                                    </CollectionView.ItemsLayout>
                                    <CollectionView.ItemTemplate>
                                        <DataTemplate>
                                            <Label Text="{Binding .}"
                                                   Style="{StaticResource DetailsLivreBody}"
                                                   Margin="0,0,1,0"
                                                   Grid.Row="1"/>
                                        </DataTemplate>
                                    </CollectionView.ItemTemplate>
                                </CollectionView>
                                <Label Text="{Binding DetailsLivreVM.Book.PublishDate,StringFormat=' ({0:yyyy})'}"
                                       Grid.Column="1"/>
                            </HorizontalStackLayout>
                        </Grid>
                    </Grid>

                    <contentView:SeparatorCutStartView/>

                    <!--Résumé-->
                    <Grid Margin="10">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>

                        <Label Text="Résumé"
                               Style="{StaticResource DetailsLivreTitle}"
                               Grid.Row="0"/>
                        <Label Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Et malesuada fames ac turpis egestas integer eget aliquet. Nunc sed id semper risus. Nisl purus in mollis nunc sed id semper risus. Egestas congue quisque egestas diam in arcu cursus euismod. Elementum integer enim neque volutpat ac tincidunt vitae. Amet luctus venenatis lectus magna fringilla urna porttitor rhoncus dolor. Sollicitudin tempor id eu nisl nunc. Eget mauris pharetra et ultrices neque. In vitae turpis massa sed elementum tempus. Posuere ac ut consequat semper viverra nam. Quisque non tellus orci ac auctor augue mauris augue. Cursus in hac habitasse platea dictumst. Pellentesque diam volutpat commodo sed egestas egestas fringilla phasellus faucibus. Vel fringilla est ullamcorper eget nulla facilisi etiam."
                               Style="{StaticResource DetailsLivreBody}"
                               Grid.Row="1"/>
                    </Grid>

                    <contentView:SeparatorCutStartView/>

                    <!--Détails-->
                    <Grid Margin="10">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>

                        <Label Text="Détails"
                               Style="{StaticResource DetailsLivreTitle}"
                               Grid.Row="0"/>
                        <Grid Grid.Row="1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>

                            <Label Text="Nombre de pages"
                                   Style="{StaticResource DetailsLivreBody}"
                                   Grid.Column="0"/>
                            <Label Text="{Binding DetailsLivreVM.Book.NbPages}"
                                   Style="{StaticResource DetailsLivreBody}"
                                   Grid.Column="2"/>
                        </Grid>
                        <Grid Grid.Row="2">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>

                            <Label Text="Langue"
                                   Style="{StaticResource DetailsLivreBody}"
                                   Grid.Column="0"/>
                            <Label Text="{Binding DetailsLivreVM.Book.Language}"
                                   Style="{StaticResource DetailsLivreBody}"
                                   Grid.Column="2"/>
                        </Grid>
                        <Grid Grid.Row="3">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>

                            <Label Text="ISBN"
                                   Style="{StaticResource DetailsLivreBody}"
                                   Grid.Column="0"/>
                            <Label Text="{Binding DetailsLivreVM.Book.ISBN13}"
                                   Style="{StaticResource DetailsLivreBody}"
                                   Grid.Column="2"/>
                        </Grid>
                    </Grid>

                    <contentView:SeparatorCutStartView/>

                    <!--Statut de lecture-->
                    <Grid Margin="10">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>

                        <Label Text="Statut de lecture"
                               Style="{StaticResource DetailsLivreTitle}"
                               Grid.Row="0"/>
                        <Grid Grid.Row="1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>

                            <Label Text="Statut"
                                   Style="{StaticResource DetailsLivreBody}"
                                   Grid.Column="0"/>
                            <Label Text="{Binding DetailsLivreVM.Book.Status}"
                                   Style="{StaticResource DetailsLivreBody}"
                                   Grid.Column="2"/>
                        </Grid>
                    </Grid>
                    
                    <contentView:SeparatorCutStartView/>

                    <!--Bibliothèque-->
                    <Grid Margin="10">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>

                        <Label Text="Bibliothèque"
                               Style="{StaticResource DetailsLivreTitle}"
                               Grid.Row="0"/>
                        <Grid Grid.Row="1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>

                            <Label Text="Ajouté le"
                                   Style="{StaticResource DetailsLivreBody}"
                                   Grid.Column="0"/>
                            <Label Text="10 août 2023"
                                   Style="{StaticResource DetailsLivreBody}"
                                   Grid.Column="2"/>
                        </Grid>
                    </Grid>

                    <contentView:SeparatorCutStartView/>

                </VerticalStackLayout>
                
                <!--Buttons-->
                <VerticalStackLayout Grid.Row="2">

                    <contentView:SeparatorCutStartView/>

                    <contentView:DetailsLivreButtonView ButtonIcon="heart.png"
                                                        ButtonTitle="{Binding DetailsLivreVM.AddFavorisButtonText}"
                                                        ButtonCommand="{Binding DetailsLivreVM.AddRemoveBookToFavoritesCommand}"
                                                        ButtonCommandParameter="{Binding DetailsLivreVM.Book}"/>

                    <contentView:SeparatorCutStartView/>

                    <contentView:DetailsLivreButtonView ButtonIcon="folder.png"
                                                        ButtonTitle="Déplacer le livre"/>

                    <contentView:SeparatorCutStartView/>

                    <contentView:DetailsLivreButtonView ButtonIcon="rounded_plus.png"
                                                        ButtonTitle="Ajouter à la liste À lire plus tard"
                                                        ButtonCommand="{Binding DetailsLivreVM.AddBookToReadListCommand}"
                                                        ButtonCommandParameter="{Binding DetailsLivreVM.Book}"/>

                    <contentView:SeparatorCutStartView/>

                    <contentView:DetailsLivreButtonView ButtonIcon="eyeglasses.png"
                                                        ButtonTitle="Changer le statut de lecture"
                                                        ButtonCommand="{Binding DetailsLivreVM.ShowPickerCommand}"/>

                    <contentView:SeparatorCutStartView/>

                    <contentView:DetailsLivreButtonView ButtonIcon="person.png"
                                                        ButtonTitle="Prêter le livre"
                                                        ButtonCommand="{Binding DetailsLivreVM.LoanBookCommand}"
                                                        ButtonCommandParameter="{Binding DetailsLivreVM.Book}"/>

                    <contentView:SeparatorCutStartView/>

                    <contentView:DetailsLivreButtonView ButtonTitle="Supprimer le livre"
                                                        ButtonCommand="{Binding DetailsLivreVM.RemoveBookCommand}"
                                                        ButtonCommandParameter="{Binding DetailsLivreVM.Book}"/>

                </VerticalStackLayout>

                <Picker ItemsSource="{Binding DetailsLivreVM.Manager.AllStatus}"
                        SelectedItem="{Binding DetailsLivreVM.Manager.SelectedStatus}"
                        IsVisible="{Binding DetailsLivreVM.IsPickerVisible}"
                        Grid.RowSpan="3"
                        HorizontalOptions="Center"
                        VerticalOptions="Center">
                    <Picker.Behaviors>
                        <toolkit:EventToCommandBehavior EventName="SelectedIndexChanged"
                                                        Command="{Binding DetailsLivreVM.Manager.UpdateStatusBookCommand}"
                                                        CommandParameter="{Binding DetailsLivreVM.Book}"/>
                    </Picker.Behaviors>
                </Picker>

            </Grid>
        </ScrollView>
    </Grid>
</ContentPage>