<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:MobileCapture.Sample"
             xmlns:capture="clr-namespace:MobileCapture.Forms.Common;assembly=MobileCapture.Forms.Common"
             xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" 
             x:DataType="local:OptionsViewModel"
             x:Class="MobileCapture.Sample.MainPage"
             ios:Page.UseSafeArea="true">
    <ContentPage.BindingContext>
        <local:OptionsViewModel/>
    </ContentPage.BindingContext>
    <ScrollView>
        <Grid Padding="20,0,20,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="7*" />
                <ColumnDefinition Width="2*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="100" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Image Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" HorizontalOptions="Center"
                   Source="logo.png" Aspect="AspectFit" Margin="32,16,32,0"/>
            <Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" HorizontalOptions="Center"
                   Text="Xamarin Mobile Capture Sample" Margin="0,0,0,16" FontAttributes="Bold" FontSize="18"/>
            
            <Label Grid.Row="2" Grid.Column="0" Text="Show Flashlight Button" VerticalOptions="Center"/>
            <Switch Grid.Row="2" Grid.Column="1" x:Name="IsFlashlightButtonVisible" IsToggled="{Binding IsFlashlightButtonVisible}"/>

            <Label Grid.Row="3" Grid.Column="0" Text="Show Capture Button" VerticalOptions="Center"/>
            <Switch Grid.Row="3" Grid.Column="1" x:Name="IsCaptureButtonVisible" IsToggled="{Binding IsCaptureButtonVisible}"/>

            <Label Grid.Row="4" Grid.Column="0" Text="Show Gallery Button" VerticalOptions="Center"/>
            <Switch Grid.Row="4" Grid.Column="1" x:Name="IsGalleryButtonVisible" IsToggled="{Binding IsGalleryButtonVisible}"/>

            <Label Grid.Row="5" Grid.Column="0" Text="Should Show Preview" VerticalOptions="Center" />
            <Switch Grid.Row="5" Grid.Column="1" x:Name="ShouldShowPreview" IsToggled="{Binding ShouldShowPreview}"/>

            <Label Grid.Row="6" Grid.Column="0" Text="Required Page Count" VerticalOptions="Center" />
            <Entry Grid.Row="6" Grid.Column="1" x:Name="RequiredPageCount" Text="{Binding RequiredPageCount}" Keyboard="Numeric"/>

            <Label Grid.Row="7" Grid.Column="0" Text="Orientation" VerticalOptions="Center"/>
            <Picker Grid.Row="7" Grid.Column="1" ItemsSource="{Binding OrientationNames}" SelectedItem="{Binding SelectedOrientation}" />

            <Label Grid.Row="8" Grid.Column="0" Text="Camera Resolution" VerticalOptions="Center"/>
            <Picker Grid.Row="8" Grid.Column="1" ItemsSource="{Binding ResolutionNames}" SelectedItem="{Binding SelectedResolution}" />

            <Label Grid.Row="9" Grid.Column="0" Text="Compression Type" VerticalOptions="Center" />
            <Picker Grid.Row="9" Grid.Column="1" ItemsSource="{Binding CompressionTypes}" SelectedItem="{Binding SelectedCompression}" />

            <Label Grid.Row="10" Grid.Column="0" Text="Compression Level" VerticalOptions="Center"/>
            <Picker Grid.Row="10" Grid.Column="1" ItemsSource="{Binding CompressionLevels}" SelectedItem="{Binding SelectedCompressionLevel}" />

            <Frame Grid.Row="11" Grid.Column="0" Grid.ColumnSpan="2" CornerRadius="20" BackgroundColor="AntiqueWhite" AbsoluteLayout.LayoutFlags="XProportional">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="7*" />
                        <ColumnDefinition Width="5*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Text="Default Image Settings" HorizontalOptions="Center"/>
                    
                    <Label Grid.Row="1" Grid.Column="0" Text="Document Size" VerticalOptions="Center"/>
                    <Picker Grid.Row="1" Grid.Column="1" ItemsSource="{Binding DocumentSizes}" SelectedIndex="{Binding SelectedDocumentSizeIndex}"/>

                    <Label Grid.Row="2" Grid.Column="0" Text="Image From Gallery Max Size" VerticalOptions="Center" />
                    <Entry Grid.Row="2" Grid.Column="1" x:Name="ImageFromGalleryMaxSize" Text="{Binding ImageFromGalleryMaxSize}" Keyboard="Numeric"/>

                    <StackLayout Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal">
                        <Label Text="{Binding MinDocToViewRatio, StringFormat='Doc to View Ratio = {0:F2}'}" VerticalOptions="Center" WidthRequest="100"/>
                        <Slider x:Name="MinDocToViewRatio"
                                Value="{Binding MinDocToViewRatio}"
                                HorizontalOptions="FillAndExpand"/>
                    </StackLayout>

                    <StackLayout Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal">
                        <Label Text="{Binding AspectRatioMin, StringFormat='Min Aspect Ratio = {0:F2}'}" VerticalOptions="Center" WidthRequest="100"/>
                        <Slider x:Name="AspectRatioMin"
                                Value="{Binding AspectRatioMin}"
                                Minimum="0"
                                Maximum="10"
                                HorizontalOptions="FillAndExpand"/>
                    </StackLayout>

                    <StackLayout Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal">
                        <Label Text="{Binding AspectRatioMax, StringFormat='Max Aspect Ratio = {0:F2}'}" VerticalOptions="Center" WidthRequest="100"/>
                        <Slider x:Name="AspectRatioMax"
                                Value="{Binding AspectRatioMax}"
                                Minimum="0"
                                Maximum="10"
                                HorizontalOptions="FillAndExpand"/>
                    </StackLayout>
                </Grid>
            </Frame>
            <Button Grid.Row="12" Grid.Column="0" Grid.ColumnSpan="2" x:Name="StartImageCapture"
                    BackgroundColor="#C8102D"
                    FontSize="16"
                    FontAttributes="Bold"
                    Margin="20,20,20,20"
                    CornerRadius="5"
                    TextColor="White"
                    Text="Start Image Capture"
                    Command="{x:Binding StartImageCaptureCommand}"/>
            <Button Grid.Row="13" Grid.Column="0" Grid.ColumnSpan="2" x:Name="OpenPdf"
                    IsVisible="{Binding HasPdfResult}"
                    BackgroundColor="Gray"
                    FontSize="16"
                    FontAttributes="Bold"
                    Margin="20,0,20,20"
                    CornerRadius="5"
                    TextColor="White"
                    Text="Open Pdf"
                    Command="{x:Binding OpenPdfCommand}"/>
            <CarouselView Grid.Row="14" Grid.Column="0" Grid.ColumnSpan="2" ItemsSource="{Binding Pages}" IsVisible="{Binding HasImagesResult}">
                <CarouselView.ItemTemplate>
                    <DataTemplate>
                        <Frame HasShadow="False" HeightRequest="600">
                            <Image x:DataType="local:IImageViewer" Source="{Binding Image}"
                                    Aspect="AspectFit"/>
                        </Frame>
                    </DataTemplate>
                </CarouselView.ItemTemplate>
            </CarouselView>
        </Grid>
    </ScrollView>
</ContentPage>
