# Ad referral

Thẻ nguồn quảng cáo của tin nhắn trong inbox.

## Key rules

- Thẻ chỉ render khi có dữ liệu quảng cáo.
- Element `chatty-ad-referral` ở mục Standard là chuẩn chatty-ui port theo; các mục theo surface mô tả component React đang chạy.

## Use when / Avoid

Hiển thị ngữ cảnh quảng cáo của hội thoại.

### Use instead

| Component | Use when |
| --- | --- |
| `AdReferralBlock` | Hiển thị ngữ cảnh quảng cáo của hội thoại. |
| `button` | Caller sở hữu tương tác liên quan. |

## Live preview

Example (Standard) — Card chỉ có caption, và card có thumbnail, link bài đăng và chi tiết thu gọn.

```html
<chatty-ad-referral heading="Facebook ad"
  >Summer collection<br />Explore our collection</chatty-ad-referral
>
<chatty-ad-referral heading="WhatsApp ad" href="https://example.com/post">
  <img slot="thumb" src="/fixtures/tote.svg" alt="" />
  Canvas tote bag<br />Carry everything, every day.
  <img
    slot="details"
    src="/fixtures/tote.svg"
    alt="Canvas tote bag"
    style="max-width: 100%; max-height: 240px; border-radius: 8px"
  />
</chatty-ad-referral>
```

Example (Standard) — Card đã mở rộng: caption đầy đủ và ảnh chi tiết.

```html
<chatty-ad-referral heading="Instagram ad" expanded>
  Canvas tote bag<br />Carry everything, every day.
  <img
    slot="details"
    src="/fixtures/tote.svg"
    alt="Canvas tote bag"
    style="width: 160px; border-radius: 8px"
  />
</chatty-ad-referral>
```

Example (Current (React), being replaced) — Thẻ thật với dữ liệu cục bộ, không có media ngoài.

```jsx
import React from 'react';
import {AdReferralBlock} from '@assets/pages/InboxManagement/v2/blocks/AdReferralBlock.jsx';
import '@assets/pages/InboxManagement/v2/styles.scss';

export function Card() {
  return <AdReferralBlock block={{adReferral: {platform: 'facebook', title: 'Summer collection', body: 'Explore our collection'}, i18n: text => text}} />;
}
```

## Standard

Example (Standard) — Card chỉ có caption, và card có thumbnail, link bài đăng và chi tiết thu gọn.

```html
<chatty-ad-referral heading="Facebook ad"
  >Summer collection<br />Explore our collection</chatty-ad-referral
>
<chatty-ad-referral heading="WhatsApp ad" href="https://example.com/post">
  <img slot="thumb" src="/fixtures/tote.svg" alt="" />
  Canvas tote bag<br />Carry everything, every day.
  <img
    slot="details"
    src="/fixtures/tote.svg"
    alt="Canvas tote bag"
    style="max-width: 100%; max-height: 240px; border-radius: 8px"
  />
</chatty-ad-referral>
```

Prototype  (cùng `ad-referral.styles.js`) là chuẩn: chatty-ui port 1:1, và `chatty-ui/custom-elements.json` sinh từ chính prototype. Caption, thumbnail và phần chi tiết (media, sản phẩm) đi qua slot. Chưa inbox dùng element thật; mục Admin bên dưới mô tả React đang chạy.

### Element

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

### API

| Kind | Name | Type | Default | Description |
| --- | --- | --- | --- | --- |
| attribute | `heading` | string | `''` | Nhãn kênh, ví dụ Facebook ad, Instagram ad, Clicked your ad. |
| attribute | `href` | string | `''` | URL bài đăng; chỉ http(s), URL khác thì ẩn link. |
| attribute | `link-label` | string | `'View post'` | Chữ của link bài đăng. |
| attribute | `toggle-label` | string | `'Ad details'` | Tên truy cập của nút mở rộng. |
| attribute | `expanded` | boolean | `false` | Mở caption đầy đủ và phần chi tiết; ẩn thumbnail. |
| event | `toggle` | Event | – | expanded đổi từ nút mở rộng. |
| event | `click` | MouseEvent | – | Kích hoạt native của nút mở rộng. |
| slot | default | – | – | Caption: tiêu đề và nội dung quảng cáo. |
| slot | `thumb` | – | – | Thumbnail, ẩn khi mở rộng. |
| slot | `details` | – | – | Media và sản phẩm, hiện khi mở rộng. |
| part | `base` | – | – | Khung card. |
| part | `label` | – | – | Nhãn kênh. |
| part | `link` | – | – | Link bài đăng. |
| part | `caption` | – | – | Caption bị kẹp khi thu gọn. |
| part | `toggle` | – | – | Nút mở rộng; chỉ hiện khi có chi tiết hoặc caption bị kẹp. |
| part | `details` | – | – | Vùng chi tiết. |
| css-property | `--chatty-ad-referral-radius` | – | – | Bo góc. |
| css-property | `--chatty-ad-referral-background` | – | – | Nền. |

## Admin

### Import / element

| Component / element | Import / file | Scope root |
| --- | --- | --- |
| `AdReferralBlock` | @assets/pages/InboxManagement/v2/blocks/AdReferralBlock.jsx | .inbox-v2 |

### Anatomy

| Part | Element |
| --- | --- |
| 1 | Thumbnail tùy chọn, nhãn, nội dung, nút mở rộng và media. |

### Placement / order

| Context | Order |
| --- | --- |
| Caller | Theo thứ tự markup của component. |

### Props

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `block` | object | adReferral và i18n | Caller | Không có adReferral thì trả null. |

### Sizes

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Component | Theo nội dung | 8px | 8px | Theo token | body-small | Nút native | Grid fit-content |

### Tokens

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Nền | Theo style inbox | Theo style inbox | No Dark skin |

### States

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Mở rộng | Có media hoặc caption bị cắt | Hiện chi tiết khi nhấn. | aria-expanded |

### Behaviour

| Interaction | Result |
| --- | --- |
| Toggle | Đổi expanded và dừng sự kiện hàng. |

### Copy

| String | i18n key | Where |
| --- | --- | --- |
| Ad details | Ad details | Nhãn nút mở rộng |

### Source

| File | Evidence |
| --- | --- |
|  | Public API |
|  | Markup |
|  | Caller |

## Do / Don't

Do: dùng API của surface hiện tại.

Don't: thay hành động của caller bằng hành vi giả định.

## Accessibility

| Surface | Role / name | Keyboard / focus | Live region | Contrast pair / ratio |
| --- | --- | --- | --- | --- |
| Admin | Nút có tên Ad details và aria-expanded | Nút native nhận Tab, Enter, Space | Không có live region | Theo style inbox |

## Target

```target
| Surface | Now | Target | Source |
| --- | --- | --- | --- |
| Admin | Thẻ React trong thread của inbox | Not available — new build follows Target. Registry block của `chatty-message` (đợt C) ánh xạ block `ad-referral` sang element `chatty-ad-referral`, không có tag `chatty-block-*` riêng; dữ liệu đi qua property, không qua attribute; block không biết thì ẩn. | [MDN: Web Components](https://developer.mozilla.org/en-US/docs/Web/API/Web_components) |
| Admin | Component React theo surface | Not available — new build follows Target. Port `chatty-ad-referral` từ mục Standard rồi chuyển caller từng surface. |  |
```


- [MDN: Web Components](https://developer.mozilla.org/en-US/docs/Web/API/Web_components)
