<UserControl x:Class="DatabaseEditor.Views.EditBookView"
             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 Source={StaticResource ViewModelLocator}, Path=EditBookViewModel}"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <TextBlock Text="Name:" />
        <TextBox Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2"
                 Text="{Binding ItemDetail.Name}" />

        <TextBlock Grid.Row="1" Grid.Column="0" Text="ISBN:" />
        <TextBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"
                 Text="{Binding ItemDetail.ISBN}" />
        
        <TextBlock Grid.Row="2" Grid.Column="0" Text="Pages:" />
        <TextBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2"
                 Text="{Binding ItemDetail.Pages}" />
        
        <TextBlock Grid.Row="3" Grid.Column="0" Text="Year:" />
        <TextBox Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2"
                 Text="{Binding ItemDetail.Year}" />

        <TextBlock Grid.Row="4" Grid.Column="0" Text="Authors:" />
        <StackPanel Grid.Row="4" Grid.Column="1">
            <ItemsControl ItemsSource="{Binding ItemDetail.Authors}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid VerticalAlignment="Center">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBlock HorizontalAlignment="Left"
                                       LineStackingStrategy="BlockLineHeight" >
                            <Run Text="{Binding Name}"/> <Run Text="{Binding Surname}"/>
                            </TextBlock>
                            <Button Grid.Column="1"
                                    Content="Remove"
                                    Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ItemsControl}, Path=DataContext.RemoveItemCommand}"
                                    CommandParameter="{Binding}" />
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
            <Button Content="Add author" Click="Button_Click" />
        </StackPanel>

        <Button Grid.Row="5" Grid.Column="1" Content="Cancel" IsCancel="True" Command="{Binding CancelCommand}" />
        <Button Grid.Row="5" Grid.Column="2" Content="Confirm" IsDefault="True" Command="{Binding ConfirmCommand}" />
    </Grid>
</UserControl>
