<?xml version="1.0" encoding="utf-8" ?>
<views:BasePage x:Class="Italia.DiciottoApp.Views.UserNotificationsPage"
                xmlns="http://xamarin.com/schemas/2014/forms"
                xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                xmlns:views="clr-namespace:Italia.DiciottoApp.Views"
                xmlns:vm="clr-namespace:Italia.DiciottoApp.ViewModels"
                xmlns:conv="clr-namespace:Italia.DiciottoApp.Converters"
                xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" 
                ios:Page.UseSafeArea="true"
                BackgroundColor="{StaticResource AppBkgndColor}"
                ControlTemplate="{StaticResource AppHeaderTemplate}" >

    <views:BasePage.BindingContext>
        <vm:UserNotificationsViewModel />
    </views:BasePage.BindingContext>

    <views:BasePage.Resources>
        <conv:NotificationDateTimeColorConverter x:Key="NotificationDateTimeColorConverter" />
        <conv:NotificationTextColorConverter x:Key="NotificationTextColorConverter" />
    </views:BasePage.Resources>

    <views:BasePage.Content>
        <Grid BackgroundColor="{StaticResource ContentBkgndColor}"
              VerticalOptions="FillAndExpand"
              HorizontalOptions="FillAndExpand"
              RowSpacing="0" ColumnSpacing="0" >

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <!-- Content header -->
            <Label Grid.Row="0" Margin="16,10,16,0"
                   VerticalOptions="CenterAndExpand" 
                   HorizontalOptions="StartAndExpand"
                   Style="{StaticResource RegularLabelStyle}"
                   TextColor="#FFA9B1B8" FontSize="14"
                   Text="{Binding ContentHeader}" />

            <!-- UserNotification list -->
            <ListView Grid.Row="1" Margin="0,16,16,0"
                      ItemsSource="{Binding UserNotifications, Mode=OneWay}"
                      HasUnevenRows="true"
                      Footer=""
                      IsVisible="{Binding NotificationListIsVisible}">
                
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout Padding="0" Spacing="0"
                                         HorizontalOptions="FillAndExpand">

                                <Label Margin="16,11,0,0"
                                       Style="{StaticResource RegularLabelStyle}"
                                       HorizontalOptions="Start" VerticalOptions="Start"
                                       TextColor="{Binding IsNewMsg, Converter={StaticResource NotificationDateTimeColorConverter}}"
                                       FontSize="14"
                                       Text="{Binding MsgDateTime}" />

                                <StackLayout Margin="16,0,0,10"
                                             Padding="0" Spacing="0"
                                             Orientation="Horizontal"
                                             HorizontalOptions="FillAndExpand"
                                             VerticalOptions="Center">

                                    <Label Margin="0,0,0,0"
                                           HorizontalOptions="StartAndExpand"
                                           VerticalOptions="Center"
                                           Style="{StaticResource RegularLabelStyle}"
                                           TextColor="{Binding IsNewMsg, Converter={StaticResource NotificationTextColorConverter}}"
                                           FontSize="14"
                                           Text="{Binding MsgText}" />

                                    <Image Margin="0,0,6,0"
                                       HorizontalOptions="End"
                                       VerticalOptions="Center"
                                       Source="{Binding MsgImage}"/>
                                </StackLayout>
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </Grid>
    </views:BasePage.Content>
</views:BasePage>