<UserControl x:Class="GitHub.VisualStudio.Views.Documents.PullRequestPageView"
             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:ghfvs="https://github.com/github/VisualStudio"
             xmlns:local="clr-namespace:GitHub.VisualStudio.Views.Documents"
             xmlns:markdig="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf"
             xmlns:vsui="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.14.0"
             xmlns:v="clr-namespace:GitHub.VisualStudio.Views"
             xmlns:ui="clr-namespace:GitHub.UI;assembly=GitHub.UI"
             mc:Ignorable="d"  d:DesignHeight="1200" d:DesignWidth="800"
             MaxWidth="800">
    <d:DesignData.DataContext>
        <ghfvs:PullRequestPageViewModelDesigner/>
    </d:DesignData.DataContext>

    <Control.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ghfvs:SharedDictionaryManager Source="pack://application:,,,/GitHub.VisualStudio.UI;component/SharedDictionary.xaml" />
                <ghfvs:SharedDictionaryManager Source="pack://application:,,,/GitHub.UI;component/SharedDictionary.xaml" />
                <ghfvs:SharedDictionaryManager Source="pack://application:,,,/GitHub.UI.Reactive;component/SharedDictionary.xaml" />
                <ghfvs:SharedDictionaryManager Source="pack://application:,,,/GitHub.VisualStudio.UI;component/Styles/Markdown.xaml" />
                <StaticResource ResourceKey="ThemedDialogDefaultStylesKey"/>
            </ResourceDictionary.MergedDictionaries>

            <Style x:Key="Separator" TargetType="Rectangle">
                <Setter Property="Fill" Value="{DynamicResource GitHubHeaderSeparatorBrush}"/>
            </Style>
        </ResourceDictionary>
    </Control.Resources>
    <StackPanel Orientation="Vertical">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <TextBlock Margin="0 8"
                       Foreground="{DynamicResource VsBrush.WindowText}"
                       TextWrapping="Wrap"
                       Style="{DynamicResource {x:Static vsui:VsResourceKeys.TextBlockEnvironment200PercentFontSizeStyleKey}}">
                <Run Text="{Binding Title, Mode=OneWay}"/>
                <Hyperlink Command="{Binding OpenOnGitHub}">
                    (#<Run Text="{Binding Number, Mode=OneWay}"/>)
                </Hyperlink>
            </TextBlock>

            <StackPanel Grid.Row="1" Orientation="Horizontal">
                <TextBlock Foreground="{DynamicResource VsBrush.WindowText}">
                    <InlineUIContainer BaselineAlignment="Bottom">
                        <v:IssueishStateBadge DataContext="{Binding State}" Margin="0,0,0,-2"/>
                    </InlineUIContainer>
                    <InlineUIContainer BaselineAlignment="TextBottom">
                        <v:ActorAvatarView ViewModel="{Binding Author}" Width="14" Height="14"/>
                    </InlineUIContainer>
                    <TextBlock FontWeight="SemiBold" Text="{Binding Author.Login, Mode=OneWay}"/>
                    wants to merge
                    <TextBlock FontWeight="SemiBold" Text="{Binding CommitCount, Mode=OneWay, StringFormat={x:Static ghfvs:Resources.CommitCountFormat}}"/>
                    into
                    <InlineUIContainer BaselineAlignment="Bottom">
                        <Border CornerRadius="2" Padding="5 0" Background="{DynamicResource GitHubBranchNameBackgroundBrush}">
                            <TextBlock FontFamily="Consolas"
                                       
                                       TextTrimming="CharacterEllipsis"
                                       ToolTip="{Binding TargetBranchDisplayName, Mode=OneWay}"
                                       Text="{Binding TargetBranchDisplayName, Mode=OneWay}" />
                        </Border>
                    </InlineUIContainer>
                    from
                    <InlineUIContainer BaselineAlignment="TextBottom">
                        <Border CornerRadius="2" Padding="5 0" Background="{DynamicResource GitHubBranchNameBackgroundBrush}">
                            <TextBlock FontFamily="Consolas" TextTrimming="CharacterEllipsis" ToolTip="{Binding TargetBranchDisplayName, Mode=OneWay}" Text="{Binding SourceBranchDisplayName, Mode=OneWay}" />
                        </Border>
                    </InlineUIContainer>
                </TextBlock>
            </StackPanel>
        </Grid>

        <Rectangle DockPanel.Dock="Top" Style="{StaticResource Separator}" Height="2" Margin="0 24 0 16"/>

        <Grid Margin="0 4 0 0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="40" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <v:ActorAvatarView Width="35" 
                               Height="35"
                               VerticalAlignment="Top"
                               Margin="0 0 5 0"
                               ViewModel="{Binding Author}" />

            <Border BorderBrush="{DynamicResource GitHubHeaderSeparatorBrush}" BorderThickness="1" 
                    Grid.Column="1" VerticalAlignment="Top">
                <StackPanel Orientation="Vertical">
                    <Border Padding="6" Background="{DynamicResource GitHubBranchNameBackgroundBrush}" BorderBrush="{DynamicResource GitHubHeaderSeparatorBrush}" BorderThickness="0 0 0 1">
                        <StackPanel Orientation="Horizontal" DockPanel.Dock="Left" >
                            <TextBlock Foreground="{DynamicResource GitHubVsToolWindowText}" Margin="4">
                                <Run FontWeight="SemiBold" Text="{Binding Author.Login}" />
                                <Run Text="commented" />
                            </TextBlock>
                            <ui:GitHubActionLink Content="{Binding CreatedAt, Converter={ui:DurationToStringConverter}}"
                                             Command="{Binding OpenOnGitHub}"
                                             Foreground="{DynamicResource GitHubVsToolWindowText}"
                                             Opacity="0.75" />
                            <Border Background="{DynamicResource VsBrush.InfoBackground}"
                                    BorderBrush="{DynamicResource VsBrush.AccentPale}"
                                    BorderThickness="1"
                                    CornerRadius="3"
                                    Padding="2 1"
                                    Visibility="{Binding IsPending, Converter={ui:BooleanToVisibilityConverter}, FallbackValue=Collapsed}">
                                <TextBlock FontSize="10" Text="{x:Static ghfvs:Resources.Pending}" />
                            </Border>
                        </StackPanel>
                    </Border>

                    <markdig:MarkdownViewer Name="bodyMarkdown" Margin="8" Foreground="{DynamicResource VsBrush.WindowText}" Markdown="{Binding Body}"/>
                </StackPanel>
            </Border>
        </Grid>

        <ItemsControl Name="timeline" ItemsSource="{Binding Timeline}">
            <ItemsControl.Resources>
                <DataTemplate DataType="{x:Type ghfvs:CommentViewModelDesigner}">
                    <local:IssueishCommentView />
                </DataTemplate>
                <DataTemplate DataType="{x:Type ghfvs:CommitListViewModel}">
                    <local:CommitListView />
                </DataTemplate>
            </ItemsControl.Resources>
        </ItemsControl>
    </StackPanel>
</UserControl>
