<!--
  ~ Copyright (c) 2022 Proton AG
  ~
  ~ This file is part of Proton Mail.
  ~
  ~ Proton Mail is free software: you can redistribute it and/or modify
  ~ it under the terms of the GNU General Public License as published by
  ~ the Free Software Foundation, either version 3 of the License, or
  ~ (at your option) any later version.
  ~
  ~ Proton Mail is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  ~ GNU General Public License for more details.
  ~
  ~ You should have received a copy of the GNU General Public License
  ~ along with Proton Mail. If not, see https://www.gnu.org/licenses/.
  -->

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/root_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:animateLayoutChanges="true"
    tools:context=".activities.composeMessage.ComposeMessageActivity">

    <!-- Toolbar -->
    <com.google.android.material.appbar.MaterialToolbar
        android:id="@+id/composer_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        app:title=" "
        app:navigationIcon="@drawable/ic_proton_cross"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <!-- No Connectivity -->
    <FrameLayout
        android:id="@+id/layout_no_connectivity_info"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@id/composer_toolbar"
        app:layout_constraintStart_toStartOf="parent"
        tools:visibility="visible"/>

    <!-- Progress -->
    <FrameLayout
        android:id="@+id/composer_progress_layout"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@id/composer_toolbar"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:elevation="99dp"
        android:background="@color/background_norm"
        android:visibility="gone"
        tools:visibility="visible">

        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:indeterminate="true" />

    </FrameLayout>

    <!-- Screen Protector -->
    <View
        android:id="@+id/screenProtectorView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:background="@android:color/transparent"
        android:clickable="true"
        android:focusable="true"
        tools:visibility="gone"/>

    <androidx.core.widget.NestedScrollView
        android:id="@+id/composer_scroll_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintVertical_bias="0"
        app:layout_constrainedHeight="true"
        app:layout_constraintTop_toBottomOf="@id/layout_no_connectivity_info"
        app:layout_constraintBottom_toTopOf="@id/composer_bottom_app_bar"
        android:fillViewport="true">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:animateLayoutChanges="true">

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/composer_fields_start_guideline"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_begin="@dimen/padding_l"/>

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/composer_fields_end_guideline"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_end="@dimen/padding_l"/>

            <!-- From -->
            <TextView
                android:id="@+id/composer_from_hint_text_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:minHeight="@dimen/height_composer_field"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintStart_toStartOf="@id/composer_fields_start_guideline"
                android:gravity="center_vertical"
                android:textAppearance="@style/Proton.Text.Default.Weak"
                android:textColor="@color/text_weak"
                android:text="@string/composer_from" />

            <Spinner
                android:id="@+id/composer_from_spinner"
                android:layout_width="0dp"
                android:layout_height="@dimen/height_composer_field"
                android:background="@drawable/bg_spinner_three_dots"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintStart_toEndOf="@id/composer_from_hint_text_view"
                app:layout_constraintEnd_toEndOf="parent"
                android:layout_marginStart="@dimen/padding_m" />

            <View
                android:layout_width="match_parent"
                android:layout_height="@dimen/size_divider"
                android:background="@color/separator_norm"
                app:layout_constraintTop_toBottomOf="@id/composer_from_hint_text_view"
                app:layout_constraintStart_toStartOf="parent"/>

            <!-- To -->
            <TextView
                android:id="@+id/composer_to_hint_text_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:minHeight="@dimen/height_composer_field"
                app:layout_constraintTop_toBottomOf="@id/composer_from_hint_text_view"
                app:layout_constraintStart_toStartOf="@id/composer_fields_start_guideline"
                android:gravity="center_vertical"
                android:textAppearance="@style/Proton.Text.Default.Weak"
                android:textColor="@color/text_weak"
                android:text="@string/composer_to" />

            <ch.protonmail.android.views.MessageRecipientView
                android:id="@+id/composer_to_recipient_view"
                style="@style/MessageRecipientView"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:minHeight="@dimen/height_composer_field"
                app:layout_constraintTop_toBottomOf="@id/composer_from_spinner"
                app:layout_constraintStart_toEndOf="@id/composer_to_hint_text_view"
                app:layout_constraintEnd_toStartOf="@id/composer_expand_recipients_button"
                android:layout_marginStart="@dimen/padding_m"
                android:paddingTop="@dimen/padding_m"
                android:paddingBottom="@dimen/padding_m"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:textCursorDrawable="@null"/>

            <ImageButton
                android:id="@+id/composer_expand_recipients_button"
                style="@style/ProtonImage.ImageButton"
                android:layout_width="@dimen/size_button_m"
                android:layout_height="@dimen/size_button_m"
                app:layout_constraintDimensionRatio="1"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@id/composer_from_spinner"
                app:srcCompat="@drawable/ic_proton_chevron_down"
                app:tint="@color/shade_80"/>

            <View
                android:id="@+id/composer_cc_top_divider"
                android:layout_width="match_parent"
                android:layout_height="@dimen/size_divider"
                android:background="@color/separator_norm"
                app:layout_constraintTop_toBottomOf="@id/composer_to_recipient_view"
                app:layout_constraintStart_toStartOf="parent"/>

            <!-- Cc -->
            <TextView
                android:id="@+id/composer_cc_hint_text_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:minHeight="@dimen/height_composer_field"
                app:layout_constraintTop_toBottomOf="@id/composer_to_recipient_view"
                app:layout_constraintStart_toStartOf="@id/composer_fields_start_guideline"
                android:gravity="center_vertical"
                android:textAppearance="@style/Proton.Text.Default.Weak"
                android:textColor="@color/text_weak"
                android:text="@string/composer_cc" />

            <ch.protonmail.android.views.MessageRecipientView
                android:id="@+id/composer_cc_recipient_view"
                style="@style/MessageRecipientView"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:minHeight="@dimen/height_composer_field"
                app:layout_constraintTop_toBottomOf="@id/composer_to_recipient_view"
                app:layout_constraintStart_toEndOf="@id/composer_cc_hint_text_view"
                app:layout_constraintEnd_toEndOf="@id/composer_fields_end_guideline"
                android:layout_marginStart="@dimen/padding_m"
                android:paddingTop="@dimen/padding_m"
                android:paddingBottom="@dimen/padding_m"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:textCursorDrawable="@null" />

            <View
                android:id="@+id/composer_bcc_top_divider"
                android:layout_width="match_parent"
                android:layout_height="@dimen/size_divider"
                android:background="@color/separator_norm"
                app:layout_constraintTop_toBottomOf="@id/composer_cc_recipient_view"
                app:layout_constraintStart_toStartOf="parent"/>

            <!-- Bcc -->
            <TextView
                android:id="@+id/composer_bcc_hint_text_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:minHeight="@dimen/height_composer_field"
                app:layout_constraintTop_toBottomOf="@id/composer_cc_recipient_view"
                app:layout_constraintStart_toStartOf="@id/composer_fields_start_guideline"
                android:gravity="center_vertical"
                android:textAppearance="@style/Proton.Text.Default.Weak"
                android:textColor="@color/text_weak"
                android:text="@string/composer_bcc" />

            <ch.protonmail.android.views.MessageRecipientView
                android:id="@+id/composer_bcc_recipient_view"
                style="@style/MessageRecipientView"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:minHeight="@dimen/height_composer_field"
                app:layout_constraintTop_toBottomOf="@id/composer_cc_recipient_view"
                app:layout_constraintStart_toEndOf="@id/composer_bcc_hint_text_view"
                app:layout_constraintEnd_toEndOf="@id/composer_fields_end_guideline"
                android:layout_marginStart="@dimen/padding_m"
                android:paddingTop="@dimen/padding_m"
                android:paddingBottom="@dimen/padding_m"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:textCursorDrawable="@null"/>

            <!-- Expanded Recipients group -->
            <androidx.constraintlayout.widget.Group
                android:id="@+id/composer_expanded_recipients_group"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:constraint_referenced_ids="composer_cc_top_divider, composer_cc_hint_text_view, composer_cc_recipient_view, composer_bcc_top_divider, composer_bcc_hint_text_view, composer_bcc_recipient_view"
                android:visibility="gone"
                tools:visibility="visible"/>

            <View
                android:id="@+id/composer_subject_top_divider"
                android:layout_width="match_parent"
                android:layout_height="@dimen/size_divider"
                android:background="@color/separator_norm"
                app:layout_constraintTop_toBottomOf="@id/composer_bcc_recipient_view"
                app:layout_constraintStart_toStartOf="parent"/>

            <!-- Subject -->
            <EditText
                android:id="@+id/composer_subject_edit_text"
                style="@style/ProtonInput.Plain"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                app:layout_constraintTop_toBottomOf="@id/composer_bcc_recipient_view"
                app:layout_constraintStart_toStartOf="@id/composer_fields_start_guideline"
                app:layout_constraintEnd_toEndOf="@id/composer_fields_end_guideline"
                android:textAppearance="@style/Proton.Text.Default.Weak"
                android:hint="@string/composer_subject"
                android:imeOptions="actionNext"
                android:inputType="textCapSentences|textMultiLine"
                android:minHeight="@dimen/height_composer_field"
                tools:text="very very long subject that will never fits in a single line"/>

            <View
                android:id="@+id/composer_body_top_divider"
                android:layout_width="match_parent"
                android:layout_height="@dimen/size_divider"
                android:background="@color/separator_norm"
                app:layout_constraintTop_toBottomOf="@id/composer_subject_edit_text"
                app:layout_constraintStart_toStartOf="parent"/>

            <!-- Body -->
            <EditText
                android:id="@+id/composer_message_body_edit_text"
                style="@style/Proton.Text.Default"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/transparent"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:hint="@string/composer_compose_email"
                android:inputType="textMultiLine|textLongMessage|textCapSentences"
                android:padding="@dimen/padding_composer_body"
                app:layout_constraintTop_toBottomOf="@id/composer_subject_edit_text"
                android:paddingBottom="@dimen/padding_s" />

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/composer_body_start_guideline"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_begin="@dimen/padding_composer_body"/>

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/composer_body_end_guideline"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_end="@dimen/padding_composer_body"/>

            <!-- Respond inline -->
            <Button
                android:id="@+id/composer_respond_inline_button"
                style="@style/ProtonButton.Borderless.Text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintTop_toBottomOf="@id/composer_message_body_edit_text"
                app:layout_constraintEnd_toEndOf="@id/composer_body_end_guideline"
                android:text="@string/respond_inline"
                android:visibility="gone"
                tools:visibility="visible"/>

            <!-- Quote Header -->
            <TextView
                android:id="@+id/composer_quote_header_text_view"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                app:layout_constraintTop_toBottomOf="@id/composer_respond_inline_button"
                app:layout_constraintStart_toStartOf="@id/composer_body_start_guideline"
                app:layout_constraintEnd_toEndOf="@id/composer_body_end_guideline"
                android:textSize="@dimen/h4"
                tools:visibility="visible"
                tools:text="@tools:sample/lorem"/>

            <!-- Quoted Message -->
            <FrameLayout
                android:id="@+id/composer_quoted_message_container"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                app:layout_constraintStart_toStartOf="@id/composer_body_start_guideline"
                app:layout_constraintEnd_toEndOf="@id/composer_body_end_guideline"
                app:layout_constraintTop_toBottomOf="@id/composer_quote_header_text_view"
                android:visibility="gone"
                tools:visibility="visible"
                tools:layout_height="20dp"
                tools:background="@color/notification_success">
                <!-- add WebView through code use application context to avoid memory leaks -->
                <!-- https://code.google.com/p/android/issues/detail?id=9375 -->
            </FrameLayout>

            <!-- Dummy keyboard TODO: still needed? -->
            <View
                android:id="@+id/dummy_keyboard"
                android:layout_width="match_parent"
                android:layout_height="20dp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintBottom_toBottomOf="@id/composer_quoted_message_container"
                android:background="@android:color/transparent"
                android:visibility="gone" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.core.widget.NestedScrollView>

    <View
        android:layout_width="match_parent"
        android:layout_height="@dimen/size_divider"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toTopOf="@id/composer_bottom_app_bar"
        android:background="@color/separator_norm" />

    <!-- Buttons -->
    <ch.protonmail.android.ui.view.ComposerBottomAppBar
        android:id="@+id/composer_bottom_app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/height_composer_field"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
