<UserControl x:Class="_1RM.View.Settings.ProtocolConfig.ProtocolRunnerSettingsPageView"
             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:attachProperty="clr-namespace:Shawn.Utils.WpfResources.Theme.AttachProperty;assembly=Shawn.Utils.WpfResources"
             xmlns:protocolConfig="clr-namespace:_1RM.View.Settings.ProtocolConfig"
             xmlns:default="clr-namespace:_1RM.Model.ProtocolRunner.Default"
             xmlns:runner="clr-namespace:_1RM.Model.ProtocolRunner"
             xmlns:controls="clr-namespace:Shawn.Utils.Wpf.Controls;assembly=Shawn.Utils.Wpf"
             d:DataContext="{d:DesignInstance protocolConfig:ProtocolRunnerSettingsPageViewModel}"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="ProtocolConfiogDictionary.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>

            <Style TargetType="TextBlock" BasedOn="{StaticResource TextBlockBase}">
                <Setter Property="Foreground" Value="{DynamicResource BackgroundTextBrush}"></Setter>
            </Style>

            <Style x:Key="ListBoxForProtocols" TargetType="{x:Type ListBox}">
                <Setter Property="BorderThickness" Value="0" />
                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" />
                <Setter Property="Background" Value="Transparent" />
                <Setter Property="ItemContainerStyle">
                    <Setter.Value>
                        <Style TargetType="ListBoxItem">
                            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="ListBoxItem">
                                        <Grid Margin="10 3" Cursor="Hand">
                                            <Border x:Name="GridContainer" CornerRadius="5" 
                                                    BorderBrush="{DynamicResource DefaultBorderBrush}" BorderThickness="1">
                                            </Border>
                                            <ContentPresenter x:Name="ContentPresenter"/>
                                        </Grid>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter Property="Background" TargetName="GridContainer" Value="{DynamicResource PrimaryTextBrush}"></Setter>
                                                <Setter Property="Opacity" Value="0.2" TargetName="GridContainer" />
                                                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                                            </Trigger>
                                            <Trigger Property="IsSelected" Value="True">
                                                <Setter Property="Opacity" Value="1" TargetName="GridContainer" />
                                                <Setter Property="TextElement.Foreground" Value="{DynamicResource AccentTextBrush}" TargetName="ContentPresenter" />
                                                <Setter Property="Background" Value="{DynamicResource AccentMidBrush}" TargetName="GridContainer" />
                                                <Setter Property="BorderThickness" Value="0" TargetName="GridContainer" />
                                                <Setter Property="Foreground" Value="{DynamicResource AccentTextBrush}"/>
                                                <Setter Property="Background" Value="{DynamicResource AccentMidBrush}"/>
                                                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </Setter.Value>
                </Setter>
                <Setter Property="ItemTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <Grid Margin="10">
                                <TextBlock Text="{Binding}"></TextBlock>
                            </Grid>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="ListBoxRunners" TargetType="{x:Type ListBox}">
                <Setter Property="BorderThickness" Value="0" />
                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" />
                <Setter Property="Background" Value="Transparent" />
                <Setter Property="ItemContainerStyle">
                    <Setter.Value>
                        <Style TargetType="ListBoxItem">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="ListBoxItem">
                                        <Grid Margin="0 0 5 0">
                                            <Border x:Name="GridContainer"></Border>
                                            <ContentPresenter x:Name="ContentPresenter"/>
                                        </Grid>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </Setter.Value>
                </Setter>
            </Style>



            <DataTemplate DataType="{x:Type default:InternalDefaultRunner}">
                <Grid Style="{StaticResource Block}">
                    <Grid.OpacityMask>
                        <VisualBrush Visual="{Binding ElementName=Border1}" />
                    </Grid.OpacityMask>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="*"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Border Name="Border1" Grid.Row="0" Grid.RowSpan="2" 
                            Background="{DynamicResource BackgroundBrush}"
                            CornerRadius="10" BorderThickness="0">
                    </Border>
                    <Grid Grid.Row="0" Background="{DynamicResource PrimaryMidBrush}">
                        <TextBlock HorizontalAlignment="Center"  VerticalAlignment="Center"
                                   Foreground="{DynamicResource PrimaryTextBrush}" 
                                   FontSize="{DynamicResource HeadFontSize}" 
                                   Text="{Binding Name}" Margin="5"></TextBlock>
                    </Grid>
                    <Grid Grid.Row="1" MinHeight="50">
                        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">Nothing special</TextBlock>
                    </Grid>
                </Grid>
            </DataTemplate>







            <DataTemplate DataType="{x:Type default:KittyRunner}">
                <protocolConfig:KittyRunnerSettings Runner="{Binding}"></protocolConfig:KittyRunnerSettings>
            </DataTemplate>

            <protocolConfig:ConverterExternalRunner2Vm x:Key="ExternalRunner2Vm"></protocolConfig:ConverterExternalRunner2Vm>



            <DataTemplate DataType="{x:Type runner:ExternalRunnerForSSH}">
                <protocolConfig:ExternalSshRunnerSettings DataContext="{Binding Path=., Converter={StaticResource ExternalRunner2Vm}}"></protocolConfig:ExternalSshRunnerSettings>
            </DataTemplate>


            <DataTemplate DataType="{x:Type runner:ExternalRunner}">
                <protocolConfig:ExternalRunnerSettings DataContext="{Binding Path=., Converter={StaticResource ExternalRunner2Vm}}"></protocolConfig:ExternalRunnerSettings>
            </DataTemplate>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <Grid MinWidth="130" Background="{DynamicResource BackgroundBrush}">
            <Border BorderThickness="0" Background="{DynamicResource BackgroundBrush}">
                <Border.Effect>
                    <DropShadowEffect Direction="0" Opacity="0.5" ShadowDepth="3"></DropShadowEffect>
                </Border.Effect>
            </Border>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="*"></RowDefinition>
                </Grid.RowDefinitions>

                <ListBox Grid.Row="1" ItemsSource="{Binding Protocols}"
                             SelectedItem="{Binding SelectedProtocol}"
                             Style="{StaticResource ListBoxForProtocols}">
                </ListBox>
            </Grid>
        </Grid>

        <Grid Grid.Column="1" ClipToBounds="True">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="*"></RowDefinition>
                </Grid.RowDefinitions>

                <ListBox Grid.Row="2" ScrollViewer.CanContentScroll="False"
                         Style="{StaticResource ListBoxRunners}" Grid.IsSharedSizeScope="True"
                         ItemsSource="{Binding Runners}">
                    <ListBox.Background>
                        <SolidColorBrush Color="{DynamicResource BackgroundTextColor}" Opacity="0.25"></SolidColorBrush>
                    </ListBox.Background>
                </ListBox>

                <Border Grid.Row="0" Grid.RowSpan="2" BorderThickness="0" Background="{DynamicResource BackgroundBrush}">
                    <Border.Effect>
                        <DropShadowEffect Direction="270" Opacity="0.5" ShadowDepth="3"></DropShadowEffect>
                    </Border.Effect>
                </Border>


                <Grid Grid.Row="1" Margin="10 3" Height="35">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                    </Grid.ColumnDefinitions>

                    <StackPanel Orientation="Horizontal" Margin="5">
                        <TextBlock Text="{Binding SelectedProtocol}" Margin="3" VerticalAlignment="Center" FontWeight="Bold"></TextBlock>
                        <TextBlock Text="{DynamicResource Default}" VerticalAlignment="Center" FontWeight="Bold"></TextBlock>
                        <TextBlock Text="Runner" VerticalAlignment="Center" FontWeight="Bold"></TextBlock>
                    </StackPanel>

                    <ComboBox Grid.Column="1" 
                              ItemsSource="{Binding Runners, UpdateSourceTrigger=PropertyChanged}"
                              DisplayMemberPath="Name"
                              SelectedItem="{Binding SelectedRunner, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                    </ComboBox>


                    <Button Grid.Column="2" Width="auto" Height="30" 
                            Margin="10 0 0 0"
                            Background="Transparent"
                            attachProperty:VisionElement.BackgroundAccent="Transparent"
                            attachProperty:VisionElement.BackgroundOnMouseDown="Transparent"
                            Style="{StaticResource ButtonBarBackgroundStyle}"
                            HorizontalAlignment="Right"
                            Command="{Binding CmdAddRunner}"
                            >
                        <StackPanel Orientation="Horizontal">
                            <Grid Height="20" Width="20">
                                <Path Data="M 41.888 18.304 L 41.888 23.584 L 23.584 23.584 L 23.584 41.888 L 18.304 41.888 L 18.304 23.584 L 0 23.584 L 0 18.304 L 18.304 18.304 L 18.304 0 L 23.584 0 L 23.584 18.304 Z"
                                  Stroke="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType=Button}}"
                                  Fill="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType=Button}}"
                                  StrokeThickness="2" Stretch="Uniform" />
                            </Grid>
                            <TextBlock VerticalAlignment="Center" Margin="2 0">
                                <Hyperlink NavigateUri="https://1remote.org/usage/protocol/runner/" TextDecorations="{x:Null}" 
                                           controls:HyperlinkHelper.IsOpenExternal="True">
                                    (?)
                                </Hyperlink>
                            </TextBlock>
                        </StackPanel>
                    </Button>
                </Grid>
            </Grid>
        </Grid>
    </Grid>
</UserControl>
