<v:ChromelessWindow 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:vm="using:SourceGit.ViewModels"
                    xmlns:v="using:SourceGit.Views"
                    mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
                    x:Class="SourceGit.Views.SelfUpdate"
                    x:DataType="vm:SelfUpdate"
                    x:Name="ThisControl"
                    Title="{DynamicResource Text.SelfUpdate.Title}"
                    Icon="/App.ico"
                    SizeToContent="WidthAndHeight"
                    CanResize="False"
                    WindowStartupLocation="CenterOwner">
  <Grid RowDefinitions="Auto,*">
    <!-- TitleBar -->
    <Grid Grid.Row="0" Height="28" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
      <Border Background="{DynamicResource Brush.TitleBar}"
              BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
              PointerPressed="BeginMoveWindow"/>

      <Path Width="14" Height="14"
            Margin="10,0,0,0"
            HorizontalAlignment="Left"
            Data="{StaticResource Icons.SoftwareUpdate}"
            IsVisible="{OnPlatform True, macOS=False}"/>

      <TextBlock Classes="bold"
                 Text="{DynamicResource Text.SelfUpdate.Title}"
                 HorizontalAlignment="Center" VerticalAlignment="Center"
                 IsHitTestVisible="False"/>

      <v:CaptionButtons HorizontalAlignment="Right"
                        IsCloseButtonOnly="True"
                        IsVisible="{OnPlatform True, macOS=False}"/>
    </Grid>

    <!-- Body -->
    <Grid Grid.Row="1">
      <ContentControl Content="{Binding Data}">
        <ContentControl.DataTemplates>
          <DataTemplate DataType="m:Version">
            <StackPanel Orientation="Vertical" Margin="16,8">
              <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,8">
                <Path Width="14" Height="14" Data="{StaticResource Icons.Info}" Fill="Green"/>
                <TextBlock Margin="8,0,0,0" FontWeight="Bold" FontSize="14" Text="{DynamicResource Text.SelfUpdate.Available}"/>
                <Border Margin="4,0,0,0" Height="20" CornerRadius="10" Background="{DynamicResource Brush.Accent}" Effect="drop-shadow(0 0 6 #40000000)">
                  <TextBlock Margin="8,0" Text="{Binding TagName}" FontSize="12" Foreground="White"/>
                </Border>
              </StackPanel>

              <Border Width="500" MaxHeight="400"
                      Margin="0,8"
                      Background="{DynamicResource Brush.Contents}"
                      BorderThickness="1"
                      BorderBrush="{DynamicResource Brush.Border2}">
                <v:UpdateInfoView/>
              </Border>

              <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                <Button Classes="flat primary"
                        Height="30"
                        Click="GotoDownload"
                        HorizontalContentAlignment="Center"
                        VerticalContentAlignment="Center">
                  <StackPanel Orientation="Horizontal">
                    <Path Width="12" Height="12" Data="{StaticResource Icons.Pull}" Fill="{DynamicResource AccentButtonForeground}"/>
                    <TextBlock Text="{DynamicResource Text.SelfUpdate.GotoDownload}" Margin="8,0,0,0" Foreground="{DynamicResource AccentButtonForeground}"/>
                  </StackPanel>
                </Button>

                <Button Classes="flat"
                        Height="30"
                        Margin="8,0,0,0"
                        Click="IgnoreThisVersion"
                        HorizontalContentAlignment="Center"
                        VerticalContentAlignment="Center">
                  <StackPanel Orientation="Horizontal">
                    <Path Width="12" Height="12" Data="{StaticResource Icons.File.Ignore}"/>
                    <TextBlock Text="{DynamicResource Text.SelfUpdate.IgnoreThisVersion}" Margin="8,0,0,0"/>
                  </StackPanel>
                </Button>
              </StackPanel>
            </StackPanel>
          </DataTemplate>

          <DataTemplate DataType="m:AlreadyUpToDate">
            <StackPanel Orientation="Vertical" Margin="16,8">
              <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,8">
                <Path Width="14" Height="14" Data="{StaticResource Icons.Info}" Fill="Green"/>
                <TextBlock Margin="8,0,0,0" Text="{DynamicResource Text.SelfUpdate.UpToDate}"/>
              </StackPanel>

              <Button Classes="flat primary"
                      Height="30"
                      Margin="4,0"
                      Click="CloseWindow"
                      Content="{DynamicResource Text.Close}"
                      HorizontalAlignment="Center"
                      HorizontalContentAlignment="Center"
                      VerticalContentAlignment="Center"/>
            </StackPanel>
          </DataTemplate>

          <DataTemplate DataType="m:SelfUpdateFailed">
            <StackPanel Orientation="Vertical" Margin="16,8">
              <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                <Path Width="14" Height="14" Data="{StaticResource Icons.Error}" Fill="Red"/>
                <TextBlock Margin="8,0,0,0" FontWeight="Bold" FontSize="14" Text="{DynamicResource Text.SelfUpdate.Error}"/>
              </StackPanel>

              <TextBlock Text="{Binding Reason}" MaxWidth="500" TextWrapping="Wrap" Margin="0,8"/>

              <Button Classes="flat primary"
                      Height="30"
                      Margin="4,0"
                      Click="CloseWindow"
                      Content="{DynamicResource Text.Close}"
                      HorizontalAlignment="Center"
                      HorizontalContentAlignment="Center"
                      VerticalContentAlignment="Center"/>
            </StackPanel>
          </DataTemplate>
        </ContentControl.DataTemplates>
      </ContentControl>
    </Grid>
  </Grid>
</v:ChromelessWindow>
