<Page
    x:Class="PCUT.Pages.LogInformationPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:PCUT.Pages"
    xmlns:localCV="using:PCUT.Converters"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:viewmodels="using:PCUT.ViewModels"
    mc:Ignorable="d"
    Loaded="Page_Loaded">
    <Page.Resources>
        <localCV:LogTimestampConverter x:Key="timestampConverter"/>
    </Page.Resources>
    <Page.DataContext>
        <viewmodels:LogViewModel/>
    </Page.DataContext>
    <Page.Background>
        <SolidColorBrush Color="White" />
    </Page.Background>

    <Page.Transitions>
        <TransitionCollection>
            <EntranceThemeTransition />
        </TransitionCollection>
    </Page.Transitions>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="0.1*"/>
            <RowDefinition Height="0.8*"/>
            <RowDefinition Height="0.1*"/>
        </Grid.RowDefinitions>
        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="0.7*" />
                <ColumnDefinition Width="0.15*" />
                <ColumnDefinition Width="0.15*"/>
            </Grid.ColumnDefinitions>
            <ComboBox
                Grid.Column="1"
                x:Name="Users"
                ItemsSource="{Binding Users.Items}"
                DisplayMemberPath="UserName"
                SelectedIndex="{Binding Users.SelectedIndex, Mode=TwoWay}"
                PlaceholderText="Users"
                IsTextSearchEnabled="True"
                Margin="5,0,5,0"
                HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
            <ComboBox
                Grid.Column="2"
                x:Name="Types"
                ItemsSource="{Binding Types.Items}"
                PlaceholderText="Log Types"
                SelectedIndex="{Binding Types.SelectedIndex, Mode=TwoWay}"
                Margin="5,0,5,0"
                HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
        </Grid>
        <Grid Grid.Row="2">
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
                <Button x:Name="btnFirst" Content="First" Click="btnFirst_Click"/>
                <Button x:Name="btnPrevious" Content="Previous" Click="btnPrevious_Click"/>
                <TextBlock x:Name="txtPageNumber" VerticalAlignment="Center" Margin="10">
                    <Run Text="{Binding Pagination.Page, Mode=OneWay}" />
                    <Run Text="/" />
                    <Run Text="{Binding Pagination.TotalPage, Mode=OneWay}" />
                </TextBlock>
                <Button x:Name="btnNext" Content="Next" Click="btnNext_Click"/>
                <Button x:Name="btnLast" Content="Last" Click="btnLast_Click"/>
                <ComboBox
                    VerticalAlignment="Center"
                    ItemsSource="{Binding Pagination.AvailablePageSizes}"
                    SelectedItem="{Binding Pagination.PageSize, Mode=TwoWay}" />
                <TextBlock VerticalAlignment="Center" Text="records/page"/>
                <TextBlock  VerticalAlignment="Center">
                    <Run Text=" (total" />
                    <Run Text="{Binding Pagination.TotalRecords, Mode=TwoWay}" />
                    <Run Text="records)" />
                </TextBlock>
            </StackPanel>
        </Grid>
        <ListView Grid.Row="1" ItemsSource="{Binding Logs}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <TextBlock>
                        <Run  Text="{Binding Timestamp, Converter={StaticResource timestampConverter}}"/>
                        <Run  Text="{Binding Content}"/>
                    </TextBlock>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Page>
