<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:ext="clr-namespace:BacklinksWarrior.Extensions"
             xmlns:my="clr-namespace:BacklinksWarrior" xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" x:Class="ResultView"
             mc:Ignorable="d" 
             d:DesignHeight="600" d:DesignWidth="600"
             DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <UserControl.CommandBindings>
        <CommandBinding Command="my:Commands.StatusNew" Executed="StatusNew_Executed" />
        <CommandBinding Command="my:Commands.StatusAdded" Executed="StatusAdded_Executed" />
        <CommandBinding Command="my:Commands.StatusIgnored" Executed="StatusIgnored_Executed" />
        <CommandBinding Command="my:Commands.OpenUrl" Executed="OpenUrl_Executed" />
        <CommandBinding Command="my:Commands.CopyUrl" Executed="CopyUrl_Executed" />
        <CommandBinding Command="my:Commands.ViewNotes" Executed="ViewNotes_Executed" />
        <CommandBinding Command="my:Commands.RemoveSelected" Executed="RemoveSelected" />
    </UserControl.CommandBindings>
    <UserControl.InputBindings>
        <KeyBinding Modifiers="Control" Key="U" Command="my:Commands.OpenUrl" />
        <KeyBinding Modifiers="Control" Key="C" Command="my:Commands.CopyUrl" />
        <KeyBinding Modifiers="Control" Key="V" Command="my:Commands.ViewNotes" />
        <KeyBinding Modifiers="Shift" Key="Del" Command="my:Commands.RemoveSelected" />
    </UserControl.InputBindings>
    <UserControl.Resources>
        <!--<my:NegativeToUnknownConverter x:Key="negativeToUnknownConverter" />
        <my:DataCenterToIconConverter x:Key="dataCenterToIconConverter" />
        <my:DomainStatusToIcon x:Key="domainStatusToIcon" />
        <my:NoteIconConverter x:Key="noteIconConverter" />-->
        <my:StatusToIconConverter x:Key="statusToIconConverter" />
        
        <ContextMenu x:Key="itemContextMenu" x:Shared="True">
            <MenuItem Header="Set Status">
                <MenuItem Command="my:Commands.StatusNew" />
                <MenuItem Command="my:Commands.StatusAdded">
                    <MenuItem.Icon>
                        <Image Source="/Backlinks%20Warrior;component/Resources/added.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Command="my:Commands.StatusIgnored">
                    <MenuItem.Icon>
                        <Image Source="/Backlinks%20Warrior;component/Resources/ignored.png" />
                    </MenuItem.Icon>
                </MenuItem>
            </MenuItem>
            <MenuItem Command="my:Commands.OpenUrl" />
            <MenuItem Command="my:Commands.CopyUrl" />
            <MenuItem Command="my:Commands.ViewNotes" />
            <MenuItem Command="my:Commands.RemoveSelected" />
        </ContextMenu>
        
        <Style x:Key="resultViewItemStyle" TargetType="{x:Type ListViewItem}">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
        
        <DataTemplate x:Key="HeaderTemplateArrowUp">
            <DockPanel LastChildFill="True" Width="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GridViewColumnHeader}}}">
                <Path x:Name="arrowUp" StrokeThickness="1" Fill="Gray" Data="M 5,10 L 15,10 L 10,5 L 5,10" DockPanel.Dock="Right" Width="20" HorizontalAlignment="Right" Margin="5,0,0,0" SnapsToDevicePixels="True"/>
                <TextBlock Text="{Binding ''}" />
            </DockPanel>
        </DataTemplate>

        <DataTemplate x:Key="HeaderTemplateArrowDown">
            <DockPanel LastChildFill="True" Width="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GridViewColumnHeader}}}">
                <Path x:Name="arrowDown" StrokeThickness="1" Fill="Gray"  Data="M 5,5 L 10,10 L 15,5 L 5,5" DockPanel.Dock="Right" Width="20" HorizontalAlignment="Right" Margin="5,0,0,0" SnapsToDevicePixels="True"/>
                <TextBlock Text="{Binding ''}" />
            </DockPanel>
        </DataTemplate>
        
    	<SolidColorBrush x:Key="ListBorder" Color="#828790"/>
        
        <Style x:Key="leftAlignHeader" TargetType="GridViewColumnHeader" BasedOn="{StaticResource {x:Type GridViewColumnHeader}}">
            <Setter Property="HorizontalContentAlignment" Value="Left" />
            <Setter Property="Padding" Value="5 2 0 2" />
        </Style>
        
        <Style x:Key="collapsedHeader" TargetType="GridViewColumnHeader" BasedOn="{StaticResource {x:Type GridViewColumnHeader}}">
            <Setter Property="FrameworkElement.Visibility" Value="Collapsed" />
            <Setter Property="Width" Value="0" />
        </Style>

        <Style x:Key="normalHeader" TargetType="GridViewColumnHeader" BasedOn="{StaticResource {x:Type GridViewColumnHeader}}">
            <Setter Property="FrameworkElement.Visibility" Value="Visible" />
            <Setter Property="Width" Value="Auto" />
        </Style>
    </UserControl.Resources>
    <Grid>
        <ListView x:Name="lstKeywords" ext:ListViewAttached.Stretch="True"
                  ButtonBase.Click="lstKeywords_Click"
                  ItemContainerStyle="{DynamicResource resultViewItemStyle}"
                  HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                  ContextMenu="{StaticResource itemContextMenu}" 
                  ItemsSource="{Binding Results}" Background="White">
            <!--<ListView.ItemTemplate>
                <DataTemplate>
                    <ContentPresenter Content="{Binding}" />
                </DataTemplate>
            </ListView.ItemTemplate>-->
            <ListView.View>
                <GridView>

                    <GridViewColumn Width="60" Header="Status" HeaderContainerStyle="{DynamicResource leftAlignHeader}">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Image Width="16" Height="16" HorizontalAlignment="Center" VerticalAlignment="Center"
                                    Source="{Binding Status, Converter={StaticResource statusToIconConverter}}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn x:Name="KeywordColumn" Width="80" Header="Keyword" HeaderContainerStyle="{DynamicResource leftAlignHeader}">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock HorizontalAlignment="Left" Text="{Binding Keyword}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    
                    <GridViewColumn Header="Page URL" HeaderContainerStyle="{DynamicResource leftAlignHeader}">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock>
                                    <Hyperlink NavigateUri="{Binding PageUrl}" Command="my:Commands.OpenUrl" CommandParameter="{Binding PageUrl}">
                                        <TextBlock Text="{Binding PageUrl}" />
                                    </Hyperlink>
                                </TextBlock>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn Width="200" Header="Notes" HeaderContainerStyle="{DynamicResource leftAlignHeader}">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock HorizontalAlignment="Center" Text="{Binding Notes}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                   </GridView>
            </ListView.View>
        </ListView>
    </Grid>
</UserControl>
