@marktiderman/genesis-chat 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +132 -3
  2. package/dist/{chunk-GBJ3YI4E.js → chunk-5XYDVUPS.js} +6 -3
  3. package/dist/chunk-5XYDVUPS.js.map +1 -0
  4. package/dist/{chunk-XQ2ULNHV.js → chunk-D4RPOYB7.js} +4 -4
  5. package/dist/chunk-D4RPOYB7.js.map +1 -0
  6. package/dist/{chunk-RYD6WJE5.js → chunk-O2QSBRSH.js} +3 -3
  7. package/dist/{chunk-RYD6WJE5.js.map → chunk-O2QSBRSH.js.map} +1 -1
  8. package/dist/{chunk-A4YJX7KT.js → chunk-ZQFREERR.js} +3 -3
  9. package/dist/{chunk-A4YJX7KT.js.map → chunk-ZQFREERR.js.map} +1 -1
  10. package/dist/{client-DUIG1hum.d.ts → client-DP7rhJ1U.d.ts} +17 -6
  11. package/dist/index.d.ts +4 -4
  12. package/dist/index.js +2 -2
  13. package/dist/native.d.ts +35 -16
  14. package/dist/native.js +168 -490
  15. package/dist/native.js.map +1 -1
  16. package/dist/{outbox-B9NAWQ58.d.ts → outbox-C4LnqpKT.d.ts} +1 -1
  17. package/dist/push.d.ts +2 -2
  18. package/dist/react.d.ts +4 -8
  19. package/dist/react.js +3 -3
  20. package/dist/server.d.ts +1 -1
  21. package/dist/server.js +1 -1
  22. package/dist/{thread-oPra7pkW.d.ts → thread-CSzdqNR_.d.ts} +1 -1
  23. package/dist/web.d.ts +201 -7
  24. package/dist/web.js +580 -56
  25. package/dist/web.js.map +1 -1
  26. package/migrations/0004_genesis_chat_tenants.sql +716 -0
  27. package/migrations/tests/0001_genesis_chat.test.sql +10 -2
  28. package/migrations/tests/0002_genesis_chat_coaching.test.sql +8 -0
  29. package/migrations/tests/0003_genesis_chat_search_threads.test.sql +8 -0
  30. package/migrations/tests/0004_genesis_chat_tenants.test.sql +259 -0
  31. package/package.json +18 -7
  32. package/src/__tests__/core.test.ts +12 -0
  33. package/src/__tests__/web-dock.test.tsx +465 -0
  34. package/src/__tests__/web-photo-viewer.test.tsx +43 -0
  35. package/src/__tests__/web.test.tsx +26 -0
  36. package/src/core/client.ts +5 -1
  37. package/src/core/types.ts +16 -0
  38. package/src/native/__tests__/photo-viewer.test.tsx +24 -5
  39. package/src/native/__tests__/thread-screen.test.tsx +40 -2
  40. package/src/native/message-bubble.tsx +1 -1
  41. package/src/native/photo-viewer.tsx +109 -422
  42. package/src/native/thread-screen.tsx +77 -207
  43. package/src/native/use-jump.ts +7 -1
  44. package/src/react/index.tsx +2 -1
  45. package/src/web/attachments.tsx +39 -55
  46. package/src/web/composer.tsx +5 -0
  47. package/src/web/dock.tsx +889 -0
  48. package/src/web/inbox.tsx +5 -0
  49. package/src/web/index.ts +23 -0
  50. package/src/web/memory-client.ts +1 -1
  51. package/src/web/thread.tsx +42 -3
  52. package/dist/chunk-GBJ3YI4E.js.map +0 -1
  53. package/dist/chunk-XQ2ULNHV.js.map +0 -1
package/dist/web.js CHANGED
@@ -1,16 +1,18 @@
1
- import { attachmentPreview, ChatErrorBoundary } from './chunk-RYD6WJE5.js';
2
- export { ChatErrorBoundary } from './chunk-RYD6WJE5.js';
1
+ import { attachmentPreview, ChatErrorBoundary } from './chunk-O2QSBRSH.js';
2
+ export { ChatErrorBoundary } from './chunk-O2QSBRSH.js';
3
3
  import { snippetParts, isHttpsUrl, scheduleQuickPicks, isSchedulable, scheduleLabel, extractLinks, topicKey } from './chunk-BJCE5O7V.js';
4
- import { useChat, useInbox, useSearch, useScheduled, useAvailability, useTopics, useConversation, useMessageActions, usePins, useFileUrls, useLinkPreviews, useBroadcast } from './chunk-XQ2ULNHV.js';
5
- import { previewText, summarizeReactions, activityLine, itemSender, startsDay, dayLabel, itemTime, startsGroup, parseMentions } from './chunk-A4YJX7KT.js';
6
- import { fileExtension, formatDuration, nextPlaybackRate, awaySummary, awayLine, WEEKDAYS, CHAT_LIMITS, waveformPeaks, recordingLimitMs, isAllowedExtension, attachmentKindFor, randomId, ChatError } from './chunk-GBJ3YI4E.js';
7
- import { createContext, useRef, useState, Fragment, useCallback, useEffect, useMemo, useImperativeHandle, useLayoutEffect, useContext } from 'react';
8
- import { MessageSquare, Pin, BellOff, AtSign, Search, X, Mic, ClipboardList, ExternalLink, VideoOff, Video, RotateCcw, SendHorizontal, Square, Circle, Pause, Play, Paperclip, ChevronLeft, ChevronRight, FileText, Download, Lock, Ban, EyeOff, ShieldAlert, AlertCircle, Clock, Reply, Copy, Pencil, PinOff, Bookmark, Flag, Trash2, SmilePlus, Plus, MoreHorizontal, ChevronUp, CalendarClock, Moon, RefreshCw, Smile, Hash, LockOpen, ArrowDown, ImagePlus, Megaphone, Link2, ArrowLeft } from 'lucide-react';
9
- import { Skeleton, cn, EmptyState, Button, UserAvatar, Badge, Input, Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, Alert, AlertDescription, Spinner, Collapsible, CollapsibleTrigger, CollapsibleContent, VisuallyHidden, Progress, ContextMenu, ContextMenuTrigger, ContextMenuContent, ContextMenuSeparator, ContextMenuItem, Tooltip, Textarea, Popover, PopoverTrigger, PopoverContent, DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuSeparator, DropdownMenuItem, DropdownMenuLabel, Label, DialogFooter, toast, Switch, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, Toggle, ToggleGroup, ToggleGroupItem, Sheet, SheetContent, SheetHeader, SheetTitle, SheetDescription, AlertDialog, AlertDialogContent, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter, AlertDialogCancel, AlertDialogAction, RadioGroup, RadioGroupItem, Split, Checkbox } from '@marktiderman/genesis-ui';
4
+ import { useChat, useInbox, useSearch, useScheduled, useAvailability, useTopics, useConversation, useMessageActions, usePins, useFileUrls, useLinkPreviews, useBroadcast } from './chunk-D4RPOYB7.js';
5
+ import { previewText, summarizeReactions, activityLine, itemSender, startsDay, dayLabel, itemTime, startsGroup, parseMentions } from './chunk-ZQFREERR.js';
6
+ import { fileExtension, formatDuration, nextPlaybackRate, awaySummary, awayLine, WEEKDAYS, CHAT_LIMITS, waveformPeaks, recordingLimitMs, isAllowedExtension, attachmentKindFor, randomId, ChatError } from './chunk-5XYDVUPS.js';
7
+ import { createContext, useRef, useState, Fragment, useCallback, useEffect, useMemo, useImperativeHandle, useLayoutEffect, useReducer, useContext, useSyncExternalStore } from 'react';
8
+ import { MessageSquare, Pin, BellOff, AtSign, Search, X, Mic, ClipboardList, ExternalLink, VideoOff, Video, RotateCcw, SendHorizontal, Square, Circle, Pause, Play, Paperclip, FileText, Download, Lock, Ban, EyeOff, ShieldAlert, AlertCircle, Clock, Reply, Copy, Pencil, PinOff, Bookmark, Flag, Trash2, SmilePlus, Plus, MoreHorizontal, ChevronUp, CalendarClock, Moon, RefreshCw, Smile, Hash, LockOpen, ArrowDown, ImagePlus, Megaphone, MessageCircle, Link2, ArrowLeft, ChevronDown, Maximize2 } from 'lucide-react';
9
+ import { Skeleton, cn, EmptyState, Button, UserAvatar, Badge, Input, Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, Alert, AlertDescription, Spinner, Collapsible, CollapsibleTrigger, CollapsibleContent, Lightbox as Lightbox$1, Progress, ContextMenu, ContextMenuTrigger, ContextMenuContent, ContextMenuSeparator, ContextMenuItem, Tooltip, Textarea, Popover, PopoverTrigger, PopoverContent, DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuSeparator, DropdownMenuItem, DropdownMenuLabel, Label, DialogFooter, toast, Switch, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, Toggle, ToggleGroup, ToggleGroupItem, Sheet, SheetContent, SheetHeader, SheetTitle, SheetDescription, AlertDialog, AlertDialogContent, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter, AlertDialogCancel, AlertDialogAction, RadioGroup, RadioGroupItem, Split, Checkbox } from '@marktiderman/genesis-ui';
10
10
  import { renderSlot } from '@marktiderman/genesis-core/slots';
11
11
  import { relativeTime as relativeTime$1 } from '@marktiderman/genesis-ui/utils';
12
12
  import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
13
13
  import { EmojiPicker } from 'frimousse';
14
+ import { useIsMobile } from '@marktiderman/genesis-ui/hooks';
15
+ import { createLocalStorageAdapter } from '@marktiderman/genesis-core/storage';
14
16
 
15
17
  function clockTime(iso, locale) {
16
18
  return new Date(iso).toLocaleTimeString(locale, { hour: "numeric", minute: "2-digit" });
@@ -141,7 +143,7 @@ function SearchSnippet({ snippet, className }) {
141
143
  (p, i) => p.match ? /* @__PURE__ */ jsx("mark", { className: "rounded-sm bg-warning/30 px-0.5 text-foreground", children: p.text }, i) : /* @__PURE__ */ jsx("span", { children: p.text }, i)
142
144
  ) });
143
145
  }
144
- function ChatSearch({ resolveUser, conversationId, onOpen, conversationTitle, autoFocus, debounceMs, className }) {
146
+ function ChatSearch({ resolveUser, conversationId, onOpen, conversationTitle: conversationTitle2, autoFocus, debounceMs, className }) {
145
147
  const [value, setValue] = useState("");
146
148
  const { hits, query, isSearching } = useSearch(value, { conversationId, debounceMs });
147
149
  const list = useRef(null);
@@ -191,9 +193,9 @@ function ChatSearch({ resolveUser, conversationId, onOpen, conversationTitle, au
191
193
  children: [
192
194
  /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2 text-xs text-muted-foreground", children: [
193
195
  /* @__PURE__ */ jsx("span", { className: "truncate font-medium text-foreground", children: who }),
194
- !conversationId && conversationTitle ? /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
196
+ !conversationId && conversationTitle2 ? /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
195
197
  "in ",
196
- conversationTitle(h.conversationId)
198
+ conversationTitle2(h.conversationId)
197
199
  ] }) : null,
198
200
  /* @__PURE__ */ jsx("span", { className: "ml-auto shrink-0", children: relativeTime(h.createdAt) })
199
201
  ] }),
@@ -1044,50 +1046,39 @@ function ImageGrid({ images, className }) {
1044
1046
  img.key
1045
1047
  );
1046
1048
  }) }),
1047
- /* @__PURE__ */ jsx(Lightbox, { images, index: open, onIndexChange: setOpen })
1049
+ /* @__PURE__ */ jsx(ChatLightbox, { images, index: open, onIndexChange: setOpen })
1048
1050
  ] });
1049
1051
  }
1050
- function Lightbox({ images, index, onIndexChange }) {
1051
- const img = index === null ? null : images[index];
1052
- const go = useCallback(
1053
- (delta) => {
1054
- if (index === null || images.length < 2) return;
1055
- onIndexChange((index + delta + images.length) % images.length);
1056
- },
1057
- [images.length, index, onIndexChange]
1052
+ function ChatLightbox({ images, index, onIndexChange }) {
1053
+ const at = useMemo(() => images.flatMap((img, i) => img.url ? [i] : []), [images]);
1054
+ const items = useMemo(
1055
+ () => at.map((i) => {
1056
+ const img = images[i];
1057
+ return {
1058
+ id: img.key,
1059
+ src: img.url,
1060
+ alt: img.name ?? "Photo",
1061
+ ...img.width ? { width: img.width } : {},
1062
+ ...img.height ? { height: img.height } : {}
1063
+ };
1064
+ }),
1065
+ [images, at]
1058
1066
  );
1059
- const onKey = (e) => {
1060
- if (e.key === "ArrowRight") {
1061
- e.preventDefault();
1062
- go(1);
1063
- } else if (e.key === "ArrowLeft") {
1064
- e.preventDefault();
1065
- go(-1);
1067
+ const shown = index === null ? -1 : at.indexOf(index);
1068
+ return /* @__PURE__ */ jsx(
1069
+ Lightbox$1,
1070
+ {
1071
+ open: shown !== -1,
1072
+ onOpenChange: (open) => !open && onIndexChange(null),
1073
+ items,
1074
+ index: Math.max(0, shown),
1075
+ onIndexChange: (i) => onIndexChange(at[i] ?? null),
1076
+ labels: { previous: "Previous photo", next: "Next photo", photo: (n, count) => `Photo ${n} of ${count}` },
1077
+ className: "genesis-chat-lightbox"
1066
1078
  }
1067
- };
1068
- return /* @__PURE__ */ jsx(Dialog, { open: img != null, onOpenChange: (o) => !o && onIndexChange(null), children: /* @__PURE__ */ jsxs(DialogContent, { className: "max-w-[min(64rem,95vw)] border-0 bg-background p-2", onKeyDown: onKey, "data-testid": "genesis-chat-lightbox", children: [
1069
- /* @__PURE__ */ jsxs(VisuallyHidden, { children: [
1070
- /* @__PURE__ */ jsx(DialogTitle, { children: img?.name ?? "Photo" }),
1071
- /* @__PURE__ */ jsxs(DialogDescription, { children: [
1072
- "Photo ",
1073
- index === null ? 0 : index + 1,
1074
- " of ",
1075
- images.length,
1076
- ". Use the arrow keys for the others."
1077
- ] })
1078
- ] }),
1079
- img?.url ? /* @__PURE__ */ jsx("img", { src: img.url, alt: img.name ?? "Photo", className: "mx-auto max-h-[80vh] w-auto rounded-md object-contain" }) : null,
1080
- images.length > 1 ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
1081
- /* @__PURE__ */ jsx(Button, { type: "button", variant: "ghost", size: "icon", onClick: () => go(-1), "aria-label": "Previous photo", children: /* @__PURE__ */ jsx(ChevronLeft, {}) }),
1082
- /* @__PURE__ */ jsxs("span", { className: "text-sm tabular-nums text-muted-foreground", children: [
1083
- (index ?? 0) + 1,
1084
- " / ",
1085
- images.length
1086
- ] }),
1087
- /* @__PURE__ */ jsx(Button, { type: "button", variant: "ghost", size: "icon", onClick: () => go(1), "aria-label": "Next photo", children: /* @__PURE__ */ jsx(ChevronRight, {}) })
1088
- ] }) : null
1089
- ] }) });
1079
+ );
1090
1080
  }
1081
+ var Lightbox = ChatLightbox;
1091
1082
  function VideoAttachment({ view }) {
1092
1083
  const a = view.attachment;
1093
1084
  const hosted = a != null && a.provider !== "storage" && a.provider !== "external" && a.provider !== "none";
@@ -1795,7 +1786,7 @@ function ScheduleDialog({ open, onOpenChange, onSchedule, now }) {
1795
1786
  )
1796
1787
  ] }) });
1797
1788
  }
1798
- function ChatScheduledList({ conversationId, conversationTitle, className }) {
1789
+ function ChatScheduledList({ conversationId, conversationTitle: conversationTitle2, className }) {
1799
1790
  const { items, isLoading, cancel } = useScheduled(conversationId);
1800
1791
  if (isLoading) {
1801
1792
  return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-2 p-3", className), "aria-busy": true, "aria-label": "Loading scheduled messages", children: [
@@ -1811,7 +1802,7 @@ function ChatScheduledList({ conversationId, conversationTitle, className }) {
1811
1802
  /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
1812
1803
  /* @__PURE__ */ jsxs("div", { className: "text-xs font-medium text-muted-foreground", children: [
1813
1804
  s.status === "failed" ? "Couldn't send" : scheduleLabel(s.sendAt),
1814
- !conversationId && conversationTitle ? ` \xB7 ${conversationTitle(s.conversationId)}` : null
1805
+ !conversationId && conversationTitle2 ? ` \xB7 ${conversationTitle2(s.conversationId)}` : null
1815
1806
  ] }),
1816
1807
  /* @__PURE__ */ jsx("div", { className: "truncate text-sm", children: previewText(s.body, s.attachments[0]?.kind ?? null) }),
1817
1808
  s.error ? /* @__PURE__ */ jsx("div", { className: "text-xs text-destructive", children: s.error }) : null
@@ -2748,6 +2739,15 @@ function ChatTopicBar({ topics, value, onValueChange, canManage = false, onSetTo
2748
2739
  ] }) })
2749
2740
  ] });
2750
2741
  }
2742
+ function centerRow(scroller, row, smooth) {
2743
+ const delta = row.getBoundingClientRect().top - scroller.getBoundingClientRect().top - (scroller.clientHeight - row.offsetHeight) / 2;
2744
+ const top = Math.max(0, scroller.scrollTop + delta);
2745
+ if (smooth && typeof scroller.scrollTo === "function") scroller.scrollTo({ top, behavior: "smooth" });
2746
+ else scroller.scrollTop = top;
2747
+ }
2748
+ function prefersReducedMotion() {
2749
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
2750
+ }
2751
2751
  var REPORT_REASONS = [
2752
2752
  { value: "spam", label: "Spam" },
2753
2753
  { value: "harassment", label: "Harassment or bullying" },
@@ -2798,13 +2798,15 @@ function ChatThread({
2798
2798
  linkPreviewImages = "off",
2799
2799
  linkPreviewProxyUrl,
2800
2800
  slots,
2801
+ markRead = true,
2802
+ autoFocus = false,
2801
2803
  className
2802
2804
  }) {
2803
2805
  const { userId: me, attachmentKinds, client: chatClient } = useChat();
2804
2806
  const topicsState = useTopics(threadRootId ? null : conversationId);
2805
2807
  const [chosenTopic, setChosenTopic] = useState(null);
2806
2808
  const topic = topicProp ?? chosenTopic ?? void 0;
2807
- const state = useConversation(conversationId, { threadRootId, topic });
2809
+ const state = useConversation(conversationId, { threadRootId, topic, markRead });
2808
2810
  const actions = useMessageActions();
2809
2811
  const pinIds = usePins(conversationId);
2810
2812
  const { items, messages, members, role, canPost, conversation, activity } = state;
@@ -2824,6 +2826,11 @@ function ChatThread({
2824
2826
  const [newCount, setNewCount] = useState(0);
2825
2827
  const [announcement, setAnnouncement] = useState("");
2826
2828
  const composer = useRef(null);
2829
+ useEffect(() => {
2830
+ if (!autoFocus) return;
2831
+ const id = requestAnimationFrame(() => composer.current?.focus());
2832
+ return () => cancelAnimationFrame(id);
2833
+ }, [autoFocus]);
2827
2834
  useEffect(() => {
2828
2835
  setReplyTo(null);
2829
2836
  setEditingId(null);
@@ -2887,7 +2894,7 @@ function ChatThread({
2887
2894
  if (initialised.current !== conversationId) {
2888
2895
  initialised.current = conversationId;
2889
2896
  const unread = state.firstUnreadId ? document.getElementById(`genesis-chat-msg-${state.firstUnreadId}`) : null;
2890
- if (unread && typeof unread.scrollIntoView === "function") unread.scrollIntoView({ block: "center" });
2897
+ if (unread) centerRow(el, unread, false);
2891
2898
  else scrollToBottom();
2892
2899
  return;
2893
2900
  }
@@ -2937,7 +2944,7 @@ function ChatThread({
2937
2944
  toast.info("That message is further up", { description: "Scroll up to load it." });
2938
2945
  return;
2939
2946
  }
2940
- if (typeof el.scrollIntoView === "function") el.scrollIntoView({ block: "center", behavior: "smooth" });
2947
+ if (scroller.current) centerRow(scroller.current, el, !prefersReducedMotion());
2941
2948
  setHighlightedId(id);
2942
2949
  setTimeout(() => setHighlightedId((h) => h === id ? null : h), 1600);
2943
2950
  }, []);
@@ -4094,7 +4101,524 @@ function ChatBroadcast({ resolveUser, kind, filter, onSent, className }) {
4094
4101
  }
4095
4102
  );
4096
4103
  }
4104
+ var emptyChatDock = { items: [], activeId: null, sheetOpen: false, used: {}, focusId: null, clock: 0 };
4105
+ var sameItem = (a, b) => Object.keys({ ...a, ...b }).every((k) => k === "minimized" || a[k] === b[k]);
4106
+ function touch(state, id) {
4107
+ const clock = state.clock + 1;
4108
+ return { clock, used: { ...state.used, [id]: clock } };
4109
+ }
4110
+ function without(record, id) {
4111
+ const { [id]: _gone, ...rest } = record;
4112
+ return rest;
4113
+ }
4114
+ function chatDockReducer(state, action, max = 3) {
4115
+ const cap = Math.max(1, max);
4116
+ switch (action.type) {
4117
+ case "open": {
4118
+ const at = state.items.findIndex((i) => i.id === action.item.id);
4119
+ const current = state.items[at];
4120
+ if (at === 0 && current && !current.minimized && sameItem(current, action.item) && state.activeId === current.id && state.sheetOpen && state.focusId === current.id) {
4121
+ return state;
4122
+ }
4123
+ const item = { ...action.item, minimized: false };
4124
+ let items = [item, ...state.items.filter((i) => i.id !== item.id)];
4125
+ let used = { ...touch(state, item.id).used };
4126
+ while (items.length > cap) {
4127
+ const oldest = items.filter((i) => i.id !== item.id).reduce((a, b) => (used[a.id] ?? 0) <= (used[b.id] ?? 0) ? a : b);
4128
+ items = items.filter((i) => i.id !== oldest.id);
4129
+ used = without(used, oldest.id);
4130
+ }
4131
+ return { items, activeId: item.id, sheetOpen: true, used, focusId: item.id, clock: state.clock + 1 };
4132
+ }
4133
+ case "close": {
4134
+ const items = state.items.filter((i) => i.id !== action.id);
4135
+ if (items.length === state.items.length) return state;
4136
+ const activeId = state.activeId === action.id ? items[0]?.id ?? null : state.activeId;
4137
+ return {
4138
+ ...state,
4139
+ items,
4140
+ activeId,
4141
+ sheetOpen: state.sheetOpen && items.length > 0,
4142
+ used: without(state.used, action.id),
4143
+ focusId: state.focusId === action.id ? null : state.focusId
4144
+ };
4145
+ }
4146
+ case "minimize": {
4147
+ if (!state.items.some((i) => i.id === action.id && i.minimized !== action.minimized)) return state;
4148
+ const items = state.items.map((i) => i.id === action.id ? { ...i, minimized: action.minimized } : i);
4149
+ if (!action.minimized) return { ...state, items, ...touch(state, action.id), focusId: action.id };
4150
+ return { ...state, items, focusId: state.focusId === action.id ? null : state.focusId };
4151
+ }
4152
+ case "activate": {
4153
+ if (!state.items.some((i) => i.id === action.id)) return state;
4154
+ if (state.activeId === action.id && state.focusId === action.id) return state;
4155
+ return { ...state, activeId: action.id, ...touch(state, action.id), focusId: action.id };
4156
+ }
4157
+ case "front": {
4158
+ const at = state.items.findIndex((i) => i.id === action.id);
4159
+ if (at === -1) return state;
4160
+ const item = { ...state.items[at], minimized: false };
4161
+ const items = [item, ...state.items.filter((_, n) => n !== at)];
4162
+ return { ...state, items, activeId: item.id, ...touch(state, item.id), focusId: item.id };
4163
+ }
4164
+ case "sheet": {
4165
+ const sheetOpen = action.open && state.items.length > 0;
4166
+ return sheetOpen === state.sheetOpen ? state : { ...state, sheetOpen };
4167
+ }
4168
+ case "update": {
4169
+ const at = state.items.findIndex((i) => i.id === action.id && i.type === "panel");
4170
+ if (at === -1) return state;
4171
+ const panel = state.items[at];
4172
+ const changed = Object.keys(action.patch).some((k) => panel[k] !== action.patch[k]);
4173
+ if (!changed) return state;
4174
+ const items = state.items.slice();
4175
+ items[at] = { ...panel, ...action.patch };
4176
+ return { ...state, items };
4177
+ }
4178
+ case "hydrate": {
4179
+ if (state.items.length > 0 || action.items.length === 0) return state;
4180
+ const items = action.items.slice(0, cap);
4181
+ const used = {};
4182
+ items.forEach((i, n) => used[i.id] = items.length - n);
4183
+ return { ...state, items, activeId: items[0]?.id ?? null, used, clock: Math.max(state.clock, items.length) };
4184
+ }
4185
+ case "closeAll":
4186
+ return state.items.length === 0 ? state : emptyChatDock;
4187
+ }
4188
+ }
4189
+ var storage = createLocalStorageAdapter();
4190
+ var storageName = (key, userId) => `${key}:${userId}`;
4191
+ function readStored(key, userId, max) {
4192
+ try {
4193
+ const raw = storage.getItem(storageName(key, userId));
4194
+ const parsed = raw ? JSON.parse(raw) : null;
4195
+ if (!Array.isArray(parsed)) return [];
4196
+ return parsed.filter((s) => !!s && typeof s.conversationId === "string" && s.conversationId !== "").slice(0, Math.max(1, max)).map((s) => ({
4197
+ type: "conversation",
4198
+ id: s.conversationId,
4199
+ conversationId: s.conversationId,
4200
+ ...typeof s.title === "string" ? { title: s.title } : {},
4201
+ // Brought back as bars: nothing opens over the page on load.
4202
+ minimized: true,
4203
+ restored: true
4204
+ }));
4205
+ } catch {
4206
+ return [];
4207
+ }
4208
+ }
4209
+ function writeStored(key, userId, items) {
4210
+ const stored = items.filter((i) => i.type === "conversation").map((i) => ({ conversationId: i.conversationId, ...i.title ? { title: i.title } : {} }));
4211
+ if (stored.length === 0) storage.removeItem(storageName(key, userId));
4212
+ else storage.setItem(storageName(key, userId), JSON.stringify(stored));
4213
+ }
4214
+ function forgetChatDock(storageKey, userId) {
4215
+ storage.removeItem(storageName(storageKey, userId));
4216
+ }
4217
+ var noSubscribe = () => () => {
4218
+ };
4219
+ function useHydrated() {
4220
+ return useSyncExternalStore(
4221
+ noSubscribe,
4222
+ () => true,
4223
+ () => false
4224
+ );
4225
+ }
4226
+ var DockContext = createContext(null);
4227
+ function ChatDockProvider({ max = 3, onExpand, storageKey, children }) {
4228
+ const { userId, client } = useChat();
4229
+ const [state, dispatch] = useReducer((s, a) => chatDockReducer(s, a, max), emptyChatDock);
4230
+ const hydrated = useHydrated();
4231
+ const [loadedFor, setLoadedFor] = useState(null);
4232
+ const storeKey = storageKey && userId ? `${storageKey}\0${userId}` : null;
4233
+ useEffect(() => {
4234
+ if (!hydrated || !storageKey || !userId || loadedFor === storeKey) return;
4235
+ dispatch({ type: "hydrate", items: readStored(storageKey, userId, max) });
4236
+ setLoadedFor(storeKey);
4237
+ }, [hydrated, storageKey, userId, storeKey, loadedFor, max]);
4238
+ useEffect(() => {
4239
+ if (!storageKey || !userId || loadedFor !== storeKey) return;
4240
+ writeStored(storageKey, userId, state.items);
4241
+ }, [storageKey, userId, storeKey, loadedFor, state.items]);
4242
+ const restoredIds = state.items.filter((i) => i.type === "conversation" && !!i.restored).map((i) => i.conversationId).join(",");
4243
+ useEffect(() => {
4244
+ if (!restoredIds) return;
4245
+ let live = true;
4246
+ for (const id of restoredIds.split(",")) {
4247
+ void client.conversation(id).then((c) => {
4248
+ if (live && !c) dispatch({ type: "close", id });
4249
+ }).catch(() => void 0);
4250
+ }
4251
+ return () => {
4252
+ live = false;
4253
+ };
4254
+ }, [restoredIds, client]);
4255
+ const expandRef = useRef(onExpand);
4256
+ expandRef.current = onExpand;
4257
+ const itemsRef = useRef(state.items);
4258
+ itemsRef.current = state.items;
4259
+ const open = useCallback((conversationId, opts = {}) => {
4260
+ if (!conversationId) return;
4261
+ const item = { type: "conversation", id: conversationId, conversationId, minimized: false };
4262
+ if (opts.title) item.title = opts.title;
4263
+ dispatch({ type: "open", item });
4264
+ if (opts.minimized) dispatch({ type: "minimize", id: conversationId, minimized: true });
4265
+ }, []);
4266
+ const openPanel = useCallback(({ minimized, ...panel }) => {
4267
+ if (!panel.id) return;
4268
+ dispatch({ type: "open", item: { ...panel, type: "panel", minimized: false } });
4269
+ if (minimized) dispatch({ type: "minimize", id: panel.id, minimized: true });
4270
+ }, []);
4271
+ const updatePanel = useCallback((id, patch) => dispatch({ type: "update", id, patch }), []);
4272
+ const close = useCallback((id) => dispatch({ type: "close", id }), []);
4273
+ const closeAll = useCallback(() => dispatch({ type: "closeAll" }), []);
4274
+ const minimize = useCallback((id) => dispatch({ type: "minimize", id, minimized: true }), []);
4275
+ const restore = useCallback((id) => dispatch({ type: "minimize", id, minimized: false }), []);
4276
+ const activate = useCallback((id) => dispatch({ type: "activate", id }), []);
4277
+ const bringToFront = useCallback((id) => dispatch({ type: "front", id }), []);
4278
+ const setSheetOpen = useCallback((o) => dispatch({ type: "sheet", open: o }), []);
4279
+ const hasExpand = !!onExpand;
4280
+ const canExpand = useCallback((item) => item.type === "panel" && !!item.onExpand || hasExpand, [hasExpand]);
4281
+ const expand = useCallback((id) => {
4282
+ const item = itemsRef.current.find((i) => i.id === id);
4283
+ if (!item) return;
4284
+ const run = item.type === "panel" && item.onExpand ? item.onExpand : expandRef.current ? () => expandRef.current(item) : null;
4285
+ if (!run) return;
4286
+ dispatch({ type: "close", id });
4287
+ run();
4288
+ }, []);
4289
+ const api = useMemo(
4290
+ () => ({
4291
+ items: state.items,
4292
+ activeId: state.activeId,
4293
+ focusId: state.focusId,
4294
+ sheetOpen: state.sheetOpen,
4295
+ open,
4296
+ openPanel,
4297
+ updatePanel,
4298
+ close,
4299
+ closeAll,
4300
+ minimize,
4301
+ restore,
4302
+ activate,
4303
+ bringToFront,
4304
+ expand,
4305
+ canExpand,
4306
+ setSheetOpen
4307
+ }),
4308
+ [state.items, state.activeId, state.focusId, state.sheetOpen, open, openPanel, updatePanel, close, closeAll, minimize, restore, activate, bringToFront, expand, canExpand, setSheetOpen]
4309
+ );
4310
+ return /* @__PURE__ */ jsx(DockContext.Provider, { value: api, children });
4311
+ }
4312
+ function useChatDock() {
4313
+ const api = useContext(DockContext);
4314
+ if (!api) throw new Error("useChatDock needs a ChatDockProvider above it (under ChatProvider).");
4315
+ return api;
4316
+ }
4317
+ function useOptionalChatDock() {
4318
+ return useContext(DockContext);
4319
+ }
4320
+ var defaultChatDockLabels = {
4321
+ minimize: "Minimize",
4322
+ restore: "Open",
4323
+ expand: "Open in Messages",
4324
+ close: "Close",
4325
+ openDock: "Open conversations",
4326
+ sheetTitle: "Conversations",
4327
+ sheetDescription: "Your open conversations.",
4328
+ unread: (n) => `${n} unread`,
4329
+ unreadTotal: (n) => n > 0 ? `${n} unread in your open conversations` : "",
4330
+ more: (n) => `+${n}`,
4331
+ moreLabel: (n) => `${n} more conversation${n === 1 ? "" : "s"}`,
4332
+ conversation: "Conversation"
4333
+ };
4334
+ var WINDOW_PX = 352;
4335
+ var GAP_PX = 12;
4336
+ var PAD_PX = 32;
4337
+ var MORE_PX = 56;
4338
+ function subscribeWidth(cb) {
4339
+ window.addEventListener("resize", cb);
4340
+ return () => window.removeEventListener("resize", cb);
4341
+ }
4342
+ function useViewportWidth() {
4343
+ return useSyncExternalStore(
4344
+ subscribeWidth,
4345
+ () => window.innerWidth,
4346
+ () => 1440
4347
+ );
4348
+ }
4349
+ function chatDockWindowsThatFit(width, count) {
4350
+ const fits = (room) => Math.max(1, Math.floor((room - PAD_PX + GAP_PX) / (WINDOW_PX + GAP_PX)));
4351
+ const all = fits(width);
4352
+ return count <= all ? count : fits(width - MORE_PX);
4353
+ }
4354
+ function conversationTitle(item, inbox, resolveUser, labels) {
4355
+ if (item.title) return item.title;
4356
+ const row = inbox.get(item.conversationId);
4357
+ return row ? inboxTitle(row, resolveUser, () => labels.conversation) : labels.conversation;
4358
+ }
4359
+ function itemTitle(item, inbox, resolveUser, labels) {
4360
+ return item.type === "panel" ? item.title : conversationTitle(item, inbox, resolveUser, labels);
4361
+ }
4362
+ function itemUnread(item, inbox) {
4363
+ if (item.type === "panel") return item.unread ?? 0;
4364
+ const row = inbox.get(item.conversationId);
4365
+ return row && !row.muted ? row.unread : 0;
4366
+ }
4367
+ function DockTitleBar({ item, title, avatar, subtitle, unread, labels, inSheet, toggleRef }) {
4368
+ const dock = useChatDock();
4369
+ const toggle = () => item.minimized ? dock.restore(item.id) : dock.minimize(item.id);
4370
+ const titleText = /* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1 text-left", children: [
4371
+ /* @__PURE__ */ jsx("span", { className: "block truncate text-sm font-semibold leading-tight", children: title }),
4372
+ subtitle ? /* @__PURE__ */ jsx("span", { className: "block truncate text-xs text-muted-foreground", children: subtitle }) : null
4373
+ ] });
4374
+ return /* @__PURE__ */ jsxs("div", { className: "flex min-h-12 shrink-0 items-center gap-1 border-b bg-background px-2 py-1.5", "data-testid": "genesis-chat-dock-titlebar", children: [
4375
+ inSheet ? /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 items-center gap-2 px-1", children: [
4376
+ avatar,
4377
+ titleText
4378
+ ] }) : /* @__PURE__ */ jsxs(
4379
+ "button",
4380
+ {
4381
+ ref: toggleRef,
4382
+ type: "button",
4383
+ onClick: toggle,
4384
+ "aria-expanded": !item.minimized,
4385
+ "aria-label": `${title}${unread > 0 ? `, ${labels.unread(unread)}` : ""}. ${item.minimized ? labels.restore : labels.minimize}`,
4386
+ className: "flex min-h-9 min-w-0 flex-1 items-center gap-2 rounded-md px-1 text-left hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
4387
+ "data-testid": "genesis-chat-dock-toggle",
4388
+ children: [
4389
+ avatar,
4390
+ titleText,
4391
+ unread > 0 ? /* @__PURE__ */ jsx("span", { className: "inline-flex h-5 min-w-5 shrink-0 items-center justify-center rounded-full bg-primary px-1.5 text-[11px] font-semibold text-primary-foreground", "aria-hidden": true, children: unread > 99 ? "99+" : unread }) : null,
4392
+ item.minimized ? /* @__PURE__ */ jsx(ChevronUp, { className: "h-4 w-4 shrink-0 text-muted-foreground", "aria-hidden": true }) : /* @__PURE__ */ jsx(ChevronDown, { className: "h-4 w-4 shrink-0 text-muted-foreground", "aria-hidden": true })
4393
+ ]
4394
+ }
4395
+ ),
4396
+ dock.canExpand(item) ? /* @__PURE__ */ jsx(Button, { type: "button", variant: "ghost", size: "icon", className: "h-8 w-8 shrink-0", onClick: () => dock.expand(item.id), "aria-label": labels.expand, title: labels.expand, "data-testid": "genesis-chat-dock-expand", children: /* @__PURE__ */ jsx(Maximize2, {}) }) : null,
4397
+ /* @__PURE__ */ jsx(Button, { type: "button", variant: "ghost", size: "icon", className: "h-8 w-8 shrink-0", onClick: () => dock.close(item.id), "aria-label": labels.close, title: labels.close, "data-testid": "genesis-chat-dock-close", children: /* @__PURE__ */ jsx(X, {}) })
4398
+ ] });
4399
+ }
4400
+ function DockItemView({ item, inbox, resolveUser, threadProps, labels, inSheet, visible, focus, toggleRef }) {
4401
+ const unread = itemUnread(item, inbox);
4402
+ const [header, setHeader] = useState(null);
4403
+ const Report = useMemo(
4404
+ () => function ReportHeader({ title: title2, activity, subtitle, otherUserId }) {
4405
+ const sub = activity ?? subtitle;
4406
+ useEffect(() => {
4407
+ setHeader((h) => h && h.title === title2 && h.subtitle === sub && h.otherUserId === otherUserId ? h : { title: title2, subtitle: sub, otherUserId });
4408
+ }, [title2, sub, otherUserId]);
4409
+ return null;
4410
+ },
4411
+ []
4412
+ );
4413
+ if (item.type === "panel") {
4414
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
4415
+ /* @__PURE__ */ jsx(
4416
+ DockTitleBar,
4417
+ {
4418
+ item,
4419
+ title: item.title,
4420
+ avatar: item.icon ? /* @__PURE__ */ jsx("span", { className: "flex h-8 w-8 shrink-0 items-center justify-center", children: item.icon }) : /* @__PURE__ */ jsx(UserAvatar, { name: item.title, size: "sm" }),
4421
+ subtitle: null,
4422
+ unread,
4423
+ labels,
4424
+ inSheet,
4425
+ toggleRef
4426
+ }
4427
+ ),
4428
+ /* @__PURE__ */ jsx("div", { className: "flex min-h-0 flex-1 flex-col overflow-y-auto", hidden: !visible, "data-testid": "genesis-chat-dock-panel", children: item.render() })
4429
+ ] });
4430
+ }
4431
+ const row = inbox.get(item.conversationId);
4432
+ const title = item.title ?? header?.title ?? conversationTitle(item, inbox, resolveUser, labels);
4433
+ const otherId = header?.otherUserId ?? row?.otherUserId ?? null;
4434
+ const other = otherId ? resolveUser(otherId) : null;
4435
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
4436
+ /* @__PURE__ */ jsx(
4437
+ DockTitleBar,
4438
+ {
4439
+ item,
4440
+ title,
4441
+ avatar: /* @__PURE__ */ jsx(UserAvatar, { name: title, src: other?.avatarUrl, size: "sm" }),
4442
+ subtitle: visible ? header?.subtitle ?? null : null,
4443
+ unread: visible ? 0 : unread,
4444
+ labels,
4445
+ inSheet,
4446
+ toggleRef
4447
+ }
4448
+ ),
4449
+ /* @__PURE__ */ jsx("div", { className: "flex min-h-0 flex-1 flex-col", hidden: !visible, "data-testid": "genesis-chat-dock-body", children: /* @__PURE__ */ jsx(
4450
+ ChatThread,
4451
+ {
4452
+ ...threadProps,
4453
+ conversationId: item.conversationId,
4454
+ resolveUser,
4455
+ ...item.title ? { title: item.title } : {},
4456
+ markRead: visible,
4457
+ autoFocus: visible && focus,
4458
+ className: cn("min-h-0 flex-1", threadProps?.className),
4459
+ slots: { ...threadProps?.slots, header: Report }
4460
+ }
4461
+ ) })
4462
+ ] });
4463
+ }
4464
+ function isEscape(e) {
4465
+ return e.key === "Escape" && !e.defaultPrevented && !e.nativeEvent.isComposing && e.keyCode !== 229;
4466
+ }
4467
+ function DockWindow(props) {
4468
+ const dock = useChatDock();
4469
+ const { item } = props;
4470
+ const toggleRef = useRef(null);
4471
+ const onKeyDown = (e) => {
4472
+ if (!isEscape(e) || item.minimized) return;
4473
+ e.preventDefault();
4474
+ dock.minimize(item.id);
4475
+ toggleRef.current?.focus();
4476
+ };
4477
+ return /* @__PURE__ */ jsx(
4478
+ "section",
4479
+ {
4480
+ "aria-label": itemTitle(item, props.inbox, props.resolveUser, props.labels),
4481
+ onKeyDown,
4482
+ className: cn(
4483
+ "pointer-events-auto flex w-[22rem] max-w-[calc(100vw-2rem)] flex-col overflow-hidden rounded-t-xl border border-b-0 bg-background shadow-xl",
4484
+ // An open window is at most 26rem tall, and never more than 60% of the screen's height,
4485
+ // so the page under it stays in view.
4486
+ item.minimized ? "h-auto" : "h-[min(26rem,60dvh)]"
4487
+ ),
4488
+ "data-testid": "genesis-chat-dock-window",
4489
+ "data-minimized": item.minimized || void 0,
4490
+ children: /* @__PURE__ */ jsx(DockItemView, { ...props, inSheet: false, visible: !item.minimized, toggleRef })
4491
+ }
4492
+ );
4493
+ }
4494
+ function SheetSwitcher({ items, activeId, inbox, resolveUser, labels }) {
4495
+ const dock = useChatDock();
4496
+ const tabs = useRef([]);
4497
+ const onKeyDown = (e) => {
4498
+ const at = items.findIndex((i) => i.id === activeId);
4499
+ const to = e.key === "ArrowRight" ? at + 1 : e.key === "ArrowLeft" ? at - 1 : e.key === "Home" ? 0 : e.key === "End" ? items.length - 1 : null;
4500
+ if (to === null) return;
4501
+ e.preventDefault();
4502
+ const next = items[(to + items.length) % items.length];
4503
+ dock.activate(next.id);
4504
+ tabs.current[items.indexOf(next)]?.focus();
4505
+ };
4506
+ return /* @__PURE__ */ jsx("div", { role: "tablist", "aria-label": labels.sheetTitle, onKeyDown, className: "flex shrink-0 gap-1 overflow-x-auto border-b px-2 py-1.5", "data-testid": "genesis-chat-dock-switcher", children: items.map((i, n) => {
4507
+ const selected = i.id === activeId;
4508
+ const count = selected ? 0 : itemUnread(i, inbox);
4509
+ return /* @__PURE__ */ jsxs(
4510
+ "button",
4511
+ {
4512
+ ref: (el) => {
4513
+ tabs.current[n] = el;
4514
+ },
4515
+ type: "button",
4516
+ role: "tab",
4517
+ id: `genesis-chat-dock-tab-${i.id}`,
4518
+ "aria-selected": selected,
4519
+ "aria-controls": `genesis-chat-dock-panel-${i.id}`,
4520
+ tabIndex: selected ? 0 : -1,
4521
+ onClick: () => dock.activate(i.id),
4522
+ className: cn(
4523
+ "flex min-h-9 max-w-[10rem] shrink-0 items-center gap-1.5 rounded-full px-3 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
4524
+ selected ? "bg-accent font-medium text-accent-foreground" : "text-muted-foreground hover:bg-accent/60"
4525
+ ),
4526
+ children: [
4527
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: itemTitle(i, inbox, resolveUser, labels) }),
4528
+ count > 0 ? /* @__PURE__ */ jsx("span", { className: "inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-primary px-1 text-[10px] font-semibold text-primary-foreground", "aria-label": labels.unread(count), children: count > 99 ? "99+" : count }) : null
4529
+ ]
4530
+ },
4531
+ i.id
4532
+ );
4533
+ }) });
4534
+ }
4535
+ function ChatDock({ resolveUser, threadProps, labels: labelOverrides, bubble = true, className }) {
4536
+ const dock = useChatDock();
4537
+ const narrow = useIsMobile();
4538
+ const width = useViewportWidth();
4539
+ const labels = useMemo(() => ({ ...defaultChatDockLabels, ...labelOverrides }), [labelOverrides]);
4540
+ const { items: inboxItems } = useInbox();
4541
+ const inbox = useMemo(() => new Map(inboxItems.map((i) => [i.conversationId, i])), [inboxItems]);
4542
+ if (dock.items.length === 0) return null;
4543
+ const active = dock.items.find((i) => i.id === dock.activeId) ?? dock.items[0];
4544
+ const seen = (i) => narrow ? dock.sheetOpen && i.id === active.id : !i.minimized;
4545
+ const unreadTotal = dock.items.reduce((n, i) => n + (seen(i) ? 0 : itemUnread(i, inbox)), 0);
4546
+ const announce = /* @__PURE__ */ jsx("span", { className: "sr-only", "aria-live": "polite", "data-testid": "genesis-chat-dock-announce", children: labels.unreadTotal(unreadTotal) });
4547
+ if (narrow) {
4548
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
4549
+ announce,
4550
+ bubble && !dock.sheetOpen ? /* @__PURE__ */ jsx("div", { className: cn("pointer-events-none flex justify-end p-4", className), children: /* @__PURE__ */ jsxs(
4551
+ "button",
4552
+ {
4553
+ type: "button",
4554
+ onClick: () => dock.setSheetOpen(true),
4555
+ "aria-label": `${labels.openDock}${unreadTotal > 0 ? `, ${labels.unread(unreadTotal)}` : ""}`,
4556
+ "aria-haspopup": "dialog",
4557
+ className: "pointer-events-auto relative flex h-14 w-14 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
4558
+ "data-testid": "genesis-chat-dock-bubble",
4559
+ children: [
4560
+ /* @__PURE__ */ jsx(MessageCircle, { className: "h-6 w-6", "aria-hidden": true }),
4561
+ unreadTotal > 0 ? /* @__PURE__ */ jsx("span", { className: "absolute -right-0.5 -top-0.5 inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-destructive px-1 text-[11px] font-semibold text-destructive-foreground ring-2 ring-background", "aria-hidden": true, children: unreadTotal > 99 ? "99+" : unreadTotal }) : null
4562
+ ]
4563
+ }
4564
+ ) }) : null,
4565
+ /* @__PURE__ */ jsx(Sheet, { open: dock.sheetOpen, onOpenChange: dock.setSheetOpen, children: /* @__PURE__ */ jsxs(SheetContent, { side: "right", showCloseButton: false, className: "flex w-full flex-col gap-0 p-0 sm:max-w-md", "data-testid": "genesis-chat-dock-sheet", children: [
4566
+ /* @__PURE__ */ jsx(SheetTitle, { className: "sr-only", children: labels.sheetTitle }),
4567
+ /* @__PURE__ */ jsx(SheetDescription, { className: "sr-only", children: labels.sheetDescription }),
4568
+ dock.items.length > 1 ? /* @__PURE__ */ jsx(SheetSwitcher, { items: dock.items, activeId: active.id, inbox, resolveUser, labels }) : null,
4569
+ dock.items.map((i) => /* @__PURE__ */ jsx(
4570
+ "div",
4571
+ {
4572
+ role: dock.items.length > 1 ? "tabpanel" : void 0,
4573
+ id: `genesis-chat-dock-panel-${i.id}`,
4574
+ "aria-labelledby": dock.items.length > 1 ? `genesis-chat-dock-tab-${i.id}` : void 0,
4575
+ hidden: i.id !== active.id,
4576
+ className: "flex min-h-0 flex-1 flex-col",
4577
+ children: /* @__PURE__ */ jsx(
4578
+ DockItemView,
4579
+ {
4580
+ item: i,
4581
+ inbox,
4582
+ resolveUser,
4583
+ threadProps,
4584
+ labels,
4585
+ inSheet: true,
4586
+ visible: dock.sheetOpen && i.id === active.id,
4587
+ focus: dock.focusId === i.id
4588
+ }
4589
+ )
4590
+ },
4591
+ i.id
4592
+ ))
4593
+ ] }) })
4594
+ ] });
4595
+ }
4596
+ const shown = dock.items.slice(0, chatDockWindowsThatFit(width, dock.items.length));
4597
+ const waiting = dock.items.slice(shown.length);
4598
+ return /* @__PURE__ */ jsxs("div", { className: cn("pointer-events-none flex flex-row-reverse items-end gap-3 px-4", className), "data-testid": "genesis-chat-dock", children: [
4599
+ announce,
4600
+ shown.map((item) => /* @__PURE__ */ jsx(DockWindow, { item, inbox, resolveUser, threadProps, labels, focus: dock.focusId === item.id }, item.id)),
4601
+ waiting.length > 0 ? /* @__PURE__ */ jsxs(DropdownMenu, { children: [
4602
+ /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
4603
+ Button,
4604
+ {
4605
+ type: "button",
4606
+ variant: "secondary",
4607
+ className: "pointer-events-auto mb-1 h-11 min-w-11 rounded-full shadow-lg",
4608
+ style: { width: MORE_PX - GAP_PX },
4609
+ "aria-label": labels.moreLabel(waiting.length),
4610
+ "data-testid": "genesis-chat-dock-more",
4611
+ children: labels.more(waiting.length)
4612
+ }
4613
+ ) }),
4614
+ /* @__PURE__ */ jsx(DropdownMenuContent, { align: "end", side: "top", children: waiting.map((i) => /* @__PURE__ */ jsxs(DropdownMenuItem, { onSelect: () => dock.bringToFront(i.id), children: [
4615
+ itemTitle(i, inbox, resolveUser, labels),
4616
+ itemUnread(i, inbox) > 0 ? ` (${labels.unread(itemUnread(i, inbox))})` : ""
4617
+ ] }, i.id)) })
4618
+ ] }) : null
4619
+ ] });
4620
+ }
4097
4621
 
4098
- export { ChatAttachmentCard, ChatAvailabilitySettings, ChatAwayBanner, ChatBroadcast, ChatComposer, ChatEmojiPicker, ChatInbox, ChatLinkPreview, ChatMarkdown, ChatPanel, ChatScheduleMenu, ChatScheduledList, ChatSearch, ChatThread, ChatTopicBar, ChatVideoPlayer, ChatVideoRecorder, FileChip, GenericAttachment, ImageGrid, Lightbox, MessageAttachments, MessageRow, QUICK_REACTIONS, SearchSnippet, VideoAttachment, VoiceNote, canPickEmoji, clockTime, createMemoryChatClient, formatBytes, inboxTitle, isSafeHref, linkPreviewImageSrc, messageLabel, muxPosterUrl, muxStreamUrl, parseMarkdown, pickVideoMimeType, pickVoiceMimeType, plainText, relativeTime, toAttachmentView, toLocalInput, uploadVideo, useVideoRecorder, useVoiceRecorder, videoFile, voiceFile };
4622
+ export { ChatAttachmentCard, ChatAvailabilitySettings, ChatAwayBanner, ChatBroadcast, ChatComposer, ChatDock, ChatDockProvider, ChatEmojiPicker, ChatInbox, ChatLinkPreview, ChatMarkdown, ChatPanel, ChatScheduleMenu, ChatScheduledList, ChatSearch, ChatThread, ChatTopicBar, ChatVideoPlayer, ChatVideoRecorder, FileChip, GenericAttachment, ImageGrid, Lightbox, MessageAttachments, MessageRow, QUICK_REACTIONS, SearchSnippet, VideoAttachment, VoiceNote, canPickEmoji, chatDockReducer, chatDockWindowsThatFit, clockTime, createMemoryChatClient, defaultChatDockLabels, emptyChatDock, forgetChatDock, formatBytes, inboxTitle, isSafeHref, linkPreviewImageSrc, messageLabel, muxPosterUrl, muxStreamUrl, parseMarkdown, pickVideoMimeType, pickVoiceMimeType, plainText, relativeTime, toAttachmentView, toLocalInput, uploadVideo, useChatDock, useOptionalChatDock, useVideoRecorder, useVoiceRecorder, videoFile, voiceFile };
4099
4623
  //# sourceMappingURL=web.js.map
4100
4624
  //# sourceMappingURL=web.js.map