<?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"
    xmlns:tools="http://schemas.android.com/tools">

    <data>

        <variable
            name="viewModel"
            type="com.topjohnwu.magisk.ui.install.InstallViewModel" />

    </data>

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:fillViewport="true"
        android:paddingTop="@{viewModel.insets.top + (int) @dimen/internal_action_bar_size}"
        android:paddingBottom="@{viewModel.insets.bottom + (int) @dimen/l2}"
        tools:paddingTop="24dp">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                goneUnless="@{viewModel.loaded}"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clipToPadding="false"
                android:orientation="vertical"
                android:paddingTop="@dimen/l1">

                <com.google.android.material.card.MaterialCardView
                    style="@style/WidgetFoundation.Card.Variant"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/l1"
                    android:layout_marginEnd="@dimen/l1"
                    app:strokeWidth="@{viewModel.step != 0 ? 0f : @dimen/l_125}">

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

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

                            <androidx.appcompat.widget.AppCompatImageView
                                android:id="@+id/install_step_options_icon"
                                style="@style/WidgetFoundation.Icon"
                                isSelected="@{viewModel.step > 0}"
                                android:layout_marginStart="@dimen/l_25"
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintTop_toTopOf="parent"
                                app:srcCompat="@drawable/ic_check_circle_md2" />

                            <androidx.appcompat.widget.AppCompatTextView
                                android:id="@+id/install_step_options_title"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_marginStart="@dimen/l1"
                                android:gravity="start"
                                android:text="@string/install_options_title"
                                android:textAppearance="@style/AppearanceFoundation.Body"
                                android:textStyle="bold"
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintEnd_toStartOf="@+id/install_step_options_button"
                                app:layout_constraintStart_toEndOf="@+id/install_step_options_icon"
                                app:layout_constraintTop_toTopOf="parent" />

                            <com.google.android.material.button.MaterialButton
                                android:id="@+id/install_step_options_button"
                                style="@style/WidgetFoundation.Button.Text"
                                gone="@{viewModel.step != 0}"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:onClick="@{() -> viewModel.step(1)}"
                                android:text="@string/install_next"
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintEnd_toEndOf="parent"
                                app:layout_constraintTop_toTopOf="parent" />

                        </androidx.constraintlayout.widget.ConstraintLayout>

                        <FrameLayout
                            gone="@{viewModel.step != 0}"
                            android:layout_width="match_parent"
                            android:paddingStart="3dp"
                            android:paddingEnd="3dp"
                            android:layout_height="wrap_content">

                            <include
                                layout="@layout/include_install_options"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginStart="@dimen/l1"
                                android:layout_marginTop="@dimen/l_50"
                                android:layout_marginEnd="@dimen/l1"
                                android:layout_marginBottom="@dimen/l_50" />

                        </FrameLayout>

                    </LinearLayout>

                </com.google.android.material.card.MaterialCardView>

                <com.google.android.material.card.MaterialCardView
                    style="@style/WidgetFoundation.Card.Variant"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/l1"
                    android:layout_marginTop="@dimen/l1"
                    android:layout_marginEnd="@dimen/l1"
                    app:strokeWidth="@{viewModel.step != 1 ? 0f : @dimen/l_125}">

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

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

                            <androidx.appcompat.widget.AppCompatImageView
                                android:id="@+id/install_step_method_icon"
                                style="@style/WidgetFoundation.Icon"
                                isSelected="@{viewModel.step > 1}"
                                android:layout_marginStart="@dimen/l_25"
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintTop_toTopOf="parent"
                                app:srcCompat="@drawable/ic_check_circle_md2" />

                            <androidx.appcompat.widget.AppCompatTextView
                                android:id="@+id/install_step_method_title"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_marginStart="@dimen/l1"
                                android:gravity="start"
                                android:text="@string/install_method_title"
                                android:textAppearance="@style/AppearanceFoundation.Body"
                                android:textStyle="bold"
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintEnd_toStartOf="@+id/install_step_method_button"
                                app:layout_constraintStart_toEndOf="@+id/install_step_method_icon"
                                app:layout_constraintTop_toTopOf="parent" />

                            <com.google.android.material.button.MaterialButton
                                android:id="@+id/install_step_method_button"
                                style="@style/WidgetFoundation.Button.Text"
                                gone="@{viewModel.step != 1}"
                                isEnabled="@{viewModel.method == @id/method_patch ? viewModel.data != null : viewModel.method != -1}"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:onClick="@{() -> viewModel.step(2)}"
                                android:text="@string/install_next"
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintEnd_toEndOf="parent"
                                app:layout_constraintTop_toTopOf="parent" />

                        </androidx.constraintlayout.widget.ConstraintLayout>

                        <RadioGroup
                            gone="@{viewModel.step != 1}"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:paddingStart="3dp"
                            android:paddingEnd="3dp"
                            android:layout_marginStart="@dimen/l1"
                            android:layout_marginTop="@dimen/l_50"
                            android:layout_marginEnd="@dimen/l1"
                            android:layout_marginBottom="@dimen/l_50"
                            android:checkedButton="@={viewModel.method}">

                            <com.google.android.material.radiobutton.MaterialRadioButton
                                android:id="@+id/method_download"
                                style="@style/WidgetFoundation.RadioButton"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:text="@string/download_zip_only"
                                tools:checked="true" />

                            <com.google.android.material.radiobutton.MaterialRadioButton
                                android:id="@+id/method_patch"
                                style="@style/WidgetFoundation.RadioButton"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:text="@string/select_patch_file" />

                            <com.google.android.material.radiobutton.MaterialRadioButton
                                android:id="@+id/method_direct"
                                style="@style/WidgetFoundation.RadioButton"
                                gone="@{!viewModel.rooted}"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:text="@string/direct_install" />

                            <com.google.android.material.radiobutton.MaterialRadioButton
                                android:id="@+id/method_inactive_slot"
                                style="@style/WidgetFoundation.RadioButton"
                                gone="@{!viewModel.isRooted || !viewModel.isAB}"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:text="@string/install_inactive_slot" />

                        </RadioGroup>

                    </LinearLayout>

                </com.google.android.material.card.MaterialCardView>

                <com.google.android.material.button.MaterialButton
                    style="@style/WidgetFoundation.Button.Text"
                    gone="@{viewModel.step != 2}"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="end"
                    android:layout_margin="@dimen/l1"
                    android:onClick="@{() -> viewModel.install()}"
                    android:text="@string/install_start"
                    app:icon="@drawable/ic_forth_md2"
                    app:iconGravity="textEnd" />

            </LinearLayout>

            <LinearLayout
                goneUnless="@{viewModel.loading}"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_marginStart="@dimen/l1"
                android:layout_marginEnd="@dimen/l1"
                android:gravity="center"
                android:orientation="vertical">

                <androidx.appcompat.widget.AppCompatTextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="@string/safetynet_attest_loading"
                    android:textAppearance="@style/AppearanceFoundation.Title" />

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/l1">

                    <ProgressBar
                        style="@style/WidgetFoundation.ProgressBar"
                        invisible="@{viewModel.progress &lt;= 0}"
                        android:layout_width="100dp"
                        android:layout_gravity="center"
                        android:progress="@{viewModel.progress}" />

                    <ProgressBar
                        style="@style/WidgetFoundation.ProgressBar.Indeterminate"
                        invisibleUnless="@{viewModel.progress &lt;= 0}"
                        android:layout_width="100dp"
                        android:layout_gravity="center" />

                </FrameLayout>


            </LinearLayout>

        </FrameLayout>

    </androidx.core.widget.NestedScrollView>

</layout>
