<!-- source-hash: c21d20125d1c832d1265f5a500b7053e -->
React context provider managing in-app notification state, including add, read, settle, remove, and panel open/close operations via a reducer pattern.

## Key Components

### `NotificationsProvider`
Wraps your app (or a subtree) to supply notification state. Uses `useReducer` for immutable state transitions and `useCallback`/`useMemo` for stable references.

**Props:**

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `initialNotifications` | `Notification[]` | `[]` | Seed the store on mount |
| `maxNotifications` | `number` | `50` | Hard cap; oldest entries are trimmed |
| `defaultShowPopups` | `boolean` | `true` | Initial popup visibility |
| `onShowPopupsChange` | `(v: boolean) => void` | — | Callback on popup toggle |
| `onHistoryClick` | `() => void` | — | Callback for "view history" action |

### `useNotifications`
Primary hook — throws if called outside the provider.

### `useOptionalNotifications`
Safe hook — returns `null` instead of throwing; useful for components that optionally participate in the notification system.

### `reducer`
Pure state reducer handling: `add`, `markRead`, `markAllRead`, `markSettled`, `remove`, `clear`.

## Usage Example

```typescript
import { NotificationsProvider, useNotifications } from './notifications-context'

// 1. Wrap your app
export default function App() {
  return (
    <NotificationsProvider maxNotifications={100} defaultShowPopups={true}>
      <Dashboard />
    </NotificationsProvider>
  )
}

// 2. Consume in any child component
function Dashboard() {
  const { addNotification, unreadCount, markAllRead, toggle } = useNotifications()

  const notify = () =>
    addNotification({
      title: 'Ticket Updated',
      description: 'Ticket #1042 was resolved by Mingo AI.',
      color: 'success',
    })

  return (
    <>
      <button onClick={notify}>Trigger</button>
      <button onClick={toggle}>Inbox ({unreadCount})</button>
      <button onClick={markAllRead}>Mark all read</button>
    </>
  )
}
```

## Context Value Reference

| Method / Property | Description |
|---|---|
| `notifications` | Full ordered array, newest first |
| `unreadCount` | Derived count of unread items |
| `isOpen` | Panel open state |
| `addNotification(input)` | Adds entry, returns generated `id` |
| `markSettled(id)` | Marks a notification as acted upon (e.g. hides progress) |
| `open / close / toggle` | Control panel visibility |
| `setShowPopups(bool)` | Toggle toast popups globally |