<?xml version="1.0" encoding="utf-8" ?>
<pages:CallbackPage xmlns="http://xamarin.com/schemas/2014/forms"
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                    x:Class="PhilExample.UI.Pages.AddCrawlSessionPage"
                    xmlns:pages="clr-namespace:PhilExample.UI.Pages"
                    xmlns:vms="clr-namespace:PhilExample.VMs"
                    xmlns:ctrl="clr-namespace:PhilExample.UI.Controls"
                    xmlns:models="clr-namespace:PhilExample.Models"
                    xmlns:ffimg="clr-namespace:FFImageLoading.Svg.Forms;assembly=FFImageLoading.Svg.Forms"
                    xmlns:utils="clr-namespace:PhilExample.Utils"
                    xmlns:views="clr-namespace:PhilExample.UI.Views"
                    x:TypeArguments="models:CrawlSessionResponse"
                    x:DataType="vms:AddCrawlSessionVM"
                    Shell.NavBarIsVisible="False">

    <ContentPage.Resources>
        <ResourceDictionary>
            <utils:IsNullConverter x:Key="isNullConv"/>
            <utils:IsNotNullConverter x:Key="isNotNullConv"/>
        </ResourceDictionary>
    </ContentPage.Resources>


    <ContentPage.Content>
        <StackLayout  Margin="24,24,24,0" 
                      HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">

            <views:PopupTitleView Title="{Binding PageTitle}" CloseCommand="{Binding CloseCommand}"/>

            
            <ScrollView>
                <StackLayout>
                    <!-- Suchbegriff -->
                    <Label Margin="0,30,0,0"
                           Text="Suchbegriff" FontSize="10" TextColor="{StaticResource Color_Text1}" FontFamily="NunitoSemiBold" />
                    <ctrl:PhExFrame>
                        <ctrl:PhExEntry Text="{Binding Keywords}" FontSize="14" 
                                      DefaultTextColor="{StaticResource Color_Text1}" FontFamily="NunitoSemiBold"
                                      IsFocused="{Binding IsKeywordsFocused}"
                                      ErrorPlaceholder="Suchbegriff eingeben"
                                      IsErrorState="{Binding IsError_Keywords}"/>
                    </ctrl:PhExFrame>

                    <!-- Location -->
                    <Label Margin="0,12,0,0"
                           Text="PLZ oder Ort" FontSize="10" TextColor="{StaticResource Color_Text1}" FontFamily="NunitoSemiBold" />
                    <ctrl:PhExFrame>
                        <ctrl:PhExEntry Text="{Binding LocationStr}" FontSize="14" TextColor="{StaticResource Color_Text1}" FontFamily="NunitoSemiBold"  />
                    </ctrl:PhExFrame>

                    <!-- Kategorie -->
                    <Label Margin="0,12,0,0"
                           Text="Kategorie" FontSize="16" TextColor="{StaticResource Color_Text1}" FontFamily="NunitoExtraBold" />
                    <ctrl:PhExFrame>
                        <Grid HorizontalOptions="FillAndExpand" Margin="0,0,4,0">
                            <ctrl:PhExEntry InputTransparent="True"
                                          Text="{Binding SelectedCategory.Name}"
                                          TextColor="{StaticResource Color_Text1}"
                                          FontSize="14"  FontFamily="NunitoSemiBold"
                                          HorizontalOptions="FillAndExpand"
                                          HorizontalTextAlignment="Start"
                                          BackgroundColor="{StaticResource Color_ControlBackground}" />
                            <ffimg:SvgCachedImage CacheType="All"
                                                  HeightRequest="18" WidthRequest="12"
                                                  Source="resource://PhilExample.Resources.Images.arrow-right.svg"
                                                  HorizontalOptions="EndAndExpand" VerticalOptions="Center" />
                            <Grid.GestureRecognizers>
                                <TapGestureRecognizer Command="{Binding SelectCategoryCommand}" />
                            </Grid.GestureRecognizers>
                        </Grid>
                    </ctrl:PhExFrame>

                    <!-- Radius -->
                    <Label Margin="0,12,0,0"
                           Text="Radius" FontSize="16" TextColor="{StaticResource Color_Text1}" FontFamily="NunitoExtraBold" />
                    <ctrl:PhExFrame>
                        <Grid HorizontalOptions="FillAndExpand" Margin="0,0,4,0">
                            <ctrl:PhExEntry InputTransparent="True"
                                          Text="{Binding SelectedRadius.Name}"
                                          TextColor="{StaticResource Color_Text1}"
                                          FontSize="14"  FontFamily="NunitoSemiBold"
                                          HorizontalOptions="FillAndExpand"
                                          HorizontalTextAlignment="Start"
                                          BackgroundColor="{StaticResource Color_ControlBackground}" />
                            <ffimg:SvgCachedImage CacheType="All"
                                                  HeightRequest="18" WidthRequest="12"
                                                  Source="resource://PhilExample.Resources.Images.arrow-right.svg"
                                                  HorizontalOptions="EndAndExpand" VerticalOptions="Center" />
                            <Grid.GestureRecognizers>
                                <TapGestureRecognizer Command="{Binding SelectRadiusCommand}" />
                            </Grid.GestureRecognizers>
                        </Grid>
                    </ctrl:PhExFrame>

                    <!-- Min-Max Price -->
                    <Label Margin="0,12,0,0">
                        <Label.FormattedText>
                            <FormattedString>
                                <Span Text="Preis (Min - Max)" FontSize="16" TextColor="{StaticResource Color_Text1}" FontFamily="NunitoSemiBold" />
                            </FormattedString>
                        </Label.FormattedText>
                    </Label>


                    <Grid Margin="0,12,0,0"
                          HorizontalOptions="FillAndExpand">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="0.2*"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <ctrl:PhExFrame>
                            <StackLayout Orientation="Horizontal" BackgroundColor="Transparent"
                                         HorizontalOptions="FillAndExpand">
                                <Label Margin="4,0,0,0"
                                       Text="€" 
                                       FontSize="14" TextColor="{StaticResource Color_Text1}" FontFamily="NunitoSemiBold"
                                       VerticalOptions="Center" />
                                <ctrl:PhExEntry Text="{Binding MinPrice}" 
                                              Keyboard="Numeric" FontSize="14" TextColor="{StaticResource Color_Text1}" FontFamily="NunitoSemiBold"
                                              HorizontalOptions="FillAndExpand" />
                            </StackLayout>
                        </ctrl:PhExFrame>

                        <ffimg:SvgCachedImage Grid.Column="1" 
                                              HeightRequest="4" WidthRequest="10"
                                              CacheType="All"
                                              Source="resource://PhilExample.Resources.Images.minus.svg"
                                              HorizontalOptions="Center" VerticalOptions="Center"/>

                        <ctrl:PhExFrame Grid.Column="2">
                            <StackLayout Orientation="Horizontal" BackgroundColor="Transparent"
                                         HorizontalOptions="FillAndExpand">
                                <Label Margin="4,0,0,0"
                                       Text="€" 
                                       FontSize="14" TextColor="{StaticResource Color_Text1}" FontFamily="NunitoSemiBold"
                                       VerticalOptions="Center" />
                                <ctrl:PhExEntry Text="{Binding MaxPrice}" 
                                              Keyboard="Numeric" FontSize="14" TextColor="{StaticResource Color_Text1}" FontFamily="NunitoSemiBold"
                                              HorizontalOptions="FillAndExpand" />
                            </StackLayout>
                        </ctrl:PhExFrame>
                    </Grid>


                    <!-- Private / Commercial -->
                    <Label Margin="0,12,0,0"
                           Text="Anbieter" FontSize="10" TextColor="{StaticResource Color_Text1}" FontFamily="NunitoSemiBold" />

                    <StackLayout Orientation="Horizontal">
                        <CheckBox IsChecked="{Binding IsPrivate}" />
                        <Label Margin="0,0,0,0"
                               Text="Privat"
                               FontSize="14" TextColor="{StaticResource Color_Text1}" FontFamily="NunitoSemiBold"
                               VerticalOptions="Center" />
                    </StackLayout>
                    <StackLayout Orientation="Horizontal">
                        <CheckBox IsChecked="{Binding IsCommercial}" />
                        <Label Margin="0,0,0,0"
                               Text="Gewerblich"
                               FontSize="14" TextColor="{StaticResource Color_Text1}" FontFamily="NunitoSemiBold"
                               VerticalOptions="Center" />
                    </StackLayout>



                </StackLayout>
            </ScrollView>

            <!-- Add -->
            <Button IsVisible="{Binding CrawlSessionID, Converter={StaticResource isNullConv}}"
                    Margin="0,30,0,40"
                    Text="Hinzufügen" 
                    TextColor="White" 
                    FontFamily="NunitoMedium"
                    Command="{Binding AddCommand}" CornerRadius="15"
                    BackgroundColor="{StaticResource Color_Primary}"
                    VerticalOptions="EndAndExpand" />


            <!-- Update/Delete -->
            <Button IsVisible="{Binding CrawlSessionID, Converter={StaticResource isNotNullConv}}"
                    Margin="0,30,0,10"
                    Text="Speichern" 
                    TextColor="White" 
                    FontFamily="NunitoSemiBold"
                    Command="{Binding UpdateCommand}" CornerRadius="15"
                    BackgroundColor="{StaticResource Color_Primary}"
                    VerticalOptions="EndAndExpand" />
            <Button IsVisible="{Binding CrawlSessionID, Converter={StaticResource isNotNullConv}}"
                    Margin="0,10,0,40"
                    Text="Crawl-Auftrag löschen" 
                    TextColor="{StaticResource Color_Error}" 
                    FontFamily="NunitoSemiBold"
                    Command="{Binding DeleteCommand}" CornerRadius="15"
                    BackgroundColor="Transparent" />
        </StackLayout>
    </ContentPage.Content>
</pages:CallbackPage>