<UserControl x:Class="GitHub.VisualStudio.Views.GitHubPane.PullRequestListView"
             Name="root"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:ghfvs="https://github.com/github/VisualStudio"
             xmlns:local="clr-namespace:GitHub.VisualStudio.Views.GitHubPane"
             xmlns:v="clr-namespace:GitHub.VisualStudio.Views"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"
             Background="{DynamicResource GitHubVsToolWindowBackground}"
             Foreground="{DynamicResource GitHubVsWindowText}"
             AutomationProperties.AutomationId="{x:Static ghfvs:AutomationIDs.PullRequestListViewCustom}">
    <d:DesignProperties.DataContext>
        <ghfvs:PullRequestListViewModelDesigner Message="None" StateCaption="3 Open"/>
    </d:DesignProperties.DataContext>

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ghfvs:SharedDictionaryManager Source="pack://application:,,,/GitHub.VisualStudio.UI;component/SharedDictionary.xaml" />
                <ghfvs:SharedDictionaryManager Source="pack://application:,,,/GitHub.UI;component/SharedDictionary.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <DockPanel>
        <DockPanel DockPanel.Dock="Top"
                   Margin="8">
            <ghfvs:DropDownButton DockPanel.Dock="Left"
                                  Cursor="Hand"
                                  Foreground="{DynamicResource GitHubActionLinkItemBrush}">
                <ghfvs:DropDownButton.DropDownContent>
                    <ListBox Background="{DynamicResource VsBrush.Window}"
                             BorderBrush="{DynamicResource VsBrush.DropDownPopupBorder}"
                             BorderThickness="1"
                             ItemsSource="{Binding States}"
                             Padding="2"
                             MinWidth="100"
                             SelectedItem="{Binding SelectedState}"/>
                </ghfvs:DropDownButton.DropDownContent>
                <TextBlock>
                    <Hyperlink Foreground="{DynamicResource GitHubActionLinkItemBrush}">
                        <Run Text="{Binding StateCaption, Mode=OneWay}"/>
                    </Hyperlink>
                </TextBlock>
            </ghfvs:DropDownButton>

            <Separator DockPanel.Dock="Left" Style="{StaticResource VerticalSeparator}" Margin="4 0" />

            <ghfvs:GitHubActionLink DockPanel.Dock="Left"
                                    Command="{Binding CreatePullRequest}"
                                    Content="{x:Static ghfvs:Resources.CreateNew}"/>

            <ghfvs:DropDownButton Name="authorFilterDropDown"
                                  DockPanel.Dock="Right"
                                  AutoCloseOnClick="False"
                                  Cursor="Hand"
                                  Foreground="{DynamicResource GitHubActionLinkItemBrush}"
                                  Padding="2"
                                  ToolTip="{x:Static ghfvs:Resources.FilterByAuthor}"
                                  VerticalAlignment="Center"
                                  Visibility="{Binding Items.Count, Converter={ghfvs:CountToVisibilityConverter}}"
                                  PopupOpened="authorFilterDropDown_PopupOpened">
                <ghfvs:OcticonImage Icon="person" Height="12" Width="12"/>
                <ghfvs:DropDownButton.DropDownContent>
                    <Border Background="{DynamicResource VsBrush.Window}"
                            BorderBrush="{DynamicResource VsBrush.DropDownPopupBorder}"
                            BorderThickness="1"
                            Padding="2"
                            MinWidth="150"
                            MaxHeight="250">
                        <v:UserFilterView x:Name="authorFilter" DataContext="{Binding AuthorFilter}"/>
                    </Border>
                </ghfvs:DropDownButton.DropDownContent>
            </ghfvs:DropDownButton>

            <ghfvs:DropDownButton DockPanel.Dock="Right"
                                  Cursor="Hand"
                                  Foreground="{DynamicResource GitHubActionLinkItemBrush}"
                                  Padding="2"
                                  ToolTip="{x:Static ghfvs:Resources.SelectFork}"
                                  VerticalAlignment="Center"
                                  Visibility="{Binding Forks, Converter={ghfvs:NullToVisibilityConverter}}">
                <ghfvs:OcticonImage Icon="repo_forked" Height="12" Width="12"/>
                <ghfvs:DropDownButton.DropDownContent>
                    <ListBox Background="{DynamicResource VsBrush.Window}"
                             BorderBrush="{DynamicResource VsBrush.DropDownPopupBorder}"
                             BorderThickness="1"
                             ItemsSource="{Binding Forks}"
                             Padding="2"
                             MinWidth="100"
                             SelectedItem="{Binding RemoteRepository}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock>
                                    <Run Text="{Binding Owner, Mode=OneWay}"/>/<Run Text="{Binding Name, Mode=OneWay}"/>
                                </TextBlock>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </ghfvs:DropDownButton.DropDownContent>
            </ghfvs:DropDownButton>

            <Rectangle/>
        </DockPanel>
        <Grid>
            <ListBox ItemsSource="{Binding ItemsView}"
                     BorderThickness="0"
                     ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                     Visibility="{Binding Message, Converter={ghfvs:EqualsToVisibilityConverter None}}"
                     ContextMenuOpening="ListBox_ContextMenuOpening"
                     KeyDown="ListBox_KeyDown">
                <ListBox.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="{x:Static ghfvs:Resources.Open}" Command="{Binding OpenItem}"/>
                        <MenuItem Header="{x:Static ghfvs:Resources.openInBrowser}" Command="{Binding OpenItemInBrowser}"/>
                    </ContextMenu>
                </ListBox.ContextMenu>
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                        <EventSetter Event="MouseDoubleClick" Handler="ListBoxItem_MouseDoubleClick"/>
                    </Style>
                </ListBox.ItemContainerStyle>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <local:PullRequestListItemView/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

            <StackPanel Margin="10" 
                        VerticalAlignment="Center"
                        Visibility="{Binding Message, Converter={ghfvs:EqualsToVisibilityConverter NoOpenItems}}">
                <ghfvs:OcticonImage Icon="git_pull_request"
                                    Margin="0,5"
                                    Width="48"
                                    Height="48"/>
                <TextBlock Foreground="{DynamicResource GitHubVsWindowText}"
                           HorizontalAlignment="Center"
                           FontSize="16"
                           Margin="4"
                           Text="{x:Static ghfvs:Resources.ThereArenTAnyOpenPullRequests}"/>
                <TextBlock TextWrapping="Wrap"
                           TextAlignment="Center"
                           HorizontalAlignment="Center"
                           Margin="4"
                           Opacity="0.75"
                           Text="{x:Static ghfvs:Resources.PullRequestsLetYouTellOthersAboutChangesYouVePushedToARepositoryOnGitHub}"/>
                <TextBlock TextWrapping="Wrap"
                           TextAlignment="Center"
                           HorizontalAlignment="Center"
                           Margin="4"
                           Opacity="0.75">
                    <Run Text="{x:Static ghfvs:Resources.ToGetStartedYouCan}"/>
                    <Hyperlink Command="{Binding CreatePullRequest}"
                               Foreground="{DynamicResource GitHubActionLinkItemBrush}">
                        <Run Text="{x:Static ghfvs:Resources.CreateAPullRequest}"/>
                    </Hyperlink>
                </TextBlock>
            </StackPanel>

            <StackPanel Margin="10" 
                        VerticalAlignment="Center"
                        Visibility="{Binding Message, Converter={ghfvs:EqualsToVisibilityConverter NoItemsMatchCriteria}}">
                <ghfvs:OcticonImage Icon="git_pull_request"
                                    Margin="0,5"
                                    Width="48"
                                    Height="48"/>
                <TextBlock Foreground="{DynamicResource GitHubVsWindowText}"
                           HorizontalAlignment="Center"
                           FontSize="16"
                           Margin="4"
                           Text="{x:Static ghfvs:Resources.NoResultsMatchedYourSearch}"/>
            </StackPanel>
        </Grid>
    </DockPanel>
</UserControl>

