# Product card

Thẻ sản phẩm trong chat: AI Mode và Classic có renderer riêng, cùng thứ tự ảnh, tên, giá, hành động.

## Key rules

- AI Mode: `ProductCard` từ `@scripttag/v2/ui/ProductCard.jsx`; card rộng 184px, ảnh 4 / 5 `contain`, tên tối đa 2 dòng.
- Classic: dùng `ProductCard` default export của ChatbotProductsMessage; card rộng 205px, ảnh 4 / 5 `contain`.
- AI Mode: hover chuột dùng `--chatty-shadow-card-hover`; cảm ứng giữ shadow nghỉ, nhấn xuống scale(0.98).
- Classic: tên và giá dùng `body-medium`, giá weight 600; ảnh và nút "View similar" là hai `button` riêng.
- Hai surface không chung component React; chuẩn port là `chatty-product-card` (Standard).

## Use when / Avoid

Dùng cho đối tượng có ảnh, tên và giá trong hội thoại. Admin chưa có product card riêng trong code. Khi dữ liệu sản phẩm lỗi, dùng text thay vì card rỗng.

### Use instead

| Component | Use when |
| --- | --- |
| `ProductCard` | AI Mode: caller truyền `product`, `onOpen` và `action`. |
| `ProductCard` | Classic: default export nhận `product`, `removedBubblingEvents`, `isFromFindSimilar`, `wizard`. |
| `AddToCartButton` | AI Mode: nút thêm vào giỏ trình bày sẵn, caller sở hữu lời gọi giỏ hàng. |

## Live preview

Example (Standard) — Hàng card layout inset: giá so sánh kèm badge giảm giá secondary "−25%" và sao lẻ, card đã chọn có pill Selected, card hết hàng; nút thẳng hàng ở đáy.

```html
<chatty-product-card
  style="align-self: stretch"
  price="$24"
  compare-at-price="$32"
  label="View product Canvas tote bag"
>
  <chatty-image
    slot="media"
    src="/fixtures/tote.svg"
    alt=""
    ratio="4 / 5"
    fit="contain"
  ></chatty-image>
  Canvas tote bag
  <span slot="rating" style="display: inline-flex; align-items: center; gap: 4px">
    <chatty-rating
      readonly
      value="4.6"
      label="Rated 4.6 out of 5"
      style="--chatty-rating-size: 16px"
    ></chatty-rating>
    <b>4.6</b> (128)
  </span>
  <chatty-badge slot="badge" variant="secondary" size="sm">−25%</chatty-badge>
  <chatty-button slot="action" size="sm">Add to cart</chatty-button>
</chatty-product-card>
<chatty-product-card
  style="align-self: stretch"
  price="$18"
  selected
  label="View product Ceramic mug"
>
  <chatty-image
    slot="media"
    src="/fixtures/mug.svg"
    alt=""
    ratio="4 / 5"
    fit="contain"
  ></chatty-image>
  <chatty-badge slot="overlay" variant="primary">
    <svg
      width="14"
      height="14"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      stroke-width="2.5"
      aria-hidden="true"
      style="vertical-align: -2px"
    >
      <path d="m5 12 5 5 9-10" />
    </svg>
    Selected
  </chatty-badge>
  Ceramic mug
  <chatty-button slot="action" size="sm">Add to cart</chatty-button>
</chatty-product-card>
<chatty-product-card style="align-self: stretch" price="$28" label="View product Wool cap">
  <chatty-image
    slot="media"
    src="/fixtures/cap.svg"
    alt=""
    ratio="4 / 5"
    fit="contain"
  ></chatty-image>
  Wool cap
  <chatty-button slot="action" size="sm" disabled>Sold out</chatty-button>
</chatty-product-card>
```

Example (Standard) — Đang thêm giỏ kèm lỗi ở footer, và skeleton cùng hộp card.

```html
<chatty-product-card
  style="align-self: stretch"
  price="$24"
  label="View product Canvas tote bag"
>
  <chatty-image
    slot="media"
    src="/fixtures/tote.svg"
    alt=""
    ratio="4 / 5"
    fit="contain"
  ></chatty-image>
  Canvas tote bag
  <chatty-button slot="action" size="sm" loading>Adding</chatty-button>
  <span slot="footer" role="alert" style="color: var(--chatty-color-critical); font-size: 14px"
    >Could not add to cart</span
  >
</chatty-product-card>
<chatty-product-card style="align-self: stretch" skeleton></chatty-product-card>
```

Example (Standard) — Layout flush của Classic: ảnh tràn mép dưới góc card, khối chữ có padding, badge giảm giá, card hết hàng.

```html
<chatty-product-card
  layout="flush"
  price="$24"
  compare-at-price="$32"
  label="View product Canvas tote bag"
>
  <chatty-image
    slot="media"
    src="/fixtures/tote.svg"
    alt=""
    ratio="4 / 5"
    fit="contain"
  ></chatty-image>
  Canvas tote bag
  <span slot="rating" style="display: inline-flex; align-items: center; gap: 4px">
    <chatty-rating
      readonly
      value="4.6"
      label="Rated 4.6 out of 5"
      style="--chatty-rating-size: 16px"
    ></chatty-rating>
    <b>4.6</b> (128)
  </span>
  <chatty-badge slot="badge" variant="secondary" size="sm">−25%</chatty-badge>
  <chatty-button slot="action">Add to cart</chatty-button>
</chatty-product-card>
<chatty-product-card
  style="align-self: stretch"
  layout="flush"
  price="$28"
  label="View product Wool cap"
>
  <chatty-image
    slot="media"
    src="/fixtures/cap.svg"
    alt=""
    ratio="4 / 5"
    fit="contain"
  ></chatty-image>
  Wool cap
  <chatty-button slot="action" disabled>Sold out</chatty-button>
</chatty-product-card>
```

Example (Standard) — Đang thêm giỏ kèm lỗi ở footer, và skeleton cùng hộp card.

```html
<chatty-product-card
  style="align-self: stretch"
  price="$24"
  label="View product Canvas tote bag"
>
  <chatty-image
    slot="media"
    src="/fixtures/tote.svg"
    alt=""
    ratio="4 / 5"
    fit="contain"
  ></chatty-image>
  Canvas tote bag
  <chatty-button slot="action" size="sm" loading>Adding</chatty-button>
  <span slot="footer" role="alert" style="color: var(--chatty-color-critical); font-size: 14px"
    >Could not add to cart</span
  >
</chatty-product-card>
<chatty-product-card style="align-self: stretch" skeleton></chatty-product-card>
```

Example (Current (React), being replaced) — Card đã tải có giá và giá so sánh, card đã chọn, hết hàng và skeleton.

```jsx
import React, {useState} from 'react';
import {ChatProductCarousel} from '@scripttag/v2/views/chat/ChatProductCarousel.jsx';
import {ChatNavigationContext} from '@scripttag/v2/views/chat/chatNavigationContext.js';
import {selectionStore} from '@scripttag/v2/stores/selectionStore.js';
import {ProductCard} from '@scripttag/v2/ui/ProductCard.jsx';
import ChatbotProductsMessage from '@scripttag/v1/Parts/InsertProduct/ChatbotProductsMessage/ChatbotProductsMessage.js';
import {
  WidgetChatStateProvider,
  createWidgetChatStateStore
} from '@scripttag/v1/WidgetChatState.js';
import {t} from '@scripttag/v2/helpers/i18n.js';
// PercentOffBadge's screen-reader phrase uses this class on both surfaces; the widget roots load it,
// the story does not mount them.
import '@scripttag/v1/Parts/InsertProduct/offerA11y.scss';

const variant = id => [`Default Title: ${id}`];
const products = [
  {
    productId: 'gid://shopify/Product/101',
    title: 'Canvas tote bag',
    url: 'https://shop.example/products/canvas-tote',
    image: '/fixtures/tote.svg',
    imageAlt: 'Canvas tote bag',
    availableForSale: true,
    currency: 'USD',
    prices: ['$24.00'],
    compareAtPrices: ['$32.00'],
    variantOptions: variant('1001')
  },
  {
    productId: 'gid://shopify/Product/102',
    title: 'Ceramic mug',
    url: 'https://shop.example/products/ceramic-mug',
    image: '/fixtures/mug.svg',
    imageAlt: 'Ceramic mug',
    availableForSale: true,
    currency: 'USD',
    prices: ['$18.00'],
    compareAtPrices: [],
    variantOptions: variant('1002')
  },
  {
    productId: 'gid://shopify/Product/103',
    title: 'Wool cap',
    url: 'https://shop.example/products/wool-cap',
    image: '/fixtures/cap.svg',
    imageAlt: 'Wool cap',
    availableForSale: false,
    currency: 'USD',
    prices: ['$28.00'],
    compareAtPrices: [],
    variantOptions: variant('1003')
  }
];

function AiCatalogue() {
  selectionStore.setState({
    selected: [{handle: 'ceramic-mug', title: 'Ceramic mug', image: '/fixtures/mug.svg'}]
  });
  return (
    <div className="specimen-grid" style={{minWidth: 0}}>
      <section style={{minWidth: 0}}>
        <h4>Carousel: loaded, selected, sold out</h4>
        <ChatNavigationContext.Provider value>
          <ChatProductCarousel messageId="guide-carousel" products={products} />
        </ChatNavigationContext.Provider>
      </section>
      <section style={{minWidth: 0}}>
        <h4>Skeleton</h4>
        <div style={{width: 184}}>
          <ProductCard skeleton />
        </div>
      </section>
    </div>
  );
}

// Classic reads its translator from the widget chat state, whose default echoes the phrase without
// interpolating {{value}}; the live widget installs the real one.
const classicState = createWidgetChatStateStore({
  i18n: Object.assign((...args) => t(...args), {locale: 'en'})
});

function ClassicCatalogue() {
  return (
    <div className="specimen-grid" style={{minWidth: 0}}>
      <section style={{minWidth: 0}}>
        <h4>Compare-at price, in stock, sold out</h4>
        <div style={{width: 360, maxWidth: '100%'}}>
          <WidgetChatStateProvider store={classicState}>
            <ChatbotProductsMessage products={products} messageId="guide-classic" />
          </WidgetChatStateProvider>
        </div>
      </section>
    </div>
  );
}

export function Catalogue() {
  const [surface, setSurface] = useState(null);
  const ref = node => {
    const found = node?.closest('[data-surface]')?.dataset.surface;
    if (found && found !== surface) setSurface(found);
  };
  return (
    <div ref={ref} style={{minWidth: 0, width: '100%'}}>
      {surface === 'classic' ? <ClassicCatalogue /> : surface ? <AiCatalogue /> : null}
    </div>
  );
}
```

Example (Current (React), being replaced) — Card Classic có giá so sánh, nút thêm vào giỏ bị vô hiệu và thông báo lỗi.

```jsx
import React, {useState} from 'react';
import {ChatProductCarousel} from '@scripttag/v2/views/chat/ChatProductCarousel.jsx';
import {ChatNavigationContext} from '@scripttag/v2/views/chat/chatNavigationContext.js';
import {selectionStore} from '@scripttag/v2/stores/selectionStore.js';
import {ProductCard} from '@scripttag/v2/ui/ProductCard.jsx';
import ChatbotProductsMessage from '@scripttag/v1/Parts/InsertProduct/ChatbotProductsMessage/ChatbotProductsMessage.js';
import {
  WidgetChatStateProvider,
  createWidgetChatStateStore
} from '@scripttag/v1/WidgetChatState.js';
import {t} from '@scripttag/v2/helpers/i18n.js';
// PercentOffBadge's screen-reader phrase uses this class on both surfaces; the widget roots load it,
// the story does not mount them.
import '@scripttag/v1/Parts/InsertProduct/offerA11y.scss';

const variant = id => [`Default Title: ${id}`];
const products = [
  {
    productId: 'gid://shopify/Product/101',
    title: 'Canvas tote bag',
    url: 'https://shop.example/products/canvas-tote',
    image: '/fixtures/tote.svg',
    imageAlt: 'Canvas tote bag',
    availableForSale: true,
    currency: 'USD',
    prices: ['$24.00'],
    compareAtPrices: ['$32.00'],
    variantOptions: variant('1001')
  },
  {
    productId: 'gid://shopify/Product/102',
    title: 'Ceramic mug',
    url: 'https://shop.example/products/ceramic-mug',
    image: '/fixtures/mug.svg',
    imageAlt: 'Ceramic mug',
    availableForSale: true,
    currency: 'USD',
    prices: ['$18.00'],
    compareAtPrices: [],
    variantOptions: variant('1002')
  },
  {
    productId: 'gid://shopify/Product/103',
    title: 'Wool cap',
    url: 'https://shop.example/products/wool-cap',
    image: '/fixtures/cap.svg',
    imageAlt: 'Wool cap',
    availableForSale: false,
    currency: 'USD',
    prices: ['$28.00'],
    compareAtPrices: [],
    variantOptions: variant('1003')
  }
];

function AiCatalogue() {
  selectionStore.setState({
    selected: [{handle: 'ceramic-mug', title: 'Ceramic mug', image: '/fixtures/mug.svg'}]
  });
  return (
    <div className="specimen-grid" style={{minWidth: 0}}>
      <section style={{minWidth: 0}}>
        <h4>Carousel: loaded, selected, sold out</h4>
        <ChatNavigationContext.Provider value>
          <ChatProductCarousel messageId="guide-carousel" products={products} />
        </ChatNavigationContext.Provider>
      </section>
      <section style={{minWidth: 0}}>
        <h4>Skeleton</h4>
        <div style={{width: 184}}>
          <ProductCard skeleton />
        </div>
      </section>
    </div>
  );
}

// Classic reads its translator from the widget chat state, whose default echoes the phrase without
// interpolating {{value}}; the live widget installs the real one.
const classicState = createWidgetChatStateStore({
  i18n: Object.assign((...args) => t(...args), {locale: 'en'})
});

function ClassicCatalogue() {
  return (
    <div className="specimen-grid" style={{minWidth: 0}}>
      <section style={{minWidth: 0}}>
        <h4>Compare-at price, in stock, sold out</h4>
        <div style={{width: 360, maxWidth: '100%'}}>
          <WidgetChatStateProvider store={classicState}>
            <ChatbotProductsMessage products={products} messageId="guide-classic" />
          </WidgetChatStateProvider>
        </div>
      </section>
    </div>
  );
}

export function Catalogue() {
  const [surface, setSurface] = useState(null);
  const ref = node => {
    const found = node?.closest('[data-surface]')?.dataset.surface;
    if (found && found !== surface) setSurface(found);
  };
  return (
    <div ref={ref} style={{minWidth: 0, width: '100%'}}>
      {surface === 'classic' ? <ClassicCatalogue /> : surface ? <AiCatalogue /> : null}
    </div>
  );
}
```

## Standard

Example (Standard) — Thread AI Mode có năm sản phẩm, rating, giá so sánh và trạng thái sold out; arrows desktop, dots touch.

```html
<style>
  .product-thread {
    box-sizing: border-box;
    width: min(100%, var(--chatty-layout-panel-chat));
    margin-inline: auto;
    padding: var(--chatty-layout-inset-desktop);
    background: var(--chatty-color-bg-surface);
  }
  .product-thread.classic {
    width: min(100%, var(--chatty-layout-panel-classic));
    padding: 8px 12px 4px;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-gutter: stable;
  }
  @media (max-width: 899px) {
    .product-thread {
      width: 100%;
      padding: 24px var(--chatty-layout-inset-mobile);
    }
  }
</style>
<section class="product-thread" aria-label="Recommended products">
  <chatty-product-row surface="ai-mode">
    <chatty-product-card
      layout="inset"
      price="$24"
      compare-at-price="$32"
      label="View Canvas tote bag"
    >
      <chatty-image
        slot="media"
        src="/fixtures/tote.svg"
        alt=""
        ratio="4 / 5"
        fit="contain"
      ></chatty-image>
      Canvas tote bag
      <span slot="rating" style="display:inline-flex;align-items:center;gap:4px">
        <chatty-rating
          readonly
          value="4.6"
          label="Rated 4.6 out of 5"
          style="--chatty-rating-size:16px"
        ></chatty-rating>
        <b>4.6</b> (128)
      </span>
      <chatty-badge slot="badge" variant="secondary" size="sm">−25%</chatty-badge>
      <chatty-button slot="action" size="sm">Add to cart</chatty-button>
    </chatty-product-card>
    <chatty-product-card layout="inset" price="$18" label="View Ceramic mug">
      <chatty-image
        slot="media"
        src="/fixtures/mug.svg"
        alt=""
        ratio="4 / 5"
        fit="contain"
      ></chatty-image>
      Ceramic mug
      <span slot="rating" style="display:inline-flex;align-items:center;gap:4px">
        <chatty-rating
          readonly
          value="4.8"
          label="Rated 4.8 out of 5"
          style="--chatty-rating-size:16px"
        ></chatty-rating>
        <b>4.8</b> (54)
      </span>
      <chatty-button slot="action" size="sm">Add to cart</chatty-button>
    </chatty-product-card>
    <chatty-product-card layout="inset" price="$28" label="View Wool cap">
      <chatty-image
        slot="media"
        src="/fixtures/cap.svg"
        alt=""
        ratio="4 / 5"
        fit="contain"
      ></chatty-image>
      Wool cap
      <chatty-button slot="action" size="sm" disabled>Sold out</chatty-button>
    </chatty-product-card>
    <chatty-product-card layout="inset" price="$24" label="View Natural canvas tote bag large">
      <chatty-image
        slot="media"
        src="/fixtures/tote.svg"
        alt=""
        ratio="4 / 5"
        fit="contain"
      ></chatty-image>
      Natural canvas tote bag large
      <chatty-button slot="action" size="sm">Add to cart</chatty-button>
    </chatty-product-card>
    <chatty-product-card layout="inset" price="$24" label="View Everyday ceramic mug">
      <chatty-image
        slot="media"
        src="/fixtures/mug.svg"
        alt=""
        ratio="4 / 5"
        fit="contain"
      ></chatty-image>
      Everyday ceramic mug
      <chatty-button slot="action" size="sm">Add to cart</chatty-button>
    </chatty-product-card>
  </chatty-product-row>
</section>
```

Example (Standard) — Panel Classic có năm sản phẩm; arrows desktop, dots touch. Classic dark: Standard dùng nền tối; widget đang ship khối trắng.

```html
<style>
  .product-thread {
    box-sizing: border-box;
    width: min(100%, var(--chatty-layout-panel-chat));
    margin-inline: auto;
    padding: var(--chatty-layout-inset-desktop);
    background: var(--chatty-color-bg-surface);
  }
  .product-thread.classic {
    width: min(100%, var(--chatty-layout-panel-classic));
    padding: 8px 12px 4px;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-gutter: stable;
  }
  @media (max-width: 899px) {
    .product-thread {
      width: 100%;
      padding: 24px var(--chatty-layout-inset-mobile);
    }
  }
</style>
<section class="product-thread classic" aria-label="Recommended products">
  <chatty-product-row surface="classic">
    <chatty-product-card
      layout="flush"
      price="$24"
      compare-at-price="$32"
      label="View Canvas tote bag"
    >
      <chatty-image
        slot="media"
        src="/fixtures/tote.svg"
        alt=""
        ratio="4 / 5"
        fit="contain"
      ></chatty-image>
      Canvas tote bag
      <span slot="rating" style="display:inline-flex;align-items:center;gap:4px">
        <chatty-rating
          readonly
          value="4.6"
          label="Rated 4.6 out of 5"
          style="--chatty-rating-size:16px"
        ></chatty-rating>
        <b>4.6</b> (128)
      </span>
      <chatty-badge slot="badge" variant="secondary" size="sm">−25%</chatty-badge>
      <chatty-button slot="action" size="sm">Add to cart</chatty-button>
    </chatty-product-card>
    <chatty-product-card layout="flush" price="$18" label="View Ceramic mug">
      <chatty-image
        slot="media"
        src="/fixtures/mug.svg"
        alt=""
        ratio="4 / 5"
        fit="contain"
      ></chatty-image>
      Ceramic mug
      <span slot="rating" style="display:inline-flex;align-items:center;gap:4px">
        <chatty-rating
          readonly
          value="4.8"
          label="Rated 4.8 out of 5"
          style="--chatty-rating-size:16px"
        ></chatty-rating>
        <b>4.8</b> (54)
      </span>
      <chatty-button slot="action" size="sm">Add to cart</chatty-button>
    </chatty-product-card>
    <chatty-product-card layout="flush" price="$28" label="View Wool cap">
      <chatty-image
        slot="media"
        src="/fixtures/cap.svg"
        alt=""
        ratio="4 / 5"
        fit="contain"
      ></chatty-image>
      Wool cap
      <chatty-button slot="action" size="sm" disabled>Sold out</chatty-button>
    </chatty-product-card>
    <chatty-product-card layout="flush" price="$24" label="View Natural canvas tote bag large">
      <chatty-image
        slot="media"
        src="/fixtures/tote.svg"
        alt=""
        ratio="4 / 5"
        fit="contain"
      ></chatty-image>
      Natural canvas tote bag large
      <chatty-button slot="action" size="sm">Add to cart</chatty-button>
    </chatty-product-card>
    <chatty-product-card layout="flush" price="$24" label="View Everyday ceramic mug">
      <chatty-image
        slot="media"
        src="/fixtures/mug.svg"
        alt=""
        ratio="4 / 5"
        fit="contain"
      ></chatty-image>
      Everyday ceramic mug
      <chatty-button slot="action" size="sm">Add to cart</chatty-button>
    </chatty-product-card>
  </chatty-product-row>
</section>
```

Prototype Product card và style đi kèm là chuẩn: package được port 1:1 từ prototype, và manifest phần tử được sinh từ cùng nguồn. Ảnh, tên, đánh giá, badge giảm giá và nút đi vào qua slot (`chatty-image`, `chatty-rating`, `chatty-badge`, `chatty-button`); giá truyền dạng chuỗi đã format. Classic dùng `layout="flush"`. Chưa surface nào dùng element thật; các mục AI Mode và Classic bên dưới mô tả React đang chạy.

### Element

| Element | Module |
| --- | --- |
| `chatty-product-card` | @avada/chatty-ui/elements/product-card.js |

### API

`chatty-product-row` (cùng module product-card.js) bọc các card trong default slot; ẩn scrollbar; fine pointer desktop dùng prev/next (AI Mode hiện khi hover hoặc focus trong hàng; Classic luôn hiện khi cuộn tiếp được), touch hoặc mobile dùng dots khi tràn. `surface="classic"` trượt một card + gap 8px, AI Mode trượt 80% viewport; arrow biến mất ở đầu/cuối, RTL đảo hướng, reduced-motion cuộn ngay. `strings` đặt nhãn previous/next. Arrow nhận focus; ArrowLeft/ArrowRight và Home/End vẫn cuộn hàng. Hàng giữ title hai dòng để giá thẳng hàng; card ngoài hàng chỉ chiếm số dòng title thực tế.

| Kind | Name | Type | Default | Description |
| --- | --- | --- | --- | --- |
| attribute | `price` | string | `''` | Giá đã format, ví dụ `$24`; rỗng thì ẩn hàng giá. |
| attribute | `compare-at-price` | string | `''` | Giá so sánh đã format, gạch ngang trước giá. |
| attribute | `label` | string | `''` | Tên truy cập của vùng mở chi tiết; rỗng thì lấy chữ bên trong. |
| attribute | `layout` | inset, flush | `'inset'` | inset (AI Mode): card có padding, ảnh bo góc; flush (Classic): ảnh tràn mép dưới góc card, chữ nằm trong khối có padding. |
| attribute | `selected` | boolean | `false` | Viền màu accent khi sản phẩm đã chọn; đi kèm pill ở slot overlay. |
| attribute | `skeleton` | boolean | `false` | Render khung chờ cùng hộp với card đã tải, aria-hidden. |
| event | `chatty-open` | CustomEvent<{}> | – | Bấm, Enter hoặc Space trên vùng mở chi tiết; phím trên action không kích hoạt. |
| slot | default | – | – | Tên sản phẩm, bị kẹp dòng. |
| slot | `media` | – | – | Ảnh sản phẩm, thường là `chatty-image` với fit contain. |
| slot | `overlay` | – | – | Nội dung nằm trên ảnh, ví dụ pill đã chọn. |
| slot | `rating` | – | – | Đánh giá sao, thường là `chatty-rating` readonly. |
| slot | `badge` | – | – | Dấu hiệu giảm giá cạnh giá, thường là `chatty-badge variant="secondary" size="sm"`. |
| slot | `action` | – | – | Action dưới vùng mở chi tiết, thường là nút thêm vào giỏ. |
| slot | `footer` | – | – | Hàng cuối cho thông báo lỗi thêm giỏ. |
| part | `base` | – | – | Khung card. |
| part | `open` | – | – | Vùng mở chi tiết (role button). |
| part | `media` | – | – | Vùng chứa ảnh. |
| part | `name` | – | – | Vùng chứa tên. |
| part | `price` | – | – | Hàng giá. |
| css-property | `--chatty-product-card-radius` | – | – | Bo góc card. |
| css-property | `--chatty-product-card-background` | – | – | Nền card. |
| css-property | `--chatty-product-card-media-radius` | – | – | Bo góc ảnh. |

## AI Mode

### Import / element

| Component / element | Import / file | Scope root |
| --- | --- | --- |
| `ProductCard` | @scripttag/v2/ui/ProductCard.jsx | .chatty-ai-mode[data-theme] |
| `AddToCartButton` | @scripttag/v2/ui/ProductCard.jsx | .chatty-ai-mode[data-theme] |

### Anatomy

| Part | Element |
| --- | --- |
| 1 | Vùng mở chi tiết `chatty-product-card-link` với `role="button"` và `tabIndex={0}`. |
| 2 | Media `chatty-product-card-media` chứa ảnh và slot `overlay`. |
| 3 | Tên `chatty-product-card-name` kẹp 2 dòng bằng `chatty-clamp-2`. |
| 4 | Đánh giá sao `chatty-product-card-rating`, chỉ khi có dữ liệu. |
| 5 | Hàng giá `chatty-product-card-price` với giá so sánh `chatty-price-compare` rồi giá. |
| 6 | Slot `action` dưới vùng mở chi tiết, chỉ hiện khi `canShowAction`. |
| 7 | Slot `footer` cuối card cho thông báo lỗi. |

### Placement / order

| Context | Order |
| --- | --- |
| Carousel chat | Mỗi card rộng 184px, `flex: 0 0 184px`, theo hàng trong track; width do carousel đặt, không do card. |
| Trong card | Ảnh, tên, đánh giá, giá, rồi `action`, rồi `footer`; `overlay` nằm trên ảnh. |

### Props

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `product` | object | id, handle, name, img, imageAlt, price, compareAtPrice, pricing, availableForSale | Caller | Trường đã sẵn sàng hiển thị; `id` dùng tra đánh giá. |
| `onOpen` | Function | Handler nhận trigger của card | Caller | Gọi khi bấm hoặc nhấn Enter / Space trên vùng chi tiết. |
| `action` | any | Node, thường là AddToCartButton | Caller | Render dưới khối thông tin. |
| `footer` | any | Node | Caller | Render cuối cùng, dưới action. |
| `overlay` | any | Node | Caller | Render trên ảnh. |
| `selected` | boolean | true / false | false | Thêm class `is-selected`. |
| `index` | number | Vị trí trong danh sách | 0 | Đặt `--i` cho stagger khi vào. |
| `cardRef` | object | ref | Caller | Chuyển tới root để fly-to-cart tìm ảnh. |
| `className` | string | CSS classes | Caller | Gộp vào root. |
| `skeleton` | boolean | true / false | false | Render placeholder cùng hộp với card đã tải. |

### Sizes

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Card | Theo nội dung | 10px | 8px | 20px (`--radius-card`) | Không có chữ | Cả vùng chi tiết | width 184px do carousel đặt |
| Media | Theo aspect-ratio 4 / 5 | Không khai báo | Không khai báo | 14px | Không có chữ | Thuộc vùng chi tiết | Không override theo viewport |
| Tên | Tối thiểu 2 dòng của line-height | Không khai báo | Không khai báo | Không khai báo | `body-medium`: Derived(15px = type(body-medium, desktop, size)) / Derived(22px = type(body-medium, desktop, line)) desktop, Derived(17px = type(body-medium, mobile, size)) / Derived(24px = type(body-medium, mobile, line)) mobile; weight 400 | Thuộc vùng chi tiết | JS .is-mobile khi width ≤899px; hoặc media (hover: none) and (pointer: coarse), kể cả landscape >899px |
| Giá | Theo line-height của role | Không khai báo | 6px | Không khai báo | `body-medium`: Derived(15px = type(body-medium, desktop, size)) / Derived(22px = type(body-medium, desktop, line)) desktop, Derived(17px = type(body-medium, mobile, size)) / Derived(24px = type(body-medium, mobile, line)) mobile; weight 600 | Thuộc vùng chi tiết | Cùng breakpoint với Tên |
| Giá so sánh | Theo line-height của role | Không khai báo | Không khai báo | Không khai báo | `body-small`: Derived(14px = type(body-small, desktop, size)) / Derived(20px = type(body-small, desktop, line)) desktop, Derived(15px = type(body-small, mobile, size)) / Derived(22px = type(body-small, mobile, line)) mobile; gạch ngang | Thuộc vùng chi tiết | Cùng breakpoint với Tên |
| Action | Theo nút `chatty-btn` | padding-block 6px | Không khai báo | Theo nút | `button-label`: Derived(14px = type(button-label, desktop, size)) / Derived(18px = type(button-label, desktop, line)) desktop, Derived(17px = type(button-label, mobile, size)) / Derived(24px = type(button-label, mobile, line)) mobile | Native box, `chatty-btn--block` | Mobile đổi sang `chip-label`: Derived(14px = type(chip-label, desktop, size)) / Derived(18px = type(chip-label, desktop, line)) |
| Pill chọn | height/min-height 28px | var(--chatty-space-300) | Theo token | 16px | `chip-label`: Derived(14px = type(chip-label, desktop, size)) / Derived(18px = type(chip-label, desktop, line)) | Mobile mở rộng tới 44px bằng `::before` inset -8px | Desktop hiện khi hover; mobile hiện sẵn |
| Skeleton | Action 32px | Không khai báo | Không khai báo | Action 10px; bone 6px | Không có chữ | Không tương tác | Giá rộng 45% và cao 1.8em |

### Tokens

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Nền card | `--bg-elevated` | #fbfaf7, kèm `--shadow-1` | Theo `chatty-surface` |
| Nền khi hover | `--fill-hover` | Không đổi nền; dùng shadow | rgba(255,255,255,0.14) |
| Shadow hover | `--chatty-shadow-card-hover` | 0 0 0 1px rgb(0 0 0 / 0.06), 0 2px 4px rgb(0 0 0 / 0.06), 0 4px 12px -4px rgb(0 0 0 / 0.18) | 0 0 0 1px rgb(255 255 255 / 0.12), 0 2px 4px rgb(0 0 0 / 0.3), 0 4px 12px -4px rgb(0 0 0 / 0.54) |
| Tên | `--vib-1` | rgba(20,19,24,0.94) | rgba(255,255,255,0.96) |
| Giá so sánh | `--vib-3` | rgba(20,19,24,0.62) | rgba(255,255,255,0.62) |
| Viền khi đã chọn | `--accent` | Merchant --faqsBtnPopupColor, fallback #8b7be8 | Same definition |
| Vòng focus | `--chatty-color-border-focus` | `--vib-1`: rgba(20,19,24,0.94) | `--vib-1`: rgba(255,255,255,0.96) |
| Lỗi | `--danger` | #ef4444 | #ef4444 |
| Chuyển động hover | `--chatty-motion-duration-250` | 250ms cho transform; 150ms cho shadow và nền | Same |

### States

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Rest | Mặc định | `box-shadow: var(--chatty-shadow-1)`. | Không thêm ARIA |
| Hover | pointer có hover và pointer fine | translateY(-2px); `--chatty-shadow-card-hover`; ảnh scale(1.03); tên gạch chân. | Không thêm ARIA |
| Focus-within | Focus trong card | Touch hoặc mobile dùng `--chatty-shadow-1` và không transform. | Không thêm ARIA |
| Focus-visible | keyboard trên vùng chi tiết | outline 2px solid `--chatty-color-border-focus`, offset 2px. | `role="button"`, `tabIndex={0}` |
| Touch active | hover: none hoặc pointer: coarse | scale(0.98); nền `color-mix(in srgb, currentColor 12%, transparent)`; thời gian `--chatty-motion-duration-100`. | Không thêm ARIA |
| Selected | `selected` true | `border-color` là `--accent`. | Class `is-selected` |
| Skeleton | `skeleton` true | Class `chatty-product-card--skeleton`; không pointer, không animation, cùng hộp card. | `aria-hidden="true"` |
| In stock / sold out | `availableForSale` true / false | Thêm class `is-in-stock` hoặc `is-sold-out`; nút action do caller vô hiệu bằng `soldOut`. | Native `disabled` trên nút action |
| Adding | status ADDING của `AddToCartButton` | Class `is-loading`; nút vô hiệu để chặn bấm lặp. | `aria-busy` |
| Reduced motion | `prefers-reduced-motion: reduce` | `animation: none`; transform none; ảnh không phóng khi hover. | Không thêm ARIA |

### Behaviour

| Interaction | Result |
| --- | --- |
| Mở chi tiết | Bấm, hoặc Enter / Space khi focus nằm trên chính vùng chi tiết, gọi `onOpen`. |
| Hiện action | Slot `action` chỉ render khi `canAddToCart` trả true theo `pricing`, khách ẩn giá và `legacyPricing`. |
| Tên dài | Kẹp 2 dòng; chiều cao tối thiểu bằng 2 line-height của role. |
| Hết hàng | Card chỉ đặt class theo `availableForSale`; caller sở hữu nút vô hiệu và tra cứu tồn kho khi chưa biết. |
| Lỗi thêm giỏ | Caller truyền thông báo vào `footer`; class `chatty-product-card-error` dùng `--danger` và role `body-small`. |

### Copy

| String | i18n key | Where |
| --- | --- | --- |
| View product | View product | `aria-label` vùng chi tiết, ghép với tên |
| Added to cart | Added to cart | `successLabel` của `AddToCartFeedback` |
| Add to cart | Add to cart | Nhãn nút khi idle |
| Sold out | Sold out | Nhãn nút khi hết hàng |
| Added | Added | Nhãn trạng thái đã thêm |
| Try again | Try again | Nhãn trạng thái lỗi |
| Tên, giá | Caller-owned | Dữ liệu `product`, không có chuỗi mặc định |

### Source

| File | Evidence |
| --- | --- |
|  | API, anatomy và action |
|  | Kích thước, trạng thái và theme |
|  | Media canvas và hover |

## Classic

### Import / element

| Component / element | Import / file | Scope root |
| --- | --- | --- |
| `ProductCard` | import ProductCard from '@scripttag/v1/Parts/InsertProduct/ChatbotProductsMessage/ProductCard.js'; | .Avada-Faqs_Popup[data-theme] .Avada-Faq_ChatbotProduct-Message_Card |

### Anatomy

| Part | Element |
| --- | --- |
| 1 | Root `Card` với class `Avada-Faq_ChatbotProduct-Message_Card`. |
| 2 | Vùng ảnh `Avada-ProductCard-ImageContainer` với `button` mở chi tiết. |
| 3 | Nút overlay "View similar", anh em của nút ảnh để không lồng button. |
| 4 | Khối thông tin `Avada-ProductCard-Info`. |
| 5 | Tên là thẻ `a` mở tab mới. |
| 6 | Đánh giá sao, chỉ khi có dữ liệu. |
| 7 | Giá qua `WithheldPrice`, kèm giá so sánh khi có. |
| 8 | Nút `Button` thêm vào giỏ trong tooltip wrapper. |
| 9 | Thông báo lỗi `role="alert"`. |

### Placement / order

| Context | Order |
| --- | --- |
| Carousel chat | ChatbotProductsMessage render một `ProductCard` cho mỗi sản phẩm; mỗi card rộng 205px, `flex: 0 0 205px`. |
| Trong card | Ảnh (overlay "View similar" ở góc phải dưới), tên, đánh giá, giá, rồi nút thêm vào giỏ; lỗi nằm cuối. |

### Props

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `product` | object | imageUrl, title, price, comparePrice, link, productId, availableForSale | Caller | Card đọc widget và store của Classic. |
| `removedBubblingEvents` | object | Handlers | Caller | Spread vào `Card`. |
| `isFromFindSimilar` | boolean | true / false | Caller | Ghi nhận hoạt động khi bấm tên từ danh sách tương tự. |
| `wizard` | boolean | true / false | false | Xem trước trong wizard: nút còn hiện nhưng bấm không làm gì. |
| `availableForSale` | boolean | true / false | false | Quyết định nút thêm vào giỏ và tooltip hết hàng. |

### Sizes

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Card | height auto | Không khai báo | Không khai báo | 14px | Không có chữ | Theo phần tử con | width 205px; border 1px; margin-bottom 2px |
| Media | Theo aspect-ratio 4 / 5 | Không khai báo | Không khai báo | 14px | Không có chữ | Nút ảnh phủ kín vùng ảnh | Không override theo viewport |
| Overlay | Theo nội dung | 6px; hover 6px 12px | 6px khi hover | 10px | `button-label`: Derived(14px = type(button-label, desktop, size)) / Derived(18px = type(button-label, desktop, line)) desktop, Derived(17px = type(button-label, mobile, size)) / Derived(24px = type(button-label, mobile, line)) mobile; icon 18px | Native box | Chữ mở rộng tới max-width 120px khi hover hoặc focus-visible |
| Thông tin | Theo nội dung | 10px 12px 12px | 10px | Không khai báo | Không có chữ | Không tương tác | Không override theo viewport |
| Tên | Kẹp 2 dòng | Không khai báo | 4px | Không khai báo | `body-medium`: Derived(15px = type(body-medium, desktop, size)) / Derived(22px = type(body-medium, desktop, line)) desktop, Derived(17px = type(body-medium, mobile, size)) / Derived(24px = type(body-medium, mobile, line)) mobile; weight 400 | Thẻ `a` theo dòng chữ | JS mobile class; `mobileMaxWidth` 899px |
| Giá | min-height 20.02px | Không khai báo | 4px 6px | Không khai báo | `body-medium`: Derived(15px = type(body-medium, desktop, size)) / Derived(22px = type(body-medium, desktop, line)) desktop, Derived(17px = type(body-medium, mobile, size)) / Derived(24px = type(body-medium, mobile, line)) mobile; weight 600 | Không tương tác | Cùng breakpoint với Tên |
| Giá so sánh | Theo line-height của role | margin-right 8px | Không khai báo | Không khai báo | `body-small`: Derived(14px = type(body-small, desktop, size)) / Derived(20px = type(body-small, desktop, line)) desktop, Derived(15px = type(body-small, mobile, size)) / Derived(22px = type(body-small, mobile, line)) mobile; gạch ngang | Không tương tác | Cùng breakpoint với Tên |
| Thêm vào giỏ | Theo nội dung | 10px 12px; mobile 6px 12px | Không khai báo | 10px | `button-label`: Derived(14px = type(button-label, desktop, size)) / Derived(18px = type(button-label, desktop, line)) desktop, Derived(17px = type(button-label, mobile, size)) / Derived(24px = type(button-label, mobile, line)) mobile | Native box, rộng 100% | Class `Avada-ProductCard-AddToCartButton-Mobile` khi `isMobile` |

### Tokens

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Chữ card | `color` | #232323 | #ffffff |
| Nền card | `background` | rgba(255,255,255,0.75) | transparent |
| Viền card | `border` | #f2f2f2 | #303030 |
| Nền khối thông tin | `background-color` | #ffffff | #303030 |
| Nút thêm vào giỏ | `background-color`; `color` | Nền #ffffff; chữ #232323; hover nền #f8f9ff | Nền #ffffff; chữ #232323; hover nền #f8f9ff |
| Nút overlay | `background-color`; `color` | Nền #ffffff; chữ #303030 | Nền #232323; chữ #ffffff |
| Giá so sánh | `color` | #000000bf | rgba(255,255,255,0.6) |
| Vòng focus | `--chatty-color-border-focus` | Fallback #232323 | Fallback #232323 |
| Lỗi | `--danger` | Fallback #b42318 | Fallback #b42318 |

### States

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Hover card | pointer có hover và pointer fine | translateY(-2px); `--chatty-shadow-card-hover`; ảnh scale(1.03); tên gạch chân. | Không thêm ARIA |
| Touch active | hover: none hoặc pointer: coarse | scale(0.98); nền `color-mix(in srgb, currentColor 12%, transparent)`. | Không thêm ARIA |
| Focus-visible ảnh | keyboard | outline 2px solid; outline-offset -3px để vòng nằm trong vùng ảnh bị cắt. | `aria-label` "View product details" + tên |
| Focus-visible overlay | keyboard | outline 2px solid; offset 2px; nhãn mở rộng như hover. | `aria-label` "View similar" + tên |
| Focus-visible tên | keyboard | outline 2px solid currentColor; offset 2px; radius 4px. | Thẻ `a` native |
| Focus-visible giỏ | keyboard | outline 2px solid; offset 2px. | `aria-label` "Add to cart" + tên |
| Giỏ vô hiệu | `!availableForSale` hoặc đang thêm | opacity 0.5; tooltip "Out of stock" khi hết hàng. | native `disabled` |
| Đang thêm | `isBusy` | Hiện `Spinner` small trước nhãn; nút vô hiệu để chặn bấm lặp. | `aria-busy` |
| Lỗi thêm giỏ | `addError` có giá trị | Dòng chữ lỗi dưới nút, role `body-small`, màu `--danger`. | `role="alert"` |
| Reduced motion | `prefers-reduced-motion: reduce` | transform none trên card, hover và active. | Không thêm ARIA |

### Behaviour

| Interaction | Result |
| --- | --- |
| Bấm ảnh | Mở chi tiết ngay trong chat qua `setProduct`; nếu tắt chi tiết hoặc cần báo giá thì mở link ở tab mới; không làm gì khi `wizard` hoặc khối chat box. |
| Bấm tên | Thẻ `a` mở tab mới với `noopener noreferrer`; `wizard` chặn điều hướng. |
| View similar | Gửi tin nhắn chat yêu cầu sản phẩm tương tự và ghi nhận hoạt động; vô hiệu khi `wizard`; ẩn trong quản trị. |
| Thêm vào giỏ | Sản phẩm một biến thể và lô bằng 1 thì thêm trực tiếp; còn lại mở bộ chọn giỏ hàng; báo giá hoặc quản trị thì không thêm. |
| Giá bị ẩn | `WithheldPrice` quyết định hiển thị theo `pricing`, `priceHidden` và `isAdmin`; thiếu `price` thì không render hàng giá. |

### Copy

| String | i18n key | Where |
| --- | --- | --- |
| View product details | View product details | `aria-label` nút ảnh, ghép với tên |
| View similar | View similar | Nhãn nút overlay |
| Add to cart | Add to cart | Nhãn nút giỏ |
| Added to cart | Added to cart | `successLabel` sau khi thêm |
| Out of stock | Out of stock | Tooltip khi hết hàng |
| Could not add to cart | Could not add to cart | Thông báo lỗi thêm giỏ |

### Source

| File | Evidence |
| --- | --- |
|  | API, anatomy và hành vi |
|  | Kích thước, màu và trạng thái |
|  | Media canvas và hover |

## Do / Don't

Do: giữ thứ tự ảnh, tên, giá, rồi một hành động chính cho mỗi sản phẩm.

Don't: không kéo giãn card đơn trong carousel hoặc đặt button lồng trong button mở chi tiết.

## Accessibility

| Surface | Role / name | Keyboard / focus | Live region | Contrast pair / ratio |
| --- | --- | --- | --- | --- |
| AI Mode | Vùng chi tiết `role="button"` có `aria-label` "View product" ghép với tên; skeleton `aria-hidden="true"`. | `tabIndex={0}`; Enter và Space chỉ kích hoạt khi focus nằm trên chính vùng chi tiết. | Không có live region trong card | Đọc `--vib-1` trên nền card trong owning scope; nền Dark theo `chatty-surface` nên chưa đo ở đây. |
| Classic | Nút ảnh, overlay và giỏ có `aria-label` ghép tên sản phẩm; tên là thẻ `a`; ảnh dùng `alt` hoặc tiêu đề. | Nút ảnh và overlay là anh em, không lồng; mỗi phần tử có outline 2px khi focus-visible. | `role="alert"` cho lỗi thêm giỏ | Chữ trên khối thông tin: Light Measured(#232323 / #ffffff = 15.72:1); Dark Measured(#ffffff / #303030 = 13.20:1) |

## Target

```target
| Surface | Now | Target | Source |
| --- | --- | --- | --- |
| Classic | Chiều rộng card Classic là 205px, khác 184px của AI Mode. | Not in code yet — build with the body values. Thống nhất chiều rộng carousel về 184px nếu hai surface cần cùng nhịp hiển thị. |  |
| AI Mode | Hit target của pill chọn trên desktop là min-height 32px. | Not in code yet — build with the body values. Mở rộng vùng bấm lên 44px như mobile đã làm bằng `::before`. | [WCAG — target size enhanced](https://www.w3.org/WAI/WCAG22/Understanding/target-size-enhanced.html) |
| AI Mode · Classic | Hai renderer React riêng | Not available — new build follows Target. Element (dự kiến): `chatty-product-card` gộp hai renderer; property `.product`; slot `actions`; event `chatty-add-to-cart` (`bubbles` + `composed`). | [MDN: Web Components](https://developer.mozilla.org/en-US/docs/Web/API/Web_components) |
```


- [WCAG — target size enhanced](https://www.w3.org/WAI/WCAG22/Understanding/target-size-enhanced.html)
- [MDN: Web Components](https://developer.mozilla.org/en-US/docs/Web/API/Web_components)
