<UserControl x:Class="Machinations.ProgramControl"
             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:wpf="clr-namespace:Machinations.WPF"
             xmlns:converters="clr-namespace:Machinations.WPF.Converters"
             xmlns:machinations="clr-namespace:Machinations"
             mc:Ignorable="d" 
             DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="BoolToVisConverter" />
        <converters:InverseBoolToVisibilityConverter x:Key="InverseBoolToVisibilityConverter"/>
        <Style TargetType="ToggleButton">
            <Setter Property="Width" Value ="40"/>
            <Setter Property="Height" Value ="40"/>
            <Setter Property="Background" Value ="AliceBlue"/>
            <Setter Property="Margin" Value="1"/>
        </Style>
        <Style TargetType="Button">
            <Setter Property="Background" Value ="AliceBlue"/>
            <Setter Property="Margin" Value="1"/>
        </Style>
    </UserControl.Resources>
    <Grid Height="800" Width="240">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <TabControl Grid.Row="0" Margin="5" MaxHeight="300" MaxWidth="300" Visibility="{Binding Running, Converter={StaticResource InverseBoolToVisibilityConverter}}">
            <TabItem Header="Graph" MinWidth="40" HorizontalAlignment="Center">
                <machinations:GraphControl x:Name="GraphControl"/>
            </TabItem>
            <TabItem Header="File" MinWidth="40" HorizontalAlignment="Center">
                <StackPanel>
                    <Button Content="New" Click="Restart_OnClick"/>
                    <Button Content="Open" Click="OpenButtonClick"/>
                    <Button Content="Import" Click="ImportButtonClick"/>
                    <Button Content="Save" Click="SaveButtonClick"/>
                </StackPanel>
            </TabItem>
            <TabItem Header="Settings" MinWidth="40" HorizontalAlignment="Center">
                <StackPanel Orientation="Vertical">
                    <ToggleButton Content="AutoSave" Width="200" Height="20" IsChecked="{Binding Settings.AutoSave}"/>
                    <Button Content="Change component folder" ToolTip="{Binding Settings.ComponentPath}" Click="ChangeComponentFolder"/>
                </StackPanel>
            </TabItem>
        </TabControl>
        <Grid Grid.Row="1" Visibility="{Binding Running, Converter={StaticResource InverseBoolToVisibilityConverter}}">
            <wpf:UserComponentControlView x:Name="UserComponents" Visibility="{Binding Running, Converter={StaticResource InverseBoolToVisibilityConverter}}"/>
        </Grid>
        <Grid Grid.Row="2" Visibility="{Binding Running, Converter={StaticResource InverseBoolToVisibilityConverter}}">
            <ScrollViewer MaxHeight="480" VerticalScrollBarVisibility="Auto">
                <wpf:ComponentsSettings x:Name="ComponentsSettings" Visibility="{Binding Running, Converter={StaticResource InverseBoolToVisibilityConverter}}"/>
            </ScrollViewer>
        </Grid>
        <Button Name="RunButton" Grid.Row ="3" Content="Start" FontSize="25" Click="RunButtonClick" Height="50" Margin="10" Background="LightGreen"/>
        <Grid Grid.Row="0" Visibility="{Binding Running, Converter={StaticResource BoolToVisConverter}}">
            <wpf:SimulationControl x:Name="MySimulationControl"/>
        </Grid>
    </Grid>
</UserControl>
