<ResourceDictionary
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:converters="clr-namespace:Ursa.Themes.Semi.Converters"
    xmlns:u="https://irihi.tech/ursa">
    <!--  Add Resources Here  -->

    <converters:NavigationMenuItemLevelToMarginConverter x:Key="MarginConverter" Indent="8" />

    <ControlTheme x:Key="{x:Type u:NavigationMenu}" TargetType="u:NavigationMenu">
        <Setter Property="VerticalAlignment" Value="Stretch" />
        <Setter Property="Template">
            <ControlTemplate TargetType="u:NavigationMenu">
                <Border
                    Name="PART_RootBorder"
                    Width="{DynamicResource NavigationMenuExpandWidth}"
                    HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    CornerRadius="{TemplateBinding CornerRadius}">
                    <Border.Transitions>
                        <Transitions>
                            <DoubleTransition Property="Width" Duration="0:0:0.1" />
                        </Transitions>
                    </Border.Transitions>
                    <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
                        <Grid
                            Name="PART_RootGrid"
                            HorizontalAlignment="Stretch"
                            Background="{TemplateBinding Background}"
                            RowDefinitions="Auto, *, Auto, Auto">
                            <StackPanel
                                Margin="{DynamicResource NavigationMenuHeaderMargin}"
                                HorizontalAlignment="Center"
                                Orientation="Horizontal">
                                <ContentPresenter
                                    Name="PART_IconPresenter"
                                    Margin="{DynamicResource NavigationMenuIconMargin}"
                                    VerticalAlignment="Center"
                                    Content="{TemplateBinding Icon}" />
                                <ContentPresenter
                                    Name="PART_HeaderPresenter"
                                    VerticalAlignment="Center"
                                    Content="{TemplateBinding Header}"
                                    ContentTemplate="{TemplateBinding HeaderTemplate}" />

                            </StackPanel>
                            <ItemsPresenter Grid.Row="1" ItemsPanel="{TemplateBinding ItemsPanel}" />
                            <ContentPresenter
                                Name="PART_FooterPresenter"
                                Grid.Row="2"
                                Content="{TemplateBinding Footer}"
                                ContentTemplate="{TemplateBinding FooterTemplate}" />
                            <ToggleSwitch
                                Name="{x:Static u:NavigationMenu.PART_CloseButton}"
                                Grid.Row="3"
                                Content="Open"
                                IsChecked="{TemplateBinding IsClosed,
                                                            Mode=TwoWay}"
                                IsVisible="{TemplateBinding ShowCollapseButton}"
                                Theme="{DynamicResource ButtonToggleSwitch}">
                                <ToggleSwitch.OnContent>
                                    <PathIcon
                                        Width="{DynamicResource NavigationMenuExpandIconWidth}"
                                        Height="{DynamicResource NavigationMenuExpandIconHeight}"
                                        Data="{DynamicResource NavigationMenuExpandIconGlyph}"
                                        Foreground="{DynamicResource ButtonDefaultTertiaryForeground}" />
                                </ToggleSwitch.OnContent>
                                <ToggleSwitch.OffContent>
                                    <PathIcon
                                        Width="{DynamicResource NavigationMenuExpandIconWidth}"
                                        Height="{DynamicResource NavigationMenuExpandIconHeight}"
                                        Data="{DynamicResource NavigationMenuExpandIconGlyph}"
                                        Foreground="{DynamicResource ButtonDefaultTertiaryForeground}" />
                                </ToggleSwitch.OffContent>
                            </ToggleSwitch>
                        </Grid>
                    </ScrollViewer>
                </Border>
            </ControlTemplate>
        </Setter>
        <Style Selector="^:closed">
            <Style Selector="^ /template/ ContentPresenter#PART_HeaderPresenter">
                <Setter Property="ContentPresenter.IsVisible" Value="False" />
            </Style>
            <Style Selector="^ /template/ Border#PART_RootBorder">
                <Setter Property="Border.Width" Value="{DynamicResource NavigationMenuClosedWidth}" />
            </Style>
            <Style Selector="^ /template/ ContentPresenter#PART_IconPresenter">
                <Setter Property="Grid.HorizontalAlignment" Value="Center" />
            </Style>
        </Style>
    </ControlTheme>

    <ControlTheme x:Key="{x:Type u:NavigationMenuItem}" TargetType="u:NavigationMenuItem">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Template">
            <ControlTemplate TargetType="u:NavigationMenuItem">
                <Border>
                    <StackPanel>
                        <Border
                            Name="PART_HeaderBorder"
                            Margin="{DynamicResource NavigationMenuItemDefaultMargin}"
                            Padding="{DynamicResource NavigationMenuItemDefaultPadding}"
                            Background="{DynamicResource NavigationMenuItemDefaultBackground}"
                            CornerRadius="{DynamicResource NavigationMenuItemDefaultCornerRadius}">
                            <Grid
                                Name="PART_RootStackPanel"
                                HorizontalAlignment="Stretch"
                                ColumnDefinitions="Auto, Auto, *, Auto">
                                <ContentPresenter
                                    Name="PART_IconPresenter"
                                    Grid.Column="1"
                                    MinWidth="{DynamicResource NavigationMenuItemIconMinWidth}"
                                    Content="{TemplateBinding Icon}"
                                    ContentTemplate="{TemplateBinding IconTemplate}">
                                    <ContentPresenter.Margin>
                                        <MultiBinding Converter="{StaticResource MarginConverter}">
                                            <Binding Path="Level" RelativeSource="{RelativeSource TemplatedParent}" />
                                            <Binding Path="IsClosed" RelativeSource="{RelativeSource TemplatedParent}" />
                                        </MultiBinding>
                                    </ContentPresenter.Margin>
                                </ContentPresenter>
                                <ContentPresenter
                                    Name="PART_HeaderPresenter"
                                    Grid.Column="2"
                                    Margin="{DynamicResource NavigationMenuItemHeaderMargin}"
                                    VerticalAlignment="Center"
                                    Background="{TemplateBinding Background}"
                                    Content="{TemplateBinding Header}"
                                    ContentTemplate="{TemplateBinding HeaderTemplate}">
                                    <ContentPresenter.Transitions>
                                        <Transitions>
                                            <DoubleTransition Property="Opacity" Duration="0:0:0.15" />
                                        </Transitions>
                                    </ContentPresenter.Transitions>
                                </ContentPresenter>
                                <PathIcon
                                    Name="PART_ExpandIcon"
                                    Grid.Column="3"
                                    Width="{DynamicResource NavigationMenuItemExpandIconWidth}"
                                    Height="{DynamicResource NavigationMenuItemExpandIconHeight}"
                                    Data="{DynamicResource NavigationMenuItemExpandIconGlyph}"
                                    Foreground="{DynamicResource NavigationMenuItemExpandIconForeground}">
                                    <PathIcon.Transitions>
                                        <Transitions>
                                            <TransformOperationsTransition Property="RenderTransform" Duration="0.1" />
                                        </Transitions>
                                    </PathIcon.Transitions>
                                </PathIcon>
                            </Grid>
                        </Border>
                        <ItemsPresenter Name="PART_ItemsPresenter" ItemsPanel="{TemplateBinding ItemsPanel}">
                            <ItemsPresenter.Transitions>
                                <Transitions>
                                    <DoubleTransition Property="Opacity" Duration="0:0:0.15" />
                                </Transitions>
                            </ItemsPresenter.Transitions>
                        </ItemsPresenter>
                    </StackPanel>
                </Border>
            </ControlTemplate>
        </Setter>

        <Style Selector="^ /template/ Border#PART_HeaderBorder:pointerover">
            <Setter Property="Border.Background" Value="{DynamicResource NavigationMenuItemPointeroverBackground}" />
        </Style>
        <Style Selector="^ /template/ Border#PART_HeaderBorder:pressed">
            <Setter Property="Border.Background" Value="{DynamicResource NavigationMenuItemPressedBackground}" />
        </Style>

        <Style Selector="^:highlighted /template/ ContentPresenter#PART_IconPresenter">
            <Setter Property="u:NavigationMenuItem.Foreground" Value="{DynamicResource NavigationMenuItemHighlightForeground}" />
        </Style>

        <Style Selector="^:selected /template/ Border#PART_HeaderBorder">
            <Setter Property="u:NavigationMenuItem.Background" Value="{DynamicResource NavigationMenuItemSelectedBackground}" />
        </Style>

        <Style Selector="^:empty:closed:top-level">
            <Setter Property="Template">
                <ControlTemplate TargetType="u:NavigationMenuItem">
                    <Border
                        Name="PART_HeaderBorder"
                        Margin="{DynamicResource NavigationMenuItemDefaultMargin}"
                        Padding="{DynamicResource NavigationMenuItemDefaultPadding}"
                        HorizontalAlignment="Center"
                        Background="{DynamicResource NavigationMenuItemDefaultBackground}"
                        CornerRadius="{DynamicResource NavigationMenuItemDefaultCornerRadius}"
                        ToolTip.ShowDelay="0"
                        ToolTip.Tip="{TemplateBinding Header}">
                        <ContentPresenter
                            Name="PART_IconPresenter"
                            Grid.Column="1"
                            MinWidth="{DynamicResource NavigationMenuItemIconMinWidth}"
                            Margin="{DynamicResource NavigationMenuItemIconMargin}"
                            Content="{TemplateBinding Icon}"
                            ContentTemplate="{TemplateBinding IconTemplate}" />
                    </Border>
                </ControlTemplate>
            </Setter>
            <Style Selector="^ /template/ Border#PART_HeaderBorder:pointerover">
                <Setter Property="Border.Background" Value="{DynamicResource NavigationMenuItemPointeroverBackground}" />
            </Style>
            <Style Selector="^ /template/ Border#PART_HeaderBorder:pressed">
                <Setter Property="Border.Background" Value="{DynamicResource NavigationMenuItemPressedBackground}" />
            </Style>
        </Style>

        <Style Selector="^:not(:empty):closed">
            <Setter Property="Template">
                <ControlTemplate TargetType="u:NavigationMenuItem">
                    <Panel>
                        <Border
                            Name="PART_HeaderBorder"
                            Margin="{DynamicResource NavigationMenuItemDefaultMargin}"
                            Padding="{DynamicResource NavigationMenuItemDefaultPadding}"
                            HorizontalAlignment="Center"
                            Background="{DynamicResource NavigationMenuItemDefaultBackground}"
                            CornerRadius="{DynamicResource NavigationMenuItemDefaultCornerRadius}">
                            <Grid HorizontalAlignment="Stretch" ColumnDefinitions="Auto, *, Auto">
                                <ContentPresenter
                                    Name="PART_IconPresenter"
                                    Grid.Column="0"
                                    MinWidth="{DynamicResource NavigationMenuItemIconMinWidth}"
                                    Content="{TemplateBinding Icon}"
                                    ContentTemplate="{TemplateBinding IconTemplate}" />
                                <ContentPresenter
                                    Name="PART_HeaderPresenter"
                                    Grid.Column="1"
                                    Margin="{DynamicResource NavigationMenuItemHeaderMargin}"
                                    VerticalAlignment="Center"
                                    Background="{TemplateBinding Background}"
                                    Content="{TemplateBinding Header}"
                                    ContentTemplate="{TemplateBinding HeaderTemplate}"
                                    IsVisible="{TemplateBinding IsTopLevelMenuItem,
                                                                Converter={x:Static BoolConverters.Not}}" />
                                <PathIcon
                                    Grid.Column="2"
                                    Width="{DynamicResource NavigationMenuItemExpandIconWidth}"
                                    Height="{DynamicResource NavigationMenuItemExpandIconHeight}"
                                    Margin="{DynamicResource NavigationMenuItemExpandIconMargin}"
                                    Data="{DynamicResource NavigationMenuItemExpandIconGlyph}"
                                    Foreground="{DynamicResource NavigationMenuItemExpandIconForeground}"
                                    IsVisible="{TemplateBinding IsTopLevelMenuItem,
                                                                Converter={x:Static BoolConverters.Not}}"
                                    RenderTransform="rotate(-90deg)" />
                            </Grid>
                        </Border>
                        <Popup
                            Name="{x:Static u:NavigationMenuItem.PART_Popup}"
                            IsLightDismissEnabled="True"
                            IsOpen="{TemplateBinding IsPopupOpen,
                                                     Mode=TwoWay}"
                            Placement="RightEdgeAlignedTop"
                            PlacementTarget="PART_HeaderBorder"
                            WindowManagerAddShadowHint="False">
                            <Border
                                MinWidth="{DynamicResource MenuFlyoutMinWidth}"
                                MinHeight="{DynamicResource MenuFlyoutMinHeight}"
                                MaxWidth="{DynamicResource MenuFlyoutMaxWidth}"
                                MaxHeight="{DynamicResource MenuFlyoutMaxHeight}"
                                Margin="{DynamicResource NavigationMenuItemFlyoutMargin}"
                                Padding="{DynamicResource MenuFlyoutPadding}"
                                HorizontalAlignment="Stretch"
                                Background="{DynamicResource MenuFlyoutBackground}"
                                BorderBrush="{DynamicResource MenuFlyoutBorderBrush}"
                                BorderThickness="{DynamicResource MenuFlyoutBorderThickness}"
                                BoxShadow="{DynamicResource MenuFlyoutBorderBoxShadow}"
                                CornerRadius="{DynamicResource MenuFlyoutCornerRadius}">
                                <ScrollViewer Theme="{DynamicResource MenuScrollViewer}">
                                    <ItemsPresenter
                                        Name="PART_ItemsPresenter"
                                        Grid.IsSharedSizeScope="True"
                                        ItemsPanel="{TemplateBinding ItemsPanel}" />
                                </ScrollViewer>
                            </Border>
                        </Popup>
                    </Panel>
                </ControlTemplate>
            </Setter>
            <Style Selector="^ /template/ Border#PART_HeaderBorder:pointerover">
                <Setter Property="Border.Background" Value="{DynamicResource NavigationMenuItemPointeroverBackground}" />
            </Style>
            <Style Selector="^ /template/ Border#PART_HeaderBorder:pressed">
                <Setter Property="Border.Background" Value="{DynamicResource NavigationMenuItemPressedBackground}" />
            </Style>
        </Style>

        <Style Selector="^:not(:closed):collapsed /template/ ItemsPresenter#PART_ItemsPresenter">
            <Setter Property="ItemsPresenter.Height" Value="{DynamicResource NavigationMenuItemCollapsedHeight}" />
            <Setter Property="ItemsPresenter.Opacity" Value="{DynamicResource NavigationMenuItemCollapsedOpacity}" />
        </Style>
        <Style Selector="^:not(:empty):not(:collapsed) /template/ PathIcon#PART_ExpandIcon">
            <Setter Property="PathIcon.RenderTransform" Value="rotate(-180deg)" />
        </Style>
        <Style Selector="^:empty /template/ PathIcon#PART_ExpandIcon">
            <Setter Property="PathIcon.IsVisible" Value="False" />
        </Style>
    </ControlTheme>

    <ControlTheme x:Key="{x:Type u:NavigationMenuSeparator}" TargetType="u:NavigationMenuSeparator">
        <Setter Property="Template">
            <ControlTemplate TargetType="u:NavigationMenuSeparator">
                <StackPanel Name="PART_RootPanel" Margin="{DynamicResource NavigationMenuSeparatorMargin}">
                    <ContentPresenter
                        Name="PART_HeaderPresenter"
                        Margin="{DynamicResource NavigationMenuSeparatorHeaderMargin}"
                        HorizontalAlignment="Left"
                        Content="{TemplateBinding Header}"
                        ContentTemplate="{TemplateBinding HeaderTemplate}"
                        Foreground="{DynamicResource TextBlockQuaternaryForeground}"
                        IsVisible="{TemplateBinding Header,
                                                    Converter={x:Static ObjectConverters.IsNotNull}}">
                        <ContentPresenter.Styles>
                            <Style Selector="TextBlock">
                                <Setter Property="FontSize" Value="{DynamicResource NavigationMenuSeparatorHeaderFontSize}" />
                            </Style>
                        </ContentPresenter.Styles>
                    </ContentPresenter>
                    <Rectangle
                        Height="{DynamicResource NavigationMenuSeparatorBorderHeight}"
                        Margin="{DynamicResource NavigationMenuSeparatorBorderMargin}"
                        HorizontalAlignment="Stretch"
                        Fill="{DynamicResource SemiColorBorder}" />
                </StackPanel>
            </ControlTemplate>
        </Setter>
        <Style Selector="^:closed /template/ StackPanel#PART_RootPanel">
            <Setter Property="StackPanel.HorizontalAlignment" Value="Center" />
            <Setter Property="StackPanel.Width" Value="{DynamicResource NavigationMenuSeparatorClosedWidth}" />
        </Style>
        <Style Selector="^:closed /template/ ContentPresenter#PART_HeaderPresenter">
            <Setter Property="ContentPresenter.IsVisible" Value="False" />
        </Style>
    </ControlTheme>
</ResourceDictionary>
