<views:PopoverViewBase
    x:Class="CharacterMap.Views.PrintView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="using:CharacterMap.Controls"
    xmlns:core="using:CharacterMap.Core"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:h="using:CharacterMap.Helpers"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:models="using:CharacterMap.Models"
    xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
    xmlns:toolkit="using:Microsoft.Toolkit.Uwp.UI.Controls"
    xmlns:views="using:CharacterMap.Views"
    Background="Transparent"
    TabFocusNavigation="Cycle"
    mc:Ignorable="d"
    d:DesignHeight="1064"
    d:DesignWidth="1280">

    <UserControl.Resources>

        <Thickness x:Key="HeaderMargin">0,16,0,0</Thickness>

        <Style TargetType="RadioButton">
            <Setter Property="MinWidth" Value="200" />
        </Style>

        <Style BasedOn="{StaticResource DefaultThemeComboBoxStyle}" TargetType="controls:UXComboBox">
            <Setter Property="MinWidth" Value="168" />
            <Setter Property="HeaderTemplate" Value="{StaticResource DefaultControlHeaderTemplate}" />
        </Style>



    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        <controls:ModalPagePresenter
            x:Name="Presenter"
            Title="{core:Localizer Key=PrintViewTitle/Text}"
            CloseClicked="{x:Bind Hide}"
            TitleBarHeight="{x:Bind TitleBarHeight, Mode=OneWay}"
            d:TitleBarHeight="32">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="8" />
                </Grid.RowDefinitions>

                <Grid
                    x:Name="ContentPanel"
                    Grid.Row="0"
                    ColumnSpacing="24"
                    CornerRadius="8 8 0 0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="0.8*" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <!--  Requires it's own element to enable theme shadows  -->
                    <Border x:Name="ContentBackground" Grid.ColumnSpan="2" />

                    <!--  Options Scroller  -->
                    <ScrollViewer x:Name="ContentScroller">
                        <StackPanel
                            x:Name="OptionsPanel"
                            Margin="20 20 20 120"
                            ChildrenTransitions="{x:Bind GetRepositionCollection(ViewModel.AllowAnimation), Mode=OneWay}">

                            <controls:ContentGroup x:Uid="PrintDataHeader" d:Text="{core:Localizer Key=PrintDataHeader/Text}">
                                <Button Margin="0 2 0 8" Style="{StaticResource ThemeTextBlockButtonStyle}">
                                    <Button.Content>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock
                                                x:Uid="PrintCharacterFilterContent"
                                                OpticalMarginAlignment="TrimSideBearings"
                                                d:Text="{core:Localizer Key=PrintCharacterFilterContent/Text}" />
                                            <TextBlock
                                                Margin="4 2 0 0"
                                                VerticalAlignment="Center"
                                                FontFamily="{ThemeResource SymbolThemeFontFamily}"
                                                FontSize="12"
                                                IsTextScaleFactorEnabled="False"
                                                Text="&#xE70D;"
                                                TextLineBounds="Tight" />
                                        </StackPanel>
                                    </Button.Content>
                                    <Button.Flyout>
                                        <Flyout
                                            x:Name="CatFlyout"
                                            core:Properties.UseExpandContractAnimation="True"
                                            FlyoutPresenterStyle="{StaticResource ThemeFlyoutStyle}"
                                            Opened="{x:Bind CatFlyoutContent.OnOpening}">
                                            <controls:CategoryFlyout
                                                x:Name="CatFlyoutContent"
                                                AcceptClicked="CategoryFlyout_AcceptClicked"
                                                Flyout="{x:Bind CatFlyout}"
                                                SourceCategories="{x:Bind ViewModel.Categories, Mode=OneWay}" />
                                        </Flyout>
                                    </Button.Flyout>
                                </Button>
                                <CheckBox
                                    x:Uid="ChkBxHideWhitespace"
                                    IsChecked="{x:Bind ViewModel.HideWhitespace, Mode=TwoWay}"
                                    Style="{StaticResource DefaultThemeCheckBoxStyle}"
                                    d:Content="{core:Localizer Key=ChkBxHideWhitespace/Content}" />
                            </controls:ContentGroup>

                            <controls:ContentGroup x:Uid="PrintViewLayoutHeader" d:Text="{core:Localizer Key=PrintViewLayoutHeader/Text}">
                                <TextBlock
                                    x:Uid="PrintViewCharSize"
                                    Style="{StaticResource HeaderStyle}"
                                    d:Text="{core:Localizer Key=PrintViewCharSize/Text}" />
                                <Slider
                                    HorizontalAlignment="Stretch"
                                    IsThumbToolTipEnabled="True"
                                    Maximum="224"
                                    Minimum="64"
                                    StepFrequency="2"
                                    TickFrequency="4"
                                    TickPlacement="Outside"
                                    Value="{x:Bind ViewModel.GlyphSize, Mode=TwoWay}"
                                    d:Value="124" />
                                <TextBlock Style="{StaticResource BaseTextStyle}">
                                    <Run Text="{x:Bind ViewModel.GlyphSize, Mode=OneWay}" d:Text="124" />
                                    <Run x:Uid="PixelUnits" d:Text="{core:Localizer Key=PixelUnits/Text}" />
                                </TextBlock>

                                <!--<TextBlock Style="{StaticResource HeaderStyle}" Text="Borders" />-->
                                <CheckBox
                                    x:Uid="ChkBxShowBorders"
                                    Margin="0 16 0 -12"
                                    IsChecked="{x:Bind ViewModel.ShowBorders, Mode=TwoWay}"
                                    Style="{StaticResource DefaultThemeCheckBoxStyle}"
                                    d:Content="{core:Localizer Key=ChkBxShowBorders/Content}" />


                                <toolkit:WrapPanel
                                    Margin="{StaticResource HeaderMargin}"
                                    ChildrenTransitions="{x:Bind GetRepositionCollection(ViewModel.AllowAnimation), Mode=OneWay}"
                                    HorizontalSpacing="24">
                                    <controls:UXComboBox
                                        x:Uid="CbListStyle"
                                        ItemsSource="{x:Bind Layouts}"
                                        SelectedIndex="0"
                                        SelectedItem="{x:Bind ViewModel.Layout, Mode=TwoWay}"
                                        d:Header="{core:Localizer Key=CbListStyle/Header}"
                                        d:PlaceholderText="{core:Localizer Key=PrintLayout_Grid}">
                                        <ComboBox.ItemTemplate>
                                            <DataTemplate x:DataType="models:PrintLayout">
                                                <TextBlock Text="{x:Bind core:Converters.GetLocalizedEnumName((models:PrintLayout))}" />
                                            </DataTemplate>
                                        </ComboBox.ItemTemplate>
                                    </controls:UXComboBox>

                                    <controls:UXComboBox
                                        x:Uid="CbCharacterLabel"
                                        ItemsSource="{x:Bind Annotations}"
                                        SelectedItem="{x:Bind ViewModel.Annotation, Mode=TwoWay}"
                                        d:Header="{core:Localizer Key=CbCharacterLabel/Header}"
                                        d:PlaceholderText="{core:Localizer Key=GlyphAnnotation_None}">
                                        <ComboBox.ItemTemplate>
                                            <DataTemplate x:DataType="models:GlyphAnnotation">
                                                <TextBlock Text="{x:Bind core:Converters.GetLocalizedEnumName((models:GlyphAnnotation))}" />
                                            </DataTemplate>
                                        </ComboBox.ItemTemplate>
                                    </controls:UXComboBox>
                                </toolkit:WrapPanel>

                            </controls:ContentGroup>

                            <controls:ContentGroup x:Uid="PrintViewPageSetupHeader" d:Text="{core:Localizer Key=PrintViewPageSetupHeader/Text}">
                                <TextBlock
                                    x:Uid="PrintViewPageRange"
                                    Style="{StaticResource HeaderStyle}"
                                    d:Text="{core:Localizer Key=PrintViewPageRange/Text}" />
                                <TextBlock
                                    x:Uid="PrintViewPageRangeDesc"
                                    Margin="0 0 0 8"
                                    Style="{StaticResource BaseTextStyle}"
                                    d:Text="{core:Localizer Key=PrintViewPageRangeDesc/Text}" />
                                <toolkit:WrapPanel
                                    ChildrenTransitions="{x:Bind GetRepositionCollection(ViewModel.AllowAnimation), Mode=OneWay}"
                                    HorizontalSpacing="24"
                                    Orientation="Horizontal"
                                    VerticalSpacing="12">
                                    <muxc:NumberBox
                                        x:Uid="PrintViewPageSelector"
                                        HeaderTemplate="{StaticResource DefaultControlHeaderTemplate}"
                                        Maximum="{x:Bind PageCount, Mode=OneWay}"
                                        Minimum="1"
                                        SpinButtonPlacementMode="Inline"
                                        Value="{x:Bind ViewModel.FirstPage, Mode=TwoWay}"
                                        d:Header="{core:Localizer Key=PrintViewPageSelector/Header}"
                                        d:Value="1" />

                                    <muxc:NumberBox
                                        x:Uid="PrintViewPageRangeSelector"
                                        HeaderTemplate="{StaticResource DefaultControlHeaderTemplate}"
                                        Maximum="{x:Bind GetMaxPageRange(ViewModel.FirstPage, PageCount), Mode=OneWay}"
                                        Minimum="1"
                                        SpinButtonPlacementMode="Inline"
                                        Value="{x:Bind ViewModel.PagesToPrint, Mode=TwoWay}"
                                        d:Header="{core:Localizer Key=PrintViewPageRangeSelector/Header}"
                                        d:Maximum="10"
                                        d:Value="10" />
                                </toolkit:WrapPanel>

                                <TextBlock
                                    Style="{StaticResource HintStyle}"
                                    Text="{x:Bind GetPageRangeLabel(ViewModel.FirstPage, ViewModel.PagesToPrint), Mode=OneWay}"
                                    d:Text="Printing pages 1 - 10" />

                                <controls:UXComboBox
                                    x:Uid="PrintViewPageOrientation"
                                    Margin="{StaticResource HeaderMargin}"
                                    SelectedIndex="0"
                                    SelectionChanged="RadioButtons_SelectionChanged"
                                    d:Header="{core:Localizer Key=PrintViewPageOrientation/Header}">
                                    <controls:UXComboBoxItem x:Uid="CbiPageOrientationPortrait" d:Content="{core:Localizer Key=CbiPageOrientationPortrait/Content}" />
                                    <controls:UXComboBoxItem x:Uid="CbiPageOrientationLandscape" d:Content="{core:Localizer Key=CbiPageOrientationLandscape/Content}" />
                                </controls:UXComboBox>

                                <TextBlock
                                    x:Uid="PrintViewHorizontalMarginHeader"
                                    Margin="{StaticResource HeaderMargin}"
                                    Style="{StaticResource HeaderStyle}"
                                    d:Text="{core:Localizer Key=PrintViewHorizontalMarginHeader/Text}" />
                                <Slider
                                    HorizontalAlignment="Stretch"
                                    IsThumbToolTipEnabled="True"
                                    Maximum="84"
                                    Minimum="44"
                                    StepFrequency="2"
                                    TickFrequency="4"
                                    TickPlacement="Outside"
                                    Value="{x:Bind ViewModel.HorizontalMargin, Mode=TwoWay}" />
                                <TextBlock Style="{StaticResource BaseTextStyle}">
                                    <Run Text="{x:Bind ViewModel.HorizontalMargin, Mode=OneWay}" d:Text="44" />
                                    <Run x:Uid="PixelUnits" d:Text="{core:Localizer Key=PixelUnits/Text}" />
                                </TextBlock>

                                <TextBlock
                                    x:Uid="PrintViewVerticalMarginHeader"
                                    Margin="{StaticResource HeaderMargin}"
                                    Style="{StaticResource HeaderStyle}"
                                    d:Text="{core:Localizer Key=PrintViewVerticalMarginHeader/Text}" />
                                <Slider
                                    HorizontalAlignment="Stretch"
                                    IsThumbToolTipEnabled="True"
                                    Maximum="84"
                                    Minimum="44"
                                    StepFrequency="2"
                                    TickFrequency="4"
                                    TickPlacement="Outside"
                                    Value="{x:Bind ViewModel.VerticalMargin, Mode=TwoWay}"
                                    d:Value="64" />
                                <TextBlock Style="{StaticResource BaseTextStyle}">
                                    <Run Text="{x:Bind ViewModel.VerticalMargin, Mode=OneWay}" d:Text="64" />
                                    <Run x:Uid="PixelUnits" d:Text="{core:Localizer Key=PixelUnits/Text}" />
                                </TextBlock>
                            </controls:ContentGroup>

                        </StackPanel>
                    </ScrollViewer>

                    <!--  Page Preview Container  -->
                    <Grid
                        Grid.Column="1"
                        Margin="12"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        core:Properties.UseStandardReposition="{x:Bind ViewModel.AllowAnimation, Mode=OneWay}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>

                        <StackPanel x:Name="PreviewOptions" Grid.Row="0">

                            <CheckBox
                                x:Uid="CbShowMargins"
                                HorizontalAlignment="Center"
                                IsChecked="{x:Bind ViewModel.ShowMargins, Mode=TwoWay}"
                                IsThreeState="False"
                                Style="{StaticResource DefaultThemeCheckBoxStyle}"
                                d:Content="{core:Localizer Key=CbShowMargins/Content}" />

                            <StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
                                <TextBlock
                                    x:Uid="PrintViewPreviewingLabel"
                                    VerticalAlignment="Center"
                                    Style="{StaticResource BaseTextStyle}"
                                    d:Text="{core:Localizer Key=PrintViewPreviewingLabel/Text}" />
                                <muxc:NumberBox
                                    Margin="8 0"
                                    LargeChange="1"
                                    Maximum="{x:Bind PageCount, Mode=OneWay}"
                                    Minimum="1"
                                    SmallChange="1"
                                    SpinButtonPlacementMode="Inline"
                                    Template="{StaticResource HorizontalNumberBoxTemplate}"
                                    ValueChanged="NumberBox_ValueChanged"
                                    Value="{x:Bind CurrentPage, Mode=TwoWay}"
                                    d:Value="1" />
                                <TextBlock VerticalAlignment="Center">
                                    <Run x:Uid="PrintViewOfLabel" d:Text="{core:Localizer Key=PrintViewOfLabel/Text}" />
                                    <Run Text="{x:Bind PageCount, Mode=OneWay}" d:Text="10" />
                                </TextBlock>
                            </StackPanel>

                            <TextBlock
                                x:Uid="PrintViewPreviewOutOfBoundsLabel"
                                Margin="0 4 0 0"
                                HorizontalAlignment="Center"
                                Style="{StaticResource HintStyle}"
                                TextAlignment="Center"
                                Visibility="{x:Bind IsOutOfRange(ViewModel.FirstPage, ViewModel.PagesToPrint, CurrentPage), Mode=OneWay}"
                                d:Text="{core:Localizer Key=PrintViewPreviewOutOfBoundsLabel/Text}" />

                        </StackPanel>

                        <Viewbox
                            x:Name="PreviewViewBox"
                            Grid.Row="1"
                            Margin="12"
                            HorizontalAlignment="Center"
                            IsHitTestVisible="False"
                            Stretch="Uniform" />

                    </Grid>
                </Grid>

                <Grid
                    x:Name="BottomBar"
                    Grid.Row="1"
                    Background="{StaticResource AltHostBrush}">

                    <TextBlock
                        x:Name="BottomLabel"
                        Margin="12 0"
                        VerticalAlignment="Center"
                        FontSize="12"
                        TextLineBounds="Tight">
                        <Run Text="{x:Bind GetPageRangeLabel(ViewModel.FirstPage, ViewModel.PagesToPrint), Mode=OneWay}" d:Text="Printing page 1 of 10" />
                    </TextBlock>

                    <StackPanel
                        x:Name="BottomButtonOptions"
                        Margin="8"
                        HorizontalAlignment="Right"
                        Orientation="Horizontal"
                        Spacing="8">
                        <Button
                            x:Name="BtnContinue"
                            x:Uid="BtnContinue"
                            Width="150"
                            h:FluentAnimation.PointerOver="ContentPresenter.Content"
                            h:FluentAnimation.PointerOverOffset="-2"
                            h:FluentAnimation.Pressed="ContentPresenter"
                            Click="BtnContinue_Click"
                            IsEnabled="{x:Bind CanContinue, Mode=OneWay}"
                            Style="{StaticResource AccentButtonStyle}"
                            d:Content="{core:Localizer Key=BtnContinue/Content}" />
                        <Button
                            Width="150"
                            Click="{x:Bind Hide}"
                            Style="{StaticResource DefaultThemeButtonStyle}"
                            Content="{core:Localizer Key=Cancel}" />
                    </StackPanel>
                </Grid>
            </Grid>
        </controls:ModalPagePresenter>

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="ThemeStates">
                <VisualState x:Name="ClassicThemeState">
                    <VisualState.Setters>
                        <Setter Target="BottomBar.Background" Value="Transparent" />
                        <Setter Target="Presenter.Margin" Value="0 0 0 -6" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</views:PopoverViewBase>
