<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="clr-namespace:ClaudeDo.Ui.ViewModels.Modals"
        x:Class="ClaudeDo.Ui.Views.Modals.ListSettingsModalView"
        x:DataType="vm:ListSettingsModalViewModel"
        Title="List settings"
        Width="520" Height="720"
        CanResize="True"
        MinWidth="460" MinHeight="520"
        WindowDecorations="None"
        ExtendClientAreaToDecorationsHint="True"
        WindowStartupLocation="CenterOwner"
        Background="{DynamicResource SurfaceBrush}">

  <Window.KeyBindings>
    <KeyBinding Gesture="Escape" Command="{Binding CancelCommand}"/>
    <KeyBinding Gesture="Enter" Command="{Binding SaveCommand}"/>
  </Window.KeyBindings>

  <Window.Styles>
    <Style Selector="TextBlock.section-label">
      <Setter Property="FontFamily" Value="{DynamicResource MonoFont}"/>
      <Setter Property="FontSize" Value="10"/>
      <Setter Property="LetterSpacing" Value="1.4"/>
      <Setter Property="Foreground" Value="{DynamicResource TextFaintBrush}"/>
      <Setter Property="Margin" Value="4,0,0,6"/>
    </Style>
    <Style Selector="TextBlock.field-label">
      <Setter Property="FontSize" Value="11"/>
      <Setter Property="Foreground" Value="{DynamicResource TextDimBrush}"/>
      <Setter Property="Margin" Value="0,0,0,4"/>
    </Style>
    <Style Selector="Border.section">
      <Setter Property="BorderBrush" Value="{DynamicResource LineBrush}"/>
      <Setter Property="BorderThickness" Value="1"/>
      <Setter Property="CornerRadius" Value="6"/>
      <Setter Property="Padding" Value="14"/>
      <Setter Property="Background" Value="{DynamicResource DeepBrush}"/>
    </Style>
    <Style Selector="Button.primary">
      <Setter Property="Background" Value="{DynamicResource AccentBrush}"/>
      <Setter Property="Foreground" Value="{DynamicResource DeepBrush}"/>
      <Setter Property="FontWeight" Value="SemiBold"/>
    </Style>
  </Window.Styles>

  <Border Background="{DynamicResource SurfaceBrush}"
          BorderBrush="{DynamicResource LineBrush}"
          BorderThickness="1">
    <Grid RowDefinitions="36,*,52">

      <!-- Title bar -->
      <Border Grid.Row="0"
              x:Name="TitleBar"
              Background="{DynamicResource DeepBrush}"
              BorderBrush="{DynamicResource LineBrush}"
              BorderThickness="0,0,0,1"
              PointerPressed="TitleBar_PointerPressed">
        <Grid ColumnDefinitions="*,Auto" Margin="14,0">
          <TextBlock Text="LIST SETTINGS"
                     FontFamily="{DynamicResource MonoFont}"
                     FontSize="11"
                     LetterSpacing="1.4"
                     Foreground="{DynamicResource TextBrush}"
                     VerticalAlignment="Center"/>
          <Button Grid.Column="1"
                  Classes="icon-btn"
                  Content="✕"
                  FontSize="12"
                  Command="{Binding CancelCommand}"
                  VerticalAlignment="Center"/>
        </Grid>
      </Border>

      <!-- Body -->
      <ScrollViewer Grid.Row="1" Padding="20,16">
        <StackPanel Spacing="18">

          <!-- GENERAL -->
          <StackPanel Spacing="0">
            <TextBlock Classes="section-label" Text="GENERAL"/>
            <Border Classes="section">
              <StackPanel Spacing="12">
                <StackPanel Spacing="4">
                  <TextBlock Classes="field-label" Text="Name"/>
                  <TextBox Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                </StackPanel>

                <StackPanel Spacing="4">
                  <TextBlock Classes="field-label" Text="Working directory"/>
                  <Grid ColumnDefinitions="*,Auto">
                    <TextBox Grid.Column="0" Text="{Binding WorkingDir}" PlaceholderText="(none)" />
                    <Button Grid.Column="1" Content="Browse..." Margin="8,0,0,0" Click="BrowseClicked" />
                  </Grid>
                </StackPanel>

                <StackPanel Spacing="4">
                  <TextBlock Classes="field-label" Text="Default commit type"/>
                  <ComboBox ItemsSource="{Binding CommitTypeOptions}"
                            SelectedItem="{Binding DefaultCommitType, Mode=TwoWay}"
                            HorizontalAlignment="Left" MinWidth="160" />
                </StackPanel>
              </StackPanel>
            </Border>
          </StackPanel>

          <!-- AGENT -->
          <StackPanel Spacing="0">
            <Grid ColumnDefinitions="*,Auto" Margin="4,0,0,6">
              <TextBlock Classes="section-label" Text="AGENT" Margin="0"/>
              <Button Grid.Column="1" Content="Reset agent settings"
                      Command="{Binding ResetAgentSettingsCommand}" />
            </Grid>
            <Border Classes="section">
              <StackPanel Spacing="12">
                <StackPanel Spacing="4">
                  <TextBlock Classes="field-label" Text="Model"/>
                  <ComboBox ItemsSource="{Binding ModelOptions}"
                            SelectedItem="{Binding SelectedModel, Mode=TwoWay}"
                            HorizontalAlignment="Left" MinWidth="160" />
                </StackPanel>

                <StackPanel Spacing="4">
                  <TextBlock Classes="field-label" Text="System prompt (appended)"/>
                  <TextBox Text="{Binding SystemPrompt, Mode=TwoWay}"
                           AcceptsReturn="True" TextWrapping="Wrap"
                           MinHeight="80" />
                </StackPanel>

                <StackPanel Spacing="4">
                  <TextBlock Classes="field-label" Text="Agent file"/>
                  <Grid ColumnDefinitions="*,Auto">
                    <ComboBox Grid.Column="0"
                              ItemsSource="{Binding Agents}"
                              SelectedItem="{Binding SelectedAgent, Mode=TwoWay}"
                              HorizontalAlignment="Stretch">
                      <ComboBox.ItemTemplate>
                        <DataTemplate>
                          <StackPanel>
                            <TextBlock Text="{Binding Name}"
                                       Foreground="{DynamicResource TextBrush}"/>
                            <TextBlock Text="{Binding Description}"
                                       Foreground="{DynamicResource TextMuteBrush}"
                                       FontSize="11" />
                          </StackPanel>
                        </DataTemplate>
                      </ComboBox.ItemTemplate>
                    </ComboBox>
                    <Button Grid.Column="1" Content="Browse..."
                            Margin="8,0,0,0" Click="BrowseAgentClicked" />
                  </Grid>
                  <TextBlock Text="{Binding SelectedAgent.Path}"
                             FontFamily="{DynamicResource MonoFont}"
                             FontSize="11"
                             Foreground="{DynamicResource TextFaintBrush}"
                             TextTrimming="PrefixCharacterEllipsis"
                             IsVisible="{Binding SelectedAgent.Path, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"/>
                </StackPanel>
              </StackPanel>
            </Border>
          </StackPanel>

        </StackPanel>
      </ScrollViewer>

      <!-- Footer -->
      <Border Grid.Row="2"
              Background="{DynamicResource DeepBrush}"
              BorderBrush="{DynamicResource LineBrush}"
              BorderThickness="0,1,0,0">
        <StackPanel Orientation="Horizontal" Spacing="8"
                    HorizontalAlignment="Right" VerticalAlignment="Center"
                    Margin="16,0">
          <Button Content="Cancel" Command="{Binding CancelCommand}" MinWidth="90"/>
          <Button Content="Save" Classes="primary" Command="{Binding SaveCommand}" MinWidth="90"/>
        </StackPanel>
      </Border>

    </Grid>
  </Border>
</Window>
