<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" Background="WhiteSmoke"
      Title="Page_ErrorTable">
    <Page.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <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}">
        <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"  />
                <TextBlock Style="{StaticResource Styles.TitleBar.Text}"  Text="报警记录"/>
            </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="显示" />
                        <StackPanel Orientation="Horizontal">
                            <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding WindowSize}" />
                            <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="行"/>
                        </StackPanel>
                    </StackPanel>
                    <StackPanel Margin="{StaticResource ControlMargin}">
                        <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="按时间查找" />
                        <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="查找ID" />
                            <StackPanel Orientation="Horizontal">
                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" 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="最新ID:"/><Run Text="{Binding LastId,Mode=OneWay}"/>
                        </TextBlock>
                        <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
                        <Run Text="当前ID:"/><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="更新中" 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="LightGray" 
                      RowHeaderWidth="0"
                      Style="{DynamicResource MahApps.Styles.DataGrid.Azure}"
                      >
                <DataGrid.Columns>
                    <DataGridTextColumn Binding="{Binding ID}" Header="ID"/>
                    <DataGridTextColumn Binding="{Binding Time,StringFormat={}{0:MM/dd HH:mm}}" Header="时间"/>
                    <DataGridTextColumn Binding="{Binding ErrCode}" Header="代码"/>
                    <DataGridTextColumn Binding="{Binding State}" Header="触发?"/>
                    <DataGridTextColumn Binding="{Binding Description}" Header="描述"/>
                    <DataGridTextColumn Binding="{Binding Accessory}" Header="附加信息"/>
                </DataGrid.Columns>
            </DataGrid>
        </Grid>
    </Grid>
</Page>

