<views:GenericPullRequestReviewCommentView x:Class="GitHub.VisualStudio.Views.PullRequestReviewCommentView"
             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:ghfvs="https://github.com/github/VisualStudio"
             xmlns:cache="clr-namespace:GitHub.UI.Helpers;assembly=GitHub.UI"
             xmlns:controls="clr-namespace:GitHub.VisualStudio.UI.Controls"
             xmlns:ui="clr-namespace:GitHub.UI;assembly=GitHub.UI"
             xmlns:markdig="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf"
             xmlns:views="clr-namespace:GitHub.VisualStudio.Views"
             mc:Ignorable="d" d:DesignWidth="300">
    <d:DesignProperties.DataContext>
        <ghfvs:CommentViewModelDesigner EditState="None">
            <ghfvs:CommentViewModelDesigner.Body>
                You can use a `CompositeDisposable` type here, it's designed to handle disposables in an optimal way (you can just call `Dispose()` on it and it will handle disposing everything it holds).
            </ghfvs:CommentViewModelDesigner.Body>
        </ghfvs:CommentViewModelDesigner>
    </d:DesignProperties.DataContext>

    <FrameworkElement.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <cache:SharedDictionaryManager Source="pack://application:,,,/GitHub.UI;component/SharedDictionary.xaml" />
                <cache:SharedDictionaryManager Source="pack://application:,,,/GitHub.UI.Reactive;component/SharedDictionary.xaml" />
                <cache:SharedDictionaryManager Source="pack://application:,,,/GitHub.VisualStudio.UI;component/SharedDictionary.xaml" />
                <cache:SharedDictionaryManager Source="pack://application:,,,/GitHub.VisualStudio.UI;component/Styles/Markdown.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <Style TargetType="Button" BasedOn="{StaticResource GitHubVsButton}"/>
        </ResourceDictionary>
    </FrameworkElement.Resources>

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

    <Grid>
        <!-- Displays an existing comment-->
        <Border BorderBrush="{DynamicResource VsBrush.ScrollBarThumbBackground}" HorizontalAlignment="Stretch">
            <Grid Background="{DynamicResource VsBrush.ToolWindowBackground}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="4" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <Grid.Style>
                    <Style TargetType="FrameworkElement">
                        <Setter Property="Visibility" Value="Collapsed"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding EditState}" Value="None">
                                <Setter Property="Visibility" Value="Visible"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Grid.Style>

                <StackPanel Background="#82909e" Grid.Row="0" Grid.Column="0" Grid.RowSpan="5" Visibility="{Binding Model.AnnotationLevel, Converter={ghfvs:EqualsToVisibilityConverter Notice}}" />

                <Border Grid.Column="1" Padding="8">
                    <StackPanel>
                        <DockPanel>
                          <StackPanel Orientation="Horizontal" DockPanel.Dock="Left" >
                            <controls:AccountAvatar Width="16" 
                                                    Height="16" 
                                                    Account="{Binding Author}"/>

                            <TextBlock Foreground="{DynamicResource GitHubVsToolWindowText}" FontWeight="SemiBold" Text="{Binding Author.Login}" Margin="4 0"/>
                            <ui:GitHubActionLink Content="{Binding CreatedAt, Converter={ui:DurationToStringConverter}}"
                                                 Command="{Binding OpenOnGitHub}"
                                                 Foreground="{DynamicResource GitHubVsToolWindowText}"
                                                 Opacity="0.75" />
                            <Border Background="{DynamicResource VsBrush.InfoBackground}"
                                    BorderBrush="{DynamicResource VsBrush.AccentPale}"
                                    BorderThickness="1"
                                    CornerRadius="3"
                                    Padding="2 1"
                                    Visibility="{Binding IsPending, Converter={ui:BooleanToVisibilityConverter}, FallbackValue=Collapsed}">
                              <TextBlock FontSize="10" Text="{x:Static ghfvs:Resources.Pending}" />
                            </Border>
                          </StackPanel>

                          <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" DockPanel.Dock="Right"
                                      Visibility="{Binding CanDelete, Converter={ui:BooleanToVisibilityConverter}}">
                            <ui:OcticonButton Command="{Binding BeginEdit}"
                                              Height="16"
                                              Width="20"
                                              Margin="0 0 4 0"
                                              Background="Transparent"
                                              Foreground="{DynamicResource GitHubVsToolWindowText}"
                                              Icon="pencil"/>
                            <ui:OcticonButton Command="{Binding Delete}"
                                              Width="16"
                                              Height="16"
                                              Margin="0"
                                              Background="Transparent"
                                              Foreground="{DynamicResource GitHubVsToolWindowText}"
                                              Icon="x"/>
                          </StackPanel>
                        </DockPanel>

                        <markdig:MarkdownViewer Grid.Column="1" Grid.Row="1" 
                                                Name="bodyMarkdown"
                                                Margin="20 2 0 0"
                                                Foreground="{DynamicResource VsBrush.WindowText}"
                                                Markdown="{Binding Body}"/>

                        <DockPanel Grid.Column="1" Grid.Row="2"
                                   Margin="0 4"
                                   HorizontalAlignment="Left" 
                                   TextBlock.Foreground="Red">
                            <DockPanel.Style>
                                <Style TargetType="FrameworkElement">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding ErrorMessage}" Value="{x:Null}">
                                            <Setter Property="Visibility" Value="Collapsed"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </DockPanel.Style>
                            <ui:OcticonImage DockPanel.Dock="Left" Icon="alert" Margin="0 0 4 0"/>
                            <TextBlock Text="{Binding ErrorMessage}" TextWrapping="Wrap"/>
                        </DockPanel>
                    </StackPanel>
                </Border>
            </Grid>
        </Border>

        <!-- Displays edit view or a reply placeholder-->
        <Grid>
            <Grid.Style>
                <Style TargetType="FrameworkElement">
                    <Setter Property="Visibility" Value="Collapsed"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding EditState}" Value="Placeholder">
                            <Setter Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding EditState}" Value="Editing">
                            <Setter Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Grid.Style>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <Separator Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" Margin="0 0 0 4" 
                       Background="{DynamicResource GitHubButtonBorderBrush}"/>

            <ui:AutoCompleteBox
                Grid.Column="1"
                Grid.Row="1"
                Margin="4 0 4 4"
                Advisor="{Binding AutoCompleteAdvisor}">
                <ui:AutoCompleteBox.ItemTemplate>
                    <DataTemplate>
                        <ui:AutoCompleteSuggestionView ViewModel="{Binding}" />
                    </DataTemplate>
                </ui:AutoCompleteBox.ItemTemplate>
                <ui:AutoCompleteBox.InputElement>
                    <ui:TextBoxAutoCompleteTextInput>
                        <ui:PromptTextBox Name="body"
                                          AcceptsReturn="True"
                                          AcceptsTab="True"
                                          IsReadOnly="{Binding IsReadOnly}"
                                          Text="{Binding Body, UpdateSourceTrigger=PropertyChanged}"
                                          TextWrapping="Wrap"
                                          VerticalAlignment="Center"
                                          GotFocus="ReplyPlaceholder_GotFocus"
                                          Loaded="body_Loaded"
                                          SpellCheck.IsEnabled="True">
                            <ui:PromptTextBox.Style>
                                <Style TargetType="ui:PromptTextBox" BasedOn="{StaticResource GitHubVsPromptTextBox}">
                                    <Setter Property="Height" Value="28"/>
                                    <Setter Property="PromptText" Value="Reply..."/>

                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding EditState}" Value="Editing">
                                            <Setter Property="MinHeight" Value="100"/>
                                            <Setter Property="PromptText" Value="Leave a comment"/>
                                        </DataTrigger>
                                    </Style.Triggers>

                                    <Style.Resources>
                                        <Style TargetType="TextBlock">
                                            <Setter Property="Foreground" Value="{DynamicResource GitHubVsToolWindowText}" />
                                        </Style>
                                    </Style.Resources>
                                </Style>
                            </ui:PromptTextBox.Style>
                        </ui:PromptTextBox>
                    </ui:TextBoxAutoCompleteTextInput>
                </ui:AutoCompleteBox.InputElement>
            </ui:AutoCompleteBox>

            <DockPanel Grid.Column="1" Grid.Row="2"
                       Margin="0 4"
                       HorizontalAlignment="Left" 
                       TextBlock.Foreground="Red">
                <DockPanel.Style>
                    <Style TargetType="FrameworkElement">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ErrorMessage}" Value="{x:Null}">
                                <Setter Property="Visibility" Value="Collapsed"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </DockPanel.Style>
                <ui:OcticonImage DockPanel.Dock="Left" Icon="alert" Margin="0 0 4 0"/>
                <TextBlock Text="{Binding ErrorMessage}" TextWrapping="Wrap"/>
            </DockPanel>

            <StackPanel Name="buttonPanel"
                        Grid.Column="1" Grid.Row="3" 
                        Margin="4 8" 
                        HorizontalAlignment="Left"
                        Orientation="Horizontal"
                        IsVisibleChanged="buttonPanel_IsVisibleChanged">
                <StackPanel.Style>
                    <Style TargetType="FrameworkElement">
                        <Setter Property="Visibility" Value="Collapsed"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding EditState}" Value="Editing">
                                <Setter Property="Visibility" Value="Visible"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </StackPanel.Style>
                <Button Command="{Binding CommitEdit}" Content="{Binding CommitCaption}"/>
                <Button Margin="4 0 0 0"
                        Command="{Binding StartReview}"
                        Content="{x:Static ghfvs:Resources.StartAReview}"
                        Visibility="{Binding CanStartReview, Converter={ui:BooleanToVisibilityConverter}}"/>
                <Button Margin="4 0 0 0" Command="{Binding CancelEdit}" Content="{x:Static ghfvs:Resources.Cancel}"/>
            </StackPanel>
        </Grid>
    </Grid>
</views:GenericPullRequestReviewCommentView>
