using Avalonia.Controls;
using Avalonia.Input;
using DodoSSH.Client.Shell.ViewModels;

namespace DodoSSH.Client.App.Views;

/// <summary>Vaults, restyled into the settings page idiom — see the remark at the top of the markup.</summary>
internal sealed partial class SettingsVaultsPage : UserControl
{
    public SettingsVaultsPage() => InitializeComponent();

    private MainWindowViewModel? Shell => DataContext as MainWindowViewModel;

    /// <remarks>
    /// Only a press on the wash itself, the same test <c>QuickConnect.OnBackdropPressed</c> makes: a press
    /// inside the card bubbles through here too, with its source the control that was actually hit rather
    /// than the backdrop, so closing on those would make the panel impossible to click into.
    /// </remarks>
    private void OnBackdropPressed(object? sender, PointerPressedEventArgs e)
    {
        if (!ReferenceEquals(e.Source, MembersBackdrop) || Shell is not { } shell)
        {
            return;
        }

        shell.Vaults.CloseMembersPanelCommand.Execute(null);
        e.Handled = true;
    }
}
