using CommunityToolkit.Mvvm.ComponentModel; using Toolkit.Foundation; namespace Wallet; public partial class ItemHeaderViewModel : Observable, INotificationHandler>, INotificationHandler>, INotificationHandler>, INotificationHandler>>, IItemViewModel { private readonly ItemHeaderConfiguration configuration; [ObservableProperty] private string? category; [ObservableProperty] private ItemState state; public ItemHeaderViewModel(IServiceProvider provider, IServiceFactory factory, IMediator mediator, IPublisher publisher, ISubscription subscriber, IDisposer disposer, ItemHeaderConfiguration configuration, ItemState state, string key, string value) : base(provider, factory, mediator, publisher, subscriber, disposer, key, value) { this.configuration = configuration; State = state; Value = value; Track(nameof(Value), () => Value, newValue => Value = newValue); } public Task Handle(UpdateEventArgs args) => Task.FromResult(State = ItemState.Write); public Task Handle(CancelEventArgs args) { Revert(); State = ItemState.Read; return Task.CompletedTask; } protected override void OnValueChanged() { if (configuration is not null) { configuration.Name = Value; } } public Task Handle(ConfirmEventArgs args) { Commit(); State = ItemState.Read; return Task.CompletedTask; } public Task Handle(NotifyEventArgs> args) { if (args.Sender is ItemCategory category) { Category = category.Value; } return Task.CompletedTask; } }