<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ghfvs="https://github.com/github/VisualStudio"
    xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
    xmlns:local="clr-namespace:GitHub.UI">

    <Style TargetType="{x:Type local:ValidationMessage}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ValidationMessage}">
                    <TextBlock Visibility="Collapsed" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="InlineValidationMessage" TargetType="{x:Type local:ValidationMessage}">
        <Setter Property="Padding" Value="2,0,2,4" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ValidationMessage}">
                    <Grid x:Name="grid" Visibility="Collapsed" Margin="{TemplateBinding Padding}" ToolTip="{TemplateBinding Text}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Viewbox
                            Width="16"
                            Height="16"
                            Grid.Column="0"
                            Visibility="{TemplateBinding ShowError, Converter={ghfvs:BooleanToVisibilityConverter}}">
                            <ghfvs:OcticonPath
                                x:Name="icon"
                                Icon="{TemplateBinding Icon}"
                                Height="16"
                                Fill="{TemplateBinding Fill}"/>
                        </Viewbox>
                        <TextBlock Grid.Column="1" Text="{TemplateBinding Text}"
                                   Margin="3,0,0,2"
                                   VerticalAlignment="Center"/>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsShowingMessage" Value="True">
                            <Setter Property="Visibility" Value="Visible" TargetName="grid" />
                        </Trigger>

                        <Trigger Property="IsShowingMessage" Value="False">
                            <Setter Property="Visibility" Value="Collapsed" TargetName="grid" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <SolidColorBrush
        x:Key="GitHubErrorAdornmentBrush"
        Color="{DynamicResource GitHubErrorColor}"
        PresentationOptions:Freeze="true" />
    
    <ControlTemplate x:Key="validationTemplate">
        <!--
            In order for the Tooltip to show up over the adorned textbox, we need to make the background of the 
            adornment (grid) transparent. But that changes the cursor type, so we change it back to IBeam.
        -->
        <Grid
            ToolTip="{Binding ElementName=adornerPlaceholder, Path=AdornedElement.(Validation.Errors).CurrentItem.ErrorContent}"
            Background="Transparent"
            Cursor="IBeam"
            IsHitTestVisible="False">
            
            <AdornedElementPlaceholder
                Name="adornerPlaceholder"
                Grid.Column="0" />
            <Viewbox
                Grid.Column="0"
                Margin="0,0,4,0"
                Width="16"
                Height="16"
                VerticalAlignment="Center"
                HorizontalAlignment="Right">
                <ghfvs:OcticonPath
                    x:Name="icon"
                    Icon="stop"
                    Fill="{StaticResource GitHubErrorAdornmentBrush}"
                    Height="16" />
            </Viewbox>
        </Grid>
    </ControlTemplate>
</ResourceDictionary>