<ResourceDictionary
    x:ClassModifier="internal"
    xmlns="https://github.com/avaloniaui"
    xmlns:converters="using:Avalonia.Controls.Converters"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <converters:StringFormatConverter x:Key="StringFormatConverter" />

    <ControlTheme TargetType="ProgressBar" x:Key="{x:Type ProgressBar}">
        <Setter Property="Background" Value="{DynamicResource AccentColor}" />
        <Setter Property="Foreground" Value="{DynamicResource AccentColor}" />
        <Setter Property="Template">
            <ControlTemplate TargetType="ProgressBar">
                <Panel>
                    <Border
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        CornerRadius="{TemplateBinding CornerRadius}"
                        Opacity="0.2" />
                    <Border
                        Background="{TemplateBinding Foreground}"
                        CornerRadius="{TemplateBinding CornerRadius}"
                        IsVisible="{Binding !IsIndeterminate, RelativeSource={RelativeSource TemplatedParent}}"
                        Name="PART_Indicator" />
                    <Border
                        Background="{TemplateBinding Foreground}"
                        IsVisible="{Binding IsIndeterminate, RelativeSource={RelativeSource TemplatedParent}}"
                        Name="PART_IndeterminateIndicator" />
                    <LayoutTransformControl
                        HorizontalAlignment="Center"
                        IsVisible="{Binding ShowProgressText, RelativeSource={RelativeSource TemplatedParent}}"
                        Name="PART_LayoutTransformControl"
                        VerticalAlignment="Center">
                        <TextBlock Foreground="{DynamicResource MainTextColor}">
                            <TextBlock.Text>
                                <MultiBinding Converter="{StaticResource StringFormatConverter}">
                                    <TemplateBinding Property="ProgressTextFormat" />
                                    <Binding Path="Value" RelativeSource="{RelativeSource TemplatedParent}" />
                                    <TemplateBinding Property="Percentage" />
                                    <TemplateBinding Property="Minimum" />
                                    <TemplateBinding Property="Maximum" />
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                    </LayoutTransformControl>
                </Panel>
            </ControlTemplate>
        </Setter>

        <Style Selector="^:horizontal /template/ Border#PART_Indicator">
            <Setter Property="HorizontalAlignment" Value="Left" />
            <Setter Property="VerticalAlignment" Value="Stretch" />
        </Style>
        <Style Selector="^:vertical /template/ Border#PART_Indicator">
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <Setter Property="VerticalAlignment" Value="Bottom" />
        </Style>
        <Style Selector="^:horizontal">
            <Setter Property="MinWidth" Value="200" />
            <Setter Property="MinHeight" Value="16" />
        </Style>
        <Style Selector="^:vertical">
            <Setter Property="MinWidth" Value="16" />
            <Setter Property="MinHeight" Value="200" />
        </Style>
        <Style Selector="^:vertical /template/ LayoutTransformControl#PART_LayoutTransformControl">
            <Setter Property="LayoutTransform">
                <Setter.Value>
                    <RotateTransform Angle="90" />
                </Setter.Value>
            </Setter>
        </Style>

        <Style Selector="^:horizontal:indeterminate /template/ Border#PART_IndeterminateIndicator">
            <Style.Animations>
                <Animation
                    Duration="0:0:3"
                    Easing="LinearEasing"
                    IterationCount="Infinite">
                    <KeyFrame Cue="0%">
                        <Setter Property="TranslateTransform.X"
                                Value="{Binding $parent[ProgressBar].TemplateSettings.IndeterminateStartingOffset}" />
                    </KeyFrame>
                    <KeyFrame Cue="100%">
                        <Setter Property="TranslateTransform.X"
                                Value="{Binding $parent[ProgressBar].TemplateSettings.IndeterminateEndingOffset}" />
                    </KeyFrame>
                </Animation>
            </Style.Animations>
            <Setter Property="Width"
                    Value="{Binding TemplateSettings.ContainerWidth, RelativeSource={RelativeSource TemplatedParent}}" />
        </Style>
        <Style Selector="^:vertical:indeterminate /template/ Border#PART_IndeterminateIndicator">
            <Style.Animations>
                <Animation
                    Duration="0:0:3"
                    Easing="LinearEasing"
                    IterationCount="Infinite">
                    <KeyFrame Cue="0%">
                        <Setter Property="TranslateTransform.Y"
                                Value="{Binding $parent[ProgressBar].TemplateSettings.IndeterminateStartingOffset}" />
                    </KeyFrame>
                    <KeyFrame Cue="100%">
                        <Setter Property="TranslateTransform.Y"
                                Value="{Binding $parent[ProgressBar].TemplateSettings.IndeterminateEndingOffset}" />
                    </KeyFrame>
                </Animation>
            </Style.Animations>
            <Setter Property="Height"
                    Value="{Binding TemplateSettings.ContainerWidth, RelativeSource={RelativeSource TemplatedParent}}" />
        </Style>
    </ControlTheme>
</ResourceDictionary>