<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="6dp"
    app:cardCornerRadius="8dp"
    app:cardElevation="3dp"
    app:cardBackgroundColor="@color/cardSurface"
    app:strokeWidth="0dp">

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

        <!-- 第一列：貨道編號 | 啟用狀態 -->
        <TextView
            android:id="@+id/textSlot"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/black"
            android:textSize="15sp"
            android:textStyle="bold"
            android:text="貨道1"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toBottomOf="@+id/layoutLock" />

        <LinearLayout
            android:id="@+id/layoutLock"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center_vertical"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent">

            <TextView
                android:id="@+id/textLockStatus"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="4dp"
                android:textSize="15sp"
                android:textStyle="bold"
                android:textColor="@color/black"
                android:text="販售中" />

            <com.google.android.material.materialswitch.MaterialSwitch
                android:id="@+id/textLock"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleX="0.8"
                android:scaleY="0.8"
                app:switchPadding="0dp"
                app:thumbTint="@color/switch_thumb_selector"
                app:trackTint="@color/switch_track_selector" />
        </LinearLayout>

        <!-- 第二列：圖片區域 1:1 -->
        <ImageView
            android:id="@+id/imageProduct"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:src="@drawable/slot_no_product"
            app:layout_constraintTop_toBottomOf="@id/layoutLock"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintDimensionRatio="1:1"
            android:layout_marginTop="16dp"
            android:scaleType="centerCrop"
            android:background="#0D000000" /> <!-- 預留空間，灰色透明度5% -->

        <View
            android:id="@+id/viewProductMask"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@color/transparent_black"
            app:layout_constraintTop_toTopOf="@id/imageProduct"
            app:layout_constraintBottom_toBottomOf="@id/imageProduct"
            app:layout_constraintStart_toStartOf="@id/imageProduct"
            app:layout_constraintEnd_toEndOf="@id/imageProduct"
            android:visibility="gone" />

        <!-- 第三列：商品名稱（點擊可選擇商品） -->
        <TextView
            android:id="@+id/textProductName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="50dp"
            android:gravity="center"
            android:paddingHorizontal="0dp"
            android:paddingVertical="0dp"
            android:background="@null"
            android:textColor="@color/black"
            android:textSize="20sp"
            android:textStyle="bold"
            android:ellipsize="end"
            android:maxLines="1"
            android:text="@string/product_name"
            app:layout_constraintTop_toBottomOf="@id/imageProduct"
            android:layout_marginTop="0dp" />

        <!-- 效期顯示（無設定時隱藏；已過期由 Adapter 改紅字提示） -->
        <TextView
            android:id="@+id/textExpiry"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textSize="13sp"
            android:textColor="@color/black"
            android:maxLines="1"
            android:ellipsize="end"
            android:text=""
            android:visibility="gone"
            app:layout_constraintTop_toBottomOf="@id/textProductName"
            android:layout_marginTop="2dp" />

        <!-- 第四列：庫存數量控制列 - Minus -->
        <com.google.android.material.button.MaterialButton
            android:id="@+id/buttonCountMinus"
            style="@style/Widget.MaterialComponents.Button.OutlinedButton"
            android:layout_width="0dp"
            android:layout_height="60dp"
            android:layout_marginTop="0dp"
            android:text="−"
            android:textSize="30sp"
            app:backgroundTint="@color/background"
            android:textColor="@color/primary"
            app:layout_constraintTop_toBottomOf="@+id/textExpiry"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/textCount" />

        <!-- 庫存數量控制列 - Count -->
        <TextView
            android:id="@+id/textCount"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:gravity="center"
            android:textSize="22sp"
            android:textStyle="bold"
            android:textColor="@color/black"
            android:text="0"
            app:layout_constraintTop_toTopOf="@+id/buttonCountMinus"
            app:layout_constraintBottom_toBottomOf="@+id/buttonCountMinus"
            app:layout_constraintStart_toEndOf="@+id/buttonCountMinus"
            app:layout_constraintEnd_toStartOf="@+id/buttonCountPlus" />

        <EditText
            android:id="@+id/editCount"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:gravity="center"
            android:text="0"
            android:inputType="numberPassword"
            android:textSize="22sp"
            android:textStyle="bold"
            android:textColor="@color/black"
            android:visibility="gone"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:imeOptions="actionSend"
            android:background="@android:color/transparent"
            app:layout_constraintTop_toTopOf="@+id/buttonCountMinus"
            app:layout_constraintBottom_toBottomOf="@+id/buttonCountMinus"
            app:layout_constraintStart_toEndOf="@+id/buttonCountMinus"
            app:layout_constraintEnd_toStartOf="@+id/buttonCountPlus" />

        <!-- 庫存數量控制列 - Plus -->
        <com.google.android.material.button.MaterialButton
            android:id="@+id/buttonCountPlus"
            style="@style/Widget.MaterialComponents.Button.OutlinedButton"
            android:layout_width="0dp"
            android:layout_height="60dp"
            android:text="+"
            android:textSize="24sp"
            android:paddingHorizontal="0dp"
            app:backgroundTint="@color/background"
            android:textColor="@color/primary"
            app:layout_constraintTop_toTopOf="@+id/buttonCountMinus"
            app:layout_constraintBottom_toBottomOf="@+id/buttonCountMinus"
            app:layout_constraintStart_toEndOf="@+id/textCount"
            app:layout_constraintEnd_toEndOf="parent" />

        <!-- 第五列：按鈕 -->
        <LinearLayout
            android:id="@+id/layoutButtons"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginTop="10dp"
            app:layout_constraintTop_toBottomOf="@+id/buttonCountMinus">

            <com.google.android.material.button.MaterialButton
                android:id="@+id/textDelete"
                style="@style/Widget.MaterialComponents.Button"
                app:backgroundTint="@color/warning"
                android:textColor="@color/onWarning"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="清空貨道" />
        </LinearLayout>

        <!-- 隱藏元件，保留避免崩潰 -->
        <Button
            android:id="@+id/buttonRestocking"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="補貨"
            android:visibility="gone"
            app:layout_constraintTop_toBottomOf="@id/buttonCountMinus"
            app:layout_constraintStart_toStartOf="parent"/>

        <TextView
            android:id="@+id/textIsZg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="购物车"
            android:visibility="gone"
            app:layout_constraintTop_toBottomOf="@id/buttonRestocking"
            app:layout_constraintStart_toStartOf="parent"/>

    </androidx.constraintlayout.widget.ConstraintLayout>

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