<UserControl x:Class="SharepointToolbox.Views.Tabs.SearchView"
             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">
        <!-- Filters panel -->
        <ScrollViewer DockPanel.Dock="Left" Width="260" VerticalScrollBarVisibility="Auto" Margin="8,8,4,8">
            <StackPanel>
                <GroupBox Margin="0,0,0,8">
                    <GroupBox.Header>
                        <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                            <TextBlock Text="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[grp.search.filters]}" VerticalAlignment="Center" />
                            <common:InfoButton Margin="6,0,0,0"
                                               Title="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.search.title]}"
                                               Body="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.search.body]}" />
                        </StackPanel>
                    </GroupBox.Header>
                    <StackPanel Margin="4">
                        <Label Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[lbl.extensions]}" Padding="0,0,0,2" />
                        <TextBox Text="{Binding Extensions, UpdateSourceTrigger=PropertyChanged}" Height="26"
                                 ToolTip="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[ph.extensions]}" Margin="0,0,0,6" />

                        <StackPanel Orientation="Horizontal" Margin="0,0,0,2">
                            <Label Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[lbl.regex]}" Padding="0" VerticalAlignment="Center" />
                            <common:InfoButton Margin="4,0,0,0"
                                               Title="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.search.regex.title]}"
                                               Body="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.search.regex.body]}" />
                        </StackPanel>
                        <TextBox Text="{Binding Regex, UpdateSourceTrigger=PropertyChanged}" Height="26"
                                 ToolTip="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[ph.regex]}" Margin="0,0,0,6" />

                        <CheckBox Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[chk.created.after]}"
                                  IsChecked="{Binding UseCreatedAfter}" Margin="0,2" />
                        <DatePicker SelectedDate="{Binding CreatedAfter}"
                                    IsEnabled="{Binding UseCreatedAfter}" Height="26" Margin="0,0,0,4" />

                        <CheckBox Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[chk.created.before]}"
                                  IsChecked="{Binding UseCreatedBefore}" Margin="0,2" />
                        <DatePicker SelectedDate="{Binding CreatedBefore}"
                                    IsEnabled="{Binding UseCreatedBefore}" Height="26" Margin="0,0,0,4" />

                        <CheckBox Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[chk.modified.after]}"
                                  IsChecked="{Binding UseModifiedAfter}" Margin="0,2" />
                        <DatePicker SelectedDate="{Binding ModifiedAfter}"
                                    IsEnabled="{Binding UseModifiedAfter}" Height="26" Margin="0,0,0,4" />

                        <CheckBox Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[chk.modified.before]}"
                                  IsChecked="{Binding UseModifiedBefore}" Margin="0,2" />
                        <DatePicker SelectedDate="{Binding ModifiedBefore}"
                                    IsEnabled="{Binding UseModifiedBefore}" Height="26" Margin="0,0,0,4" />

                        <Label Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[lbl.created.by]}" Padding="0,0,0,2" />
                        <TextBox Text="{Binding CreatedBy, UpdateSourceTrigger=PropertyChanged}" Height="26"
                                 ToolTip="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[ph.created.by]}" Margin="0,0,0,6" />

                        <Label Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[lbl.modified.by]}" Padding="0,0,0,2" />
                        <TextBox Text="{Binding ModifiedBy, UpdateSourceTrigger=PropertyChanged}" Height="26"
                                 ToolTip="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[ph.modified.by]}" Margin="0,0,0,6" />

                        <Label Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[lbl.library]}" Padding="0,0,0,2" />
                        <TextBox Text="{Binding Library, UpdateSourceTrigger=PropertyChanged}" Height="26"
                                 ToolTip="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[ph.library]}" Margin="0,0,0,6" />

                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0">
                            <Label Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[lbl.max.results]}"
                                   VerticalAlignment="Center" Padding="0,0,4,0" />
                            <TextBox Text="{Binding MaxResults, UpdateSourceTrigger=PropertyChanged}"
                                     Width="60" Height="22" VerticalAlignment="Center" />
                        </StackPanel>
                    </StackPanel>
                </GroupBox>

                <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[btn.run.search]}"
                        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" />

                <GroupBox Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[grp.export.fmt]}" Margin="0,0,0,8">
                    <StackPanel Margin="4">
                        <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[srch.rad.csv]}"
                                Command="{Binding ExportCsvCommand}" Height="26" Margin="0,2" />
                        <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[srch.rad.html]}"
                                Command="{Binding ExportHtmlCommand}" Height="26" Margin="0,2" />
                    </StackPanel>
                </GroupBox>

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

        <!-- Results DataGrid -->
        <DataGrid ItemsSource="{Binding Results}" IsReadOnly="True" AutoGenerateColumns="False"
                  VirtualizingPanel.IsVirtualizing="True" Margin="4,8,8,8">
            <DataGrid.Columns>
                <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[srch.col.name]}"
                                    Binding="{Binding Title}" Width="180" />
                <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[srch.col.ext]}"
                                    Binding="{Binding FileExtension}" Width="70" />
                <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[srch.col.created]}"
                                    Binding="{Binding Created, StringFormat=yyyy-MM-dd}" Width="100" />
                <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[srch.col.author]}"
                                    Binding="{Binding Author}" Width="130" />
                <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[srch.col.modified]}"
                                    Binding="{Binding LastModified, StringFormat=yyyy-MM-dd}" Width="100" />
                <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[srch.col.modby]}"
                                    Binding="{Binding ModifiedBy}" Width="130" />
                <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[srch.col.size]}"
                                    Binding="{Binding SizeBytes, Converter={StaticResource BytesConverter}}"
                                    Width="90" ElementStyle="{StaticResource RightAlignStyle}" />
                <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[srch.col.path]}"
                                    Binding="{Binding Path}" Width="*" />
            </DataGrid.Columns>
        </DataGrid>
    </DockPanel>
</UserControl>
