<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="using:MarkdownEditor.ViewModels"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:views="using:MarkdownEditor.Views"
        xmlns:ae="using:AvaloniaEdit"
        xmlns:i="https://github.com/projektanker/icons.avalonia"
        mc:Ignorable="d" d:DesignWidth="1200" d:DesignHeight="800"
        x:Class="MarkdownEditor.Views.MainWindow"
        x:DataType="vm:MainWindowViewModel"
        Icon="/Assets/markus-logo.png"
        Title="Markus - A Simple Markdown Editor"
        Width="1200" Height="800">

    <Design.DataContext>
        <vm:MainWindowViewModel/>
    </Design.DataContext>

    <Window.KeyBindings>
        <KeyBinding Gesture="Cmd+O" Command="{Binding OpenFileCommand}"/>
        <KeyBinding Gesture="Cmd+S" Command="{Binding SaveFileCommand}"/>
        <KeyBinding Gesture="Cmd+Shift+S" Command="{Binding SaveFileAsCommand}"/>
        <KeyBinding Gesture="Cmd+T" Command="{Binding AddNewTabCommand}"/>
    </Window.KeyBindings>

    <NativeMenu.Menu>
        <NativeMenu>
            <NativeMenuItem Header="_File">
                <NativeMenu>
                    <NativeMenuItem Header="_New Tab" Command="{Binding AddNewTabCommand}" Gesture="Cmd+T"/>
                    <NativeMenuItem Header="_Open..." Command="{Binding OpenFileCommand}" Gesture="Cmd+O"/>
                    <NativeMenuItemSeparator/>
                    <NativeMenuItem Header="_Save" Command="{Binding SaveFileCommand}" Gesture="Cmd+S"/>
                    <NativeMenuItem Header="Save _As..." Command="{Binding SaveFileAsCommand}" Gesture="Cmd+Shift+S"/>
                    <NativeMenuItemSeparator/>
                    <NativeMenuItem Header="Export to PDF..." Command="{Binding ExportToPdfCommand}" Gesture="Cmd+E"/>
                </NativeMenu>
            </NativeMenuItem>
            <NativeMenuItem Header="_Edit">
                <NativeMenu>
                    <NativeMenuItem Header="Cu_t" Gesture="Cmd+X"/>
                    <NativeMenuItem Header="_Copy" Gesture="Cmd+C"/>
                    <NativeMenuItem Header="_Paste" Gesture="Cmd+V"/>
                    <NativeMenuItemSeparator/>
                    <NativeMenuItem Header="Select _All" Gesture="Cmd+A"/>
                </NativeMenu>
            </NativeMenuItem>
            <NativeMenuItem Header="_View">
                <NativeMenu>
                    <NativeMenuItem Header="Toggle Raw/Pretty" Gesture="Cmd+E"/>
                </NativeMenu>
            </NativeMenuItem>
        </NativeMenu>
    </NativeMenu.Menu>

    <DockPanel Background="{Binding BackgroundColor}">

        <!-- Tab control with custom tab strip -->
        <TabControl ItemsSource="{Binding Tabs}"
                   SelectedItem="{Binding SelectedTab}"
                   Margin="0"
                   x:Name="MainTabControl">
            <TabControl.Styles>
                <!-- Sparkle animation for Pretty mode -->
                <Style Selector="Button.active i|Icon#SparkleIcon">
                    <Style.Animations>
                        <Animation Duration="0:0:0.33" FillMode="Forward">
                            <KeyFrame Cue="0%">
                                <Setter Property="Opacity" Value="0"/>
                            </KeyFrame>
                            <KeyFrame Cue="100%">
                                <Setter Property="Opacity" Value="1"/>
                            </KeyFrame>
                        </Animation>
                    </Style.Animations>
                </Style>

                <!-- Modern toolbar button style -->
                <Style Selector="Button.toolbar-btn">
                    <Setter Property="Background" Value="Transparent"/>
                    <Setter Property="Foreground" Value="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).ForegroundColor}"/>
                    <Setter Property="BorderThickness" Value="0"/>
                    <Setter Property="Padding" Value="8,4"/>
                    <Setter Property="Margin" Value="0"/>
                    <Setter Property="CornerRadius" Value="4"/>
                    <Setter Property="FontSize" Value="13"/>
                </Style>
                
                <!-- Compact tab styling -->
                <Style Selector="TabItem">
                    <Setter Property="FontSize" Value="13"/>
                    <Setter Property="Padding" Value="10,4"/>
                    <Setter Property="MinHeight" Value="30"/>
                    <Setter Property="Foreground" Value="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).ForegroundColor}"/>
                </Style>
                
                <Style Selector="TabControl">
                    <Setter Property="Template">
                        <ControlTemplate>
                            <DockPanel>
                                <!-- Custom tab strip with logo, tabs, and controls -->
                                <Grid DockPanel.Dock="Top" Background="{Binding SecondaryBackgroundColor}">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>

                                    <!-- Left: Logo -->
                                    <Image Grid.Column="0"
                                          Source="/Assets/markus-logo.png"
                                          Width="28" Height="28"
                                          Margin="8,2,8,2"
                                          VerticalAlignment="Center"
                                          ToolTip.Tip="Markus - A Simple Markdown Editor"/>

                                    <!-- Center: Tabs with scrolling -->
                                    <StackPanel Grid.Column="1" Orientation="Horizontal">
                                        <ItemsPresenter Name="PART_ItemsPresenter"
                                                       ItemsPanel="{TemplateBinding ItemsPanel}"/>
                                        <Button Content="+"
                                               Command="{Binding AddNewTabCommand}"
                                               Padding="8,2"
                                               Margin="2,0,0,0"
                                               VerticalAlignment="Center"
                                               Background="Transparent"
                                               Foreground="{Binding ForegroundColor}"
                                               FontSize="14"
                                               ToolTip.Tip="New Tab (Cmd+T)"/>
                                    </StackPanel>

                                    <!-- Right: Theme, Text Size, and Color controls -->
                                    <StackPanel Grid.Column="2" Orientation="Horizontal" Spacing="12" Margin="12,0,8,0">
                                        <!-- Theme toggle -->
                                        <Border BorderBrush="{Binding BorderColor}"
                                               BorderThickness="1"
                                               CornerRadius="4"
                                               Background="{Binding SecondaryBackgroundColor}">
                                            <StackPanel Orientation="Horizontal" Spacing="0">
                                                <!-- Light mode button -->
                                                <Button Command="{Binding ToggleThemeCommand}"
                                                       Padding="8,4"
                                                       CornerRadius="4,0,0,4"
                                                       BorderThickness="0"
                                                       Focusable="False"
                                                       ToolTip.Tip="Light Mode"
                                                       Classes.active="{Binding !IsDarkMode}">
                                                    <Button.Styles>
                                                        <Style Selector="Button">
                                                            <Setter Property="Background" Value="Transparent"/>
                                                            <Setter Property="Foreground" Value="{Binding SecondaryForegroundColor}"/>
                                                        </Style>
                                                        <Style Selector="Button.active">
                                                            <Setter Property="Background" Value="{Binding ActiveBackgroundColor}"/>
                                                            <Setter Property="Foreground" Value="{Binding ForegroundColor}"/>
                                                        </Style>
                                                    </Button.Styles>
                                                    <i:Icon Value="fa-solid fa-sun" FontSize="16"/>
                                                </Button>
                                                <!-- Dark mode button -->
                                                <Button Command="{Binding ToggleThemeCommand}"
                                                       Padding="8,4"
                                                       CornerRadius="0,4,4,0"
                                                       BorderThickness="0"
                                                       Focusable="False"
                                                       ToolTip.Tip="Dark Mode"
                                                       Classes.active="{Binding IsDarkMode}">
                                                    <Button.Styles>
                                                        <Style Selector="Button">
                                                            <Setter Property="Background" Value="Transparent"/>
                                                            <Setter Property="Foreground" Value="{Binding SecondaryForegroundColor}"/>
                                                        </Style>
                                                        <Style Selector="Button.active">
                                                            <Setter Property="Background" Value="{Binding ActiveBackgroundColor}"/>
                                                            <Setter Property="Foreground" Value="{Binding ForegroundColor}"/>
                                                        </Style>
                                                    </Button.Styles>
                                                    <i:Icon Value="fa-solid fa-moon" FontSize="16"/>
                                                </Button>
                                            </StackPanel>
                                        </Border>

                                        <!-- Text size toggle -->
                                        <Border BorderBrush="{Binding BorderColor}"
                                               BorderThickness="1"
                                               CornerRadius="4"
                                               Background="{Binding SecondaryBackgroundColor}">
                                            <StackPanel Orientation="Horizontal" Spacing="0">
                                                <Button Content="S"
                                                       Command="{Binding SetTextSizeSmallCommand}"
                                                       Padding="8,4"
                                                       CornerRadius="4,0,0,4"
                                                       BorderThickness="0"
                                                       Focusable="False"
                                                       FontSize="13"
                                                       ToolTip.Tip="Small Text"
                                                       Classes.active="{Binding TextSize, Converter={x:Static ObjectConverters.Equal}, ConverterParameter=Small}">
                                                    <Button.Styles>
                                                        <Style Selector="Button">
                                                            <Setter Property="Background" Value="Transparent"/>
                                                            <Setter Property="Foreground" Value="{Binding SecondaryForegroundColor}"/>
                                                        </Style>
                                                        <Style Selector="Button.active">
                                                            <Setter Property="Background" Value="{Binding ActiveBackgroundColor}"/>
                                                            <Setter Property="Foreground" Value="{Binding ForegroundColor}"/>
                                                        </Style>
                                                    </Button.Styles>
                                                </Button>
                                                <Button Content="M"
                                                       Command="{Binding SetTextSizeMediumCommand}"
                                                       Padding="8,4"
                                                       CornerRadius="0"
                                                       BorderThickness="0"
                                                       Focusable="False"
                                                       FontSize="13"
                                                       ToolTip.Tip="Medium Text"
                                                       Classes.active="{Binding TextSize, Converter={x:Static ObjectConverters.Equal}, ConverterParameter=Medium}">
                                                    <Button.Styles>
                                                        <Style Selector="Button">
                                                            <Setter Property="Background" Value="Transparent"/>
                                                            <Setter Property="Foreground" Value="{Binding SecondaryForegroundColor}"/>
                                                        </Style>
                                                        <Style Selector="Button.active">
                                                            <Setter Property="Background" Value="{Binding ActiveBackgroundColor}"/>
                                                            <Setter Property="Foreground" Value="{Binding ForegroundColor}"/>
                                                        </Style>
                                                    </Button.Styles>
                                                </Button>
                                                <Button Content="L"
                                                       Command="{Binding SetTextSizeLargeCommand}"
                                                       Padding="8,4"
                                                       CornerRadius="0,4,4,0"
                                                       BorderThickness="0"
                                                       Focusable="False"
                                                       FontSize="13"
                                                       ToolTip.Tip="Large Text"
                                                       Classes.active="{Binding TextSize, Converter={x:Static ObjectConverters.Equal}, ConverterParameter=Large}">
                                                    <Button.Styles>
                                                        <Style Selector="Button">
                                                            <Setter Property="Background" Value="Transparent"/>
                                                            <Setter Property="Foreground" Value="{Binding SecondaryForegroundColor}"/>
                                                        </Style>
                                                        <Style Selector="Button.active">
                                                            <Setter Property="Background" Value="{Binding ActiveBackgroundColor}"/>
                                                            <Setter Property="Foreground" Value="{Binding ForegroundColor}"/>
                                                        </Style>
                                                    </Button.Styles>
                                                </Button>
                                            </StackPanel>
                                        </Border>

                                        <!-- Color picker (fake for now) -->
                                        <Button Padding="8,4"
                                               CornerRadius="4"
                                               BorderThickness="1"
                                               BorderBrush="{Binding BorderColor}"
                                               Background="{Binding SecondaryBackgroundColor}"
                                               Focusable="False"
                                               ToolTip.Tip="Theme Color">
                                            <Border Width="16" Height="16"
                                                   CornerRadius="2"
                                                   Background="#007ACC"/>
                                        </Button>
                                    </StackPanel>
                                </Grid>
                                <ContentPresenter Name="PART_SelectedContentHost"
                                                 Content="{TemplateBinding SelectedContent}"
                                                 ContentTemplate="{TemplateBinding SelectedContentTemplate}"
                                                 Margin="{TemplateBinding Padding}"/>
                            </DockPanel>
                        </ControlTemplate>
                    </Setter>
                </Style>
            </TabControl.Styles>

            <TabControl.ItemTemplate>
                <DataTemplate DataType="vm:MarkdownTabViewModel">
                    <StackPanel Orientation="Horizontal" Spacing="6">
                        <TextBlock Text="{Binding DisplayTitle}"
                                  VerticalAlignment="Center"
                                  FontSize="13"
                                  Foreground="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).ForegroundColor}"/>
                        <Button Content="×"
                               Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).CloseTabCommand}"
                               CommandParameter="{Binding}"
                               Padding="3,0"
                               FontSize="15"
                               Background="Transparent"
                               BorderThickness="0"
                               Foreground="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).ForegroundColor}"
                               ToolTip.Tip="Close Tab"/>
                    </StackPanel>
                </DataTemplate>
            </TabControl.ItemTemplate>

            <TabControl.ContentTemplate>
                <DataTemplate DataType="vm:MarkdownTabViewModel">
                    <DockPanel>
                        <!-- View mode toggle and file actions -->
                        <Border DockPanel.Dock="Top"
                               Background="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).TertiaryBackgroundColor}"
                               BorderBrush="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).BorderColor}"
                               BorderThickness="0,0,0,1"
                               Padding="8,4">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>

                                <!-- Left side: View toggle and file actions -->
                                <StackPanel Grid.Column="0" Orientation="Horizontal" Spacing="8">
                                    <!-- Raw/Pretty toggle -->
                                    <Border BorderBrush="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).BorderColor}"
                                           BorderThickness="1"
                                           CornerRadius="4"
                                           Background="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).SecondaryBackgroundColor}">
                                        <StackPanel Orientation="Horizontal" Spacing="0">
                                            <!-- Raw button -->
                                            <Button Command="{Binding SetRawViewCommand}"
                                                   Padding="8,4"
                                                   CornerRadius="4,0,0,4"
                                                   BorderThickness="0"
                                                   FontSize="13"
                                                   Focusable="False"
                                                   Classes.active="{Binding !IsPrettyView}">
                                                <Button.Styles>
                                                    <Style Selector="Button">
                                                        <Setter Property="Background" Value="Transparent"/>
                                                        <Setter Property="Foreground" Value="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).SecondaryForegroundColor}"/>
                                                    </Style>
                                                    <Style Selector="Button.active">
                                                        <Setter Property="Background" Value="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).ActiveBackgroundColor}"/>
                                                        <Setter Property="Foreground" Value="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).ForegroundColor}"/>
                                                    </Style>
                                                    <Style Selector="Button:pointerover /template/ ContentPresenter">
                                                        <Setter Property="Background" Value="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).HoverBackgroundColor}"/>
                                                    </Style>
                                                    <Style Selector="Button.active:pointerover /template/ ContentPresenter">
                                                        <Setter Property="Background" Value="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).ActiveBackgroundColor}"/>
                                                    </Style>
                                                </Button.Styles>
                                                <TextBlock Text="Raw"/>
                                            </Button>

                                            <!-- Pretty button -->
                                            <Button Command="{Binding SetPrettyViewCommand}"
                                                   Padding="8,4"
                                                   CornerRadius="0,4,4,0"
                                                   BorderThickness="0"
                                                   FontSize="13"
                                                   Focusable="False"
                                                   Classes.active="{Binding IsPrettyView}">
                                                <Button.Styles>
                                                    <Style Selector="Button">
                                                        <Setter Property="Background" Value="Transparent"/>
                                                        <Setter Property="Foreground" Value="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).SecondaryForegroundColor}"/>
                                                    </Style>
                                                    <Style Selector="Button.active">
                                                        <Setter Property="Background" Value="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).ActiveBackgroundColor}"/>
                                                        <Setter Property="Foreground" Value="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).ForegroundColor}"/>
                                                    </Style>
                                                    <Style Selector="Button:pointerover /template/ ContentPresenter">
                                                        <Setter Property="Background" Value="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).HoverBackgroundColor}"/>
                                                    </Style>
                                                    <Style Selector="Button.active:pointerover /template/ ContentPresenter">
                                                        <Setter Property="Background" Value="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).ActiveBackgroundColor}"/>
                                                    </Style>
                                                </Button.Styles>
                                                <StackPanel Orientation="Horizontal" Spacing="4">
                                                    <TextBlock Text="Pretty" VerticalAlignment="Center"/>
                                                    <i:Icon x:Name="SparkleIcon"
                                                           Value="fa-solid fa-wand-magic-sparkles"
                                                           VerticalAlignment="Center"
                                                           Opacity="0"
                                                           FontSize="14"/>
                                                </StackPanel>
                                            </Button>
                                        </StackPanel>
                                    </Border>

                                    <!-- File action buttons -->
                                    <Button Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).OpenFileCommand}"
                                           Classes="toolbar-btn"
                                           ToolTip.Tip="Open File (Cmd+O)"
                                           Focusable="False">
                                        <i:Icon Value="fa-solid fa-folder-open" FontSize="16"/>
                                    </Button>
                                    <Button Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).SaveFileCommand}"
                                           Classes="toolbar-btn"
                                           ToolTip.Tip="Save File (Cmd+S)"
                                           Focusable="False">
                                        <i:Icon Value="fa-solid fa-floppy-disk" FontSize="16"/>
                                    </Button>
                                    <Button Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).ExportToPdfCommand}"
                                           Classes="toolbar-btn"
                                           ToolTip.Tip="Export to PDF (Cmd+E)"
                                           Focusable="False">
                                        <i:Icon Value="fa-solid fa-file-pdf" FontSize="16"/>
                                    </Button>
                                </StackPanel>
                            </Grid>
                        </Border>

                        <!-- Formatting toolbar -->
                        <Border DockPanel.Dock="Top"
                               Background="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).SecondaryBackgroundColor}"
                               BorderBrush="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).BorderColor}"
                               BorderThickness="0,0,0,1"
                               Padding="8,4"
                               IsVisible="{Binding !IsPrettyView}">
                            <WrapPanel>
                                <Button Content="B" Command="{Binding FormatBoldCommand}"
                                       Classes="toolbar-btn" FontWeight="Bold" ToolTip.Tip="Bold (Cmd+B)"
                                       Focusable="False"/>
                                <Button Content="I" Command="{Binding FormatItalicCommand}"
                                       Classes="toolbar-btn" FontStyle="Italic" ToolTip.Tip="Italic (Cmd+I)"
                                       Focusable="False"/>
                                <Separator Width="1" Height="20" Margin="4,0" Background="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).BorderColor}"/>
                                <Button Content="H1" Command="{Binding FormatHeading1Command}"
                                       Classes="toolbar-btn" FontWeight="SemiBold" ToolTip.Tip="Heading 1"
                                       Focusable="False"/>
                                <Button Content="H2" Command="{Binding FormatHeading2Command}"
                                       Classes="toolbar-btn" FontWeight="SemiBold" ToolTip.Tip="Heading 2"
                                       Focusable="False"/>
                                <Button Content="H3" Command="{Binding FormatHeading3Command}"
                                       Classes="toolbar-btn" FontWeight="SemiBold" ToolTip.Tip="Heading 3"
                                       Focusable="False"/>
                                <Separator Width="1" Height="20" Margin="4,0" Background="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).BorderColor}"/>
                                <Button Content="• List" Command="{Binding FormatBulletListCommand}"
                                       Classes="toolbar-btn" ToolTip.Tip="Bullet List"
                                       Focusable="False"/>
                                <Button Content="1. List" Command="{Binding FormatNumberedListCommand}"
                                       Classes="toolbar-btn" ToolTip.Tip="Numbered List"
                                       Focusable="False"/>
                                <Separator Width="1" Height="20" Margin="4,0" Background="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).BorderColor}"/>
                                <Button Content="&lt;/&gt;" Command="{Binding FormatCodeCommand}"
                                       Classes="toolbar-btn" FontFamily="Consolas,Courier New,monospace" ToolTip.Tip="Inline Code"
                                       Focusable="False"/>
                                <Button Content="{}{  }" Command="{Binding FormatCodeBlockCommand}"
                                       Classes="toolbar-btn" FontFamily="Consolas,Courier New,monospace" ToolTip.Tip="Code Block"
                                       Focusable="False"/>
                                <Button Content="&quot;" Command="{Binding FormatQuoteCommand}"
                                       Classes="toolbar-btn" ToolTip.Tip="Quote"
                                       Focusable="False"/>
                                <Separator Width="1" Height="20" Margin="4,0" Background="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).BorderColor}"/>
                                <Button Content="🔗" Click="OnInsertHyperlink"
                                       Classes="toolbar-btn" ToolTip.Tip="Insert Link"
                                       Focusable="False"
                                       Tag="{Binding}"/>
                                <Button Content="🖼" Click="OnInsertImage"
                                       Classes="toolbar-btn" ToolTip.Tip="Insert Image"
                                       Focusable="False"
                                       Tag="{Binding}"/>
                            </WrapPanel>
                        </Border>

                        <!-- Content area - fills remaining DockPanel space -->
                        <Grid>
                            <!-- Raw editor view with AvaloniaEdit -->
                            <ae:TextEditor x:Name="EditorTextBox"
                                          views:TextEditorHelper.Document="{Binding Document}"
                                          FontFamily="Consolas,Courier New,monospace"
                                          FontSize="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).EditorFontSize}"
                                          ShowLineNumbers="True"
                                          IsVisible="{Binding !IsPrettyView}"
                                          Background="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).BackgroundColor}"
                                          Foreground="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).ForegroundColor}"
                                          LineNumbersForeground="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).LineNumberColor}"
                                          HorizontalScrollBarVisibility="Auto"
                                          VerticalScrollBarVisibility="Auto"/>

                            <!-- Pretty markdown viewer -->
                            <views:MarkdownViewer Markdown="{Binding SafeMarkdownContent}"
                                                 IsVisible="{Binding IsPrettyView}"
                                                 FontSize="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).ContentFontSize}"
                                                 Foreground="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).ForegroundColor}"
                                                 Background="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).BackgroundColor}"/>
                        </Grid>
                    </DockPanel>
                </DataTemplate>
            </TabControl.ContentTemplate>
        </TabControl>
    </DockPanel>
</Window>
