<?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="item"
            type="com.topjohnwu.magisk.model.entity.recycler.PolicyItem" />

        <variable
            name="viewModel"
            type="com.topjohnwu.magisk.redesign.superuser.SuperuserViewModel" />

    </data>

    <com.google.android.material.card.MaterialCardView
        style="?styleCardVariant"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:alpha="@{item.isEnabled() ? 1f : .5f}"
        android:onClick="@{() -> item.toggle(viewModel)}"
        tools:layout_marginBottom="@dimen/l1"
        tools:layout_marginEnd="@dimen/l1"
        tools:layout_width="200dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingTop="@dimen/l2"
            android:paddingBottom="@dimen/l2">

            <androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/policy_app_icon"
                style="?styleImageBig"
                android:src="@{item.icon}"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                tools:srcCompat="@drawable/ic_logo" />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/policy_app_name"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/margin_generic"
                android:layout_marginTop="@dimen/l1"
                android:layout_marginRight="@dimen/margin_generic"
                android:ellipsize="middle"
                android:gravity="center"
                android:singleLine="true"
                android:text="@{item.item.appName}"
                android:textAppearance="?appearanceTextTitleNormal"
                android:textIsSelectable="false"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/policy_app_icon"
                tools:text="@string/app_name" />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/policy_package_name"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:ellipsize="middle"
                android:gravity="center"
                android:singleLine="true"
                android:text="@{item.item.packageName}"
                android:textAppearance="?appearanceTextCaptionVariant"
                android:textColor="@android:color/tertiary_text_dark"
                android:textIsSelectable="false"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="@id/policy_app_name"
                app:layout_constraintStart_toStartOf="@id/policy_app_name"
                app:layout_constraintTop_toBottomOf="@id/policy_app_name"
                tools:text="com.topjohnwu.magisk" />

        </androidx.constraintlayout.widget.ConstraintLayout>

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/policy_expand_container"
            revealFix="@{item.isExpanded()}"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintTop_toBottomOf="@+id/policy_package_name"
            android:background="?colorSurfaceVariant"
            android:visibility="invisible"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            tools:alpha="0.9"
            tools:visibility="visible">

            <androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/policy_notify"
                style="?styleIconNormal"
                android:background="?selectableItemBackground"
                isSelected="@{item.shouldNotify}"
                tooltipText="@{@string/superuser_toggle_notification}"
                android:contentDescription="@string/superuser_toggle_notification"
                android:onClick="@{() -> item.toggleNotify(viewModel)}"
                app:layout_constraintBottom_toTopOf="@+id/policy_delete"
                app:layout_constraintEnd_toStartOf="@+id/policy_log"
                app:layout_constraintHorizontal_chainStyle="packed"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_chainStyle="packed"
                app:srcCompat="@drawable/ic_notifications"
                app:tint="@color/color_state_primary_transient" />

            <androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/policy_log"
                style="?styleIconNormal"
                android:background="?selectableItemBackground"
                isSelected="@{item.shouldLog}"
                tooltipText="@{@string/superuser_toggle_log}"
                android:contentDescription="@string/superuser_toggle_log"
                android:onClick="@{() -> item.toggleLog(viewModel)}"
                app:layout_constraintBottom_toBottomOf="@+id/policy_notify"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@+id/policy_notify"
                app:layout_constraintTop_toTopOf="@+id/policy_notify"
                app:srcCompat="@drawable/ic_bug_report"
                app:tint="@color/color_state_primary_transient" />

            <com.google.android.material.button.MaterialButton
                android:id="@+id/policy_delete"
                style="?styleButtonText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="@{() -> viewModel.deletePressed(item)}"
                android:text="@string/superuser_toggle_revoke"
                android:textAllCaps="false"
                android:textColor="?colorError"
                android:textSize="12sp"
                app:icon="@drawable/ic_delete_md2"
                app:iconPadding="@dimen/l_50"
                app:iconTint="?colorError"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/policy_notify"
                app:rippleColor="?colorError" />

        </androidx.constraintlayout.widget.ConstraintLayout>

        <androidx.appcompat.widget.AppCompatImageView
            style="?styleIconNormal"
            isEnabled="@{item.isEnabled}"
            isSelected="@{item.isExpanded}"
            android:layout_gravity="top|end"
            android:onClick="@{(view) -> item.toggle(view)}"
            android:rotation="@{item.isExpanded ? 225 : 180}"
            app:srcCompat="@drawable/ic_more_collapse" />

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

</layout>