<Page
    x:Class="AppControlManager.Pages.ViewCurrentPolicies"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:AppControlManager.Pages"
    xmlns:customUI="using:AppControlManager.CustomUIElements"
    xmlns:AppControlManager="using:AppControlManager"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ui="using:CommunityToolkit.WinUI"
    xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:controls="using:CommunityToolkit.WinUI.Controls"
    xmlns:tk7controls="using:CommunityToolkit.WinUI.UI.Controls"
    xmlns:animatedvisuals="using:AnimatedVisuals"
    mc:Ignorable="d">

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

        <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>

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

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


                <Button>
                    <Button.Content>
                        <StackPanel Orientation="Horizontal">
                            <FontIcon Glyph="&#xE71C;" />
                            <TextBlock Text="Filter" Margin="5,0,0,0" />
                        </StackPanel>
                    </Button.Content>

                    <Button.Flyout>

                        <customUI:MenuFlyoutV2 Closing="MenuFlyout_Closing">

                            <ToggleMenuFlyoutItem Text="Base Policies" x:Name="IncludeBasePolicies" IsChecked="True">
                                <ToggleMenuFlyoutItem.Icon>
                                    <FontIcon Glyph="&#xEB41;" />
                                </ToggleMenuFlyoutItem.Icon>
                            </ToggleMenuFlyoutItem>

                            <ToggleMenuFlyoutItem Text="Supplemental Policies" x:Name="IncludeSupplementalPolicies" IsChecked="True">
                                <ToggleMenuFlyoutItem.Icon>
                                    <FontIcon Glyph="&#xECC4;" />
                                </ToggleMenuFlyoutItem.Icon>
                            </ToggleMenuFlyoutItem>

                            <ToggleMenuFlyoutItem Text="System Policies" x:Name="IncludeSystemPolicies" IsChecked="False">
                                <ToggleMenuFlyoutItem.Icon>
                                    <FontIcon Glyph="&#xE770;" />
                                </ToggleMenuFlyoutItem.Icon>
                            </ToggleMenuFlyoutItem>

                            <ToggleMenuFlyoutItem Text="Automatic Policies" x:Name="IncludeAppControlManagerSupplementalPolicy" IsChecked="False">
                                <ToggleMenuFlyoutItem.Icon>
                                    <FontIcon Glyph="&#xEC12;" />
                                </ToggleMenuFlyoutItem.Icon>
                            </ToggleMenuFlyoutItem>

                        </customUI:MenuFlyoutV2>
                    </Button.Flyout>
                </Button>

                <Button Name="RetrievePoliciesButton" Click="RetrievePoliciesButton_Click" HorizontalAlignment="Center" VerticalAlignment="Center" ToolTipService.ToolTip="Retrieve the latest deployed policies on the system">
                    <Button.Content>
                        <StackPanel Orientation="Horizontal">
                            <AnimatedIcon Height="25" Width="25" Margin="-5,-5,0,-5">
                                <AnimatedIcon.Source>
                                    <animatedvisuals:Refresh/>
                                </AnimatedIcon.Source>
                            </AnimatedIcon>
                            <TextBlock Text="Retrieve Policies" Margin="5,0,0,0" />
                        </StackPanel>
                    </Button.Content>
                </Button>

                <TextBlock Name="PoliciesCountTextBlock" Text="Number of Policies: 0" VerticalAlignment="Center" HorizontalAlignment="Center" ToolTipService.ToolTip="The count of all of the displayed policies"/>

                <Button x:Name="RemovePolicyButton" Click="RemovePolicy_Click" HorizontalAlignment="Center" VerticalAlignment="Center" ToolTipService.ToolTip="Remove any non-system policy from the system">
                    <Button.Content>
                        <StackPanel Orientation="Horizontal">
                            <FontIcon Glyph="&#xE74D;" />
                            <TextBlock Text="Remove Policy" Margin="5,0,0,0" />
                        </StackPanel>
                    </Button.Content>
                </Button>

                <!-- Search Box for filtering policies -->
                <TextBox x:Name="SearchBox" Width="300" PlaceholderText="Search policies..." TextChanged="SearchBox_TextChanged" VerticalAlignment="Center" />

            </controls:WrapPanel>

        </Border>

        <Border Grid.Row="1" Style="{StaticResource GridCardStyle}" Margin="0" Padding="5">

            <tk7controls:DataGrid
        x:Name="DeployedPolicies"
        ItemsSource="{x:Bind AllPolicies, Mode=OneWay}"
        AllowDrop="False"
        AreRowDetailsFrozen="True"
        AutoGenerateColumns="False"
        CanDrag="False"
        HeadersVisibility="Column"
        IsReadOnly="True"
        IsTabStop="True"
        RowDetailsVisibilityMode="Collapsed"
        SelectionMode="Single"
        TabIndex="2"
        ScrollViewer.HorizontalScrollBarVisibility="Visible"
        ScrollViewer.VerticalScrollBarVisibility="Visible"
        ScrollViewer.VerticalScrollMode="Auto"
        ScrollViewer.HorizontalScrollMode="Auto"
        SelectionChanged="DeployedPolicies_SelectionChanged"
        Sorting="DeployedPoliciesDataGrid_Sorting"
        CanUserSortColumns="True"
        Loaded="DeployedPoliciesDataGrid_Loaded">
                <tk7controls:DataGrid.ContextFlyout>
                    <MenuFlyout>

                        <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="Policy ID" Binding="{Binding PolicyID}" Tag="PolicyID" Width="Auto"/>
                    <tk7controls:DataGridTextColumn Header="Base Policy ID" Binding="{Binding BasePolicyID}" Tag="BasePolicyID" Width="Auto"/>
                    <tk7controls:DataGridTextColumn Header="Friendly Name" Binding="{Binding FriendlyName}" Tag="FriendlyName" Width="Auto"/>
                    <tk7controls:DataGridTextColumn Header="Version" Binding="{Binding Version}" Tag="Version" Width="Auto"/>
                    <tk7controls:DataGridTextColumn Header="Is Authorized" Binding="{Binding IsAuthorized}" Tag="IsAuthorized" Width="Auto"/>
                    <tk7controls:DataGridTextColumn Header="Is Enforced" Binding="{Binding IsEnforced}" Tag="IsEnforced" Width="Auto"/>
                    <tk7controls:DataGridTextColumn Header="Is On Disk" Binding="{Binding IsOnDisk}" Tag="IsOnDisk" Width="Auto"/>
                    <tk7controls:DataGridTextColumn Header="Is Signed Policy" Binding="{Binding IsSignedPolicy}" Tag="IsSignedPolicy" Width="Auto"/>
                    <tk7controls:DataGridTextColumn Header="Is System Policy" Binding="{Binding IsSystemPolicy}" Tag="IsSystemPolicy" Width="Auto"/>
                    <tk7controls:DataGridTextColumn Header="Policy Options" Binding="{Binding PolicyOptionsDisplay}" Tag="PolicyOptionsDisplay" Width="Auto"/>
                </tk7controls:DataGrid.Columns>
            </tk7controls:DataGrid>
        </Border>
    </Grid>
</Page>
