<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.MergeModalView"
        x:DataType="vm:MergeModalViewModel"
        Title="{loc:Tr modals.merge.windowTitle}"
        Width="560" Height="460" MinWidth="460" MinHeight="360"
        CanResize="True"
        WindowDecorations="BorderOnly"
        ExtendClientAreaToDecorationsHint="True"
        ExtendClientAreaTitleBarHeightHint="-1"
        WindowStartupLocation="CenterOwner"
        Background="{DynamicResource SurfaceBrush}">

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

  <ctl:ModalShell Title="{loc:Tr modals.merge.title}" CloseCommand="{Binding CancelCommand}">
    <ctl:ModalShell.Footer>
      <StackPanel Orientation="Horizontal" Spacing="8"
                  HorizontalAlignment="Right" VerticalAlignment="Center">
        <Button Classes="btn" Content="{loc:Tr modals.merge.cancel}" Command="{Binding CancelCommand}" MinWidth="90"/>
        <Button Content="{loc:Tr modals.merge.merge}" Classes="primary"
                Command="{Binding SubmitCommand}"
                IsDefault="True" MinWidth="90"/>
      </StackPanel>
    </ctl:ModalShell.Footer>

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

        <TextBlock Classes="title" Text="{Binding TaskTitle, StringFormat='Merging: {0}'}" />

        <StackPanel Spacing="4">
          <TextBlock Classes="field-label" Text="{loc:Tr modals.merge.targetBranch}"/>
          <ComboBox ItemsSource="{Binding Branches}"
                    SelectedItem="{Binding SelectedBranch}"
                    HorizontalAlignment="Stretch"
                    IsEnabled="{Binding !IsBusy}" />
        </StackPanel>

        <CheckBox Content="{loc:Tr modals.merge.removeWorktree}"
                  IsChecked="{Binding RemoveWorktree}"
                  IsEnabled="{Binding !IsBusy}" />

        <StackPanel Spacing="4">
          <TextBlock Classes="field-label" Text="{loc:Tr modals.merge.commitMessage}"/>
          <TextBox Text="{Binding CommitMessage}"
                   AcceptsReturn="True"
                   TextWrapping="Wrap"
                   Height="70"
                   IsEnabled="{Binding !IsBusy}" />
        </StackPanel>

        <TextBlock Text="{Binding ErrorMessage}"
                   Foreground="{DynamicResource BloodBrush}"
                   TextWrapping="Wrap"
                   IsVisible="{Binding ErrorMessage, Converter={x:Static ObjectConverters.IsNotNull}}" />

        <Border Classes="danger-box"
                IsVisible="{Binding HasConflict}">
          <StackPanel Spacing="4">
            <TextBlock Classes="title" Text="{loc:Tr modals.merge.conflictedFiles}" />
            <ItemsControl ItemsSource="{Binding ConflictFiles}">
              <ItemsControl.ItemTemplate>
                <DataTemplate>
                  <TextBlock Classes="meta" Text="{Binding}" />
                </DataTemplate>
              </ItemsControl.ItemTemplate>
            </ItemsControl>
          </StackPanel>
        </Border>

        <TextBlock Text="{Binding SuccessMessage}"
                   Foreground="{DynamicResource MossBrightBrush}"
                   IsVisible="{Binding SuccessMessage, Converter={x:Static ObjectConverters.IsNotNull}}" />
      </StackPanel>
    </ScrollViewer>

  </ctl:ModalShell>
</Window>
