<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:r="clr-namespace:Billing.Languages"
             xmlns:ui="clr-namespace:Billing.UI"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Billing.UI.BillingDate"
             x:DataType="ui:BillingDate"
             x:Name="billingDate"
             BindingContext="{x:Reference billingDate}">
    <ContentView.Resources>
        <Style x:Key="centerLabel" TargetType="Label">
            <Setter Property="HorizontalOptions" Value="Center"/>
            <Setter Property="FontSize" Value="Small"/>
            <Setter Property="TextColor" Value="{DynamicResource TextColor}"/>
        </Style>
        <Style x:Key="dateLabel" TargetType="Label">
            <Setter Property="HorizontalOptions" Value="Center"/>
        </Style>
        <ControlTemplate x:Key="weekDay">
            <Grid Padding="0, 8, 0, 0" RowDefinitions="Auto, 3" RowSpacing="{OnPlatform Android=0, iOS=4}">
                <Grid.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding OnDayTapped, Source={x:Reference billingDate}}" CommandParameter="{TemplateBinding BillingDay}"/>
                </Grid.GestureRecognizers>
                <Label Style="{StaticResource dateLabel}" Text="{TemplateBinding BillingDay.Text}"
                       TextColor="{DynamicResource TextColor}"
                       FontFamily="{TemplateBinding BillingDay.FontFamily}"
                       Opacity="{TemplateBinding BillingDay.TextOpacity}"/>
                <StackLayout Grid.Row="1"
                             IsVisible="{TemplateBinding BillingDay.IsSelected}"
                             BackgroundColor="{DynamicResource PrimaryColor}"
                             Opacity="{TemplateBinding BillingDay.Opacity}"/>
            </Grid>
        </ControlTemplate>
        <ControlTemplate x:Key="weekEnd">
            <Grid Padding="0, 8, 0, 0" RowDefinitions="Auto, 3" RowSpacing="{OnPlatform Android=0, iOS=4}">
                <Grid.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding OnDayTapped, Source={x:Reference billingDate}}" CommandParameter="{TemplateBinding BillingDay}"/>
                </Grid.GestureRecognizers>
                <Label Style="{StaticResource dateLabel}" Text="{TemplateBinding BillingDay.Text}"
                       TextColor="{DynamicResource RedColor}"
                       FontFamily="{TemplateBinding BillingDay.FontFamily}"
                       Opacity="{TemplateBinding BillingDay.TextOpacity}"/>
                <StackLayout Grid.Row="1"
                             IsVisible="{TemplateBinding BillingDay.IsSelected}"
                             BackgroundColor="{DynamicResource PrimaryColor}"
                             Opacity="{TemplateBinding BillingDay.Opacity}"/>
            </Grid>
        </ControlTemplate>
        <Style TargetType="ui:BillingDayView">
            <Setter Property="ControlTemplate" Value="{StaticResource weekDay}"/>
        </Style>
    </ContentView.Resources>
    <ContentView.Content>
        <Grid Padding="0, 8, 0, 4" ColumnDefinitions="*,*,*,*,*,*,*" RowDefinitions="Auto, Auto">
            <Grid.GestureRecognizers>
                <PanGestureRecognizer PanUpdated="OnPanUpdated"/>
            </Grid.GestureRecognizers>

            <Label Grid.Column="0" Text="{r:Text Sunday}" Style="{StaticResource centerLabel}"/>
            <Label Grid.Column="1" Text="{r:Text Monday}" Style="{StaticResource centerLabel}"/>
            <Label Grid.Column="2" Text="{r:Text Tuesday}" Style="{StaticResource centerLabel}"/>
            <Label Grid.Column="3" Text="{r:Text Wednesday}" Style="{StaticResource centerLabel}"/>
            <Label Grid.Column="4" Text="{r:Text Thursday}" Style="{StaticResource centerLabel}"/>
            <Label Grid.Column="5" Text="{r:Text Friday}" Style="{StaticResource centerLabel}"/>
            <Label Grid.Column="6" Text="{r:Text Saturday}" Style="{StaticResource centerLabel}"/>

            <ui:BillingDayView Grid.Row="1" Grid.Column="0" BillingDay="{Binding Sunday}" ControlTemplate="{StaticResource weekEnd}"/>
            <ui:BillingDayView Grid.Row="1" Grid.Column="1" BillingDay="{Binding Monday}"/>
            <ui:BillingDayView Grid.Row="1" Grid.Column="2" BillingDay="{Binding Tuesday}"/>
            <ui:BillingDayView Grid.Row="1" Grid.Column="3" BillingDay="{Binding Wednesday}"/>
            <ui:BillingDayView Grid.Row="1" Grid.Column="4" BillingDay="{Binding Thursday}"/>
            <ui:BillingDayView Grid.Row="1" Grid.Column="5" BillingDay="{Binding Friday}"/>
            <ui:BillingDayView Grid.Row="1" Grid.Column="6" BillingDay="{Binding Saturday}" ControlTemplate="{StaticResource weekEnd}"/>
        </Grid>
    </ContentView.Content>
</ContentView>