<UserControl x:Class="Valg.EVA.Skanning.UserInterfaceElements.RoleSelector.RoleSelectorView"
             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:roleSelector="clr-namespace:Valg.EVA.Skanning.UserInterfaceElements.RoleSelector"
             mc:Ignorable="d" 
             d:DataContext="{d:DesignInstance d:Type=roleSelector:RoleSelectorViewModel}">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Valg.EVA.Skanning.Assets;component/ResourceDictionaries/ResourceLibrary.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <StackPanel>
        <TextBlock Style="{StaticResource TextBlockLargeHeader}" Text="{Binding ElectionEventName}" Margin="0, 0, 0, 50" />
        <ScrollViewer VerticalScrollBarVisibility="Auto">
            <ItemsControl IsTabStop="False" ItemsSource="{Binding Roles}" AlternationCount="2">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.Resources>
                                <Style TargetType="TextBlock" BasedOn="{StaticResource TextBlockNormal}">
                                    <Setter Property="Padding" Value="15,25, 0, 0" />
                                    <Setter Property="VerticalAlignment" Value="Top" />
                                </Style>
                                <Style TargetType="Button" BasedOn="{StaticResource LinkButtonNormal}">
                                    <Setter Property="Margin" Value="15,25, 0, 0" />
                                    <Setter Property="VerticalAlignment" Value="Top" />
                                </Style>
                                <Style TargetType="ToggleButton">
                                    <Setter Property="Margin" Value="15,25, 0, 0" />
                                    <Setter Property="VerticalAlignment" Value="Top" />
                                </Style>
                                <Style TargetType="Border">
                                    <Setter Property="MinHeight" Value="60" />
                                </Style>
                            </Grid.Resources>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="450" />
                                <ColumnDefinition Width="300" />
                                <ColumnDefinition Width="350" />
                            </Grid.ColumnDefinitions>
                            <Border Grid.Column="0" x:Name="ElectionCell">
                                <StackPanel>
                                    <StackPanel Orientation="Vertical" Visibility="{Binding ShowSubAreas, Converter={StaticResource BooleanToVisibilityConverter}}">
                                        <ToggleButton Background="White" Foreground="{StaticResource ActiveElementBackgroundBrush}" IsChecked="{Binding IsChecked}">
                                            <ToggleButton.Template>
                                                <ControlTemplate>
                                                    <Grid Cursor="Hand">
                                                        <Grid.ColumnDefinitions>
                                                            <ColumnDefinition Width="auto" />
                                                            <ColumnDefinition Width="*" />
                                                        </Grid.ColumnDefinitions>
                                                        <TextBlock Grid.Column="0" Style="{StaticResource PlayArrowIcon}" Visibility="{Binding IsChecked, Converter={StaticResource InvertedBooleanToVisibilityConverter}}" FontSize="12" VerticalAlignment="Center" />
                                                        <TextBlock Grid.Column="0" Style="{StaticResource DownArrowIcon}" Visibility="{Binding IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}" FontSize="12" VerticalAlignment="Center" />
                                                        <TextBlock Margin="5, 0, 0, 0" Grid.Column="1" TextDecorations="Underline" Text="{Binding Contest}" Style="{StaticResource TextBlockNormal}" VerticalAlignment="Center" />
                                                    </Grid>
                                                </ControlTemplate>
                                            </ToggleButton.Template>
                                        </ToggleButton>
                                        <ItemsControl ItemsSource="{Binding SubAreaRoles}" Visibility="{Binding IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="10, 0, 0,15">
                                            <ItemsControl.ItemTemplate>
                                                <DataTemplate>
                                                    <Button Content="{Binding DisplayText}"
                                                            Command="{Binding Path=DataContext.SelectRoleCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type roleSelector:RoleSelectorView}} }"
                                                            CommandParameter="{Binding}"
                                                            Margin="25,10, 0, 5" />
                                                </DataTemplate>
                                            </ItemsControl.ItemTemplate>
                                        </ItemsControl>
                                    </StackPanel>
                                    <Button Content="{Binding Contest}"
                                                Visibility="{Binding ShowSubAreas, Converter={StaticResource InvertedBooleanToVisibilityConverter}}"
                                                Command="{Binding Path=DataContext.SelectRoleCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type roleSelector:RoleSelectorView}} }"
                                                CommandParameter="{Binding}" />
                                </StackPanel>
                            </Border>
                            <Border Grid.Column="1" x:Name="AreaCell">
                                <TextBlock  Text="{Binding Area}" />
                            </Border>
                            <Border Grid.Column="2" x:Name="RoleNameCell">
                                <TextBlock  Text="{Binding RoleName}" />
                            </Border>
                        </Grid>
                        <DataTemplate.Triggers>
                            <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                                <Setter Property="Background" Value="White" TargetName="ElectionCell" />
                                <Setter Property="Background" Value="White" TargetName="AreaCell" />
                                <Setter Property="Background" Value="White" TargetName="RoleNameCell" />
                            </Trigger>
                            <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                                <Setter Property="Background" Value="{StaticResource AlternatingRow}" TargetName="ElectionCell" />
                                <Setter Property="Background" Value="{StaticResource AlternatingRow}" TargetName="AreaCell" />
                                <Setter Property="Background" Value="{StaticResource AlternatingRow}" TargetName="RoleNameCell" />
                            </Trigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
                <ItemsControl.Template>
                    <ControlTemplate>
                        <StackPanel>
                            <Grid>
                                <Grid.Resources>
                                    <Style TargetType="TextBlock" BasedOn="{StaticResource TextBlockNormal}">
                                        <Setter Property="Padding" Value="15" />
                                        <Setter Property="Foreground" Value="White" />
                                        <Setter Property="VerticalAlignment" Value="Center" />
                                    </Style>
                                    <Style TargetType="Border">
                                        <Setter Property="Background" Value="{StaticResource DefaultBlackishBackground}" />
                                        <Setter Property="BorderBrush" Value="White" />
                                        <Setter Property="BorderThickness" Value="0,0,1,0" />
                                        <Setter Property="Height" Value="50" />
                                    </Style>
                                </Grid.Resources>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="450" />
                                    <ColumnDefinition Width="300" />
                                    <ColumnDefinition Width="350" />
                                </Grid.ColumnDefinitions>
                                <Border Grid.Column="0">
                                    <TextBlock Text="{Binding LanguageString.RoleSelector_LabelElection }" />
                                </Border>
                                <Border Grid.Column="1">
                                    <TextBlock Text="{Binding LanguageString.RoleSelector_LabelCountingAs }" />
                                </Border>
                                <Border Grid.Column="2">
                                    <TextBlock Text="{Binding LanguageString.RoleSelector_LabelRole }" />
                                </Border>
                            </Grid>
                            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                        </StackPanel>
                    </ControlTemplate>
                </ItemsControl.Template>
            </ItemsControl>
        </ScrollViewer>
    </StackPanel>
</UserControl>
