<UserControl x:Class="ComPDFKit.Controls.PDFControlUI.AnnotationReplyListControl"
             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:common="clr-namespace:ComPDFKit.Controls.Common"
             xmlns:local="clr-namespace:ComPDFKit.Controls.PDFControlUI"
             mc:Ignorable="d" 
             Loaded= "UserControl_Loaded"
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../../../Asset/Styles/MenuItemStyle.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
            <common:TextLengthToVisibilityConverter x:Key="TextLengthToVisibilityConverter"></common:TextLengthToVisibilityConverter>
            <common:SubtractionConverter x:Key="SubtractionConverter"></common:SubtractionConverter>
            <common:AntiVisibilityConverter x:Key="AntiVisibilityConverter"></common:AntiVisibilityConverter>
            <common:BoolToVisibleConverter x:Key="BoolToVisibleConverter"></common:BoolToVisibleConverter>
            <common:BotaResourceConverter x:Key="BotaResourceConverter"></common:BotaResourceConverter>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid x:Name="ReplyGrid" Margin="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="0"></RowDefinition>
            <RowDefinition Height="0"></RowDefinition>
            <RowDefinition Height="0"></RowDefinition>
        </Grid.RowDefinitions>

        <Grid Grid.Row="0">
            <TextBox x:Name="InputTxb" Height="30" VerticalContentAlignment="Center"></TextBox>
            <TextBlock Text="{Binding Converter={StaticResource BotaResourceConverter},ConverterParameter=Holder_Reply}" VerticalAlignment="Center" Margin="10,0,0,0" Foreground="#A0A0A0" IsHitTestVisible="False"
                      Visibility="{Binding ElementName=InputTxb, Path=Text, Converter={StaticResource TextLengthToVisibilityConverter}}"></TextBlock>
        </Grid>

        <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
            <Button Content="{Binding Converter={StaticResource BotaResourceConverter},ConverterParameter=Button_Cancel}" Background="Transparent" BorderThickness="0" Margin="0,0,5,0" Width="56" Height="30" Click="ButtonCancel_Click"></Button>
            <Button Content="{Binding Converter={StaticResource BotaResourceConverter},ConverterParameter=Button_Reply}" Width="56" Height="30" Foreground="White" Background="#1460F3" BorderThickness="0" Click="ReplyButton_Click"></Button>
        </StackPanel>

        <ListView Grid.Row="2" x:Name="ReplyList" Margin="0,0,0,0" VirtualizingPanel.IsVirtualizingWhenGrouping="True" 
                 ScrollViewer.HorizontalScrollBarVisibility="Hidden" BorderThickness="0" SelectionMode="Single" 
                   Visibility="{Binding ElementName=ReplyList, Path=HasItems, Converter={StaticResource BoolToVisibleConverter}}">
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Background="#FAFCFF" HorizontalAlignment="Stretch" MaxHeight="200"
                                           Width="{Binding ActualWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListView}, Converter={StaticResource SubtractionConverter}, ConverterParameter=5}"></VirtualizingStackPanel>
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ListViewItem">
                                <ContentPresenter />
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="MinHeight" Value="0" />
                    <Setter Property="Height" Value="Auto" /> 
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.ItemTemplate>
                <ItemContainerTemplate> 
                    <Grid>
                        <Grid.Style>
                            <Style TargetType="Grid"> 
                                <Style.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Background" Value="#D0D9E1"/> 
                                    </Trigger>
                                    <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListViewItem}}" Value="True">
                                        <Setter Property="Background" Value="#D0D9E1"/> 
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Grid.Style>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>

                        <DockPanel Grid.Column="0">
                            <StackPanel VerticalAlignment="Center">
                                <TextBlock Text="{Binding Author}" FontSize="14" Foreground="#43474D" VerticalAlignment="Center"/>
                                <TextBlock Text="{Binding Date}" FontSize="11" Foreground="#999999" VerticalAlignment="Center"/>
                            </StackPanel>
                        </DockPanel>

                        <Menu Background="Transparent" BorderThickness="0" Grid.Column="1">
                            <MenuItem  BorderThickness="0" Width="30" Height="30" Padding="4,3,0,0">
                                <MenuItem.Header>
                                    <Canvas Width="30" Height="30"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                                        <Path Data="M10 5.5C10.8284 5.5 11.5 4.82843 11.5 4C11.5 3.17157 10.8284 2.5 10 2.5C9.17157 2.5 8.5 3.17157 8.5 4C8.5 4.82843 9.17157 5.5 10 5.5ZM11.5 10C11.5 10.8284 10.8284 11.5 10 11.5C9.17157 11.5 8.5 10.8284 8.5 10C8.5 9.17157 9.17157 8.5 10 8.5C10.8284 8.5 11.5 9.17157 11.5 10ZM11.5 16C11.5 16.8284 10.8284 17.5 10 17.5C9.17157 17.5 8.5 16.8284 8.5 16C8.5 15.1716 9.17157 14.5 10 14.5C10.8284 14.5 11.5 15.1716 11.5 16Z" 
                                             Fill="#43474D"/>
                                    </Canvas>
                                </MenuItem.Header>
                                <MenuItem Header="{Binding Converter={StaticResource BotaResourceConverter},ConverterParameter=Menu_Edit}" Style="{StaticResource Sub_MenuItem}">
                                    <MenuItem.Command>
                                        <local:ShowContentBoxCommand/>
                                    </MenuItem.Command>
                                    <MenuItem.CommandParameter>
                                        <Binding ElementName="ContentBox"/>
                                    </MenuItem.CommandParameter>
                                </MenuItem>

                                <MenuItem Header="{Binding Converter={StaticResource BotaResourceConverter},ConverterParameter=Menu_Delete}" Style="{StaticResource Sub_MenuItem}">
                                    <MenuItem.Command>
                                        <local:DeleteReplyCommand/>
                                    </MenuItem.Command>
                                    <MenuItem.CommandParameter>
                                        <Binding Path="."></Binding>
                                    </MenuItem.CommandParameter>
                                </MenuItem>
                            </MenuItem>
                        </Menu>
                        <Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
                            <TextBox x:Name="ContentBox" Text="{Binding Content}" FontSize="14" Foreground="#666666" Margin="5,5,0,0"
                                    Visibility="Collapsed" VerticalAlignment="Center" LostFocus="ContentBox_LostFocus"></TextBox>

                            <TextBlock Text="{Binding Content}" x:Name="ContentTxb" FontSize="14" Foreground="#666666" Margin="5,5,0,0" VerticalAlignment="Center"
                                      Visibility="{Binding ElementName=ContentBox,Path=Visibility,Converter={StaticResource AntiVisibilityConverter}}"></TextBlock>
                        </Grid>

                    </Grid>
                </ItemContainerTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</UserControl>
