<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:m="using:SourceGit.Models"
             xmlns:v="using:SourceGit.Views"
             xmlns:vm="using:SourceGit.ViewModels"
             xmlns:c="using:SourceGit.Converters"
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
             x:Class="SourceGit.Views.Conflict"
             x:DataType="vm:Conflict">
  <Border Background="{DynamicResource Brush.Window}" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}">
    <Grid VerticalAlignment="Center">
      <StackPanel Orientation="Vertical" IsVisible="{Binding !IsResolved}">
        <Path Width="64" Height="64" Data="{StaticResource Icons.Conflict}" Fill="{DynamicResource Brush.FG2}" HorizontalAlignment="Center"/>
        <TextBlock Margin="0,16" FontSize="20" FontWeight="Bold" Text="{DynamicResource Text.WorkingCopy.Conflicts}" Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Center"/>

        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,0,0,8">
          <Border Height="16" VerticalAlignment="Center" Background="Red" CornerRadius="8">
            <TextBlock Text="{Binding Marker}" Foreground="White" FontWeight="Bold" Margin="8,0" FontSize="10"/>
          </Border>

          <TextBlock Margin="8,0,0,0" VerticalAlignment="Center" Text="{Binding Description}"/>
        </StackPanel>

        <Border Margin="16,0" Padding="8" CornerRadius="4" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}">
          <Border.DataTemplates>
            <DataTemplate DataType="vm:ConflictSourceBranch">
              <StackPanel Orientation="Horizontal">
                <Path Width="12" Height="12" Data="{StaticResource Icons.Branch}"/>
                <TextBlock Margin="4,0,0,0" Text="{Binding Name}"/>
                <TextBlock Margin="4,0,0,0"
                           Text="{Binding Head, Converter={x:Static c:StringConverters.ToShortSHA}}"
                           Foreground="DarkOrange"
                           TextDecorations="Underline"
                           Cursor="Hand"
                           PointerPressed="OnPressedSHA"
                           ToolTip.Tip="{Binding Revision}"
                           ToolTip.ShowDelay="0">
                  <TextBlock.DataTemplates>
                    <DataTemplate DataType="m:Commit">
                      <StackPanel MinWidth="400" Orientation="Vertical">
                        <Grid ColumnDefinitions="Auto,*,Auto">
                          <v:Avatar Grid.Column="0" Width="16" Height="16" VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}"/>
                          <TextBlock Grid.Column="1" Text="{Binding Author.Name}" Margin="8,0,0,0"/>
                          <TextBlock Grid.Column="2" Text="{Binding CommitterTimeStr}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
                        </Grid>

                        <TextBlock Margin="0,8,0,0" Text="{Binding Subject}" TextWrapping="Wrap"/>
                      </StackPanel>
                    </DataTemplate>
                  </TextBlock.DataTemplates>
                </TextBlock>
              </StackPanel>
            </DataTemplate>

            <DataTemplate DataType="m:Commit">
              <StackPanel Orientation="Horizontal">
                <Path Width="12" Height="12" Data="{StaticResource Icons.Commit}"/>
                <v:CommitRefsPresenter Margin="8,0,0,0"
                                       Foreground="{DynamicResource Brush.FG1}"
                                       FontSize="12"
                                       VerticalAlignment="Center"
                                       UseGraphColor="False"/>
                <TextBlock Margin="4,0,0,0"
                           Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}"
                           Foreground="DarkOrange"
                           TextDecorations="Underline"
                           Cursor="Hand"
                           PointerPressed="OnPressedSHA"
                           ToolTip.Tip="{Binding}"
                           ToolTip.ShowDelay="0">
                  <TextBlock.DataTemplates>
                    <DataTemplate DataType="m:Commit">
                      <StackPanel MinWidth="400" Orientation="Vertical">
                        <Grid ColumnDefinitions="Auto,*,Auto">
                          <v:Avatar Grid.Column="0" Width="16" Height="16" VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}"/>
                          <TextBlock Grid.Column="1" Text="{Binding Author.Name}" Margin="8,0,0,0"/>
                          <TextBlock Grid.Column="2" Text="{Binding CommitterTimeStr}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
                        </Grid>

                        <TextBlock Margin="0,8,0,0" Text="{Binding Subject}" TextWrapping="Wrap"/>
                      </StackPanel>
                    </DataTemplate>
                  </TextBlock.DataTemplates>
                </TextBlock>
                <TextBlock Margin="4,0,0,0" Text="{Binding Subject}"/>
              </StackPanel>
            </DataTemplate>

            <DataTemplate DataType="x:String">
              <StackPanel Orientation="Horizontal">
                <Path Width="12" Height="12" Data="{StaticResource Icons.Changes}"/>
                <TextBlock Margin="4,0,0,0" Text="{Binding}"/>
              </StackPanel>
            </DataTemplate>
          </Border.DataTemplates>

          <Border.IsVisible>
            <MultiBinding Converter="{x:Static BoolConverters.And}">
              <Binding Path="Theirs" Converter="{x:Static ObjectConverters.IsNotNull}"/>
              <Binding Path="Mine" Converter="{x:Static ObjectConverters.IsNotNull}"/>
            </MultiBinding>
          </Border.IsVisible>

          <Grid Margin="8,0,0,0" RowDefinitions="32,32" ColumnDefinitions="Auto,*">
            <TextBlock Grid.Row="0" Grid.Column="0" Classes="info_label" Text="MINE"/>
            <ContentControl Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Content="{Binding Mine}"/>
            <TextBlock Grid.Row="1" Grid.Column="0" Classes="info_label" Text="THEIRS"/>
            <ContentControl Grid.Row="1" Grid.Column="1" Margin="16,0,0,0" Content="{Binding Theirs}"/>
          </Grid>
        </Border>

        <StackPanel Margin="0,8,0,0" Orientation="Horizontal" HorizontalAlignment="Center">
          <Button Classes="flat" Margin="0,0,0,0" Click="OnUseTheirs">
            <StackPanel Orientation="Horizontal">
              <Path Width="12" Height="12" Data="{StaticResource Icons.Incoming}"/>
              <TextBlock Margin="6,0,0,0" Text="{DynamicResource Text.WorkingCopy.Conflicts.UseTheirs}" VerticalAlignment="Center"/>
            </StackPanel>
          </Button>
          <Button Classes="flat" Margin="8,0,0,0" Click="OnUseMine">
            <StackPanel Orientation="Horizontal">
              <Path Width="12" Height="12" Data="{StaticResource Icons.Local}"/>
              <TextBlock Margin="6,0,0,0" Text="{DynamicResource Text.WorkingCopy.Conflicts.UseMine}" VerticalAlignment="Center"/>
            </StackPanel>
          </Button>
          <Button Classes="flat"
                  Margin="8,0,0,0"
                  Click="OnOpenExternalMergeTool"
                  IsVisible="{Binding CanUseExternalMergeTool}"
                  HotKey="{OnPlatform Ctrl+Shift+D, macOS=⌘+Shift+D}">
            <StackPanel Orientation="Horizontal">
              <Path Width="12" Height="12" Data="{StaticResource Icons.OpenWith}"/>
              <TextBlock Margin="6,0,0,0" Text="{DynamicResource Text.WorkingCopy.Conflicts.OpenExternalMergeTool}" VerticalAlignment="Center"/>
            </StackPanel>
          </Button>
        </StackPanel>
      </StackPanel>

      <StackPanel Orientation="Vertical" IsVisible="{Binding IsResolved}">
        <Path Width="64" Height="64" Data="{StaticResource Icons.Check}" Fill="Green"/>
        <TextBlock Margin="0,16,0,8" FontSize="20" FontWeight="Bold" Text="{DynamicResource Text.WorkingCopy.Conflicts.Resolved}" Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Center"/>
        <TextBlock Text="{DynamicResource Text.WorkingCopy.CanStageTip}" Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Center"/>
      </StackPanel>
    </Grid>
  </Border>
</UserControl>
