<featurebase:FeaturePage
    x:Class="was.droidtransfer.features.calendars.CalendarsFeaturePage"
    xmlns:featurebase="using:was.droidtransfer.features"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:was.droidtransfer.features.calendars"
    xmlns:converters="using:was.droidtransfer.features.calendars.converters"
    xmlns:commonConverters="using:was.droidtransfer.features.converters"
    xmlns:ical="using:Ical.Net"
    xmlns:icalcomponents="using:Ical.Net.CalendarComponents"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
    mc:Ignorable="d" d:DataContext="{d:DesignInstance Type=local:CalendarsFeaturePage}">
    <Page.Resources>
        <ResourceDictionary>
            <converters:CalendarEventDateTimeToStringConverter x:Key="CalendarEventDateTimeToStringConverter"/>
            <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"/>
                    <AppBarButton x:Name="appBarButtonSaveICal" x:Uid="AppBarItemSaveICal" Label="XX Save as iCal" Style="{ThemeResource AppBarButtonStyle}"  IsEnabled="{x:Bind IsExportAvailable, Mode=OneWay}" Click="_appBarButtonSaveICal_Click">
                        <AppBarButton.Content>
                            <FontIcon Glyph="&#xE787;" Foreground="{ThemeResource AccentFillColorDefaultBrush}"/>
                        </AppBarButton.Content>
                    </AppBarButton>
                    <AppBarButton x:Name="appBarButtonSaveCSV" x:Uid="AppBarItemSaveCSV" Label="XX Save as CSV" Style="{ThemeResource AppBarButtonStyle}"  IsEnabled="{x:Bind appBarButtonSaveICal.IsEnabled, Mode=OneWay}" Click="_appBarButtonSaveCSV_Click">
                        <AppBarButton.Content>
                            <FontIcon Glyph="&#xE9F9;" Foreground="{ThemeResource AccentFillColorDefaultBrush}"/>
                        </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 -->
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <CalendarView x:Name="CalendarView" SelectedDatesChanged="_calendarView_SelectedDatesChanged" SelectionMode="Single" 
                      IsGroupLabelVisible="True" CalendarItemCornerRadius="6" 
                      OutOfScopeBackground="{ThemeResource ButtonDisabledBackgroundThemeBrush }"
                      HorizontalAlignment="Stretch" Margin="6,0,0,0">
                            <CalendarView.ContextFlyout>
                                <MenuFlyout>
                                    <MenuFlyoutItem x:Uid="MenuFLyoutItemToday" Text="XX Today" Click="_menuFlyoutItemToday_Click" />
                                </MenuFlyout>
                            </CalendarView.ContextFlyout>
                        </CalendarView>
                        <Button Grid.Row="1" x:Name="ButtonGoToToday" x:Uid="ButtonGoToToday" Style="{ThemeResource  SubtleButtonStyle}" FontSize="12"
                                Content="XX Go to Today" HorizontalAlignment="Right" Margin="0,5,2,0" Padding="2,0,2,0" Background="Transparent"
                                Click="ButtonGoToToday_Click"/>
                    </Grid>

                    <MenuFlyoutSeparator Grid.Row="1" Margin="0,5,0,10" />

                    <!-- 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.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">
                <Grid>
                    <!-- 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>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="50"/>
                                        <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'}" MinWidth="100"/>
                                    <Grid Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,3,0,0" Visibility="{x:Bind Alarms.Count, Converter={StaticResource ValueToVisibilityConverter}}">
                                        <FontIcon Glyph="&#xEA8F;"/>
                                    </Grid>
                                    <StackPanel Grid.Column="3">
                                        <TextBlock Text="{x:Bind Summary}" FontWeight="Medium"/>
                                        <TextBlock Text="{x:Bind Description}" x:Name="textBlockCalenderItemDescription" Visibility="{x:Bind Description, Converter={StaticResource ValueToVisibilityConverter}}"/>
                                        <Border Height="7" HorizontalAlignment="Stretch" Visibility="{Binding ElementName=textBlockCalenderItemDescription, Path=Visibility}"/>
                                    </StackPanel>
                                </Grid>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                    <!-- No Events Found -->
                    <Grid x:Name="gridNoEventsToDisplay">
                        <StackPanel VerticalAlignment="Center" Margin="20" HorizontalAlignment="Center">
                            <TextBlock x:Name="textBlockSelectedDate" Style="{ThemeResource CaptionTextBlockStyle}" TextAlignment="Center" />
                            <TextBlock x:Uid="TextBlockNoEventsMatchingSelection" Text="No events matching selection." Style="{ThemeResource SubheaderTextBlockStyle}" TextAlignment="Center" FontSize="22" />
                            <Line X1="0" X2="300" Y1="36" Y2="36" StrokeThickness="0.4" Stroke="{ThemeResource TextFillColorPrimary}" Opacity=".3" />
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,16,0,0" Spacing="8">
                                <TextBlock x:Uid="TextBlockViewingEventViewModeLabel" Text="XX Viewing" VerticalAlignment="Center" />
                                <ComboBox x:Name="comboBoxEventViewMode" SelectionChanged="_comboBoxEventViewMode_SelectionChanged">
                                    <ComboBoxItem x:Uid="ComboBoxItemEventViewModeSelectedDay" Content="XX Selected day only" />
                                    <ComboBoxItem x:Uid="ComboBoxItemEventViewModeWeek" Content="XX Upcoming 7 days"  />
                                    <ComboBoxItem x:Uid="ComboBoxItemEventViewModeMonth" Content="XX Upcoming month" />
                                    <ComboBoxItem x:Uid="ComboBoxItemEventViewModeYear" Content="XX Upcoming year"  />
                                    <ComboBoxItem x:Uid="ComboBoxItemEventViewModeFuture" Content="XX Upcoming 5 years" />
                                    <ComboBoxItem x:Uid="ComboBoxItemEventViewModeFarFuture" Content="XX All future events" />
                                </ComboBox>
                            </StackPanel>
                        </StackPanel>
                    </Grid>
                </Grid>
            </Border>
        </SplitView>
        <ContentDialog x:Name="contentDialogEmptyCalendarExport" x:Uid="ContentDialogEmptyCalendarExport" Title="XX Exporting Empty Calendar" PrimaryButtonText="XX Save Anyway" SecondaryButtonText="XX Include All Events" CloseButtonText="XX Skip" DefaultButton="Close">
            <StackPanel Spacing="16">
                <TextBlock x:Uid="TextBlockEmptyCalendarExportLineOne" Style="{ThemeResource BodyTextBlockStyle}" Text="XX One or more calendars do not contain events for the selection made and will result in an empty file." />
                <StackPanel>
                    <StackPanel Orientation="Horizontal" Spacing="4">
                        <TextBlock x:Uid="TextBlockEmptyCalendarExportDate" Style="{ThemeResource BodyStrongTextBlockStyle}" Text="XX Start Date:"/>
                        <TextBlock x:Name="textBlockEmptyCalendarExportDate" Style="{ThemeResource BodyTextBlockStyle}"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" Spacing="4">
                        <TextBlock x:Uid="TextBlockEmptyCalendarExportFilter" Style="{ThemeResource BodyStrongTextBlockStyle}" Text="XX Filter:"/>
                        <TextBlock x:Name="textBlockEmptyCalendarExportFilter" Style="{ThemeResource BodyTextBlockStyle}"/>
                    </StackPanel>
                </StackPanel>
                <TextBlock x:Uid="TextBlockEmptyCalendarExportLineTwo" Style="{ThemeResource BodyTextBlockStyle}" Text="XX Should the file be saved anyway, or should the selection be expanded to include all events for the calendar? Alternatively the calendar can be skipped." />
                <CheckBox x:Uid="CheckBoxEmptyCalendarExportRemember" x:Name="checkBoxEmptyCalendarExportRemember" Content="XX Remember my selection for future exports." />
            </StackPanel>
        </ContentDialog>
    </Grid>
</featurebase:FeaturePage>
