using AudibleUtilities; using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Threading.Tasks; namespace LibationWinForms.AvaloniaUI.Views.Dialogs { public partial class AccountsDialog : DialogWindow { public ObservableCollection Accounts { get; } = new(); public class AccountDto { public IList Locales { get; init; } public bool LibraryScan { get; set; } = true; public string AccountId { get; set; } public AudibleApi.Locale SelectedLocale { get; set; } public string AccountName { get; set; } public bool IsDefault => AccountId is null && SelectedLocale is null && AccountName is null; } private static string GetAudibleCliAppDataPath() => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Audible"); private List Locales => AudibleApi.Localization.Locales.OrderBy(l => l.Name).ToList(); public AccountsDialog() { InitializeComponent(); // WARNING: accounts persister will write ANY EDIT to object immediately to file // here: copy strings and dispose of persister // only persist in 'save' step using var persister = AudibleApiStorage.GetAccountsSettingsPersister(); var accounts = persister.AccountsSettings.Accounts; if (!accounts.Any()) return; ControlToFocusOnShow = this.FindControl