<?xml version="1.0" encoding="utf-8" ?>
<views:BasePage x:Class="Italia.DiciottoApp.Views.ShopPage"
                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: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:ShopViewModel />
    </views:BasePage.BindingContext>

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

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

            <!-- Shop header-->
            <Image Grid.Row="0"
                   WidthRequest="{Binding Width, Source={x:Reference ContentGrid}}"
                   Aspect="AspectFill"
                   Source="{Binding ShopBkgndImageSource}" />

            <Label Grid.Row="0" Margin="26,22,0,0"
                   HorizontalOptions="Start"
                   VerticalOptions="Start"
                   Style="{StaticResource BoldLabelStyle}"
                   TextColor="White" FontSize="14"
                   Text="{Binding Shop.ElencoCategorie}" />

            <StackLayout Grid.Row="0" Padding="24,0,0,29" Spacing="0"
                         VerticalOptions="EndAndExpand">

                <Label Margin="0"
                       HorizontalOptions="Start"
                       Style="{StaticResource BoldLabelStyle}"
                       TextColor="White" FontSize="32"
                       Text="{Binding Shop.Title}" />

                <StackLayout Padding="0" Spacing="0"
                             Orientation="Horizontal">

                    <Image HorizontalOptions="Start" VerticalOptions="Center"
                           Source="{Binding ShopKindImageSource}"/>

                    <StackLayout Margin="11,0,0,0"
                                 VerticalOptions="CenterAndExpand"
                                 IsVisible="{Binding IsNotOnline}">

                        <Label HorizontalOptions="Start"
                               VerticalOptions="Center"
                               Style="{StaticResource ItalicLabelStyle}"
                               TextColor="White" FontSize="14"
                               Text="{Binding ShopAddress}"/>

                        <Label Margin="0,-10,0,0"
                               HorizontalOptions="Start"
                               VerticalOptions="Center"
                               Style="{StaticResource BoldItalicLabelStyle}"
                               TextColor="White" FontSize="14"
                               Text="{Binding ShopAddress2}"/>
                    </StackLayout>

                    <Label Margin="8,0,0,0" HorizontalOptions="Start"
                           VerticalOptions="Center"
                           Style="{StaticResource ItalicLabelStyle}"
                           TextColor="White" FontSize="14"
                           Text="{Binding Shop.Url}"
                           IsVisible="{Binding Shop.IsOnline}"/>
                </StackLayout>
            </StackLayout>

            <!-- Shop commands -->
            <StackLayout Grid.Row="1" Margin="0,0,0,18" Padding="0" Spacing="0">

                <!-- Bottone: nuovo buono -->
                <Frame CornerRadius="5" Padding="1"
                       HasShadow="False"
                       Margin="16,16" HeightRequest="48"
                       BackgroundColor="{StaticResource AppBkgndColor}">

                    <Frame.GestureRecognizers>
                        <TapGestureRecognizer Tapped="OnNewVoucherButtonTapped" />
                    </Frame.GestureRecognizers>

                    <StackLayout Grid.Row="1" Padding="0" Spacing="8"
                                 Orientation="Horizontal"
                                 HorizontalOptions="Center" >

                        <Image Source="plus_white" VerticalOptions="Center" />

                        <Label VerticalOptions="Center"
                               Style="{StaticResource BoldLabelStyle}" 
                               FontSize="16"
                               TextColor="White"
                               Text="NUOVO BUONO"/>
                    </StackLayout>
                </Frame>

                <!-- Bottoni per negozio fisico:  mappa e percorso -->
                <StackLayout Padding="0" Spacing="0"
                             Orientation="Horizontal"
                             HorizontalOptions="Center"
                             IsVisible="{Binding IsNotOnline}">

                    <Image VerticalOptions="Center"
                            Source="map_icon">
                        <Image.GestureRecognizers>
                            <TapGestureRecognizer Tapped="OnShowMapButtonTapped" />
                        </Image.GestureRecognizers>
                    </Image>

                    <Label Margin="12,0,0,0" VerticalOptions="Center"
                           Style="{StaticResource BoldLabelStyle}" 
                           FontSize="16"
                           TextColor="#FF0C6DCE"
                           Text="MAPPA">
                        <Label.GestureRecognizers>
                            <TapGestureRecognizer Tapped="OnShowMapButtonTapped" />
                        </Label.GestureRecognizers>
                    </Label>

                    <Image Margin="54,0,0,0"
                           VerticalOptions="Center"
                           Source="route">
                        <Image.GestureRecognizers>
                            <TapGestureRecognizer Tapped="OnRouteToShopButtonTapped" />
                        </Image.GestureRecognizers>
                    </Image>

                    <Label  Margin="12,0,0,0" VerticalOptions="Center"
                            Style="{StaticResource BoldLabelStyle}" 
                            FontSize="16"
                            TextColor="#FF0C6DCE"
                            Text="PERCORSO">
                        <Label.GestureRecognizers>
                            <TapGestureRecognizer Tapped="OnRouteToShopButtonTapped" />
                        </Label.GestureRecognizers>
                    </Label>
                </StackLayout>

                <!-- Bottone per negozio online: vai al sito -->
                <StackLayout Padding="0" Spacing="0"
                             Orientation="Horizontal"
                             HorizontalOptions="Center"
                             IsVisible="{Binding Shop.IsOnline}">
                        <StackLayout.GestureRecognizers>
                            <TapGestureRecognizer Tapped="OnGotoOnlineButtonTapped" />
                        </StackLayout.GestureRecognizers>

                    <Image VerticalOptions="Center" Source="link" />

                    <Label Margin="12,0,0,0" VerticalOptions="Center"
                           Style="{StaticResource BoldLabelStyle}" 
                           FontSize="16"
                           TextColor="#FF0C6DCE"
                           Text="VAI AL SITO DEL NEGOZIO" />
                </StackLayout>
            </StackLayout>
        </Grid>
    </views:BasePage.Content>
</views:BasePage>