<UserControl x:Class="SharepointToolbox.Views.Tabs.FolderStructureView"
             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 Margin="10">
        <ScrollViewer DockPanel.Dock="Left" Width="280" Margin="0,0,10,0"
                      VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
        <StackPanel>
            <!-- Library input -->
            <TextBlock Text="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[folderstruct.library]}"
                       Margin="0,0,0,3" />
            <TextBox Text="{Binding LibraryTitle, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,0,10" />

            <StackPanel Orientation="Horizontal" Margin="0,0,0,5">
                <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[folderstruct.import]}"
                        Command="{Binding ImportCsvCommand}" />
                <common:InfoButton Margin="6,0,0,0"
                                   Title="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.folderstruct.title]}"
                                   Body="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.folderstruct.body]}" />
            </StackPanel>
            <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[folderstruct.example]}"
                    Command="{Binding LoadExampleCommand}" Margin="0,0,0,10" />

            <TextBlock Text="{Binding PreviewSummary}" TextWrapping="Wrap" Margin="0,0,0,10" />

            <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[folderstruct.execute]}"
                    Command="{Binding RunCommand}" Margin="0,0,0,5"
                    IsEnabled="{Binding IsRunning, Converter={StaticResource InverseBoolConverter}}" />
            <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[status.cancelled]}"
                    Command="{Binding CancelCommand}"
                    Visibility="{Binding IsRunning, Converter={StaticResource BoolToVisibilityConverter}}" />

            <common:Spinner Width="20" Height="20" HorizontalAlignment="Left" Margin="0,10,0,5"
                            Visibility="{Binding IsRunning, Converter={StaticResource BoolToVisibilityConverter}}" />
            <TextBlock Text="{Binding StatusMessage}" TextWrapping="Wrap" />

            <TextBlock Text="{Binding ResultSummary}" FontWeight="Bold" Margin="0,10,0,5" />
            <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[bulk.exportfailed]}"
                    Command="{Binding ExportFailedCommand}" />
        </StackPanel>
        </ScrollViewer>

        <DataGrid ItemsSource="{Binding PreviewRows}" AutoGenerateColumns="False"
                  IsReadOnly="True" CanUserSortColumns="True">
            <DataGrid.RowStyle>
                <Style TargetType="DataGridRow">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsValid}" Value="False">
                            <Setter Property="Background" Value="#FFFDE0E0" />
                            <Setter Property="Foreground" Value="#FFB00020" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.RowStyle>
            <DataGrid.Columns>
                <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[common.valid]}"
                                    Binding="{Binding IsValid}" Width="50" />
                <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[folderstruct.col.level1]}"
                                    Binding="{Binding Record.Level1}" Width="*" />
                <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[folderstruct.col.level2]}"
                                    Binding="{Binding Record.Level2}" Width="*" />
                <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[folderstruct.col.level3]}"
                                    Binding="{Binding Record.Level3}" Width="*" />
                <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[folderstruct.col.level4]}"
                                    Binding="{Binding Record.Level4}" Width="*" />
                <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[common.errors]}"
                                    Binding="{Binding Errors, Converter={StaticResource ListToStringConverter}}"
                                    Width="*" />
            </DataGrid.Columns>
        </DataGrid>
    </DockPanel>
</UserControl>
