# Toast / confirmation

CartConfirmation là receipt riêng trong thread của AI Mode và inbox; không phải toast.

## Key rules

- AI Mode: `CartConfirmation` có thể render một dòng hoặc nhóm dòng; View cart gọi `onViewCart` của caller.
- AI Mode: ảnh 80px × 64px, nhãn body-small, quantity và giá cùng một dòng.
- Admin: inbox dùng cùng `CartConfirmation` nhưng không truyền `onViewCart` cho viewer admin nên không có View cart.
- Receipt nằm trong thread và không tự biến mất; hiệu ứng quantity có thời gian riêng.
- Element `chatty-toast` ở mục Standard là chuẩn cho thông báo tạm thời của storefront; receipt trong thread không dùng toast.

## Use when / Avoid

Dùng sau khi hệ thống xác nhận thêm giỏ thành công. Không ghép xác nhận vào văn bản AI và không dùng cho phản hồi tạm thời: receipt nằm lại trong thread. Classic dùng cùng block cho khách.

### Use instead

| Component | Use when |
| --- | --- |
| `CartConfirmation` | AI Mode: receipt trong danh sách tin nhắn, có View cart. |
| `CartConfirmation` | Admin inbox: cùng receipt, không có View cart cho viewer admin. |

## Live preview

Example (Standard) — Element chatty-toast: neutral có action, success và critical; token chuẩn.

```html
<chatty-toast style="width: 100%" open duration="0">Message deleted<chatty-button slot="action" variant="plain" size="sm">Undo</chatty-button></chatty-toast>
<chatty-toast style="width: 100%" open duration="0" tone="success">Added to cart</chatty-toast>
<chatty-toast style="width: 100%" open duration="0" tone="critical">Couldn't send. Check your connection and try again.</chatty-toast>
```

Example (Standard) — Element chatty-toast trên Classic.

```html
<chatty-toast style="width: 100%" open duration="0">Message deleted<chatty-button slot="action" variant="plain" size="sm">Undo</chatty-button></chatty-toast>
<chatty-toast style="width: 100%" open duration="0" tone="success">Added to cart</chatty-toast>
<chatty-toast style="width: 100%" open duration="0" tone="critical">Couldn't send. Check your connection and try again.</chatty-toast>
```

Example (Current (React), being replaced) — Snackbar của ChatPage (useSnackbar contained): nền --chatty-tooltip-bg, chữ trắng; token inverse lấy từ đây.

```jsx
import useSnackbar from '@assets/hooks/useSnackbar';

  const {toast, handleOpenToast} = useSnackbar({contained: true});

import {Snackbar} from '@assets/components/ui';

/**
 * One toast slot; each open may set its own display time.
 * @param {string} vertical
 * @param {string} horizontal
 * @param {Object} style
 * @param {string} className
 * @param {boolean} contained anchor to the chat panel instead of the viewport
 * @returns {{toast: JSX.Element, handleOpenToast: (content: *, autoHideDuration?: number) => void}}
 */
export default function useSnackbar({
  vertical = 'bottom',
  horizontal = 'center',
  style = {},
  className,
  contained = false
} = {}) {
  const [open, setOpen] = useState(false);
  const [content, setContent] = useState('');
  const [autoHideDuration, setAutoHideDuration] = useState(DEFAULT_AUTO_HIDE_MS);

  const handleOpenToast = (content, duration = DEFAULT_AUTO_HIDE_MS) => {
    setOpen(true);
    setContent(content);
    setAutoHideDuration(duration);
  };
  // Stable because Snackbar restarts its auto-hide timer whenever onClose changes, and callers re-render often.
  const handleCloseToast = useCallback((_, reason) => {
    if (reason !== 'clickaway') {
      setOpen(false);
      setContent('');
    }
  }, []);

  const toast = useMemo(() => {
    return (
      <Snackbar
        open={open}
        autoHideDuration={autoHideDuration}
        anchorOrigin={{vertical, horizontal}}
        onClose={handleCloseToast}
        className={className}
        style={{
          display: open ? 'flex' : 'none',
          minWidth: 'unset',
          justifyContent: 'center',
          flex: 'unset',
          padding: '0 16px',
          ...style,
          ...(contained ? CONTAINED_STYLE : {})
        }}
        onClick={handleCloseToast}
      >
        <div style={{padding: '6px 16px'}}>{content}</div>
      </Snackbar>
    );
  }, [open, content, autoHideDuration, style, className, contained]);

  return {
    toast,
    handleOpenToast
  };
}
```

Example (Current (React), being replaced) — Chỉ để so sánh: receipt thêm giỏ, không phải toast; xem trang Cart confirmation. AI Mode có View cart.

```jsx
import React, {useState} from 'react';
import {CartConfirmation} from '@avada/chatty-ui/primitives/CartConfirmation.jsx';
export function Receipt({surface}) {
  const [opened, setOpened] = useState(false);
  return <div>
    <CartConfirmation receipt={{title: 'Cotton T-shirt', variant: 'Blue / Medium', quantity: 2, linePrice: 40, currency: 'USD'}} translate={text => text} formatMoney={(amount, currency) => new Intl.NumberFormat('en-US', {style: 'currency', currency}).format(amount)} onViewCart={surface === 'admin' ? undefined : () => setOpened(true)} />
    {opened && <p role="status">Cart opened</p>}
  </div>;
}
```

Example (Current (React), being replaced) — Chỉ để so sánh: receipt thêm giỏ, không phải toast; xem trang Cart confirmation. Inbox chỉ đọc, không có View cart.

```jsx
import React, {useState} from 'react';
import {CartConfirmation} from '@avada/chatty-ui/primitives/CartConfirmation.jsx';
export function Receipt({surface}) {
  const [opened, setOpened] = useState(false);
  return <div>
    <CartConfirmation receipt={{title: 'Cotton T-shirt', variant: 'Blue / Medium', quantity: 2, linePrice: 40, currency: 'USD'}} translate={text => text} formatMoney={(amount, currency) => new Intl.NumberFormat('en-US', {style: 'currency', currency}).format(amount)} onViewCart={surface === 'admin' ? undefined : () => setOpened(true)} />
    {opened && <p role="status">Cart opened</p>}
  </div>;
}
```

Example (Current (React), being replaced) — Chỉ để so sánh: receipt thêm giỏ, không phải toast; xem trang Cart confirmation. Khách có View cart.

```jsx
import React, {useState} from 'react';
import {CartConfirmation} from '@avada/chatty-ui/primitives/CartConfirmation.jsx';
export function Receipt({surface}) {
  const [opened, setOpened] = useState(false);
  return <div>
    <CartConfirmation receipt={{title: 'Cotton T-shirt', variant: 'Blue / Medium', quantity: 2, linePrice: 40, currency: 'USD'}} translate={text => text} formatMoney={(amount, currency) => new Intl.NumberFormat('en-US', {style: 'currency', currency}).format(amount)} onViewCart={surface === 'admin' ? undefined : () => setOpened(true)} />
    {opened && <p role="status">Cart opened</p>}
  </div>;
}
```

## Standard

Example (Standard) — Element chatty-toast: neutral có action, success và critical; token chuẩn.

```html
<chatty-toast style="width: 100%" open duration="0">Message deleted<chatty-button slot="action" variant="plain" size="sm">Undo</chatty-button></chatty-toast>
<chatty-toast style="width: 100%" open duration="0" tone="success">Added to cart</chatty-toast>
<chatty-toast style="width: 100%" open duration="0" tone="critical">Couldn't send. Check your connection and try again.</chatty-toast>
```

Prototype  (cùng `toast.styles.js` và ) là chuẩn cho thông báo tạm thời của storefront: chatty-ui port 1:1 các file này, và `chatty-ui/custom-elements.json` sinh từ chính prototype. Receipt thêm giỏ trong thread không phải toast; nó là `chatty-cart-confirmation` ở trang Cart confirmation. Admin giữ App Bridge toast. Chưa surface nào dùng element thật; các mục bên dưới mô tả React đang chạy.

### Element

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

### API

| Kind | Name | Type | Default | Description |
| --- | --- | --- | --- | --- |
| attribute | `open` | boolean | `false` | Toast đang hiện. |
| attribute | `tone` | neutral, critical, success, caution | `'neutral'` | Ý nghĩa của thông báo: icon đầu dòng màu chữ inverse (không dựa riêng vào màu); critical đổi role sang alert. |
| attribute | `duration` | number | `6000` | Tự đóng sau số ms này; 0 giữ lại; tạm dừng khi hover hoặc focus. |
| attribute | `close-label` | string | `'Close'` | Tên truy cập của nút đóng. |
| event | `click` | MouseEvent | – | Click native của nút đóng, nổi ra ngoài shadow root. |
| event | `chatty-close` | CustomEvent<{reason: timeout, close-button}> | – | Yêu cầu đóng (timeout hoặc close-button); preventDefault giữ toast. |
| slot | default | – | – | Nội dung thông báo. |
| slot | `action` | – | – | Một action tuỳ chọn, ví dụ Undo. |
| slot | `close-icon` | – | – | Icon của nút đóng; mặc định là dấu nhân. |
| part | `base` | – | – | Khung toast. |
| part | `icon` | – | – | Icon đầu dòng theo tone (critical, success, caution); neutral không có. |
| part | `message` | – | – | Vùng chứa thông báo. |
| part | `action` | – | – | Vùng chứa action. |
| part | `close` | – | – | Nút đóng. |
| css-property | `--chatty-toast-background` | – | – | Nền toast. |
| css-property | `--chatty-toast-color` | – | – | Màu chữ toast. |

## AI Mode

### Import / element

| Component / element | Import / file | Scope root |
| --- | --- | --- |
| `CartConfirmation` | @avada/chatty-ui/primitives/CartConfirmation.jsx | .chatty-ai-mode (token màu và type) |

### Anatomy

| Part | Element |
| --- | --- |
| 1 | section có class chatty-cart-confirmation và aria-label từ translate. |
| 2 | Nhãn đầu card, một dòng, chiếm cả hai cột. |
| 3 | Ảnh `img` tùy chọn, alt rỗng; ẩn khi thiếu thumbnail hoặc ảnh lỗi. |
| 4 | Body: title, variant tùy chọn, dòng quantity cùng giá. |
| 5 | Nút View cart tùy chọn, chỉ có khi truyền `onViewCart`. |

### Placement / order

| Context | Order |
| --- | --- |
| Message list | ChatMessage render receipt trong div có data-message-id, thay cho bubble khi message mang cartConfirmation. |
| Trong card | Nhãn, ảnh, rồi body theo thứ tự title, variant, quantity và giá, cuối cùng View cart; khi không có ảnh body chiếm cả hai cột. |

### Props

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `receipt` | object | Dữ liệu một cart-line | Bắt buộc | Component không render (null) khi readCartConfirmation không trả line hợp lệ. |
| `receipts` | array | Nhiều cart-line | undefined | Khi có dòng hợp lệ, render grouped receipt. |
| `showAll` | boolean | true / false | false | Hiện tất cả dòng grouped; mặc định chỉ ba dòng nếu có hơn bốn. |
| `formatMoney` | function | (linePrice, currency) trả chuỗi | Bắt buộc | Kết quả nằm trong `bdi` cạnh quantity. |
| `translate` | function | Hàm dịch theo key | Bắt buộc | Dùng cho nhãn, quantity và View cart. |
| `onViewCart` | function | Click handler | undefined | Truthy mới render nút View cart. |

### Sizes

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Card | Theo nội dung | 16px (fallback `--chatty-space-400`) | 12px (fallback `--chatty-space-300`) | 20px | 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 | Không tương tác | Grid 64px + `minmax(0, 1fr)`; width `min(100%, 360px)` |
| Nhãn, variant, dòng quantity | Theo nội dung | Không có | 4px | Không có | 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 | Không tương tác | Cùng role trên mọi viewport của surface |
| Ảnh | 80px | Không có | Không có | 10px | Không có chữ | Không tương tác | Rộng 64px, `object-fit` cover |
| View cart desktop | min 40px | 8px / 0 | Không khai báo | 6px | Kế thừa `font: inherit` | min 40px | Mặc định |
| View cart mobile | min 44px | Như View cart desktop | Không khai báo | Như View cart desktop | Kế thừa | min 44px | max-width 899px hoặc root mobile của surface |

### Tokens

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Card fill | `--chatty-color-bg-surface` | #f6f4f0 | #131215 |
| Text | `--chatty-color-text` | rgba(20,19,24,0.94) | rgba(255,255,255,0.96) |
| Variant text | `--chatty-color-text-secondary` | rgba(20,19,24,0.74) | rgba(255,255,255,0.74) |
| Border | `--chatty-color-border` | rgba(20,19,24,0.08) | rgba(255,255,255,0.12) |
| Ảnh nền | `--chatty-color-bg-surface-secondary` | #f7f7f7 fallback | #f7f7f7 fallback |

### States

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Có ảnh | thumbnail hợp lệ | Cột ảnh 64px; ảnh 80px | `img` alt rỗng, trang trí |
| Không ảnh | thiếu thumbnail hoặc `onError` | Thêm class `chatty-cart-confirmation--no-media`; body chiếm cả hai cột | Không đổi |
| Hover View cart | pointer | Gạch chân 2px (từ 1px) | Native button |
| Active View cart | pointer down | Gạch chân 3px | Native button |
| Focus-visible View cart | keyboard | outline 2px solid currentColor, offset 2px | Native focus |
| Không có View cart | `onViewCart` undefined | Nút không render | Không đổi |

### Behaviour

| Interaction | Result |
| --- | --- |
| Click View cart | Gọi `onViewCart` của caller; component không tự mở giỏ. |
| Receipt không hợp lệ | Component trả null, không có card rỗng. |
| Tiêu đề dài | `overflow-wrap` anywhere trong body; giá `white-space` nowrap. |
| Grouped | Tối đa bốn dòng hiện đầy đủ; nếu nhiều hơn, hiện ba dòng và số còn lại. Admin có thể hiện tất cả. |
| Quantity thay đổi | Hiệu ứng đánh dấu kết thúc sau 600ms; reduced motion tắt animation. |

### Copy

| String | i18n key | Where |
| --- | --- | --- |
| Added to cart | Added to cart | Nhãn card và aria-label; caller truyền `t` |
| Quantity in cart | Quantity in cart | Dòng quantity |
| View cart | View cart | Nút View cart |

### Source

| File | Evidence |
| --- | --- |
|  | API và DOM |
|  | Kích thước và token |
|  | Caller AI Mode |
|  | Token màu AI Mode |

## Classic

### Import / element

| Component / element | Import / file | Scope root |
| --- | --- | --- |
| `CartConfirmation` | @avada/chatty-ui/primitives/CartConfirmation.jsx | .Avada-Faqs_Popup |

### Anatomy

| Part | Element |
| --- | --- |
| 1 | section có class chatty-cart-confirmation và aria-label từ translate. |
| 2 | Nhãn đầu card, một dòng, chiếm cả hai cột. |
| 3 | Ảnh `img` tùy chọn, alt rỗng; ẩn khi thiếu thumbnail hoặc ảnh lỗi. |
| 4 | Body: title, variant tùy chọn, dòng quantity cùng giá. |
| 5 | Nút View cart tùy chọn, chỉ có khi truyền `onViewCart`. |

### Placement / order

| Context | Order |
| --- | --- |
| Inbox block | widgetRegistry gắn block cart-confirmation; khách có thể mở giỏ qua View cart. |
| Trong card | Nhãn, ảnh, rồi body theo thứ tự title, variant, quantity và giá, cuối cùng View cart; khi không có ảnh body chiếm cả hai cột. |

### Props

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `receipt` | object | Dữ liệu một cart-line | Bắt buộc | Component không render (null) khi readCartConfirmation không trả line hợp lệ. |
| `receipts` | array | Nhiều cart-line | undefined | Khi có dòng hợp lệ, render grouped receipt. |
| `showAll` | boolean | true / false | false | Hiện tất cả dòng grouped; mặc định chỉ ba dòng nếu có hơn bốn. |
| `formatMoney` | function | (linePrice, currency) trả chuỗi | Bắt buộc | Kết quả nằm trong `bdi` cạnh quantity. |
| `translate` | function | Hàm dịch theo key | Bắt buộc | Dùng cho nhãn, quantity và View cart. |
| `onViewCart` | function | Click handler | undefined | Truthy mới render nút View cart. |

### Sizes

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Card | Theo nội dung | 16px (fallback `--chatty-space-400`) | 12px (fallback `--chatty-space-300`) | 12px | 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 | Không tương tác | Grid 64px + `minmax(0, 1fr)`; width `min(100%, 360px)` |
| Nhãn, variant, dòng quantity | Theo nội dung | Không có | 4px | Không có | 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 | Không tương tác | Cùng role trên mọi viewport của surface |
| Ảnh | 80px | Không có | Không có | 10px | Không có chữ | Không tương tác | Rộng 64px, `object-fit` cover |
| View cart desktop | min 40px | 8px / 0 | Không khai báo | 6px | Kế thừa `font: inherit` | min 40px | Mặc định |
| View cart mobile | min 44px | Như View cart desktop | Không khai báo | Như View cart desktop | Kế thừa | min 44px | max-width 899px hoặc root mobile của surface |

### Tokens

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Card fill | `--chatty-color-bg-surface` | #fff fallback | Theo scope |
| Text | `--chatty-color-text` | #303030 fallback | Theo scope |
| Variant text | `--chatty-color-text-secondary` | #616161 fallback | Theo scope |
| Border | `--chatty-color-border` | #e3e3e3 fallback | Theo scope |
| Ảnh nền | `--chatty-color-bg-surface-secondary` | #f7f7f7 fallback | Theo scope |

### States

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Có ảnh | thumbnail hợp lệ | Cột ảnh 64px; ảnh 80px | `img` alt rỗng, trang trí |
| Không ảnh | thiếu thumbnail hoặc `onError` | Thêm class `chatty-cart-confirmation--no-media`; body chiếm cả hai cột | Không đổi |
| Hover View cart | pointer | Gạch chân 2px (từ 1px) | Native button |
| Active View cart | pointer down | Gạch chân 3px | Native button |
| Focus-visible View cart | keyboard | outline 2px solid currentColor, offset 2px | Native focus |
| Không có View cart | `onViewCart` undefined | Nút không render | Không đổi |

### Behaviour

| Interaction | Result |
| --- | --- |
| Click View cart | Gọi `onViewCart` của caller; component không tự mở giỏ. |
| Receipt không hợp lệ | Component trả null, không có card rỗng. |
| Tiêu đề dài | `overflow-wrap` anywhere trong body; giá `white-space` nowrap. |
| Grouped | Tối đa bốn dòng hiện đầy đủ; nếu nhiều hơn, hiện ba dòng và số còn lại. Admin có thể hiện tất cả. |
| Quantity thay đổi | Hiệu ứng đánh dấu kết thúc sau 600ms; reduced motion tắt animation. |

### Copy

| String | i18n key | Where |
| --- | --- | --- |
| Added to cart | Added to cart | Nhãn card và aria-label; caller truyền `i18n` |
| Quantity in cart | Quantity in cart | Dòng quantity |
| View cart | View cart | Nút View cart cho khách |

### Source

| File | Evidence |
| --- | --- |
|  | API và DOM |
|  | Kích thước và token |
|  | Caller inbox |

## Admin

### Import / element

| Component / element | Import / file | Scope root |
| --- | --- | --- |
| `CartConfirmation` | @avada/chatty-ui/primitives/CartConfirmation.jsx | .inbox-v2 |

### Anatomy

| Part | Element |
| --- | --- |
| 1 | section có class chatty-cart-confirmation và aria-label từ translate. |
| 2 | Nhãn đầu card, một dòng, chiếm cả hai cột. |
| 3 | Ảnh `img` tùy chọn, alt rỗng; ẩn khi thiếu thumbnail hoặc ảnh lỗi. |
| 4 | Body: title, variant tùy chọn, dòng quantity cùng giá. |
| 5 | Nút View cart tùy chọn, chỉ có khi truyền `onViewCart`. |

### Placement / order

| Context | Order |
| --- | --- |
| Inbox block | widgetRegistry gắn block cart-confirmation; viewer admin nhận receipt không có View cart. |
| Trong card | Nhãn, ảnh, rồi body theo thứ tự title, variant, quantity và giá, cuối cùng View cart; khi không có ảnh body chiếm cả hai cột. |

### Props

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `receipt` | object | Dữ liệu một cart-line | Bắt buộc | Component không render (null) khi readCartConfirmation không trả line hợp lệ. |
| `receipts` | array | Nhiều cart-line | undefined | Khi có dòng hợp lệ, render grouped receipt. |
| `showAll` | boolean | true / false | false | Hiện tất cả dòng grouped; mặc định chỉ ba dòng nếu có hơn bốn. |
| `formatMoney` | function | (linePrice, currency) trả chuỗi | Bắt buộc | Kết quả nằm trong `bdi` cạnh quantity. |
| `translate` | function | Hàm dịch theo key | Bắt buộc | Dùng cho nhãn, quantity và View cart. |
| `onViewCart` | function | Click handler | undefined | Truthy mới render nút View cart. |

### Sizes

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Card | Theo nội dung | 16px (fallback `--chatty-space-400`) | 12px (fallback `--chatty-space-300`) | 20px | body-medium: Derived(13px = type(body-medium, admin, desktop, size)) / Derived(20px = type(body-medium, admin, desktop, line)) desktop, Derived(15px = type(body-medium, admin, mobile, size)) / Derived(22px = type(body-medium, admin, mobile, line)) mobile | Không tương tác | Grid 64px + `minmax(0, 1fr)`; width `min(100%, 360px)` |
| Nhãn, variant, dòng quantity | Theo nội dung | Không có | 4px | Không có | body-small: Derived(12px = type(body-small, admin, desktop, size)) / Derived(18px = type(body-small, admin, desktop, line)) desktop, Derived(13px = type(body-small, admin, mobile, size)) / Derived(20px = type(body-small, admin, mobile, line)) mobile | Không tương tác | Cùng role trên mọi viewport của surface |
| Ảnh | 80px | Không có | Không có | 10px | Không có chữ | Không tương tác | Rộng 64px, `object-fit` cover |
| View cart desktop | min 40px | 8px / 0 | Không khai báo | 6px | Kế thừa `font: inherit` | min 40px | Mặc định |
| View cart mobile | min 44px | Như View cart desktop | Không khai báo | Như View cart desktop | Kế thừa | min 44px | max-width 899px hoặc root mobile của surface |

### Tokens

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Card fill | `--chatty-color-bg-surface` | #fff fallback | No Dark skin |
| Text | `--chatty-color-text` | #303030 fallback | No Dark skin |
| Variant text | `--chatty-color-text-secondary` | #616161 fallback | No Dark skin |
| Border | `--chatty-color-border` | #e3e3e3 fallback | No Dark skin |
| Ảnh nền | `--chatty-color-bg-surface-secondary` | #f7f7f7 fallback | No Dark skin |

### States

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Có ảnh | thumbnail hợp lệ | Cột ảnh 64px; ảnh 80px | `img` alt rỗng, trang trí |
| Không ảnh | thiếu thumbnail hoặc `onError` | Thêm class `chatty-cart-confirmation--no-media`; body chiếm cả hai cột | Không đổi |
| Hover View cart | pointer | Gạch chân 2px (từ 1px) | Native button |
| Active View cart | pointer down | Gạch chân 3px | Native button |
| Focus-visible View cart | keyboard | outline 2px solid currentColor, offset 2px | Native focus |
| Không có View cart | `onViewCart` undefined | Nút không render | Không đổi |

### Behaviour

| Interaction | Result |
| --- | --- |
| Click View cart | Gọi `onViewCart` của caller; component không tự mở giỏ. |
| Receipt không hợp lệ | Component trả null, không có card rỗng. |
| Tiêu đề dài | `overflow-wrap` anywhere trong body; giá `white-space` nowrap. |
| Grouped | Tối đa bốn dòng hiện đầy đủ; nếu nhiều hơn, hiện ba dòng và số còn lại. Admin có thể hiện tất cả. |
| Quantity thay đổi | Hiệu ứng đánh dấu kết thúc sau 600ms; reduced motion tắt animation. |

### Copy

| String | i18n key | Where |
| --- | --- | --- |
| Added to cart | Added to cart | Nhãn card và aria-label; caller truyền `i18n` |
| Quantity in cart | Quantity in cart | Dòng quantity |
| View cart | View cart | Không render cho viewer admin |

### Source

| File | Evidence |
| --- | --- |
|  | API và DOM |
|  | Kích thước và token |
|  | Caller inbox |

## Do / Don't

Do: hiện receipt sau khi server xác nhận và truyền `onViewCart` chỉ khi người xem sở hữu giỏ.

Don't: báo thành công trước khi có xác nhận, hoặc dựng toast nổi thay cho receipt.

## Accessibility

Contrast đo trên nền card; admin chỉ có Light.

| Surface | Role / name | Keyboard / focus | Live region | Contrast pair / ratio |
| --- | --- | --- | --- | --- |
| AI Mode | Receipt một dòng có aria-label "Added to cart"; ảnh alt rỗng | View cart là native button, outline 2px khi focus-visible | CartThreadStatus thông báo receipt mới qua polite live region | Light text Measured(rgba(20,19,24,0.94) / #f6f4f0 = 14.65:1), variant Measured(rgba(20,19,24,0.74) / #f6f4f0 = 7.58:1); Dark text Measured(rgba(255,255,255,0.96) / #131215 = 17.20:1), variant Measured(rgba(255,255,255,0.74) / #131215 = 10.42:1) |
| Classic | Receipt một dòng có aria-label và ảnh alt rỗng | View cart là nút native | Caller sở hữu thông báo | Theo scope |
| Admin | Receipt một dòng có aria-label "Added to cart"; ảnh alt rỗng | Không có View cart cho viewer admin; còn lại như AI Mode | Không có | Text Measured(#303030 / #ffffff = 13.20:1); variant Measured(#616161 / #ffffff = 6.19:1) |

## Target

```target
| Surface | Now | Target | Source |
| --- | --- | --- | --- |
| AI Mode · Classic | CartConfirmation React trong thread | Not available — new build follows Target. Receipt dùng `chatty-cart-confirmation`; thông báo tạm thời port `chatty-toast` từ mục Standard, chỉ cho storefront. |  |
| Admin | Receipt trong thread của inbox | Not available — new build follows Target. Toast của admin giữ App Bridge `shopify.toast`; receipt trong thread dùng `chatty-cart-confirmation`. | [Shopify: Built for Shopify requirements](https://shopify.dev/docs/apps/launch/built-for-shopify/requirements) |
```


- [WCAG — status messages](https://www.w3.org/WAI/WCAG22/Understanding/status-messages.html)
- [MDN: Web Components](https://developer.mozilla.org/en-US/docs/Web/API/Web_components)
- [Shopify: Built for Shopify requirements](https://shopify.dev/docs/apps/launch/built-for-shopify/requirements)
