<Window 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"
        mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
        Width="520" Height="460"
        Padding="16"
        WindowStartupLocation="CenterOwner"
        CanResize="False"
        Title="Job hinzufügen / bearbeiten"
        x:Class="ClawdDotNet.Desktop.Views.AddJobWindow"
        x:DataType="vm:AddJobViewModel">

  <DockPanel>

    <!-- Bottom Buttons -->
    <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right" Spacing="8" Margin="0,16,0,0">
      <Button Content="Abbrechen" Command="{Binding CancelCommand}" />
      <Button Content="Speichern" Command="{Binding ConfirmCommand}" Classes="accent" />
    </StackPanel>

    <TextBlock DockPanel.Dock="Bottom" Text="{Binding StatusMessage}" Foreground="Red" Margin="0,8,0,0" />

    <ScrollViewer>
      <StackPanel Spacing="12">

        <!-- Agent Selection -->
        <StackPanel Spacing="4">
          <TextBlock Text="Agent:" FontWeight="Bold" />
          <ComboBox ItemsSource="{Binding AvailableAgents}" SelectedItem="{Binding SelectedAgent}" HorizontalAlignment="Stretch">
            <ComboBox.ItemTemplate>
              <DataTemplate>
                <TextBlock Text="{Binding DisplayName}" />
              </DataTemplate>
            </ComboBox.ItemTemplate>
          </ComboBox>
        </StackPanel>

        <!-- Job Type RadioButtons -->
        <StackPanel Spacing="4" Margin="0,4,0,0">
          <TextBlock Text="Job-Typ:" FontWeight="Bold" />
          <RadioButton Content="Agent Wakeup (Periodische Ausführung)" IsChecked="{Binding IsAgentWakeup}" />
          <RadioButton Content="Tool Job (Werkzeug-spezifischer Job)" IsChecked="{Binding IsToolJob}" />
        </StackPanel>

        <!-- Tool Job Details -->
        <StackPanel Spacing="8" IsVisible="{Binding IsToolJob}" Margin="12,4,0,0">
          <StackPanel Spacing="4">
            <TextBlock Text="Tool:" FontWeight="Bold" />
            <ComboBox ItemsSource="{Binding AvailableTools}" SelectedItem="{Binding SelectedToolName}" HorizontalAlignment="Stretch" />
          </StackPanel>

          <StackPanel Spacing="4">
            <TextBlock Text="Job-Typ-ID / Name:" FontWeight="Bold" />
            <TextBox Text="{Binding JobTypeId}" PlaceholderText="z.B. PollMail" />
          </StackPanel>
        </StackPanel>

        <!-- Agent Wakeup Details -->
        <StackPanel Spacing="4" IsVisible="{Binding IsAgentWakeup}">
          <TextBlock Text="Aufgabenbeschreibung / Nachricht:" FontWeight="Bold" />
          <TextBox Text="{Binding TaskMessage}" PlaceholderText="Nachricht an den Agenten..." AcceptsReturn="True" Height="60" />
        </StackPanel>

        <!-- Cron & Options -->
        <StackPanel Spacing="4">
          <TextBlock Text="Cron-Ausdruck:" FontWeight="Bold" />
          <TextBox Text="{Binding CronExpression}" PlaceholderText="0 * * * *" />
          <TextBlock Text="Syntax: Min Std Tag Mon Wochentag (z.B. '*/15 * * * *' alle 15 Minuten)" Classes="caption" />
        </StackPanel>

        <CheckBox Content="Beim Anwendungsstart einmalig sofort ausführen" IsChecked="{Binding RunOnStart}" Margin="0,4,0,0" />

      </StackPanel>
    </ScrollViewer>

  </DockPanel>

</Window>
