<?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.ui.superuser.PolicyRvItem" />

    </data>

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

        <com.google.android.material.card.MaterialCardView
            style="@style/WidgetFoundation.Card"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:alpha="@{item.enabled ? 1f : .5f}"
            android:onClick="@{() -> item.toggleExpand()}">

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

                    <ImageView
                        android:id="@+id/policy_app_icon"
                        style="@style/WidgetFoundation.Image"
                        android:layout_marginStart="@dimen/l1"
                        android:layout_marginTop="@dimen/l1"
                        android:layout_marginBottom="@dimen/l1"
                        srcCompat="@{item.icon}"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent"
                        app:layout_constraintVertical_bias="0"
                        tools:srcCompat="@drawable/ic_logo" />

                    <TextView
                        android:id="@+id/policy_app_name"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/margin_generic"
                        android:layout_marginRight="@dimen/margin_generic"
                        android:ellipsize="middle"
                        android:gravity="start"
                        android:maxLines="2"
                        android:text="@{item.item.appName}"
                        android:textAppearance="@style/AppearanceFoundation.Body"
                        android:textIsSelectable="false"
                        android:textStyle="bold"
                        app:layout_constraintEnd_toStartOf="@+id/policy_indicator"
                        app:layout_constraintStart_toEndOf="@+id/policy_app_icon"
                        app:layout_constraintTop_toTopOf="@+id/policy_app_icon"
                        tools:text="@string/magisk" />

                    <TextView
                        android:id="@+id/policy_package_name"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="@dimen/l1"
                        android:ellipsize="middle"
                        android:gravity="start"
                        android:maxLines="2"
                        android:text="@{item.item.packageName}"
                        android:textAppearance="@style/AppearanceFoundation.Caption.Variant"
                        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"
                        app:layout_constraintVertical_bias="0"
                        tools:text="com.topjohnwu.magisk" />

                    <com.google.android.material.switchmaterial.SwitchMaterial
                        android:id="@+id/policy_indicator"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:checked="@={item.enabled}"
                        android:layout_marginEnd="@dimen/l1"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />

                </androidx.constraintlayout.widget.ConstraintLayout>

                <LinearLayout
                    android:id="@+id/policy_expand_container"
                    android:orientation="horizontal"
                    gone="@{!item.isExpanded}"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="?colorSurfaceVariant"
                    tools:visibility="visible">

                    <Button
                        android:id="@+id/policy_notify"
                        style="@style/WidgetFoundation.Button.Text"
                        isSelected="@{item.shouldNotify}"
                        android:layout_weight="1"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:minHeight="24dp"
                        android:onClick="@{() -> item.toggleNotify()}"
                        android:text="@string/superuser_toggle_notification"
                        android:textAllCaps="false"
                        android:textAppearance="@style/AppearanceFoundation.Tiny"
                        android:textColor="@color/color_state_primary_transient"
                        app:icon="@drawable/ic_notifications_md2"
                        app:iconTint="@color/color_state_primary_transient"
                        app:tint="@color/color_state_primary_transient" />

                    <View
                        android:layout_width="1dp"
                        android:layout_height="match_parent"
                        android:layout_marginTop="@dimen/l_50"
                        android:layout_marginBottom="@dimen/l_50"
                        android:background="?colorSurfaceSurfaceVariant" />

                    <Button
                        android:id="@+id/policy_log"
                        style="@style/WidgetFoundation.Button.Text"
                        isSelected="@{item.shouldLog}"
                        android:layout_weight="1"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:minHeight="24dp"
                        android:onClick="@{() -> item.toggleLog()}"
                        android:text="@string/logs"
                        android:textAllCaps="false"
                        android:textAppearance="@style/AppearanceFoundation.Tiny"
                        android:textColor="@color/color_state_primary_transient"
                        app:icon="@drawable/ic_bug_md2"
                        app:iconTint="@color/color_state_primary_transient"
                        app:tint="@color/color_state_primary_transient" />

                    <View
                        android:layout_width="1dp"
                        android:layout_height="match_parent"
                        android:layout_marginTop="@dimen/l_50"
                        android:layout_marginBottom="@dimen/l_50"
                        android:background="?colorSurfaceSurfaceVariant" />

                    <Button
                        android:id="@+id/policy_delete"
                        style="@style/WidgetFoundation.Button.Text"
                        android:layout_weight="1"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:minHeight="24dp"
                        android:onClick="@{() -> item.revoke()}"
                        android:text="@string/superuser_toggle_revoke"
                        android:textAllCaps="false"
                        android:textColor="?colorError"
                        android:textSize="12sp"
                        app:icon="@drawable/ic_delete_md2"
                        app:iconTint="?colorError"
                        app:rippleColor="?colorError" />

                </LinearLayout>

            </LinearLayout>

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

    </FrameLayout>

</layout>
