<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="PhilExample.UI.Pages.DashboardPage"
             xmlns:views="clr-namespace:PhilExample.UI.Views"
             xmlns:vm="clr-namespace:PhilExample.VMs"
             xmlns:utils="clr-namespace:PhilExample.Utils"
             x:DataType="vm:DashboardVM"
             Shell.NavBarIsVisible="False">


    <ContentPage.Resources>
        <ResourceDictionary>
            <utils:IsEmptyConverter x:Key="isEmptyConv"/>
            <utils:IsNotEmptyConverter x:Key="isNotEmptyConv"/>
        </ResourceDictionary>
    </ContentPage.Resources>



    <ContentPage.Content>
        <StackLayout Margin="24,24,0,0">
            <Label Text="PhilExampleCrawler" FontSize="24" TextColor="{StaticResource Color_TextTitle}" FontFamily="NunitoExtraBold" />

            <!-- Crawl Sessions -->
            <StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand"
                         Margin="0,30,0,0">
                <Label Text="Meine Crawl-Aufträge" FontSize="16" TextColor="{StaticResource Color_Text1}" FontFamily="NunitoExtraBold" />
                <Label Text="hinzufügen" FontSize="14" TextColor="{StaticResource Color_Primary}" TextDecorations="Underline" FontFamily="NunitoBold" 
                       HorizontalOptions="EndAndExpand"
                       Margin="0,0,36,0">

                    <Label.GestureRecognizers>
                        <TapGestureRecognizer Command="{Binding AddCommand}" />
                    </Label.GestureRecognizers>
                </Label>


            </StackLayout>

            <!-- Empty View-->
            <Grid IsVisible="{Binding CrawlSessions, Converter={StaticResource isEmptyConv}}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="44" />
                    <RowDefinition Height="44" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="140" />
                </Grid.ColumnDefinitions>

                <BoxView Grid.RowSpan="3"
                         BackgroundColor="{StaticResource Color_Primary}"
                         CornerRadius="15" />

                <Label Grid.Row="0" Margin="10,10,4,0"
                       Text="Crawl-Auftrag" FontSize="14"
                       TextColor="{StaticResource Color_TextContrast}" FontFamily="NunitoBold"/>
                <Label Grid.Row="1" Margin="10,0,4,10"
                       Text="Hinzufügen" FontSize="12" 
                       TextColor="{StaticResource Color_TextContrast}" TextDecorations="Underline" FontFamily="NunitoBold"
                       VerticalOptions="End">
                    <Label.GestureRecognizers>
                        <TapGestureRecognizer Command="{Binding AddCommand}" />
                    </Label.GestureRecognizers>
                </Label>
            </Grid>
            
            <!-- NonEmpty View -->
            <CollectionView IsVisible="{Binding CrawlSessions, Converter={StaticResource isNotEmptyConv}}"
                            Margin="0,10,0,0"
                            HeightRequest="140"
                            ItemsSource="{Binding CrawlSessions}"
                            HorizontalScrollBarVisibility="Never"
                            VerticalScrollBarVisibility="Never"
                            ItemsLayout="HorizontalList">

                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <views:CrawlSessionMiniView />
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>


            <!-- Insertions -->
            <StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand"
                         Margin="0,30,0,0">
                <Label Text="Neue Treffer" FontSize="16" TextColor="{StaticResource Color_Text1}" FontFamily="NunitoExtraBold" />
                <Label Text="Alle anzeigen" FontSize="14" TextColor="{StaticResource Color_Primary}" TextDecorations="Underline" FontFamily="NunitoBold" 
                       HorizontalOptions="EndAndExpand"
                       Margin="0,0,36,0"/>
            </StackLayout>

            <!-- Empty View -->
            <RefreshView IsVisible="{Binding FoundInsertions, Converter={StaticResource isEmptyConv}}"
                         IsRefreshing="{Binding IsRefreshing, Mode=OneWay}"
                         Command="{Binding RefreshInsertionsCommand}"
                         Margin="0" Padding="0"
                         HorizontalOptions="FillAndExpand"
                         VerticalOptions="FillAndExpand">

                <Label Margin="0,20,0,0"
                       Text="Leider gibt es aktuell noch keine Treffer zu Ihren Crawling-Aufträgen." FontSize="14" 
                       TextColor="{StaticResource Color_Text4}" FontFamily="NunitoMedium"
                       HorizontalTextAlignment="Center"/>
            </RefreshView>

            <!-- NonEmpty View -->
            <RefreshView IsVisible="{Binding FoundInsertions, Converter={StaticResource isNotEmptyConv}}"
                         IsRefreshing="{Binding IsRefreshing, Mode=OneWay}"
                         Command="{Binding RefreshInsertionsCommand}"
                         Margin="0" Padding="0">

                <CollectionView Margin="0,10,24,60"
                                ItemsSource="{Binding FoundInsertions}"
                                HorizontalScrollBarVisibility="Never"
                                VerticalScrollBarVisibility="Never"
                                ItemsLayout="VerticalList">

                    <CollectionView.ItemTemplate>
                        <DataTemplate>
                            <views:InsertionMiniView />
                        </DataTemplate>
                    </CollectionView.ItemTemplate>
                </CollectionView>
                
            </RefreshView>
        </StackLayout>

    </ContentPage.Content>

</ContentPage>