# Answer error

Thông báo lỗi an toàn cho khách và hành động Retry do host xử lý.

## Key rules

- Element prototype là chuẩn để chatty-ui port theo.
- Host giữ dữ liệu, dịch nhãn và xử lý event; preview chỉ dùng dữ liệu cục bộ.

## Use when / Avoid

Dùng trong cuộc trò chuyện. Tránh nối trực tiếp element với API của shop.

### Use instead

| Component | Use when |
| --- | --- |
| `AnswerError` | Implementation React đang chạy. |
| Element prototype | Consumer chuyển sang custom element. |

## Live preview

Example (Current (React), being replaced) — Component React thật; dữ liệu fixture, không gửi request.

```jsx
import React, {useState} from 'react';
import {AnswerError} from '@avada/chatty-ui/canonical/AnswerError.jsx';

export function Retry({surface}) {
  const [retried, setRetried] = useState(false);
  return (
    <div className={surface === 'classic' ? 'Avada-Faqs__ChatMessages-Container--v2' : undefined}>
      <AnswerError t={text => text} onRetry={() => setRetried(true)} />
      {retried && <p role="status">Retry requested locally.</p>}
    </div>
  );
}
```

Example (Current (React), being replaced) — Component React thật; dữ liệu fixture, không gửi request.

```jsx
import React, {useState} from 'react';
import {AnswerError} from '@avada/chatty-ui/canonical/AnswerError.jsx';

export function Retry({surface}) {
  const [retried, setRetried] = useState(false);
  return (
    <div className={surface === 'classic' ? 'Avada-Faqs__ChatMessages-Container--v2' : undefined}>
      <AnswerError t={text => text} onRetry={() => setRetried(true)} />
      {retried && <p role="status">Retry requested locally.</p>}
    </div>
  );
}
```

## Standard

Example (Standard) — Element prototype với token trung tính.

```html
<chatty-answer-error></chatty-answer-error> 
```

Admin chỉ dùng trong inbox và chỉ light; admin-dark là N/A. Surface chưa có React tương ứng ghi Not available bên dưới.

### Element

| Element | Module |
| --- | --- |
| `chatty-answer-error` | @avada/chatty-ui/elements/answer-error.js |

### API

| Kind | Name | Type | Default | Description |
| --- | --- | --- | --- | --- |
| attribute | `label` | string | `'Something went wrong while preparing the answer.'` | Translated safe error message. |
| attribute | `retry-label` | string | `'Try again'` | Translated retry action. |
| attribute | `disabled` | boolean | `false` | Prevents a duplicate retry while pending. |
| event | `chatty-retry` | CustomEvent<{}> | Not available | Requests another answer attempt. |
| event | `click` | MouseEvent | Not available | Native retry button click. |
| part | `base` | Not available | Not available | Error alert. |
| part | `retry` | Not available | Not available | Retry button. |

## Classic

Token values dưới đây là fallback cục bộ; theme của caller có thể override.

### Import / element

| Component / element | Import / file | Scope root |
| --- | --- | --- |
| `AnswerError` | @avada/chatty-ui/canonical/AnswerError.jsx | AnswerError |

### Anatomy

| Part | Element |
| --- | --- |
| 1 | AnswerError |

### Placement / order

| Context | Order |
| --- | --- |
| Conversation | Caller supplies surrounding content |

### Props

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `onRetry` | See source | Caller supplied | See source | Retry callback |

### Sizes

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Retry base | min-height 44px | 12px | 6px | 999px | button-label | 44px | Base CSS; caller may override |

### Tokens

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Error text | `--chatty-contact-muted` | Fallback #6b6b6b | Fallback #6b6b6b |
| Retry ink | `--chatty-contact-fg` | Fallback #1f1f1f | Fallback #1f1f1f |

### States

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Error | Answer fails | Error label and Retry visible | role alert |

### Behaviour

| Interaction | Result |
| --- | --- |
| Retry | Calls onRetry |

### Copy

| String | i18n key | Where |
| --- | --- | --- |
| Caller translated | Not available | AnswerError |

### Source

| File | Evidence |
| --- | --- |
|  | Owning React implementation. |

## AI Mode

Token values dưới đây là fallback cục bộ; theme của caller có thể override.

### Import / element

| Component / element | Import / file | Scope root |
| --- | --- | --- |
| `AnswerError` | @avada/chatty-ui/canonical/AnswerError.jsx | AnswerError |

### Anatomy

| Part | Element |
| --- | --- |
| 1 | AnswerError |

### Placement / order

| Context | Order |
| --- | --- |
| Conversation | Caller supplies surrounding content |

### Props

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `onRetry` | See source | Caller supplied | See source | Retry callback |

### Sizes

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Retry base | min-height 44px | 12px | 6px | 999px | button-label | 44px | Base CSS; caller may override |

### Tokens

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Error text | `--chatty-contact-muted` | Fallback #6b6b6b | Fallback #6b6b6b |
| Retry ink | `--chatty-contact-fg` | Fallback #1f1f1f | Fallback #1f1f1f |

### States

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Error | Answer fails | Error label and Retry visible | role alert |

### Behaviour

| Interaction | Result |
| --- | --- |
| Retry | Calls onRetry |

### Copy

| String | i18n key | Where |
| --- | --- | --- |
| Caller translated | Not available | AnswerError |

### Source

| File | Evidence |
| --- | --- |
|  | Owning React implementation. |

## Do / Don't

Do: giữ host làm owner của dữ liệu.

Don't: gửi lại chỉ vì element render.

## Accessibility

| Surface | Role / name | Keyboard / focus | Live region | Contrast pair / ratio |
| --- | --- | --- | --- | --- |
| Classic | Alert | Tab to Retry; Enter or Space activates | Alert | See neutral token preview |
| AI Mode | Alert | Tab to Retry; Enter or Space activates | Alert | See neutral token preview |

