<UserControl x:Class="NETworkManager.Views.HTTPHeadersView"
        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:Converter="clr-namespace:NETworkManager.Converters"
        xmlns:Validator="clr-namespace:NETworkManager.Validators"
        xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
        xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"        
        xmlns:IconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
        mc:Ignorable="d">
    <UserControl.Resources>
        <Converter:BooleanReverseToVisibilityConverter x:Key="BooleanReverseToVisibilityConverter" />
        <Converter:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <Converter:BooleanReverseConverter x:Key="BooleanReverseConverter" />
        <Converter:NullableDateTimeToStringConverter x:Key="NullableDateTimeToStringConverter" />
    </UserControl.Resources>
    <Grid>
        <Grid Grid.Column="0" Grid.Row="0" Margin="10">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <TextBlock Grid.Row="0" Style="{StaticResource HeaderTextBlock}" Text="{DynamicResource String_Header_Website}" />
            <Grid Grid.Row="1" Margin="0,0,0,20">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid Grid.Row="0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="10" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="10" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Column="0" Text="{DynamicResource String_URL}" Style="{DynamicResource DefaultTextBlock}" VerticalAlignment="Center" />
                    <ComboBox Grid.Column="2" x:Name="cbWebsiteUri" ItemsSource="{Binding WebsiteUriHistoryView}" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_ExampleWebsiteUri}" Validation.ErrorTemplate="{StaticResource DefaultErrorTemplate}" IsEnabled="{Binding IsCheckRunning, Converter={StaticResource BooleanReverseConverter}}" Style="{StaticResource HistoryComboBox}">
                        <ComboBox.Text>
                            <Binding Path="WebsiteUri" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                                <Binding.ValidationRules>
                                    <Validator:EmptyValidator ValidatesOnTargetUpdated="True" />
                                    <Validator:HttpAndHttpsUriValidator ValidatesOnTargetUpdated="True" />
                                </Binding.ValidationRules>
                            </Binding>
                        </ComboBox.Text>
                    </ComboBox>
                    <Button Grid.Column="4" Command="{Binding CheckCommand}" IsDefault="{Binding IsCheckRunning, Converter={StaticResource BooleanReverseConverter}}">
                        <Button.Resources>
                            <Style TargetType="{x:Type Button}" BasedOn="{StaticResource ImageWithTextButton}">
                                <Setter Property="IsEnabled" Value="True" />
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Path=(Validation.HasError), ElementName=cbWebsiteUri}" Value="True" >
                                        <Setter Property="IsEnabled" Value="False" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding IsCheckRunning}" Value="True">
                                        <Setter Property="IsEnabled" Value="False" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Button.Resources>
                        <Button.Content>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Rectangle Width="20" Height="20" Margin="10,5,0,5">
                                    <Rectangle.Resources>
                                        <VisualBrush x:Key="VisualControlPlay" Stretch="Uniform" Visual="{IconPacks:Material Kind=Play}"/>
                                    </Rectangle.Resources>
                                    <Rectangle.Style>
                                        <Style TargetType="{x:Type Rectangle}">
                                            <Setter Property="OpacityMask" Value="{StaticResource VisualControlPlay}" />
                                            <Setter Property="Fill" Value="{DynamicResource GrayBrush3}" />
                                        </Style>
                                    </Rectangle.Style>
                                </Rectangle>
                                <TextBlock Grid.Column="1" Margin="10,5" TextAlignment="Center" Text="{DynamicResource String_Button_Check}" />
                            </Grid>
                        </Button.Content>
                    </Button>
                </Grid>
                <Controls:MetroProgressBar Grid.Row="1" Margin="0,10,0,0" Foreground="{DynamicResource AccentColorBrush}" IsIndeterminate="True">
                    <Controls:MetroProgressBar.Style>
                        <Style TargetType="{x:Type  Controls:MetroProgressBar}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsCheckRunning}" Value="False">
                                    <Setter Property="Visibility" Value="Collapsed" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Controls:MetroProgressBar.Style>
                </Controls:MetroProgressBar>
                <TextBlock Grid.Row="2" Foreground="{DynamicResource AccentColorBrush}" Text="{Binding StatusMessage}" Visibility="{Binding DisplayStatusMessage, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{DynamicResource DefaultTextBlock}" Margin="0,10,0,0" />
            </Grid>
            <TextBlock Grid.Row="2" Style="{StaticResource HeaderTextBlock}" Text="{DynamicResource String_Header_Headers}" />
            <TextBox Grid.Row="3" Text="{Binding Headers}" Style="{StaticResource ConsoleTextBox}" IsReadOnly="True" ContextMenu="{StaticResource CopyContextMenu}"/>
            <Expander Grid.Row="4" IsExpanded="{Binding ExpandStatistics}" Visibility="{Binding ShowStatistics, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource HeaderExpander}" Margin="0,20,0,0">
                <Expander.Header>
                    <TextBlock Text="{DynamicResource String_Header_Statistics}" Style="{StaticResource HeaderTextBlock}" Margin="0" />
                </Expander.Header>
                <StackPanel>
                    <Grid Margin="0,10,0,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="10" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.Resources>
                            <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource CenterTextBlock}" />
                            <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextBlockAsTextBox}">
                                <Setter Property="VerticalAlignment" Value="Center" />
                                <Setter Property="ContextMenu" Value="{StaticResource CopyContextMenu}" />
                                <Setter Property="TextWrapping" Value="NoWrap" />
                            </Style>
                        </Grid.Resources>
                        <TextBlock Grid.Column="0" Grid.Row="0" Text="{DynamicResource String_StartTime}" />
                        <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding StartTime, Converter={StaticResource NullableDateTimeToStringConverter}}" />
                        <TextBlock Grid.Column="0" Grid.Row="1" Text="{DynamicResource String_Duration}" />
                        <TextBox Grid.Column="1" Grid.Row="1" Text="{Binding Duration, StringFormat={}{0:hh}h {0:mm}m {0:ss}s {0:ff}ms}" />
                        <TextBlock Grid.Column="0" Grid.Row="2" Text="{DynamicResource String_EndTime}" />
                        <TextBox Grid.Column="1" Grid.Row="2" Text="{Binding EndTime, Converter={StaticResource NullableDateTimeToStringConverter}}" />
                        <TextBlock Grid.Column="3" Grid.Row="0" Text="{DynamicResource String_Headers}" />
                        <TextBox Grid.Column="4" Grid.Row="0" Text="{Binding HeadersCount}" />
                    </Grid>
                </StackPanel>
            </Expander>
        </Grid>
    </Grid>
</UserControl>
