<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.App.Views.ConnectingCard"
             x:DataType="vm:MainWindowViewModel"
             Background="{StaticResource Canvas}">

  <!--
    What the terminal's rectangle holds while the selected tab has no pane: a connection being made, or one
    that was refused.

    It exists because connecting stopped blocking the window. The tab appears the moment the user asks for
    it and the handshake runs behind it, so there is a stretch — seconds against a machine that is asleep,
    longer against one that is not there — in which a tab is selected and there is nothing to show in it.
    Showing the last terminal's pane would be a lie, and showing nothing reads as the application having
    broken, so this says which machine, as whom, and how far along it is.

    It obeys the occlusion rule the whole window obeys: this is Avalonia-drawn content in the WebView's own
    rectangle, so the shell collapses the terminal while it is up. IsTerminalShowing and IsConnectingShowing
    are exclusive by construction — a selected tab either has a session or it does not — which is what makes
    that safe rather than merely arranged. See MainWindow.axaml.

    In its own file rather than in the window, like every other card here, because nothing inside that window
    can be laid out by a test: WebView2's adapter refuses the headless session's thread.
  -->

  <Panel>
    <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Spacing="14" MaxWidth="460"
                Margin="24">

      <StackPanel Spacing="6" HorizontalAlignment="Center">
        <TextBlock Classes="mono" Text="{Binding SelectedTab.Label}" FontSize="16" FontWeight="Medium"
                   Foreground="{StaticResource Text}" HorizontalAlignment="Center"
                   TextTrimming="CharacterEllipsis" />
        <TextBlock Classes="mono" Text="{Binding SelectedTab.Address}" FontSize="11.5"
                   Foreground="{StaticResource TextFaint}" HorizontalAlignment="Center"
                   TextTrimming="CharacterEllipsis" />
      </StackPanel>

      <!--
        Two states, deliberately different. Waiting is an accent line under the host's name; a refusal is
        the reason, in the palette's red, because it is the only place the reason will be after the user
        navigates away from the screen that started the connection.
      -->
      <TextBlock Classes="mono" Text="{Binding SelectedTab.Status}" FontSize="12"
                 Foreground="{StaticResource Accent}" HorizontalAlignment="Center"
                 TextWrapping="Wrap" TextAlignment="Center"
                 IsVisible="{Binding SelectedTab.IsConnecting}" />

      <SelectableTextBlock Text="{Binding SelectedTab.Status}" FontSize="13"
                           Foreground="{StaticResource Danger}" HorizontalAlignment="Center"
                           TextWrapping="Wrap" TextAlignment="Center"
                           IsVisible="{Binding SelectedTab.IsFailed}" />

      <TextBlock Classes="hint" FontSize="11.5" TextAlignment="Center" HorizontalAlignment="Center"
                 Text="Nothing else is waiting for this. Every other screen still works, and the strip above says how this one is getting on."
                 IsVisible="{Binding SelectedTab.IsConnecting}" />

      <!--
        The same command the tab's own cross runs, named for what pressing it means in each of the two
        states. On a connecting tab it is how the attempt is given up on: the shell forgets it, and a
        handshake that finishes afterwards is adopted rather than dropped — see
        MainWindowViewModel.CloseTabAsync. Two buttons rather than one with a converted label, because the
        two are different decisions and only one of them abandons something still running.
      -->
      <Button Classes="ghost" HorizontalAlignment="Center" Content="GIVE UP"
              Command="{Binding CloseTabCommand}" CommandParameter="{Binding SelectedTab}"
              IsVisible="{Binding SelectedTab.IsConnecting}" />

      <Button Classes="ghost" HorizontalAlignment="Center" Content="CLOSE TAB"
              Command="{Binding CloseTabCommand}" CommandParameter="{Binding SelectedTab}"
              IsVisible="{Binding SelectedTab.IsFailed}" />

    </StackPanel>
  </Panel>

</UserControl>
