<?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.SendAddOnlyPage"
    xmlns:pages="clr-namespace:Bit.App.Pages"
    xmlns:u="clr-namespace:Bit.App.Utilities"
    xmlns:controls="clr-namespace:Bit.App.Controls"
    xmlns:behaviors="clr-namespace:Bit.App.Behaviors"
    xmlns:effects="clr-namespace:Bit.App.Effects"
    x:DataType="pages:SendAddEditPageViewModel"
    x:Name="_page"
    Title="{Binding PageTitle}">
    <ContentPage.BindingContext>
        <pages:SendAddEditPageViewModel />
    </ContentPage.BindingContext>

    <ContentPage.ToolbarItems>
        <!--Order matters here or the avatar's image won't be updated correctly, check iOS CustomNavigationRenderer for more info-->
        <controls:ExtendedToolbarItem
            x:Name="_accountAvatar"
            IconImageSource="{Binding AvatarImageSource}"
            Command="{Binding Source={x:Reference _accountListOverlay}, Path=ToggleVisibililtyCommand}"
            Order="Primary"
            Priority="-2"
            UseOriginalImage="True"
            AutomationProperties.IsInAccessibleTree="True"
            AutomationProperties.Name="{u:I18n Account}" />
        <ToolbarItem Text="{u:I18n Cancel}" Clicked="Close_Clicked" Order="Primary" Priority="-1" x:Name="_closeItem" />
        <ToolbarItem Text="{u:I18n Save}" Clicked="Save_Clicked" Order="Primary" x:Name="_saveItem"/>
    </ContentPage.ToolbarItems>

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

    <AbsoluteLayout>
        <ScrollView
            x:Name="_scrollView"
            AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
            AbsoluteLayout.LayoutFlags="All">
            <StackLayout x:Name="_mainContainer" StyleClass="box">
                <Frame
                    IsVisible="{Binding SendEnabled, Converter={StaticResource inverseBool}}"
                    Padding="10"
                    Margin="0, 12, 0, 0"
                    HasShadow="False"
                    BackgroundColor="Transparent"
                    BorderColor="{DynamicResource PrimaryColor}">
                    <Label
                        Text="{u:I18n SendDisabledWarning}"
                        StyleClass="text-muted, text-sm, text-bold"
                        HorizontalTextAlignment="Center" />
                </Frame>
                <Frame
                    IsVisible="{Binding SendOptionsPolicyInEffect}"
                    Padding="10"
                    Margin="0, 12, 0, 0"
                    HasShadow="False"
                    BackgroundColor="Transparent"
                    BorderColor="{DynamicResource PrimaryColor}">
                    <Label
                        Text="{u:I18n SendOptionsPolicyInEffect}"
                        StyleClass="text-muted, text-sm, text-bold"
                        HorizontalTextAlignment="Center" />
                </Frame>
                <StackLayout StyleClass="box-row">
                    <Label
                        Text="{u:I18n Name}"
                        StyleClass="box-label" />
                    <Entry
                        x:Name="_nameEntry"
                        Text="{Binding Send.Name}"
                        IsEnabled="{Binding SendEnabled}"
                        StyleClass="box-value" />
                    <Label
                        Text="{u:I18n NameInfo}"
                        StyleClass="box-footer-label"
                        Margin="0,5,0,0" />
                </StackLayout>
                <StackLayout
                    StyleClass="box-row"
                    IsVisible="{Binding IsFile}">
                    <Label
                        Text="{u:I18n TypeFile}"
                        StyleClass="box-label" />
                    <StackLayout
                        StyleClass="box-row">
                        <Label
                            Text="{Binding FileName}"
                            LineBreakMode="CharacterWrap"
                            StyleClass="text-sm, text-muted"
                            HorizontalOptions="FillAndExpand"
                            HorizontalTextAlignment="Center" />
                        <Label
                            Margin="0, 5, 0, 0"
                            Text="{u:I18n MaxFileSize}"
                            StyleClass="text-sm, text-muted"
                            HorizontalOptions="FillAndExpand"
                            HorizontalTextAlignment="Center" />
                    </StackLayout>
                </StackLayout>
                <StackLayout
                    StyleClass="box-row"
                    IsVisible="{Binding IsText}">
                    <Label
                        Text="{u:I18n TypeText}"
                        StyleClass="box-label" />
                    <Editor
                        x:Name="_textEditor"
                        AutoSize="TextChanges"
                        Text="{Binding Send.Text.Text}"
                        IsEnabled="{Binding SendEnabled}"
                        StyleClass="box-value"
                        Margin="{Binding EditorMargins}" 
                        effects:ScrollEnabledEffect.IsScrollEnabled="false" >
                        <Editor.Behaviors>
                            <behaviors:EditorPreventAutoBottomScrollingOnFocusedBehavior ParentScrollView="{x:Reference _scrollView}" />
                        </Editor.Behaviors>
                        <Editor.Effects>
                            <effects:ScrollEnabledEffect />
                        </Editor.Effects>
                    </Editor>
                    <BoxView
                        StyleClass="box-row-separator" />
                    <Label
                        Text="{u:I18n TypeTextInfo}"
                        StyleClass="box-footer-label"
                        Margin="0,5,0,10" />
                    <StackLayout
                        StyleClass="box-row, box-row-switch"
                        Margin="0,10,0,0">
                        <Label
                            Text="{u:I18n HideTextByDefault}"
                            StyleClass="box-label-regular"
                            VerticalOptions="Center"
                            HorizontalOptions="StartAndExpand" />
                        <Switch
                            IsToggled="{Binding Send.Text.Hidden}"
                            IsEnabled="{Binding SendEnabled}"
                            HorizontalOptions="End"
                            Margin="10,0,0,0" />
                    </StackLayout>
                </StackLayout>
                <StackLayout
                    StyleClass="box-row, box-row-switch">
                    <Label
                        Text="{Binding ShareOnSaveText}"
                        StyleClass="box-label-regular"
                        VerticalOptions="Center"
                        HorizontalOptions="StartAndExpand" />
                    <Switch
                        IsToggled="{Binding ShareOnSave}"
                        IsEnabled="{Binding SendEnabled}"
                        HorizontalOptions="End"
                        Margin="10,0,0,0" />
                </StackLayout>
                <StackLayout
                    Orientation="Horizontal"
                    Spacing="0"
                    AutomationProperties.IsInAccessibleTree="True"
                    AutomationProperties.Name="{Binding OptionsAccessilibityText}">
                    <StackLayout.GestureRecognizers>
                        <TapGestureRecognizer Tapped="OptionsHeader_Tapped" />
                    </StackLayout.GestureRecognizers>
                    <Label
                        Text="{u:I18n Options}"
                        TextColor="{DynamicResource PrimaryColor}"
                        Margin="0,0,5,0"
                        AutomationProperties.IsInAccessibleTree="False"/>
                    <controls:IconLabel
                        Text="{Binding OptionsShowHideIcon}"
                        TextColor="{DynamicResource PrimaryColor}"
                        AutomationProperties.IsInAccessibleTree="False"/>
                </StackLayout>
                <pages:SendAddOnlyOptionsLazyView x:Name="_lazyOptionsView" IsVisible="{Binding ShowOptions}" />
            </StackLayout>
        </ScrollView>
        
        <controls:AccountSwitchingOverlayView
            x:Name="_accountListOverlay"
            AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
            AbsoluteLayout.LayoutFlags="All"
            LongPressAccountEnabled="False"
            BindingContext="{Binding AccountSwitchingOverlayViewModel}"/>
    </AbsoluteLayout>
    
</pages:BaseContentPage>
