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

  <!--
    v5c: Security, against Settings-Security.dc.html.

    The end-to-end card's sentence is ADR 0001's own claim in the design's words: "The server stores
    ciphertext and never holds a key" and "the relay operator ... see ciphertext only" — see docs/adr/0001-e2ee-trust-model.md.

    UNLOCKING is Windows Hello's register/"Stop unlocking here" pair, moved here whole from the old
    PreferencesScreen.axaml — same RegisterDeviceCommand, ForgetDeviceCommand and the no-TPM explanation
    (HasNoDeviceKeyOption). One home for this fact rather than two; see the cross-reference on the
    Preferences page. The design's own auto-lock link row is refused: there is nothing to link to, since
    auto-lock and per-vault unlock rules do not exist anywhere in this client.

    CONNECTING keeps exactly one row, Approved host keys. Strict host-key checking and the allowed-algorithm
    chips are both refused — the app always asks on a changed key, and there is no algorithm allow-list
    anywhere in the SSH stack. The count and the "N that no host dials" clause both come straight off
    KnownHostsViewModel.Summary, the same sentence the known-hosts screen's own header prints, so this row
    can never say a different number than the screen it sends you to. "Open host keys" leaves settings mode
    on purpose — known-hosts is a MAIN-chrome screen, and there is no honest way to show it without leaving;
    ShowScreenCommand already does that for any target that is not Preferences or Vaults.

    RECENT SECURITY EVENTS is the link row alone, not the design's own list of rows. A real list would mean
    building a filtered read over LogsViewModel's activity and connection logs — which entries count as
    "security" is itself a judgement call the design does not resolve — and the honest link is complete on
    its own: Logs already holds the whole story, and this row says so rather than half-repeating it.
  -->

  <ScrollViewer>
    <StackPanel MaxWidth="1100" Margin="40" HorizontalAlignment="Stretch">

      <TextBlock Classes="settingstitle" Text="Security" />

      <Border Classes="settingscard" Margin="0,26,0,0" Padding="20,20">
        <StackPanel Orientation="Horizontal" Spacing="16">
          <Border Width="44" Height="44" CornerRadius="12" Background="#103A2F">
            <TextBlock FontFamily="{StaticResource IconFont}" Text="&#xE897;" FontSize="20"
                       Foreground="{StaticResource Live}"
                       HorizontalAlignment="Center" VerticalAlignment="Center" />
          </Border>
          <StackPanel Spacing="6" VerticalAlignment="Center">
            <TextBlock Text="End-to-end encrypted" FontSize="15" FontWeight="Bold" LetterSpacing="-0.2"
                       Foreground="{StaticResource Text}" />
            <TextBlock Classes="settingsrowcaption"
                       Text="Every vault item is sealed on your devices. The server and the relay both store ciphertext and timestamps only — neither can read a single field." />
          </StackPanel>
        </StackPanel>
      </Border>

      <TextBlock Classes="settingssection" Text="UNLOCKING" />

      <Border Classes="settingscard">
        <StackPanel>
          <Border Classes="settingsrow last">
            <Grid ColumnDefinitions="*,Auto">
              <StackPanel Grid.Column="0" Spacing="6" Margin="0,0,16,0" MaxWidth="640">
                <TextBlock Classes="settingsrowtitle" Text="Windows Hello on this machine" />
                <TextBlock Classes="settingsrowcaption"
                           Text="Registers this machine so a later launch can open the keychain with a Windows confirmation instead of your passphrase. Your passphrase keeps working."
                           IsVisible="{Binding CanRegisterDevice}" />
                <TextBlock Classes="settingsrowcaption"
                           Text="Registered · the TPM holds a device key that can open the keychain with a Windows confirmation."
                           IsVisible="{Binding CanForgetDevice}" />
                <TextBlock Classes="settingsrowcaption"
                           Text="This machine has nowhere to keep a device key, so the keychain will keep asking for your passphrase. That needs a TPM and a Windows keystore willing to release the key."
                           IsVisible="{Binding HasNoDeviceKeyOption}" />
              </StackPanel>
              <Button Grid.Column="1" Classes="accent" Height="38" Content="REGISTER"
                      Command="{Binding RegisterDeviceCommand}"
                      IsEnabled="{Binding !IsBusy}"
                      IsVisible="{Binding CanRegisterDevice}" />
              <Button Grid.Column="1" Classes="danger" Height="38" Content="STOP UNLOCKING HERE"
                      Command="{Binding ForgetDeviceCommand}"
                      IsEnabled="{Binding !IsBusy}"
                      IsVisible="{Binding CanForgetDevice}"
                      ToolTip.Tip="Withdraws this machine's device key, here and from your account, so it goes back to asking for your passphrase. Do this to a machine you have lost." />
            </Grid>
          </Border>
        </StackPanel>
      </Border>

      <TextBlock Classes="settingssection" Text="CONNECTING" />

      <Border Classes="settingscard">
        <StackPanel>
          <Border Classes="settingsrow last">
            <Grid ColumnDefinitions="*,Auto">
              <StackPanel Grid.Column="0" Spacing="6" Margin="0,0,16,0" MaxWidth="640">
                <TextBlock Classes="settingsrowtitle" Text="Approved host keys" />
                <TextBlock Classes="settingsrowcaption" Text="{Binding KnownHostsScreen.Summary}" />
              </StackPanel>
              <Button Grid.Column="1" Classes="ghost" Height="38" Content="OPEN HOST KEYS"
                      Command="{Binding ShowScreenCommand}"
                      CommandParameter="{x:Static vm:ShellScreen.KnownHosts}" />
            </Grid>
          </Border>
        </StackPanel>
      </Border>

      <TextBlock Classes="settingssection" Text="RECENT SECURITY EVENTS" />

      <Border Classes="settingscard" Margin="0,12,0,40">
        <StackPanel>
          <Border Classes="settingsrow last">
            <Button Classes="flat" Padding="0" HorizontalAlignment="Left"
                    Command="{Binding ShowScreenCommand}"
                    CommandParameter="{x:Static vm:ShellScreen.Logs}">
              <StackPanel Orientation="Horizontal" Spacing="8">
                <TextBlock Text="See all activity in Logs" FontSize="12" FontWeight="SemiBold"
                           Foreground="{StaticResource AccentText}" />
                <TextBlock FontFamily="{StaticResource IconFont}" Text="&#xE5C8;" FontSize="14"
                           Foreground="{StaticResource AccentText}" />
              </StackPanel>
            </Button>
          </Border>
        </StackPanel>
      </Border>

    </StackPanel>
  </ScrollViewer>

</UserControl>
