<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="eShopOnContainers.Core.Views.ProfileView"    
             xmlns:views="clr-namespace:eShopOnContainers.Core.Views;assembly=eShopOnContainers.Core"       
             xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
             xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"      
             Title="My profile">
    <ContentPage.Resources>
        <ResourceDictionary>

            <Style x:Key="LoginButtonStyle" 
               TargetType="{x:Type Label}">
                <Setter Property="FontFamily"
                        Value="{StaticResource MontserratRegular}" />
                <Setter Property="TextColor"
                        Value="{StaticResource WhiteColor}" />
                <Setter Property="HorizontalOptions"
                        Value="Center" />
                <Setter Property="VerticalOptions"
                        Value="Center" />
            </Style>
            
            <Style x:Key="MyOrdersLabelStyle" 
               TargetType="{x:Type Label}">
                <Setter Property="FontFamily"
                        Value="{StaticResource MontserratRegular}" />
                <Setter Property="FontSize"
                        Value="{StaticResource MediumSize}" />
                <Setter Property="HorizontalOptions"
                        Value="Center" />
                <Setter Property="VerticalOptions"
                        Value="Center" />
                <Setter Property="Margin"
                        Value="0, 12" />
            </Style>
            
        </ResourceDictionary>
    </ContentPage.Resources>
    <Grid    
        Padding="0"     
        ColumnSpacing="0"   
        RowSpacing="0"
        BackgroundColor="{StaticResource BackgroundColor}">
        <Grid.RowDefinitions>
            <RowDefinition Height="60" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <!-- LOG OUT BUTTON -->
        <Button         
            Grid.Row="0"
            Text="LOG OUT" 
            TextColor="{StaticResource BlackColor}"
            BackgroundColor="{StaticResource GrayColor}"
            Command="{Binding LogoutCommand}" />
        <!-- ORDERS -->
        <Grid
            Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Label 
                Grid.Row="0"
                Text="MY ORDERS"
                Style="{StaticResource MyOrdersLabelStyle}"/>
            <Grid 
                Grid.Row="1">
                <Grid 
                    IsVisible="{Binding IsBusy, Converter={StaticResource InverseBoolConverter}}">
                    <Label 
                        Text="NO ORDERS"      
                        IsVisible="{Binding Orders.Count, Converter={StaticResource InverseCountToBoolConverter}}"
                        HorizontalOptions="Center"
                        VerticalOptions="Center"/>
                </Grid>
                <ListView 
                    ItemsSource="{Binding Orders}"
                    HasUnevenRows="True"
                    SeparatorVisibility="None"
                    CachingStrategy="RecycleElement">
                    <ListView.Behaviors>
                        <behaviors:EventToCommandBehavior           
                            EventName="ItemTapped"
                            Command="{Binding OrderDetailCommand}"
                            EventArgsConverter="{StaticResource ItemTappedEventArgsConverter}" />
                    </ListView.Behaviors>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <templates:OrderTemplate />
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </Grid>
        </Grid>
    </Grid>
</ContentPage>