# Welcome / first open

Lời chào và starter trong lần mở chat đầu, theo code AI Mode đang chạy.

## Key rules

- Starter dùng `CommonlyAskedSection`: ở hub Home và ngay dưới welcome bubble khi thread còn trống.
- Mỗi starter là một row cao tối thiểu 32px, bo `--radius-pill`, chữ `button-label`.
- Starter đã được trả lời bị loại khỏi danh sách; không còn starter thì không render section.
- Starter có answer của merchant trả lời bằng copy đó; không có answer thì gửi như một lượt hỏi AI.

## Use when / Avoid

Dùng cho lúc khách chưa gửi tin nào: lời chào của merchant cộng với các câu hỏi gợi ý. Câu hỏi gợi ý sau một câu trả lời thuộc về pattern Suggested questions. Classic không có implementation tương ứng trong source nên không nằm trong trang này.

### Use instead

| Component | Use when |
| --- | --- |
| `CommonlyAskedSection` | Starter ở hub Home theo cấu hình sectionsOrder. |
| `CommonlyAskedSection` | Starter dưới welcome bubble khi thread còn ở trạng thái mở đầu. |

## Entry points

| Surface | Owner |
| --- | --- |
| AI Mode | `CommonlyAskedSection` do `HomePage` ghép khi `suggestionFAQs` có phần tử. |
| AI Mode | `CommonlyAskedSection` do `ChatThread` ghép sau welcome bubble khi `isOpening`. |

## Flow

| Surface | Step | Trigger | UI shown | Component | Copy + i18n key | Timing |
| --- | --- | --- | --- | --- | --- | --- |
| AI Mode | Hub Home | Panel mở, `suggestionFAQs` không rỗng | Label Commonly Asked và các row starter | `CommonlyAskedSection` | Commonly Asked / Commonly Asked | Theo vòng render của caller |
| AI Mode | Thread mở đầu | Có welcome bubble và `isOpening` | Welcome bubble rồi các row starter | `CommonlyAskedSection` | Commonly Asked / Commonly Asked | Theo vòng render của caller |
| AI Mode | Khách chưa có thông tin liên hệ | `preForm?.mode` là guest | Pre-chat nudge, câu hỏi giữ trong `quickReply` | `CommonlyAskedSection` | Not available | Khi click |
| AI Mode | Starter có answer | Click, `answer` có giá trị | Copy của merchant được trả qua `answerQuickReply` | `CommonlyAskedSection` | Copy do merchant viết | Khi click |
| AI Mode | Starter không có answer | Click, `answer` trống | Gửi như lượt hỏi AI qua `deliverTurn` | `CommonlyAskedSection` | Copy do merchant viết | Khi click |

## Edge cases

| Surface | Case | Behaviour |
| --- | --- | --- |
| AI Mode | Không có starter | Hub Home không render section khi `suggestionFAQs` rỗng |
| AI Mode | Mọi starter đã trả lời | Section trả về null sau khi lọc `excludeQuestions` |
| AI Mode | Click khi lượt trước còn chạy | Bị bỏ qua và không tracking, row không có trạng thái disabled |
| AI Mode | Entry cũ không có answer | Rơi về lượt hỏi AI thay vì đọc FAQ |

## Live preview

Hub Home, merchant answer, AI answer và pre-chat guest đều dùng fixture local; có thể tiếp tục bằng email hoặc Chat anonymously, không gọi API.

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

### Standard

Example (Standard) — Widget thread Standard; tương tác bằng dữ liệu fixture.

```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 '@avada/chatty-ui/elements/chatty-block-suggestions.js';
import '@avada/chatty-ui/elements/pre-chat.js';
import '@avada/chatty-ui/elements/contact-form.js';
export function Standard({surface}) {
  const store = fixtureStore([
    {id: 'welcome', senderType: 'bot', text: 'Hi! How can we help today?'}
  ]);
  let remaining = [
    {
      id: 'delivery',
      question: 'When will my order arrive?',
      answer: 'Orders arrive in 3–5 business days.'
    },
    {id: 'material', question: 'What is the tote made of?', answer: ''}
  ];
  let contactKnown = false;
  let pending = null;
  const busy = () =>
    store
      .getState()
      .messages.some(
        message =>
          message.status === 'streaming' ||
          message.blocks?.some(block => ['loading', 'reasoning'].includes(block.type))
      );
  const commit = (faq, owner) => {
    if (!faq || busy()) return;
    store.setMessages([
      ...store.getState().messages,
      {
        id: `answer-${faq.id}`,
        senderType: 'bot',
        text: faq.answer || `You asked: “${faq.question}”. The tote uses sturdy cotton canvas.`
      }
    ]);
    owner.querySelector('chatty-contact-form').hidden = true;
    owner.querySelector('[data-welcome-invitation]').hidden = true;
    const invitation = owner.querySelector('chatty-pre-chat');
    invitation.hidden = !invitation.email;
    const composer = owner.querySelector('chatty-composer');
    composer.hidden = false;
    composer.renderRoot.querySelector('textarea').focus({preventScroll: true});
    pending = null;
  };
  const accept = (event, email = '') => {
    const owner = event.currentTarget.closest('[data-welcome]');
    contactKnown = true;
    owner.querySelector('chatty-pre-chat').email = email;
    commit(pending, owner);
  };
  return html`<div data-welcome style="inline-size:100%;min-inline-size:0">
    <style>
      [data-welcome] chatty-block-suggestions {
        --chatty-button-height: 32px;
      }
      [data-welcome-invitation] chatty-button[variant='secondary'] {
        --chatty-button-secondary-bg: transparent;
        --chatty-button-secondary-border: var(--chatty-color-border);
        --chatty-button-radius: 8px;
      }
      @media (max-width: 899px), (pointer: coarse) {
        [data-welcome-invitation] chatty-button,
        [data-welcome] chatty-block-suggestions {
          --chatty-button-height: 44px;
        }
      }
    </style>
    ${patternShell({
      surface,
      store,
      title: 'Example store',
      content: html`
        <section aria-label="Hub Home" data-starters style="display:grid;gap:8px;margin-block:16px">
          <h2 style="font:inherit;font-weight:600;margin:0">Commonly Asked</h2>
          <chatty-block-suggestions
            .block=${{data: {layout: 'row', suggestions: remaining.map(item => item.question)}}}
            @chatty-suggest=${event => {
              if (busy() || pending) return;
              const faq = remaining.find(item => item.question === event.detail.text);
              if (!faq) return;
              const owner = event.currentTarget.closest('[data-welcome]');
              remaining = remaining.filter(item => item !== faq);
              const section = owner.querySelector('[data-starters]');
              if (remaining.length)
                event.currentTarget.block = {
                  data: {layout: 'row', suggestions: remaining.map(item => item.question)}
                };
              else section.remove();
              appendViewer(store, surface, faq.question);
              if (contactKnown) {
                commit(faq, owner);
                return;
              }
              pending = faq;
              const invitation = owner.querySelector('[data-welcome-invitation]');
              invitation.hidden = false;
              invitation.querySelector('chatty-button').focus({preventScroll: true});
              owner.querySelector('chatty-composer').hidden = true;
            }}
          ></chatty-block-suggestions>
        </section>
        <section data-welcome-invitation hidden style="display:grid;gap:12px;margin-block:16px">
          <p style="margin:0">Please enter your email to stay updated with our replies</p>
          <chatty-button
            variant="primary"
            @click=${event => {
              const owner = event.currentTarget.closest('[data-welcome]');
              owner.querySelector('[data-welcome-invitation]').hidden = true;
              const form = owner.querySelector('chatty-contact-form');
              form.hidden = false;
              form.renderRoot.querySelector('chatty-text-field').focus({preventScroll: true});
            }}
            >Get replies by email</chatty-button
          >
          <chatty-button variant="secondary" @click=${event => accept(event)}
            >Chat anonymously</chatty-button
          >
        </section>
        <chatty-pre-chat hidden></chatty-pre-chat>
        <chatty-contact-form
          hidden
          skippable
          description="Where can we reply?"
          @chatty-submit=${event => accept(event, event.detail.values.email)}
          @chatty-skip=${event => accept(event)}
        ></chatty-contact-form>
      `
    })}
  </div>`;
}
```

### Current

Example (Current (React), being replaced) — `CommonlyAskedSection` thật với 3 starter cố định; dữ liệu cục bộ, không gọi mạng.

```jsx
import {useContext} from 'react';

/**
 * Conversation starters, minus the ones already answered in this thread — classic filters the
 * same list on conversation.excludeQuestions so a clicked starter stops being offered.
 * @param {Array<{questionId: string, question: string, answer: string}>} faqs
 */
export function CommonlyAskedSection({faqs}) {
  const {excludeQuestions} = useChatStore(['excludeQuestions']);
  const remaining = faqs.filter(faq => !excludeQuestions?.includes(faq.questionId));
  // The onboarding preview starts from the composer, so it offers no starter list.
  if (!remaining.length || getRuntimeHost()?.hideConversationStarters) return null;
  return (
    <div className="chatty-section chatty-suggested-section">
      <div className="chatty-label">{t('Commonly Asked')}</div>
      {remaining.map(faq => (
        <ListRow
          key={faq.questionId}
          questionId={faq.questionId}
          text={faq.question}
          answer={faq.answer}
        />
      ))}
    </div>
  );
}

/**
 * A Commonly Asked chip — classic's conversation starter; the merchant writes the answer next to the question, so clicking replies with that copy rather than asking the AI, and entries with no answer fall back to a normal AI turn.
 * @param {string} questionId
 * @param {string} text
 * @param {string} answer merchant-authored answer copy, absent on older entries
 */
function ListRow({questionId, text, answer}) {
  const navigate = useChatNavigate();
  const surface = useContext(ChatSurfaceContext);
  const ask = async () => {
    let {preForm} = chatStore.getState();
    if (!preForm) {
      if (!canSendMessage(chatStore.getState())) return;
      await chatActions.showPreChatGate();
      ({preForm} = chatStore.getState());
    }
    if (preForm?.mode === 'guest') {
      chatStore.setState({
        preForm: {...preForm, quickReply: {questionId, question: text, answer}, navigate}
      });
      return chatActions.nudgePreForm({navigate, surface});
    }
    // This row has no disabled state, so a click during a streaming turn is silently dropped —
    // tracking first would credit the chip with a turn that never left.
    if (!canSendMessage(chatStore.getState())) return;
    markLauncherEngaged();
    trackEndCustomerEvent('quick_reply_click', {
      chip_type: 'conversation_starter',
      question_id: questionId,
      question: text
    });
    // Only the answered branch is a FAQ read; the other becomes an AI turn and would inflate the report.
    // The chip's own copy, not the shopper's words, so it stays out of send_message like classic's starters.
    if (!answer)
      return chatActions.deliverTurn(text, {entryPoint: EVENT_ENTRY_POINT.QUICK_REPLY, navigate});
    return chatActions.answerQuickReply({questionId, question: text, answer, navigate});
  };
  return (
    <button
      type="button"
      className="chatty-list-row chatty-suggested-question"
      data-query={text}
      onClick={ask}
    >
      <span>{text}</span>
    </button>
  );
}
```

Example (Current (React), being replaced) — `ChatThread` thật ở trạng thái mở đầu: welcome bubble rồi các starter.

```jsx
import {CommonlyAskedSection} from '../components/CommonlyAskedSection.jsx';

        {welcomeBubble && isOpening && <CommonlyAskedSection faqs={suggestionFAQs} />}
```

## AI Mode

### Import / element

#### CommonlyAskedSection

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

### Anatomy

#### CommonlyAskedSection

| Part | Element |
| --- | --- |
| 1 | Label `chatty-label` phía trên các row. |
| 2 | Row `chatty-list-row` + `chatty-suggested-question`, chữ là câu hỏi của starter. |

### Placement / order

#### CommonlyAskedSection

| Context | Order |
| --- | --- |
| Hub Home | Theo thứ tự `sectionsOrder`; không render khi `suggestionFAQs` rỗng. |
| Thread mở đầu | Ngay sau welcome bubble, chỉ khi `isOpening`. |
| Section | Label rồi các row, xếp cột, căn đầu dòng. |

### Props

#### CommonlyAskedSection

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `faqs` | array | {questionId, question, answer} | Caller truyền | Danh sách bị lọc theo `excludeQuestions`; rỗng thì trả về null. |
| `answer` | string | Copy merchant viết | Không có ở entry cũ | Có giá trị thì trả bằng `answerQuickReply`; trống thì gửi lượt AI. |

### Sizes

#### CommonlyAskedSection

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Row | min-height 32px | 5px 12px; mobile 10px theo block | 8px giữa các row | 30px via `--radius-pill` | `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, mobile min-height 44px | Mobile và pointer coarse tăng target |

### Tokens

#### CommonlyAskedSection

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Chữ row | `--vib-2` | rgba(20,19,24,0.74) | rgba(255,255,255,0.74) |
| Viền row | `--glass-edge` | rgba(20,19,24,0.08) | rgba(255,255,255,0.12) |
| Fill hover | `--fill-hover` | rgba(20,19,24,0.1) dưới 900px; rgba(255,255,255,0.92) từ min-width 900px | rgba(255,255,255,0.14) |
| Viền hover | `--vib-3` | rgba(20,19,24,0.62) | rgba(255,255,255,0.62) |
| Focus ring | `--focus-ring` | color-mix(in srgb, var(--accent) 25%, transparent) | Same |
| Bo góc | `--radius-pill` | 30px | Same |

### States

#### CommonlyAskedSection

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Rest | Row hiển thị | Viền 1px `--glass-edge`, chữ `--vib-2`, nền trong suốt | Native button |
| Hover | Con trỏ | Nền `--fill-hover`, viền `--vib-3` | Không thêm ARIA |
| Focus-visible | Bàn phím | Outline 2px solid `--focus-ring`, `outline-offset` 2px | Native focus |
| Disabled | Not available | Not available; row không có trạng thái disabled | Not available |

### Behaviour

#### CommonlyAskedSection

| Interaction | Result |
| --- | --- |
| Click khi chưa có pre-chat | `nudgePreForm` mở pre-chat với `quickReply` giữ câu hỏi. |
| Click có answer | `answerQuickReply` trả copy của merchant, không hỏi AI. |
| Click không có answer | `deliverTurn` gửi câu hỏi như lượt AI. |
| Tracking | `quick_reply_click` với chip_type conversation_starter, chỉ sau khi chắc chắn gửi được. |
| Bàn phím | Button native kích hoạt bằng Enter hoặc Space. |

### Copy

#### CommonlyAskedSection

| String | i18n key | Where |
| --- | --- | --- |
| Commonly Asked | Commonly Asked | Label của section qua `t` |
| Câu hỏi starter | Merchant-owned | Trường `question` của mỗi entry |
| Welcome message by chatbot | Welcome message by chatbot | Lời chào AI do merchant cấu hình `welcomeMessage` |
| Welcome back, {{name}} | Welcome back, {{name}} | `HomeGreeting` cho khách đã đăng nhập hoặc đã verify |

### Source

#### CommonlyAskedSection

| File | Evidence |
| --- | --- |
|  | Section, row và click flow |
|  | Section layout và hover |
|  | Row material, size và focus |
|  | Vị trí trong thread mở đầu |
|  | Vị trí ở hub Home |

## Do / Don't

Do: dùng starter ngắn gửi được ngay, đúng với nội dung merchant sẵn sàng trả lời.

Don't: tự dựng danh sách starter riêng ngoài `CommonlyAskedSection` hoặc giữ starter đã được trả lời.

## Accessibility

| Surface | Role / name | Keyboard / focus | Live region | Contrast pair / ratio |
| --- | --- | --- | --- | --- |
| AI Mode | Native button; tên accessible là câu hỏi của starter | Tab tới row, Enter/Space theo button native; `ask` không gọi hàm focus nào nên focus ở lại row; outline 2px | Not available; section không có live region | Light Measured(rgba(20,19,24,0.74) / #f6f4f0 = 7.58:1); Dark Measured(rgba(255,255,255,0.74) / #131215 = 10.42:1) |


-  .chatty-suggested-question
