<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:vm="using:DodoSSH.Client.Shell.ViewModels"
             x:Class="DodoSSH.Client.Android.Views.HostKeySheet"
             x:DataType="vm:VaultViewModel">

  <!--
    Designs 05 and 06 in one control, because they are one decision point with two answers and the shell
    should not be able to show both. Which one draws is HasPendingHostKey against HasHostKeyMismatch, and
    the view models make those mutually exclusive.

    ◆ Both are load-bearing, and the difference between them is the most important thing on either screen:

    05 offers TRUST AND CONNECT, because first contact is a decision a person is entitled to make.
    06 offers no way forward at all. There is no continue button, no "connect anyway", and no gesture that
    dismisses it into a connection — the only exits are BACK and the host's own editor. That is deliberate
    and the plan names presenting it as dismissible as the one design mistake that matters here. A phone
    makes this easy to get wrong, because a bottom sheet is swipe-to-dismiss by convention; this is not a
    sheet for that reason, it is a full-screen panel.

    ◆ WHAT IS BEHIND IT IS NO LONGER ALWAYS THE HOST LIST. The shell used to move to HOSTS before letting a
    handshake ask this, because the desktop head drew the question as a banner on that screen; both heads draw
    it over the surface now, so this is raised over whatever the user was on — including the connect box on the
    Connections surface, which is where a machine that is in no keychain at all is dialled from. Nothing here
    changes for that, and that is the point: this control never knew which screen it was over. See
    MainWindowViewModel.OnVaultConnectionFailed and HostKeyCard.axaml on the desktop.
  -->

  <Panel>

    <!-- ============ 05 UNKNOWN HOST KEY ============ -->
    <Panel IsVisible="{Binding HasPendingHostKey}">

      <!--
        Scrim. Non-interactive by itself: tapping outside must not answer the question. 62% of Canvas,
        written out because the palette holds no alpha variant of a surface — see QuickConnect on the
        desktop, which carries the same note.
      -->
      <Border Background="#9E05050A" />

      <Border VerticalAlignment="Bottom" Background="{StaticResource Panel}"
              BorderBrush="{StaticResource BorderMid}" BorderThickness="0,1,0,0"
              CornerRadius="22,22,0,0" Padding="20,18,20,16">
        <ScrollViewer MaxHeight="620">
          <StackPanel Spacing="0">

            <Border Width="38" Height="4" CornerRadius="2" Background="{StaticResource BorderMid}"
                    HorizontalAlignment="Center" Margin="0,0,0,16" />

            <TextBlock Classes="title" Text="UNKNOWN HOST KEY" FontSize="13" />

            <TextBlock Classes="body" Margin="0,6,0,0">
              <Run Text="First contact with" />
              <Run Text="{Binding PendingHostKey.Host}" Foreground="{StaticResource Text}" />
              <Run Text="·" />
              <Run Text="{Binding PendingHostKey.Port}" />
              <Run Text=". Nothing in this keychain has approved this key." />
            </TextBlock>

            <TextBlock Classes="label" Margin="0,14,0,5" Foreground="{StaticResource TextFaint}"
                       Text="{Binding PendingHostKey.Algorithm}" />

            <!-- ◆ In full, and wrapping rather than clipping. See the .fingerprint style. -->
            <Border Background="{StaticResource Field}" BorderBrush="{StaticResource BorderMid}"
                    BorderThickness="1" CornerRadius="6" Padding="12,11">
              <SelectableTextBlock Classes="fingerprint" Text="{Binding PendingHostKey.Fingerprint}" />
            </Border>

            <TextBlock Classes="detail" Margin="0,8,0,0" TextWrapping="Wrap"
                       Text="Compare with the fingerprint the operator published before trusting." />

            <Button Classes="primary" Content="TRUST AND CONNECT" Margin="0,16,0,0"
                    Command="{Binding TrustHostKeyCommand}" />

            <Button Classes="secondary" Content="CANCEL" Margin="0,8,0,0"
                    Command="{Binding RejectHostKeyCommand}" />

          </StackPanel>
        </ScrollViewer>
      </Border>
    </Panel>

    <!-- ============ 06 CHANGED HOST KEY ============ -->
    <!--
      Opaque and full-screen, not a sheet over the previous screen. There is nothing behind this worth
      seeing and nothing behind it worth tapping.
    -->
    <Border IsVisible="{Binding HasHostKeyMismatch}" Background="{StaticResource Canvas}">
      <ScrollViewer>
        <StackPanel Margin="22,40,22,24" Spacing="0">

          <Border Width="44" Height="44" BorderBrush="{StaticResource Danger}" BorderThickness="1.5"
                  CornerRadius="6" HorizontalAlignment="Left">
            <TextBlock Text="!" Foreground="{StaticResource Danger}" FontFamily="{StaticResource MonoFont}"
                       FontSize="20" FontWeight="SemiBold"
                       HorizontalAlignment="Center" VerticalAlignment="Center" />
          </Border>

          <TextBlock Classes="title" Text="HOST KEY CHANGED" FontSize="17"
                     Foreground="{StaticResource Danger}" Margin="0,16,0,0" />

          <!--
            The whole explanation comes from the view model, which already composes it for the desktop
            head — including which host, which dates, and both fingerprints. Rewriting it here would be a
            second copy of the most safety-critical sentence in the product.
          -->
          <SelectableTextBlock Classes="fingerprint" Margin="0,12,0,0" FontSize="11"
                               Foreground="{StaticResource Text}"
                               Text="{Binding HostKeyMismatch}" />

          <TextBlock Classes="body" Margin="0,16,0,0" Foreground="{StaticResource TextFaint}"
                     Text="If this server was rebuilt on purpose, open the host's editor and use FORGET HOST KEY, then connect again. There is no way to continue from this screen — that is deliberate." />

          <!--
            The only control on the screen, and it goes back rather than forward. Compare the sheet above,
            where the accent button connects.

            ◆ IT SAID "BACK TO HOSTS", AND IT NEITHER WENT THERE NOR CAME BACK. Two things were wrong with
            it at once. RejectHostKey cleared only the pending key, so pressing it left HasHostKeyMismatch
            set and this opaque panel up over whatever the user navigated to next — including the host editor
            the paragraph above sends them to. And the shell no longer moves to Hosts to ask the question, so
            even fixed it does not land there: it lowers this panel and reveals the screen that was already
            underneath. "BACK" is what that is. See VaultViewModel.RejectHostKey.
          -->
          <Button Classes="secondary" Content="BACK" Margin="0,24,0,0"
                  Command="{Binding RejectHostKeyCommand}" />

        </StackPanel>
      </ScrollViewer>
    </Border>

  </Panel>

</UserControl>
