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

        <variable
            name="viewModel"
            type="com.topjohnwu.magisk.ui.log.LogViewModel" />

    </data>

    <com.google.android.material.card.MaterialCardView
        style="@style/Widget.Card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardElevation="2dp">

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

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/log_header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="?attr/selectableItemBackground"
                android:onClick="@{() -> item.toggle()}"
                android:orientation="horizontal"
                android:paddingLeft="@dimen/margin_generic"
                android:paddingTop="@dimen/margin_generic_half"
                android:paddingRight="@dimen/margin_generic"
                android:paddingBottom="@dimen/margin_generic_half"
                app:layout_constraintTop_toTopOf="parent">

                <androidx.appcompat.widget.AppCompatTextView
                    style="@style/Widget.Text.Emphasize"
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:gravity="center_vertical"
                    android:text="@{item.date}"
                    android:textColor="?android:attr/textColorPrimary"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toStartOf="@+id/log_header_indicator"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    tools:text="@tools:sample/date/ddmmyy" />

                <androidx.appcompat.widget.AppCompatImageView
                    android:id="@+id/log_header_indicator"
                    style="@style/Widget.Icon"
                    android:background="@android:color/transparent"
                    android:rotation="@{item.isExpanded() ? 180 : 0}"
                    android:tint="?attr/imageColorTint"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:srcCompat="@drawable/ic_arrow"
                    tools:rotation="180" />
            </androidx.constraintlayout.widget.ConstraintLayout>

            <androidx.recyclerview.widget.RecyclerView
                gone="@{!item.isExpanded}"
                itemBinding="@{viewModel.itemBinding}"
                items="@{item.items}"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
                app:layout_constraintTop_toBottomOf="@+id/log_header"
                tools:itemCount="3"
                tools:listitem="@layout/item_superuser_log_entry" />

        </androidx.constraintlayout.widget.ConstraintLayout>

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

</layout>