<?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>

        <import type="com.topjohnwu.magisk.core.Info" />

        <import type="com.topjohnwu.magisk.core.Config" />

        <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="@dimen/internal_action_bar_size"
        android:paddingBottom="@dimen/l2"
        app:fitsSystemWindowsInsets="top|bottom"
        tools:paddingTop="24dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="false"
            android:orientation="vertical"
            android:paddingTop="@dimen/l_50">

            <com.google.android.material.card.MaterialCardView
                style="@style/WidgetFoundation.Card"
                gone="@{viewModel.skipOptions}"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/l1"
                android:layout_marginEnd="@dimen/l1"
                android:focusable="false">

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

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

                        <ImageView
                            style="@style/WidgetFoundation.Icon"
                            isSelected="@{viewModel.step > 0}"
                            android:layout_marginStart="@dimen/l_25"
                            app:srcCompat="@drawable/ic_check_circle_md2" />

                        <TextView
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_marginStart="@dimen/l1"
                            android:layout_weight="1"
                            android:gravity="center_vertical"
                            android:text="@string/install_options_title"
                            android:textAppearance="@style/AppearanceFoundation.Body"
                            android:textStyle="bold" />

                        <Button
                            style="@style/WidgetFoundation.Button.Text"
                            gone="@{viewModel.step != 0}"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:onClick="@{() -> viewModel.setStep(1)}"
                            android:text="@string/install_next" />

                    </LinearLayout>

                    <LinearLayout
                        gone="@{viewModel.step != 0}"
                        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"
                        android:orientation="vertical"
                        android:paddingStart="3dp"
                        android:paddingEnd="3dp"
                        tools:layout_gravity="center">

                        <CheckBox
                            style="@style/WidgetFoundation.Checkbox"
                            gone="@{Info.isSAR}"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:checked="@={Config.keepVerity}"
                            android:text="@string/keep_dm_verity"
                            tools:checked="true" />

                        <CheckBox
                            style="@style/WidgetFoundation.Checkbox"
                            goneUnless="@{Info.isFDE}"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:checked="@={Config.keepEnc}"
                            android:text="@string/keep_force_encryption"
                            app:tint="?colorPrimary" />

                        <CheckBox
                            style="@style/WidgetFoundation.Checkbox"
                            gone="@{Info.ramdisk}"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:checked="@={Config.recovery}"
                            android:text="@string/recovery_mode"
                            app:tint="?colorPrimary" />

                    </LinearLayout>

                </LinearLayout>

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

            <com.google.android.material.card.MaterialCardView
                style="@style/WidgetFoundation.Card"
                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"
                android:focusable="false">

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

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

                        <ImageView
                            style="@style/WidgetFoundation.Icon"
                            isSelected="@{viewModel.step > 1}"
                            android:layout_marginStart="@dimen/l_25"
                            app:srcCompat="@drawable/ic_check_circle_md2" />

                        <TextView
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_marginStart="@dimen/l1"
                            android:layout_weight="1"
                            android:gravity="center_vertical"
                            android:text="@string/install_method_title"
                            android:textAppearance="@style/AppearanceFoundation.Body"
                            android:textStyle="bold" />

                        <Button
                            style="@style/WidgetFoundation.Button.Text"
                            gone="@{viewModel.step != 1}"
                            isEnabled="@{(viewModel.method == @id/method_patch || viewModel.method == @id/method_download) ? viewModel.data != null : viewModel.method != -1}"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:onClick="@{() -> viewModel.install()}"
                            android:text="@string/install_start"
                            app:icon="@drawable/ic_forth_md2"
                            app:iconGravity="textEnd" />

                    </LinearLayout>

                    <RadioGroup
                        gone="@{viewModel.step != 1}"
                        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"
                        android:checkedButton="@={viewModel.method}"
                        android:paddingStart="3dp"
                        android:paddingEnd="3dp">

                        <RadioButton
                            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" />

                        <RadioButton
                            android:id="@+id/method_download"
                            style="@style/WidgetFoundation.RadioButton"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="@string/download_patch_file" />

                        <RadioButton
                            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" />

                        <RadioButton
                            android:id="@+id/method_inactive_slot"
                            style="@style/WidgetFoundation.RadioButton"
                            gone="@{viewModel.noSecondSlot}"
                            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.card.MaterialCardView
                style="@style/WidgetFoundation.Card"
                gone="@{viewModel.notes.length == 0}"
                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"
                android:focusable="false">

                <TextView
                    android:id="@+id/release_notes"
                    markdownText="@{viewModel.notes}"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="15dp"
                    android:breakStrategy="simple"
                    android:hyphenationFrequency="none"
                    android:textAppearance="@style/AppearanceFoundation.Caption"
                    tools:ignore="UnusedAttribute"
                    tools:maxLines="5"
                    tools:text="@tools:sample/lorem/random"
                    tools:visibility="visible" />

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

        </LinearLayout>

    </androidx.core.widget.NestedScrollView>

</layout>
