# Resting launcher

Nút mở panel AI Mode dùng chung markup cho cold và full app.

## Key rules

- Launcher gọi action do caller truyền.
- Element `chatty-launcher` ở 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

Mở panel hoặc giỏ từ trạng thái resting.

### Use instead

| Component | Use when |
| --- | --- |
| `LauncherChrome` | Mở panel hoặc giỏ từ trạng thái resting. |
| `RestingSearchBar` | Caller sở hữu tương tác liên quan. |

## Live preview

Example (Standard) — Pill resting có chấm online, và pill có nút giỏ với badge số món.

```html
<chatty-launcher label="Open Chatty" live>
  <svg slot="icon" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
    <path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z" />
  </svg>
  Ask a question
</chatty-launcher>
<chatty-launcher label="Open Chatty" bag count="2">
  <svg slot="icon" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
    <path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z" />
  </svg>
  Ask a question
  <svg
    slot="bag-icon"
    viewBox="0 0 24 24"
    fill="none"
    stroke="currentColor"
    stroke-width="1.8"
    aria-hidden="true"
  >
    <path d="M5 8h14l-1 12H6zM9 8a3 3 0 0 1 6 0" />
  </svg>
</chatty-launcher>
```

Example (Current (React), being replaced) — Launcher thật với hành động cục bộ.

```jsx
import React from 'react';
import {LauncherChrome} from '@scripttag/v2/components/LauncherChrome.jsx';
import {ButtonIcon} from '@scripttag/v2/icons/buttonIcon.jsx';
import IconBag from '@scripttag/v2/icons/IconBag.jsx';
import {SearchPlaceholder} from '@scripttag/v2/components/SearchBar/SearchPlaceholder.jsx';
import '@scripttag/v2/styles/glass.scss';
import '@scripttag/v2/components/SearchBar/SearchBar.scss';

// The resting skin hangs off `.chatty-ai-mode.state-resting` (and the bag off `.has-bag`), which
// AIModeWidgetRoot sets on the widget root; the frame root has neither, so the story adds them.
const resting = node => node?.closest('[data-surface]')?.classList.add('state-resting', 'has-bag');

export function Resting() {
  return <div ref={resting}>
    <LauncherChrome assistantName="Chatty" invitePhrases={['Ask a question']} actions={{loadPanel: () => {}, openPanel: () => {}}} bagCount={0} Icon={ButtonIcon} BagIcon={IconBag} Placeholder={SearchPlaceholder} />
  </div>;
}
```

## Standard

Example (Standard) — Pill resting có chấm online, và pill có nút giỏ với badge số món.

```html
<chatty-launcher label="Open Chatty" live>
  <svg slot="icon" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
    <path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z" />
  </svg>
  Ask a question
</chatty-launcher>
<chatty-launcher label="Open Chatty" bag count="2">
  <svg slot="icon" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
    <path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z" />
  </svg>
  Ask a question
  <svg
    slot="bag-icon"
    viewBox="0 0 24 24"
    fill="none"
    stroke="currentColor"
    stroke-width="1.8"
    aria-hidden="true"
  >
    <path d="M5 8h14l-1 12H6zM9 8a3 3 0 0 1 6 0" />
  </svg>
</chatty-launcher>
```

Prototype  (cùng `launcher.styles.js`) là chuẩn: chatty-ui port 1:1, và `chatty-ui/custom-elements.json` sinh từ chính prototype. Trigger mở panel và nút giỏ là hai button anh em (React lồng button trong role button). Icon trợ lý, icon giỏ và câu mời đi qua slot. 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-launcher` | @avada/chatty-ui/elements/launcher.js |

### API

| Kind | Name | Type | Default | Description |
| --- | --- | --- | --- | --- |
| attribute | `label` | string | `''` | Tên truy cập của trigger, ví dụ Open Chatty. |
| attribute | `bag` | boolean | `false` | Hiện nút giỏ; giỏ xác nhận rỗng thì bỏ. |
| attribute | `count` | number | `0` | Số món trong giỏ; badge hiện khi lớn hơn 0 và có trần hiển thị. |
| attribute | `bag-label` | string | `'Shopping bag'` | Tên nút giỏ khi count bằng 0. |
| attribute | `count-label` | string | `'{count} items in cart'` | Tên nút giỏ khi count lớn hơn 0; `{count}` được thay. |
| attribute | `live` | boolean | `false` | Chấm online trên orb. |
| event | `chatty-open` | CustomEvent<{target: 'panel' , 'bag'}> | – | Trigger (target panel) hoặc nút giỏ (target bag) được kích hoạt. |
| event | `chatty-preload` | CustomEvent<{}> | – | Lần đầu rê chuột vào hoặc focus; host tải panel trước. |
| event | `click` | MouseEvent | – | Kích hoạt native của trigger hoặc nút giỏ. |
| slot | default | – | – | Câu mời, ví dụ Ask a question. |
| slot | `icon` | – | – | Icon trợ lý trong orb. |
| slot | `bag-icon` | – | – | Icon giỏ. |
| part | `base` | – | – | Khung pill. |
| part | `trigger` | – | – | Button mở panel; vùng bấm phủ cả pill trừ nút giỏ. |
| part | `orb` | – | – | Orb trợ lý. |
| part | `bag` | – | – | Nút giỏ. |
| part | `count` | – | – | Badge số món. |
| css-property | `--chatty-launcher-width` | – | – | Bề rộng pill. |
| css-property | `--chatty-launcher-background` | – | – | Nền pill. |

## AI Mode

### Import / element

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

### Anatomy

| Part | Element |
| --- | --- |
| 1 | Trigger, icon, placeholder và nút giỏ. |

### Placement / order

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

### Props

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `assistantName` | string | Tên trợ lý | Caller | Dùng trong nhãn mở panel. |
| `preview` | boolean | true, false | false | Bản xem tĩnh cho preview preset ở admin: trigger không role, nhãn, handler; giỏ là span. |

### Sizes

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Component | Theo caller | Theo caller | Theo caller | Theo caller | Theo caller | Nút native và trigger | Style từ SearchBar |

### Tokens

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Nền | Theo scope | Theo scope | Theo scope |

### States

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Giỏ có hàng | bagCount lớn hơn 0 | Hiện badge số lượng. | aria-label theo số lượng |

### Behaviour

| Interaction | Result |
| --- | --- |
| Mở panel | Click trigger gọi action; click nút giỏ truyền bag. |
| Cold takeover | Khi full app đã sẵn sàng, chuyển lại biến và focus cho panel tương ứng. |
| Cold icon | Icon upload dùng ảnh; nếu không thì dùng Glyph do caller truyền. |

### Copy

| String | i18n key | Where |
| --- | --- | --- |
| Shopping bag | Shopping bag | Nhãn giỏ 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 |
| --- | --- | --- | --- | --- |
| AI Mode | Trigger role button có tên; nút giỏ có aria-label | Caller xử lý phím cho trigger; giỏ là nút native, trừ bản preview | Không có live region | Theo scope |

## Target

```target
| Surface | Now | Target | Source |
| --- | --- | --- | --- |
| AI Mode | Markup React dùng chung cho cold và full app | Not available — new build follows Target. Launcher thuộc gốc surface `chatty-ai-mode` (dự kiến); host giữ `#chatty-ai-mode-root` và `.chatty-ai-mode` ở light DOM để `customCss` chỉnh vị trí vẫn ăn. | [MDN: Web Components](https://developer.mozilla.org/en-US/docs/Web/API/Web_components) |
| AI Mode | Component React theo surface | Not available — new build follows Target. Port `chatty-launcher` 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)
