<?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="loginViewModel"
            type="it.integry.integrywmsnative.gest.login.viewmodel.LoginViewModel" />
    </data>


    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fitsSystemWindows="true">

        <androidx.appcompat.widget.LinearLayoutCompat
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingLeft="24dp"
            android:paddingTop="56dp"
            android:paddingRight="24dp">

            <androidx.appcompat.widget.AppCompatImageView
                android:layout_width="wrap_content"
                android:layout_height="72dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginBottom="24dp"
                android:src="@drawable/logo_integry_testo" />

            <!-- Username Label -->
            <com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                app:errorText="@{loginViewModel.usernameError}"
                app:hintTextAppearance="@style/hint_text"
                style="@style/TextInputLayout.OutlinePrimary">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/input_username"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Username"
                    android:inputType="textEmailAddress"
                    app:binding="@{loginViewModel.username}" />
            </com.google.android.material.textfield.TextInputLayout>

            <!-- Password Label -->
            <com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                app:errorText="@{loginViewModel.passwordError}"
                app:hintTextAppearance="@style/hint_text"
                app:passwordToggleEnabled="true"
                style="@style/TextInputLayout.OutlinePrimary">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/input_password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Password"
                    android:inputType="textPassword"
                    app:binding="@{loginViewModel.password}" />
            </com.google.android.material.textfield.TextInputLayout>

            <androidx.appcompat.widget.AppCompatCheckBox
                android:id="@+id/login_checkbox_custom_server"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:enabled="@{loginViewModel.customSettingsCheckboxEnabled}"
                android:text="@string/action_customize_server_settings"
                app:checked="@{loginViewModel.customSettingsCheckboxChecked}" />

            <net.cachapa.expandablelayout.ExpandableLayout
                android:id="@+id/login_layout_server_details"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingTop="6dp"
                android:paddingBottom="12dp"
                app:el_duration="400"
                app:el_expanded_bind="@{loginViewModel.customSettingsCheckboxChecked}">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <!--Host Label-->
                    <com.google.android.material.textfield.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="8dp"
                        app:errorText="@{loginViewModel.codAziendaError}"
                        app:hintTextAppearance="@style/hint_text"
                        style="@style/TextInputLayout.OutlinePrimary">

                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/input_cod_azienda"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:hint="Codice azienda"
                            android:inputType="text"
                            app:binding="@{loginViewModel.codAzienda}" />
                    </com.google.android.material.textfield.TextInputLayout>

                </LinearLayout>

            </net.cachapa.expandablelayout.ExpandableLayout>


            <com.google.android.material.button.MaterialButton
                android:id="@+id/btn_login"
                style="@style/Button.PrimaryFull"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="24dp"
                android:layout_marginBottom="24dp"
                android:enabled="@{loginViewModel.loginButtonEnabled}"
                android:text="@string/login"
                app:onClick="@{() -> loginViewModel.login(loginViewModel.validate())}" />


        </androidx.appcompat.widget.LinearLayoutCompat>
    </ScrollView>
</layout>