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

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

    The profile card is read-only, unlike the design's own — there is no "Edit profile" row here because
    there is no endpoint to send an edit to. Name, email and avatar all come from MeResponse and nothing in
    this client can change any of the three.

    The SIGN-IN card keeps one row rather than the design's two. The issuer sentence is real:
    MainWindowViewModel.Issuer is MeResponse.Issuer, cached the same turn AccountName and Email are and
    surfaced here for the first time — see the remark on that property. "Master passphrase" and its "Change
    passphrase" button are refused outright: there is no change-passphrase flow, only the one enrollment-time
    choice, and a button that opened nothing would be worse than no button.

    DEVICES and "Sign out everywhere" are both refused. There is no list-devices endpoint and no
    sign-out-everywhere endpoint; the one honest device fact this client has — this machine's own Windows
    Hello registration — is drawn on the Security page, not duplicated here as a one-row list.

    SignOutCard is the same control the old PreferencesScreen used, restyled into this page's card idiom
    rather than rewritten — see that control's own remark on why it is a bare StackPanel and not a card of
    its own, and why one control serves both this screen and the unlock screen's copy of it.
  -->

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

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

      <Border Classes="settingscard" Margin="0,26,0,0" Padding="24,22">
        <StackPanel Orientation="Horizontal" Spacing="18">
          <Border Width="64" Height="64" CornerRadius="60" Background="{StaticResource AvatarGradient}">
            <TextBlock Text="{Binding AvatarInitials}" FontWeight="Bold" FontSize="20" LetterSpacing="0.5"
                       Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" />
          </Border>
          <StackPanel Spacing="7" VerticalAlignment="Center">
            <TextBlock Text="{Binding AccountName}" FontSize="20" FontWeight="Bold" LetterSpacing="-0.25"
                       Foreground="{StaticResource Text}" />
            <TextBlock Classes="mono" FontSize="12.5" Foreground="{StaticResource TextFaint}"
                       Text="{Binding Email}"
                       IsVisible="{Binding Email, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" />
          </StackPanel>
        </StackPanel>
      </Border>

      <TextBlock Classes="settingssection" Text="SIGN-IN" />

      <Border Classes="settingscard">
        <StackPanel>
          <Border Classes="settingsrow last">
            <StackPanel Spacing="6" MaxWidth="640">
              <TextBlock Classes="settingsrowtitle" Text="Single sign-on" />
              <TextBlock Classes="settingsrowcaption"
                         Text="Signing in proves who you are — it never decrypts a vault." />
              <TextBlock Classes="mono" FontSize="12" Margin="0,4,0,0" Foreground="{StaticResource Live}"
                         Text="{Binding Issuer, StringFormat='You sign in through {0}.'}"
                         IsVisible="{Binding Issuer, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" />
            </StackPanel>
          </Border>
        </StackPanel>
      </Border>

      <TextBlock Classes="settingssection" Text="THIS MACHINE" />

      <Border Classes="settingscard" Margin="0,12,0,40">
        <Panel>
          <Border Classes="settingsrow last" IsVisible="{Binding !IsConfirmingSignOut}">
            <Grid ColumnDefinitions="*,Auto">
              <StackPanel Grid.Column="0" Spacing="6" Margin="0,0,16,0">
                <TextBlock Classes="settingsrowtitle" Text="Sign out of this machine" />
                <TextBlock Classes="settingsrowcaption"
                           Text="Deletes this machine's copy of the keychain and withdraws its device key, so it goes back to knowing nothing. The keychain stays on the server; signing in again brings it back. Use this to hand a machine on, or to enrol a different account." />
              </StackPanel>
              <Button Grid.Column="1" Classes="danger" Height="38" Content="SIGN OUT"
                      Command="{Binding SignOutCommand}"
                      IsEnabled="{Binding !IsBusy}" />
            </Grid>
          </Border>

          <Border Padding="24,20" IsVisible="{Binding IsConfirmingSignOut}">
            <views:SignOutCard />
          </Border>
        </Panel>
      </Border>

    </StackPanel>
  </ScrollViewer>

</UserControl>
