<UserControl x:Class="SharepointToolbox.Views.Tabs.VersionCleanupView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:loc="clr-namespace:SharepointToolbox.Localization"
             xmlns:common="clr-namespace:SharepointToolbox.Views.Common">
  <DockPanel LastChildFill="True">
    <ScrollViewer DockPanel.Dock="Left" Width="280" VerticalScrollBarVisibility="Auto" Margin="8,8,4,8">
      <StackPanel>
        <GroupBox Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.grp.libs]}"
                  Margin="0,0,0,8">
          <StackPanel Margin="4">
            <TextBlock Text="{Binding SelectedLibrariesLabel}" Margin="0,0,0,6"
                       Foreground="{DynamicResource TextMutedBrush}" />
            <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.btn.pickLibs]}"
                    Command="{Binding SelectLibrariesCommand}" Height="26" Margin="0,0,0,4" />
            <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.btn.clearLibs]}"
                    Command="{Binding ClearLibrariesCommand}" Height="26" />
          </StackPanel>
        </GroupBox>

        <GroupBox Margin="0,0,0,8">
          <GroupBox.Header>
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
              <TextBlock Text="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.grp.policy]}" VerticalAlignment="Center" />
              <common:InfoButton Margin="6,0,0,0"
                                 Title="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.versions.policy.title]}"
                                 Body="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.versions.policy.body]}" />
            </StackPanel>
          </GroupBox.Header>
          <StackPanel Margin="4">
            <StackPanel Orientation="Horizontal" Margin="0,2">
              <Label Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.lbl.keepLast]}"
                     VerticalAlignment="Center" Padding="0,0,4,0" />
              <TextBox Text="{Binding KeepLast, UpdateSourceTrigger=PropertyChanged}"
                       Width="50" Height="22" VerticalAlignment="Center" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" Margin="0,4,0,2">
              <CheckBox Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.chk.keepFirst]}"
                        IsChecked="{Binding KeepFirstVersion}" VerticalAlignment="Center" />
              <common:InfoButton Margin="6,0,0,0"
                                 Title="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.versions.keepfirst.title]}"
                                 Body="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.versions.keepfirst.body]}" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" Margin="0,4,0,2">
              <CheckBox Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.chk.confirm]}"
                        IsChecked="{Binding ConfirmDelete}" VerticalAlignment="Center" />
              <common:InfoButton Margin="6,0,0,0"
                                 Title="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.versions.confirm.title]}"
                                 Body="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.versions.confirm.body]}" />
            </StackPanel>
            <TextBlock Text="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.note]}"
                       TextWrapping="Wrap" FontSize="11" Foreground="{DynamicResource TextMutedBrush}"
                       Margin="0,6,0,0" />
          </StackPanel>
        </GroupBox>

        <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.btn.run]}"
                Command="{Binding RunCommand}" Height="28" Margin="0,0,0,4" />
        <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[btn.cancel]}"
                Command="{Binding CancelCommand}" Height="28" Margin="0,0,0,8" />

        <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[audit.btn.exportCsv]}"
                Command="{Binding ExportCsvCommand}" Height="28" Margin="0,0,0,4" />
        <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[audit.btn.exportHtml]}"
                Command="{Binding ExportHtmlCommand}" Height="28" Margin="0,0,0,4" />

        <TextBlock Text="{Binding StatusMessage}" TextWrapping="Wrap" FontSize="11"
                   Foreground="{DynamicResource TextMutedBrush}" Margin="0,6" />
      </StackPanel>
    </ScrollViewer>

    <Grid Margin="4,8,8,8">
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
      </Grid.RowDefinitions>

      <Border Grid.Row="0" Background="{DynamicResource AccentSoftBrush}" CornerRadius="4"
              Padding="12,8" Margin="0,0,0,6">
        <Border.Style>
          <Style TargetType="Border">
            <Setter Property="Visibility" Value="Collapsed" />
            <Style.Triggers>
              <DataTrigger Binding="{Binding HasResults}" Value="True">
                <Setter Property="Visibility" Value="Visible" />
              </DataTrigger>
            </Style.Triggers>
          </Style>
        </Border.Style>
        <StackPanel Orientation="Horizontal">
          <StackPanel Orientation="Horizontal" Margin="0,0,24,0">
            <TextBlock Text="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.summary.files]}"
                       FontWeight="SemiBold" />
            <TextBlock Text="{Binding TotalFilesAffected, StringFormat=N0, Mode=OneWay}" Margin="4,0,0,0" />
          </StackPanel>
          <StackPanel Orientation="Horizontal" Margin="0,0,24,0">
            <TextBlock Text="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.summary.deleted]}"
                       FontWeight="SemiBold" />
            <TextBlock Text="{Binding TotalVersionsDeleted, StringFormat=N0, Mode=OneWay}" Margin="4,0,0,0" />
          </StackPanel>
          <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.summary.freed]}"
                       FontWeight="SemiBold" />
            <TextBlock Text="{Binding TotalBytesFreed, Converter={StaticResource BytesConverter}, Mode=OneWay}"
                       Margin="4,0,0,0" />
          </StackPanel>
        </StackPanel>
      </Border>

      <DataGrid Grid.Row="1" ItemsSource="{Binding Results}" IsReadOnly="True" AutoGenerateColumns="False"
                VirtualizingPanel.IsVirtualizing="True"
                ScrollViewer.HorizontalScrollBarVisibility="Auto">
        <DataGrid.Columns>
          <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.col.library]}"
                              Binding="{Binding Library}" Width="140" />
          <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.col.file]}"
                              Binding="{Binding FileName}" Width="200" />
          <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.col.before]}"
                              Binding="{Binding VersionsBefore, StringFormat=N0}" Width="80"
                              ElementStyle="{StaticResource RightAlignStyle}" />
          <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.col.deleted]}"
                              Binding="{Binding VersionsDeleted, StringFormat=N0}" Width="80"
                              ElementStyle="{StaticResource RightAlignStyle}" />
          <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.col.remaining]}"
                              Binding="{Binding VersionsRemaining, StringFormat=N0}" Width="90"
                              ElementStyle="{StaticResource RightAlignStyle}" />
          <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.col.freed]}"
                              Binding="{Binding BytesFreed, Converter={StaticResource BytesConverter}}" Width="100"
                              ElementStyle="{StaticResource RightAlignStyle}" />
          <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.col.path]}"
                              Binding="{Binding FileServerRelativeUrl}" Width="*" />
          <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[versions.col.error]}"
                              Binding="{Binding Error}" Width="160" />
        </DataGrid.Columns>
      </DataGrid>
    </Grid>
  </DockPanel>
</UserControl>
