<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>
        <variable
            name="viewModel"
            type="com.fsck.k9.ui.addaccount.AddAccountViewModel" />
    </data>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:fitsSystemWindows="true">

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

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/emailAddressLayout"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginTop="16dp"
                android:layout_marginEnd="16dp"
                app:error="@{viewModel.emailAddressError}"
                app:errorEnabled="true"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/emailAddress"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:enabled="@{viewModel.isInputEnabled}"
                    android:hint="@string/account_setup_basics_email_hint"
                    android:imeOptions="flagNoExtractUi"
                    android:inputType="textEmailAddress"
                    android:text="@={viewModel.emailAddress}" />

            </com.google.android.material.textfield.TextInputLayout>

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/emailPasswordLayout"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="16dp"
                app:error="@{viewModel.passwordError}"
                app:errorEnabled="true"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/emailAddressLayout"
                app:passwordToggleEnabled="true">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/emailPassword"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:enabled="@{viewModel.isInputEnabled}"
                    android:hint="@string/account_setup_basics_password_hint"
                    android:imeOptions="flagNoExtractUi"
                    android:inputType="textPassword"
                    android:text="@={viewModel.password}" />

            </com.google.android.material.textfield.TextInputLayout>

            <TextView
                android:id="@+id/setupError"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginTop="16dp"
                android:layout_marginEnd="16dp"
                android:text="@{viewModel.setupErrorText}"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/emailPasswordLayout" />

            <ProgressBar
                android:id="@+id/progressBar"
                style="?android:attr/progressBarStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginTop="32dp"
                android:layout_marginEnd="16dp"
                android:layout_marginBottom="32dp"
                app:isVisible="@{viewModel.isProgressBarVisible()}"
                app:layout_constraintBottom_toTopOf="@+id/nextButton"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/setupError" />

            <Button
                android:id="@+id/nextButton"
                style="@style/Widget.AppCompat.Button.Colored"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="24dp"
                android:layout_marginEnd="16dp"
                android:layout_marginBottom="16dp"
                android:enabled="@{viewModel.isNextButtonEnabled()}"
                android:onClick="@{() -> viewModel.onNextButtonClicked()}"
                android:text="@string/next_action"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/emailPasswordLayout"
                app:layout_constraintVertical_bias="1.0" />

        </androidx.constraintlayout.widget.ConstraintLayout>
    </ScrollView>
</layout>
