<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:vm="using:ClawdDotNet.Desktop.ViewModels"
             xmlns:ctrl="using:ClawdDotNet.Desktop.Controls"
             mc:Ignorable="d" d:DesignWidth="1100" d:DesignHeight="740"
             x:Class="ClawdDotNet.Desktop.Views.SettingsPageView"
             x:DataType="vm:SettingsPageViewModel">

  <DockPanel>

    <!-- Aktionen unten: Der Entwurf setzt flache Felder ohne Karten, damit bleibt am
         unteren Rand nur die Zeile mit Verwerfen und Speichern. -->
    <Border DockPanel.Dock="Bottom" BorderBrush="{DynamicResource DividerBrush}"
            BorderThickness="0,1,0,0" Padding="0,12,0,0" Margin="0,16,0,0">
      <StackPanel Orientation="Horizontal" Spacing="8" HorizontalAlignment="Right">
        <Button Content="Verwerfen" Command="{Binding LoadFromHostCommand}" />
        <Button Classes="primary" Command="{Binding SaveSettingsCommand}">
          <StackPanel Orientation="Horizontal" Spacing="6">
            <ctrl:StrokeIcon Data="{StaticResource IconSave}" Width="14" Height="14" />
            <TextBlock Text="Speichern" />
          </StackPanel>
        </Button>
      </StackPanel>
    </Border>

    <ScrollViewer VerticalScrollBarVisibility="Auto">
      <StackPanel Spacing="26" MaxWidth="680" HorizontalAlignment="Left">

        <!-- ══════════════════ Instanz ══════════════════ -->
        <StackPanel Spacing="14">
          <TextBlock Classes="kicker" Text="INSTANZ" />

          <StackPanel>
            <TextBlock Classes="label" Text="Instanz-Name" />
            <TextBox Text="{Binding InstanceName}" />
          </StackPanel>

          <StackPanel>
            <TextBlock Classes="label" Text="OpenRouter API-Key" />
            <TextBox Text="{Binding OpenRouterApiKey}" PasswordChar="•" />
          </StackPanel>

          <Grid ColumnDefinitions="*,16,*">
            <StackPanel Grid.Column="0">
              <TextBlock Classes="label" Text="Tagesbudget ($ USD)" />
              <TextBox Text="{Binding InstanceDailyCostUsd}" />
            </StackPanel>
            <StackPanel Grid.Column="2">
              <TextBlock Classes="label" Text="Tagesbudget (Tokens)" />
              <TextBox Text="{Binding InstanceDailyTokens}" />
            </StackPanel>
          </Grid>
        </StackPanel>

        <Border Classes="hr" />

        <!-- ══════════════════ Allgemein ══════════════════ -->
        <StackPanel Spacing="14">
          <TextBlock Classes="kicker" Text="ALLGEMEIN" />

          <StackPanel>
            <TextBlock Classes="label" Text="Log-Verzeichnis" />
            <TextBox Text="{Binding LogDirectory}" />
          </StackPanel>

          <StackPanel>
            <TextBlock Classes="label" Text="Instanzen-Verzeichnis" />
            <TextBox Text="{Binding InstancesDirectory}" />
          </StackPanel>

          <Grid ColumnDefinitions="*,16,*">
            <StackPanel Grid.Column="0">
              <TextBlock Classes="label" Text="Minimaler Log-Level" />
              <ComboBox ItemsSource="{Binding LogLevels}" SelectedItem="{Binding MinimumLogLevel}"
                        HorizontalAlignment="Stretch" />
            </StackPanel>
            <StackPanel Grid.Column="2">
              <TextBlock Classes="label" Text="OpenRouter Base-URL" />
              <TextBox Text="{Binding OpenRouterBaseUrl}" />
            </StackPanel>
          </Grid>
        </StackPanel>

        <Border Classes="hr" />

        <!-- ══════════════════ Deploymentcenter ══════════════════ -->
        <StackPanel Spacing="14">
          <TextBlock Classes="kicker" Text="DEPLOYMENTCENTER &amp; LIZENZ" />

          <StackPanel>
            <TextBlock Classes="label" Text="Server-URL" />
            <TextBox Text="{Binding DeploymentcenterUrl}" />
          </StackPanel>

          <StackPanel>
            <TextBlock Classes="label" Text="Master-Token" />
            <TextBox Text="{Binding DeploymentcenterToken}" PasswordChar="•" />
          </StackPanel>

          <Grid ColumnDefinitions="*,16,*">
            <StackPanel Grid.Column="0">
              <TextBlock Classes="label" Text="Update-Kanal" />
              <ComboBox ItemsSource="{Binding UpdateChannels}" SelectedItem="{Binding UpdateChannel}"
                        HorizontalAlignment="Stretch" />
            </StackPanel>
            <StackPanel Grid.Column="2">
              <TextBlock Classes="label" Text="Umgebung" />
              <ComboBox ItemsSource="{Binding Environments}"
                        SelectedItem="{Binding DeploymentcenterEnvironment}"
                        HorizontalAlignment="Stretch" />
            </StackPanel>
          </Grid>

          <StackPanel>
            <TextBlock Classes="label" Text="Lizenzschlüssel" />
            <TextBox Text="{Binding LicenseKey}" PasswordChar="•" />
          </StackPanel>

          <StackPanel Spacing="10" Margin="0,4,0,0">
            <CheckBox Content="Fehler automatisch an Deploymentcenter melden"
                      IsChecked="{Binding ErrorReportingEnabled}" />
            <CheckBox Content="Beim Start automatisch auf Updates prüfen"
                      IsChecked="{Binding UpdateCheckEnabled}" />
          </StackPanel>
        </StackPanel>

      </StackPanel>
    </ScrollViewer>

  </DockPanel>

</UserControl>
