<UserControl x:Class="_1RM.Controls.NoteDisplay.NoteDisplayAndEditor"
             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:wpf="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf"
             xmlns:system="clr-namespace:System;assembly=System.Runtime"
             xmlns:attachProperty="clr-namespace:Shawn.Utils.WpfResources.Theme.AttachProperty;assembly=Shawn.Utils.WpfResources"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <system:Double x:Key="LauncherGridKeywordHeight">46</system:Double>
        <system:Double x:Key="LauncherOutlineCornerRadius">8</system:Double>
        <CornerRadius x:Key="LauncherOutlineCornerRadiusObj" TopLeft="{StaticResource LauncherOutlineCornerRadius}" TopRight="{StaticResource LauncherOutlineCornerRadius}" BottomLeft="{StaticResource LauncherOutlineCornerRadius}" BottomRight="{StaticResource LauncherOutlineCornerRadius}"></CornerRadius>
    </UserControl.Resources>

    <Border Padding="0 " Margin="0" Background="Transparent">
        <Border CornerRadius="{StaticResource LauncherOutlineCornerRadiusObj}" Background="{DynamicResource PrimaryMidBrush}">
            <Grid Name="Main">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="*"></RowDefinition>
                </Grid.RowDefinitions>

                <Grid RowSpan="2" PreviewMouseDown="Ignore_OnPreviewMouseDown" PreviewMouseMove="Ignore_OnPreviewMouseMove" Background="Transparent"></Grid>

                <Border Grid.Row="0" Background="{DynamicResource PrimaryMidBrush}" Height="{StaticResource LauncherGridKeywordHeight}"
                        BorderThickness="0 0 0 1">
                    <Border.BorderBrush>
                        <SolidColorBrush Color="{DynamicResource PrimaryTextColor}" Opacity="0.5"></SolidColorBrush>
                    </Border.BorderBrush>
                    <Border.CornerRadius>
                        <CornerRadius TopLeft="{StaticResource LauncherOutlineCornerRadius}" TopRight="{StaticResource LauncherOutlineCornerRadius}"></CornerRadius>
                    </Border.CornerRadius>
                    <Grid>
                        <TextBlock Text="{DynamicResource Note}" 
                                   Style="{StaticResource TextBlockBase}"
                                   FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Center"
                                   Foreground="{DynamicResource PrimaryTextBrush}"></TextBlock>

                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                            <Button Name="ButtonEdit" Width="20" Height="20"
                                    Style="{StaticResource ButtonBarPrimaryStyle}"
                                    Background="Transparent"
                                    attachProperty:VisionElement.BackgroundAccent="Transparent"
                                    attachProperty:VisionElement.BackgroundOnMouseDown="Transparent"
                                    HorizontalAlignment="Right"
                                    attachProperty:VisionElement.Opacity="0.5"
                                    attachProperty:VisionElement.OpacityAccent="0.9"
                                    Click="ButtonNoteStartEdit_OnClick"
                                    Margin="5 0">
                                <Path Data="M804.6 689.8l64-64c10-10 27.4-3 27.4 11.4V928c0 53-43 96-96 96H96c-53 0-96-43-96-96V224c0-53 43-96 96-96h547c14.2 0 21.4 17.2 11.4 27.4l-64 64c-3 3-7 4.6-11.4 4.6H96v704h704V701c0-4.2 1.6-8.2 4.6-11.2z m313.2-403.6L592.6 811.4l-180.8 20c-52.4 5.8-97-38.4-91.2-91.2l20-180.8L865.8 34.2c45.8-45.8 119.8-45.8 165.4 0l86.4 86.4c45.8 45.8 45.8 120 0.2 165.6zM920.2 348L804 231.8 432.4 603.6l-14.6 130.6 130.6-14.6L920.2 348z m129.6-159.4l-86.4-86.4c-8.2-8.2-21.6-8.2-29.6 0L872 164l116.2 116.2 61.8-61.8c8-8.4 8-21.6-0.2-29.8z"
                                      Width="18"
                                      Stroke="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType=Button}}"
                                      Fill="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType=Button}}"
                                      StrokeThickness="0" Stretch="Uniform" />
                            </Button>


                            <Button Name="ButtonClose" Width="20" Height="20" 
                                    Style="{StaticResource ButtonBarPrimaryStyle}"
                                    IsEnabled="False"
                                    Background="Transparent"
                                    attachProperty:VisionElement.BackgroundAccent="Transparent"
                                    attachProperty:VisionElement.BackgroundOnMouseDown="Transparent"
                                    attachProperty:VisionElement.Opacity="0.5"
                                    attachProperty:VisionElement.OpacityAccent="0.9"
                                    Click="ButtonClose_OnClick"
                                    Margin="5 0">
                                <Path Data="{StaticResource GeometryCloseCross}"
                                      Width="12"
                                      Stroke="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType=Button}}"
                                      Fill="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType=Button}}"
                                      StrokeThickness="2" Stretch="Uniform" />
                            </Button>
                        </StackPanel>
                    </Grid>
                </Border>


                <Border Grid.Row="1" Background="{DynamicResource PrimaryMidBrush}">
                    <Border.CornerRadius>
                        <CornerRadius BottomLeft="{StaticResource LauncherOutlineCornerRadius}" BottomRight="{StaticResource LauncherOutlineCornerRadius}"></CornerRadius>
                    </Border.CornerRadius>
                    <FrameworkElement.CommandBindings>
                        <CommandBinding Command="{x:Static wpf:Commands.Hyperlink}" Executed="OpenHyperlink" />
                        <CommandBinding Command="{x:Static wpf:Commands.Image}" Executed="ClickOnImage" />
                    </FrameworkElement.CommandBindings>
                    <Grid Margin="10"
                          MouseEnter="GridEditor_OnMouseEnter"
                          MouseLeave="GridEditor_OnMouseLeave"
                          Background="Transparent"
                          >
                        <wpf:MarkdownViewer Name="MarkdownViewer"
                                            PreviewMouseDown="Ignore_OnPreviewMouseDown" 
                                            PreviewMouseMove="Ignore_OnPreviewMouseMove"
                                            Foreground="{DynamicResource PrimaryTextBrush}">
                        </wpf:MarkdownViewer>

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


                            <TextBox Grid.Row="0" Name="TbMarkdown" TextWrapping="Wrap" Width="Auto"
                                     MouseWheel="TbMarkdown_OnMouseWheel"
                                     PreviewMouseDown="TbMarkdown_OnPreviewMouseDown"
                                     TextAlignment="Left" Margin="0 5"
                                     VerticalContentAlignment="Top"
                                     AcceptsReturn="True"
                                     AcceptsTab="True"
                                     Tag="&#13;# Markdown support&#13;&#13;- write your note here&#13;- foo&#13;&#13;![pic](http://x/structure.png)&#13;&#13;[link](http://x/readme.md)" xml:space="preserve">
                            </TextBox>


                            <StackPanel Name="GridButtons"  Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center">
                                <Button Name="ButtonSave"
                                        Margin="0 0 15 0"
                                        Padding="0 1 0 0" MinWidth="80" MinHeight="25"
                                        HorizontalAlignment="Left"
                                        Click="ButtonSave_OnClick"
                                        Style="{StaticResource ButtonAccentStyle}"
                                        Content="{DynamicResource Save}">
                                </Button>

                                <Button Padding="0 1 0 0" MinWidth="80" MinHeight="25"
                                        Margin="15 0 0 0"
                                        HorizontalAlignment="Right"
                                        Click="ButtonCancelEdit_OnClick"
                                        Style="{StaticResource ButtonPrimaryStyle}"
                                        Content="{DynamicResource Cancel}">
                                </Button>
                            </StackPanel>
                        </Grid>

                    </Grid>
                </Border>
            </Grid>
        </Border>
    </Border>
</UserControl>
