<Page
    x:Class="Microsoft.PowerToys.Settings.UI.Views.SearchResultsPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls"
    xmlns:converters="using:Microsoft.PowerToys.Settings.UI.Converters"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:models="using:Settings.UI.Library"
    xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls"
    xmlns:tkconverters="using:CommunityToolkit.WinUI.Converters"
    xmlns:ui="using:CommunityToolkit.WinUI"
    xmlns:vm="using:Microsoft.PowerToys.Settings.UI.ViewModels"
    x:Name="RootPage"
    AutomationProperties.LandmarkType="Main"
    mc:Ignorable="d">

    <Page.Resources>
        <converters:IconConverter x:Key="IconConverter" />
        <tkconverters:CollectionVisibilityConverter x:Key="CollectionVisibilityConverter" />
    </Page.Resources>

    <controls:SettingsPageControl x:Name="PageControl" x:Uid="SearchResults_Title">
        <controls:SettingsPageControl.ModuleContent>
            <StackPanel Margin="0,-40,0,0" Orientation="Vertical">
                <controls:SettingsGroup
                    x:Uid="SearchResults_ModulesTitle"
                    Margin="0,-10,0,0"
                    Visibility="{x:Bind ViewModel.ModuleResults, Mode=OneWay, Converter={StaticResource CollectionVisibilityConverter}}">
                    <ItemsControl
                        x:Name="ModulesItemsControl"
                        IsTabStop="False"
                        ItemsSource="{x:Bind ViewModel.ModuleResults, Mode=OneWay}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate x:DataType="models:SettingEntry">
                                <tkcontrols:SettingsCard
                                    Margin="0,0,0,2"
                                    Click="ModuleButton_Click"
                                    Header="{x:Bind Header}"
                                    HeaderIcon="{x:Bind Icon, Converter={StaticResource IconConverter}, ConverterParameter=&#xE8B7;}"
                                    IsClickEnabled="True" />
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </controls:SettingsGroup>

                <!--  Settings Groups  -->
                <ItemsControl
                    x:Name="SettingsGroupsItemsControl"
                    IsTabStop="False"
                    ItemsSource="{x:Bind ViewModel.GroupedSettingsResults, Mode=OneWay}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate x:DataType="vm:SettingsGroup">
                            <controls:SettingsGroup Header="{x:Bind GroupName}">
                                <ItemsControl IsTabStop="False" ItemsSource="{x:Bind Settings}">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate x:DataType="models:SettingEntry">
                                            <tkcontrols:SettingsCard
                                                Margin="0,0,0,2"
                                                Click="SettingButton_Click"
                                                Description="{x:Bind Description}"
                                                Header="{x:Bind Header}"
                                                HeaderIcon="{x:Bind Icon, Converter={StaticResource IconConverter}, ConverterParameter=&#xE713;}"
                                                IsClickEnabled="True" />
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </controls:SettingsGroup>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>

                <!--  No Results Message  -->
                <StackPanel
                    x:Name="NoResultsPanel"
                    HorizontalAlignment="Center"
                    Spacing="16"
                    Visibility="{x:Bind ViewModel.HasNoResults, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
                    <FontIcon
                        AutomationProperties.AccessibilityView="Raw"
                        FontSize="48"
                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                        Glyph="&#xE71C;" />
                    <TextBlock HorizontalAlignment="Center" TextAlignment="Center">
                        <Run x:Uid="SearchResults_NoResultsHeader" FontWeight="SemiBold" />
                        <LineBreak />
                        <Run x:Uid="SearchResults_NoResultsDescription" Foreground="{ThemeResource TextFillColorSecondaryBrush}" />
                    </TextBlock>
                </StackPanel>
            </StackPanel>
        </controls:SettingsPageControl.ModuleContent>
    </controls:SettingsPageControl>
</Page>
