<Page x:Class="FLY.Thick.Base.UI.PgErrorAllTable"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
      xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
      xmlns:local="clr-namespace:FLY.Thick.Base.UI"
      mc:Ignorable="d" 
      d:DesignHeight="900" d:DesignWidth="960" 
      Title="Page_ErrorTable">
    <Page.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/FLY.ControlLibrary;component/Themes/Styles.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/FLY.ControlLibrary;component/Converter/Converters.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <local:PgErrorAllTableVmUt x:Key="viewModel" />
        </ResourceDictionary>
    </Page.Resources>
    <Grid d:DataContext="{StaticResource viewModel}" Background="{StaticResource Brushes.ThemeBackground}">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <Grid Background="{StaticResource Brushes.TitleBar.Background}" >
            <StackPanel Orientation="Horizontal" >
                <Button Style="{StaticResource Styles.TitleBar.BackButton2}" Command="BrowseBack"  >
                    <iconPacks:PackIconMaterial Kind="ArrowLeftThick" />
                </Button>
                <TextBlock Style="{StaticResource Styles.TitleBar.Text}"  Text="{StaticResource str.PgErrorAllTable.Title}"/>
            </StackPanel>
        </Grid>

        <Grid Grid.Row="1" >
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <WrapPanel>
                <StackPanel Orientation="Horizontal" Margin="{StaticResource ControlMargin}">
                    <StackPanel Margin="{StaticResource ControlMargin}">
                        <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="{StaticResource str.PgErrorAllTable.WindowSize}" />
                        <StackPanel Orientation="Horizontal">
                            <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding WindowSize}" />
                            <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="{StaticResource str.PgErrorAllTable.Row}"/>
                        </StackPanel>
                    </StackPanel>
                    <StackPanel Margin="{StaticResource ControlMargin}">
                        <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="{StaticResource str.PgErrorAllTable.IsSearchByTime}" />
                        <ToggleButton Style="{StaticResource Styles.ToggleButton.YESNO}" HorizontalAlignment="Left" IsChecked="{Binding IsSearchByTime}" />
                    </StackPanel>
                    <Grid Margin="{StaticResource ControlMargin}">
                        <StackPanel Visibility="{Binding IsSearchByTime,Converter={StaticResource visbilityconv},ConverterParameter=CollapsedWhenTrue}" >
                            <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="{StaticResource str.PgErrorAllTable.SearchId}" />
                            <StackPanel Orientation="Horizontal">
                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding SearchId}" />
                            </StackPanel>
                        </StackPanel>
                        <DatePicker 
                            Visibility="{Binding IsSearchByTime,Converter={StaticResource visbilityconv},ConverterParameter=Collapsed}" 
                            Width="200"
                            Margin="{StaticResource ControlMargin}"
                            Height="auto"
                            HorizontalAlignment="Center"
                            HorizontalContentAlignment="Stretch"
                            controls:TextBoxHelper.UseFloatingWatermark="True"
                            controls:TextBoxHelper.Watermark="开始日期"
                            controls:TextBoxHelper.WatermarkAlignment="Right" 
                                        SelectedDate="{Binding SearchTime}"/>
                    </Grid>
                    <Button Style="{StaticResource Styles.Button.Icon.Rectangle}" Command="{Binding SearchCmd}">
                        <iconPacks:PackIconMaterial Kind="Magnify" />
                    </Button>
                </StackPanel>

                <StackPanel Orientation="Horizontal" Margin="{StaticResource ControlMargin}">
                    <Button Style="{StaticResource Styles.Button.Icon.Rectangle}" Command="{Binding PreViewCmd}">
                        <Grid>
                            <iconPacks:PackIconMaterial Kind="ArrowLeft" />
                        </Grid>
                    </Button>
                    <StackPanel VerticalAlignment="Center">
                        <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
                            <Run Text="{StaticResource str.PgErrorAllTable.NewestId}"/>:<Run Text="{Binding LastId,Mode=OneWay}"/>
                        </TextBlock>
                        <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
                            <Run Text="{StaticResource str.PgErrorAllTable.CurrentId}"/>:<Run Text="{Binding Id,Mode=OneWay}"/>
                        </TextBlock>
                    </StackPanel>
                    <Button Command="{Binding NextViewCmd}">
                        <Button.Style>
                            <Style TargetType="Button" BasedOn="{StaticResource Styles.Button.Icon.Rectangle}">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsNewest}" Value="True">
                                        <Setter Property="IsEnabled" Value="False"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Button.Style>
                        <Grid>
                            <iconPacks:PackIconMaterial Kind="ArrowRight" />
                        </Grid>
                    </Button>
                    <Button Command="{Binding ToNewestCmd}">
                        <Button.Style>
                            <Style TargetType="Button" BasedOn="{StaticResource Styles.Button.Icon.Rectangle}">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsNewest}" Value="True">
                                        <Setter Property="IsEnabled" Value="False"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Button.Style>
                        <iconPacks:PackIconMaterial Kind="ArrowCollapseRight" />
                    </Button>


                    <TextBlock Style="{StaticResource Styles.Text.FieldContent}" VerticalAlignment="Center"
                               Text="{StaticResource str.PgErrorAllTable.Loading}" Visibility="{Binding IsLoading,Converter={StaticResource visbilityconv}}"/>
                </StackPanel>

            </WrapPanel>
            <DataGrid Grid.Row="1" ItemsSource="{Binding Values}" AutoGenerateColumns="False" IsReadOnly="True" Margin="{StaticResource ControlMargin}"
                      AlternationCount ="2"
                      AlternatingRowBackground="{StaticResource Brushes.Gray9}" 
                      RowHeaderWidth="0"
                      Style="{StaticResource MahApps.Styles.DataGrid.Azure}"
                      >
                <DataGrid.Columns>
                    <DataGridTextColumn Binding="{Binding ID}" Header="{StaticResource str.PgErrorAllTable.ID}"/>
                    <DataGridTextColumn Binding="{Binding Time,StringFormat={}{0:MM/dd HH:mm}}" Header="{StaticResource str.PgErrorAllTable.Time}"/>
                    <DataGridTextColumn Binding="{Binding ErrCode}" Header="{StaticResource str.PgErrorAllTable.ErrCode}"/>
                    <DataGridTextColumn Binding="{Binding State}" Header="{StaticResource str.PgErrorAllTable.State}"/>
                    <DataGridTextColumn Binding="{Binding Description}" Header="{StaticResource str.PgErrorAllTable.Description}"/>
                    <DataGridTextColumn Binding="{Binding Accessory}" Header="{StaticResource str.PgErrorAllTable.Accessory}"/>
                </DataGrid.Columns>
            </DataGrid>
        </Grid>
    </Grid>
</Page>

