@declarion/react 0.39.0 → 0.40.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.
@@ -0,0 +1,1802 @@
1
+ import { s as e, t } from "./DynamicIcon-DeRpAaXm.js";
2
+ import { A as n, C as r, Cn as i, D as a, Dn as o, F as s, Fn as c, Jn as l, L as u, Mt as d, N as f, Q as p, Sn as m, Tn as h, Tt as g, Z as _, _ as v, _t as y, ar as b, at as ee, bn as x, dn as S, er as C, et as w, ft as te, i as T, j as E, jt as ne, kn as re, mt as ie, or as ae, sr as D, tt as oe, wn as se, wt as ce, xn as le, xt as O } from "./useCurrentScreen-mw8TfE8q.js";
3
+ import { E as ue, L as k, R as A, V as j, _ as M, b as de, c as fe, d as pe, f as me, m as he, n as ge, o as _e, r as ve, t as ye, w as be } from "./RefreshControl-VQf34HKZ.js";
4
+ import { E as xe, F as Se, G as Ce, I as we, J as Te, K as Ee, M as De, O as Oe, U as ke, W as Ae, Y as je, _ as Me, a as Ne, i as Pe, it as Fe, j as Ie, k as Le, mt as Re, q as ze, s as Be, ut as Ve, w as He } from "./registry-DFtAh6zc.js";
5
+ import { n as Ue, r as We, t as Ge } from "./dataTableStyles-vwD1mVOP.js";
6
+ import { n as Ke, t as qe } from "./LayoutRenderer-D4oTfZhV.js";
7
+ import { Fragment as N, useCallback as P, useEffect as F, useMemo as I, useRef as Je, useState as L } from "react";
8
+ import { useLocation as Ye, useParams as Xe, useSearchParams as Ze } from "react-router-dom";
9
+ import { useQuery as R, useQueryClient as z } from "@tanstack/react-query";
10
+ import { Fragment as Qe, jsx as B, jsxs as V } from "react/jsx-runtime";
11
+ //#region src/components/shared/AssociationTabs.tsx
12
+ function $e({ entityCode: e, recordId: n, associations: r, schema: i }) {
13
+ let a = I(() => Object.entries(r), [r]), [o, s] = L(0);
14
+ if (a.length === 0) return null;
15
+ let [c, l] = a[o];
16
+ return /* @__PURE__ */ B(Re, {
17
+ title: /* @__PURE__ */ B("div", {
18
+ style: {
19
+ display: "flex",
20
+ alignItems: "center",
21
+ gap: 4,
22
+ borderBottom: "1px solid var(--divider)",
23
+ margin: "-10px -14px 0 -14px",
24
+ padding: "0 14px"
25
+ },
26
+ children: a.map(([e, n], r) => {
27
+ let i = r === o;
28
+ return /* @__PURE__ */ V("button", {
29
+ onClick: (e) => {
30
+ e.stopPropagation(), s(r);
31
+ },
32
+ style: {
33
+ display: "inline-flex",
34
+ alignItems: "center",
35
+ gap: 6,
36
+ padding: "10px 12px",
37
+ fontSize: 12.5,
38
+ background: "transparent",
39
+ border: 0,
40
+ borderBottom: `2px solid ${i ? "var(--accent)" : "transparent"}`,
41
+ marginBottom: -1,
42
+ color: i ? "var(--text)" : "var(--text-3)",
43
+ cursor: "pointer",
44
+ fontWeight: i ? 600 : 500
45
+ },
46
+ children: [n.display?.icon && /* @__PURE__ */ B(t, {
47
+ name: n.display.icon,
48
+ size: 13
49
+ }), h(n.display?.name) || e]
50
+ }, e);
51
+ })
52
+ }),
53
+ collapsible: !1,
54
+ padding: "0",
55
+ children: /* @__PURE__ */ B(et, {
56
+ entityCode: e,
57
+ recordId: n,
58
+ assocKey: c,
59
+ association: l,
60
+ schema: i
61
+ })
62
+ });
63
+ }
64
+ function et({ entityCode: t, recordId: i, assocKey: a, association: o, schema: s }) {
65
+ let c = Fe(), l = n(), u = `${t}.${a}`, { data: d, isLoading: f } = R({
66
+ queryKey: [
67
+ "association",
68
+ u,
69
+ i
70
+ ],
71
+ queryFn: () => g(u, [i])
72
+ }), p = d?.target_entity ?? o.target, _ = s.entities[p], v = I(() => d?.ids ?? [], [d?.ids]), y = I(() => _?.fields.names().find((e) => _.fields.get(e)?.primary) ?? "id", [_]), b = I(() => v.slice(0, 50), [v]), { data: ee, isLoading: x } = R({
73
+ queryKey: [
74
+ "association-records",
75
+ p,
76
+ b
77
+ ],
78
+ queryFn: () => ce(p, {
79
+ per_page: 50,
80
+ filters: [{
81
+ field: y,
82
+ op: "in",
83
+ value: b
84
+ }]
85
+ }),
86
+ enabled: b.length > 0 && !!_
87
+ }), S = ee?.data ?? [], C = ee?.$refs, w = I(() => _ ? _.fields.names().filter((e) => {
88
+ let t = _.fields.get(e);
89
+ return t && !t.primary && !t.auto && t.display?.is_listable !== !1;
90
+ }).slice(0, 6) : [], [_]), te = () => {
91
+ let e = r(s, p);
92
+ if (!e) return;
93
+ let t = h(o.display?.name) || a, n = new URLSearchParams();
94
+ n.set("filters", JSON.stringify([{
95
+ field: y,
96
+ op: "in",
97
+ value: v
98
+ }])), c(e.route, {
99
+ title: t,
100
+ icon: o.display?.icon || e.icon,
101
+ search: n.toString()
102
+ });
103
+ }, T = {
104
+ fontSize: 12.5,
105
+ color: "var(--text-3)",
106
+ padding: "14px 16px"
107
+ };
108
+ if (f || x) return /* @__PURE__ */ B("div", {
109
+ style: T,
110
+ children: "Loading…"
111
+ });
112
+ if (!_) return /* @__PURE__ */ B("div", {
113
+ style: T,
114
+ children: "Entity not found."
115
+ });
116
+ if (v.length === 0) return /* @__PURE__ */ B("div", {
117
+ style: T,
118
+ children: "No related records."
119
+ });
120
+ let ne = r(s, p);
121
+ return /* @__PURE__ */ V("div", {
122
+ style: { padding: "8px 0" },
123
+ children: [
124
+ /* @__PURE__ */ V("table", {
125
+ style: We,
126
+ children: [/* @__PURE__ */ B("thead", { children: /* @__PURE__ */ B("tr", { children: w.map((e) => /* @__PURE__ */ B("th", {
127
+ style: Ue,
128
+ children: m(_.fields.get(e), e, s.entities)
129
+ }, e)) }) }), /* @__PURE__ */ B("tbody", { children: S.map((e, t) => /* @__PURE__ */ B("tr", { children: w.map((t) => {
130
+ let n = _.fields.get(t);
131
+ return n ? /* @__PURE__ */ B("td", {
132
+ style: Ge,
133
+ children: E({
134
+ field: n,
135
+ fieldName: t,
136
+ value: e[t],
137
+ mode: "display",
138
+ record: e,
139
+ refs: C,
140
+ locale: l
141
+ })
142
+ }, t) : /* @__PURE__ */ B("td", {}, t);
143
+ }) }, t)) })]
144
+ }),
145
+ ne && d && d.count > S.length && /* @__PURE__ */ B("div", {
146
+ style: {
147
+ padding: "10px 16px",
148
+ textAlign: "center"
149
+ },
150
+ children: /* @__PURE__ */ V(D, {
151
+ icon: /* @__PURE__ */ B(e.external, { size: 12 }),
152
+ onClick: te,
153
+ children: [
154
+ "View all ",
155
+ d.count,
156
+ " records"
157
+ ]
158
+ })
159
+ }),
160
+ ne && S.length > 0 && d && d.count <= S.length && /* @__PURE__ */ B("div", {
161
+ style: {
162
+ padding: "10px 16px",
163
+ textAlign: "center"
164
+ },
165
+ children: /* @__PURE__ */ B(D, {
166
+ kind: "ghost",
167
+ icon: /* @__PURE__ */ B(e.external, { size: 12 }),
168
+ onClick: te,
169
+ children: "Open in list view"
170
+ })
171
+ })
172
+ ]
173
+ });
174
+ }
175
+ //#endregion
176
+ //#region src/components/pages/RecordDocumentsPanel.tsx
177
+ var H = 4e3;
178
+ function U(e) {
179
+ return e?.some((e) => e.status === "pending") ? H : !1;
180
+ }
181
+ function tt({ entityCode: t, objectId: n, canGenerateOne: r, canManageTemplates: i }) {
182
+ let { data: a, isLoading: o, error: s } = R({
183
+ queryKey: [
184
+ M,
185
+ t,
186
+ n
187
+ ],
188
+ queryFn: async () => (await O("document.object_links", {
189
+ entity: t,
190
+ object_id: n
191
+ })).result?.documents ?? [],
192
+ enabled: !!(t && n) && (!!r || !!i),
193
+ refetchInterval: (e) => U(e.state.data)
194
+ }), c = (a?.length ?? 0) > 0;
195
+ return !r && !c ? null : /* @__PURE__ */ V(Re, {
196
+ title: /* @__PURE__ */ B(W, {}),
197
+ collapsible: !1,
198
+ padding: "0",
199
+ children: [
200
+ o && /* @__PURE__ */ B(G, {
201
+ icon: /* @__PURE__ */ B(e.loader, { size: 14 }),
202
+ text: "Loading documents..."
203
+ }),
204
+ s && /* @__PURE__ */ B(G, {
205
+ icon: /* @__PURE__ */ B(e.warning, { size: 14 }),
206
+ text: s instanceof Error ? s.message : String(s)
207
+ }),
208
+ !o && !s && (a?.length ?? 0) === 0 && /* @__PURE__ */ B(G, {
209
+ icon: /* @__PURE__ */ B(e.file, { size: 14 }),
210
+ text: "No generated documents"
211
+ }),
212
+ !o && !s && a && a.length > 0 && /* @__PURE__ */ B("div", {
213
+ style: {
214
+ display: "flex",
215
+ flexDirection: "column"
216
+ },
217
+ children: a.map((e) => /* @__PURE__ */ B(nt, {
218
+ entityCode: t,
219
+ objectId: n,
220
+ doc: e
221
+ }, e.generated_document_id))
222
+ })
223
+ ]
224
+ });
225
+ }
226
+ function W() {
227
+ return /* @__PURE__ */ V("div", {
228
+ style: {
229
+ display: "flex",
230
+ alignItems: "center",
231
+ gap: 6,
232
+ margin: "-10px -14px 0 -14px",
233
+ padding: "10px 14px",
234
+ fontSize: 12.5,
235
+ fontWeight: 600,
236
+ color: "var(--text)"
237
+ },
238
+ children: [/* @__PURE__ */ B(e.file, { size: 13 }), "Documents"]
239
+ });
240
+ }
241
+ function nt({ entityCode: t, objectId: n, doc: r }) {
242
+ let i = z(), [a, o] = L(!1), [s, c] = L(!1), [l, u] = L(!1), [d, f] = L(!1), [p, m] = L(null), g = h(r.title) || r.filename || r.template_code, _ = r.status === "ready" && r.download_url && !d;
243
+ async function v() {
244
+ o(!0), m(null);
245
+ try {
246
+ let e = (await O("document.download_format", {
247
+ generated_document_id: r.generated_document_id,
248
+ format: "pdf"
249
+ })).result;
250
+ e?.download_url && await w(e.download_url, e.filename);
251
+ } catch (e) {
252
+ oe(e) ? (f(!0), m("Artifact unavailable")) : m(e instanceof Error ? e.message : String(e));
253
+ } finally {
254
+ o(!1);
255
+ }
256
+ }
257
+ async function y() {
258
+ if (r.download_url) {
259
+ c(!0), m(null);
260
+ try {
261
+ await w(r.download_url, r.filename);
262
+ } catch (e) {
263
+ oe(e) ? (f(!0), m("Artifact unavailable")) : m(e instanceof Error ? e.message : String(e));
264
+ } finally {
265
+ c(!1);
266
+ }
267
+ }
268
+ }
269
+ async function b() {
270
+ u(!0), m(null);
271
+ try {
272
+ await O("document.generate", {
273
+ ...r.input ?? {},
274
+ template_code: r.template_code,
275
+ template_source: r.template_source,
276
+ output_format: r.output_format
277
+ }), await i.invalidateQueries({ queryKey: [
278
+ M,
279
+ t,
280
+ n
281
+ ] });
282
+ } catch (e) {
283
+ m(e instanceof Error ? e.message : String(e));
284
+ } finally {
285
+ u(!1);
286
+ }
287
+ }
288
+ return /* @__PURE__ */ V("div", {
289
+ style: {
290
+ display: "grid",
291
+ gridTemplateColumns: "minmax(0, 1fr) auto",
292
+ gap: 12,
293
+ alignItems: "center",
294
+ padding: "11px 14px",
295
+ borderTop: "1px solid var(--divider)"
296
+ },
297
+ children: [/* @__PURE__ */ V("div", {
298
+ style: { minWidth: 0 },
299
+ children: [
300
+ /* @__PURE__ */ B("div", {
301
+ style: {
302
+ fontSize: 13,
303
+ fontWeight: 600,
304
+ color: "var(--text)",
305
+ overflow: "hidden",
306
+ textOverflow: "ellipsis",
307
+ whiteSpace: "nowrap"
308
+ },
309
+ children: g
310
+ }),
311
+ /* @__PURE__ */ V("div", {
312
+ style: {
313
+ marginTop: 3,
314
+ display: "flex",
315
+ gap: 8,
316
+ alignItems: "center",
317
+ color: "var(--text-3)",
318
+ fontSize: 11.5
319
+ },
320
+ children: [
321
+ /* @__PURE__ */ B("span", { children: r.output_format.toUpperCase() }),
322
+ /* @__PURE__ */ B("span", { children: d ? "artifact unavailable" : r.status }),
323
+ /* @__PURE__ */ B("span", { children: r.ready_at || r.created_at })
324
+ ]
325
+ }),
326
+ r.status === "failed" && r.error_text && /* @__PURE__ */ B("div", {
327
+ style: {
328
+ marginTop: 5,
329
+ color: "var(--danger)",
330
+ fontSize: 12
331
+ },
332
+ children: r.error_text
333
+ }),
334
+ p && /* @__PURE__ */ B("div", {
335
+ style: {
336
+ marginTop: 5,
337
+ color: "var(--danger)",
338
+ fontSize: 12
339
+ },
340
+ children: p
341
+ })
342
+ ]
343
+ }), _ ? /* @__PURE__ */ V("div", {
344
+ style: {
345
+ display: "flex",
346
+ gap: 6
347
+ },
348
+ children: [/* @__PURE__ */ B(D, {
349
+ kind: "ghost",
350
+ size: "sm",
351
+ icon: B(a ? e.loader : e.file, { size: 12 }),
352
+ onClick: v,
353
+ disabled: a,
354
+ children: "PDF"
355
+ }), /* @__PURE__ */ B(D, {
356
+ kind: "default",
357
+ size: "sm",
358
+ icon: B(s ? e.loader : e.download, { size: 12 }),
359
+ onClick: y,
360
+ disabled: s,
361
+ children: "Download"
362
+ })]
363
+ }) : d ? /* @__PURE__ */ B(D, {
364
+ kind: "ghost",
365
+ size: "sm",
366
+ icon: B(l ? e.loader : e.file, { size: 12 }),
367
+ onClick: b,
368
+ disabled: l,
369
+ children: "Regenerate"
370
+ }) : /* @__PURE__ */ B(D, {
371
+ kind: "ghost",
372
+ size: "sm",
373
+ disabled: !0,
374
+ children: r.status === "pending" ? "Pending" : "Unavailable"
375
+ })]
376
+ });
377
+ }
378
+ function G({ icon: e, text: t }) {
379
+ return /* @__PURE__ */ V("div", {
380
+ style: {
381
+ display: "flex",
382
+ alignItems: "center",
383
+ gap: 8,
384
+ padding: "14px",
385
+ color: "var(--text-3)",
386
+ fontSize: 12.5
387
+ },
388
+ children: [e, t]
389
+ });
390
+ }
391
+ //#endregion
392
+ //#region src/components/detail-layout/ErrorSummary.tsx
393
+ function rt({ errors: t, onJump: n }) {
394
+ if (t.length === 0) return null;
395
+ let r = t.length !== 1;
396
+ return /* @__PURE__ */ V("div", {
397
+ role: "alert",
398
+ style: {
399
+ display: "flex",
400
+ gap: 10,
401
+ padding: "10px 12px",
402
+ marginBottom: 12,
403
+ borderRadius: 8,
404
+ background: "var(--danger-soft)",
405
+ border: "1px solid var(--danger-border)",
406
+ color: "var(--text)"
407
+ },
408
+ children: [/* @__PURE__ */ B("span", {
409
+ style: {
410
+ color: "var(--danger)",
411
+ marginTop: 1,
412
+ display: "flex"
413
+ },
414
+ children: /* @__PURE__ */ B(e.warning, { size: 14 })
415
+ }), /* @__PURE__ */ V("div", {
416
+ style: {
417
+ flex: 1,
418
+ minWidth: 0
419
+ },
420
+ children: [/* @__PURE__ */ V("div", {
421
+ style: {
422
+ fontSize: 12.5,
423
+ fontWeight: 600,
424
+ marginBottom: 4
425
+ },
426
+ children: [
427
+ t.length,
428
+ " ",
429
+ r ? "fields need" : "field needs",
430
+ " attention"
431
+ ]
432
+ }), /* @__PURE__ */ B("ul", {
433
+ style: {
434
+ margin: 0,
435
+ padding: 0,
436
+ listStyle: "none",
437
+ display: "flex",
438
+ flexDirection: "column",
439
+ gap: 2
440
+ },
441
+ children: t.map((e) => /* @__PURE__ */ B("li", { children: /* @__PURE__ */ V("button", {
442
+ type: "button",
443
+ onClick: n ? () => n(e.name) : void 0,
444
+ style: {
445
+ background: "transparent",
446
+ border: 0,
447
+ padding: 0,
448
+ cursor: n ? "pointer" : "default",
449
+ fontSize: 12,
450
+ textAlign: "left",
451
+ fontFamily: "inherit"
452
+ },
453
+ children: [
454
+ /* @__PURE__ */ B("span", {
455
+ style: {
456
+ color: "var(--danger)",
457
+ marginRight: 6
458
+ },
459
+ children: "•"
460
+ }),
461
+ /* @__PURE__ */ B("span", {
462
+ style: {
463
+ fontWeight: 500,
464
+ color: "var(--text-2)"
465
+ },
466
+ children: e.label
467
+ }),
468
+ /* @__PURE__ */ V("span", {
469
+ style: { color: "var(--text-3)" },
470
+ children: [" - ", e.message]
471
+ })
472
+ ]
473
+ }) }, e.name))
474
+ })]
475
+ })]
476
+ });
477
+ }
478
+ //#endregion
479
+ //#region src/components/shared/HighlightsStrip.tsx
480
+ function K({ items: e }) {
481
+ return e.length === 0 ? null : /* @__PURE__ */ B("div", {
482
+ style: {
483
+ display: "flex",
484
+ alignItems: "center",
485
+ flexWrap: "wrap",
486
+ gap: "6px 0",
487
+ fontSize: 12
488
+ },
489
+ children: e.map((e, t) => /* @__PURE__ */ V(N, { children: [t > 0 && /* @__PURE__ */ B("span", { style: {
490
+ width: 1,
491
+ height: 12,
492
+ background: "var(--divider)",
493
+ marginInline: 12
494
+ } }), /* @__PURE__ */ V("span", {
495
+ style: {
496
+ display: "inline-flex",
497
+ alignItems: "center",
498
+ gap: 6,
499
+ lineHeight: 1.3
500
+ },
501
+ children: [/* @__PURE__ */ B("span", {
502
+ style: {
503
+ color: "var(--text-3)",
504
+ fontSize: 11.5
505
+ },
506
+ children: e.label
507
+ }), /* @__PURE__ */ B("span", {
508
+ style: { color: "var(--text)" },
509
+ children: e.value
510
+ })]
511
+ })] }, t))
512
+ });
513
+ }
514
+ //#endregion
515
+ //#region src/components/detail-layout/DetailHighlights.tsx
516
+ function it({ screen: e, entity: t, entityCode: n, record: r, refs: i, objectStatuses: a, schema: o, locale: s }) {
517
+ let c = e.highlights;
518
+ if (!c || c.length === 0) return null;
519
+ let l = [];
520
+ for (let e of c) {
521
+ let c = t.status_groups?.[e];
522
+ if (c) {
523
+ let t = a?.find((t) => t.group_code === e), n = t ? c.statuses.find((e) => e.code === t.status_code) : void 0;
524
+ l.push({
525
+ label: h(c.name),
526
+ value: n ? /* @__PURE__ */ B(b, {
527
+ tone: n.color ?? "slate",
528
+ size: "xs",
529
+ children: h(n.name)
530
+ }) : /* @__PURE__ */ B("span", {
531
+ style: { color: "var(--text-4)" },
532
+ children: "—"
533
+ })
534
+ });
535
+ continue;
536
+ }
537
+ if (t.fields.get(e) || t.files?.get(e)) {
538
+ let a = ze({
539
+ entity: t,
540
+ entityCode: n,
541
+ fieldName: e,
542
+ record: r,
543
+ mode: "display",
544
+ refs: i,
545
+ entities: o.entities,
546
+ screens: o.screens,
547
+ surface: "list",
548
+ locale: s
549
+ });
550
+ l.push({
551
+ label: Te(t, e, o.entities),
552
+ value: a
553
+ });
554
+ continue;
555
+ }
556
+ }
557
+ return l.length === 0 ? null : /* @__PURE__ */ B(K, { items: l });
558
+ }
559
+ //#endregion
560
+ //#region src/components/shared/AuditMetaStrip.tsx
561
+ function at(e) {
562
+ return e.by != null || e.at != null;
563
+ }
564
+ function ot({ lines: e }) {
565
+ let t = e.filter(at);
566
+ return t.length === 0 ? null : /* @__PURE__ */ B("div", {
567
+ style: {
568
+ display: "flex",
569
+ flexWrap: "wrap",
570
+ gap: "8px 24px",
571
+ padding: "10px 14px",
572
+ background: "var(--surface-2)",
573
+ border: "1px solid var(--border)",
574
+ borderRadius: 8,
575
+ fontSize: 11.5,
576
+ color: "var(--text-3)"
577
+ },
578
+ children: t.map((e, t) => /* @__PURE__ */ B(st, { line: e }, t))
579
+ });
580
+ }
581
+ function st({ line: e }) {
582
+ return /* @__PURE__ */ V("div", {
583
+ style: {
584
+ display: "flex",
585
+ alignItems: "center",
586
+ gap: 8,
587
+ minWidth: 0
588
+ },
589
+ children: [/* @__PURE__ */ B("span", {
590
+ style: {
591
+ fontSize: 11,
592
+ fontWeight: 600,
593
+ color: "var(--text-4)",
594
+ flexShrink: 0
595
+ },
596
+ children: e.label
597
+ }), /* @__PURE__ */ V("span", {
598
+ style: {
599
+ display: "inline-flex",
600
+ alignItems: "center",
601
+ gap: 6,
602
+ minWidth: 0
603
+ },
604
+ children: [
605
+ e.by != null && /* @__PURE__ */ B("span", {
606
+ style: { color: "var(--text-2)" },
607
+ children: e.by
608
+ }),
609
+ e.by != null && e.at != null && /* @__PURE__ */ B("span", {
610
+ style: { color: "var(--text-4)" },
611
+ children: "·"
612
+ }),
613
+ e.at != null && /* @__PURE__ */ B("span", {
614
+ className: "num",
615
+ children: e.at
616
+ })
617
+ ]
618
+ })]
619
+ });
620
+ }
621
+ //#endregion
622
+ //#region src/components/detail-layout/DetailAuditStrip.tsx
623
+ function ct({ screen: e, entity: t, entityCode: n, record: r, refs: i, schema: a, locale: o }) {
624
+ let s = e.audit;
625
+ if (s?.enabled === !1) return null;
626
+ let c = (e) => {
627
+ if (!e || !t.fields.get(e)) return;
628
+ let s = r[e];
629
+ if (!(s == null || s === "")) return ze({
630
+ entity: t,
631
+ entityCode: n,
632
+ fieldName: e,
633
+ record: r,
634
+ mode: "display",
635
+ refs: i,
636
+ entities: a.entities,
637
+ screens: a.screens,
638
+ surface: "list",
639
+ locale: o
640
+ });
641
+ };
642
+ return /* @__PURE__ */ B(ot, { lines: s?.lines && s.lines.length > 0 ? s.lines.map((e) => ({
643
+ label: h(e.label),
644
+ at: c(e.at),
645
+ by: c(e.by)
646
+ })) : [{
647
+ label: "Created",
648
+ at: c("created_at"),
649
+ by: c("created_by")
650
+ }, {
651
+ label: "Updated",
652
+ at: c("updated_at"),
653
+ by: c("updated_by")
654
+ }] });
655
+ }
656
+ //#endregion
657
+ //#region src/components/detail-layout/EvidenceBlock.tsx
658
+ function q(e) {
659
+ if (!e) return;
660
+ let t = new Date(e);
661
+ if (!Number.isNaN(t.getTime())) return t.toLocaleString();
662
+ }
663
+ function lt({ evidence: e }) {
664
+ let t = e?.verdict ?? "unverified", n = q(e?.verified_at), r = [];
665
+ return n && r.push(`Verified ${n}`), e?.seq && r.push(`chain #${e.seq}`), e?.checkpoint_number && r.push(`checkpoint ${e.checkpoint_number}`), e?.generation && r.push(`generation ${e.generation}`), /* @__PURE__ */ V("div", {
666
+ style: {
667
+ display: "flex",
668
+ flexDirection: "column",
669
+ gap: 6
670
+ },
671
+ children: [/* @__PURE__ */ V("div", {
672
+ style: {
673
+ display: "flex",
674
+ alignItems: "center",
675
+ gap: 10,
676
+ flexWrap: "wrap"
677
+ },
678
+ children: [
679
+ /* @__PURE__ */ B("span", {
680
+ style: {
681
+ fontSize: 12,
682
+ fontWeight: 600,
683
+ color: "var(--muted-foreground)"
684
+ },
685
+ children: "Evidence"
686
+ }),
687
+ /* @__PURE__ */ B(b, {
688
+ tone: ve(t),
689
+ size: "sm",
690
+ dot: !0,
691
+ children: ge(t)
692
+ }),
693
+ r.length > 0 && /* @__PURE__ */ B("span", {
694
+ style: {
695
+ fontSize: 12,
696
+ color: "var(--muted-foreground)"
697
+ },
698
+ children: r.join(" · ")
699
+ })
700
+ ]
701
+ }), e?.reason && /* @__PURE__ */ B("span", {
702
+ style: {
703
+ fontSize: 12,
704
+ color: "var(--destructive)"
705
+ },
706
+ children: e.reason
707
+ })]
708
+ });
709
+ }
710
+ //#endregion
711
+ //#region src/components/shared/RecordHeader.tsx
712
+ function ut({ icon: t, avatarName: n, title: r, recordId: i, description: a, highlights: o, mode: s, dirty: c = !1, showBack: l = !1, onBack: u, right: d, identityControls: f, showTitle: p = !0 }) {
713
+ let m = C(), h = m.category === "phone" || m.width <= 520;
714
+ return /* @__PURE__ */ V("div", {
715
+ style: {
716
+ display: "flex",
717
+ alignItems: "flex-start",
718
+ gap: 10,
719
+ flexWrap: h ? "wrap" : "nowrap",
720
+ minWidth: 0
721
+ },
722
+ children: [
723
+ p && l && /* @__PURE__ */ B("div", {
724
+ style: {
725
+ paddingTop: 4,
726
+ flexShrink: 0
727
+ },
728
+ children: /* @__PURE__ */ B(ae, {
729
+ size: 26,
730
+ icon: /* @__PURE__ */ B(e.back, { size: 14 }),
731
+ title: "Back",
732
+ onClick: u
733
+ })
734
+ }),
735
+ p && (n || t) && /* @__PURE__ */ B("div", {
736
+ style: {
737
+ flexShrink: 0,
738
+ paddingTop: 2
739
+ },
740
+ children: n ? /* @__PURE__ */ B(j, {
741
+ name: n,
742
+ size: 32
743
+ }) : /* @__PURE__ */ B("span", {
744
+ style: {
745
+ width: 32,
746
+ height: 32,
747
+ borderRadius: 8,
748
+ background: "var(--accent-soft)",
749
+ color: "var(--accent)",
750
+ display: "flex",
751
+ alignItems: "center",
752
+ justifyContent: "center"
753
+ },
754
+ children: t
755
+ })
756
+ }),
757
+ p && /* @__PURE__ */ V("div", {
758
+ style: {
759
+ flex: "1 1 0",
760
+ minWidth: 0
761
+ },
762
+ children: [/* @__PURE__ */ V("div", {
763
+ style: {
764
+ display: "flex",
765
+ alignItems: "center",
766
+ gap: 8,
767
+ flexWrap: "wrap"
768
+ },
769
+ children: [
770
+ /* @__PURE__ */ B("h1", {
771
+ style: {
772
+ margin: 0,
773
+ fontSize: "var(--page-title-size, var(--page-title-size-detail))",
774
+ fontWeight: 600,
775
+ letterSpacing: 0,
776
+ lineHeight: "var(--page-title-line-height, var(--page-title-line-height-detail))",
777
+ color: "var(--text)",
778
+ minWidth: 0,
779
+ overflow: "hidden",
780
+ textOverflow: "ellipsis",
781
+ whiteSpace: h ? "normal" : "nowrap",
782
+ overflowWrap: "anywhere",
783
+ maxWidth: "100%"
784
+ },
785
+ children: r
786
+ }),
787
+ i && /* @__PURE__ */ B(k, { value: i }),
788
+ a && /* @__PURE__ */ B(A, {
789
+ label: a,
790
+ "data-testid": "detail-description-info"
791
+ }),
792
+ f,
793
+ s === "edit" && c && /* @__PURE__ */ V("span", {
794
+ style: {
795
+ display: "inline-flex",
796
+ alignItems: "center",
797
+ gap: 5,
798
+ fontSize: 11,
799
+ color: "var(--warn)"
800
+ },
801
+ children: [/* @__PURE__ */ B("span", { style: {
802
+ width: 6,
803
+ height: 6,
804
+ borderRadius: 999,
805
+ background: "var(--warn)"
806
+ } }), "Unsaved"]
807
+ }),
808
+ s === "create" && /* @__PURE__ */ B(b, {
809
+ tone: "violet",
810
+ size: "xs",
811
+ dot: !0,
812
+ children: "New record"
813
+ })
814
+ ]
815
+ }), o && s === "display" && /* @__PURE__ */ B("div", {
816
+ style: { marginTop: 8 },
817
+ children: o
818
+ })]
819
+ }),
820
+ d && /* @__PURE__ */ B("div", {
821
+ role: "toolbar",
822
+ "aria-label": "Page actions",
823
+ style: {
824
+ display: "flex",
825
+ alignItems: "center",
826
+ gap: 6,
827
+ flex: h ? "1 1 100%" : "0 1 auto",
828
+ flexWrap: "wrap",
829
+ justifyContent: h ? "flex-start" : "flex-end",
830
+ minWidth: 0
831
+ },
832
+ children: d
833
+ })
834
+ ]
835
+ });
836
+ }
837
+ //#endregion
838
+ //#region src/lib/children-validation.ts
839
+ function dt(e, t, n) {
840
+ let r = [];
841
+ for (let [i, a] of e.fields) {
842
+ if (!a.required || a.auto || n && a.primary || e.tenant_key && i === e.tenant_key || a.default !== void 0 && a.default !== null) continue;
843
+ let o = t[i];
844
+ (o == null || o === "") && r.push(i);
845
+ }
846
+ return r;
847
+ }
848
+ var ft = /^[^@\s]+@[^@\s]+\.[^@\s]+$/;
849
+ function pt(e, t) {
850
+ let n = [];
851
+ for (let [r, i] of e.fields) {
852
+ if (i.type !== "email") continue;
853
+ let e = t[r];
854
+ typeof e == "string" && e !== "" && !ft.test(e) && n.push(r);
855
+ }
856
+ return n;
857
+ }
858
+ function mt(e, t) {
859
+ let n = /* @__PURE__ */ new Set();
860
+ for (let r of Object.values(t.entities)) if (r.children) {
861
+ for (let t of r.children) if (t.entity === e && t.foreign_key) {
862
+ let e = Array.isArray(t.foreign_key) ? t.foreign_key : [t.foreign_key];
863
+ for (let t of e) n.add(t);
864
+ }
865
+ }
866
+ return n;
867
+ }
868
+ function ht(e, t) {
869
+ if (!e || !t) return {};
870
+ let n = {};
871
+ for (let [r, i] of Object.entries(e)) {
872
+ let e = t.entities[r];
873
+ if (!e) continue;
874
+ let a = mt(r, t), o = [];
875
+ for (let [t, n] of e.fields) e.tenant_key && t === e.tenant_key || n.required && !n.auto && !n.primary && !a.has(t) && o.push(t);
876
+ if (o.length !== 0) for (let e of i) {
877
+ if (e._deleted) continue;
878
+ let t = [];
879
+ for (let n of o) {
880
+ let r = e[n];
881
+ (r == null || r === "") && t.push(n);
882
+ }
883
+ t.length > 0 && (n[r] || (n[r] = {}), n[r][e._key] = t);
884
+ }
885
+ }
886
+ return n;
887
+ }
888
+ //#endregion
889
+ //#region src/components/pages/SmartDetailPage.impl.tsx
890
+ var gt = () => {};
891
+ function _t(e, t) {
892
+ return e.length === t.length && JSON.stringify(e) === JSON.stringify(t);
893
+ }
894
+ function vt(e, t) {
895
+ if (e) {
896
+ let n = re(le(e, t));
897
+ if (n.replace(/^\|+|\|+$/g, "")) return n;
898
+ }
899
+ return t.id == null ? crypto.randomUUID() : c(t.id);
900
+ }
901
+ function J({ screenCode: e }) {
902
+ return /* @__PURE__ */ B(f, { children: /* @__PURE__ */ B(yt, { screenCode: e }) });
903
+ }
904
+ function yt({ screenCode: t }) {
905
+ let { id: r } = Xe(), a = ee(), [c, l] = Ze(), { data: f } = ne(), g = d((e) => e.user), v = s(), y = C(), b = f?.screens[t], w = b?.entity ? f?.entities[b.entity] : void 0, T = b?.entity, E = x(w, "create"), D = x(w, "update"), oe = x(w, "restore"), ce = (() => {
906
+ if (!w || !w.singleton || !w.prefilter) return;
907
+ let e = se(w);
908
+ if (e.length !== 1) return;
909
+ let t = w.prefilter[e[0]];
910
+ if (t === "$caller.user_id") return g?.id;
911
+ if (t === "$caller.tenant_id") return g?.tenant?.id;
912
+ })(), O = ce !== void 0, k = O ? ce : r, A = !O && k === "new", j = I(() => {
913
+ if (!k || A) return;
914
+ if (!w) return k;
915
+ let e = se(w);
916
+ if (e.length === 1) return { [e[0]]: k };
917
+ let t = o(k, e.length);
918
+ if (!t) return;
919
+ let n = {};
920
+ for (let r = 0; r < e.length; r++) n[e[r]] = t[r] ?? "";
921
+ return n;
922
+ }, [
923
+ k,
924
+ A,
925
+ w
926
+ ]), M = I(() => {
927
+ if (j) return typeof j == "string" ? j : re(j);
928
+ }, [j]), me = Ne(T, j), { data: he, isLoading: ge, error: ve } = me, ye = we((e) => e.degradedEntities), Te = T ? Se(w?.realtime, ye, T) : !1;
929
+ de(Pe(T, j), !A);
930
+ let De = xe(T ?? ""), Fe = Le(T ?? ""), Ie = Oe(T ?? ""), Re = Object.keys(w?.status_groups ?? {}).length > 0, ze = he?.data, Ue = ze?.$statuses, We = ze?.$properties, Ge = c.get("edit") === "true", [N, R] = L(A || Ge), [z, et] = L({}), [H, U] = L({}), [W, nt] = L({}), [G, K] = L(void 0), [at, ot] = L(!1), [st, q] = L(void 0), [ut, ft] = L(!1), mt = A ? E : D, J = N && mt, yt = ie();
931
+ te(J && !A, yt.enabled);
932
+ let [xt, St] = L(() => {
933
+ let e = parseInt(b?.sidebar_width || "380", 10);
934
+ return isNaN(e) ? 380 : e;
935
+ }), wt = Je(null), Y = Je(null), Tt = P((e) => {
936
+ e.preventDefault();
937
+ let t = wt.current;
938
+ if (!t) return;
939
+ let n = t.offsetWidth;
940
+ Y.current = {
941
+ startX: e.clientX,
942
+ startW: n
943
+ };
944
+ let r = (e) => {
945
+ if (!Y.current) return;
946
+ let n = Y.current.startX - e.clientX, r = Math.max(280, Math.min(800, Y.current.startW + n));
947
+ t.style.width = `${r}px`;
948
+ }, i = () => {
949
+ Y.current && t && St(parseInt(t.style.width, 10) || Y.current.startW), Y.current = null, document.removeEventListener("mousemove", r), document.removeEventListener("mouseup", i);
950
+ };
951
+ document.addEventListener("mousemove", r), document.addEventListener("mouseup", i);
952
+ }, []), X = he?.data, Z = typeof X?.$row_version == "string" ? X.$row_version : void 0, Et = X?.$refs, Dt = Je(Z);
953
+ F(() => {
954
+ if (!Z) return;
955
+ let e = Dt.current;
956
+ Dt.current = Z, e && e !== Z && N && ot(!0);
957
+ }, [N, Z]);
958
+ let Ot = !!w?.soft_delete && X != null && X[w.soft_delete] != null, kt = Ye(), At = Je(null);
959
+ fe({ scrollElementRef: At });
960
+ let jt = !A && ve instanceof S && ve.status === 404, Mt = Je(null);
961
+ F(() => {
962
+ if (!jt) return;
963
+ let e = be(kt);
964
+ Mt.current !== e && (Mt.current = e, ue.getState().kill(e));
965
+ }, [jt, kt]);
966
+ let { openTab: Nt, updateTabTitle: Pt, findTabByPathname: Ft } = Ve();
967
+ F(() => {
968
+ if (!w || O || yt.enabled) return;
969
+ let e = kt.pathname, t = h(b?.display?.name) || h(w.display.name), n = b?.display?.icon || w.display.icon;
970
+ Ft(e) || Nt({
971
+ pathname: e,
972
+ search: "",
973
+ title: A ? `New ${t}` : t,
974
+ icon: n,
975
+ closable: !0
976
+ });
977
+ }, [
978
+ kt.pathname,
979
+ b?.display?.name?.en,
980
+ w?.display.name?.en,
981
+ b?.display?.icon,
982
+ w?.display.icon,
983
+ A,
984
+ O,
985
+ yt.enabled
986
+ ]), F(() => {
987
+ if (!X || !w || O || yt.enabled) return;
988
+ let e = Ft(kt.pathname);
989
+ if (e) {
990
+ let t = h(b?.display?.name) || h(w.display.name), n = i(X, w), r = n && !String(n).startsWith("/") ? String(n) : t;
991
+ Pt(e.id, r);
992
+ }
993
+ }, [
994
+ X,
995
+ w?.display.name?.en,
996
+ w?.display.display_field,
997
+ kt.pathname,
998
+ O,
999
+ yt.enabled
1000
+ ]);
1001
+ let It = I(() => {
1002
+ if (!w || !mt) return /* @__PURE__ */ new Set();
1003
+ let e = /* @__PURE__ */ new Set();
1004
+ for (let [t, n] of w.fields) !n.auto && !n.primary && e.add(t);
1005
+ for (let [t] of w.files ?? []) e.add(t);
1006
+ return e;
1007
+ }, [w, mt]);
1008
+ F(() => {
1009
+ if (!(!Ge || !X || !w || !D)) {
1010
+ if (N || R(!0), Object.keys(z).length === 0) {
1011
+ let e = k ? _e(k) : null;
1012
+ e && Ae(ke({
1013
+ entity: w,
1014
+ formData: e,
1015
+ record: void 0,
1016
+ isNew: !0
1017
+ })).forEach((e) => {
1018
+ v.registerDraft({
1019
+ fileId: e,
1020
+ discard: () => u(e)
1021
+ });
1022
+ });
1023
+ let t = {};
1024
+ It.forEach((n) => {
1025
+ let r = e ? e[n] : void 0;
1026
+ if (r !== void 0) {
1027
+ t[n] = r;
1028
+ return;
1029
+ }
1030
+ let i = Ee(w, X, n);
1031
+ t[n] = Ce(w, n) ? i ?? null : i ?? "";
1032
+ }), et(t);
1033
+ }
1034
+ if (w.children !== void 0 && w.children.length > 0 && G === void 0) {
1035
+ let e = X.$children;
1036
+ if (e && Object.keys(e).length > 0) {
1037
+ let t = {};
1038
+ for (let [n, r] of Object.entries(e)) {
1039
+ let e = f?.entities[n];
1040
+ t[n] = r.map((t) => ({
1041
+ ...t,
1042
+ _key: vt(e, t)
1043
+ }));
1044
+ }
1045
+ K(t), q(e);
1046
+ } else K({}), q({});
1047
+ }
1048
+ l((e) => {
1049
+ let t = new URLSearchParams(e);
1050
+ return t.delete("edit"), t;
1051
+ }, { replace: !0 });
1052
+ }
1053
+ }, [
1054
+ Ge,
1055
+ X,
1056
+ It,
1057
+ D,
1058
+ w,
1059
+ G,
1060
+ f
1061
+ ]), F(() => {
1062
+ !A || !E || !w?.children || w.children.length === 0 || G === void 0 && (K({}), q({}));
1063
+ }, [
1064
+ A,
1065
+ E,
1066
+ w?.children
1067
+ ]);
1068
+ let Lt = P(async () => {
1069
+ if (await v.flushAllDrafts(), A) {
1070
+ let e = b?.route?.replace("/:id", "") ?? "/";
1071
+ a(e);
1072
+ } else R(!1), et({}), U({}), nt({}), K(void 0), q(void 0), ft(!1);
1073
+ }, [
1074
+ v,
1075
+ A,
1076
+ b,
1077
+ a
1078
+ ]), Rt = P((e, t) => {
1079
+ et((n) => ({
1080
+ ...n,
1081
+ [e]: t
1082
+ }));
1083
+ }, []), Q = I(() => {
1084
+ if (!b?.route) return "/";
1085
+ let e = b.route.split("/");
1086
+ return e.pop(), e.join("/") || "/";
1087
+ }, [b]), zt = I(() => !f?.screens || !Q || Q === "/" ? !1 : Object.values(f.screens).some((e) => e.route === Q), [f, Q]), Bt = Me({ fallback: P(() => {
1088
+ if (!zt) {
1089
+ a("/");
1090
+ return;
1091
+ }
1092
+ let e = Ft(Q)?.search ?? "";
1093
+ a(e ? `${Q}?${e}` : Q);
1094
+ }, [
1095
+ zt,
1096
+ Q,
1097
+ Ft,
1098
+ a
1099
+ ]) }), Vt = !O && (Bt.hasOriginBack || Bt.allowFallbackBack && !!zt), Ht = n(), Ut = I(() => {
1100
+ if (!w) return {};
1101
+ let e = {};
1102
+ for (let t of dt(w, z, A)) It.has(t) && (e[t] = "Required");
1103
+ for (let t of pt(w, z)) It.has(t) && (e[t] = "Invalid email address");
1104
+ return e;
1105
+ }, [
1106
+ w,
1107
+ z,
1108
+ A,
1109
+ It
1110
+ ]), Wt = Object.keys(Ut).length > 0, Gt = P(() => {
1111
+ if (!T || !w || A && !E || !A && !D || (ft(!0), Wt)) return;
1112
+ let e = {}, t = ke({
1113
+ entity: w,
1114
+ formData: z,
1115
+ record: X,
1116
+ isNew: A
1117
+ }), n = Ae(t);
1118
+ if (A) for (let [t, n] of Object.entries(z)) {
1119
+ if (w.files?.has(t)) continue;
1120
+ let r = je(w, t, n);
1121
+ r !== "" && r != null && (e[t] = r);
1122
+ }
1123
+ else {
1124
+ for (let [t, n] of Object.entries(z)) {
1125
+ if (w.files?.has(t)) continue;
1126
+ let r = X ? Ee(w, X, t) : void 0, i = je(w, t, n), a = je(w, t, r);
1127
+ (i === "" ? null : i) !== (a === "" || a === void 0 ? null : a) && (e[t] = i);
1128
+ }
1129
+ Z && (e.$row_version = Z);
1130
+ }
1131
+ if (Object.keys(t).length > 0 && (e.$files = t), Object.keys(H).length > 0 && (e.$statuses = Object.entries(H).map(([e, t]) => ({
1132
+ status_group_code: e,
1133
+ status_code: t
1134
+ }))), Object.keys(W).length > 0 && (e.$properties = Object.entries(W).map(([e, t]) => ({
1135
+ property_code: e,
1136
+ value: t
1137
+ }))), G) {
1138
+ let t = {};
1139
+ for (let [e, n] of Object.entries(G)) {
1140
+ let r = n.filter((e) => !e._deleted).map((e) => {
1141
+ let { _key: t, _deleted: n, _dirty: r, ...i } = e;
1142
+ return i;
1143
+ }), i = st?.[e] ?? [];
1144
+ (A || !_t(r, i)) && (t[e] = r);
1145
+ }
1146
+ Object.keys(t).length > 0 && (e.$children = t);
1147
+ }
1148
+ if (!A && Object.keys(e).length === 0) {
1149
+ R(!1), U({}), nt({}), K(void 0), q(void 0), ft(!1);
1150
+ return;
1151
+ }
1152
+ let r = () => {
1153
+ R(!1), ot(!1), ft(!1), U({}), nt({}), K(void 0), q(void 0);
1154
+ };
1155
+ A ? De.mutate(e, { onSuccess: (e) => {
1156
+ n.forEach((e) => v.markCommitted(e));
1157
+ let t = e.data, i = re(w ? le(w, t) : {});
1158
+ a(i ? `${Q}/${encodeURIComponent(i)}` : Q, { replace: !0 }), r();
1159
+ } }) : j && Fe.mutate({
1160
+ pkValues: j,
1161
+ data: e
1162
+ }, {
1163
+ onSuccess: () => {
1164
+ n.forEach((e) => v.markCommitted(e)), r();
1165
+ },
1166
+ onError: (e) => {
1167
+ e instanceof S && e.code === "STALE_OBJECT" && ot(!0);
1168
+ }
1169
+ });
1170
+ }, [
1171
+ v,
1172
+ A,
1173
+ E,
1174
+ D,
1175
+ T,
1176
+ z,
1177
+ Wt,
1178
+ H,
1179
+ W,
1180
+ G,
1181
+ st,
1182
+ De,
1183
+ Fe,
1184
+ w,
1185
+ a,
1186
+ Q,
1187
+ X,
1188
+ Z,
1189
+ j
1190
+ ]), Kt = P((e, t) => {
1191
+ K((n) => ({
1192
+ ...n ?? {},
1193
+ [e]: t
1194
+ }));
1195
+ }, []), qt = P(() => {
1196
+ !j || A || !oe || Ie.mutate(j);
1197
+ }, [
1198
+ j,
1199
+ A,
1200
+ oe,
1201
+ Ie
1202
+ ]), Jt = I(() => ht(G, f), [G, f]), Yt = Object.keys(Jt).length > 0;
1203
+ if (!b || !w) return null;
1204
+ if (!A && ge) return /* @__PURE__ */ B(He, {});
1205
+ if (!A && !X || jt) return /* @__PURE__ */ V("div", {
1206
+ style: { padding: 24 },
1207
+ children: [/* @__PURE__ */ V("div", {
1208
+ style: {
1209
+ display: "flex",
1210
+ alignItems: "center",
1211
+ gap: 8,
1212
+ marginBottom: 8
1213
+ },
1214
+ children: [Vt && /* @__PURE__ */ B(ae, {
1215
+ icon: /* @__PURE__ */ B(e.back, { size: 14 }),
1216
+ onClick: Bt.goBack,
1217
+ title: "Back"
1218
+ }), /* @__PURE__ */ B("h1", {
1219
+ style: {
1220
+ margin: 0,
1221
+ fontSize: 18,
1222
+ fontWeight: 600,
1223
+ color: "var(--text)"
1224
+ },
1225
+ children: "Not Found"
1226
+ })]
1227
+ }), /* @__PURE__ */ B("p", {
1228
+ style: { color: "var(--text-3)" },
1229
+ children: "Record not found."
1230
+ })]
1231
+ });
1232
+ let Xt = w.display, Zt = h(b.display?.name) || h(Xt.name), Qt = i(X, w), $t = A ? `New ${Zt}` : Qt ? String(Qt) : Zt, en = De.isPending || Fe.isPending, tn = b.responsive?.[y.category]?.layout, nn = tn?.tabs ?? (y.isPhone ? "sections" : void 0), rn = tn?.header_card === !0 ? Be({
1233
+ entity: w,
1234
+ screen: b
1235
+ }) : void 0, $ = {
1236
+ schema: f,
1237
+ entity: w,
1238
+ entityCode: T,
1239
+ recordId: M ?? k ?? "",
1240
+ record: J ? {
1241
+ ...X ?? {},
1242
+ ...z
1243
+ } : X ?? {},
1244
+ isNew: A,
1245
+ mode: J ? "edit" : "display",
1246
+ onFieldChange: J ? Rt : void 0,
1247
+ refs: Et,
1248
+ objectProperties: (() => {
1249
+ let e = We ?? [];
1250
+ if (!J || Object.keys(W).length === 0) return e.length > 0 ? e : void 0;
1251
+ let t = e.map((e) => W[e.property_code] === void 0 ? e : {
1252
+ ...e,
1253
+ value: W[e.property_code]
1254
+ });
1255
+ for (let [n, r] of Object.entries(W)) e.some((e) => e.property_code === n) || t.push({
1256
+ property_code: n,
1257
+ name: {},
1258
+ type: "string",
1259
+ value: r
1260
+ });
1261
+ return t;
1262
+ })(),
1263
+ onSetProperty: A || !D ? void 0 : J ? (e, t) => nt((n) => ({
1264
+ ...n,
1265
+ [e]: t
1266
+ })) : void 0,
1267
+ isPropertyPending: !1,
1268
+ objectStatuses: (() => {
1269
+ let e = Ue ?? [];
1270
+ if (!J || Object.keys(H).length === 0) return e.length > 0 ? e : void 0;
1271
+ let t = e.map((e) => H[e.group_code] === void 0 ? e : {
1272
+ ...e,
1273
+ status_code: H[e.group_code]
1274
+ });
1275
+ for (let [n, r] of Object.entries(H)) e.some((e) => e.group_code === n) || t.push({
1276
+ group_code: n,
1277
+ status_code: r,
1278
+ status_name: {},
1279
+ set_at: p()
1280
+ });
1281
+ return t;
1282
+ })(),
1283
+ onSetStatus: A || !D ? void 0 : J ? (e, t) => U((n) => ({
1284
+ ...n,
1285
+ [e]: t
1286
+ })) : void 0,
1287
+ isStatusPending: !1,
1288
+ pendingChildren: J ? G : void 0,
1289
+ onChildrenChange: J ? Kt : void 0,
1290
+ childValidationErrors: J ? Jt : void 0,
1291
+ fieldErrors: J && ut ? Ut : void 0,
1292
+ detailTabsPresentation: nn,
1293
+ relatedRecordsPresentation: tn?.related_records
1294
+ }, an = !!b.sidebar && b.sidebar.length > 0, on = tn?.sidebar === "hidden", sn = an && !on && !y.isDesktop, cn = an && !on && y.isDesktop, ln = !A && X ? /* @__PURE__ */ B(it, {
1295
+ screen: b,
1296
+ entity: w,
1297
+ entityCode: T,
1298
+ record: X,
1299
+ refs: Et,
1300
+ objectStatuses: Ue,
1301
+ schema: f,
1302
+ locale: Ht
1303
+ }) : void 0, un = /* @__PURE__ */ B(Ct, {
1304
+ title: $t,
1305
+ recordId: k,
1306
+ editing: J,
1307
+ isNew: A,
1308
+ isRecordDeleted: Ot,
1309
+ dirty: N,
1310
+ isSaving: en,
1311
+ hasChildErrors: Yt,
1312
+ hasFieldErrors: ut && Wt,
1313
+ canRestore: oe,
1314
+ entity: w,
1315
+ screen: b,
1316
+ globalActions: f?.actions,
1317
+ entityCode: T,
1318
+ record: X,
1319
+ id: k,
1320
+ listRoute: Q,
1321
+ listRouteExists: !!zt,
1322
+ highlights: ln,
1323
+ showBack: Vt,
1324
+ onBack: Bt.goBack,
1325
+ onCancelEdit: Lt,
1326
+ onSave: Gt,
1327
+ onRestore: qt,
1328
+ isRestoring: Ie.isPending,
1329
+ refreshControl: {
1330
+ refetch: me.refetch,
1331
+ isFetching: me.isFetching,
1332
+ isLoading: me.isLoading,
1333
+ isLive: Te
1334
+ },
1335
+ isRealtimeEntity: w?.realtime === !0,
1336
+ canManageTemplates: pe(f)
1337
+ }), dn = Ot && /* @__PURE__ */ V("div", {
1338
+ style: {
1339
+ display: "flex",
1340
+ alignItems: "center",
1341
+ gap: 8,
1342
+ padding: "10px 14px",
1343
+ marginBottom: 12,
1344
+ borderRadius: 8,
1345
+ border: "1px solid var(--danger)",
1346
+ background: "var(--danger-soft)",
1347
+ color: "var(--danger)",
1348
+ fontSize: 12.5
1349
+ },
1350
+ children: [/* @__PURE__ */ B(e.warning, { size: 14 }), /* @__PURE__ */ V("span", { children: ["This record was deleted on ", _(String(X[w.soft_delete]))] })]
1351
+ }), fn = at && /* @__PURE__ */ V("div", {
1352
+ style: {
1353
+ display: "flex",
1354
+ alignItems: "center",
1355
+ gap: 8,
1356
+ padding: "10px 14px",
1357
+ marginBottom: 12,
1358
+ borderRadius: 8,
1359
+ border: "1px solid var(--warn)",
1360
+ background: "var(--warn-soft)",
1361
+ color: "var(--warn)",
1362
+ fontSize: 12.5
1363
+ },
1364
+ children: [/* @__PURE__ */ B(e.warning, { size: 14 }), /* @__PURE__ */ B("span", { children: "This record changed on the server while you were viewing or editing it." })]
1365
+ }), pn = J && ut && Wt && /* @__PURE__ */ B(rt, {
1366
+ errors: Object.entries(Ut).map(([e, t]) => {
1367
+ let n = w.fields.get(e);
1368
+ return {
1369
+ name: e,
1370
+ label: n ? m(n, e, f?.entities) : e,
1371
+ message: t
1372
+ };
1373
+ }),
1374
+ onJump: (e) => {
1375
+ let t = document.getElementById(`${T}-${e}`);
1376
+ t && (t.scrollIntoView({
1377
+ block: "center",
1378
+ behavior: "smooth"
1379
+ }), t.focus?.());
1380
+ }
1381
+ }), mn = Re && !A && !(b.items && b.items.length > 0) && /* @__PURE__ */ B("div", {
1382
+ className: "mb-4",
1383
+ children: /* @__PURE__ */ B(Ke, {
1384
+ statusGroups: w.status_groups ?? {},
1385
+ objectStatuses: $.objectStatuses,
1386
+ onSetStatus: D && J ? (e, t) => U((n) => ({
1387
+ ...n,
1388
+ [e]: t
1389
+ })) : gt,
1390
+ isPending: !1,
1391
+ mode: J ? "edit" : "display"
1392
+ })
1393
+ }), hn = w.evidence_covered && !A && X && /* @__PURE__ */ B("div", {
1394
+ className: "mb-4",
1395
+ children: /* @__PURE__ */ B(lt, { evidence: X.$evidence })
1396
+ }), gn = /* @__PURE__ */ V(Qe, { children: [
1397
+ rn && (X || A) && /* @__PURE__ */ B(bt, {
1398
+ card: rn,
1399
+ entity: w,
1400
+ record: $.record,
1401
+ objectStatuses: $.objectStatuses,
1402
+ objectProperties: $.objectProperties
1403
+ }),
1404
+ b.items && b.items.length > 0 && (X || A) && f && /* @__PURE__ */ B(qe, {
1405
+ nodes: b.items,
1406
+ ctx: $
1407
+ }),
1408
+ !A && k && T && w.associations && Object.keys(w.associations).length > 0 && f && /* @__PURE__ */ B($e, {
1409
+ entityCode: T,
1410
+ recordId: M ?? k ?? "",
1411
+ associations: w.associations,
1412
+ schema: f
1413
+ }),
1414
+ !A && k && T && /* @__PURE__ */ B(tt, {
1415
+ entityCode: T,
1416
+ objectId: M ?? k,
1417
+ canGenerateOne: !!w?.documents?.generate_one,
1418
+ canManageTemplates: pe(f)
1419
+ }),
1420
+ !A && X && f && /* @__PURE__ */ B(ct, {
1421
+ screen: b,
1422
+ entity: w,
1423
+ entityCode: T,
1424
+ record: X,
1425
+ refs: Et,
1426
+ schema: f,
1427
+ locale: Ht
1428
+ })
1429
+ ] });
1430
+ if (cn) return /* @__PURE__ */ V("div", {
1431
+ style: {
1432
+ height: "100%",
1433
+ display: "flex",
1434
+ overflow: "hidden",
1435
+ background: "var(--background)"
1436
+ },
1437
+ children: [
1438
+ /* @__PURE__ */ V("div", {
1439
+ style: {
1440
+ flex: 1,
1441
+ minWidth: 0,
1442
+ display: "flex",
1443
+ flexDirection: "column",
1444
+ height: "100%"
1445
+ },
1446
+ children: [/* @__PURE__ */ V("div", {
1447
+ style: {
1448
+ flexShrink: 0,
1449
+ padding: "14px 20px 8px"
1450
+ },
1451
+ children: [
1452
+ un,
1453
+ fn,
1454
+ dn,
1455
+ pn,
1456
+ mn,
1457
+ hn
1458
+ ]
1459
+ }), /* @__PURE__ */ B("div", {
1460
+ ref: At,
1461
+ style: {
1462
+ flex: 1,
1463
+ minHeight: 0,
1464
+ overflowY: "auto",
1465
+ padding: "4px 20px 24px",
1466
+ display: "flex",
1467
+ flexDirection: "column",
1468
+ gap: 16
1469
+ },
1470
+ children: gn
1471
+ })]
1472
+ }),
1473
+ /* @__PURE__ */ B("div", {
1474
+ className: "detail-resize-handle",
1475
+ onMouseDown: Tt,
1476
+ title: "Drag to resize",
1477
+ children: /* @__PURE__ */ B("div", { style: {
1478
+ position: "absolute",
1479
+ top: 0,
1480
+ bottom: 0,
1481
+ left: "50%",
1482
+ transform: "translateX(-50%)",
1483
+ width: 1,
1484
+ background: "var(--border)"
1485
+ } })
1486
+ }),
1487
+ /* @__PURE__ */ B("div", {
1488
+ ref: wt,
1489
+ style: {
1490
+ flexShrink: 0,
1491
+ height: "100%",
1492
+ width: `${xt}px`
1493
+ },
1494
+ children: (X || A) && f && /* @__PURE__ */ B(qe, {
1495
+ nodes: b.sidebar,
1496
+ ctx: $
1497
+ })
1498
+ })
1499
+ ]
1500
+ });
1501
+ let _n = y.isPhone ? 12 : 24;
1502
+ return /* @__PURE__ */ V("div", {
1503
+ style: {
1504
+ height: "100%",
1505
+ display: "flex",
1506
+ flexDirection: "column",
1507
+ overflow: "hidden",
1508
+ background: "var(--background)"
1509
+ },
1510
+ children: [/* @__PURE__ */ V("div", {
1511
+ style: {
1512
+ flexShrink: 0,
1513
+ padding: y.isPhone ? "14px 12px 8px" : "24px 24px 8px"
1514
+ },
1515
+ children: [
1516
+ un,
1517
+ fn,
1518
+ dn,
1519
+ pn,
1520
+ mn,
1521
+ hn
1522
+ ]
1523
+ }), /* @__PURE__ */ V("div", {
1524
+ ref: At,
1525
+ style: {
1526
+ flex: 1,
1527
+ minHeight: 0,
1528
+ overflowY: "auto",
1529
+ padding: `4px ${_n}px calc(24px + var(--safe-area-bottom, 0px))`,
1530
+ display: "flex",
1531
+ flexDirection: "column",
1532
+ gap: 16,
1533
+ minWidth: 0,
1534
+ WebkitOverflowScrolling: "touch"
1535
+ },
1536
+ children: [gn, sn && (X || A) && f && /* @__PURE__ */ B("div", {
1537
+ "data-testid": "detail-sidebar-inline",
1538
+ style: {
1539
+ display: "flex",
1540
+ flexDirection: "column",
1541
+ gap: 16,
1542
+ minWidth: 0
1543
+ },
1544
+ children: /* @__PURE__ */ B(qe, {
1545
+ nodes: b.sidebar,
1546
+ ctx: $
1547
+ })
1548
+ })]
1549
+ })]
1550
+ });
1551
+ }
1552
+ function bt({ card: e, entity: t, record: n, objectStatuses: r, objectProperties: a }) {
1553
+ let o = (e) => {
1554
+ let i = xt(t, e, n, r, a);
1555
+ return i != null && c(i) !== "";
1556
+ }, s = (e) => c(xt(t, e, n, r, a)) || /* @__PURE__ */ B("span", {
1557
+ style: { color: "var(--text-3)" },
1558
+ children: "-"
1559
+ }), l = c(e.titleUsesDisplay ? i(n, t) : e.titleField ? xt(t, e.titleField, n, r, a) : void 0) || h(t.display?.name) || "Record", u = e.badgeFields.filter((t) => !e.hideEmptyFields || o(t)), d = e.bodyFields.filter((t) => !e.hideEmptyFields || o(t)), f = e.metaFields.filter((t) => !e.hideEmptyFields || o(t));
1560
+ return /* @__PURE__ */ V("section", {
1561
+ "data-testid": "detail-header-card",
1562
+ style: {
1563
+ width: "100%",
1564
+ minWidth: 0,
1565
+ border: "1px solid var(--border)",
1566
+ borderRadius: 8,
1567
+ background: "var(--surface)",
1568
+ boxShadow: "var(--shadow-xs)",
1569
+ padding: 14,
1570
+ boxSizing: "border-box"
1571
+ },
1572
+ children: [
1573
+ /* @__PURE__ */ V("div", {
1574
+ style: { minWidth: 0 },
1575
+ children: [/* @__PURE__ */ B("div", {
1576
+ style: {
1577
+ fontSize: 15,
1578
+ lineHeight: 1.25,
1579
+ fontWeight: 700,
1580
+ color: "var(--text)",
1581
+ overflowWrap: "anywhere"
1582
+ },
1583
+ children: l
1584
+ }), e.subtitleField && /* @__PURE__ */ B("div", {
1585
+ style: {
1586
+ marginTop: 4,
1587
+ fontSize: 12.5,
1588
+ lineHeight: 1.35,
1589
+ color: "var(--text-3)",
1590
+ overflowWrap: "anywhere"
1591
+ },
1592
+ children: s(e.subtitleField)
1593
+ })]
1594
+ }),
1595
+ u.length > 0 && /* @__PURE__ */ B("div", {
1596
+ style: {
1597
+ display: "flex",
1598
+ flexWrap: "wrap",
1599
+ gap: 6,
1600
+ marginTop: 10
1601
+ },
1602
+ children: u.map((e) => /* @__PURE__ */ B("span", {
1603
+ style: {
1604
+ minWidth: 0,
1605
+ maxWidth: "100%",
1606
+ borderRadius: 999,
1607
+ background: "var(--surface-2)",
1608
+ color: "var(--text-2)",
1609
+ padding: "2px 8px",
1610
+ fontSize: 12,
1611
+ lineHeight: 1.4,
1612
+ overflowWrap: "anywhere"
1613
+ },
1614
+ children: s(e)
1615
+ }, e))
1616
+ }),
1617
+ d.length > 0 && /* @__PURE__ */ B("dl", {
1618
+ style: {
1619
+ display: "grid",
1620
+ gridTemplateColumns: "minmax(84px, max-content) minmax(0, 1fr)",
1621
+ gap: "6px 10px",
1622
+ margin: "12px 0 0",
1623
+ fontSize: 12.5,
1624
+ lineHeight: 1.35
1625
+ },
1626
+ children: d.map((e) => /* @__PURE__ */ V("div", {
1627
+ style: { display: "contents" },
1628
+ children: [/* @__PURE__ */ B("dt", {
1629
+ style: { color: "var(--text-3)" },
1630
+ children: St(t, e)
1631
+ }), /* @__PURE__ */ B("dd", {
1632
+ style: {
1633
+ margin: 0,
1634
+ color: "var(--text-2)",
1635
+ minWidth: 0,
1636
+ overflowWrap: "anywhere"
1637
+ },
1638
+ children: s(e)
1639
+ })]
1640
+ }, e))
1641
+ }),
1642
+ f.length > 0 && /* @__PURE__ */ B("div", {
1643
+ style: {
1644
+ display: "flex",
1645
+ flexWrap: "wrap",
1646
+ gap: 10,
1647
+ marginTop: 10,
1648
+ color: "var(--text-3)",
1649
+ fontSize: 11.5
1650
+ },
1651
+ children: f.map((e) => /* @__PURE__ */ V("span", {
1652
+ style: {
1653
+ minWidth: 0,
1654
+ overflowWrap: "anywhere"
1655
+ },
1656
+ children: [
1657
+ St(t, e),
1658
+ ": ",
1659
+ s(e)
1660
+ ]
1661
+ }, e))
1662
+ })
1663
+ ]
1664
+ });
1665
+ }
1666
+ function xt(e, t, n, r, i) {
1667
+ if (t.startsWith("$status.")) {
1668
+ let e = t.slice(8), n = r?.find((t) => t.group_code === e);
1669
+ return h(n?.status_name) || n?.status_code;
1670
+ }
1671
+ if (t.startsWith("$property.")) {
1672
+ let e = t.slice(10);
1673
+ return i?.find((t) => t.property_code === e)?.value;
1674
+ }
1675
+ return Ee(e, n, t);
1676
+ }
1677
+ function St(e, t) {
1678
+ if (t.startsWith("$status.")) return t.slice(8);
1679
+ if (t.startsWith("$property.")) return t.slice(10);
1680
+ let n = e.fields.get(t);
1681
+ return n ? m(n, t) : t;
1682
+ }
1683
+ function Ct({ title: r, recordId: i, editing: o, isNew: s, isRecordDeleted: c, dirty: u, isSaving: d, hasChildErrors: f, hasFieldErrors: p, canRestore: m, entity: g, screen: _, globalActions: b, entityCode: x, record: S, id: C, listRoute: w, listRouteExists: te, highlights: E, showBack: ne, onBack: re, onCancelEdit: ie, onSave: ae, onRestore: oe, isRestoring: se, refreshControl: ce, isRealtimeEntity: le, canManageTemplates: k }) {
1684
+ let { run: A } = T(), j = he("detail"), M = Fe(), de = ee(), fe = n(), pe = a(_?.action_layout, g?.action_layout, g?.actions, b, "detail_toolbar"), ge = v(a(_?.action_layout, g?.action_layout, g?.actions, b, "detail"), g?.actions, b, S ?? {}, []), _e = v(pe, g?.actions, b, S ?? {}, []), ve = I(() => {
1685
+ if (!g) return;
1686
+ let e = C ? [C] : [];
1687
+ return {
1688
+ entity: g,
1689
+ entityCode: x ?? "",
1690
+ screen: _,
1691
+ screenRoute: _?.route ?? "",
1692
+ selectedRows: S ? [S] : [],
1693
+ selectedIds: e,
1694
+ locale: fe,
1695
+ tabNavigate: (e, t) => M(e, {
1696
+ title: t?.title,
1697
+ icon: t?.icon,
1698
+ search: t?.search
1699
+ }),
1700
+ runActionApi: (e, t) => O(e, t)
1701
+ };
1702
+ }, [
1703
+ g,
1704
+ x,
1705
+ _,
1706
+ C,
1707
+ S,
1708
+ fe,
1709
+ M
1710
+ ]), xe = (e, t) => {
1711
+ let n = Ie(e, t, { row: S ?? void 0 });
1712
+ if (n === null) return;
1713
+ let r = C ? [C] : [], i = e === "__delete" && te ? w : null;
1714
+ return A({
1715
+ action: t,
1716
+ title: h(t.display?.name) || e,
1717
+ row: S ?? void 0,
1718
+ execute: (e) => O(n, y(e, r)),
1719
+ onSuccess: i ? () => {
1720
+ ue.getState().kill(be(location)), de(i, { replace: !0 });
1721
+ } : void 0
1722
+ });
1723
+ }, Se = j.isVisible("show_actions") && !s && C && ge.length > 0 ? /* @__PURE__ */ B(De, {
1724
+ layout: ge,
1725
+ row: S,
1726
+ onRun: xe,
1727
+ kind: "detail",
1728
+ entityActions: g?.actions,
1729
+ globalActions: b,
1730
+ reservedRightWidth: 0,
1731
+ widgetContext: ve,
1732
+ constrain: !1
1733
+ }) : null, Ce = !s && C ? /* @__PURE__ */ B(ye, {
1734
+ liveObject: ce,
1735
+ realtime: le
1736
+ }) : null, we = j.isVisible("show_actions") && !s && C && _e.length > 0 ? /* @__PURE__ */ V("div", {
1737
+ style: {
1738
+ display: "flex",
1739
+ justifyContent: "flex-end",
1740
+ alignItems: "center",
1741
+ gap: 8,
1742
+ marginTop: 10
1743
+ },
1744
+ children: [Se ? null : Ce, /* @__PURE__ */ B(De, {
1745
+ layout: _e,
1746
+ row: S,
1747
+ onRun: xe,
1748
+ kind: "detail",
1749
+ entityActions: g?.actions,
1750
+ globalActions: b,
1751
+ reservedRightWidth: 0,
1752
+ widgetContext: ve,
1753
+ ariaLabel: Se ? "Detail toolbar actions" : "Page actions"
1754
+ })]
1755
+ }) : null, Te = j.isVisible("show_actions") && !s && C && x ? /* @__PURE__ */ B(me, {
1756
+ entityCode: x,
1757
+ scope: "detail",
1758
+ objectIds: [C],
1759
+ capability: g?.documents,
1760
+ canManageTemplates: k
1761
+ }) : null, Ee = c ? m ? /* @__PURE__ */ B(D, {
1762
+ kind: "primary",
1763
+ icon: B(se ? l : e.refresh, { size: 13 }),
1764
+ onClick: oe,
1765
+ disabled: se,
1766
+ children: se ? "Restoring…" : "Restore"
1767
+ }) : null : o ? /* @__PURE__ */ V(Qe, { children: [/* @__PURE__ */ B(D, {
1768
+ icon: /* @__PURE__ */ B(e.x, { size: 13 }),
1769
+ onClick: ie,
1770
+ disabled: d,
1771
+ children: "Cancel"
1772
+ }), /* @__PURE__ */ B(D, {
1773
+ kind: "primary",
1774
+ icon: B(d ? l : e.save, { size: 13 }),
1775
+ onClick: ae,
1776
+ disabled: d || f || p,
1777
+ title: f ? "Fix errors in child rows" : p ? "Fix the highlighted fields" : void 0,
1778
+ children: d ? "Saving…" : "Save"
1779
+ })] }) : !s && C ? Se ? /* @__PURE__ */ V("span", {
1780
+ style: { display: "contents" },
1781
+ children: [Te, Se]
1782
+ }) : Te : null;
1783
+ return /* @__PURE__ */ V(Qe, { children: [/* @__PURE__ */ B(ut, {
1784
+ icon: g?.display.icon ? /* @__PURE__ */ B(t, {
1785
+ name: g.display.icon,
1786
+ size: 16
1787
+ }) : void 0,
1788
+ title: r,
1789
+ description: h(_?.display?.description) || h(g?.display?.description),
1790
+ recordId: i,
1791
+ highlights: E,
1792
+ identityControls: !c && !o && !s ? Ce : null,
1793
+ mode: s ? "create" : o ? "edit" : "display",
1794
+ dirty: u,
1795
+ showBack: ne,
1796
+ onBack: re,
1797
+ right: Ee,
1798
+ showTitle: j.isVisible("show_title")
1799
+ }), we] });
1800
+ }
1801
+ //#endregion
1802
+ export { J as SmartDetailPage };