<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:c="using:SourceGit.Converters"
             xmlns:vm="using:SourceGit.ViewModels"
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
             x:Class="SourceGit.Views.RevisionFileContentViewer">
  <UserControl.DataTemplates>
    <DataTemplate DataType="m:RevisionBinaryFile">
      <StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
        <Path Width="64" Height="64" Data="{StaticResource Icons.Error}" Fill="{DynamicResource Brush.FG2}"/>
        <TextBlock Margin="0,16,0,0" Text="{DynamicResource Text.BinaryNotSupported}" FontSize="18" FontWeight="Bold" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.FG2}"/>
        <StackPanel Margin="0,8,0,0" Orientation="Horizontal" HorizontalAlignment="Center">
          <TextBlock Text="{Binding Size, Converter={x:Static c:LongConverters.ToFileSize}}" Foreground="{DynamicResource Brush.FG2}"/>
        </StackPanel>
      </StackPanel>
    </DataTemplate>

    <DataTemplate DataType="m:RevisionTextFile">
      <v:RevisionTextFileView FontFamily="{DynamicResource Fonts.Monospace}"
                              FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
                              TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
                              UseSyntaxHighlighting="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseSyntaxHighlighting}"
                              Background="{DynamicResource Brush.Contents}"/>
    </DataTemplate>

    <DataTemplate DataType="m:RevisionImageFile">
      <Grid RowDefinitions="*,Auto" Margin="0,8" VerticalAlignment="Center" HorizontalAlignment="Center">
        <Border Grid.Row="0" HorizontalAlignment="Center" Effect="drop-shadow(0 0 8 #A0000000)">
          <Border Background="{DynamicResource Brush.Window}">
            <Border BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" Margin="8">
              <v:ImageView Image="{Binding Image}"/>
            </Border>
          </Border>
        </Border>

        <StackPanel Grid.Row="1" Margin="0,8,0,0" Orientation="Horizontal" HorizontalAlignment="Center">
          <Border Height="16" Background="Green" CornerRadius="8" VerticalAlignment="Center">
            <TextBlock Text="{Binding ImageType}" Margin="8,0" FontSize="10" Foreground="White"/>
          </Border>

          <TextBlock Text="{Binding ImageSize}" Margin="8,0,0,0"/>
          <TextBlock Text="{Binding FileSize, Converter={x:Static c:LongConverters.ToFileSize}}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
        </StackPanel>
      </Grid>
    </DataTemplate>

    <DataTemplate DataType="m:RevisionLFSObject">
      <StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
        <TextBlock Text="{DynamicResource Text.CommitDetail.Files.LFS}" FontSize="18" FontWeight="Bold" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.FG2}"/>
        <Path Width="64" Height="64" Margin="0,24,0,0" Data="{StaticResource Icons.LFS}" Fill="{DynamicResource Brush.FG2}"/>
        <SelectableTextBlock Margin="0,16,0,0" Text="{Binding Object.Oid}" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.FG2}"/>
        <StackPanel Margin="0,8,0,0" Orientation="Horizontal" HorizontalAlignment="Center">
          <TextBlock Text="{Binding Object.Size, Converter={x:Static c:LongConverters.ToFileSize}}" Foreground="{DynamicResource Brush.FG2}"/>
        </StackPanel>
      </StackPanel>
    </DataTemplate>

    <DataTemplate DataType="m:RevisionSubmodule">
      <Grid RowDefinitions="Auto,*" Margin="8,0">
        <TextBlock Grid.Row="0" Margin="0,8,0,0" Text="{DynamicResource Text.CommitDetail.Files.Submodule}" FontSize="18" FontWeight="Bold" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.FG2}"/>
        <ScrollViewer Grid.Row="1" Margin="0,16,0,0" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
          <v:CommitBaseInfo Content="{Binding Commit}" FullMessage="{Binding FullMessage}"/>
        </ScrollViewer>
      </Grid>
    </DataTemplate>

    <DataTemplate DataType="vm:RevisionLFSImage">
      <TabControl Margin="0,8,0,0" SelectedIndex="{Binding Source={x:Static vm:Preferences.Instance}, Path=LFSImageActiveIdx, Mode=TwoWay}">
        <TabControl.Styles>
          <Style Selector="TabControl /template/ ItemsPresenter#PART_ItemsPresenter > WrapPanel">
            <Setter Property="HorizontalAlignment" Value="Center"/>
          </Style>
        </TabControl.Styles>

        <TabItem>
          <TabItem.Header>
            <TextBlock Text="LFS" FontWeight="Bold"/>
          </TabItem.Header>

          <ContentControl Content="{Binding LFS}"/>
        </TabItem>

        <TabItem>
          <TabItem.Header>
            <TextBlock Text="IMAGE" FontWeight="Bold"/>
          </TabItem.Header>

          <ContentControl Content="{Binding Image}"/>
        </TabItem>
      </TabControl>
    </DataTemplate>
  </UserControl.DataTemplates>
</UserControl>
