# AlertDialog

## Overview

A specialized modal for **irreversible destructive actions** — delete, revoke, reset, permanently disable. Unlike `Dialog`, `AlertDialog` enforces that the user must explicitly confirm or cancel; clicking outside does not dismiss it.

---

## When to Use

- Deleting a record
- Revoking access or permissions
- Permanently disabling or deactivating an entity
- Any action that cannot be undone

## When NOT to Use

- Non-destructive confirmations — use `Dialog` instead.
- Quick succinct confirmations that don't require explanation — use `toast` with an undo option instead.

---

## Anatomy

```
<AlertDialog>
  <AlertDialogTrigger />
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle />
      <AlertDialogDescription />
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel />   ← always first (left)
      <AlertDialogAction />   ← destructive action (right)
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>
```

---

## Props

### AlertDialog

| Prop           | Type                      | Description           |
| -------------- | ------------------------- | --------------------- |
| `open`         | `boolean`                 | Controlled open state |
| `onOpenChange` | `(open: boolean) => void` | State handler         |

### AlertDialogTrigger

| Prop      | Type      | Description              |
| --------- | --------- | ------------------------ |
| `asChild` | `boolean` | Renders as child element |

### AlertDialogAction

| Prop        | Type         | Description                                     |
| ----------- | ------------ | ----------------------------------------------- |
| `className` | `string`     | Style the action button (typically destructive) |
| `onClick`   | `() => void` | Action to execute on confirm                    |

---

## Examples

### Delete Confirmation

```tsx
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
  Button,
} from 'xertica-ui/ui';

<AlertDialog>
  <AlertDialogTrigger asChild>
    <Button variant="destructive">Delete Account</Button>
  </AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
      <AlertDialogDescription>
        This action cannot be undone. This will permanently delete your account and remove all
        associated data.
      </AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>Cancel</AlertDialogCancel>
      <AlertDialogAction
        className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
        onClick={handleDelete}
      >
        Delete
      </AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>;
```

---

## AI Rules

- `AlertDialogTitle` is **required** — omitting it will trigger an accessibility error.
- `AlertDialogDescription` is **required** — it explains what will happen and cannot be undone.
- `AlertDialogCancel` must appear **before** `AlertDialogAction` in the footer — left to right: Cancel → Confirm.
- Style the `AlertDialogAction` with `className="bg-destructive text-destructive-foreground hover:bg-destructive/90"` for destructive actions.
- Clicking outside the dialog does NOT dismiss it — this is intentional to prevent accidental dismissal during destructive operations.
- Never omit the Cancel option — users must always have a safe exit.

---

## Related Components

- [`Dialog`](./dialog.md) — For non-destructive modals
- [`Button`](./button.md) — The trigger button
- [`Sonner`](./sonner.md) — For toast confirmations with undo
