<!--
// (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.
-->

<ResourceDictionary
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:vs="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.14.0"
    xmlns:ui="clr-namespace:GitHub.UI">

    <!--  CommonValidationToolTipTemplate  -->
    <ControlTemplate x:Key="CommonValidationToolTipTemplate" TargetType="ToolTip">
        <Grid x:Name="Root" Margin="5,0" RenderTransformOrigin="0,0" Opacity="0">
            <Grid.RenderTransform>
                <TranslateTransform x:Name="Translation" X="-25" />
            </Grid.RenderTransform>

            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup Name="OpenStates">
                    <VisualStateGroup.Transitions>
                        <VisualTransition GeneratedDuration="0" />
                        <VisualTransition To="Open" GeneratedDuration="0:0:0.2">
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="Translation" Storyboard.TargetProperty="X" To="0" Duration="0:0:0.2" />
                                <DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.2" />
                            </Storyboard>
                        </VisualTransition>
                    </VisualStateGroup.Transitions>
                    <VisualState x:Name="Closed">
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="0" Duration="0" />
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Open">
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="Translation" Storyboard.TargetProperty="X" To="0" Duration="0" />
                            <DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>

            <Border Margin="4,4,-4,-4" Background="#052A2E31" CornerRadius="5" />
            <Border Margin="3,3,-3,-3" Background="#152A2E31" CornerRadius="4" />
            <Border Margin="2,2,-2,-2" Background="#252A2E31" CornerRadius="3" />
            <Border Margin="1,1,-1,-1" Background="#352A2E31" CornerRadius="2" />

            <Border Background="#FFDC000C" CornerRadius="2">
                <TextBlock
                    Foreground="White"
                    Margin="8,4,8,4"
                    MaxWidth="250"
                    TextWrapping="Wrap"
                    Text="{Binding (Validation.Errors)[0].ErrorContent}" />
            </Border>
        </Grid>
    </ControlTemplate>

    <ControlTemplate x:Key="ListViewItemControlTemplate" TargetType="{x:Type ListBoxItem}">
        <Border BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                Background="{TemplateBinding Background}"
                SnapsToDevicePixels="True"
                Padding="{TemplateBinding Padding}">
            <ContentPresenter Content="{TemplateBinding Content}"
                              ContentTemplate="{TemplateBinding ContentTemplate}"
                              ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" />
        </Border>
    </ControlTemplate>
    
    <Style x:Key="AutoCompleteListItemContainerStyle" TargetType="{x:Type ListBoxItem}">
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Padding" Value="5,3,3,3" />
        <Setter Property="Template" Value="{StaticResource ListViewItemControlTemplate}" />
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static vs:ThemedDialogColors.ListItemMouseOverBrushKey}}" />
                <Setter Property="Foreground" Value="{DynamicResource {x:Static vs:ThemedDialogColors.ListItemMouseOverTextBrushKey}}" />
            </Trigger>
            <Trigger Property="IsSelected" Value="true">
                <Setter Property="Background" Value="{DynamicResource {x:Static vs:ThemedDialogColors.SelectedItemInactiveBrushKey}}" />
                <Setter Property="Foreground" Value="{DynamicResource {x:Static vs:ThemedDialogColors.SelectedItemInactiveTextBrushKey}}" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsSelected" Value="True" />
                    <Condition Property="Selector.IsSelectionActive" Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Background" Value="{DynamicResource {x:Static vs:ThemedDialogColors.SelectedItemActiveBrushKey}}" />
                <Setter Property="Foreground" Value="{DynamicResource {x:Static vs:ThemedDialogColors.SelectedItemActiveTextBrushKey}}" />
            </MultiTrigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{DynamicResource {x:Static vs:ThemedDialogColors.ListItemDisabledTextBrushKey}}" />
            </Trigger>
        </Style.Triggers>
    </Style>
    
    <!--  input:AutoCompleteBox  -->
    <Style TargetType="ui:AutoCompleteBox">
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Padding" Value="2" />
        <Setter Property="Background" Value="{DynamicResource {x:Static vs:ThemedDialogColors.WindowPanelBrushKey}}" />
        <Setter Property="Foreground" Value="{DynamicResource {x:Static vs:ThemedDialogColors.WindowPanelTextBrushKey}}" />
        <Setter Property="MinWidth" Value="45" />
        <Setter Property="ItemContainerStyle" Value="{StaticResource AutoCompleteListItemContainerStyle}" />

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ui:AutoCompleteBox">
                    <Grid Opacity="{TemplateBinding Opacity}">
                        <ContentPresenter
                            x:Name="Text"
                            Content="{Binding InputElement.Control, RelativeSource={RelativeSource TemplatedParent}}"/>
                        <!-- TODO: What should we use for validation BorderBrush? -->
                        <Border
                            x:Name="ValidationErrorElement"
                            Visibility="Collapsed"
                            BorderBrush="#FFDB000C"
                            BorderThickness="1"
                            CornerRadius="1">
                            <ToolTipService.ToolTip>
                                <ToolTip
                                    x:Name="validationTooltip"
                                    DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                    Template="{StaticResource CommonValidationToolTipTemplate}"
                                    Placement="Right"
                                    PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                                    <ToolTip.Triggers>
                                        <EventTrigger RoutedEvent="Canvas.Loaded">
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <ObjectAnimationUsingKeyFrames
                                                        Storyboard.TargetName="validationTooltip"
                                                        Storyboard.TargetProperty="IsHitTestVisible">
                                                        <DiscreteObjectKeyFrame KeyTime="0">
                                                            <DiscreteObjectKeyFrame.Value>
                                                                <sys:Boolean>true</sys:Boolean>
                                                            </DiscreteObjectKeyFrame.Value>
                                                        </DiscreteObjectKeyFrame>
                                                    </ObjectAnimationUsingKeyFrames>
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </EventTrigger>
                                    </ToolTip.Triggers>
                                </ToolTip>
                            </ToolTipService.ToolTip>
                            <Grid
                                Height="12"
                                HorizontalAlignment="Right"
                                Margin="1,-4,-4,0"
                                VerticalAlignment="Top"
                                Width="12"
                                Background="Transparent">
                                <Path Fill="#FFDC000C" Margin="1,3,0,0" Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 z" />
                                <Path Fill="#ffffff" Margin="1,3,0,0" Data="M 0,0 L2,0 L 8,6 L8,8" />
                            </Grid>
                        </Border>
                        <Popup x:Name="Popup" Placement="Custom">
                            <Grid Opacity="{TemplateBinding Opacity}" Background="{TemplateBinding Background}">
                                <Border
                                    x:Name="PopupBorder"
                                    HorizontalAlignment="Stretch"
                                    Opacity="0"
                                    BorderBrush="{DynamicResource {x:Static vs:CommonControlsColors.TextBoxBorderFocusedBrushKey}}"
                                    BorderThickness="1">
                                    <ListBox
                                        x:Name="Selector"
                                        ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                        ScrollViewer.VerticalScrollBarVisibility="Auto"
                                        ItemContainerStyle="{TemplateBinding ItemContainerStyle}"
                                        Background="{TemplateBinding Background}"
                                        Foreground="{TemplateBinding Foreground}"
                                        BorderThickness="0"
                                        ItemTemplate="{TemplateBinding ItemTemplate}" />
                                </Border>
                            </Grid>
                        </Popup>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="PopupStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0:0:0.1" To="PopupOpened" />
                                    <VisualTransition GeneratedDuration="0:0:0.2" To="PopupClosed" />
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="PopupOpened">
                                    <Storyboard>
                                        <DoubleAnimation
                                            Storyboard.TargetName="PopupBorder"
                                            Storyboard.TargetProperty="Opacity"
                                            To="1.0"
                                            Duration="0:0:0.1" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="PopupClosed">
                                    <Storyboard>
                                        <DoubleAnimation
                                            Storyboard.TargetName="PopupBorder"
                                            Storyboard.TargetProperty="Opacity"
                                            To="0"
                                            Duration="0:0:0.2" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="ValidationStates">
                                <VisualState x:Name="Valid" />
                                <VisualState x:Name="InvalidUnfocused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames
                                            Storyboard.TargetName="ValidationErrorElement"
                                            Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="InvalidFocused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames
                                            Storyboard.TargetName="ValidationErrorElement"
                                            Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames
                                            Storyboard.TargetName="validationTooltip"
                                            Storyboard.TargetProperty="IsOpen">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <sys:Boolean>True</sys:Boolean>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>