using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Deploymentcenter.Client;
using PolyTrader.App.Avalonia.Controls;
using PolyTrader.Core;
using PolyTrader.Core.Configuration;
using PolyTrader.Core.Modularity;
using PolyTrader.Core.Persistence;
using PolyTrader.Core.Security;
using PolyTraderSharp;
using PolyTraderSharp.Models;
using PolyTraderSharp.Services;
using PolyTrader.Web.Configuration;
namespace PolyTrader.App.Avalonia.Views
{
///
/// Einstellungen: allgemeine Server-Settings und die Polymarket-Accounts. Beide Bereiche nutzen
/// den anstelle der früheren PropertyGrids.
/// Layout vollständig in SettingsWindow.axaml.
///
public partial class SettingsWindow : UserControl
{
private const string SettingsPath = "server_settings.xml";
private readonly ObservableCollection _accounts = new();
private ServerSettings _settings = new();
private IAccountRepository? _accountRepo;
private TradingState? _state;
private WatchdogHeartbeatService? _watchdog;
private MullvadVpnService? _vpn;
private TerminalLogger? _logger;
private DeploymentcenterOptions? _dcOptions;
private WebUiOptions _webOptions = new();
public SettingsWindow() => AvaloniaXamlLoader.Load(this);
public SettingsWindow(IModuleUiHost host, IAccountRepository accountRepo, TradingState state,
TerminalLogger logger, WatchdogHeartbeatService? watchdog = null,
MullvadVpnService? vpn = null, DeploymentcenterOptions? dcOptions = null,
WebUiOptions? webOptions = null) : this()
{
_accountRepo = accountRepo;
_state = state;
_logger = logger;
_watchdog = watchdog;
_vpn = vpn;
_dcOptions = dcOptions;
_webOptions = webOptions ?? Program.LoadWebUiOptions();
var grid = this.FindControl("gridAccounts")!;
grid.ItemsSource = _accounts;
grid.SelectionChanged += (_, _) =>
this.FindControl("editorAccount")!.Show(grid.SelectedItem);
this.FindControl