<!--
  TimeLimit Copyright <C> 2019 - 2024 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.payment.PurchaseFragment">

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

        <variable
            name="handlers"
            type="io.timelimit.android.ui.payment.PurchaseFragmentHandlers" />

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

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

        <variable
            name="priceData"
            type="io.timelimit.android.ui.payment.PurchaseModel.Status.ReadyRegular" />

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

        <import type="android.view.View" />
    </data>

    <io.timelimit.android.ui.view.SafeViewFlipper
        android:id="@+id/flipper"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            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">

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

                <androidx.cardview.widget.CardView
                    android:onClick="@{() -> handlers.buyForOneMonth()}"
                    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:textAppearance="?android:textAppearanceLarge"
                            android:text="@string/purchase_one_month"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />

                        <TextView
                            android:text="@{priceData.monthPrice}"
                            tools:text="1,00 €"
                            android:textAppearance="?android:textAppearanceMedium"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />
                    </LinearLayout>
                </androidx.cardview.widget.CardView>

                <androidx.cardview.widget.CardView
                    android:onClick="@{() -> handlers.buyForOneYear()}"
                    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:textAppearance="?android:textAppearanceLarge"
                            android:text="@string/purchase_one_year"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />

                        <TextView
                            android:text="@{priceData.yearPrice}"
                            tools:text="10,00 €"
                            android:textAppearance="?android:textAppearanceMedium"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />
                    </LinearLayout>
                </androidx.cardview.widget.CardView>

            </LinearLayout>

            <TextView
                android:textAppearance="?android:textAppearanceSmall"
                android:padding="8dp"
                android:layout_alignParentBottom="true"
                android:text="@string/purchase_info_assigned_to_account"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:padding="8dp"
                android:orientation="vertical"
                android:layout_centerVertical="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:textAppearance="?android:textAppearanceMedium"
                    android:gravity="center_horizontal"
                    android:text="@{errorReason}"
                    android:autoLink="web"
                    tools:text="You have to update the App before you can do purchases"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

                <Button
                    android:layout_marginTop="4dp"
                    android:visibility="@{safeUnbox(showRetryButton) ? View.VISIBLE : View.GONE}"
                    android:onClick="@{() -> handlers.retryAtErrorScreenClicked()}"
                    android:text="@string/generic_retry"
                    android:layout_gravity="center_horizontal"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <Button
                    style="?borderlessButtonStyle"
                    android:layout_marginTop="4dp"
                    android:visibility="@{showErrorDetailsButton ? View.VISIBLE : View.GONE}"
                    android:onClick="@{() -> handlers.showErrorDetails()}"
                    android:text="@string/generic_show_details"
                    android:layout_gravity="center_horizontal"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </RelativeLayout>

        <include layout="@layout/circular_progress_indicator" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <LinearLayout
                android:padding="8dp"
                android:orientation="vertical"
                android:layout_centerVertical="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

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

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

            </LinearLayout>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:padding="8dp"
                android:orientation="vertical"
                android:layout_centerVertical="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

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

                <Button
                    android:layout_marginTop="4dp"
                    android:onClick="@{() -> handlers.showAuthDialog()}"
                    android:text="@string/add_user_authentication_required_btn"
                    android:layout_gravity="center_horizontal"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:padding="8dp"
                android:orientation="vertical"
                android:layout_centerVertical="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:textAppearance="?android:textAppearanceMedium"
                    android:gravity="center_horizontal"
                    android:text="@string/purchase_token_explain"
                    android:autoLink="web"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

                <ScrollView
                    android:paddingTop="8dp"
                    android:paddingBottom="8dp"
                    android:layout_weight="1"
                    android:layout_width="match_parent"
                    android:layout_height="0dp">
                    <TextView
                        android:textAppearance="?android:textAppearanceSmall"
                        android:layout_gravity="center_horizontal"
                        tools:text="12345678"
                        android:text="@{purchaseToken}"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />
                </ScrollView>

                <Button
                    android:layout_marginTop="4dp"
                    android:onClick="@{() -> handlers.copyPurchaseTokenToClipboard()}"
                    android:text="@string/diagnose_sync_copy_to_clipboard"
                    android:layout_gravity="center_horizontal"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </RelativeLayout>
    </io.timelimit.android.ui.view.SafeViewFlipper>
</layout>
