<UserControl x:Class="DatabaseEditor.Views.BookDetailView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:DatabaseEditor.Views"
             DataContext="{Binding BookDetailViewModel, Source={StaticResource ViewModelLocator}}"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <TextBlock Grid.Row="0" Grid.Column="0">Name:</TextBlock>
        <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding ItemDetail.Name}" />
        
        <TextBlock Grid.Row="1" Grid.Column="0">Pages: </TextBlock>
        <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding ItemDetail.Pages}" />
        
        <TextBlock Grid.Row="2" Grid.Column="0">ISBN: </TextBlock>
        <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding ItemDetail.ISBN}" />
        
        <TextBlock Grid.Row="3" Grid.Column="0" Text="Authors:" />
        <ItemsControl Grid.Row="3" Grid.Column="1"
                      HorizontalAlignment="Left" Height="Auto"
                      ItemsSource="{Binding ItemDetail.Authors}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <TextBlock HorizontalAlignment="Left">
                        <Button
                            Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}, Path=DataContext.ShowRelatedItemCommand}"
                            CommandParameter="{Binding}"
                            Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
                            <Button.Content>
                                <TextBlock>
                                    <Run Text="{Binding Name}" /> <Run Text="{Binding Surname}" />
                                </TextBlock>
                            </Button.Content>
                        </Button>
                    </TextBlock>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
        <StackPanel Orientation="Horizontal" Grid.Row="4" Grid.Column="1" HorizontalAlignment="Right">
            <Button Content=" Edit " HorizontalAlignment="Right" VerticalAlignment="Bottom"
                    Command="{Binding EditCommand}" CommandParameter="{Binding ItemDetail}" />
            <Button Content="Delete" HorizontalAlignment="Right" VerticalAlignment="Bottom"
                    Command="{Binding DeleteCommand}" CommandParameter="{Binding ItemDetail}" />
        </StackPanel>
    </Grid>
</UserControl>