<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:dx="http://schemas.devexpress.com/maui"
             x:Class="CrmDemo.Views.InvoicePdfPreviewPage"
             xmlns:dxi="clr-namespace:DevExpress.Maui.Core.Internal;assembly=DevExpress.Maui.Core"
             xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             xmlns:viewsCommon="clr-namespace:CrmDemo.Views.Common"
             xmlns:viewModels="clr-namespace:CrmDemo.ViewModels.Orders"
             Title="Invoice Preview"
             BackgroundColor="{dx:ThemeColor Surface}">
    <dxi:DXPageExtension.ToolbarItems>
        <dxi:DXToolbarItem IconImageSource="export" Command="{Binding SharePdfCommand}"/>
    </dxi:DXPageExtension.ToolbarItems>
    <ContentPage.BindingContext>
        <viewModels:OrderPdfPreviewViewModel/>
    </ContentPage.BindingContext>
    <Grid>
        <dx:ImageEdit Source="{Binding PdfPreview}" x:Name="previewImage" CropAreaBorderColor="Transparent" ScrimColor="Transparent" CropAreaOffset="0" MaxScaleFactor="2"/>

        <dx:DXButton Style="{StaticResource fabStyle}" Icon="signature" Command="{Binding OpenSignatureViewCommand}" HorizontalOptions="End" VerticalOptions="End"/>
        <dx:DXPopup x:Name="signatureDrawerPopup" IsOpen="{Binding IsSignatureViewOpened, Mode=TwoWay}" ScrimColor="#50505050" AllowScrim="true">
            <Grid RowDefinitions="*,Auto">
                <toolkit:DrawingView IsMultiLineModeEnabled="True" Background="White" Lines="{Binding SignatureLines, Mode=TwoWay}" x:Name="signatureDrawer" HeightRequest="300" WidthRequest="350">
                    <toolkit:DrawingView.Behaviors>
                        <viewsCommon:DrawingViewMVVMBehavior x:Name="drawingMvvmBehavior" DrawingAcceptedCommand="{Binding SignPdfCommand}"/>
                    </toolkit:DrawingView.Behaviors>
                </toolkit:DrawingView>
                <dx:DXButton Content="&#8634;" ButtonType="ToolButton" Command="{Binding Source={x:Reference drawingMvvmBehavior}, Path=ClearCommand}" VerticalOptions="Start" HorizontalOptions="End" Background="Transparent" TextColor="Black" FontSize="24" HeightRequest="40" WidthRequest="40" Padding="0" Margin="24" />
                <HorizontalStackLayout HorizontalOptions="End" Grid.Row="1" Margin="24">
                    <dx:DXButton Content="Cancel" Command="{Binding CloseSignatureViewCommand}" Margin="4,0" />
                    <dx:DXButton Content="Sign PDF" Command="{Binding Source={x:Reference drawingMvvmBehavior}, Path=AcceptDrawingCommand}" Margin="4,0" />
                </HorizontalStackLayout>
            </Grid>
        </dx:DXPopup>
    </Grid>
</ContentPage>
