# Order lookup + verification

Hỏi thông tin nhận diện đơn bằng một form rõ ràng ngay khi cần tra cứu.

## Key rules

- Classic: form email nằm trong bubble của tin nhắn nhắc; nút Submit disabled tới khi email hợp lệ, sai email hiện `role="alert"`.
- Classic: role `input-value` đọc 18px trên mobile để field không bị zoom.
- AI Mode: dùng `ChatFormCard` với một `FormField` email; lỗi sai email hiện qua `chatty-field-error`.
- Hỏi email theo số đơn của Smart link; không đòi nhập dữ liệu có cấu trúc trong văn xuôi.

## Use when / Avoid

Dùng khi khách mở Smart link tới một đơn mà link không kèm email. Đây là xác thực đơn, không thay form thu thông tin pre-chat.

### Use instead

| Component | Use when |
| --- | --- |
| `SmartLinkEmailForm` | Email để mở đơn của Smart link, ở Classic và AI Mode. |
| `ChatFormCard` | Vỏ card chung cho form trong thread của AI Mode. |

## Entry points

| Surface | Owner |
| --- | --- |
| Classic | SmartLinkOrderThread portal form vào bubble tin nhắn nhắc |
| AI Mode | Block smartLinkEmailForm trong ChatMessage |

## Flow

| Surface | Step | Trigger | UI shown | Component | Copy + i18n key | Timing |
| --- | --- | --- | --- | --- | --- | --- |
| Classic | Nhắc nhập email | Link không kèm email | Tin nhắn nhắc nhập email kèm số đơn | SmartLinkOrderThread | Please enter the email used for order #{{order_number}} so we can show its details. / cùng chuỗi | Ngay khi mở thread |
| Classic | Gửi email | Submit | Nút aria-disabled khi chờ; field readonly giữ focus | SmartLinkEmailForm | Submit / Submit | Theo `onSubmit` |
| Classic | Sai email | `onSubmit` không tìm thấy đơn | Lỗi `role="alert"` dưới input | SmartLinkEmailForm | That email doesn't match order #{{order_number}}. Check the email you used when you ordered and try again. / cùng chuỗi | Ngay sau response |
| AI Mode | Hiện form | Block smartLinkEmailForm | Card form một field email | SmartLinkEmailForm | Email input placeholder / Email input placeholder | Ngay khi block render |
| AI Mode | Gửi email | Nút hoặc Enter | `is-loading`, field và nút disabled | SmartLinkEmailForm | Submit / Submit | Theo `confirmOrderEmail` |
| AI Mode | Sai email | Store báo `isWrongEmail` | Lỗi dưới field, viền `--danger` | SmartLinkEmailForm | Smart link order email mismatch / Smart link order email mismatch | Ngay sau response |

## Edge cases

| Surface | Case | Behaviour |
| --- | --- | --- |
| Classic | Link sai hoặc không tìm thấy đơn | Hiện thông báo không tìm thấy, không có form |
| Classic | Không có số đơn | Lời nhắc và lỗi dùng chuỗi không có số đơn |
| AI Mode | Email chưa đủ hợp lệ | Nút disabled, Enter không gửi |
| AI Mode | Đã xác minh | Post-purchase kết hợp phần đơn hàng và rewards. |

## Live preview

Classic: bubble thu gọn là fixture từ chatty-icon-button; Current: FloatButtonWidget, chưa có element. Bag và menu (…) ở header: N/A trong preview.

AI Mode: SignIn, EmailContinue, Reset và Bag ở header: N/A trong preview.

### Standard

Example (Standard) — Thread Standard dùng fixture cục bộ.

```js
import '@avada/chatty-ui/tokens/tokens.css';
import {html} from 'lit';
import {IconClose, IconMessage} from '@avada/chatty-ui/elements/icon-glyphs.js';
import '@avada/chatty-ui/elements/surface.js';
import '@avada/chatty-ui/elements/avatar.js';
import '@avada/chatty-ui/elements/badge.js';
import '@avada/chatty-ui/elements/icon-button.js';
import '@avada/chatty-ui/elements/launcher.js';
import '@avada/chatty-ui/elements/button.js';
import {sameGroup} from '@avada/chatty-ui/behaviors/messages.js';

// Reference viewport: 1280 × 900 desktop, 390 × 900 mobile.
const sizes = {
  classic: {width: 400, height: 700},
  'ai-mode': {width: 820, height: 657},
  admin: {width: 527, height: 842}
};
const question = {
  id: 'question',
  senderType: 'customer',
  text: 'Can you help me?',
  createdAt: '2026-01-15T10:00:00Z'
};

/** Viewport-relative sizing survives the initial hidden iframe layout. */
function widgetSize(surface) {
  const mode = new URLSearchParams(location.search).get('mobile');
  const isMobile = mode === null ? innerWidth < 900 : mode === 'true';
  const width = `min(${sizes[surface].width}px, max(0px, 100vw - 40px))`;
  const height = isMobile
    ? `min(${surface === 'admin' ? 848 : 888}px, round(down, calc(${width} * 2.2), 1px))`
    : `${sizes[surface].height}px`;
  return {...sizes[surface], height, mobile: isMobile};
}

/** Local immutable message state with real subscriptions for live previews. */
function fixtureStore(initial) {
  let state = {messages: initial};
  const listeners = new Set();
  return {
    getState: () => state,
    subscribe(listener) {
      listeners.add(listener);
      return () => listeners.delete(listener);
    },
    setMessages(messages) {
      state = {messages};
      listeners.forEach(listener => listener());
    }
  };
}

/** Appends the viewer message without replacing the existing conversation. */
function appendViewer(store, surface, text) {
  const message = {
    id: `viewer-${store.getState().messages.length}`,
    senderType: surface === 'admin' ? 'agent' : 'customer',
    senderMeta: {name: surface === 'admin' ? 'Alex' : 'You'},
    text,
    createdAt: new Date().toISOString()
  };
  store.setMessages([...store.getState().messages, message]);
}

/**
 * One shell owns surface sizing, header, thread and composer for every pattern.
 * @param {string} surface
 * @param {Object} store
 * @param {Object} strings
 * @param {Object} content
 * @param {Function} renderMessage
 * @param {Function} onSend
 * @param {Object} registry
 * @param {boolean} composerHidden
 * @param {string} title
 * @param {Object} headerStart
 * @param {Object} headerActions
 * @param {boolean} sheet
 * @param {string | null} status
 * @returns {Object}
 */
function patternShell({
  surface,
  store,
  strings = {header: 'Store assistant', message: 'Message', send: 'Send'},
  content,
  renderMessage,
  onSend,
  registry,
  title,
  headerStart,
  headerActions,
  status = 'online',
  sheet = false,
  composerHidden = false
}) {
  const size = widgetSize(surface);
  const mobileSheet = sheet && size.mobile;
  if (mobileSheet) {
    size.width = 'none';
    size.height = 'calc(100dvh - 12px)';
  }
  const toggle = (event, closed) => {
    const frame = event.currentTarget.closest('[data-pattern-frame]');
    const panel = frame.querySelector('chatty-surface');
    const launcher = frame.querySelector('[data-pattern-launcher]');
    panel.hidden = closed;
    frame.dataset.closed = String(closed);
    const background = frame.querySelector('[data-sheet-page]');
    if (background) background.inert = !closed && surface === 'ai-mode';
    launcher.hidden = !closed;
    if (closed) {
      launcher.style.insetBlockEnd = `${Math.max(surface === 'ai-mode' ? 40 : 16, frame.getBoundingClientRect().bottom - innerHeight + 20)}px`;
      launcher.focus({preventScroll: true});
    } else {
      const composer = panel.querySelector('chatty-composer');
      const input = !composer.hidden
        ? composer.renderRoot.querySelector('textarea')
        : (panel
            .querySelector('chatty-contact-form:not([hidden])')
            ?.renderRoot.querySelector('chatty-text-field') ??
          panel.querySelector('form chatty-text-field') ??
          panel.querySelector('[data-welcome-invitation]:not([hidden]) chatty-button') ??
          panel
            .querySelector('chatty-pre-chat:not([hidden])')
            ?.renderRoot.querySelector('chatty-button'));
      input?.focus({preventScroll: true});
    }
  };
  const sender = message => {
    const content = renderMessage?.(message) ?? {};
    const messages = store.getState().messages;
    const previous = messages[messages.indexOf(message) - 1];
    if (message.senderType !== 'bot' || sameGroup(message, previous)) return content;
    return {
      ...content,
      sender: html`<span style="display:inline-flex;align-items:center;gap:6px"
        ><chatty-avatar size="sm" label="Assistant">A</chatty-avatar
        >${content.sender ?? message.senderName ?? message.senderMeta?.name ?? 'Assistant'}</span
      >`
    };
  };
  return html`<style>
      [data-pattern-frame] {
        display: flex;
        position: relative;
        justify-content: center;
        inline-size: 100%;
        min-inline-size: 0;
      }
      [data-pattern-frame='classic'] {
        justify-content: flex-end;
      }
      [data-pattern-frame] chatty-surface::part(header) {
        padding: 0;
      }
      [data-pattern-frame='classic'] chatty-surface::part(header),
      [data-pattern-frame='ai-mode'] chatty-surface::part(header) {
        border-bottom-width: 0;
      }
      [data-pattern-frame] [hidden] {
        display: none !important;
      }
      [data-pattern-header] {
        display: flex;
        align-items: center;
        gap: 10px;
        box-sizing: border-box;
        min-inline-size: 0;
        block-size: 52px;
        padding: 0 16px;
      }
      [data-pattern-frame='classic'] [data-pattern-header] {
        block-size: 56px;
        background: var(--chatty-color-accent);
        color: var(--chatty-color-on-accent);
      }
      [data-pattern-frame='classic'] [data-pattern-header] chatty-icon-button {
        --chatty-color-border-focus: var(--chatty-color-on-accent);
      }
      [data-pattern-frame='admin'] [data-pattern-header] {
        block-size: 68px;
        padding: 8px 12px;
      }
      [data-pattern-header] chatty-avatar {
        --chatty-avatar-size: 32px;
      }
      [data-pattern-frame='classic'] [data-pattern-header] chatty-avatar {
        --chatty-avatar-background: #fff;
      }
      [data-pattern-frame='classic'] [data-pattern-header] chatty-avatar::part(base) {
        color: #303030;
        border: 1px solid #767676;
      }
      [data-pattern-actions] {
        display: flex;
        align-items: center;
        gap: 8px;
      }
      [data-pattern-title] {
        flex: 1;
        min-inline-size: 0;
        display: flex;
        flex-direction: column;
      }
      [data-pattern-frame='admin'] [data-pattern-title] {
        gap: 4px;
      }
      [data-pattern-frame='admin'] [data-pattern-title] strong {
        display: flex;
        align-items: center;
        min-block-size: 28px;
        font: var(--p-font-weight-semibold, 650) var(--p-text-heading-md-font-size, 14px) /
          var(--p-text-heading-md-font-line-height, 20px) var(--p-font-family-sans, system-ui);
      }
      [data-pattern-title] strong {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      [data-pattern-header] chatty-icon-button {
        --chatty-icon-button-size: 32px;
        --chatty-icon-button-color: currentColor;
      }
      @media (max-width: 899px), (pointer: coarse) {
        [data-pattern-header] chatty-icon-button {
          --chatty-icon-button-size: 44px;
        }
      }
      [data-pattern-launcher] {
        position: absolute;
        inset-inline-end: 0;
        inset-block-end: 0;
      }
      [data-pattern-frame='ai-mode'] [data-pattern-launcher] {
        inset-inline-end: auto;
        inset-inline-start: 50%;
        transform: translateX(-50%);
      }
      [data-pattern-frame='classic'] [data-pattern-launcher] {
        --chatty-icon-button-size: 56px;
        border-radius: 50%;
        background: var(--chatty-color-accent);
        --chatty-icon-button-color: var(--chatty-color-on-accent);
      }
      [data-sheet-mobile='true'] {
        position: fixed;
        inset: 0;
        inline-size: 100vw;
      }
      [data-sheet-mobile='true'] chatty-surface::part(base) {
        border-radius: 16px 16px 0 0;
      }
      [data-sheet-mobile='true'] chatty-surface {
        position: relative;
        z-index: 2;
        margin-block-start: 12px;
      }
      [data-sheet-page],
      [data-sheet-scrim] {
        position: absolute;
        inset: 0;
        box-sizing: border-box;
      }
      [data-sheet-page] {
        padding: 20px;
        background: var(--chatty-color-bg-surface);
        color: var(--chatty-color-text);
      }
      [data-sheet-scrim] {
        z-index: 1;
        border: 0;
        background: rgb(0 0 0 / 40%);
        animation: sheet-scrim 400ms ease;
      }
      [data-sheet-mobile='true'][data-closed='true'] [data-sheet-scrim] {
        display: none;
      }
      [data-sheet-mobile='true'] [data-pattern-launcher] {
        z-index: 3;
      }
      @keyframes sheet-scrim {
        from {
          opacity: 0;
        }
        to {
          opacity: 1;
        }
      }
      @media (prefers-reduced-motion: reduce) {
        [data-sheet-scrim] {
          animation: none;
        }
      }
    </style>
    <div
      data-pattern-frame=${surface}
      data-sheet-mobile=${String(mobileSheet)}
      data-closed="false"
      style=${`block-size:calc(${size.height} + ${mobileSheet ? 12 : 0}px)`}
    >
      ${
        mobileSheet
          ? html`<div data-sheet-page .inert=${surface === 'ai-mode'}>
                <p>Example storefront</p>
                <chatty-button
                  variant="secondary"
                  type="button"
                  @click=${event => {
                    event.currentTarget.textContent = 'Products opened';
                  }}
                >
                  Browse products
                </chatty-button>
              </div>
              ${surface === 'ai-mode' ? html`<button type="button" data-sheet-scrim tabindex="-1" aria-label="Close chat background" @click=${event => toggle(event, true)}></button>` : ''}`
          : ''
      }
      <chatty-surface
        data-chatty-surface=${surface}
        data-chatty-theme=${surface === 'admin' ? 'light' : (document.documentElement.dataset.chattyTheme ?? document.documentElement.dataset.theme ?? 'light')}
        style=${`inline-size:100%;max-inline-size:${mobileSheet ? 'none' : `${size.width}px`};--chatty-surface-height:${size.height}`}
        .store=${store}
        .registry=${registry ?? null}
        viewer-type=${surface === 'admin' ? 'agent' : 'customer'}
        .selfTypes=${surface === 'admin' ? ['agent', 'bot'] : null}
        .renderMessage=${sender}
      >
        <div slot="header" data-pattern-header>
          ${headerStart ?? ''}
          ${surface === 'admin' ? '' : html`<chatty-avatar label="Store" .status=${status}>S</chatty-avatar>`}
          <span data-pattern-title
            ><strong
              >${title ?? (surface === 'admin' ? 'Customer conversation' : strings.header)}</strong
            >${surface === 'admin' ? html`<chatty-badge size="sm" variant="secondary" style="align-self:flex-start">Customer</chatty-badge>` : status == null ? '' : html`<small data-pattern-status>${status === 'online' ? 'Open' : 'Closed'}</small>`}</span
          >
          <span data-pattern-actions>${headerActions ?? ''}</span>
          ${
            surface === 'admin'
              ? ''
              : html`<chatty-icon-button label="Close panel" @click=${event => toggle(event, true)}
                  >${IconClose()}</chatty-icon-button
                >`
          }
        </div>
        <chatty-thread .strings=${{bot: 'Assistant', ...strings}}></chatty-thread>${content ?? ''}
        <chatty-composer
          slot="footer"
          ?hidden=${composerHidden}
          .label=${strings.message}
          .sendLabel=${strings.send}
          @chatty-send=${event => {
            appendViewer(store, surface, event.detail.text);
            if (onSend) onSend(event.detail.text, event.currentTarget);
            else if (surface !== 'admin')
              store.setMessages([
                ...store.getState().messages,
                {
                  id: `fixture-${store.getState().messages.length}`,
                  senderType: 'bot',
                  text: `You asked: “${event.detail.text}”. I can help with that.`,
                  hasEventTime: false
                }
              ]);
          }}
        ></chatty-composer> </chatty-surface
      >${
        surface === 'admin'
          ? ''
          : surface === 'ai-mode'
            ? html`<chatty-launcher
                data-pattern-launcher
                hidden
                label="Open chat"
                @chatty-open=${event => toggle(event, false)}
                >${IconMessage({size: 20, slot: 'icon'})}Ask a question</chatty-launcher
              >`
            : html`<chatty-icon-button
                data-pattern-launcher
                hidden
                size="lg"
                label="Open chat"
                @click=${event => toggle(event, false)}
                >${IconMessage({size: 24})}</chatty-icon-button
              >`
      }
    </div>`;
}

import {createBlockRegistry} from '@avada/chatty-ui/behaviors/block-registry.js';
import '@avada/chatty-ui/elements/chatty-block-email-verify.js';
export function Standard({surface}) {
  const registry = createBlockRegistry({
    'email-verify': {tag: 'chatty-block-email-verify', wide: true}
  });
  const store = fixtureStore([
    question,
    {
      id: 'verify',
      senderType: 'bot',
      text: 'Please enter the email used for order #1001 so we can show its details.',
      blocks: [{type: 'email-verify', data: {number: '1001'}}]
    }
  ]);
  const update = data =>
    store.setMessages(
      store
        .getState()
        .messages.map(m =>
          m.id === 'verify'
            ? {...m, blocks: [{type: 'email-verify', data: {number: '1001', ...data}}]}
            : m
        )
    );
  return html`<div
    style="inline-size:100%;min-inline-size:0"
    @chatty-verify=${event => {
      update({loading: true});
      const finish = () => update({mismatch: true});
      if (matchMedia('(prefers-reduced-motion: reduce)').matches) finish();
      else setTimeout(finish, 450);
    }}
  >
    ${patternShell({surface, store, registry})}
  </div>`;
}
```

Email verify nằm trong tin bot; fixture luôn trả mismatch để kiểm sửa email và retry. Unlock order/rewards thật: N/A trong preview.

### Current

Example (Current (React), being replaced) — SmartLinkEmailForm thật của AI Mode, trạng thái ban đầu từ smartLinkOrderStore.

```jsx
import React, {useState} from 'react';
import SmartLinkEmailForm from '@scripttag/v1/Parts/SmartLinkOrder/SmartLinkEmailForm';
import {SmartLinkEmailForm as AiSmartLinkEmailForm} from '@scripttag/v2/components/ChatBlocks/SmartLinkEmailForm.jsx';
import {smartLinkOrderStore} from '@scripttag/v2/stores/smartLinkOrderStore.js';

export function AiEmail() {
  const [ready] = useState(() => seed(false));
  return ready ? <AiSmartLinkEmailForm number="1001" /> : null;
}
```

Example (Current (React), being replaced) — Cùng form với `isWrongEmail` bật trong store thật: lỗi email không khớp số đơn.

```jsx
import React, {useState} from 'react';
import SmartLinkEmailForm from '@scripttag/v1/Parts/SmartLinkOrder/SmartLinkEmailForm';
import {SmartLinkEmailForm as AiSmartLinkEmailForm} from '@scripttag/v2/components/ChatBlocks/SmartLinkEmailForm.jsx';
import {smartLinkOrderStore} from '@scripttag/v2/stores/smartLinkOrderStore.js';

export function AiEmailMismatch() {
  const [ready] = useState(() => seed(true));
  return ready ? <AiSmartLinkEmailForm number="1001" /> : null;
}
```

Example (Current (React), being replaced) — Form email thật của Classic; onSubmit cục bộ luôn báo sai email để thấy trạng thái lỗi.

```jsx
import React, {useState} from 'react';
import SmartLinkEmailForm from '@scripttag/v1/Parts/SmartLinkOrder/SmartLinkEmailForm';
import {SmartLinkEmailForm as AiSmartLinkEmailForm} from '@scripttag/v2/components/ChatBlocks/SmartLinkEmailForm.jsx';
import {smartLinkOrderStore} from '@scripttag/v2/stores/smartLinkOrderStore.js';

export function Email() {
  return (
    <SmartLinkEmailForm
      number="1001"
      placeholder="Email"
      label={(text, values = {}) => text.replace(/{{(\w+)}}/g, (_, key) => values[key])}
      onSubmit={async () => false}
    />
  );
}

// The store holds the verdict of the last email check; the story freezes it.
const seed = isWrongEmail => {
  smartLinkOrderStore.setState({status: 'form', number: '1001', isWrongEmail});
  return true;
};
```

## Classic

### Import / element

#### SmartLinkEmailForm

| Component / element | Import / file | Scope root |
| --- | --- | --- |
| `SmartLinkEmailForm` | import SmartLinkEmailForm from '@scripttag/v1/Parts/SmartLinkOrder/SmartLinkEmailForm'; | .Avada-Faqs_Popup |

### Anatomy

#### SmartLinkEmailForm

| Part | Element |
| --- | --- |
| 1 | Form `Avada-Faqs_SmartLink-Form`. |
| 2 | Input email với `aria-label`. |
| 3 | Lỗi sai email `role="alert"`, chỉ hiện sau khi submit thất bại. |
| 4 | Nút `submit`. |

### Placement / order

#### SmartLinkEmailForm

| Context | Order |
| --- | --- |
| Tin nhắn nhắc nhập email | Form được portal vào bubble của tin nhắn nhắc; thứ tự: lời nhắc, input, lỗi (nếu có), nút Submit. |

### Props

#### SmartLinkEmailForm

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `number` | string | Số đơn mà email phải khớp | Không có | Hiện trong lời nhắc và lỗi |
| `placeholder` | string | Chuỗi i18n Email input placeholder | Không có | Truyền từ hook |
| `label` | function | Hàm dịch có English fallback | Không có | Dùng cho aria-label và nút |
| `onSubmit` | function | Nhận email đã trim; trả true khi tìm thấy đơn | Không có | Sai thì form hiện lỗi |

### Sizes

#### SmartLinkEmailForm

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| input | Theo padding và role | `--chatty-space-250` / `--chatty-space-300` | `--chatty-space-200` bên dưới | 8px | `input-value`: Derived(15px = type(input-value, desktop, size)) / Derived(22px = type(input-value, desktop, line)) desktop, Derived(18px = type(input-value, mobile, size)) / Derived(24px = type(input-value, mobile, line)) mobile | Width 100% | Mobile theo class `.mobile` |
| button | Theo padding và role | `--chatty-space-250` / `--chatty-space-300` | — | 8px | `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 | Width 100% | Mobile theo class `.mobile` |
| error | Theo role | — | `--chatty-space-200` bên dưới | — | `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 phải điều khiển | Mobile theo class `.mobile` |

### Tokens

#### SmartLinkEmailForm

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Viền input | `--chatty-color-border` | #e3e3e3 | #ffffff17 |
| Nền input | `--chatty-color-bg-surface` | #fff | #1a1a1a |
| Chữ input | `--chatty-color-text` | #303030 | #eee |
| Nền nút | `--chatty-color-accent` | #303030 | #eee |
| Chữ nút | `--chatty-color-on-accent` | #fff | #1a1a1a |
| Nút disabled | `--chatty-color-text-disabled` | #767676 | #999 |
| Chữ lỗi | `--chatty-color-critical` | #c5280c | #ff9a8a |

### States

#### SmartLinkEmailForm

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Email chưa hợp lệ | Chuỗi không khớp regex | Nút disabled, nền `--chatty-color-text-disabled`, con trỏ mặc định. | `disabled` |
| Đang gửi | `loading` true | Nút disabled; form chờ `onSubmit`. | `disabled` |
| Sai email | `onSubmit` không tìm thấy đơn | Hiện lỗi; nút bật lại khi `loading` false. | `role="alert"` |
| Focus-visible | keyboard | Outline 2px `var(--chatty-ring)`, offset 2px. | Native focus |

### Behaviour

#### SmartLinkEmailForm

| Interaction | Result |
| --- | --- |
| Submit | `preventDefault`, gọi `onSubmit` với email đã trim. |
| Tìm thấy đơn | Phụ huynh thay form bằng thông tin đơn; form không tự cập nhật. |
| Enter | Form native nên Enter trong input gửi form. |

### Copy

#### SmartLinkEmailForm

| String | i18n key | Where |
| --- | --- | --- |
| Please enter the email used for order #{{order_number}} so we can show its details. | Please enter the email used for order #{{order_number}} so we can show its details. | Lời nhắc trong bubble |
| Email | Email | `aria-label` của input |
| Submit | Submit | Nút gửi |
| That email doesn't match order #{{order_number}}. Check the email you used when you ordered and try again. | That email doesn't match order #{{order_number}}. Check the email you used when you ordered and try again. | Lỗi sai email |

### Source

#### SmartLinkEmailForm

| File | Evidence |
| --- | --- |
|  | Form |
|  | Style form |
|  | Portal vào bubble |
|  | Điều kiện hiện form |

## AI Mode

### Import / element

#### SmartLinkEmailForm

| Component / element | Import / file | Scope root |
| --- | --- | --- |
| `SmartLinkEmailForm` | @scripttag/v2/components/ChatBlocks/SmartLinkEmailForm.jsx | .chatty-ai-mode[data-theme] |

### Anatomy

#### SmartLinkEmailForm

| Part | Element |
| --- | --- |
| 1 | `ChatFormCard` bao form. |
| 2 | `FormFields` với một `FormField` email, `wide`. |
| 3 | Lỗi `chatty-field-error` với `role="alert"` do FormField vẽ khi có `error`. |
| 4 | `FormActions` với nút accent `smart-link-email-submit`. |

### Placement / order

#### SmartLinkEmailForm

| Context | Order |
| --- | --- |
| Block `smartLinkEmailForm` trong thread | Card rộng hết lane; thứ tự: field email, nút Submit. |

### Props

#### SmartLinkEmailForm

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `number` | string | Số đơn mà email phải khớp | Không có | Chuyển vào `confirmOrderEmail` và thông báo lỗi |

### Sizes

#### SmartLinkEmailForm

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| card | Theo nội dung | 18px | 14px | `--radius-card` (20px) | Role theo field và nút | Card không phải điều khiển | Max-width 380px khi chỉ có một field; mobile `.is-mobile` đổi padding 15px, khoảng cách 12px |
| input | Theo padding và role | 11px / 13px | 5px giữa label và lỗi | `--radius-sm` (10px) | `body-large`: Derived(17px = type(body-large, desktop, size)) / Derived(24px = type(body-large, desktop, line)) desktop, Derived(19px = type(body-large, mobile, size)) / Derived(26px = type(body-large, mobile, line)) mobile | Width 100% | Role đổi theo `.is-mobile` |
| button | min-height 40px | 0 / 16px | — | `--radius-md` (14px) | `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 | Min-height 40px | `.is-mobile` đặt nút width 100% |

### Tokens

#### SmartLinkEmailForm

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Viền input | `--glass-edge` | rgba(20, 19, 24, 0.08) | rgba(255, 255, 255, 0.12) |
| Chữ input | `--vib-1` | rgba(20, 19, 24, 0.94) | rgba(255, 255, 255, 0.96) |
| Nút disabled | `--vib-3` | rgba(20, 19, 24, 0.62) | rgba(255, 255, 255, 0.62) |
| Lỗi | `--danger` | #ef4444 | #ef4444 |

### States

#### SmartLinkEmailForm

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Email chưa hợp lệ | `isEmail(email)` false | Nút disabled, nền `--vib-3`. | `disabled` |
| Đang gửi | `submitting` true | Class `is-loading`; nút disabled; field disabled. | `disabled` |
| Sai email | `isWrongEmail` true | Input `is-error` viền `--danger`; lỗi hiện dưới field. | `aria-invalid`; `role="alert"` |
| Focus input | keyboard | Viền `--accent`; halo `0 0 3px` qua `--focus-ring`. | Native focus |

### Behaviour

#### SmartLinkEmailForm

| Interaction | Result |
| --- | --- |
| Submit | Nút hoặc Enter trong field gọi `confirmOrderEmail({number, email})`. |
| Kết thúc | `submitting` về false trong `finally`. |

### Copy

#### SmartLinkEmailForm

| String | i18n key | Where |
| --- | --- | --- |
| Email input placeholder | Email input placeholder | Placeholder của field |
| Smart link order email mismatch | Smart link order email mismatch | Lỗi sai email, nhận `number` |
| Submit | Submit | Nút gửi |

### Source

#### SmartLinkEmailForm

| File | Evidence |
| --- | --- |
|  | Form |
|  | Card form dùng chung |
|  | Field và lỗi |

## Do / Don't

Do: nêu rõ email cần nhập là email đã dùng khi đặt đơn.

Don't: coi form pre-chat là bằng chứng đã xác thực đơn.

## Accessibility

| Surface | Role / name | Keyboard / focus | Live region | Contrast pair / ratio |
| --- | --- | --- | --- | --- |
| Classic | Input có `aria-label`; nút `submit` | Form native; Enter gửi; focus ring theo States | `role="alert"` cho lỗi sai email | Nút: Light Measured(#ffffff / #303030 = 13.20:1); Dark Measured(#1a1a1a / #eeeeee = 15.00:1). Lỗi: Light Measured(#c5280c / #ffffff = 5.70:1); Dark Measured(#ff9a8a / #1a1a1a = 8.49:1) |
| AI Mode | Field có `aria-invalid` khi lỗi; nút `button` | Enter trong field gửi; focus input theo States | `role="alert"` cho lỗi sai email | Không đo ở trang này: nền field lấy từ token fill của AI Mode |

## Target

```target
| Surface | Now | Target |
| --- | --- | --- |
| Classic | Input dùng `--chatty-form-border` ở các form khác nhưng form này dùng `--chatty-color-border` | Not in code yet — build with the body values. Target: đổi viền input sang `--chatty-form-border` để khớp mọi field khác của Classic. |
```

