<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:core="clr-namespace:NuGet;assembly=NuGet.Core"
    xmlns:gl="clr-namespace:System.Globalization;assembly=mscorlib"
    xmlns:self="clr-namespace:NuGet.Dialog.PackageManagerUI;assembly=NuGet.DialogServices"
    xmlns:resources="clr-namespace:NuGet.Dialog;assembly=NuGet.DialogServices">
    
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="TemplateStyles.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <self:DescriptionLabelConverter x:Key="DescriptionLabelConverter" />
    <self:NormalizeTextConverter x:Key="NormalizeTextConverter" />
    <self:FixUrlConverter x:Key="urlConverter" />
    <self:BooleanToVisibilityConverter Inverted="True" x:Key="invertedBoolToVis" />
    <self:BooleanToVisibilityConverter x:Key="boolToVis" />
    <self:CountToVisibilityConverter x:Key="countConverter" />
    <self:CountToVisibilityConverter Inverted="True" x:Key="invertedCountConverter" />
    <self:ProjectToDisplayNameConverter x:Key="ProjectToNameConverter" />
    <self:MultiNullToVisibilityConverter x:Key="multiNullToVisibilityConverter" />
    <BitmapImage x:Key="BitmapImage_AlreadyInstalled" UriSource="pack://application:,,,/Microsoft.VisualStudio.ExtensionManager.Implementation;Component/UI/AlreadyInstalled.png" />
    
    <DataTemplate DataType="{x:Type core:PackageDependency}">
        <TextBlock Text="{Binding}" TextWrapping="Wrap" />
    </DataTemplate>

    <DataTemplate DataType="{x:Type core:PackageDependencySet}">
        <Grid Margin="0,0,0,8">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <TextBlock Text="{Binding TargetFramework, TargetNullValue={x:Static resources:Resources.NoFxDependencyGroup}}" FontWeight="SemiBold" TextWrapping="Wrap" />
            <ItemsControl
                x:Name="dependenciesList"
                Grid.Row="1"
                Margin="20,0,0,0"
                ItemsSource="{Binding Dependencies}" />
                
            <self:TextBlockControl
                Grid.Row="1"
                Margin="20,0,0,0"
                Visibility="{Binding Items.Count, ElementName=dependenciesList, Converter={StaticResource invertedCountConverter}}"
                Style="{StaticResource NoDependencyTextBoxStyle}" 
                Text="{x:Static resources:Resources.Dialog_NoDependencyLabel}">
            </self:TextBlockControl>
        </Grid>
    </DataTemplate>

    <Style x:Key="DescriptionLabelStyle" BasedOn="{StaticResource DetailMetadataLabelStyle}" TargetType="{x:Type self:TextBlockControl}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsUpdateItem, Mode=OneTime}" Value="true">
                <Setter Property="Text" Value="{Binding PackageIdentity.ReleaseNotes, Mode=OneTime, Converter={StaticResource DescriptionLabelConverter}}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding IsUpdateItem, Mode=OneTime}" Value="false">
                <Setter Property="Text" Value="{x:Static resources:Resources.Dialog_DescriptionLabel}" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="TileImageStyle" TargetType="{x:Type Image}">
        <Setter Property="Height" Value="32" />
        <Setter Property="Width" Value="32" />
        <Setter Property="HorizontalAlignment" Value="Center" />
        <Setter Property="StretchDirection" Value="DownOnly" />
        <Setter Property="Stretch" Value="Fill" />
        <Style.Triggers>
            <EventTrigger RoutedEvent="ImageFailed">
                <BeginStoryboard>
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Source" FillBehavior="HoldEnd">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{StaticResource BitmapImage_DefaultIcon}">
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Style.Triggers>
    </Style>

    <!-- data template for the package extension item -->
    <DataTemplate x:Key="PackageItemTemplate">
        <Grid Style="{StaticResource TileTemplateGridStyle}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" MinWidth="38" SharedSizeGroup="IconColumn" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <StackPanel Orientation="Vertical" Margin="0,3,0,0">
                <Image Style="{StaticResource TileImageStyle}" Source="{Binding PackageIdentity.IconUrl, Converter={StaticResource urlConverter}, TargetNullValue={StaticResource BitmapImage_DefaultIcon}}">
                </Image>

                <TextBlock 
                    Text="{x:Static resources:Resources.Dialog_PackagePrereleaseLabel}"
                    FontStyle="Italic"
                    FontSize="9"
                    Margin="0,4"
                    HorizontalAlignment="Center"
                    Visibility="{Binding IsPrerelease, Converter={StaticResource boolToVis}}" />
            </StackPanel>

            <StackPanel Grid.Column="1" Style="{StaticResource TileMiddleStackPanelStyle}">
                <self:TextBlockControl  
                    Text="{Binding Name}" 
                    Style="{StaticResource TileTitleTextBoxStyle}">
                    <TextBlock.ToolTip>
                        <TextBlock Text="{Binding Name}" Style="{StaticResource TileToolTipStyle}"/>
                    </TextBlock.ToolTip>
                </self:TextBlockControl>

                <self:TextBlockControl
                    x:Name="SummaryText"
                    Text="{Binding Summary, Converter={StaticResource NormalizeTextConverter}}" 
                    Style="{StaticResource TileDescriptionTextBoxStyle}">
                    <self:TextBlockControl.ToolTip>
                        <TextBlock Text="{Binding Summary, Converter={StaticResource NormalizeTextConverter}}" Style="{StaticResource TileToolTipStyle}"/>
                    </self:TextBlockControl.ToolTip>
                </self:TextBlockControl>
            </StackPanel>
            
            <StackPanel 
                Grid.Column="2"
                Style="{StaticResource TileRightStackPanelStyle}"
                Visibility="Visible">
                <Image
                    HorizontalAlignment="Right"
                    Source="{StaticResource BitmapImage_AlreadyInstalled}"
                    Visibility="{Binding IsEnabled, Mode=OneWay, Converter={StaticResource invertedBoolToVis}}">
                    <Image.ToolTip>
                        <TextBlock 
                            Text="{x:Static resources:Resources.Dialog_PackageInstalledTooltip}"
                            Style="{StaticResource TileToolTipStyle}"/>
                    </Image.ToolTip>
                </Image>
                <Button 
                    x:Name="ExecuteButton"
                    Command="{x:Static self:PackageManagerWindowCommands.PackageOperationCommand}"
                    Content="{Binding CommandName}"
                    IsDefault="False"
                    Visibility="Collapsed"
                    Style="{StaticResource DetailButtonStyle}" />
            </StackPanel>
        </Grid>
        
        <DataTemplate.Triggers>
            <MultiDataTrigger >
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding IsSelected}" Value="True" />
                    <Condition Binding="{Binding IsEnabled}" Value="True" />
                </MultiDataTrigger.Conditions>
                <Setter TargetName="ExecuteButton" Property="Visibility" Value="Visible" />
            </MultiDataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
    
    <!-- data template for the package details pane -->
    <DataTemplate x:Key="PackageDetailTemplate">
        <DataTemplate.Resources>
            <self:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
            <self:StringCollectionsToStringConverter x:Key="authorNamesConverter" />
            <self:DateTimeOffsetToLocalConverter x:Key="dateTimeOffsetToLocalConverter" />
        </DataTemplate.Resources>
        
        <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" Focusable="False">                
            <StackPanel Margin="8">                
                <!-- Authors -->
                <DockPanel>
                    <self:TextBlockControl DockPanel.Dock="Left" Text="{x:Static resources:Resources.Dialog_CreatedByLabel}" Style="{StaticResource DetailMetadataLabelStyle}" />
                    <self:TextBlockControl Text="{Binding Authors, Converter={StaticResource authorNamesConverter}}" Style="{StaticResource DetailMetadataValueStyle}" TextWrapping="Wrap" ToolTip="{Binding Path=Text, RelativeSource={RelativeSource Self}}" />
                </DockPanel>

                <!-- Id -->
                <StackPanel Style="{StaticResource DetailMetadataStyle}">
                    <self:TextBlockControl Text="{x:Static resources:Resources.Dialog_IdLabel}" Style="{StaticResource DetailMetadataLabelStyle}" />
                    <self:TextBlockControl x:Name="IdTextBlock" ToolTip="{Binding PackageIdentity.GalleryDetailsUrl, Mode=OneTime, FallbackValue={x:Null}}" Style="{StaticResource DetailMetadataValueStyle}">
                        <Hyperlink AutomationProperties.AutomationId="IdLink" Style="{StaticResource CommonHyperlinkStyle}" NavigateUri="{Binding PackageIdentity.GalleryDetailsUrl, Mode=OneTime, FallbackValue={x:Null}}" Command="{x:Static self:PackageManagerWindowCommands.OpenExternalLink}">
                            <Run Text="{Binding Id, Mode=OneWay}" />
                        </Hyperlink>
                    </self:TextBlockControl>
                    <self:TextBlockControl x:Name="IdTextOnlyBlock" Text="{Binding Id, Mode=OneWay}" Style="{StaticResource DetailMetadataValueStyle}" Visibility="Collapsed" ToolTip="{Binding Path=Text, RelativeSource={RelativeSource Self}}" />
                </StackPanel>

                <!-- Version -->
                <StackPanel Style="{StaticResource DetailMetadataStyle}">
                    <self:TextBlockControl Text="{x:Static resources:Resources.Dialog_VersionLabel}" Style="{StaticResource DetailMetadataLabelStyle}" />
                    <self:TextBlockControl AutomationProperties.AutomationId="VersionText" Text="{Binding Version, Mode=OneWay}" Style="{StaticResource DetailMetadataValueStyle}" ToolTip="{Binding Path=Text, RelativeSource={RelativeSource Self}}" />
                    <self:TextBlockControl AutomationProperties.AutomationId="PrereleaseText" Margin="3,0,0,0" Text="{Binding Mode=OneWay, Source={x:Static resources:Resources.Dialog_PackagePrereleaseLabel}, StringFormat='({0})'}" Visibility="{Binding IsPrerelease, Converter={StaticResource boolToVis}}" ToolTip="{Binding Path=Text, RelativeSource={RelativeSource Self}}" />
                </StackPanel>

                <!-- Current Version -->
                <StackPanel Style="{StaticResource DetailMetadataStyle}" Visibility="{Binding OldVersion, Converter={StaticResource NullToVisibilityConverter}}">
                    <self:TextBlockControl Text="{x:Static resources:Resources.Dialog_CurrentVersionLabel}" Style="{StaticResource DetailMetadataLabelStyle}" />
                    <self:TextBlockControl AutomationProperties.AutomationId="CurrentVersionText" Text="{Binding OldVersion, Mode=OneWay}" Style="{StaticResource DetailMetadataValueStyle}" ToolTip="{Binding Path=Text, RelativeSource={RelativeSource Self}}" />
                </StackPanel>

                <!-- Last Published -->
                <StackPanel Style="{StaticResource DetailMetadataStyle}" Visibility="{Binding PackageIdentity.Published, Converter={StaticResource NullToVisibilityConverter}, FallbackValue=Collapsed}">
                    <self:TextBlockControl Text="{x:Static resources:Resources.Dialog_LastPublishedLabel}" Style="{StaticResource DetailMetadataLabelStyle}" />
                    <self:TextBlockControl AutomationProperties.AutomationId="LastPublishedDate" Text="{Binding PackageIdentity.Published, Converter={StaticResource dateTimeOffsetToLocalConverter}, Mode=OneWay, StringFormat='{}{0:d}', ConverterCulture={x:Static gl:CultureInfo.CurrentCulture}}" Style="{StaticResource DetailMetadataValueStyle}" ToolTip="{Binding Path=Text, RelativeSource={RelativeSource Self}}" />
                </StackPanel>

                <!-- Download count -->
                <StackPanel Style="{StaticResource DetailMetadataStyle}" Visibility="{Binding PackageIdentity.DownloadCount, Converter={StaticResource countConverter}, ConverterParameter=-1}">
                    <self:TextBlockControl Text="{x:Static resources:Resources.Dialog_DownloadsLabel}" Style="{StaticResource DetailMetadataLabelStyle}" />
                    <self:TextBlockControl  AutomationProperties.AutomationId="DownloadCount" Text="{Binding PackageIdentity.DownloadCount}" Style="{StaticResource DetailMetadataValueStyle}" ToolTip="{Binding Path=Text, RelativeSource={RelativeSource Self}}" />
                </StackPanel>

                <!-- License header -->
                <self:TextBlockControl Margin="0,5,0,0" AutomationProperties.AutomationId="LicenseHeader" Text="{x:Static resources:Resources.License_Header}" Style="{StaticResource DetailMetadataLabelStyle}">
                    <self:TextBlockControl.Visibility>
                        <MultiBinding Converter="{StaticResource multiNullToVisibilityConverter}">
                            <Binding Path="LicenseUrl" Converter="{StaticResource urlConverter}" />
                            <Binding Path="PackageIdentity.LicenseNames" />
                            <Binding Path="PackageIdentity.LicenseReportUrl" Converter="{StaticResource urlConverter}" />
                        </MultiBinding>
                    </self:TextBlockControl.Visibility>
                </self:TextBlockControl>

                <!-- View License Url -->
                <TextBlock Margin="25,5,0,0" AutomationProperties.AutomationId="LicenseLinkContainer" ToolTip="{Binding LicenseUrl, Mode=OneTime}" Visibility="{Binding LicenseUrl, Converter={StaticResource urlConverter}}">
                    <Hyperlink AutomationProperties.AutomationId="LicenseLink" Style="{StaticResource CommonHyperlinkStyle}" NavigateUri="{Binding LicenseUrl, Mode=OneTime}" Command="{x:Static self:PackageManagerWindowCommands.OpenExternalLink}">
                        <Run Text="{x:Static resources:Resources.License_ViewLicense}" />
                    </Hyperlink>
                </TextBlock>

                <!-- License Friendly names -->
                <ItemsControl
                    Margin="25,5,0,0"
                    Visibility="{Binding PackageIdentity.LicenseNames, Converter={StaticResource NullToVisibilityConverter}, FallbackValue=Collapsed}"
                    ItemsSource="{Binding PackageIdentity.LicenseNameCollection}" />

                <!-- Component report link -->
                <TextBlock Margin="25,5,0,0" AutomationProperties.AutomationId="ComponentLicenseLinkContainer" Visibility="{Binding PackageIdentity.LicenseReportUrl, Converter={StaticResource urlConverter}, FallbackValue=Collapsed}">
                    <Hyperlink AutomationProperties.AutomationId="ComponentLicenseLink" Style="{StaticResource CommonHyperlinkStyle}" NavigateUri="{Binding PackageIdentity.LicenseReportUrl, Mode=OneTime}" Command="{x:Static self:PackageManagerWindowCommands.OpenExternalLink}">
                        <Run Text="{x:Static resources:Resources.License_ViewLicenseReport}" />
                    </Hyperlink>
                </TextBlock>

                <!-- Project Url -->
                <TextBlock AutomationProperties.AutomationId="ProjectInfoLinkContainer" ToolTip="{Binding PackageIdentity.ProjectUrl, Mode=OneTime}" Visibility="{Binding PackageIdentity.ProjectUrl, Converter={StaticResource urlConverter}}">
                    <Hyperlink AutomationProperties.AutomationId="ProjectInfoLink" Style="{StaticResource CommonHyperlinkStyle}" NavigateUri="{Binding PackageIdentity.ProjectUrl, Mode=OneTime}" Command="{x:Static self:PackageManagerWindowCommands.OpenExternalLink}">
                        <Run Text="{x:Static resources:Resources.Dialog_MoreInfo}" />
                    </Hyperlink>
                </TextBlock>

                <!-- Report Abuse Url -->
                <TextBlock AutomationProperties.AutomationId="ReportAbuseLinkContainer" ToolTip="{Binding PackageIdentity.ReportAbuseUrl, Mode=OneTime}" Visibility="{Binding PackageIdentity.ReportAbuseUrl, Converter={StaticResource urlConverter}}">
                    <Hyperlink AutomationProperties.AutomationId="ReportAbuseLink" Style="{StaticResource CommonHyperlinkStyle}" NavigateUri="{Binding PackageIdentity.ReportAbuseUrl, Mode=OneTime}" Command="{x:Static self:PackageManagerWindowCommands.OpenExternalLink}">
                        <Run Text="{x:Static resources:Resources.Dialog_ReportAbuse}" />
                    </Hyperlink>
                </TextBlock>

                <!-- Description -->
                <self:TextBlockControl Margin="0,3,0,0" Style="{StaticResource DescriptionLabelStyle}">
                </self:TextBlockControl>
                
                <self:TextBlockControl
                    AutomationProperties.AutomationId="PackageDescription"
                    Text="{Binding Description, Converter={StaticResource NormalizeTextConverter}, Mode=OneWay}"
                    Style="{StaticResource DetailMetadataValueStyle}"
                    TextWrapping="Wrap"
                    Margin="0,5">
                </self:TextBlockControl>

                <!-- Tags -->
                <DockPanel Margin="0,3,0,0" Visibility="{Binding PackageIdentity.Tags, Converter={StaticResource NullToVisibilityConverter}}">
                    <self:TextBlockControl DockPanel.Dock="Left" Text="{x:Static resources:Resources.Dialog_TagLabel}" Style="{StaticResource DetailMetadataLabelStyle}" />
                    <self:TextBlockControl Text="{Binding PackageIdentity.Tags}" Style="{StaticResource DetailMetadataValueStyle}" TextWrapping="Wrap" />
                </DockPanel>

                <!-- Dependencies list -->
                <self:TextBlockControl Margin="0,3,0,0" Text="{x:Static resources:Resources.Dialog_DependenciesLabel}" Style="{StaticResource DetailMetadataLabelStyle}" />
                                        
                <ItemsControl
                    x:Name="DependencyItems"
                    Margin="25,5,0,0"
                    ItemsSource="{Binding DisplayDependencies}">
                </ItemsControl>

                <self:TextBlockControl 
                    Margin="25,5,0,0"
                    Visibility="{Binding Items.Count, ElementName=DependencyItems, Converter={StaticResource invertedCountConverter}}"
                    Style="{StaticResource NoDependencyTextBoxStyle}" 
                    Text="{x:Static resources:Resources.Dialog_NoDependencyLabel}">
                </self:TextBlockControl>

                <!-- Disclaimer text -->
                <self:TextBlockControl 
                    x:Name="Disclaimer"
                    FontStyle="Italic"
                    Visibility="{Binding Items.Count, ElementName=DependencyItems, Converter={StaticResource countConverter}}"
                    Style="{StaticResource DetailDescriptionTextBoxStyle}" 
                    Text="{x:Static resources:Resources.Dialog_PackageDisclaimer}"
                    TextWrapping="Wrap">
                </self:TextBlockControl>

                <!-- Installed Project list -->
                <self:TextBlockControl 
                    Margin="0,10,0,0" 
                    Text="{x:Static resources:Resources.Dialog_ProjectListLabel}" 
                    Style="{StaticResource DetailMetadataLabelStyle}"
                    Visibility="{Binding Items.Count, ElementName=ProjectItems, Converter={StaticResource countConverter}}" />

                <ItemsControl 
                    x:Name="ProjectItems" 
                    ItemsSource="{Binding ReferenceProjects}"
                    Margin="25,5,0,0"
                    DisplayMemberPath="Name">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Converter={StaticResource ProjectToNameConverter}}" ToolTipService.ToolTip="{Binding Name}" TextTrimming="CharacterEllipsis" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </StackPanel>
        </ScrollViewer>

        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding PackageIdentity.GalleryDetailsUrl, Mode=OneTime, FallbackValue={x:Null}}" Value="{x:Null}">
                <Setter TargetName="IdTextOnlyBlock" Property="Visibility" Value="Visible" />
                <Setter TargetName="IdTextBlock" Property="Visibility" Value="Collapsed" />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
</ResourceDictionary>