<UserControl
    x:Class="Microsoft.PowerToys.Settings.UI.Controls.ModuleList"
    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.Controls.Converters"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:tk="using:CommunityToolkit.WinUI"
    xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls"
    xmlns:tkconverters="using:CommunityToolkit.WinUI.Converters"
    mc:Ignorable="d">

    <UserControl.Resources>
        <converters:ModuleListSortOptionToBooleanConverter x:Key="ModuleListSortOptionToBooleanConverter" />
        <x:Double x:Key="SettingsCardWrapThreshold">0</x:Double>
        <tkconverters:BoolToVisibilityConverter
            x:Key="BoolToVisibilityConverter"
            FalseValue="Collapsed"
            TrueValue="Visible" />
        <tkconverters:BoolToVisibilityConverter
            x:Key="ReverseBoolToVisibilityConverter"
            FalseValue="Visible"
            TrueValue="Collapsed" />
        <tkconverters:BoolNegationConverter x:Key="BoolNegationConverter" />

        <Style x:Key="NewInfoBadgeStyle" TargetType="InfoBadge">
            <Setter Property="Padding" Value="5,1,5,2" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="InfoBadge">
                        <Border
                            x:Name="RootGrid"
                            Padding="{TemplateBinding Padding}"
                            Background="{TemplateBinding Background}"
                            CornerRadius="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.InfoBadgeCornerRadius}">
                            <TextBlock
                                x:Uid="NewInfoBadge"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                FontSize="10" />
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <ItemsRepeater x:Name="DashboardView" ItemsSource="{x:Bind ItemsSource, Mode=OneWay}">
        <ItemsRepeater.Layout>
            <StackLayout Orientation="Vertical" Spacing="0" />
        </ItemsRepeater.Layout>
        <ItemsRepeater.ItemTemplate>
            <DataTemplate x:DataType="controls:ModuleListItem">
                <tkcontrols:SettingsCard
                    MinWidth="0"
                    MinHeight="0"
                    Padding="12,4,12,4"
                    tk:FrameworkElementExtensions.AncestorType="controls:ModuleList"
                    Background="Transparent"
                    BorderBrush="{ThemeResource DividerStrokeColorDefaultBrush}"
                    BorderThickness="{Binding (tk:FrameworkElementExtensions.Ancestor).DividerThickness, RelativeSource={RelativeSource Self}}"
                    Click="OnSettingsCardClick"
                    CornerRadius="0"
                    IsClickEnabled="{Binding (tk:FrameworkElementExtensions.Ancestor).IsItemClickable, RelativeSource={RelativeSource Self}}"
                    Tag="{x:Bind}">
                    <tkcontrols:SettingsCard.Header>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{x:Bind Label, Mode=OneWay}" />
                            <!--  InfoBadge  -->
                            <InfoBadge
                                x:Name="NewInfoBadge"
                                Margin="4,0,0,0"
                                Style="{StaticResource NewInfoBadgeStyle}"
                                Visibility="{x:Bind IsNew, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}" />
                            <FontIcon
                                Width="20"
                                Margin="4,0,0,0"
                                FontSize="16"
                                Glyph="&#xE72E;"
                                Visibility="{x:Bind IsLocked, Converter={StaticResource ReverseBoolToVisibilityConverter}, ConverterParameter=True}">
                                <ToolTipService.ToolTip>
                                    <TextBlock x:Uid="GPOWarning" TextWrapping="WrapWholeWords" />
                                </ToolTipService.ToolTip>
                            </FontIcon>
                        </StackPanel>
                    </tkcontrols:SettingsCard.Header>

                    <tkcontrols:SettingsCard.HeaderIcon>
                        <ImageIcon>
                            <ImageIcon.Source>
                                <BitmapImage UriSource="{x:Bind Icon, Mode=OneWay}" />
                            </ImageIcon.Source>
                        </ImageIcon>
                    </tkcontrols:SettingsCard.HeaderIcon>

                    <ToggleSwitch
                        HorizontalAlignment="Right"
                        AutomationProperties.Name="{x:Bind Label, Mode=OneWay}"
                        IsEnabled="{x:Bind IsLocked, Converter={StaticResource BoolNegationConverter}, ConverterParameter=True, Mode=OneWay}"
                        IsOn="{x:Bind IsEnabled, Mode=TwoWay}"
                        OffContent=""
                        OnContent="" />
                </tkcontrols:SettingsCard>
            </DataTemplate>
        </ItemsRepeater.ItemTemplate>
    </ItemsRepeater>
</UserControl>
