<!--
SidebarTreeView.xaml
12/4/2023

RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
COMPANY.

THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT

UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.

WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
PENALTIES.

DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
DESTROY BY ANY  METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
RECONSTRUCTION OF THE DOCUMENT.
POC: Alex Kravchenko (1118268)
-->
<mah:MetroContentControl x:Class="Raytheon.LogDashboard.View.SidebarTreeView"
             xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
             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:helpers="clr-namespace:Raytheon.LogDashboard.Helpers"
             xmlns:threeView="clr-namespace:Raytheon.LogDashboard.Model"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             DataContext="{Binding LogDashboard, Source={StaticResource LogDashLocator}}"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">

    <mah:MetroContentControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Styles/Styles.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            <HierarchicalDataTemplate DataType="{x:Type threeView:Node}" ItemsSource="{Binding Children}">
                
                <StackPanel Orientation="Horizontal" Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType=mah:MetroContentControl}}">
                    
                    <CheckBox IsChecked="{Binding IsChecked}" Uid="{Binding Id}" 
                              Command="{Binding Path=DataContext.TreeViewElementCheckCommand, RelativeSource={RelativeSource AncestorType=mah:MetroContentControl}}" 
                              x:Name="TreeViewCheckBox"
                              CommandParameter="{Binding RelativeSource={RelativeSource Self}}" 
                              PreviewMouseLeftButtonDown="TreeViewCheckBox_OnPreviewMouseLeftButtonDown" 
                              PreviewKeyDown="TreeViewCheckBox_OnPreviewKeyDown">
                    </CheckBox>
                    
                    <helpers:SearchableTextControl Text="{Binding Text}" 
                                                   SearchText="{Binding DataContext.LoggerHighlightText, RelativeSource={RelativeSource AncestorType=mah:MetroContentControl}}" 
                                                   IsHighlight="True" IsMatchCase="False" 
                                                   Background="{Binding ToggleMark}">
                        <helpers:SearchableTextControl.ToolTip>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="65"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="30"/>
                                    <RowDefinition/>
                                </Grid.RowDefinitions>
                                <TextBlock Grid.Row="0" Text="{Binding Name, StringFormat={}{0}:}" FontWeight="Bold" VerticalAlignment="Top"/>
                                <TextBlock Grid.Row="1" Text="{Binding Source, StringFormat={}{0}:}" FontWeight="Bold"/>

                                <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Text}" VerticalAlignment="Top"/>
                                <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Source}"/>
                            </Grid>
                        </helpers:SearchableTextControl.ToolTip>
                    </helpers:SearchableTextControl>

                    <StackPanel.ContextMenu>
                        <ContextMenu Style="{StaticResource BaseContextMenu}">
                            <MenuItem Header="Collapse All" 
                                      Margin="0" 
                                      Command="{Binding PlacementTarget.Tag.CollapseChildrenCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ContextMenu}}" 
                                      CommandParameter="{Binding}">
                                <MenuItem.Icon>
                                    <Image Source="{StaticResource CollapseImage}" Width="24" Height="24" Margin="4"/>
                                </MenuItem.Icon>
                            </MenuItem>

                            <MenuItem Header="Expand All" 
                                      Margin="0" 
                                      Command="{Binding PlacementTarget.Tag.ExpandChildrenCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ContextMenu}}" 
                                      CommandParameter="{Binding}">
                                <MenuItem.Icon>
                                    <Image Source="{StaticResource ExpandImage}" Width="24" Height="24" Margin="4"/>
                                </MenuItem.Icon>
                            </MenuItem>

                            <Separator />

                            <MenuItem Header="Show only this Logger" 
                                      Command="{Binding PlacementTarget.Tag.ShowOnlyThisLoggerCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ContextMenu}}" 
                                      CommandParameter="{Binding}">
                                <MenuItem.Icon>
                                    <Image Source="{StaticResource EyeImage}" Width="24" Height="24" Margin="4"/>
                                </MenuItem.Icon>
                            </MenuItem>

                            <MenuItem Header="Don't Receive this Logger" 
                                      ToolTip="Don't add new messages to buffer from this Logger" 
                                      Command="{Binding PlacementTarget.Tag.DontReceiveThisLoggerCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}" 
                                      CommandParameter="{Binding}">
                                <MenuItem.Icon>
                                    <Image Source="{StaticResource StopImage}" Width="24" Height="24" Margin="4"/>
                                </MenuItem.Icon>
                            </MenuItem>

                            <MenuItem Header="Add current IP to Ignore List" ToolTip="Don't receive new messages from this IP address" 
                                      Command="{Binding PlacementTarget.Tag.IgnoreThisIPCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}" 
                                      CommandParameter="{Binding}">
                                <MenuItem.Icon>
                                    <Image Source="{StaticResource IgnoreIPStopImage}" Width="24" Height="24" Margin="4"/>
                                </MenuItem.Icon>
                            </MenuItem>

                            <MenuItem Header="Toggle Marking" ToolTip="Mark the messages of this logger in a different color" 
                                      Command="{Binding PlacementTarget.Tag.ToggleMarkCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}" 
                                      CommandParameter="{Binding}">
                                <MenuItem.Icon>
                                    <Image Source="{StaticResource MarkDrawingImage}" Width="24" Height="24" Margin="4"/>
                                </MenuItem.Icon>
                            </MenuItem>

                            <Separator />

                            <MenuItem Header="Clear" Margin="0" 
                                      Command="{Binding PlacementTarget.Tag.ClearChildrenCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ContextMenu}}" 
                                      CommandParameter="{Binding}">
                                <MenuItem.Icon>
                                    <Image Source="{StaticResource CleanImage}" Width="24" Height="24" Margin="4"/>
                                </MenuItem.Icon>
                            </MenuItem>

                            <Separator />

                            <MenuItem Header="Export Current Logger to File" Margin="0" 
                                      Command="{Binding PlacementTarget.Tag.ExportCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ContextMenu}}" 
                                      CommandParameter="{Binding}">
                                <MenuItem.Icon>
                                    <Image Source="{StaticResource ExportDrawingImage}" Width="24" Height="24" Margin="4"/>
                                </MenuItem.Icon>
                            </MenuItem>
                        </ContextMenu>
                    </StackPanel.ContextMenu>
                </StackPanel>
            </HierarchicalDataTemplate>
        </ResourceDictionary>
    </mah:MetroContentControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition/>
            <ColumnDefinition MinWidth="10"/>
        </Grid.ColumnDefinitions>

        <TextBlock Text="Loggers" FontSize="14" Margin="10, 5" HorizontalAlignment="Left" Foreground="{Binding IconColor}"/>

        <Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Margin="0,0,10,10">

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

            <Border CornerRadius="2" Margin="10,0,0,0" Height="33" HorizontalAlignment="Stretch">
                <Border.Style>
                    <Style TargetType="{x:Type Border}">
                        <Setter Property="BorderBrush" Value="{Binding FontColor}"/>
                        <Setter Property="BorderThickness" Value="1"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsFocused, ElementName=SearchLoggerTextBox}" Value="True">
                                <Setter Property="BorderBrush" Value="{Binding IconColor}" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Border.Style>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBox x:Name="SearchLoggerTextBox"
                                Text="{Binding Path=SearchLoggerText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                                Margin="5,0,5,0" 
                                BorderThickness="0"
                                HorizontalAlignment="Stretch" VerticalContentAlignment="Center" >
                        <TextBox.InputBindings>
                            <KeyBinding  Command="{Binding Path=SearchLoggersCommand}" Key="Return" />
                        </TextBox.InputBindings>
                    </TextBox>

                    <Button Grid.Column="1" Margin="0,0,3,0" Padding="0" Height="20" Width="20" ToolTip="Clear search loggers result"
                            Command="{Binding Path=ClearSearchLoggerResultCommand}"
                            Visibility="{Binding Path=IsEnableClearSearchLoggers, Converter={StaticResource BooleanToVisibility}}">
                        <Button.Template>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <Grid x:Name="RootGrid">
                                    <Image Source="{StaticResource CancelDrawingImage}" Cursor="Hand"/>
                                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                </Grid>

                                <ControlTemplate.Triggers>
                                    <Trigger Property ="IsPressed" Value ="True">
                                        <Setter TargetName="RootGrid" Property="RenderTransform">
                                            <Setter.Value>
                                                <ScaleTransform ScaleX="0.95" ScaleY="0.95"/>
                                            </Setter.Value>
                                        </Setter>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Button.Template>
                    </Button>
                </Grid>
            </Border>

            <Button Grid.Column="1" 
                    Height="32" 
                    Width="32" 
                    Margin="5,0,0,0" 
                    Padding="2" 
                    ToolTip="Find Loggers" 
                    Command="{Binding Path=SearchLoggersCommand}">
                <Image Source="{StaticResource SearchDrawingImage}"/>
                <Button.Style>
                    <Style TargetType="{x:Type Button}" BasedOn="{StaticResource CircleImageButtonStyle}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Text.Length, ElementName=SearchLoggerTextBox, UpdateSourceTrigger=PropertyChanged}" Value="0">
                                <Setter Property="IsEnabled" Value="False"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>
        </Grid>

        <TreeView Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" 
                  VerticalAlignment="Top"
                  ItemsSource="{Binding Path=Loggers}" 
                  IsEnabled="{Binding Path=IsEnableLogList}" 
                  x:Name="LoggersTreeView"
                  VirtualizingStackPanel.IsVirtualizing="True"
                  VirtualizingStackPanel.VirtualizationMode="Recycling" >
            <i:Interaction.Behaviors>
                <helpers:BindableSelectedItemBehavior SelectedItem="{Binding SelectedNode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            </i:Interaction.Behaviors>
        </TreeView>

        <StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3">
            <Button Grid.Row="3" Grid.Column="0"
                HorizontalAlignment="Left" 
                VerticalAlignment="Bottom"
                Content="Collapse All" 
                Width="100" 
                Margin="10" 
                Background="{Binding IconColor}"
                Command="{Binding Path=CollapseLoggersCommand}"/>

            <Button Grid.Row="3" Grid.Column="1"
                HorizontalAlignment="Right" 
                VerticalAlignment="Bottom"
                Background="{Binding IconColor}"
                Content="Clear All" 
                Width="100" 
                Margin="10" 
                Command="{Binding Path=ClearLoggersCommand}"/>

        </StackPanel>

    </Grid>

</mah:MetroContentControl>
