<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="CafeTerrace.Views.MainPage"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    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"
    Title="{Binding Title}"
    BackgroundColor="{StaticResource Gray-200}"
    FlowDirection="RightToLeft"
    NavigationPage.HasNavigationBar="False">

    <Grid>
        <Grid Margin="0,0,0,0">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="300" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <StackLayout BackgroundColor="{StaticResource PrimaryColor}" />
            </Grid>
            <Grid Margin="15,60,15,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="45" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Button
                        Grid.Column="2"
                        Padding="0"
                        BackgroundColor="White"
                        Command="{Binding ProfileButtonCommand}"
                        CornerRadius="25"
                        FontFamily="{StaticResource MaterialFontFamily}"
                        FontSize="26"
                        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>

                    <StackLayout>
                        <Label
                            FontFamily="{StaticResource ShabnameBold}"
                            FontSize="20"
                            Text="کافه رستوران تـــــراس"
                            TextColor="Accent"
                            VerticalOptions="Center" />
                        <StackLayout Margin="0,-5,0,0" Orientation="Horizontal">
                            <Label Text="{Binding Path=HomeMobileRoot.FullName}" />
                            <Frame
                                Margin="0,2,0,0"
                                Padding="15,2,15,0"
                                BackgroundColor="Accent"
                                CornerRadius="15">
                                <Label
                                    FontFamily="{StaticResource ShabnameBold}"
                                    FontSize="10"
                                    Text="{Binding Path=HomeMobileRoot.GradeName}"
                                    TextColor="{StaticResource PrimaryColor}" />
                            </Frame>
                        </StackLayout>
                    </StackLayout>

                </Grid>
                <StackLayout Grid.Row="1" Margin="0,20,0,0">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="210" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <!--#region Old Category Slider-->

                        <!--<ScrollView Grid.Row="1" Margin="-15,-35,-15,0">
                            <StackLayout Margin="0,15" BindableLayout.ItemsSource="{Binding Path=HomeMobileRoot.BaseCategories}">
                                <BindableLayout.ItemTemplate>
                                    <DataTemplate>
                                        <Frame
                                            Margin="0,20"
                                            Padding="0"
                                            BackgroundColor="Transparent"
                                            CornerRadius="0"
                                            HasShadow="False">
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="*" />
                                                </Grid.ColumnDefinitions>
                                                <forms:CachedImage Aspect="AspectFill" Source="{Binding ImageBase64}" />
                                                <StackLayout Padding="10" BackgroundColor="#50000000">
                                                    <Label
                                                        FontFamily="{StaticResource ShabnameBold}"
                                                        FontSize="17"
                                                        Text="{Binding CategoryName}"
                                                        TextColor="White" />
                                                    <CollectionView
                                                        x:Name="categoryCollection"
                                                        Margin="-10,0,-10,10"
                                                        FlowDirection="RightToLeft"
                                                        HeightRequest="160"
                                                        HorizontalOptions="Start"
                                                        ItemsSource="{Binding Categories}"
                                                        SelectionChanged="CategoryCollection_OnSelectionChanged"
                                                        SelectionMode="Single">
                                                        <CollectionView.ItemsLayout>
                                                            <LinearItemsLayout
                                                                ItemSpacing="5"
                                                                Orientation="Horizontal"
                                                                SnapPointsAlignment="Start"
                                                                SnapPointsType="Mandatory" />
                                                        </CollectionView.ItemsLayout>
                                                        <CollectionView.ItemTemplate>
                                                            <DataTemplate>
                                                                <Grid>
                                                                    <Frame
                                                                        Margin="4"
                                                                        Padding="0"
                                                                        CornerRadius="10"
                                                                        HeightRequest="130"
                                                                        HorizontalOptions="Center"
                                                                        VerticalOptions="Center"
                                                                        WidthRequest="140">
                                                                        <forms:CachedImage Aspect="AspectFill" Source="{Binding ImageBase64}" />
                                                                    </Frame>
                                                                    <Frame
                                                                        Margin="2"
                                                                        Padding="15,4"
                                                                        BackgroundColor="{StaticResource PrimaryColor}"
                                                                        CornerRadius="50"
                                                                        HorizontalOptions="Center"
                                                                        VerticalOptions="End">
                                                                        <Label
                                                                            FontFamily="{StaticResource Shabname}"
                                                                            FontSize="16"
                                                                            HorizontalOptions="Center"
                                                                            Text="{Binding CategoryName}"
                                                                            TextColor="Accent"
                                                                            VerticalOptions="Center" />
                                                                    </Frame>
                                                                </Grid>
                                                            </DataTemplate>
                                                        </CollectionView.ItemTemplate>
                                                    </CollectionView>
                                                </StackLayout>
                                            </Grid>
                                        </Frame>
                                    </DataTemplate>
                                </BindableLayout.ItemTemplate>
                            </StackLayout>
                        </ScrollView>-->
                        <!--#endregion-->




                        <Frame
                            x:Name="sliderFrame"
                            Grid.Row="0"
                            Margin="8"
                            Padding="0"
                            CornerRadius="10"
                            HeightRequest="210"
                            WidthRequest="300">
                            <Grid>
                                <CarouselView
                                    x:Name="sliderCarousel"
                                    IsSwipeEnabled="True"
                                    ItemsSource="{Binding Path=HomeMobileRoot.ChefSuggestionFoods}">
                                    <CarouselView.ItemTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <forms:CachedImage Aspect="AspectFill" Source="{Binding Path=FoodImages.Image}" />
                                                <Grid BackgroundColor="#70000000" VerticalOptions="End">
                                                    <StackLayout HorizontalOptions="Start" VerticalOptions="End">
                                                        <Label
                                                            Margin="8,8,8,0"
                                                            FontFamily="{StaticResource ShabnameBold}"
                                                            FontSize="18"
                                                            Text="{Binding Name}"
                                                            TextColor="White"
                                                            VerticalOptions="Center" />
                                                        <StackLayout Margin="8,-9,8,0" Orientation="Horizontal">
                                                            <Label
                                                                FontFamily="{StaticResource ShabnameBold}"
                                                                FontSize="20"
                                                                Text="{Binding Path=Price.Amount, 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
                                                            FontFamily="{StaticResource ShabnameBold}"
                                                            FontSize="17"
                                                            Text="{Binding AverageRate}"
                                                            TextColor="{StaticResource PrimaryColor}"
                                                            VerticalOptions="Center" />
                                                        <Label
                                                            Margin="0,0,0,1"
                                                            FontFamily="{StaticResource MaterialFontFamily}"
                                                            FontSize="20"
                                                            Text="{x:Static model:MaterialIconFont.Star}"
                                                            TextColor="{StaticResource PrimaryColor}"
                                                            VerticalOptions="Center" />
                                                    </StackLayout>
                                                </Grid>
                                                <Grid.GestureRecognizers>
                                                    <TapGestureRecognizer Tapped="ChefSuggestSlider_OnTapped" />
                                                </Grid.GestureRecognizers>
                                            </Grid>
                                        </DataTemplate>
                                    </CarouselView.ItemTemplate>
                                </CarouselView>
                                <Frame
                                    Margin="8"
                                    Padding="10,8"
                                    BackgroundColor="Accent"
                                    CornerRadius="8"
                                    HorizontalOptions="Start"
                                    VerticalOptions="Start">
                                    <StackLayout Orientation="Horizontal">
                                        <Label
                                            FontFamily="{StaticResource MaterialFontFamily}"
                                            FontSize="21"
                                            Text="{x:Static model:MaterialIconFont.Star}"
                                            TextColor="{StaticResource PrimaryColor}"
                                            VerticalOptions="Center" />
                                        <Label
                                            FontFamily="{StaticResource ShabnameBold}"
                                            Text="پیشنهاد ویــژه تراس"
                                            TextColor="{StaticResource PrimaryColor}" />
                                    </StackLayout>
                                </Frame>
                            </Grid>
                        </Frame>

                        <ScrollView Grid.Row="1">
                            <FlexLayout
                                AlignContent="Start"
                                BindableLayout.ItemsSource="{Binding Path=HomeMobileRoot.BaseCategories}"
                                HorizontalOptions="Center"
                                JustifyContent="Center"
                                VerticalOptions="Fill"
                                Wrap="Wrap">
                                <BindableLayout.ItemTemplate>
                                    <DataTemplate>
                                        <Grid HeightRequest="180" WidthRequest="160">
                                            <Grid HeightRequest="180" WidthRequest="160">
                                                <Frame
                                                    Margin="4"
                                                    Padding="0"
                                                    CornerRadius="10"
                                                    HeightRequest="150"
                                                    HorizontalOptions="Center"
                                                    VerticalOptions="Center"
                                                    WidthRequest="160">
                                                    <forms:CachedImage Aspect="AspectFill" Source="{Binding ImageBase64}" />
                                                </Frame>
                                                <Frame
                                                    Margin="2,0,0,3"
                                                    Padding="15,4"
                                                    BackgroundColor="{StaticResource PrimaryColor}"
                                                    CornerRadius="50"
                                                    HorizontalOptions="Center"
                                                    VerticalOptions="End">
                                                    <Label
                                                        FontFamily="{StaticResource Shabname}"
                                                        FontSize="16"
                                                        HorizontalOptions="Center"
                                                        Text="{Binding CategoryName}"
                                                        TextColor="Accent"
                                                        VerticalOptions="Center" />
                                                </Frame>
                                                <Grid.GestureRecognizers>
                                                    <TapGestureRecognizer Tapped="Categor_OnTapped" />
                                                </Grid.GestureRecognizers>
                                            </Grid>

                                            <Frame
                                                Margin="4"
                                                Padding="0"
                                                BackgroundColor="#90000000"
                                                CornerRadius="10"
                                                HeightRequest="130"
                                                IsVisible="{Binding DontShow}"
                                                VerticalOptions="Center"
                                                WidthRequest="140">
                                                <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>
                    </Grid>
                </StackLayout>
            </Grid>

        </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="sliderMenuFrame"
                            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>