using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
using DodoSSH.Client.Shell.ViewModels;

namespace DodoSSH.Client.App.Views;

/// <summary>
/// Importing hosts from <c>~/.ssh/config</c>.
/// </summary>
/// <remarks>
/// A task rather than a destination, which is why it is reached from Preferences rather than from the nav
/// rail. v5c-3 moved it inside settings mode as an overlay over the Preferences page — it no longer has a
/// keyboard target of its own to hand back: <c>MainWindow.axaml.cs</c>'s <c>KeyboardHome</c> falls back to
/// the window for settings mode as a whole, the same way it already does for the account and logs screens,
/// so a <c>KeyboardTarget</c> property here would be dead code nothing reads.
/// </remarks>
internal sealed partial class ImportScreen : UserControl
{
    public ImportScreen()
    {
        InitializeComponent();

        // The count on the import button is derived from the ticks, and a CheckBox bound with
        // {Binding IsSelected} tells its own row and nothing else. Rather than have every row hold a
        // reference back to the screen, the screen listens for the event they all bubble.
        AddHandler(ToggleButton.IsCheckedChangedEvent, OnTickChanged, RoutingStrategies.Bubble);
    }

    private void OnTickChanged(object? sender, RoutedEventArgs e)
    {
        if (DataContext is ImportViewModel import)
        {
            import.NoteSelectionChanged();
        }
    }
}
