<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="clr-namespace:ClaudeDo.Ui.ViewModels.Modals"
        xmlns:ctl="using:ClaudeDo.Ui.Views.Controls"
        xmlns:loc="using:ClaudeDo.Ui.Localization"
        x:Class="ClaudeDo.Ui.Views.Modals.ListSettingsModalView"
        x:DataType="vm:ListSettingsModalViewModel"
        Title="{loc:Tr modals.listSettings.title}"
        Width="520" Height="720"
        CanResize="True"
        MinWidth="460" MinHeight="520"
        WindowDecorations="BorderOnly"
        ExtendClientAreaToDecorationsHint="True"
        ExtendClientAreaTitleBarHeightHint="-1"
        WindowStartupLocation="CenterOwner"
        Background="{DynamicResource SurfaceBrush}">

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

  <ctl:ModalShell Title="{loc:Tr modals.listSettings.title}" CloseCommand="{Binding CancelCommand}">
    <ctl:ModalShell.Footer>
      <Grid ColumnDefinitions="Auto,*,Auto" VerticalAlignment="Center">
        <Button Grid.Column="0" Content="{loc:Tr modals.listSettings.deleteList}" Classes="danger"
                Command="{Binding DeleteCommand}" MinWidth="90"/>
        <StackPanel Grid.Column="2" Orientation="Horizontal" Spacing="8">
          <Button Classes="btn" Content="{loc:Tr settings.cancel}" Command="{Binding CancelCommand}" MinWidth="90"/>
          <Button Content="{loc:Tr settings.save}" Classes="primary" Command="{Binding SaveCommand}" MinWidth="90"/>
        </StackPanel>
      </Grid>
    </ctl:ModalShell.Footer>

    <!-- Body -->
    <ScrollViewer Padding="20,16">
      <StackPanel Spacing="12">

        <!-- GENERAL -->
        <StackPanel Spacing="0">
          <TextBlock Classes="section-label" Text="{loc:Tr modals.listSettings.sectionGeneral}"/>
          <Border Classes="section">
            <StackPanel Spacing="12">
              <StackPanel Spacing="4">
                <TextBlock Classes="field-label" Text="{loc:Tr modals.listSettings.name}"/>
                <TextBox Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
              </StackPanel>

              <StackPanel Spacing="4">
                <TextBlock Classes="field-label" Text="{loc:Tr modals.listSettings.workingDirectory}"/>
                <Grid ColumnDefinitions="*,Auto">
                  <TextBox Grid.Column="0" Text="{Binding WorkingDir}" PlaceholderText="{loc:Tr modals.listSettings.workingDirectoryPlaceholder}" />
                  <Button Classes="btn" Grid.Column="1" Content="{loc:Tr modals.listSettings.browse}" Margin="8,0,0,0" Click="BrowseClicked" />
                </Grid>
              </StackPanel>

              <StackPanel Spacing="4">
                <TextBlock Classes="field-label" Text="{loc:Tr modals.listSettings.defaultCommitType}"/>
                <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="{loc:Tr modals.listSettings.sectionAgent}" Margin="0"/>
            <Button Classes="btn" Grid.Column="1" Content="{loc:Tr modals.listSettings.resetAgentSettings}"
                    Command="{Binding Agent.ResetAllCommand}" />
          </Grid>
          <Border Classes="section">
            <ctl:AgentConfigEditor DataContext="{Binding Agent}" ShowAgentBrowse="True"/>
          </Border>
        </StackPanel>

      </StackPanel>
    </ScrollViewer>

  </ctl:ModalShell>
</Window>
