<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
                    xmlns:Converters="clr-namespace:MahApps.Metro.Converters;assembly=MahApps.Metro"
                    xmlns:IconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
                    xmlns:behaviours="clr-namespace:MahApps.Metro.Behaviours;assembly=MahApps.Metro"
                    xmlns:converter="clr-namespace:Vulnerator.View.Converter"
                    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
                    xmlns:local="clr-namespace:Vulnerator.View.Styles"
                    xmlns:po="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
                    xmlns:vh="clr-namespace:Vulnerator.View.ViewHelper"
                    xmlns:vm="clr-namespace:Vulnerator.ViewModel">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Shared.xaml" />
        <ResourceDictionary Source="pack://application:,,,/Vulnerator;component/View/Styles/Storyboard.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <converter:IsNullConverter x:Key="IsNullConverter" />

    <Style x:Key="HeaderedDatePickerStyle"
           TargetType="{x:Type DatePicker}">
        <Setter Property="Background" Value="{DynamicResource ControlBackgroundBrush}" />
        <Setter Property="BorderBrush" Value="{DynamicResource TextBoxBorderBrush}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="CalendarStyle" Value="{DynamicResource MahApps.Metro.Styles.BaseMetroCalendar}" />
        <Setter Property="Controls:ControlsHelper.FocusBorderBrush" Value="{DynamicResource TextBoxFocusBorderBrush}" />
        <Setter Property="Controls:ControlsHelper.MouseOverBorderBrush" Value="{DynamicResource TextBoxMouseOverBorderBrush}" />
        <Setter Property="Controls:TextBoxHelper.ButtonWidth" Value="22" />
        <Setter Property="Controls:TextBoxHelper.IsMonitoring" Value="True" />
        <Setter Property="Controls:TextBoxHelper.UseFloatingWatermark" Value="True" />
        <Setter Property="FontFamily" Value="{DynamicResource ContentFontFamily}" />
        <Setter Property="FontSize" Value="{DynamicResource ContentFontSize}" />
        <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
        <Setter Property="IsTodayHighlighted" Value="True" />
        <Setter Property="MinHeight" Value="26" />
        <Setter Property="Padding" Value="0" />
        <Setter Property="SelectedDate" Value="{Binding Path=(vh:DependencyProperties.PrimaryValue), RelativeSource={RelativeSource Self}}" />
        <Setter Property="SelectedDateFormat" Value="Short" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DatePicker}">
                    <Grid x:Name="PART_Root">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Border x:Name="DisabledVisualElement"
                                Grid.RowSpan="2"
                                Background="{DynamicResource ControlsDisabledBrush}"
                                BorderBrush="{DynamicResource ControlsDisabledBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                IsHitTestVisible="False"
                                Opacity="0"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        <ContentControl x:Name="PART_FloatingMessageContainer"
                                        Grid.Row="0"
                                        Margin="0"
                                        HorizontalAlignment="Left"
                                        vh:DependencyProperties.FloatingWatermarkForeground="{TemplateBinding vh:DependencyProperties.FloatingWatermarkForeground}"
                                        Style="{DynamicResource FloatingMessageContainerStyle}"
                                        Visibility="Hidden">
                            <ContentControl.Width>
                                <MultiBinding Converter="{Converters:MathMultiplyConverter}">
                                    <Binding Mode="OneWay"
                                             ElementName="PART_FloatingMessage"
                                             Path="ActualWidth" />
                                    <Binding Mode="OneWay"
                                             ElementName="PART_FloatingMessageContainer"
                                             Path="Opacity" />
                                </MultiBinding>
                            </ContentControl.Width>
                            <TextBlock x:Name="PART_FloatingMessage"
                                       HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                       VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                       Foreground="{TemplateBinding vh:DependencyProperties.FloatingWatermarkForeground}"
                                       Opacity="1"
                                       Style="{DynamicResource MetroAutoCollapsingTextBlock}"
                                       Text="{TemplateBinding vh:DependencyProperties.FloatingWatermark}"
                                       TextAlignment="{TemplateBinding Controls:TextBoxHelper.WatermarkAlignment}"
                                       TextTrimming="{TemplateBinding Controls:TextBoxHelper.WatermarkTrimming}">
                                <TextBlock.RenderTransform>
                                    <TranslateTransform x:Name="FloatingMessageTransform">
                                        <TranslateTransform.Y>
                                            <MultiBinding Converter="{Converters:MathSubtractConverter}">
                                                <Binding Mode="OneWay"
                                                         ElementName="PART_FloatingMessage"
                                                         Path="ActualHeight" />
                                                <Binding Mode="OneWay"
                                                         ElementName="PART_FloatingMessageContainer"
                                                         Path="ActualHeight" />
                                            </MultiBinding>
                                        </TranslateTransform.Y>
                                    </TranslateTransform>
                                </TextBlock.RenderTransform>
                            </TextBlock>
                        </ContentControl>

                        <Border x:Name="Base"
                                Grid.Row="1"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="3"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        <Grid x:Name="PART_InnerGrid"
                              Grid.Row="1"
                              Margin="2">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition x:Name="ButtonColumn"
                                                  Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition x:Name="ButtonRow"
                                               Height="*" />
                            </Grid.RowDefinitions>

                            <Button x:Name="PART_Button"
                                    Grid.RowSpan="2"
                                    Grid.Column="1"
                                    VerticalAlignment="Stretch"
                                    Foreground="{TemplateBinding Foreground}"
                                    IsTabStop="False"
                                    Style="{DynamicResource ChromelessButtonStyle}">
                                <ContentControl Width="{TemplateBinding Controls:TextBoxHelper.ButtonWidth}"
                                                Height="{TemplateBinding Controls:TextBoxHelper.ButtonWidth}"
                                                Padding="2"
                                                HorizontalAlignment="Center"
                                                VerticalAlignment="Center"
                                                Content="{IconPacks:FontAwesomeLight Kind=CalendarDay}"
                                                Style="{DynamicResource MahApps.Styles.ContentControl.PathIcon}" />
                            </Button>

                            <DatePickerTextBox x:Name="PART_TextBox"
                                               Grid.Row="1"
                                               Grid.Column="0"
                                               Margin="0,1"
                                               Padding="0,1"
                                               HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                               VerticalContentAlignment="Center"
                                               Controls:TextBoxHelper.Watermark="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.Watermark), Mode=OneWay}"
                                               Controls:TextBoxHelper.WatermarkAlignment="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.WatermarkAlignment), Mode=OneWay}"
                                               Controls:TextBoxHelper.WatermarkTrimming="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.WatermarkTrimming), Mode=OneWay}"
                                               CaretBrush="{DynamicResource BlackBrush}"
                                               Focusable="{TemplateBinding Focusable}"
                                               FontSize="{TemplateBinding FontSize}"
                                               Foreground="{TemplateBinding Foreground}"
                                               SelectionBrush="{DynamicResource HighlightBrush}">
                                <i:Interaction.Behaviors>
                                    <behaviours:DatePickerTextBoxBehavior />
                                </i:Interaction.Behaviors>
                            </DatePickerTextBox>

                            <Popup x:Name="PART_Popup"
                                   Grid.Row="1"
                                   Grid.Column="0"
                                   AllowsTransparency="True"
                                   Placement="Bottom"
                                   PlacementTarget="{Binding ElementName=PART_Root}"
                                   StaysOpen="False" />
                        </Grid>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <Trigger Property="Controls:ControlsHelper.IsReadOnly" Value="True">
                            <Setter TargetName="PART_Button" Property="IsEnabled" Value="False" />
                            <Setter TargetName="PART_TextBox" Property="IsReadOnly" Value="True" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="Base" Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.MouseOverBorderBrush)}" />
                        </Trigger>
                        <Trigger SourceName="PART_TextBox" Property="IsFocused" Value="True">
                            <Setter TargetName="Base" Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.FocusBorderBrush)}" />
                        </Trigger>
                        <Trigger Property="IsKeyboardFocusWithin" Value="True">
                            <Setter TargetName="Base" Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.FocusBorderBrush)}" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="DisabledVisualElement" Property="Opacity" Value="0.6" />
                        </Trigger>
                        <Trigger SourceName="PART_Button" Property="IsMouseOver" Value="True">
                            <Setter TargetName="PART_Button" Property="Background" Value="{DynamicResource GrayBrush8}" />
                            <Setter TargetName="PART_Button" Property="Foreground" Value="{DynamicResource AccentColorBrush}" />
                        </Trigger>
                        <Trigger SourceName="PART_Button" Property="IsPressed" Value="True">
                            <Setter TargetName="PART_Button" Property="Background" Value="{DynamicResource BlackBrush}" />
                            <Setter TargetName="PART_Button" Property="Foreground" Value="{DynamicResource WhiteBrush}" />
                        </Trigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding Path=IsVisible, RelativeSource={RelativeSource Self}}" Value="True" />
                                <Condition Binding="{Binding Path=(Controls:TextBoxHelper.UseFloatingWatermark), RelativeSource={RelativeSource Self}}" Value="True" />
                                <Condition Binding="{Binding Path=(Controls:TextBoxHelper.HasText), RelativeSource={RelativeSource Self}}" Value="True" />
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource CustomShowFloatingMessageStoryboard}" />
                            </MultiDataTrigger.EnterActions>
                            <MultiDataTrigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource CustomHideFloatingMessageStoryboard}" />
                            </MultiDataTrigger.ExitActions>
                        </MultiDataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Validation.ErrorTemplate">
            <Setter.Value>
                <ControlTemplate>
                    <StackPanel>
                        <AdornedElementPlaceholder x:Name="textBox" />
                        <Border Background="Red"
                                BorderBrush="Red"
                                BorderThickness="1,0,1,1">
                            <TextBlock Foreground="White"
                                       Text="{Binding [0].ErrorContent}" />
                        </Border>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="vh:DependencyProperties.FloatingWatermark" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.Watermark)}" />
        <Setter Property="vh:DependencyProperties.FloatingWatermarkForeground" Value="{Binding RelativeSource={RelativeSource Self}, Path=Foreground}" />
        <Setter Property="vh:DependencyProperties.PrimaryValue" Value="{Binding Path=(vh:DependencyProperties.PrimaryValue), RelativeSource={RelativeSource Self}}" />
        <Setter Property="vh:DependencyProperties.SecondaryValue" Value="{Binding Path=(vh:DependencyProperties.PrimaryValue), RelativeSource={RelativeSource Self}}" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=(vh:DependencyProperties.AlternateValueTrigger), RelativeSource={RelativeSource Self}, Converter={StaticResource IsNullConverter}}"
                         Value="False">
                <Setter Property="SelectedDate" Value="{Binding Path=(vh:DependencyProperties.SecondaryValue), RelativeSource={RelativeSource Self}}" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="MetroDatePickerTextBox"
           TargetType="{x:Type DatePickerTextBox}">
        <Setter Property="Background" Value="{DynamicResource ControlBackgroundBrush}" />
        <Setter Property="ContextMenu" Value="{DynamicResource TextBoxMetroContextMenu}" />
        <Setter Property="Controls:TextBoxHelper.IsMonitoring" Value="True" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="FontFamily" Value="{DynamicResource ContentFontFamily}" />
        <Setter Property="FontSize" Value="{DynamicResource ContentFontSize}" />
        <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
        <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
        <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DatePickerTextBox}">
                    <ControlTemplate.Resources>
                        <Storyboard x:Key="EnterGotFocus">
                            <DoubleAnimation Storyboard.TargetName="PART_Watermark"
                                             Storyboard.TargetProperty="Opacity"
                                             To=".2"
                                             Duration="0:0:0.2" />
                            <DoubleAnimation Storyboard.TargetName="PART_Message"
                                             Storyboard.TargetProperty="Opacity"
                                             To=".2"
                                             Duration="0:0:0.2" />
                        </Storyboard>
                        <Storyboard x:Key="ExitGotFocus">
                            <DoubleAnimation Storyboard.TargetName="PART_Watermark"
                                             Storyboard.TargetProperty="Opacity"
                                             Duration="0:0:0.2" />
                            <DoubleAnimation Storyboard.TargetName="PART_Message"
                                             Storyboard.TargetProperty="Opacity"
                                             Duration="0:0:0.2" />
                        </Storyboard>

                        <Storyboard x:Key="EnterHasText">
                            <DoubleAnimation Storyboard.TargetName="PART_Watermark"
                                             Storyboard.TargetProperty="Opacity"
                                             From=".2"
                                             To="0"
                                             Duration="0:0:0.2" />
                            <DoubleAnimation Storyboard.TargetName="PART_Message"
                                             Storyboard.TargetProperty="Opacity"
                                             From=".2"
                                             To="0"
                                             Duration="0:0:0.2" />
                        </Storyboard>
                        <Storyboard x:Key="ExitHasText">
                            <DoubleAnimation Storyboard.TargetName="PART_Watermark"
                                             Storyboard.TargetProperty="Opacity"
                                             Duration="0:0:0.2" />
                            <DoubleAnimation Storyboard.TargetName="PART_Message"
                                             Storyboard.TargetProperty="Opacity"
                                             Duration="0:0:0.2" />
                        </Storyboard>
                    </ControlTemplate.Resources>
                    <Grid x:Name="PART_InnerGrid"
                          Margin="2">

                        <ScrollViewer x:Name="PART_ContentHost"
                                      VerticalAlignment="Stretch"
                                      Background="{x:Null}"
                                      BorderThickness="0"
                                      FocusVisualStyle="{x:Null}"
                                      IsTabStop="False" />
                        <ContentControl x:Name="PART_Watermark"
                                        Margin="4,0,0,0"
                                        HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                        VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                        Controls:TextBoxHelper.WatermarkAlignment="{TemplateBinding Controls:TextBoxHelper.WatermarkAlignment}"
                                        Controls:TextBoxHelper.WatermarkTrimming="{TemplateBinding Controls:TextBoxHelper.WatermarkTrimming}"
                                        Focusable="False"
                                        Foreground="{TemplateBinding Foreground}"
                                        IsHitTestVisible="False"
                                        Opacity="0.6"
                                        Visibility="Hidden">
                            <ContentControl.Template>
                                <ControlTemplate TargetType="{x:Type ContentControl}">
                                    <TextBlock HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                               VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                               Text="{TemplateBinding Content}"
                                               TextAlignment="{TemplateBinding Controls:TextBoxHelper.WatermarkAlignment}"
                                               TextTrimming="{TemplateBinding Controls:TextBoxHelper.WatermarkTrimming}" />
                                </ControlTemplate>
                            </ContentControl.Template>
                        </ContentControl>
                        <TextBlock x:Name="PART_Message"
                                   Margin="4,0,0,0"
                                   HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                   VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                   Foreground="{TemplateBinding Foreground}"
                                   Style="{DynamicResource MahApps.Metro.Styles.MetroWatermarkTextBlock}"
                                   Text="{TemplateBinding Controls:TextBoxHelper.Watermark}"
                                   TextAlignment="{TemplateBinding Controls:TextBoxHelper.WatermarkAlignment}"
                                   TextTrimming="{TemplateBinding Controls:TextBoxHelper.WatermarkTrimming}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="Controls:TextBoxHelper.HasText" Value="False" />
                                <Condition Property="IsFocused" Value="True" />
                            </MultiTrigger.Conditions>
                            <MultiTrigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource EnterGotFocus}" />
                            </MultiTrigger.EnterActions>
                            <MultiTrigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource ExitGotFocus}" />
                            </MultiTrigger.ExitActions>
                        </MultiTrigger>

                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.Watermark)}"
                                     Value="">
                            <Setter TargetName="PART_Watermark" Property="Visibility" Value="Visible" />
                        </DataTrigger>

                        <Trigger Property="Controls:TextBoxHelper.HasText" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource EnterHasText}" />
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource ExitHasText}" />
                            </Trigger.ExitActions>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>