<UserControl
    x:Class="SHH.CameraDashboard.ServiceNodesDiagnostic"
    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:local="clr-namespace:SHH.CameraDashboard"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    d:DesignHeight="450"
    d:DesignWidth="800"
    mc:Ignorable="d">

    <UserControl.Resources>

        <local:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
        <local:InverseNullToVisibilityConverter x:Key="InverseNullToVisibilityConverter" />

    </UserControl.Resources>

    <Grid Background="{DynamicResource Brush.Bg.Window}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" MinWidth="250" />
                <ColumnDefinition Width="5" />
                <ColumnDefinition Width="*" MinWidth="300" />
            </Grid.ColumnDefinitions>

            <ListView
                x:Name="LogList"
                Grid.Column="0"
                Background="Transparent"
                BorderThickness="0"
                ItemContainerStyle="{StaticResource Style.ListViewItem.Table}"
                ItemsSource="{Binding Logs}"
                SelectedItem="{Binding SelectedLog}">
                <ListView.View>
                    <GridView ColumnHeaderContainerStyle="{StaticResource Style.GridViewHeader.Flat}">
                        <GridViewColumn
                            Width="150"
                            DisplayMemberBinding="{Binding Time, StringFormat='MM-dd HH:mm:ss fff'}"
                            Header="请求时间" />
                        <GridViewColumn
                            Width="60"
                            DisplayMemberBinding="{Binding StatusCode}"
                            Header="状态" />
                        <GridViewColumn
                            Width="70"
                            DisplayMemberBinding="{Binding ElapsedMilliseconds}"
                            Header="耗时 ms" />
                        <GridViewColumn
                            Width="60"
                            DisplayMemberBinding="{Binding Method}"
                            Header="动作" />
                        <GridViewColumn
                            Width="120"
                            DisplayMemberBinding="{Binding AppModule}"
                            Header="模块" />
                        <GridViewColumn
                            Width="300"
                            DisplayMemberBinding="{Binding Url}"
                            Header="URL" />
                    </GridView>
                </ListView.View>
            </ListView>

            <GridSplitter
                Grid.Column="1"
                Width="5"
                HorizontalAlignment="Stretch"
                Background="{DynamicResource Brush.Bg.Panel}" />

            <Grid Grid.Column="2" Background="{DynamicResource Brush.Bg.Input}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <Border
                    Background="{DynamicResource Brush.Bg.Panel}"
                    BorderBrush="{DynamicResource Brush.Border}"
                    BorderThickness="0,0,0,1">
                    <DockPanel LastChildFill="False">
                        <StackPanel Orientation="Horizontal">
                            <RadioButton
                                Command="{Binding SwitchTabCommand}"
                                CommandParameter="0"
                                Content="Request"
                                GroupName="Logs"
                                IsChecked="True"
                                Style="{StaticResource TabRadioStyle}" />
                            <RadioButton
                                Command="{Binding SwitchTabCommand}"
                                CommandParameter="1"
                                Content="Response"
                                GroupName="Logs"
                                Style="{StaticResource TabRadioStyle}" />
                        </StackPanel>
                    </DockPanel>
                </Border>

                <TextBox
                    Grid.Row="1"
                    IsReadOnly="True"
                    Style="{StaticResource Style.TextBox.CodeEditor}"
                    Text="{Binding DisplayContent}"
                    Visibility="{Binding SelectedLog, Converter={StaticResource NullToVisibilityConverter}}" />

                <StackPanel
                    Grid.Row="1"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Visibility="{Binding SelectedLog, Converter={StaticResource InverseNullToVisibilityConverter}}">
                    <TextBlock Foreground="{DynamicResource Brush.Text.Secondary}" Text="请选择一条日志查看详情" />
                </StackPanel>
            </Grid>
        </Grid>

        <CheckBox
            Margin="15,0,0,0"
            HorizontalAlignment="Right"
            VerticalAlignment="Top"
            Content="过滤自动发送"
            Foreground="{DynamicResource Brush.Text.Secondary}"
            IsChecked="{Binding IsFilterAutoLogs}"
            Style="{DynamicResource Style.CheckBox.Switch}" />
    </Grid>
</UserControl>
