<UserControl x:Class="Artemis.UI.Screens.SurfaceEditor.Visualization.SurfaceDeviceView"
             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:s="https://github.com/canton7/Stylet"
             xmlns:converters="clr-namespace:Artemis.UI.Converters"
             xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
             xmlns:local="clr-namespace:Artemis.UI.Screens.SurfaceEditor.Visualization"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance {x:Type local:SurfaceDeviceViewModel}}"
             d:DesignHeight="450" d:DesignWidth="800"
             Cursor="{Binding Cursor}"
             MouseEnter="{s:Action MouseEnter}"
             MouseLeave="{s:Action MouseLeave}"
             ToolTip="{Binding Device.RgbDevice.DeviceInfo.DeviceName}">
    <UserControl.Resources>
        <shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
    </UserControl.Resources>
    <Grid>
        <!-- Content -->
        <Grid>
            <Rectangle Fill="{DynamicResource MaterialDesignCardBackground}"
                       Stroke="{DynamicResource MaterialDesignTextBoxBorder}"
                       StrokeThickness="1"
                       Visibility="{Binding Device.Layout.Image, ConverterParameter=Inverted, Converter={StaticResource NullToVisibilityConverter}}" 
                       IsHitTestVisible="False"/>
            <TextBlock Text="{Binding Device.RgbDevice.DeviceInfo.DeviceName}"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center"
                       TextWrapping="Wrap"
                       TextAlignment="Center"
                       Visibility="{Binding Device.Layout.Image, ConverterParameter=Inverted, Converter={StaticResource NullToVisibilityConverter}}"
                       IsHitTestVisible="False"/>

            <shared:DeviceVisualizer Device="{Binding Device}" 
                                     RenderOptions.BitmapScalingMode="HighQuality"
                                     ShowColors="True" 
                                     VerticalAlignment="Top" 
                                     HorizontalAlignment="Left" />

          </Grid>

        <!-- Selection rectangle -->
        <Rectangle Width="Auto" Height="Auto" StrokeThickness="2">
            <Rectangle.Stroke>
                <SolidColorBrush Color="{StaticResource Accent700}" />
            </Rectangle.Stroke>
            <Rectangle.Fill>
                <SolidColorBrush Color="{StaticResource Accent700}" Opacity="0.25" />
            </Rectangle.Fill>
            <Rectangle.Style>
                <Style TargetType="{x:Type Rectangle}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding SelectionStatus}" Value="{x:Static local:SelectionStatus.Hover}">
                            <DataTrigger.EnterActions>
                                <StopStoryboard BeginStoryboardName="ToSelected" />
                                <BeginStoryboard x:Name="ToHover">
                                    <Storyboard>
                                        <ColorAnimation
                                            Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)"
                                            To="{StaticResource Accent700}" Duration="0:0:0.25" />
                                        <ColorAnimation
                                            Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)"
                                            To="{StaticResource Accent700}" Duration="0:0:0.25" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.EnterActions>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding SelectionStatus}" Value="{x:Static local:SelectionStatus.Selected}">
                            <DataTrigger.EnterActions>
                                <StopStoryboard BeginStoryboardName="ToHover" />
                                <BeginStoryboard x:Name="ToSelected">
                                    <Storyboard>
                                        <ColorAnimation
                                            Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)"
                                            To="{StaticResource Primary400}" Duration="0:0:0.25" />
                                        <ColorAnimation
                                            Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)"
                                            To="{StaticResource Primary400}" Duration="0:0:0.25" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.EnterActions>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding SelectionStatus}" Value="{x:Static local:SelectionStatus.None}">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.25" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.EnterActions>
                            <DataTrigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.25" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.ExitActions>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Rectangle.Style>
        </Rectangle>
    </Grid>
</UserControl>