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

    <views:BasePage.Content>
        <Grid VerticalOptions="FillAndExpand"
              HorizontalOptions="FillAndExpand"
              RowSpacing="0" ColumnSpacing="0" >

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

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <!-- Tabs -->
            <BoxView Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3"
                     BackgroundColor="{StaticResource TabsBkgndColor}" />

            <BoxView Grid.Row="0" Grid.Column="2"
                     HeightRequest="5"
                     VerticalOptions="End"
                     BackgroundColor="White" />

            <StackLayout Grid.Row="0" Grid.Column="0" BackgroundColor="Transparent">
                <StackLayout.GestureRecognizers>
                    <TapGestureRecognizer Tapped="OnNearToYouTabTapped" />
                </StackLayout.GestureRecognizers>
                <Label Text="VICINO A TE"
                       VerticalOptions="CenterAndExpand"
                       Style="{StaticResource TabLabelStyle}" />
            </StackLayout>

            <StackLayout Grid.Row="0" Grid.Column="1" BackgroundColor="Transparent">
                <StackLayout.GestureRecognizers>
                    <TapGestureRecognizer Tapped="OnOnlineTabTapped" />
                </StackLayout.GestureRecognizers>
                <Label Text="SU INTERNET"
                       VerticalOptions="CenterAndExpand"
                       Style="{StaticResource TabLabelStyle}" />
            </StackLayout>

            <Label Grid.Row="0" Grid.Column="2"
                   Text="RICERCA"
                   Style="{StaticResource TabLabelStyle}">
            </Label>

            <!--Scelta categoria -->
            <StackLayout Grid.Row="1" Grid.ColumnSpan="3"
                         Padding="0" Spacing="0"
                         Margin="16,16,16,0"
                         HorizontalOptions="Fill" >

                <StackLayout Padding="0" Spacing="0"
                             Orientation="Horizontal"
                             HorizontalOptions="Fill">
                    <StackLayout.GestureRecognizers>
                        <TapGestureRecognizer Tapped="OnCategoryButtonTapped" />
                    </StackLayout.GestureRecognizers>

                    <Image Margin="11,0,0,0" VerticalOptions="Center" Source="funnel_gray" />

                    <Label Margin="12,0,0,0"
                           VerticalOptions="Center" HorizontalOptions="Start"
                           Style="{StaticResource BoldLabelStyle}" 
                           FontSize="16"
                           TextColor="#FF30383D"
                           Text="{Binding SelectedCategory.Titolo}"
                           IsVisible="{Binding IsCategorySelected}" />

                    <Label Margin="12,0,0,0"
                           VerticalOptions="Center" HorizontalOptions="Start"
                           Style="{StaticResource ItalicLabelStyle}" 
                           FontSize="16"
                           TextColor="{StaticResource AppLightGrayColor}"
                           Text="Scegli la categoria..."
                           IsVisible="{Binding IsCategoryNotSelected}" />

                    <Label Margin="12,0,0,0"
                           VerticalOptions="Center" HorizontalOptions="Start"
                           Style="{StaticResource BoldLabelStyle}" 
                           FontSize="16"
                           TextColor="#FF30383D"
                           Text="Tutte le categorie"
                           IsVisible="{Binding AllCategoriesSelected}" />

                    <Image Margin="0,0,15,0" VerticalOptions="Center"
                           HorizontalOptions="EndAndExpand"
                           Source="down_gray" />
                </StackLayout>

                <BoxView Margin="0,10,0,0"
                         HeightRequest="1"
                         BackgroundColor="#FFF0F0F0"/>
            </StackLayout>

            <!--Scelta comune -->
            <StackLayout Grid.Row="2" Grid.ColumnSpan="3"
                         Padding="0" Spacing="0"
                         Margin="16,16,16,0"
                         HorizontalOptions="Fill" >

                <StackLayout Padding="0" Spacing="0"
                             Orientation="Horizontal"
                             HorizontalOptions="Fill">
                    <StackLayout.GestureRecognizers>
                        <TapGestureRecognizer Tapped="OnMunicipalityButtonTapped" />
                    </StackLayout.GestureRecognizers>

                    <Image Margin="11,0,0,0"
                           VerticalOptions="Center"
                           Source="city_gray" />

                    <Label Margin="12,0,0,0"
                           VerticalOptions="Center" HorizontalOptions="Start"
                           Style="{StaticResource BoldLabelStyle}" 
                           FontSize="16"
                           TextColor="#FF30383D"
                           Text="{Binding SelectedMunicipality.NomeCompleto}"
                           IsVisible="{Binding IsMunicipalitySelected}" />

                    <Label Margin="12,0,0,0"
                           VerticalOptions="Center" HorizontalOptions="Start"
                           Style="{StaticResource ItalicLabelStyle}" 
                           FontSize="16"
                           TextColor="{StaticResource AppLightGrayColor}"
                           Text="Scegli il comune..."
                           IsVisible="{Binding IsMunicipalityNotSelected}" />

                    <Image Margin="0,0,15,0" VerticalOptions="Center"
                           HorizontalOptions="EndAndExpand"
                           Source="down_gray" />
                </StackLayout>

                <BoxView Margin="0,10,0,0"
                         HeightRequest="1"
                         BackgroundColor="#FFF0F0F0"/>
            </StackLayout>

            <!-- Find text -->
            <StackLayout  Grid.Row="3" Grid.ColumnSpan="3"
                          Padding="0" Spacing="0"
                          Margin="16,16,16,0"
                          HorizontalOptions="Fill"
                          IsVisible="{Binding FindIsVisible}">

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

                    <Image Margin="11,0,0,0"
                           VerticalOptions="Center"
                           Source="search_gray" />

                    <Entry Margin="16,0,0,0"
                           HorizontalOptions="FillAndExpand"
                           VerticalOptions="Center"
                           TextColor="#FF1168C9" FontSize="16"
                           Placeholder="Cerca nel nome"
                           PlaceholderColor="#FFEFEFEF"
                           Text="{Binding SearchText}"
                           Focused="OnFindFieldFocused"
                           Unfocused="OnFindFieldUnfocused"/>
                </StackLayout>

                <BoxView Margin="0,10,0,0"
                         HeightRequest="1"
                         BackgroundColor="#FFEFEFEF" />
            </StackLayout>

            <!-- Content header -->
            <Label Grid.Row="4" Grid.ColumnSpan="3" Margin="16,16,16,0"
                   HorizontalOptions="Start"
                   Style="{StaticResource RegularLabelStyle}"
                   TextColor="#FFAAAAAA" FontSize="14"
                   Text="{Binding ContentHeader}"
                   IsVisible="{Binding ContentHeaderIsVisible}"/>

            <!-- Lista negozi online -->
            <ListView Grid.Row="5" Grid.ColumnSpan="3" Margin="0,0,16,0"
                      ItemsSource="{Binding Shops, Mode=OneWay}"
                      HasUnevenRows="true"
                      ItemTapped="OnListViewItemTapped"
                      Footer=""
                      IsVisible="{Binding ShopListIsVisible}">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout Padding="0" Spacing="0"
                                         Orientation="Horizontal">

                                <StackLayout Padding="0" Spacing="0" Margin="16,0,0,0"
                                             HorizontalOptions="StartAndExpand">

                                    <Label Margin="0,11,0,0"
                                       Style="{StaticResource BoldLabelStyle}"
                                       HorizontalOptions="Start" VerticalOptions="Start"
                                       TextColor="#FF1168C9" FontSize="16"
                                       Text="{Binding Title}" />

                                    <Label Margin="0,0,0,0"
                                       Style="{StaticResource RegularLabelStyle}"
                                       VerticalTextAlignment="Start"
                                       TextColor="#FF596672" FontSize="14"
                                       Text="{Binding Url}" />

                                    <Label Margin="0,0,0,15"
                                       Style="{StaticResource RegularLabelStyle}"
                                       VerticalTextAlignment="Start"
                                       TextColor="#FF1168C9" FontSize="14"
                                       Text="{Binding ElencoCategorie}" />

                                </StackLayout>

                                <Image Margin="18,0,6,0"
                                       HorizontalOptions="Start" VerticalOptions="CenterAndExpand"
                                       Source="forward"/>
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

        </Grid>
    </views:BasePage.Content>
</views:BasePage>