<UserControl x:Class="Valg.EVA.Skanning.JobManagement.Startup.UI.TransferOverview.TransferOverviewView"
             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:vm="clr-namespace:Valg.EVA.Skanning.JobManagement.Startup.UI.TransferOverview"
             xmlns:ui="clr-namespace:Valg.EVA.Skanning.JobManagement.Startup.UI"
             mc:Ignorable="d" 
             d:DataContext="{d:DesignInstance d:Type=vm:TransferOverviewViewModel}"
             d:DesignHeight="300" 
             Name="TransferOverview">
    <ui:ContextAwareControl VotingCategoryType="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ui:ContextAwareControl}}, Path=VotingCategoryType}"
                            PollingDistrict="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ui:ContextAwareControl}}, Path=PollingDistrict}">
        <ui:ContextAwareControl.Content>
            <Grid Grid.IsSharedSizeScope="True">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Border Grid.Row="0" BorderBrush="Black" BorderThickness="0,0,0,1" Padding="0,0,0,5" HorizontalAlignment="Stretch">
                    <TextBlock Width="Auto" Text="{Binding JobManagementLanguageString.TransferOverview_Title}" Style="{StaticResource TextBlockMediumHeader}"/>
                </Border>
                <Grid Grid.Row="1" Margin="0,10,0,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition SharedSizeGroup="Name" Width="*"></ColumnDefinition>
                        <ColumnDefinition SharedSizeGroup="Status" Width="*"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <Border Grid.Column="0" BorderBrush="#797979" BorderThickness="1,1,1,0">
                        <TextBlock FontSize="14" FontFamily="Arial Regular" MinWidth="200" Text="{Binding JobManagementLanguageString.TransferOverview_NameHeader}" Padding="10" Background="#333333" Foreground="White" />
                    </Border>
                    <Border Grid.Column="1" BorderBrush="#797979" BorderThickness="0,1,1,0">
                        <TextBlock FontSize="14" FontFamily="Arial Regular" MinWidth="300" Text="{Binding JobManagementLanguageString.TransferOverview_StatusHeader}" Padding="10" Background="#333333" Foreground="White" />
                    </Border>
                </Grid>
                <Border Grid.Row="2" BorderBrush="{StaticResource GrayBorder}" BorderThickness="0,0,0,1" >
                    <ItemsControl IsTabStop="False" ItemsSource="{Binding CompletedCountings}" AlternationCount="2">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition SharedSizeGroup="Name" Width="*"></ColumnDefinition>
                                        <ColumnDefinition SharedSizeGroup="Status" Width="*"></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <StackPanel Grid.Column="0" Name="NameCell">
                                        <Button Name="NameLink"
                                        Content="{Binding CountingName}"
                                        Margin="10,15"
                                        CommandParameter="{Binding}"
                                        Command="{Binding
                                            RelativeSource={RelativeSource AncestorType=UserControl},
                                            Path=DataContext.ShowTransferDetailsCommand}">
                                            <Button.Style>
                                                <Style BasedOn="{StaticResource LinkButtonNormal}" TargetType="Button">
                                                    <Setter Property="VerticalAlignment" Value="Center"></Setter>
                                                    <Style.Triggers>
                                                        <DataTrigger Binding="{Binding DataContext.AllowedToViewDetails, RelativeSource={RelativeSource AncestorType=UserControl}}" Value="false">
                                                            <Setter Property="Visibility" Value="Collapsed" />
                                                        </DataTrigger>
                                                        <DataTrigger Binding="{Binding IsErrorState}" Value="true">
                                                            <Setter Property="Foreground" Value="{StaticResource Error}"/>
                                                        </DataTrigger>
                                                        <DataTrigger Binding="{Binding IsSuccessState}" Value="true">
                                                            <Setter Property="Foreground" Value="{StaticResource Green}"/>
                                                        </DataTrigger>
                                                    </Style.Triggers>
                                                </Style>
                                            </Button.Style>
                                        </Button>
                                        <TextBlock Name="NameText"
                                        Text="{Binding CountingName}"
                                        Margin="10,15">
                                            <TextBlock.Style>
                                                <Style TargetType="TextBlock" BasedOn="{StaticResource TextBlockNormal}">
                                                    <Setter Property="VerticalAlignment" Value="Center"></Setter>
                                                    <Style.Triggers>
                                                        <DataTrigger Binding="{Binding DataContext.AllowedToViewDetails, RelativeSource={RelativeSource AncestorType=UserControl}}" Value="true">
                                                            <Setter Property="Visibility" Value="Collapsed" />
                                                        </DataTrigger>
                                                        <DataTrigger Binding="{Binding IsErrorState}" Value="true">
                                                            <Setter Property="Foreground" Value="{StaticResource Error}"/>
                                                        </DataTrigger>
                                                        <DataTrigger Binding="{Binding IsSuccessState}" Value="true">
                                                            <Setter Property="Foreground" Value="{StaticResource Green}"/>
                                                        </DataTrigger>
                                                    </Style.Triggers>
                                                </Style>
                                            </TextBlock.Style>
                                        </TextBlock>
                                    </StackPanel>
                                    <StackPanel Name="StateCell" Grid.Column="1" Orientation="Horizontal">
                                        <TextBlock FontSize="14" Text="{Binding Status}"  Padding="10,15">
                                            <TextBlock.Style>
                                                <Style TargetType="TextBlock" BasedOn="{StaticResource TextBlockNormal}">
                                                    <Style.Triggers>
                                                        <DataTrigger Binding="{Binding IsErrorState}" Value="true">
                                                            <Setter Property="Foreground" Value="{StaticResource Error}"></Setter>
                                                            <Setter Property="FontWeight" Value="Bold"></Setter>
                                                            <Setter Property="ToolTip" Value="{Binding ErrorCode}"></Setter>
                                                        </DataTrigger>
                                                        <DataTrigger Binding="{Binding IsSuccessState}" Value="true">
                                                            <Setter Property="Foreground" Value="{StaticResource Green}"/>
                                                        </DataTrigger>
                                                    </Style.Triggers>
                                                </Style>
                                            </TextBlock.Style>
                                        </TextBlock>
                                        <Button 
                                            Content="{Binding JobManagementLanguageString.TransferOverview_CheckStatus, FallbackValue='Sjekk status'}"
                                            Margin="10,15"
                                            CommandParameter="{Binding}"
                                            Command="{Binding
                                                RelativeSource={RelativeSource AncestorType=UserControl},
                                                Path=DataContext.RestartStatusCheckCommand}"
                                            Visibility="{Binding CheckStatusForTransferManually, Converter={StaticResource BooleanToVisibilityConverter}}"
                                            Style="{StaticResource LinkButtonNormal}"/>
                                    </StackPanel>
                                </Grid>
                                <DataTemplate.Triggers>
                                    <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                                        <Setter Property="Background" Value="{StaticResource AlternatingRow}" TargetName="NameCell"/>
                                        <Setter Property="Background" Value="{StaticResource AlternatingRow}" TargetName="StateCell"/>
                                    </Trigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </Border>
            </Grid>
        </ui:ContextAwareControl.Content>
    </ui:ContextAwareControl>
</UserControl>

