<?xml version="1.0" encoding="utf-8"?>

<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:mobile="clr-namespace:InABox.Mobile;assembly=InABox.Mobile.Shared"
             x:Class="InABox.Mobile.MobileMenuButtonMenu" Padding="5">
    <ContentView.BindingContext>
        <mobile:MobileMenuButtonMenuViewModel 
            x:Name="_viewModel" 
            LayoutChanged="_viewModel_OnLayoutChanged" 
            ItemClicked="_viewModel_OnItemClicked"/>
    </ContentView.BindingContext>
    <ContentView.Content>
        <Grid 
            x:Name="_menu" 
            VerticalOptions="StartAndExpand" 
            HorizontalOptions="StartAndExpand"
            Margin="0,5,0,0"
            RowSpacing="5"
            BindableLayout.ItemsSource = "{Binding VisibleItems}"
            >
            <BindableLayout.EmptyView>
                <Label 
                    FontSize="Small"
                    Text="(No Options)"
                    TextColor="Gray"/>
            </BindableLayout.EmptyView>
            
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            
            <BindableLayout.ItemTemplate>
                <DataTemplate x:DataType="mobile:MobileMenuEntry">
                    
                    <StackLayout
                        Orientation="Vertical"
                        IsVisible="{Binding IsVisible}"
                        HorizontalOptions="Fill"
                        Grid.Row="{Binding Index}">
                        
                        <Label 
                            Text="{Binding Text}" 
                            VerticalOptions="CenterAndExpand" 
                            HorizontalOptions="Fill" 
                            HorizontalTextAlignment="Start"
                            VerticalTextAlignment="Center"
                            FontSize="Small"
                            Padding="2,5,2,2"
                            IsVisible="False"
                            TextColor="Black">
                            
                            <Label.GestureRecognizers>
                                <TapGestureRecognizer Tapped="TapGestureRecognizer_OnTapped" />
                            </Label.GestureRecognizers>    
                            
                            <Label.Triggers>
                                <DataTrigger TargetType="Label" Binding="{Binding Type}" Value="Item">
                                    <Setter Property="IsVisible" Value="True" />
                                </DataTrigger>
                            </Label.Triggers>
                            
                        </Label>
                        
                        <BoxView
                            HeightRequest="1"
                            VerticalOptions="Center"
                            HorizontalOptions="Fill"
                            BackgroundColor="Gray"
                            Opacity="0.5"
                            Margin="2,5,2,2"
                            IsVisible="False">
                            <BoxView.Triggers>
                                <DataTrigger TargetType="BoxView" Binding="{Binding Type}" Value="Separator">
                                    <Setter Property="IsVisible" Value="True" />
                                </DataTrigger>
                            </BoxView.Triggers>
                        </BoxView>
                        
                    </StackLayout>
                    
                </DataTemplate>
            </BindableLayout.ItemTemplate>
            
        </Grid>
    </ContentView.Content>
</ContentView>