<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false"
    android:theme="@style/Theme.Ecommerce_serang"
    tools:context=".ui.chat.ChatActivity">

    <!-- Top Toolbar -->
    <androidx.appcompat.widget.Toolbar
        android:id="@+id/chatToolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        android:elevation="4dp"
        app:layout_constraintTop_toTopOf="parent">

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

            <ImageButton
                android:id="@+id/btnBack"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:contentDescription="Back"
                android:src="@drawable/ic_back_24"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent" />

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/imgProfile"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_marginStart="8dp"
                android:src="@drawable/ic_person"
                app:layout_constraintStart_toEndOf="@+id/btnBack"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent" />

            <TextView
                android:id="@+id/tvStoreName"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginEnd="8dp"
                android:text="SnackEnak"
                android:textColor="@android:color/black"
                android:textSize="16sp"
                android:textStyle="bold"
                app:layout_constraintStart_toEndOf="@+id/imgProfile"
                app:layout_constraintTop_toTopOf="@+id/imgProfile"
                app:layout_constraintEnd_toStartOf="@+id/btnOptions"
                app:layout_constraintBottom_toBottomOf="parent"/>


            <ImageButton
                android:id="@+id/btnOptions"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:contentDescription="Options"
                android:src="@drawable/ic_arrow_right"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent" />

        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.appcompat.widget.Toolbar>

    <!-- Product Card -->
    <androidx.cardview.widget.CardView
        android:id="@+id/cardProduct"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        app:cardCornerRadius="8dp"
        app:cardElevation="4dp"
        app:layout_constraintTop_toBottomOf="@+id/chatToolbar">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/product_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16dp">

            <ImageView
                android:id="@+id/imgProduct"
                android:layout_width="64dp"
                android:layout_height="64dp"
                android:scaleType="centerCrop"
                android:src="@drawable/placeholder_image"
                app:layout_constraintDimensionRatio="1:1"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/tvProductName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:text="Keripik Balado"
                android:textColor="@android:color/black"
                android:textSize="18sp"
                android:textStyle="bold"
                app:layout_constraintTop_toBottomOf="@+id/imgProduct" />

            <TextView
                android:id="@+id/tvProductPrice"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="4dp"
                android:text="Rp65.000"
                android:textColor="@android:color/black"
                android:textSize="16sp"
                android:textStyle="bold"
                app:layout_constraintTop_toBottomOf="@+id/tvProductName" />

            <RatingBar
                android:id="@+id/ratingBar"
                style="?android:attr/ratingBarStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="4dp"
                android:isIndicator="true"
                android:numStars="5"
                android:rating="5.0"
                android:stepSize="0.1"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/tvProductPrice" />

            <TextView
                android:id="@+id/tvRating"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="4dp"
                android:text="5.0"
                android:textColor="#F9A825"
                android:textSize="12sp"
                app:layout_constraintBottom_toBottomOf="@+id/ratingBar"
                app:layout_constraintStart_toEndOf="@+id/ratingBar"
                app:layout_constraintTop_toTopOf="@+id/ratingBar" />

            <TextView
                android:id="@+id/tvSellerName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="4dp"
                android:text="SnackEnak"
                android:textColor="#666666"
                android:textSize="12sp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/ratingBar" />

        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.cardview.widget.CardView>

    <!-- Chat messages -->
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerChat"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:clipToPadding="false"
        android:paddingTop="8dp"
        android:paddingBottom="8dp"
        app:layout_constraintBottom_toTopOf="@+id/layoutChatInput"
        app:layout_constraintTop_toBottomOf="@+id/cardProduct" />

    <!-- Typing indicator -->
    <androidx.cardview.widget.CardView
        android:id="@+id/layoutAttachImage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:padding="4dp"
        app:layout_constraintBottom_toTopOf="@id/layoutChatInput"
        app:layout_constraintStart_toStartOf="parent">
        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="4dp">
            <ImageView
                android:id="@+id/iv_attach"
                android:layout_width="120dp"
                android:layout_height="150dp"
                android:clipToOutline="true"
                android:layout_marginStart="8dp"
                android:layout_marginVertical="8dp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                />
            <ImageButton
                android:id="@+id/btn_close_chat"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:backgroundTint="@android:color/transparent"
                android:layout_marginEnd="16dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                android:src="@drawable/ic_close_chat"
                />
        </androidx.constraintlayout.widget.ConstraintLayout>


    </androidx.cardview.widget.CardView>

    <!-- Chat input area -->
    <LinearLayout
        android:id="@+id/layoutChatInput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        android:elevation="8dp"
        android:orientation="horizontal"
        android:padding="8dp"
        app:layout_constraintBottom_toBottomOf="parent">

        <ImageButton
            android:id="@+id/btnAttachment"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center_vertical"
            android:background="?attr/selectableItemBackgroundBorderless"
            android:contentDescription="Attachment"
            android:src="@drawable/baseline_attach_file_24" />

        <EditText
            android:id="@+id/editTextMessage"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            android:layout_weight="1"
            android:background="@drawable/bg_edit_text_background"
            android:hint="Tulis pesan"
            android:fontFamily="@font/dmsans_regular"
            android:inputType="textMultiLine"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:maxLines="4"
            android:minHeight="40dp"
            android:padding="8dp" />

        <ImageButton
            android:id="@+id/btnSend"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center_vertical"
            android:background="?attr/selectableItemBackgroundBorderless"
            android:contentDescription="Send"
            android:src="@drawable/ic_sent" />
    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>