<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:avaloniaEdit="https://github.com/avaloniaui/avaloniaedit"
             xmlns:mdxaml="https://github.com/whistyun/Markdown.Avalonia.Tight"
             xmlns:fa="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
             xmlns:input="clr-namespace:System.Windows.Input;assembly=System.ObjectModel"
             xmlns:ui="clr-namespace:Artemis.UI"
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
             x:Class="Artemis.UI.Controls.SplitMarkdownEditor">
    <UserControl.Resources>
        <ui:ArtemisLinkCommand x:Key="ArtemisLinkCommand" />
    </UserControl.Resources>
    <Grid RowDefinitions="Auto,*">
        <Grid Row="0" ColumnDefinitions="Auto,*">
            <Label Grid.Column="0" Name="DescriptionEditorLabel" Target="DescriptionEditor" Margin="0 28 0 0" />
            <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
                <CheckBox Name="SynchronizedScrolling" IsChecked="True" VerticalAlignment="Bottom">Synchronized scrolling</CheckBox>
                <HyperlinkButton
                    Margin="0 0 0 -20"
                    Content="Markdown supported"
                    NavigateUri="https://wiki.artemis-rgb.com/guides/user/markdown?mtm_campaign=artemis&amp;mtm_kwd=markdown-editor"
                    HorizontalAlignment="Right" />
            </StackPanel>
        </Grid>

        <Grid Grid.Row="1" Grid.Column="0" ColumnDefinitions="*,Auto,*">
            <Border Grid.Column="0" BorderThickness="1"
                    BorderBrush="{DynamicResource TextControlBorderBrush}"
                    CornerRadius="{DynamicResource ControlCornerRadius}"
                    Background="{DynamicResource TextControlBackground}"
                    Padding="{DynamicResource TextControlThemePadding}">
                <avaloniaEdit:TextEditor
                    FontFamily="{StaticResource RobotoMono}"
                    FontSize="13"
                    Name="DescriptionEditor"
                    TextChanged="DescriptionEditor_OnTextChanged"
                    WordWrap="True" />
            </Border>

            <GridSplitter Grid.Column="1" Margin="5 0"></GridSplitter>
            <Border Grid.Column="2" Classes="card-condensed">
                <mdxaml:MarkdownScrollViewer Margin="5 0"
                                             Name="DescriptionPreview"
                                             Markdown="{CompiledBinding Document.Text, Mode=OneWay, ElementName=DescriptionEditor}"
                                             MarkdownStyleName="FluentAvalonia"
                                             SaveScrollValueWhenContentUpdated="True">
                    <mdxaml:MarkdownScrollViewer.Engine>
                        <mdxaml:Markdown HyperlinkCommand="{StaticResource ArtemisLinkCommand}" />
                    </mdxaml:MarkdownScrollViewer.Engine>
                    <mdxaml:MarkdownScrollViewer.Styles>
                        <StyleInclude Source="/Styles/Markdown.axaml" />
                    </mdxaml:MarkdownScrollViewer.Styles>
                </mdxaml:MarkdownScrollViewer>
            </Border>
        </Grid>
    </Grid>
</UserControl>