# chatty-voice-player

API chuẩn của element chatty-voice-player, sinh từ custom-elements.json của prototype trong guide.

## Key rules

- `chatty-voice-player` khai báo 3 attribute, 1 property không có attribute, 3 event, 1 slot, 6 part và 4 CSS custom property.
- Import 1 module `@avada/chatty-ui/elements/voice-player.js` là define `chatty-voice-player`; chunk chỉ import element nó dùng. Prototype chuẩn:  trong guide.
- Đổi tên attribute, event, slot, part hay CSS custom property là đổi API: diff của custom-elements.json phải có trong 1 MR.

## Overview

Voice message player: play/pause, seek track, time, playback speed and an optional download link. Arrow Left/Right on the track seek 5 seconds; Space or Enter toggles playback. Class `ChattyVoicePlayer`.

### Attributes

| Name | Property | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `src` | `src` | `string` | `''` | Validated audio URL; empty disables the controls. |
| `duration` | `duration` | `number` | `0` | Placeholder length in seconds until the audio reports its own. |
| `download` | `download` | `string` | `''` | File name; when set and `src` is present, a download link is shown. |

### Properties

Attributes also expose the properties listed in the Property column above.

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `strings` | `Partial<typeof STRINGS>` | `{}` | translated labels; English by default. |

### Events

| Name | Detail type | Description |
| --- | --- | --- |
| `play` | `Event` | Playback started. |
| `pause` | `Event` | Playback paused or ended. |
| `click` | `MouseEvent` | Native activation of a control. |

### Slots

| Name | Description |
| --- | --- |
| `download-icon` | Icon of the download link. |

### Parts

| Name | Description |
| --- | --- |
| `base` | Player row. |
| `play` | Play/pause button. |
| `track` | Seek track wrapper. |
| `time` | Elapsed / duration text. |
| `speed` | Playback speed button. |
| `download` | Download link. |

### CSS custom properties

| Name | Default | Description |
| --- | --- | --- |
| `--chatty-voice-player-background` | – | Background. |
| `--chatty-voice-player-color` | – | Icon and text colour. |
| `--chatty-voice-player-border-color` | – | Border colour. |
| `--chatty-voice-player-track` | – | Unplayed track colour; keep 3:1 against the background. |

## Usage

```js
import '@avada/chatty-ui/tokens/tokens.css';
import '@avada/chatty-ui/elements/voice-player.js';
```

```html
<chatty-voice-player duration="42" download="voice-message.mp3" style="width: 320px">
  <svg
    slot="download-icon"
    viewBox="0 0 24 24"
    fill="none"
    stroke="currentColor"
    stroke-width="2"
    aria-hidden="true"
  >
    <path d="M12 4v11m-5-5 5 5 5-5M5 20h14" />
  </svg>
</chatty-voice-player>
```

## Live preview

Component thật dùng cùng story với trang component; dữ liệu mẫu nằm trong frame cục bộ.

Example (Standard) — Default: trạng thái mặc định và nội dung mẫu của element.

```html
<chatty-voice-player duration="42" download="voice-message.mp3" style="width: 320px">
  <svg
    slot="download-icon"
    viewBox="0 0 24 24"
    fill="none"
    stroke="currentColor"
    stroke-width="2"
    aria-hidden="true"
  >
    <path d="M12 4v11m-5-5 5 5 5-5M5 20h14" />
  </svg>
</chatty-voice-player>
```

## Anatomy

Số trong hình khớp bảng bên dưới. Phần chỉ hiện ở state khác được ghi Not shown; ví dụ không thêm phần tử giả.

Example (Standard) — Anatomy: một instance mặc định riêng, có khoảng trống quanh các phần được đánh số.

```html
<chatty-voice-player duration="42" download="voice-message.mp3" style="width: 320px">
  <svg
    slot="download-icon"
    viewBox="0 0 24 24"
    fill="none"
    stroke="currentColor"
    stroke-width="2"
    aria-hidden="true"
  >
    <path d="M12 4v11m-5-5 5 5 5-5M5 20h14" />
  </svg>
</chatty-voice-player>
```

| Part | Element | Source |
| --- | --- | --- |
| 1 | CSS part `base` | chatty-ui/custom-elements.json |
| 2 | CSS part `play` | chatty-ui/custom-elements.json |
| 3 | CSS part `track` | chatty-ui/custom-elements.json |
| 4 | CSS part `time` | chatty-ui/custom-elements.json |
| 5 | CSS part `speed` | chatty-ui/custom-elements.json |
| 6 | CSS part `download` | chatty-ui/custom-elements.json |

## Keyboard

| Key | Action |
| --- | --- |
| Enter / Space | Toggle playback on the seek track or activate a control. |
| ArrowLeft / ArrowRight | Seek backward / forward five seconds. |

### Source

- chatty-ui/custom-elements.json
