<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.QuickConnect"
             x:DataType="vm:MainWindowViewModel">

  <!--
    Ctrl+K: type a few characters of a host's name and press Enter to connect to it.

    The design's box promises "search hosts · run command". Only the first half is here, because there is no
    snippet or saved-command item type in the vault for the second half to run — see
    docs/design-import-gaps.md.

    It connects through the vault's own ConnectCommand rather than opening a session itself, so it inherits
    every refusal that path already makes: a key or credential that has been deleted on another machine, a
    host with no username, a host key that has changed. A second connect path would be a second place for
    those to be forgotten.

    While this is open the shell collapses the terminal's WebView, and that is not a visual nicety — the
    WebView is a native child window that composites above anything Avalonia draws in the same rectangle, so
    an overlay across the middle of this window would be painted underneath it and take no clicks.
  -->

  <!--
    The wash is named and takes a press, because clicking away from a palette is how every palette closes.
    The handler answers only for presses whose source is the wash itself, which is what separates "outside"
    from "inside": a press anywhere on the card below reports that control as its source and bubbles through
    here on its way to the window.
  -->
  <Border x:Name="Backdrop" Background="#CC0A0C0B" PointerPressed="OnBackdropPressed">
    <Border Width="520" VerticalAlignment="Top" Margin="0,90,0,0"
            Background="{StaticResource Chrome}" BorderBrush="{StaticResource BorderMid}"
            BorderThickness="1" CornerRadius="6">
      <StackPanel>

        <Border Padding="12,10" BorderBrush="{StaticResource BorderSubtle}" BorderThickness="0,0,0,1">
          <Grid ColumnDefinitions="Auto,*">
            <TextBlock Grid.Column="0" Classes="mono" Text="&gt;" FontSize="12"
                       Foreground="{StaticResource Accent}" VerticalAlignment="Center" />
            <TextBox Grid.Column="1" x:Name="Query" Text="{Binding SearchText}"
                     PlaceholderText="search hosts" Margin="8,0,0,0"
                     FontFamily="{StaticResource MonoFont}" FontSize="13"
                     Background="Transparent" BorderThickness="0" />
          </Grid>
        </Border>

        <!--
          Arrow keys move the selection and Enter takes it; the code-behind owns both, because a ListBox that
          took focus would take the arrow keys away from the box being typed into.

          A click connects rather than merely selecting, which is what a list of hosts under a search box
          looks like it does — the keyboard route already treats choosing a row and connecting to it as one
          act, and a pointer that only highlighted would leave the palette open over a choice already made.
          The gesture is wired in the code-behind, as the sidebar's double-click is.
        -->
        <ListBox x:Name="Results" MaxHeight="280" Focusable="False"
                 ItemsSource="{Binding SearchResults}"
                 SelectedItem="{Binding SelectedSearchResult}">
          <ListBox.ItemTemplate>
            <DataTemplate x:DataType="vm:HostRowViewModel">
              <Grid ColumnDefinitions="Auto,*,Auto" Margin="0,8,12,8">
                <Border Grid.Column="0" Classes="rowmark" />
                <StackPanel Grid.Column="1" Spacing="1" Margin="12,0,0,0">
                  <TextBlock Classes="mono" Text="{Binding Label}" FontSize="12" FontWeight="Medium"
                             Foreground="{StaticResource Text}" />
                  <TextBlock Classes="mono" Text="{Binding Address}" FontSize="9.5"
                             Foreground="{StaticResource TextFaint}" />
                </StackPanel>
                <TextBlock Grid.Column="2" Classes="mono" Text="{Binding Authentication}" FontSize="9"
                           Foreground="{StaticResource TextFaint}" VerticalAlignment="Center" />
              </Grid>
            </DataTemplate>
          </ListBox.ItemTemplate>
        </ListBox>

        <TextBlock Classes="hint" FontSize="11" Margin="14,16"
                   Text="No host matches that."
                   IsVisible="{Binding !HasSearchResults}" />

        <Border Padding="12,7" BorderBrush="{StaticResource BorderSubtle}" BorderThickness="0,1,0,0">
          <TextBlock Classes="mono" FontSize="9" Foreground="{StaticResource TextFaint}"
                     Text="↑ ↓ to choose · ENTER or click to connect · ESC to close" />
        </Border>

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

</UserControl>
