<UserControl x:Class="Hearthstone_Deck_Tracker.FlyoutControls.DeckEditor.DeckEditorView"
             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:deckEditor="clr-namespace:Hearthstone_Deck_Tracker.FlyoutControls.DeckEditor"
             xmlns:controls="clr-namespace:Hearthstone_Deck_Tracker.Controls"
             xmlns:hearthstoneDeckTracker="clr-namespace:Hearthstone_Deck_Tracker"
             xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:lex="http://wpflocalizeextension.codeplex.com"
             xmlns:system="clr-namespace:System;assembly=mscorlib"
             xmlns:deckEditorEnums="clr-namespace:Hearthstone_Deck_Tracker.FlyoutControls.DeckEditor.Enums"
             xmlns:deckSetIcons="clr-namespace:Hearthstone_Deck_Tracker.Controls.DeckSetIcons"
             mc:Ignorable="d" 
             d:DesignHeight="600" d:DesignWidth="700">
    <UserControl.DataContext>
        <deckEditor:DeckEditorViewModel/>
    </UserControl.DataContext>
    <UserControl.Resources>
        <Style TargetType="ListViewItem">
            <Setter Property="Margin" Value="-4,-3,-3,0"/>
        </Style>
        <ObjectDataProvider x:Key="CostFilterEnum" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="deckEditorEnums:CostFilter"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        <ObjectDataProvider x:Key="ClassFilterEnum" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="deckEditorEnums:ClassFilter"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        <ObjectDataProvider x:Key="SetFilterEnum" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="deckEditorEnums:SetFilter"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        <DataTemplate x:Key="EnumText">
            <TextBlock Text="{Binding Path=., Converter={StaticResource EnumDescriptionConverter}}" />
        </DataTemplate>
    </UserControl.Resources>
    <StackPanel Orientation="Horizontal" Margin="5,0,10,10" HorizontalAlignment="Center">
        <GroupBox Header="{lex:LocTextUpper MainWindow_DeckBuilder_Header_CardDatabase}">
            <DockPanel Width="235">
                <TextBox Name="TextBoxDbInput" Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}" 
                    DockPanel.Dock="Top" mahapps:TextBoxHelper.Watermark="{lex:Loc MainWindow_DeckBuilder_TextBox_Search_Watermark}">
                    <TextBox.InputBindings>
                        <KeyBinding Key="Enter" Command="{Binding AddCardByIndexCommand}" CommandParameter="{Binding SelectedDbIndex}"/>
                        <KeyBinding Key="D1" Command="{Binding AddCardByIndexCommand}" CommandParameter="0"/>
                        <KeyBinding Key="D2" Command="{Binding AddCardByIndexCommand}" CommandParameter="1"/>
                        <KeyBinding Key="D3" Command="{Binding AddCardByIndexCommand}" CommandParameter="2"/>
                        <KeyBinding Key="D4" Command="{Binding AddCardByIndexCommand}" CommandParameter="3"/>
                        <KeyBinding Key="Down" Command="{Binding MoveSelectionCommand}" CommandParameter="1"/>
                        <KeyBinding Key="Up" Command="{Binding MoveSelectionCommand}" CommandParameter="-1"/>
                    </TextBox.InputBindings>
                </TextBox>
                <ListView ItemsSource="{Binding CardDatabase}" Style="{DynamicResource VirtualisedMetroListView}"
                    SelectedIndex="{Binding SelectedDbIndex}" ScrollViewer.VerticalScrollBarVisibility="Visible"
                    ScrollViewer.PanningMode="VerticalOnly"
                    Margin="0,5,0,0" BorderThickness="0">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <controls:Card>
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="PreviewMouseLeftButtonUp">
                                        <i:InvokeCommandAction CommandParameter="{Binding}"
                                            Command="{Binding DataContext.AddCardCommand, RelativeSource={RelativeSource AncestorType=deckEditor:DeckEditorView}}" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </controls:Card>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                    <ListView.InputBindings>
                        <KeyBinding Key="Enter" Command="{Binding AddCardByIndexCommand}" CommandParameter="{Binding SelectedDbIndex}"/>
                    </ListView.InputBindings>
                </ListView>
            </DockPanel>
        </GroupBox>
        <GroupBox Header="{lex:LocTextUpper MainWindow_DeckBuilder_Header_Deck}" Margin="10,5,5,5">
            <DockPanel Width="235">
                <Border MinHeight="26" BorderThickness="1" BorderBrush="{DynamicResource TextBrush}" DockPanel.Dock="Top">
                    <DockPanel>
                        <StackPanel DockPanel.Dock="Left" Orientation="Horizontal" VerticalAlignment="Top" Margin="0,3">
                            <TextBlock Text="{lex:LocTextUpper MainWindow_DeckBuilder_Label_Cards}" VerticalAlignment="Center" FontWeight="SemiBold" FontSize="14" Margin="5,0,0,0"/>
                            <TextBlock VerticalAlignment="Center" Text="{Binding CardCount}" FontWeight="SemiBold" FontSize="14" Margin="5,0,0,0"/>
                        </StackPanel>
                        <deckSetIcons:DeckSetIconsView x:Name="DeckSetIcons" Margin="2,4,2,2" Fill="{DynamicResource TextBrush}" HorizontalContentAlignment="Right" />
                    </DockPanel>
                </Border>
                <hearthstoneDeckTracker:ManaCurve x:Name="ManaCurve" DockPanel.Dock="Bottom" Height="150" />
                <ListView ItemsSource="{Binding Cards}" ScrollViewer.VerticalScrollBarVisibility="Visible"
                          ScrollViewer.CanContentScroll="False"
                          ScrollViewer.HorizontalScrollBarVisibility="Disabled"  Margin="0,5" BorderThickness="0">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <controls:Card>
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="PreviewMouseLeftButtonUp">
                                        <i:InvokeCommandAction CommandParameter="{Binding}"
                                            Command="{Binding DataContext.RemoveCardCommand, RelativeSource={RelativeSource AncestorType=deckEditor:DeckEditorView}}" />
                                    </i:EventTrigger>
                                    <i:EventTrigger EventName="PreviewMouseRightButtonUp">
                                        <i:InvokeCommandAction CommandParameter="{Binding}"
                                            Command="{Binding DataContext.AddCardCommand, RelativeSource={RelativeSource AncestorType=deckEditor:DeckEditorView}}" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </controls:Card>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ListView>
            </DockPanel>
        </GroupBox>
        <StackPanel Margin="5,0,0,0">
            <GroupBox Header="{lex:LocTextUpper MainWindow_DeckBuilder_Header_Filters}">
                <StackPanel Width="235">
                    <CheckBox IsChecked="{Binding ConstructedCardLimits}" Margin="2" Visibility="{Binding ConstructedCardLimitsVisibility}">
                        <TextBlock Text="{lex:Loc MainWindow_DeckBuilder_CheckBox_CardLimit}" TextWrapping="Wrap"/>
                    </CheckBox>
                    <CheckBox IsChecked="{Binding IncludeWild}" Margin="2">
                        <TextBlock Text="{lex:Loc MainWindow_DeckBuilder_CheckBox_IncludeWild}" TextWrapping="Wrap"/>
                    </CheckBox>
                    <CheckBox IsChecked="{Binding FullTextSearch}" Margin="2">
                        <TextBlock Text="{lex:Loc MainWindow_DeckBuilder_Label_SearchCardText}" TextWrapping="Wrap"/>
                    </CheckBox>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="10"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Label Grid.Column="0" Grid.Row="0" Content="{lex:Loc MainWindow_DeckBuilder_Filter_Cost}" Margin="0,5,0,0"/>
                        <Label Grid.Column="0" Grid.Row="1" Content="{lex:Loc MainWindow_DeckBuilder_Filter_Type}" Margin="0,5,0,0"/>
                        <Label Grid.Column="0" Grid.Row="2" Content="{lex:Loc MainWindow_DeckBuilder_Filter_Set}" Margin="0,5,0,0"/>
                        <ComboBox Grid.Column="2" Grid.Row="0" Margin="0,5,0,0" ItemsSource="{Binding Source={StaticResource CostFilterEnum}}"
                            SelectedItem="{Binding SelectedCostFilter}"  ItemTemplate="{Binding Source={StaticResource EnumText}}"/>
                        <ComboBox Grid.Column="2" Grid.Row="1" Margin="0,5,0,0" ItemsSource="{Binding Source={StaticResource ClassFilterEnum}}"
                            SelectedItem="{Binding SelectedClassFilter}" ItemTemplate="{Binding Source={StaticResource EnumText}}"/>
                        <ComboBox Grid.Column="2" Grid.Row="2" Margin="0,5,0,0" ItemsSource="{Binding Source={StaticResource SetFilterEnum}}"
                            SelectedItem="{Binding SelectedSetFilter}" ItemTemplate="{Binding Source={StaticResource EnumText}}"/>
                    </Grid>
                </StackPanel>
            </GroupBox>
            <StackPanel Margin="5">
                <TextBox Text="{Binding DeckName, UpdateSourceTrigger=PropertyChanged, Delay=100}" DockPanel.Dock="Top" mahapps:TextBoxHelper.Watermark="{lex:Loc MainWindow_DeckBuilder_TextBox_Name_Watermark}" />
                <ComboBox ItemsSource="{Binding SaveOperations}" SelectedItem="{Binding SelectedSaveOperation}" Visibility="{Binding SaveOperationSelectionVisibility}" Margin="0,5,0,0"/>
                <Button Style="{DynamicResource AccentedSquareButtonStyle}" Margin="0,5,0,0" Command="{Binding SaveCommand}" IsEnabled="{Binding CanSave}">
                    <TextBlock Text="{lex:LocTextUpper MainWindow_DeckBuilder_Button_Save}"/>
                </Button>
                <ItemsControl ItemsSource="{Binding ErrorMessages}" Margin="0,5,0,0">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Rectangle Width="12" Height="12" Margin="0,0,5,0">
                                    <Rectangle.Fill>
                                        <VisualBrush Visual="{StaticResource appbar_warning_circle}" />
                                    </Rectangle.Fill>
                                </Rectangle>
                                <TextBlock TextWrapping="Wrap" Foreground="Red">
                                    <Run Text="{Binding Path=., Mode=OneWay}"/>
                                </TextBlock>
                            </StackPanel>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
                <ItemsControl ItemsSource="{Binding WarningMessages}" Margin="0,5,0,0">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Rectangle Width="12" Height="12" Margin="0,0,5,0">
                                    <Rectangle.Fill>
                                        <VisualBrush Visual="{StaticResource appbar_warning}" />
                                    </Rectangle.Fill>
                                </Rectangle>
                                <TextBlock Text="{Binding Path=., Mode=OneWay}" TextWrapping="Wrap" Foreground="Yellow"/>
                            </StackPanel>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </StackPanel>
        </StackPanel>
    </StackPanel>
</UserControl>
