<UserControl
  x:Class="NuGet.PackageManagement.UI.PackageMetadataControl"
  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:nuget="clr-namespace:NuGet.PackageManagement.UI"
  Background="{DynamicResource {x:Static nuget:Brushes.DetailPaneBackground}}"
  Foreground="{DynamicResource {x:Static nuget:Brushes.UIText}}"
  mc:Ignorable="d"
  d:DesignHeight="300"
  d:DesignWidth="300">
  <UserControl.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <nuget:SharedResources />
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </UserControl.Resources>
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition
        Height="Auto" />
      <RowDefinition
        Height="Auto" />
      <RowDefinition
        Height="Auto" />
      <RowDefinition
        Height="Auto" />
    </Grid.RowDefinitions>

    <!-- descriptions -->
    <TextBlock
      Grid.Row="0"
      Text="{x:Static nuget:Resources.Label_Description}"
      FontWeight="Bold" />
    <TextBox
      Style="{DynamicResource SelectableTextBlockStyle}" 
      Grid.Row="1"
      x:Name="_description"
      Margin="0,8,0,0"
      TextWrapping="Wrap"
      Text="{Binding Path=Description}" />

    <!-- metadata -->
    <Grid
      Grid.Row="2"
      x:Name="_metadataGrid"
      Margin="0,8">
      <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition
          Width="Auto" />
        <ColumnDefinition />
      </Grid.ColumnDefinitions>

      <!-- version -->
      <TextBlock
        Visibility="{Binding Path=Version,Converter={StaticResource NullToVisibilityConverter}}"
        Grid.Row="0"
        Grid.Column="0"
        Margin="0,8,0,0"
        FontWeight="Bold"
        Text="{x:Static nuget:Resources.Label_Version}" />
      <TextBox
        Style="{DynamicResource SelectableTextBlockStyle}" 
        Grid.Row="0"
        Grid.Column="1"
        Visibility="{Binding Path=Version,Converter={StaticResource NullToVisibilityConverter}}"
        Text="{Binding Path=Version,Converter={StaticResource VersionToStringConverter}}"
        Margin="8,8,0,0"
        TextWrapping="Wrap" />

      <!-- Owner(s) -->
      <TextBlock
        Visibility="{Binding Path=Owners,Converter={StaticResource NullToVisibilityConverter}}"
        Grid.Row="1"
        Grid.Column="0"
        Margin="0,8,0,0"
        FontWeight="Bold"
        Text="{x:Static nuget:Resources.Label_Owners}" />
      <TextBox
        Style="{DynamicResource SelectableTextBlockStyle}" 
        Visibility="{Binding Path=Owners,Converter={StaticResource NullToVisibilityConverter}}"
        Text="{Binding Path=Owners}"
        Margin="8,8,0,0"
        TextWrapping="Wrap"
        Grid.Row="1"
        Grid.Column="1" />

      <!-- Author(s) -->
      <TextBlock
        Visibility="{Binding Path=Authors,Converter={StaticResource NullToVisibilityConverter}}"
        Grid.Row="2"
        Grid.Column="0"
        Margin="0,8,0,0"
        FontWeight="Bold"
        Text="{x:Static nuget:Resources.Label_Authors}" />
      <TextBox
        Style="{DynamicResource SelectableTextBlockStyle}" 
        Visibility="{Binding Path=Authors,Converter={StaticResource NullToVisibilityConverter}}"
        Text="{Binding Path=Authors}"
        Margin="8,8,0,0"
        TextWrapping="Wrap"
        Grid.Row="2"
        Grid.Column="1" />

      <!-- License -->
      <TextBlock
        Visibility="{Binding Path=LicenseUrl,Converter={StaticResource NullToVisibilityConverter}}"
        Grid.Row="3"
        Grid.Column="0"
        FontWeight="Bold"
        Margin="0,8,0,0"
        Text="{x:Static nuget:Resources.Label_License}" />
      <TextBlock
        Visibility="{Binding Path=LicenseUrl,Converter={StaticResource NullToVisibilityConverter}}"
        TextWrapping="Wrap"
        Margin="8,8,0,0"
        Grid.Row="3"
        Grid.Column="1">
        <Hyperlink
          NavigateUri="{Binding Path=LicenseUrl}"
          Style="{StaticResource HyperlinkStyle}"
          Command="{x:Static nuget:PackageManagerControlCommands.OpenExternalLink}">
          <Run Text="{Binding Path=LicenseUrl}" />
        </Hyperlink>
      </TextBlock>

      <!-- downloads -->
      <TextBlock
        Visibility="{Binding Path=DownloadCount,Converter={StaticResource  DownloadCountToVisibilityConverter}}"
        Grid.Row="4"
        Grid.Column="0"
        FontWeight="Bold"
        Margin="0,8,0,0"
        Text="{x:Static nuget:Resources.Label_Downloads}" />
      <TextBox
        Style="{DynamicResource SelectableTextBlockStyle}" 
        Visibility="{Binding Path=DownloadCount,Converter={StaticResource DownloadCountToVisibilityConverter}}"
        Text="{Binding Path=DownloadCount,StringFormat={}{0:N0}}"
        Margin="8,8,0,0"
        TextWrapping="Wrap"
        Grid.Row="4"
        Grid.Column="1" />

      <!--Date Published -->
      <TextBlock
        Visibility="{Binding Path=Published,Converter={StaticResource NullToVisibilityConverter}}"
        Grid.Row="5"
        Grid.Column="0"
        FontWeight="Bold"
        Margin="0,8,0,0"
        Text="{x:Static nuget:Resources.Label_DatePublished}" />
      <TextBox
        Style="{DynamicResource SelectableTextBlockStyle}" 
        Visibility="{Binding Path=Published,Converter={StaticResource NullToVisibilityConverter}}"
        Text="{Binding Path=Published,StringFormat={}{0:D} ({0:d})}"
        Margin="8,8,0,0"
        TextWrapping="Wrap"
        Grid.Row="5"
        Grid.Column="1" />

      <!-- Project Url -->
      <TextBlock
        Visibility="{Binding Path=ProjectUrl,Converter={StaticResource NullToVisibilityConverter}}"
        Grid.Row="6"
        Grid.Column="0"
        FontWeight="Bold"
        Margin="0,8,0,0"
        Text="{x:Static nuget:Resources.Label_ProjectUrl}" />

      <TextBlock
        Visibility="{Binding Path=ProjectUrl,Converter={StaticResource NullToVisibilityConverter}}"
        TextWrapping="Wrap"
        Margin="8,8,0,0"
        Grid.Row="6"
        Grid.Column="1">
        <Hyperlink
          NavigateUri="{Binding Path=ProjectUrl}"
          Style="{StaticResource HyperlinkStyle}"
          Command="{x:Static nuget:PackageManagerControlCommands.OpenExternalLink}">
          <Run Text="{Binding Path=ProjectUrl}" />
        </Hyperlink>
      </TextBlock>

      <!-- Report abuse Url -->
      <TextBlock
        Visibility="{Binding Path=ReportAbuseUrl,Converter={StaticResource NullToVisibilityConverter}}"
        Grid.Row="7"
        Grid.Column="0"
        FontWeight="Bold"
        Margin="0,8,0,0"
        Text="{x:Static nuget:Resources.Label_ReportAbuse}" />

      <TextBlock
        Visibility="{Binding Path=ReportAbuseUrl,Converter={StaticResource NullToVisibilityConverter}}"
        TextWrapping="Wrap"
        Margin="8,8,0,0"
        Grid.Row="7"
        Grid.Column="1">
        <Hyperlink
          NavigateUri="{Binding Path=ReportAbuseUrl}"
          Style="{StaticResource HyperlinkStyle}"
          Command="{x:Static nuget:PackageManagerControlCommands.OpenExternalLink}">
          <Run Text="{Binding Path=ReportAbuseUrl}" />
        </Hyperlink>
      </TextBlock>

      <!-- Tags -->
      <TextBlock
        Visibility="{Binding Path=Tags,Converter={StaticResource NullToVisibilityConverter}}"
        Grid.Row="8"
        Grid.Column="0"
        FontWeight="Bold"
        Margin="0,8,0,0"
        Text="{x:Static nuget:Resources.Label_Tags}" />
      <TextBox
        Style="{DynamicResource SelectableTextBlockStyle}" 
        Visibility="{Binding Path=Tags,Converter={StaticResource NullToVisibilityConverter}}"
        Text="{Binding Path=Tags}"
        Margin="8,8,0,0"
        TextWrapping="Wrap"
        Grid.Row="8"
        Grid.Column="1" />
    </Grid>

    <!-- dependencies -->
    <StackPanel
      Grid.Row="3"
      Margin="0,8">
      <TextBlock
        FontWeight="Bold"
        Margin="0,8,0,0"
        Text="{x:Static nuget:Resources.Label_Dependencies}" />

      <ItemsControl
        ItemsSource="{Binding Path=DependencySets}"
        Visibility="{Binding Path=HasDependencies,Converter={StaticResource BooleanToVisibilityConverter}}"
        IsTabStop="False"
        Margin="8,0,0,0">
        <ItemsControl.ItemTemplate>
          <DataTemplate>
            <StackPanel
              Orientation="Vertical"
              Margin="0,8,0,0">
              <TextBlock
                Text="{Binding TargetFramework,Converter={StaticResource NuGetFrameworkToStringConverter}}"
                FontWeight="Bold"
                Visibility="{Binding TargetFramework,Converter={StaticResource NuGetFrameworkToVisibilityConverter}}" />
              <ItemsControl
                ItemsSource="{Binding Dependencies}"
                IsTabStop="False">
                <ItemsControl.ItemTemplate>
                  <DataTemplate>
                    <TextBox 
                      Style="{DynamicResource SelectableTextBlockStyle}"
                      Text="{Binding Mode=OneWay}"/>
                  </DataTemplate>
                </ItemsControl.ItemTemplate>
              </ItemsControl>
              <TextBlock
                FontStyle="Italic"
                Text="{x:Static nuget:Resources.Text_NoDependencies}"
                Visibility="{Binding Dependencies,Converter={StaticResource EmptyEnumerableToVisibilityConverter}}" />
            </StackPanel>
          </DataTemplate>
        </ItemsControl.ItemTemplate>
      </ItemsControl>

      <TextBlock
        Margin="0,8,0,0"
        Visibility="{Binding Path=HasDependencies,Converter={StaticResource InvertedBooleanToVisibilityConverter}}"
        FontStyle="Italic"
        Text="{x:Static nuget:Resources.Text_NoDependencies}" />
    </StackPanel>
  </Grid>
</UserControl>