<UserControl x:Class="Valg.EVA.Skanning.UserInterfaceElements.TopBar.TopBar"
             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:commands="clr-namespace:Valg.EVA.Skanning.UserInterfaceElements.Commands"
             xmlns:topBar="clr-namespace:Valg.EVA.Skanning.UserInterfaceElements.TopBar"
             xmlns:language="clr-namespace:Valg.EVA.Skanning.Resources.Language;assembly=Valg.EVA.Skanning.Resources"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance d:Type=topBar:TopBarViewModel}">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Valg.EVA.Skanning.Assets;component/ResourceDictionaries/ResourceLibrary.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <Style BasedOn="{StaticResource LinkButtonNormal}" TargetType="Button">
                <Setter Property="Margin" Value="0,0,20,0" />
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>
    <UserControl.Template>
        <ControlTemplate>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="10" />
                    <RowDefinition Height="5" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="2" />
                </Grid.RowDefinitions>
                <StackPanel Grid.Row="0" Background="Black" HorizontalAlignment="Stretch"/>
                <StackPanel Grid.Row="1" Background="#A29061" HorizontalAlignment="Stretch" Margin="50,0,50,0"/>
                <StackPanel Grid.Row="2" Margin="50,0,50,0">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="1" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <Grid Grid.Row="0" Grid.Column="0" Margin="0,5,0,10" Height="auto" >
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Button Grid.Column="0" Command="{Binding GoToHomePageCommand}" IsTabStop="False" Visibility="{Binding IsPrerelease, Converter={StaticResource InvertedBooleanToVisibilityConverter}}">
                                <Button.Template>
                                    <ControlTemplate>
                                        <Image Style="{StaticResource ElectionLogo}"/>
                                    </ControlTemplate>
                                </Button.Template>
                            </Button>

                            <Button Grid.Column="0" Command="{Binding GoToHomePageCommand}" IsTabStop="False" Visibility="{Binding IsPrerelease, Converter={StaticResource BooleanToVisibilityConverter}}" >
                                <Button.Template>
                                    <ControlTemplate>
                                        <Image Style="{StaticResource ElectionLogoPrerelease}"/>
                                    </ControlTemplate>
                                </Button.Template>
                            </Button>
                            <topBar:BoxCountingInformationView DataContext="{Binding BoxCountingInformationViewModel}" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,10,0,0" />
                        </Grid>

                        <StackPanel Grid.Row="0" Grid.Column="1" Margin="0,10,0,10">
                            <Line  X1="0" Y1="0" X2="0" Y2="75" Stroke="Black" StrokeDashArray="1 1" StrokeThickness="1"/>
                        </StackPanel>

                        <StackPanel Grid.Row="0" Grid.Column="2" Orientation="Vertical" Style="{StaticResource StackPanelHeaderBackground}">
                            <StackPanel Orientation="Vertical" VerticalAlignment="Bottom" Margin="10,20,0,10">
                                <StackPanel Visibility="{Binding HasUserName, Converter={StaticResource BooleanToVisibilityConverter}}" VerticalAlignment="Top" Orientation="Horizontal" Margin="0,0,0,3">
                                    <TextBlock Style="{StaticResource UserIcon}" Margin="0,0,5,0"></TextBlock>
                                    <TextBlock Style="{StaticResource TextBlockNormal}" Text="{Binding Name, FallbackValue='' }" />
                                    <TextBlock Style="{StaticResource TextBlockNormal}" Visibility="{Binding ShowRoleField, Converter={StaticResource BooleanToVisibilityHiddenConverter}}">
                                        <TextBlock.Inlines>
                                            <Run Text=" | " />
                                            <Run Text="{Binding RoleName, FallbackValue='' }">
                                                <Run.Style>
                                                    <Style TargetType="Run">
                                                        <Style.Triggers >
                                                            <DataTrigger Binding="{Binding IsInEmergencyMode}" Value="True">
                                                                <Setter Property="Foreground" Value="Red"/>
                                                            </DataTrigger>
                                                        </Style.Triggers>
                                                    </Style>
                                                </Run.Style>
                                            </Run>
                                        </TextBlock.Inlines>
                                    </TextBlock>
                                </StackPanel>

                                <TextBlock Visibility="{Binding HasRole, Converter={StaticResource BooleanToVisibilityHiddenConverter}}" VerticalAlignment="Stretch" Style="{StaticResource TextBlockNormal}" Margin="0,0,0,10">
                                    <TextBlock.Inlines>
                                        <Run Text="{Binding LanguageString.TopBar_CountingFor, Mode=OneWay}"></Run>
                                        <Run Text="{Binding Area}"></Run>
                                        <Run Text=" | "></Run>
                                        <Run Text="{Binding Election}" FontWeight="Bold"></Run>
                                        <Run Text="{Binding Contest}" FontWeight="Bold"></Run>
                                    </TextBlock.Inlines>
                                </TextBlock>

                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="0,0,10,0">
                                    <Button Content="{Binding LanguageString.Button_Help, FallbackValue={x:Static language:LanguageString.Button_Help}}" Command="{Binding ShowHelpCommand}" IsTabStop="False"
                                        Visibility="{Binding HasUserName, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                                    <ContentPresenter Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}" />
                                    <Button Content="{Binding LanguageString.Button_Close, FallbackValue={x:Static language:LanguageString.Button_Close}}" Command="{x:Static commands:WellKnownSystemCommands.CloseCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" IsTabStop="False"  />
                                </StackPanel>
                            </StackPanel>
                        </StackPanel>
                    </Grid>
                </StackPanel>

                <StackPanel Grid.Row="3">
                    <Line X1="0" Y1="0" X2="2000" Y2="0" Stroke="Black" StrokeDashArray="1 1" StrokeThickness="1" ClipToBounds="False" SnapsToDevicePixels="True"/>
                </StackPanel>
            </Grid>
        </ControlTemplate>
    </UserControl.Template>
</UserControl>
