<?xml version="1.0" encoding="utf-8"?>
<Page
    x:Class="was.droidtransfer.features.calllogs.CallLogsContentPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:common="using:was.android.connect.common.calllog"
    xmlns:converters="using:was.droidtransfer.features.calllogs.converters"
    xmlns:fconverters="using:was.droidtransfer.features.converters"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Page.Resources>
        <ResourceDictionary>
            <converters:CallLogEntryToFontIconColorConverter x:Key="CallLogEntryToFontIconColorConverter" />
            <converters:CallLogEntryToFontIconGlyphConverter x:Key="CallLogEntryToFontIconGlyphConverter" />
            <converters:CallLogEntryToDurationStringConverter x:Key="CallLogEntryToDurationStringConverter" />
            <converters:CallLogEntryToDetailStringConverter x:Key="CallLogEntryToDetailStringConverter" />
            <converters:CallLogEntryToDurationFontWeightConverter x:Key="CallLogEntryToDurationFontWeightConverter" />
            <converters:CallLogFilterOptionsToDescriptionStringConverter x:Key="CallLogFilterOptionsToDescriptionStringConverter" />
            <converters:EnumerableCountToVisibilityConverter x:Key="EnumerableCountToVisibilityConverter" />
            <fconverters:ValueToVisibilityConverter x:Key="ValueToVisibilityConverter" />
            <fconverters:VisibilityInverter x:Key="VisibilityInverter" />
        </ResourceDictionary>
    </Page.Resources>
    <Border Style="{ThemeResource FeatureContentPageBorder}" Padding="0" >
        <ScrollViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="0,20">
            <Grid>
                <Grid x:Name="gridContent" Visibility="{x:Bind CallLog, Converter={StaticResource ValueToVisibilityConverter}, Mode=OneWay}">
                    <StackPanel Orientation="Vertical">
                        <InfoBar x:Uid="InfoBarFilter" IsOpen="True" Title="Date Filter Applied" Message="{x:Bind DateFilterOptions, Converter={StaticResource CallLogFilterOptionsToDescriptionStringConverter}, Mode=OneWay}" Severity="Informational" HorizontalAlignment="Stretch" IsClosable="False" Margin="30,0,30,20" Visibility="{x:Bind DateFilterOptions.HasRange, Converter={StaticResource ValueToVisibilityConverter}, Mode=OneWay}">
                            <InfoBar.IconSource>
                                <SymbolIconSource Symbol="Calendar"/>
                            </InfoBar.IconSource>
                            <InfoBar.ActionButton>
                                <Button x:Name="buttonClearFilter" x:Uid="ClearFilterButton" Content="Clear Filter" Click="_buttonClearDateFilter_Click" />
                            </InfoBar.ActionButton>
                        </InfoBar>
                        <TextBlock Text="{x:Bind CallLog.DisplayName, Mode=OneWay}" Style="{ThemeResource TitleTextBlockStyle}" Margin="30,0,30,0" />
                        <ItemsRepeater x:Name="itemsRepeater" ItemsSource="{x:Bind Entries, Mode=OneWay}" Margin="0,30,0,0" Visibility="{Binding ItemsSource, ElementName=itemsRepeater, Converter={StaticResource EnumerableCountToVisibilityConverter}, Mode=OneWay}">
                            <ItemsRepeater.Layout>
                                <StackLayout Orientation="Vertical" />
                            </ItemsRepeater.Layout>

                            <ItemsRepeater.ItemTemplate>
                                <DataTemplate x:DataType="common:CallLogEntry">
                                    <Border BorderThickness="0,0,0,1" BorderBrush="{ThemeResource ButtonBorderThemeBrush}" Margin="30,0,30,10" Padding="0,0,0,10">
                                        <Grid ColumnSpacing="10">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="auto" />
                                                <ColumnDefinition Width="*" />
                                            </Grid.ColumnDefinitions>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="auto" />
                                                <RowDefinition Height="auto" />
                                            </Grid.RowDefinitions>
                                            <FontIcon Grid.RowSpan="1" Glyph="{x:Bind Converter={StaticResource CallLogEntryToFontIconGlyphConverter}}" Foreground="{x:Bind Converter={StaticResource CallLogEntryToFontIconColorConverter}}" />
                                            <TextBlock Grid.Row="0" Grid.Column="1" Text="{x:Bind Converter={StaticResource CallLogEntryToDetailStringConverter}}" TextWrapping="Wrap" />
                                            <TextBlock Grid.Row="1" Grid.Column="1" Text="{x:Bind Converter={StaticResource CallLogEntryToDurationStringConverter}}" FontWeight="{x:Bind Converter={StaticResource CallLogEntryToDurationFontWeightConverter}}" />
                                        </Grid>
                                    </Border>
                                </DataTemplate>
                            </ItemsRepeater.ItemTemplate>
                        </ItemsRepeater>
                    </StackPanel>
                </Grid>
                <Grid Visibility="{Binding Visibility, ElementName=gridContent, Converter={StaticResource VisibilityInverter}, Mode=OneWay}" Margin="30,0,30,0">
                    <StackPanel Visibility="{x:Bind HasCallLogs, Converter={StaticResource ValueToVisibilityConverter}, ConverterParameter='invert', Mode=OneWay}" VerticalAlignment="Center" Spacing="16">
                        <Grid HorizontalAlignment="Center" ColumnSpacing="8">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <FontIcon Grid.Column="0" Glyph="&#xE783;" VerticalAlignment="Top" />
                            <TextBlock Grid.Column="1" Text="{x:Bind NoCallLogsFoundText, Mode=OneWay}" TextAlignment="Center" TextWrapping="Wrap" Style="{ThemeResource BodyTextBlockStyle}"  VerticalAlignment="Center" />
                        </Grid>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="10">
                            <Button x:Name="buttonClearSearchTerm" Content="Clear Search Term" HorizontalAlignment="Center" Margin="0,8,0,0" MinWidth="{Binding ActualWidth, ElementName=buttonClearDateFilter, Mode=OneWay}" Visibility="{x:Bind SearchTerm, Converter={StaticResource ValueToVisibilityConverter}, Mode=OneWay}" Click="_buttonClearSearchTerm_Click" />
                            <Button x:Name="buttonClearDateFilter" Content="Clear Date Filter" HorizontalAlignment="Center" Margin="0,8,0,0" MinWidth="{Binding ActualWidth, ElementName=buttonClearSearchTerm, Mode=OneWay}" Visibility="{x:Bind DateFilterOptions.HasRange, Converter={StaticResource ValueToVisibilityConverter}, Mode=OneWay}" Click="_buttonClearDateFilter_Click" />
                        </StackPanel>
                    </StackPanel>
                </Grid>
            </Grid>
        </ScrollViewer>
    </Border>
</Page>
