<?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="android.os.Build" />
        <import type="com.topjohnwu.magisk.core.Info" />
        <import type="com.topjohnwu.magisk.BuildConfig" />
        <import type="com.topjohnwu.magisk.R" />

        <variable
            name="viewModel"
            type="com.topjohnwu.magisk.ui.safetynet.SafetynetViewModel" />

    </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"
        app:fitsSystemWindowsInsets="top|bottom"
        tools:paddingBottom="48dp"
        tools:paddingTop="24dp">

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

            <TextView
                invisibleUnless="@{viewModel.checking}"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="@string/safetynet_attest_loading"
                android:textAppearance="@style/AppearanceFoundation.Title" />

            <androidx.constraintlayout.widget.ConstraintLayout
                invisible="@{viewModel.checking}"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingTop="@dimen/l1"
                android:paddingBottom="@dimen/l1">

                <com.google.android.material.card.MaterialCardView
                    android:id="@+id/safetynet_attestation"
                    style="@style/WidgetFoundation.Card.Elevated"
                    cardBackgroundColorAttr="@{viewModel.success ? R.attr.colorPrimary : R.attr.colorError}"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/l1"
                    android:layout_marginTop="@dimen/l2"
                    android:layout_marginEnd="@dimen/l1"
                    app:cardCornerRadius="@dimen/l1"
                    app:cardElevation="@dimen/l1"
                    app:layout_constraintHorizontal_chainStyle="packed"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias=".35"
                    app:layout_constraintWidth_max="300dp"
                    tools:cardBackgroundColor="?colorPrimary">

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

                        <TextView
                            android:id="@+id/safetynet_title"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="@dimen/l1"
                            android:layout_marginTop="@dimen/l2"
                            android:layout_marginEnd="@dimen/l1"
                            android:gravity="center"
                            android:text="@{viewModel.safetyNetTitle}"
                            android:textAppearance="@style/AppearanceFoundation.Display.OnPrimary"
                            android:textStyle="bold"
                            app:textColorAttr="@{viewModel.textColorAttr}"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintHorizontal_chainStyle="packed"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent"
                            tools:text="@string/safetynet_attest_success" />

                        <ImageView
                            android:id="@+id/safetynet_divider"
                            android:layout_width="50dp"
                            android:layout_height="4dp"
                            android:layout_marginTop="@dimen/l2"
                            app:srcCompat="@drawable/bg_divider_rounded_on_primary"
                            app:tintAttr="@{viewModel.textColorAttr}"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@+id/safetynet_title"
                            tools:tint="?colorOnPrimary"/>

                        <androidx.constraintlayout.widget.ConstraintLayout
                            android:id="@+id/checkbox_layout"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:paddingBottom="@dimen/l1"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@+id/safetynet_divider">

                            <TextView
                                android:id="@+id/basic_text"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_gravity="center_vertical"
                                android:gravity="start"
                                android:text="basicIntegrity"
                                android:textAppearance="@style/AppearanceFoundation.Body.OnPrimary"
                                android:textStyle="bold"
                                android:layout_marginTop="@dimen/l2"
                                app:textColorAttr="@{viewModel.textColorAttr}"
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintEnd_toEndOf="@id/snet_barrier"
                                app:layout_constraintTop_toTopOf="parent"
                                tools:ignore="HardcodedText" />

                            <TextView
                                android:id="@+id/cts_text"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_gravity="center_vertical"
                                android:gravity="start"
                                android:text="ctsProfile"
                                android:textAppearance="@style/AppearanceFoundation.Body.OnPrimary"
                                android:textStyle="bold"
                                android:layout_marginTop="@dimen/l2"
                                app:textColorAttr="@{viewModel.textColorAttr}"
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintEnd_toEndOf="@id/snet_barrier"
                                app:layout_constraintTop_toBottomOf="@id/basic_text"
                                tools:ignore="HardcodedText" />

                            <androidx.constraintlayout.widget.Barrier
                                android:id="@+id/snet_barrier"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                app:barrierDirection="end"
                                app:constraint_referenced_ids="basic_text,cts_text"/>

                            <ImageView
                                style="@style/WidgetFoundation.Icon.OnPrimary"
                                isSelected="@{viewModel.basicIntegrityState}"
                                android:layout_gravity="center"
                                app:srcCompat="@drawable/ic_check_circle_md2"
                                app:tintAttr="@{viewModel.textColorAttr}"
                                app:layout_constraintStart_toEndOf="@id/snet_barrier"
                                app:layout_constraintTop_toTopOf="@id/basic_text"
                                app:layout_constraintBottom_toBottomOf="@id/basic_text"
                                tools:tint="?colorOnPrimary"/>

                            <ImageView
                                style="@style/WidgetFoundation.Icon.OnPrimary"
                                isSelected="@{viewModel.ctsState}"
                                android:layout_gravity="center"
                                app:srcCompat="@drawable/ic_check_circle_md2"
                                app:tintAttr="@{viewModel.textColorAttr}"
                                app:layout_constraintStart_toEndOf="@id/snet_barrier"
                                app:layout_constraintTop_toTopOf="@id/cts_text"
                                app:layout_constraintBottom_toBottomOf="@id/cts_text"
                                tools:tint="?colorOnPrimary"/>

                        </androidx.constraintlayout.widget.ConstraintLayout>

                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:orientation="horizontal"
                            android:paddingBottom="@dimen/l2"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@+id/checkbox_layout">

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_gravity="center_vertical"
                                android:gravity="start"
                                android:text="evalType"
                                android:textAppearance="@style/AppearanceFoundation.Body.OnPrimary"
                                android:textStyle="bold"
                                app:textColorAttr="@{viewModel.textColorAttr}"
                                tools:ignore="HardcodedText" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_gravity="center_vertical"
                                android:textAppearance="@style/AppearanceFoundation.Body.OnPrimary"
                                android:textStyle="bold"
                                android:layout_marginStart="@dimen/l1"
                                android:text="@{viewModel.evalType}"
                                app:textColorAttr="@{viewModel.textColorAttr}"
                                tools:text="HARDWARE"/>

                        </LinearLayout>

                    </androidx.constraintlayout.widget.ConstraintLayout>

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

                <Button
                    style="@style/WidgetFoundation.Button.Text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/l1"
                    android:layout_marginBottom="@dimen/l1"
                    android:onClick="@{() -> viewModel.reset()}"
                    android:text="@string/safetynet_attest_restart"
                    android:textAllCaps="false"
                    android:textColor="?colorOnSurfaceVariant"
                    app:icon="@drawable/ic_refresh_safetynet_md2"
                    app:iconTint="?colorOnSurfaceVariant"
                    app:layout_constraintEnd_toEndOf="@+id/safetynet_attestation"
                    app:layout_constraintTop_toBottomOf="@+id/safetynet_attestation" />

            </androidx.constraintlayout.widget.ConstraintLayout>

        </FrameLayout>


    </androidx.core.widget.NestedScrollView>

</layout>
