<Window x:Class="eSuite.WorkBench.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:eSuite.WorkBench"
        xmlns:utilities="clr-namespace:eSuite.WorkBench.Utilities"
        xmlns:wpfHelper="clr-namespace:eSuite.WorkBench.WpfHelper"
        mc:Ignorable="d"
        d:DataContext="{d:DesignInstance {x:Type local:MainWindowViewModel}}"
        Title="{Binding ApplicationTitle}" Height="650" MinHeight="650" Width="1024" MinWidth="400">
    <Grid Height="auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="auto" Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="750"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <GroupBox Grid.Row="0" Height="Auto">
            <GroupBox.Header>
                <TextBlock FontWeight="Bold">Branches</TextBlock>
            </GroupBox.Header>
            <Grid Height="Auto" Margin="0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="25" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Button x:Name="RefreshListButton" Content="Refresh list" Grid.Row="0" Grid.Column="0" Command="{Binding GetTagListCommand}" Margin="2"/>
                <TreeView
                    Name="EsuiteApiBranchesTreeView" 
                    Grid.Row="1" 
                    Grid.Column="0" 
                    ItemsSource="{Binding Branches}"
                    wpfHelper:BindableSelectedItemHelper.Attach="True" 
                    wpfHelper:BindableSelectedItemHelper.SelectedItem="{Binding SelectedBranch, Mode=TwoWay}"
                    Margin="2,3,2,1">
                    <TreeView.Resources>
                        <BooleanToVisibilityConverter x:Key="BoolToVis" />
                        <Style TargetType="TreeViewItem">
                            <Setter Property="IsExpanded" Value="True"/>
                            <EventSetter Event="MouseRightButtonDown" Handler="TreeViewItem_MouseRightButtonDown"/>
                        </Style>
                    </TreeView.Resources>
                    <TreeView.ItemTemplate>
                        <HierarchicalDataTemplate ItemsSource="{Binding BranchVersions}" >
                            <Label Content="{Binding BranchName}"/>
                            <HierarchicalDataTemplate.ItemTemplate>
                                <DataTemplate>
                                    <Label  Padding="1,1,1,1" >
                                        <TextBlock Text="{Binding BranchName}"></TextBlock>
                                    </Label>
                                </DataTemplate>
                            </HierarchicalDataTemplate.ItemTemplate>
                        </HierarchicalDataTemplate>
                    </TreeView.ItemTemplate>
                    <TreeView.ContextMenu>
                        <ContextMenu>
                            <MenuItem x:Name="MenuItemSelect" Header="Select" 
                                      Command="{Binding SelectBranchCommand}" 
                                      CommandParameter="{Binding SelectedBranch, UpdateSourceTrigger=PropertyChanged}"/>
                            <Separator Visibility="{Binding Path=DeveloperMode, Converter={StaticResource BoolToVis}}"/>
                            <MenuItem x:Name="MenuItemDeleteAllImagesForBranch" Header="Delete all images for branch" 
                                      Command="{Binding DeleteBranchCommand}" 
                                      CommandParameter="{Binding SelectedBranch, UpdateSourceTrigger=PropertyChanged}"
                                      Visibility="{Binding Path=DeveloperMode, Converter={StaticResource BoolToVis}}"/>
                        </ContextMenu>
                    </TreeView.ContextMenu>
                </TreeView>
            </Grid>
        </GroupBox>
        <GroupBox Grid.Row="1">
            <GroupBox.Header>
                <TextBlock FontWeight="Bold">Containers state</TextBlock>
            </GroupBox.Header>
            <StackPanel Orientation="Vertical">
                <Button x:Name="StartContainerButton" Grid.Row="1" Grid.ColumnSpan="2" Height="auto" Content="Start containers" Command="{Binding StartContainersCommand}"  Margin="2"/>
                <Button x:Name="StopRunningContainersButton" Grid.Row="3" Grid.ColumnSpan="2" Height="auto" Content="Stop containers" Command="{Binding StopContainersCommand}"  Margin="2"/>
            </StackPanel>
        </GroupBox>
        <GroupBox Grid.Row="2" >
            <GroupBox.Header>
                <TextBlock FontWeight="Bold">Select images</TextBlock>
            </GroupBox.Header>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="200" />
                </Grid.ColumnDefinitions>
                <Label Content="e-suite.Proxy" Height="26" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Stretch"/>
                <ComboBox x:Name="SelectProxyImageComboBox" ItemsSource="{Binding AvailableProxyTags}" SelectedItem="{Binding AvailableProxyTags.SelectedItem}" Height="22" Grid.Row="0" Grid.Column="1" Margin="2" IsEditable="true"/>
                <Label Content="e-suite.api" Height="26" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Stretch"/>
                <ComboBox x:Name="SelectApiImageComboBox" ItemsSource="{Binding AvailableApiTags}" SelectedItem="{Binding AvailableApiTags.SelectedItem}" Height="22" Grid.Row="1" Grid.Column="1" Margin="2" IsEditable="true"/>
                <Label Content="e-suite.webui" Height="26" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Stretch"/>
                <ComboBox x:Name="SelectWebUiImageComboBox" ItemsSource="{Binding AvailableWebUiTags}" SelectedItem="{Binding AvailableWebUiTags.SelectedItem}" Height="22" Grid.Row="2" Grid.Column="1" Margin="2" IsEditable="true"/>
                <Label Content="e-suite.database.migrator" Height="26" Grid.Row="3" Grid.Column="0" HorizontalAlignment="Stretch"/>
                <ComboBox x:Name="SelectDbMigratorImageComboBox" ItemsSource="{Binding AvailableDbMigratorTags}" SelectedItem="{Binding AvailableDbMigratorTags.SelectedItem}" Height="22" Grid.Row="3" Grid.Column="1" Margin="2" IsEditable="true"/>
                <Label Content="e-suite.Scheduler" Height="26" Grid.Row="4" Grid.Column="0" HorizontalAlignment="Stretch"/>
                <ComboBox x:Name="SelectSchedulerImageComboBox" ItemsSource="{Binding AvailableSchedulerTags}" SelectedItem="{Binding AvailableSchedulerTags.SelectedItem}" Height="22" Grid.Row="4" Grid.Column="1" Margin="2" IsEditable="true"/>
                <Label Content="e-suite.MessageProcessor" Height="26" Grid.Row="5" Grid.Column="0" HorizontalAlignment="Stretch"/>
                <ComboBox x:Name="SelectMessageProcessorImageComboBox" ItemsSource="{Binding AvailableMessageProcessorTags}" SelectedItem="{Binding AvailableMessageProcessorTags.SelectedItem}" Height="22" Grid.Row="5" Grid.Column="1" Margin="2" IsEditable="true"/>
                <Button Grid.Row="0" Grid.Column="2" Content="Web UI" Height="auto" Margin="2" Command="{Binding LaunchWebUiCommand}"/>
                <Button Grid.Row="1" Grid.Column="2" Content="Swagger" Height="auto" Margin="2" Command="{Binding LaunchSwaggerCommand}"/>
                <Button Grid.Row="2" Grid.Column="2" Content="Healthz" Height="auto" Margin="2" Command="{Binding LaunchHealthZCommand}"/>
            </Grid>
        </GroupBox>
        <Expander Grid.Row="3" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5">
            <Expander.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform AngleX="0"/>
                    <RotateTransform/>
                    <TranslateTransform X="0"/>
                </TransformGroup>
            </Expander.RenderTransform>
            <Expander.Header>
                <TextBlock FontWeight="Bold">Settings</TextBlock>
            </Expander.Header>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <TextBox x:Name="SqlAdminLoginField" Text="{Binding SettingsLogin, UpdateSourceTrigger=PropertyChanged}" Grid.Row="0" Grid.Column="0" Margin="2" />
                <PasswordBox x:Name="SqlAdminPasswordField" Grid.Row="1" Grid.Column="0" Margin="2" ToolTip="Enter new password to overwrite existing" />
                <CheckBox IsEnabled="False" x:Name="DeveloperModeField" IsChecked="{Binding DeveloperMode, UpdateSourceTrigger=PropertyChanged}" Grid.Row="2" Grid.Column="0" Margin="2" ToolTip="Enables menu options that allow deleting of compiled images from the server">
                    <TextBlock>Developer Mode</TextBlock>
                </CheckBox>
                <TextBox x:Name="UpdatePersonalAccessKey" Text="{Binding DevopsPersonalAccessKey, UpdateSourceTrigger=PropertyChanged}" Grid.Row="3" Grid.Column="0" Margin="2" ToolTip="Enter your personal access key to enable updates" />
                <Button x:Name="SaveSettingsButton" Content="Save settings" Grid.Row="4" Grid.Column="0" Command="{Binding SaveUserSettingsCommand}" CommandParameter="{Binding ElementName=SqlAdminPasswordField}" Margin="2"/>
            </Grid>
        </Expander>
        <TextBox Grid.Column="2" Grid.Row="0" Grid.RowSpan="5" Margin="5, 18, 5, 5" TextWrapping="Wrap" IsReadOnly="True" VerticalScrollBarVisibility="Auto" Text="{Binding FeedbackOutput, Mode=OneWay}" utilities:TextBoxBehaviour.ScrollOnTextChanged="True">
            <TextBox.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Clear" Command="{Binding ClearFeedBackCommand}"/>
                </ContextMenu>
            </TextBox.ContextMenu>
        </TextBox>
    </Grid>
</Window>
