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

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

    The design's page has three cards — STARTUP, APPEARANCE, UPDATES — and this one has one. STARTUP
    (launch at login, reopen tabs) and APPEARANCE (theme, language) are refused outright: nothing tracks
    whether Windows starts this application, nothing remembers a tab list across a launch, only the one dark
    theme exists, and there is no i18n anywhere in the client. Building either card would be two rows of
    controls that toggle a field nothing reads. See design-notes/v5c-fidelity-notes.md.

    UPDATES is the whole page's real content, moved here from the old PreferencesScreen.axaml verbatim —
    same UpdateViewModel, same states, same warnings, restyled into this page's row idiom. Its own
    update-channel switcher is refused the same way STARTUP and APPEARANCE are: which channel a copy follows
    is fixed when it is built, so this screen cannot offer to switch it.
  -->

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

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

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

      <Border Classes="settingscard">
        <StackPanel>

          <Border Classes="settingsrow">
            <Grid ColumnDefinitions="*,Auto">
              <StackPanel Grid.Column="0" Spacing="6" Margin="0,0,16,0">
                <TextBlock Classes="settingsrowtitle" Text="Version" />
                <TextBlock Classes="mono" FontSize="12" Foreground="{StaticResource TextFaint}"
                           TextTrimming="CharacterEllipsis" Text="{Binding Updates.CurrentVersion}" />
              </StackPanel>
              <Button Grid.Column="1" Classes="ghost" Height="38" Content="CHECK NOW"
                      Command="{Binding Updates.CheckNowCommand}"
                      IsEnabled="{Binding Updates.CanCheckNow}" />
            </Grid>
          </Border>

          <Border Classes="settingsrow">
            <Grid ColumnDefinitions="*,Auto">
              <StackPanel Grid.Column="0" Spacing="6" Margin="0,0,16,0">
                <TextBlock Classes="settingsrowtitle" Text="Check on its own" />
                <TextBlock Classes="settingsrowcaption"
                           Text="Every six hours while DodoSSH is running, starting a couple of minutes after launch. It keeps checking while the keychain is locked, because where builds come from has nothing to do with your vault." />
              </StackPanel>
              <CheckBox Grid.Column="1" VerticalAlignment="Top"
                        IsChecked="{Binding Updates.IsAutomatic}"
                        IsEnabled="{Binding Updates.IsSupported}" />
            </Grid>
          </Border>

          <Border Classes="settingsrow" IsVisible="{Binding Updates.IsDownloading}">
            <StackPanel Spacing="8">
              <TextBlock Classes="settingsrowtitle" Text="Downloading…" />
              <ProgressBar Height="4" Minimum="0" Maximum="100"
                           Value="{Binding Updates.DownloadPercent}"
                           Foreground="{StaticResource Accent}" Background="{StaticResource Chip}" />
            </StackPanel>
          </Border>

          <Border Classes="settingsrow" IsVisible="{Binding Updates.IsReady}">
            <Grid ColumnDefinitions="*,Auto">
              <StackPanel Grid.Column="0" Spacing="6" Margin="0,0,16,0">
                <TextBlock Classes="settingsrowtitle" Text="{Binding Updates.ReadyHeadline}" TextWrapping="Wrap" />
                <TextBlock Classes="settingsrowcaption" Text="{Binding Updates.RestartWarning}" />
              </StackPanel>
              <Button Grid.Column="1" Classes="accent" Height="38" Content="RESTART NOW"
                      Command="{Binding Updates.RestartNowCommand}" />
            </Grid>
          </Border>

          <Border Classes="settingsrow last">
            <StackPanel Spacing="8">
              <TextBlock Classes="settingsrowcaption"
                         Text="Builds come from the project's own release page, and never from the server you sign in to. Whoever hands you the client can hand you a client that copies your passphrase, and the operator of a DodoSSH deployment is the party the trust model is about. A deployment may tell you where to get it. It is not where it comes from." />
              <TextBlock Classes="settingsrowcaption" Foreground="{StaticResource TextFaint}"
                         Text="{Binding Updates.Status}"
                         IsVisible="{Binding Updates.Status, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" />
              <TextBlock Classes="settingsrowcaption"
                         Text="This copy of DodoSSH cannot replace itself, so nothing above does anything. That is what a build run from a source checkout looks like, and also what a copy somebody unzipped by hand looks like — it is the installer that registers the update path."
                         IsVisible="{Binding Updates.IsUnsupported}" />
            </StackPanel>
          </Border>

        </StackPanel>
      </Border>

      <TextBlock Classes="settingssection" Text="NOT BUILT YET" />

      <Border Classes="settingscard">
        <StackPanel Margin="24,20" Spacing="10">
          <TextBlock Classes="settingsrowcaption"
                     Text="These are on the design and have nothing behind them here. They are listed rather than left out, so what this page does not do is as legible as what it does. The full list, and what each would take, is in docs/design-import-gaps.md." />
          <TextBlock Classes="settingsrowcaption"
                     Text="Update channel — there is a nightly as well as a release, but which one a copy follows is fixed when it is built, so moving between them means installing the other one." />
          <TextBlock Classes="settingsrowcaption"
                     Text="Launch at login — nothing registers this application with Windows' own startup list." />
          <TextBlock Classes="settingsrowcaption"
                     Text="Reopen tabs from last session — nothing remembers which tabs were open across a launch, and every connection would need to authenticate again regardless." />
          <TextBlock Classes="settingsrowcaption"
                     Text="Theme and language — only the one dark theme exists, and there is no translation anywhere in this client." />
        </StackPanel>
      </Border>

    </StackPanel>
  </ScrollViewer>

</UserControl>
