<UserControl x:Class="GitHub.VisualStudio.Views.GitHubPane.PullRequestFilesView"
             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.GitHubPane"
             xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"
             xmlns:catalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog"
             xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.14.0"
             mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"
             Name="root">

    <d:DesignProperties.DataContext>
        <ghfvs:PullRequestFilesViewModelDesigner/>
    </d:DesignProperties.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>

            <ContextMenu x:Key="FileContextMenu">
                <MenuItem Header="{x:Static ghfvs:Resources.ViewChanges}" Command="{Binding DiffFile}"/>
                <MenuItem Header="{x:Static ghfvs:Resources.ViewFile}" Command="{Binding ViewFile}"/>
                <MenuItem Header="{x:Static ghfvs:Resources.ViewChangesInSolution}" Command="{Binding DiffFileWithWorkingDirectory}"/>
                <MenuItem Header="{x:Static ghfvs:Resources.OpenFileInSolution}" Command="{Binding OpenFileInWorkingDirectory}"/>
            </ContextMenu>
        </ResourceDictionary>
    </Control.Resources>

    <TreeView Name="changesTree"
              ItemsSource="{Binding Items}"
              ContextMenu="{StaticResource FileContextMenu}"
              Background="Transparent"
              BorderThickness="0"
              Margin="0 6 0 0"
              ContextMenuOpening="changesTree_ContextMenuOpening"
              KeyUp="changesTree_KeyUp"
              MouseDoubleClick="changesTree_MouseDoubleClick"
              MouseRightButtonDown="changesTree_MouseRightButtonDown">
        <TreeView.ItemContainerStyle>
            <Style TargetType="TreeViewItem" BasedOn="{StaticResource {x:Type TreeViewItem}}">
                <Setter Property="IsExpanded" Value="True"/>
            </Style>
        </TreeView.ItemContainerStyle>
        <TreeView.Resources>
            <local:DirectoryIsExpandedToImageMonikerConverter x:Key="DirectoryIsExpandedToImageMonikerConverter" />
            <local:FileNameToImageMonikerConverter x:Key="FileNameToImageMonikerConverter" />

            <HierarchicalDataTemplate DataType="{x:Type ghfvs:PullRequestDirectoryNode}"
                                      ItemsSource="{Binding Children}">
                <StackPanel Orientation="Horizontal">
                    <imaging:CrispImage Moniker="{Binding Converter={StaticResource DirectoryIsExpandedToImageMonikerConverter}, RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}, Path=IsExpanded}"
                                        Width="16" Height="16" Margin="0,0,0,2"/>
                    <TextBlock Text="{Binding DirectoryName}" Margin="4 2" VerticalAlignment="Center"/>
                </StackPanel>
            </HierarchicalDataTemplate>

            <DataTemplate DataType="{x:Type ghfvs:PullRequestFileNode}">
                <StackPanel Orientation="Horizontal"
                            Tag="{Binding DataContext, ElementName=root}"
                            KeyboardNavigation.DirectionalNavigation="None">

                    <imaging:CrispImage Moniker="{Binding Converter={StaticResource FileNameToImageMonikerConverter}, Path=FileName}"
                                        Width="16" Height="16" Margin="0,2"/>

                    <TextBlock Text="{Binding FileName}" Margin="4 2" VerticalAlignment="Center">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Status}" Value="Removed">
                                        <Setter Property="TextDecorations" Value="Strikethrough"/>
                                    </DataTrigger>
                                    <MultiDataTrigger>
                                        <MultiDataTrigger.Conditions>
                                            <Condition Binding="{Binding Status}" Value="Removed"/>
                                            <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}, Path=IsSelected}" Value="False"/>
                                        </MultiDataTrigger.Conditions>
                                        <Setter Property="Foreground" Value="{DynamicResource GitHubDeletedFileBrush}"/>
                                    </MultiDataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>

                    <TextBlock Text="{Binding StatusDisplay, StringFormat=[{0}]}" VerticalAlignment="Center" Opacity="0.5">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding StatusDisplay}" Value="{x:Null}">
                                        <Setter Property="Visibility" Value="Collapsed"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>

                    <TextBlock VerticalAlignment="Center" Margin="4 0">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding AnnotationNoticeCount}" Value="0">
                                        <Setter Property="Visibility" Value="Collapsed"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                        <imaging:CrispImage Width="10" Height="10" 
                                            Moniker="{x:Static catalog:KnownMonikers.StatusInformation}" Margin="-2 0" />
                        <Hyperlink Command="{Binding DataContext.OpenFirstAnnotationNotice, ElementName=root}"
                                   CommandParameter="{Binding}">
                            <Run Text="{Binding AnnotationNoticeCount, Mode=OneWay}"/>
                        </Hyperlink>
                    </TextBlock>

                    <TextBlock VerticalAlignment="Center" Margin="4 0">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding AnnotationWarningCount}" Value="0">
                                        <Setter Property="Visibility" Value="Collapsed"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                        <imaging:CrispImage Width="10" Height="10" 
                                            Moniker="{x:Static catalog:KnownMonikers.StatusWarning}" Margin="-2 0"/>
                        <Hyperlink Command="{Binding DataContext.OpenFirstAnnotationWarning, ElementName=root}"
                                   CommandParameter="{Binding}">
                            <Run Text="{Binding AnnotationWarningCount, Mode=OneWay}"/>
                        </Hyperlink>
                    </TextBlock>

                    <TextBlock VerticalAlignment="Center" Margin="4 0">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding AnnotationFailureCount}" Value="0">
                                        <Setter Property="Visibility" Value="Collapsed"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                        <imaging:CrispImage Width="10" Height="10" 
                                            Moniker="{x:Static catalog:KnownMonikers.StatusError}" Margin="-2 0" />
                        <Hyperlink Command="{Binding DataContext.OpenFirstAnnotationFailure, ElementName=root}"
                                   CommandParameter="{Binding}">
                            <Run Text="{Binding AnnotationFailureCount, Mode=OneWay}"/>
                        </Hyperlink>
                    </TextBlock>

                    <TextBlock VerticalAlignment="Center" Margin="4 0">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding CommentCount}" Value="0">
                                        <Setter Property="Visibility" Value="Collapsed"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                        <ghfvs:OcticonImage Icon="comment_discussion" Height="10" Margin="-2 0"/>
                        <Hyperlink Command="{Binding DataContext.OpenFirstComment, ElementName=root}"
                                   CommandParameter="{Binding}"
                                   Style="{StaticResource {x:Static vsfx:VsResourceKeys.ThemedDialogHyperlinkStyleKey}}">
                            <Run Text="{Binding CommentCount, Mode=OneWay}"/>
                        </Hyperlink>
                    </TextBlock>
                </StackPanel>
            </DataTemplate>
        </TreeView.Resources>
    </TreeView>
</UserControl>
