<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.MergeModalView"
        x:DataType="vm:MergeModalViewModel"
        Title="Merge worktree"
        Width="560" Height="420"
        CanResize="False"
        WindowStartupLocation="CenterOwner">
  <Grid Margin="20" RowDefinitions="Auto,Auto,Auto,Auto,Auto,*,Auto">

    <TextBlock Grid.Row="0"
               Text="{Binding TaskTitle, StringFormat='Merging: {0}'}"
               FontWeight="SemiBold" Margin="0,0,0,12" />

    <StackPanel Grid.Row="1" Orientation="Vertical" Margin="0,0,0,8">
      <TextBlock Text="Target branch" Margin="0,0,0,4" />
      <ComboBox ItemsSource="{Binding Branches}"
                SelectedItem="{Binding SelectedBranch}"
                HorizontalAlignment="Stretch"
                IsEnabled="{Binding !IsBusy}" />
    </StackPanel>

    <CheckBox Grid.Row="2"
              Content="Remove worktree after merge"
              IsChecked="{Binding RemoveWorktree}"
              IsEnabled="{Binding !IsBusy}"
              Margin="0,0,0,8" />

    <StackPanel Grid.Row="3" Orientation="Vertical" Margin="0,0,0,8">
      <TextBlock Text="Commit message" Margin="0,0,0,4" />
      <TextBox Text="{Binding CommitMessage}"
               AcceptsReturn="True"
               TextWrapping="Wrap"
               Height="70"
               IsEnabled="{Binding !IsBusy}" />
    </StackPanel>

    <TextBlock Grid.Row="4"
               Text="{Binding ErrorMessage}"
               Foreground="IndianRed"
               TextWrapping="Wrap"
               IsVisible="{Binding ErrorMessage, Converter={x:Static ObjectConverters.IsNotNull}}"
               Margin="0,0,0,8" />

    <Border Grid.Row="5"
            BorderBrush="IndianRed"
            BorderThickness="1"
            Padding="8"
            IsVisible="{Binding HasConflict}">
      <StackPanel>
        <TextBlock Text="Conflicted files:" FontWeight="SemiBold" Margin="0,0,0,4" />
        <ItemsControl ItemsSource="{Binding ConflictFiles}">
          <ItemsControl.ItemTemplate>
            <DataTemplate>
              <TextBlock Text="{Binding}" />
            </DataTemplate>
          </ItemsControl.ItemTemplate>
        </ItemsControl>
      </StackPanel>
    </Border>

    <StackPanel Grid.Row="6" Orientation="Horizontal"
                HorizontalAlignment="Right" Margin="0,12,0,0">
      <TextBlock Text="{Binding SuccessMessage}"
                 Foreground="SeaGreen"
                 VerticalAlignment="Center"
                 Margin="0,0,12,0"
                 IsVisible="{Binding SuccessMessage, Converter={x:Static ObjectConverters.IsNotNull}}" />
      <Button Content="Cancel"
              Command="{Binding CancelCommand}"
              Margin="0,0,8,0" />
      <Button Content="Merge"
              Command="{Binding SubmitCommand}"
              IsDefault="True"
              Classes="accent" />
    </StackPanel>

  </Grid>
</Window>
