<Window x:Class="ServerManagerTool.ModDetailsWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:com="clr-namespace:ServerManagerTool.Common;assembly=ServerManager.Common"
        MinWidth="600" MinHeight="480" Width="900" Height="480" ResizeMode="CanResize" WindowStyle="ToolWindow" WindowStartupLocation="CenterOwner" ShowInTaskbar="False" 
        Loaded="Window_Loaded" Closing="Window_Closing" 
        Icon="../Art/favicon.ico" Title="{DynamicResource ModDetails_Title}"
        FocusManager.FocusedElement="{Binding ElementName=ModDetailsFilterStringTextBox}"
        Name="ModDetailsUI">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="..\Globalization\en-US\en-US.xaml"/>
                <ResourceDictionary Source="..\Styles\Default.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    
    <Grid Background="{StaticResource BeigeGradient}" MouseLeftButtonUp="OnMouseLeftButtonUp" MouseMove="OnMouseMove">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="10*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="200*"/>
        </Grid.ColumnDefinitions>

        <Button Grid.Row="0" Grid.Column="0" Width="22" Height="22" Margin="5,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="SaveMods_Click" ToolTip="{DynamicResource ModDetails_SaveModsTooltip}">
            <Image Source="{com:Icon Path=/ConanServerManager;component/Art/Save.ico,Size=32}"/>
        </Button>

        <Button Grid.Row="0" Grid.Column="1" Width="22" Height="22" Margin="10,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="AddMods_Click" ToolTip="{DynamicResource ModDetails_AddModsTooltip}">
            <Image Source="{com:Icon Path=/ConanServerManager;component/Art/Add.ico,Size=32}"/>
        </Button>

        <Button Grid.Row="0" Grid.Column="2" Width="22" Height="22" Margin="0,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="RemoveAllMods_Click" ToolTip="{DynamicResource ModDetails_RemoveAllModsTooltip}">
            <Image Source="{com:Icon Path=/ConanServerManager;component/Art/Delete.ico,Size=32}"/>
        </Button>

        <Button Grid.Row="0" Grid.Column="3" Width="22" Height="22" Margin="10,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="RefreshMods_Click" ToolTip="{DynamicResource ModDetails_RefreshModsTooltip}">
            <Image Source="{com:Icon Path=/ConanServerManager;component/Art/Refresh.ico,Size=32}"/>
        </Button>

        <Button Grid.Row="0" Grid.Column="4" Width="22" Height="22" Margin="0,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="ReloadMods_Click" ToolTip="{DynamicResource ModDetails_ReloadModsTooltip}">
            <Image Source="{com:Icon Path=/ConanServerManager;component/Art/Reload.ico,Size=32}"/>
        </Button>

        <Button Grid.Row="0" Grid.Column="5" Width="22" Height="22" Margin="0,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="LoadMods_Click" ToolTip="{DynamicResource ModDetails_LoadModsTooltip}">
            <Image Source="{com:Icon Path=/ConanServerManager;component/Art/FolderOpen.ico,Size=32}"/>
        </Button>

        <Button Grid.Row="0" Grid.Column="6" Width="22" Height="22" Margin="10,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="PurgeModsFolder_Click" IsEnabled="{Binding Path=ModDetailsChanged, ElementName=ModDetailsUI, Converter={StaticResource InvertBooleanConverter}}" ToolTip="{DynamicResource ModDetails_PurgeModsFolderTooltip}">
            <Image Source="{com:Icon Path=/ConanServerManager;component/Art/FolderDelete.ico,Size=32}"/>
        </Button>

        <Button Grid.Row="0" Grid.Column="7" Width="22" Height="22" Margin="10,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="SaveModDetails_Click" ToolTip="{DynamicResource ModDetails_SaveModDetailsTooltip}">
            <Image Source="{com:Icon Path=/ConanServerManager;component/Art/Copy.ico,Size=32}"/>
        </Button>

        <StackPanel Grid.Row="0" Grid.Column="8" Orientation="Horizontal">
            <TextBlock Margin="30,5,5,0" Text="{DynamicResource ModDetails_TotalCountLabel}" VerticalAlignment="Center" />
            <TextBlock Margin="5,5,5,0" Text="{Binding ModDetails.Count}" VerticalAlignment="Center" />
        </StackPanel>

        <StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="9" Margin="0,5,0,0" Orientation="Horizontal" Height="30" DataContext="{Binding}">
            <TextBlock Margin="5,0,5,0" Text="{DynamicResource General_FilterLabel}" VerticalAlignment="Center" />
            <TextBox x:Name="ModDetailsFilterStringTextBox" Margin="5,0,5,0" Text="{Binding ModDetailsFilterString, Mode=TwoWay}" Width="200" Padding="2" VerticalAlignment="Center"/>
            <Button Margin="5,0,5,0" Width="22" Height="22" HorizontalAlignment="Left" VerticalAlignment="Center" Click="FilterMods_Click" ToolTip="{DynamicResource General_FilterButtonTooltip}">
                <Image Source="{com:Icon Path=/ConanServerManager;component/Art/Filter.ico,Size=32}"/>
            </Button>
            <TextBlock Margin="5,0,5,0" Text="{Binding ModDetailsStatusMessage}" VerticalAlignment="Center" Foreground="SteelBlue" />
        </StackPanel>

        <DataGrid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="9" Name="ModDetailsGrid" ItemsSource="{Binding ModDetails}" Margin="5" AutoGenerateColumns="False" CanUserAddRows="False" CanUserReorderColumns="False" CanUserSortColumns="True" RowHeaderWidth="0" SelectionMode="Single" PreviewMouseLeftButtonDown="OnMouseLeftButtonDown">
            <DataGrid.Resources>
                <Style TargetType="{x:Type DataGridRow}">
                    <Style.Resources>
                        <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{x:Static SystemColors.HighlightColor}"/>
                        <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="{x:Static SystemColors.HighlightTextColor}"/>
                    </Style.Resources>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsValid}" Value="False">
                            <Setter Property="Background" Value="#FFB8E7F5" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding UpToDate}" Value="False">
                            <Setter Property="Background" Value="#FFF5DFB8" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.Resources>
            
            <DataGrid.HorizontalGridLinesBrush>
                <SolidColorBrush Color="#FFB4B4B4"/>
            </DataGrid.HorizontalGridLinesBrush>
            <DataGrid.VerticalGridLinesBrush>
                <SolidColorBrush Color="#FFB4B4B4"/>
            </DataGrid.VerticalGridLinesBrush>
            
            <DataGrid.Columns>
                <DataGridTextColumn     Width="Auto" Binding="{Binding Index, Mode=OneWay}">
                    <DataGridTextColumn.Header>
                        <TextBlock Text="{DynamicResource ModDetails_IndexColumnLabel}" />
                    </DataGridTextColumn.Header>
                </DataGridTextColumn>
                <DataGridTemplateColumn Width="Auto" MinWidth="100" CanUserSort="True" SortMemberPath="ModId">
                    <DataGridTemplateColumn.Header>
                        <TextBlock Text="{DynamicResource ModDetails_ModIdColumnLabel}" />
                    </DataGridTemplateColumn.Header>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock>
                                <Hyperlink NavigateUri="{Binding ModUrl}" RequestNavigate="Mod_RequestNavigate">
                                    <TextBlock Text="{Binding ModId, Mode=OneWay}"/>
                                </Hyperlink>
                            </TextBlock>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn     Width="1*" Binding="{Binding Title, Mode=OneWay}">
                    <DataGridTextColumn.Header>
                        <TextBlock Text="{DynamicResource ModDetails_TitleColumnLabel}" />
                    </DataGridTextColumn.Header>
                </DataGridTextColumn>
                <DataGridTextColumn     Width="Auto" MinWidth="80" Binding="{Binding ModTypeString, Mode=OneWay}">
                    <DataGridTextColumn.Header>
                        <TextBlock Text="{DynamicResource ModDetails_TypeColumnLabel}" />
                    </DataGridTextColumn.Header>
                </DataGridTextColumn>
                <DataGridTextColumn     Width="Auto" MinWidth="130" Binding="{Binding LastWriteTimeString, Mode=OneWay}" Header="{DynamicResource ModDetails_LastUpdatedColumnLabel}" SortMemberPath="LastWriteTimeSortString">
                    <DataGridTextColumn.HeaderStyle>
                        <Style TargetType="DataGridColumnHeader" BasedOn="{StaticResource {x:Type DataGridColumnHeader}}">
                            <Setter Property="HorizontalContentAlignment" Value="Right"/>
                        </Style>
                    </DataGridTextColumn.HeaderStyle>
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
                            <Setter Property="HorizontalAlignment" Value="Right"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>
                <DataGridTextColumn     Width="Auto" MinWidth="130" Binding="{Binding TimeUpdatedString, Mode=OneWay}" Header="{DynamicResource ModDetails_TimeUpdatedColumnLabel}" SortMemberPath="TimeUpdatedSortString">
                    <DataGridTextColumn.HeaderStyle>
                        <Style TargetType="DataGridColumnHeader" BasedOn="{StaticResource {x:Type DataGridColumnHeader}}">
                            <Setter Property="HorizontalContentAlignment" Value="Right"/>
                        </Style>
                    </DataGridTextColumn.HeaderStyle>
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
                            <Setter Property="HorizontalAlignment" Value="Right"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>
                <DataGridTextColumn     Width="Auto" MinWidth="80" Binding="{Binding TimeUpdated, Mode=OneWay}" Header="{DynamicResource ModDetails_TimestampColumnLabel}">
                    <DataGridTextColumn.HeaderStyle>
                        <Style TargetType="DataGridColumnHeader" BasedOn="{StaticResource {x:Type DataGridColumnHeader}}">
                            <Setter Property="HorizontalContentAlignment" Value="Right"/>
                        </Style>
                    </DataGridTextColumn.HeaderStyle>
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
                            <Setter Property="HorizontalAlignment" Value="Right"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>
                <DataGridTextColumn     Width="85" Binding="{Binding FolderSizeString, Mode=OneWay}" Header="{DynamicResource ModDetails_FolderSizeColumnLabel}" SortMemberPath="FolderSize">
                    <DataGridTextColumn.HeaderStyle>
                        <Style TargetType="DataGridColumnHeader" BasedOn="{StaticResource {x:Type DataGridColumnHeader}}">
                            <Setter Property="HorizontalContentAlignment" Value="Right"/>
                        </Style>
                    </DataGridTextColumn.HeaderStyle>
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
                            <Setter Property="HorizontalAlignment" Value="Right"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>
                <DataGridTemplateColumn Width="30" CanUserReorder="False" CanUserResize="False">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Width="22" Height="22" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center" Click="MoveModUp_Click" ToolTip="{DynamicResource ModDetails_MoveModUpTooltip}">
                                <Image Source="{com:Icon Path=/ConanServerManager;component/Art/Up.ico,Size=32}"/>
                            </Button>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellStyle>
                        <Style TargetType="{x:Type DataGridCell}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsFirst}" Value="True">
                                    <Setter Property="Visibility" Value="Hidden" />
                                </DataTrigger>
                                <DataTrigger Binding="{Binding ModDetailsFilterString, ElementName=ModDetailsUI, Converter={StaticResource IsNullOrWhiteSpaceValueConverter}}" Value="False">
                                    <Setter Property="Visibility" Value="Hidden" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </DataGridTemplateColumn.CellStyle>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Width="30" CanUserReorder="False" CanUserResize="False">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Width="22" Height="22" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center" Click="MoveModDown_Click" ToolTip="{DynamicResource ModDetails_MoveModDownTooltip}">
                                <Image Source="{com:Icon Path=/ConanServerManager;component/Art/Down.ico,Size=32}"/>
                            </Button>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellStyle>
                        <Style TargetType="{x:Type DataGridCell}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsLast}" Value="True">
                                    <Setter Property="Visibility" Value="Hidden" />
                                </DataTrigger>
                                <DataTrigger Binding="{Binding ModDetailsFilterString, ElementName=ModDetailsUI, Converter={StaticResource IsNullOrWhiteSpaceValueConverter}}" Value="False">
                                    <Setter Property="Visibility" Value="Hidden" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </DataGridTemplateColumn.CellStyle>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Width="30" CanUserReorder="False" CanUserResize="False">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Width="22" Height="22" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center" Click="RemoveMod_Click" ToolTip="{DynamicResource ModDetails_RemoveModTooltip}">
                                <Image Source="{com:Icon Path=/ConanServerManager;component/Art/Delete.ico,Size=32}"/>
                            </Button>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Width="30" CanUserReorder="False" CanUserResize="False">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Width="22" Height="22" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center" Click="WriteTimestampMod_Click" ToolTip="{DynamicResource ModDetails_WriteTimestampModTooltip}">
                                <Image Source="{com:Icon Path=/ConanServerManager;component/Art/Edit.ico,Size=32}"/>
                            </Button>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellStyle>
                        <Style TargetType="{x:Type DataGridCell}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsValid}" Value="False">
                                    <Setter Property="Visibility" Value="Hidden" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </DataGridTemplateColumn.CellStyle>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>

        <!-- Drag and Drop Popup -->
        <Popup Grid.Row="0" Grid.Column="0" x:Name="popup" IsHitTestVisible="False" Placement="RelativePoint" PlacementTarget="{Binding ElementName=ModDetailsUI}" AllowsTransparency="True">
            <Border BorderBrush="LightSteelBlue" BorderThickness="2" Background="White" Opacity="0.75">
                <StackPanel Orientation="Horizontal" Margin="4,3,8,3">
                    <Image Source="{com:Icon Path=/ConanServerManager;component/Art/Drag.ico,Size=32}"/>
                    <TextBlock FontSize="14" VerticalAlignment="Center" Text="{Binding DraggedItem, ElementName=ModDetailsUI}" Margin="8,0,0,0" />
                </StackPanel>
            </Border>
        </Popup>
    </Grid>
</Window>
