<UserControl x:Class="Machinations.WPF.SimulationControl"
             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:converters="clr-namespace:Machinations.WPF.Converters"
             xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
             mc:Ignorable="d" 
             DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <UserControl.Resources>
        <Style TargetType="TextBlock">
            <Setter Property="Margin" Value="10,2,10,2"/>
        </Style>
        <Style TargetType="ToggleButton">
            <Setter Property="Width" Value ="100"/>
            <Setter Property="Height" Value ="20"/>
            <Setter Property="Background" Value ="White"/>
            <Setter Property="Margin" Value="1"/>
            <Setter Property="HorizontalAlignment" Value="Center"/>
        </Style>
        <converters:TurnBasedTimeModeToVisibConverter x:Key="TimeModeToVisConverter" />
        <BooleanToVisibilityConverter x:Key="BoolToVisConverter" />
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <TextBlock Grid.Row ="0" Grid.Column="0" Text="TimeMode:"/>
            <TextBlock Grid.Row ="0" HorizontalAlignment ="Right" Grid.Column="1" Text="{Binding TimeMode}"/>
            <TextBlock Grid.Row ="1" Grid.Column="0" Text="Step:"/>
            <TextBlock Grid.Row ="1" HorizontalAlignment ="Right" Grid.Column="1" Text="{Binding LastStep}"/>
            <TextBlock Grid.Row ="3" Grid.Column="0" Text="Jump forward" Visibility="{Binding TimeMode, Converter={StaticResource TimeModeToVisConverter}}"/>
            <StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right" Visibility="{Binding TimeMode, Converter={StaticResource TimeModeToVisConverter}}">
                 <xctk:ShortUpDown Increment="10" Minimum="2" Maximum="1000" Value="{Binding JumpForward}"/>
                <Button  Width="40" HorizontalAlignment="Right" Content="&gt;&gt;" Click="JumpForwardClick" IsEnabled="{Binding CanRightClick}"/>
            </StackPanel>
        </Grid>
        <Grid Grid.Row="1" Visibility="{Binding TimeMode, Converter={StaticResource TimeModeToVisConverter}}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Button Grid.Column ="0" Width="40" HorizontalAlignment="Center"  Content="&lt;" Click="OnLeftButtonClick"/>
                <TextBlock Grid.Column="1" Text="{Binding Step}" HorizontalAlignment="Center"/>
                <Button Grid.Column ="2" Width="40" HorizontalAlignment="Center" Content="&gt;" Click="OnRightButtonClick" IsEnabled="{Binding CanRightClick}"/>
            </Grid>
            <Slider Grid.Row="1" Minimum ="0" Maximum="{Binding LastStep}" Value="{Binding Step}"/>
        </Grid>
        <Grid Grid.Row="2">
            <ScrollViewer Height="500" Width="220">
                <ListView ItemsSource="{Binding Actions}" SelectionChanged="Selector_OnSelectionChanged"  Width="300" IsSynchronizedWithCurrentItem="True">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="Step" Width ="30" DisplayMemberBinding="{Binding Step}"/>
                            <GridViewColumn Header="Node" Width ="100" DisplayMemberBinding="{Binding ElementName}"/>
                            <GridViewColumn Header="ActionType" Width ="90" DisplayMemberBinding="{Binding Cause}"/>
                        </GridView>
                    </ListView.View>
                </ListView>
            </ScrollViewer>
        </Grid>
        <Grid Grid.Row ="3">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <ToggleButton Content="Automatic" IsChecked="{Binding ShowAutomatic}"/>
                <ToggleButton Grid.Row="1" Grid.Column="0" Content="Interactive" IsChecked="{Binding ShowInteractive}"/>
                <ToggleButton Grid.Row="2" Grid.Column="0" Content="Start" IsChecked="{Binding ShowOnStart}"/>
                <ToggleButton Grid.Row="3" Grid.Column="0" Content="Passive" IsChecked="{Binding ShowPassive}"/>
                <ToggleButton Grid.Row="0" Grid.Column="1" Content="Pools" IsChecked="{Binding ShowPools}"/>
                <ToggleButton Grid.Row="1" Grid.Column="1" Content="Sources" IsChecked="{Binding ShowSources}"/>
                <ToggleButton Grid.Row="2" Grid.Column="1" Content="Converters" IsChecked="{Binding ShowConverters}"/>
                <ToggleButton Grid.Row="3" Grid.Column="1" Content="Other" IsChecked="{Binding ShowOthers}"/>
            </Grid>
        </Grid>
        <TextBox Grid.Row ="4" FontSize="25" Text="{Binding EndText, Mode=OneWay}" Visibility="{Binding Ended, Converter={StaticResource BoolToVisConverter}}"/>
    </Grid>
</UserControl>
