<ResourceDictionary
    x:Class="Wino.Styles.WinoExpanderStyle"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals"
    xmlns:controls="using:Wino.Controls"
    xmlns:local="using:Wino.Styles"
    xmlns:muxc="using:Microsoft.UI.Xaml.Controls">

    <ControlTemplate x:Key="DefaultWinoThreadControlTemplate" TargetType="controls:WinoExpander">
        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <!--  Header  -->
            <ContentControl
                x:Name="HeaderGrid"
                Grid.Column="1"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch"
                HorizontalContentAlignment="Stretch"
                VerticalContentAlignment="Stretch"
                Background="{TemplateBinding Background}"
                Content="{TemplateBinding Header}" />

            <!--  Content  -->
            <Grid x:Name="ContentAreaWrapper" Grid.Row="1">
                <ContentControl
                    x:Name="ContentArea"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch"
                    HorizontalContentAlignment="Stretch"
                    VerticalContentAlignment="Stretch"
                    Content="{TemplateBinding Content}"
                    RenderTransformOrigin="0.5,0.5"
                    Visibility="Collapsed">
                    <ContentControl.RenderTransform>
                        <CompositeTransform />
                    </ContentControl.RenderTransform>
                </ContentControl>
            </Grid>

            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="OpenCloseStates">
                    <VisualState x:Name="Collapsed">
                        <VisualState.Storyboard>
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentArea" Storyboard.TargetProperty="Visibility">
                                    <DiscreteObjectKeyFrame KeyTime="0:0:0.111" Value="Collapsed" />
                                </ObjectAnimationUsingKeyFrames>
                                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ContentArea" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)">
                                    <DiscreteDoubleKeyFrame KeyTime="0" Value="0" />
                                    <SplineDoubleKeyFrame
                                        KeySpline="1.0, 1.0, 0.0, 1.0"
                                        KeyTime="0:0:0.111"
                                        Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.NegativeContentHeight}" />
                                </DoubleAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState.Storyboard>
                    </VisualState>
                    <VisualState x:Name="Expanded">
                        <VisualState.Storyboard>
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentArea" Storyboard.TargetProperty="Visibility">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                                </ObjectAnimationUsingKeyFrames>
                                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ContentArea" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)">
                                    <DiscreteDoubleKeyFrame KeyTime="0" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.NegativeContentHeight}" />
                                    <SplineDoubleKeyFrame
                                        KeySpline="0.0, 0.0, 0.0, 1.0"
                                        KeyTime="0:0:0.333"
                                        Value="0" />
                                </DoubleAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState.Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
        </Grid>
    </ControlTemplate>

    <Style TargetType="controls:WinoExpander">
        <Setter Property="Background" Value="{ThemeResource AppBarItemBackgroundThemeBrush}" />
        <Setter Property="Template" Value="{StaticResource DefaultWinoThreadControlTemplate}" />
    </Style>

</ResourceDictionary>
