<ResourceDictionary
    x:ClassModifier="internal"
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ControlTheme TargetType="TextBox" x:Key="{x:Type TextBox}">
        <Setter Property="CaretBrush" Value="{DynamicResource MainTextColor}" />
        <Setter Property="SelectionBrush" Value="{DynamicResource AccentColor}" />
        <Setter Property="SelectionForegroundBrush" Value="{DynamicResource MainTextColor}" />
        <Setter Property="Padding" Value="8,4,0,4" />
        <Setter Property="ScrollViewer.IsScrollChainingEnabled" Value="True" />
        <Setter Property="LineHeight" Value="16" />
        <Setter Property="Template">
            <ControlTemplate>
                <Border
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    CornerRadius="{TemplateBinding CornerRadius}"
                    Name="border">
                    <DockPanel
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        Margin="{TemplateBinding Padding}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}">

                        <DataValidationErrors>

                            <Grid ColumnDefinitions="Auto,*,Auto">
                                <ContentPresenter Content="{TemplateBinding InnerLeftContent}" Grid.Column="0" />
                                <ScrollViewer
                                    AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}"
                                    BringIntoViewOnFocusChange="{TemplateBinding (ScrollViewer.BringIntoViewOnFocusChange)}"
                                    Grid.Column="1"
                                    HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}"
                                    IsScrollChainingEnabled="{TemplateBinding (ScrollViewer.IsScrollChainingEnabled)}"
                                    Name="PART_ScrollViewer"
                                    VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}">
                                    <Panel>
                                        <TextBlock
                                            Foreground="{DynamicResource MainTextColorFaded}"
                                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                            IsVisible="{TemplateBinding Text,
                                                                        Converter={x:Static StringConverters.IsNullOrEmpty}}"
                                            Name="watermark"
                                            Opacity="0.5"
                                            Text="{TemplateBinding Watermark}"
                                            TextAlignment="{TemplateBinding TextAlignment}"
                                            TextWrapping="{TemplateBinding TextWrapping}"
                                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                        <TextPresenter
                                            CaretBrush="{TemplateBinding CaretBrush}"
                                            CaretIndex="{TemplateBinding CaretIndex}"
                                            LetterSpacing="{TemplateBinding LetterSpacing}"
                                            LineHeight="{TemplateBinding LineHeight}"
                                            Name="PART_TextPresenter"
                                            PasswordChar="{TemplateBinding PasswordChar}"
                                            RevealPassword="{TemplateBinding RevealPassword}"
                                            SelectionBrush="{TemplateBinding SelectionBrush}"
                                            SelectionEnd="{TemplateBinding SelectionEnd}"
                                            SelectionForegroundBrush="{TemplateBinding SelectionForegroundBrush}"
                                            SelectionStart="{TemplateBinding SelectionStart}"
                                            Text="{TemplateBinding Text,
                                                                   Mode=TwoWay}"
                                            TextAlignment="{TemplateBinding TextAlignment}"
                                            TextWrapping="{TemplateBinding TextWrapping}" />
                                    </Panel>
                                    <ScrollViewer.Styles>
                                        <Style Selector="ScrollContentPresenter#PART_ContentPresenter">
                                            <Setter Property="Cursor" Value="IBeam" />
                                        </Style>
                                    </ScrollViewer.Styles>
                                </ScrollViewer>
                                <ContentPresenter Content="{TemplateBinding InnerRightContent}" Grid.Column="2" />
                            </Grid>
                        </DataValidationErrors>
                    </DockPanel>
                </Border>
            </ControlTemplate>
        </Setter>

        <Style Selector="^:pointerover:not(:readonly) /template/ Border#border">
            <Setter Property="BorderBrush" Value="{DynamicResource SecondaryBorderColor}" />
            <Setter Property="Cursor" Value="IBeam" />
        </Style>
        <Style Selector="^.disabled:pointerover /template/ Border#border">
            <Setter Property="BorderBrush" Value="{TemplateBinding BorderBrush}" />
        </Style>
        <Style Selector="^:focus:not(:readonly) /template/ Border#border">
            <Setter Property="BorderBrush" Value="{DynamicResource AccentColor}" />
        </Style>
        <Style Selector="^.active /template/ Border#border">
            <Setter Property="BorderBrush" Value="{DynamicResource SecondaryAccentColor}" />
        </Style>
        <Style Selector="^:error /template/ Border#border">
            <Setter Property="BorderBrush" Value="{StaticResource ErrorBrush}" />
        </Style>
        <Style Selector="^ /template/ DockPanel">
            <Setter Property="Cursor" Value="IBeam" />
        </Style>

        <Style Selector="^:disabled /template/ Border#border">
            <Setter Property="Background" Value="{DynamicResource DisabledBackgroundColor}" />
        </Style>

        <Style Selector="^:disabled /template/ TextBlock#watermark">
            <Setter Property="IsVisible" Value="False" />
        </Style>
        <Style Selector="^:disabled /template/ TextPresenter#PART_TextPresenter">
            <Setter Property="IsVisible" Value="False" />
        </Style>

        <Style Selector="^.txtShadow /template/ TextPresenter#PART_TextPresenter">
            <Setter Property="Effect" Value="{StaticResource TextShadow}" />
        </Style>

        <Style Selector="^:readonly /template/ Border#border">
            <Setter Property="Background" Value="{DynamicResource DisabledBackgroundColor}" />
        </Style>
    </ControlTheme>
</ResourceDictionary>