<common:LayoutAwarePage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:RichTextBoxShare"
    xmlns:common="using:RichTextBoxShare.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:c1RTB="using:C1.Xaml.RichTextBox"
    x:Name="pageRoot"
    x:Class="RichTextBoxShare.MainPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Mode=Self}}"
    mc:Ignorable="d">

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled" />

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="rtb">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Thickness>50</Thickness>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="bottomAppBar" Storyboard.TargetProperty="(FrameworkElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0" >
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Grid.Column="1" Text="{StaticResource AppName}" Style="{StaticResource PageHeaderTextStyle}"/>
        </Grid>

        <c1RTB:C1RichTextBox x:Name="rtb" Grid.Row="1" Margin="116 0 100 100" Padding="5" GotFocus="rtb_GotFocus"/>
    </Grid>
    <Page.BottomAppBar>
        <AppBar x:Name="bottomAppBar" IsSticky="True" Padding="10,0,10,0" Background="{ThemeResource ButtonBackgroundThemeBrush}" >
            <Grid>
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                    <Button x:Name="btnInsertTable" Style="{StaticResource TableAppBarButtonStyle}" Click="btnInsertTable_Click">
                        <TextBlock Text="&#x25A6;" FontSize="26" FontWeight="Light" Margin="-1 -2 0 0"/>
                    </Button>
                    <Button x:Name="btnInsertImage" Style="{StaticResource PictureAppBarButtonStyle}" Click="btnInsertPicture_Click" />
                    <Button x:Name="btnInsertHyperlink" Style="{StaticResource HyperlinkAppBarButtonStyle}" Click="btnInsertHyperlink_Click"/>
                    <Line X1="0" Y1="60" Margin="0,10,0,0" Stroke="{ThemeResource ApplicationForegroundThemeBrush}" StrokeThickness="2" />
                    <Button x:Name="btnSelectAll" Style="{StaticResource SelectAllAppBarButtonStyle}" Click="btnSelectAll_Click" />
                    <Button x:Name="btnAlign" Style="{StaticResource AlignAppBarButtonStyle}" Click="btnAlign_Click"/>

                </StackPanel>
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                    <c1RTB:C1BoldTool x:Name="btnBold" Style="{StaticResource BoldAppBarButtonStyle}" />
                    <c1RTB:C1ItalicTool x:Name="btnItalic" Style="{StaticResource ItalicAppBarButtonStyle}" />
                    <c1RTB:C1UnderlineTool x:Name="btnUnderline" Style="{StaticResource UnderlineAppBarButtonStyle}" />
                    <Button x:Name="btnFontColor" Style="{StaticResource FontColorAppBarButtonStyle}" Click="btnFontColor_Click"/>
                    <Button x:Name="btnHighlight" Style="{StaticResource HighlightAppBarButtonStyle}" Click="btnHighlight_Click"/>
                    <Button x:Name="btnMore" Style="{StaticResource MoreAppBarButtonStyle}" Click="btnMore_Click"/>
                </StackPanel>
            </Grid>
        </AppBar>
    </Page.BottomAppBar>
</common:LayoutAwarePage>
