<?xml version="1.0" encoding="utf-8"?>
<Page
    x:Class="AppControlManager.Pages.AllowNewAppsEventLogsDataGrid"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:AppControlManager.Pages"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:ui="using:CommunityToolkit.WinUI"
    xmlns:controls="using:CommunityToolkit.WinUI.Controls"
    xmlns:tk7controls="using:CommunityToolkit.WinUI.UI.Controls"
    xmlns:animations="using:CommunityToolkit.WinUI.Animations">

    <Grid>

        <Grid.Resources>
            <Style x:Key="GridCardStyle" TargetType="Border">
                <Style.Setters>
                    <Setter Property="Background" Value="{ThemeResource CardBackgroundFillColorDefaultBrush}" />
                    <Setter Property="BorderThickness" Value="1" />
                    <Setter Property="BorderBrush" Value="{ThemeResource CardStrokeColorDefaultBrush}" />
                    <Setter Property="CornerRadius" Value="{StaticResource OverlayCornerRadius}" />
                </Style.Setters>
            </Style>

        </Grid.Resources>

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


        <Border Grid.Row="0" Margin="0,10,0,10" Style="{StaticResource GridCardStyle}" Padding="8">

            <controls:WrapPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalSpacing="10" VerticalSpacing="10">

                <ProgressRing x:Name="SelectLogsProgressRing" Visibility="Collapsed" IsActive="False" />

                <DropDownButton Content="Actions" ToolTipService.ToolTip="Multiple actions to take on the logs">
                    <DropDownButton.Flyout>

                        <MenuFlyout Placement="Bottom">

                            <MenuFlyoutItem Text="Select All" Click="SelectAll_Click">
                                <MenuFlyoutItem.Icon>
                                    <FontIcon Glyph="&#xE762;"/>
                                </MenuFlyoutItem.Icon>
                            </MenuFlyoutItem>

                            <MenuFlyoutItem Text="De-Select All" Click="DeSelectAll_Click">
                                <MenuFlyoutItem.Icon>
                                    <FontIcon Glyph="&#xE8E6;"/>
                                </MenuFlyoutItem.Icon>
                            </MenuFlyoutItem>

                            <MenuFlyoutItem Text="Clear Data" Click="ClearDataButton_Click" ToolTipService.ToolTip="Clears all of the displayed data">
                                <MenuFlyoutItem.Icon>
                                    <SymbolIcon Symbol="Delete" />
                                </MenuFlyoutItem.Icon>
                            </MenuFlyoutItem>

                        </MenuFlyout>

                    </DropDownButton.Flyout>
                </DropDownButton>

                <TextBox PlaceholderText="Total logs: 0"
               x:Name="TotalCountOfTheFilesTextBox"
               IsReadOnly="True"
               VerticalAlignment="Center"
               VerticalContentAlignment="Center" ToolTipService.ToolTip="The total number of the logs"/>

                <TextBox x:Name="SearchBox" Width="300" PlaceholderText="Search data..." TextChanged="SearchBox_TextChanged" VerticalAlignment="Center" VerticalContentAlignment="Center" ToolTipService.ToolTip="Search the data" />

            </controls:WrapPanel>
        </Border>

        <!-- DataGrid for FileIdentity Outputs -->
        <Border Grid.Row="1" Style="{StaticResource GridCardStyle}" Margin="0,0,0,25" Padding="5">
            <tk7controls:DataGrid
            ItemsSource="{x:Bind local:AllowNewAppsStart.Instance.EventLogsFileIdentities, Mode=OneWay}"
            x:Name="FileIdentitiesDataGrid"
            AllowDrop="False"
            AreRowDetailsFrozen="True"
            AutoGenerateColumns="False"
            CanDrag="False"
            HeadersVisibility="Column"
            IsReadOnly="True"
            IsTabStop="True"
            RowDetailsVisibilityMode="Collapsed"
            SelectionMode="Extended"
            TabIndex="2"
            ScrollViewer.HorizontalScrollBarVisibility="Auto"
            ScrollViewer.VerticalScrollBarVisibility="Auto"
            ScrollViewer.VerticalScrollMode="Auto"
            ScrollViewer.HorizontalScrollMode="Auto"
            Sorting="FileIdentitiesDataGrid_Sorting"
            CanUserSortColumns="True"
            Loaded="FileIdentitiesDataGrid_Loaded">
                <tk7controls:DataGrid.ContextFlyout>
                    <MenuFlyout>
                        <MenuFlyoutItem Text="Delete Row" Click="DataGridFlyoutMenuDelete_Click">
                            <MenuFlyoutItem.Icon>
                                <FontIcon Glyph="&#xE74D;" />
                            </MenuFlyoutItem.Icon>
                        </MenuFlyoutItem>

                        <MenuFlyoutItem Text="Copy Row" Click="DataGridFlyoutMenuCopy_Click">
                            <MenuFlyoutItem.Icon>
                                <FontIcon Glyph="&#xE8C8;" />
                            </MenuFlyoutItem.Icon>
                        </MenuFlyoutItem>

                        <MenuFlyoutSubItem x:Name="CopyIndividualItemsSubMenu" Text="Copy Individual Items">
                            <MenuFlyoutSubItem.Icon>
                                <FontIcon Glyph="&#xE8C8;" />
                            </MenuFlyoutSubItem.Icon>
                            <!-- Dynamic items will be added here in the Loaded event handler -->
                        </MenuFlyoutSubItem>

                    </MenuFlyout>
                </tk7controls:DataGrid.ContextFlyout>

                <tk7controls:DataGrid.Columns>
                    <tk7controls:DataGridTextColumn Header="File Name" Binding="{Binding FileName}" Width="Auto" Tag="FileName"/>
                    <tk7controls:DataGridTextColumn Header="Time Created" Binding="{Binding TimeCreated}" Width="Auto" Tag="TimeCreated"/>
                    <tk7controls:DataGridTextColumn Header="Signature Status" Binding="{Binding SignatureStatus}" Tag="SignatureStatus" Width="Auto"/>
                    <tk7controls:DataGridTextColumn Header="Action" Binding="{Binding Action}" Width="Auto" Tag="Action"/>
                    <tk7controls:DataGridTextColumn Header="Original File Name" Binding="{Binding OriginalFileName}" Width="Auto" Tag="OriginalFileName"/>
                    <tk7controls:DataGridTextColumn Header="InternalName" Binding="{Binding InternalName}" Width="Auto" Tag="InternalName"/>
                    <tk7controls:DataGridTextColumn Header="File Description" Binding="{Binding FileDescription}" Width="Auto" Tag="FileDescription"/>
                    <tk7controls:DataGridTextColumn Header="Product Name" Binding="{Binding ProductName}" Width="Auto" Tag="ProductName"/>
                    <tk7controls:DataGridTextColumn Header="File Version" Binding="{Binding FileVersion}" Width="Auto" Tag="FileVersion"/>
                    <tk7controls:DataGridTextColumn Header="Package Family Name" Binding="{Binding PackageFamilyName}" Width="Auto" Tag="PackageFamilyName"/>
                    <tk7controls:DataGridTextColumn Header="SHA256 Hash" Binding="{Binding SHA256Hash}" Width="Auto" Tag="SHA256Hash"/>
                    <tk7controls:DataGridTextColumn Header="SHA1 Hash" Binding="{Binding SHA1Hash}" Width="Auto" Tag="SHA1Hash"/>
                    <tk7controls:DataGridTextColumn Header="SHA256 Flat Hash" Binding="{Binding SHA256FlatHash}" Width="Auto" Tag="SHA256FlatHash"/>
                    <tk7controls:DataGridTextColumn Header="SHA1 Flat Hash" Binding="{Binding SHA1FlatHash}" Width="Auto" Tag="SHA1FlatHash"/>
                    <tk7controls:DataGridTextColumn Header="Signing Scenario" Binding="{Binding SISigningScenario}" Width="Auto" Tag="SISigningScenario"/>
                    <tk7controls:DataGridTextColumn Header="File Path" Binding="{Binding FilePath}" Width="Auto" Tag="FilePath"/>
                    <tk7controls:DataGridTextColumn Header="Computer Name" Binding="{Binding ComputerName}" Width="Auto" Tag="ComputerName"/>
                    <tk7controls:DataGridTextColumn Header="Policy GUID" Binding="{Binding PolicyGUID}" Width="Auto" Tag="PolicyGUID"/>
                    <tk7controls:DataGridTextColumn Header="Policy Name" Binding="{Binding PolicyName}" Width="Auto" Tag="PolicyName"/>
                    <tk7controls:DataGridTextColumn Header="File Publishers" Binding="{Binding FilePublishersToDisplay}" Width="Auto" Tag="FilePublishersToDisplay"/>

                </tk7controls:DataGrid.Columns>
            </tk7controls:DataGrid>
        </Border>

    </Grid>
</Page>
