<adonisControls:AdonisWindow x:Class="FModel.Views.UpdateView"
                             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                             xmlns:local="clr-namespace:FModel"
                             xmlns:converters="clr-namespace:FModel.Views.Resources.Converters"
                             xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
                             xmlns:adonisExtensions="clr-namespace:AdonisUI.Extensions;assembly=AdonisUI"
                             xmlns:adonisControls="clr-namespace:AdonisUI.Controls;assembly=AdonisUI"
                             xmlns:controls="clr-namespace:FModel.Views.Resources.Controls"
                             WindowStartupLocation="CenterScreen" IconVisibility="Collapsed" ResizeMode="CanMinimize" Loaded="OnLoaded"
                             MinHeight="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenHeight}, Converter={converters:RatioConverter}, ConverterParameter='0.40'}"
                             Width="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenWidth}, Converter={converters:RatioConverter}, ConverterParameter='0.35'}">
    <adonisControls:AdonisWindow.Style>
        <Style TargetType="adonisControls:AdonisWindow" BasedOn="{StaticResource {x:Type adonisControls:AdonisWindow}}" >
            <Setter Property="Title" Value="Releases" />
        </Style>
    </adonisControls:AdonisWindow.Style>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <TextBlock Grid.Row="0" TextWrapping="Wrap" HorizontalAlignment="Center" TextAlignment="Center" Margin="10">
            All releases listed below are available for download. They are sorted by date, with the latest release at the top.
            We regularly remove old ones to keep the list clean and up to date with the latest UE releases.
            If you wish to manually check for updates, this window is accessible via the Help > Releases menu.
        </TextBlock>

        <Grid Grid.Row="1" HorizontalAlignment="Center">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="5" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <!-- <Grid.Style> -->
            <!--     <Style TargetType="Grid"> -->
            <!--         <Setter Property="Visibility" Value="Visible" /> -->
            <!--         <Style.Triggers> -->
            <!--             <DataTrigger Binding="{Binding Title, RelativeSource={RelativeSource AncestorType=adonisControls:AdonisWindow}}" Value="Releases"> -->
            <!--                 <Setter Property="Visibility" Value="Collapsed" /> -->
            <!--             </DataTrigger> -->
            <!--         </Style.Triggers> -->
            <!--     </Style> -->
            <!-- </Grid.Style> -->

            <Button Grid.Column="0" Style="{DynamicResource {x:Static adonisUi:Styles.AccentButton}}"
                    VerticalAlignment="Top" Height="{Binding ActualHeight, ElementName=RemindButton}"
                    Click="OnDownloadLatest">
                Download Latest Release
            </Button>
            <StackPanel Grid.Column="2">
                <adonisControls:SplitButton x:Name="RemindButton" Content="Remind Me Now ..." Command="{Binding RemindMeCommand}">
                    <adonisControls:SplitButton.SplitMenu>
                        <ContextMenu>
                            <MenuItem Header="In 3 Days" Command="{Binding RemindMeCommand}" CommandParameter="Days" />
                            <MenuItem Header="Next Week" Command="{Binding RemindMeCommand}" CommandParameter="Week" />
                            <MenuItem Header="Next Month" Command="{Binding RemindMeCommand}" CommandParameter="Month" />
                            <MenuItem Header="Never" Command="{Binding RemindMeCommand}" CommandParameter="Never" />
                        </ContextMenu>
                    </adonisControls:SplitButton.SplitMenu>
                </adonisControls:SplitButton>
                <TextBlock VerticalAlignment="Bottom" HorizontalAlignment="Right" FontSize="10" Margin="0 2.5 0 0"
                           Text="{Binding NextUpdateCheck, Source={x:Static local:Settings.UserSettings.Default}, Converter={x:Static converters:TextToRefreshConverter.Instance}}" />
            </StackPanel>
        </Grid>

        <Separator Grid.Row="2" Style="{StaticResource CustomSeparator}" Tag="History" />
        <ScrollViewer Grid.Row="3" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
            <ItemsControl ItemsSource="{Binding CommitsView, IsAsync=True}">
                <ItemsControl.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.ContainerStyle>
                            <Style TargetType="GroupItem">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="GroupItem">
                                            <GroupBox adonisExtensions:LayerExtension.Layer="3"
                                                      Header="{Binding Name}"
                                                      HeaderStringFormat="Commits on {0:MMM d, yyyy}"
                                                      Margin="0 0 0 5">
                                                <ItemsPresenter />
                                            </GroupBox>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </GroupStyle.ContainerStyle>
                        <GroupStyle.Panel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Vertical" />
                            </ItemsPanelTemplate>
                        </GroupStyle.Panel>
                    </GroupStyle>
                </ItemsControl.GroupStyle>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <controls:CommitControl Margin="0 0 0 1" />
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
                <ItemsControl.Style>
                    <Style TargetType="ItemsControl" BasedOn="{StaticResource {x:Type ItemsControl}}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Items.Count, RelativeSource={RelativeSource Self}, FallbackValue=0}" Value="0">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate>
                                            <Grid>
                                                <TextBlock Text="No commits found" FontWeight="SemiBold" TextAlignment="Center"
                                                           Foreground="{DynamicResource {x:Static adonisUi:Brushes.ErrorBrush}}" />
                                            </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ItemsControl.Style>
            </ItemsControl>
        </ScrollViewer>
    </Grid>
</adonisControls:AdonisWindow>

