using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using Avalonia.Controls; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.DependencyInjection; using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; using Nebula.Launcher.Models; namespace Nebula.Launcher.ViewModels; public partial class MainViewModel : ViewModelBase { public MainViewModel(AccountInfoViewModel accountInfoViewModel, IServiceProvider serviceProvider) { _currentPage = accountInfoViewModel; _serviceProvider = serviceProvider; Items = new ObservableCollection(_templates); SelectedListItem = Items.First(vm => vm.ModelType == typeof(AccountInfoViewModel)); } private readonly List _templates = [ new ListItemTemplate(typeof(AccountInfoViewModel), "HomeRegular", "Account"), ]; [ObservableProperty] private bool _isPaneOpen; [ObservableProperty] private ViewModelBase _currentPage; private readonly IServiceProvider _serviceProvider; [ObservableProperty] private ListItemTemplate? _selectedListItem; partial void OnSelectedListItemChanged(ListItemTemplate? value) { if (value is null) return; var vm = Design.IsDesignMode ? Activator.CreateInstance(value.ModelType) : _serviceProvider.GetService(value.ModelType); if (vm is not ViewModelBase vmb) return; CurrentPage = vmb; } public ObservableCollection Items { get; } [RelayCommand] private void TriggerPane() { IsPaneOpen = !IsPaneOpen; } }