<nuget:VsDialogWindow
  x:Class="NuGet.PackageManagement.UI.LicenseAcceptanceWindow"
  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"
  xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"  
  xmlns:catalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog"  
  x:Name="_self"
  MinWidth="450"
  MinHeight="450"
  Width="450"
  Height="450"
  Background="{DynamicResource {x:Static nuget:Brushes.BackgroundBrushKey}}"
  Foreground="{DynamicResource {x:Static nuget:Brushes.UIText}}"
  mc:Ignorable="d"
  ShowInTaskbar="False"
  WindowStartupLocation="CenterOwner"
  KeyDown="OnButtonKeyDown"
  Title="{x:Static nuget:Resources.WindowTitle_LicenseAcceptance}"
  d:DesignHeight="300"
  d:DesignWidth="300"
  FocusManager.FocusedElement="{Binding ElementName=_acceptButton}">
  <Window.Resources>
    <ResourceDictionary>

      <ResourceDictionary.MergedDictionaries>
        <nuget:SharedResources />
      </ResourceDictionary.MergedDictionaries>
      <DataTemplate DataType="{x:Type nuget:LicenseText}">
        <TextBlock
            AutomationProperties.AutomationId="{Binding Id, Mode=OneWay, StringFormat='LicenseTerm_{0}'}"
            AutomationProperties.LabeledBy="{Binding ElementName=_licenseHeaderText}"
            >
                <Hyperlink
                    AutomationProperties.AutomationId="{Binding Id, Mode=OneWay, StringFormat='LicenseTermLink_{0}'}"
                    Style="{StaticResource HyperlinkStyle}"
                    ToolTip="{Binding Link}"
                    RequestNavigate="OnViewLicenseTermsRequestNavigate"
                    NavigateUri="{Binding Link}">
                    <Run Text="{Binding Text}"></Run>
                </Hyperlink>
        </TextBlock>
      </DataTemplate>
      
      <DataTemplate DataType="{x:Type nuget:FreeText}">
        <TextBlock
            AutomationProperties.LabeledBy="{Binding ElementName=_licenseHeaderText}"
            AutomationProperties.AutomationId="{Binding Id, Mode=OneWay, StringFormat='LicenseOperator_{0}'}"
            Text="{Binding Text}" />
      </DataTemplate>

      <DataTemplate DataType="{x:Type nuget:LicenseFileText}">
        <TextBlock>
                <Hyperlink
                    AutomationProperties.AutomationId="{Binding Text}"
                    Style="{StaticResource WindowHyperlinkStyle}"
                    Click="ViewLicense_Click">
                  <Run Text="{Binding Text}"/>
                </Hyperlink>
        </TextBlock>
      </DataTemplate>

      <DataTemplate DataType="{x:Type nuget:WarningText}">
        <imaging:CrispImage
                        x:Name="_licenseWarning"
                        Margin="5,0,5,5"
                        Visibility="{Binding Text, Converter={StaticResource NullToVisibilityConverter}}"
                        ToolTip="{Binding Text}"
                        Moniker="{x:Static catalog:KnownMonikers.StatusWarning}" />
      </DataTemplate>

      <DataTemplate x:Key="LicenseItemTemplate">
        <StackPanel
          Margin="2,0,2,5">
          <TextBlock
            TextWrapping="Wrap"
            x:Name="_packageLicenseText"
            AutomationProperties.Name="{Binding Text}">
                    <Run
              Text="{Binding Id, Mode=OneTime}"
              FontWeight="Bold" />
                    <Run
              Text=" " />
                    <Run
              Text="{x:Static nuget:Resources.Label_Authors}" />
                    <Run
              Text="{Binding Authors, Mode=OneTime}" />
          </TextBlock>
          <ItemsControl ItemsSource="{Binding License}">
            <ItemsControl.ItemsPanel>
              <ItemsPanelTemplate>
                <WrapPanel Orientation="Horizontal" />
              </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
          </ItemsControl>
        </StackPanel>
      </DataTemplate>
    </ResourceDictionary>
  </Window.Resources>
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition
        Height="Auto" />
      <RowDefinition
        Height="Auto" />
      <RowDefinition />
      <RowDefinition
        Height="Auto" />
      <RowDefinition
        Height="Auto" />
    </Grid.RowDefinitions>
    <TextBlock
      Grid.Row="0"
      Grid.Column="0"
      Margin="12,8,12,0"
      x:Name="_licenseAcceptanceText"
      AutomationProperties.Name="{Binding Text}"
      Text="{x:Static nuget:Resources.Text_LicenseAcceptance}"
      FontSize="{Binding ElementName=_self,Path=FontSize,Converter={StaticResource Font122PercentSizeConverter}}" />

    <TextBlock
      Grid.Row="1"
      Grid.Column="0"
      Margin="12,4,12,0"
      x:Name="_licenseHeaderText"
      AutomationProperties.Name="{Binding Text}"
      Text="{x:Static nuget:Resources.Text_LicenseHeaderText}"
      TextWrapping="Wrap" />
    <ItemsControl
      Grid.Row="2"
      Grid.Column="0"
      Margin="12,8"
      MinHeight="130"
      IsTabStop="False"
      ItemsSource="{Binding}"
      ItemTemplate="{StaticResource LicenseItemTemplate}">
      <ItemsControl.Template>
        <ControlTemplate
          TargetType="{x:Type ItemsControl}">
          <Border
            BorderThickness="1"
            BorderBrush="{DynamicResource {x:Static nuget:Brushes.BorderBrush}}">
            <ScrollViewer
              Padding="3"
              CanContentScroll="True"
              VerticalScrollBarVisibility="Visible"
              HorizontalScrollBarVisibility="Disabled"
              AutomationProperties.LabeledBy="{Binding ElementName=_licenseHeaderText}">
              <ItemsPresenter></ItemsPresenter>
            </ScrollViewer>
          </Border>
        </ControlTemplate>
      </ItemsControl.Template>
    </ItemsControl>

    <TextBlock
      Grid.Row="3"
      Grid.Column="0"
      Margin="12,0,12,12"
      x:Name="_licenseText"
      Text="{x:Static nuget:Resources.Text_LicenseText}"
      TextWrapping="Wrap" />
    <Grid
      Grid.Row="5"
      Grid.Column="0"
      HorizontalAlignment="Right">
      <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition
            Width="auto" />
        <ColumnDefinition
            Width="auto" />
      </Grid.ColumnDefinitions>

      <Button
          Name="_acceptButton"
          Grid.Column="1"
          MinWidth="86"
          MinHeight="24"
          Margin="0,12"
          Content="{x:Static nuget:Resources.Button_IAccept}"
          AutomationProperties.AutomationId="AcceptButton"
          Click="OnAcceptButtonClick" />
      <Button
          Grid.Column="2"
          MinWidth="86"
          MinHeight="24"
          Margin="6,12,12,12"
          Content="{x:Static nuget:Resources.Button_IDecline}"
          AutomationProperties.AutomationId="DeclineButton"
          Click="OnDeclineButtonClick" />
    </Grid>
  </Grid>
</nuget:VsDialogWindow>
