<!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
-->

<Styles xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=netstandard">
  <Style Selector="CalendarDatePicker">

    <Setter Property="Background" Value="{DynamicResource ThemeBackgroundBrush}"/>
    <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}"/>
    <Setter Property="BorderThickness" Value="{DynamicResource ThemeBorderThickness}"/>
    <Setter Property="Padding" Value="4"/>
    
    <Setter Property="Template">
      <ControlTemplate>
        <Grid ColumnDefinitions="*,Auto">

          <Grid.Styles>

            <Style Selector="Button.CalendarDropDown">
              <Setter Property="Template">
                <ControlTemplate>
                  <Grid Height="18"
                        Width="19"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        Margin="0"
                        Background="{DynamicResource ThemeControlLowBrush}"
                        ColumnDefinitions="*,*,*,*"
                        RowDefinitions="23*,19*,19*,19*"
                        ClipToBounds="False">

                    <Border Name="Highlight"
                            Margin="-1"
                            Grid.ColumnSpan="4"
                            Grid.Row="0"
                            Grid.RowSpan="4"
                            BorderThickness="1"
                            BorderBrush="{DynamicResource HighlightBrush}" />
                    <Border Name="Background"
                            Margin="0,-1,0,0"
                            Grid.ColumnSpan="4"
                            Grid.Row="1"
                            Grid.RowSpan="3"
                            BorderThickness="1"
                            BorderBrush="{DynamicResource ThemeBorderHighBrush}"
                            CornerRadius=".5" />
                    <Rectangle Grid.ColumnSpan="4"
                               Grid.RowSpan="1"
                               StrokeThickness="1"
                               Stroke="{DynamicResource ThemeBorderHighBrush}"
                               Fill="{DynamicResource ThemeAccentBrush}">
                    </Rectangle>
                    <TextBlock Margin="0,-1,0,0"
                               VerticalAlignment="Center"
                               HorizontalAlignment="Center"
                               Grid.Column="0"
                               Grid.Row="1"
                               Grid.ColumnSpan="4"
                               Grid.RowSpan="3"
                               FontSize="{DynamicResource FontSizeSmall}"
                               Foreground="{DynamicResource ThemeBorderHighBrush}"
                               Text="{Binding Source={x:Static sys:DateTime.Today}, Path=Day}"/>

                    <Ellipse HorizontalAlignment="Center" VerticalAlignment="Center" Fill="{DynamicResource ThemeControlLowBrush}" StrokeThickness="0" Grid.ColumnSpan="4" Width="3" Height="3"/>
                  </Grid>
                </ControlTemplate>
              </Setter>
            </Style>

            <Style Selector="Button.CalendarDropDown /template/ Border#Highlight">
              <Setter Property="IsVisible" Value="False"/>
            </Style>
            <Style Selector="Button.CalendarDropDown:pressed /template/ Border#Highlight">
              <Setter Property="IsVisible" Value="True"/>
            </Style>

            <Style Selector="Button.CalendarDropDown:pointerover /template/ Border#Background">
              <Setter Property="Background" Value="{DynamicResource ThemeAccentBrush4}"/>
            </Style>
            
          </Grid.Styles>
          
          <TextBox Name="PART_TextBox"
                   Background="{TemplateBinding Background}" 
                   BorderBrush="{TemplateBinding BorderBrush}" 
                   BorderThickness="{TemplateBinding BorderThickness}"
                   CornerRadius="{TemplateBinding CornerRadius}"
                   Padding="{TemplateBinding Padding}"
                   Watermark="{TemplateBinding Watermark}"
                   UseFloatingWatermark="{TemplateBinding UseFloatingWatermark}"
                   DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}"
                   VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                   HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                   Grid.Column="0"/>

          <Button Name="PART_Button"
                  Grid.Column="1"
                  Width="20"
                  Classes="CalendarDropDown"
                  Foreground="{TemplateBinding Foreground}"
                  Background="Transparent"
                  BorderThickness="0"
                  Margin="2,0,2,0"
                  Padding="0"
                  ClipToBounds="False"
                  Focusable="False"/>

          <Popup Name="PART_Popup"
                 PlacementTarget="{TemplateBinding}"
                 StaysOpen="False">
            <Calendar Name="PART_Calendar"
                      FirstDayOfWeek="{TemplateBinding FirstDayOfWeek}"
                      IsTodayHighlighted="{TemplateBinding IsTodayHighlighted}"
                      SelectedDate="{TemplateBinding SelectedDate, Mode=TwoWay}"
                      DisplayDate="{TemplateBinding DisplayDate}"
                      DisplayDateStart="{TemplateBinding DisplayDateStart}"
                      DisplayDateEnd="{TemplateBinding DisplayDateEnd}" />
          </Popup>
        </Grid>
      </ControlTemplate>
    </Setter>
  </Style>

  <Style Selector="CalendarDatePicker:focus /template/ TextBox#PART_TextBox">
    <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderHighBrush}"/>
  </Style>
  
</Styles>
