<UserControl x:Class="Vulnerator.View.UI.NewsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
             xmlns:Converters="clr-namespace:Vulnerator.View.Converter"
             xmlns:IconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
             xmlns:LiveCharts="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:dat="clr-namespace:System.Windows.Data;assembly=PresentationFramework"
             xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:local="clr-namespace:Vulnerator.View.UI"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
             xmlns:v="clr-namespace:Vulnerator.View"
             xmlns:vm="clr-namespace:Vulnerator.ViewModel"
             xmlns:wpf="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf"
             HorizontalAlignment="Stretch"
             VerticalAlignment="Stretch"
             d:DesignHeight="800"
             d:DesignWidth="800"
             DataContext="{Binding News, Source={StaticResource Locator}}"
             mc:Ignorable="d">

    <FrameworkElement.CommandBindings>
        <CommandBinding Command="{x:Static wpf:Commands.Hyperlink}"
                        Executed="OpenHyperlink" />
    </FrameworkElement.CommandBindings>

    <UserControl.Resources>
        <Converters:HtmlToFlowDocumentConverter x:Key="HtmlToFlowDocumentConverter" />
    </UserControl.Resources>

    <Grid Background="{DynamicResource WindowBackgroundBrush}">
        <Controls:MetroAnimatedSingleRowTabControl Controls:TabControlHelper.Underlined="SelectedTabItem">
            <TabItem Header="Issues"
                     Style="{StaticResource CustomMetroTabItem}">
                <Grid Margin="5,0,5,5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Expander Margin="0,5"
                              Background="{DynamicResource WindowBackgroundBrush}"
                              BorderThickness="0"
                              ExpandDirection="Right"
                              IsExpanded="False">
                        <Expander.Header>
                            <Label Foreground="{DynamicResource LabelTextBrush}">
                                <Label.LayoutTransform>
                                    <RotateTransform Angle="90" />
                                </Label.LayoutTransform>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <IconPacks:PackIconFontAwesomeLight Grid.Column="0"
                                                                        Margin="5"
                                                                        HorizontalAlignment="Center"
                                                                        VerticalAlignment="Center"
                                                                        Kind="ExclamationCircle">
                                        <IconPacks:PackIconFontAwesomeLight.LayoutTransform>
                                            <RotateTransform Angle="-90" />
                                        </IconPacks:PackIconFontAwesomeLight.LayoutTransform>
                                    </IconPacks:PackIconFontAwesomeLight>
                                    <TextBlock Grid.Column="1"
                                               Margin="5,0"
                                               HorizontalAlignment="Center"
                                               VerticalAlignment="Center"
                                               Foreground="{DynamicResource LabelTextBrush}"
                                               Text="Open Issues"
                                               TextTrimming="CharacterEllipsis" />
                                </Grid>
                            </Label>
                        </Expander.Header>
                        <ListBox x:Name="issueListBox"
                                 DisplayMemberPath="Title"
                                 ItemsSource="{Binding IssueList}" />
                    </Expander>
                    <Grid Grid.Column="1">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Grid Grid.Row="0"
                              Margin="5,0,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Label Grid.Column="0"
                                   Style="{StaticResource TopLevelHeaderStyle}">
                                <TextBlock Text="Issue: "
                                           TextTrimming="CharacterEllipsis" />
                            </Label>
                            <Label Grid.Column="1"
                                   Style="{StaticResource TopLevelHeaderStyle}">
                                <TextBlock Text="{Binding ElementName=issueListBox, Path=SelectedItem.Title}"
                                           TextWrapping="Wrap" />
                            </Label>
                        </Grid>
                        <Grid Grid.Row="1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition Width=".25*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <Grid Margin="5,0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition />
                                    <ColumnDefinition />
                                    <ColumnDefinition />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <Label Grid.Column="0"
                                       Style="{StaticResource ThirdLevelHeaderStyle}">
                                    <StackPanel Orientation="Horizontal">
                                        <IconPacks:PackIconFontAwesomeLight Margin="0,0,5,0"
                                                                            VerticalAlignment="Center"
                                                                            Kind="Hashtag"
                                                                            ToolTip="Issue Number" />
                                        <TextBlock VerticalAlignment="Center"
                                                   Text="{Binding ElementName=issueListBox, Path=SelectedItem.Number}"
                                                   TextTrimming="CharacterEllipsis" />
                                    </StackPanel>
                                </Label>
                                <Label Grid.Column="1"
                                       Style="{StaticResource ThirdLevelHeaderStyle}">
                                    <StackPanel Orientation="Horizontal">
                                        <IconPacks:PackIconFontAwesomeLight Margin="0,0,5,0"
                                                                            VerticalAlignment="Center"
                                                                            Kind="CommentsAlt"
                                                                            ToolTip="Comments" />
                                        <TextBlock VerticalAlignment="Center"
                                                   Text="{Binding ElementName=issueListBox, Path=SelectedItem.Comments}"
                                                   TextTrimming="CharacterEllipsis" />
                                    </StackPanel>
                                </Label>
                                <Label Grid.Column="2"
                                       Style="{StaticResource ThirdLevelHeaderStyle}">
                                    <StackPanel Orientation="Horizontal">
                                        <IconPacks:PackIconFontAwesomeLight Margin="0,0,5,0"
                                                                            VerticalAlignment="Center"
                                                                            Kind="MapSigns"
                                                                            ToolTip="Milestone" />
                                        <TextBlock VerticalAlignment="Center"
                                                   Text="{Binding ElementName=issueListBox, Path=SelectedItem.Milestone}"
                                                   TextTrimming="CharacterEllipsis" />
                                    </StackPanel>
                                </Label>
                                <Label Grid.Column="3"
                                       Style="{StaticResource ThirdLevelHeaderStyle}">
                                    <StackPanel Orientation="Horizontal">
                                        <IconPacks:PackIconFontAwesomeLight Margin="0,0,5,0"
                                                                            VerticalAlignment="Center"
                                                                            Kind="Browser" />
                                        <TextBlock HorizontalAlignment="Stretch"
                                                   Style="{StaticResource HyperlinkTextBlockStyle}"
                                                   Text="View on GitHub"
                                                   TextTrimming="CharacterEllipsis"
                                                   ToolTip="{Binding ElementName=issueListBox, Path=SelectedItem.HtmlUrl}">
                                            <TextBlock.InputBindings>
                                                <MouseBinding Command="{Binding GitHubLinksCommand}"
                                                              CommandParameter="{Binding ElementName=issueListBox, Path=SelectedItem.HtmlUrl}"
                                                              MouseAction="LeftClick" />
                                            </TextBlock.InputBindings>
                                        </TextBlock>
                                    </StackPanel>
                                </Label>
                            </Grid>
                            <Grid Grid.RowSpan="2"
                                  Grid.Column="1">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Label Style="{StaticResource ThirdLevelHeaderStyle}">
                                    <TextBlock Text="Assigned Labels"
                                               TextTrimming="CharacterEllipsis" />
                                </Label>
                                <ListView Grid.Row="1"
                                          BorderBrush="{DynamicResource TextBoxBorderBrush}"
                                          BorderThickness="1"
                                          ItemsSource="{Binding ElementName=issueListBox, Path=SelectedItem.Labels}"
                                          ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                          Style="{StaticResource CustomListView}">
                                    <ListView.ItemContainerStyle>
                                        <Style TargetType="Control">
                                            <Setter Property="Focusable" Value="False" />
                                        </Style>
                                    </ListView.ItemContainerStyle>
                                    <ListView.ItemTemplate>
                                        <DataTemplate>
                                            <Grid Margin="2">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition />
                                                </Grid.ColumnDefinitions>
                                                <Rectangle Width="5"
                                                           VerticalAlignment="Stretch"
                                                           Fill="{Binding Color}"
                                                           RadiusX="3"
                                                           RadiusY="3" />
                                                <TextBlock Grid.Column="1"
                                                           Margin="5,0,0,0"
                                                           Text="{Binding Name}"
                                                           TextTrimming="CharacterEllipsis"
                                                           TextWrapping="NoWrap" />
                                            </Grid>
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                </ListView>
                                <Label Grid.Row="2"
                                       Style="{StaticResource ThirdLevelHeaderStyle}">
                                    <TextBlock Text="Label Categories"
                                               TextTrimming="CharacterEllipsis" />
                                </Label>
                                <ListView Grid.Row="3"
                                          Controls:ControlsHelper.CornerRadius="3"
                                          BorderBrush="{DynamicResource TextBoxBorderBrush}"
                                          BorderThickness="1"
                                          ItemsSource="{Binding IssueLabelCategoryList}"
                                          ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                          Style="{StaticResource CustomListView}">
                                    <ListView.ItemContainerStyle>
                                        <Style TargetType="Control">
                                            <Setter Property="Focusable" Value="False" />
                                        </Style>
                                    </ListView.ItemContainerStyle>
                                    <ListView.ItemTemplate>
                                        <DataTemplate>
                                            <Grid Margin="2">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition />
                                                </Grid.ColumnDefinitions>
                                                <Rectangle Width="{Binding RelativeSource={RelativeSource Self}, Path=ActualHeight}"
                                                           VerticalAlignment="Stretch"
                                                           Fill="{Binding Color}"
                                                           RadiusX="3"
                                                           RadiusY="3" />
                                                <TextBlock Grid.Column="1"
                                                           Margin="5,0,0,0"
                                                           Text="{Binding Category}"
                                                           TextTrimming="CharacterEllipsis"
                                                           TextWrapping="NoWrap" />
                                            </Grid>
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                </ListView>
                            </Grid>
                            <Border Grid.Row="1"
                                    Margin="5,0"
                                    BorderBrush="{DynamicResource TextBoxBorderBrush}"
                                    BorderThickness="1"
                                    CornerRadius="3">
                                <wpf:MarkdownViewer VerticalAlignment="Stretch"
                                                    HorizontalContentAlignment="Left"
                                                    Markdown="{Binding ElementName=issueListBox, Path=SelectedItem.Body}"
                                                    Pipeline="{Binding MarkdownPipeline}"
                                                    ScrollViewer.CanContentScroll="True"
                                                    ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                                    ScrollViewer.VerticalScrollBarVisibility="Auto" />
                            </Border>
                        </Grid>
                    </Grid>
                </Grid>
            </TabItem>
            <TabItem Header="Releases"
                     Style="{StaticResource CustomMetroTabItem}">
                <Grid Margin="5,0,5,5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Expander Margin="0,5"
                              Background="{DynamicResource WindowBackgroundBrush}"
                              BorderThickness="0"
                              ExpandDirection="Right"
                              IsExpanded="False">
                        <Expander.Header>
                            <Label Foreground="{DynamicResource LabelTextBrush}">
                                <Label.LayoutTransform>
                                    <RotateTransform Angle="90" />
                                </Label.LayoutTransform>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <IconPacks:PackIconFontAwesomeLight Grid.Column="0"
                                                                        Margin="5"
                                                                        HorizontalAlignment="Center"
                                                                        VerticalAlignment="Center"
                                                                        Kind="Tag">
                                        <IconPacks:PackIconFontAwesomeLight.LayoutTransform>
                                            <RotateTransform Angle="-90" />
                                        </IconPacks:PackIconFontAwesomeLight.LayoutTransform>
                                    </IconPacks:PackIconFontAwesomeLight>
                                    <TextBlock Grid.Column="1"
                                               Margin="5,0"
                                               HorizontalAlignment="Center"
                                               VerticalAlignment="Center"
                                               Foreground="{DynamicResource LabelTextBrush}"
                                               Text="Releases"
                                               TextTrimming="CharacterEllipsis" />
                                </Grid>
                            </Label>
                        </Expander.Header>
                        <ListBox x:Name="releaseListBox"
                                 DisplayMemberPath="TagName"
                                 ItemsSource="{Binding ReleaseList}" />
                    </Expander>
                    <Grid Grid.Column="1">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Grid Grid.Row="0"
                              Margin="5,0,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Label Grid.Column="0"
                                   Style="{StaticResource TopLevelHeaderStyle}">
                                <TextBlock Text="Release: "
                                           TextTrimming="CharacterEllipsis" />
                            </Label>
                            <Label Grid.Column="1"
                                   Style="{StaticResource TopLevelHeaderStyle}">
                                <TextBlock Text="{Binding ElementName=releaseListBox, Path=SelectedItem.Name}"
                                           TextWrapping="Wrap" />
                            </Label>
                        </Grid>
                        <Grid Grid.Row="1"
                              Margin="5,0,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition />
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Label Grid.Column="0"
                                   Style="{StaticResource ThirdLevelHeaderStyle}">
                                <StackPanel Orientation="Horizontal">
                                    <IconPacks:PackIconFontAwesomeLight Margin="0,0,5,0"
                                                                        VerticalAlignment="Center"
                                                                        Kind="Tag"
                                                                        ToolTip="Tag" />
                                    <TextBlock VerticalAlignment="Center"
                                               Text="{Binding ElementName=releaseListBox, Path=SelectedItem.TagName}"
                                               TextTrimming="CharacterEllipsis" />
                                </StackPanel>
                            </Label>
                            <Label Grid.Column="1"
                                   Style="{StaticResource ThirdLevelHeaderStyle}">
                                <StackPanel Orientation="Horizontal">
                                    <IconPacks:PackIconFontAwesomeLight Margin="0,0,5,0"
                                                                        VerticalAlignment="Center"
                                                                        Kind="CalendarAlt"
                                                                        ToolTip="Release Date" />
                                    <TextBlock VerticalAlignment="Center"
                                               Text="{Binding ElementName=releaseListBox, Path=SelectedItem.CreatedAt}"
                                               TextTrimming="CharacterEllipsis" />
                                </StackPanel>
                            </Label>
                            <Label Grid.Column="2"
                                   Style="{StaticResource ThirdLevelHeaderStyle}">
                                <StackPanel Orientation="Horizontal">
                                    <IconPacks:PackIconFontAwesomeLight Margin="0,0,5,0"
                                                                        VerticalAlignment="Center"
                                                                        Kind="Download"
                                                                        ToolTip="Download Count" />
                                    <TextBlock VerticalAlignment="Center"
                                               Text="{Binding ElementName=releaseListBox, Path=SelectedItem.Downloads}"
                                               TextTrimming="CharacterEllipsis" />
                                </StackPanel>
                            </Label>
                            <Label Grid.Column="3"
                                   Style="{StaticResource ThirdLevelHeaderStyle}">
                                <StackPanel Orientation="Horizontal">
                                    <IconPacks:PackIconFontAwesomeLight Margin="0,0,5,0"
                                                                        VerticalAlignment="Center"
                                                                        Kind="Browser" />
                                    <TextBlock HorizontalAlignment="Stretch"
                                               Style="{StaticResource HyperlinkTextBlockStyle}"
                                               Text="View on GitHub"
                                               TextTrimming="CharacterEllipsis"
                                               ToolTip="{Binding ElementName=releaseListBox, Path=SelectedItem.HtmlUrl}">
                                        <TextBlock.InputBindings>
                                            <MouseBinding Command="{Binding GitHubLinksCommand}"
                                                          CommandParameter="{Binding ElementName=releaseListBox, Path=SelectedItem.HtmlUrl}"
                                                          MouseAction="LeftClick" />
                                        </TextBlock.InputBindings>
                                    </TextBlock>
                                </StackPanel>
                            </Label>
                        </Grid>
                        <Border Grid.Row="2"
                                Margin="5,0,0,0"
                                BorderBrush="{DynamicResource TextBoxBorderBrush}"
                                BorderThickness="1"
                                CornerRadius="3">
                            <wpf:MarkdownViewer VerticalAlignment="Stretch"
                                                HorizontalContentAlignment="Left"
                                                Markdown="{Binding ElementName=releaseListBox, Path=SelectedItem.Body}"
                                                Pipeline="{Binding MarkdownPipeline}"
                                                ScrollViewer.CanContentScroll="True"
                                                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                                ScrollViewer.VerticalScrollBarVisibility="Auto" />
                        </Border>
                    </Grid>
                </Grid>
            </TabItem>
        </Controls:MetroAnimatedSingleRowTabControl>
    </Grid>
</UserControl>
