<featurebase:FeaturePage
    x:Class="was.touchcopy.features.calendar.CalendarPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:was.touchcopy.features.calendar"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:featurebase="using:was.touchcopy.features" 
    xmlns:converters="using:was.touchcopy.features.calendar.converters"
    xmlns:commonConverters="using:was.touchcopy.features.converters"
    xmlns:ical="using:Ical.Net"
    xmlns:icalcomponents="using:Ical.Net.CalendarComponents"
    xmlns:calendardata="using:was.touchcopy.features.calendar.data" 
    xmlns:utilities="using:was.touchcopy.features.utilities"
    d:DataContext="{d:DesignInstance Type=local:CalendarPage}"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Page.Resources>
        <ResourceDictionary>
            <converters:CalendarEventDateTimeToStringConverter x:Key="CalendarEventDateTimeToStringConverter"/>
            <converters:CalendarEventToAttachmentListConverter x:Key="CalendarEventToAttachmentListConverter" />
            <converters:CalendarEventToAttachmentVisibilityConverter x:Key="CalendarEventToAttachmentVisibilityConverter" />
            <converters:CalendarDateToListHeaderStringConverter x:Key="CalendarDateToListHeaderStringConverter"/>
            <converters:ICalPropertiesToColorConverter x:Key="ICalPropertiesToColorConverter"/>
            <converters:ICalPropertiesToCalendarName x:Key="ICalPropertiesToCalendarName"/>
            <commonConverters:ValueToVisibilityConverter x:Key="ValueToVisibilityConverter"/>
        </ResourceDictionary>
    </Page.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Border Style="{ThemeResource PageHeaderBorderStyle}">
            <Grid>
                <CommandBar Style="{ThemeResource PageHeaderCommandBarStyle}">
                    <featurebase:CopyProgressAppBarUserController x:Name="copyProgressUserControl" Visibility="Collapsed" OnCancelTapped="_copyProgressUserControl_OnCancelTapped" MaxWidth="350"/>
                    <AppBarButton x:Name="appBarButtonSaveICal" x:Uid="AppBarItemSaveICal" Label="XX Save as iCal" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonSaveICal_Click" IsEnabled="{x:Bind IsExportAvailable, Mode=OneWay}">
                        <AppBarButton.Content>
                            <FontIcon Glyph="&#xE787;" Foreground="{x:Bind utilities:AppBarUtilities.BrushForAppBarIcon(appBarButtonSaveICal.IsEnabled), Mode=OneWay}"/>
                        </AppBarButton.Content>
                    </AppBarButton>
                    <AppBarButton x:Name="appBarButtonSaveCSV" x:Uid="AppBarItemSaveCSV" Label="XX Save as CSV" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonSaveCSV_Click" IsEnabled="{x:Bind appBarButtonSaveICal.IsEnabled, Mode=OneWay}">
                        <AppBarButton.Content>
                            <FontIcon Glyph="&#xE9F9;" Foreground="{x:Bind utilities:AppBarUtilities.BrushForAppBarIcon(appBarButtonSaveCSV.IsEnabled), Mode=OneWay}"/>
                        </AppBarButton.Content>
                    </AppBarButton>
                </CommandBar>
                <TextBlock Text="{Binding PageTitle }" Style="{ThemeResource PageHeaderTitleStyle}"/>
            </Grid>
        </Border>

        <SplitView Grid.Row="1"  Style="{ThemeResource FeatureSplitViewStyle}" OpenPaneLength="350">
            <SplitView.Pane>
                <Grid Margin="5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <!-- Calendar Date Picker -->
                    <CalendarView x:Name="CalendarView" SelectedDatesChanged="_calendarView_SelectedDatesChanged"
                                  SelectionMode="Single" IsGroupLabelVisible="True" HorizontalAlignment="Stretch" Margin="6,0,0,0">
                        <CalendarView.ContextFlyout>
                            <MenuFlyout>
                                <MenuFlyoutItem x:Uid="MenuFlyoutItemGoToToday" Text="XX Go to Today" Click="_menuFlyoutItemGoToToday_Click">
                                    <MenuFlyoutItem.Icon>
                                        <FontIcon Glyph="&#xE8D1;" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                            </MenuFlyout>
                        </CalendarView.ContextFlyout>
                    </CalendarView>
                    <HyperlinkButton Grid.Row="1" HorizontalAlignment="Center" Click="_hyperlinkButtonGoToToday_Click" Margin="8,8,8,0">
                        <StackPanel Orientation="Horizontal" Spacing="5">
                            <FontIcon Glyph="&#xE8D1;" />
                            <TextBlock x:Uid="TextBlockGoToToday" Text="XX Go to Today" Style="{ThemeResource BodyTextBlockStyle}" />
                        </StackPanel>
                    </HyperlinkButton>

                    <!-- Calendars List View -->
                    <ListView x:Name="listViewCalendars" Grid.Row="2" Margin="0,0,0,0" SelectionMode="Multiple" IsMultiSelectCheckBoxEnabled="True"
                              ItemsSource="{Binding CalendarGroups.View}">
                        <ListView.Resources>
                            <SolidColorBrush x:Key="ListViewItemBackgroundSelected" Color="{ThemeResource SolidBackgroundFillColorBase}" />
                            <SolidColorBrush x:Key="ListViewItemBackgroundSelectedPointerOver" Color="{ThemeResource SolidBackgroundFillColorBase}" />
                        </ListView.Resources>
                        <ListView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <ItemsStackPanel AreStickyGroupHeadersEnabled="False"/>
                            </ItemsPanelTemplate>
                        </ListView.ItemsPanel>
                        <ListView.GroupStyle>
                            <GroupStyle HidesIfEmpty="True">
                                <GroupStyle.HeaderTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Key}" />
                                    </DataTemplate>
                                </GroupStyle.HeaderTemplate>
                            </GroupStyle>
                        </ListView.GroupStyle>
                        <ListView.ItemTemplate>
                            <DataTemplate x:DataType="ical:Calendar">
                                <ListViewItem>

                                    <ListViewItem.ContextFlyout>
                                        <MenuFlyout>
                                            <MenuFlyoutItem x:Name="calendarMenuItemSaveICal" x:Uid="menuItemSaveICal" Text="XX Save as iCal" Click="_appBarButtonSaveICal_Click">
                                                <MenuFlyoutItem.Icon >
                                                    <FontIcon Glyph="&#xE787;"/>
                                                </MenuFlyoutItem.Icon>
                                            </MenuFlyoutItem>
                                            <MenuFlyoutItem x:Name="calendarMenuItemSaveCSV" x:Uid="menuItemSaveCSV" Text="XX Save as CSV" Click="_appBarButtonSaveCSV_Click">
                                                <MenuFlyoutItem.Icon >
                                                    <FontIcon Glyph="&#xE9F9;"/>
                                                </MenuFlyoutItem.Icon>
                                            </MenuFlyoutItem>
                                            <MenuFlyoutSeparator/>
                                            <MenuFlyoutItem x:Name="calendarmenuItemDisableAll" x:Uid="calendarmenuItemDisableAll" Text="XX Uncheck All" Click="_calendarMenuItemDisableAll_Click">
                                                <MenuFlyoutItem.Icon >
                                                    <FontIcon Glyph="&#xE739;"/>
                                                </MenuFlyoutItem.Icon>
                                            </MenuFlyoutItem>
                                            <MenuFlyoutItem x:Name="calendarmenuItemEnableAll" x:Uid="calendarmenuItemEnableAll" Text="XX Check All" Click="_calendarMenuItemEnableAll_Click">
                                                <MenuFlyoutItem.Icon >
                                                    <FontIcon Glyph="&#xE73A;"/>
                                                </MenuFlyoutItem.Icon>
                                            </MenuFlyoutItem>
                                        </MenuFlyout>
                                    </ListViewItem.ContextFlyout>

                                    <ListViewItem.Content>
                                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
                                            <Border Width="10" Height="20" Background="{Binding Properties, Converter={StaticResource ICalPropertiesToColorConverter}}"  CornerRadius="4" Margin="5,0"/>
                                            <TextBlock Text="{x:Bind Properties, Converter={StaticResource ICalPropertiesToCalendarName}}" VerticalAlignment="Center" Margin="3,0,0,1"/>
                                        </StackPanel>
                                    </ListViewItem.Content>
                                </ListViewItem>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                </Grid>
            </SplitView.Pane>
            <Border Style="{ThemeResource FeatureContentPageBorder}" Padding="0" Background="{ThemeResource CardBackgroundFillColorDefaultBrush}">

                <!-- Calendar Item List View -->
                <ListView x:Name="listViewCalendarItems" ItemsSource="{Binding CalendarItemGroups.View}" IsDoubleTapEnabled="True" DoubleTapped="_listViewCalendarItems_DoubleTapped">
                    <ListView.GroupStyle>
                        <GroupStyle HidesIfEmpty="True">
                            <GroupStyle.HeaderTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Key, Converter={StaticResource CalendarDateToListHeaderStringConverter}}" />
                                </DataTemplate>
                            </GroupStyle.HeaderTemplate>
                        </GroupStyle>
                    </ListView.GroupStyle>
                    <ListView.ItemTemplate>
                        <DataTemplate x:DataType="icalcomponents:CalendarEvent">
                            <Grid Padding="0,4,0,4" Background="#00000000">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="auto"/>
                                    <ColumnDefinition Width="200"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Grid.Resources>
                                    <Style TargetType="TextBlock">
                                        <Setter Property="TextWrapping" Value="Wrap"/>
                                    </Style>
                                </Grid.Resources>
                                <Border Width="10" Height="20" CornerRadius="4" Margin="5,3" VerticalAlignment="Top" Background="{x:Bind Properties, Converter={StaticResource ICalPropertiesToColorConverter}}"/>
                                <TextBlock Grid.Column="1" VerticalAlignment="Top" Margin="5,2,0,0" x:Uid="textBlockCalendarEventDateTime"
                                Text="{x:Bind Converter={StaticResource CalendarEventDateTimeToStringConverter }, ConverterParameter='All Day'}"/>

                                <StackPanel Grid.Column="2" >
                                    <TextBlock Text="{x:Bind Summary}" FontWeight="Medium" Margin="0,0,0,2"/>
                                    <Grid Margin="10,2,0,2"  Visibility="{x:Bind Description, Converter={StaticResource ValueToVisibilityConverter}}">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>
                                        <FontIcon Grid.Column="0"  Glyph="&#xE70b;" FontFamily="Segoe MDL2 Assets" FontSize="14" Margin="0,4,0,0" VerticalAlignment="Top" />
                                        <TextBlock Grid.Column="1" Text="{x:Bind Description}" Margin="5,0,0,0"/>
                                    </Grid>
                                    <StackPanel Orientation="Horizontal" Spacing="4" Margin="10,2,0,2" Visibility="{x:Bind Url, Converter={StaticResource ValueToVisibilityConverter}}" >
                                        <FontIcon Grid.Column="3"  Glyph="&#59252;" FontFamily="Segoe MDL2 Assets" FontSize="14" />
                                        <HyperlinkButton  Margin="-4,0,0,4"  Padding="4" NavigateUri="{x:Bind Url}">
                                            <TextBlock Text="{x:Bind Url}" Style="{ThemeResource CaptionTextBlockStyle}"/>
                                        </HyperlinkButton>
                                    </StackPanel>
                                    <ItemsRepeater ItemsSource="{x:Bind Converter={StaticResource CalendarEventToAttachmentListConverter}}" 
                                                   Visibility="{x:Bind Converter={StaticResource CalendarEventToAttachmentVisibilityConverter}}"
                                                   Margin="10,2,0,2">
                                        <ItemsRepeater.ItemTemplate>
                                            <DataTemplate x:DataType="calendardata:CalendarAttachment">
                                                <StackPanel Orientation="Horizontal" Spacing="4" Margin="0,2,0,2">
                                                    <FontIcon Grid.Column="3" Glyph="&#xe723;" FontFamily="Segoe MDL2 Assets" FontSize="14" />
                                                    <TextBlock Text="{x:Bind Name}" Style="{ThemeResource CaptionTextBlockStyle}" FontStyle="Italic" />
                                                </StackPanel>
                                            </DataTemplate>
                                        </ItemsRepeater.ItemTemplate>
                                    </ItemsRepeater>
                                </StackPanel>
                                <Grid.ContextFlyout>
                                    <MenuFlyout>
                                        <MenuFlyoutItem Text="{x:Bind Summary}" Margin="-28,0,0,0" IsEnabled="False" />
                                        <MenuFlyoutItem x:Uid="MenuFlyoutItemSaveAsICal" Text="XX Save as iCal" Click="_menuFlyoutItemSaveICal_Click">
                                            <MenuFlyoutItem.Icon >
                                                <FontIcon Glyph="&#xE787;"/>
                                            </MenuFlyoutItem.Icon>
                                        </MenuFlyoutItem>
                                        <MenuFlyoutItem x:Uid="MenuFlyoutItemSaveNote" Text="XX Save Note" Click="_menuFlyoutItemSaveNote_Click" Visibility="{x:Bind Description, Converter={StaticResource ValueToVisibilityConverter}}">
                                            <MenuFlyoutItem.Icon >
                                                <FontIcon Glyph="&#xE70B;"/>
                                            </MenuFlyoutItem.Icon>
                                        </MenuFlyoutItem>
                                        <!--<MenuFlyoutItem x:Uid="MenuFlyoutItemSaveAttachment" Text="XX Save Attachment" Click="_menuFlyoutItemSaveAttachement_Click" Visibility="{x:Bind Converter={StaticResource CalendarEventToAttachmentVisibilityConverter}}">
                                            <MenuFlyoutItem.Icon >
                                                <FontIcon Glyph="&#xE70B;"/> 
                                            </MenuFlyoutItem.Icon>
                                        </MenuFlyoutItem>-->
                                        <MenuFlyoutItem x:Uid="MenuFlyoutItemSaveUrl" Text="XX Save URL" Click="_menuFlyoutItemSaveUrl_Click" Visibility="{x:Bind Url, Converter={StaticResource ValueToVisibilityConverter}}">
                                            <MenuFlyoutItem.Icon >
                                                <FontIcon Glyph="&#xE774;"/>
                                            </MenuFlyoutItem.Icon>
                                        </MenuFlyoutItem>
                                    </MenuFlyout>
                                </Grid.ContextFlyout>
                            </Grid>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

            </Border>
        </SplitView>
    </Grid>
</featurebase:FeaturePage>
