<UserControl x:Class="Pulsar.Server.Controls.Wpf.ProcessTreeView"
             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:wpf="clr-namespace:Pulsar.Server.Controls.Wpf"
             mc:Ignorable="d"
             d:DesignWidth="640"
             d:DesignHeight="480">
    <UserControl.Resources>
        <SolidColorBrush x:Key="RowSeparatorBrush" Color="#2E2E2E" />
        <SolidColorBrush x:Key="RowHoverBrush" Color="#2A2A2A" />
        <SolidColorBrush x:Key="ScrollbarTrackBrush" Color="#1E1E1E" />
        <SolidColorBrush x:Key="ScrollbarThumbBrush" Color="#3C3C3C" />
        <SolidColorBrush x:Key="ScrollbarThumbHoverBrush" Color="#525252" />

        <HierarchicalDataTemplate DataType="{x:Type wpf:ProcessTreeNode}" ItemsSource="{Binding Children}">
            <Border BorderBrush="{StaticResource RowSeparatorBrush}"
                    BorderThickness="0,0,0,1"
                    Background="Transparent"
                    Padding="0">
                <Grid Margin="0" VerticalAlignment="Center">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="2*" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Column="0"
                               Text="{Binding Name}"
                               Foreground="{Binding Foreground}" />
                    <TextBlock Grid.Column="1"
                               Text="{Binding PidDisplay}"
                               Margin="16,0,16,0"
                               HorizontalAlignment="Left"
                               Foreground="{Binding Foreground}" />
                    <TextBlock Grid.Column="2"
                               Text="{Binding WindowTitle}"
                               Foreground="{Binding Foreground}" />
                </Grid>
            </Border>
        </HierarchicalDataTemplate>

        <Style TargetType="TreeViewItem">
            <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
            <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
            <Setter Property="Padding" Value="4" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="Foreground" Value="#F5F5F5" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsRatProcess}" Value="True">
                    <Setter Property="Foreground" Value="#9CFF9C" />
                    <Setter Property="FontWeight" Value="SemiBold" />
                </DataTrigger>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background" Value="{StaticResource RowHoverBrush}" />
                    <Setter Property="Foreground" Value="#FFFFFF" />
                </Trigger>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="{StaticResource RowHoverBrush}" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style TargetType="ScrollBar">
            <Setter Property="Width" Value="12" />
            <Setter Property="Background" Value="{StaticResource ScrollbarTrackBrush}" />
            <Setter Property="Foreground" Value="{StaticResource ScrollbarThumbBrush}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ScrollBar">
                        <Grid Background="{TemplateBinding Background}">
                            <Track x:Name="PART_Track"
                                   IsDirectionReversed="true">
                                <Track.Thumb>
                                    <Thumb x:Name="Thumb"
                                           Background="{Binding RelativeSource={RelativeSource AncestorType=ScrollBar}, Path=Foreground}">
                                        <Thumb.Template>
                                            <ControlTemplate TargetType="Thumb">
                                                <Border Background="{TemplateBinding Background}" CornerRadius="4" />
                                            </ControlTemplate>
                                        </Thumb.Template>
                                    </Thumb>
                                </Track.Thumb>
                            </Track>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="Thumb" Property="Background" Value="{StaticResource ScrollbarThumbHoverBrush}" />
                            </Trigger>
                            <Trigger Property="Orientation" Value="Horizontal">
                                <Setter Property="Width" Value="Auto" />
                                <Setter Property="Height" Value="12" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <Grid Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Border Grid.Row="0"
                Background="#1F1F1F"
                BorderBrush="#2E2E2E"
                BorderThickness="0,0,0,1"
                Padding="10,6">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="2*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <StackPanel Grid.Column="0"
                            Orientation="Horizontal"
                            Cursor="Hand"
                            MouseLeftButtonUp="OnNameHeaderClick">
                    <TextBlock Text="Name"
                               Foreground="#F0F0F0"
                               FontSize="13"
                               FontWeight="SemiBold" />
                    <TextBlock Text="{Binding HeaderGlyphName}"
                               Foreground="#F0F0F0"
                               Margin="6,0,0,0" />
                </StackPanel>

                <StackPanel Grid.Column="1"
                            Orientation="Horizontal"
                            Margin="16,0"
                            Cursor="Hand"
                            MouseLeftButtonUp="OnPidHeaderClick">
                    <TextBlock Text="PID"
                               Foreground="#F0F0F0"
                               FontSize="13"
                               FontWeight="SemiBold" />
                    <TextBlock Text="{Binding HeaderGlyphPid}"
                               Foreground="#F0F0F0"
                               Margin="6,0,0,0" />
                </StackPanel>

                <StackPanel Grid.Column="2"
                            Orientation="Horizontal"
                            Cursor="Hand"
                            MouseLeftButtonUp="OnTitleHeaderClick">
                    <TextBlock Text="Window Title"
                               Foreground="#F0F0F0"
                               FontSize="13"
                               FontWeight="SemiBold" />
                    <TextBlock Text="{Binding HeaderGlyphTitle}"
                               Foreground="#F0F0F0"
                               Margin="6,0,0,0" />
                </StackPanel>
            </Grid>
        </Border>

        <Border Grid.Row="1" Background="Transparent">
            <TreeView x:Name="Tree"
                      ItemsSource="{Binding RootNodes}"
                      Background="Transparent"
                      BorderThickness="0"
                      ScrollViewer.VerticalScrollBarVisibility="Auto"
                      ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                      SelectedItemChanged="OnTreeSelected"
                      PreviewMouseRightButtonDown="OnTreePreviewRightMouse"
                      PreviewMouseWheel="OnTreePreviewMouseWheel" />
        </Border>
    </Grid>
</UserControl>