<!--
  TimeLimit Copyright <C> 2019 - 2022 Jonas Lochmann
  This program 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 version 3 of the License.

  This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
-->
<layout 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"
    tools:context="io.timelimit.android.ui.manage.parent.ManageParentFragment">

    <data>
        <variable
            name="username"
            type="String" />

        <variable
            name="mail"
            type="String" />

        <variable
            name="isUsingLocalMode"
            type="Boolean" />

        <variable
            name="hasU2fSupport"
            type="boolean" />

        <variable
            name="handlers"
            type="io.timelimit.android.ui.manage.parent.ManageParentFragmentHandlers" />

        <import type="android.text.TextUtils" />
        <import type="android.view.View" />
        <import type="io.timelimit.android.BuildConfig" />
    </data>

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ScrollView
            android:id="@+id/scroll"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <LinearLayout
                android:padding="8dp"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <androidx.cardview.widget.CardView
                    android:onClick="@{() -> handlers.onChangePasswordClicked()}"
                    android:foreground="?selectableItemBackground"
                    app:cardUseCompatPadding="true"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <LinearLayout
                        android:padding="8dp"
                        android:orientation="vertical"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <TextView
                            android:text="@string/manage_parent_change_password_title"
                            android:textAppearance="?android:textAppearanceLarge"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />

                        <TextView
                            android:text="@string/manage_parent_change_password_text"
                            android:textAppearance="?android:textAppearanceMedium"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />

                    </LinearLayout>
                </androidx.cardview.widget.CardView>

                <androidx.cardview.widget.CardView
                    android:visibility="@{BuildConfig.hasServer ? View.VISIBLE : View.GONE}"
                    android:foreground="?selectableItemBackground"
                    android:clickable="@{!TextUtils.isEmpty(mail)}"
                    android:onClick="@{() -> handlers.onRestorePasswordClicked()}"
                    app:cardUseCompatPadding="true"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <LinearLayout
                        android:padding="8dp"
                        android:orientation="vertical"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <TextView
                            android:text="@string/manage_parent_restore_password_title"
                            android:textAppearance="?android:textAppearanceLarge"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />

                        <TextView
                            tools:text="@string/manage_parent_restore_password_text_not_possible"
                            android:text="@{TextUtils.isEmpty(mail) ? @string/manage_parent_restore_password_text_not_possible : @string/manage_parent_restore_password_text_require_mail(mail)}"
                            android:textAppearance="?android:textAppearanceMedium"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />

                    </LinearLayout>
                </androidx.cardview.widget.CardView>

                <androidx.cardview.widget.CardView
                    android:visibility="@{BuildConfig.hasServer ? View.VISIBLE : View.GONE}"
                    android:onClick="@{() -> handlers.onLinkMailClicked()}"
                    android:foreground="?selectableItemBackground"
                    android:clickable="@{TextUtils.isEmpty(mail) &amp;&amp; (!safeUnbox(isUsingLocalMode))}"
                    app:cardUseCompatPadding="true"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <LinearLayout
                        android:padding="8dp"
                        android:orientation="vertical"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <TextView
                            android:text="@string/manage_parent_link_mail_title"
                            android:textAppearance="?android:textAppearanceLarge"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />

                        <TextView
                            android:visibility="@{safeUnbox(isUsingLocalMode) ? View.VISIBLE : View.GONE}"
                            android:text="@string/manage_parent_link_mail_status_not_possible_local_mode"
                            android:textAppearance="?android:textAppearanceMedium"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />

                        <TextView
                            android:visibility="@{TextUtils.isEmpty(mail) &amp;&amp; !safeUnbox(isUsingLocalMode) ? View.VISIBLE : View.GONE}"
                            android:text="@string/manage_parent_link_mail_status_disabled"
                            android:textAppearance="?android:textAppearanceMedium"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />

                        <TextView
                            android:visibility="@{!TextUtils.isEmpty(mail) ? View.VISIBLE : View.GONE}"
                            tools:text="@string/manage_parent_link_mail_status_enabled"
                            android:text="@{@string/manage_parent_link_mail_status_enabled(mail)}"
                            android:textAppearance="?android:textAppearanceMedium"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />

                    </LinearLayout>
                </androidx.cardview.widget.CardView>

                <include android:id="@+id/manage_notifications"
                    layout="@layout/manage_parent_notifications" />

                <androidx.cardview.widget.CardView
                    android:visibility="@{hasU2fSupport ? View.VISIBLE : View.GONE}"
                    android:onClick="@{() -> handlers.onManageU2FClicked()}"
                    android:foreground="?selectableItemBackground"
                    app:cardUseCompatPadding="true"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <LinearLayout
                        android:padding="8dp"
                        android:orientation="vertical"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <TextView
                            android:text="@string/manage_parent_u2f_title"
                            android:textAppearance="?android:textAppearanceLarge"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />

                        <TextView
                            android:text="@string/manage_parent_u2f_description"
                            android:textAppearance="?android:textAppearanceMedium"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />

                        <TextView
                            android:textAppearance="?android:textAppearanceSmall"
                            android:text="@string/purchase_required_info_local_mode_free"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />

                    </LinearLayout>
                </androidx.cardview.widget.CardView>

                <include android:id="@+id/user_key"
                    layout="@layout/manage_user_key_view" />

                <include android:id="@+id/timezone"
                    layout="@layout/user_timezone_view" />

                <include android:id="@+id/parent_limit_login"
                    layout="@layout/parent_limit_login_view" />

                <include android:id="@+id/delete_parent"
                    layout="@layout/delete_parent_view" />

            </LinearLayout>
        </ScrollView>

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            app:fabSize="normal"
            android:src="@drawable/ic_lock_open_white_24dp"
            android:layout_margin="16dp"
            android:layout_gravity="end|bottom"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
