using System; using System.Collections.Generic; using System.Windows.Input; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Metadata; using Avalonia.VisualTree; using FluentAvalonia.UI.Controls; using StabilityMatrix.Core.Processes; namespace StabilityMatrix.Avalonia.Controls; public class SettingsAccountLinkExpander : TemplatedControl { private readonly List _items = new(); [Content] public List Items => _items; // ReSharper disable MemberCanBePrivate.Global public static readonly StyledProperty HeaderProperty = HeaderedItemsControl.HeaderProperty.AddOwner(); public object? Header { get => GetValue(HeaderProperty); set => SetValue(HeaderProperty, value); } public static readonly StyledProperty HeaderTargetUriProperty = AvaloniaProperty.Register< SettingsAccountLinkExpander, Uri? >("HeaderTargetUri"); public Uri? HeaderTargetUri { get => GetValue(HeaderTargetUriProperty); set => SetValue(HeaderTargetUriProperty, value); } public static readonly StyledProperty IconSourceProperty = SettingsExpander.IconSourceProperty.AddOwner(); public IconSource? IconSource { get => GetValue(IconSourceProperty); set => SetValue(IconSourceProperty, value); } public static readonly StyledProperty IsConnectedProperty = AvaloniaProperty.Register< SettingsAccountLinkExpander, bool >("IsConnected"); public bool IsConnected { get => GetValue(IsConnectedProperty); set => SetValue(IsConnectedProperty, value); } public static readonly StyledProperty OnDescriptionProperty = AvaloniaProperty.Register( "OnDescription", Languages.Resources.Label_Connected ); public object? OnDescription { get => GetValue(OnDescriptionProperty); set => SetValue(OnDescriptionProperty, value); } public static readonly StyledProperty OnDescriptionExtraProperty = AvaloniaProperty.Register("OnDescriptionExtra"); public object? OnDescriptionExtra { get => GetValue(OnDescriptionExtraProperty); set => SetValue(OnDescriptionExtraProperty, value); } public static readonly StyledProperty OffDescriptionProperty = AvaloniaProperty.Register("OffDescription"); public object? OffDescription { get => GetValue(OffDescriptionProperty); set => SetValue(OffDescriptionProperty, value); } public static readonly StyledProperty ConnectCommandProperty = AvaloniaProperty.Register( nameof(ConnectCommand), enableDataValidation: true ); public ICommand? ConnectCommand { get => GetValue(ConnectCommandProperty); set => SetValue(ConnectCommandProperty, value); } public static readonly StyledProperty DisconnectCommandProperty = AvaloniaProperty.Register( nameof(DisconnectCommand), enableDataValidation: true ); public ICommand? DisconnectCommand { get => GetValue(DisconnectCommandProperty); set => SetValue(DisconnectCommandProperty, value); } /*public static readonly StyledProperty IsLoading2Property = AvaloniaProperty.Register( nameof(IsLoading2)); public bool IsLoading2 { get => GetValue(IsLoading2Property); set => SetValue(IsLoading2Property, value); }*/ private bool _isLoading; public static readonly DirectProperty IsLoadingProperty = AvaloniaProperty.RegisterDirect( "IsLoading", o => o.IsLoading, (o, v) => o.IsLoading = v ); public bool IsLoading { get => _isLoading; set => SetAndRaise(IsLoadingProperty, ref _isLoading, value); } // ReSharper restore MemberCanBePrivate.Global /// protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); // Bind tapped event on header if ( HeaderTargetUri is { } headerTargetUri && e.NameScope.Find("PART_HeaderTextBlock") is { } headerTextBlock ) { headerTextBlock.Tapped += (_, _) => { ProcessRunner.OpenUrl(headerTargetUri.ToString()); }; } if (e.NameScope.Find("PART_SettingsExpander") is { } expander) { expander.ItemsSource = Items; } if (ConnectCommand is { } command) { var connectButton = e.NameScope.Get