@alfadocs/ui-kit 1.147.1 → 1.148.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 (108) hide show
  1. package/dist/_chunks/{appointment-details-panel.history-eqPMKmW0.js → appointment-details-panel.history-BxNqcA-r.js} +109 -110
  2. package/dist/_chunks/{appointment-timeline-D5qbZ7in.js → appointment-timeline-CuZW-CGT.js} +2 -2
  3. package/dist/_chunks/{bill-line-table-DnkFqMnM.js → bill-line-table-B8Cc2pTH.js} +2 -2
  4. package/dist/_chunks/button-group-CHQD8GJ0.js +449 -0
  5. package/dist/_chunks/{calendar-appointment-editor-dialog-sY-k0GGW.js → calendar-appointment-editor-dialog-Cz8F2H4M.js} +6 -6
  6. package/dist/_chunks/{calendar-waiting-list-panel-Bm7NAZdk.js → calendar-waiting-list-panel-C4T85b4q.js} +3 -3
  7. package/dist/_chunks/{calendar.sheets-CCvdZF-R.js → calendar.sheets-DsgPdycU.js} +4 -4
  8. package/dist/_chunks/{data-grid-CujX-2tF.js → data-grid-CkzbCZSo.js} +486 -476
  9. package/dist/_chunks/{default-tabs-CqP1uWdx.js → default-tabs-C45FVzsG.js} +3 -3
  10. package/dist/_chunks/editable-description-BsSjLnSx.js +193 -0
  11. package/dist/_chunks/{editable-description.agent-Bm_LBV2j.js → editable-description.agent-zyyR_hxB.js} +2 -2
  12. package/dist/_chunks/{face-scheme-ByYeboH9.js → face-scheme-BC2whb1S.js} +2 -2
  13. package/dist/_chunks/{invoice-upload-list-srvWy5_d.js → invoice-upload-list-BReimsvV.js} +3 -3
  14. package/dist/_chunks/{notes-panel-C9aB1Cma.js → notes-panel-BHMnLbEH.js} +2 -2
  15. package/dist/_chunks/prescription-history-CQuJmd4H.js +1846 -0
  16. package/dist/_chunks/{rich-text-editor-CJXc5GgH.js → rich-text-editor-BAcJq1PO.js} +445 -437
  17. package/dist/_chunks/{tasks-panel-DsjfS_k5.js → tasks-panel-DufAoAxG.js} +2 -2
  18. package/dist/_chunks/{toolbar-z_6tE7zG.js → toolbar-B9oh9XY9.js} +2 -2
  19. package/dist/_chunks/{use-appointment-details-read-Dod21IxM.js → use-appointment-details-read-kYp-gfhb.js} +417 -422
  20. package/dist/agent-catalog.json +2 -2
  21. package/dist/appointment-editor-panel/index.js +1 -1
  22. package/dist/browser-support.js +1 -1
  23. package/dist/calendar-action-buttons/index.js +1 -1
  24. package/dist/components/appointment-details-panel/appointment-details-panel.history.d.ts +4 -6
  25. package/dist/components/appointment-details-panel/index.js +1 -1
  26. package/dist/components/appointment-timeline/index.js +1 -1
  27. package/dist/components/bill-line-table/index.js +1 -1
  28. package/dist/components/bill-table/index.js +1 -1
  29. package/dist/components/button-group/button-group.d.ts +2 -1
  30. package/dist/components/button-group/index.js +1 -1
  31. package/dist/components/data-grid/data-grid.variants.d.ts +7 -1
  32. package/dist/components/data-grid/index.js +2 -2
  33. package/dist/components/editable-description/editable-description.d.ts +2 -1
  34. package/dist/components/editable-description/index.js +2 -2
  35. package/dist/components/face-scheme/index.js +1 -1
  36. package/dist/components/invoice-upload-list/index.js +1 -1
  37. package/dist/components/notes-panel/index.js +1 -1
  38. package/dist/components/rich-text-editor/index.js +1 -1
  39. package/dist/components/tasks-panel/index.js +1 -1
  40. package/dist/core.css +1 -1
  41. package/dist/find-free-slots-panel/index.js +1 -1
  42. package/dist/host-compat.css +7 -1
  43. package/dist/i18n/locales/ar.d.ts +0 -1
  44. package/dist/i18n/locales/ar.js +1 -2
  45. package/dist/i18n/locales/de.d.ts +0 -1
  46. package/dist/i18n/locales/de.js +1 -2
  47. package/dist/i18n/locales/el.d.ts +0 -1
  48. package/dist/i18n/locales/el.js +1 -2
  49. package/dist/i18n/locales/en.d.ts +0 -1
  50. package/dist/i18n/locales/en.js +1 -2
  51. package/dist/i18n/locales/es.d.ts +0 -1
  52. package/dist/i18n/locales/es.js +1 -2
  53. package/dist/i18n/locales/fr.d.ts +0 -1
  54. package/dist/i18n/locales/fr.js +1 -2
  55. package/dist/i18n/locales/hi.d.ts +0 -1
  56. package/dist/i18n/locales/hi.js +1 -2
  57. package/dist/i18n/locales/it.d.ts +0 -1
  58. package/dist/i18n/locales/it.js +1 -2
  59. package/dist/i18n/locales/ja.d.ts +0 -1
  60. package/dist/i18n/locales/ja.js +1 -2
  61. package/dist/i18n/locales/nl.d.ts +0 -1
  62. package/dist/i18n/locales/nl.js +1 -2
  63. package/dist/i18n/locales/pl.d.ts +0 -1
  64. package/dist/i18n/locales/pl.js +1 -2
  65. package/dist/i18n/locales/pt.d.ts +0 -1
  66. package/dist/i18n/locales/pt.js +1 -2
  67. package/dist/i18n/locales/ro.d.ts +0 -1
  68. package/dist/i18n/locales/ro.js +1 -2
  69. package/dist/i18n/locales/ru.d.ts +0 -1
  70. package/dist/i18n/locales/ru.js +1 -2
  71. package/dist/i18n/locales/sq.d.ts +0 -1
  72. package/dist/i18n/locales/sq.js +1 -2
  73. package/dist/i18n/locales/sv.d.ts +0 -1
  74. package/dist/i18n/locales/sv.js +1 -2
  75. package/dist/i18n/locales/tr.d.ts +0 -1
  76. package/dist/i18n/locales/tr.js +1 -2
  77. package/dist/i18n/locales/zh.d.ts +0 -1
  78. package/dist/i18n/locales/zh.js +1 -2
  79. package/dist/index.js +17 -17
  80. package/dist/locales/ar.json +1 -2
  81. package/dist/locales/de.json +1 -2
  82. package/dist/locales/el.json +1 -2
  83. package/dist/locales/en.json +1 -2
  84. package/dist/locales/es.json +1 -2
  85. package/dist/locales/fr.json +1 -2
  86. package/dist/locales/hi.json +1 -2
  87. package/dist/locales/it.json +1 -2
  88. package/dist/locales/ja.json +1 -2
  89. package/dist/locales/nl.json +1 -2
  90. package/dist/locales/pl.json +1 -2
  91. package/dist/locales/pt.json +1 -2
  92. package/dist/locales/ro.json +1 -2
  93. package/dist/locales/ru.json +1 -2
  94. package/dist/locales/sq.json +1 -2
  95. package/dist/locales/sv.json +1 -2
  96. package/dist/locales/tr.json +1 -2
  97. package/dist/locales/zh.json +1 -2
  98. package/dist/online-bookings-panel/index.js +1 -1
  99. package/dist/patterns/calendar/index.js +2 -2
  100. package/dist/patterns/prescription/index.d.ts +1 -1
  101. package/dist/patterns/prescription/index.js +1 -1
  102. package/dist/patterns/prescription/prescription-history.d.ts +28 -0
  103. package/dist/tokens.css +1 -1
  104. package/dist/waiting-list-panel/index.js +2 -2
  105. package/package.json +1 -1
  106. package/dist/_chunks/button-group-N60L3HMa.js +0 -408
  107. package/dist/_chunks/editable-description-BQauSuCG.js +0 -142
  108. package/dist/_chunks/prescription-history-CFs3JMIE.js +0 -1773
@@ -0,0 +1,1846 @@
1
+ import { jsxs as b, jsx as e, Fragment as _e } from "react/jsx-runtime";
2
+ import { forwardRef as Oe, useId as Ne, useState as te, useRef as T, useEffect as Pe, useCallback as M, useMemo as Ge, useImperativeHandle as Pt } from "react";
3
+ import { c as C } from "./index-D2ZczOXr.js";
4
+ import { useTranslation as xe } from "react-i18next";
5
+ import { A as ge } from "./alert-C4WKViaS.js";
6
+ import { B as ze } from "./button-Dp4j9ygh.js";
7
+ import { E as Yt } from "./empty-state-5REM7oDM.js";
8
+ import { E as Ut } from "./error-summary-DxNhwf_G.js";
9
+ import { F as Xt } from "./field-array-kwUgFOIr.js";
10
+ import { F as me } from "./form-field-CyHfOVKF.js";
11
+ import { S as xt } from "./select-Bw5FvGJ7.js";
12
+ import { S as De } from "./skeleton-tTWJpvAq.js";
13
+ import { P as Jt } from "./patient-picker-Dm74jHIk.js";
14
+ import { p as lt } from "./privacy-mask-text-B8YfzB7L.js";
15
+ import { u as Zt } from "./use-controllable-state-BiY4xTzM.js";
16
+ import { u as Ce } from "./use-isomorphic-layout-effect-BGfaCOP1.js";
17
+ import { u as er, a as tr } from "./use-error-summary-CecJZo6w.js";
18
+ import { C as rr } from "./checkbox-DV4sNDeB.js";
19
+ import { N as ir } from "./number-input-Bi5Yk6PX.js";
20
+ import { T as nt } from "./text-input-B6iAgCr3.js";
21
+ import { M as sr } from "./medication-search-CTUtXuPT.js";
22
+ import { a as ar, S as nr } from "./suggestion-chip-BNRWZL51.js";
23
+ import { V as dt } from "./visually-hidden-BHxEUGyT.js";
24
+ import { T as or } from "./timestamp-UMF1llBs.js";
25
+ import { I as Et } from "./icon-button-u9VMQn3x.js";
26
+ import { B as cr } from "./button-group-CHQD8GJ0.js";
27
+ import { D as Fe } from "./dropdown-menu-Bm1KALnk.js";
28
+ import { K as lr, a as oe, S as St } from "./key-value-pair-BykhMTcP.js";
29
+ import { a as dr, M as pr } from "./medication-line-DFa5oFhf.js";
30
+ import { P as ur } from "./print-sheet-gaxObGcm.js";
31
+ import { a as mr } from "./whatsapp-button-XbozeDl_.js";
32
+ import { f as He } from "./intl-locale-FWh-Y5_3.js";
33
+ import { A as qt } from "./avatar-Dp5apm1d.js";
34
+ import { P as At } from "./printer-rkK0T1gi.js";
35
+ import { D as fr } from "./download-CfYKJO_j.js";
36
+ import { M as hr } from "./mail-BqXVF2zH.js";
37
+ import { M as br } from "./message-square-Bye4ATvx.js";
38
+ import { C as gr } from "./chevron-down-DWE7GSq9.js";
39
+ import { I as vr } from "./icon-button-group-DEAx9M5v.js";
40
+ import { T as yr } from "./tag-BNlcEJfE.js";
41
+ import { R as Ir } from "./row-actions-CA938TAd.js";
42
+ import { e as Nr } from "./data-grid-CkzbCZSo.js";
43
+ import { D as ee, a as xr } from "./toolbar-B9oh9XY9.js";
44
+ import { B as Sr } from "./badge-BUk4RjTS.js";
45
+ import { C as kr } from "./check-DrFSN__t.js";
46
+ import { L as wr } from "./loader-circle-BECIU_8N.js";
47
+ import { C as Tr } from "./circle-alert-rGDZ73Wh.js";
48
+ import { E as $r } from "./eye-BjhN2nYf.js";
49
+ import { P as Cr } from "./plus-DzMQ_c6b.js";
50
+ function Pr(t, a) {
51
+ const n = {};
52
+ if (t.patientId && a.patientId && (n.patientId = t.patientId), t.prescriberId && a.prescriberId && (n.prescriberId = t.prescriberId), t.treatmentId && a.treatmentId === t.treatmentId && (n.treatmentId = t.treatmentId), t.items && a.items && (n.items = t.items), t.itemErrors) {
53
+ const h = t.itemErrors.map(
54
+ (m, k) => {
55
+ var N;
56
+ const g = (N = a.itemErrors) == null ? void 0 : N[k];
57
+ if (!m || !g) return;
58
+ const o = {};
59
+ return m.medicationId && g.medicationId && (o.medicationId = m.medicationId), m.dosage && g.dosage && (o.dosage = m.dosage), m.quantity && g.quantity && (o.quantity = m.quantity), Object.keys(o).length > 0 ? o : void 0;
60
+ }
61
+ );
62
+ h.some((m) => m !== void 0) && (n.itemErrors = h);
63
+ }
64
+ return n;
65
+ }
66
+ const Er = 5, qr = C(
67
+ "ds:@container/rxline ds:flex ds:flex-col ds:gap-[var(--spacing-sm)]",
68
+ {
69
+ variants: {
70
+ separated: {
71
+ true: "ds:border-t ds:border-[color:var(--border)] ds:pt-[var(--spacing-lg)]",
72
+ false: "ds:pt-[var(--spacing-xs)]"
73
+ }
74
+ },
75
+ defaultVariants: { separated: !1 }
76
+ }
77
+ );
78
+ function Ar({
79
+ index: t,
80
+ item: a,
81
+ medication: n,
82
+ medicationFieldId: h,
83
+ dosageFieldId: m,
84
+ quantityFieldId: k,
85
+ medicationError: g,
86
+ dosageError: o,
87
+ quantityError: N,
88
+ announceMedicationError: q,
89
+ announceDosageError: $,
90
+ announceQuantityError: j,
91
+ searchMedications: L,
92
+ codeLabel: W,
93
+ catalogueStatus: Q,
94
+ onCatalogueRetry: ie,
95
+ suggestions: Y,
96
+ onMedicationChange: P,
97
+ onDosageChange: p,
98
+ onNotesChange: fe,
99
+ onQuantityChange: R,
100
+ onDurationChange: f,
101
+ onNotSubstitutableChange: ce,
102
+ medicationSearchId: le,
103
+ medicationRef: O,
104
+ dosageInputRef: se,
105
+ onSuggestionChosen: U
106
+ }) {
107
+ const { t: E } = xe("ui"), l = t + 1, X = `${h}-legend`, d = Y.slice(0, Er), I = `${h}-hint`;
108
+ return /* @__PURE__ */ b(
109
+ "div",
110
+ {
111
+ role: "group",
112
+ "aria-labelledby": X,
113
+ "data-slot": "prescription-item",
114
+ "data-index": t,
115
+ className: qr({ separated: t > 0 }),
116
+ children: [
117
+ /* @__PURE__ */ e("p", { id: X, className: "type-label ds:text-foreground", children: E("prescription.composer.medicationLegend", { number: l }) }),
118
+ /* @__PURE__ */ e(
119
+ me,
120
+ {
121
+ id: h,
122
+ label: E("prescription.composer.medication"),
123
+ required: !0,
124
+ error: g,
125
+ announceError: q,
126
+ children: /* @__PURE__ */ e(
127
+ sr,
128
+ {
129
+ ref: O,
130
+ id: le,
131
+ loadOptions: L,
132
+ value: n,
133
+ onValueChange: P,
134
+ codeLabel: W,
135
+ status: Q,
136
+ onRetry: ie
137
+ }
138
+ )
139
+ }
140
+ ),
141
+ /* @__PURE__ */ e(
142
+ me,
143
+ {
144
+ id: m,
145
+ label: E("prescription.composer.dosage"),
146
+ required: !0,
147
+ error: o,
148
+ announceError: $,
149
+ children: /* @__PURE__ */ e(
150
+ nt,
151
+ {
152
+ ref: se,
153
+ dir: "auto",
154
+ value: a.dosage,
155
+ onChange: (x) => p(x.target.value)
156
+ }
157
+ )
158
+ }
159
+ ),
160
+ n && d.length > 0 ? /* @__PURE__ */ b(
161
+ "div",
162
+ {
163
+ "data-slot": "dosage-suggestions",
164
+ className: "ds:flex ds:flex-col ds:gap-[var(--spacing-xs)]",
165
+ children: [
166
+ /* @__PURE__ */ e("p", { id: I, className: "type-body-sm ds:text-muted-foreground", children: E("prescription.composer.dosageSuggestionsHint") }),
167
+ /* @__PURE__ */ e(
168
+ ar,
169
+ {
170
+ label: E("prescription.composer.dosageSuggestions"),
171
+ "aria-describedby": I,
172
+ children: d.map((x) => /* @__PURE__ */ e(
173
+ nr,
174
+ {
175
+ value: x,
176
+ dir: "auto",
177
+ keepOnSelect: !0,
178
+ onSelect: U,
179
+ children: x
180
+ },
181
+ x
182
+ ))
183
+ }
184
+ )
185
+ ]
186
+ }
187
+ ) : null,
188
+ /* @__PURE__ */ b("div", { className: "ds:grid ds:grid-cols-1 ds:gap-[var(--spacing-sm)] ds:@[576px]/rxline:grid-cols-[minmax(8rem,10rem)_minmax(0,1fr)_minmax(0,1fr)]", children: [
189
+ /* @__PURE__ */ e(
190
+ me,
191
+ {
192
+ id: k,
193
+ label: E("prescription.composer.quantity"),
194
+ required: !0,
195
+ description: n == null ? void 0 : n.packsHint,
196
+ error: N,
197
+ announceError: j,
198
+ children: /* @__PURE__ */ e(
199
+ ir,
200
+ {
201
+ min: 1,
202
+ max: n == null ? void 0 : n.maxPacks,
203
+ step: 1,
204
+ value: Number.isFinite(a.quantity) ? a.quantity : null,
205
+ onChange: (x) => R(x ?? Number.NaN)
206
+ }
207
+ )
208
+ }
209
+ ),
210
+ /* @__PURE__ */ e(me, { label: E("prescription.composer.notes"), optional: !0, children: /* @__PURE__ */ e(
211
+ nt,
212
+ {
213
+ dir: "auto",
214
+ value: a.notes,
215
+ onChange: (x) => fe(x.target.value)
216
+ }
217
+ ) }),
218
+ /* @__PURE__ */ e(me, { label: E("prescription.composer.duration"), optional: !0, children: /* @__PURE__ */ e(
219
+ nt,
220
+ {
221
+ dir: "auto",
222
+ value: a.duration,
223
+ onChange: (x) => f(x.target.value)
224
+ }
225
+ ) })
226
+ ] }),
227
+ /* @__PURE__ */ e(
228
+ rr,
229
+ {
230
+ label: E("prescription.composer.notSubstitutable"),
231
+ checked: a.notSubstitutable,
232
+ disabled: !(n != null && n.code) && !a.notSubstitutable,
233
+ disabledReason: E("prescription.composer.notSubstitutableNeedsCode"),
234
+ onCheckedChange: (x) => ce(x === !0)
235
+ }
236
+ )
237
+ ]
238
+ }
239
+ );
240
+ }
241
+ const Vr = /^(\d{4})-(\d{2})-(\d{2})$/;
242
+ function Mr(t, a) {
243
+ const n = Vr.exec(t);
244
+ if (!n) return t;
245
+ const h = Number(n[1]), m = Number(n[2]), k = Number(n[3]), g = new Date(2e3, m - 1, k);
246
+ return g.setFullYear(h), Number.isNaN(g.getTime()) || g.getMonth() !== m - 1 || g.getDate() !== k ? t : new Intl.DateTimeFormat(He(a), {
247
+ dateStyle: "long"
248
+ }).format(g);
249
+ }
250
+ function Re(t) {
251
+ return t !== void 0 && t.trim() !== "";
252
+ }
253
+ const Lr = C("ds:@container/pblock ds:flex ds:items-start", {
254
+ variants: {
255
+ density: {
256
+ default: "ds:gap-[var(--spacing-md)]",
257
+ compact: "ds:gap-[var(--spacing-sm)]"
258
+ }
259
+ },
260
+ defaultVariants: { density: "default" }
261
+ }), pt = Oe(
262
+ ({
263
+ patient: t,
264
+ privacyMode: a = !1,
265
+ density: n = "default",
266
+ showAvatar: h = !1,
267
+ className: m,
268
+ ...k
269
+ }, g) => {
270
+ const { t: o, i18n: N } = xe("ui"), q = () => /* @__PURE__ */ b(_e, { children: [
271
+ /* @__PURE__ */ e(dt, { children: o("calendarWorkspace.privacy.hidden") }),
272
+ /* @__PURE__ */ e("span", { "aria-hidden": "true", children: lt() })
273
+ ] }), $ = [];
274
+ Re(t.firstName) && $.push({
275
+ key: "firstName",
276
+ label: o("prescription.patient.firstName"),
277
+ value: a ? q() : /* @__PURE__ */ e("span", { dir: "auto", children: t.firstName })
278
+ }), Re(t.lastName) && $.push({
279
+ key: "lastName",
280
+ label: o("prescription.patient.lastName"),
281
+ value: a ? q() : /* @__PURE__ */ e("span", { dir: "auto", children: t.lastName })
282
+ }), Re(t.dateOfBirth) && $.push({
283
+ key: "dateOfBirth",
284
+ label: o("prescription.patient.dateOfBirth"),
285
+ value: a ? q() : Mr(t.dateOfBirth, N.language)
286
+ }), Re(t.fiscalCode) && $.push({
287
+ key: "fiscalCode",
288
+ label: o("prescription.patient.fiscalCode"),
289
+ value: a ? q() : t.fiscalCode,
290
+ mono: !0
291
+ });
292
+ const j = `${t.firstName} ${t.lastName}`.trim();
293
+ return /* @__PURE__ */ b(
294
+ "div",
295
+ {
296
+ ...k,
297
+ ref: g,
298
+ role: "group",
299
+ "aria-label": o("prescription.patient.details"),
300
+ className: Lr({ density: n, className: m }),
301
+ "data-component": "prescription-patient-block",
302
+ "data-density": n,
303
+ "data-privacy": a ? "masked" : void 0,
304
+ children: [
305
+ h ? (
306
+ /* Under privacy mode the avatar shows no initials: an empty name
307
+ gives the Avatar's own neutral icon, at the same size. */
308
+ /* @__PURE__ */ e(
309
+ qt,
310
+ {
311
+ name: a ? "" : j,
312
+ size: "md",
313
+ className: "ds:shrink-0",
314
+ "aria-hidden": "true",
315
+ role: "presentation",
316
+ "aria-label": void 0
317
+ }
318
+ )
319
+ ) : null,
320
+ /* @__PURE__ */ e(
321
+ lr,
322
+ {
323
+ semantic: !0,
324
+ rowGap: n === "compact" ? "sm" : "md",
325
+ className: "ds:min-w-0 ds:flex-1 ds:@[448px]/pblock:grid-cols-[repeat(2,auto_fit-content(40%)_minmax(0,1fr))]",
326
+ children: $.map((L) => /* @__PURE__ */ e(
327
+ oe,
328
+ {
329
+ label: L.label,
330
+ value: L.value,
331
+ mono: L.mono,
332
+ "data-field": L.key
333
+ },
334
+ L.key
335
+ ))
336
+ }
337
+ )
338
+ ]
339
+ }
340
+ );
341
+ }
342
+ );
343
+ pt.displayName = "PrescriptionPatientBlock";
344
+ const je = Object.freeze({
345
+ medicationId: "",
346
+ dosage: "",
347
+ notes: "",
348
+ quantity: 1,
349
+ notSubstitutable: !1,
350
+ duration: ""
351
+ });
352
+ function Dr(t = "") {
353
+ return {
354
+ patientId: "",
355
+ prescriberId: t,
356
+ treatmentId: "",
357
+ items: [{ ...je }]
358
+ };
359
+ }
360
+ function re(t) {
361
+ return t == null || t.trim() === "";
362
+ }
363
+ function ct(t) {
364
+ return re(t.medicationId) && re(t.dosage) && re(t.notes) && re(t.duration) && !t.notSubstitutable;
365
+ }
366
+ function Fr(t, a) {
367
+ if (typeof t != "number" || Number.isNaN(t)) return "required";
368
+ if (!Number.isInteger(t) || t < 1) return "invalid";
369
+ if (a !== void 0 && t > a) return "tooMany";
370
+ }
371
+ function Rr(t, {
372
+ treatmentOptions: a,
373
+ treatmentOptionsPatientId: n
374
+ }) {
375
+ if (re(t.treatmentId)) return "required";
376
+ if (n !== void 0 && n !== t.patientId || a && !a.some((h) => h.id === t.treatmentId))
377
+ return "invalid";
378
+ }
379
+ function kt(t, a = {}) {
380
+ const n = {};
381
+ re(t.patientId) && (n.patientId = "required"), re(t.prescriberId) && (n.prescriberId = "required");
382
+ const h = Rr(t, a);
383
+ h && (n.treatmentId = h);
384
+ const m = t.items ?? [];
385
+ if (m.filter((o) => !ct(o)).length === 0)
386
+ return n.items = "required", m.length > 0 && (n.itemErrors = m.map(
387
+ (o, N) => N === 0 ? { medicationId: "required" } : void 0
388
+ )), n;
389
+ const g = m.map((o) => {
390
+ var $;
391
+ if (ct(o)) return;
392
+ const N = {};
393
+ re(o.medicationId) && (N.medicationId = "required"), re(o.dosage) && (N.dosage = "required");
394
+ const q = Fr(
395
+ o.quantity,
396
+ re(o.medicationId) || ($ = a.maxPacksFor) == null ? void 0 : $.call(a, o.medicationId.trim())
397
+ );
398
+ return q && (N.quantity = q), Object.keys(N).length > 0 ? N : void 0;
399
+ });
400
+ return g.some((o) => o !== void 0) && (n.itemErrors = g), n;
401
+ }
402
+ function wt(t) {
403
+ return Object.keys(t).length === 0;
404
+ }
405
+ function zr(t) {
406
+ return {
407
+ patientId: t.patientId.trim(),
408
+ prescriberId: t.prescriberId.trim(),
409
+ treatmentId: t.treatmentId.trim(),
410
+ items: t.items.filter((a) => !ct(a)).map((a) => ({
411
+ medicationId: a.medicationId.trim(),
412
+ dosage: a.dosage.trim(),
413
+ notes: a.notes.trim(),
414
+ quantity: a.quantity,
415
+ notSubstitutable: a.notSubstitutable,
416
+ duration: (a.duration ?? "").trim()
417
+ }))
418
+ };
419
+ }
420
+ const Br = C(
421
+ "ds:flex ds:w-full ds:flex-col ds:gap-[var(--spacing-lg)]"
422
+ );
423
+ function ot(t) {
424
+ return `${t.firstName} ${t.lastName}`.trim();
425
+ }
426
+ function Tt(t) {
427
+ return t.items.length > 0 ? t : { ...t, items: [{ ...je }] };
428
+ }
429
+ const _r = Oe(function({
430
+ patients: a,
431
+ searchPatients: n,
432
+ treatmentOptions: h,
433
+ treatmentOptionsPatientId: m,
434
+ prescribers: k,
435
+ defaultPrescriberId: g,
436
+ searchMedications: o,
437
+ resolveMedication: N,
438
+ suggestDosages: q,
439
+ codeLabel: $,
440
+ catalogueStatus: j = "ready",
441
+ onCatalogueRetry: L,
442
+ value: W,
443
+ defaultValue: Q,
444
+ onChange: ie,
445
+ onSubmit: Y,
446
+ onPatientChange: P,
447
+ loading: p = !1,
448
+ error: fe,
449
+ privacyMode: R = !1,
450
+ lockPatient: f = !1,
451
+ editing: ce = !1,
452
+ submitLabel: le,
453
+ id: O,
454
+ className: se,
455
+ ...U
456
+ }, E) {
457
+ const { t: l } = xe("ui"), X = Ne(), d = O ?? X, [I] = te(
458
+ () => Q ?? Dr(
459
+ g && k.some((r) => r.id === g) ? g : ""
460
+ )
461
+ ), [x, z] = Zt({
462
+ value: W,
463
+ defaultValue: I,
464
+ onChange: ie
465
+ }), B = Tt(x ?? I), w = T(B);
466
+ Ce(() => {
467
+ w.current = B;
468
+ });
469
+ const [A, G] = te({}), [H, s] = te(!1), [S, _] = te(!1), he = T(!1), F = T(!0);
470
+ Pe(() => (F.current = !0, () => {
471
+ F.current = !1;
472
+ }), []);
473
+ const [Ke, We] = te(() => /* @__PURE__ */ new Map()), [Ee, J] = te(() => /* @__PURE__ */ new Map()), Se = T(/* @__PURE__ */ new Map()), be = T(N);
474
+ Ce(() => {
475
+ be.current = N;
476
+ });
477
+ const de = M(
478
+ (r) => {
479
+ var i, c;
480
+ return (c = Se.current.get(r) ?? ((i = be.current) == null ? void 0 : i.call(be, r))) == null ? void 0 : c.maxPacks;
481
+ },
482
+ []
483
+ ), ke = M(
484
+ (r) => {
485
+ for (const i of r) Se.current.set(i.id, i);
486
+ J((i) => {
487
+ if (r.every((u) => i.get(u.id) === u)) return i;
488
+ const c = new Map(i);
489
+ for (const u of r) c.set(u.id, u);
490
+ return c;
491
+ });
492
+ },
493
+ []
494
+ ), v = T(o);
495
+ Ce(() => {
496
+ v.current = o;
497
+ });
498
+ const ve = M(
499
+ async (r, i) => {
500
+ const c = await v.current(r, i);
501
+ return i.signal.aborted || ke(c), c;
502
+ },
503
+ [ke]
504
+ ), ye = T(n);
505
+ Ce(() => {
506
+ ye.current = n;
507
+ });
508
+ const we = n !== void 0, Qe = Ge(() => {
509
+ if (we)
510
+ return async (r, i) => {
511
+ const c = ye.current, u = c ? await c(r, i) : [];
512
+ return i.signal.aborted || We((D) => {
513
+ const Z = new Map(D);
514
+ for (const ue of u) Z.set(ue.id, ue);
515
+ return Z;
516
+ }), u.map((D) => ({ id: D.id, name: ot(D) }));
517
+ };
518
+ }, [we]), pe = B.patientId, Te = pe ? (a == null ? void 0 : a.find((r) => r.id === pe)) ?? Ke.get(pe) : void 0, V = M(
519
+ (r) => {
520
+ w.current = r, z(r), G(
521
+ (i) => Object.keys(i).length === 0 ? i : Pr(
522
+ i,
523
+ kt(r, {
524
+ treatmentOptions: h,
525
+ treatmentOptionsPatientId: m,
526
+ maxPacksFor: de
527
+ })
528
+ )
529
+ );
530
+ },
531
+ [z, h, m, de]
532
+ ), Ye = M(
533
+ (r) => {
534
+ const i = w.current;
535
+ r !== i.patientId && (G({}), s(!1), V({
536
+ patientId: r,
537
+ prescriberId: i.prescriberId,
538
+ treatmentId: "",
539
+ items: [{ ...je }]
540
+ }), P == null || P(r));
541
+ },
542
+ [V, P]
543
+ ), ut = T(!1), Ue = M(
544
+ (r) => {
545
+ ut.current = !0, V({ ...w.current, prescriberId: r });
546
+ },
547
+ [V]
548
+ ), mt = T(!1);
549
+ Pe(() => {
550
+ if (mt.current || ut.current || !g || !k.some((i) => i.id === g))
551
+ return;
552
+ mt.current = !0;
553
+ const r = w.current;
554
+ r.prescriberId === "" && V({ ...r, prescriberId: g });
555
+ }, [g, k, V]);
556
+ const Xe = M(
557
+ (r) => V({ ...w.current, treatmentId: r }),
558
+ [V]
559
+ ), ae = M(
560
+ (r, i) => {
561
+ const c = w.current;
562
+ r < 0 || r >= c.items.length || V({
563
+ ...c,
564
+ items: c.items.map((u, D) => {
565
+ if (D !== r) return u;
566
+ const Z = i.medicationId !== void 0 && i.medicationId !== u.medicationId;
567
+ return {
568
+ ...u,
569
+ ...Z ? { notSubstitutable: !1 } : {},
570
+ ...i
571
+ };
572
+ })
573
+ });
574
+ },
575
+ [V]
576
+ ), Je = M(
577
+ (r) => {
578
+ const i = w.current;
579
+ return V({
580
+ ...i,
581
+ items: [...i.items, { ...je, ...r }]
582
+ }), i.items.length;
583
+ },
584
+ [V]
585
+ ), Ze = M(
586
+ (r) => {
587
+ const i = w.current;
588
+ i.items.length <= 1 || r < 0 || r >= i.items.length || V({
589
+ ...i,
590
+ items: i.items.filter((c, u) => u !== r)
591
+ });
592
+ },
593
+ [V]
594
+ ), ft = T(null), et = T(/* @__PURE__ */ new Map()), tt = T(/* @__PURE__ */ new Map()), [Ie, qe] = te(null);
595
+ Pe(() => {
596
+ var r, i, c, u;
597
+ Ie && (Ie.kind === "medication" ? (r = et.current.get(Ie.index)) == null || r.focus() : Ie.kind === "dosage" ? (i = tt.current.get(Ie.index)) == null || i.focus() : (u = (c = document.getElementById(`${d}-items`)) == null ? void 0 : c.querySelector(":scope > button")) == null || u.focus(), qe(null));
598
+ }, [Ie, d]);
599
+ const Mt = (r) => {
600
+ const i = w.current.items.length;
601
+ Ze(r), !(i <= 1) && qe(
602
+ i - 1 === 1 ? { kind: "add" } : { kind: "medication", index: Math.min(r, i - 2) }
603
+ );
604
+ }, ht = (r) => {
605
+ var i;
606
+ return l("prescription.composer.errors.quantityMax", {
607
+ max: de(((i = B.items[r]) == null ? void 0 : i.medicationId) ?? "")
608
+ });
609
+ }, ne = (r) => {
610
+ var D;
611
+ if (r === "patient")
612
+ return A.patientId ? l("prescription.composer.errors.patient") : void 0;
613
+ if (r === "prescriber")
614
+ return A.prescriberId ? l("prescription.composer.errors.prescriber") : void 0;
615
+ if (r === "treatment")
616
+ return A.treatmentId ? A.treatmentId === "invalid" ? l("prescription.composer.errors.treatmentInvalid") : l("prescription.composer.errors.treatment") : void 0;
617
+ if (r === "items")
618
+ return A.items ? l("prescription.composer.errors.items") : void 0;
619
+ const [i, c] = r.split(":"), u = (D = A.itemErrors) == null ? void 0 : D[Number(c)];
620
+ return i === "medication" ? u != null && u.medicationId && !A.items ? l("prescription.composer.errors.medication") : void 0 : i === "quantity" ? u != null && u.quantity ? u.quantity === "tooMany" ? ht(Number(c)) : u.quantity === "invalid" ? l("prescription.composer.errors.quantityInvalid") : l("prescription.composer.errors.quantity") : void 0 : u != null && u.dosage ? l("prescription.composer.errors.dosage") : void 0;
621
+ }, Lt = [
622
+ "patient",
623
+ "treatment",
624
+ "prescriber",
625
+ "items",
626
+ ...B.items.flatMap((r, i) => [
627
+ `medication:${i}`,
628
+ `dosage:${i}`,
629
+ `quantity:${i}`
630
+ ])
631
+ ], K = er(Lt, ne), bt = K.listed.length > 0, Dt = (r) => {
632
+ if (r === "items") return `${d}-medication-0`;
633
+ const [i, c] = r.split(":");
634
+ return c === void 0 ? `${d}-${r}` : `${d}-${i}-${c}`;
635
+ }, Ft = (r) => {
636
+ var u, D, Z, ue;
637
+ const [i, c] = r.split(":");
638
+ return i === "medication" ? l("prescription.composer.errors.medicationLine", {
639
+ number: Number(c) + 1
640
+ }) : i === "dosage" ? l("prescription.composer.errors.dosageLine", {
641
+ number: Number(c) + 1
642
+ }) : i === "quantity" ? ((D = (u = A.itemErrors) == null ? void 0 : u[Number(c)]) == null ? void 0 : D.quantity) === "tooMany" ? ht(Number(c)) : ((ue = (Z = A.itemErrors) == null ? void 0 : Z[Number(c)]) == null ? void 0 : ue.quantity) === "invalid" ? l("prescription.composer.errors.quantityInvalidLine", {
643
+ number: Number(c) + 1
644
+ }) : l("prescription.composer.errors.quantityLine", {
645
+ number: Number(c) + 1
646
+ }) : ne(r) ?? "";
647
+ }, Ae = M(
648
+ (r) => {
649
+ G(r), K.open();
650
+ },
651
+ // eslint-disable-next-line react-hooks/exhaustive-deps
652
+ [K.open]
653
+ ), Ve = M(
654
+ () => kt(w.current, {
655
+ treatmentOptions: h,
656
+ treatmentOptionsPatientId: m,
657
+ maxPacksFor: de
658
+ }),
659
+ [h, m, de]
660
+ ), gt = T(Y);
661
+ Ce(() => {
662
+ gt.current = Y;
663
+ });
664
+ const rt = M(async () => {
665
+ if (he.current) return;
666
+ const r = Ve();
667
+ if (!wt(r)) {
668
+ Ae(r);
669
+ return;
670
+ }
671
+ G({}), s(!1), he.current = !0, _(!0);
672
+ try {
673
+ return await gt.current(
674
+ zr(w.current)
675
+ ) ?? void 0;
676
+ } catch {
677
+ F.current && s(!0);
678
+ return;
679
+ } finally {
680
+ he.current = !1, F.current && _(!1);
681
+ }
682
+ }, [Ve, Ae]), vt = M(() => {
683
+ const r = w.current;
684
+ G({}), s(!1), V(Tt(I)), r.patientId !== I.patientId && (P == null || P(I.patientId));
685
+ }, [V, I, P]);
686
+ Pt(
687
+ E,
688
+ () => ({
689
+ getDraft: () => w.current,
690
+ setPatient: Ye,
691
+ setPrescriber: Ue,
692
+ setTreatment: Xe,
693
+ addItem: Je,
694
+ updateItem: ae,
695
+ removeItem: Ze,
696
+ validate: () => {
697
+ const r = Ve();
698
+ return wt(r) ? G({}) : Ae(r), r;
699
+ },
700
+ submit: rt,
701
+ reset: vt,
702
+ focusTitle: () => {
703
+ var r;
704
+ return (r = ft.current) == null ? void 0 : r.focus();
705
+ }
706
+ }),
707
+ [
708
+ Ye,
709
+ Ue,
710
+ Xe,
711
+ Je,
712
+ ae,
713
+ Ze,
714
+ Ve,
715
+ Ae,
716
+ rt,
717
+ vt
718
+ ]
719
+ );
720
+ const Me = fe ?? (H ? l("prescription.composer.errors.submit") : void 0), Rt = tr(Me, bt), zt = f && Te !== void 0, yt = `${d}-message`, [Bt, _t] = te("");
721
+ Pe(() => {
722
+ _t(p ? l("prescription.composer.loading") : "");
723
+ }, [p, l]);
724
+ const Gt = {
725
+ ...U,
726
+ "data-component": "prescription-composer",
727
+ "data-component-id": O,
728
+ "data-has-patient": pe !== "" ? !0 : void 0,
729
+ "data-submitting": S ? !0 : void 0
730
+ }, jt = Br({ className: se }), Ot = (a ?? []).map((r) => ({
731
+ id: r.id,
732
+ name: ot(r)
733
+ })), Ht = !R && Te ? ot(Te) : void 0, it = m !== void 0 && m !== pe, Le = it ? [] : h ?? [], $e = [];
734
+ for (const r of Le)
735
+ r.carePlan && !$e.some((i) => {
736
+ var c;
737
+ return i.id === ((c = r.carePlan) == null ? void 0 : c.id);
738
+ }) && $e.push(r.carePlan);
739
+ const Kt = (r) => {
740
+ const i = $e.filter((u) => u.label === r.label), c = i.length > 1 ? `${r.label} (${i.findIndex((u) => u.id === r.id) + 1})` : r.label;
741
+ return l("prescription.composer.carePlanGroup", {
742
+ label: `⁨${c}⁩`
743
+ });
744
+ }, st = (r, i) => ({
745
+ value: r.id,
746
+ label: r.label,
747
+ group: i,
748
+ dir: "auto"
749
+ }), It = $e.length === 0 ? Le.map((r) => st(r, void 0)) : [
750
+ ...$e.flatMap(
751
+ (r) => Le.filter((i) => {
752
+ var c;
753
+ return ((c = i.carePlan) == null ? void 0 : c.id) === r.id;
754
+ }).map((i) => st(i, Kt(r)))
755
+ ),
756
+ ...Le.filter((r) => !r.carePlan).map(
757
+ (r) => st(
758
+ r,
759
+ l("prescription.composer.treatmentsStandalone")
760
+ )
761
+ )
762
+ ], Wt = k.map((r) => ({
763
+ value: r.id,
764
+ label: r.name,
765
+ description: r.specialty,
766
+ dir: "auto"
767
+ })), Qt = (r) => {
768
+ r.preventDefault(), rt();
769
+ }, Nt = Me ? /* @__PURE__ */ e(ge, { id: yt, variant: "error", announce: Rt, children: /* @__PURE__ */ e(ge.Description, { children: Me }) }) : null;
770
+ return /* @__PURE__ */ b("div", { ...Gt, className: jt, children: [
771
+ /* @__PURE__ */ e("div", { role: "status", className: "ds:sr-only", children: Bt }),
772
+ p ? /* @__PURE__ */ b(
773
+ "div",
774
+ {
775
+ "aria-hidden": "true",
776
+ className: "ds:flex ds:flex-col ds:gap-[var(--spacing-lg)]",
777
+ children: [
778
+ /* @__PURE__ */ e(De, { variant: "rounded", size: "sm" }),
779
+ /* @__PURE__ */ e(De, { variant: "text", lines: 3 }),
780
+ /* @__PURE__ */ e(De, { variant: "rounded", size: "sm" }),
781
+ /* @__PURE__ */ e(De, { variant: "rounded", size: "lg" })
782
+ ]
783
+ }
784
+ ) : /* @__PURE__ */ b(
785
+ "form",
786
+ {
787
+ noValidate: !0,
788
+ onSubmit: Qt,
789
+ "aria-labelledby": `${d}-title`,
790
+ className: "ds:flex ds:flex-col ds:gap-[var(--spacing-lg)]",
791
+ children: [
792
+ /* @__PURE__ */ e(
793
+ "h2",
794
+ {
795
+ ref: ft,
796
+ id: `${d}-title`,
797
+ tabIndex: -1,
798
+ className: "type-title-section ds:m-0 ds:focus:outline-none",
799
+ children: l(ce ? "prescription.composer.editTitle" : "prescription.composer.title")
800
+ }
801
+ ),
802
+ bt ? /* @__PURE__ */ e(
803
+ Ut,
804
+ {
805
+ ref: K.ref,
806
+ title: l("prescription.composer.errorTitle"),
807
+ headingLevel: 3,
808
+ "aria-describedby": Me ? yt : void 0,
809
+ errors: K.listed.map((r) => ({
810
+ field: r,
811
+ message: Ft(r),
812
+ targetId: Dt(r)
813
+ }))
814
+ }
815
+ ) : null,
816
+ zt ? null : /* @__PURE__ */ e(
817
+ me,
818
+ {
819
+ id: `${d}-patient`,
820
+ label: l("prescription.composer.patient"),
821
+ required: !0,
822
+ description: R && pe !== "" ? l("calendarWorkspace.privacy.hidden") : void 0,
823
+ error: ne("patient"),
824
+ announceError: !K.lists("patient"),
825
+ children: /* @__PURE__ */ e(
826
+ Jt,
827
+ {
828
+ value: pe,
829
+ onValueChange: Ye,
830
+ patients: Ot,
831
+ searchPatients: Qe,
832
+ selectedLabel: Ht,
833
+ privacyMask: R ? lt() : void 0,
834
+ placeholder: l("prescription.composer.patientPlaceholder")
835
+ }
836
+ )
837
+ }
838
+ ),
839
+ pe === "" ? /* @__PURE__ */ b(_e, { children: [
840
+ /* @__PURE__ */ e(
841
+ Yt,
842
+ {
843
+ variant: "first-use",
844
+ size: "sm",
845
+ title: l("prescription.composer.choosePatientTitle"),
846
+ description: l("prescription.composer.choosePatientBody")
847
+ }
848
+ ),
849
+ Nt
850
+ ] }) : /* @__PURE__ */ b(_e, { children: [
851
+ Te ? /* @__PURE__ */ e(
852
+ pt,
853
+ {
854
+ patient: Te,
855
+ privacyMode: R,
856
+ showAvatar: !0
857
+ }
858
+ ) : null,
859
+ /* @__PURE__ */ e(
860
+ me,
861
+ {
862
+ id: `${d}-treatment`,
863
+ label: l("prescription.composer.treatment"),
864
+ required: !0,
865
+ description: It.length === 0 && !it ? l("prescription.composer.treatmentEmpty") : void 0,
866
+ error: ne("treatment"),
867
+ announceError: !K.lists("treatment"),
868
+ children: /* @__PURE__ */ e(
869
+ xt,
870
+ {
871
+ options: It,
872
+ value: B.treatmentId,
873
+ onValueChange: Xe,
874
+ id: `${d}-treatment-select`,
875
+ disabled: it,
876
+ placeholder: l("prescription.composer.treatmentPlaceholder")
877
+ }
878
+ )
879
+ }
880
+ ),
881
+ /* @__PURE__ */ e(
882
+ me,
883
+ {
884
+ id: `${d}-prescriber`,
885
+ label: l("prescription.composer.prescriber"),
886
+ required: !0,
887
+ error: ne("prescriber"),
888
+ announceError: !K.lists("prescriber"),
889
+ children: /* @__PURE__ */ e(
890
+ xt,
891
+ {
892
+ options: Wt,
893
+ value: B.prescriberId,
894
+ onValueChange: Ue,
895
+ id: `${d}-prescriber-select`,
896
+ placeholder: l("prescription.composer.prescriberPlaceholder"),
897
+ showDescriptions: !0
898
+ }
899
+ )
900
+ }
901
+ ),
902
+ /* @__PURE__ */ e(
903
+ Xt,
904
+ {
905
+ id: `${d}-items`,
906
+ className: "ds:gap-[var(--spacing-lg)] ds:[&>legend]:[--type-label-size:var(--type-title-item-size)] ds:[&>legend]:[--type-label-weight:var(--type-title-item-weight)] ds:[&>legend]:[--type-label-line-height:var(--type-title-item-line-height)]",
907
+ legend: l("prescription.composer.medications"),
908
+ items: B.items,
909
+ min: 1,
910
+ addLabel: l("prescription.composer.addMedication"),
911
+ removeItemLabel: (r) => l("prescription.composer.removeMedication", {
912
+ number: r + 1
913
+ }),
914
+ onAdd: () => {
915
+ const r = Je();
916
+ qe({ kind: "medication", index: r });
917
+ },
918
+ onRemove: Mt,
919
+ renderItem: (r, i) => {
920
+ const c = r.medicationId ? Ee.get(r.medicationId) ?? (N == null ? void 0 : N(r.medicationId)) ?? null : null, u = `medication:${i}`, D = `dosage:${i}`, Z = `quantity:${i}`, ue = i === 0 ? ne("items") : void 0;
921
+ return /* @__PURE__ */ e(
922
+ Ar,
923
+ {
924
+ index: i,
925
+ item: r,
926
+ medication: c,
927
+ medicationFieldId: `${d}-medication-${i}`,
928
+ dosageFieldId: `${d}-dosage-${i}`,
929
+ quantityFieldId: `${d}-quantity-${i}`,
930
+ medicationError: ue ?? ne(u),
931
+ dosageError: ne(D),
932
+ quantityError: ne(Z),
933
+ announceMedicationError: !K.lists(ue ? "items" : u),
934
+ announceDosageError: !K.lists(D),
935
+ announceQuantityError: !K.lists(Z),
936
+ searchMedications: ve,
937
+ codeLabel: $,
938
+ catalogueStatus: j,
939
+ onCatalogueRetry: L,
940
+ suggestions: c && q ? q(c) : [],
941
+ onMedicationChange: (y) => {
942
+ y && ke([y]);
943
+ const at = y == null ? void 0 : y.maxPacks;
944
+ ae(i, {
945
+ medicationId: (y == null ? void 0 : y.id) ?? "",
946
+ ...at !== void 0 && r.quantity > at ? { quantity: at } : {}
947
+ });
948
+ },
949
+ onDosageChange: (y) => ae(i, { dosage: y }),
950
+ onNotesChange: (y) => ae(i, { notes: y }),
951
+ onQuantityChange: (y) => ae(i, { quantity: y }),
952
+ onDurationChange: (y) => ae(i, { duration: y }),
953
+ onNotSubstitutableChange: (y) => ae(i, { notSubstitutable: y }),
954
+ medicationSearchId: `${d}-medication-${i}-search`,
955
+ medicationRef: (y) => {
956
+ y ? et.current.set(i, y) : et.current.delete(i);
957
+ },
958
+ dosageInputRef: (y) => {
959
+ y ? tt.current.set(i, y) : tt.current.delete(i);
960
+ },
961
+ onSuggestionChosen: (y) => {
962
+ ae(i, { dosage: y }), qe({ kind: "dosage", index: i });
963
+ }
964
+ }
965
+ );
966
+ }
967
+ }
968
+ ),
969
+ Nt,
970
+ /* @__PURE__ */ e(
971
+ ze,
972
+ {
973
+ type: "submit",
974
+ loading: S,
975
+ className: "ds:self-start ds:min-h-[var(--min-target-size)]",
976
+ children: le ?? l("prescription.composer.save")
977
+ }
978
+ )
979
+ ] })
980
+ ]
981
+ }
982
+ )
983
+ ] });
984
+ });
985
+ _r.displayName = "PrescriptionComposer";
986
+ const Gr = {
987
+ sent: "success",
988
+ sending: "info",
989
+ failed: "error"
990
+ };
991
+ function Vt({
992
+ status: t
993
+ }) {
994
+ const { t: a } = xe("ui"), n = t === "sent" ? /* @__PURE__ */ e(kr, { "aria-hidden": "true" }) : t === "sending" ? /* @__PURE__ */ e(
995
+ wr,
996
+ {
997
+ "aria-hidden": "true",
998
+ className: "ds:animate-spin ds:motion-reduce:animate-none"
999
+ }
1000
+ ) : /* @__PURE__ */ e(Tr, { "aria-hidden": "true" });
1001
+ return /* @__PURE__ */ e(Sr, { size: "sm", variant: Gr[t], leading: n, children: a(t === "sent" ? "prescription.status.sent" : t === "sending" ? "prescription.status.sending" : "prescription.status.failed") });
1002
+ }
1003
+ const jr = C("ds:flex ds:flex-col ds:gap-[var(--spacing-lg)]"), Or = C("ds:flex ds:flex-col", {
1004
+ variants: {
1005
+ density: {
1006
+ default: "ds:gap-[var(--spacing-lg)]",
1007
+ compact: "ds:gap-[var(--spacing-md)]"
1008
+ }
1009
+ },
1010
+ defaultVariants: { density: "default" }
1011
+ });
1012
+ function Hr(t) {
1013
+ if (typeof globalThis.reportError == "function") {
1014
+ globalThis.reportError(t);
1015
+ return;
1016
+ }
1017
+ setTimeout(() => {
1018
+ throw t;
1019
+ }, 0);
1020
+ }
1021
+ function Kr({
1022
+ label: t,
1023
+ items: a,
1024
+ blocked: n,
1025
+ describedBy: h,
1026
+ ...m
1027
+ }) {
1028
+ const [k, g] = te(!1);
1029
+ return /* @__PURE__ */ b(
1030
+ Fe.Root,
1031
+ {
1032
+ open: k && !n,
1033
+ onOpenChange: (o) => g(o && !n),
1034
+ children: [
1035
+ /* @__PURE__ */ e(Fe.Trigger, { asChild: !0, children: /* @__PURE__ */ e(
1036
+ Et,
1037
+ {
1038
+ ...m,
1039
+ icon: /* @__PURE__ */ e(gr, { "aria-hidden": "true" }),
1040
+ "aria-label": t,
1041
+ "aria-haspopup": "menu",
1042
+ "aria-disabled": n || void 0,
1043
+ "aria-describedby": h,
1044
+ "data-action": "moreActions",
1045
+ className: "ds:min-h-[var(--min-target-size)] ds:min-w-[var(--min-target-size)]"
1046
+ }
1047
+ ) }),
1048
+ /* @__PURE__ */ e(Fe.Content, { align: "end", children: a.map((o) => /* @__PURE__ */ e(
1049
+ Fe.Item,
1050
+ {
1051
+ startIcon: o.icon,
1052
+ "data-action": o.action,
1053
+ "aria-busy": o.busy || void 0,
1054
+ onSelect: () => {
1055
+ o.busy || o.run();
1056
+ },
1057
+ children: o.label
1058
+ },
1059
+ o.action
1060
+ )) })
1061
+ ]
1062
+ }
1063
+ );
1064
+ }
1065
+ function Wr(t) {
1066
+ return typeof t == "object" && t !== null && typeof t.then == "function";
1067
+ }
1068
+ const Qr = Oe(
1069
+ ({
1070
+ record: t,
1071
+ practiceHeader: a,
1072
+ size: n = "a4",
1073
+ density: h = "default",
1074
+ codeLabel: m,
1075
+ privacyMode: k = !1,
1076
+ isolateBrowserPrint: g = !1,
1077
+ numberLabel: o,
1078
+ pinLabel: N,
1079
+ printMode: q,
1080
+ onPrint: $,
1081
+ onDownloadPdf: j,
1082
+ onSendEmail: L,
1083
+ onSendSms: W,
1084
+ onSendWhatsApp: Q,
1085
+ onResend: ie,
1086
+ onEdit: Y,
1087
+ id: P,
1088
+ className: p,
1089
+ ...fe
1090
+ }, R) => {
1091
+ const { t: f, i18n: ce } = xe("ui"), le = He(ce.language), O = T(null), se = Ne(), U = Ne(), E = Ne(), l = Ne(), X = Ne(), d = t.sendStatus, I = d === "sending" || d === "failed", z = (q ?? (d ? "host" : "sheet")) === "host", B = T(() => {
1092
+ }), w = T(z);
1093
+ w.current = z;
1094
+ const A = T(I);
1095
+ A.current = I;
1096
+ const G = T(t);
1097
+ G.current = t;
1098
+ const H = Ge(
1099
+ () => ({
1100
+ print: () => {
1101
+ var v;
1102
+ A.current || (w.current ? B.current() : (v = O.current) == null || v.print());
1103
+ },
1104
+ getRecordId: () => G.current.id,
1105
+ focusTitle: () => {
1106
+ var v;
1107
+ return (v = O.current) == null ? void 0 : v.focusTitle();
1108
+ }
1109
+ }),
1110
+ []
1111
+ );
1112
+ Pt(R, () => H, [H]);
1113
+ const [s, S] = te(() => /* @__PURE__ */ new Set()), _ = T(/* @__PURE__ */ new Set()), he = T(!0);
1114
+ Pe(() => (he.current = !0, () => {
1115
+ he.current = !1;
1116
+ }), []);
1117
+ const F = M(
1118
+ (v, ve) => {
1119
+ if (!ve || _.current.has(v) || A.current && v !== "resend" && v !== "edit")
1120
+ return;
1121
+ let ye;
1122
+ try {
1123
+ ye = ve(G.current);
1124
+ } catch (Qe) {
1125
+ Hr(Qe);
1126
+ return;
1127
+ }
1128
+ if (!Wr(ye)) return;
1129
+ _.current.add(v), S(new Set(_.current));
1130
+ const we = () => {
1131
+ _.current.delete(v), he.current && S(new Set(_.current));
1132
+ };
1133
+ ye.then(we, we);
1134
+ },
1135
+ []
1136
+ ), Ke = M(() => {
1137
+ var v;
1138
+ _.current.has("print") || (z || (v = O.current) == null || v.print(), F("print", $));
1139
+ }, [F, $, z]);
1140
+ B.current = () => F("print", $);
1141
+ const We = [
1142
+ $ && {
1143
+ action: "print",
1144
+ label: f("prescription.sheet.print"),
1145
+ icon: /* @__PURE__ */ e(At, { "aria-hidden": "true" }),
1146
+ run: Ke
1147
+ },
1148
+ j && {
1149
+ action: "downloadPdf",
1150
+ label: f("prescription.sheet.downloadPdf"),
1151
+ icon: /* @__PURE__ */ e(fr, { "aria-hidden": "true" }),
1152
+ run: () => F("downloadPdf", j)
1153
+ },
1154
+ L && {
1155
+ action: "sendEmail",
1156
+ label: f("prescription.sheet.sendEmail"),
1157
+ icon: /* @__PURE__ */ e(hr, { "aria-hidden": "true" }),
1158
+ run: () => F("sendEmail", L)
1159
+ },
1160
+ W && {
1161
+ action: "sendSms",
1162
+ label: f("prescription.sheet.sendSms"),
1163
+ icon: /* @__PURE__ */ e(br, { "aria-hidden": "true" }),
1164
+ run: () => F("sendSms", W)
1165
+ },
1166
+ Q && {
1167
+ action: "sendWhatsApp",
1168
+ label: f("prescription.sheet.sendWhatsApp"),
1169
+ icon: /* @__PURE__ */ e(mr, {}),
1170
+ run: () => F("sendWhatsApp", Q)
1171
+ }
1172
+ ].filter((v) => !!v), Ee = I ? "outline" : "primary", [J, ...Se] = We, be = J ? /* @__PURE__ */ e(
1173
+ ze,
1174
+ {
1175
+ type: "button",
1176
+ intent: Ee,
1177
+ startIcon: J.icon,
1178
+ loading: s.has(J.action),
1179
+ "aria-disabled": I || void 0,
1180
+ "aria-describedby": [
1181
+ I ? l : void 0,
1182
+ z && J.action === "print" ? X : void 0
1183
+ ].filter(Boolean).join(" ") || void 0,
1184
+ onClick: I ? void 0 : J.run,
1185
+ "data-action": J.action,
1186
+ className: "ds:min-h-[var(--min-target-size)]",
1187
+ children: J.label
1188
+ }
1189
+ ) : null, de = J && Se.length > 0 ? /* @__PURE__ */ b(
1190
+ cr,
1191
+ {
1192
+ label: f("prescription.sheet.shareActions"),
1193
+ intent: Ee,
1194
+ separator: !I,
1195
+ children: [
1196
+ be,
1197
+ /* @__PURE__ */ e(
1198
+ Kr,
1199
+ {
1200
+ blocked: I,
1201
+ describedBy: I ? l : void 0,
1202
+ label: f("prescription.sheet.moreActions"),
1203
+ items: Se.map((v) => ({
1204
+ ...v,
1205
+ busy: s.has(v.action)
1206
+ }))
1207
+ }
1208
+ )
1209
+ ]
1210
+ }
1211
+ ) : be, ke = de !== null;
1212
+ return /* @__PURE__ */ b(
1213
+ "div",
1214
+ {
1215
+ ...fe,
1216
+ id: P,
1217
+ className: jr({ className: p }),
1218
+ "data-component": "prescription-sheet",
1219
+ "data-component-id": P,
1220
+ "data-prescription-id": t.id,
1221
+ children: [
1222
+ d ? /* @__PURE__ */ e(
1223
+ "div",
1224
+ {
1225
+ id: l,
1226
+ "data-slot": "send-status",
1227
+ "data-send-status": d,
1228
+ className: "ds:mx-auto ds:flex ds:w-full ds:max-w-3xl ds:justify-center ds:print:hidden",
1229
+ children: d === "sent" ? /* @__PURE__ */ b("p", { className: "ds:m-0 ds:flex ds:flex-wrap ds:items-center ds:justify-center ds:gap-[var(--spacing-sm)] type-body-sm", children: [
1230
+ /* @__PURE__ */ e(Vt, { status: "sent" }),
1231
+ t.sentAt ? /* @__PURE__ */ b("span", { children: [
1232
+ f("prescription.sheet.sentAt"),
1233
+ " ",
1234
+ /* @__PURE__ */ e(
1235
+ or,
1236
+ {
1237
+ locale: le,
1238
+ value: t.sentAt,
1239
+ format: "absolute",
1240
+ shape: "bare",
1241
+ absoluteFormat: {
1242
+ dateStyle: "medium",
1243
+ timeStyle: "short"
1244
+ }
1245
+ }
1246
+ )
1247
+ ] }) : null
1248
+ ] }) : d === "sending" ? /* @__PURE__ */ e(ge, { variant: "info", announce: "polite", className: "ds:w-full", children: /* @__PURE__ */ e(ge.Title, { as: "p", children: f("prescription.sheet.sendingTitle") }) }) : /* @__PURE__ */ b(ge, { variant: "error", className: "ds:w-full", children: [
1249
+ /* @__PURE__ */ e(ge.Title, { as: "p", children: f("prescription.sheet.sendFailedTitle") }),
1250
+ /* @__PURE__ */ e(ge.Description, { children: t.sendError ?? f("prescription.sheet.sendFailedBody") }),
1251
+ ie || Y ? /* @__PURE__ */ b(
1252
+ "div",
1253
+ {
1254
+ "data-slot": "failed-actions",
1255
+ className: "ds:mt-[var(--spacing-sm)] ds:flex ds:flex-wrap ds:items-center ds:gap-[var(--spacing-sm)]",
1256
+ children: [
1257
+ ie ? /* @__PURE__ */ e(
1258
+ ze,
1259
+ {
1260
+ type: "button",
1261
+ intent: "primary",
1262
+ loading: s.has("resend"),
1263
+ onClick: () => F("resend", ie),
1264
+ "data-action": "resend",
1265
+ className: "ds:min-h-[var(--min-target-size)]",
1266
+ children: f("prescription.sheet.resend")
1267
+ }
1268
+ ) : null,
1269
+ Y ? /* @__PURE__ */ e(
1270
+ ze,
1271
+ {
1272
+ type: "button",
1273
+ intent: "secondary",
1274
+ loading: s.has("edit"),
1275
+ onClick: () => F("edit", Y),
1276
+ "data-action": "edit",
1277
+ className: "ds:min-h-[var(--min-target-size)]",
1278
+ children: f("prescription.sheet.edit")
1279
+ }
1280
+ ) : null
1281
+ ]
1282
+ }
1283
+ ) : null
1284
+ ] })
1285
+ }
1286
+ ) : null,
1287
+ ke ? /* @__PURE__ */ e(
1288
+ "div",
1289
+ {
1290
+ role: "group",
1291
+ "aria-label": f("prescription.sheet.actions"),
1292
+ "data-slot": "actions",
1293
+ className: "ds:flex ds:flex-wrap ds:items-center ds:justify-center ds:gap-[var(--spacing-sm)] ds:print:hidden",
1294
+ children: de
1295
+ }
1296
+ ) : null,
1297
+ z ? (
1298
+ /* Not print:hidden: when the page itself is printed (Ctrl or Cmd+P),
1299
+ the summary prints with its note, right above the sheet. */
1300
+ /* @__PURE__ */ e(
1301
+ "p",
1302
+ {
1303
+ id: X,
1304
+ "data-slot": "summary-note",
1305
+ className: "ds:m-0 ds:text-center type-body-sm ds:text-[color:var(--muted-foreground)]",
1306
+ children: f("prescription.sheet.summaryNote")
1307
+ }
1308
+ )
1309
+ ) : null,
1310
+ /* @__PURE__ */ e(
1311
+ ur,
1312
+ {
1313
+ ref: O,
1314
+ registerAgent: !1,
1315
+ id: P ? `${P}-sheet` : void 0,
1316
+ size: n,
1317
+ density: h,
1318
+ isolateBrowserPrint: z ? !1 : g,
1319
+ header: a,
1320
+ title: f("prescription.sheet.title"),
1321
+ date: t.createdAt,
1322
+ signature: {
1323
+ name: t.prescriber.name,
1324
+ detail: t.prescriber.specialty
1325
+ },
1326
+ children: /* @__PURE__ */ b("div", { className: Or({ density: h }), children: [
1327
+ /* @__PURE__ */ b(St, { children: [
1328
+ t.number ? /* @__PURE__ */ e(
1329
+ oe,
1330
+ {
1331
+ label: o ?? f("prescription.sheet.number"),
1332
+ value: /* @__PURE__ */ e("span", { dir: "ltr", children: t.number }),
1333
+ mono: !0,
1334
+ "data-field": "number"
1335
+ }
1336
+ ) : null,
1337
+ t.pin ? /* @__PURE__ */ e(
1338
+ oe,
1339
+ {
1340
+ label: N ?? f("prescription.sheet.pin"),
1341
+ value: k ? /* @__PURE__ */ b(_e, { children: [
1342
+ /* @__PURE__ */ e(dt, { children: f("calendarWorkspace.privacy.hidden") }),
1343
+ /* @__PURE__ */ e("span", { "aria-hidden": "true", children: lt() })
1344
+ ] }) : /* @__PURE__ */ e("span", { dir: "ltr", children: t.pin }),
1345
+ mono: !0,
1346
+ "data-field": "pin"
1347
+ }
1348
+ ) : null,
1349
+ /* @__PURE__ */ e(
1350
+ oe,
1351
+ {
1352
+ label: f("prescription.sheet.treatment"),
1353
+ value: /* @__PURE__ */ e("span", { dir: "auto", children: t.treatment.label }),
1354
+ "data-field": "treatment"
1355
+ }
1356
+ ),
1357
+ t.treatment.carePlan ? /* @__PURE__ */ e(
1358
+ oe,
1359
+ {
1360
+ label: f("prescription.sheet.carePlan"),
1361
+ value: /* @__PURE__ */ e("span", { dir: "auto", children: t.treatment.carePlan.label }),
1362
+ "data-field": "carePlan"
1363
+ }
1364
+ ) : null
1365
+ ] }),
1366
+ /* @__PURE__ */ b(
1367
+ "section",
1368
+ {
1369
+ "aria-labelledby": se,
1370
+ className: "ds:flex ds:flex-col ds:gap-[var(--spacing-sm)]",
1371
+ children: [
1372
+ /* @__PURE__ */ e(
1373
+ "h3",
1374
+ {
1375
+ id: se,
1376
+ className: "ds:m-0 type-title-item ds:break-after-avoid",
1377
+ children: f("prescription.sheet.patient")
1378
+ }
1379
+ ),
1380
+ /* @__PURE__ */ e(
1381
+ pt,
1382
+ {
1383
+ patient: t.patient,
1384
+ privacyMode: k,
1385
+ density: h
1386
+ }
1387
+ )
1388
+ ]
1389
+ }
1390
+ ),
1391
+ /* @__PURE__ */ b(
1392
+ "section",
1393
+ {
1394
+ "aria-labelledby": U,
1395
+ className: "ds:flex ds:flex-col ds:gap-[var(--spacing-sm)]",
1396
+ children: [
1397
+ /* @__PURE__ */ e(
1398
+ "h3",
1399
+ {
1400
+ id: U,
1401
+ className: "ds:m-0 type-title-item ds:break-after-avoid",
1402
+ children: f("prescription.sheet.medications")
1403
+ }
1404
+ ),
1405
+ /* @__PURE__ */ e(
1406
+ dr,
1407
+ {
1408
+ density: h,
1409
+ "aria-labelledby": U,
1410
+ children: t.items.map((v, ve) => /* @__PURE__ */ e(
1411
+ pr,
1412
+ {
1413
+ as: "li",
1414
+ medication: v.medication,
1415
+ dosage: v.dosage,
1416
+ notes: v.notes,
1417
+ quantity: v.quantity,
1418
+ duration: v.duration,
1419
+ notSubstitutable: v.notSubstitutable,
1420
+ codeLabel: m
1421
+ },
1422
+ `${v.medication.id}-${ve}`
1423
+ ))
1424
+ }
1425
+ )
1426
+ ]
1427
+ }
1428
+ ),
1429
+ /* @__PURE__ */ b(
1430
+ "section",
1431
+ {
1432
+ "aria-labelledby": E,
1433
+ className: "ds:flex ds:flex-col ds:gap-[var(--spacing-sm)]",
1434
+ children: [
1435
+ /* @__PURE__ */ e(
1436
+ "h3",
1437
+ {
1438
+ id: E,
1439
+ className: "ds:m-0 type-title-item ds:break-after-avoid",
1440
+ children: f("prescription.sheet.prescriber")
1441
+ }
1442
+ ),
1443
+ /* @__PURE__ */ b(St, { children: [
1444
+ /* @__PURE__ */ e(
1445
+ oe,
1446
+ {
1447
+ label: f("prescription.sheet.prescriberName"),
1448
+ value: /* @__PURE__ */ e("span", { dir: "auto", children: t.prescriber.name }),
1449
+ "data-field": "prescriber"
1450
+ }
1451
+ ),
1452
+ t.prescriber.specialty ? /* @__PURE__ */ e(
1453
+ oe,
1454
+ {
1455
+ label: f("prescription.history.specialty"),
1456
+ value: /* @__PURE__ */ e("span", { dir: "auto", children: t.prescriber.specialty }),
1457
+ "data-field": "specialty"
1458
+ }
1459
+ ) : null,
1460
+ t.prescriber.fiscalCode ? /* @__PURE__ */ e(
1461
+ oe,
1462
+ {
1463
+ label: f("prescription.sheet.prescriberFiscalCode"),
1464
+ value: /* @__PURE__ */ e("span", { dir: "ltr", children: t.prescriber.fiscalCode }),
1465
+ mono: !0,
1466
+ "data-field": "prescriberFiscalCode"
1467
+ }
1468
+ ) : null,
1469
+ t.prescriber.registrationNumber ? /* @__PURE__ */ e(
1470
+ oe,
1471
+ {
1472
+ label: f("prescription.sheet.registrationNumber"),
1473
+ value: /* @__PURE__ */ e("span", { dir: "ltr", children: t.prescriber.registrationNumber }),
1474
+ mono: !0,
1475
+ "data-field": "registrationNumber"
1476
+ }
1477
+ ) : null
1478
+ ] })
1479
+ ]
1480
+ }
1481
+ )
1482
+ ] })
1483
+ }
1484
+ )
1485
+ ]
1486
+ }
1487
+ );
1488
+ }
1489
+ );
1490
+ Qr.displayName = "PrescriptionSheet";
1491
+ const Yr = C("ds:block ds:min-w-0 ds:w-full"), Ur = C(
1492
+ "ds:flex ds:flex-col ds:gap-[var(--spacing-sm)] ds:pb-[var(--spacing-md)]"
1493
+ ), Xr = C(
1494
+ "ds:flex ds:flex-wrap ds:items-center ds:justify-between ds:gap-[var(--spacing-md)]"
1495
+ ), Jr = C(
1496
+ "ds:flex ds:min-w-0 ds:flex-col ds:gap-[var(--spacing-xs)]"
1497
+ ), Zr = C(
1498
+ "ds:m-0 ds:text-start ds:text-[color:var(--foreground)] ds:focus:outline-none",
1499
+ {
1500
+ variants: {
1501
+ level: { page: "type-title-page", section: "type-title-section" }
1502
+ }
1503
+ }
1504
+ ), ei = C(
1505
+ "type-body-sm ds:m-0 ds:text-start ds:text-[color:var(--muted-foreground)]"
1506
+ ), ti = C(
1507
+ "ds:flex ds:min-w-0 ds:max-w-full ds:flex-wrap ds:items-center ds:gap-[var(--spacing-sm)]"
1508
+ ), ri = C("ds:w-[16rem] ds:max-w-full ds:min-w-0"), ii = C(
1509
+ "ds:inline-flex ds:min-w-0 ds:items-center ds:gap-[var(--spacing-xs)]"
1510
+ ), Be = C("ds:min-w-0 ds:break-words"), si = C("ds:flex ds:flex-wrap ds:gap-[var(--spacing-2xs)]"), ai = "11rem", ni = C(
1511
+ "ds:min-w-0 ds:break-words ds:text-[color:var(--muted-foreground)]"
1512
+ ), oi = C("ds:font-mono ds:tabular-nums"), ci = [
1513
+ { colId: "date", sort: "desc" }
1514
+ ], li = {
1515
+ dateStyle: "medium",
1516
+ timeStyle: "short"
1517
+ };
1518
+ function $t(t, a) {
1519
+ const n = new Date(t.createdAt);
1520
+ return Number.isNaN(n.getTime()) ? t.createdAt : new Intl.DateTimeFormat(He(a), li).format(
1521
+ n
1522
+ );
1523
+ }
1524
+ function Ct({ name: t }) {
1525
+ return /* @__PURE__ */ b("span", { className: ii(), children: [
1526
+ /* @__PURE__ */ e(
1527
+ qt,
1528
+ {
1529
+ name: t,
1530
+ size: "xs",
1531
+ className: "ds:shrink-0",
1532
+ "aria-hidden": "true",
1533
+ role: "presentation",
1534
+ "aria-label": void 0
1535
+ }
1536
+ ),
1537
+ /* @__PURE__ */ e("span", { dir: "auto", className: Be(), children: t })
1538
+ ] });
1539
+ }
1540
+ const as = Oe(function({
1541
+ records: a,
1542
+ status: n = "ready",
1543
+ onOpen: h,
1544
+ onReprint: m,
1545
+ onRetry: k,
1546
+ caption: g,
1547
+ showPatient: o = !1,
1548
+ privacyMode: N = !1,
1549
+ showSendStatus: q,
1550
+ heading: $,
1551
+ headingLevel: j = 2,
1552
+ description: L,
1553
+ newAction: W,
1554
+ id: Q,
1555
+ className: ie,
1556
+ ...Y
1557
+ }, P) {
1558
+ const { t: p, i18n: fe } = xe("ui"), R = fe.language || "en", f = h !== void 0 || m !== void 0, ce = q ?? a.some((d) => d.sendStatus !== void 0), le = Ge(() => {
1559
+ const d = [];
1560
+ return h && d.push({
1561
+ id: "open",
1562
+ icon: /* @__PURE__ */ e($r, {}),
1563
+ label: p("prescription.history.open"),
1564
+ onClick: h
1565
+ }), m && d.push({
1566
+ id: "reprint",
1567
+ icon: /* @__PURE__ */ e(At, {}),
1568
+ label: p("prescription.history.reprint"),
1569
+ onClick: m
1570
+ }), d;
1571
+ }, [p, h, m]), O = Ge(() => {
1572
+ const d = new Intl.Collator(He(R)), I = (s) => $t(s, R), x = (s) => `${s.patient.lastName} ${s.patient.firstName}`.trim(), z = (s) => p(s === "sent" ? "prescription.status.sent" : s === "sending" ? "prescription.status.sending" : "prescription.status.failed"), B = /* @__PURE__ */ e("span", { className: ni(), children: p("prescription.history.noCarePlan") }), w = 3, A = 2, G = o ? 2 : 1, H = [
1573
+ {
1574
+ id: "date",
1575
+ header: p("prescription.history.date"),
1576
+ headerLabel: p("prescription.history.date"),
1577
+ rowHeader: !0,
1578
+ sort: "date",
1579
+ sortDescFirst: !0,
1580
+ value: (s) => new Date(s.createdAt),
1581
+ exportValue: I,
1582
+ filter: { kind: "dateRange" },
1583
+ search: !1,
1584
+ size: 124,
1585
+ wrap: !0,
1586
+ cell: (s) => /* @__PURE__ */ e("time", { dateTime: s.createdAt, children: I(s) })
1587
+ }
1588
+ ];
1589
+ if (ce && (H.push({
1590
+ id: "number",
1591
+ header: p("prescription.history.number"),
1592
+ headerLabel: p("prescription.history.number"),
1593
+ responsiveTier: A,
1594
+ sort: "text",
1595
+ value: (s) => s.number ?? null,
1596
+ exportValue: (s) => s.number ?? "",
1597
+ filter: { kind: "text" },
1598
+ size: 124,
1599
+ cell: (s) => s.number ? /* @__PURE__ */ e("span", { dir: "ltr", className: oi(), children: s.number }) : null
1600
+ }), H.push({
1601
+ id: "status",
1602
+ header: p("prescription.history.status"),
1603
+ headerLabel: p("prescription.history.status"),
1604
+ responsiveTier: G,
1605
+ sort: "text",
1606
+ value: (s) => s.sendStatus ?? null,
1607
+ exportValue: (s) => s.sendStatus ? z(s.sendStatus) : "",
1608
+ filter: {
1609
+ kind: "select",
1610
+ options: ["sent", "sending", "failed"].map((s) => ({
1611
+ value: s,
1612
+ label: z(s)
1613
+ }))
1614
+ },
1615
+ search: !1,
1616
+ size: 108,
1617
+ cell: (s) => s.sendStatus ? /* @__PURE__ */ e(Vt, { status: s.sendStatus }) : null
1618
+ })), o && H.push({
1619
+ id: "patient",
1620
+ header: p("prescription.history.patient"),
1621
+ headerLabel: p("prescription.history.patient"),
1622
+ responsiveTier: 1,
1623
+ wrap: !0,
1624
+ privacy: "mask",
1625
+ sort: (s, S) => d.compare(x(s), x(S)),
1626
+ value: x,
1627
+ exportValue: x,
1628
+ filter: { kind: "text" },
1629
+ size: 144,
1630
+ cell: (s) => /* @__PURE__ */ e(Ct, { name: x(s) })
1631
+ }), H.push(
1632
+ {
1633
+ id: "treatment",
1634
+ header: p("prescription.history.treatment"),
1635
+ headerLabel: p("prescription.history.treatment"),
1636
+ responsiveTier: w,
1637
+ wrap: !0,
1638
+ sort: "text",
1639
+ value: (s) => s.treatment.label,
1640
+ exportValue: (s) => s.treatment.label,
1641
+ filter: { kind: "text" },
1642
+ size: 136,
1643
+ cell: (s) => /* @__PURE__ */ e("span", { dir: "auto", className: Be(), children: s.treatment.label })
1644
+ },
1645
+ {
1646
+ id: "carePlan",
1647
+ header: p("prescription.history.carePlan"),
1648
+ headerLabel: p("prescription.history.carePlan"),
1649
+ responsiveTier: w,
1650
+ wrap: !0,
1651
+ sort: "text",
1652
+ value: (s) => {
1653
+ var S;
1654
+ return ((S = s.treatment.carePlan) == null ? void 0 : S.label) ?? null;
1655
+ },
1656
+ exportValue: (s) => {
1657
+ var S;
1658
+ return ((S = s.treatment.carePlan) == null ? void 0 : S.label) ?? "";
1659
+ },
1660
+ filter: { kind: "select" },
1661
+ size: 128,
1662
+ cell: (s) => s.treatment.carePlan ? /* @__PURE__ */ e("span", { dir: "auto", className: Be(), children: s.treatment.carePlan.label }) : B
1663
+ },
1664
+ {
1665
+ id: "medications",
1666
+ header: p("prescription.history.medications"),
1667
+ headerLabel: p("prescription.history.medications"),
1668
+ wrap: !0,
1669
+ value: (s) => s.items.map((S) => S.medication.name).join("; "),
1670
+ exportValue: (s) => s.items.map((S) => S.medication.name).join("; "),
1671
+ /* The grid's filters read one scalar per row, so the drug filter is
1672
+ a text "contains" on the names, not a list of drugs. */
1673
+ filter: { kind: "text" },
1674
+ size: 216,
1675
+ cell: (s) => /* @__PURE__ */ e("span", { className: si(), children: s.items.map((S, _) => /* @__PURE__ */ e(
1676
+ yr,
1677
+ {
1678
+ label: S.medication.name,
1679
+ size: "sm",
1680
+ variant: "neutral",
1681
+ maxInlineSize: ai
1682
+ },
1683
+ `${S.medication.id}-${_}`
1684
+ )) })
1685
+ },
1686
+ {
1687
+ id: "prescriber",
1688
+ header: p("prescription.history.prescriber"),
1689
+ headerLabel: p("prescription.history.prescriber"),
1690
+ responsiveTier: o ? w : A,
1691
+ wrap: !0,
1692
+ sort: "text",
1693
+ value: (s) => s.prescriber.name,
1694
+ exportValue: (s) => s.prescriber.name,
1695
+ filter: { kind: "select" },
1696
+ search: !0,
1697
+ size: 136,
1698
+ cell: (s) => /* @__PURE__ */ e(Ct, { name: s.prescriber.name })
1699
+ },
1700
+ {
1701
+ id: "specialty",
1702
+ header: p("prescription.history.specialty"),
1703
+ headerLabel: p("prescription.history.specialty"),
1704
+ defaultHidden: !0,
1705
+ wrap: !0,
1706
+ sort: "text",
1707
+ value: (s) => s.prescriber.specialty ?? null,
1708
+ exportValue: (s) => s.prescriber.specialty ?? "",
1709
+ filter: { kind: "select" },
1710
+ size: 140,
1711
+ cell: (s) => s.prescriber.specialty ? /* @__PURE__ */ e("span", { dir: "auto", className: Be(), children: s.prescriber.specialty }) : null
1712
+ }
1713
+ ), f) {
1714
+ const s = p("prescription.history.actions");
1715
+ H.push({
1716
+ id: "actions",
1717
+ header: /* @__PURE__ */ e(dt, { children: s }),
1718
+ headerLabel: s,
1719
+ pin: "end",
1720
+ size: 64,
1721
+ hideable: !1,
1722
+ reorderable: !1,
1723
+ pinnable: !1,
1724
+ resizable: !1,
1725
+ exportable: !1,
1726
+ printable: !1,
1727
+ search: !1,
1728
+ /* The kit RowActions leaf, menu only: one "Actions" button per row,
1729
+ named by reference with the row's own name. */
1730
+ cell: (S, _) => /* @__PURE__ */ e(
1731
+ Ir,
1732
+ {
1733
+ row: S,
1734
+ actions: le,
1735
+ maxInline: 0,
1736
+ "aria-labelledby": _.inputLabelledBy
1737
+ }
1738
+ )
1739
+ });
1740
+ }
1741
+ return H;
1742
+ }, [p, R, f, o, ce, le]), se = T(null), U = /* @__PURE__ */ b(
1743
+ vr,
1744
+ {
1745
+ role: "toolbar",
1746
+ "aria-label": p("dataTable.tableActions"),
1747
+ className: "ds:bg-[var(--background)]",
1748
+ children: [
1749
+ W ? /* @__PURE__ */ e(
1750
+ Et,
1751
+ {
1752
+ intent: "primary",
1753
+ icon: /* @__PURE__ */ e(Cr, { "aria-hidden": "true" }),
1754
+ tooltip: W.label,
1755
+ "data-action": "new",
1756
+ onClick: W.onClick
1757
+ }
1758
+ ) : null,
1759
+ /* @__PURE__ */ e(ee.ExportMenu, {}),
1760
+ /* @__PURE__ */ e(ee.Print, {}),
1761
+ /* @__PURE__ */ e(ee.ColumnToggle, {})
1762
+ ]
1763
+ }
1764
+ ), E = /* @__PURE__ */ b(ee, { children: [
1765
+ /* @__PURE__ */ b(ee.FilterBar, { children: [
1766
+ /* @__PURE__ */ e(ee.QuickSearch, {}),
1767
+ /* @__PURE__ */ e(ee.FilterChips, {})
1768
+ ] }),
1769
+ /* @__PURE__ */ e(ee.Actions, { children: U })
1770
+ ] }), l = j === 1 ? "h1" : "h2", X = $ ? /* @__PURE__ */ e(xr, { getGrid: () => se.current, children: /* @__PURE__ */ b("div", { className: Ur(), children: [
1771
+ /* @__PURE__ */ b("div", { className: Xr(), children: [
1772
+ /* @__PURE__ */ b("div", { className: Jr(), children: [
1773
+ /* @__PURE__ */ e(
1774
+ l,
1775
+ {
1776
+ tabIndex: -1,
1777
+ className: Zr({
1778
+ level: j === 1 ? "page" : "section"
1779
+ }),
1780
+ children: $
1781
+ }
1782
+ ),
1783
+ L ? /* @__PURE__ */ e("p", { className: ei(), children: L }) : null
1784
+ ] }),
1785
+ /* @__PURE__ */ b("div", { className: ti(), children: [
1786
+ /* @__PURE__ */ e("div", { className: ri(), children: /* @__PURE__ */ e(ee.QuickSearch, {}) }),
1787
+ U
1788
+ ] })
1789
+ ] }),
1790
+ /* @__PURE__ */ e(ee.FilterChips, {})
1791
+ ] }) }) : null;
1792
+ return /* @__PURE__ */ b(
1793
+ "div",
1794
+ {
1795
+ ...Y,
1796
+ ref: P,
1797
+ "data-component": "prescription-history",
1798
+ "data-component-id": Q,
1799
+ className: Yr({ className: ie }),
1800
+ children: [
1801
+ X,
1802
+ /* @__PURE__ */ e(
1803
+ Nr,
1804
+ {
1805
+ ref: se,
1806
+ columns: O,
1807
+ rows: a,
1808
+ getRowId: (d) => d.id,
1809
+ getRowLabel: (d) => {
1810
+ const I = p("prescription.history.rowLabel", {
1811
+ date: $t(d, R)
1812
+ });
1813
+ return o ? `${I}, ${d.patient.lastName} ${d.patient.firstName}` : I;
1814
+ },
1815
+ privacyMode: N,
1816
+ toolbar: X ? void 0 : E,
1817
+ caption: g ?? p("prescription.history.caption"),
1818
+ defaultSorting: ci,
1819
+ status: n,
1820
+ gridId: Q ? `${Q}-grid` : void 0,
1821
+ empty: {
1822
+ title: p("prescription.history.emptyTitle"),
1823
+ description: p("prescription.history.emptyBody")
1824
+ },
1825
+ error: {
1826
+ title: p("prescription.history.errorTitle"),
1827
+ onRetry: k
1828
+ }
1829
+ }
1830
+ )
1831
+ ]
1832
+ }
1833
+ );
1834
+ });
1835
+ export {
1836
+ je as E,
1837
+ _r as P,
1838
+ as as a,
1839
+ Qr as b,
1840
+ Dr as c,
1841
+ wt as d,
1842
+ ct as i,
1843
+ zr as n,
1844
+ kt as v
1845
+ };
1846
+ //# sourceMappingURL=prescription-history-CQuJmd4H.js.map