<?xml version="1.0" encoding="utf-8" ?>
<pages:BaseContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="Bit.App.Pages.RegisterPage"
    xmlns:pages="clr-namespace:Bit.App.Pages"
    xmlns:controls="clr-namespace:Bit.App.Controls"
    xmlns:u="clr-namespace:Bit.App.Utilities"
    x:DataType="pages:RegisterPageViewModel"
    Title="{Binding PageTitle}">
    
    <ContentPage.BindingContext>
        <pages:RegisterPageViewModel />
    </ContentPage.BindingContext>

    <ContentPage.Resources>
        <ResourceDictionary>
            <u:InverseBoolConverter x:Key="inverseBool" />
        </ResourceDictionary>
    </ContentPage.Resources>

    <ContentPage.ToolbarItems>
        <ToolbarItem Text="{u:I18n Cancel}" Clicked="Close_Clicked" Order="Primary" Priority="-1" />
        <ToolbarItem Text="{u:I18n Submit}" Clicked="Submit_Clicked" />
    </ContentPage.ToolbarItems>

    <ScrollView>
        <StackLayout Spacing="10">
            <StackLayout StyleClass="box">
                <StackLayout StyleClass="box-row">
                    <Label
                        Text="{u:I18n EmailAddress}"
                        StyleClass="box-label" />
                    <Entry
                        x:Name="_email"
                        Text="{Binding Email}"
                        Keyboard="Email"
                        StyleClass="box-value" />
                </StackLayout>
                <Grid StyleClass="box-row">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Label
                        Text="{u:I18n MasterPassword}"
                        StyleClass="box-label"
                        Grid.Row="0"
                        Grid.Column="0" />
                    <controls:MonoEntry
                        x:Name="_masterPassword"
                        Text="{Binding MasterPassword}"
                        StyleClass="box-value"
                        IsSpellCheckEnabled="False"
                        IsTextPredictionEnabled="False"
                        IsPassword="{Binding ShowPassword, Converter={StaticResource inverseBool}}"
                        Grid.Row="1"
                        Grid.Column="0" />
                    <controls:IconButton
                        StyleClass="box-row-button, box-row-button-platform"
                        Text="{Binding ShowPasswordIcon}"
                        Command="{Binding TogglePasswordCommand}"
                        Grid.Row="0"
                        Grid.Column="1"
                        Grid.RowSpan="2"
                        AutomationProperties.IsInAccessibleTree="True"
                        AutomationProperties.Name="{u:I18n ToggleVisibility}" 
                        AutomationProperties.HelpText="{Binding PasswordVisibilityAccessibilityText}"/>
                </Grid>
                <Label
                    StyleClass="box-sub-label"
                    Margin="0,0,0,10">
                        <Label.FormattedText>
                            <FormattedString>
                                <Span Text="{u:I18n Important}" TextColor="{DynamicResource InfoColor}"/>
                                <Span Text=": " TextColor="{DynamicResource InfoColor}"/>
                                <Span Text="{Binding MasterPasswordMininumCharactersDescription}" TextColor="{DynamicResource MutedColor}"/>
                            </FormattedString>
                        </Label.FormattedText>
                </Label>
                <controls:PasswordStrengthProgressBar
                    BindingContext="{Binding PasswordStrengthViewModel}"
                    Margin="0,0"/>
            </StackLayout>
            <StackLayout StyleClass="box">
                <Grid StyleClass="box-row">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Label
                        Text="{u:I18n RetypeMasterPassword}"
                        StyleClass="box-label"
                        Grid.Row="0"
                        Grid.Column="0" />
                    <controls:MonoEntry
                        x:Name="_confirmMasterPassword"
                        Text="{Binding ConfirmMasterPassword}"
                        StyleClass="box-value"
                        IsSpellCheckEnabled="False"
                        IsTextPredictionEnabled="False"
                        IsPassword="{Binding ShowPassword, Converter={StaticResource inverseBool}}"
                        Grid.Row="1"
                        Grid.Column="0" />
                    <controls:IconButton
                        StyleClass="box-row-button, box-row-button-platform"
                        Text="{Binding ShowPasswordIcon}"
                        Command="{Binding ToggleConfirmPasswordCommand}"
                        Grid.Row="0"
                        Grid.Column="1"
                        Grid.RowSpan="2"
                        AutomationProperties.IsInAccessibleTree="True"
                        AutomationProperties.Name="{u:I18n ToggleVisibility}"
                        AutomationProperties.HelpText="{Binding PasswordVisibilityAccessibilityText}" />
                </Grid>
                <StackLayout StyleClass="box-row">
                    <Label
                        Text="{u:I18n MasterPasswordHint}"
                        StyleClass="box-label" />
                    <Entry
                        x:Name="_hint"
                        Text="{Binding Hint}"
                        StyleClass="box-value"
                        ReturnType="Go"
                        ReturnCommand="{Binding SubmitCommand}" />
                </StackLayout>
                <Label
                    Text="{u:I18n MasterPasswordHintDescription}"
                    StyleClass="box-footer-label" />
            </StackLayout>
            <StackLayout StyleClass="box">
                <StackLayout StyleClass="box-row, box-row-switch">
                    <Switch
                        IsToggled="{Binding CheckExposedMasterPassword}"
                        StyleClass="box-value"
                        HorizontalOptions="Start"
                        Margin="0, 0, 10, 0"/>
                    <Label
                        Text="{u:I18n CheckKnownDataBreachesForThisPassword}"
                        StyleClass="box-footer-label"
                        VerticalOptions="Center"/>
                </StackLayout>
                <StackLayout StyleClass="box-row, box-row-switch"
                            IsVisible="{Binding ShowTerms}">
                    <Switch
                        IsToggled="{Binding AcceptPolicies}"
                        StyleClass="box-value"
                        HorizontalOptions="Start"
                        Margin="0, 0, 10, 0"/>
                    <Label StyleClass="box-footer-label"
                           HorizontalOptions="Fill">
                        <Label.FormattedText>
                            <FormattedString>
                                <Span Text="{u:I18n AcceptPolicies}" />
                                <Span Text="{u:I18n TermsOfService}"
                                      TextColor="{DynamicResource HyperlinkColor}">
                                    <Span.GestureRecognizers>
                                        <TapGestureRecognizer Command="{Binding PoliciesClickCommand}"
                                                              CommandParameter="https://bitwarden.com/terms/" />
                                    </Span.GestureRecognizers>
                                </Span>
                                <Span Text=", " />
                                <Span Text="{u:I18n PrivacyPolicy}"
                                      TextColor="{DynamicResource HyperlinkColor}">
                                    <Span.GestureRecognizers>
                                        <TapGestureRecognizer Command="{Binding PoliciesClickCommand}"
                                                              CommandParameter="https://bitwarden.com/privacy/" />
                                    </Span.GestureRecognizers>
                                </Span>
                            </FormattedString>
                        </Label.FormattedText>
                    </Label>
                </StackLayout>
            </StackLayout>
        </StackLayout>
    </ScrollView>

</pages:BaseContentPage>
