<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:ClassIsland.Controls;assembly=ClassIsland"
                    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
                    xmlns:ci="http://classisland.tech/schemas/xaml/core"
                    xmlns:system="clr-namespace:System;assembly=mscorlib"
                    xmlns:classIsland="clr-namespace:ClassIsland;assembly=ClassIsland">
    <ci:SolidColorBrushToColorConverter x:Key="SolidColorBrushToColorConverter"/>
    <ci:BindingProxy x:Key="PrimaryHueLightBrushProxy" Data="{DynamicResource PrimaryHueLightBrush}"/>
    <ci:BindingProxy x:Key="PrimaryHueMidBrushProxy" Data="{DynamicResource PrimaryHueMidBrush}"/>
    <ci:BindingProxy x:Key="PrimaryHueDarkBrushProxy" Data="{DynamicResource PrimaryHueDarkBrush}"/>

    <!-- Default override style -->
    <DataTemplate x:Key="ComponentOverrideTemplate">
        <Grid Height="40" VerticalAlignment="Bottom" Margin="0 0 0 0">
            <ContentPresenter Content="{Binding Content, RelativeSource={RelativeSource AncestorType= ci:ComponentPresenter}}" />
        </Grid>
    
    </DataTemplate>

    <Style TargetType="{x:Type Grid}" x:Key="GridComponentPresenterContainerStyle">
        <Style.Triggers>
            <Trigger Property="IsVisible" Value="True">
                <Trigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)">
                                <EasingDoubleKeyFrame KeyTime="00:00:00" Value="0.00"/>
                                <EasingDoubleKeyFrame KeyTime="00:00:00.4000000" Value="1">
                                </EasingDoubleKeyFrame>
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
                                <EasingDoubleKeyFrame KeyTime="00:00:00.0000000" Value="-70"/>
                                <EasingDoubleKeyFrame KeyTime="00:00:00.4000000" Value="0">
                                    <EasingDoubleKeyFrame.EasingFunction>
                                        <CircleEase EasingMode="EaseOut"/>
                                    </EasingDoubleKeyFrame.EasingFunction>
                                </EasingDoubleKeyFrame>
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.EnterActions>
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style TargetType="{x:Type ci:ComponentPresenter}" >
        <Style.Triggers>
            <Trigger Property="IsRootComponent" Value="True">
                <Setter Property="Template" >
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ci:ComponentPresenter}">
                            <Grid Style="{StaticResource GridComponentPresenterContainerStyle}"  ClipToBounds="False"
                                  Margin="0 8">
                                <Grid.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform />
                                        <SkewTransform />
                                        <RotateTransform />
                                        <TranslateTransform Y="-70" />
                                    </TransformGroup>
                                </Grid.RenderTransform>
                                <Border CornerRadius="8" Padding="15 0"
                                            Background="{DynamicResource MaterialDesignBackground}" 
                                            Height="40"
                                            Opacity="{Binding ViewModel.Settings.Opacity, RelativeSource={RelativeSource AncestorType=classIsland:MainWindow}}"
                                            > 
                                    <Border.Effect>
                                        <DropShadowEffect BlurRadius="8" ShadowDepth="0" Opacity="0.8"  Color="#00000000"/>
                                    </Border.Effect>
                                </Border>
                                <Border CornerRadius="8" Padding="15 0"
                                        Height="40"
                                        >
                                    <Grid>
                                        <ContentPresenter Content="{Binding}">
                                            <ContentPresenter.Style>
                                                <Style TargetType="{x:Type ContentPresenter}">
                                                    <!-- default -->
                                                    <Setter Property="ContentTemplate" Value="{DynamicResource ComponentOverrideTemplate}"/>
                                                </Style>    
                                            </ContentPresenter.Style>                  
                                        </ContentPresenter>
                                    </Grid>   
                                </Border>
                            </Grid>
                        </ControlTemplate> 
                    </Setter.Value>
                </Setter>  
            </Trigger>
            
        </Style.Triggers>
    </Style>


    
    <!-- 覆盖行容器外观，可以通过修改其中的控件模板来自定义行容器外观 -->
    <Style BasedOn="{StaticResource MainWindowLineBaseStyle}" TargetType="{x:Type controls:MainWindowLine}">
        <Style.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="./Storyboards.xaml"/>
                </ResourceDictionary.MergedDictionaries>

                <!-- 行容器高度 -->
                <system:Double x:Key="IslandContainerHeight">NaN</system:Double>
            </ResourceDictionary>
        </Style.Resources>
        <!-- <Setter Property="Height" Value="60"/> -->
        <Style.Triggers>
            <Trigger Property="IsMainLine" Value="False">
                <Setter Property="Template">
                    <Setter.Value>
                        <!-- 行容器控件模板 -->
                        <ControlTemplate x:Key="MainWindowLineMinControlTemplate">
                            <Grid>
                                <Grid.Effect>
                                    <DropShadowEffect BlurRadius="8" Direction="0" 
                                                    ShadowDepth="0" Opacity="0"
                                                    x:Name="RootDropShadowEffect"
                                                    Color="Black"/>
                                </Grid.Effect>
                                <Grid 
                                    ClipToBounds="True"
                                    Style="{StaticResource DockingStyle}">
                                    <Grid x:Name="PART_GridWrapper" ClipToBounds="True"
                                        Height="{DynamicResource IslandContainerHeight}"
                                        SnapsToDevicePixels="True"
                                        Style="{StaticResource DockingStyle}">
    
                                        <Grid Height="{DynamicResource IslandContainerHeight}"
                                            x:Name="GridContentRoot"
                                            Margin="12 0">
                                            <ContentPresenter
                                                Content="{Binding Content, RelativeSource={RelativeSource AncestorType=controls:MainWindowLine}}" />
                                        </Grid>
                                    </Grid>
                                </Grid>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="Visibility" Value="{Binding IsAllComponentsHid, RelativeSource={RelativeSource Self}, Converter={StaticResource InverseBoolToVisConverter}}"/>
            </Trigger>
        </Style.Triggers>
        <Setter Property="Template">
            <Setter.Value>
                <!-- 完整行容器控件模板 -->
                <ControlTemplate x:Key="MainWindowLineFullControlTemplate">
                    <Grid>
                        <Grid.Effect>
                            <DropShadowEffect BlurRadius="8" Direction="0" 
                                            ShadowDepth="0" Opacity="0"
                                            x:Name="RootDropShadowEffect"
                                            Color="Black"/>
                        </Grid.Effect>
                        <Grid
                            ClipToBounds="True"
                            Style="{StaticResource DockingStyle}">
                            <!-- Background -->
                            <Border x:Name="BackgroundBorderOverlay"
                                    Style="{StaticResource BackgroundBorderStyle}"
                                    Opacity="0"
                                    SnapsToDevicePixels="True"
                                    Height="{DynamicResource IslandContainerHeight}">
                            </Border>
                            <Grid
                                Style="{StaticResource DockingStyle}"
                                Width="{Binding BackgroundWidth, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType=controls:MainWindowLine}}"
                                Height="{DynamicResource IslandContainerHeight}"
                                SnapsToDevicePixels="True"
                                ClipToBounds="True">
                                <materialDesign:ColorZone x:Name="BackgroundBorderOverlayMask" Mode="PrimaryMid"
                                                        VerticalAlignment="Stretch"
                                                        RenderTransformOrigin="0.5,0.5">
                                    <materialDesign:ColorZone.RenderTransform>
                                        <TransformGroup>
                                            <ScaleTransform />
                                            <SkewTransform />
                                            <RotateTransform />
                                            <TranslateTransform Y="-100" />
                                        </TransformGroup>
                                    </materialDesign:ColorZone.RenderTransform>
                                </materialDesign:ColorZone>
                            </Grid>

                            <Grid x:Name="PART_GridWrapper" ClipToBounds="True"
                                Height="{DynamicResource IslandContainerHeight}"
                                SnapsToDevicePixels="True"
                                Style="{StaticResource DockingStyle}">

                                <Grid Height="{DynamicResource IslandContainerHeight}"
                                    x:Name="GridContentRoot"
                                    Margin="12 0">
                                    <ContentPresenter
                                        Content="{Binding Content, RelativeSource={RelativeSource AncestorType=controls:MainWindowLine}}" />
                                </Grid>
                            
                                <!-- Overlay View -->
                                <Grid x:Name="GridOverlay"
                                    SnapsToDevicePixels="True"
                                    ClipToBounds="True"
                                    Margin="15 8"
                                    Opacity="0">
                                    <Border Background="{DynamicResource MaterialDesignBackground}"
                                            CornerRadius="8"
                                            Opacity="{Binding ViewModel.Settings.Opacity, RelativeSource={RelativeSource AncestorType=classIsland:MainWindow}}"/>
                                    <Border ClipToBounds="True">
                                        <ProgressBar VerticalAlignment="Bottom"
                                                    Maximum="1"
                                                    Value="{Binding NotificationProgressBarValue, RelativeSource={RelativeSource AncestorType=classIsland:MainWindow}}"
                                                    x:Name="OverlayTimeProgressBar"
                                                    materialDesign:TransitionAssist.DisableTransitions="True"
                                                    Height="3"
                                                    Foreground="{DynamicResource PrimaryHueMidBrush}"
                                                    Background="Transparent"
                                                    BorderBrush="Transparent">
                                            <ProgressBar.Effect>
                                                <DropShadowEffect BlurRadius="12" ShadowDepth="0" Opacity="1"  Color="{Binding Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ProgressBar}, Converter={StaticResource SolidColorBrushToColorConverter}}"/>
                                            </ProgressBar.Effect>
                                        </ProgressBar>
                                    </Border>
                                    <ContentPresenter
                                        Content="{Binding ViewModel.CurrentOverlayElement, RelativeSource={RelativeSource FindAncestor, AncestorType=classIsland:MainWindow}}" />

                                </Grid>

                                <!-- Mask -->
                                <materialDesign:ColorZone x:Name="OverlayMask" Mode="PrimaryMid" HorizontalAlignment="Stretch"
                                                        VerticalAlignment="Stretch"
                                                        RenderTransformOrigin="0.5,0.5"
                                                        SnapsToDevicePixels="True"
                                                        CornerRadius="8"
                                                        Margin="15 8"
                                                        Opacity="0">
                                    <materialDesign:ColorZone.Background>
                                        <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                                            <GradientStop Color="{Binding Data, Source={StaticResource PrimaryHueLightBrushProxy}, Converter={StaticResource SolidColorBrushToColorConverter}}" Offset="0.0" />
                                            <GradientStop Color="{Binding Data, Source={StaticResource PrimaryHueMidBrushProxy}, Converter={StaticResource SolidColorBrushToColorConverter}}" Offset="1.0" />
                                        </LinearGradientBrush>
                                    </materialDesign:ColorZone.Background>
                                    <materialDesign:ColorZone.Effect>
                                        <BlurEffect Radius="0" KernelType="Gaussian"
                                                    x:Name="MaskBlurEffect"/>
                                    </materialDesign:ColorZone.Effect>
                                    <materialDesign:ColorZone.RenderTransform>
                                        <TransformGroup>
                                            <ScaleTransform />
                                            <SkewTransform />
                                            <RotateTransform />
                                            <TranslateTransform Y="0" />
                                        </TransformGroup>
                                    </materialDesign:ColorZone.RenderTransform>
                                    <ContentPresenter x:Name="OverlayMaskContent"
                                                      Content="{Binding ViewModel.CurrentMaskElement, RelativeSource={RelativeSource FindAncestor, AncestorType=classIsland:MainWindow}}" />
                                </materialDesign:ColorZone>
                            </Grid>
                        </Grid>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

    </Style>

</ResourceDictionary>