<UserControl x:Class="WowUp.WPF.Views.GetAddonsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
             xmlns:local="clr-namespace:WowUp.WPF.Views"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary >
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Styles.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            <Style x:Key="HyperlinkStyle" TargetType="Hyperlink">
                <Setter Property="Foreground" Value="White" />
                <Setter Property="TextDecorations" Value="None" />
            </Style>
            
            <DataTemplate x:Key="AddonColumnTemplate" >
                <Border Padding="10">
                    <Grid Background="Transparent">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <StackPanel Grid.Column="0" Margin="0, 0, 10, 0" VerticalAlignment="Center">
                            <Border Background="{StaticResource Dark2}"  >
                                <Image Source="{Binding ThumbnailUrl, Converter={StaticResource UriToThumbnailConverter}}" Width="40" Height="40" />
                            </Border>
                        </StackPanel>
                        <StackPanel Grid.Column="1" VerticalAlignment="Center">
                            <TextBlock Visibility="{Binding ExternalUrl, Converter={StaticResource StringToVisibilty}}" 
                                       Style="{StaticResource labelAddonName}" >
                                <Hyperlink x:Name="AddonLink"
                                           Style="{StaticResource HyperlinkStyle}"
                                           NavigateUri="{Binding ExternalUrl}"
                                           Command="{Binding OpenLinkCommand}">
                                    <TextBlock Text="{Binding Name}" TextWrapping="Wrap"/>
                                </Hyperlink>    
                            </TextBlock>
                            <TextBlock Visibility="{Binding ExternalUrl, Converter={StaticResource InverseStringToVisibilty}}"
                                       Text="{Binding Name}"  
                                       Style="{StaticResource labelAddonName}" 
                                       TextWrapping="Wrap"/>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding DownloadCount}" 
                                           Foreground="{StaticResource White3Brush}"
                                           Style="{StaticResource labelAddonText}" />
                                <TextBlock Text="{Binding ProviderName}"
                                           Margin="10 0 0 0"
                                           Foreground="{StaticResource White3Brush}"
                                           Style="{StaticResource labelAddonText}" />
                            </StackPanel>
                        </StackPanel>
                    </Grid>
                </Border>
            </DataTemplate>

            <DataTemplate x:Key="AuthorTemplate" >
                <Border Padding="10">
                    <Grid Background="Transparent">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <StackPanel Grid.Column="0" VerticalAlignment="Center">
                            <TextBlock Text="{Binding Author}" 
                                       TextWrapping="Wrap"
                                       Style="{StaticResource labelAddonText}" />
                        </StackPanel>
                    </Grid>
                </Border>
            </DataTemplate>
            
            <DataTemplate x:Key="ProviderTemplate" >
                <Border Padding="10">
                    <StackPanel VerticalAlignment="Center">
                        <TextBlock Text="{Binding ProviderName}" 
                                    TextWrapping="Wrap"
                                    Style="{StaticResource labelAddonText}" />
                    </StackPanel>
                </Border>
            </DataTemplate>

            <DataTemplate x:Key="StatusColumnTemplate" >
                <Border Padding="10">
                    <StackPanel VerticalAlignment="Center">
                        <StackPanel>
                            <TextBlock Text="Installed"
                                       HorizontalAlignment="Center"
                                       Visibility="{Binding IsInstalled, Converter={StaticResource BoolToVisibilty}}" />
                        </StackPanel>
                        <Button Visibility="{Binding ShowInstallButton, Converter={StaticResource BoolToVisibilty}}"
                                Style="{StaticResource purpleButton}"
                                Command="{Binding InstallCommand}">Install</Button>
                        <StackPanel >
                            <TextBlock Visibility="{Binding ShowProgressText, Converter={StaticResource BoolToVisibilty}}"
                                       Text="{Binding ProgressText}" 
                                       Style="{StaticResource labelAddonText}"
                                       HorizontalAlignment ="Center"/>
                            <ProgressBar Visibility="{Binding ShowProgressBar, Converter={StaticResource BoolToVisibilty}}"
                                         Minimum="0" Maximum="100" Value="{Binding InstallProgress}" />
                        </StackPanel>
                    </StackPanel>
                </Border>
            </DataTemplate>
            
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid Background="{StaticResource Dark3}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <!--MENU BAR-->
        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Border Grid.Column="0" Padding="10">
                <StackPanel  Orientation="Horizontal">
                    <TextBlock Text="World of Warcraft" FontSize="14" Foreground="White" VerticalAlignment="Center" Margin="0, 0, 10,0"/>
                    <ComboBox x:Name="WowClientComboBox"
                              SelectedItem="{Binding SelectedClientType}"
                              IsEnabled="{Binding IsBusy, Converter={StaticResource InverseBool}}"
                              Style="{StaticResource ComboBoxFlatStyle}"
                              ItemsSource="{Binding ClientTypeNames}">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="SelectionChanged">
                                <i:InvokeCommandAction Command="{Binding SelectedWowClientCommand}" 
                                                      CommandParameter="{Binding ElementName=WowClientComboBox, Path=SelectedValue}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </ComboBox>
                </StackPanel>
            </Border>
            <Border Grid.Column="1" Padding="10">
                <StackPanel  Orientation="Horizontal">
                    <Button Style="{StaticResource purpleButton}" Margin="0 0 10 0" Command="{Binding RefreshCommand}">Refresh</Button>
                    <Button Style="{StaticResource purpleButton}" Margin="0 0 10 0" Command="{Binding InstallNewCommand}">Install From URL</Button>
                    <local:SearchInput Width="150" VerticalAlignment="Center" DataContext="{Binding SearchInputViewModel}"/>
                </StackPanel>
            </Border>
        </Grid>
        <!--DATA GRID-->
        <DataGrid Grid.Row="1"
                  ItemsSource="{Binding DisplayAddons}"
                  AutoGenerateColumns="False" 
                  GridLinesVisibility="Horizontal"       
                  CanUserReorderColumns="False"
                  HorizontalGridLinesBrush="{StaticResource Dark2}"
                  BorderBrush="Transparent"
                  BorderThickness="0"
                  VirtualizingPanel.ScrollUnit="Pixel"
                  IsReadOnly="True">
            <DataGrid.Resources>
                <Style TargetType="{x:Type DataGrid}">
                    <Setter Property="Background" Value="{StaticResource Dark3}"/>
                </Style>
                <Style TargetType="{x:Type DataGridRow}">
                    <Setter Property="Background" Value="{StaticResource Dark3}"/>
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="{StaticResource Dark1}" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
                <Style TargetType="{x:Type DataGridRowHeader}">
                    <Setter Property="Background" Value="{StaticResource Dark3}"/>
                </Style>
                <Style TargetType="{x:Type DataGridCell}">
                    <Style.Triggers>
                        <Trigger Property="DataGridCell.IsSelected" Value="True">
                            <Setter Property="BorderBrush" Value="Transparent"/>
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                            <Setter Property="Background" Value="Transparent"/>
                        </Trigger>

                    </Style.Triggers>
                </Style>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="Background" Value="{StaticResource Dark2}"/>
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <Border Padding="5">
                                    <TextBlock Text="{Binding}" TextWrapping="Wrap" Style="{StaticResource labelTableHeader}"/>
                                </Border>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </DataGrid.Resources>
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="Addon" CellTemplate="{StaticResource AddonColumnTemplate}" Width="*" />
                <DataGridTemplateColumn Header="Author" CellTemplate="{StaticResource AuthorTemplate}" Width="150" MinWidth="150"  CanUserResize="True" />
                <DataGridTemplateColumn Header="Provider" CellTemplate="{StaticResource ProviderTemplate}" Width="Auto" MinWidth="80" CanUserResize="False" />
                <DataGridTemplateColumn Header="Status" CellTemplate="{StaticResource StatusColumnTemplate}" Width="120" CanUserResize="False"/>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</UserControl>
