using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace DodoSSH.Client.Android.Views;

/// <summary>
/// A state this head has not built, saying so in its own words.
/// </summary>
/// <remarks>
/// <para>
/// Styled properties rather than a view model: there is no state behind this control, and giving it one
/// would make it look like a screen that might one day have data.
/// </para>
/// <para>
/// <b>It must not set its own DataContext, and the two properties are read with <c>$parent</c> for exactly
/// that reason.</b> This control once did <c>DataContext = this</c> so the properties could be bound as
/// <c>{Binding Heading}</c>, and it cost the phone its navigation. A binding written by the <em>parent</em>
/// on one of these — <c>IsVisible="{Binding IsPreferencesShowing}"</c> in PhoneShell — resolves against
/// this control's own data context, so with one set here the binding looked for a shell property on a
/// PendingScreen, found nothing, and left <c>IsVisible</c> at its default of true. The result was an opaque
/// PREFERENCES panel permanently on top of the host list, over a bottom bar whose buttons all worked
/// perfectly and changed nothing anybody could see.
/// </para>
/// <para>
/// The desktop head carries the other half of this lesson in <c>MainWindow.axaml</c>, where the terminal's
/// visibility is given a <c>FallbackValue</c> for the same reason: an unresolved <c>IsVisible</c> binding
/// does not hide anything, it shows everything.
/// </para>
/// </remarks>
internal sealed partial class PendingScreen : UserControl
{
    public static readonly StyledProperty<string> HeadingProperty =
        AvaloniaProperty.Register<PendingScreen, string>(nameof(Heading), string.Empty);

    public static readonly StyledProperty<string> DetailProperty =
        AvaloniaProperty.Register<PendingScreen, string>(nameof(Detail), string.Empty);

    public PendingScreen() => AvaloniaXamlLoader.Load(this);

    public string Heading
    {
        get => GetValue(HeadingProperty);
        set => SetValue(HeadingProperty, value);
    }

    public string Detail
    {
        get => GetValue(DetailProperty);
        set => SetValue(DetailProperty, value);
    }
}
