<UserControl x:Class="FModel.Views.Resources.Controls.CommitControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:converters="clr-namespace:FModel.Views.Resources.Converters"
             xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
             xmlns:controls="clr-namespace:FModel.Views.Resources.Controls">
    <Border BorderThickness="1" CornerRadius="0.5"
            BorderBrush="{DynamicResource {x:Static adonisUi:Brushes.Layer4BackgroundBrush}}">
        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Grid Grid.Column="0" Margin="5">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="5" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <TextBlock Grid.Row="0" Text="{Binding Commit.Message, Converter={x:Static converters:CommitMessageConverter.Instance}, ConverterParameter=Title}" FontWeight="Bold" TextWrapping="Wrap" />
                <TextBlock Grid.Row="1" Text="{Binding Commit.Message, Converter={x:Static converters:CommitMessageConverter.Instance}, ConverterParameter=Description}" TextWrapping="Wrap">
                    <TextBlock.Style>
                        <Style TargetType="TextBlock">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Commit.Message, Converter={x:Static converters:CommitMessageConverter.Instance}, ConverterParameter=Description}" Value="">
                                    <Setter Property="Visibility" Value="Collapsed"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                </TextBlock>

                <Grid Grid.Row="3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="5"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="5"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>

                    <ItemsControl Grid.Column="0" ItemsSource="{Binding Authors}">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Horizontal" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Ellipse Width="16" Height="16" Margin="0,0,2,0">
                                    <Ellipse.Fill>
                                        <ImageBrush ImageSource="{Binding AvatarUrl}" />
                                    </Ellipse.Fill>
                                </Ellipse>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                    <TextBlock Grid.Column="2" FontSize="11">
                        <TextBlock.Text>
                            <MultiBinding StringFormat="{}{0} committed {1}">
                                <Binding Path="AuthorNames" />
                                <Binding Path="Commit.Author.Date" Converter="{x:Static converters:RelativeDateTimeConverter.Instance}" />
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </Grid>
            </Grid>

            <Grid Grid.Column="1" MaxHeight="96">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="15" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <Border Grid.Column="0"
                        BorderThickness="1"
                        CornerRadius="2.5"
                        Padding="5,2"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center">
                    <TextBlock FontSize="9" Foreground="{Binding BorderBrush, RelativeSource={RelativeSource AncestorType=Border}}">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Asset.IsLatest}" Value="True">
                                        <Setter Property="Text" Value="Latest" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding IsCurrent}" Value="True">
                                        <Setter Property="Text" Value="Current" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>

                    <Border.Style>
                        <Style TargetType="Border">
                            <Setter Property="Visibility" Value="Collapsed" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Asset.IsLatest}" Value="True">
                                    <Setter Property="Visibility" Value="Visible" />
                                    <Setter Property="BorderBrush" Value="#3fb950" />
                                    <Setter Property="Background" Value="#0f3fb950" />
                                </DataTrigger>
                                <DataTrigger Binding="{Binding IsCurrent}" Value="True">
                                    <Setter Property="Visibility" Value="Visible" />
                                    <Setter Property="BorderBrush" Value="#3f92b9" />
                                    <Setter Property="Background" Value="#0f3f92b9" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Border.Style>
                </Border>

                <controls:CommitDownloaderControl Grid.Column="2" Commit="{Binding}">
                    <controls:CommitDownloaderControl.Style>
                        <Style TargetType="controls:CommitDownloaderControl">
                            <Setter Property="Visibility" Value="Collapsed" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsDownloadable}" Value="True">
                                    <Setter Property="Visibility" Value="Visible"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </controls:CommitDownloaderControl.Style>
                </controls:CommitDownloaderControl>
            </Grid>
        </Grid>
    </Border>
</UserControl>
