<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="using:ClaudeDo.Ui.ViewModels.Planning"
        x:Class="ClaudeDo.Ui.Views.Planning.PlanningDiffView"
        x:DataType="vm:PlanningDiffViewModel"
        Title="Planning — Combined diff"
        Width="1100" Height="700"
        WindowDecorations="None"
        ExtendClientAreaToDecorationsHint="True"
        WindowStartupLocation="CenterOwner"
        Background="{StaticResource SurfaceBrush}">

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

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

      <!-- 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="Planning — Combined diff"
                     VerticalAlignment="Center"
                     FontFamily="{StaticResource MonoFamily}"
                     FontSize="12"
                     Foreground="{StaticResource TextDimBrush}"/>
          <Button Grid.Column="1"
                  Classes="icon-btn"
                  Content="✕"
                  FontSize="12"
                  Command="{Binding CloseCommand}"
                  VerticalAlignment="Center"/>
        </Grid>
      </Border>

      <!-- Toolbar row -->
      <StackPanel Grid.Row="1"
                  Orientation="Horizontal"
                  Spacing="8"
                  Margin="8,6">
        <ToggleButton Content="Preview combined" IsChecked="{Binding IsCombinedMode}"/>
        <TextBlock Text="{Binding CombinedWarning}"
                   Foreground="Orange"
                   VerticalAlignment="Center"
                   IsVisible="{Binding CombinedWarning, Converter={x:Static ObjectConverters.IsNotNull}}"/>
        <TextBlock Text="Loading…"
                   VerticalAlignment="Center"
                   IsVisible="{Binding IsLoadingCombined}"/>
      </StackPanel>

      <!-- Two-pane body -->
      <Grid Grid.Row="2" ColumnDefinitions="240,*">

        <!-- Subtask list (left pane) -->
        <Border Grid.Column="0"
                BorderBrush="{StaticResource LineBrush}"
                BorderThickness="0,0,1,0"
                Background="{StaticResource DeepBrush}">
          <ListBox ItemsSource="{Binding Subtasks}"
                   SelectedItem="{Binding SelectedSubtask}"
                   IsEnabled="{Binding !IsCombinedMode}"
                   Background="Transparent"
                   BorderThickness="0"
                   ScrollViewer.HorizontalScrollBarVisibility="Disabled">
            <ListBox.ItemTemplate>
              <DataTemplate x:DataType="vm:SubtaskDiffRow">
                <Border Padding="10,8" Background="Transparent">
                  <StackPanel Spacing="2">
                    <TextBlock Text="{Binding Title}"
                               FontWeight="SemiBold"
                               TextTrimming="CharacterEllipsis"/>
                    <TextBlock Text="{Binding DiffStat}"
                               Opacity="0.7"
                               FontFamily="{StaticResource MonoFamily}"
                               FontSize="11"/>
                  </StackPanel>
                </Border>
              </DataTemplate>
            </ListBox.ItemTemplate>
          </ListBox>
        </Border>

        <!-- Diff content (right pane) -->
        <Grid Grid.Column="1" Background="{StaticResource VoidBrush}">
          <ScrollViewer HorizontalScrollBarVisibility="Auto"
                        VerticalScrollBarVisibility="Auto">
            <TextBox Text="{Binding DisplayedDiff, Mode=OneWay}"
                     IsReadOnly="True"
                     AcceptsReturn="True"
                     FontFamily="Consolas,Menlo,monospace"
                     FontSize="12"
                     Background="Transparent"
                     BorderThickness="0"
                     Padding="8"/>
          </ScrollViewer>
        </Grid>

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