// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;
using PowerToysExtension.Helpers;
using PowerToysExtension.Properties;

namespace PowerToysExtension.Pages;

internal sealed partial class PowerToysListPage : ListPage
{
    private readonly CommandItem _empty;

    public PowerToysListPage()
    {
        Icon = PowerToysResourcesHelper.ProviderIcon();
        Name = Title = Resources.PowerToys_DisplayName;
        Id = "com.microsoft.cmdpal.powertoys";
        SettingsChangeNotifier.SettingsChanged += OnItemsChanged;
        KeyboardManagerStateService.StatusChanged += OnItemsChanged;
        _empty = new CommandItem()
        {
            Icon = PowerToysResourcesHelper.ProviderIcon(),
            Title = Resources.PowerToys_NoMatchingModule,
            Subtitle = SearchText,
        };
        EmptyContent = _empty;
    }

    private void OnItemsChanged()
    {
        RaiseItemsChanged(0);
    }

    public override IListItem[] GetItems() => ModuleCommandCatalog.GetAllItems();
}
