<UserControl x:Class="Hearthstone_Deck_Tracker.Windows.MainWindowControls.DeckChartsView"
             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:local="clr-namespace:Hearthstone_Deck_Tracker.Windows.MainWindowControls"
             xmlns:wpf="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
             xmlns:converters="clr-namespace:Hearthstone_Deck_Tracker.Utility.Converters"
             xmlns:lex="http://wpflocalizeextension.codeplex.com"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="400">
    <UserControl.Resources>
        <converters:GameStatsHasReplayConverter x:Key="CanViewReplayConverter" />
        <converters:LocalizationConverter x:Key="LocalizationConverter" />
    </UserControl.Resources>
    <UserControl.DataContext>
        <local:DeckChartsViewModel/>
    </UserControl.DataContext>
    <Grid>
        <DockPanel Visibility="{Binding HasData, Converter={StaticResource BoolToVisibility}}">
            <Grid HorizontalAlignment="Center" DockPanel.Dock="Top" Width="360" Margin="0,0,0,5"
                  Visibility="{Binding Deck.IsDungeonDeck, Converter={StaticResource InverseBoolToVisibility}}">
                <StackPanel HorizontalAlignment="Left">
                    <!--
                        FlowDirection="RightToLeft" to make resizing based on legend work properly with LegendLocation="Right"
                        LocalizedChartLegend sets FlowDirection="LeftToRight" again
                    -->
                    <wpf:PieChart DataTooltip="{x:Null}" Hoverable="False" Width="250" Height="230" 
                        Series="{Binding OpponentCollection}" StartingRotationAngle="0" LegendLocation="Right" FlowDirection="RightToLeft">
                        <wpf:PieChart.ChartLegend>
                            <local:LocalizedChartLegend/>
                        </wpf:PieChart.ChartLegend>
                    </wpf:PieChart>
                </StackPanel>
                <StackPanel Margin="0,10,0,0" HorizontalAlignment="Right">
                    <TextBlock FontWeight="SemiBold" TextAlignment="Center" Margin="0,10,0,0">
                        <Run Text="{lex:Loc DeckCharts_Label_Wins}"/>
                        <Run Text="{Binding Wins}"/>
                    </TextBlock>
                    <TextBlock FontWeight="SemiBold" TextAlignment="Center" Margin="0,2,0,10">
                        <Run Text="{lex:Loc DeckCharts_Label_Losses}"/>
                        <Run Text="{Binding Losses}"/>
                    </TextBlock>
                    <Grid VerticalAlignment="Top">
                        <TextBlock Style="{StaticResource WinrateGaugeTextStyle}">
                            <Run Text="{Binding WinrateTotal}"/>%
                            <LineBreak/>
                            <Run Text="{lex:LocTextUpper DeckCharts_Label_Winrate}" FontSize="10" />
                        </TextBlock>
                        <wpf:Gauge Value="{Binding WinrateTotal}" Style="{StaticResource WinrateGaugeStyle}"/>
                    </Grid>
                </StackPanel>
            </Grid>
            <ScrollViewer>
                <ItemsControl ItemsSource="{Binding Games, IsAsync=True}">
                    <ItemsControl.Resources>
                        <Style TargetType="TextBlock">
                            <Setter Property="VerticalAlignment" Value="Center"/>
                            <Setter Property="FontWeight" Value="SemiBold"/>
                        </Style>
                    </ItemsControl.Resources>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Border Name="ItemBorder"  BorderThickness="0,0,0,1" BorderBrush="{DynamicResource MenuItemDisabledBrush}">
                                <Grid Cursor="Hand" Height="35" IsEnabled="{Binding Converter={StaticResource CanViewReplayConverter}, Path=.}">
                                    <Grid.InputBindings>
                                        <MouseBinding MouseAction="LeftClick" Command="{Binding Source={StaticResource GlobalCommands}, Path=OpenReplay}"
                                            CommandParameter="{Binding}"/>
                                    </Grid.InputBindings>
                                    <Grid.Style>
                                        <Style TargetType="Grid">
                                            <Setter Property="Background" Value="Transparent"></Setter>
                                            <Style.Triggers>
                                                <Trigger Property="IsMouseOver" Value="True">
                                                    <Setter Property="Background" Value="{DynamicResource AccentColorBrush4}"/>
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Grid.Style>
                                    <Grid.Resources>
                                        <Style TargetType="TextBlock">
                                            <Setter Property="VerticalAlignment" Value="Center"/>
                                            <Setter Property="FontWeight" Value="SemiBold"/>
                                        </Style>
                                    </Grid.Resources>
                                    <DockPanel HorizontalAlignment="Left" Width="140">
                                        <TextBlock Margin="7,0,0,0" Text="{Binding VersusLabel}" DockPanel.Dock="Left"/>
                                        <Image Source="{Binding OpponentHeroImage}" Width="28" Height="28" RenderOptions.BitmapScalingMode="Fant" Margin="5,0,0,0" DockPanel.Dock="Left"/>
                                        <TextBlock Text="{Binding OpponentHero, Converter={StaticResource LocalizationConverter}}" Margin="5,0,0,0" TextTrimming="CharacterEllipsis"/>
                                    </DockPanel>
                                    <TextBlock Margin="5,0,0,0" HorizontalAlignment="Center">
                                        <Run Text="{Binding Result, Converter={StaticResource EnumDescriptionConverter}}" Foreground="{Binding ResultTextColor}"/>
                                    </TextBlock>
                                    <StackPanel Margin="5,0,0,0" HorizontalAlignment="Right" Orientation="Horizontal">
                                        <TextBlock Text="{Binding Age}" FontWeight="SemiBold" VerticalAlignment="Center" />
                                        <Grid Width="15" DockPanel.Dock="Right" Margin="5,0,0,0">
                                            <TextBlock Text="✓" ToolTip="{Binding UploadedTooltip}" Foreground="Green" 
                                                Visibility="{Binding HsReplay.Uploaded, Converter={StaticResource BoolToVisibility}}" />
                                            <TextBlock Text="✗" ToolTip="{Binding NoReplayDataTooltip}" Foreground="Red" ToolTipService.ShowOnDisabled="True"
                                                Visibility="{Binding IsEnabled, RelativeSource={RelativeSource AncestorType=Grid}, Converter={StaticResource InverseBoolToVisibility}}" />
                                        </Grid>
                                    </StackPanel>
                                </Grid>
                            </Border>
                            <DataTemplate.Triggers>
                                <DataTrigger Binding="{Binding RelativeSource={RelativeSource PreviousData}}" Value="{x:Null}">
                                    <Setter TargetName="ItemBorder" Property="BorderThickness" Value="0,1"/>
                                </DataTrigger>
                            </DataTemplate.Triggers>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>
        </DockPanel>
        <Grid Visibility="{Binding HasData, Converter={StaticResource InverseBoolToVisibility}}">
            <Image Source="{StaticResource AppIcon}" Width="256" Height="256" Opacity="0.05"/> 
            <Grid VerticalAlignment="Center">
                <Grid.Resources>
                    <Style TargetType="TextBlock">
                        <Setter Property="Foreground" Value="Gray"></Setter>
                        <Setter Property="TextAlignment" Value="Center"></Setter>
                    </Style>
                </Grid.Resources>
                <TextBlock Visibility="{Binding HasDeck, Converter={StaticResource BoolToVisibility}}">
                    <Run Text="{lex:Loc DeckCharts_Label_NoData}" />
                    <LineBreak/>
                    <Run Text="{lex:Loc DeckCharts_Label_PlaySomeGames}"/>
                </TextBlock>
                <TextBlock Text="{lex:Loc DeckCharts_Label_NoSelectedDeck}"
                    Visibility="{Binding HasDeck, Converter={StaticResource InverseBoolToVisibility}}">
                </TextBlock>
            </Grid>
        </Grid>
    </Grid>
</UserControl>
