using System.Linq; using System.Windows; using ClaudeDo.Installer.Core; using ClaudeDo.Installer.Pages.InstallPage; using ClaudeDo.Installer.Pages.WelcomePage; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; namespace ClaudeDo.Installer.Views; public partial class WizardViewModel : ObservableObject { private readonly InstallContext _context; public IReadOnlyList Pages { get; } [ObservableProperty] [NotifyPropertyChangedFor(nameof(CanGoBack))] [NotifyPropertyChangedFor(nameof(IsLastPage))] [NotifyPropertyChangedFor(nameof(NextButtonText))] [NotifyPropertyChangedFor(nameof(CurrentPage))] private int _currentPageIndex; public IInstallerPage CurrentPage => Pages[CurrentPageIndex]; public bool CanGoBack => CurrentPageIndex > 0; public bool IsLastPage => CurrentPageIndex == Pages.Count - 1; public string NextButtonText => IsLastPage ? "Install" : "Next \u2192"; [ObservableProperty] private string? _validationError; public WizardViewModel(PageResolver resolver, InstallContext context) { _context = context; var all = resolver.WizardPages; Pages = context.Mode == InstallerMode.Update ? all.Where(p => p is WelcomePageViewModel || p is InstallPageViewModel).ToList() : all; if (Pages.Count > 0) _ = InitAsync(); } private async Task InitAsync() { try { await Pages[0].LoadAsync(); } catch { /* first page loads with defaults on error */ } } [RelayCommand] private async Task GoBack() { if (!CanGoBack) return; CurrentPageIndex--; await CurrentPage.LoadAsync(); ValidationError = null; } [RelayCommand] private async Task GoNext() { if (!CurrentPage.Validate()) { ValidationError = "Please fix the highlighted errors before continuing."; return; } ValidationError = null; await CurrentPage.ApplyAsync(); if (CurrentPageIndex < Pages.Count - 1) { CurrentPageIndex++; await CurrentPage.LoadAsync(); } } [RelayCommand] private void Close() { Application.Current.Shutdown(); } }