<mah:MetroWindow x:Class="FFXIV_TexTools.Views.ModListView"
        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:FFXIV_TexTools.Views"
        xmlns:vms="clr-namespace:FFXIV_TexTools.ViewModels"
        xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
        xmlns:models="clr-namespace:FFXIV_TexTools.Models"
        xmlns:resx="clr-namespace:FFXIV_TexTools.Resources"
        resx:Localization.Enabled="True"
        mc:Ignorable="d"
        Title="{Binding Source={x:Static resx:UIStrings.Mod_List}}" Height="700" Width="900" ShowMaxRestoreButton="False" ShowMinButton="False" WindowStartupLocation="CenterOwner" Closed="MetroWindow_Closed">
    <mah:MetroWindow.DataContext>
        <vms:ModListViewModel/>
    </mah:MetroWindow.DataContext>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition Width="2*"/>
        </Grid.ColumnDefinitions>
        <GroupBox Grid.Column="0" Header="{Binding Source={x:Static resx:UIStrings.Modded_Items}}" Margin="5">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid Grid.Row="0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <Label Content="{Binding Source={x:Static resx:UIStrings.Filter_By_colon}}"></Label>
                    <RadioButton Grid.Column="1" Content="{Binding Source={x:Static resx:UIStrings.Item}}" GroupName="Lights" Margin="5" IsChecked="{Binding ItemFilter}"/>
                    <RadioButton Grid.Column="2" Content="{Binding Source={x:Static resx:UIStrings.Mod_Pack}}" GroupName="Lights" Margin="5" IsChecked="{Binding ModPackFilter}"/>
                    <Label Content="{Binding Source={x:Static resx:UIStrings.Sort_By_colon}}" Margin="0,22,0,-22"></Label>
                    <RadioButton Grid.Column="1" Content="{Binding Source={x:Static resx:UIStrings.Name}}" GroupName="Sort" Margin="5,28,5,-18" IsChecked="{Binding NameSort}"/>
                    <RadioButton Grid.Column="2" Content="{Binding Source={x:Static resx:UIStrings.Date}}" GroupName="Sort" Margin="5,28,5,-18" IsChecked="{Binding DateSort}"/>
                </Grid>
                <TreeView x:Name="ModListTreeView" Grid.Row="1" ItemsSource="{Binding Categories}" SelectedItemChanged="TreeView_SelectedItemChanged" Style="{StaticResource VirtualisedMetroTreeView}" Margin="0,28,0,0">
                    <TreeView.ItemContainerStyle>
                        <Style TargetType="{x:Type TreeViewItem}">
                            <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
                        </Style>
                    </TreeView.ItemContainerStyle>
                    <TreeView.Resources>
                        <HierarchicalDataTemplate ItemsSource="{Binding Categories}" DataType="{x:Type models:Category}">
                            <StackPanel>
                                <TextBlock Text="{Binding Name}"/>
                            </StackPanel>
                        </HierarchicalDataTemplate>
                    </TreeView.Resources>
                </TreeView>
            </Grid>
        </GroupBox>

        <Grid Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="9*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <GroupBox Grid.Row="0" Header="{Binding Source={x:Static resx:UIStrings.Previe_List}}" Margin="5">
                <Grid>
                    <ListView x:Name="ModItemList" ItemsSource="{Binding ModListPreviewList}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectionChanged="ListBox_SelectionChanged" BorderThickness="0" BorderBrush="{x:Null}" Visibility="{Binding ListVisibility}">
                        <ListBox.ItemContainerStyle>
                            <Style TargetType="ListBoxItem">
                                <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
                            </Style>
                        </ListBox.ItemContainerStyle>
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <Border BorderBrush="{Binding ActiveBorder}" BorderThickness="2" Background="{Binding Active}" Opacity="{Binding ActiveOpacity}" ToolTip="{Binding Path=FilePath}" HorizontalAlignment="Stretch">

                                    <Border.ContextMenu>
                                        <ContextMenu>
                                            <MenuItem Header="View/Edit File" Click="OpenFile_Click">
                                            </MenuItem>
                                            <MenuItem Click="CopyPath_Click">
                                                <MenuItem.Header>
                                                    <TextBlock>
                                                            <Run>Copy Path: </Run> 
                                                            <Run Text="{Binding Path=FilePath}"></Run>
                                                    </TextBlock>
                                                </MenuItem.Header>
                                            </MenuItem>
                                        </ContextMenu>
                                    </Border.ContextMenu>

                                    <Grid HorizontalAlignment="Stretch">
                                        <Grid.RowDefinitions>
                                            <RowDefinition/>
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="120"/>
                                            <ColumnDefinition Width="1*"/>
                                        </Grid.ColumnDefinitions>

                                        <!-- Preview Image -->
                                        <Grid Margin="2" Grid.Row="0" Grid.Column="0" Width="76" Height="76">
                                            <Image Source="{Binding Image}" MaxWidth="76" MaxHeight="76" VerticalAlignment="Center" HorizontalAlignment="Center"  RenderOptions.BitmapScalingMode="NearestNeighbor"/>
                                        </Grid>

                                        <Grid Grid.Column="1">
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="28"/>
                                                <RowDefinition Height="28"/>
                                                <RowDefinition Height="28"/>
                                            </Grid.RowDefinitions>

                                            <Border Grid.Row="0" BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" BorderThickness="1">
                                                <TextBlock Margin="5,0" VerticalAlignment="Center">
                                                    <Run Text="{Binding ItemName}"/>
                                                    <Run Text=" - "/>
                                                    <Run Text="{Binding FileName}"/>
                                                </TextBlock>
                                            </Border>

                                            <Border Grid.Row="1" BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" BorderThickness="1">
                                                <TextBlock Margin="5,0" VerticalAlignment="Center">
                                                    <Run Text="{Binding Type}"/>
                                                    <Run Text=" - "/>
                                                    <Run Text="{Binding Race}"/>
                                                    <Run Text=" - "/>
                                                    <Run Text="{Binding Material}"/>
                                                </TextBlock>
                                            </Border>

                                            <Border Grid.Row="2" BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" BorderThickness="1">
                                                <TextBlock Margin="5,0" VerticalAlignment="Center">
                                                    <Run Text="{Binding FilePath}"/>
                                                </TextBlock>
                                            </Border>
                                        </Grid>
                                    </Grid>
                                    
                                </Border>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                    <Grid Visibility="{Binding InfoGridVisibility}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Grid Grid.Column="0">
                            <StackPanel>
                                <Label Content="{Binding ModPackTitle, FallbackValue='ModPack Title'}" MinWidth="80" HorizontalAlignment="Left" FontWeight="Bold"/>
                                <StackPanel Orientation="Horizontal">
                                    <Label Content="{Binding Source={x:Static resx:UIStrings.Author_colon}}" MinWidth="80"/>
                                    <Label Content="{Binding ModPackModAuthorLabel, FallbackValue='0'}" FontWeight="Bold"/>
                                </StackPanel>
                                <StackPanel Orientation="Horizontal">
                                    <Label Content="{Binding Source={x:Static resx:UIStrings.Mod_Count_colon}}" MinWidth="80"/>
                                    <Label Content="{Binding ModPackModCountLabel, FallbackValue='0'}" FontWeight="Bold"/>
                                </StackPanel>
                                <StackPanel Orientation="Horizontal">
                                    <Label Content="{Binding Source={x:Static resx:UIStrings.Version_colon}}" MinWidth="80"/>
                                    <Label Content="{Binding ModPackModVersionLabel, FallbackValue='1.0'}" FontWeight="Bold"/>
                                </StackPanel>
                            </StackPanel>
                        </Grid>
                        <Grid Grid.Column="1">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <Label Grid.Row="0" Content="{Binding Source={x:Static resx:UIStrings.Mod_Pack_Content}}"/>
                                <TextBox Grid.Row="1" TextWrapping="NoWrap" Text="{Binding ModPackContentList}" HorizontalScrollBarVisibility="Visible" IsReadOnly="True"/>
                            </Grid>
                        </Grid>
                    </Grid>
                </Grid>
            </GroupBox>
            <mah:MetroProgressBar Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="7" Width="100" Height="20" Value="{Binding ProgressValue}"/>
            <Label Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="7" Width="100" Height="20" Content="{Binding ProgressText}" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontWeight="Bold"/>
            <Grid Margin="10" Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Button x:Name="modToggleButton" Content="{Binding ModToggleText}" Margin="10,0" IsEnabled="False" Click="modToggleButton_Click"/>
                <Button x:Name="modDeleteButton" Content="{Binding Source={x:Static resx:UIStrings.Delete}}" Grid.Column="1" Margin="10,0" IsEnabled="False" Click="modDeleteButton_Click"/>
            </Grid>
        </Grid>
    </Grid>
</mah:MetroWindow>
