<Page
    x:Class="PCUT.Pages.MainMenuPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:PCUT.Pages"
    xmlns:converts="using:PCUT.Converters"
    xmlns:viewmodels="using:PCUT.ViewModels"
    Loading="Page_Loading"
    Loaded="Page_Loaded"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Page.Transitions>
        <TransitionCollection>
            <EntranceThemeTransition />
        </TransitionCollection>
    </Page.Transitions>

    <Page.Resources>
        <converts:BooleanToVisibilityConverter x:Key="BoolToVisConverter"/>
    </Page.Resources>

    <Page.DataContext>
        <viewmodels:MainMenuPageViewModel/>
    </Page.DataContext>
    
    <Grid>

        <Grid>
            <NavigationView
                x:Name="NavigationView"
                PaneTitle="Menu"
                PaneDisplayMode="Top"
                IsSettingsVisible="False"
                IsBackButtonVisible="Collapsed"
                ItemInvoked="NavigationViewItem_Invoked">

                <NavigationView.PaneHeader>
                    <Image Source="/Assets/logo.jpg" Stretch="Fill" Margin="10,0,10,0"/>
                </NavigationView.PaneHeader>

                <NavigationView.MenuItems>
                    <NavigationViewItem Tag="Menu" SelectsOnInvoked="False">
                        <NavigationViewItem.Icon>
                            <SymbolIcon Symbol="GlobalNavigationButton" Foreground="{ThemeResource SystemAccentColor}"/>
                        </NavigationViewItem.Icon>
                    </NavigationViewItem>
                    
                    <NavigationViewItem
                        x:Name="DataCenterNavItem"
                        Icon="SlideShow" Content="Data Center" 
                        Tag="DataCenter"
                        CornerRadius="10"
                        Background="{ThemeResource SystemAccentColor}" 
                        Margin="0,0,3,0"/>

                    <NavigationViewItem 
                        x:Name="DesignCenterNavItem"
                        Icon="Edit" Content="Design Center" 
                        Tag="DesignCenter" 
                        CornerRadius="10"
                        Background="{ThemeResource SystemAccentColor}" 
                        Margin="0,0,3,0"/>

                    <NavigationViewItem 
                        x:Name= "UserGuideNavItem" 
                        Icon="Globe" Content="User Guide"
                        Tag= "UserGuide"
                        CornerRadius= "10"
                        Background= "{ThemeResource SystemAccentColor}" 
                        Margin="0,0,3,0"/>

                    <NavigationViewItem 
                        x:Name= "AdminCenterNavItem" 
                        Icon="Admin" Content="Admin" 
                        Tag= "AdminCenter"
                        CornerRadius= "10"
                        Background= "{ThemeResource SystemAccentColor}" 
                        IsEnabled= "{Binding IsUserRoleAdmin, Mode=OneWay}"
                        Visibility="{Binding IsUserRoleAdmin, Mode=OneWay, Converter={StaticResource BoolToVisConverter}}"/>
                </NavigationView.MenuItems>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="0.2*" />
                        <ColumnDefinition Width="0.8*" />
                    </Grid.ColumnDefinitions>
                    <Frame x:Name="ContentFrame" Grid.ColumnSpan="2" Navigated="ContentFrame_Navigated"/>
                    <Grid
                        Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
                        BorderBrush="Black" BorderThickness="0,0,1,0"
                        Visibility="{Binding IsMenuDisplay, Mode=OneWay}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="0.1*"/>
                            <RowDefinition Height="0.75*"/>
                            <RowDefinition Height="0.15*"/>
                        </Grid.RowDefinitions>
                        <ListView
                            Grid.Row="1"
                            x:Name="CategoryList"
                            HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                            HorizontalContentAlignment="Center"
                            IsItemClickEnabled="True"
                            ItemsSource="{Binding Categories.Items, Mode=OneWay}"
                            SelectedIndex="{Binding Categories.SelectedIndex, Mode=OneWay}"
                            Tapped="CategoryList_Tapped">
                            <ListView.Transitions>
                                <TransitionCollection>
                                    <EntranceThemeTransition FromHorizontalOffset="0" />
                                </TransitionCollection>
                            </ListView.Transitions>
                            <ListView.Header>
                                <TextBlock Text="Categories" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5 5 5 15" FontSize="20" />
                            </ListView.Header>
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Name}"/>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                        <Grid Grid.Row="2">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="0.25*"/>
                                <RowDefinition Height="0.25*"/>
                                <RowDefinition Height="0.5*"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="0.1*"/>
                                <ColumnDefinition Width="0.25*"/>
                                <ColumnDefinition Width="0.35*"/>
                                <ColumnDefinition Width="0.1*"/>
                            </Grid.ColumnDefinitions>
                            <Border
                                Grid.Row="0" Grid.Column="1"
                                BorderBrush="Black" BorderThickness="1,1,0,0">
                                <TextBlock Text="User: " VerticalAlignment="Center" Margin="5,0,0,0"/>
                            </Border>
                            <Border
                                Grid.Row="0" Grid.Column="2"
                                BorderBrush="Black" BorderThickness="1,1,1,0">
                                <TextBlock
                                    x:Name="Username"
                                    Text="{Binding UserName, Mode=OneWay}"
                                    TextTrimming="CharacterEllipsis"
                                    VerticalAlignment="Center"
                                    HorizontalAlignment="Right"
                                    Margin="0,0,5,0"/>
                            </Border>
                            <Border
                                Grid.Row="1" Grid.Column="1"
                                BorderBrush="Black" BorderThickness="1,1,0,1">
                                <TextBlock Text="Expire: " VerticalAlignment="Center" Margin="5,0,0,0"/>
                            </Border>
                            <Border
                                Grid.Row="1" Grid.Column="2"
                                BorderBrush="Black" BorderThickness="1,1,1,1">
                                <TextBlock
                                    x:Name="UserExpire"
                                    Text="{Binding Expiry, Mode=OneWay}"
                                    TextTrimming="CharacterEllipsis"
                                    VerticalAlignment="Center"
                                    HorizontalAlignment="Right"
                                    Margin="0,0,5,0"/>
                            </Border>
                            <Button
                                Grid.Row="2" Grid.ColumnSpan="4"
                                x:Name="LogOutNavItem"
                                Tag="LogOut"
                                MinWidth="120"
                                CornerRadius= "10"
                                Background="{ThemeResource SystemAccentColor}"
                                HorizontalAlignment="Center"
                                Tapped="LogOutNavItem_Tapped">
                                <StackPanel Orientation="Horizontal">
                                    <SymbolIcon Symbol="DisconnectDrive" Margin="0,0,5,0" />
                                    <TextBlock Text="Logout" />
                                </StackPanel>
                            </Button>
                        </Grid>
                    </Grid>
                </Grid>
            </NavigationView>
        </Grid>
    </Grid>
</Page>
