<UserControl
    x:Class="Wallet.Avalonia.MainView"
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ui="using:FluentAvalonia.UI.Controls"
    xmlns:vm="using:Wallet"
    x:DataType="vm:MainViewModel">
    <NavigationView
        FooterMenuItemsSource="{Binding Footer}"
        IsSettingsVisible="False"
        MenuItemTemplate="{Binding Template}"
        MenuItemsSource="{Binding SelectedItem}"
        SelectionFollowsFocus="True">
        <Interaction.Behaviors>
            <DataTriggerBehavior Binding="{ReflectionBinding SelectedItem.IsOpened}" Value="True">
                <InvokeNavigationViewItemAction SelectedIndex="1" />
            </DataTriggerBehavior>
            <DataTriggerBehavior Binding="{ReflectionBinding SelectedItem.IsSelected}" Value="True">
                <InvokeNavigationViewItemAction SelectedIndex="1" />
            </DataTriggerBehavior>
        </Interaction.Behaviors>
        <NavigationView.PaneHeader>
            <Border
                Margin="12,0,0,0"
                Padding="12,4,12,4"
                HorizontalAlignment="Left"
                VerticalAlignment="Center"
                Background="{DynamicResource AccentFillColorDefaultBrush}"
                CornerRadius="12">
                <TextBlock FontSize="10" Text="BETA PREVIEW 1" />
            </Border>
        </NavigationView.PaneHeader>
        <NavigationView.PaneCustomContent>
            <Grid RowDefinitions="*,Auto">
                <ListBox
                    Grid.Row="0"
                    Margin="1,2,1,0"
                    HorizontalAlignment="Center"
                    ItemTemplate="{ReflectionBinding Template}"
                    ItemsSource="{Binding}"
                    SelectedItem="{Binding SelectedItem}">
                    <ListBox.Resources>
                        <StaticResource x:Key="ListViewItemBackgroundSelected" ResourceKey="SubtleFillColorTransparentBrush" />
                        <x:Double x:Key="WalletItemSize">40</x:Double>
                        <CornerRadius x:Key="WalletItemCornerRadius">40</CornerRadius>
                        <ControlTheme x:Key="{x:Type ListBoxItem}" TargetType="ListBoxItem">
                            <Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" />
                            <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
                            <Setter Property="Background" Value="{DynamicResource ListViewItemBackground}" />
                            <Setter Property="Foreground" Value="{DynamicResource ListViewItemForeground}" />
                            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                            <Setter Property="VerticalContentAlignment" Value="Center" />
                            <Setter Property="Width" Value="{StaticResource WalletItemSize}" />
                            <Setter Property="Height" Value="{StaticResource WalletItemSize}" />
                            <Setter Property="MinHeight" Value="{StaticResource WalletItemSize}" />
                            <Setter Property="MinWidth" Value="{StaticResource WalletItemSize}" />
                            <Setter Property="CornerRadius" Value="{StaticResource WalletItemCornerRadius}" />
                            <Setter Property="Template">
                                <ControlTemplate>
                                    <Panel>
                                        <Border
                                            x:Name="PART_ContentBorder"
                                            Background="{TemplateBinding Background}"
                                            BorderBrush="{TemplateBinding BorderBrush}"
                                            BorderThickness="{TemplateBinding BorderThickness}"
                                            CornerRadius="{TemplateBinding CornerRadius}">
                                            <Grid>
                                                <ContentPresenter
                                                    Name="PART_ContentPresenter"
                                                    HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                    VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                                    Content="{TemplateBinding Content}"
                                                    ContentTemplate="{TemplateBinding ContentTemplate}" />
                                                <Border
                                                    Name="SelectionIndicator"
                                                    BorderBrush="{DynamicResource AccentFillColorDefaultBrush}"
                                                    BorderThickness="3"
                                                    CornerRadius="{TemplateBinding CornerRadius}"
                                                    IsVisible="False"
                                                    UseLayoutRounding="False" />
                                            </Grid>
                                        </Border>
                                    </Panel>
                                </ControlTemplate>
                            </Setter>
                            <Style Selector="^:disabled">
                                <Setter Property="Opacity" Value="0.5" />
                            </Style>
                            <Style Selector="^:pointerover">
                                <Style Selector="^ /template/ Border#PART_ContentBorder">
                                    <Setter Property="Background" Value="{DynamicResource ListViewItemBackgroundPointerOver}" />
                                </Style>
                                <Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
                                    <Setter Property="Foreground" Value="{DynamicResource ListViewItemForegroundPointerOver}" />
                                </Style>
                            </Style>
                            <Style Selector="^:pressed">
                                <Style Selector="^ /template/ Border#PART_ContentBorder">
                                    <Setter Property="Background" Value="{DynamicResource ListViewItemBackgroundPressed}" />
                                </Style>
                                <Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
                                    <Setter Property="Foreground" Value="{DynamicResource ListViewItemForegroundPressed}" />
                                </Style>
                            </Style>
                            <Style Selector="^:selected">
                                <Style Selector="^ /template/ Border#PART_ContentBorder">
                                    <Setter Property="Background" Value="{DynamicResource ListViewItemBackgroundSelected}" />
                                </Style>
                                <Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
                                    <Setter Property="Foreground" Value="{DynamicResource ListViewItemForegroundSelected}" />
                                </Style>
                                <Style Selector="^ /template/ Border#SelectionIndicator">
                                    <Setter Property="IsVisible" Value="True" />
                                </Style>
                                <Style Selector="^:not(:focus) /template/ Border#PART_ContentBorder">
                                    <Setter Property="Background" Value="{DynamicResource ListViewItemBackgroundSelected}" />
                                </Style>
                                <Style Selector="^:not(:focus) /template/ ContentPresenter#PART_ContentPresenter">
                                    <Setter Property="Foreground" Value="{DynamicResource ListViewItemForegroundSelected}" />
                                </Style>
                                <Style Selector="^:pointerover">
                                    <Style Selector="^ /template/ Border#PART_ContentBorder">
                                        <Setter Property="Background" Value="{DynamicResource ListViewItemBackgroundSelectedPointerOver}" />
                                    </Style>
                                    <Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
                                        <Setter Property="Foreground" Value="{DynamicResource ListViewItemForegroundSelectedPointerOver}" />
                                    </Style>
                                    <Style Selector="^ /template/ Border#SelectionIndicator">
                                        <Setter Property="BorderBrush" Value="{DynamicResource ListViewItemSelectionIndicatorPointerOverBrush}" />
                                    </Style>
                                </Style>
                                <Style Selector="^:pressed">
                                    <Style Selector="^ /template/ Border#PART_ContentBorder">
                                        <Setter Property="Background" Value="{DynamicResource ListViewItemBackgroundSelectedPressed}" />
                                    </Style>
                                    <Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
                                        <Setter Property="Foreground" Value="{DynamicResource ListViewItemForegroundSelectedPressed}" />
                                    </Style>
                                </Style>
                                <Style Selector="^:disabled /template/ Border#SelectionIndicator">
                                    <Setter Property="BorderBrush" Value="{DynamicResource ListViewItemSelectionIndicatorDisabledBrush}" />
                                </Style>
                            </Style>
                        </ControlTheme>
                    </ListBox.Resources>
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Spacing="6">
                                <StackPanel.Styles>
                                    <Style Selector="StackPanel.Closed">
                                        <Setter Property="Orientation" Value="Vertical" />
                                    </Style>
                                    <Style Selector="StackPanel.Opened">
                                        <Setter Property="Orientation" Value="Horizontal" />
                                    </Style>
                                </StackPanel.Styles>
                                <Interaction.Behaviors>
                                    <DataTriggerBehavior Binding="{Binding $parent[NavigationView].IsPaneOpen}" Value="True">
                                        <AddClassAction ClassName="Opened" RemoveIfExists="True" />
                                        <RemoveClassAction ClassName="Closed" />
                                    </DataTriggerBehavior>
                                    <DataTriggerBehavior Binding="{Binding $parent[NavigationView].IsPaneOpen}" Value="False">
                                        <AddClassAction ClassName="Closed" RemoveIfExists="True" />
                                        <RemoveClassAction ClassName="Opened" />
                                    </DataTriggerBehavior>
                                </Interaction.Behaviors>
                            </StackPanel>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                </ListBox>
                <NavigationViewItemSeparator Grid.Row="1" />
            </Grid>
        </NavigationView.PaneCustomContent>
        <NavigationView.Resources>
            <CornerRadius x:Key="NavigationViewContentGridCornerRadius">0</CornerRadius>
            <Thickness x:Key="NavigationViewContentGridBorderThickness">1,0,0,0</Thickness>
        </NavigationView.Resources>
        <Frame>
            <Interaction.Behaviors>
                <AttachedBehaviour>
                    <NavigateRegionAction Name="Main">
                        <NavigateAction Region="Main" Route="Wallet" />
                    </NavigateRegionAction>
                </AttachedBehaviour>
            </Interaction.Behaviors>
        </Frame>
    </NavigationView>
</UserControl>

