<UserControl x:Class="Valg.Eva.Skanning.Scan.Presentation.ScanInProgress.ScanInProgressControl"
             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:scanInProgress="clr-namespace:Valg.Eva.Skanning.Scan.Presentation.ScanInProgress"
             xmlns:controls="clr-namespace:Ab2d.Controls;assembly=Ab2d.Controls.ZoomPanel"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance d:Type=scanInProgress:ScanInProgressViewModel}"
             x:Name="scanInProgressControl">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Valg.EVA.Skanning.Assets;component/ResourceDictionaries/ResourceLibrary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="1"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <StackPanel Grid.Column="0" Margin="0,0,40,0">
            <TextBlock HorizontalAlignment="Left" Style="{StaticResource TextBlockLargeHeader}" Text="{Binding ScanInProgressText}" Margin="0,0,0,0" />
            <TextBlock HorizontalAlignment="Left" Style="{StaticResource TextBlockLargeHeader}" Text="{Binding BallotsScannedCounterText}" Margin="0,30,0,0"/>

            <Button HorizontalAlignment="Left"
                    Style="{StaticResource RedButtonCancel}" Margin="0,30,0,0" Height="49px"
                    Visibility="{Binding ThereAreNoErrorsOrNotifications, Converter={StaticResource BooleanToVisibilityConverter}}"
                    Command="{Binding CancelScanningCommand}"
                    Content="{Binding CancelScanningText, FallbackValue='Stop scanning'}">
            </Button>

            <scanInProgress:NotificationsDuringScanningControl Margin="0,30,0,0" DataContext="{Binding NotificationViewModel}" 
                                                               Visibility="{Binding ElementName=scanInProgressControl, Path=DataContext.ThereAreNoErrorsOrNotifications, Converter={StaticResource InvertedBooleanToVisibilityConverter}}"
                                                               HorizontalAlignment="Stretch" />
        </StackPanel>

        <StackPanel Grid.Column="1" Margin="0,20,0,10">
            <Line X1="0" Y1="0" X2="0" Y2="2000" Stroke="Black" StrokeDashArray="1 1" StrokeThickness="1" ClipToBounds="False" />
        </StackPanel>
        
        <Grid MouseEnter="UIElement_OnMouseEnter" MouseLeave="UIElement_OnMouseLeave" Margin="20,0,0,0" Grid.Column="2">
            <controls:ZoomPanel 
                x:Name="ImageZoomPanel"
                Viewbox="0.0 0.0 1.0 1.0"
                RotationAngle="{Binding CompensatingRotationAngle}"
                IsMouseWheelZoomEnabled="True"  
                IsAnimated="True" IsPanningAnimated="False" 
                ZoomMode="Rectangle"
                IsViewboxLimited="True"
                ViewboxLimits="-0.5 -0.5 2 2">
                <Image Source="{Binding LastScannedImage}" Margin="10"/>
            </controls:ZoomPanel>
            <StackPanel Orientation="Vertical" HorizontalAlignment="Right" VerticalAlignment="Bottom" Visibility="Hidden" x:Name="ZoomPanelButtons">
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,20,20,20">
                    <ToggleButton x:Name="MoveButton" Command="{x:Static controls:ZoomPanel.SetMoveModeCommand}" CommandTarget="{Binding ElementName=ImageZoomPanel}" Style="{StaticResource MoveImageButton}" Height="40" Width="40" Margin="0,0,0,0"></ToggleButton>
                    <ToggleButton x:Name="RectangleButton" Command="{x:Static controls:ZoomPanel.SetRectangleModeCommand}" CommandTarget="{Binding ElementName=ImageZoomPanel}" Style="{StaticResource RectangleButton}" Height="40" Width="40" Margin="8,0,0,0">Rectangle</ToggleButton>
                    <Button Command="{x:Static controls:ZoomPanel.ResetCommand}" CommandTarget="{Binding ElementName=ImageZoomPanel}" Style="{StaticResource ResetImageButton}" Height="40" Width="40" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="8,0,0,0"></Button>
                </StackPanel>
            </StackPanel>
        </Grid>
    </Grid>
</UserControl>

