using System.Reflection; using System.Windows.Input; using Titano.App.Infrastructure; using Titano.App.Shell; using Titano.Core.Localization; using Titano.Ui.Mvvm; using Titano.Ui.Theming; namespace Titano.App.Sections; /// Library (home): sequences of the archive (BRIEF §12.2). public sealed class LibraryViewModel(ShellViewModel shell) : SectionViewModel(SectionKey.Library, "Icon.Library") { public ShellViewModel Shell { get; } = shell; public ICommand ImportCardCommand => new RelayCommand(() => Shell.Navigate(SectionKey.Import)); public ICommand OpenArchiveCommand => new RelayCommand(() => Shell.Navigate(SectionKey.Archive)); public ICommand ConnectCommand => new RelayCommand(() => Shell.Navigate(SectionKey.Server)); } /// Card and folder import (BRIEF §12.4). public sealed class ImportViewModel(ShellViewModel shell) : SectionViewModel(SectionKey.Import, "Icon.Import") { public ShellViewModel Shell { get; } = shell; } /// Sequence editor (BRIEF §12.3). public sealed class SequenceViewModel(ShellViewModel shell) : SectionViewModel(SectionKey.Sequence, "Icon.Sequence") { public ShellViewModel Shell { get; } = shell; public ICommand OpenLibraryCommand => new RelayCommand(() => Shell.Navigate(SectionKey.Library)); } /// Archive manager (BRIEF §12.5). public sealed class ArchiveViewModel(ShellViewModel shell) : SectionViewModel(SectionKey.Archive, "Icon.Archive") { public ShellViewModel Shell { get; } = shell; } /// Job queue and history (BRIEF §12.6). public sealed class JobsViewModel(ShellViewModel shell) : SectionViewModel(SectionKey.Jobs, "Icon.Jobs") { public ShellViewModel Shell { get; } = shell; } /// Server connection and sync (BRIEF §12.7). public sealed class ServerViewModel(ShellViewModel shell) : SectionViewModel(SectionKey.Server, "Icon.Server") { public ShellViewModel Shell { get; } = shell; } public sealed record LanguageOption(string Code, string Name); /// Settings (BRIEF §12.8): section list on the left, controls on the right, tooltips only. public sealed class SettingsViewModel : SectionViewModel { private readonly AppSettings _settings; private string _page = "General"; public SettingsViewModel(ShellViewModel shell, AppSettings settings) : base(SectionKey.Settings, "Icon.Settings") { Shell = shell; _settings = settings; Languages = Core.Localization.Languages.Shipped .Select(c => new LanguageOption(c, Core.Localization.Languages.NativeName(c))) .ToList(); SelectPageCommand = new RelayCommand(p => { if (p is string page) Page = page; }); } public ShellViewModel Shell { get; } public IReadOnlyList Pages { get; } = ["General", "Advanced"]; public ICommand SelectPageCommand { get; } public string Page { get => _page; set => Set(ref _page, value); } public IReadOnlyList Languages { get; } public LanguageOption SelectedLanguage { get => Languages.FirstOrDefault(l => l.Code.Equals(Loc.Culture.Name, StringComparison.OrdinalIgnoreCase)) ?? Languages[0]; set { if (value is null) return; _settings.Language = value.Code; App.Current.ApplyLanguage(value.Code); App.Current.SaveSettings(); } } public bool IsDarkTheme { get => _settings.Theme == AppTheme.Dark; set { if (value) ApplyTheme(AppTheme.Dark); } } public bool IsLightTheme { get => _settings.Theme == AppTheme.Light; set { if (value) ApplyTheme(AppTheme.Light); } } public bool IsSystemTheme { get => _settings.Theme == AppTheme.System; set { if (value) ApplyTheme(AppTheme.System); } } public bool CheckForUpdates { get => _settings.CheckForUpdates; set { _settings.CheckForUpdates = value; App.Current.SaveSettings(); OnPropertyChanged(); } } private void ApplyTheme(AppTheme theme) { _settings.Theme = theme; ThemeManager.Apply(theme); App.Current.SaveSettings(); OnPropertyChanged(nameof(IsDarkTheme)); OnPropertyChanged(nameof(IsLightTheme)); OnPropertyChanged(nameof(IsSystemTheme)); } } /// About (BRIEF §12.9). public sealed class AboutViewModel(ShellViewModel shell) : SectionViewModel(SectionKey.About, "Icon.About") { public ShellViewModel Shell { get; } = shell; public string Version => typeof(App).Assembly.GetCustomAttribute()?.InformationalVersion ?? "0.0.0"; public string Runtime => System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription; public string OperatingSystem => System.Runtime.InteropServices.RuntimeInformation.OSDescription; public string DataFolder => App.Current.Environment.DataDirectory; public ICommand OpenDataFolderCommand => new RelayCommand(() => ShellActions.OpenFolder(DataFolder)); public ICommand OpenReleasesCommand => new RelayCommand(() => ShellActions.OpenUrl(ProductLinks.Releases)); }