<?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.settings.BaseSettingsItem" />

        <variable
            name="callback"
            type="com.topjohnwu.magisk.ui.settings.BaseSettingsItem.Callback" />

    </data>

    <com.google.android.material.card.MaterialCardView
        style="@style/WidgetFoundation.Card"
        isEnabled="@{item.enabled}"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:alpha="@{item.enabled ? 1f : .5f}"
        android:clickable="@{item.enabled}"
        android:focusable="@{item.enabled}"
        android:onClick="@{(view) -> item.onPressed(view, callback)}"
        tools:layout_gravity="center">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:paddingStart="@{item.icon == 0 ? @dimen/l1 : 0}"
            android:paddingEnd="@dimen/l1">

            <ImageView
                android:id="@+id/icon"
                style="@style/WidgetFoundation.Icon"
                gone="@{item.icon == 0}"
                android:background="@null"
                app:srcCompat="@{item.icon}"
                tools:srcCompat="@drawable/ic_fingerprint" />

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center_vertical"
                android:orientation="vertical"
                android:paddingTop="@dimen/l1"
                android:paddingBottom="@dimen/l1">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:gravity="start"
                    android:text="@{item.title}"
                    android:textAppearance="@style/AppearanceFoundation.Body"
                    android:textStyle="bold"
                    tools:lines="1"
                    tools:text="@tools:sample/lorem/random" />

                <TextView
                    gone="@{item.description.empty}"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@{item.description}"
                    android:textAppearance="@style/AppearanceFoundation.Tiny.Variant"
                    tools:lines="2"
                    tools:text="@tools:sample/lorem/random" />

            </LinearLayout>

            <com.google.android.material.switchmaterial.SwitchMaterial
                android:id="@+id/selector_indicator"
                goneUnless="@{item.showSwitch}"
                isEnabled="@{item.enabled}"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="@{item.checked}"
                android:focusable="@{item.enabled}"
                android:onCheckedChanged="@{(v, c) -> item.onToggle(v, callback, c)}" />

        </LinearLayout>

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

</layout>
