<Page
    x:Name="pageRoot"
    x:Class="SSRS.Viewer.App.ReportsPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SSRS.Viewer.App"
    xmlns:data="using:SSRS.Viewer.App.Data"
    xmlns:common="using:SSRS.Viewer.App.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>

        <local:CatalogItemTemplateSelector x:Key="CatalogItemTemplateSelector">
            <local:CatalogItemTemplateSelector.Resources>
                <ResourceDictionary>
                    <DataTemplate x:Key="Report">
                        <Grid Margin="6,10,0,10" Height="64" >
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="64"/>
                                <ColumnDefinition Width="224"/>
                            </Grid.ColumnDefinitions>
                            <Image Source="Assets/ReportImage.png" />
                            <StackPanel Grid.Column="1" Margin="20,0,0,0" VerticalAlignment="Center">
                                <TextBlock Text="{Binding Name}" TextTrimming="CharacterEllipsis"/>
                                <TextBlock Text="{Binding Description}" Margin="0,8,0,0" TextTrimming="CharacterEllipsis"
                                           Foreground="{ThemeResource ToolTipBorderThemeBrush}"
                                           TextWrapping="WrapWholeWords" FontSize="12" Height="32"/>
                            </StackPanel>
                        </Grid>
                    </DataTemplate>
                </ResourceDictionary>
            </local:CatalogItemTemplateSelector.Resources>
        </local:CatalogItemTemplateSelector>

    </Page.Resources>

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="80"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <ProgressRing x:Name="loadProgressRing" Grid.RowSpan="4" Width="55" Height="55" Foreground="#FF5BCDC8" />

        <Border Grid.Row="1" BorderThickness="0,1,0,1" BorderBrush="{ThemeResource ToolTipBorderThemeBrush}">
            <StackPanel Margin="100, 0, 0, 0" Orientation="Horizontal">
                <StackPanel Orientation="Vertical" VerticalAlignment="Center">
                    <TextBlock FontSize="16" Text="SSRS Folder URL:" FontWeight="Bold" />
                    <TextBlock x:Name="txtPathLabel" Margin="0, 4, 0, 0" FontSize="14" />
                </StackPanel>
                <AppBarButton
                    x:Name="btnMoreLess" IsCompact="True" Margin="10,0,0,0"
                    ToolTipService.ToolTip="Edit URL and Credentials"
                    ToolTipService.Placement="Top">
                    
                    <AppBarButton.Icon>
                        <FontIcon FontFamily="Segoe UI Symbol" FontSize="22" Glyph="&#xE10C;"/>
                    </AppBarButton.Icon>
                    <AppBarButton.Flyout>
                        <Flyout Closed="Flyout_Closed" Opened="Flyout_Opened">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="10"/>
                                    <ColumnDefinition Width="*"/>
                                </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>

                                <TextBlock Grid.ColumnSpan="3" FontSize="16" Margin="0,12,0,0">Report Server URL:</TextBlock>
                                <TextBox x:Name="tbReportServer" Grid.Row="1" Grid.ColumnSpan="3" Width="390" />
                                <TextBlock FontSize="16" Grid.Row="2" Grid.ColumnSpan="3" Margin="0,20,0,0">Folder:</TextBlock>
                                <TextBox x:Name="tbFolder" Grid.Row="3" Grid.ColumnSpan="3" Width="390" />
                                <TextBlock FontSize="16" Grid.Row="4" Margin="0,20,0,0">User Name:</TextBlock>
                                <TextBox x:Name="tbUserName" Grid.Row="5" HorizontalAlignment="Left" Width="190" />
                                <TextBlock FontSize="16" Grid.Row="4" Grid.Column="2" Margin="0,20,0,0">Password:</TextBlock>
                                <PasswordBox x:Name="tbPassword" Grid.Row="5" Grid.Column="2" HorizontalAlignment="Left" Width="190" />
                                <StackPanel Orientation="Horizontal" Grid.Row="6" Grid.ColumnSpan="3" Margin="0,20,0,0" HorizontalAlignment="Right">
                                    <Button x:Name="btnOkFlyout" Content="OK" Click="btnOkFlyout_Click" Width="100" />
                                    <Button x:Name="btnCancelFlyout" Margin="10,0,0,0" Content="Cancel" Click="btnCancelFlyout_Click" Width="100" />
                                </StackPanel>
                            </Grid>
                        </Flyout>
                    </AppBarButton.Flyout>
                </AppBarButton>

                <Button x:Name="btnConnect" Content="Connect" VerticalAlignment="Center" Margin="10,0,0,0" FontSize="16" Click="btnConnect_Click" />
            </StackPanel>
        </Border>

        <TextBlock
            x:Name="reportsTitle"
            Grid.Row="2"
            FontSize="30"
            Margin="100, 0, 0, 0"
            VerticalAlignment="Bottom"
            Text="Select a report from the list:"
            Visibility="Collapsed"
            />

        <ListView 
            x:Name="reportsList"
            ItemTemplateSelector="{StaticResource CatalogItemTemplateSelector}"
            TabIndex="1"
            Grid.Row="3"
            Visibility="Collapsed"
            Margin="91,30,50,50"
            SelectionMode="None"
            IsSwipeEnabled="false"
            IsItemClickEnabled="True"
            ItemClick="Reports_ItemClick"
            >
            <ListView.ItemContainerTransitions>
                <TransitionCollection />
            </ListView.ItemContainerTransitions>
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapGrid Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
        </ListView>

        <!-- Page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="100"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <TextBlock x:Name="pageTitle" Text="C1 SSRS Report Viewer" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1" 
                        IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,40"/>
        </Grid>
    </Grid>
</Page>
