<Page
    x:Class="was.touchcopy.features.reminders.RemindersContentPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:was.touchcopy.features.reminders"
    xmlns:coreconverters="using:was.touchcopy.features.converters"
    xmlns:converters="using:was.touchcopy.features.reminders.converters"
    xmlns:data="using:was.touchcopy.features.reminders.data"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DataContext="{d:DesignInstance Type=local:RemindersContentPage}"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Page.Resources>
        <ResourceDictionary>
            <converters:ColorStringToColorConverter x:Key="ColorStringToColorConverter" />
            <converters:ReminderCompletionToOpacityConverter x:Key="ReminderCompletionToOpacityConverter" />
            <converters:ReminderSectionIsDefaultToOpacityConverter x:Key="ReminderSectionIsDefaultToOpacityConverter" />
            <converters:ReminderPriorityToExclamationStringConverter x:Key="ReminderPriorityToExclamationStringConverter" />
            <converters:ReminderPriorityToVisibilityConverter x:Key="ReminderPriorityToVisibilityConverter" />
            <converters:RemindersItemsToChildrenVisibilityConverter x:Key="RemindersItemsToChildrenVisibilityConverter" />
            <converters:RemindersListToDisplayTitleConverter x:Key="RemindersListToDisplayTitleConverter" />
            <converters:RemindersListToItemsSourceConverter x:Key="RemindersListToItemsSourceConverter" />
            <converters:RemindersTagListToStringConverter x:Key="RemindersTagListToStringConverter" />
            <coreconverters:ValueToVisibilityConverter x:Key="ValueToVisibilityConverter" />
            <DataTemplate x:Key="SubListDataTemplate" x:DataType="data:RemindersList">
                <StackPanel Orientation="Vertical">
                    <Border Background="{x:Bind ColorString, Converter={StaticResource ColorStringToColorConverter}}" Height="2" HorizontalAlignment="Stretch" Margin="0,8,0,4" />
                    <TextBlock Text="{x:Bind Title}" Style="{ThemeResource SubtitleTextBlockStyle}" Foreground="{x:Bind ColorString, Converter={StaticResource ColorStringToColorConverter}}" TextTrimming="WordEllipsis" TextWrapping="NoWrap" />
                    <ItemsRepeater ItemsSource="{x:Bind Sections}" Margin="0,10,0,0" ItemTemplate="{StaticResource RemindersItemTemplateSelector}">
                        <ItemsRepeater.Layout>
                            <StackLayout Orientation="Vertical" />
                        </ItemsRepeater.Layout>
                    </ItemsRepeater>
                </StackPanel>
            </DataTemplate>
            <DataTemplate x:Key="SectionDataTemplate" x:DataType="data:RemindersSection">
                <StackPanel Orientation="Vertical" Padding="0,0,0,16">
                    <TextBlock Text="{x:Bind DisplayName}" Style="{ThemeResource SubtitleTextBlockStyle}" TextTrimming="WordEllipsis" TextWrapping="NoWrap" Visibility="{x:Bind DisplayName, Converter={StaticResource ValueToVisibilityConverter}}" Opacity="{x:Bind IsDefault, Converter={StaticResource ReminderSectionIsDefaultToOpacityConverter}}" />
                    <ItemsRepeater ItemsSource="{x:Bind Items}" Margin="0,10,0,0" ItemTemplate="{StaticResource RemindersItemTemplateSelector}">
                        <ItemsRepeater.Layout>
                            <StackLayout Orientation="Vertical" />
                        </ItemsRepeater.Layout>
                    </ItemsRepeater>
                    <Border Background="{ThemeResource TextFillColorPrimary}" Height="1" Opacity=".3" Margin="0,16,0,0" Visibility="{x:Bind IsDefault, Converter={StaticResource ValueToVisibilityConverter}, ConverterParameter='invert'}" />
                </StackPanel>
            </DataTemplate>
            <DataTemplate x:Key="SubsectionDataTemplate" x:DataType="data:RemindersSection">
                <StackPanel Orientation="Vertical" Padding="0,0,0,16">
                    <TextBlock Text="{x:Bind DisplayName}" Style="{ThemeResource BodyStrongTextBlockStyle}" TextTrimming="WordEllipsis" TextWrapping="NoWrap" Visibility="{x:Bind DisplayName, Converter={StaticResource ValueToVisibilityConverter}}" Opacity="{x:Bind IsDefault, Converter={StaticResource ReminderSectionIsDefaultToOpacityConverter}}" />
                    <ItemsRepeater ItemsSource="{x:Bind Items}" Margin="0,10,0,0" ItemTemplate="{StaticResource RemindersItemTemplateSelector}">
                        <ItemsRepeater.Layout>
                            <StackLayout Orientation="Vertical" />
                        </ItemsRepeater.Layout>
                    </ItemsRepeater>
                    <Border Background="{ThemeResource TextFillColorPrimary}" Height="1" Opacity=".3" Margin="0,16,0,0" Visibility="{x:Bind IsDefault, Converter={StaticResource ValueToVisibilityConverter}, ConverterParameter='invert'}" />
                </StackPanel>
            </DataTemplate>
            <DataTemplate x:Key="ItemDataTemplate" x:DataType="data:RemindersItem">
                <Grid Margin="0,5,0,5" ColumnSpacing="8">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                    </Grid.RowDefinitions>
                    <Grid VerticalAlignment="Top">
                        <Border Width="20" Height="20" BorderBrush="{x:Bind ColorString, Converter={StaticResource ColorStringToColorConverter}}" BorderThickness="1.2" CornerRadius="12" />
                        <Border Width="12" Height="12" Background="{x:Bind ColorString, Converter={StaticResource ColorStringToColorConverter}}" CornerRadius="9" Visibility="{x:Bind IsCompleted}" />
                    </Grid>
                    <Grid Grid.Column="1" HorizontalAlignment="Stretch">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="{x:Bind Priority, Converter={StaticResource ReminderPriorityToExclamationStringConverter}}" FontWeight="SemiBold" Foreground="{x:Bind ColorString, Converter={StaticResource ColorStringToColorConverter}}" Opacity=".7" Margin="0,0,5,0" Visibility="{x:Bind Priority, Converter={StaticResource ReminderPriorityToVisibilityConverter}}" />
                        <TextBlock Grid.Column="1" Text="{x:Bind Title}" TextWrapping="Wrap" Opacity="{x:Bind IsCompleted, Converter={StaticResource ReminderCompletionToOpacityConverter}}" />
                    </Grid>
                    <TextBlock Grid.Column="1" Grid.Row="1" Text="{x:Bind Note}" Opacity=".7" TextWrapping="Wrap" Visibility="{x:Bind Note, Converter={StaticResource ValueToVisibilityConverter}}" />
                    <local:RemindersItemInlineDetailControl Grid.Column="1" Grid.Row="2" ReminderItem="{x:Bind}" />
                    <TextBlock Grid.Column="1" Grid.Row="3" Text="{x:Bind Tags, Converter={StaticResource RemindersTagListToStringConverter}}" TextWrapping="Wrap" Visibility="{x:Bind Tags, Converter={StaticResource ValueToVisibilityConverter}}" Foreground="{x:Bind ColorString, Converter={StaticResource ColorStringToColorConverter}}" Style="{ThemeResource CaptionTextBlockStyle}" FontWeight="SemiBold" Padding="0,4,0,0" />
                    <local:RemindersItemTriggerDetailControl Grid.Column="1" Grid.Row="4" ReminderItem="{x:Bind}" />
                    <local:RemindersItemAttachmentDetailControl Grid.Column="1" Grid.Row="5" ReminderItem="{x:Bind}" />
                    <ItemsRepeater Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="6" ItemsSource="{x:Bind Children}" ItemTemplate="{StaticResource RemindersItemTemplateSelector}" Visibility="{x:Bind Children, Converter={StaticResource RemindersItemsToChildrenVisibilityConverter}}" Margin="0,10,0,0">
                        <ItemsRepeater.Layout>
                            <StackLayout Orientation="Vertical" />
                        </ItemsRepeater.Layout>
                    </ItemsRepeater>
                    <FontIcon Grid.Column="2" Glyph="&#xe7c1;" Foreground="{ThemeResource SystemAccentColor}" Margin="8,0,0,0" Visibility="{x:Bind IsFlagged, Converter={StaticResource ValueToVisibilityConverter}}" VerticalAlignment="Top" />
                </Grid>
            </DataTemplate>
            <DataTemplate x:Key="ItemProxyDataTemplate" x:DataType="data:RemindersItemProxy">
                <Grid Margin="0,5,0,5" ColumnSpacing="8">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                    </Grid.RowDefinitions>
                    <Grid VerticalAlignment="Top">
                        <Border Width="20" Height="20" BorderBrush="{x:Bind ColorString, Converter={StaticResource ColorStringToColorConverter}}" BorderThickness="1.2" CornerRadius="12" />
                        <Border Width="12" Height="12" Background="{x:Bind ColorString, Converter={StaticResource ColorStringToColorConverter}}" CornerRadius="9" Visibility="{x:Bind IsCompleted}" />
                    </Grid>
                    <Grid Grid.Column="1" HorizontalAlignment="Stretch">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="{x:Bind Priority, Converter={StaticResource ReminderPriorityToExclamationStringConverter}}" FontWeight="SemiBold" Foreground="{x:Bind ColorString, Converter={StaticResource ColorStringToColorConverter}}" Opacity=".7" Margin="0,0,5,0" Visibility="{x:Bind Priority, Converter={StaticResource ReminderPriorityToVisibilityConverter}}" />
                        <TextBlock Grid.Column="1" Text="{x:Bind Title}" TextWrapping="Wrap" Opacity="{x:Bind IsCompleted, Converter={StaticResource ReminderCompletionToOpacityConverter}}" />
                    </Grid>
                    <TextBlock Grid.Column="1" Grid.Row="1" Text="{x:Bind Note}" Opacity=".7" TextWrapping="Wrap" Visibility="{x:Bind Note, Converter={StaticResource ValueToVisibilityConverter}}" />
                    <local:RemindersItemInlineDetailControl Grid.Column="1" Grid.Row="2" ReminderItem="{x:Bind}" />
                    <TextBlock Grid.Column="1" Grid.Row="3" Text="{x:Bind Tags, Converter={StaticResource RemindersTagListToStringConverter}}" TextWrapping="Wrap" Visibility="{x:Bind Tags, Converter={StaticResource ValueToVisibilityConverter}}" Foreground="{x:Bind ColorString, Converter={StaticResource ColorStringToColorConverter}}" Style="{ThemeResource CaptionTextBlockStyle}" FontWeight="SemiBold" Padding="0,4,0,0" />
                    <local:RemindersItemTriggerDetailControl Grid.Column="1" Grid.Row="4" ReminderItem="{x:Bind}" />
                    <local:RemindersItemAttachmentDetailControl Grid.Column="1" Grid.Row="5" ReminderItem="{x:Bind}" />
                    <ItemsRepeater Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="6" ItemsSource="{x:Bind Children}" ItemTemplate="{StaticResource RemindersItemTemplateSelector}" Visibility="{x:Bind Children, Converter={StaticResource RemindersItemsToChildrenVisibilityConverter}}" Margin="0,10,0,0">
                        <ItemsRepeater.Layout>
                            <StackLayout Orientation="Vertical" />
                        </ItemsRepeater.Layout>
                    </ItemsRepeater>
                    <FontIcon Grid.Column="2" Glyph="&#xe7c1;" Foreground="{ThemeResource SystemAccentColor}" Margin="8,0,0,0" Visibility="{x:Bind IsFlagged, Converter={StaticResource ValueToVisibilityConverter}}" VerticalAlignment="Top" />
                </Grid>
            </DataTemplate>
            <local:RemindersItemTemplateSelector x:Key="RemindersItemTemplateSelector" SubListDataTemplate="{StaticResource SubListDataTemplate}" SectionDataTemplate="{StaticResource SectionDataTemplate}" SubsectionDataTemplate="{StaticResource SubsectionDataTemplate}" ItemDataTemplate="{StaticResource ItemDataTemplate}" ItemProxyDataTemplate="{StaticResource ItemProxyDataTemplate}" />
        </ResourceDictionary>
    </Page.Resources>
    <Border Style="{ThemeResource FeatureContentPageBorder}" Padding="0">
        <Grid  Background="{ThemeResource CardBackgroundFillColorDefaultBrush}">
            <ScrollViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="30,20,20,0">
                <StackPanel Orientation="Vertical">
                    <TextBlock Text="{x:Bind RemindersList, Converter={StaticResource RemindersListToDisplayTitleConverter}, Mode=OneWay}" Style="{ThemeResource TitleTextBlockStyle}" Foreground="{x:Bind RemindersList.ColorString, Mode=OneWay, Converter={StaticResource ColorStringToColorConverter}}" TextTrimming="WordEllipsis" TextWrapping="NoWrap" />
                    <ItemsRepeater ItemsSource="{x:Bind RemindersList, Converter={StaticResource RemindersListToItemsSourceConverter}, Mode=OneWay}" Margin="0,10,0,0" ItemTemplate="{StaticResource RemindersItemTemplateSelector}">
                        <ItemsRepeater.Layout>
                            <StackLayout Orientation="Vertical" />
                        </ItemsRepeater.Layout>
                    </ItemsRepeater>
                </StackPanel>
            </ScrollViewer>
            <Grid Padding="20" Visibility="{x:Bind RemindersList.IsEmpty, Converter={StaticResource ValueToVisibilityConverter}, Mode=OneWay}">
                <TextBlock x:Uid="TextBlockNoReminders" Text="XX No Reminders" Style="{ThemeResource BodyStrongTextBlockStyle}" VerticalAlignment="Center" TextAlignment="Center" Opacity="0.7" />
            </Grid>
        </Grid>
    </Border>
</Page>
