<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. -->
<local:TestPage
    x:Class="MUXControlsTestApp.NumberBoxPage"
    x:Name="NumberBoxTestPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MUXControlsTestApp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:controls="http://schemas.modernwpf.com/2019"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:contract5Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <StackPanelEx Orientation="Vertical" contract5Present:Spacing="4" Background="{ThemeResource SystemControlBackgroundBaseLowBrush}" Padding="12">

            <ComboBoxEx x:Name="ValidationComboBox" AutomationProperties.Name="ValidationComboBox" Header="Validation Mode" SelectedIndex="0" SelectionChanged="Validation_Changed">
                <ComboBoxItem Content="InvalidInputOverwritten"/>
                <ComboBoxItem Content="Disabled"/>
            </ComboBoxEx>

            <ComboBoxEx x:Name="SpinModeComboBox" AutomationProperties.Name="SpinModeComboBox" SelectedIndex="0" SelectionChanged="SpinMode_Changed" Header="SpinButtonMode">
                <ComboBoxItem Content="Hidden"/>
                <ComboBoxItem Content="Compact"/>
                <ComboBoxItem Content="Inline"/>
            </ComboBoxEx>

            <ComboBoxEx x:Name="TextAlignmentComboBox" AutomationProperties.Name="TextAlignmentComboBox" Header="TextAlignment" SelectedIndex="0" SelectionChanged="TextAlignment_Changed">
                <ComboBoxItem Content="Left" />
                <ComboBoxItem Content="Center" />
                <ComboBoxItem Content="Right" />
            </ComboBoxEx>

            <ComboBoxEx x:Name="InputScopeComboBox" AutomationProperties.Name="InputScopeComboBox" Header="InputScope" SelectedIndex="0" SelectionChanged="InputScope_Changed">
                <ComboBoxItem Content="Number" />
                <ComboBoxItem Content="Default" />
                <ComboBoxItem Content="CurrencyAmountAndSymbol" />
                <ComboBoxItem Content="TelephoneNumber" />
                <ComboBoxItem Content="Formula" />
            </ComboBoxEx>

            <CheckBox x:Name="EnabledCheckBox" AutomationProperties.Name="EnabledCheckBox" IsChecked="True" Content="Enabled"/>

            <CheckBox x:Name="ExpressionCheckBox" AutomationProperties.Name="ExpressionCheckBox" IsChecked="False" Content="Accepts Expression"/>

            <CheckBox x:Name="WrapCheckBox" AutomationProperties.Name="WrapCheckBox" IsChecked="False" Content="Wrap Enabled"/>

            <!-- Set Text instead of Value to verify that it works -->
            <controls:NumberBox x:Name="SmallChangeNumberBox" AutomationProperties.Name="SmallChangeNumberBox" Text="1" Header="SmallChange"/>
            <controls:NumberBox x:Name="LargeChangeNumberBox" AutomationProperties.Name="LargeChangeNumberBox" Text="10" Header="LargeChange"/>

            <StackPanel Orientation="Horizontal">
                <CheckBox x:Name="MinCheckBox" AutomationProperties.Name="MinCheckBox" IsChecked="False" Checked="MinCheckBox_CheckChanged" Unchecked="MinCheckBox_CheckChanged" MinWidth="32" VerticalAlignment="Bottom"/>
                <controls:NumberBox x:Name="MinNumberBox" AutomationProperties.Name="MinNumberBox" Header="Minimum" Value="0" IsEnabled="False" ValueChanged="MinValueChanged"/>
            </StackPanel>

            <StackPanel Orientation="Horizontal">
                <CheckBox x:Name="MaxCheckBox" AutomationProperties.Name="MaxCheckBox" IsChecked="False" Checked="MaxCheckBox_CheckChanged" Unchecked="MaxCheckBox_CheckChanged" MinWidth="32" VerticalAlignment="Bottom"/>
                <!-- Verify that setting Value overrides setting Text -->
                <controls:NumberBox x:Name="MaxNumberBox" AutomationProperties.Name="MaxNumberBox" Header="Maximum" Value="100" Text="50" IsEnabled="False" ValueChanged="MaxValueChanged"/>
            </StackPanel>

            <Button x:Name="CustomFormatterButton" AutomationProperties.Name="CustomFormatterButton" Content="Custom Formatter" Click="CustomFormatterButton_Click" Margin="0,4,0,0"/>

            <Button x:Name="SetTextButton" AutomationProperties.Name="SetTextButton" Content="Set text to 15" Click="SetTextButton_Click" Margin="0,4,0,0"/>

            <Button x:Name="SetValueButton" AutomationProperties.Name="SetValueButton" Content="Set value to 42" Click="SetValueButton_Click" Margin="0,4,0,0"/>

            <Button x:Name="SetValueNaNButton" AutomationProperties.Name="SetValueNaNButton" Content="Set value to NaN" Click="SetNaNButton_Click" Margin="0,4,0,0"/>

            <Button x:Name="SetTwoWayBoundValueNaNButton" AutomationProperties.Name="SetTwoWayBoundValueNaNButton" Content="Set two way bound value to NaN" Click="SetTwoWayBoundNaNButton_Click" Margin="0,4,0,0"/>

            <Button x:Name="ToggleHeaderValueButton" AutomationProperties.Name="ToggleHeaderValueButton" Content="Toggle header for clipping issue" Click="ToggleHeaderValueButton_Click" Margin="0,4,0,0"/>

            <Button x:Name="ToggleHeaderTemplateValueButton" AutomationProperties.Name="ToggleHeaderTemplateValueButton" Content="Toggle header template" Click="ToggleHeaderTemplateValueButton_Click" Margin="0,4,0,0"/>

        </StackPanelEx>

        <Grid Grid.Column="1">

            <StackPanelEx HorizontalAlignment="Center" VerticalAlignment="Center"
                        Orientation="Vertical" contract5Present:Spacing="4">
                <!--Standard NumberBox test UI -->
                <StackPanel>
                    <controls:NumberBox
                        MinWidth="150"
                        x:Name="TestNumberBox"
                        Description="Description text"
                        Header="TestNumberBox"
                        PlaceholderText="Text"
                        ValueChanged="NumberBoxValueChanged"
                        SmallChange="{x:Bind SmallChangeNumberBox.Value, Mode=OneWay}"
                        LargeChange="{x:Bind LargeChangeNumberBox.Value, Mode=OneWay}"
                        AcceptsExpression="{x:Bind ExpressionCheckBox.IsChecked.Value, Mode=OneWay}"
                        IsWrapEnabled="{x:Bind WrapCheckBox.IsChecked.Value, Mode=OneWay}"
                        IsEnabled="{x:Bind EnabledCheckBox.IsChecked.Value, Mode=OneWay}"/>

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Value:" Margin="0,0,5,0" />
                        <TextBlock x:Name="NewValueTextBox" AutomationProperties.Name="NewValueTextBox" Text="0" />
                    </StackPanel>

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Old Value:" Margin="0,0,5,0" />
                        <TextBlock x:Name="OldValueTextBox" AutomationProperties.Name="OldValueTextBox"/>
                    </StackPanel>

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Text:" Margin="0,0,5,0" />
                        <TextBlock x:Name="TextTextBox" AutomationProperties.Name="TextTextBox" Text="0"/>
                    </StackPanel>
                </StackPanel>

                <!-- NumberBox for nested scrolling bug(s)-->
                <StackPanel Margin="30,0,0,0">
                    <TextBlock>NumberBox inside ScrollViewer test</TextBlock>
                    <ScrollViewerEx x:Name="ScrollviewerWithScroll" Height="50"
                                  Width="200"
                            ViewChanged="ScrollviewerWithScroll_ViewChanged">
                        <StackPanel>
                            <controls:NumberBox x:Name="NumberBoxInScroller"
                                    AutomationProperties.Name="NumberBoxInScroller"/>
                            <controls:NumberBox/>
                            <controls:NumberBox/>
                        </StackPanel>
                    </ScrollViewerEx>

                    <TextBlock x:Name="VerticalOffsetDisplayBlock" Text="0"
                            AutomationProperties.Name="VerticalOffsetDisplayBlock"/>
                </StackPanel>

                <!-- NumberBox two way binding with x:Bind -->
                <StackPanel>
                    <controls:NumberBox Header="TwoWayBinding" x:Name="TwoWayBoundNumberBox"
                              Value="{x:Bind DataModelWithINPC.Value, Mode=TwoWay}" />
                    <TextBlock x:Name="TwoWayBoundNumberBoxValue" AutomationProperties.Name="TwoWayBoundNumberBoxValue" />
                </StackPanel>

                <!-- Testing alignment with textbox and without specified header -->
                <StackPanel Orientation="Horizontal">
                    <TextBox MaxHeight="30" VerticalAlignment="Top"/>
                    <controls:NumberBox x:Name="HeaderTestingNumberBox" MaxHeight="32" VerticalAlignment="Top" PlaceholderText="I should not be clipped without header"/>
                    <controls:NumberBox x:Name="HeaderTestingNumberBoxTwo" MaxHeight="32" VerticalAlignment="Top">
                        <controls:NumberBox.HeaderTemplate>
                            <DataTemplate>
                                <TextBlock AutomationProperties.Name="HeaderTemplateBeforeApplayTemplateTest"  Text="MyText"/>
                            </DataTemplate>
                        </controls:NumberBox.HeaderTemplate>
                    </controls:NumberBox>
                    <controls:NumberBox>
                        <controls:NumberBox.Header>
                            <TextBlock AutomationProperties.Name="HeaderBeforeApplyTemplateTest" Text="TestNumberBox"/>
                        </controls:NumberBox.Header>
                    </controls:NumberBox>
                    <controls:NumberBox x:Name="HeaderTemplateTestingNumberBox"/>
                </StackPanel>

                <!-- FontSize propagation -->
                <controls:NumberBox Header="Header text" FontSize="50"/>

                <StackPanel Orientation="Horizontal" Height="50">
                    <controls:NumberBox PlaceholderText="Number"/>
                    <TextBoxEx PlaceholderText="Text"/>
                    <controls:AutoSuggestBox PlaceholderText="Auto"/>
                    <RichEditBox PlaceholderText="Rich" Style="{StaticResource DefaultRichTextBoxStyle}"/>
                </StackPanel>

                <!-- Property propagation -->
                <StackPanel Orientation="Horizontal">
                    <TextBoxEx Header="Header text" FontSize="14" Foreground="{ThemeResource SystemControlForegroundAccentBrush}"
                        Padding="20" Margin="20" BorderThickness="5" BorderBrush="Red"
                        Height="100" Width="200"/>
                    <controls:NumberBox Header="Header text" FontSize="14" Foreground="{ThemeResource SystemControlForegroundAccentBrush}" SpinButtonPlacementMode="Inline"
                        Padding="20" Margin="20" BorderThickness="5" BorderBrush="Red"
                        Height="100" Width="200"/>
                </StackPanel>
            </StackPanelEx>
        </Grid>

    </Grid>
</local:TestPage>
