<!--
    This Source Code Form is subject to the terms of the MIT License.
    If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
    Copyright (C) Leszek Pomianowski and WPF UI Contributors.
    All Rights Reserved.
    
    Based on Microsoft XAML for Win UI
    Copyright (c) Microsoft Corporation. All Rights Reserved.
-->

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib">

    <Thickness x:Key="DatePickerBorderThemeThickness">1,1,1,0</Thickness>
    <Thickness x:Key="DatePickerAccentBorderThemeThickness">0,0,0,1</Thickness>
    <Thickness x:Key="DatePickerLeftIconMargin">10,8,0,0</Thickness>
    <Thickness x:Key="DatePickerRightIconMargin">0,8,10,0</Thickness>
    <Thickness x:Key="DatePickerCalendarButtonMargin">0,5,4,0</Thickness>
    <Thickness x:Key="DatePickerCalendarButtonPadding">0,0,0,0</Thickness>
    <sys:Double x:Key="DatePickerCalendarButtonHeight">24</sys:Double>
    <sys:Double x:Key="DatePickerCalendarButtonIconSize">14</sys:Double>
    <sys:String x:Key="CalendarGlyph">&#xE787;</sys:String>

    <Style x:Key="DefaultDatePickerTextBoxStyle" TargetType="{x:Type DatePickerTextBox}">
        <Setter Property="FocusVisualStyle" Value="{DynamicResource DefaultControlFocusVisualStyle}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Stretch" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="AutomationProperties.Name" Value="{Binding Path=(AutomationProperties.Name), Mode=OneWay, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DatePicker}}}" />
        <Setter Property="Foreground" Value="{DynamicResource DatePickerTextBoxForeground}" />
        <Setter Property="CaretBrush" Value="{DynamicResource DatePickerTextBoxCaretBrush}" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DatePickerTextBox}">
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup Name="WatermarkStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0" />
                                </VisualStateGroup.Transitions>
                                <VisualState Name="Unwatermarked" />
                                <VisualState Name="Watermarked">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="PART_Watermark" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                        <Border Margin="{TemplateBinding Margin}">
                            <Decorator x:Name="PART_ContentHost" Margin="{TemplateBinding Padding}" />
                        </Border>
                        <Border Margin="{TemplateBinding Margin}">
                            <!-- This is a placeholder for DatePickerTextBox -->
                            <ContentControl 
                                x:Name="PART_Watermark"
                                Opacity="0"
                                Margin="{TemplateBinding Padding}"
                                Focusable="False"
                                IsHitTestVisible="False" />
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="DatePickerCalendarStyle" BasedOn="{StaticResource DefaultCalendarStyle}" TargetType="{x:Type Calendar}">
        <Setter Property="Background" Value="{DynamicResource DatePickerPopupBackground}" />
    </Style>

    <Style x:Key="DefaultDatePickerStyle" TargetType="{x:Type DatePicker}">
        <Setter Property="FocusVisualStyle" Value="{DynamicResource DefaultControlFocusVisualStyle}" />
        <Setter Property="ContextMenu" Value="{DynamicResource DefaultControlContextMenu}" />
        <Setter Property="CalendarStyle" Value="{DynamicResource DatePickerCalendarStyle}" />
        <Setter Property="Foreground" Value="{DynamicResource DatePickerForeground}" />
        <Setter Property="Background" Value="{DynamicResource DatePickerBackground}" />
        <Setter Property="BorderBrush" Value="{DynamicResource ControlElevationBorderBrush}" />
        <Setter Property="BorderThickness" Value="{StaticResource DatePickerBorderThemeThickness}" />
        <Setter Property="HorizontalAlignment" Value="Stretch" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Top" />
        <Setter Property="MinHeight" Value="{DynamicResource TextControlThemeMinHeight}" />
        <Setter Property="MinWidth" Value="{DynamicResource TextControlThemeMinWidth}" />
        <Setter Property="Padding" Value="{DynamicResource TextControlThemePadding}" />
        <Setter Property="Border.CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="KeyboardNavigation.TabNavigation" Value="Local" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DatePicker}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid Grid.Row="0">
                            <Border
                                x:Name="ContentBorder"
                                MinWidth="{TemplateBinding MinWidth}"
                                MinHeight="{TemplateBinding MinHeight}"
                                Padding="0"
                                HorizontalAlignment="Stretch"
                                VerticalAlignment="Stretch"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="{TemplateBinding Border.CornerRadius}">
                                <Grid x:Name="PART_Root" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <Grid Grid.Column="0">
                                        <DatePickerTextBox
                                            x:Name="PART_TextBox"
                                            Margin="0"
                                            Padding="{TemplateBinding Padding}"
                                            HorizontalAlignment="Stretch"
                                            VerticalAlignment="Stretch"
                                            ContextMenu="{TemplateBinding ContextMenu}"
                                            Focusable="{TemplateBinding Focusable}"
                                            Foreground="{TemplateBinding Foreground}" />
                                    </Grid>
                                    <!--  Buttons and Icons have no padding from the main element to allow absolute positions if height is larger than the text entry zone  -->
                                    <Button
                                        x:Name="PART_Button"
                                        Grid.Column="1"
                                        Width="{StaticResource DatePickerCalendarButtonHeight}"
                                        Height="{StaticResource DatePickerCalendarButtonHeight}"
                                        Margin="{StaticResource DatePickerCalendarButtonMargin}"
                                        Padding="{StaticResource DatePickerCalendarButtonPadding}"
                                        HorizontalAlignment="Center"
                                        VerticalAlignment="Top"
                                        HorizontalContentAlignment="Center"
                                        VerticalContentAlignment="Center"
                                        Background="Transparent"
                                        BorderBrush="Transparent"
                                        AutomationProperties.Name="{Binding Path=(AutomationProperties.Name), Mode=OneWay, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DatePicker}}}"
                                        Cursor="Arrow"
                                        Focusable="True"
                                        IsTabStop="True" >
                                        <!--  WPF overrides paddings for button  -->

                                        <TextBlock
                                            Margin="{StaticResource DatePickerCalendarButtonPadding}"
                                            HorizontalAlignment="Center"
                                            VerticalAlignment="Center"
                                            FontFamily="{DynamicResource SymbolThemeFontFamily}"
                                            FontSize="{StaticResource DatePickerCalendarButtonIconSize}"
                                            Foreground="{TemplateBinding Foreground}"
                                            Text="{StaticResource CalendarGlyph}" />
                                    </Button>
                                </Grid>
                            </Border>
                            <!--  The Accent Border is a separate element so that changes to the border thickness do not affect the position of the element  -->
                            <Border
                                x:Name="AccentBorder"
                                HorizontalAlignment="Stretch"
                                VerticalAlignment="Stretch"
                                BorderThickness="{StaticResource DatePickerAccentBorderThemeThickness}"
                                CornerRadius="{TemplateBinding Border.CornerRadius}" 
                                BorderBrush="{DynamicResource ControlStrongStrokeColorDefaultBrush}"/>
                        </Grid>
                        <Popup
                            x:Name="PART_Popup"
                            Grid.Row="1"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Top"
                            AllowsTransparency="True"
                            Placement="Bottom"
                            PlacementTarget="{Binding ElementName=PART_TextBox}"
                            StaysOpen="False" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsKeyboardFocusWithin" Value="True">
                            <Setter TargetName="AccentBorder" Property="BorderThickness" Value="0,0,0,2" />
                            <Setter TargetName="AccentBorder" Property="BorderBrush" Value="{DynamicResource DatePickerFocusedBorderBrush}" />
                            <Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource DatePickerBackgroundFocused}" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsEnabled" Value="True" />
                                <Condition Property="IsMouseOver" Value="True" />
                                <Condition Property="IsKeyboardFocusWithin" Value="False" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource DatePickerBackgroundPointerOver}" />
                        </MultiTrigger>
                        <Trigger Property="IsEnabled" Value="True">
                            <Setter Property="Cursor" Value="IBeam" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource ControlFillColorDisabledBrush}" />
                            <Setter TargetName="ContentBorder" Property="BorderBrush" Value="{DynamicResource ControlStrokeColorDefaultBrush}" />
                            <Setter TargetName="AccentBorder" Property="BorderBrush" Value="{DynamicResource ControlStrokeColorDefaultBrush}" />
                            <Setter Property="Foreground" Value="{DynamicResource TextFillColorDisabledBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style BasedOn="{StaticResource DefaultDatePickerTextBoxStyle}" TargetType="{x:Type DatePickerTextBox}" />
    <Style BasedOn="{StaticResource DefaultDatePickerStyle}" TargetType="{x:Type DatePicker}" />

</ResourceDictionary>
