<Page x:Class="SWRIS.Pages.RealTime.OneRopePage"
      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:SWRIS.Pages.RealTime"
      xmlns:cvt="clr-namespace:SWRIS.Converters" 
      xmlns:ctr="clr-namespace:SWRIS.Controls" 
      xmlns:vm="clr-namespace:SWRIS.Models.ViewModel" 
      xmlns:enum="clr-namespace:SWRIS.Enums"
      mc:Ignorable="d" FontSize="28"
      Foreground="#FFFFFF" 
      FontFamily="{StaticResource PuHuiTiRegular}"
      d:DesignHeight="900" d:DesignWidth="1920" 
      Title="OneRopePage">
    <Page.Resources>
        <cvt:RiskLevelToColorConverter x:Key="RiskLevelToColorConverter"/>
        <cvt:RiskLevelToTextConverter x:Key="RiskLevelToTextConverter"/>
        <cvt:ConnectivityFaultToColorConverter x:Key="ConnectivityFaultConverter"/>
        <cvt:CollectionCountToVisibilityConverter x:Key="CollectionCountToVisibilityConverter"/>
        <cvt:ConnectivityToVisibilityConverter x:Key="ConnectivityToVisibilityConverter"/>
        <cvt:StringEmptyToVisibilityConverter x:Key="StringEmptyToVisibilityConverter"/>
    </Page.Resources>
    <Page.DataContext>
        <vm:OneRopeViewModel/>
    </Page.DataContext>
    <Grid Margin="25,30,25,7">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="370"/>
        </Grid.ColumnDefinitions>
        <Border CornerRadius="10" Grid.Column="0">
            <Border.Background>
                <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                    <GradientStop Color="#2a2956" Offset="0"/>
                    <GradientStop Color="#161536" Offset="0.40"/>
                    <GradientStop Color="#1f1e44" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>
            <Grid  DataContext="{Binding EquipmentData}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="410"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="200"/>
                </Grid.ColumnDefinitions>
                <StackPanel Orientation="Vertical" Grid.Row="0" Grid.Column="0" Margin="55,50,80,0">
                    <DockPanel>
                        <!--钢丝绳状态及名称-->
                        <Rectangle Height="25" Width="20" RadiusX="6" RadiusY="6">
                            <Rectangle.Fill>
                                <MultiBinding Converter="{StaticResource ConnectivityFaultConverter}">
                                    <Binding Path="IsConnect"/>
                                    <Binding Path="Faults"/>
                                </MultiBinding>
                            </Rectangle.Fill>
                        </Rectangle>
                        <TextBlock Text="{Binding RopeName}" FontSize="30" FontWeight="Bold"  FontFamily="{StaticResource PuHuiTiBold}" Margin="13,0" VerticalAlignment="Center"/>
                        <StackPanel Orientation="Horizontal" Margin="30,0" MouseLeftButtonDown="ParameterSetting_MouseDown" Cursor="Hand">
                            <Image Source="/Resources/eqSet.png" Margin="10,0" Width="26" Height="26"/>
                            <TextBlock Text="参数设置" FontSize="24" VerticalAlignment="Center" Foreground="#8D86E5" FontWeight="Regular"/>
                        </StackPanel>
                        <!--消息通知-->
                        <ctr:NotificationBar FontSize="24" Height="50" MaxWidth="800" HorizontalAlignment="Right" Messages="{Binding Messages}"/>
                    </DockPanel>
                    <UniformGrid Columns="4" Width="900" Margin="0,80,0,0" HorizontalAlignment="Left">
                        <StackPanel Orientation="Vertical">
                            <TextBlock Text="风险等级" Foreground="#7886B2" FontWeight="Regular"/>
                            <TextBlock FontWeight="Bold"  FontFamily="{StaticResource PuHuiTiRegular}" FontSize="36" Margin="0,10"/>
                        </StackPanel>
                        <StackPanel Orientation="Vertical">
                            <TextBlock Text="起升高度" Foreground="#7886B2" FontWeight="Regular"/>
                            <TextBlock FontWeight="Bold"  FontFamily="{StaticResource PuHuiTiRegular}" FontSize="36" Margin="0,10">
                                <Run Text="{Binding LiftHeight,StringFormat=#0.0}"/>
                                <Run Text="m"/>
                            </TextBlock>
                        </StackPanel>
                        <StackPanel Orientation="Vertical">
                            <TextBlock Text="损伤数量" Foreground="#7886B2" FontWeight="Regular"/>
                            <StackPanel Orientation="Horizontal" Margin="0,10">
                                <TextBlock Text="{Binding DamageCount}" FontWeight="Bold"  FontFamily="{StaticResource PuHuiTiRegular}" FontSize="36" MaxWidth="80"/>
                                <TextBlock Text="详情" Foreground="#7F74FF" FontSize="24" FontWeight="Regular" Margin="15,10" 
                                           Cursor="Hand" MouseLeftButtonDown="AlarmDetail_MouseDown"
                                           Visibility="{Binding DamageCount,Converter={StaticResource CollectionCountToVisibilityConverter}}"/>
                            </StackPanel>
                        </StackPanel>
                        <StackPanel Orientation="Vertical">
                            <TextBlock Text="最大损伤值" Foreground="#7886B2" FontWeight="Regular"/>
                            <TextBlock FontWeight="Bold"  FontFamily="{StaticResource PuHuiTiRegular}" FontSize="36" Margin="0,10">
                                <Run Text="{Binding MaxDamageValue,StringFormat=#0.0}"/>
                                <Run Text="%"/>
                            </TextBlock>
                        </StackPanel>
                    </UniformGrid>
                    <ctr:DamageRangeControl Margin="0,40,-105,0" HorizontalAlignment="Stretch" Height="50" FontSize="20"
                                         MildCount="{Binding MildCount}" LightCount="{Binding LightCount}"
                                         ModerateCount="{Binding ModerateCount}" SevereCount="{Binding SevereCount}"
                                         CriticalCount="{Binding CriticalCount}" ExtremeCount="{Binding ExtremeCount}"/>

                </StackPanel>
                <ctr:RopeEquipmentControl Grid.RowSpan="2" Grid.Column="1" Grid.Row="0"
                                          PanelMargin="-80,50,0,0"
                                          EquipmentTopPosition="300"
                                          PanelNameFontSize="24"
                                          PanelValueFontSize="26"
                                          RopeImageSource="/Resources/rope_block.png"
                                          EquipmentImageSource="/Resources/equipment.png"
                                          AnimationDuration="0.5" RopeHeight="903">
                    <ctr:RopeEquipmentControl.Style>
                        <Style TargetType="ctr:RopeEquipmentControl">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Direction}" Value="{x:Static enum:DirectionState.Stoped}">
                                    <Setter Property="IsAnimationRunning" Value="False"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding Direction}" Value="{x:Static enum:DirectionState.Forward}">
                                    <Setter Property="IsAnimationRunning" Value="True"/>
                                    <Setter Property="IsAnimationReversed" Value="False"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding Direction}" Value="{x:Static enum:DirectionState.Reverse}">
                                    <Setter Property="IsAnimationRunning" Value="True"/>
                                    <Setter Property="IsAnimationReversed" Value="True"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </ctr:RopeEquipmentControl.Style>
                </ctr:RopeEquipmentControl>

                <ctr:RealTimeLineChart x:Name="chartLine" Grid.Row="1"  Margin="20,0,-40,-5"
                                       SensorCount="{Binding SensorCount,Mode=TwoWay}"
                                       SamplingStep="{Binding SamplingStep,Mode=TwoWay}"
                                       RopeLength="{Binding RopeLength,Mode=TwoWay}"/>

                <StackPanel Grid.Row="2" Orientation="Horizontal" Margin="40,0,-100,5" 
                            Visibility="{Binding DebugMessage.Message,Converter={StaticResource StringEmptyToVisibilityConverter}}">
                    <TextBlock Style="{StaticResource HeartbeatTextBlockStyle}" FontSize="17" VerticalAlignment="Center" Foreground="#7F74FF"/>
                    <TextBlock Text="{Binding  DebugMessage.DateTime,StringFormat=HH:mm:ss}" FontSize="16" Margin="5,0" VerticalAlignment="Center" Foreground="#7F74FF"/>
                    <TextBlock Text="{Binding DebugMessage.Message}" FontSize="16" Margin="5,0" VerticalAlignment="Center" Foreground="#7F74FF"/>
                </StackPanel>
            </Grid>
        </Border>
        <ctr:DamageRecordControl Grid.Column="1" Margin="25,0,0,0" Records="{Binding Records}" Title="近期记录"/>
    </Grid>
</Page>
