<Window x:Class="XLAB2.VerificationReportsWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Отчеты"
        Height="760"
        Width="1280"
        MinHeight="640"
        MinWidth="1100"
        Loaded="Window_Loaded"
        WindowStartupLocation="CenterOwner">
    <Grid Margin="12">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <GroupBox Grid.Row="0"
                  Header="Параметры отчета">
            <Grid Margin="8">
                <DockPanel LastChildFill="False">
                    <Button DockPanel.Dock="Right"
                            Width="130"
                            Margin="12,0,0,0"
                            Command="{Binding RefreshCommand}"
                            Content="Сформировать" />
                    <WrapPanel>
                        <StackPanel Margin="0,0,16,8">
                            <TextBlock Margin="0,0,0,4"
                                       Text="Заказчик" />
                            <ComboBox Width="280"
                                      ItemsSource="{Binding CustomerItems}"
                                      SelectedValue="{Binding SelectedCustomerId}"
                                      SelectedValuePath="Id"
                                      DisplayMemberPath="Name"
                                      IsTextSearchEnabled="True" />
                        </StackPanel>

                        <StackPanel Margin="0,0,16,8">
                            <TextBlock Margin="0,0,0,4"
                                       Text="Область измерений" />
                            <ComboBox Width="280"
                                      ItemsSource="{Binding MeasurementAreaItems}"
                                      SelectedValue="{Binding SelectedMeasurementAreaId}"
                                      SelectedValuePath="Id"
                                      DisplayMemberPath="Name"
                                      IsTextSearchEnabled="True" />
                        </StackPanel>

                        <StackPanel Margin="0,0,16,8">
                            <TextBlock Margin="0,0,0,4"
                                       Text="Дата поверки с" />
                            <DatePicker Width="145"
                                        SelectedDate="{Binding DateFrom, Mode=TwoWay}"
                                        SelectedDateFormat="Short" />
                        </StackPanel>

                        <StackPanel Margin="0,0,0,8">
                            <TextBlock Margin="0,0,0,4"
                                       Text="Дата поверки по" />
                            <DatePicker Width="145"
                                        SelectedDate="{Binding DateTo, Mode=TwoWay}"
                                        SelectedDateFormat="Short" />
                        </StackPanel>
                    </WrapPanel>
                </DockPanel>
            </Grid>
        </GroupBox>

        <GroupBox Grid.Row="1"
                  Margin="0,12,0,0"
                  Header="Итоги">
            <Grid Margin="8">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <TextBlock Grid.Row="0"
                           Margin="0,0,0,8"
                           Foreground="DimGray"
                           Text="{Binding PeriodText}" />

                <UniformGrid Grid.Row="1"
                             Columns="5">
                    <Border Margin="0,0,8,0"
                            Padding="12,8"
                            Background="{StaticResource AppSurfaceBrush}"
                            BorderBrush="{StaticResource AppBorderBrush}"
                            BorderThickness="1">
                        <StackPanel>
                            <TextBlock Foreground="DimGray"
                                       Text="Поверено" />
                            <TextBlock FontSize="24"
                                       FontWeight="SemiBold"
                                       Text="{Binding Summary.TotalCount}" />
                        </StackPanel>
                    </Border>

                    <Border Margin="0,0,8,0"
                            Padding="12,8"
                            Background="{StaticResource AppSurfaceBrush}"
                            BorderBrush="{StaticResource AppBorderBrush}"
                            BorderThickness="1">
                        <StackPanel>
                            <TextBlock Foreground="DimGray"
                                       Text="Годен" />
                            <TextBlock FontSize="24"
                                       FontWeight="SemiBold"
                                       Text="{Binding Summary.GoodCount}" />
                        </StackPanel>
                    </Border>

                    <Border Margin="0,0,8,0"
                            Padding="12,8"
                            Background="{StaticResource AppSurfaceBrush}"
                            BorderBrush="{StaticResource AppBorderBrush}"
                            BorderThickness="1">
                        <StackPanel>
                            <TextBlock Foreground="DimGray"
                                       Text="Забракован" />
                            <TextBlock FontSize="24"
                                       FontWeight="SemiBold"
                                       Text="{Binding Summary.RejectedCount}" />
                        </StackPanel>
                    </Border>

                    <Border Margin="0,0,8,0"
                            Padding="12,8"
                            Background="{StaticResource AppSurfaceBrush}"
                            BorderBrush="{StaticResource AppBorderBrush}"
                            BorderThickness="1">
                        <StackPanel>
                            <TextBlock Foreground="DimGray"
                                       Text="Без результата" />
                            <TextBlock FontSize="24"
                                       FontWeight="SemiBold"
                                       Text="{Binding Summary.WithoutResultCount}" />
                        </StackPanel>
                    </Border>

                    <Border Padding="12,8"
                            Background="{StaticResource AppSurfaceBrush}"
                            BorderBrush="{StaticResource AppBorderBrush}"
                            BorderThickness="1">
                        <StackPanel>
                            <TextBlock Foreground="DimGray"
                                       Text="С выдачей" />
                            <TextBlock FontSize="24"
                                       FontWeight="SemiBold"
                                       Text="{Binding Summary.IssuedCount}" />
                        </StackPanel>
                    </Border>
                </UniformGrid>
            </Grid>
        </GroupBox>

        <GroupBox Grid.Row="2"
                  Margin="0,12,0,0"
                  Header="Сводные таблицы">
            <TabControl Margin="8">
                <TabItem Header="По заказчикам">
                    <DataGrid ItemsSource="{Binding CustomerRows}"
                              AutoGenerateColumns="False"
                              CanUserAddRows="False"
                              IsReadOnly="True"
                              HeadersVisibility="Column">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Заказчик"
                                                Width="360"
                                                Binding="{Binding CustomerName}" />
                            <DataGridTextColumn Header="Поверено"
                                                Width="110"
                                                Binding="{Binding TotalCount}" />
                            <DataGridTextColumn Header="Годен"
                                                Width="110"
                                                Binding="{Binding GoodCount}" />
                            <DataGridTextColumn Header="Забракован"
                                                Width="120"
                                                Binding="{Binding RejectedCount}" />
                            <DataGridTextColumn Header="Без результата"
                                                Width="125"
                                                Binding="{Binding WithoutResultCount}" />
                            <DataGridTextColumn Header="С выдачей"
                                                Width="110"
                                                Binding="{Binding IssuedCount}" />
                        </DataGrid.Columns>
                    </DataGrid>
                </TabItem>

                <TabItem Header="По видам измерений">
                    <DataGrid ItemsSource="{Binding MeasurementAreaRows}"
                              AutoGenerateColumns="False"
                              CanUserAddRows="False"
                              IsReadOnly="True"
                              HeadersVisibility="Column">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Область измерений"
                                                Width="360"
                                                Binding="{Binding MeasurementAreaName}" />
                            <DataGridTextColumn Header="Поверено"
                                                Width="110"
                                                Binding="{Binding TotalCount}" />
                            <DataGridTextColumn Header="Годен"
                                                Width="110"
                                                Binding="{Binding GoodCount}" />
                            <DataGridTextColumn Header="Забракован"
                                                Width="120"
                                                Binding="{Binding RejectedCount}" />
                            <DataGridTextColumn Header="Без результата"
                                                Width="125"
                                                Binding="{Binding WithoutResultCount}" />
                            <DataGridTextColumn Header="С выдачей"
                                                Width="110"
                                                Binding="{Binding IssuedCount}" />
                        </DataGrid.Columns>
                    </DataGrid>
                </TabItem>
            </TabControl>
        </GroupBox>

        <TextBlock Grid.Row="3"
                   Margin="0,8,0,0"
                   Foreground="DimGray"
                   Text="{Binding StatusText}" />

        <StackPanel Grid.Row="4"
                    Margin="0,12,0,0"
                    Orientation="Horizontal"
                    HorizontalAlignment="Right">
            <Button Width="90"
                    IsCancel="True"
                    Content="Закрыть" />
        </StackPanel>
    </Grid>
</Window>
