<UserControl x:Class="JuliusSweetland.OptiKey.UI.Views.MainView"
             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:properties="clr-namespace:JuliusSweetland.OptiKey.Properties"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:interactionRequest="http://www.codeplex.com/prism"
             xmlns:triggerActions="clr-namespace:JuliusSweetland.OptiKey.UI.TriggerActions"
             xmlns:controls="clr-namespace:JuliusSweetland.OptiKey.UI.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    </UserControl.Resources>

    <i:Interaction.Triggers>
        <interactionRequest:InteractionRequestTrigger SourceObject="{Binding CalibrateRequest, Mode=OneWay}">
            <triggerActions:CalibrateWindowAction CalibrationService="{Binding CalibrationService}" />
        </interactionRequest:InteractionRequestTrigger>
    </i:Interaction.Triggers>

    <Grid>
        <controls:KeyboardHost Keyboard="{Binding Keyboard, Mode=OneWay}"
                               PointToKeyValueMap="{Binding PointToKeyValueMap, Mode=OneWayToSource}">
            <controls:KeyboardHost.ErrorContent>
                <Border Background="Black">
                    <Viewbox>
                        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" >
                            <TextBlock Text="PROBLEM LOADING KEYBOARD" HorizontalAlignment="Center" 
                                            VerticalAlignment="Center" Foreground="DarkRed"  Margin="10" />
                            <TextBlock Text="The current keyboard &amp; language combination is not valid"
                                            HorizontalAlignment="Center" VerticalAlignment="Center" 
                                            Foreground="DarkRed" Margin="10" />
                        </StackPanel>
                    </Viewbox>
                </Border>
            </controls:KeyboardHost.ErrorContent>
        </controls:KeyboardHost>
            
        <controls:PointVisualiser Visibility="{Binding Source={x:Static properties:Settings.Default}, Path=Debug, 
                                                       Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}"
                                  PointsToDisplay="{Binding SelectionResultPoints, Mode=OneWay}" />

            <TextBlock Text="{Binding ApplicationAndSystemInfo}" 
                       Foreground="{DynamicResource DebugTextForegroundBrush}"
                       Visibility="{Binding Source={x:Static properties:Settings.Default}, Path=Debug, 
                                            Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}"
                       HorizontalAlignment="Left" VerticalAlignment="Bottom" />

        <TextBlock Text="{Binding PointsPerSecond, StringFormat='{}{0} points per second'}" 
                   Foreground="{DynamicResource DebugTextForegroundBrush}"
                   Visibility="{Binding Source={x:Static properties:Settings.Default}, Path=Debug, 
                                        Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}"
                   HorizontalAlignment="Right" VerticalAlignment="Bottom" />

        <controls:CursorPopup IsHitTestVisible="False" Placement="Absolute" AllowsTransparency="True">
            <controls:Cursor IsHitTestVisible="False" />
        </controls:CursorPopup>

        <controls:MagnifyPopup IsHitTestVisible="False" Placement="AbsolutePoint" AllowsTransparency="True" />
        
        <controls:ToastNotificationPopup PlacementTarget="{Binding RelativeSource={RelativeSource AncestorType=Window}}" 
                                         Placement="Center" AllowsTransparency="True" IsOpen="False">
            <controls:ToastNotification RenderTransformOrigin="0,1">
                <controls:ToastNotification.RenderTransform>
                    <ScaleTransform ScaleY="1" />
                </controls:ToastNotification.RenderTransform>
            </controls:ToastNotification>
        </controls:ToastNotificationPopup>
    </Grid>
</UserControl>
