<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="using:ClaudeDo.Ui.ViewModels.Planning"
        x:DataType="vm:ConflictResolutionViewModel"
        x:Class="ClaudeDo.Ui.Views.Planning.ConflictResolutionView"
        Title="Merge conflict"
        Width="560" SizeToContent="Height"
        WindowDecorations="None"
        ExtendClientAreaToDecorationsHint="True"
        WindowStartupLocation="CenterOwner"
        Background="{StaticResource SurfaceBrush}">

  <Window.KeyBindings>
    <KeyBinding Gesture="Escape" Command="{Binding AbortCommand}"/>
  </Window.KeyBindings>

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

      <!-- Title bar / drag handle -->
      <Border Grid.Row="0"
              x:Name="TitleBar"
              Background="{StaticResource Surface2Brush}"
              BorderBrush="{StaticResource LineBrush}"
              BorderThickness="0,0,0,1"
              PointerPressed="TitleBar_PointerPressed">
        <Grid ColumnDefinitions="*,Auto" Margin="14,0">
          <TextBlock Text="Merge conflict"
                     VerticalAlignment="Center"
                     FontFamily="{StaticResource MonoFamily}"
                     FontSize="12"
                     Foreground="{StaticResource TextDimBrush}"/>
        </Grid>
      </Border>

      <!-- Content -->
      <StackPanel Grid.Row="1" Spacing="12" Margin="16" MinWidth="520">
        <TextBlock FontWeight="SemiBold" FontSize="16"
                   Text="{Binding SubtaskTitle, StringFormat='Conflicts in subtask: {0}'}"/>
        <TextBlock Text="{Binding TargetBranch, StringFormat='Merging into: {0}'}" Opacity="0.7"/>
        <ItemsControl ItemsSource="{Binding ConflictedFiles}">
          <ItemsControl.ItemTemplate>
            <DataTemplate>
              <TextBlock Text="{Binding}" FontFamily="Consolas,Menlo,monospace"/>
            </DataTemplate>
          </ItemsControl.ItemTemplate>
        </ItemsControl>
        <TextBlock Text="{Binding VsCodeError}" Foreground="OrangeRed"
                   IsVisible="{Binding VsCodeError, Converter={x:Static ObjectConverters.IsNotNull}}"
                   TextWrapping="Wrap"/>
        <TextBlock Text="{Binding ActionError}" Foreground="OrangeRed"
                   IsVisible="{Binding ActionError, Converter={x:Static ObjectConverters.IsNotNull}}"
                   TextWrapping="Wrap"/>
        <StackPanel Orientation="Horizontal" Spacing="8" HorizontalAlignment="Right" Margin="0,4,0,4">
          <Button Content="Open all in VS Code" Command="{Binding OpenInVsCodeCommand}"/>
          <Button Content="I've resolved — continue" Command="{Binding ContinueCommand}"/>
          <Button Content="Abort this merge" Command="{Binding AbortCommand}"/>
        </StackPanel>
      </StackPanel>

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