<ui:ContextAwareControl x:Class="Valg.EVA.Skanning.JobManagement.Startup.UI.PollingDistrict.PollingDistrictView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:ui="clr-namespace:Valg.EVA.Skanning.JobManagement.Startup.UI"
             xmlns:transferOverview="clr-namespace:Valg.EVA.Skanning.JobManagement.Startup.UI.TransferOverview"
             xmlns:counting="clr-namespace:Valg.EVA.Skanning.JobManagement.Startup.UI.Counting"
             xmlns:pollingDistrict="clr-namespace:Valg.EVA.Skanning.JobManagement.Startup.UI.PollingDistrict"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance d:Type=pollingDistrict:PollingDistrictViewModel}"
             PollingDistrict="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ui:ContextAwareControl}}, Path=PollingDistrict}"
             VotingCategoryType="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ui:ContextAwareControl}}, Path=VotingCategoryType}"
                        IsTabStop="False">
    <Grid Visibility="{Binding IsVisible, Converter={StaticResource BooleanToVisibilityConverter}}">
        <DockPanel>
            <ToggleButton DockPanel.Dock="Top"
                          Style="{StaticResource BlackAndBlueToggleButton}"
                          Height="40px"
                          IsChecked="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=Explicit}"
                          Command="{Binding ShowDetailsCommand}" Visibility="{Binding HasOnlyOnePollingDistrict, Converter={StaticResource InvertedBooleanToVisibilityConverter}}">
                <ToggleButton.Content>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <TextBlock Style="{StaticResource PlayArrowIcon}" VerticalAlignment="Center" Foreground="White" Margin="15,0,15,0" 
                                   Visibility="{Binding IsChecked, Converter={StaticResource InvertedBooleanToVisibilityConverter}}"/>
                        <TextBlock Style="{StaticResource DownArrowIcon}" VerticalAlignment="Center" Foreground="White" Margin="15,0,15,0" 
                                   Visibility="{Binding IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                        <TextBlock Text="{Binding DisplayName}" VerticalAlignment="Center" Style="{StaticResource TextBlockNormal}" Foreground="White" />
                    </StackPanel>
                </ToggleButton.Content>
            </ToggleButton>
            <StackPanel DockPanel.Dock="Top" Visibility="{Binding ShowPollingDistrictContent, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="15">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition MinWidth="630" Width="Auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <StackPanel Grid.Column="0" Margin="0,0,10,0">
                        <StackPanel Visibility="{Binding HasCounting, Converter={StaticResource BooleanToVisibilityConverter}}">
                            <TextBlock Text="{Binding JobManagementLanguageString.PollingDistrict_ItemTitle}" Style="{StaticResource TextBlockMediumHeader}" />
                            <ItemsControl IsTabStop="False" ItemsSource="{Binding Countings}">
                                <ItemsControl.Template>
                                    <ControlTemplate TargetType="ItemsControl">
                                        <StackPanel>
                                            <Rectangle Height="1" Stroke="Black" Margin="0,5,0,0" HorizontalAlignment="Stretch"/>
                                            <ItemsPresenter Margin="0, 10, 0, 0" />
                                        </StackPanel>
                                    </ControlTemplate>
                                </ItemsControl.Template>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <counting:CountingView DataContext="{Binding}"/>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </StackPanel>
                        <counting:StartCountingButtonView HorizontalAlignment="Left"
                                                          Margin="5,10,0,0"
                                                          Visibility="{Binding DataContext.AreAllCountingsComplete, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type pollingDistrict:PollingDistrictView}}, 
                                                                        Converter={StaticResource BooleanToVisibilityConverter}}"
                                                          DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=StartCountingButtonViewModel}"
                                                          VotingCategoryType="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ui:ContextAwareControl}}, Path=VotingCategoryType}"            
                                                          PollingDistrict="{Binding DataContext.ActivePollingDistrict, RelativeSource={ RelativeSource Mode=FindAncestor, AncestorType={x:Type pollingDistrict:PollingDistrictView}}}" />
                    </StackPanel>
                    <StackPanel Grid.Column="2" Visibility="{Binding HasCounting, Converter={StaticResource BooleanToVisibilityConverter}}" >
                        <transferOverview:TransferOverviewView DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=TransferOverviewViewModel}" Height="Auto" Width="Auto" />
                    </StackPanel>
                </Grid>
            </StackPanel>
        </DockPanel>
    </Grid>
</ui:ContextAwareControl>

