<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             xmlns:cv="clr-namespace:Camera.MAUI;assembly=Camera.MAUI"
             x:Class="LivreLand.View.ScanView"
             Title="ScanView">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>

        <Grid Grid.Row="0">
            <cv:CameraView BarCodeDetectionEnabled="True"
                           Camera="{Binding ScanVM.Camera}"
                           Cameras="{Binding ScanVM.Cameras}"
                           NumCamerasDetected="{Binding ScanVM.CamerasCount}"
                           AutoStartPreview="{Binding ScanVM.AutoStartPreview}"
                           AutoStartRecording="{Binding ScanVM.AutoStartRecording}"
                           WidthRequest="300"
                           HeightRequest="200">
                <cv:CameraView.Behaviors>
                    <toolkit:EventToCommandBehavior EventName="BarcodeDetected"
                                                    Command="{Binding ScanVM.BarcodeDetectCommand}"/>
                    <toolkit:EventToCommandBehavior EventName="CamerasLoaded"
                                                    Command="{Binding ScanVM.CamerasLoadCommand}"/>
                </cv:CameraView.Behaviors>
            </cv:CameraView>
        </Grid>
        
        <Grid Margin="2"
              Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>

            <Label Text="Annuler"
                   TextColor="{StaticResource Blue100Accent}"
                   Grid.Column="0"/>

            <Button Text="Start Camera" 
                    Command="{Binding ScanVM.StartCameraCommand}"
                    Grid.Column="2"/>

            <Button Text="Start Record" 
                    Command="{Binding ScanVM.StartRecordingCommand}"/>

            <Label Text="{Binding ScanVM.BarcodeText}"
                   TextColor="{StaticResource Blue100Accent}"
                   Grid.Column="4"/>
        </Grid>

    </Grid>

</ContentPage>