<UserControl x:Class="Valg.EVA.Skanning.Verify.Startup.VerifyBallotPaper.WriteIns.WriteInPageView"
             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:filterControls="clr-namespace:Valg.EVA.Skanning.UserInterfaceElements.FilterControls;assembly=Valg.EVA.Skanning.UserInterfaceElements"
             xmlns:writeIns="clr-namespace:Valg.EVA.Skanning.Verify.Startup.VerifyBallotPaper.WriteIns"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:verifyBallotPaper="clr-namespace:Valg.EVA.Skanning.Verify.Startup.VerifyBallotPaper"
             xmlns:ballotNumber="clr-namespace:Valg.EVA.Skanning.Verify.Startup.VerifyBallotPaper.BallotNumber"
             xmlns:userInterfaceElements="clr-namespace:Valg.EVA.Skanning.UserInterfaceElements;assembly=Valg.EVA.Skanning.UserInterfaceElements"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance d:Type=writeIns:WriteInPageViewModel}">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Valg.EVA.Skanning.Assets;component/ResourceDictionaries/ResourceLibrary.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <StackPanel>
        <ItemsControl ItemsSource="{Binding WriteIns}" verifyBallotPaper:ActiveMainControlManager.IsMainControl="True" IsTabStop="False" Focusable="False">
            <ItemsControl.Template>
                <ControlTemplate>
                    <Border Style="{StaticResource BlueBackgroundBorder}" Padding="25,30,30,30" Width="600" Height="auto" >
                        <StackPanel>
                            <TextBlock Margin="36,0,0,8"                                
                                Text="{Binding VerifyLanguageString.WriteInPage_WriteInToVerifyHeader}"
                                Style="{StaticResource TextBlockMediumHeader}" Foreground="White"
                                Visibility="{Binding NeedsVerification, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                            <TextBlock Margin="36,0,0,8"                           
                                Text="{Binding VerifyLanguageString.WriteInPage_NoneToVerifyHeader}"
                                Style="{StaticResource TextBlockMediumHeader}" Foreground="White"
                                Visibility="{Binding NeedsVerification, Converter={StaticResource InvertedBooleanToVisibilityConverter }}"/>
                            <ItemsPresenter />
                        </StackPanel>
                    </Border>
                </ControlTemplate>
            </ItemsControl.Template>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Grid Margin="0,0,0,0" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="35" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="80" />
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" 
                                   Style="{StaticResource NeedsVerificationIcon}" 
                                   Foreground="White" 
                                   VerticalAlignment="Center"  
                                   HorizontalAlignment="Center"
                                   Visibility="{Binding NeedsVerification, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                        <TextBlock Grid.Column="0"
                                   Style="{StaticResource UserCorrectionHasBeenMadeIcon}"
                                   Foreground="White" 
                                   Visibility="{Binding UserCorrectionHasBeenMade, Converter={StaticResource BooleanToVisibilityConverter}}"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center" />
                        <filterControls:FilteredComboBox
                            Margin="0"
                            HorizontalAlignment="Left"
                            Tag="FocusElement"
                            Grid.Column="1"
                            Text="{Binding Path=CurrentValue}" 
                            SelectedSearchItem="{Binding SelectedSearchItem, Mode=TwoWay}"
                            ValidSearchItems="{Binding DataContext.CandidateList, RelativeSource={ RelativeSource Mode=FindAncestor, AncestorType={x:Type writeIns:WriteInPageView}} }"                
                            IsEnabled="{Binding IgnoreWriteIn, Converter={StaticResource InverseBooleanConverter}}"
                            userInterfaceElements:FocusExtension.IsFocused="{Binding IsWriteInFocused}"
                            DisplayMemberPath="DisplayValue" 
                            SelectedValuePath="SearchValue"
                            MinimumSearchLength="1"
                            Style="{StaticResource ComboBoxFiltered}"
                            Width="430">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="DropDownClosed">
                                    <i:InvokeCommandAction 
                                        Command="{Binding Path=WriteInSelectionFromDropDownCommand}"                                     
                                    CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type filterControls:FilteredComboBox}}}"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </filterControls:FilteredComboBox>
                        <CheckBox Grid.Column="2" 
                                  Margin="10, 0, 0, 0"
                                  VerticalAlignment="Center"
                                  Style="{StaticResource BlueCheckBox}" 
                                  IsChecked="{Binding IgnoreWriteIn}"
                                  Content="{Binding VerifyLanguageString.WriteInPage_IgnoreCheckbox}"
                                  ballotNumber:FocusAdvancement.MovesByEnterKey="{Binding ElementName=NextButtonBlinking}">
                            <CheckBox.InputBindings>
                                <KeyBinding Key="Enter" 
                                    Command="{Binding Path=EnterKeyWasPressedOnIgnoreCheckboxCommand}"/>
                            </CheckBox.InputBindings>
                        </CheckBox>
                    </Grid>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </StackPanel>
</UserControl>
