<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="CafeTerrace.Views.FoodPage"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:app="clr-namespace:CafeTerrace;assembly=CafeTerrace"
    xmlns:controller="clr-namespace:CafeTerrace.Views.Controller;assembly=CafeTerrace"
    xmlns:forms="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
    xmlns:implementations="clr-namespace:BottomSheetXF.Implementations;assembly=BottomSheetXF"
    xmlns:model="clr-namespace:CafeTerrace.Models;assembly=CafeTerrace"
    xmlns:prism="http://prismlibrary.com"
    xmlns:transformations="clr-namespace:FFImageLoading.Transformations;assembly=FFImageLoading.Transformations"
    prism:ViewModelLocator.AutowireViewModel="True"
    BackgroundColor="{StaticResource Gray-200}"
    FlowDirection="RightToLeft"
    NavigationPage.HasNavigationBar="False">
    <Grid>


        <Grid>
            <ScrollView>

                <Grid>

                    <Grid.RowDefinitions>
                        <RowDefinition Height="350" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Frame
                        Margin="0,-30,0,0"
                        Padding="0"
                        CornerRadius="25">
                        <Grid Margin="0,25,0,0">

                            <CarouselView x:Name="sliderCarousel" ItemsSource="{Binding Path=Food.FoodPhoto}">
                                <CarouselView.ItemTemplate>
                                    <DataTemplate>
                                        <Grid>
                                            <forms:CachedImage Aspect="AspectFill" Source="{Binding Path=Image}" />
                                            <Grid.GestureRecognizers>
                                                <TapGestureRecognizer Tapped="SliderTapGestureRecognizer_OnTapped" />
                                            </Grid.GestureRecognizers>
                                        </Grid>
                                    </DataTemplate>
                                </CarouselView.ItemTemplate>
                            </CarouselView>
                        </Grid>
                    </Frame>

                    <Grid Grid.Row="1" Margin="10,-40,10,0">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="30" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Frame Padding="12,12,12,40" CornerRadius="8">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <Label
                                        FontFamily="{StaticResource ShabnameBold}"
                                        FontSize="20"
                                        Text="{Binding Path=Food.Name}" />
                                    <StackLayout Grid.Column="1" Orientation="Horizontal">
                                        <Label
                                            FontFamily="{StaticResource ShabnameBold}"
                                            FontSize="18"
                                            Text="{Binding Path=Food.Price.FinalAmount, StringFormat=' {0:N0} ریال'}"
                                            TextColor="{StaticResource PrimaryColor}" />
                                    </StackLayout>
                                </Grid>
                                <Grid Grid.Row="1">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <controller:Rating
                                        Grid.Column="1"
                                        HorizontalOptions="End"
                                        Rate="{Binding Path=Food.AverageRate}" />
                                </Grid>
                                <Label
                                    Grid.Row="2"
                                    Margin="0,5"
                                    FontSize="13"
                                    Text="{Binding Path=Food.Description}" />

                            </Grid>
                        </Frame>
                        <FlexLayout
                            Grid.Row="1"
                            Margin="0,-36,0,0"
                            AlignContent="Start"
                            BindableLayout.ItemsSource="{Binding Foods}"
                            HorizontalOptions="Center"
                            JustifyContent="Center"
                            VerticalOptions="Fill"
                            Wrap="Wrap">
                            <!--<Frame
                                x:Name="serveTimeFrame"
                                Margin="2,13,2,0"
                                Padding="3,0,15,0"
                                BackgroundColor="{StaticResource Gray-200}"
                                CornerRadius="30"
                                HeightRequest="30"
                                IsVisible="False"
                                VerticalOptions="Start">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <Frame
                                        Padding="0"
                                        BackgroundColor="{StaticResource PrimaryColor}"
                                        CornerRadius="20"
                                        HeightRequest="25"
                                        HorizontalOptions="Start"
                                        VerticalOptions="Center"
                                        WidthRequest="25">
                                        <Label
                                            FontFamily="{StaticResource MaterialFontFamily}"
                                            FontSize="15"
                                            HorizontalOptions="Center"
                                            Text="{x:Static model:MaterialIconFont.Food}"
                                            TextColor="White"
                                            VerticalOptions="Center" />
                                    </Frame>
                                    <Label
                                        Grid.Column="1"
                                        Margin="0,-1,0,0"
                                        FontFamily="{StaticResource Shabname}"
                                        FontSize="16"
                                        Text="سرو سریع"
                                        TextColor="{StaticResource PrimaryDarkColor}"
                                        VerticalOptions="Center" />
                                </Grid>
                                <Frame.GestureRecognizers>
                                    <TapGestureRecognizer Tapped="FastServe_OnTapped" />
                                </Frame.GestureRecognizers>
                            </Frame>-->
                            <Frame
                                x:Name="serveFrame"
                                Margin="2,13,2,0"
                                Padding="3,0,15,0"
                                BackgroundColor="{StaticResource Gray-200}"
                                CornerRadius="30"
                                HeightRequest="30"
                                IsVisible="{Binding IsTyped}"
                                VerticalOptions="Start">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <Frame
                                        Padding="0"
                                        BackgroundColor="{StaticResource PrimaryColor}"
                                        CornerRadius="20"
                                        HeightRequest="25"
                                        HorizontalOptions="Start"
                                        VerticalOptions="Center"
                                        WidthRequest="25">
                                        <Label
                                            FontFamily="{StaticResource MaterialFontFamily}"
                                            FontSize="15"
                                            HorizontalOptions="Center"
                                            Text="{x:Static model:MaterialIconFont.Food}"
                                            TextColor="White"
                                            VerticalOptions="Center" />
                                    </Frame>
                                    <Label
                                        Grid.Column="1"
                                        Margin="0,-1,0,0"
                                        FontFamily="{StaticResource Shabname}"
                                        FontSize="16"
                                        Text="نوع سرو"
                                        TextColor="{StaticResource PrimaryDarkColor}"
                                        VerticalOptions="Center" />
                                </Grid>
                                <Frame.GestureRecognizers>
                                    <TapGestureRecognizer Tapped="FoodTypeButton_OnTapped" />
                                </Frame.GestureRecognizers>
                            </Frame>
                            <Frame
                                x:Name="buyFrame"
                                Margin="2,8,2,0"
                                Padding="3,0,15,0"
                                BackgroundColor="{StaticResource Gray-200}"
                                CornerRadius="30"
                                HeightRequest="40"
                                VerticalOptions="Start">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <Frame
                                        Padding="0"
                                        BackgroundColor="{StaticResource PrimaryColor}"
                                        CornerRadius="20"
                                        HeightRequest="35"
                                        HorizontalOptions="Start"
                                        VerticalOptions="Center"
                                        WidthRequest="35">
                                        <Label
                                            FontFamily="{StaticResource FontAwsomeFontFamily}"
                                            FontSize="15"
                                            HorizontalOptions="Center"
                                            Text="{x:Static model:FaIconFont.ShoppingCart}"
                                            TextColor="White"
                                            VerticalOptions="Center" />
                                    </Frame>
                                    <Label
                                        Grid.Column="1"
                                        FontFamily="{StaticResource ShabnameBold}"
                                        FontSize="20"
                                        Text="سفـــارش"
                                        TextColor="{StaticResource PrimaryDarkColor}"
                                        VerticalOptions="Center" />
                                </Grid>
                                <Frame.GestureRecognizers>
                                    <TapGestureRecognizer Command="{Binding BuyButtonCommand}" />
                                </Frame.GestureRecognizers>
                            </Frame>
                            <Picker
                                x:Name="foodTypePicker"
                                IsEnabled="False"
                                IsVisible="False"
                                ItemDisplayBinding="{Binding Type}"
                                ItemsSource="{Binding Path=Food.FoodType}"
                                SelectedIndexChanged="FoodTypePicker_OnSelectedIndexChanged" />

                        </FlexLayout>

                        <StackLayout Grid.Row="2" Margin="0,8,0,0">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <StackLayout Orientation="Horizontal">
                                    <Label
                                        FontFamily="{StaticResource ShabnameBold}"
                                        FontSize="25"
                                        Text="{Binding Path=Food.RatesCount}"
                                        VerticalOptions="Center" />
                                    <Label
                                        FontFamily="{StaticResource Shabname}"
                                        FontSize="20"
                                        Text="نظــــر"
                                        VerticalOptions="Center" />
                                </StackLayout>
                                <Button
                                    Grid.Column="1"
                                    Padding="25,0"
                                    BackgroundColor="Accent"
                                    Command="{Binding AddCommentButtonCommand}"
                                    CornerRadius="20"
                                    FontFamily="{StaticResource ShabnameBold}"
                                    FontSize="12"
                                    HeightRequest="40"
                                    IsEnabled="True"
                                    Text="نظـــر دادن"
                                    TextColor="{StaticResource PrimaryColor}"
                                    VerticalOptions="Center"
                                    WidthRequest="130" />
                            </Grid>

                            <CollectionView
                                Margin="-20,8"
                                HeightRequest="150"
                                ItemsSource="{Binding Path=Food.Rates}">
                                <CollectionView.ItemsLayout>
                                    <LinearItemsLayout
                                        ItemSpacing="5"
                                        Orientation="Horizontal"
                                        SnapPointsAlignment="Center"
                                        SnapPointsType="MandatorySingle" />
                                </CollectionView.ItemsLayout>
                                <CollectionView.ItemTemplate>
                                    <DataTemplate>
                                        <Grid>
                                            <Frame
                                                Margin="3"
                                                Padding="8"
                                                CornerRadius="10"
                                                WidthRequest="300">
                                                <Grid>
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="Auto" />
                                                        <RowDefinition Height="Auto" />
                                                        <RowDefinition Height="Auto" />
                                                    </Grid.RowDefinitions>
                                                    <Label
                                                        FontFamily="{StaticResource ShabnameBold}"
                                                        FontSize="16"
                                                        Text="{Binding UserName}"
                                                        TextColor="#555" />
                                                    <Grid Grid.Row="1">
                                                        <Grid.ColumnDefinitions>
                                                            <ColumnDefinition Width="Auto" />
                                                            <ColumnDefinition Width="*" />
                                                        </Grid.ColumnDefinitions>

                                                        <Label
                                                            FontFamily="{StaticResource Shabname}"
                                                            FontSize="11"
                                                            Text="{Binding PersianRegister}"
                                                            TextColor="{StaticResource Gray-500}"
                                                            VerticalOptions="Center" />
                                                    </Grid>
                                                    <Label
                                                        Grid.Row="2"
                                                        FontFamily="{StaticResource Shabname}"
                                                        FontSize="11"
                                                        MaxLines="3"
                                                        Text="{Binding Description}"
                                                        VerticalOptions="Center" />
                                                </Grid>
                                            </Frame>
                                        </Grid>
                                    </DataTemplate>
                                </CollectionView.ItemTemplate>
                            </CollectionView>
                        </StackLayout>
                    </Grid>
                </Grid>
            </ScrollView>
        </Grid>

        <Grid Margin="15,35,15,0" VerticalOptions="Start">

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Button
                Grid.Column="2"
                BackgroundColor="White"
                CornerRadius="25"
                FontFamily="{StaticResource MaterialFontFamily}"
                FontSize="25"
                HeightRequest="45"
                Text="{x:Static model:MaterialIconFont.AccountOutline}"
                TextColor="{StaticResource Gray-700}"
                WidthRequest="45" />
            <controller:BuyBagButton Grid.Column="1">
                <controller:BuyBagButton.GestureRecognizers>
                    <TapGestureRecognizer Tapped="BuyBagTapGestureRecognizer_OnTapped" />
                </controller:BuyBagButton.GestureRecognizers>
            </controller:BuyBagButton>
            <Button
                Grid.Column="3"
                Padding="0"
                BackgroundColor="#90ffffff"
                Command="{Binding BackButtonCommand}"
                CornerRadius="25"
                FontFamily="{StaticResource MaterialFontFamily}"
                FontSize="30"
                HeightRequest="45"
                Text="{x:Static model:MaterialIconFont.ChevronLeft}"
                TextColor="{StaticResource Gray-700}"
                WidthRequest="45" />
        </Grid>

        <implementations:SimpleBottomSheet
            x:Name="SimpleBottomSheet"
            Margin="0,0,0,0"
            ContentPosition="Bottom"
            IsOpen="False"
            MainPadding="0,0,0,0"
            Movement="BottomUp">
            <implementations:SimpleBottomSheet.View>
                <ContentView>
                    <Grid>
                        <Frame
                            x:Name="sliderFrame"
                            Margin="0,15,0,0"
                            Padding="8,8,8,8"
                            BackgroundColor="{StaticResource Gray-200}"
                            CornerRadius="8" />
                        <Button
                            Margin="0,-10,0,0"
                            Padding="0"
                            BackgroundColor="{StaticResource Red}"
                            Clicked="CloseBuyBagButton_OnClicked"
                            CornerRadius="20"
                            FontFamily="{StaticResource MaterialFontFamily}"
                            FontSize="25"
                            HeightRequest="40"
                            HorizontalOptions="Center"
                            Text="{x:Static model:MaterialIconFont.Close}"
                            TextColor="White"
                            VerticalOptions="Start"
                            WidthRequest="40" />
                    </Grid>
                </ContentView>
            </implementations:SimpleBottomSheet.View>
        </implementations:SimpleBottomSheet>
    </Grid>
</ContentPage>