<UserControl x:Class="SharepointToolbox.Views.Tabs.BulkMembersView"
             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">
        <!-- Options Panel (Left) -->
        <ScrollViewer DockPanel.Dock="Left" Width="240" Margin="0,0,10,0"
                      VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
        <StackPanel>
            <StackPanel Orientation="Horizontal" Margin="0,0,0,5">
                <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[bulkmembers.import]}"
                        Command="{Binding ImportCsvCommand}" />
                <common:InfoButton Margin="6,0,0,0"
                                   Title="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.bulkmembers.title]}"
                                   Body="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.bulkmembers.body]}" />
            </StackPanel>
            <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[bulkmembers.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=[bulkmembers.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.retryfailed]}"
                    Command="{Binding RetryFailedCommand}" Margin="0,0,0,5" />
            <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[bulk.exportfailed]}"
                    Command="{Binding ExportFailedCommand}" />
        </StackPanel>
        </ScrollViewer>

        <!-- Preview DataGrid (Right) -->
        <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="{DynamicResource ErrorRowBgBrush}" />
                            <Setter Property="Foreground" Value="{DynamicResource ErrorRowFgBrush}" />
                        </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=[bulkmembers.groupname]}"
                                    Binding="{Binding Record.GroupName}" Width="*" />
                <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[bulkmembers.email]}"
                                    Binding="{Binding Record.Email}" Width="*" />
                <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[bulkmembers.role]}"
                                    Binding="{Binding Record.Role}" Width="80" />
                <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[common.errors]}"
                                    Binding="{Binding Errors, Converter={StaticResource ListToStringConverter}}"
                                    Width="*" />
            </DataGrid.Columns>
        </DataGrid>
    </DockPanel>
</UserControl>
