<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"
                    xmlns:sys="clr-namespace:System;assembly=mscorlib"
                    mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
                    x:Class="SourceGit.Views.SelfUpdate"
                    x:DataType="vm:SelfUpdate"
                    Title="{DynamicResource Text.SelfUpdate.Title}"
                    Icon="/App.ico"
                    SizeToContent="WidthAndHeight"
                    CanResize="False"
                    WindowStartupLocation="CenterOwner">
  <Grid RowDefinitions="Auto,*">
    <!-- TitleBar -->
    <Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Height="30">
      <Border Grid.Column="0" Grid.ColumnSpan="3"
              Background="{DynamicResource Brush.TitleBar}"
              BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
              PointerPressed="BeginMoveWindow"/>

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

      <Grid Grid.Column="0" Classes="caption_button_box" Margin="2,4,0,0" IsVisible="{OnPlatform False, macOS=True}">
        <Button Classes="caption_button_macos" Click="CloseWindow">
          <Grid>
            <Ellipse Fill="{DynamicResource Brush.MacOS.Close}"/>
            <Path Height="6" Width="6" Stretch="Fill" Fill="#505050" Data="{StaticResource Icons.MacOS.Close}"/>
          </Grid>
        </Button>
      </Grid>

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

      <Button Grid.Column="2"
              Classes="caption_button"
              Click="CloseWindow"
              IsVisible="{OnPlatform True, macOS=False}">
        <Path Data="{StaticResource Icons.Window.Close}"/>
      </Button>
    </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 Classes="monospace" Margin="8,0" Text="{Binding TagName}" FontSize="12" Foreground="White"/>
                </Border>
              </StackPanel>

              <TextBox IsReadOnly="True"
                       TextWrapping="Wrap"
                       ScrollViewer.VerticalScrollBarVisibility="Auto"
                       MaxWidth="500" MaxHeight="400"
                       Margin="0,8" Padding="0"
                       VerticalContentAlignment="Top"
                       Text="{Binding Body}"/>

              <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}"/>
                    <TextBlock Text="{DynamicResource Text.SelfUpdate.GotoDownload}" Margin="8,0,0,0"/>
                  </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="sys:Exception">
            <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 Message}" 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>

          <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>
        </ContentControl.DataTemplates>
      </ContentControl>
    </Grid>
  </Grid>
</v:ChromelessWindow>
