<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:reskeys="clr-namespace:PixiEditor.Styles.AvalonDock.Themes.Menu">

	<!--  Source https://github.com/Dirkster99/MLib/blob/master/source/Components/MLib/Controls/Menu/ContextMenu.xaml  -->
	<ControlTemplate x:Key="MLibMenuItem" TargetType="{x:Type MenuItem}">
		<ControlTemplate.Resources>
			<Geometry x:Key="Checkmark">M 0,5.1 L 1.7,5.2 L 3.4,7.1 L 8,0.4 L 9.2,0 L 3.3,10.8 Z</Geometry>
		</ControlTemplate.Resources>
		<!--  Border 1 Item with Submenu underneath  -->
		<Border
			x:Name="Border"
			Background="Transparent"
			BorderBrush="Transparent"
			BorderThickness="{TemplateBinding BorderThickness}"
			SnapsToDevicePixels="True">
			<Grid x:Name="Grid">
				<Grid.ColumnDefinitions>
					<ColumnDefinition
						x:Name="Col0"
						Width="Auto"
						MinWidth="17"
						SharedSizeGroup="MenuItemIconColumnGroup" />
					<ColumnDefinition Width="Auto" SharedSizeGroup="MenuTextColumnGroup" />
					<ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIGTColumnGroup" />
					<ColumnDefinition x:Name="Col3" Width="*" />
				</Grid.ColumnDefinitions>

				<ContentPresenter
					x:Name="Icon"
					Grid.Column="0"
					Margin="2,0,2,0"
					VerticalAlignment="Center"
					ContentSource="Icon" />

				<Border
					x:Name="GlyphPanel"
					Width="18"
					Height="18"
					Margin="2,0,2,0"
					HorizontalAlignment="Center"
					Background="{DynamicResource {x:Static reskeys:MenuKeys.CheckMarkBackgroundBrushKey}}"
					BorderBrush="{DynamicResource {x:Static reskeys:MenuKeys.CheckMarkBorderBrushKey}}"
					BorderThickness="2"
					CornerRadius="0"
					Visibility="Collapsed">

					<Path
						x:Name="Glyph"
						Width="9"
						Height="11"
						HorizontalAlignment="Center"
						Data="{StaticResource Checkmark}"
						Fill="{DynamicResource {x:Static reskeys:MenuKeys.CheckMarkForegroundBrushKey}}"
						FlowDirection="LeftToRight" />
				</Border>

				<ContentPresenter
					x:Name="HeaderHost"
					Grid.Column="1"
					Margin="{TemplateBinding Padding}"
					VerticalAlignment="Center"
					ContentSource="Header"
					RecognizesAccessKey="True" />

				<ContentPresenter
					x:Name="IGTHost"
					Grid.Column="2"
					Margin="8,1,8,1"
					VerticalAlignment="Center"
					ContentSource="InputGestureText" />

				<Grid
					x:Name="ArrowPanel"
					Grid.Column="3"
					Margin="4,0,6,0"
					HorizontalAlignment="Stretch"
					VerticalAlignment="Center">
					<Path
						x:Name="ArrowPanelPath"
						HorizontalAlignment="Right"
						VerticalAlignment="Center"
						Data="M0,0 L0,8 L4,4 z"
						Fill="{TemplateBinding Foreground}" />
				</Grid>
				<Popup
					x:Name="SubMenuPopup"
					AllowsTransparency="True"
					Focusable="false"
					HorizontalOffset="-1"
					IsOpen="{Binding Path=IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
					Placement="Right"
					PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}">
					<Grid Margin="0,0,5,5">
						<!--  Border 2  -->
						<Border
							x:Name="SubMenuBorder"
							Background="{DynamicResource {x:Static reskeys:MenuKeys.SubmenuItemBackgroundKey}}"
							BorderBrush="{DynamicResource {x:Static reskeys:MenuKeys.MenuSeparatorBorderBrushKey}}"
							BorderThickness="1"
							Effect="{DynamicResource {x:Static reskeys:MenuKeys.DropShadowEffectKey}}"
							SnapsToDevicePixels="True">
							<Grid
								x:Name="SubMenu"
								Margin="2"
								Grid.IsSharedSizeScope="True">
								<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" />
							</Grid>
						</Border>
						<!--  Border 3  -->
						<Border
							x:Name="TransitionBorder"
							Width="0"
							Height="2"
							Margin="1,0,0,0"
							HorizontalAlignment="Left"
							VerticalAlignment="Top"
							Background="{DynamicResource {x:Static reskeys:MenuKeys.SubmenuItemBackgroundKey}}"
							BorderBrush="{DynamicResource {x:Static reskeys:MenuKeys.SubmenuItemBackgroundKey}}"
							BorderThickness="1"
							SnapsToDevicePixels="False" />
					</Grid>
				</Popup>
			</Grid>
		</Border>
		<ControlTemplate.Triggers>
			<!--  A menu entry with check mark cannot have an icon  -->
			<Trigger Property="IsChecked" Value="true">
				<Setter TargetName="GlyphPanel" Property="Visibility" Value="Visible" />
				<Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
			</Trigger>

			<!--<Trigger Property="Role" Value="TopLevelHeader">
                                    <Setter Property="Padding" Value="6,0,6,2"/>
                                    <Setter TargetName="SubMenuPopup" Property="Placement" Value="Bottom"/>
                                    <Setter TargetName="Col0" Property="MinWidth" Value="0"/>
                                    <Setter TargetName="Col3" Property="Width" Value="Auto"/>
                                    <Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
                                    <Setter TargetName="IGTHost" Property="Visibility" Value="Collapsed" />
                                    <Setter TargetName="ArrowPanel" Property="Visibility" Value="Collapsed"/>
                                    <Setter TargetName="SubMenuBorder" Property="BorderThickness" Value="1,1,1,1"/>
                                    <Setter TargetName="SubMenu" Property="Margin" Value="2,3,2,2"/>
                                    <Setter TargetName="TransitionBorder" Property="Width" Value="{Binding ActualWidth, ElementName=Grid}"/>
                                </Trigger>
                                <Trigger Property="Role" Value="TopLevelItem">
                                    <Setter Property="Padding" Value="6,0,6,2"/>
                                    <Setter TargetName="Col0" Property="MinWidth" Value="0"/>
                                    <Setter TargetName="Col3" Property="Width" Value="Auto"/>
                                    <Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
                                    <Setter TargetName="IGTHost" Property="Visibility" Value="Collapsed"/>
                                    <Setter TargetName="ArrowPanel" Property="Visibility" Value="Collapsed"/>
                                </Trigger>-->
			<Trigger Property="Role" Value="SubmenuHeader">
				<Setter Property="DockPanel.Dock" Value="Top" />
				<Setter Property="Padding" Value="10,3,0,3" />
				<Setter TargetName="Border" Property="MinHeight" Value="22" />
				<Setter TargetName="Border" Property="Background" Value="{DynamicResource {x:Static reskeys:MenuKeys.SubmenuItemBackgroundKey}}" />
			</Trigger>
			<Trigger Property="Role" Value="SubmenuItem">
				<Setter Property="DockPanel.Dock" Value="Top" />
				<Setter Property="Padding" Value="10,3,0,3" />
				<Setter TargetName="Border" Property="MinHeight" Value="22" />
				<Setter TargetName="ArrowPanel" Property="Visibility" Value="Collapsed" />
				<Setter TargetName="Border" Property="Background" Value="{DynamicResource {x:Static reskeys:MenuKeys.SubmenuItemBackgroundKey}}" />
			</Trigger>
			<Trigger Property="IsHighlighted" Value="True">
				<!--  Border Applies to item with sub-menu attached to it  -->
				<Setter TargetName="Border" Property="Background" Value="{DynamicResource {x:Static reskeys:MenuKeys.ItemBackgroundHoverKey}}" />
			</Trigger>
			<!-- MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsHighlighted" Value="true"/>
                    <Condition Property="Role" Value="TopLevelHeader"/>
                </MultiTrigger.Conditions>
                <Setter TargetName="Border" Property="Background" Value="{DynamicResource {x:Static reskeys:MenuKeys.MenuItemHighlightedBackgroundKey}}"/>
            </>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsHighlighted" Value="true"/>
                    <Condition Property="Role" Value="TopLevelItem"/>
                </MultiTrigger.Conditions>
                <Setter TargetName="Border" Property="Background" Value="{DynamicResource {x:Static reskeys:MenuKeys.MenuItemHighlightedBackgroundKey}}"/>
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsHighlighted" Value="true"/>
                    <Condition Property="Role" Value="SubmenuHeader"/>
                </MultiTrigger.Conditions>
                <Setter TargetName="Border" Property="Background" Value="{DynamicResource {x:Static reskeys:MenuKeys.SubmenuItemBackgroundHighlightedKey}}"/>
                <Setter TargetName="Border" Property="Background" Value="{DynamicResource {x:Static reskeys:MenuKeys.SubmenuItemBackgroundHighlightedKey}}"/>
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsHighlighted" Value="true"/>
                    <Condition Property="Role" Value="SubmenuItem"/>
                </MultiTrigger.Conditions>
                <Setter TargetName="Border" Property="Background" Value="{DynamicResource {x:Static reskeys:MenuKeys.SubmenuItemBackgroundHighlightedKey}}"/>
            </MultiTrigger-->
			<MultiTrigger>
				<MultiTrigger.Conditions>
					<Condition Property="IsSubmenuOpen" Value="true" />
					<Condition Property="Role" Value="TopLevelHeader" />
				</MultiTrigger.Conditions>
				<Setter TargetName="Border" Property="Background" Value="{DynamicResource {x:Static reskeys:MenuKeys.SubmenuItemBackgroundKey}}" />
				<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource {x:Static reskeys:MenuKeys.MenuSeparatorBorderBrushKey}}" />
				<Setter TargetName="Border" Property="BorderThickness" Value="1,1,1,0" />
			</MultiTrigger>
			<Trigger Property="IsSubmenuOpen" Value="true">
				<Setter TargetName="ArrowPanelPath" Property="Fill" Value="{DynamicResource {x:Static reskeys:MenuKeys.ItemBackgroundSelectedKey}}" />
			</Trigger>
			<Trigger Property="IsSuspendingPopupAnimation" Value="true">
				<Setter TargetName="SubMenuPopup" Property="PopupAnimation" Value="None" />
			</Trigger>
			<Trigger Property="Icon" Value="{x:Null}">
				<Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
			</Trigger>
			<Trigger Property="IsEnabled" Value="False">
				<Setter Property="Foreground" Value="{DynamicResource {x:Static reskeys:MenuKeys.ItemTextDisabledKey}}" />
				<Setter TargetName="GlyphPanel" Property="Background" Value="{DynamicResource {x:Static reskeys:MenuKeys.DisabledSubMenuItemBackgroundBrushKey}}" />
				<Setter TargetName="GlyphPanel" Property="BorderBrush" Value="{DynamicResource {x:Static reskeys:MenuKeys.DisabledSubMenuItemBorderBrushKey}}" />
			</Trigger>
		</ControlTemplate.Triggers>
	</ControlTemplate>

</ResourceDictionary>