<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="CafeTerrace.Views.FoodListedPage"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:forms="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
    xmlns:model="clr-namespace:CafeTerrace.Models;assembly=CafeTerrace"
    xmlns:prism="http://prismlibrary.com"
    prism:ViewModelLocator.AutowireViewModel="True"
    BackgroundColor="{StaticResource Gray-200}"
    FlowDirection="RightToLeft"
    NavigationPage.HasNavigationBar="False">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="2*" />
            <RowDefinition Height="10*" />
        </Grid.RowDefinitions>
        <Frame
            Grid.Row="0"
            Margin="0,-15,0,2"
            Padding="0"
            CornerRadius="15">
            <Grid>
                <forms:CachedImage Aspect="AspectFill" Source="{Binding Path=HeaderImage}" />
                <Grid Padding="20,30,20,0" BackgroundColor="#35000000">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Label
                        Grid.Column="0"
                        FontFamily="{StaticResource ShabnameBold}"
                        FontSize="22"
                        Text="{Binding Title}"
                        TextColor="White"
                        VerticalOptions="Center" />

                    <Button
                        Grid.Column="1"
                        Padding="0"
                        BackgroundColor="#70000000"
                        Command="{Binding BackButtonCommand}"
                        CornerRadius="25"
                        FontFamily="{StaticResource MaterialFontFamily}"
                        FontSize="35"
                        HeightRequest="45"
                        Text="{x:Static model:MaterialIconFont.ChevronLeft}"
                        TextColor="{StaticResource Gray-100}"
                        VerticalOptions="Center"
                        WidthRequest="45" />
                </Grid>
            </Grid>
        </Frame>
        <StackLayout Grid.Row="1">

            <ScrollView>
                <FlexLayout
                    AlignContent="Start"
                    BindableLayout.ItemsSource="{Binding Foods}"
                    HorizontalOptions="Center"
                    JustifyContent="Center"
                    VerticalOptions="Fill"
                    Wrap="Wrap">
                    <BindableLayout.ItemTemplate>
                        <DataTemplate>

                            <Grid HeightRequest="170" WidthRequest="170">
                                <Frame
                                    Margin="4"
                                    Padding="0"
                                    CornerRadius="10"
                                    HeightRequest="170"
                                    IsEnabled="{Binding IsEnable}"
                                    WidthRequest="170">
                                    <Grid>
                                        <forms:CachedImage Aspect="AspectFill" Source="{Binding Path=FoodImages.Image}" />
                                        <Grid BackgroundColor="#10000000">
                                            <StackLayout HorizontalOptions="Start" VerticalOptions="End">
                                                <Label
                                                    Margin="8,8,8,0"
                                                    FontFamily="{StaticResource ShabnameBold}"
                                                    FontSize="16"
                                                    Text="{Binding Name}"
                                                    TextColor="White"
                                                    VerticalOptions="Center" />
                                                <StackLayout Margin="8,-9,8,0" Orientation="Horizontal">
                                                    <Label
                                                        FontFamily="{StaticResource ShabnameBold}"
                                                        FontSize="19"
                                                        Text="{Binding Path=Price.FinalAmount, StringFormat='{0:N0}'}"
                                                        TextColor="{StaticResource Orange}" />
                                                    <Label
                                                        FontFamily="{StaticResource Shabname}"
                                                        FontSize="15"
                                                        Text="{StaticResource Money}"
                                                        TextColor="{StaticResource Orange}"
                                                        VerticalOptions="Center" />
                                                </StackLayout>
                                            </StackLayout>
                                            <StackLayout
                                                Margin="5"
                                                HorizontalOptions="End"
                                                Orientation="Horizontal"
                                                VerticalOptions="Start">
                                                <Label
                                                    Margin="0,0,0,-1"
                                                    FontFamily="{StaticResource MaterialFontFamily}"
                                                    FontSize="20"
                                                    Text="{x:Static model:MaterialIconFont.Star}"
                                                    TextColor="{StaticResource PrimaryColor}"
                                                    VerticalOptions="Center" />
                                                <Label
                                                    FontFamily="{StaticResource ShabnameBold}"
                                                    FontSize="17"
                                                    Text="{Binding AverageRate}"
                                                    TextColor="{StaticResource PrimaryColor}"
                                                    VerticalOptions="Center" />
                                            </StackLayout>
                                        </Grid>
                                    </Grid>
                                    <Frame.GestureRecognizers>
                                        <TapGestureRecognizer Tapped="FoodItem_OnTapped" />
                                    </Frame.GestureRecognizers>
                                </Frame>

                                <Frame
                                    Margin="4"
                                    Padding="0"
                                    BackgroundColor="#90000000"
                                    CornerRadius="10"
                                    HeightRequest="150"
                                    IsVisible="{Binding DontShow}"
                                    WidthRequest="150">
                                    <StackLayout HorizontalOptions="Center" VerticalOptions="Center">

                                        <Label
                                            FontFamily="{StaticResource MaterialFontFamily}"
                                            FontSize="60"
                                            HorizontalOptions="Center"
                                            Text="{x:Static model:MaterialIconFont.CloseCircle}"
                                            TextColor="OrangeRed"
                                            VerticalOptions="Center" />
                                        <Label
                                            FontFamily="{StaticResource ShabnameBold}"
                                            FontSize="16"
                                            HorizontalOptions="Center"
                                            HorizontalTextAlignment="Center"
                                            Text="این غـــذا تمام شده است"
                                            TextColor="White"
                                            VerticalOptions="Center" />
                                    </StackLayout>
                                </Frame>
                            </Grid>
                        </DataTemplate>
                    </BindableLayout.ItemTemplate>
                </FlexLayout>
            </ScrollView>
        </StackLayout>

    </Grid>
</ContentPage>