# Email continue form

Biểu mẫu gửi hội thoại hiện tại qua email để tiếp tục trò chuyện.

## Key rules

- AI Mode: form dùng email của hội thoại nếu đã có; nếu không thì yêu cầu khách nhập.
- Element `chatty-email-continue` ở 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

Dùng khi khách tiếp tục cùng hội thoại qua email.

### Use instead

| Component | Use when |
| --- | --- |
| `EmailContinueForm` | Gửi hội thoại để khách tiếp tục qua email. |
| `FormField` | Field email trong form khi hội thoại chưa có email. |

## Live preview

Example (Standard) — Email đã có hiện dạng chữ, và ô nhập khi chưa có email.

```html
<chatty-email-continue email="guest@example.com"></chatty-email-continue>
<chatty-email-continue value="guest@example"></chatty-email-continue>
```

Example (Standard) — Đang gửi, gửi lỗi và biên nhận sau khi gửi.

```js
import '@avada/chatty-ui/tokens/tokens.css';
import {IconCheck} from '@avada/chatty-ui/elements/icon-glyphs.js';
// Standard: the chatty-email-continue prototype chatty-ui ports from (chatty-ui/src/elements/email-continue.js).
import {html} from 'lit';
import '@avada/chatty-ui/elements/email-continue.js';

export function States() {
  return html`
    <chatty-email-continue email="guest@example.com" loading></chatty-email-continue>
    <chatty-email-continue email="guest@example.com" failed></chatty-email-continue>
    <chatty-email-continue sent-to="guest@example.com">
      ${IconCheck({slot: 'icon'})}
    </chatty-email-continue>
  `;
}
```

Example (Current (React), being replaced) — Form thật dùng dữ liệu cục bộ; dịch vụ gửi được mock.

```jsx
import React from 'react';
import {EmailContinueForm} from '@scripttag/v2/components/EmailContinue/EmailContinueForm.jsx';

export function Form() {
  return <EmailContinueForm conversation={{email: 'guest@example.com'}} onFallback={() => {}} />;
}
```

## Standard

Example (Standard) — Email đã có hiện dạng chữ, và ô nhập khi chưa có email.

```html
<chatty-email-continue email="guest@example.com"></chatty-email-continue>
<chatty-email-continue value="guest@example"></chatty-email-continue>
```

Prototype  (cùng `email-continue.styles.js`) là chuẩn: chatty-ui port 1:1, và `chatty-ui/custom-elements.json` sinh từ chính prototype. Element kiểm định dạng email rồi phát `chatty-submit`; host gửi email và đặt `loading`, `sent-to` hoặc `failed`. Nhãn đi qua property `.strings`. Chưa surface nào dùng element thật; mục AI Mode bên dưới mô tả React đang chạy.

### Element

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

### API

| Kind | Name | Type | Default | Description |
| --- | --- | --- | --- | --- |
| attribute | `email` | string | `''` | Email đã có trên hội thoại; hiện dạng chữ thay cho ô nhập. |
| attribute | `value` | string | `''` | Giá trị điền sẵn của ô nhập. |
| attribute | `loading` | boolean | `false` | Đang gửi: nút hiện spinner, chặn gửi lặp. |
| attribute | `failed` | boolean | `false` | Hiện thông báo gửi lỗi (role alert). |
| attribute | `sent-to` | string | `''` | Email đã gửi tới; card đổi thành biên nhận. |
| event | `chatty-submit` | CustomEvent<{email: string}> | – | Gửi với email hợp lệ (nút Send hoặc Enter trong ô nhập). |
| slot | `icon` | – | – | Icon check của biên nhận. |
| part | `base` | – | – | Card, hoặc biên nhận sau khi gửi. |
| part | `title` | – | – | Tiêu đề card. |
| part | `input` | – | – | Ô nhập email. |
| part | `error` | – | – | Lỗi định dạng hoặc lỗi gửi. |
| css-property | `--chatty-email-continue-radius` | – | – | Bo góc card. |
| css-property | `--chatty-email-continue-background` | – | – | Nền card. |

## AI Mode

### Import / element

| Component / element | Import / file | Scope root |
| --- | --- | --- |
| `EmailContinueForm` | @scripttag/v2/components/EmailContinue/EmailContinueForm.jsx | .chatty-ai-mode |

### Anatomy

| Part | Element |
| --- | --- |
| 1 | ChatFormCard chứa title và lead. |
| 2 | Email đã biết hoặc FormField nhập email. |
| 3 | Nút Send và thông báo lỗi khi cần. |

### Placement / order

| Context | Order |
| --- | --- |
| Form | Title và lead, email, lỗi nếu có, rồi action. |

### Props

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `conversation` | object | Hội thoại hiện tại | Caller | Email hiện có được ưu tiên. |
| `onFallback` | function | Callback | Caller | Gọi khi server yêu cầu mailto. |

### Sizes

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Form | Theo ChatFormCard | Theo ChatFormCard | Theo ChatFormCard | Theo ChatFormCard | Theo form | Nút native | Caller đặt trong panel |

### Tokens

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Form | Theo ChatFormCard | Theo scope | Theo scope |

### States

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Invalid | Email không hợp lệ | FormField nhận error. | Theo FormField |
| Submitting | Đang gửi | Field và action disabled. | Native disabled |
| Failed | Request lỗi | Thông báo lỗi hiện dưới field. | role alert |
| Sent | Server thành công | FormDone hiện địa chỉ nhận. | Theo FormDone |

### Behaviour

| Interaction | Result |
| --- | --- |
| Submit | Chặn gửi lặp, kiểm tra email rồi gọi dịch vụ. |
| Fallback | Khi server yêu cầu mailto, gọi callback. |

### Copy

| String | i18n key | Where |
| --- | --- | --- |
| Continue as email | Continue as email | Tiêu đề form |
| Email | Email | Nhãn field |
| Send | Send | Action |
| Transcript email failure | Transcript email failure | Lỗi gửi |

### Source

| File | Evidence |
| --- | --- |
|  | API, trạng thái và markup |
|  | Style form |

## Do / Don't

Do: dùng email hiện có của hội thoại khi có.

Don't: gửi lặp trong lúc request đang chạy.

## Accessibility

| Surface | Role / name | Keyboard / focus | Live region | Contrast pair / ratio |
| --- | --- | --- | --- | --- |
| AI Mode | Field email có label; lỗi gửi role alert | Field nhận autoFocus; Enter submit; nút native | Lỗi gửi là alert | Theo scope form |

## Target

```target
| Surface | Now | Target | Source |
| --- | --- | --- | --- |
| AI Mode | Form React | Not available — new build follows Target. Control dùng `chatty-text-field` và `chatty-buttontype=submit`; composite thuộc `chatty-contact-form` (dự kiến), gửi qua actions của chat-core. | [MDN: ElementInternals](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals) |
| AI Mode | Component React theo surface | Not available — new build follows Target. Port `chatty-email-continue` từ mục Standard rồi chuyển caller từng surface. |  |
```


-  .chatty-email-continue
- [MDN: ElementInternals](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals)
