using System.Linq; using System.Text.Json.Nodes; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Newtonsoft.Json; using StabilityMatrix.Avalonia.Controls; using StabilityMatrix.Avalonia.Models.Inference; using StabilityMatrix.Avalonia.Services; using StabilityMatrix.Avalonia.ViewModels.Base; using StabilityMatrix.Core.Attributes; using StabilityMatrix.Core.Extensions; #pragma warning disable CS0657 // Not a valid attribute location for this declaration namespace StabilityMatrix.Avalonia.ViewModels.Inference; [View(typeof(StackExpander))] [ManagedService] [Transient] public partial class StackExpanderViewModel : StackViewModelBase { public const string ModuleKey = "StackExpander"; [ObservableProperty] [property: JsonIgnore] private string? title; [ObservableProperty] [property: JsonIgnore] private string? titleExtra; [ObservableProperty] private bool isEnabled; /// /// True if parent StackEditableCard is in edit mode (can drag to reorder) /// [ObservableProperty] [property: JsonIgnore] private bool isEditEnabled; /// /// True to show the settings button, invokes when clicked /// public virtual bool IsSettingsEnabled { get; set; } public virtual IRelayCommand? SettingsCommand { get; set; } /// public StackExpanderViewModel(ServiceManager vmFactory) : base(vmFactory) { } public override void OnContainerIndexChanged(int value) { TitleExtra = $"{value + 1}."; } /// public override void LoadStateFromJsonObject(JsonObject state) { base.LoadStateFromJsonObject(state); if ( state.TryGetPropertyValue(nameof(IsEnabled), out var isEnabledNode) && isEnabledNode is JsonValue jsonValue && jsonValue.TryGetValue(out bool isEnabledBool) ) { IsEnabled = isEnabledBool; } } /// public override JsonObject SaveStateToJsonObject() { var state = base.SaveStateToJsonObject(); state.Add(nameof(IsEnabled), IsEnabled); return state; } }