<UserControl x:Class="HistoryUI.Views.Alarm"
             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:local="clr-namespace:HistoryUI.Views"
             xmlns:prism="http://prismlibrary.com/"
             prism:ViewModelLocator.AutoWireViewModel="True"
             xmlns:hc="https://handyorg.github.io/handycontrol"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid Background="{StaticResource BackgroundColor}">

        <Grid Margin="16">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="0"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <Grid Grid.Row="0" Margin="8,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="8"/>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="8"/>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="8"/>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="8"/>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="8"/>
                </Grid.ColumnDefinitions>
                <GroupBox Header="Start Time" BorderThickness="0">
                    <hc:DateTimePicker MinWidth="160" Height="32" SelectedDateTime="{Binding StartTime}"/>
                </GroupBox>
                <GroupBox Grid.Column="2" Header="End Time" BorderThickness="0">
                    <hc:DateTimePicker MinWidth="160" Height="32" SelectedDateTime="{Binding EndTime}"/>
                </GroupBox>
                <GroupBox Grid.Column="4" Header="Mini8" BorderThickness="0">
                    <hc:ComboBox MinWidth="160" Height="32" ItemsSource="{Binding Hardwares.Mini8s}" SelectedItem="{Binding SelectedMini8}" DisplayMemberPath="Value.Name"/>
                </GroupBox>
                <!--<GroupBox Grid.Column="6" Header="Channel" BorderThickness="0">
                    <hc:ComboBox MinWidth="160" Height="32" ItemsSource="{Binding Channels}" SelectedItem="{Binding SelectedChannel}" DisplayMemberPath="Value.Name"/>
                </GroupBox>-->
                <Button Grid.Column="8" Margin="0,8,0,0" VerticalAlignment="Center" HorizontalAlignment="Center" Style="{StaticResource FunctionButton}" Command="{Binding QueryCommand}" MinWidth="80" Height="32">Query</Button>
                <Button Grid.Column="10" Margin="0,8,0,0" VerticalAlignment="Center" HorizontalAlignment="Center" Style="{StaticResource FunctionButton}" Command="{Binding ExitCommand}" Background="{StaticResource EmergencyColor}" MinWidth="80" Height="32">Exit</Button>
            </Grid>

            <Border Grid.Row="2" BorderBrush="{StaticResource DarkBorderColor}" BorderThickness="2" Margin="8">
                <DataGrid  ItemsSource="{Binding Results}" 
                            Background="Transparent" BorderThickness="1"
                           CanUserAddRows="False" 
                           CanUserDeleteRows="False" 
                           CanUserResizeColumns="False"
                           CanUserResizeRows="False"
                           IsReadOnly="True"
                           HorizontalScrollBarVisibility="Disabled"
                           TextElement.FontSize="16"
                           >
                    <DataGrid.Columns>
                        <DataGridTemplateColumn Width="200" Header="Time">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock>
                                        <Run Text="{Binding Value.DateTime , StringFormat={}{0:yyyy-MM-dd}}"/>
                                        <Run> </Run>
                                        <Run Text="{Binding Value.DateTime , StringFormat={}{0:HH:mm:ss}}"/>
                                    </TextBlock>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTextColumn Header="Channel"   IsReadOnly="True" Width="auto" MinWidth="120" Binding="{Binding Value.ChannelIndex}"/>
                        <DataGridTextColumn Header="AlarmType"   IsReadOnly="True" Width="auto" MinWidth="120" Binding="{Binding Value.AlarmType}"/>
                        <DataGridTextColumn Header="PV" IsReadOnly="True" Width="auto" MinWidth="120" Binding="{Binding Value.PV, StringFormat=0.00}"/>
                        <DataGridTextColumn Header="Caps" IsReadOnly="True" Width="auto" MinWidth="120" Binding="{Binding Value.Caps, StringFormat=0.00}"/>
                        <DataGridTextColumn Header="Floor" IsReadOnly="True" Width="auto" MinWidth="120" Binding="{Binding Value.Floor, StringFormat=0.00}"/>
       
                    </DataGrid.Columns>
                </DataGrid>
            </Border>
        </Grid>
    </Grid>
</UserControl>
