<UserControl x:Class="HistoryView.Controls.WarningPopUp"
             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:HistoryView.Controls"
             xmlns:converters="clr-namespace:HistoryView.Converters"
             xmlns:resource="clr-namespace:HistoryView.Resources"
             mc:Ignorable="d" 
             x:Name="This"
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <converters:DateTimeToString x:Key="DatetimeConverter"/>
        <converters:IAlarmLastConverter x:Key="IAlarmLastConverter"/>
   
    </UserControl.Resources>
    <Grid>
        <Border x:Name="PopPos" CornerRadius="4" Background="Transparent">
            <StackPanel Orientation="Horizontal">
                <Image Source="{StaticResource Icon_Bell}" Height="22"/>
                <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="{StaticResource TextColor}" MaxWidth="72" TextWrapping="Wrap" Margin="8,0" Text="{DynamicResource Alarm}"/>
                <Border x:Name="WarningHint"  VerticalAlignment="Center" Background="{StaticResource EmergencyColor}" CornerRadius="2">
                    <TextBlock Margin="4,0" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="{StaticResource TextColor}" Text="{Binding ElementName=This, Path=Counter}"/>
                </Border>
            </StackPanel>
        </Border>
        
        <Popup Width="300" Height="auto" PopupAnimation="Slide"  StaysOpen="True" IsOpen="{Binding ElementName=This, Path=IsOpen}" AllowsTransparency="True" Placement="Bottom" PlacementTarget="{Binding ElementName=PopPos}" VerticalOffset="12">
            <Border CornerRadius="4" Height="400" BorderThickness="2" BorderBrush="Black" Background="AliceBlue">
                <Grid Margin="8">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="8"/>
                        <RowDefinition/>
                        <RowDefinition Height="8"/>
                        <RowDefinition Height="auto"/>
                    </Grid.RowDefinitions>
                    <TextBlock FontSize="14" FontWeight="Bold" >警报信息</TextBlock>

                    <resource:TouchableScrollViewer Grid.Row="2" VerticalScrollBarVisibility="Hidden">
                        <ItemsControl ItemsSource="{Binding ElementName=This, Path=AlarmSource}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Border Margin="2,6">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="auto"/>
                                                <ColumnDefinition Width="12"/>
                                                <ColumnDefinition Width="auto"/>
                                                <ColumnDefinition Width="12"/>
                                                <ColumnDefinition Width="auto"/>
                                                <ColumnDefinition Width="12"/>
                                                <ColumnDefinition Width="auto"/>
                                            </Grid.ColumnDefinitions>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="auto"/>
                                                <RowDefinition Height="2"/>
                                                <RowDefinition Height="auto"/>
                                            </Grid.RowDefinitions>
                                            <Image Grid.Column="0" Grid.Row="0" Grid.RowSpan="3" Source="{StaticResource Icon_Warning}" Height="22" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                                            <TextBlock Grid.Column="2" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Value, Converter={StaticResource IAlarmLastConverter}, ConverterParameter=Date}"/>
                                            <TextBlock Grid.Column="2" Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Value, Converter={StaticResource IAlarmLastConverter}, ConverterParameter=Time}"/>
                                            <TextBlock Grid.Column="4" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Value, Converter={StaticResource IAlarmLastConverter}, ConverterParameter=AlarmMini8}"/>
                                            <TextBlock Grid.Column="6" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Value, Converter={StaticResource IAlarmLastConverter}, ConverterParameter=AlarmChannel}"/>
                                            <TextBlock Grid.Column="4" Grid.Row="2" Grid.ColumnSpan="3" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Value, Converter={StaticResource IAlarmLastConverter}, ConverterParameter=AlarmDetail}"/>
                                        </Grid>
                                    </Border>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel VerticalAlignment="Top"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                        </ItemsControl>
                    </resource:TouchableScrollViewer>

                    <Button Grid.Row="4" Style="{StaticResource FunctionButton}" Click="Button_Click">关闭</Button>
                </Grid>
            </Border>
        </Popup>
    </Grid>
</UserControl>
