@nivaro/react 0.3.117 → 0.3.118

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 (137) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +1 -1
  3. package/dist/index.d.ts +136 -14
  4. package/dist/index.js +488 -485
  5. package/dist/shared/components/ActivityEntry.js +130 -125
  6. package/dist/shared/components/AgentPresenceChip.js +36 -26
  7. package/dist/shared/components/CellCopyLayer.js +50 -45
  8. package/dist/shared/components/CollectionBrowserView.js +3757 -3695
  9. package/dist/shared/components/FilePreviewLightbox.js +96 -58
  10. package/dist/shared/components/InStep.js +18 -17
  11. package/dist/shared/components/ItemEditForm.js +4220 -4175
  12. package/dist/shared/components/JobsTray.js +8 -8
  13. package/dist/shared/components/LiveNewMatchesPill.js +21 -14
  14. package/dist/shared/components/LiveOffNote.js +3 -2
  15. package/dist/shared/components/LiveRowMark.js +53 -23
  16. package/dist/shared/components/LiveTraceView.js +162 -123
  17. package/dist/shared/components/MyWorkView.js +320 -299
  18. package/dist/shared/components/NotificationBell.js +14 -14
  19. package/dist/shared/components/OverflowRail.js +1 -1
  20. package/dist/shared/components/PageRenderer.js +120 -116
  21. package/dist/shared/components/ProfileView.js +203 -202
  22. package/dist/shared/components/RealtimeStatusBanner.js +31 -29
  23. package/dist/shared/components/RecordDrilldownSheet.js +7 -7
  24. package/dist/shared/components/RecordHoverCard.js +102 -84
  25. package/dist/shared/components/RecordReadView.js +146 -146
  26. package/dist/shared/components/ScreenRefreshButton.js +34 -32
  27. package/dist/shared/components/TipLayer.js +65 -58
  28. package/dist/shared/components/WidgetImageMenu.js +83 -43
  29. package/dist/shared/components/activity/RecordActivityStream.js +175 -173
  30. package/dist/shared/components/bulk/BulkSelectionNotices.js +142 -119
  31. package/dist/shared/components/change-proposals/ChangeProposalsPanel.js +158 -143
  32. package/dist/shared/components/change-proposals/ProposeChangeButton.js +17 -11
  33. package/dist/shared/components/change-proposals/ProposeChangeDialog.js +201 -173
  34. package/dist/shared/components/chat/ChatAnalyticsView.js +27 -27
  35. package/dist/shared/components/chat/HuddleAnalyticsTab.js +17 -17
  36. package/dist/shared/components/collections-directory/CollectionsToolbar.js +39 -41
  37. package/dist/shared/components/collections-directory/page-model.js +72 -67
  38. package/dist/shared/components/integrations/RecordIntegrationPreview.js +48 -56
  39. package/dist/shared/components/integrations/SendStatus.js +65 -59
  40. package/dist/shared/components/integrations/console/ReadyToSendView.js +275 -209
  41. package/dist/shared/components/integrations/console/SignalCard.js +237 -230
  42. package/dist/shared/components/item-edit/CatalogPickerField.js +227 -205
  43. package/dist/shared/components/item-edit/ChangedAfterApprovalBadge.js +131 -92
  44. package/dist/shared/components/item-edit/CloneDialog.js +191 -161
  45. package/dist/shared/components/item-edit/DerivedCauseNote.js +44 -30
  46. package/dist/shared/components/item-edit/DraftRecoveryBanner.js +153 -134
  47. package/dist/shared/components/item-edit/FieldComments.js +54 -53
  48. package/dist/shared/components/item-edit/FieldPointer.js +82 -67
  49. package/dist/shared/components/item-edit/FieldRow.js +106 -100
  50. package/dist/shared/components/item-edit/FieldSourceBadge.js +58 -56
  51. package/dist/shared/components/item-edit/FilePickerField.js +452 -387
  52. package/dist/shared/components/item-edit/HeaderSummaryChip.js +78 -56
  53. package/dist/shared/components/item-edit/HeaderTools.js +94 -85
  54. package/dist/shared/components/item-edit/InlineTableField.js +1242 -1218
  55. package/dist/shared/components/item-edit/ListNeighborNav.js +47 -50
  56. package/dist/shared/components/item-edit/LiveTraceSheet.js +15 -10
  57. package/dist/shared/components/item-edit/MembershipSetField.js +285 -254
  58. package/dist/shared/components/item-edit/OutboxReviewTray.js +155 -144
  59. package/dist/shared/components/item-edit/QueueReturnChip.js +15 -36
  60. package/dist/shared/components/item-edit/RecalcValue.js +57 -32
  61. package/dist/shared/components/item-edit/RecordHelpChip.js +21 -22
  62. package/dist/shared/components/item-edit/RecordLiveSync.js +283 -231
  63. package/dist/shared/components/item-edit/RelationCombobox.js +439 -393
  64. package/dist/shared/components/item-edit/RemoteChangeUi.js +292 -224
  65. package/dist/shared/components/item-edit/RemoteUploads.js +26 -20
  66. package/dist/shared/components/item-edit/RemovedLineNote.js +77 -67
  67. package/dist/shared/components/item-edit/RichTextEditorImpl.js +184 -179
  68. package/dist/shared/components/item-edit/ScheduledChangeChip.js +168 -134
  69. package/dist/shared/components/item-edit/SectionPresence.js +18 -10
  70. package/dist/shared/components/item-edit/SplitLinesButton.js +163 -139
  71. package/dist/shared/components/item-edit/UserChip.js +1 -1
  72. package/dist/shared/components/item-edit/file-live.js +69 -54
  73. package/dist/shared/components/item-edit/layout-switch.js +98 -89
  74. package/dist/shared/components/item-edit/partner-needs.js +12 -12
  75. package/dist/shared/components/item-edit/removed-line.js +31 -25
  76. package/dist/shared/components/layout-editor/pickers/field-picker.js +112 -104
  77. package/dist/shared/components/list/ListViewers.js +46 -35
  78. package/dist/shared/components/notifications/NotificationCenterView.js +479 -437
  79. package/dist/shared/components/panels/AccessDeniedPanel.js +176 -101
  80. package/dist/shared/components/panels/AlertBanners.js +82 -72
  81. package/dist/shared/components/panels/BranchLanes.js +22 -22
  82. package/dist/shared/components/panels/CommentImages.js +123 -102
  83. package/dist/shared/components/panels/CommentPanel.js +186 -185
  84. package/dist/shared/components/panels/ExternalRequestsChip.js +111 -119
  85. package/dist/shared/components/panels/OwnerOpenedLine.js +31 -24
  86. package/dist/shared/components/panels/PipelinePanel.js +2037 -1885
  87. package/dist/shared/components/panels/ResubmissionDiff.js +163 -142
  88. package/dist/shared/components/pipeline/OwnerMatrixSheet.js +400 -288
  89. package/dist/shared/components/pipeline/PipelineEditorView.js +7 -2
  90. package/dist/shared/components/profile/AgentNameField.js +107 -81
  91. package/dist/shared/components/profile/AgentsPanel.js +184 -184
  92. package/dist/shared/components/profile/PersonAccess.js +599 -495
  93. package/dist/shared/components/profile/SignInTroubleshooter.js +160 -127
  94. package/dist/shared/components/profile/SignedInDevices.js +17 -17
  95. package/dist/shared/components/profile/primitives.js +1 -1
  96. package/dist/shared/components/queue/OwnerAvatars.js +91 -54
  97. package/dist/shared/components/queue/QueueTeamStrip.js +56 -46
  98. package/dist/shared/components/queue/QueueWorklist.js +1002 -983
  99. package/dist/shared/components/support/AssignRules.js +1733 -0
  100. package/dist/shared/components/support/PersonPick.js +88 -0
  101. package/dist/shared/components/support/RequestList.js +790 -0
  102. package/dist/shared/components/support/ScreenShare.js +158 -152
  103. package/dist/shared/components/support/SupportRequestDialog.js +50 -48
  104. package/dist/shared/components/support/SupportView.js +140 -246
  105. package/dist/shared/components/support/TicketDetailSheet.js +82 -75
  106. package/dist/shared/components/support/TicketSlowScreens.js +9 -9
  107. package/dist/shared/components/support/assign-rules-text.js +171 -0
  108. package/dist/shared/components/support/support-list.js +125 -0
  109. package/dist/shared/components/ui/SimpleSelect.js +28 -20
  110. package/dist/shared/components/ui/checkbox.js +6 -6
  111. package/dist/shared/components/ui/select.js +43 -39
  112. package/dist/shared/components/ui/sheet.js +9 -9
  113. package/dist/shared/components/ui/switch.js +12 -11
  114. package/dist/shared/components/watch-list/WatchDock.js +532 -459
  115. package/dist/shared/components/watch-list/WatchExtras.js +332 -286
  116. package/dist/shared/components/watch-list/WatchRows.js +164 -140
  117. package/dist/shared/lib/activity-sentence.js +103 -91
  118. package/dist/shared/lib/agent-presence.js +27 -21
  119. package/dist/shared/lib/approval-progress.js +2 -2
  120. package/dist/shared/lib/copy-rules.js +31 -24
  121. package/dist/shared/lib/derived-causes.js +113 -78
  122. package/dist/shared/lib/grid-cursors.js +26 -26
  123. package/dist/shared/lib/label-flash.js +27 -0
  124. package/dist/shared/lib/list-return.js +137 -125
  125. package/dist/shared/lib/live-deltas.js +40 -34
  126. package/dist/shared/lib/live-groups.js +56 -52
  127. package/dist/shared/lib/live-preference.js +64 -59
  128. package/dist/shared/lib/live-screen.js +223 -192
  129. package/dist/shared/lib/partner-failure.js +11 -11
  130. package/dist/shared/lib/rollup-recalc.js +68 -64
  131. package/dist/shared/lib/screen-refresh.js +74 -68
  132. package/dist/shared/lib/screen-share.js +108 -104
  133. package/dist/shared/lib/send-status.js +77 -61
  134. package/dist/shared/lib/text-diff-window.js +29 -0
  135. package/dist/shared/lib/watch-list.js +210 -209
  136. package/dist/shared/lib/widget-image-render.js +72 -49
  137. package/package.json +1 -1
@@ -0,0 +1,1733 @@
1
+ import { jsx as t, jsxs as o, Fragment as N } from "react/jsx-runtime";
2
+ import { useSensors as _e, useSensor as X, PointerSensor as qe, KeyboardSensor as Re, DndContext as Pe, closestCenter as Te } from "@dnd-kit/core";
3
+ import { sortableKeyboardCoordinates as Ee, SortableContext as Le, verticalListSortingStrategy as De, arrayMove as Ae, useSortable as Oe } from "@dnd-kit/sortable";
4
+ import { CSS as Ue } from "@dnd-kit/utilities";
5
+ import { useQueryClient as We, useQuery as E, useMutation as le } from "@tanstack/react-query";
6
+ import { ChevronDown as se, Plus as G, Route as ne, GripVertical as Me, Check as ie, Pencil as je, Copy as oe, Trash2 as $e, X as L } from "lucide-react";
7
+ import { useState as w, useEffect as ee, useRef as Ie, useMemo as Be } from "react";
8
+ import { toast as Fe } from "sonner";
9
+ import { useNivaroClient as W } from "../../context.js";
10
+ import { get as A, post as de, put as Ke } from "../../lib/commands.js";
11
+ import { toastError as ce } from "../../lib/error-toast.js";
12
+ import { useUnsavedWork as Ge } from "../../lib/unsaved-work.js";
13
+ import { cn as h } from "../../lib/utils.js";
14
+ import { ErrorNotice as He } from "../ErrorNotice.js";
15
+ import { RelationCombobox as q } from "../item-edit/RelationCombobox.js";
16
+ import { ConfirmButton as Ve } from "../profile/primitives.js";
17
+ import { Command as ue, CommandList as pe, CommandGroup as F, CommandItem as me, CommandInput as Ye, CommandEmpty as ze } from "../ui/command.js";
18
+ import { Popover as he, PopoverTrigger as be, PopoverContent as xe } from "../ui/popover.js";
19
+ import { SimpleSelect as g } from "../ui/SimpleSelect.js";
20
+ import { Switch as Qe } from "../ui/switch.js";
21
+ import { hoursWords as Je, blankRule as te, clock12 as ae, ruleSentence as Ze, SOURCE_LABELS as O, STRATEGY_OPTIONS as K } from "./assign-rules-text.js";
22
+ import { PersonDisc as D } from "./PersonPick.js";
23
+ const T = "h-8 rounded-md border border-slate-200 bg-white px-2.5 text-[12.5px] text-slate-900 outline-none placeholder:text-slate-400 focus:border-nvr-cyan dark:border-border dark:bg-background dark:text-slate-100", f = "h-8 w-auto min-w-[8rem] gap-1.5 rounded-md border-slate-200 bg-white px-2.5 text-[12.5px] text-slate-800 dark:border-border dark:bg-background dark:text-slate-100", R = "min-w-0 [&>div>button]:h-8 [&>div>button]:rounded-md [&>div>button]:border-slate-200 [&>div>button]:bg-white [&>div>button]:px-2.5 [&>div>button]:text-[12.5px] dark:[&>div>button]:border-border dark:[&>div>button]:bg-card", U = "inline-flex h-8 items-center gap-1.5 rounded-md px-2.5 text-[12.5px] text-slate-600 hover:bg-slate-100 dark:text-slate-300 dark:hover:bg-white/10", M = "inline-flex h-8 items-center gap-1.5 rounded-md bg-nvr-cyan px-3 text-[12.5px] font-medium text-white hover:brightness-95 disabled:opacity-50", ge = [
24
+ { value: "type", label: "Request type", description: "The type the person picked." },
25
+ {
26
+ value: "about",
27
+ label: "What it is about",
28
+ description: "A record of some kind, or General Support."
29
+ },
30
+ {
31
+ value: "field",
32
+ label: "A field on the record",
33
+ description: "Zone, Region, Project type… read when the request comes in."
34
+ },
35
+ {
36
+ value: "step",
37
+ label: "The record’s step",
38
+ description: "Where the record is in its pipeline."
39
+ },
40
+ { value: "requester", label: "Who raised it", description: "Particular people." },
41
+ { value: "requester_role", label: "Requester’s role", description: "Their role in Nivaro." },
42
+ { value: "requester_team", label: "Requester’s team", description: "A team they belong to." },
43
+ { value: "priority", label: "Priority", description: "Low, normal or urgent." },
44
+ {
45
+ value: "text",
46
+ label: "Words in the title or description",
47
+ description: "Any, all or none of some words."
48
+ },
49
+ {
50
+ value: "source",
51
+ label: "Where it was raised",
52
+ description: "Get help, a record, an error, Report a problem."
53
+ },
54
+ { value: "hours", label: "When it comes in", description: "Inside or outside business hours." }
55
+ ], Xe = [
56
+ { value: "in", label: "is one of" },
57
+ { value: "not_in", label: "is not one of" }
58
+ ];
59
+ function et(e, r) {
60
+ var s;
61
+ switch (e) {
62
+ case "type":
63
+ return { kind: e, op: "in", values: [] };
64
+ case "about":
65
+ return { kind: e, op: "record_in", collections: [] };
66
+ case "field":
67
+ return {
68
+ kind: e,
69
+ collection: ((s = r == null ? void 0 : r.collections[0]) == null ? void 0 : s.collection) ?? "",
70
+ field: "",
71
+ op: "in",
72
+ values: []
73
+ };
74
+ case "step":
75
+ return { kind: e, op: "in", states: [] };
76
+ case "requester":
77
+ return { kind: e, op: "in", users: [] };
78
+ case "requester_role":
79
+ return { kind: e, op: "in", roles: [] };
80
+ case "requester_team":
81
+ return { kind: e, op: "in", teams: [] };
82
+ case "priority":
83
+ return { kind: e, op: "in", values: ["urgent"] };
84
+ case "text":
85
+ return { kind: e, op: "any", words: [] };
86
+ case "source":
87
+ return { kind: e, op: "in", values: ["error"] };
88
+ case "hours":
89
+ return { kind: e, op: "outside" };
90
+ }
91
+ }
92
+ function tt(e) {
93
+ const r = [];
94
+ for (const s of e) {
95
+ for (const i of s.conditions)
96
+ i.kind === "requester" && r.push(...i.users), i.kind === "field" && r.push(`${i.collection}.${i.field}:${i.values.join(",")}`);
97
+ s.action.kind === "person" && r.push(s.action.user), s.action.kind === "share" && r.push(...s.action.people.map((i) => i.id)), s.fallback.kind === "person" && r.push(s.fallback.user);
98
+ }
99
+ return [...new Set(r)].sort().join("|");
100
+ }
101
+ function Bt() {
102
+ var J, Z;
103
+ const e = W(), r = We(), s = E({
104
+ queryKey: ["support-assign-rules"],
105
+ queryFn: () => e.request(A("/support/assign-rules"))
106
+ }), { data: i } = E({
107
+ queryKey: ["support-assign-options"],
108
+ queryFn: () => e.request(A("/support/assign-rules/options")).then((c) => c.data)
109
+ }), [a, n] = w(null), [d, p] = w(null), [u, l] = w([]), [b, m] = w(!1);
110
+ ee(() => {
111
+ s.data && a == null && n(s.data.data);
112
+ }, [s.data, a]);
113
+ const k = !!a && !!s.data && JSON.stringify(a) !== JSON.stringify(s.data.data);
114
+ Ge(k, "Support assignment rules");
115
+ const P = a ? tt(a.rules) : "", { data: C } = E({
116
+ queryKey: ["support-assign-labels", P],
117
+ enabled: !!a && k && !!P,
118
+ staleTime: 6e4,
119
+ queryFn: () => e.request(
120
+ de("/support/assign-rules/labels", { rules: (a == null ? void 0 : a.rules) ?? [] })
121
+ ).then((c) => c.data).catch(() => null)
122
+ }), j = {
123
+ people: { ...((J = s.data) == null ? void 0 : J.labels.people) ?? {}, ...(C == null ? void 0 : C.people) ?? {} },
124
+ values: { ...((Z = s.data) == null ? void 0 : Z.labels.values) ?? {}, ...(C == null ? void 0 : C.values) ?? {} }
125
+ }, $ = at(i, j), I = le({
126
+ mutationFn: (c) => e.request(Ke("/support/assign-rules", c)).then((x) => x.data),
127
+ onSuccess: (c) => {
128
+ l([]), n(c), p(null), r.invalidateQueries({ queryKey: ["support-assign-rules"] }), Fe.success("Assignment rules saved");
129
+ },
130
+ onError: (c) => {
131
+ var v, y;
132
+ const x = c.response;
133
+ if ((v = x == null ? void 0 : x.errors) != null && v.length) {
134
+ l(x.errors);
135
+ const S = x.errors.find((Se) => Se.rule >= 0);
136
+ S && a && p(((y = a.rules[S.rule]) == null ? void 0 : y.id) ?? null);
137
+ } else ce(c, "Could not save the rules");
138
+ }
139
+ }), V = Ie(null), [ke, Y] = w(!1);
140
+ ee(() => {
141
+ const c = V.current;
142
+ if (!c || typeof IntersectionObserver > "u") return Y(!1);
143
+ const x = new IntersectionObserver(([v]) => {
144
+ var S;
145
+ const y = ((S = v.rootBounds) == null ? void 0 : S.bottom) ?? window.innerHeight;
146
+ Y(!v.isIntersecting && v.boundingClientRect.top >= y - 1);
147
+ });
148
+ return x.observe(c), () => x.disconnect();
149
+ }, [k]);
150
+ const ye = _e(
151
+ X(qe, { activationConstraint: { distance: 4 } }),
152
+ X(Re, { coordinateGetter: Ee })
153
+ ), Ne = (c) => {
154
+ if (!a || !c.over || c.active.id === c.over.id) return;
155
+ const x = a.rules.findIndex((y) => y.id === c.active.id), v = a.rules.findIndex((y) => {
156
+ var S;
157
+ return y.id === ((S = c.over) == null ? void 0 : S.id);
158
+ });
159
+ x < 0 || v < 0 || n({ ...a, rules: Ae(a.rules, x, v) });
160
+ };
161
+ if (s.isLoading || !a)
162
+ return s.isError ? /* @__PURE__ */ t("div", { className: "mt-4", children: /* @__PURE__ */ t(
163
+ He,
164
+ {
165
+ error: s.error,
166
+ what: "the assignment rules",
167
+ onRetry: () => void s.refetch()
168
+ }
169
+ ) }) : /* @__PURE__ */ t("div", { className: "mt-4 space-y-2", "aria-busy": !0, children: [0, 1, 2].map((c) => /* @__PURE__ */ t("div", { className: "h-14 animate-pulse rounded-lg bg-[hsl(var(--nvr-skeleton))]" }, c)) });
170
+ const we = (c, x) => n({ ...a, rules: a.rules.map((v) => v.id === c ? x : v) }), z = () => {
171
+ const c = te(a.rules.length + 1);
172
+ n({ ...a, rules: [...a.rules, c] }), p(c.id);
173
+ }, Ce = (c) => u.filter((x) => x.rule === c).map((x) => x.message), Q = u.filter((c) => c.rule < 0).map((c) => c.message);
174
+ return /* @__PURE__ */ o("div", { className: "mt-4 space-y-4", "data-support-assign-rules": !0, children: [
175
+ /* @__PURE__ */ o("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [
176
+ /* @__PURE__ */ t("p", { className: "max-w-2xl text-[12.5px] text-slate-600 dark:text-muted-foreground", children: "When someone raises a request, the first rule that fits decides who gets it. If none fits, the request type’s default assignee takes it, else it waits on the desk. Drag rules to change their order." }),
177
+ /* @__PURE__ */ o(
178
+ "button",
179
+ {
180
+ type: "button",
181
+ onClick: () => m((c) => !c),
182
+ "aria-expanded": b,
183
+ "data-support-hours-toggle": !0,
184
+ className: "inline-flex items-center gap-1.5 rounded-md border border-slate-200 bg-white px-2.5 py-1.5 text-[12px] text-slate-700 hover:border-slate-300 dark:border-border dark:bg-card dark:text-slate-200",
185
+ children: [
186
+ /* @__PURE__ */ t("span", { className: "text-slate-500 dark:text-muted-foreground", children: "Business hours" }),
187
+ Je(a.hours),
188
+ /* @__PURE__ */ t(
189
+ se,
190
+ {
191
+ className: h("h-3.5 w-3.5 opacity-60 transition-transform", b && "rotate-180")
192
+ }
193
+ )
194
+ ]
195
+ }
196
+ )
197
+ ] }),
198
+ b && /* @__PURE__ */ t(xt, { hours: a.hours, onChange: (c) => n({ ...a, hours: c }) }),
199
+ Q.length > 0 && /* @__PURE__ */ t(H, { messages: Q }),
200
+ a.rules.length === 0 ? /* @__PURE__ */ t(rt, { onAdd: z }) : /* @__PURE__ */ t(Pe, { sensors: ye, collisionDetection: Te, onDragEnd: Ne, children: /* @__PURE__ */ t(
201
+ Le,
202
+ {
203
+ items: a.rules.map((c) => c.id),
204
+ strategy: De,
205
+ children: /* @__PURE__ */ t("ol", { className: "space-y-2", "data-support-rule-list": !0, children: a.rules.map((c, x) => /* @__PURE__ */ t(
206
+ lt,
207
+ {
208
+ index: x,
209
+ rule: c,
210
+ names: $,
211
+ options: i,
212
+ editing: d === c.id,
213
+ errors: Ce(x),
214
+ onEdit: () => p(d === c.id ? null : c.id),
215
+ onChange: (v) => we(c.id, v),
216
+ onDuplicate: () => {
217
+ const v = {
218
+ ...structuredClone(c),
219
+ id: te(0).id,
220
+ name: `${c.name} (copy)`
221
+ }, y = [...a.rules];
222
+ y.splice(x + 1, 0, v), n({ ...a, rules: y }), p(v.id);
223
+ },
224
+ onDelete: () => {
225
+ n({ ...a, rules: a.rules.filter((v) => v.id !== c.id) }), d === c.id && p(null);
226
+ }
227
+ },
228
+ c.id
229
+ )) })
230
+ }
231
+ ) }),
232
+ a.rules.length > 0 && /* @__PURE__ */ o(
233
+ "button",
234
+ {
235
+ type: "button",
236
+ onClick: z,
237
+ className: h(U, "border border-dashed border-slate-300 dark:border-slate-600"),
238
+ "data-support-add-rule": !0,
239
+ children: [
240
+ /* @__PURE__ */ t(G, { className: "h-3.5 w-3.5" }),
241
+ " Add a rule"
242
+ ]
243
+ }
244
+ ),
245
+ k && /* @__PURE__ */ t(
246
+ "div",
247
+ {
248
+ className: h(
249
+ "sticky -bottom-6 z-10 -mx-1 bg-slate-50 px-1 pt-2 dark:bg-background",
250
+ // Stuck to the bottom: room for the host's padding below. In place: a normal gap.
251
+ ke ? "pb-9" : "pb-1"
252
+ ),
253
+ children: /* @__PURE__ */ o(
254
+ "div",
255
+ {
256
+ className: "flex flex-wrap items-center gap-2 rounded-lg border border-slate-200 bg-white px-3 py-2 shadow-[0_-2px_12px_rgba(15,23,42,0.08)] dark:border-border dark:bg-card dark:shadow-[0_-2px_12px_rgba(0,0,0,0.4)]",
257
+ "data-support-rules-savebar": !0,
258
+ children: [
259
+ /* @__PURE__ */ t("span", { className: "text-[12.5px] font-medium text-slate-800 dark:text-slate-100", children: "Unsaved changes" }),
260
+ /* @__PURE__ */ t("span", { className: "text-[12px] text-slate-500 dark:text-muted-foreground", children: "New requests keep using the saved rules until you save." }),
261
+ /* @__PURE__ */ o("span", { className: "ml-auto flex items-center gap-1", children: [
262
+ /* @__PURE__ */ t(
263
+ "button",
264
+ {
265
+ type: "button",
266
+ className: U,
267
+ onClick: () => {
268
+ var c;
269
+ n(((c = s.data) == null ? void 0 : c.data) ?? a), l([]), p(null);
270
+ },
271
+ children: "Discard"
272
+ }
273
+ ),
274
+ /* @__PURE__ */ t(
275
+ "button",
276
+ {
277
+ type: "button",
278
+ className: M,
279
+ disabled: I.isPending,
280
+ onClick: () => I.mutate(a),
281
+ "data-support-rules-save": !0,
282
+ children: I.isPending ? "Saving…" : "Save rules"
283
+ }
284
+ )
285
+ ] })
286
+ ]
287
+ }
288
+ )
289
+ }
290
+ ),
291
+ k && /* @__PURE__ */ t("div", { ref: V, "aria-hidden": !0, className: "-mt-4 h-px" }),
292
+ /* @__PURE__ */ t(ft, { draft: a, options: i, dirty: k })
293
+ ] });
294
+ }
295
+ function at(e, r) {
296
+ const [s] = w(() => /* @__PURE__ */ new Map());
297
+ return Be(() => {
298
+ const i = new Map(((e == null ? void 0 : e.types) ?? []).map((l) => [l.id, l.name])), a = new Map(((e == null ? void 0 : e.collections) ?? []).map((l) => [l.collection, l.name])), n = new Map(
299
+ Object.values((e == null ? void 0 : e.steps) ?? {}).flat().map((l) => [l.id.toUpperCase(), l.label])
300
+ ), d = new Map(((e == null ? void 0 : e.roles) ?? []).map((l) => [String(l.id).toUpperCase(), l.name])), p = new Map(((e == null ? void 0 : e.teams) ?? []).map((l) => [l.id, l.name])), u = (l) => s.get(l) ?? l.replace(/_id$/, "").replace(/[_-]+/g, " ").replace(/\b\w/g, (b) => b.toUpperCase());
301
+ return {
302
+ type: (l) => i.get(l) ?? `type #${l}`,
303
+ collection: (l) => a.get(l) ?? l,
304
+ field: (l, b) => u(b),
305
+ value: (l, b, m) => r.values[`${l}.${b}:${m}`] ?? m,
306
+ step: (l) => n.get(l.toUpperCase()) ?? "a step",
307
+ person: (l) => r.people[l.toUpperCase()] ?? "someone",
308
+ role: (l) => d.get(l.toUpperCase()) ?? "a role",
309
+ team: (l) => p.get(l) ?? "a team"
310
+ };
311
+ }, [e, r.people, r.values, s]);
312
+ }
313
+ function H({ messages: e }) {
314
+ return /* @__PURE__ */ t("ul", { className: "space-y-0.5 text-[12px] text-red-700 dark:text-red-300", role: "alert", children: e.map((r) => /* @__PURE__ */ t("li", { children: r }, r)) });
315
+ }
316
+ function rt({ onAdd: e }) {
317
+ return /* @__PURE__ */ o(
318
+ "div",
319
+ {
320
+ className: "flex flex-col items-center gap-2 rounded-lg border border-slate-200 bg-white px-6 py-10 text-center dark:border-border dark:bg-card",
321
+ "data-support-rules-empty": !0,
322
+ children: [
323
+ /* @__PURE__ */ t(ne, { className: "h-6 w-6 text-slate-300 dark:text-slate-600" }),
324
+ /* @__PURE__ */ t("p", { className: "text-[13px] font-medium text-slate-800 dark:text-slate-100", children: "No assignment rules yet" }),
325
+ /* @__PURE__ */ t("p", { className: "max-w-md text-[12.5px] text-slate-500 dark:text-muted-foreground", children: "Requests go to their type’s default assignee or wait on the desk. A rule can send them straight to the right person — for example, “When the type is Vendor change and the record’s Zone is East, share it among Beth and Sam — whoever has the fewest open requests.”" }),
326
+ /* @__PURE__ */ o(
327
+ "button",
328
+ {
329
+ type: "button",
330
+ onClick: e,
331
+ className: h(M, "mt-1"),
332
+ "data-support-add-rule": !0,
333
+ children: [
334
+ /* @__PURE__ */ t(G, { className: "h-3.5 w-3.5" }),
335
+ " Add the first rule"
336
+ ]
337
+ }
338
+ )
339
+ ]
340
+ }
341
+ );
342
+ }
343
+ function lt({
344
+ index: e,
345
+ rule: r,
346
+ names: s,
347
+ options: i,
348
+ editing: a,
349
+ errors: n,
350
+ onEdit: d,
351
+ onChange: p,
352
+ onDuplicate: u,
353
+ onDelete: l
354
+ }) {
355
+ const { attributes: b, listeners: m, setNodeRef: k, transform: P, transition: C, isDragging: j } = Oe({
356
+ id: r.id
357
+ });
358
+ return /* @__PURE__ */ o(
359
+ "li",
360
+ {
361
+ ref: k,
362
+ style: { transform: Ue.Transform.toString(P), transition: C },
363
+ "data-support-rule": r.id,
364
+ className: h(
365
+ "rounded-lg border bg-white dark:bg-card",
366
+ a ? "border-nvr-cyan/60 shadow-sm" : n.length ? "border-red-300 dark:border-red-500/50" : "border-slate-200 dark:border-border",
367
+ j && "relative z-10 shadow-lg"
368
+ ),
369
+ children: [
370
+ /* @__PURE__ */ o("div", { className: "grid grid-cols-[20px_24px_minmax(0,1fr)_auto] items-start gap-x-2 gap-y-1 px-2 py-2.5 sm:px-3", children: [
371
+ /* @__PURE__ */ t(
372
+ "button",
373
+ {
374
+ type: "button",
375
+ ...b,
376
+ ...m,
377
+ "aria-label": `Move rule ${e + 1}`,
378
+ "data-tip": "Drag to reorder",
379
+ className: "mt-0.5 flex h-6 w-5 shrink-0 cursor-grab items-center justify-center rounded text-slate-400 hover:bg-slate-100 active:cursor-grabbing dark:hover:bg-white/10",
380
+ children: /* @__PURE__ */ t(Me, { className: "h-4 w-4" })
381
+ }
382
+ ),
383
+ /* @__PURE__ */ t("span", { className: "mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-slate-100 text-[11px] font-semibold tabular-nums text-slate-600 dark:bg-white/10 dark:text-slate-300", children: e + 1 }),
384
+ /* @__PURE__ */ t("div", { className: h("mt-0.5 min-w-0", !r.active && "opacity-60"), children: /* @__PURE__ */ o("p", { className: "text-[13px] font-medium text-slate-900 dark:text-slate-100", children: [
385
+ r.name || "Untitled rule",
386
+ !r.active && /* @__PURE__ */ t("span", { className: "ml-2 rounded bg-slate-100 px-1.5 py-px text-[10.5px] font-medium text-slate-500 dark:bg-white/10 dark:text-slate-400", children: "Off" })
387
+ ] }) }),
388
+ /* @__PURE__ */ o("div", { className: "flex shrink-0 items-center gap-0.5", children: [
389
+ /* @__PURE__ */ t(
390
+ Qe,
391
+ {
392
+ checked: r.active,
393
+ onCheckedChange: ($) => p({ ...r, active: $ }),
394
+ "aria-label": r.active ? "Rule is on" : "Rule is off",
395
+ className: "mr-1 scale-90"
396
+ }
397
+ ),
398
+ /* @__PURE__ */ t(
399
+ "button",
400
+ {
401
+ type: "button",
402
+ onClick: d,
403
+ "aria-expanded": a,
404
+ "data-tip": a ? "Close the editor" : "Edit",
405
+ "aria-label": a ? "Close the editor" : "Edit",
406
+ className: "inline-flex h-7 w-7 items-center justify-center rounded text-slate-500 hover:bg-slate-100 hover:text-slate-800 dark:hover:bg-white/10 dark:hover:text-slate-100",
407
+ children: a ? /* @__PURE__ */ t(ie, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ t(je, { className: "h-3.5 w-3.5" })
408
+ }
409
+ ),
410
+ /* @__PURE__ */ t(
411
+ "button",
412
+ {
413
+ type: "button",
414
+ onClick: u,
415
+ "data-tip": "Duplicate",
416
+ "aria-label": "Duplicate",
417
+ className: "hidden h-7 w-7 items-center justify-center rounded text-slate-500 hover:bg-slate-100 hover:text-slate-800 sm:inline-flex dark:hover:bg-white/10 dark:hover:text-slate-100",
418
+ children: /* @__PURE__ */ t(oe, { className: "h-3.5 w-3.5" })
419
+ }
420
+ ),
421
+ /* @__PURE__ */ t(
422
+ Ve,
423
+ {
424
+ onConfirm: l,
425
+ title: "Delete",
426
+ confirmLabel: "Delete?",
427
+ className: "inline-flex h-7 min-w-7 items-center justify-center rounded px-1.5 text-[11.5px] text-slate-500 hover:bg-slate-100 hover:text-red-600 dark:hover:bg-white/10",
428
+ armedClassName: "!bg-red-600 !text-white hover:!bg-red-700 dark:!bg-red-600 dark:hover:!bg-red-700",
429
+ children: /* @__PURE__ */ t($e, { className: "h-3.5 w-3.5" })
430
+ }
431
+ )
432
+ ] }),
433
+ /* @__PURE__ */ o(
434
+ "div",
435
+ {
436
+ className: h(
437
+ "col-span-4 max-w-[80ch] sm:col-span-2 sm:col-start-3",
438
+ !r.active && "opacity-60"
439
+ ),
440
+ children: [
441
+ /* @__PURE__ */ t(
442
+ "p",
443
+ {
444
+ className: "text-[12.5px] leading-relaxed text-slate-600 dark:text-slate-300",
445
+ "data-support-rule-sentence": !0,
446
+ children: Ze(r, s)
447
+ }
448
+ ),
449
+ n.length > 0 && !a && /* @__PURE__ */ t(H, { messages: n })
450
+ ]
451
+ }
452
+ )
453
+ ] }),
454
+ a && /* @__PURE__ */ t(
455
+ st,
456
+ {
457
+ rule: r,
458
+ options: i,
459
+ errors: n,
460
+ onChange: p,
461
+ onDuplicate: u,
462
+ onDone: d
463
+ }
464
+ )
465
+ ]
466
+ }
467
+ );
468
+ }
469
+ function B({ title: e, hint: r, children: s }) {
470
+ return /* @__PURE__ */ o("section", { className: "space-y-2", children: [
471
+ /* @__PURE__ */ o("div", { children: [
472
+ /* @__PURE__ */ t("h4", { className: "text-[12.5px] font-semibold text-slate-800 dark:text-slate-100", children: e }),
473
+ r && /* @__PURE__ */ t("p", { className: "text-[11.5px] text-slate-500 dark:text-muted-foreground", children: r })
474
+ ] }),
475
+ s
476
+ ] });
477
+ }
478
+ function st({
479
+ rule: e,
480
+ options: r,
481
+ errors: s,
482
+ onChange: i,
483
+ onDuplicate: a,
484
+ onDone: n
485
+ }) {
486
+ const d = (u) => i({ ...e, ...u }), p = (u, l) => d({ conditions: e.conditions.map((b, m) => m === u ? l : b) });
487
+ return /* @__PURE__ */ o(
488
+ "div",
489
+ {
490
+ className: "space-y-5 border-t border-slate-100 px-3 pb-4 pt-4 sm:px-5 dark:border-border/60",
491
+ "data-support-rule-editor": !0,
492
+ children: [
493
+ s.length > 0 && /* @__PURE__ */ t(H, { messages: s }),
494
+ /* @__PURE__ */ o("label", { className: "block max-w-md", children: [
495
+ /* @__PURE__ */ t("span", { className: "mb-1 block text-[12px] font-medium text-slate-700 dark:text-slate-200", children: "Rule name" }),
496
+ /* @__PURE__ */ t(
497
+ "input",
498
+ {
499
+ value: e.name,
500
+ onChange: (u) => d({ name: u.target.value }),
501
+ placeholder: "e.g. Vendor changes East",
502
+ className: h(T, "w-full"),
503
+ "data-support-rule-name": !0
504
+ }
505
+ ),
506
+ /* @__PURE__ */ t("span", { className: "mt-1 block text-[11.5px] text-slate-500 dark:text-muted-foreground", children: "Shown to the desk in the request’s history. Requesters only see who got it." })
507
+ ] }),
508
+ /* @__PURE__ */ o(B, { title: "When", children: [
509
+ /* @__PURE__ */ o("div", { className: "flex flex-wrap items-center gap-2 text-[12.5px] text-slate-700 dark:text-slate-200", children: [
510
+ "A request matches when",
511
+ /* @__PURE__ */ o("span", { className: "inline-flex items-center gap-2 whitespace-nowrap", children: [
512
+ /* @__PURE__ */ t(
513
+ g,
514
+ {
515
+ value: e.match,
516
+ onChange: (u) => d({ match: u }),
517
+ options: [
518
+ { value: "all", label: "all of these" },
519
+ { value: "any", label: "any of these" }
520
+ ],
521
+ ariaLabel: "Match all or any",
522
+ className: f
523
+ }
524
+ ),
525
+ "are true",
526
+ e.conditions.length === 0 ? "" : ":"
527
+ ] }),
528
+ e.conditions.length === 0 && /* @__PURE__ */ t("span", { children: "— with none, every request matches." })
529
+ ] }),
530
+ /* @__PURE__ */ t("div", { className: "space-y-2", children: e.conditions.map((u, l) => /* @__PURE__ */ t(
531
+ it,
532
+ {
533
+ cond: u,
534
+ options: r,
535
+ first: l === 0,
536
+ match: e.match,
537
+ onChange: (b) => p(l, b),
538
+ onRemove: () => d({ conditions: e.conditions.filter((b, m) => m !== l) })
539
+ },
540
+ l
541
+ )) }),
542
+ /* @__PURE__ */ t(
543
+ nt,
544
+ {
545
+ onAdd: (u) => d({ conditions: [...e.conditions, et(u, r)] })
546
+ }
547
+ )
548
+ ] }),
549
+ /* @__PURE__ */ t(B, { title: "Then", children: /* @__PURE__ */ t(
550
+ mt,
551
+ {
552
+ action: e.action,
553
+ options: r,
554
+ onChange: (u) => d({ action: u })
555
+ }
556
+ ) }),
557
+ e.action.kind !== "team" && /* @__PURE__ */ t(
558
+ B,
559
+ {
560
+ title: "If nobody on it can take it",
561
+ hint: "Everyone is out, at their cap, or the record has no step owner.",
562
+ children: /* @__PURE__ */ o("div", { className: "flex flex-wrap items-center gap-2", children: [
563
+ /* @__PURE__ */ t(
564
+ g,
565
+ {
566
+ value: e.fallback.kind,
567
+ onChange: (u) => d({ fallback: u === "person" ? { kind: "person", user: "" } : { kind: "desk" } }),
568
+ options: [
569
+ { value: "desk", label: "Leave it on the desk" },
570
+ { value: "person", label: "Give it to…" }
571
+ ],
572
+ ariaLabel: "If nobody can take it",
573
+ className: f
574
+ }
575
+ ),
576
+ e.fallback.kind === "person" && /* @__PURE__ */ t("div", { className: h("w-64", R), children: /* @__PURE__ */ t(
577
+ q,
578
+ {
579
+ collection: "nivaro_users",
580
+ value: e.fallback.user || null,
581
+ onChange: (u) => d({ fallback: { kind: "person", user: u ? String(u).toUpperCase() : "" } }),
582
+ placeholder: "Pick a person"
583
+ }
584
+ ) })
585
+ ] })
586
+ }
587
+ ),
588
+ /* @__PURE__ */ o("label", { className: "flex max-w-xl items-start gap-2 text-[12.5px] text-slate-700 dark:text-slate-200", children: [
589
+ /* @__PURE__ */ t(
590
+ "input",
591
+ {
592
+ type: "checkbox",
593
+ checked: e.on_type_change,
594
+ onChange: (u) => d({ on_type_change: u.target.checked }),
595
+ className: "mt-0.5 h-3.5 w-3.5 accent-nvr-navy dark:accent-nvr-cyan"
596
+ }
597
+ ),
598
+ /* @__PURE__ */ o("span", { children: [
599
+ "Also when a request’s type changes",
600
+ /* @__PURE__ */ t("span", { className: "block text-[11.5px] text-slate-500 dark:text-muted-foreground", children: "Moves requests someone already has. Off: a type change only assigns requests nobody has." })
601
+ ] })
602
+ ] }),
603
+ /* @__PURE__ */ o("div", { className: "flex items-center gap-2 pt-1", children: [
604
+ /* @__PURE__ */ t("button", { type: "button", onClick: n, className: M, children: "Done" }),
605
+ /* @__PURE__ */ o("button", { type: "button", onClick: a, className: h(U, "sm:hidden"), children: [
606
+ /* @__PURE__ */ t(oe, { className: "h-3.5 w-3.5" }),
607
+ " Duplicate"
608
+ ] }),
609
+ /* @__PURE__ */ t("span", { className: "text-[11.5px] text-slate-500 dark:text-muted-foreground", children: "Changes apply once you save the rules." })
610
+ ] })
611
+ ]
612
+ }
613
+ );
614
+ }
615
+ function nt({ onAdd: e }) {
616
+ const [r, s] = w(!1);
617
+ return /* @__PURE__ */ o(he, { open: r, onOpenChange: s, children: [
618
+ /* @__PURE__ */ t(be, { asChild: !0, children: /* @__PURE__ */ o("button", { type: "button", className: U, "data-support-add-condition": !0, children: [
619
+ /* @__PURE__ */ t(G, { className: "h-3.5 w-3.5" }),
620
+ " Add a condition"
621
+ ] }) }),
622
+ /* @__PURE__ */ t(xe, { align: "start", className: "w-72 p-0", children: /* @__PURE__ */ t(ue, { children: /* @__PURE__ */ t(pe, { className: "max-h-80", children: /* @__PURE__ */ t(F, { children: ge.map((i) => /* @__PURE__ */ o(
623
+ me,
624
+ {
625
+ value: i.label,
626
+ onSelect: () => {
627
+ e(i.value), s(!1);
628
+ },
629
+ className: "flex-col items-start gap-0 py-1.5",
630
+ children: [
631
+ /* @__PURE__ */ t("span", { className: "text-[12.5px]", children: i.label }),
632
+ /* @__PURE__ */ t("span", { className: "text-[11px] text-slate-500 dark:text-muted-foreground", children: i.description })
633
+ ]
634
+ },
635
+ i.value
636
+ )) }) }) }) })
637
+ ] });
638
+ }
639
+ function it({
640
+ cond: e,
641
+ options: r,
642
+ first: s,
643
+ match: i,
644
+ onChange: a,
645
+ onRemove: n
646
+ }) {
647
+ var p;
648
+ const d = ((p = ge.find((u) => u.value === e.kind)) == null ? void 0 : p.label) ?? e.kind;
649
+ return /* @__PURE__ */ o(
650
+ "div",
651
+ {
652
+ className: "flex flex-wrap items-start gap-2 rounded-md bg-slate-50 px-2.5 py-2 dark:bg-white/[0.05] dark:ring-1 dark:ring-inset dark:ring-white/[0.06]",
653
+ "data-support-condition": e.kind,
654
+ children: [
655
+ /* @__PURE__ */ t("span", { className: "mt-1.5 w-9 shrink-0 text-right text-[11.5px] font-medium uppercase tracking-wide text-slate-400 max-sm:w-auto", children: s ? "If" : i === "all" ? "and" : "or" }),
656
+ /* @__PURE__ */ t("span", { className: "mt-1.5 shrink-0 text-[12.5px] font-medium text-slate-800 max-sm:flex-1 dark:text-slate-100", children: d }),
657
+ /* @__PURE__ */ t("div", { className: "flex min-w-0 flex-1 flex-wrap items-center gap-2 max-sm:order-last max-sm:basis-full", children: /* @__PURE__ */ t(ot, { cond: e, options: r, onChange: a }) }),
658
+ /* @__PURE__ */ t(
659
+ "button",
660
+ {
661
+ type: "button",
662
+ onClick: n,
663
+ "aria-label": "Remove this condition",
664
+ "data-tip": "Remove",
665
+ className: "mt-0.5 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded text-slate-400 hover:bg-slate-200/60 hover:text-slate-700 dark:hover:bg-white/10 dark:hover:text-slate-100",
666
+ children: /* @__PURE__ */ t(L, { className: "h-3.5 w-3.5" })
667
+ }
668
+ )
669
+ ]
670
+ }
671
+ );
672
+ }
673
+ function ot({
674
+ cond: e,
675
+ options: r,
676
+ onChange: s
677
+ }) {
678
+ const i = /* @__PURE__ */ t(
679
+ g,
680
+ {
681
+ value: "op" in e ? e.op : "",
682
+ onChange: (a) => s({ ...e, op: a }),
683
+ options: Xe,
684
+ ariaLabel: "How to compare",
685
+ className: f
686
+ }
687
+ );
688
+ switch (e.kind) {
689
+ case "type":
690
+ return /* @__PURE__ */ o(N, { children: [
691
+ i,
692
+ /* @__PURE__ */ t(
693
+ _,
694
+ {
695
+ label: "Pick types",
696
+ values: e.values.map(String),
697
+ choices: ((r == null ? void 0 : r.types) ?? []).map((a) => ({ value: String(a.id), label: a.name })),
698
+ onChange: (a) => s({ ...e, values: a.map(Number) })
699
+ }
700
+ )
701
+ ] });
702
+ case "about":
703
+ return /* @__PURE__ */ o(N, { children: [
704
+ /* @__PURE__ */ t(
705
+ g,
706
+ {
707
+ value: e.op,
708
+ onChange: (a) => s({ ...e, op: a, collections: [] }),
709
+ options: [
710
+ { value: "record_in", label: "is a record in" },
711
+ { value: "general", label: "is General Support" }
712
+ ],
713
+ ariaLabel: "What it is about",
714
+ className: f
715
+ }
716
+ ),
717
+ e.op === "record_in" && /* @__PURE__ */ t(
718
+ _,
719
+ {
720
+ label: "Any kind of record",
721
+ values: e.collections,
722
+ choices: ((r == null ? void 0 : r.collections) ?? []).map((a) => ({
723
+ value: a.collection,
724
+ label: a.name
725
+ })),
726
+ onChange: (a) => s({ ...e, collections: a })
727
+ }
728
+ )
729
+ ] });
730
+ case "field":
731
+ return /* @__PURE__ */ t(ct, { cond: e, options: r, onChange: s });
732
+ case "step": {
733
+ const a = Object.entries((r == null ? void 0 : r.steps) ?? {}).map(([n, d]) => {
734
+ var p;
735
+ return {
736
+ heading: ((p = r == null ? void 0 : r.collections.find((u) => u.collection === n)) == null ? void 0 : p.name) ?? n,
737
+ choices: d.map((u) => ({ value: u.id, label: u.label }))
738
+ };
739
+ });
740
+ return /* @__PURE__ */ o(N, { children: [
741
+ i,
742
+ /* @__PURE__ */ t(
743
+ _,
744
+ {
745
+ label: "Pick steps",
746
+ values: e.states,
747
+ groups: a,
748
+ onChange: (n) => s({ ...e, states: n })
749
+ }
750
+ )
751
+ ] });
752
+ }
753
+ case "requester":
754
+ return /* @__PURE__ */ o(N, { children: [
755
+ i,
756
+ /* @__PURE__ */ t(pt, { users: e.users, onChange: (a) => s({ ...e, users: a }) })
757
+ ] });
758
+ case "requester_role":
759
+ return /* @__PURE__ */ o(N, { children: [
760
+ i,
761
+ /* @__PURE__ */ t(
762
+ _,
763
+ {
764
+ label: "Pick roles",
765
+ values: e.roles,
766
+ choices: ((r == null ? void 0 : r.roles) ?? []).map((a) => ({ value: String(a.id), label: a.name })),
767
+ onChange: (a) => s({ ...e, roles: a })
768
+ }
769
+ )
770
+ ] });
771
+ case "requester_team":
772
+ return /* @__PURE__ */ o(N, { children: [
773
+ /* @__PURE__ */ t(
774
+ g,
775
+ {
776
+ value: e.op,
777
+ onChange: (a) => s({ ...e, op: a }),
778
+ options: [
779
+ { value: "in", label: "is in" },
780
+ { value: "not_in", label: "is not in" }
781
+ ],
782
+ ariaLabel: "How to compare",
783
+ className: f
784
+ }
785
+ ),
786
+ /* @__PURE__ */ t(
787
+ _,
788
+ {
789
+ label: "Pick teams",
790
+ values: e.teams.map(String),
791
+ choices: ((r == null ? void 0 : r.teams) ?? []).map((a) => ({ value: String(a.id), label: a.name })),
792
+ onChange: (a) => s({ ...e, teams: a.map(Number) })
793
+ }
794
+ )
795
+ ] });
796
+ case "priority":
797
+ return /* @__PURE__ */ o(N, { children: [
798
+ i,
799
+ /* @__PURE__ */ t(
800
+ _,
801
+ {
802
+ label: "Pick priorities",
803
+ values: e.values,
804
+ choices: [
805
+ { value: "urgent", label: "Urgent" },
806
+ { value: "normal", label: "Normal" },
807
+ { value: "low", label: "Low" }
808
+ ],
809
+ onChange: (a) => s({ ...e, values: a })
810
+ }
811
+ )
812
+ ] });
813
+ case "text":
814
+ return /* @__PURE__ */ o(N, { children: [
815
+ /* @__PURE__ */ t(
816
+ g,
817
+ {
818
+ value: e.op,
819
+ onChange: (a) => s({ ...e, op: a }),
820
+ options: [
821
+ { value: "any", label: "mentions any of" },
822
+ { value: "all", label: "mentions all of" },
823
+ { value: "none", label: "mentions none of" }
824
+ ],
825
+ ariaLabel: "How to compare",
826
+ className: f
827
+ }
828
+ ),
829
+ /* @__PURE__ */ t(fe, { words: e.words, onChange: (a) => s({ ...e, words: a }) })
830
+ ] });
831
+ case "source":
832
+ return /* @__PURE__ */ o(N, { children: [
833
+ i,
834
+ /* @__PURE__ */ t(
835
+ _,
836
+ {
837
+ label: "Pick places",
838
+ values: e.values,
839
+ choices: Object.keys(O).map((a) => ({
840
+ value: a,
841
+ label: O[a].replace(/^./, (n) => n.toUpperCase())
842
+ })),
843
+ onChange: (a) => s({ ...e, values: a })
844
+ }
845
+ )
846
+ ] });
847
+ case "hours":
848
+ return /* @__PURE__ */ t(
849
+ g,
850
+ {
851
+ value: e.op,
852
+ onChange: (a) => s({ ...e, op: a }),
853
+ options: [
854
+ { value: "inside", label: "is during business hours" },
855
+ { value: "outside", label: "is outside business hours" }
856
+ ],
857
+ ariaLabel: "When it comes in",
858
+ className: f
859
+ }
860
+ );
861
+ }
862
+ }
863
+ const dt = /^(integer|biginteger|float|decimal|date|datetime|timestamp|time)$/i;
864
+ function re(e) {
865
+ const r = [
866
+ { value: "empty", label: "is empty" },
867
+ { value: "not_empty", label: "is filled in" }
868
+ ];
869
+ return e ? e.related || e.choices ? [
870
+ { value: "in", label: "is one of" },
871
+ { value: "not_in", label: "is not one of" },
872
+ ...r
873
+ ] : dt.test(e.type) ? [
874
+ { value: "is", label: "is" },
875
+ { value: "is_not", label: "is not" },
876
+ { value: "gt", label: "is more than" },
877
+ { value: "gte", label: "is at least" },
878
+ { value: "lt", label: "is less than" },
879
+ { value: "lte", label: "is at most" },
880
+ ...r
881
+ ] : /^bool/i.test(e.type) ? [{ value: "is", label: "is" }, ...r] : [
882
+ { value: "in", label: "is one of" },
883
+ { value: "not_in", label: "is not one of" },
884
+ { value: "contains", label: "contains" },
885
+ { value: "not_contains", label: "does not contain" },
886
+ ...r
887
+ ] : [{ value: "in", label: "is one of" }];
888
+ }
889
+ function ct({
890
+ cond: e,
891
+ options: r,
892
+ onChange: s
893
+ }) {
894
+ const i = W(), { data: a = [] } = E({
895
+ queryKey: ["support-assign-fields", e.collection],
896
+ enabled: !!e.collection,
897
+ staleTime: 5 * 6e4,
898
+ queryFn: () => i.request(
899
+ A("/support/assign-rules/fields", { collection: e.collection })
900
+ ).then((l) => l.data ?? [])
901
+ }), n = a.find((l) => l.field === e.field), d = re(n), p = e.op === "empty" || e.op === "not_empty", u = ["gt", "gte", "lt", "lte", "is", "is_not"].includes(e.op);
902
+ return /* @__PURE__ */ o(N, { children: [
903
+ /* @__PURE__ */ t(
904
+ g,
905
+ {
906
+ value: e.collection,
907
+ onChange: (l) => s({ ...e, collection: l, field: "", values: [] }),
908
+ options: ((r == null ? void 0 : r.collections) ?? []).map((l) => ({ value: l.collection, label: l.name })),
909
+ ariaLabel: "Kind of record",
910
+ className: f
911
+ }
912
+ ),
913
+ /* @__PURE__ */ t(
914
+ g,
915
+ {
916
+ value: e.field,
917
+ onChange: (l) => {
918
+ const b = a.find((m) => m.field === l);
919
+ s({ ...e, field: l, op: re(b)[0].value, values: [] });
920
+ },
921
+ options: [
922
+ { value: "", label: "Pick a field" },
923
+ ...a.map((l) => ({ value: l.field, label: l.label }))
924
+ ],
925
+ ariaLabel: "Field",
926
+ className: f
927
+ }
928
+ ),
929
+ e.field && /* @__PURE__ */ t(
930
+ g,
931
+ {
932
+ value: e.op,
933
+ onChange: (l) => s({
934
+ ...e,
935
+ op: l,
936
+ values: l === "empty" || l === "not_empty" ? [] : e.values
937
+ }),
938
+ options: d,
939
+ ariaLabel: "How to compare",
940
+ className: f
941
+ }
942
+ ),
943
+ e.field && !p && (n != null && n.related) ? /* @__PURE__ */ t(
944
+ ut,
945
+ {
946
+ collection: n.related,
947
+ values: e.values,
948
+ onChange: (l) => s({ ...e, values: l })
949
+ }
950
+ ) : e.field && !p && (n != null && n.choices) ? /* @__PURE__ */ t(
951
+ _,
952
+ {
953
+ label: "Pick values",
954
+ values: e.values,
955
+ choices: n.choices,
956
+ onChange: (l) => s({ ...e, values: l })
957
+ }
958
+ ) : e.field && !p && /^bool/i.test((n == null ? void 0 : n.type) ?? "") ? /* @__PURE__ */ t(
959
+ g,
960
+ {
961
+ value: e.values[0] ?? "true",
962
+ onChange: (l) => s({ ...e, values: [l] }),
963
+ options: [
964
+ { value: "true", label: "Yes" },
965
+ { value: "false", label: "No" }
966
+ ],
967
+ ariaLabel: "Value",
968
+ className: f
969
+ }
970
+ ) : e.field && !p && u ? /* @__PURE__ */ t(
971
+ "input",
972
+ {
973
+ value: e.values[0] ?? "",
974
+ onChange: (l) => s({ ...e, values: l.target.value ? [l.target.value] : [] }),
975
+ placeholder: /date|time/i.test((n == null ? void 0 : n.type) ?? "") ? "YYYY-MM-DD" : "Value",
976
+ "aria-label": "Value",
977
+ className: h(T, "w-36")
978
+ }
979
+ ) : e.field && !p ? /* @__PURE__ */ t(
980
+ fe,
981
+ {
982
+ words: e.values,
983
+ onChange: (l) => s({ ...e, values: l }),
984
+ placeholder: "Type a value, Enter"
985
+ }
986
+ ) : null,
987
+ /* @__PURE__ */ t("p", { className: "basis-full text-[11.5px] text-slate-500 dark:text-muted-foreground", children: "Read from the record when the request comes in. Neither the requester nor the history ever shows the value through this rule." })
988
+ ] });
989
+ }
990
+ function ut({
991
+ collection: e,
992
+ values: r,
993
+ onChange: s
994
+ }) {
995
+ return /* @__PURE__ */ o("div", { className: "flex flex-wrap items-center gap-1.5", children: [
996
+ r.map((i, a) => /* @__PURE__ */ o("div", { className: "flex items-center gap-0.5", children: [
997
+ /* @__PURE__ */ t("div", { className: h("w-48", R), children: /* @__PURE__ */ t(
998
+ q,
999
+ {
1000
+ collection: e,
1001
+ value: i,
1002
+ onChange: (n) => {
1003
+ const d = [...r];
1004
+ n == null || n === "" ? d.splice(a, 1) : d[a] = String(n), s([...new Set(d)]);
1005
+ }
1006
+ }
1007
+ ) }),
1008
+ /* @__PURE__ */ t(
1009
+ "button",
1010
+ {
1011
+ type: "button",
1012
+ "aria-label": "Remove this value",
1013
+ onClick: () => s(r.filter((n) => n !== i)),
1014
+ className: "inline-flex h-7 w-6 items-center justify-center rounded text-slate-400 hover:text-slate-700 dark:hover:text-slate-100",
1015
+ children: /* @__PURE__ */ t(L, { className: "h-3 w-3" })
1016
+ }
1017
+ )
1018
+ ] }, i)),
1019
+ /* @__PURE__ */ t("div", { className: h("w-48", R), children: /* @__PURE__ */ t(
1020
+ q,
1021
+ {
1022
+ collection: e,
1023
+ value: null,
1024
+ onChange: (i) => i != null && i !== "" && s([.../* @__PURE__ */ new Set([...r, String(i)])]),
1025
+ placeholder: r.length ? "Add another" : "Pick a value"
1026
+ },
1027
+ r.length
1028
+ ) })
1029
+ ] });
1030
+ }
1031
+ function _({
1032
+ label: e,
1033
+ values: r,
1034
+ choices: s,
1035
+ groups: i,
1036
+ onChange: a
1037
+ }) {
1038
+ const [n, d] = w(!1), p = i ? i.flatMap((m) => m.choices) : s ?? [], u = (m) => {
1039
+ var k;
1040
+ return ((k = p.find((P) => P.value === m)) == null ? void 0 : k.label) ?? m;
1041
+ }, l = (m) => a(r.includes(m) ? r.filter((k) => k !== m) : [...r, m]), b = (m, k = "") => /* @__PURE__ */ o(
1042
+ me,
1043
+ {
1044
+ value: `${k}${m.label} ${m.value}`,
1045
+ onSelect: () => l(m.value),
1046
+ className: "gap-2 text-[12.5px]",
1047
+ children: [
1048
+ /* @__PURE__ */ t(
1049
+ "span",
1050
+ {
1051
+ className: h(
1052
+ "flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-sm border",
1053
+ r.includes(m.value) ? "border-nvr-navy bg-nvr-navy text-white dark:border-nvr-cyan dark:bg-nvr-cyan dark:text-[#0f172a]" : "border-slate-400 dark:border-slate-500"
1054
+ ),
1055
+ children: r.includes(m.value) && /* @__PURE__ */ t(ie, { className: "h-3 w-3" })
1056
+ }
1057
+ ),
1058
+ /* @__PURE__ */ t("span", { className: "truncate", children: m.label })
1059
+ ]
1060
+ },
1061
+ `${k}${m.value}`
1062
+ );
1063
+ return /* @__PURE__ */ o(he, { open: n, onOpenChange: d, children: [
1064
+ /* @__PURE__ */ t(be, { asChild: !0, children: /* @__PURE__ */ o(
1065
+ "button",
1066
+ {
1067
+ type: "button",
1068
+ className: "inline-flex min-h-8 max-w-full flex-wrap items-center gap-1 rounded-md border border-slate-200 bg-white px-1.5 py-1 text-left text-[12.5px] text-slate-800 hover:border-slate-300 dark:border-border dark:bg-background dark:text-slate-100",
1069
+ children: [
1070
+ r.length ? r.map((m) => /* @__PURE__ */ t(
1071
+ "span",
1072
+ {
1073
+ className: "rounded bg-slate-100 px-1.5 py-px text-[12px] text-slate-700 dark:bg-white/10 dark:text-slate-200",
1074
+ children: u(m)
1075
+ },
1076
+ m
1077
+ )) : /* @__PURE__ */ t("span", { className: "px-1 text-slate-400", children: e }),
1078
+ /* @__PURE__ */ t(se, { className: "ml-0.5 h-3.5 w-3.5 shrink-0 opacity-60" })
1079
+ ]
1080
+ }
1081
+ ) }),
1082
+ /* @__PURE__ */ t(xe, { align: "start", className: "w-72 p-0", children: /* @__PURE__ */ o(ue, { children: [
1083
+ /* @__PURE__ */ t(Ye, { placeholder: "Search", className: "h-9 text-[12.5px]" }),
1084
+ /* @__PURE__ */ o(pe, { className: "max-h-72", children: [
1085
+ /* @__PURE__ */ t(ze, { className: "py-4 text-center text-[12px] text-slate-500", children: "Nothing matches" }),
1086
+ i ? i.map((m) => /* @__PURE__ */ t(F, { heading: m.heading, children: m.choices.map((k) => b(k, `${m.heading} `)) }, m.heading)) : /* @__PURE__ */ t(F, { children: p.map((m) => b(m)) })
1087
+ ] })
1088
+ ] }) })
1089
+ ] });
1090
+ }
1091
+ function fe({
1092
+ words: e,
1093
+ onChange: r,
1094
+ placeholder: s = "Type a word, Enter"
1095
+ }) {
1096
+ const [i, a] = w(""), n = () => {
1097
+ const d = i.split(",").map((p) => p.trim()).filter(Boolean);
1098
+ d.length && r([.../* @__PURE__ */ new Set([...e, ...d])]), a("");
1099
+ };
1100
+ return /* @__PURE__ */ o("div", { className: "flex min-h-8 min-w-[14rem] flex-1 flex-wrap items-center gap-1 rounded-md border border-slate-200 bg-white px-1.5 py-1 focus-within:border-nvr-cyan dark:border-border dark:bg-background", children: [
1101
+ e.map((d) => /* @__PURE__ */ o(
1102
+ "span",
1103
+ {
1104
+ className: "inline-flex items-center gap-0.5 rounded bg-slate-100 py-px pl-1.5 pr-0.5 text-[12px] text-slate-700 dark:bg-white/10 dark:text-slate-200",
1105
+ children: [
1106
+ d,
1107
+ /* @__PURE__ */ t(
1108
+ "button",
1109
+ {
1110
+ type: "button",
1111
+ "aria-label": `Remove ${d}`,
1112
+ onClick: () => r(e.filter((p) => p !== d)),
1113
+ className: "rounded p-0.5 text-slate-400 hover:text-slate-700 dark:hover:text-slate-100",
1114
+ children: /* @__PURE__ */ t(L, { className: "h-3 w-3" })
1115
+ }
1116
+ )
1117
+ ]
1118
+ },
1119
+ d
1120
+ )),
1121
+ /* @__PURE__ */ t(
1122
+ "input",
1123
+ {
1124
+ value: i,
1125
+ onChange: (d) => a(d.target.value),
1126
+ onKeyDown: (d) => {
1127
+ d.key === "Enter" || d.key === "," ? (d.preventDefault(), n()) : d.key === "Backspace" && !i && e.length && r(e.slice(0, -1));
1128
+ },
1129
+ onBlur: n,
1130
+ placeholder: e.length ? "" : s,
1131
+ "aria-label": "Words",
1132
+ className: "min-w-[6rem] flex-1 bg-transparent px-1 text-[12.5px] text-slate-900 outline-none placeholder:text-slate-400 dark:text-slate-100"
1133
+ }
1134
+ )
1135
+ ] });
1136
+ }
1137
+ function pt({ users: e, onChange: r }) {
1138
+ return /* @__PURE__ */ o("div", { className: "flex flex-wrap items-center gap-1.5", children: [
1139
+ e.map((s) => /* @__PURE__ */ o(
1140
+ "span",
1141
+ {
1142
+ className: "inline-flex items-center gap-1 rounded-full border border-slate-200 bg-white py-0.5 pl-0.5 pr-1 text-[12px] dark:border-border dark:bg-card",
1143
+ children: [
1144
+ /* @__PURE__ */ t(ve, { id: s }),
1145
+ /* @__PURE__ */ t(
1146
+ "button",
1147
+ {
1148
+ type: "button",
1149
+ "aria-label": "Remove",
1150
+ onClick: () => r(e.filter((i) => i !== s)),
1151
+ className: "rounded-full p-0.5 text-slate-400 hover:text-slate-700 dark:hover:text-slate-100",
1152
+ children: /* @__PURE__ */ t(L, { className: "h-3 w-3" })
1153
+ }
1154
+ )
1155
+ ]
1156
+ },
1157
+ s
1158
+ )),
1159
+ /* @__PURE__ */ t("div", { className: h("w-52", R), children: /* @__PURE__ */ t(
1160
+ q,
1161
+ {
1162
+ collection: "nivaro_users",
1163
+ value: null,
1164
+ onChange: (s) => s && r([.../* @__PURE__ */ new Set([...e, String(s).toUpperCase()])]),
1165
+ placeholder: "Add a person"
1166
+ },
1167
+ e.length
1168
+ ) })
1169
+ ] });
1170
+ }
1171
+ function ve({ id: e }) {
1172
+ const r = W(), { data: s } = E({
1173
+ queryKey: ["user-card", e],
1174
+ staleTime: 30 * 6e4,
1175
+ queryFn: () => r.request(
1176
+ A(`/users/${e}/card`)
1177
+ ).then((a) => a.data).catch(() => null)
1178
+ }), i = s ? [s.first_name, s.last_name].filter(Boolean).join(" ") || s.email || "Someone" : "…";
1179
+ return /* @__PURE__ */ o("span", { className: "inline-flex min-w-0 items-center gap-1.5", children: [
1180
+ /* @__PURE__ */ t(D, { id: e, name: i, size: 20 }),
1181
+ /* @__PURE__ */ t("span", { className: "truncate text-slate-800 dark:text-slate-100", children: i })
1182
+ ] });
1183
+ }
1184
+ function mt({
1185
+ action: e,
1186
+ options: r,
1187
+ onChange: s
1188
+ }) {
1189
+ return /* @__PURE__ */ o("div", { className: "space-y-3", children: [
1190
+ /* @__PURE__ */ t(
1191
+ g,
1192
+ {
1193
+ value: e.kind,
1194
+ onChange: (i) => {
1195
+ var a;
1196
+ return s(
1197
+ i === "person" ? { kind: "person", user: "" } : i === "share" ? { kind: "share", people: [], strategy: "fewest_open", give_to_cover: !0 } : i === "step_owner" ? { kind: "step_owner", pick: "fewest_open" } : { kind: "team", team: ((a = r == null ? void 0 : r.teams[0]) == null ? void 0 : a.id) ?? 0 }
1198
+ );
1199
+ },
1200
+ options: [
1201
+ {
1202
+ value: "share",
1203
+ label: "Share it among people",
1204
+ description: "Pick one of several people by load, turns or experience."
1205
+ },
1206
+ {
1207
+ value: "person",
1208
+ label: "Give it to one person",
1209
+ description: "Their cover takes it while they are out."
1210
+ },
1211
+ {
1212
+ value: "step_owner",
1213
+ label: "Give it to the record’s step owner",
1214
+ description: "Whoever owns the record’s current pipeline step."
1215
+ },
1216
+ {
1217
+ value: "team",
1218
+ label: "Send it to a team’s desk",
1219
+ description: "Unassigned, for that team to pick up."
1220
+ }
1221
+ ],
1222
+ ariaLabel: "What the rule does",
1223
+ className: h(f, "min-w-[16rem]"),
1224
+ triggerProps: { "data-support-action": e.kind }
1225
+ }
1226
+ ),
1227
+ e.kind === "person" && /* @__PURE__ */ t("div", { className: h("w-72", R), children: /* @__PURE__ */ t(
1228
+ q,
1229
+ {
1230
+ collection: "nivaro_users",
1231
+ value: e.user || null,
1232
+ onChange: (i) => s({ kind: "person", user: i ? String(i).toUpperCase() : "" }),
1233
+ placeholder: "Pick a person"
1234
+ }
1235
+ ) }),
1236
+ e.kind === "team" && /* @__PURE__ */ t(
1237
+ g,
1238
+ {
1239
+ value: String(e.team || ""),
1240
+ onChange: (i) => s({ kind: "team", team: Number(i) }),
1241
+ options: ((r == null ? void 0 : r.teams) ?? []).map((i) => ({ value: String(i.id), label: i.name })),
1242
+ ariaLabel: "Team",
1243
+ className: f
1244
+ }
1245
+ ),
1246
+ e.kind === "step_owner" && /* @__PURE__ */ t(
1247
+ g,
1248
+ {
1249
+ value: e.pick,
1250
+ onChange: (i) => s({ kind: "step_owner", pick: i }),
1251
+ options: [
1252
+ { value: "fewest_open", label: "The owner with the fewest open requests" },
1253
+ { value: "first", label: "The first owner" }
1254
+ ],
1255
+ ariaLabel: "Which owner",
1256
+ className: f
1257
+ }
1258
+ ),
1259
+ e.kind === "share" && /* @__PURE__ */ t(ht, { action: e, onChange: s })
1260
+ ] });
1261
+ }
1262
+ function ht({
1263
+ action: e,
1264
+ onChange: r
1265
+ }) {
1266
+ const s = (a, n) => r({ ...e, people: e.people.map((d, p) => p === a ? n : d) }), i = K.find((a) => a.value === e.strategy);
1267
+ return /* @__PURE__ */ o("div", { className: "space-y-3", "data-support-share-editor": !0, children: [
1268
+ /* @__PURE__ */ o("div", { className: "overflow-hidden rounded-md border border-slate-200 dark:border-border", children: [
1269
+ e.people.length === 0 ? /* @__PURE__ */ t("p", { className: "px-3 py-3 text-[12px] text-slate-500 dark:text-muted-foreground", children: "Add the people who share these requests." }) : /* @__PURE__ */ t("ul", { className: "divide-y divide-slate-100 dark:divide-border/60", children: e.people.map((a, n) => /* @__PURE__ */ o(
1270
+ "li",
1271
+ {
1272
+ className: "flex flex-wrap items-center gap-2 bg-white px-2.5 py-1.5 dark:bg-card",
1273
+ children: [
1274
+ /* @__PURE__ */ t("span", { className: "min-w-[10rem] flex-1 text-[12.5px]", children: /* @__PURE__ */ t(ve, { id: a.id }) }),
1275
+ /* @__PURE__ */ o("label", { className: "flex items-center gap-1.5 text-[12px] text-slate-600 dark:text-slate-300", children: [
1276
+ "At most",
1277
+ /* @__PURE__ */ t(
1278
+ "input",
1279
+ {
1280
+ type: "number",
1281
+ min: 1,
1282
+ inputMode: "numeric",
1283
+ value: a.cap ?? "",
1284
+ onChange: (d) => s(n, {
1285
+ ...a,
1286
+ cap: d.target.value ? Math.max(1, Math.floor(Number(d.target.value))) : null
1287
+ }),
1288
+ placeholder: "any",
1289
+ "aria-label": "Most open requests",
1290
+ className: h(T, "h-7 w-16 px-2 tabular-nums")
1291
+ }
1292
+ ),
1293
+ "open"
1294
+ ] }),
1295
+ /* @__PURE__ */ t(
1296
+ g,
1297
+ {
1298
+ value: a.when,
1299
+ onChange: (d) => s(n, { ...a, when: d }),
1300
+ options: [
1301
+ { value: "always", label: "Any time" },
1302
+ { value: "business_hours", label: "Business hours only" },
1303
+ { value: "online", label: "Only while online" }
1304
+ ],
1305
+ ariaLabel: "When they take requests",
1306
+ className: h(f, "h-7 w-[10.5rem] min-w-0")
1307
+ }
1308
+ ),
1309
+ /* @__PURE__ */ t(
1310
+ "button",
1311
+ {
1312
+ type: "button",
1313
+ "aria-label": "Remove this person",
1314
+ "data-tip": "Remove",
1315
+ onClick: () => r({ ...e, people: e.people.filter((d, p) => p !== n) }),
1316
+ className: "inline-flex h-7 w-7 items-center justify-center rounded text-slate-400 hover:bg-slate-100 hover:text-slate-700 dark:hover:bg-white/10 dark:hover:text-slate-100",
1317
+ children: /* @__PURE__ */ t(L, { className: "h-3.5 w-3.5" })
1318
+ }
1319
+ )
1320
+ ]
1321
+ },
1322
+ a.id
1323
+ )) }),
1324
+ /* @__PURE__ */ t("div", { className: "border-t border-slate-100 bg-slate-50 px-2.5 py-1.5 dark:border-border/60 dark:bg-white/[0.03]", children: /* @__PURE__ */ t("div", { className: h("w-64", R), children: /* @__PURE__ */ t(
1325
+ q,
1326
+ {
1327
+ collection: "nivaro_users",
1328
+ value: null,
1329
+ onChange: (a) => a && !e.people.some((n) => n.id === String(a).toUpperCase()) && r({
1330
+ ...e,
1331
+ people: [
1332
+ ...e.people,
1333
+ { id: String(a).toUpperCase(), cap: null, when: "always" }
1334
+ ]
1335
+ }),
1336
+ placeholder: "Add a person"
1337
+ },
1338
+ e.people.length
1339
+ ) }) })
1340
+ ] }),
1341
+ /* @__PURE__ */ o("div", { className: "flex flex-wrap items-center gap-2 text-[12.5px] text-slate-700 dark:text-slate-200", children: [
1342
+ "Choose",
1343
+ /* @__PURE__ */ t(
1344
+ g,
1345
+ {
1346
+ value: e.strategy,
1347
+ onChange: (a) => r({ ...e, strategy: a }),
1348
+ options: K,
1349
+ ariaLabel: "How to choose",
1350
+ className: h(f, "min-w-[15rem]"),
1351
+ triggerProps: { "data-support-strategy": e.strategy }
1352
+ }
1353
+ )
1354
+ ] }),
1355
+ i && /* @__PURE__ */ t("p", { className: "-mt-1 text-[11.5px] text-slate-500 dark:text-muted-foreground", children: i.description }),
1356
+ /* @__PURE__ */ o("label", { className: "flex items-start gap-2 text-[12.5px] text-slate-700 dark:text-slate-200", children: [
1357
+ /* @__PURE__ */ t(
1358
+ "input",
1359
+ {
1360
+ type: "checkbox",
1361
+ checked: e.give_to_cover,
1362
+ onChange: (a) => r({ ...e, give_to_cover: a.target.checked }),
1363
+ className: "mt-0.5 h-3.5 w-3.5 accent-nvr-navy dark:accent-nvr-cyan"
1364
+ }
1365
+ ),
1366
+ /* @__PURE__ */ o("span", { children: [
1367
+ "Someone out of office hands it to their cover",
1368
+ /* @__PURE__ */ t("span", { className: "block text-[11.5px] text-slate-500 dark:text-muted-foreground", children: "Off: they are skipped. Suspended people are always skipped." })
1369
+ ] })
1370
+ ] })
1371
+ ] });
1372
+ }
1373
+ const bt = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
1374
+ function xt({
1375
+ hours: e,
1376
+ onChange: r
1377
+ }) {
1378
+ return /* @__PURE__ */ o(
1379
+ "div",
1380
+ {
1381
+ className: "flex flex-wrap items-center gap-3 rounded-lg border border-slate-200 bg-white px-3 py-2.5 dark:border-border dark:bg-card",
1382
+ "data-support-hours": !0,
1383
+ children: [
1384
+ /* @__PURE__ */ t("fieldset", { className: "flex items-center gap-1", "aria-label": "Business days", children: bt.map((s, i) => {
1385
+ const a = e.days.includes(i);
1386
+ return /* @__PURE__ */ t(
1387
+ "button",
1388
+ {
1389
+ type: "button",
1390
+ "aria-pressed": a,
1391
+ onClick: () => r({
1392
+ ...e,
1393
+ days: a ? e.days.filter((n) => n !== i) : [...e.days, i].sort()
1394
+ }),
1395
+ className: h(
1396
+ "h-7 w-10 rounded-md text-[12px]",
1397
+ a ? "bg-nvr-cyan/15 font-medium text-nvr-navy dark:text-nvr-cyan" : "text-slate-500 hover:bg-slate-100 dark:text-slate-400 dark:hover:bg-white/10"
1398
+ ),
1399
+ children: s
1400
+ },
1401
+ s
1402
+ );
1403
+ }) }),
1404
+ /* @__PURE__ */ o("label", { className: "flex items-center gap-1.5 text-[12px] text-slate-600 dark:text-slate-300", children: [
1405
+ "From",
1406
+ /* @__PURE__ */ t(
1407
+ "input",
1408
+ {
1409
+ type: "time",
1410
+ value: e.start,
1411
+ onChange: (s) => r({ ...e, start: s.target.value }),
1412
+ className: h(T, "w-28")
1413
+ }
1414
+ )
1415
+ ] }),
1416
+ /* @__PURE__ */ o("label", { className: "flex items-center gap-1.5 text-[12px] text-slate-600 dark:text-slate-300", children: [
1417
+ "to",
1418
+ /* @__PURE__ */ t(
1419
+ "input",
1420
+ {
1421
+ type: "time",
1422
+ value: e.end,
1423
+ onChange: (s) => r({ ...e, end: s.target.value }),
1424
+ className: h(T, "w-28")
1425
+ }
1426
+ )
1427
+ ] }),
1428
+ /* @__PURE__ */ o("span", { className: "text-[11.5px] text-slate-500 dark:text-muted-foreground", children: [
1429
+ "Eastern time · ",
1430
+ ae(e.start),
1431
+ " – ",
1432
+ ae(e.end)
1433
+ ] })
1434
+ ]
1435
+ }
1436
+ );
1437
+ }
1438
+ function gt(e, r) {
1439
+ if (e === "now") return;
1440
+ const s = r.days[0] ?? 1, i = /* @__PURE__ */ new Date(), a = (s - i.getUTCDay() + 7) % 7 || 7;
1441
+ i.setUTCDate(i.getUTCDate() + a);
1442
+ const [n] = r.start.split(":").map(Number), [d] = r.end.split(":").map(Number), p = e === "inside" ? Math.floor((n + d) / 2) : 22;
1443
+ return i.setUTCHours(p + 5, 0, 0, 0), i.toISOString();
1444
+ }
1445
+ function ft({
1446
+ draft: e,
1447
+ options: r,
1448
+ dirty: s
1449
+ }) {
1450
+ const i = W(), [a, n] = w({
1451
+ category_id: "",
1452
+ collection: "",
1453
+ item: "",
1454
+ requester: "",
1455
+ priority: "normal",
1456
+ title: "",
1457
+ source: "",
1458
+ when: "now"
1459
+ }), d = (l) => n((b) => ({ ...b, ...l })), p = le({
1460
+ mutationFn: () => i.request(
1461
+ de("/support/assign-rules/test", {
1462
+ rules: e.rules,
1463
+ hours: e.hours,
1464
+ request: {
1465
+ category_id: a.category_id || null,
1466
+ collection: a.collection || null,
1467
+ item: a.collection && a.item || null,
1468
+ requester: a.requester || null,
1469
+ priority: a.priority,
1470
+ title: a.title,
1471
+ source: a.source || null,
1472
+ at: gt(a.when, e.hours)
1473
+ }
1474
+ })
1475
+ ).then((l) => l.data),
1476
+ onError: (l) => ce(l, "Could not try that request")
1477
+ }), u = (l, b) => /* @__PURE__ */ o("div", { className: "flex min-w-0 flex-col gap-1", children: [
1478
+ /* @__PURE__ */ t("span", { className: "text-[11.5px] font-medium text-slate-600 dark:text-slate-300", children: l }),
1479
+ b
1480
+ ] });
1481
+ return /* @__PURE__ */ o(
1482
+ "section",
1483
+ {
1484
+ className: "rounded-lg border border-slate-200 bg-white dark:border-border dark:bg-card",
1485
+ "data-support-try": !0,
1486
+ children: [
1487
+ /* @__PURE__ */ o("header", { className: "border-b border-slate-100 px-4 py-3 dark:border-border/60", children: [
1488
+ /* @__PURE__ */ t("h3", { className: "text-[13px] font-semibold text-slate-900 dark:text-slate-100", children: "Try a request" }),
1489
+ /* @__PURE__ */ o("p", { className: "text-[12px] text-slate-500 dark:text-muted-foreground", children: [
1490
+ "Describe a request to see which rule wins and who would get it",
1491
+ s ? " — using your unsaved changes" : "",
1492
+ ". Nothing is created."
1493
+ ] })
1494
+ ] }),
1495
+ /* @__PURE__ */ o("div", { className: "grid grid-cols-1 gap-3 px-4 py-3 sm:grid-cols-2 lg:grid-cols-4", children: [
1496
+ u(
1497
+ "Type",
1498
+ /* @__PURE__ */ t(
1499
+ g,
1500
+ {
1501
+ value: a.category_id,
1502
+ onChange: (l) => d({ category_id: l }),
1503
+ options: [
1504
+ { value: "", label: "No type" },
1505
+ ...((r == null ? void 0 : r.types) ?? []).map((l) => ({ value: String(l.id), label: l.name }))
1506
+ ],
1507
+ ariaLabel: "Type",
1508
+ className: h(f, "w-full")
1509
+ }
1510
+ )
1511
+ ),
1512
+ u(
1513
+ "About",
1514
+ /* @__PURE__ */ t(
1515
+ g,
1516
+ {
1517
+ value: a.collection,
1518
+ onChange: (l) => d({ collection: l, item: "" }),
1519
+ options: [
1520
+ { value: "", label: "General Support" },
1521
+ ...((r == null ? void 0 : r.collections) ?? []).filter((l) => !l.hidden).map((l) => ({ value: l.collection, label: l.name }))
1522
+ ],
1523
+ ariaLabel: "About",
1524
+ className: h(f, "w-full")
1525
+ }
1526
+ )
1527
+ ),
1528
+ a.collection ? u(
1529
+ "Record",
1530
+ /* @__PURE__ */ t("div", { className: R, children: /* @__PURE__ */ t(
1531
+ q,
1532
+ {
1533
+ collection: a.collection,
1534
+ value: a.item || null,
1535
+ onChange: (l) => d({ item: l == null ? "" : String(l) }),
1536
+ placeholder: "Pick a record"
1537
+ },
1538
+ a.collection
1539
+ ) })
1540
+ ) : null,
1541
+ u(
1542
+ "Requester",
1543
+ /* @__PURE__ */ t("div", { className: R, children: /* @__PURE__ */ t(
1544
+ q,
1545
+ {
1546
+ collection: "nivaro_users",
1547
+ value: a.requester || null,
1548
+ onChange: (l) => d({ requester: l ? String(l) : "" }),
1549
+ placeholder: "Anyone"
1550
+ }
1551
+ ) })
1552
+ ),
1553
+ u(
1554
+ "Priority",
1555
+ /* @__PURE__ */ t(
1556
+ g,
1557
+ {
1558
+ value: a.priority,
1559
+ onChange: (l) => d({ priority: l }),
1560
+ options: [
1561
+ { value: "normal", label: "Normal" },
1562
+ { value: "urgent", label: "Urgent" },
1563
+ { value: "low", label: "Low" }
1564
+ ],
1565
+ ariaLabel: "Priority",
1566
+ className: h(f, "w-full")
1567
+ }
1568
+ )
1569
+ ),
1570
+ u(
1571
+ "Raised from",
1572
+ /* @__PURE__ */ t(
1573
+ g,
1574
+ {
1575
+ value: a.source,
1576
+ onChange: (l) => d({ source: l }),
1577
+ options: [
1578
+ { value: "", label: "Worked out from the request" },
1579
+ ...Object.keys(O).map((l) => ({
1580
+ value: l,
1581
+ label: O[l].replace(/^./, (b) => b.toUpperCase())
1582
+ }))
1583
+ ],
1584
+ ariaLabel: "Raised from",
1585
+ className: h(f, "w-full")
1586
+ }
1587
+ )
1588
+ ),
1589
+ u(
1590
+ "When",
1591
+ /* @__PURE__ */ t(
1592
+ g,
1593
+ {
1594
+ value: a.when,
1595
+ onChange: (l) => d({ when: l }),
1596
+ options: [
1597
+ { value: "now", label: "Right now" },
1598
+ { value: "inside", label: "During business hours" },
1599
+ { value: "outside", label: "Outside business hours" }
1600
+ ],
1601
+ ariaLabel: "When",
1602
+ className: h(f, "w-full")
1603
+ }
1604
+ )
1605
+ ),
1606
+ /* @__PURE__ */ t("div", { className: "sm:col-span-2 lg:col-span-4", children: u(
1607
+ "Title and description",
1608
+ /* @__PURE__ */ t(
1609
+ "input",
1610
+ {
1611
+ value: a.title,
1612
+ onChange: (l) => d({ title: l.target.value }),
1613
+ placeholder: "e.g. Please change the vendor on this PO",
1614
+ className: h(T, "w-full")
1615
+ }
1616
+ )
1617
+ ) })
1618
+ ] }),
1619
+ /* @__PURE__ */ t("div", { className: "flex items-center gap-2 border-t border-slate-100 px-4 py-2.5 dark:border-border/60", children: /* @__PURE__ */ t(
1620
+ "button",
1621
+ {
1622
+ type: "button",
1623
+ className: M,
1624
+ onClick: () => p.mutate(),
1625
+ disabled: p.isPending,
1626
+ "data-support-try-run": !0,
1627
+ children: p.isPending ? "Checking…" : "Who gets it?"
1628
+ }
1629
+ ) }),
1630
+ p.data && /* @__PURE__ */ t(vt, { result: p.data })
1631
+ ]
1632
+ }
1633
+ );
1634
+ }
1635
+ function vt({ result: e }) {
1636
+ var a;
1637
+ const r = e.outcome, s = r.kind === "person" ? r.user.name : r.kind === "team" ? `${r.team.name}’s desk` : r.via === "keep" ? "Stays with whoever has it" : "The desk (unassigned)", i = r.kind === "person" && r.via === "type_default" ? "the type’s default assignee — no rule fits" : r.rule ? `rule “${r.rule.name}”${r.via === "rule_fallback" ? " — its fallback" : ""}` : "no rule fits";
1638
+ return /* @__PURE__ */ o(
1639
+ "div",
1640
+ {
1641
+ className: "space-y-4 border-t border-slate-100 px-4 py-4 dark:border-border/60",
1642
+ "data-support-try-result": !0,
1643
+ role: "status",
1644
+ children: [
1645
+ /* @__PURE__ */ o("div", { className: "flex items-center gap-3", children: [
1646
+ r.kind === "person" ? /* @__PURE__ */ t(D, { id: r.user.id, name: r.user.name, size: 32 }) : /* @__PURE__ */ t("span", { className: "flex h-8 w-8 items-center justify-center rounded-full bg-slate-100 dark:bg-white/10", children: /* @__PURE__ */ t(ne, { className: "h-4 w-4 text-slate-500" }) }),
1647
+ /* @__PURE__ */ o("div", { children: [
1648
+ /* @__PURE__ */ t("p", { className: "text-[14px] font-semibold text-slate-900 dark:text-slate-100", children: s }),
1649
+ /* @__PURE__ */ o("p", { className: "text-[12px] text-slate-500 dark:text-muted-foreground", children: [
1650
+ "By ",
1651
+ i,
1652
+ ". ",
1653
+ r.note
1654
+ ] })
1655
+ ] })
1656
+ ] }),
1657
+ e.pick && (e.pick.ranking.length > 0 || e.pick.skipped.length > 0) && /* @__PURE__ */ o("div", { className: "grid gap-4 md:grid-cols-2", children: [
1658
+ e.pick.ranking.length > 0 && /* @__PURE__ */ o("div", { children: [
1659
+ /* @__PURE__ */ o("h4", { className: "mb-1.5 text-[12px] font-semibold text-slate-700 dark:text-slate-200", children: [
1660
+ "Ranking",
1661
+ e.pick.used !== void 0 ? ` — ${(a = K.find((n) => {
1662
+ var d;
1663
+ return n.value === ((d = e.pick) == null ? void 0 : d.used);
1664
+ })) == null ? void 0 : a.label.toLowerCase()}` : ""
1665
+ ] }),
1666
+ /* @__PURE__ */ t("ol", { className: "space-y-1", children: e.pick.ranking.map((n, d) => /* @__PURE__ */ o("li", { className: "flex items-center gap-2 text-[12.5px]", children: [
1667
+ /* @__PURE__ */ t("span", { className: "w-4 text-right tabular-nums text-slate-400", children: d + 1 }),
1668
+ /* @__PURE__ */ t(D, { id: n.id, name: n.name, size: 18 }),
1669
+ /* @__PURE__ */ o(
1670
+ "span",
1671
+ {
1672
+ className: h(
1673
+ "truncate",
1674
+ d === 0 ? "font-medium text-slate-900 dark:text-slate-100" : "text-slate-700 dark:text-slate-300"
1675
+ ),
1676
+ children: [
1677
+ n.name,
1678
+ n.for && /* @__PURE__ */ o("span", { className: "font-normal text-slate-500", children: [
1679
+ " (covering ",
1680
+ n.for,
1681
+ ")"
1682
+ ] })
1683
+ ]
1684
+ }
1685
+ ),
1686
+ /* @__PURE__ */ t("span", { className: "ml-auto shrink-0 tabular-nums text-slate-500 dark:text-muted-foreground", children: n.measure })
1687
+ ] }, n.id)) })
1688
+ ] }),
1689
+ e.pick.skipped.length > 0 && /* @__PURE__ */ o("div", { children: [
1690
+ /* @__PURE__ */ t("h4", { className: "mb-1.5 text-[12px] font-semibold text-slate-700 dark:text-slate-200", children: "Skipped" }),
1691
+ /* @__PURE__ */ t("ul", { className: "space-y-1", children: e.pick.skipped.map((n) => /* @__PURE__ */ o("li", { className: "flex items-center gap-2 text-[12.5px]", children: [
1692
+ /* @__PURE__ */ t(D, { id: n.id, name: n.name, size: 18 }),
1693
+ /* @__PURE__ */ t("span", { className: "truncate text-slate-700 dark:text-slate-300", children: n.name }),
1694
+ /* @__PURE__ */ t("span", { className: "ml-auto shrink-0 text-right text-slate-500 dark:text-muted-foreground", children: n.reason })
1695
+ ] }, n.id)) })
1696
+ ] })
1697
+ ] }),
1698
+ e.trace.length > 0 && /* @__PURE__ */ o("div", { children: [
1699
+ /* @__PURE__ */ t("h4", { className: "mb-1.5 text-[12px] font-semibold text-slate-700 dark:text-slate-200", children: "Each rule" }),
1700
+ /* @__PURE__ */ t("ol", { className: "space-y-1", children: e.trace.map((n, d) => /* @__PURE__ */ o(
1701
+ "li",
1702
+ {
1703
+ className: "flex flex-wrap items-baseline gap-x-2 gap-y-0.5 text-[12.5px]",
1704
+ children: [
1705
+ /* @__PURE__ */ t("span", { className: "w-4 text-right tabular-nums text-slate-400", children: d + 1 }),
1706
+ /* @__PURE__ */ t(
1707
+ "span",
1708
+ {
1709
+ className: h(
1710
+ "inline-flex w-[5.75rem] shrink-0 justify-center rounded px-1.5 py-px text-[11px] font-medium",
1711
+ n.result === "matched" ? "bg-emerald-50 text-emerald-700 dark:bg-emerald-400/10 dark:text-emerald-300" : "bg-slate-100 text-slate-600 dark:bg-white/10 dark:text-slate-300"
1712
+ ),
1713
+ children: n.result === "matched" ? "Wins" : n.result === "no_match" ? "Doesn’t fit" : n.result === "held" ? "Held back" : "Not reached"
1714
+ }
1715
+ ),
1716
+ /* @__PURE__ */ t("span", { className: "font-medium text-slate-800 dark:text-slate-100", children: n.name }),
1717
+ n.reasons.length > 0 && // Phone: the reason on its own line under the rule name, no hanging dash.
1718
+ /* @__PURE__ */ o("span", { className: "text-slate-500 max-sm:basis-full max-sm:pl-6 dark:text-muted-foreground", children: [
1719
+ /* @__PURE__ */ t("span", { className: "max-sm:hidden", children: "— " }),
1720
+ n.reasons.join("; ")
1721
+ ] })
1722
+ ]
1723
+ },
1724
+ n.id
1725
+ )) })
1726
+ ] })
1727
+ ]
1728
+ }
1729
+ );
1730
+ }
1731
+ export {
1732
+ Bt as AssignRulesView
1733
+ };