<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:vm="using:SourceGit.ViewModels"
             xmlns:v="using:SourceGit.Views"
             xmlns:c="using:SourceGit.Converters"
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
             x:Class="SourceGit.Views.CommitChanges"
             x:DataType="vm:CommitDetail">
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="{Binding Source={x:Static vm:Preference.Instance}, Path=Layout.CommitDetailChangesLeftWidth, Mode=TwoWay}" MinWidth="200" MaxWidth="480"/>
      <ColumnDefinition Width="4"/>
      <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <Grid Grid.Column="0" RowDefinitions="26,*">
      <!-- Search & Display Mode -->
      <Grid Grid.Row="0" ColumnDefinitions="*,18">
        <TextBox Grid.Column="0"
                 Height="26"
                 BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}" 
                 Background="Transparent"
                 CornerRadius="4"
                 Watermark="{DynamicResource Text.CommitDetail.Changes.Search}"
                 Text="{Binding SearchChangeFilter, Mode=TwoWay}">
          <TextBox.InnerLeftContent>
            <Path Width="14" Height="14" Margin="4,0,0,0" Fill="{DynamicResource Brush.FG2}" Data="{StaticResource Icons.Search}"/>
          </TextBox.InnerLeftContent>

          <TextBox.InnerRightContent>
            <Button Classes="icon_button"
                    IsVisible="{Binding SearchChangeFilter, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
                    Command="{Binding ClearSearchChangeFilter}">
              <Path Width="14" Height="14" Fill="{DynamicResource Brush.FG2}" Data="{StaticResource Icons.Clear}"/>
            </Button>
          </TextBox.InnerRightContent>
        </TextBox>

        <v:ChangeViewModeSwitcher Grid.Column="1"
                                  Width="14" Height="14"
                                  HorizontalAlignment="Right"
                                  ViewMode="{Binding Source={x:Static vm:Preference.Instance}, Path=CommitChangeViewMode, Mode=TwoWay}"/>
      </Grid>

      <!-- Changes -->
      <Border Grid.Row="1" Margin="0,4,0,0" BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="1" Background="{DynamicResource Brush.Contents}">
        <v:ChangeCollectionView IsWorkingCopyChange="False"
                                ViewMode="{Binding Source={x:Static vm:Preference.Instance}, Path=CommitChangeViewMode}"
                                Changes="{Binding VisibleChanges}"
                                SelectedChanges="{Binding SelectedChanges, Mode=TwoWay}"
                                ContextRequested="OnChangeContextRequested"/>
      </Border>
    </Grid>

    <GridSplitter Grid.Column="1"
                  MinWidth="1"
                  HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                  Background="Transparent"/>

    <Grid Grid.Column="2">
      <Border BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}">
        <StackPanel Orientation="Vertical" VerticalAlignment="Center">
          <Path Width="64" Height="64" Data="{StaticResource Icons.Diff}" Fill="{DynamicResource Brush.FG2}"/>
          <TextBlock Margin="0,16,0,0"
                     Text="{DynamicResource Text.Diff.Welcome}"
                     FontSize="18" FontWeight="Bold"
                     Foreground="{DynamicResource Brush.FG2}"
                     HorizontalAlignment="Center"/>
        </StackPanel>
      </Border>

      <ContentControl Content="{Binding DiffContext}">
        <ContentControl.DataTemplates>
          <DataTemplate DataType="vm:DiffContext">
            <v:DiffView/>
          </DataTemplate>
        </ContentControl.DataTemplates>
      </ContentControl>
    </Grid>
  </Grid>
</UserControl>
