<UserControl x:Class="HistoryView.Controls.TempStatus"
             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:converter="clr-namespace:HistoryView.Converters"
             mc:Ignorable="d" 
             x:Name="This"
             d:DesignHeight="450" d:DesignWidth="800">

    <UserControl.Resources>
        <converter:MutiValueToVisibility x:Key="VisConvert"/>
        <converter:ChannelModeToImage x:Key="ChannelMode"/>
        <converter:StatusToBrush x:Key="StatusBrush"/>
        <converter:AutoTuntToVisibility x:Key="AutoTune"/>
        <converter:StatusToVisibility x:Key="StatusVis"/>
        <converter:TcBrockenToVisibility x:Key="TcBroken"/>
        <converter:ChannelModeToVisbility x:Key="ChannelModeVis"/>
        <converter:ChannelModeToChannelDisplay x:Key="ChannelModeHide"/>
    </UserControl.Resources>
    
    <Border CornerRadius="4" BorderThickness="0" Width="68" >
        <Border.BorderBrush>
            <MultiBinding Converter="{StaticResource StatusBrush}" ConverterParameter="Bright">
                <Binding ElementName="This" Path="Source.Inhibit"/>
                <Binding ElementName="This" Path="Mini8Status"/>
                <Binding ElementName="This" Path="Source.Status"/>
                <Binding ElementName="This" Path="IsConnected"/>
            </MultiBinding>
        </Border.BorderBrush>
        <Border.Background>
            <MultiBinding Converter="{StaticResource StatusBrush}" ConverterParameter="Light">
                <Binding ElementName="This" Path="Source.Inhibit"/>
                <Binding ElementName="This" Path="Mini8Status"/>
                <Binding ElementName="This" Path="Source.Status"/>
                <Binding ElementName="This" Path="IsConnected"/>
            </MultiBinding>
        </Border.Background>
        <Grid Margin="0,2">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" MinHeight="24"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="0"/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>

            <TextBlock Foreground="Black" VerticalAlignment="Center" HorizontalAlignment="Center" Block.TextAlignment="Center" TextWrapping="WrapWithOverflow" FontSize="10" Text="{Binding ElementName=This, Path=Source.Name}"/>

            <ProgressBar Grid.Row="1" Height="3" BorderThickness="0" Margin="6,0"
                             Value="{Binding ElementName=This, Path=Source.WorkingOutput}" 
                             Foreground="{StaticResource NiceBlue}" Background="{StaticResource LightDisableColor}">
            </ProgressBar>

            <Border Grid.Row="2" Panel.ZIndex="1" Margin="2,0" CornerRadius="2">
                <Border.Visibility>
                    <MultiBinding Converter="{StaticResource TcBroken}">
                        <Binding ElementName="This" Path="Source.ChannelMode"/>
                        <Binding ElementName="This" Path="Source.SensorBreakAlarm"/>
                    </MultiBinding>
                </Border.Visibility>
                <Border.Background>
                    <MultiBinding Converter="{StaticResource StatusBrush}" ConverterParameter="Bright">
                        <Binding ElementName="This" Path="Source.Inhibit"/>
                        <Binding ElementName="This" Path="Mini8Status"/>
                        <Binding ElementName="This" Path="Source.Status"/>
                        <Binding ElementName="This" Path="IsConnected"/>
                    </MultiBinding>
                </Border.Background>
                <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">TcBorcken</TextBlock>
            </Border>

            <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" Visibility="{Binding ElementName=This, Path=Source.Inhibit, Converter={StaticResource StatusVis}}">
                <TextBlock Grid.Row="2" Foreground="Black" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,4,0"
                            Visibility="{Binding  ElementName=This, Path=Source.ChannelMode, Converter={StaticResource ChannelModeHide}}">
                     <Run Text="{Binding ElementName=This, Path=Source.PV ,StringFormat=0.00}"/>
                     <!--<Run>℃</Run>-->
                </TextBlock>

                <Border Grid.Row="6" BorderBrush="Black" BorderThickness="0" VerticalAlignment="Center" HorizontalAlignment="Center">
                    <Image Source="{StaticResource ArrowUP}" Width="16" VerticalAlignment="Center" HorizontalAlignment="Center">
                        <Image.Visibility>
                            <MultiBinding Converter="{StaticResource VisConvert}" ConverterParameter="Over">
                                <Binding ElementName="This" Path="Source.CapsWarning"/>
                                <Binding ElementName="This" Path="Source.FloorWarning"/>
                                <Binding ElementName="This" Path="Source.PV"/>
                                <Binding ElementName="This" Path="Source.Inhibit"/>
                                <Binding ElementName="This" Path="Source.ChannelMode"/>
                                <Binding ElementName="This" Path="IsEnable"/>
                                <Binding ElementName="This" Path="IsConnected"/>
                            </MultiBinding>
                        </Image.Visibility>
                    </Image>
                </Border>

                <Border Grid.Row="6" BorderBrush="Black" BorderThickness="0" VerticalAlignment="Center" HorizontalAlignment="Center">
                    <Image Source="{StaticResource ArrowDown}" Width="16" VerticalAlignment="Center" HorizontalAlignment="Center">
                        <Image.Visibility>
                            <MultiBinding Converter="{StaticResource VisConvert}" ConverterParameter="Under">
                                <Binding ElementName="This" Path="Source.CapsWarning"/>
                                <Binding ElementName="This" Path="Source.FloorWarning"/>
                                <Binding ElementName="This" Path="Source.PV"/>
                                <Binding ElementName="This" Path="Source.Inhibit"/>
                                <Binding ElementName="This" Path="Source.ChannelMode"/>
                                <Binding ElementName="This" Path="IsEnable"/>
                                <Binding ElementName="This" Path="IsConnected"/>
                            </MultiBinding>
                        </Image.Visibility>
                    </Image>
                </Border>
            </StackPanel>


            <Border Grid.Row="4" Panel.ZIndex="1" Margin="2,0" CornerRadius="2" Visibility="{Binding ElementName=This, Path=Source.ChannelMode, Converter={StaticResource ChannelModeVis}}">
                <Border.Background>
                    <MultiBinding Converter="{StaticResource StatusBrush}" ConverterParameter="Light">
                        <Binding ElementName="This" Path="Source.Inhibit"/>
                        <Binding ElementName="This" Path="Mini8Status"/>
                        <Binding ElementName="This" Path="Source.Status"/>
                        <Binding ElementName="This" Path="IsConnected"/>
                    </MultiBinding>
                </Border.Background>

                <Image Grid.Row="4" Source="{Binding ElementName=This, Path=Source.ChannelMode, Converter={StaticResource ChannelMode}}" Height="16"/>
            </Border>

            <Border Grid.Row="4" Panel.ZIndex="1" Margin="2,0" CornerRadius="2">
                <Border.Background>
                    <MultiBinding Converter="{StaticResource StatusBrush}" ConverterParameter="Bright">
                        <Binding ElementName="This" Path="Source.Inhibit"/>
                        <Binding ElementName="This" Path="Mini8Status"/>
                        <Binding ElementName="This" Path="Source.Status"/>
                        <Binding ElementName="This" Path="IsConnected"/>
                        <Binding ElementName="This" Path="Source.AutoTuneStatus"/>
                    </MultiBinding>
                </Border.Background>
                <Border.Visibility>
                    <MultiBinding Converter="{StaticResource AutoTune}">
                        <Binding ElementName="This" Path="Source.Inhibit"/>
                        <Binding ElementName="This" Path="Source.AutoTuneStatus"/>
                        <Binding ElementName="This" Path="Source.ActiveTuneSet"/>
                    </MultiBinding>
                </Border.Visibility>
                <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding ElementName=This, Path=Source.AutoTuneStatus}"/>
            </Border>

            <TextBlock Grid.Row="4" Foreground="Black" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,4,0">
             <Run>SP:</Run>
             <Run Text="{Binding ElementName=This, Path=Source.SetPoint ,StringFormat=0}"/>
            </TextBlock>
        </Grid>
    </Border>
</UserControl>
