﻿<UserControl x:Class="OpenTapEditor.LogControl"
             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:local="clr-namespace:OpenTapEditor.UI"
             mc:Ignorable="d" 
             xmlns:pu="https://opensource.panuon.com/wpf-ui"
             d:DesignHeight="450" d:DesignWidth="800" Cursor="">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <pu:StyleDictionary Includes="TextBox" />
            </ResourceDictionary.MergedDictionaries>
            <CollectionViewSource x:Key="LogFilter" Source="{Binding Datasouruce}" Filter="CollectionViewSource_Filter">

            </CollectionViewSource>
        </ResourceDictionary>
    </UserControl.Resources>

    <Border Grid.Row="5" Background="White" BorderBrush="{StaticResource BorderDarkBrush}" BorderThickness="1">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="26"/>
                <RowDefinition Height="28"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <Border Grid.Row="0" Background="#E8E8E8"
                 BorderBrush="{StaticResource BorderBrush}" BorderThickness="0,0,0,1">
                <TextBlock Text="{DynamicResource 日志}" FontWeight="Bold" FontSize="11"
                        VerticalAlignment="Center" Margin="4,0"/>
            </Border>

            <Border Grid.Row="1" Background="{StaticResource BgBrush}"
                 BorderBrush="{StaticResource BorderBrush}" BorderThickness="0,0,0,1">
                <StackPanel Orientation="Horizontal" Margin="4,0">
                    <ToggleButton Content="{DynamicResource 错误}" Height="22" Padding="8,0" Cursor="Hand"
                         IsChecked="{Binding ShowError,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                         Background="#FFEBEE" Foreground="{StaticResource ErrorBrush}"
                         BorderBrush="{StaticResource ErrorBrush}" BorderThickness="1" FontSize="10"/>
                    <ToggleButton Content="{DynamicResource 警告}" Height="22" Padding="8,0" Margin="2,0,0,0" Cursor="Hand"
                         IsChecked="{Binding ShowWarn,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                         Background="#FFF8E1" Foreground="{StaticResource WarningBrush}"
                         BorderBrush="{StaticResource WarningBrush}" BorderThickness="1" FontSize="10"/>
                    <ToggleButton Content="{DynamicResource 信息}" Height="22" Padding="8,0" Margin="2,0,0,0" Cursor="Hand"
                         IsChecked="{Binding ShowInfo,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                         Background="#E8F5E9" Foreground="{StaticResource SuccessBrush}"
                         BorderBrush="{StaticResource SuccessBrush}" BorderThickness="1" FontSize="10"/>
                    <ToggleButton Content="{DynamicResource 调试}" Height="22" Padding="8,0" Margin="2,0,0,0" Cursor="Hand"
                         IsChecked="{Binding ShowDebug,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                         Background="White" BorderBrush="{StaticResource BorderBrush}"
                         BorderThickness="1" FontSize="10"/>
                    <ToggleButton Content="{DynamicResource 全部}" Height="22" Padding="8,0" Margin="2,0,0,0" Cursor="Hand"
                         IsChecked="{Binding ShowAll,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                         Background="White" BorderBrush="{StaticResource BorderBrush}"
                         BorderThickness="1" FontSize="10"/>

                    <Rectangle Width="1" Height="20" Fill="{StaticResource BorderBrush}" Margin="6,0"/>

                    <TextBlock Text="{DynamicResource 搜索}" VerticalAlignment="Center" Margin="8,0,4,0" FontSize="11"/>
                    <TextBox Width="150" Height="22" 
                             pu:TextBoxHelper.ClearButtonVisibility="VisibleOnHoverAndNonnull"
                             Text="{Binding SearchText,UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center"/>

                    <Button Style="{StaticResource ActionButtonStyle}" Content="{DynamicResource 清空}" Click="Button_Click" 
                            Margin="8,0,0,0" Padding="8,0"/>
                </StackPanel>
            </Border>

            <ListView x:Name="log" Grid.Row="2" ScrollViewer.HorizontalScrollBarVisibility="Disabled" BorderThickness="0"
          VirtualizingPanel.ScrollUnit="Pixel" 
          ItemsSource="{Binding ViewSource.View}">
                <ListView.Resources>
                    <Style TargetType="TextBlock">
                        <Setter Property="TextWrapping" Value="Wrap"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Type}" Value="10">
                                <Setter Property="Foreground" Value="Red"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Type}" Value="20">
                                <Setter Property="Foreground" Value="OrangeRed"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Type}" Value="40">
                                <Setter Property="Foreground" Value="Gray"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ListView.Resources>
            </ListView>

            <Border x:Name="resultShow" Margin="0,50,0,50" Grid.Row="2" Visibility="Collapsed">
                <Label VerticalContentAlignment="Center" HorizontalContentAlignment="Center"
                       FontSize="50" x:Name="resultLabel"/>
            </Border>
        </Grid>
    </Border>

    <!--<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
            <CheckBox VerticalAlignment="Center" VerticalContentAlignment="Center" IsChecked="{Binding ShowError,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Content="错误"/>
            <CheckBox VerticalAlignment="Center" VerticalContentAlignment="Center" IsChecked="{Binding ShowWarn,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Content="警告"/>
            <CheckBox VerticalAlignment="Center" VerticalContentAlignment="Center" IsChecked="{Binding ShowInfo,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Content="信息"/>
            <CheckBox VerticalAlignment="Center" VerticalContentAlignment="Center" IsChecked="{Binding ShowDebug,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Content="调试"/>
            <Button VerticalAlignment="Center" VerticalContentAlignment="Center" Click="Button_Click">清空</Button>
        </StackPanel>
        <ListView x:Name="log" Grid.Row="1" ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                  VirtualizingPanel.ScrollUnit="Pixel" 
                  ItemsSource="{Binding ViewSource.View}">
            <ListView.Resources>
                <Style TargetType="TextBlock">
                    <Setter Property="TextWrapping" Value="Wrap"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Type}" Value="10">
                            <Setter Property="Foreground" Value="Red"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="20">
                            <Setter Property="Foreground" Value="OrangeRed"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="40">
                            <Setter Property="Foreground" Value="Gray"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ListView.Resources>
            -->
    <!--<ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="Foreground" Value="Red"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Texy BorderThickness="0" IsReadOnly="True"
                                         TextWrapping="Wrap" Text="{Binding Mode=OneWay}"/>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Type,RelativeSource={RelativeSource Self}}" Value="10">
                            <Setter Property="Foreground" Value="Red"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type,RelativeSource={RelativeSource Self}}" Value="20">
                            <Setter Property="Foreground" Value="OrangeRed"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type,RelativeSource={RelativeSource Self}}" Value="40">
                            <Setter Property="Foreground" Value="Gray"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ListView.ItemContainerStyle>-->
    <!--
        </ListView>
    </Grid>-->
</UserControl>
