using Microsoft.Extensions.DependencyInjection; using Toolkit.Foundation; namespace Wallet; public class WalletNavigationCollectionViewModelActivationHandler(IPublisher publisher, IWalletHostCollection Wallets) : INotificationHandler> { public Task Handle(ActivationEventArgs args) { bool selected = true; foreach (IComponentHost Wallet in Wallets.OrderBy(x => { IConfigurationDescriptor descriptor = x.Services.GetRequiredService>(); return descriptor?.Name; }, Comparer.Create((x, y) => { bool xIsNumeric = int.TryParse(x, out int xNum); bool yIsNumeric = int.TryParse(y, out int yNum); return (xIsNumeric, yIsNumeric) switch { (true, true) => xNum.CompareTo(yNum), (true, false) => -1, (false, true) => 1, _ => string.Compare(x, y, StringComparison.Ordinal) }; }))) { if (Wallet.Services.GetRequiredService>() is IConfigurationDescriptor configuration) { if (Wallet.Services.GetRequiredService() is IServiceFactory factory) { IDecoratorService> profileImageDecorator = Wallet.Services.GetRequiredService>>(); ProfileImage? profileImage = profileImageDecorator.Value; if (factory.Create(args => args.Initialize(), configuration.Name, profileImage?.Value ?? null, selected) is WalletNavigationViewModel viewModel) { publisher.Publish(Create.As(viewModel), nameof(WalletNavigationCollectionViewModel)); selected = false; } } } } return Task.CompletedTask; } }