<Window x:Class="SyncTrayzor.Pages.ConflictResolution.ConflictResolutionView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:SyncTrayzor.Pages.ConflictResolution"
        xmlns:s="https://github.com/canton7/Stylet"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
        xmlns:xaml="clr-namespace:SyncTrayzor.Xaml"
        xmlns:l="clr-namespace:SyncTrayzor.Localization"
        mc:Ignorable="d"
        d:DataContext="{d:DesignInstance local:ConflictResolutionViewModel}"
        Title="{l:Loc ConflictResolutionView_Title}" Height="500" Width="800"
        MinHeight="400" MinWidth="500"
        FlowDirection="{x:Static l:Localizer.FlowDirection}">
    <Window.Resources>
        <CollectionViewSource x:Key="ConflictsItemsSource" Source="{Binding Conflicts}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="FolderLabel"/>
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>
        <Style x:Key="SectionBorderStyle" TargetType="Border">
            <Setter Property="BorderBrush" Value="#828790"/>
            <Setter Property="BorderThickness" Value="1"/>
        </Style>
    </Window.Resources>
    <DockPanel Margin="10,0">
        <!--  Visibility="{Binding IsLoading, Converter={x:Static s:BoolToVisibilityConverter.Instance}}" -->
        <DockPanel DockPanel.Dock="Top" Margin="0,10,0,0" Visibility="{Binding IsLoading, Converter={x:Static s:BoolToVisibilityConverter.Instance}}">
            <TextBlock DockPanel.Dock="Left" Text="{l:Loc ConflictResolutionView_Scanning_Label}"/>
            <Button DockPanel.Dock="Right" Command="{s:Action Cancel}" Content="{l:Loc ConflictResolutionView_Scanning_CancelButton}"/>
            <ProgressBar IsIndeterminate="True" Height="10" Margin="10,0"/>
        </DockPanel>

        <Button DockPanel.Dock="Bottom"
                Margin="10,10,0,10"
                HorizontalAlignment="Right"
                Command="{s:Action Close}"
                Style="{StaticResource DialogButton}"
                Content="{l:Loc Generic_Dialog_Close}"
                IsDefault="True"
                IsCancel="True"/>

        <Border DockPanel.Dock="Bottom" Margin="0,10,0,0"
                Style="{StaticResource SectionBorderStyle}"
                Visibility="{Binding ResolutionViewModel, Converter={x:Static s:BoolToVisibilityConverter.Instance}}">
            <DockPanel>
                <CheckBox DockPanel.Dock="Bottom" Margin="5"
                          IsChecked="{Binding DeleteToRecycleBin}"
                          Content="{l:Loc ConflictResolutionView_DeleteToRecycleBin}"/>

                <ContentControl s:View.Model="{Binding ResolutionViewModel}"/>
            </DockPanel>
        </Border>

        <Border Margin="0,10,0,0" Style="{StaticResource SectionBorderStyle}">
            <Grid>
                <Grid.Resources>
                    <Style x:Key="MessageStyle" TargetType="TextBlock">
                        <Setter Property="HorizontalAlignment" Value="Center"/>
                        <Setter Property="VerticalAlignment" Value="Center"/>
                    </Style>
                </Grid.Resources>
                <TextBlock Style="{StaticResource MessageStyle}"
                           Visibility="{Binding IsLoadingAndNoConflictsFound, Converter={x:Static s:BoolToVisibilityConverter.Instance}}"
                           Text="{l:Loc ConflictResolutionView_Status_Scanning}"/>
                <TextBlock Style="{StaticResource MessageStyle}"
                           Visibility="{Binding HasFinishedLoadingAndNoConflictsFound, Converter={x:Static s:BoolToVisibilityConverter.Instance}}"
                           Text="{l:Loc ConflictResolutionView_Status_NoConflicts}"/>
                <TextBlock Style="{StaticResource MessageStyle}"
                           Visibility="{Binding IsSyncthingStopped, Converter={x:Static s:BoolToVisibilityConverter.Instance}}"
                           Text="{l:Loc ConflictResolutionView_Status_SyncthingNotRunning}"/>

                <ListView Visibility="{Binding Conflicts, Converter={x:Static s:BoolToVisibilityConverter.Instance}}"
                          ItemsSource="{Binding Source={StaticResource ConflictsItemsSource}}"
                          SelectionMode="Extended"
                          SelectionChanged="{s:Action SelectionChanged}"
                          MouseDoubleClick="{s:Action ListViewDoubleClick}"
                          BorderThickness="0"
                          MinHeight="10">
                    <i:Interaction.Behaviors>
                        <xaml:GridViewSortByBehaviour/>
                    </i:Interaction.Behaviors>
                    <ListView.Resources>
                        <Style TargetType="GridViewColumnHeader">
                            <Setter Property="HorizontalContentAlignment" Value="Left"/>
                            <Setter Property="Padding" Value="5,0"/>
                        </Style>
                        <Style TargetType="ListViewItem">
                            <Setter Property="IsSelected" Value="{Binding IsSelected}"/>
                        </Style>
                    </ListView.Resources>
                    <ListView.View>
                        <GridView>
                            <GridViewColumn xaml:GridViewSortBy.SortByKey="FileName"
                                            xaml:GridViewSortBy.IsInitiallySorted="True">
                                <!-- Need a proper header for this, for the initial sort -->
                                <GridViewColumnHeader>
                                    <TextBlock Text="{l:Loc ConflictResolutionView_Header_File}"/>
                                </GridViewColumnHeader>
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <Image Width="15" Height="15" Margin="5,0,5,0"
                                                   Source="{Binding Icon}"/>
                                            <TextBlock Text="{Binding FileName}"/>
                                        </StackPanel>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="{l:Loc ConflictResolutionView_Header_LastModified}"
                                            DisplayMemberBinding="{Binding LastModified}"
                                            xaml:GridViewSortBy.SortByKey="LastModified"/>
                            <GridViewColumn Header="{l:Loc ConflictResolutionView_Header_Folder}"
                                            xaml:GridViewSortBy.SortByKey="InnerFolder">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock>
                                            <TextBlock Text="{Binding InnerFolder}"/>
                                            (<TextBlock Text="{Binding Folder}"/>)
                                        </TextBlock>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
                    <ListView.GroupStyle>
                        <GroupStyle>
                            <GroupStyle.ContainerStyle>
                                <Style TargetType="{x:Type GroupItem}">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate>
                                                <Expander IsExpanded="True">
                                                    <Expander.Header>
                                                        <TextBlock Text="{Binding Name}" FontWeight="Bold"/>
                                                    </Expander.Header>
                                                    <ItemsPresenter />
                                                </Expander>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </GroupStyle.ContainerStyle>
                        </GroupStyle>
                    </ListView.GroupStyle>
                </ListView>
            </Grid>
        </Border>
    </DockPanel>
</Window>
