using System; using System.Collections.Generic; using Avalonia.Collections; using StabilityMatrix.Core.Extensions; namespace StabilityMatrix.Avalonia.ViewModels.Inference; public abstract class StackViewModelBase : LoadableViewModelBase { private readonly Dictionary> viewModelManager = new(); public AvaloniaList Cards { get; } = new(); /// /// Register new cards /// public void AddCards(IEnumerable cards) { foreach (var card in cards) { var list = viewModelManager.GetOrAdd(card.GetType()); list.Add(card); Cards.Add(card); } } /// /// Registers new cards and returns self /// public StackViewModelBase WithCards(IEnumerable cards) { AddCards(cards); return this; } /// /// Gets a card by type at specified index /// public T GetCard(int index = 0) where T : LoadableViewModelBase { return (T) viewModelManager[typeof(T)][index]; } }