@object-ui/plugin-detail 14.1.0 → 16.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,93 @@
1
1
  # @object-ui/plugin-detail
2
2
 
3
+ ## 16.0.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5534535: feat(grid): built-in row Edit/Delete honor per-record CEL predicates (#2614)
8
+
9
+ The object's `userActions.edit` / `userActions.delete` now also accept an
10
+ object form `{ enabled?, visibleWhen?, disabledWhen? }`. The predicates are
11
+ evaluated per row on the canonical CEL engine (`useRowPredicate`, the same
12
+ machinery custom row actions use): `visibleWhen` false → the built-in
13
+ Edit/Delete item is not rendered for that row (fail-closed); `disabledWhen`
14
+ true → rendered disabled (fail-soft). Wired through ObjectGrid's
15
+ RowActionMenu and the data-table's row overflow menu (the related-list
16
+ path), with the app-shell `crudAffordances` mirror kept in lockstep.
17
+ Omitting the predicates (or using plain booleans) keeps today's behavior
18
+ bit-for-bit; declared predicates evaluate only when a row's menu opens, so
19
+ grid rendering cost is unchanged.
20
+
21
+ ### Patch Changes
22
+
23
+ - 59d4fa9: fix(detail): show the "Locked for approval" band on request-tracked backends (objectui#2618)
24
+
25
+ The DetailView approval-lock band keyed only off the record's own
26
+ `approval_status` field, so it never rendered on backends that track the lock
27
+ via an open approval request and never materialize that field — even though
28
+ the lock was real (writes rejected with `RECORD_LOCKED`). The record-level
29
+ `InlineEditContext` now carries the host's `locked`/`lockedReason` signal
30
+ (the same dual-source `approvalLocked` that already gates `canEdit` in
31
+ `RecordDetailView`), and the band renders from it while keeping `DetailView`
32
+ DataSource-agnostic. Also backfills the approval-lock strings into the detail
33
+ translation defaults so a bare DetailView shows the label, not the raw i18n key.
34
+
35
+ - 9d4a429: fix(form+detail): keep single-file children as inline grids; drop non-spec `attachment` handling
36
+
37
+ Two follow-ups to the upload-in-grid work (objectui#2360):
38
+
39
+ - **#2654** — Now that `file`/`image`/`avatar` fields render a compact upload
40
+ cell in the line-item grid, a child object with a _single_ such field no
41
+ longer flips the smart `inlineEdit` default to a per-row form. `resolveInlineMode`
42
+ splits the old `FORM_ONLY_TYPES`: truly form-only types (textarea / richtext /
43
+ html / markdown / json / location / address) still tip to `form` on their own,
44
+ while file-family types only tip when several rich fields pile up
45
+ (`RICH_FIELD_FORM_THRESHOLD`, default 2). An explicit `inlineEdit` always wins.
46
+
47
+ - **#2655** — `attachment` is not a `@objectstack/spec` field type (the spec
48
+ media types are file/image/avatar/video/audio), so the renderer no longer
49
+ models it: removed from `fieldTypeToColumnType`, the inline-mode heuristic, and
50
+ `RelatedList`'s auto-column `SKIP_TYPES`. Contract-first cleanup — the renderer
51
+ stops fossilizing a phantom type (AGENTS.md #0.1).
52
+
53
+ - Updated dependencies [d3e19ed]
54
+ - Updated dependencies [59d4fa9]
55
+ - Updated dependencies [4c7c47f]
56
+ - Updated dependencies [210806a]
57
+ - Updated dependencies [b4ef588]
58
+ - Updated dependencies [ca0f5f0]
59
+ - Updated dependencies [5534535]
60
+ - Updated dependencies [9b8f978]
61
+ - Updated dependencies [195a651]
62
+ - Updated dependencies [33b4995]
63
+ - @object-ui/react@16.0.0
64
+ - @object-ui/components@16.0.0
65
+ - @object-ui/types@16.0.0
66
+ - @object-ui/i18n@16.0.0
67
+ - @object-ui/fields@16.0.0
68
+ - @object-ui/core@16.0.0
69
+ - @object-ui/permissions@16.0.0
70
+
71
+ ## 15.0.0
72
+
73
+ ### Patch Changes
74
+
75
+ - bb22788: Inline-edit field enrichment passes `min`/`max`/`step` through to the numeric
76
+ editors (objectui#2572 live dogfood find). Both `DetailSection` and
77
+ `HeaderHighlight` copy an explicit whitelist of objectSchema keys into the
78
+ enriched field they hand `InlineFieldInput`; the numeric range/step
79
+ constraints were missing from that list, so a currency field declaring
80
+ `min: 0` rendered a number input with no range affordance. Adds a live e2e
81
+ spec (`e2e/live/inline-edit-polish-2572.spec.ts`) driving the whole #2572
82
+ polish set against the real showcase stack.
83
+ - @object-ui/types@15.0.0
84
+ - @object-ui/core@15.0.0
85
+ - @object-ui/i18n@15.0.0
86
+ - @object-ui/react@15.0.0
87
+ - @object-ui/components@15.0.0
88
+ - @object-ui/fields@15.0.0
89
+ - @object-ui/permissions@15.0.0
90
+
3
91
  ## 14.1.0
4
92
 
5
93
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"DetailSection.d.ts","sourceRoot":"","sources":["../src/DetailSection.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAqB/B,OAAO,KAAK,EAAE,iBAAiB,IAAI,qBAAqB,EAAkC,MAAM,kBAAkB,CAAC;AAsBnH;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAmBxF;AAED,MAAM,WAAW,oBAAoB;IACnC,oDAAoD;IACpD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,mDAAmD;IACnD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,qBAAqB,CAAC;IAC/B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gEAAgE;IAChE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IACpD;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,oEAAoE;IACpE,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,6FAA6F;IAC7F,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,oEAAoE;IACpE,aAAa,CAAC,EAAE,oBAAoB,CAAC;CACtC;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAictD,CAAC"}
1
+ {"version":3,"file":"DetailSection.d.ts","sourceRoot":"","sources":["../src/DetailSection.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAqB/B,OAAO,KAAK,EAAE,iBAAiB,IAAI,qBAAqB,EAAkC,MAAM,kBAAkB,CAAC;AAsBnH;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAmBxF;AAED,MAAM,WAAW,oBAAoB;IACnC,oDAAoD;IACpD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,mDAAmD;IACnD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,qBAAqB,CAAC;IAC/B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gEAAgE;IAChE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IACpD;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,oEAAoE;IACpE,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,6FAA6F;IAC7F,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,oEAAoE;IACpE,aAAa,CAAC,EAAE,oBAAoB,CAAC;CACtC;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAsctD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"DetailView.d.ts","sourceRoot":"","sources":["../src/DetailView.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAwC/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAA4B,MAAM,kBAAkB,CAAC;AAsE/F,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,gBAAgB,CAAC;IACzB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;OAIG;IACH,cAAc,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACjC;;;;OAIG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC5B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IACrC;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CAC5C;AAED,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAmsChD,CAAC"}
1
+ {"version":3,"file":"DetailView.d.ts","sourceRoot":"","sources":["../src/DetailView.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAwC/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAA4B,MAAM,kBAAkB,CAAC;AAsE/F,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,gBAAgB,CAAC;IACzB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;OAIG;IACH,cAAc,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACjC;;;;OAIG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC5B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IACrC;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CAC5C;AAED,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CA4sChD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"HeaderHighlight.d.ts","sourceRoot":"","sources":["../src/HeaderHighlight.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAS/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAQvD,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB;AAED,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CA+N1D,CAAC"}
1
+ {"version":3,"file":"HeaderHighlight.d.ts","sourceRoot":"","sources":["../src/HeaderHighlight.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAS/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAQvD,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB;AAED,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAoO1D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"RelatedList.d.ts","sourceRoot":"","sources":["../src/RelatedList.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAoB/B,OAAO,EAAkD,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAY5G,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,kBAAkB,CAAC;AAMlE,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACb,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;IACnB,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,iDAAiD;IACjD,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;IAC/B,mDAAmD;IACnD,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;IACjC;;;;;;;;OAQG;IACH,GAAG,CAAC,EAAE;QACJ,MAAM,EAAE;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,UAAU,CAAC,EAAE,MAAM,CAAC;YAAC,UAAU,CAAC,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,GAAG,CAAA;SAAE,CAAC;QACnF,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,2DAA2D;IAC3D,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;IAChC;;;OAGG;IACH,UAAU,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACnC,iEAAiE;IACjE,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,EAAE,GAAG,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9E;;;;OAIG;IACH,cAAc,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACvC,8DAA8D;IAC9D,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxE,6DAA6D;IAC7D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4BAA4B;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,4BAA4B;IAC5B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,sCAAsC;IACtC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAgBD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC;IAC1C,MAAM,EAAE,mBAAmB,CAAC;IAC5B,eAAe,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxE,CAmBA,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAsxBlD,CAAC"}
1
+ {"version":3,"file":"RelatedList.d.ts","sourceRoot":"","sources":["../src/RelatedList.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAoB/B,OAAO,EAAkD,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAY5G,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,kBAAkB,CAAC;AAMlE,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACb,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;IACnB,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,iDAAiD;IACjD,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;IAC/B,mDAAmD;IACnD,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;IACjC;;;;;;;;OAQG;IACH,GAAG,CAAC,EAAE;QACJ,MAAM,EAAE;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,UAAU,CAAC,EAAE,MAAM,CAAC;YAAC,UAAU,CAAC,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,GAAG,CAAA;SAAE,CAAC;QACnF,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,2DAA2D;IAC3D,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;IAChC;;;OAGG;IACH,UAAU,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACnC,iEAAiE;IACjE,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,EAAE,GAAG,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9E;;;;OAIG;IACH,cAAc,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACvC,8DAA8D;IAC9D,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxE,6DAA6D;IAC7D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4BAA4B;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,4BAA4B;IAC5B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,sCAAsC;IACtC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAgBD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC;IAC1C,MAAM,EAAE,mBAAmB,CAAC;IAC5B,eAAe,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxE,CAmBA,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAoyBlD,CAAC"}
package/dist/index.js CHANGED
@@ -196,7 +196,14 @@ var Qt = {
196
196
  "detail.concurrentUpdateUpdatedAt": "Updated at {{when}}",
197
197
  "detail.concurrentUpdateReload": "Reload latest",
198
198
  "detail.concurrentUpdateOverwrite": "Overwrite anyway",
199
- "detail.concurrentUpdateCancel": "Cancel"
199
+ "detail.concurrentUpdateCancel": "Cancel",
200
+ "detail.lockedByApproval": "Locked for approval",
201
+ "detail.lockedTooltip": "This record has a pending approval request; editing is locked",
202
+ "detail.cancelApproval": "Recall approval",
203
+ "detail.cancelApprovalInFlight": "Recalling…",
204
+ "detail.cancelApprovalTooltip": "Recall the pending approval request to unlock this record",
205
+ "detail.cancelApprovalFailed": "Failed to recall approval",
206
+ "detail.cancelApprovalUnavailable": "Recalling approvals is not supported on this data source"
200
207
  }, $ = Zt(Qt, "detail.back");
201
208
  //#endregion
202
209
  //#region src/renderers/PermissionFacetLink.tsx
@@ -404,7 +411,7 @@ var ln = ({ section: e, data: t, className: n, objectSchema: r, objectName: a, i
404
411
  });
405
412
  let i = cn(e.span, I), d = r?.fields?.[e.name], f = { ...e };
406
413
  if (d) {
407
- !e.type && d.type && (f.type = d.type), d.options && !f.options && (f.options = d.options), d.currency && !f.currency && (f.currency = d.currency), d.precision !== void 0 && f.precision === void 0 && (f.precision = d.precision), d.scale !== void 0 && f.scale === void 0 && (f.scale = d.scale), d.format && !f.format && (f.format = d.format), d.widget && !f.widget && (f.widget = d.widget);
414
+ !e.type && d.type && (f.type = d.type), d.options && !f.options && (f.options = d.options), d.currency && !f.currency && (f.currency = d.currency), d.precision !== void 0 && f.precision === void 0 && (f.precision = d.precision), d.scale !== void 0 && f.scale === void 0 && (f.scale = d.scale), d.min !== void 0 && f.min === void 0 && (f.min = d.min), d.max !== void 0 && f.max === void 0 && (f.max = d.max), d.step !== void 0 && f.step === void 0 && (f.step = d.step), d.format && !f.format && (f.format = d.format), d.widget && !f.widget && (f.widget = d.widget);
408
415
  let t = d.reference_to || d.reference;
409
416
  t && !f.reference_to && (f.reference_to = t), d.reference_field && !f.reference_field && (f.reference_field = d.reference_field), d.dueLike !== void 0 && f.dueLike === void 0 && (f.dueLike = d.dueLike);
410
417
  }
@@ -866,7 +873,6 @@ var fn = ({ action: e, onToolbarAction: t }) => {
866
873
  if (e.length > 0) return e.slice(0, Math.max(1, te));
867
874
  }
868
875
  let d = e, f = /* @__PURE__ */ new Set([
869
- "attachment",
870
876
  "rich_text",
871
877
  "html",
872
878
  "json"
@@ -932,6 +938,10 @@ var fn = ({ action: e, onToolbarAction: t }) => {
932
938
  onRowClick: O
933
939
  };
934
940
  }
941
+ let e = q?.userActions?.edit, r = q?.userActions?.delete, i = (e) => typeof e == "object" && e && (e.visibleWhen != null || e.disabledWhen != null) ? {
942
+ visibleWhen: e.visibleWhen ?? void 0,
943
+ disabledWhen: e.disabledWhen ?? void 0
944
+ } : void 0;
935
945
  switch (t) {
936
946
  case "grid":
937
947
  case "table": return {
@@ -945,6 +955,8 @@ var fn = ({ action: e, onToolbarAction: t }) => {
945
955
  rowActions: Ge,
946
956
  onRowEdit: E,
947
957
  onRowDelete: D ? ze : void 0,
958
+ rowEditPredicates: i(e),
959
+ rowDeletePredicates: i(r),
948
960
  onRowClick: O,
949
961
  rowActionDefs: We ? k : void 0,
950
962
  onRowActionDef: We ? j : void 0
@@ -973,7 +985,8 @@ var fn = ({ action: e, onToolbarAction: t }) => {
973
985
  ze,
974
986
  O,
975
987
  Ke,
976
- n
988
+ n,
989
+ q
977
990
  ]), Ye = P ? "cursor-pointer select-none" : void 0, Xe = P ? () => ge((e) => !e) : void 0, Ze = dn(L), Qe = !oe && B.length === 0, $e = ie;
978
991
  return /* @__PURE__ */ Q(S, {
979
992
  className: W("shadow-none border-border/60 bg-transparent", Qe && "bg-muted/10", s),
@@ -1230,6 +1243,9 @@ var fn = ({ action: e, onToolbarAction: t }) => {
1230
1243
  ...d?.currencyConfig && { currencyConfig: d.currencyConfig },
1231
1244
  ...d?.precision !== void 0 && { precision: d.precision },
1232
1245
  ...d?.scale !== void 0 && { scale: d.scale },
1246
+ ...d?.min !== void 0 && { min: d.min },
1247
+ ...d?.max !== void 0 && { max: d.max },
1248
+ ...d?.step !== void 0 && { step: d.step },
1233
1249
  ...d?.format && { format: d.format },
1234
1250
  ...p && { reference_to: p },
1235
1251
  ...d?.reference_field && { reference_field: d.reference_field },
@@ -2285,7 +2301,7 @@ var Vn = ({ schema: e, dataSource: n, className: r, onEdit: a, onDelete: o, onBa
2285
2301
  objectSchema: A
2286
2302
  }),
2287
2303
  c && K.showHeader === !1 && (() => {
2288
- let e = h?.approval_status, t = e === "pending" || e === "in_approval";
2304
+ let e = h?.approval_status, t = (w?.locked ?? !1) || e === "pending" || e === "in_approval";
2289
2305
  return !t && !O ? null : /* @__PURE__ */ Q("div", {
2290
2306
  className: "flex flex-col items-end gap-1",
2291
2307
  children: [t && /* @__PURE__ */ Q("div", {
@@ -2293,7 +2309,7 @@ var Vn = ({ schema: e, dataSource: n, className: r, onEdit: a, onDelete: o, onBa
2293
2309
  children: [/* @__PURE__ */ Q("span", {
2294
2310
  role: "status",
2295
2311
  className: "inline-flex items-center gap-1 rounded-md border border-amber-300 bg-amber-50 px-2 py-1 text-xs text-amber-800",
2296
- title: P("detail.lockedTooltip"),
2312
+ title: w?.lockedReason ?? P("detail.lockedTooltip"),
2297
2313
  children: [/* @__PURE__ */ Z(Re, { className: "h-3 w-3" }), /* @__PURE__ */ Z("span", { children: P("detail.lockedByApproval") })]
2298
2314
  }), n?.cancelPendingApproval && /* @__PURE__ */ Q(x, {
2299
2315
  variant: "outline",
@@ -2657,7 +2673,7 @@ var Vn = ({ schema: e, dataSource: n, className: r, onEdit: a, onDelete: o, onBa
2657
2673
  "system",
2658
2674
  "append-only",
2659
2675
  "better-auth"
2660
- ]), E = y?.managedBy, D = y?.userActions?.edit ?? !(E != null && T.has(E)), O = (e.inlineEdit ?? !0) && D, k = {
2676
+ ]), E = y?.managedBy, D = y?.userActions?.edit, O = (typeof D == "object" && D ? D.enabled : D) ?? !(E != null && T.has(E)), k = (e.inlineEdit ?? !0) && O, A = {
2661
2677
  type: "detail-view",
2662
2678
  objectName: r.objectName,
2663
2679
  resourceId: r.recordId,
@@ -2668,15 +2684,15 @@ var Vn = ({ schema: e, dataSource: n, className: r, onEdit: a, onDelete: o, onBa
2668
2684
  fields: C,
2669
2685
  showBack: !1,
2670
2686
  showHeader: e.showHeader ?? !1,
2671
- inlineEdit: O
2687
+ inlineEdit: k
2672
2688
  };
2673
2689
  return /* @__PURE__ */ Z("div", {
2674
2690
  className: t,
2675
2691
  ...i,
2676
2692
  children: /* @__PURE__ */ Z(Vn, {
2677
- schema: k,
2693
+ schema: A,
2678
2694
  dataSource: r.dataSource,
2679
- inlineEdit: O
2695
+ inlineEdit: k
2680
2696
  })
2681
2697
  });
2682
2698
  }, Gn = (e) => typeof e == "string" ? e : e && typeof e == "object" && (e.field || e.name || e.key) || null, Kn = (e) => e?.id ?? e?._id ?? null, qn = (e) => {
@@ -1,4 +1,4 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@object-ui/core"),require("react"),require("@object-ui/components"),require("lucide-react"),require("@object-ui/react"),require("@object-ui/fields"),require("react-router-dom"),require("react/jsx-runtime"),require("@object-ui/permissions"),require("@object-ui/i18n"),require("@objectstack/spec/data"),require("@object-ui/types")):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`react`,`@object-ui/components`,`lucide-react`,`@object-ui/react`,`@object-ui/fields`,`react-router-dom`,`react/jsx-runtime`,`@object-ui/permissions`,`@object-ui/i18n`,`@objectstack/spec/data`,`@object-ui/types`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginDetail={},e.ObjectUICore,e.React,e.ObjectUIComponents,e.LucideReact,e.ObjectUIReact,e.ObjectUIFields,e.react_router_dom,e.jsxRuntime,e._object_ui_permissions,e._object_ui_i18n,e._objectstack_spec_data,e.ObjectUITypes))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var p=Object.create,m=Object.defineProperty,h=Object.getOwnPropertyDescriptor,g=Object.getOwnPropertyNames,_=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty,y=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=g(t),a=0,o=i.length,s;a<o;a++)s=i[a],!v.call(e,s)&&s!==n&&m(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=h(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:p(_(e)),y(t||!e||!e.__esModule?m(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var b=new Set([`textarea`,`markdown`,`html`,`grid`,`rich-text`,`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`]);function x(e){return b.has(e)}function S(e,t){let n;return n=e<=3?1:e<=8?2:e<=15?3:4,t!==void 0&&t<640?Math.min(n,1):n}function C(e,t){return t<=1?e:e.map(e=>e.span===void 0&&e.type&&x(e.type)?{...e,span:t}:e)}function w(e,t,n){if(t!==void 0)return{fields:C(e,t),columns:t};let r=S(e.length,n);return{fields:C(e,r),columns:r}}function T(e,t){return function(){try{let n=(0,a.useObjectTranslation)();return n.t(t)===t?{t:(t,n)=>{let r=e[t]||t;if(n)for(let[e,t]of Object.entries(n))r=r.replace(`{{${e}}}`,String(t));return r}}:{t:n.t}}catch{return{t:(t,n)=>{let r=e[t]||t;if(n)for(let[e,t]of Object.entries(n))r=r.replace(`{{${e}}}`,String(t));return r}}}}}var E={"detail.back":`Back`,"detail.edit":`Edit`,"detail.editInline":`Edit`,"detail.save":`Save`,"detail.saveChanges":`Save changes`,"detail.editFieldsInline":`Edit fields inline`,"detail.editInlineHint":`Double-click to edit`,"detail.cancel":`Cancel`,"detail.cancelEdit":`Discard changes`,"detail.openInNewTab":`Open in new tab`,"detail.share":`Share`,"detail.duplicate":`Duplicate`,"detail.export":`Export`,"detail.viewHistory":`View history`,"detail.delete":`Delete`,"detail.moreActions":`More actions`,"detail.addToFavorites":`Add to favorites`,"detail.removeFromFavorites":`Remove from favorites`,"detail.previousRecord":`Previous record`,"detail.nextRecord":`Next record`,"detail.recordOf":`{{current}} of {{total}}`,"detail.recordNotFound":`Record not found`,"detail.recordNotFoundDescription":`The record you are looking for does not exist or may have been deleted.`,"detail.goBack":`Go back`,"detail.details":`Details`,"detail.related":`Related`,"detail.relatedRecords":`{{count}} records`,"detail.relatedRecordOne":`{{count}} record`,"detail.noRelatedRecords":`No related records found`,"detail.loading":`Loading...`,"detail.copyToClipboard":`Copy to clipboard`,"detail.copied":`Copied!`,"detail.deleteConfirmation":`Are you sure you want to delete this record?`,"detail.editRecord":`Edit record`,"detail.viewAll":`View All`,"detail.new":`New`,"detail.emptyValue":`—`,"detail.noValue":`No value`,"detail.activity":`Activity`,"detail.copyRecordId":`Copy record ID`,"detail.showEmptyFields":`Show {{count}} empty fields`,"detail.hideEmptyFields":`Hide empty fields`,"detail.editRow":`Edit`,"detail.deleteRow":`Delete`,"detail.deleteRowConfirmation":`Are you sure you want to delete this record?`,"detail.actions":`Actions`,"detail.previousPage":`Previous`,"detail.nextPage":`Next`,"detail.pageOf":`Page {{current}} of {{total}}`,"detail.sortBy":`Sort by`,"detail.filterPlaceholder":`Filter...`,"detail.highlightFields":`Key Fields`,"detail.comments":`Comments`,"detail.searchComments":`Search comments…`,"detail.addCommentPlaceholder":`Add a comment… (Ctrl+Enter to submit)`,"detail.noMatchingComments":`No matching comments`,"detail.noCommentsYet":`No comments yet`,"detail.pinned":`Pinned`,"detail.pin":`Pin`,"detail.unpin":`Unpin`,"detail.justNow":`just now`,"detail.minutesAgo":`{{count}}m ago`,"detail.hoursAgo":`{{count}}h ago`,"detail.daysAgo":`{{count}}d ago`,"detail.createdBy":`Created by`,"detail.updatedBy":`Updated by`,"detail.created":`Created`,"detail.updated":`Updated`,"detail.dropFilesToUpload":`Drop files here or click to upload`,"detail.attachmentCount":`{{count}} attachment`,"detail.attachmentCountPlural":`{{count}} attachments`,"detail.removeAttachment":`Remove attachment`,"detail.unifiedDiff":`Unified diff`,"detail.sideBySideDiff":`Side-by-side diff`,"detail.noChanges":`No changes`,"detail.previousVersion":`Previous`,"detail.currentVersion":`Current`,"detail.discussion":`Discussion`,"detail.showDiscussion":`Show Discussion ({{count}})`,"detail.hideDiscussion":`Hide discussion`,"detail.bold":`Bold (Ctrl+B)`,"detail.italic":`Italic (Ctrl+I)`,"detail.listFormat":`List`,"detail.inlineCode":`Inline code`,"detail.mentionSomeone":`Mention someone`,"detail.preview":`Preview`,"detail.submitComment":`Submit (Ctrl+Enter)`,"detail.sendComment":`Send`,"detail.writeComment":`Write a comment…`,"detail.subscribedTooltip":`Subscribed — click to unsubscribe`,"detail.unsubscribedTooltip":`Subscribe to notifications`,"detail.firstRecord":`First record (Home)`,"detail.previousRecordKey":`Previous record (←)`,"detail.nextRecordKey":`Next record (→)`,"detail.lastRecord":`Last record (End)`,"detail.noRecords":`No records`,"detail.showEmptyRelated_one":`+ {{count}} empty`,"detail.showEmptyRelated_other":`+ {{count}} empty`,"detail.searchWhileNavigating":`Search while navigating`,"detail.searchRecords":`Search records…`,"detail.allActivity":`All Activity`,"detail.commentsOnly":`Comments Only`,"detail.fieldChangesFilter":`Field Changes`,"detail.tasksOnly":`Tasks Only`,"detail.leaveCommentPlaceholder":`Leave a comment… (Ctrl+Enter to submit)`,"detail.noActivity":`No activity recorded`,"detail.loadMore":`Load more`,"detail.edited":`(edited)`,"detail.via":`via {{source}}`,"detail.viewSource":`View source`,"detail.replyCount":`{{count}} reply`,"detail.replyCountPlural":`{{count}} replies`,"detail.replyPlaceholder":`Reply…`,"detail.filterActivity":`Filter activity`,"detail.openDiscussion":`Open discussion panel`,"detail.closeDiscussion":`Close discussion panel`,"detail.subscribeAriaLabel":`Subscribe to notifications`,"detail.unsubscribeAriaLabel":`Unsubscribe from notifications`,"detail.clearSearch":`Clear search`,"detail.concurrentUpdateTitle":`This record was modified by someone else`,"detail.concurrentUpdateDescription":`Another user saved a newer version of {{field}} while you were editing. To prevent silently overwriting their change, please choose how to resolve the conflict.`,"detail.concurrentUpdateYourEdit":`Your edit`,"detail.concurrentUpdateCurrentValue":`Current value`,"detail.concurrentUpdateUpdatedBy":`Updated by {{name}}`,"detail.concurrentUpdateUpdatedAt":`Updated at {{when}}`,"detail.concurrentUpdateReload":`Reload latest`,"detail.concurrentUpdateOverwrite":`Overwrite anyway`,"detail.concurrentUpdateCancel":`Cancel`},D=T(E,`detail.back`);function O(e){if(typeof e==`string`){let t=e.trim();if(!t)return null;try{return JSON.parse(t)}catch{return t}}return e??null}function k(e){let t=O(e);return t==null||t===``?0:Array.isArray(t)?t.length:typeof t==`object`?Object.keys(t).length:1}function A({value:e,field:t}){let{t:n}=D(),i=(0,a.useRecordContext)(),{appName:l}=(0,s.useParams)(),u=t?.name||``,d=i?.data?.name,f=l&&d?`/apps/${l}/metadata/permission/${encodeURIComponent(String(d))}`:null,p=k(e),m=p===0;return(0,c.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-2 gap-y-1 text-sm`,children:[(()=>{if(m)return(0,c.jsx)(`span`,{className:`text-muted-foreground`,children:n(`perm.facet.none`,{defaultValue:`None`})});if(u===`system_permissions`){let t=(0,o.parseCapabilityNames)(e),i=t.slice(0,6),a=t.length-i.length;return(0,c.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-1`,children:[i.map(e=>(0,c.jsx)(r.Badge,{variant:`outline`,children:e},e)),a>0&&(0,c.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:n(`perm.facet.more`,{count:a,defaultValue:`+${a} more`})})]})}return(0,c.jsx)(`span`,{className:`text-foreground`,children:(()=>{switch(u){case`object_permissions`:return n(`perm.facet.objects`,{count:p,defaultValue:`${p} object${p===1?``:`s`}`});case`field_permissions`:return n(`perm.facet.fields`,{count:p,defaultValue:`${p} field rule${p===1?``:`s`}`});case`row_level_security`:return n(`perm.facet.rls`,{count:p,defaultValue:`${p} RLS polic${p===1?`y`:`ies`}`});case`tab_permissions`:return n(`perm.facet.tabs`,{count:p,defaultValue:`${p} tab rule${p===1?``:`s`}`});case`admin_scope`:return n(`perm.facet.adminScope`,{defaultValue:`Delegated admin configured`});default:return String(p)}})()})})(),f?(0,c.jsx)(s.Link,{to:f,className:`text-primary hover:underline whitespace-nowrap`,children:n(`perm.facet.designInStudio`,{defaultValue:`Design in Studio →`})}):(0,c.jsx)(`span`,{className:`text-muted-foreground/60 whitespace-nowrap`,children:n(`perm.facet.designInStudioHint`,{defaultValue:`Design in Studio`})})]})}var j=new Set([`id`,`_id`,`__v`,`created`,`created_at`,`createdAt`,`created_by`,`modified`,`modified_by`,`updated_at`,`updatedAt`,`updated_by`,`deleted_at`,`is_deleted`,`deleted`,`instance_state`]),M=new Set([`formula`,`summary`,`rollup`,`auto_number`]);function N(e){if(e==null)return e;if(Array.isArray(e))return e.map(N);if(typeof e==`object`){let t=e;return t.id??t._id??t.value??``}return e}var P=({field:e,value:t,onChange:n,dataSource:r,autoFocus:i})=>{let a=e.type,s=e.widget;if(s===`permission-facet-link`)return(0,c.jsx)(A,{value:t,field:e});if(s===`capability-multiselect`)return(0,c.jsx)(o.CapabilityMultiSelectField,{value:t,onChange:e=>n(e),field:e,dataSource:r});if(a===`select`&&Array.isArray(e.options)&&e.options.length>0)return(0,c.jsx)(o.SelectField,{field:e,value:t==null?``:String(t),onChange:e=>n(e)});if(a===`boolean`)return(0,c.jsx)(o.BooleanField,{field:e,value:!!t,onChange:e=>n(e)});let l=a===`user`||a===`owner`,u=a===`lookup`||a===`master_detail`||a===`tree`||!!e.reference_to&&!M.has(a);if(l||u)return(0,c.jsx)(l?o.UserField:o.LookupField,{field:e,value:t,onChange:e=>n(e),dataSource:r});if(a===`number`)return(0,c.jsx)(o.NumberField,{field:e,value:t,onChange:e=>n(e),autoFocus:i});if(a===`currency`)return(0,c.jsx)(o.CurrencyField,{field:e,value:t,onChange:e=>n(e),autoFocus:i});if(a===`percent`)return(0,c.jsx)(o.PercentField,{field:e,value:t,onChange:e=>n(e),autoFocus:i});let d=a===`date`||a===`datetime`;return(0,c.jsx)(`input`,{type:d?`date`:`text`,autoFocus:i,className:`w-full px-2 py-1.5 text-sm border rounded-md bg-background focus:outline-none focus:ring-2 focus:ring-ring`,value:t==null?``:d?(()=>{let e=String(t);if(/^\d{4}-\d{2}-\d{2}/.test(e))return e.slice(0,10);let n=new Date(e);return isNaN(n.getTime())?``:n.toLocaleDateString(`en-CA`)})():String(typeof t==`object`?(0,o.coerceToSafeValue)(t)??``:t),onChange:e=>{let t=e.target.value;n(d&&t?new Date(t+`T00:00:00`).toISOString():t)}})},F=({name:e})=>/^[a-z0-9][a-z0-9-]*$/i.test(e)?(0,c.jsx)(r.LazyIcon,{name:e,className:`h-4 w-4 shrink-0 text-muted-foreground`,"aria-hidden":!0}):(0,c.jsx)(`span`,{className:`text-muted-foreground`,children:e});function I(e,t){return!e||e<=1||t<=1?``:t===2?e>=2?`md:col-span-2`:``:t===3?e===2?`md:col-span-2`:e>=3?`md:col-span-2 lg:col-span-3`:``:e===2?`md:col-span-2`:e===3?`md:col-span-2 lg:col-span-3`:e>=4?`md:col-span-2 lg:col-span-3 xl:col-span-4`:``}var L=({section:e,data:t,className:s,objectSchema:l,objectName:u,isEditing:d=!1,onFieldChange:f,onEnterInlineEdit:p,autoFocusField:m,dataSource:h,virtualScroll:g})=>{let[_,v]=n.useState(e.defaultCollapsed??!1),[y,b]=n.useState(null),[x,S]=n.useState(void 0),[C,T]=n.useState(!1),{t:E}=D(),{fieldLabel:O,translateOptions:k}=(0,a.useSafeFieldLabel)(),N=n.useCallback((e,t)=>{let n=t==null?``:String(t);navigator.clipboard.writeText(n).then(()=>{b(e),setTimeout(()=>b(null),2e3)})},[]),L=n.useCallback(e=>{let n=t?.[e.name]??e.value;return n==null||n===``},[t]),R=n.useMemo(()=>e.fields.filter(L).length,[e.fields,L]),ee=(0,r.useIsMobile)(),te=ee?3:4,z=ee?.2:.25,B=e.fields.length-R,V=!e.hideEmpty&&!d&&e.fields.length>=te&&R/e.fields.length>=z&&B>0,H=!C&&(e.hideEmpty||V)?e.fields.filter(e=>!L(e)):e.fields,{fields:U,columns:W}=w(H,e.columns),ne=Math.min(W,Math.max(1,H.length)),G=e=>{let n=t?.[e.name]??e.value;if(e.render)return(0,c.jsx)(a.SchemaRenderer,{schema:e.render,data:{...t,value:n}});let s=I(e.span,ne),g=l?.fields?.[e.name],_={...e};if(g){!e.type&&g.type&&(_.type=g.type),g.options&&!_.options&&(_.options=g.options),g.currency&&!_.currency&&(_.currency=g.currency),g.precision!==void 0&&_.precision===void 0&&(_.precision=g.precision),g.scale!==void 0&&_.scale===void 0&&(_.scale=g.scale),g.format&&!_.format&&(_.format=g.format),g.widget&&!_.widget&&(_.widget=g.widget);let t=g.reference_to||g.reference;t&&!_.reference_to&&(_.reference_to=t),g.reference_field&&!_.reference_field&&(_.reference_field=g.reference_field),g.dueLike!==void 0&&_.dueLike===void 0&&(_.dueLike=g.dueLike)}u&&Array.isArray(_.options)&&_.options.length>0&&(_.options=k(u,e.name,_.options));let v=_.type||e.type,b=M.has(v),x=e.readonly===!0||g?.readonly===!0,S=j.has(e.name),C=!x&&!b&&!S,w=C&&!!p,T=(()=>{if((_.widget||e.widget)===`permission-facet-link`)return(0,c.jsx)(A,{value:n,field:_});if(n==null||n===``)return(0,c.jsx)(`span`,{className:`text-muted-foreground/60 text-sm select-none`,"aria-label":E(`detail.noValue`,{defaultValue:`No value`}),title:E(`detail.noValue`,{defaultValue:`No value`}),children:`—`});let t=(0,o.resolveCellRendererType)(_)||e.type;if(t){let e=(0,o.getCellRenderer)(t);if(e)return(0,c.jsx)(e,{value:n,field:_})}return String(n)})(),D=n!=null&&n!==``,F=D&&!w,L=y===e.name,R=O(u||``,e.name,e.label||e.name);return ee&&!(d&&C)?(0,c.jsxs)(`div`,{className:(0,r.cn)(`flex items-baseline justify-between gap-4 py-2.5 min-h-[44px] group`,D&&`cursor-pointer active:bg-muted/40 transition-colors`),onClick:D?()=>N(e.name,n):void 0,onKeyDown:D?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),N(e.name,n))}:void 0,role:D?`button`:void 0,tabIndex:D?0:void 0,children:[(0,c.jsx)(`span`,{className:`text-[15px] text-muted-foreground shrink-0`,children:R}),(0,c.jsx)(`span`,{className:`text-[15px] text-foreground text-right break-words min-w-0 leading-snug`,children:T})]},e.name):(0,c.jsxs)(`div`,{className:(0,r.cn)(`space-y-1.5 group min-w-0`,s),children:[(0,c.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:O(u||``,e.name,e.label||e.name)}),d&&C?(0,c.jsx)(`div`,{className:`min-h-[44px] sm:min-h-0`,children:(0,c.jsx)(P,{field:_,value:n,onChange:t=>f?.(e.name,t),dataSource:h,autoFocus:m===e.name})}):(0,c.jsxs)(`div`,{className:(0,r.cn)(`flex items-start justify-between gap-2 min-h-[44px] sm:min-h-0 rounded-md`,F&&`cursor-pointer active:bg-muted/60 transition-colors`,w&&`cursor-pointer hover:bg-muted/40 transition-colors -mx-1.5 px-1.5`),onClick:F?()=>N(e.name,n):void 0,onDoubleClick:w?()=>p?.(e.name):void 0,onKeyDown:F?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),N(e.name,n))}:void 0,role:F?`button`:void 0,tabIndex:F?0:void 0,title:w?E(`detail.editInlineHint`):void 0,children:[(0,c.jsx)(`div`,{className:`text-sm flex-1 min-w-0 break-words py-1`,children:T}),w?(0,c.jsx)(r.TooltipProvider,{children:(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,"aria-label":E(`detail.editInlineHint`),onClick:t=>{t.stopPropagation(),p?.(e.name)},children:(0,c.jsx)(i.Pencil,{className:`h-3 w-3`})})}),(0,c.jsx)(r.TooltipContent,{children:E(`detail.editInlineHint`)})]})}):D?(0,c.jsx)(r.TooltipProvider,{children:(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,onClick:t=>{t.stopPropagation(),N(e.name,n)},children:L?(0,c.jsx)(i.Check,{className:`h-3 w-3 text-green-600`}):(0,c.jsx)(i.Copy,{className:`h-3 w-3`})})}),(0,c.jsx)(r.TooltipContent,{children:E(L?`detail.copied`:`detail.copyToClipboard`)})]})}):null]})]},e.name)},re=g?.enabled===!0,K=g?.batchSize??20;if(n.useEffect(()=>{if(!re){S(void 0);return}if(U.length<=K){S(void 0);return}S(K);let e=setTimeout(()=>S(void 0),100);return()=>clearTimeout(e)},[re,U.length,K]),H.length===0&&R===e.fields.length)return null;let ie=x===void 0?U:U.slice(0,x),q=R>0&&(e.hideEmpty||V),ae=(0,c.jsxs)(c.Fragment,{children:[ee?(0,c.jsx)(`div`,{className:`flex flex-col divide-y divide-border/60`,children:ie.map(G)}):(0,c.jsx)(`div`,{className:(0,r.cn)(`grid gap-3 sm:gap-4`,ne===1?`grid-cols-1`:ne===2?`grid-cols-1 md:grid-cols-2`:ne===3?`grid-cols-1 md:grid-cols-2 lg:grid-cols-3`:`grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`),children:ie.map(G)}),q&&(0,c.jsx)(`div`,{className:`mt-3 -ml-2`,children:(0,c.jsxs)(r.Button,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>T(e=>!e),className:`h-7 px-2 text-xs text-muted-foreground hover:text-foreground`,children:[C?(0,c.jsx)(i.EyeOff,{className:`h-3.5 w-3.5 mr-1.5`}):(0,c.jsx)(i.Eye,{className:`h-3.5 w-3.5 mr-1.5`}),C?E(`detail.hideEmptyFields`,{defaultValue:`Hide empty fields`}):E(`detail.showEmptyFields`,{count:R,defaultValue:`Show ${R} empty field${R===1?``:`s`}`})]})})]});return!e.title&&!e.collapsible&&e.showBorder===!1?(0,c.jsx)(`div`,{className:(0,r.cn)(s),children:ae}):e.collapsible?(0,c.jsx)(r.Collapsible,{open:!_,onOpenChange:e=>v(!e),className:s,children:(0,c.jsxs)(r.Card,{children:[(0,c.jsx)(r.CollapsibleTrigger,{asChild:!0,children:(0,c.jsxs)(r.CardHeader,{className:(0,r.cn)(`py-3 px-4 sm:py-4 sm:px-6 cursor-pointer hover:bg-muted/50 transition-colors`,e.headerColor&&`bg-${e.headerColor}`),children:[(0,c.jsxs)(r.CardTitle,{className:`flex items-center justify-between text-base font-semibold tracking-tight`,children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,c.jsx)(F,{name:e.icon}),(0,c.jsx)(`span`,{children:e.title})]}),(0,c.jsx)(`div`,{className:`flex items-center gap-2`,children:_?(0,c.jsx)(i.ChevronRight,{className:`h-4 w-4 text-muted-foreground`}):(0,c.jsx)(i.ChevronDown,{className:`h-4 w-4 text-muted-foreground`})})]}),e.description&&!_&&(0,c.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.description})]})}),(0,c.jsx)(r.CollapsibleContent,{children:(0,c.jsx)(r.CardContent,{className:`pt-3 sm:pt-4 px-3 sm:px-6 pb-4 sm:pb-5`,children:ae})})]})}):(0,c.jsxs)(r.Card,{className:(0,r.cn)(e.showBorder===!1?`border-none shadow-none`:``,s),children:[e.title&&(0,c.jsxs)(r.CardHeader,{className:(0,r.cn)(`py-3 px-4 sm:py-4 sm:px-6`,e.headerColor&&`bg-${e.headerColor}`),children:[(0,c.jsx)(r.CardTitle,{className:`flex items-center justify-between text-base font-semibold tracking-tight`,children:(0,c.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,c.jsx)(F,{name:e.icon}),(0,c.jsx)(`span`,{children:e.title})]})}),e.description&&(0,c.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.description})]}),(0,c.jsx)(r.CardContent,{className:`pt-3 sm:pt-4 px-3 sm:px-6 pb-4 sm:pb-5`,children:ae})]})},R=({tabs:e,data:t,className:i})=>{let[o,s]=n.useState(e[0]?.key),l=e.filter(e=>typeof e.visible==`boolean`?e.visible:(e.visible,!0));return(0,c.jsxs)(r.Tabs,{value:o,onValueChange:s,className:i,children:[(0,c.jsx)(r.TabsList,{className:`w-full justify-start border-b rounded-none bg-transparent p-0`,children:l.map(e=>(0,c.jsx)(r.TabsTrigger,{value:e.key,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:(0,c.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,c.jsx)(`span`,{children:e.icon}),(0,c.jsx)(`span`,{children:e.label}),e.badge&&(0,c.jsx)(r.Badge,{variant:`secondary`,className:`ml-1`,children:e.badge})]})},e.key))}),l.map(e=>(0,c.jsx)(r.TabsContent,{value:e.key,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:(0,c.jsx)(n.Suspense,{fallback:null,children:Array.isArray(e.content)?(0,c.jsx)(`div`,{className:`space-y-4`,children:e.content.map((e,n)=>(0,c.jsx)(a.SchemaRenderer,{schema:e,data:t},n))}):(0,c.jsx)(a.SchemaRenderer,{schema:e.content,data:t})})},e.key))]})};function ee(e){return e&&i.icons[e.split(/[-_\s]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)]||i.Inbox}var te=({action:e,onToolbarAction:t})=>{let n=e.visible,i=(0,a.useCondition)((0,a.toPredicateInput)(n));if(n&&!i)return null;let o=e.icon?ee(e.icon):null;return(0,c.jsxs)(r.Button,{variant:e.variant===`primary`?`default`:`outline`,size:`sm`,onClick:n=>{n.stopPropagation(),t(e)},className:`gap-1 h-9 sm:h-7 text-xs shadow-none`,"data-testid":`related-toolbar-action-${e.name}`,children:[o&&(0,c.jsx)(o,{className:`h-3.5 w-3.5`}),e.label||e.name]})},z=({title:e,type:t,api:s,data:u,schema:d,columns:f,className:p,dataSource:m,objectName:h,onNew:g,onViewAll:_,onRowEdit:v,onRowDelete:y,onRowClick:b,rowActions:x,onRowAction:S,toolbarActions:C,onToolbarAction:w,add:T,maxColumns:E=6,pageSize:O,sortable:k=!1,filterable:A=!1,collapsible:j=!1,defaultCollapsed:M=!1,referenceField:N,parentId:P,icon:F})=>{let I=u!==void 0,L=u??[],[R,z]=n.useState(L),[B,V]=n.useState(()=>!!s&&!I),[H,U]=n.useState(0),[W,ne]=n.useState(null),[G,re]=n.useState(`asc`),[K,ie]=n.useState(``),[q,ae]=n.useState(null),[oe,se]=n.useState(M),[J,ce]=n.useState(!1),[le,ue]=n.useState(!1),[de,fe]=n.useState(null),[pe,me]=n.useState(0),[he,ge]=n.useState({}),{t:Y}=D(),{fieldLabel:_e}=(0,a.useSafeFieldLabel)();n.useEffect(()=>{I&&z(u??[])},[u,I]),n.useEffect(()=>{s&&m?.getObjectSchema&&m.getObjectSchema(s).then(ae).catch(e=>{console.warn(`[RelatedList] Failed to fetch schema for ${s}:`,e)})},[s,m]),n.useEffect(()=>{if(s&&!I){if(!(N&&P!=null&&P!==``)){s&&(P==null||P===``)&&!N&&console.warn(`[RelatedList] "${s}" has no referenceField/parentId — refusing to fetch all rows. Pass relationshipField + parentId to scope the query.`),z([]),V(!1);return}V(!0);let e={[N]:P};if(m&&typeof m.find==`function`)m.find(s,{$filter:e}).then(e=>{let t=Array.isArray(e)?e:Array.isArray(e?.data)?e.data:[];z(t),V(!1)}).catch(e=>{console.error(`Failed to fetch related data:`,e),V(!1)});else{let e=new URLSearchParams({[`filter[${N}]`]:String(P)}).toString();fetch(`${s}?${e}`).then(e=>e.json()).then(e=>{let t=Array.isArray(e)?e:e?.data||[];z(t)}).catch(e=>{console.error(`Failed to fetch related data:`,e)}).finally(()=>V(!1))}}},[s,I,m,N,P,pe]),n.useEffect(()=>{if(!s||I)return;let e=e=>{let t=e.detail||{};t.objectName&&t.objectName!==s||me(e=>e+1)};return window.addEventListener(`objectui:related-changed`,e),()=>window.removeEventListener(`objectui:related-changed`,e)},[s,I]),n.useEffect(()=>{if(!m?.find||!q?.fields||!R.length)return;let e=q.fields,t=[];for(let[n,r]of Object.entries(e)){if(!r||r.type!==`lookup`&&r.type!==`master_detail`)continue;let e=r.reference_to||r.reference;if(!e)continue;let i=new Set;for(let e of R){let t=e?.[n];t!=null&&(typeof t==`string`&&t?i.add(t):typeof t==`number`&&i.add(String(t)))}let a=he[n]||{},o=Array.from(i).filter(e=>!(e in a));o.length>0&&t.push({fieldName:n,target:e,ids:o})}if(t.length===0)return;let n=!1;return Promise.all(t.map(({fieldName:e,target:t,ids:n})=>m.find(t,{$filter:{id:{$in:n}},$top:n.length}).then(t=>{let n=Array.isArray(t)?t:t?.data||[],r={};for(let e of n){let t=e?.id||e?._id;t&&(r[String(t)]=e?.full_name||e?.fullname||e?.display_name||e?.name||e?.subject||e?.title||e?.label||e?.code||e?.email||String(t))}return{fieldName:e,map:r}}).catch(t=>(console.warn(`[RelatedList] Failed to resolve lookups for ${e}:`,t),{fieldName:e,map:{}})))).then(e=>{n||ge(t=>{let n={...t};for(let{fieldName:t,map:r}of e)n[t]={...n[t]||{},...r};return n})}),()=>{n=!0}},[m,q,R]);let ve=n.useMemo(()=>{if(!K)return R;let e=K.toLowerCase();return R.filter(t=>Object.values(t).some(t=>t!=null&&String(t).toLowerCase().includes(e)))},[R,K]),X=n.useMemo(()=>W?[...ve].sort((e,t)=>{let n=e[W],r=t[W];if(n==null&&r==null)return 0;if(n==null)return 1;if(r==null)return-1;let i=String(n).localeCompare(String(r),void 0,{numeric:!0});return G===`asc`?i:-i}):ve,[ve,W,G]),Z=O&&O>0?O:0,ye=Z?Math.max(1,Math.ceil(X.length/Z)):1,Q=Z?X.slice(H*Z,(H+1)*Z):X;n.useEffect(()=>{U(0)},[K,W,G]);let be=n.useCallback(e=>{W===e?re(e=>e===`asc`?`desc`:`asc`):(ne(e),re(`asc`))},[W]),[$,xe]=n.useState(null),Se=n.useCallback(e=>{xe(e)},[]),Ce=n.useCallback(async()=>{if($)try{await y?.($),me(e=>e+1)}catch(e){console.error(`[RelatedList] remove failed`,e)}xe(null)},[$,y]),we=n.useCallback(async e=>{if(!T||!m||!s||N==null||P==null)return;let t=T.picker.valueField||`id`;ue(!0),fe(null);try{for(let n of e||[]){let e=n?.[t]??n?.id;e!=null&&(T.linkField?await m.create?.(s,{[N]:P,[T.linkField]:e}):await m.update?.(T.picker.object,String(e),{[N]:P}))}me(e=>e+1)}catch(e){let t=e?.body?.error??e?.error??e?.message??String(e);fe(typeof t==`string`?t:`Failed to add`)}finally{ue(!1),ce(!1)}},[T,m,s,N,P]),Te=(0,l.usePermissions)(),Ee=n.useMemo(()=>{let e=h||s||``,t=t=>!Te?.isLoaded||!e?t:t.filter(t=>{let n=t?.accessorKey||t?.field||t?.name;return!n||Te.checkField(e,String(n),`read`)}),r=e=>N?e.filter(e=>(e?.accessorKey||e?.field||e?.name)!==N):e,i=e=>e==null||typeof e==`string`&&e.trim()===``||Array.isArray(e)&&e.length===0,a=e=>R.length?e.filter(e=>{let t=e?.accessorKey||e?.field||e?.name;return!t||R.some(e=>!i(e?.[t]))}):e,c=(e,t)=>{if(!t?.type)return;let r=(0,o.getCellRenderer)((0,o.resolveCellRendererType)({type:t.type,format:t.format})||t.type);if(!r)return;let i=t.type===`lookup`||t.type===`master_detail`?he[e]:void 0,a=i&&Object.keys(i).length>0?Object.entries(i).map(([e,t])=>({value:e,label:t})):void 0,s={name:e,label:t.label||e,type:t.type,...(a||t.options)&&{options:a||t.options},...t.currency&&{currency:t.currency},...t.precision!==void 0&&{precision:t.precision},...t.scale!==void 0&&{scale:t.scale},...t.format&&{format:t.format},...(t.reference_to||t.reference)&&{reference_to:t.reference_to||t.reference},...t.reference_field&&{reference_field:t.reference_field}};return e=>e==null?n.createElement(`span`,{className:`text-muted-foreground/50 text-xs italic`},`—`):n.createElement(r,{value:e,field:s})},l=t=>{if(typeof t!=`string`){let e=t?.accessorKey||t?.field||t?.name;if(t&&!t.cell&&!t.render&&e){let n=q?.fields?.[e],r=n?c(String(e),n):void 0;if(r)return{...t,cell:r}}return t}let n=q?.fields?.[t],r={accessorKey:t,header:n?.label||_e(e,t,n)||t,fieldDef:n,fieldType:n?.type},i=n?c(t,n):void 0;return i&&(r.cell=i),r};if(f&&f.length>0)return a(t(r(f.map(l))));if(!q?.fields)return[];let u=Array.isArray(q.highlightFields)?q.highlightFields.filter(e=>typeof e==`string`&&e.length>0):[];if(u.length>0){let e=a(t(r(u.map(l))));if(e.length>0)return e.slice(0,Math.max(1,E))}let d=e,p=new Set([`attachment`,`rich_text`,`html`,`json`]),m=[`name`,`full_name`,`fullname`,`title`,`subject`,`label`,`code`,`number`],g=Object.entries(q.fields).filter(([e,t])=>!(e.startsWith(`_`)||e===`id`||e===N||t?.hidden||t?.type&&p.has(t.type)||Te?.isLoaded&&d&&!Te.checkField(d,e,`read`))),_=new Set([`created_at`,`updated_at`,`created_by`,`updated_by`,`owner_id`,`organization_id`]);return g.sort(([e,t],[n,r])=>{let i=_.has(e);if(i!==_.has(n))return i?1:-1;let a=m.indexOf(e),o=m.indexOf(n),s=a>=0?a:100,c=o>=0?o:100;if(s!==c)return s-c;let l=t?.type===`select`||e.includes(`status`);return l===(r?.type===`select`||n.includes(`status`))?0:l?-1:1}),a(g.map(([e,t])=>{let n={accessorKey:e,header:_e(d,e,t.label||e)};if(t.type){let r=c(e,t);r&&(n.cell=r)}return n})).slice(0,Math.max(1,E))},[f,q,h,s,_e,N,R,E,he,Te]),De=Array.isArray(x)&&x.length>0,Oe=!!v||!!y||De,ke=(0,r.useIsMobile)(),Ae=n.useMemo(()=>{if(d)return d;if(ke&&(t===`grid`||t===`table`)){let e=Ee[0]?.accessorKey||Ee[0]?.field||Ee[0]?.name,t=Ee.slice(1,4).map(e=>e.accessorKey||e.field||e.name).filter(Boolean);return{type:`object-gallery`,data:Q,objectName:s,gallery:{titleField:e||`name`,visibleFields:t,cardSize:`medium`},onRowClick:b}}switch(t){case`grid`:case`table`:return{type:`data-table`,data:Q,columns:Ee,pagination:!1,pageSize:Z||10,searchable:!1,exportable:!1,rowActions:Oe,onRowEdit:v,onRowDelete:y?Se:void 0,onRowClick:b,rowActionDefs:De?x:void 0,onRowActionDef:De?S:void 0};case`list`:return{type:`data-list`,data:Q};default:return{type:`div`,children:`No view configured`}}},[t,Q,Ee,d,Z,Oe,De,x,S,v,y,Se,b,ke,s]),je=j?`cursor-pointer select-none`:void 0,Me=j?()=>se(e=>!e):void 0,Ne=ee(F),Pe=!B&&R.length===0,Fe=A;return(0,c.jsxs)(r.Card,{className:(0,r.cn)(`shadow-none border-border/60 bg-transparent`,Pe&&`bg-muted/10`,p),children:[(0,c.jsx)(r.CardHeader,{className:(0,r.cn)(`py-3 px-4 sm:py-3 min-h-12 sm:min-h-0`,je),onClick:Me,children:(0,c.jsxs)(r.CardTitle,{className:`flex items-center justify-between gap-2 text-sm font-semibold`,children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[j&&(oe?(0,c.jsx)(i.ChevronRight,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,c.jsx)(i.ChevronDown,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})),(0,c.jsx)(Ne,{className:`h-4 w-4 text-muted-foreground shrink-0`,"aria-hidden":!0}),(0,c.jsx)(`span`,{className:(0,r.cn)(`truncate`,Pe&&`text-muted-foreground font-medium`),children:e}),(0,c.jsx)(r.Badge,{variant:`secondary`,className:(0,r.cn)(`text-xs font-normal h-5 px-1.5`,R.length===0&&`bg-muted text-muted-foreground`),"aria-label":`${R.length} records`,children:R.length}),Pe&&(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground/70 italic ml-1 truncate`,children:Y(`detail.noRelatedRecords`)})]}),(0,c.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[w&&(C??[]).map(e=>(0,c.jsx)(te,{action:e,onToolbarAction:w},e.name)),T&&(0,c.jsxs)(r.Button,{variant:Pe?`ghost`:`outline`,size:`sm`,disabled:le,onClick:e=>{e.stopPropagation(),fe(null),ce(!0)},className:`gap-1 h-9 sm:h-7 text-xs shadow-none`,children:[(0,c.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),T.label||Y(`detail.add`,{defaultValue:`Add`})]}),g&&(0,c.jsxs)(r.Button,{variant:Pe?`ghost`:`outline`,size:`sm`,onClick:e=>{e.stopPropagation(),g()},className:`gap-1 h-9 sm:h-7 text-xs shadow-none`,children:[(0,c.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),Y(`detail.new`)]})]})]})}),!oe&&!Pe&&(0,c.jsxs)(r.CardContent,{className:(0,r.cn)(`pt-0 pb-4 px-4`),children:[Fe&&(0,c.jsx)(`div`,{className:`mb-3`,children:(0,c.jsx)(r.Input,{placeholder:Y(`detail.filterPlaceholder`),value:K,onChange:e=>ie(e.target.value),className:`h-8 text-sm`})}),k&&Ee&&Ee.length>0&&R.length>0&&(0,c.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-3`,children:Ee.map(e=>{let t=e.accessorKey||e.field||e.name;if(!t)return null;let n=e.header||e.label||t,a=W===t;return(0,c.jsxs)(r.Button,{variant:a?`secondary`:`ghost`,size:`sm`,className:`gap-1 h-7 text-xs`,onClick:()=>be(t),children:[(0,c.jsx)(i.ArrowUpDown,{className:`h-3 w-3`}),n,a&&(G===`asc`?` ↑`:` ↓`)]},t)})}),B?(0,c.jsx)(`div`,{className:`flex items-center justify-center py-6 text-muted-foreground text-sm`,children:Y(`detail.loading`)}):(0,c.jsx)(a.SchemaRenderer,{schema:Ae}),Z>0&&X.length>Z&&(0,c.jsxs)(`div`,{className:`flex items-center justify-between mt-3 pt-3 border-t`,children:[(0,c.jsxs)(r.Button,{variant:`outline`,size:`sm`,className:`h-7 text-xs gap-1`,disabled:H===0,onClick:()=>U(e=>Math.max(0,e-1)),children:[(0,c.jsx)(i.ChevronLeft,{className:`h-3 w-3`}),Y(`detail.previousPage`)]}),(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:Y(`detail.pageOf`,{current:H+1,total:ye})}),(0,c.jsxs)(r.Button,{variant:`outline`,size:`sm`,className:`h-7 text-xs gap-1`,disabled:H>=ye-1,onClick:()=>U(e=>Math.min(ye-1,e+1)),children:[Y(`detail.nextPage`),(0,c.jsx)(i.ChevronRight,{className:`h-3 w-3`})]})]}),_&&!Pe&&Z>0&&X.length>Z&&(0,c.jsx)(`div`,{className:`mt-3 pt-3 border-t flex justify-center`,children:(0,c.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),_()},className:`text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1 transition-colors`,children:[Y(`detail.viewAll`),(0,c.jsx)(i.ExternalLink,{className:`h-3 w-3`})]})})]}),(0,c.jsx)(r.AlertDialog,{open:$!==null,onOpenChange:e=>{e||xe(null)},children:(0,c.jsxs)(r.AlertDialogContent,{children:[(0,c.jsxs)(r.AlertDialogHeader,{children:[(0,c.jsx)(r.AlertDialogTitle,{children:Y(`detail.deleteRowTitle`,{defaultValue:`Delete record`})}),(0,c.jsx)(r.AlertDialogDescription,{children:Y(`detail.deleteRowConfirmation`)})]}),(0,c.jsxs)(r.AlertDialogFooter,{children:[(0,c.jsx)(r.AlertDialogCancel,{children:Y(`detail.cancel`,{defaultValue:`Cancel`})}),(0,c.jsx)(r.AlertDialogAction,{onClick:Ce,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:Y(`detail.delete`,{defaultValue:`Delete`})})]})]})}),de&&(0,c.jsx)(`div`,{className:`mx-4 mb-3 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,role:`alert`,children:de}),T&&m&&(0,c.jsx)(o.RecordPickerDialog,{open:J,onOpenChange:e=>ce(e),multiple:!0,dataSource:m,objectName:T.picker.object,title:T.label||Y(`detail.add`,{defaultValue:`Add`}),onSelect:()=>{},onSelectRecords:e=>{we(e)}})]})},B=({group:e,data:t,className:a,objectSchema:o,objectName:s,isEditing:l=!1,onFieldChange:u,onEnterInlineEdit:d,autoFocusField:f,dataSource:p})=>{let m=e.collapsible??!0,[h,g]=n.useState(e.defaultCollapsed??!1),_=(0,c.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:e.sections.map((e,n)=>(0,c.jsx)(L,{section:e,data:t,objectSchema:o,objectName:s,isEditing:l,onFieldChange:u,onEnterInlineEdit:d,autoFocusField:f,dataSource:p},n))});return m?(0,c.jsxs)(r.Collapsible,{open:!h,onOpenChange:e=>g(!e),className:a,children:[(0,c.jsx)(r.CollapsibleTrigger,{asChild:!0,children:(0,c.jsxs)(`div`,{className:`flex items-center gap-2 pb-2 border-b cursor-pointer hover:bg-muted/50 transition-colors rounded-t-md px-2 py-1.5`,children:[h?(0,c.jsx)(i.ChevronRight,{className:`h-4 w-4 text-muted-foreground shrink-0`}):(0,c.jsx)(i.ChevronDown,{className:`h-4 w-4 text-muted-foreground shrink-0`}),e.icon&&(0,c.jsx)(`span`,{className:`text-muted-foreground`,children:e.icon}),(0,c.jsx)(`h3`,{className:`text-lg font-semibold`,children:e.title})]})}),e.description&&!h&&(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e.description}),(0,c.jsx)(r.CollapsibleContent,{children:(0,c.jsx)(`div`,{className:`mt-3`,children:_})})]}):(0,c.jsxs)(`div`,{className:(0,r.cn)(`space-y-3`,a),children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-2 pb-2 border-b`,children:[e.icon&&(0,c.jsx)(`span`,{className:`text-muted-foreground`,children:e.icon}),(0,c.jsx)(`h3`,{className:`text-lg font-semibold`,children:e.title})]}),e.description&&(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description}),_]})},V=({fields:e,data:t,className:n,objectName:s,objectSchema:l,dataSource:u})=>{let{fieldLabel:d}=(0,a.useSafeFieldLabel)(),{t:f}=D(),p=(0,a.useInlineEdit)(),m=p?.editing??!1,h=p?.canEdit??!1;if(!e.length||!t)return null;let g=m?e:e.filter(e=>{let n=t?.[e.name];return n!=null&&n!==``});return g.length===0?null:(0,c.jsx)(r.TooltipProvider,{children:(0,c.jsx)(`section`,{className:(0,r.cn)(`@container border-b border-border/60 pb-4`,n),"aria-label":`Record highlights`,children:(0,c.jsx)(`div`,{className:(0,r.cn)(`flex flex-wrap gap-y-4`),children:g.map(e=>{let n=t[e.name],a=l?.fields?.[e.name],g=e.type||a?.type,_=a?.reference_to||a?.reference,v={name:e.name,label:e.label,type:g||`text`,...a?.options&&{options:a.options},...a?.currency&&{currency:a.currency},...a?.currencyConfig&&{currencyConfig:a.currencyConfig},...a?.precision!==void 0&&{precision:a.precision},...a?.scale!==void 0&&{scale:a.scale},...a?.format&&{format:a.format},..._&&{reference_to:_},...a?.reference_field&&{reference_field:a.reference_field},...a?.widget&&{widget:a.widget}},y=p?.draft?.[e.name],b=y===void 0?n:y,x=M.has(g),S=e.readonly===!0||a?.readonly===!0,C=j.has(e.name),w=h&&!x&&!S&&!C,T=m&&w,E=(0,o.getCellRenderer)((0,o.resolveCellRendererType)(v)||g||`text`),D=g===`number`||g===`integer`||g===`currency`||g===`percent`||g===`decimal`,O=g===`email`||g===`url`||g===`textarea`||g===`reference`||g===`lookup`||g===`master_detail`,k=g===`boolean`,A=b==null||b===``;return(0,c.jsxs)(`div`,{className:(0,r.cn)(`group flex flex-col gap-1 min-w-[7rem] px-5 border-l border-border/60 first:border-l-0 first:pl-0`,O||T?`basis-[16rem] max-w-[24rem]`:`basis-[9rem] max-w-[16rem]`),children:[(0,c.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:d(s||``,e.name,e.label)}),T?(0,c.jsx)(P,{field:v,value:b,onChange:t=>p.setField(e.name,t),dataSource:u,autoFocus:p.autoFocusField===e.name}):(0,c.jsxs)(`div`,{className:(0,r.cn)(`flex items-start justify-between gap-1`,w&&`cursor-pointer rounded-md -mx-1.5 px-1.5 hover:bg-muted/40 transition-colors`),onDoubleClick:w?()=>p.enter(e.name):void 0,title:w?f(`detail.editInlineHint`):void 0,children:[(0,c.jsx)(`div`,{className:`min-w-0 flex-1`,children:k?b?(0,c.jsxs)(`span`,{className:`inline-flex items-center gap-1 self-start rounded-full bg-emerald-500/10 px-2 py-0.5 text-xs font-medium text-emerald-600 ring-1 ring-inset ring-emerald-500/30 dark:text-emerald-400`,children:[(0,c.jsx)(i.Check,{className:`h-3 w-3`,"aria-hidden":!0}),`Yes`]}):(0,c.jsxs)(`span`,{className:`inline-flex items-center gap-1 self-start rounded-full bg-amber-500/10 px-2 py-0.5 text-xs font-medium text-amber-700 ring-1 ring-inset ring-amber-500/30 dark:text-amber-400`,children:[(0,c.jsx)(i.X,{className:`h-3 w-3`,"aria-hidden":!0}),`No`]}):A?(0,c.jsx)(`span`,{className:`block text-sm text-muted-foreground/60 select-none`,"aria-label":f(`detail.noValue`,{defaultValue:`No value`}),children:`—`}):(0,c.jsx)(`span`,{title:(Array.isArray(v.options)?v.options.find(e=>e?.value===b)?.label:void 0)??(typeof b==`string`||typeof b==`number`?String(b):void 0),className:(0,r.cn)(`block min-w-0 truncate text-sm font-semibold`,D&&`tabular-nums tracking-tight`),children:(0,c.jsx)(E,{value:b,field:v})})}),w&&(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-5 w-5 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity`,"aria-label":f(`detail.editInlineHint`),onClick:t=>{t.stopPropagation(),p.enter(e.name)},children:(0,c.jsx)(i.Pencil,{className:`h-3 w-3`})})}),(0,c.jsx)(r.TooltipContent,{children:f(`detail.editInlineHint`)})]})]})]},e.name)})})})})};function H(e){try{let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);return a<7?`${a}d ago`:t.toLocaleDateString()}catch{return e}}var U=({comments:e,onAddComment:t,onTogglePin:a,searchable:o=!1,className:s})=>{let{t:l}=D(),[u,d]=n.useState(``),[f,p]=n.useState(!1),[m,h]=n.useState(``),g=n.useCallback(async()=>{let e=u.trim();if(!(!e||!t)){p(!0);try{await t(e),d(``)}finally{p(!1)}}},[u,t]),_=n.useCallback(e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),g())},[g]),v=n.useMemo(()=>[...m.trim()?e.filter(e=>{let t=m.trim().toLowerCase();return e.text.toLowerCase().includes(t)||e.author.toLowerCase().includes(t)}):e].sort((e,t)=>e.pinned&&!t.pinned?-1:!e.pinned&&t.pinned?1:0),[e,m]);return(0,c.jsxs)(r.Card,{className:(0,r.cn)(``,s),children:[(0,c.jsx)(r.CardHeader,{children:(0,c.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,c.jsx)(i.MessageSquare,{className:`h-4 w-4`}),l(`detail.comments`),(0,c.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,e.length,`)`]})]})}),(0,c.jsxs)(r.CardContent,{className:`space-y-4`,children:[o&&(0,c.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,c.jsxs)(`div`,{className:`relative flex-1`,children:[(0,c.jsx)(i.Search,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,c.jsx)(`input`,{className:`w-full rounded-md border border-input bg-background pl-8 pr-8 py-1.5 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,placeholder:l(`detail.searchComments`),value:m,onChange:e=>h(e.target.value),"aria-label":l(`detail.searchComments`)}),m&&(0,c.jsx)(`button`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,onClick:()=>h(``),"aria-label":l(`detail.clearSearch`),type:`button`,children:(0,c.jsx)(i.X,{className:`h-3.5 w-3.5`})})]})}),t&&(0,c.jsxs)(`div`,{className:`flex gap-2`,children:[(0,c.jsx)(`textarea`,{className:`flex-1 min-h-[60px] rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring resize-none`,placeholder:l(`detail.addCommentPlaceholder`),value:u,onChange:e=>d(e.target.value),onKeyDown:_,disabled:f}),(0,c.jsx)(r.Button,{size:`icon`,variant:`default`,onClick:g,disabled:!u.trim()||f,className:`shrink-0 self-end`,children:(0,c.jsx)(i.Send,{className:`h-4 w-4`})})]}),v.length===0?(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:m.trim()?l(`detail.noMatchingComments`):l(`detail.noCommentsYet`)}):(0,c.jsx)(`div`,{className:`space-y-3`,children:v.map(e=>(0,c.jsxs)(`div`,{className:(0,r.cn)(`flex gap-3`,e.pinned&&`bg-muted/40 rounded-md p-2 -mx-2`),children:[(0,c.jsx)(`div`,{className:`shrink-0`,children:e.avatarUrl?(0,c.jsx)(`img`,{src:e.avatarUrl,alt:e.author,className:`h-8 w-8 rounded-full object-cover`}):(0,c.jsx)(`div`,{className:`h-8 w-8 rounded-full bg-muted flex items-center justify-center text-xs font-medium text-muted-foreground`,children:e.author.charAt(0).toUpperCase()})}),(0,c.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-2 mb-0.5`,children:[(0,c.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e.author}),(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:H(e.createdAt)}),e.pinned&&(0,c.jsxs)(`span`,{className:`text-xs text-amber-600 flex items-center gap-0.5`,children:[(0,c.jsx)(i.Pin,{className:`h-3 w-3`}),l(`detail.pinned`)]})]}),(0,c.jsx)(`p`,{className:`text-sm whitespace-pre-wrap break-words`,children:e.text}),a&&(0,c.jsxs)(`button`,{type:`button`,className:`mt-1 text-xs text-muted-foreground hover:text-foreground flex items-center gap-1`,onClick:()=>a(e.id),"aria-label":e.pinned?l(`detail.unpin`):l(`detail.pin`),children:[(0,c.jsx)(i.Pin,{className:`h-3 w-3`}),e.pinned?l(`detail.unpin`):l(`detail.pin`)]})]})]},e.id))})]})]})},W={field_change:i.Edit,create:i.PlusCircle,delete:i.Trash2,comment:i.MessageSquare,status_change:i.ArrowRightLeft},ne={field_change:`bg-blue-100 text-blue-600`,create:`bg-green-100 text-green-600`,delete:`bg-red-100 text-red-600`,comment:`bg-purple-100 text-purple-600`,status_change:`bg-amber-100 text-amber-600`};function G(e){try{let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);return a<7?`${a}d ago`:t.toLocaleDateString()}catch{return e}}function re(e){return e.description?e.description:e.type===`field_change`&&e.field?`Changed ${e.field.charAt(0).toUpperCase()+e.field.slice(1).replace(/_/g,` `)} from "${e.oldValue==null?`(empty)`:String(e.oldValue)}" to "${e.newValue==null?`(empty)`:String(e.newValue)}"`:e.type===`create`?`Created this record`:e.type===`delete`?`Deleted this record`:e.type===`status_change`&&e.field?`Changed status to "${e.newValue==null?`(empty)`:String(e.newValue)}"`:`Updated record`}var K={all:`All`,field_change:`Field Changes`,create:`Creates`,delete:`Deletes`,comment:`Comments`,status_change:`Status Changes`},ie=({activities:e,filterable:t=!1,defaultFilter:a=`all`,className:o})=>{let[s,l]=n.useState(a),u=n.useMemo(()=>s===`all`?e:e.filter(e=>e.type===s),[e,s]);return(0,c.jsxs)(r.Card,{className:(0,r.cn)(``,o),children:[(0,c.jsx)(r.CardHeader,{children:(0,c.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,c.jsx)(i.Activity,{className:`h-4 w-4`}),`Activity`,(0,c.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,u.length,`)`]})]})}),(0,c.jsxs)(r.CardContent,{children:[t&&(0,c.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-4`,role:`group`,"aria-label":`Activity type filter`,children:Object.keys(K).map(e=>(0,c.jsxs)(`button`,{type:`button`,className:(0,r.cn)(`inline-flex items-center gap-1 rounded-full px-2.5 py-0.5 text-xs font-medium transition-colors`,s===e?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-muted/80`),onClick:()=>l(e),"aria-pressed":s===e,children:[e!==`all`&&n.createElement(W[e]||i.Edit,{className:`h-3 w-3`}),K[e]]},e))}),u.length===0?(0,c.jsx)(r.DataEmptyState,{title:`No activity recorded`,className:`py-6`}):(0,c.jsxs)(`div`,{className:`relative`,children:[(0,c.jsx)(`div`,{className:`absolute left-4 top-2 bottom-2 w-px bg-border`}),(0,c.jsx)(`div`,{className:`space-y-4`,children:u.map(e=>{let t=W[e.type]||i.Edit;return(0,c.jsxs)(`div`,{className:`flex gap-3 relative`,children:[(0,c.jsx)(`div`,{className:(0,r.cn)(`shrink-0 h-8 w-8 rounded-full flex items-center justify-center z-10`,ne[e.type]||`bg-gray-100 text-gray-600`),children:(0,c.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,c.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,c.jsxs)(`p`,{className:`text-sm`,children:[(0,c.jsx)(`span`,{className:`font-medium`,children:e.user}),` `,(0,c.jsx)(`span`,{className:`text-muted-foreground`,children:re(e)})]}),(0,c.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:G(e.timestamp)})]})]},e.id)})})]})]})]})},q={create:`default`,update:`secondary`,delete:`destructive`,restore:`outline`,login:`outline`,logout:`outline`,permission_change:`secondary`,config_change:`secondary`,export:`outline`,import:`outline`};function ae(e){if(!e)return``;let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}var oe=[[60,`second`],[60,`minute`],[24,`hour`],[7,`day`],[4.34524,`week`],[12,`month`],[1/0,`year`]];function se(e,t){if(!e)return``;let n=e instanceof Date?e:new Date(e);if(Number.isNaN(n.getTime()))return String(e);let r=(n.getTime()-Date.now())/1e3;for(let[n,i]of oe){if(Math.abs(r)<n)try{return new Intl.RelativeTimeFormat(t,{numeric:`auto`}).format(Math.round(r),i)}catch{return ae(e)}r/=n}return ae(e)}function J(e){if(!e)return`?`;let t=e.trim().split(/\s+/).filter(Boolean).slice(0,2);return t.length===0?`?`:t.map(e=>e.charAt(0).toUpperCase()).join(``)}function ce(e){if(e==null||e===``)return`—`;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function le({entries:e,loading:t,emptyText:n,className:i,locale:a}){return t?(0,c.jsx)(`div`,{className:(0,r.cn)(`space-y-3`,i),children:Array.from({length:4}).map((e,t)=>(0,c.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,c.jsx)(r.Skeleton,{className:`h-8 w-8 rounded-full`}),(0,c.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,c.jsx)(r.Skeleton,{className:`h-4 w-1/3`}),(0,c.jsx)(r.Skeleton,{className:`h-3 w-1/2`})]})]},t))}):!e||e.length===0?(0,c.jsx)(`div`,{className:(0,r.cn)(`flex items-center justify-center rounded-md border border-dashed py-10 text-sm text-muted-foreground`,i),children:n??`No history yet`}):(0,c.jsx)(r.TooltipProvider,{delayDuration:150,children:(0,c.jsx)(`ol`,{className:(0,r.cn)(`space-y-4`,i),children:e.map((e,t)=>{let n=(e.action??``).toLowerCase(),i=q[n]??`outline`,o=typeof e.user_name==`string`&&e.user_name.trim()||`Unknown user`,s=ae(e.created_at),l=se(e.created_at,a),u=typeof e.user_avatar==`string`?e.user_avatar:void 0;return(0,c.jsxs)(`li`,{className:`flex items-start gap-3`,children:[(0,c.jsxs)(r.Avatar,{className:`h-8 w-8 mt-0.5 shrink-0`,children:[u?(0,c.jsx)(r.AvatarImage,{src:u,alt:o}):null,(0,c.jsx)(r.AvatarFallback,{className:`text-[10px] font-medium`,children:J(e.user_name)})]}),(0,c.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,c.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1`,children:[(0,c.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:o}),e.action&&(0,c.jsx)(r.Badge,{variant:i,className:`text-[10px] uppercase tracking-wide`,children:e.action}),s&&(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground cursor-help`,"aria-label":s,children:l||s})}),(0,c.jsx)(r.TooltipContent,{children:s})]})]}),e.summary&&(0,c.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e.summary}),e.changes&&e.changes.length>0&&(n===`create`?(0,c.jsxs)(`details`,{className:`mt-1 group`,children:[(0,c.jsxs)(`summary`,{className:`cursor-pointer list-none text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1 select-none`,children:[(0,c.jsx)(`span`,{className:`transition-transform group-open:rotate-90`,children:`▸`}),(0,c.jsx)(`span`,{children:e.changes.length===1?`1 field populated`:`${e.changes.length} fields populated`})]}),(0,c.jsx)(`ul`,{className:`mt-1.5 space-y-0.5 text-xs text-muted-foreground pl-4`,children:e.changes.map(e=>(0,c.jsxs)(`li`,{className:`leading-relaxed`,children:[(0,c.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label||e.field}),`: `,(0,c.jsx)(`span`,{className:`text-foreground`,children:ce(e.to)})]},e.field))})]}):(0,c.jsx)(`ul`,{className:`mt-1.5 space-y-0.5 text-xs text-muted-foreground`,children:e.changes.map(e=>(0,c.jsxs)(`li`,{className:`leading-relaxed`,children:[(0,c.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label||e.field}),`: `,(0,c.jsx)(`span`,{className:`line-through opacity-70`,children:ce(e.from)}),` → `,(0,c.jsx)(`span`,{className:`text-foreground`,children:ce(e.to)})]},e.field))}))]})]},e.id??t)})})})}var ue={createdAt:`created_at`,createdBy:`created_by`,updatedAt:`updated_at`,updatedBy:`updated_by`};function de(e){if(!e)return null;if(e instanceof Date)return isNaN(e.getTime())?null:e;if(typeof e==`string`||typeof e==`number`){let t=new Date(e);return isNaN(t.getTime())?null:t}return null}function fe(e,t){let n=Date.now()-e.getTime(),r=Math.max(0,Math.floor(n/1e3));if(r<60)return t(`detail.justNow`);let i=Math.floor(r/60);if(i<60)return t(`detail.minutesAgo`,{count:i});let a=Math.floor(i/60);return a<24?t(`detail.hoursAgo`,{count:a}):t(`detail.daysAgo`,{count:Math.floor(a/24)})}function pe(e){try{return new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(e)}catch{return e.toISOString()}}var me=({value:e,objectSchema:t,fieldName:r})=>{if(e==null||e===``)return null;let i=t?.fields?.[r],a=i?.reference_to||i?.reference,s={name:r,type:i?.type||(a?`lookup`:`text`),...a&&{reference_to:a},...i?.reference_field&&{reference_field:i.reference_field}},l=(0,o.resolveCellRendererType)(s)||s.type;if(l){let t=(0,o.getCellRenderer)(l);if(t)return(0,c.jsx)(`span`,{className:`inline-flex items-center [&_a]:text-inherit [&_a]:hover:underline`,children:n.createElement(t,{value:e,field:s})})}return(0,c.jsx)(`span`,{children:String(e)})},he=({label:e,user:t,date:n,objectSchema:i,userField:a,t:o})=>{if(!t&&!n)return null;let s=n?(0,c.jsx)(r.TooltipProvider,{delayDuration:200,children:(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(`time`,{dateTime:n.toISOString(),className:`cursor-default underline decoration-dotted decoration-muted-foreground/40 underline-offset-2`,children:fe(n,o)})}),(0,c.jsx)(r.TooltipContent,{side:`top`,children:pe(n)})]})}):null;return(0,c.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,c.jsx)(`span`,{className:`text-muted-foreground/70`,children:e}),t?(0,c.jsx)(me,{value:t,objectSchema:i,fieldName:a}):null,t&&s?(0,c.jsx)(`span`,{className:`text-muted-foreground/40`,children:`·`}):null,s]})},ge=({data:e,objectSchema:t,objectName:n,className:i})=>{let{t:a}=D();if(!e)return null;let o=de(e[ue.createdAt]),s=de(e[ue.updatedAt]),l=e[ue.createdBy],u=e[ue.updatedBy],d=!!(o||l),f=o&&s&&Math.abs(s.getTime()-o.getTime())<2e3,p=!!(s||u)&&!(f&&(l!=null&&u!=null&&String(l)===String(u)||!u));return!d&&!p?null:(0,c.jsxs)(`div`,{className:(0,r.cn)(`mt-6 pt-3 border-t border-border/40`,`flex flex-wrap items-center gap-x-4 gap-y-1`,`text-xs text-muted-foreground`,i),"data-testid":`record-meta-footer`,children:[d&&(0,c.jsx)(he,{label:a(l?`detail.createdBy`:`detail.created`),user:l,date:o,objectSchema:t,userField:ue.createdBy,t:a}),p&&(0,c.jsx)(he,{label:a(u?`detail.updatedBy`:`detail.updated`),user:u,date:s,objectSchema:t,userField:ue.updatedBy,t:a})]})},Y=5,_e={};function ve(e,n,r,i){if(e&&typeof e==`object`){if(n.primaryField){let t=e[n.primaryField];if(t!=null&&t!==``)return String(t)}let i=(0,t.formatTitleTemplate)(r?.titleFormat,e);if(i)return i}if(e&&typeof e==`object`){let n=e.id??e._id,i=(0,t.getRecordDisplayName)(r,e,{deriveFromRecordKeys:!1});if(!(i===`Untitled`||n!=null&&i===`Record #${n}`))return i}if(n.title)return n.title;if(e&&typeof e==`object`){let t=e.id??e._id;if(t!=null&&String(t).trim()!==``)return`Record #${t}`}return i}var X=({schema:e,dataSource:o,className:s,onEdit:d,onDelete:f,onBack:p,inlineEdit:m=!1,discussionSlot:h,rightRail:g,objectLabel:_,onDataLoaded:v,isFavorite:y,onToggleFavorite:b})=>{let[x,S]=n.useState(e.data),[C,w]=n.useState(!e.data&&!!(e.api&&e.resourceId||o&&e.objectName&&e.resourceId)),[T,E]=n.useState(!1),O=y??T,k=(0,a.useInlineEdit)(),A=k?.editing??!1,j=k?.draft??_e,M=k?.autoFocusField??null,[N,P]=n.useState(null),[F,I]=n.useState(null),[ee,te]=n.useState(!1),[H,W]=n.useState(0),ne=(0,a.useDataInvalidation)(e.objectName||void 0,e.resourceId==null?void 0:String(e.resourceId)),[G,re]=n.useState(!1),{t:K}=D(),{currency:q}=(0,u.useLocalization)(),{fieldOptionLabel:ae}=(0,a.useSafeFieldLabel)(),oe=(0,r.useIsMobile)(),se=(0,l.usePermissions)(),J=n.useMemo(()=>{if(!se?.isLoaded||!e.objectName)return e;let t=t=>se.checkField(e.objectName,t,`read`),n=e=>e&&e.filter(e=>{let n=typeof e==`string`?e:e?.name;return!n||t(n)});return{...e,fields:n(e.fields),sections:e.sections?.map(e=>({...e,fields:n(e.fields)})),summaryFields:n(e.summaryFields)}},[e,se]);n.useEffect(()=>{x&&v&&v(x)},[x,v]);let ce=n.useMemo(()=>{if(J.summaryFields&&J.summaryFields.length>0)return[];let e=[...J.sections?.flatMap(e=>e.fields)||[],...J.fields||[]],t={};for(let n of e)t[n.name]||(t[n.name]=n);if(F?.fields)for(let[e,n]of Object.entries(F.fields))t[e]={...t[e]||{},...n,name:e};let n=e=>x?.[e]!==void 0&&x?.[e]!==null&&x?.[e]!==``,r=[],i=[`status`,`stage`,`state`,`phase`].find(e=>t[e]&&n(e))||Object.keys(t).find(e=>t[e]?.type===`select`&&n(e));i&&r.push(i);let a=Object.keys(t).find(e=>(t[e]?.type===`currency`||/amount|revenue|value|total|price/i.test(e))&&n(e));a&&!r.includes(a)&&r.push(a);let o=Object.keys(t).find(e=>(t[e]?.type===`date`||t[e]?.type===`datetime`)&&/close|due|start|end|expected/i.test(e)&&n(e));return o&&!r.includes(o)&&r.push(o),r},[J.summaryFields,J.sections,J.fields,F,x]),ue=J.summaryFields&&J.summaryFields.length>0?J.summaryFields:ce,de=n.useCallback(()=>{J.resourceId&&navigator.clipboard.writeText(String(J.resourceId)).then(()=>{te(!0),setTimeout(()=>te(!1),1500)})},[J.resourceId]);n.useEffect(()=>{let e=!0;if(J.data)return S(J.data),w(!1),o?.getObjectSchema&&J.objectName&&o.getObjectSchema(J.objectName).then(t=>{e&&I(t)}).catch(()=>{}),()=>{e=!1};if(o&&J.objectName&&J.resourceId){w(!0),I(null),S(null);let n=J.objectName,r=J.resourceId,i=`${n}-`,a=[...J.sections?.flatMap(e=>e.fields)||[],...J.fields||[]];(o.getObjectSchema?o.getObjectSchema(n).catch(()=>null):Promise.resolve(null)).then(s=>{if(!e)return;I(s);let c=(0,t.buildExpandFields)(s?.fields,a),l=c.length>0?{$expand:c}:void 0,u=l?o.findOne(n,r,l):o.findOne(n,r),d=()=>{let t=String(r),a=t.startsWith(i)?t.slice(i.length):`${i}${t}`;return(l?o.findOne(n,a,l):o.findOne(n,a)).then(t=>{e&&(S(t),w(!1))}).catch(()=>{e&&(S(null),w(!1))})};return u.catch(()=>null).then(t=>{if(e){if(t){S(t),w(!1);return}return d()}})}).catch(t=>{e&&(console.error(`Failed to fetch detail data:`,t),w(!1))})}else J.api&&J.resourceId&&(w(!0),fetch(`${J.api}/${J.resourceId}`).then(e=>e.json()).then(t=>{e&&S(t?.data||t)}).catch(e=>{console.error(`Failed to fetch detail data:`,e)}).finally(()=>{e&&w(!1)}));return()=>{e=!1}},[J.api,J.resourceId,J.objectName,o,J.sections,J.fields,H,ne]);let fe=n.useCallback(()=>{if(p)p();else if(J.onNavigate){let e=J.backUrl||(J.objectName?`/${J.objectName}`:`/`);J.onNavigate(e,{replace:!0})}else J.backUrl?window.location.href=J.backUrl:window.history.back()},[p,J]),pe=n.useCallback(()=>{d?d():J.onNavigate&&J.editUrl?J.onNavigate(J.editUrl):J.onNavigate&&J.objectName&&J.resourceId?J.onNavigate(`/${J.objectName}/${J.resourceId}/edit`):J.editUrl&&(window.location.href=J.editUrl)},[d,J]),me=n.useCallback(async()=>{if(!o?.cancelPendingApproval||!J.objectName||!J.resourceId){P(K(`detail.cancelApprovalUnavailable`));return}re(!0),P(null);try{if(await o.cancelPendingApproval(String(J.objectName),String(J.resourceId)),o.findOne)try{let e=await o.findOne(String(J.objectName),String(J.resourceId));e&&S(e)}catch{}W(e=>e+1);try{window.dispatchEvent(new CustomEvent(`objectui:record-changed`,{detail:{objectName:String(J.objectName),recordId:String(J.resourceId),reason:`approval-recalled`}}))}catch{}}catch(e){let t=(e?.message||e?.error||String(e??`Cancel failed`)).replace(/^\[[^\]]+\]\s*/,``).replace(/^[A-Z][A-Z0-9_]+:\s*/,``);P(`${K(`detail.cancelApprovalFailed`)}: ${t}`)}finally{re(!1)}},[o,J.objectName,J.resourceId,K]),he=n.useCallback(()=>{let e=J.deleteConfirmation||K(`detail.deleteConfirmation`);window.confirm(e)&&(f?.(),J.onNavigate&&J.objectName&&J.onNavigate(`/${J.objectName}`,{replace:!0}))},[f,J]),X=n.useCallback(()=>{navigator.share&&J.objectName&&J.resourceId?navigator.share({title:J.title||K(`detail.details`),text:`${J.objectName} #${J.resourceId}`,url:window.location.href}).catch(e=>console.log(`Share failed:`,e)):navigator.clipboard.writeText(window.location.href).then(()=>{console.log(`Link copied to clipboard`)})},[J]),Z=n.useCallback(()=>{let e=!O;b&&b(e),y===void 0&&E(e)},[O,y,b]),ye=k?.setField,Q=k&&k.canEdit?k.enter:void 0;n.useEffect(()=>{if(!J.recordNavigation)return;let e=J.recordNavigation,t=t=>{let n=t.target?.tagName;n===`INPUT`||n===`TEXTAREA`||t.target?.isContentEditable||(t.key===`ArrowLeft`&&e.currentIndex>0?(t.preventDefault(),e.onNavigate(e.recordIds[e.currentIndex-1])):t.key===`ArrowRight`&&e.currentIndex<e.recordIds.length-1&&(t.preventDefault(),e.onNavigate(e.recordIds[e.currentIndex+1])))};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[J.recordNavigation]);let be=n.useMemo(()=>J.related??[],[J.related]),$=n.useMemo(()=>{let e=[];return e.push({name:`sys_share`,label:K(`detail.share`),icon:`share-2`,type:`script`,onClick:X}),J.showEdit&&e.push({name:`sys_edit_mobile`,label:K(`detail.edit`),icon:`edit`,type:`script`,className:`sm:hidden`,onClick:pe}),J.showDelete&&e.push({name:`sys_delete`,label:K(`detail.delete`),icon:`trash-2`,type:`script`,variant:`destructive`,tags:[`separator-before`],onClick:he}),e},[K,J.showEdit,J.showDelete,X,pe,he]),xe=n.useMemo(()=>{let e=J.actions??[];if($.length===0)return e;let t=!1,n=e.map(e=>{let n=e;if(n&&typeof n==`object`&&n.type===`action:bar`&&(!n.location||n.location===`record_header`)){t=!0;let e=Array.isArray(n.systemActions)?n.systemActions:[];return{...n,systemActions:[...e,...$]}}return e});return t||n.push({type:`action:bar`,location:`record_header`,systemActions:$}),n},[J.actions,$]);return C||J.loading?(0,c.jsxs)(`div`,{className:(0,r.cn)(`space-y-4`,s),children:[(0,c.jsx)(r.Skeleton,{className:`h-10 w-full`}),(0,c.jsx)(r.Skeleton,{className:`h-64 w-full`}),(0,c.jsx)(r.Skeleton,{className:`h-48 w-full`})]}):!x&&!J.data?(0,c.jsxs)(`div`,{className:(0,r.cn)(`flex flex-col items-center justify-center py-16 text-center`,s),children:[(0,c.jsx)(`p`,{className:`text-lg font-semibold`,children:K(`detail.recordNotFound`)}),(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:K(`detail.recordNotFoundDescription`)}),(J.showBack??!0)&&(0,c.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:fe,className:`mt-4 gap-2`,children:[(0,c.jsx)(i.ArrowLeft,{className:`h-4 w-4`}),K(`detail.goBack`)]})]}):(0,c.jsx)(r.TooltipProvider,{children:(0,c.jsxs)(`div`,{className:(0,r.cn)(`space-y-6`,s),children:[J.showHeader!==!1&&(0,c.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start justify-between gap-3 sm:gap-4 pb-4 border-b`,children:[(0,c.jsxs)(`div`,{className:`flex items-start gap-2 sm:gap-3 flex-1 min-w-0`,children:[(J.showBack??!0)&&(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,onClick:fe,className:`shrink-0 mt-1`,children:(0,c.jsx)(i.ArrowLeft,{className:`h-4 w-4`})})}),(0,c.jsx)(r.TooltipContent,{children:K(`detail.back`)})]}),(0,c.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,c.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold truncate`,children:ve(x,J,F,K(`detail.details`))}),ue.map(e=>{let t=x?.[e];if(t==null||t===``)return null;let n=(J.sections||[]).flatMap(e=>e.fields).concat(J.fields||[]).find(t=>t.name===e),i=F?.fields?.[e],a=n?.type||i?.type,o=String(t),s=null;try{if(a===`currency`){let e=Number(t);if(!Number.isNaN(e)){let t=(0,u.resolveFieldCurrency)({...i,...n},q);o=t?new Intl.NumberFormat(void 0,{style:`currency`,currency:t,maximumFractionDigits:0}).format(e):new Intl.NumberFormat(void 0,{maximumFractionDigits:0}).format(e)}}else if(a===`date`||a===`datetime`){let e=new Date(t);Number.isNaN(e.getTime())||(o=a===`datetime`?e.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):e.toLocaleDateString(void 0,{dateStyle:`medium`}))}else if(a===`percent`){let e=Number(t);if(!Number.isNaN(e)){o=`${e}%`;let t=e<=1?e*100:e;s=Math.max(0,Math.min(100,t))}}else if(a===`select`||a===`status`||a===`multiselect`){let r=n?.options||i?.options,a=String(t);if(Array.isArray(r)){let e=r.find(e=>String(e?.value??e)===String(t));e?.label&&(a=e.label)}else if(r&&typeof r==`object`){let e=r[String(t)];e?.label&&(a=e.label)}o=J.objectName?ae(J.objectName,e,String(t),a):a}}catch{}return s===null?(0,c.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent hover:bg-primary/15`,"aria-label":`${e}: ${o}`,children:o},e):(0,c.jsxs)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent hover:bg-primary/15 gap-1.5 pl-2 pr-2`,"aria-label":`${e}: ${o}`,children:[(0,c.jsx)(`span`,{className:`relative inline-block h-1.5 w-12 rounded-full bg-primary/20 overflow-hidden`,"aria-hidden":!0,children:(0,c.jsx)(`span`,{className:`absolute inset-y-0 left-0 rounded-full bg-primary`,style:{width:`${s}%`}})}),o]},e)}),(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 shrink-0`,onClick:Z,"aria-label":K(O?`detail.removeFromFavorites`:`detail.addToFavorites`),children:O?(0,c.jsx)(i.Star,{className:`h-4 w-4 fill-yellow-400 text-yellow-400`}):(0,c.jsx)(i.Star,{className:`h-4 w-4 text-muted-foreground`})})}),(0,c.jsx)(r.TooltipContent,{children:K(O?`detail.removeFromFavorites`:`detail.addToFavorites`)})]})]}),J.objectName&&(0,c.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1 flex items-center gap-1`,children:[(0,c.jsx)(`span`,{className:`font-medium`,children:_||J.objectName}),J.resourceId&&(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-5 w-5 shrink-0 text-muted-foreground/60 hover:text-foreground`,onClick:de,"aria-label":K(`detail.copyRecordId`,{defaultValue:`Copy record ID`}),children:ee?(0,c.jsx)(i.Check,{className:`h-3 w-3 text-green-600`}):(0,c.jsx)(i.Copy,{className:`h-3 w-3`})})}),(0,c.jsx)(r.TooltipContent,{children:ee?K(`detail.copied`,{defaultValue:`Copied`}):K(`detail.copyRecordId`,{defaultValue:`Copy record ID`})})]})]})]})]}),(0,c.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 shrink-0 w-full sm:w-auto`,children:[J.recordNavigation&&(0,c.jsxs)(`div`,{className:`flex items-center gap-1 mr-2`,children:[(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:J.recordNavigation.currentIndex<=0,onClick:()=>{let e=J.recordNavigation;e.currentIndex>0&&e.onNavigate(e.recordIds[e.currentIndex-1])},children:(0,c.jsx)(i.ChevronLeft,{className:`h-4 w-4`})})}),(0,c.jsx)(r.TooltipContent,{children:K(`detail.previousRecord`)})]}),(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap px-1`,children:K(`detail.recordOf`,{current:J.recordNavigation.currentIndex+1,total:J.recordNavigation.recordIds.length})}),(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:J.recordNavigation.currentIndex>=J.recordNavigation.recordIds.length-1,onClick:()=>{let e=J.recordNavigation;e.currentIndex<e.recordIds.length-1&&e.onNavigate(e.recordIds[e.currentIndex+1])},children:(0,c.jsx)(i.ChevronRight,{className:`h-4 w-4`})})}),(0,c.jsx)(r.TooltipContent,{children:K(`detail.nextRecord`)})]})]}),J.showEdit&&(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsxs)(r.Button,{variant:`default`,onClick:pe,className:`gap-2 hidden sm:inline-flex`,children:[(0,c.jsx)(i.Edit,{className:`h-4 w-4`}),(0,c.jsx)(`span`,{className:`hidden sm:inline`,children:K(`detail.edit`)})]})}),(0,c.jsx)(r.TooltipContent,{children:K(`detail.editRecord`)})]}),xe.map((e,t)=>(0,c.jsx)(a.SchemaRenderer,{schema:e,data:x},`header-action-${t}`))]})]}),J.header&&(0,c.jsx)(`div`,{children:(0,c.jsx)(a.SchemaRenderer,{schema:J.header,data:x})}),J.highlightFields&&J.highlightFields.length>0&&(0,c.jsx)(V,{fields:J.highlightFields,data:x,objectName:J.objectName,objectSchema:F}),m&&J.showHeader===!1&&(()=>{let e=x?.approval_status,t=e===`pending`||e===`in_approval`;return!t&&!N?null:(0,c.jsxs)(`div`,{className:`flex flex-col items-end gap-1`,children:[t&&(0,c.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,c.jsxs)(`span`,{role:`status`,className:`inline-flex items-center gap-1 rounded-md border border-amber-300 bg-amber-50 px-2 py-1 text-xs text-amber-800`,title:K(`detail.lockedTooltip`),children:[(0,c.jsx)(i.Lock,{className:`h-3 w-3`}),(0,c.jsx)(`span`,{children:K(`detail.lockedByApproval`)})]}),o?.cancelPendingApproval&&(0,c.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:me,disabled:G,className:`gap-2 border-amber-300 text-amber-800 hover:bg-amber-50`,title:K(`detail.cancelApprovalTooltip`),children:[(0,c.jsx)(i.X,{className:`h-4 w-4`}),(0,c.jsx)(`span`,{children:K(G?`detail.cancelApprovalInFlight`:`detail.cancelApproval`)})]})]}),N&&(0,c.jsx)(`div`,{role:`alert`,className:`text-xs text-destructive bg-destructive/10 border border-destructive/20 rounded-md px-2 py-1 max-w-md text-right`,children:N})]})})(),J.autoTabs&&!J.tabs?.length?(()=>{let e=be.length>0,t=!!J.activities&&J.activities.length>0,n=!!h,i=!!J.history,a=[`details`,...e?[`related`]:[],...t?[`activity`]:[],...n?[`discussion`]:[],...i?[`history`]:[]],s=J.defaultTab,l=s&&a.includes(s)?s:`details`,u=J.onTabChange,d=(0,c.jsxs)(`div`,{className:`space-y-3 sm:space-y-4`,children:[J.sectionGroups&&J.sectionGroups.length>0&&J.sectionGroups.map((e,t)=>(0,c.jsx)(B,{group:e,data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:ye,onEnterInlineEdit:m?Q:void 0,autoFocusField:M,dataSource:o},t)),J.sections&&J.sections.length>0&&J.sections.map((e,t)=>(0,c.jsx)(L,{section:e,data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:ye,onEnterInlineEdit:m?Q:void 0,autoFocusField:M,dataSource:o},t)),J.fields&&J.fields.length>0&&!J.sections?.length&&(0,c.jsx)(L,{section:{fields:J.fields,columns:J.columns},data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:ye,onEnterInlineEdit:m?Q:void 0,autoFocusField:M,dataSource:o}),J.comments&&(0,c.jsx)(U,{comments:J.comments,onAddComment:J.onAddComment})]});return!e&&!t&&!n&&!i?(0,c.jsx)(`div`,{className:`mt-2`,children:d}):(0,c.jsxs)(r.Tabs,{defaultValue:l,onValueChange:u,className:`w-full`,children:[(0,c.jsxs)(r.TabsList,{className:`w-full justify-start border-b rounded-none bg-transparent p-0`,children:[(0,c.jsx)(r.TabsTrigger,{value:`details`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:K(`detail.details`)}),e&&(0,c.jsx)(r.TabsTrigger,{value:`related`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:(0,c.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[K(`detail.related`),(0,c.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:be.length})]})}),t&&(0,c.jsx)(r.TabsTrigger,{value:`activity`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:(0,c.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[K(`detail.activity`),(0,c.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:J.activities.length})]})}),n&&(0,c.jsx)(r.TabsTrigger,{value:`discussion`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:K(`detail.discussion`,{defaultValue:`Discussion`})}),i&&(0,c.jsx)(r.TabsTrigger,{value:`history`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:(0,c.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[K(`detail.history`,{defaultValue:`History`}),!J.history.loading&&J.history.entries.length>0&&(0,c.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:J.history.entries.length})]})})]}),(0,c.jsx)(r.TabsContent,{value:`details`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:d}),e&&(0,c.jsx)(r.TabsContent,{value:`related`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:(0,c.jsx)(`div`,{className:`space-y-3`,children:be.map((e,t)=>(0,c.jsx)(z,{title:e.title,type:e.type,api:e.api,data:e.data,columns:e.columns,dataSource:o,objectName:e.api,referenceField:e.referenceField,icon:e.icon,onNew:e.onNew,onViewAll:e.onViewAll,onRowClick:e.onRowClick,onRowEdit:e.onRowEdit,onRowDelete:e.onRowDelete,collapsible:!0,defaultCollapsed:oe&&t>0,pageSize:Y},t))})}),t&&(0,c.jsx)(r.TabsContent,{value:`activity`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:(0,c.jsx)(ie,{activities:J.activities})}),n&&(0,c.jsx)(r.TabsContent,{value:`discussion`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:h}),i&&(0,c.jsx)(r.TabsContent,{value:`history`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:(0,c.jsx)(le,{entries:J.history.entries,loading:J.history.loading,emptyText:J.history.emptyText??K(`detail.historyEmpty`,{defaultValue:`No history yet`})})})]})})():(0,c.jsxs)(c.Fragment,{children:[J.sectionGroups&&J.sectionGroups.length>0&&(0,c.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:J.sectionGroups.map((e,t)=>(0,c.jsx)(B,{group:e,data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:ye,onEnterInlineEdit:m?Q:void 0,autoFocusField:M,dataSource:o},t))}),J.sections&&J.sections.length>0&&(0,c.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:J.sections.map((e,t)=>(0,c.jsx)(L,{section:e,data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:ye,onEnterInlineEdit:m?Q:void 0,autoFocusField:M,dataSource:o},t))}),J.fields&&J.fields.length>0&&!J.sections?.length&&(0,c.jsx)(L,{section:{fields:J.fields,columns:J.columns},data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:ye,onEnterInlineEdit:m?Q:void 0,autoFocusField:M,dataSource:o}),J.tabs&&J.tabs.length>0&&(0,c.jsx)(R,{tabs:J.tabs,data:x}),be.length>0&&(0,c.jsxs)(`div`,{className:`space-y-3`,children:[(0,c.jsx)(`h2`,{className:`text-lg font-semibold`,children:K(`detail.related`)}),be.map((e,t)=>(0,c.jsx)(z,{title:e.title,type:e.type,api:e.api,data:e.data,columns:e.columns,dataSource:o,objectName:e.api,referenceField:e.referenceField,icon:e.icon,onNew:e.onNew,onViewAll:e.onViewAll,onRowClick:e.onRowClick,onRowEdit:e.onRowEdit,onRowDelete:e.onRowDelete,collapsible:!0,defaultCollapsed:oe&&t>0,pageSize:Y},t))]}),J.comments&&(0,c.jsx)(U,{comments:J.comments,onAddComment:J.onAddComment}),J.activities&&J.activities.length>0&&(0,c.jsx)(ie,{activities:J.activities})]}),(0,c.jsx)(ge,{data:{...x,...j},objectSchema:F,objectName:J.objectName}),J.footer&&(0,c.jsx)(`div`,{children:(0,c.jsx)(a.SchemaRenderer,{schema:J.footer,data:x})})]})})},Z=e=>typeof e==`string`?e:e&&typeof e==`object`&&(e.field||e.name)||null,ye=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},Q=({schema:e={},className:t,...n})=>{let r=(0,a.useRecordContext)(),{designer:i}=ye(n),o=r?.objectName||``,s=(0,l.usePermissions)(),{readableFields:d}=(0,l.useFieldPermissions)(o),{sectionLabel:f}=(0,a.useSafeFieldLabel)(),{language:p}=(0,u.useObjectTranslation)(),m=(0,a.useHighlightFieldNames)();if(!r)return(0,c.jsx)(`div`,{className:t,"data-record-details-placeholder":!0,...i,children:(0,c.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2 border border-dashed rounded`,children:`record:details — bind a record to preview`})});let h=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(h.length>0&&o&&!h.every(e=>s.can(o,e)))return(0,c.jsx)(`div`,{className:t,...i,role:`status`,"aria-live":`polite`,children:(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view details.`})});let g=e.layout===`inline`||e.layout===`compact`?`horizontal`:`vertical`,_=e.enforceFieldSecurity===!0,v=Array.isArray(e.redactFields)?e.redactFields:[],y=e=>{if(!e||!_&&v.length===0)return e;let t=e.map(Z).filter(e=>!!e),n=new Set((_&&o?d(t):t).filter(e=>!v.includes(e)));return e.filter(e=>{let t=Z(e);return!t||n.has(t)})},b=e=>typeof e==`string`?{name:e}:e&&typeof e==`object`&&!e.name&&e.field?{...e,name:e.field}:e,x=e=>Array.isArray(e)?e.map(b):e,S=new Set((Array.isArray(e.hideFields)?e.hideFields:[]).map(e=>typeof e==`string`?e:Z(e)).filter(e=>!!e));for(let e of m)S.add(e);let C=r.objectSchema,w=r.data??{},T=[C?.primaryField,`name`,`full_name`,`title`,`subject`,`display_name`,`label`].filter(e=>typeof e==`string`&&e.length>0);for(let e of T)if(w[e]!==void 0&&w[e]!==null&&w[e]!==``){S.add(e);break}let E=e=>!e||S.size===0?e:e.filter(e=>{let t=Z(e);return!t||!S.has(t)}),D=E(x(y(e.fields))),O=Array.isArray(e.sections)?e.sections.map(e=>{let t=e.title??e.label,n=t==null?void 0:(0,u.pickLocalized)(t,p),r=e.name&&o?f(o,e.name,n??e.name):n;return{...e,title:r,showBorder:e.showBorder??!!r,hideEmpty:e.hideEmpty??!0,fields:E(x(y(e.fields)))}}):e.sections,k=new Set([`system`,`append-only`,`better-auth`]),A=C?.managedBy,j=C?.userActions?.edit??!(A!=null&&k.has(A)),M=(e.inlineEdit??!0)&&j,N={type:`detail-view`,objectName:r.objectName,resourceId:r.recordId,data:r.data,layout:g,columns:e.columns,sections:O,fields:D,showBack:!1,showHeader:e.showHeader??!1,inlineEdit:M};return(0,c.jsx)(`div`,{className:t,...i,children:(0,c.jsx)(X,{schema:N,dataSource:r.dataSource,inlineEdit:M})})},be=e=>typeof e==`string`?e:e&&typeof e==`object`&&(e.field||e.name||e.key)||null,$=e=>e?.id??e?._id??null,xe=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},Se=({schema:e={},className:t,...r})=>{let i=(0,a.useRecordContext)(),{designer:s}=xe(r),d=(0,a.useSafeFieldLabel)(),{language:f}=(0,u.useObjectTranslation)(),p=e.objectName,m=p&&d.objectLabel?d.objectLabel({name:p,label:(0,o.humanizeLabel)(p)}):p?(0,o.humanizeLabel)(p):``,h=(0,u.pickLocalized)(e.title,f)||m||`Related`;if(!p)return(0,c.jsx)(`div`,{className:t,...s,children:(0,c.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2 border border-dashed rounded`,children:`record:related_list — missing objectName`})});let g=(0,l.usePermissions)(),{readableFields:_}=(0,l.useFieldPermissions)(p),v=e.relationshipValueField||`id`,y=v===`id`?i?.recordId??null:i?.data?.[v]??null,b=(0,a.useRelatedRecordActions)(),x=n.default.useMemo(()=>b?.resolve({objectName:p,relationshipField:e.relationshipField,parentId:y})??null,[b,p,e.relationshipField,y]);if(g.isLoaded&&!g.can(p,`read`))return null;let S=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(S.length>0&&!S.every(e=>g.can(p,e)))return(0,c.jsx)(`div`,{className:t,...s,role:`status`,"aria-live":`polite`,children:(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view related list.`})});let C=e.enforceFieldSecurity===!0,w=Array.isArray(e.redactFields)?e.redactFields:[],T=Array.isArray(e.columns)?e.columns:[],E=T;if(C||w.length>0){let e=T.map(be).filter(e=>!!e),t=new Set((C?_(e):e).filter(e=>!w.includes(e)));E=T.filter(e=>{let n=be(e);return!n||t.has(n)})}return(0,c.jsx)(`div`,{className:t,...s,children:(0,c.jsx)(z,{title:h,type:`table`,api:p,objectName:p,referenceField:e.relationshipField,parentId:y,columns:E,pageSize:e.limit,dataSource:i?.dataSource,add:e.add?{...e.add,label:(0,u.pickLocalized)(e.add.label,f)||void 0}:void 0,rowActions:x?.rowActions,onRowAction:x?.onRowAction,toolbarActions:x?.toolbarActions,onToolbarAction:x?.onToolbarAction,onNew:x?.onCreate,onRowClick:x?.onView?e=>{let t=$(e);t!=null&&x.onView(t,e)}:void 0,onRowEdit:x?.onEdit?e=>{let t=$(e);t!=null&&x.onEdit(t,e)}:void 0,onRowDelete:x?.onDelete?e=>{let t=$(e);if(t!=null)return x.onDelete(t,e)}:e.add&&i?.dataSource?async e=>{let t=e?.id??e?._id;t!=null&&await i.dataSource.delete?.(p,String(t))}:void 0})})},Ce=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},we=({schema:e={},className:t,...r})=>{let i=(0,a.useRecordContext)(),{designer:o}=Ce(r),s=i?.objectName||``,u=(0,l.usePermissions)(),{readableFields:d}=(0,l.useFieldPermissions)(s),f=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(f.length>0&&s&&!f.every(e=>u.can(s,e)))return(0,c.jsx)(`div`,{className:t,...o,role:`status`,"aria-live":`polite`,children:(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view highlights.`})});let p=(Array.isArray(e.fields)?e.fields:[]).map(e=>typeof e==`string`?{name:e}:{name:e?.name,label:e?.label,icon:e?.icon,type:e?.type}).filter(e=>typeof e.name==`string`&&e.name.length>0),m=e.enforceFieldSecurity===!0,h=Array.isArray(e.redactFields)?e.redactFields:[],g=m&&s?new Set(d(p.map(e=>e.name))):null,_=p.filter(e=>!(h.includes(e.name)||g&&!g.has(e.name)));return(0,a.useRegisterHighlightFields)(n.default.useId(),_.map(e=>e.name)),(0,c.jsx)(`div`,{className:t,...o,children:(0,c.jsx)(V,{fields:_,data:i?.data,objectName:i?.objectName,objectSchema:i?.objectSchema,dataSource:i?.dataSource})})},Te=({change:e,className:t})=>{let n=e.fieldLabel??e.field.charAt(0).toUpperCase()+e.field.slice(1).replace(/_/g,` `),a=e.oldDisplayValue??(e.oldValue==null?`(empty)`:String(e.oldValue)),o=e.newDisplayValue??(e.newValue==null?`(empty)`:String(e.newValue));return(0,c.jsxs)(`div`,{className:(0,r.cn)(`flex items-center gap-1.5 text-sm flex-wrap`,t),children:[(0,c.jsx)(`span`,{className:`font-medium text-foreground`,children:n}),(0,c.jsx)(`span`,{className:`text-muted-foreground line-through`,children:a}),(0,c.jsx)(i.ArrowRight,{className:`h-3 w-3 text-muted-foreground shrink-0`}),(0,c.jsx)(`span`,{className:`text-foreground`,children:o})]})},Ee=[`👍`,`❤️`,`🎉`,`😂`,`😮`,`😢`],De=({reactions:e,onToggleReaction:t,emojiOptions:a=Ee,className:o})=>{let[s,l]=n.useState(!1),u=n.useCallback(e=>{t?.(e),l(!1)},[t]);return(0,c.jsxs)(`div`,{className:(0,r.cn)(`flex items-center gap-1 flex-wrap`,o),children:[e.map(e=>(0,c.jsxs)(`button`,{type:`button`,className:(0,r.cn)(`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs border transition-colors`,e.reacted?`bg-primary/10 border-primary/30 text-primary`:`bg-muted border-border text-muted-foreground hover:bg-muted/80`),onClick:()=>u(e.emoji),disabled:!t,"aria-label":`${e.emoji} ${e.count} reaction${e.count===1?``:`s`}`,children:[(0,c.jsx)(`span`,{children:e.emoji}),(0,c.jsx)(`span`,{children:e.count})]},e.emoji)),t&&(0,c.jsxs)(`div`,{className:`relative`,children:[(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>l(!s),"aria-label":`Add reaction`,children:(0,c.jsx)(i.SmilePlus,{className:`h-3.5 w-3.5`})}),s&&(0,c.jsx)(`div`,{className:`absolute bottom-full mb-1 left-0 bg-popover border rounded-md shadow-md z-50 p-1.5 flex gap-1`,role:`listbox`,"aria-label":`Emoji picker`,children:a.map(t=>(0,c.jsx)(`button`,{type:`button`,className:`hover:bg-accent rounded p-1 text-base transition-colors`,onClick:()=>u(t),role:`option`,"aria-selected":e.some(e=>e.emoji===t&&e.reacted),children:t},t))})]})]})};function Oe(e,t){try{let n=new Date(e),r=new Date().getTime()-n.getTime(),i=Math.floor(r/6e4);if(i<1)return t(`detail.justNow`);if(i<60)return t(`detail.minutesAgo`,{count:i});let a=Math.floor(i/60);if(a<24)return t(`detail.hoursAgo`,{count:a});let o=Math.floor(a/24);return o<7?t(`detail.daysAgo`,{count:o}):n.toLocaleDateString()}catch{return e}}var ke=({parentItem:e,replies:t,onAddReply:a,showReplyInput:o=!0,className:s})=>{let{t:l}=D(),[u,d]=n.useState(!1),[f,p]=n.useState(``),[m,h]=n.useState(!1),g=n.useCallback(async()=>{let t=f.trim();if(!(!t||!a)){h(!0);try{await a(e.id,t),p(``)}finally{h(!1)}}},[f,a,e.id]),_=n.useCallback(e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),g())},[g]);return t.length===0&&!o?null:(0,c.jsxs)(`div`,{className:(0,r.cn)(`ml-10 mt-1`,s),children:[t.length>0&&(0,c.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors mb-1`,onClick:()=>d(!u),"aria-expanded":u,children:[u?(0,c.jsx)(i.ChevronDown,{className:`h-3 w-3`}):(0,c.jsx)(i.ChevronRight,{className:`h-3 w-3`}),(0,c.jsx)(i.MessageSquare,{className:`h-3 w-3`}),(0,c.jsx)(`span`,{children:t.length===1?l(`detail.replyCount`,{count:t.length}):l(`detail.replyCountPlural`,{count:t.length})})]}),u&&(0,c.jsx)(`div`,{className:`space-y-2 border-l-2 border-border pl-3`,children:t.map(e=>(0,c.jsxs)(`div`,{className:`flex gap-2`,children:[(0,c.jsx)(`div`,{className:`shrink-0`,children:e.actorAvatarUrl?(0,c.jsx)(`img`,{src:e.actorAvatarUrl,alt:e.actor,className:`h-6 w-6 rounded-full object-cover`}):(0,c.jsx)(`div`,{className:`h-6 w-6 rounded-full bg-muted flex items-center justify-center text-[10px] font-medium text-muted-foreground`,children:e.actor.charAt(0).toUpperCase()})}),(0,c.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,c.jsx)(`span`,{className:`text-xs font-medium`,children:e.actor}),(0,c.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:Oe(e.createdAt,l)})]}),(0,c.jsx)(`p`,{className:`text-xs whitespace-pre-wrap break-words`,children:e.body})]})]},e.id))}),o&&a&&(0,c.jsxs)(`div`,{className:`flex gap-1.5 mt-1.5`,children:[(0,c.jsx)(`input`,{className:`flex-1 rounded-md border border-input bg-background px-2 py-1 text-xs placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,placeholder:l(`detail.replyPlaceholder`),value:f,onChange:e=>p(e.target.value),onKeyDown:_,disabled:m}),(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 shrink-0`,onClick:g,disabled:!f.trim()||m,"aria-label":`Send reply`,children:(0,c.jsx)(i.Send,{className:`h-3 w-3`})})]})]})},Ae=({subscription:e,onToggle:t,className:a})=>{let{t:o}=D(),[s,l]=n.useState(!1),u=n.useCallback(async()=>{if(t){l(!0);try{await t(!e.subscribed)}finally{l(!1)}}},[t,e.subscribed]);return(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:(0,r.cn)(`h-8 w-8`,a),onClick:u,disabled:s||!t,"aria-label":e.subscribed?o(`detail.unsubscribeAriaLabel`):o(`detail.subscribeAriaLabel`),title:e.subscribed?o(`detail.subscribedTooltip`):o(`detail.unsubscribedTooltip`),children:e.subscribed?(0,c.jsx)(i.Bell,{className:`h-4 w-4 text-primary`}):(0,c.jsx)(i.BellOff,{className:`h-4 w-4 text-muted-foreground`})})};function je(e){let t=e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/```([\s\S]*?)```/g,`<pre class="bg-muted rounded p-2 text-xs font-mono my-1 overflow-x-auto">$1</pre>`).replace(/`([^`]+)`/g,`<code class="bg-muted rounded px-1 py-0.5 text-xs font-mono">$1</code>`).replace(/\*\*(.+?)\*\*/g,`<strong>$1</strong>`).replace(/\*(.+?)\*/g,`<em>$1</em>`).replace(/@(\w+)/g,`<span class="text-primary font-medium">@$1</span>`).replace(/^- (.+)$/gm,`<li class="ml-4 list-disc">$1</li>`).replace(/\n/g,`<br/>`);return t=t.replace(/(<li[^>]*>.*?<\/li>(?:<br\/>)?)+/g,e=>`<ul class="my-1">${e.replace(/<br\/>/g,``)}</ul>`),t}var Me=({value:e,onChange:t,onSubmit:a,mentionSuggestions:o=[],placeholder:s,className:l,disabled:u=!1,extraSlot:d,canSubmitEmpty:f=!1})=>{let{t:p}=D(),[m,h]=n.useState(!1),[g,_]=n.useState(!1),[v,y]=n.useState(``),[b,x]=n.useState(0),S=n.useRef(null),C=n.useMemo(()=>{if(!v)return o;let e=v.toLowerCase();return o.filter(t=>t.label.toLowerCase().includes(e))},[v,o]),w=n.useCallback((n,r=``)=>{let i=S.current;if(!i)return;let a=i.selectionStart,o=i.selectionEnd,s=e.slice(a,o);t(e.slice(0,a)+n+s+r+e.slice(o)),requestAnimationFrame(()=>{i.focus();let e=a+n.length+s.length;i.setSelectionRange(e,e)})},[e,t]),T=n.useCallback(()=>w(`**`,`**`),[w]),E=n.useCallback(()=>w(`*`,`*`),[w]),O=n.useCallback(()=>w(`
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@object-ui/core"),require("react"),require("@object-ui/components"),require("lucide-react"),require("@object-ui/react"),require("@object-ui/fields"),require("react-router-dom"),require("react/jsx-runtime"),require("@object-ui/permissions"),require("@object-ui/i18n"),require("@objectstack/spec/data"),require("@object-ui/types")):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`react`,`@object-ui/components`,`lucide-react`,`@object-ui/react`,`@object-ui/fields`,`react-router-dom`,`react/jsx-runtime`,`@object-ui/permissions`,`@object-ui/i18n`,`@objectstack/spec/data`,`@object-ui/types`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginDetail={},e.ObjectUICore,e.React,e.ObjectUIComponents,e.LucideReact,e.ObjectUIReact,e.ObjectUIFields,e.react_router_dom,e.jsxRuntime,e._object_ui_permissions,e._object_ui_i18n,e._objectstack_spec_data,e.ObjectUITypes))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var p=Object.create,m=Object.defineProperty,h=Object.getOwnPropertyDescriptor,g=Object.getOwnPropertyNames,_=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty,y=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=g(t),a=0,o=i.length,s;a<o;a++)s=i[a],!v.call(e,s)&&s!==n&&m(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=h(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:p(_(e)),y(t||!e||!e.__esModule?m(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var b=new Set([`textarea`,`markdown`,`html`,`grid`,`rich-text`,`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`]);function x(e){return b.has(e)}function S(e,t){let n;return n=e<=3?1:e<=8?2:e<=15?3:4,t!==void 0&&t<640?Math.min(n,1):n}function C(e,t){return t<=1?e:e.map(e=>e.span===void 0&&e.type&&x(e.type)?{...e,span:t}:e)}function w(e,t,n){if(t!==void 0)return{fields:C(e,t),columns:t};let r=S(e.length,n);return{fields:C(e,r),columns:r}}function T(e,t){return function(){try{let n=(0,a.useObjectTranslation)();return n.t(t)===t?{t:(t,n)=>{let r=e[t]||t;if(n)for(let[e,t]of Object.entries(n))r=r.replace(`{{${e}}}`,String(t));return r}}:{t:n.t}}catch{return{t:(t,n)=>{let r=e[t]||t;if(n)for(let[e,t]of Object.entries(n))r=r.replace(`{{${e}}}`,String(t));return r}}}}}var E={"detail.back":`Back`,"detail.edit":`Edit`,"detail.editInline":`Edit`,"detail.save":`Save`,"detail.saveChanges":`Save changes`,"detail.editFieldsInline":`Edit fields inline`,"detail.editInlineHint":`Double-click to edit`,"detail.cancel":`Cancel`,"detail.cancelEdit":`Discard changes`,"detail.openInNewTab":`Open in new tab`,"detail.share":`Share`,"detail.duplicate":`Duplicate`,"detail.export":`Export`,"detail.viewHistory":`View history`,"detail.delete":`Delete`,"detail.moreActions":`More actions`,"detail.addToFavorites":`Add to favorites`,"detail.removeFromFavorites":`Remove from favorites`,"detail.previousRecord":`Previous record`,"detail.nextRecord":`Next record`,"detail.recordOf":`{{current}} of {{total}}`,"detail.recordNotFound":`Record not found`,"detail.recordNotFoundDescription":`The record you are looking for does not exist or may have been deleted.`,"detail.goBack":`Go back`,"detail.details":`Details`,"detail.related":`Related`,"detail.relatedRecords":`{{count}} records`,"detail.relatedRecordOne":`{{count}} record`,"detail.noRelatedRecords":`No related records found`,"detail.loading":`Loading...`,"detail.copyToClipboard":`Copy to clipboard`,"detail.copied":`Copied!`,"detail.deleteConfirmation":`Are you sure you want to delete this record?`,"detail.editRecord":`Edit record`,"detail.viewAll":`View All`,"detail.new":`New`,"detail.emptyValue":`—`,"detail.noValue":`No value`,"detail.activity":`Activity`,"detail.copyRecordId":`Copy record ID`,"detail.showEmptyFields":`Show {{count}} empty fields`,"detail.hideEmptyFields":`Hide empty fields`,"detail.editRow":`Edit`,"detail.deleteRow":`Delete`,"detail.deleteRowConfirmation":`Are you sure you want to delete this record?`,"detail.actions":`Actions`,"detail.previousPage":`Previous`,"detail.nextPage":`Next`,"detail.pageOf":`Page {{current}} of {{total}}`,"detail.sortBy":`Sort by`,"detail.filterPlaceholder":`Filter...`,"detail.highlightFields":`Key Fields`,"detail.comments":`Comments`,"detail.searchComments":`Search comments…`,"detail.addCommentPlaceholder":`Add a comment… (Ctrl+Enter to submit)`,"detail.noMatchingComments":`No matching comments`,"detail.noCommentsYet":`No comments yet`,"detail.pinned":`Pinned`,"detail.pin":`Pin`,"detail.unpin":`Unpin`,"detail.justNow":`just now`,"detail.minutesAgo":`{{count}}m ago`,"detail.hoursAgo":`{{count}}h ago`,"detail.daysAgo":`{{count}}d ago`,"detail.createdBy":`Created by`,"detail.updatedBy":`Updated by`,"detail.created":`Created`,"detail.updated":`Updated`,"detail.dropFilesToUpload":`Drop files here or click to upload`,"detail.attachmentCount":`{{count}} attachment`,"detail.attachmentCountPlural":`{{count}} attachments`,"detail.removeAttachment":`Remove attachment`,"detail.unifiedDiff":`Unified diff`,"detail.sideBySideDiff":`Side-by-side diff`,"detail.noChanges":`No changes`,"detail.previousVersion":`Previous`,"detail.currentVersion":`Current`,"detail.discussion":`Discussion`,"detail.showDiscussion":`Show Discussion ({{count}})`,"detail.hideDiscussion":`Hide discussion`,"detail.bold":`Bold (Ctrl+B)`,"detail.italic":`Italic (Ctrl+I)`,"detail.listFormat":`List`,"detail.inlineCode":`Inline code`,"detail.mentionSomeone":`Mention someone`,"detail.preview":`Preview`,"detail.submitComment":`Submit (Ctrl+Enter)`,"detail.sendComment":`Send`,"detail.writeComment":`Write a comment…`,"detail.subscribedTooltip":`Subscribed — click to unsubscribe`,"detail.unsubscribedTooltip":`Subscribe to notifications`,"detail.firstRecord":`First record (Home)`,"detail.previousRecordKey":`Previous record (←)`,"detail.nextRecordKey":`Next record (→)`,"detail.lastRecord":`Last record (End)`,"detail.noRecords":`No records`,"detail.showEmptyRelated_one":`+ {{count}} empty`,"detail.showEmptyRelated_other":`+ {{count}} empty`,"detail.searchWhileNavigating":`Search while navigating`,"detail.searchRecords":`Search records…`,"detail.allActivity":`All Activity`,"detail.commentsOnly":`Comments Only`,"detail.fieldChangesFilter":`Field Changes`,"detail.tasksOnly":`Tasks Only`,"detail.leaveCommentPlaceholder":`Leave a comment… (Ctrl+Enter to submit)`,"detail.noActivity":`No activity recorded`,"detail.loadMore":`Load more`,"detail.edited":`(edited)`,"detail.via":`via {{source}}`,"detail.viewSource":`View source`,"detail.replyCount":`{{count}} reply`,"detail.replyCountPlural":`{{count}} replies`,"detail.replyPlaceholder":`Reply…`,"detail.filterActivity":`Filter activity`,"detail.openDiscussion":`Open discussion panel`,"detail.closeDiscussion":`Close discussion panel`,"detail.subscribeAriaLabel":`Subscribe to notifications`,"detail.unsubscribeAriaLabel":`Unsubscribe from notifications`,"detail.clearSearch":`Clear search`,"detail.concurrentUpdateTitle":`This record was modified by someone else`,"detail.concurrentUpdateDescription":`Another user saved a newer version of {{field}} while you were editing. To prevent silently overwriting their change, please choose how to resolve the conflict.`,"detail.concurrentUpdateYourEdit":`Your edit`,"detail.concurrentUpdateCurrentValue":`Current value`,"detail.concurrentUpdateUpdatedBy":`Updated by {{name}}`,"detail.concurrentUpdateUpdatedAt":`Updated at {{when}}`,"detail.concurrentUpdateReload":`Reload latest`,"detail.concurrentUpdateOverwrite":`Overwrite anyway`,"detail.concurrentUpdateCancel":`Cancel`,"detail.lockedByApproval":`Locked for approval`,"detail.lockedTooltip":`This record has a pending approval request; editing is locked`,"detail.cancelApproval":`Recall approval`,"detail.cancelApprovalInFlight":`Recalling…`,"detail.cancelApprovalTooltip":`Recall the pending approval request to unlock this record`,"detail.cancelApprovalFailed":`Failed to recall approval`,"detail.cancelApprovalUnavailable":`Recalling approvals is not supported on this data source`},D=T(E,`detail.back`);function O(e){if(typeof e==`string`){let t=e.trim();if(!t)return null;try{return JSON.parse(t)}catch{return t}}return e??null}function k(e){let t=O(e);return t==null||t===``?0:Array.isArray(t)?t.length:typeof t==`object`?Object.keys(t).length:1}function A({value:e,field:t}){let{t:n}=D(),i=(0,a.useRecordContext)(),{appName:l}=(0,s.useParams)(),u=t?.name||``,d=i?.data?.name,f=l&&d?`/apps/${l}/metadata/permission/${encodeURIComponent(String(d))}`:null,p=k(e),m=p===0;return(0,c.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-2 gap-y-1 text-sm`,children:[(()=>{if(m)return(0,c.jsx)(`span`,{className:`text-muted-foreground`,children:n(`perm.facet.none`,{defaultValue:`None`})});if(u===`system_permissions`){let t=(0,o.parseCapabilityNames)(e),i=t.slice(0,6),a=t.length-i.length;return(0,c.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-1`,children:[i.map(e=>(0,c.jsx)(r.Badge,{variant:`outline`,children:e},e)),a>0&&(0,c.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:n(`perm.facet.more`,{count:a,defaultValue:`+${a} more`})})]})}return(0,c.jsx)(`span`,{className:`text-foreground`,children:(()=>{switch(u){case`object_permissions`:return n(`perm.facet.objects`,{count:p,defaultValue:`${p} object${p===1?``:`s`}`});case`field_permissions`:return n(`perm.facet.fields`,{count:p,defaultValue:`${p} field rule${p===1?``:`s`}`});case`row_level_security`:return n(`perm.facet.rls`,{count:p,defaultValue:`${p} RLS polic${p===1?`y`:`ies`}`});case`tab_permissions`:return n(`perm.facet.tabs`,{count:p,defaultValue:`${p} tab rule${p===1?``:`s`}`});case`admin_scope`:return n(`perm.facet.adminScope`,{defaultValue:`Delegated admin configured`});default:return String(p)}})()})})(),f?(0,c.jsx)(s.Link,{to:f,className:`text-primary hover:underline whitespace-nowrap`,children:n(`perm.facet.designInStudio`,{defaultValue:`Design in Studio →`})}):(0,c.jsx)(`span`,{className:`text-muted-foreground/60 whitespace-nowrap`,children:n(`perm.facet.designInStudioHint`,{defaultValue:`Design in Studio`})})]})}var j=new Set([`id`,`_id`,`__v`,`created`,`created_at`,`createdAt`,`created_by`,`modified`,`modified_by`,`updated_at`,`updatedAt`,`updated_by`,`deleted_at`,`is_deleted`,`deleted`,`instance_state`]),M=new Set([`formula`,`summary`,`rollup`,`auto_number`]);function N(e){if(e==null)return e;if(Array.isArray(e))return e.map(N);if(typeof e==`object`){let t=e;return t.id??t._id??t.value??``}return e}var P=({field:e,value:t,onChange:n,dataSource:r,autoFocus:i})=>{let a=e.type,s=e.widget;if(s===`permission-facet-link`)return(0,c.jsx)(A,{value:t,field:e});if(s===`capability-multiselect`)return(0,c.jsx)(o.CapabilityMultiSelectField,{value:t,onChange:e=>n(e),field:e,dataSource:r});if(a===`select`&&Array.isArray(e.options)&&e.options.length>0)return(0,c.jsx)(o.SelectField,{field:e,value:t==null?``:String(t),onChange:e=>n(e)});if(a===`boolean`)return(0,c.jsx)(o.BooleanField,{field:e,value:!!t,onChange:e=>n(e)});let l=a===`user`||a===`owner`,u=a===`lookup`||a===`master_detail`||a===`tree`||!!e.reference_to&&!M.has(a);if(l||u)return(0,c.jsx)(l?o.UserField:o.LookupField,{field:e,value:t,onChange:e=>n(e),dataSource:r});if(a===`number`)return(0,c.jsx)(o.NumberField,{field:e,value:t,onChange:e=>n(e),autoFocus:i});if(a===`currency`)return(0,c.jsx)(o.CurrencyField,{field:e,value:t,onChange:e=>n(e),autoFocus:i});if(a===`percent`)return(0,c.jsx)(o.PercentField,{field:e,value:t,onChange:e=>n(e),autoFocus:i});let d=a===`date`||a===`datetime`;return(0,c.jsx)(`input`,{type:d?`date`:`text`,autoFocus:i,className:`w-full px-2 py-1.5 text-sm border rounded-md bg-background focus:outline-none focus:ring-2 focus:ring-ring`,value:t==null?``:d?(()=>{let e=String(t);if(/^\d{4}-\d{2}-\d{2}/.test(e))return e.slice(0,10);let n=new Date(e);return isNaN(n.getTime())?``:n.toLocaleDateString(`en-CA`)})():String(typeof t==`object`?(0,o.coerceToSafeValue)(t)??``:t),onChange:e=>{let t=e.target.value;n(d&&t?new Date(t+`T00:00:00`).toISOString():t)}})},F=({name:e})=>/^[a-z0-9][a-z0-9-]*$/i.test(e)?(0,c.jsx)(r.LazyIcon,{name:e,className:`h-4 w-4 shrink-0 text-muted-foreground`,"aria-hidden":!0}):(0,c.jsx)(`span`,{className:`text-muted-foreground`,children:e});function I(e,t){return!e||e<=1||t<=1?``:t===2?e>=2?`md:col-span-2`:``:t===3?e===2?`md:col-span-2`:e>=3?`md:col-span-2 lg:col-span-3`:``:e===2?`md:col-span-2`:e===3?`md:col-span-2 lg:col-span-3`:e>=4?`md:col-span-2 lg:col-span-3 xl:col-span-4`:``}var L=({section:e,data:t,className:s,objectSchema:l,objectName:u,isEditing:d=!1,onFieldChange:f,onEnterInlineEdit:p,autoFocusField:m,dataSource:h,virtualScroll:g})=>{let[_,v]=n.useState(e.defaultCollapsed??!1),[y,b]=n.useState(null),[x,S]=n.useState(void 0),[C,T]=n.useState(!1),{t:E}=D(),{fieldLabel:O,translateOptions:k}=(0,a.useSafeFieldLabel)(),N=n.useCallback((e,t)=>{let n=t==null?``:String(t);navigator.clipboard.writeText(n).then(()=>{b(e),setTimeout(()=>b(null),2e3)})},[]),L=n.useCallback(e=>{let n=t?.[e.name]??e.value;return n==null||n===``},[t]),R=n.useMemo(()=>e.fields.filter(L).length,[e.fields,L]),ee=(0,r.useIsMobile)(),te=ee?3:4,z=ee?.2:.25,B=e.fields.length-R,V=!e.hideEmpty&&!d&&e.fields.length>=te&&R/e.fields.length>=z&&B>0,H=!C&&(e.hideEmpty||V)?e.fields.filter(e=>!L(e)):e.fields,{fields:U,columns:W}=w(H,e.columns),ne=Math.min(W,Math.max(1,H.length)),G=e=>{let n=t?.[e.name]??e.value;if(e.render)return(0,c.jsx)(a.SchemaRenderer,{schema:e.render,data:{...t,value:n}});let s=I(e.span,ne),g=l?.fields?.[e.name],_={...e};if(g){!e.type&&g.type&&(_.type=g.type),g.options&&!_.options&&(_.options=g.options),g.currency&&!_.currency&&(_.currency=g.currency),g.precision!==void 0&&_.precision===void 0&&(_.precision=g.precision),g.scale!==void 0&&_.scale===void 0&&(_.scale=g.scale),g.min!==void 0&&_.min===void 0&&(_.min=g.min),g.max!==void 0&&_.max===void 0&&(_.max=g.max),g.step!==void 0&&_.step===void 0&&(_.step=g.step),g.format&&!_.format&&(_.format=g.format),g.widget&&!_.widget&&(_.widget=g.widget);let t=g.reference_to||g.reference;t&&!_.reference_to&&(_.reference_to=t),g.reference_field&&!_.reference_field&&(_.reference_field=g.reference_field),g.dueLike!==void 0&&_.dueLike===void 0&&(_.dueLike=g.dueLike)}u&&Array.isArray(_.options)&&_.options.length>0&&(_.options=k(u,e.name,_.options));let v=_.type||e.type,b=M.has(v),x=e.readonly===!0||g?.readonly===!0,S=j.has(e.name),C=!x&&!b&&!S,w=C&&!!p,T=(()=>{if((_.widget||e.widget)===`permission-facet-link`)return(0,c.jsx)(A,{value:n,field:_});if(n==null||n===``)return(0,c.jsx)(`span`,{className:`text-muted-foreground/60 text-sm select-none`,"aria-label":E(`detail.noValue`,{defaultValue:`No value`}),title:E(`detail.noValue`,{defaultValue:`No value`}),children:`—`});let t=(0,o.resolveCellRendererType)(_)||e.type;if(t){let e=(0,o.getCellRenderer)(t);if(e)return(0,c.jsx)(e,{value:n,field:_})}return String(n)})(),D=n!=null&&n!==``,F=D&&!w,L=y===e.name,R=O(u||``,e.name,e.label||e.name);return ee&&!(d&&C)?(0,c.jsxs)(`div`,{className:(0,r.cn)(`flex items-baseline justify-between gap-4 py-2.5 min-h-[44px] group`,D&&`cursor-pointer active:bg-muted/40 transition-colors`),onClick:D?()=>N(e.name,n):void 0,onKeyDown:D?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),N(e.name,n))}:void 0,role:D?`button`:void 0,tabIndex:D?0:void 0,children:[(0,c.jsx)(`span`,{className:`text-[15px] text-muted-foreground shrink-0`,children:R}),(0,c.jsx)(`span`,{className:`text-[15px] text-foreground text-right break-words min-w-0 leading-snug`,children:T})]},e.name):(0,c.jsxs)(`div`,{className:(0,r.cn)(`space-y-1.5 group min-w-0`,s),children:[(0,c.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:O(u||``,e.name,e.label||e.name)}),d&&C?(0,c.jsx)(`div`,{className:`min-h-[44px] sm:min-h-0`,children:(0,c.jsx)(P,{field:_,value:n,onChange:t=>f?.(e.name,t),dataSource:h,autoFocus:m===e.name})}):(0,c.jsxs)(`div`,{className:(0,r.cn)(`flex items-start justify-between gap-2 min-h-[44px] sm:min-h-0 rounded-md`,F&&`cursor-pointer active:bg-muted/60 transition-colors`,w&&`cursor-pointer hover:bg-muted/40 transition-colors -mx-1.5 px-1.5`),onClick:F?()=>N(e.name,n):void 0,onDoubleClick:w?()=>p?.(e.name):void 0,onKeyDown:F?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),N(e.name,n))}:void 0,role:F?`button`:void 0,tabIndex:F?0:void 0,title:w?E(`detail.editInlineHint`):void 0,children:[(0,c.jsx)(`div`,{className:`text-sm flex-1 min-w-0 break-words py-1`,children:T}),w?(0,c.jsx)(r.TooltipProvider,{children:(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,"aria-label":E(`detail.editInlineHint`),onClick:t=>{t.stopPropagation(),p?.(e.name)},children:(0,c.jsx)(i.Pencil,{className:`h-3 w-3`})})}),(0,c.jsx)(r.TooltipContent,{children:E(`detail.editInlineHint`)})]})}):D?(0,c.jsx)(r.TooltipProvider,{children:(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,onClick:t=>{t.stopPropagation(),N(e.name,n)},children:L?(0,c.jsx)(i.Check,{className:`h-3 w-3 text-green-600`}):(0,c.jsx)(i.Copy,{className:`h-3 w-3`})})}),(0,c.jsx)(r.TooltipContent,{children:E(L?`detail.copied`:`detail.copyToClipboard`)})]})}):null]})]},e.name)},re=g?.enabled===!0,K=g?.batchSize??20;if(n.useEffect(()=>{if(!re){S(void 0);return}if(U.length<=K){S(void 0);return}S(K);let e=setTimeout(()=>S(void 0),100);return()=>clearTimeout(e)},[re,U.length,K]),H.length===0&&R===e.fields.length)return null;let ie=x===void 0?U:U.slice(0,x),q=R>0&&(e.hideEmpty||V),ae=(0,c.jsxs)(c.Fragment,{children:[ee?(0,c.jsx)(`div`,{className:`flex flex-col divide-y divide-border/60`,children:ie.map(G)}):(0,c.jsx)(`div`,{className:(0,r.cn)(`grid gap-3 sm:gap-4`,ne===1?`grid-cols-1`:ne===2?`grid-cols-1 md:grid-cols-2`:ne===3?`grid-cols-1 md:grid-cols-2 lg:grid-cols-3`:`grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`),children:ie.map(G)}),q&&(0,c.jsx)(`div`,{className:`mt-3 -ml-2`,children:(0,c.jsxs)(r.Button,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>T(e=>!e),className:`h-7 px-2 text-xs text-muted-foreground hover:text-foreground`,children:[C?(0,c.jsx)(i.EyeOff,{className:`h-3.5 w-3.5 mr-1.5`}):(0,c.jsx)(i.Eye,{className:`h-3.5 w-3.5 mr-1.5`}),C?E(`detail.hideEmptyFields`,{defaultValue:`Hide empty fields`}):E(`detail.showEmptyFields`,{count:R,defaultValue:`Show ${R} empty field${R===1?``:`s`}`})]})})]});return!e.title&&!e.collapsible&&e.showBorder===!1?(0,c.jsx)(`div`,{className:(0,r.cn)(s),children:ae}):e.collapsible?(0,c.jsx)(r.Collapsible,{open:!_,onOpenChange:e=>v(!e),className:s,children:(0,c.jsxs)(r.Card,{children:[(0,c.jsx)(r.CollapsibleTrigger,{asChild:!0,children:(0,c.jsxs)(r.CardHeader,{className:(0,r.cn)(`py-3 px-4 sm:py-4 sm:px-6 cursor-pointer hover:bg-muted/50 transition-colors`,e.headerColor&&`bg-${e.headerColor}`),children:[(0,c.jsxs)(r.CardTitle,{className:`flex items-center justify-between text-base font-semibold tracking-tight`,children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,c.jsx)(F,{name:e.icon}),(0,c.jsx)(`span`,{children:e.title})]}),(0,c.jsx)(`div`,{className:`flex items-center gap-2`,children:_?(0,c.jsx)(i.ChevronRight,{className:`h-4 w-4 text-muted-foreground`}):(0,c.jsx)(i.ChevronDown,{className:`h-4 w-4 text-muted-foreground`})})]}),e.description&&!_&&(0,c.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.description})]})}),(0,c.jsx)(r.CollapsibleContent,{children:(0,c.jsx)(r.CardContent,{className:`pt-3 sm:pt-4 px-3 sm:px-6 pb-4 sm:pb-5`,children:ae})})]})}):(0,c.jsxs)(r.Card,{className:(0,r.cn)(e.showBorder===!1?`border-none shadow-none`:``,s),children:[e.title&&(0,c.jsxs)(r.CardHeader,{className:(0,r.cn)(`py-3 px-4 sm:py-4 sm:px-6`,e.headerColor&&`bg-${e.headerColor}`),children:[(0,c.jsx)(r.CardTitle,{className:`flex items-center justify-between text-base font-semibold tracking-tight`,children:(0,c.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,c.jsx)(F,{name:e.icon}),(0,c.jsx)(`span`,{children:e.title})]})}),e.description&&(0,c.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.description})]}),(0,c.jsx)(r.CardContent,{className:`pt-3 sm:pt-4 px-3 sm:px-6 pb-4 sm:pb-5`,children:ae})]})},R=({tabs:e,data:t,className:i})=>{let[o,s]=n.useState(e[0]?.key),l=e.filter(e=>typeof e.visible==`boolean`?e.visible:(e.visible,!0));return(0,c.jsxs)(r.Tabs,{value:o,onValueChange:s,className:i,children:[(0,c.jsx)(r.TabsList,{className:`w-full justify-start border-b rounded-none bg-transparent p-0`,children:l.map(e=>(0,c.jsx)(r.TabsTrigger,{value:e.key,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:(0,c.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon&&(0,c.jsx)(`span`,{children:e.icon}),(0,c.jsx)(`span`,{children:e.label}),e.badge&&(0,c.jsx)(r.Badge,{variant:`secondary`,className:`ml-1`,children:e.badge})]})},e.key))}),l.map(e=>(0,c.jsx)(r.TabsContent,{value:e.key,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:(0,c.jsx)(n.Suspense,{fallback:null,children:Array.isArray(e.content)?(0,c.jsx)(`div`,{className:`space-y-4`,children:e.content.map((e,n)=>(0,c.jsx)(a.SchemaRenderer,{schema:e,data:t},n))}):(0,c.jsx)(a.SchemaRenderer,{schema:e.content,data:t})})},e.key))]})};function ee(e){return e&&i.icons[e.split(/[-_\s]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)]||i.Inbox}var te=({action:e,onToolbarAction:t})=>{let n=e.visible,i=(0,a.useCondition)((0,a.toPredicateInput)(n));if(n&&!i)return null;let o=e.icon?ee(e.icon):null;return(0,c.jsxs)(r.Button,{variant:e.variant===`primary`?`default`:`outline`,size:`sm`,onClick:n=>{n.stopPropagation(),t(e)},className:`gap-1 h-9 sm:h-7 text-xs shadow-none`,"data-testid":`related-toolbar-action-${e.name}`,children:[o&&(0,c.jsx)(o,{className:`h-3.5 w-3.5`}),e.label||e.name]})},z=({title:e,type:t,api:s,data:u,schema:d,columns:f,className:p,dataSource:m,objectName:h,onNew:g,onViewAll:_,onRowEdit:v,onRowDelete:y,onRowClick:b,rowActions:x,onRowAction:S,toolbarActions:C,onToolbarAction:w,add:T,maxColumns:E=6,pageSize:O,sortable:k=!1,filterable:A=!1,collapsible:j=!1,defaultCollapsed:M=!1,referenceField:N,parentId:P,icon:F})=>{let I=u!==void 0,L=u??[],[R,z]=n.useState(L),[B,V]=n.useState(()=>!!s&&!I),[H,U]=n.useState(0),[W,ne]=n.useState(null),[G,re]=n.useState(`asc`),[K,ie]=n.useState(``),[q,ae]=n.useState(null),[oe,se]=n.useState(M),[J,ce]=n.useState(!1),[le,ue]=n.useState(!1),[de,fe]=n.useState(null),[pe,me]=n.useState(0),[he,ge]=n.useState({}),{t:Y}=D(),{fieldLabel:_e}=(0,a.useSafeFieldLabel)();n.useEffect(()=>{I&&z(u??[])},[u,I]),n.useEffect(()=>{s&&m?.getObjectSchema&&m.getObjectSchema(s).then(ae).catch(e=>{console.warn(`[RelatedList] Failed to fetch schema for ${s}:`,e)})},[s,m]),n.useEffect(()=>{if(s&&!I){if(!(N&&P!=null&&P!==``)){s&&(P==null||P===``)&&!N&&console.warn(`[RelatedList] "${s}" has no referenceField/parentId — refusing to fetch all rows. Pass relationshipField + parentId to scope the query.`),z([]),V(!1);return}V(!0);let e={[N]:P};if(m&&typeof m.find==`function`)m.find(s,{$filter:e}).then(e=>{let t=Array.isArray(e)?e:Array.isArray(e?.data)?e.data:[];z(t),V(!1)}).catch(e=>{console.error(`Failed to fetch related data:`,e),V(!1)});else{let e=new URLSearchParams({[`filter[${N}]`]:String(P)}).toString();fetch(`${s}?${e}`).then(e=>e.json()).then(e=>{let t=Array.isArray(e)?e:e?.data||[];z(t)}).catch(e=>{console.error(`Failed to fetch related data:`,e)}).finally(()=>V(!1))}}},[s,I,m,N,P,pe]),n.useEffect(()=>{if(!s||I)return;let e=e=>{let t=e.detail||{};t.objectName&&t.objectName!==s||me(e=>e+1)};return window.addEventListener(`objectui:related-changed`,e),()=>window.removeEventListener(`objectui:related-changed`,e)},[s,I]),n.useEffect(()=>{if(!m?.find||!q?.fields||!R.length)return;let e=q.fields,t=[];for(let[n,r]of Object.entries(e)){if(!r||r.type!==`lookup`&&r.type!==`master_detail`)continue;let e=r.reference_to||r.reference;if(!e)continue;let i=new Set;for(let e of R){let t=e?.[n];t!=null&&(typeof t==`string`&&t?i.add(t):typeof t==`number`&&i.add(String(t)))}let a=he[n]||{},o=Array.from(i).filter(e=>!(e in a));o.length>0&&t.push({fieldName:n,target:e,ids:o})}if(t.length===0)return;let n=!1;return Promise.all(t.map(({fieldName:e,target:t,ids:n})=>m.find(t,{$filter:{id:{$in:n}},$top:n.length}).then(t=>{let n=Array.isArray(t)?t:t?.data||[],r={};for(let e of n){let t=e?.id||e?._id;t&&(r[String(t)]=e?.full_name||e?.fullname||e?.display_name||e?.name||e?.subject||e?.title||e?.label||e?.code||e?.email||String(t))}return{fieldName:e,map:r}}).catch(t=>(console.warn(`[RelatedList] Failed to resolve lookups for ${e}:`,t),{fieldName:e,map:{}})))).then(e=>{n||ge(t=>{let n={...t};for(let{fieldName:t,map:r}of e)n[t]={...n[t]||{},...r};return n})}),()=>{n=!0}},[m,q,R]);let ve=n.useMemo(()=>{if(!K)return R;let e=K.toLowerCase();return R.filter(t=>Object.values(t).some(t=>t!=null&&String(t).toLowerCase().includes(e)))},[R,K]),X=n.useMemo(()=>W?[...ve].sort((e,t)=>{let n=e[W],r=t[W];if(n==null&&r==null)return 0;if(n==null)return 1;if(r==null)return-1;let i=String(n).localeCompare(String(r),void 0,{numeric:!0});return G===`asc`?i:-i}):ve,[ve,W,G]),Z=O&&O>0?O:0,ye=Z?Math.max(1,Math.ceil(X.length/Z)):1,Q=Z?X.slice(H*Z,(H+1)*Z):X;n.useEffect(()=>{U(0)},[K,W,G]);let be=n.useCallback(e=>{W===e?re(e=>e===`asc`?`desc`:`asc`):(ne(e),re(`asc`))},[W]),[$,xe]=n.useState(null),Se=n.useCallback(e=>{xe(e)},[]),Ce=n.useCallback(async()=>{if($)try{await y?.($),me(e=>e+1)}catch(e){console.error(`[RelatedList] remove failed`,e)}xe(null)},[$,y]),we=n.useCallback(async e=>{if(!T||!m||!s||N==null||P==null)return;let t=T.picker.valueField||`id`;ue(!0),fe(null);try{for(let n of e||[]){let e=n?.[t]??n?.id;e!=null&&(T.linkField?await m.create?.(s,{[N]:P,[T.linkField]:e}):await m.update?.(T.picker.object,String(e),{[N]:P}))}me(e=>e+1)}catch(e){let t=e?.body?.error??e?.error??e?.message??String(e);fe(typeof t==`string`?t:`Failed to add`)}finally{ue(!1),ce(!1)}},[T,m,s,N,P]),Te=(0,l.usePermissions)(),Ee=n.useMemo(()=>{let e=h||s||``,t=t=>!Te?.isLoaded||!e?t:t.filter(t=>{let n=t?.accessorKey||t?.field||t?.name;return!n||Te.checkField(e,String(n),`read`)}),r=e=>N?e.filter(e=>(e?.accessorKey||e?.field||e?.name)!==N):e,i=e=>e==null||typeof e==`string`&&e.trim()===``||Array.isArray(e)&&e.length===0,a=e=>R.length?e.filter(e=>{let t=e?.accessorKey||e?.field||e?.name;return!t||R.some(e=>!i(e?.[t]))}):e,c=(e,t)=>{if(!t?.type)return;let r=(0,o.getCellRenderer)((0,o.resolveCellRendererType)({type:t.type,format:t.format})||t.type);if(!r)return;let i=t.type===`lookup`||t.type===`master_detail`?he[e]:void 0,a=i&&Object.keys(i).length>0?Object.entries(i).map(([e,t])=>({value:e,label:t})):void 0,s={name:e,label:t.label||e,type:t.type,...(a||t.options)&&{options:a||t.options},...t.currency&&{currency:t.currency},...t.precision!==void 0&&{precision:t.precision},...t.scale!==void 0&&{scale:t.scale},...t.format&&{format:t.format},...(t.reference_to||t.reference)&&{reference_to:t.reference_to||t.reference},...t.reference_field&&{reference_field:t.reference_field}};return e=>e==null?n.createElement(`span`,{className:`text-muted-foreground/50 text-xs italic`},`—`):n.createElement(r,{value:e,field:s})},l=t=>{if(typeof t!=`string`){let e=t?.accessorKey||t?.field||t?.name;if(t&&!t.cell&&!t.render&&e){let n=q?.fields?.[e],r=n?c(String(e),n):void 0;if(r)return{...t,cell:r}}return t}let n=q?.fields?.[t],r={accessorKey:t,header:n?.label||_e(e,t,n)||t,fieldDef:n,fieldType:n?.type},i=n?c(t,n):void 0;return i&&(r.cell=i),r};if(f&&f.length>0)return a(t(r(f.map(l))));if(!q?.fields)return[];let u=Array.isArray(q.highlightFields)?q.highlightFields.filter(e=>typeof e==`string`&&e.length>0):[];if(u.length>0){let e=a(t(r(u.map(l))));if(e.length>0)return e.slice(0,Math.max(1,E))}let d=e,p=new Set([`rich_text`,`html`,`json`]),m=[`name`,`full_name`,`fullname`,`title`,`subject`,`label`,`code`,`number`],g=Object.entries(q.fields).filter(([e,t])=>!(e.startsWith(`_`)||e===`id`||e===N||t?.hidden||t?.type&&p.has(t.type)||Te?.isLoaded&&d&&!Te.checkField(d,e,`read`))),_=new Set([`created_at`,`updated_at`,`created_by`,`updated_by`,`owner_id`,`organization_id`]);return g.sort(([e,t],[n,r])=>{let i=_.has(e);if(i!==_.has(n))return i?1:-1;let a=m.indexOf(e),o=m.indexOf(n),s=a>=0?a:100,c=o>=0?o:100;if(s!==c)return s-c;let l=t?.type===`select`||e.includes(`status`);return l===(r?.type===`select`||n.includes(`status`))?0:l?-1:1}),a(g.map(([e,t])=>{let n={accessorKey:e,header:_e(d,e,t.label||e)};if(t.type){let r=c(e,t);r&&(n.cell=r)}return n})).slice(0,Math.max(1,E))},[f,q,h,s,_e,N,R,E,he,Te]),De=Array.isArray(x)&&x.length>0,Oe=!!v||!!y||De,ke=(0,r.useIsMobile)(),Ae=n.useMemo(()=>{if(d)return d;if(ke&&(t===`grid`||t===`table`)){let e=Ee[0]?.accessorKey||Ee[0]?.field||Ee[0]?.name,t=Ee.slice(1,4).map(e=>e.accessorKey||e.field||e.name).filter(Boolean);return{type:`object-gallery`,data:Q,objectName:s,gallery:{titleField:e||`name`,visibleFields:t,cardSize:`medium`},onRowClick:b}}let e=q?.userActions?.edit,n=q?.userActions?.delete,r=e=>typeof e==`object`&&e&&(e.visibleWhen!=null||e.disabledWhen!=null)?{visibleWhen:e.visibleWhen??void 0,disabledWhen:e.disabledWhen??void 0}:void 0;switch(t){case`grid`:case`table`:return{type:`data-table`,data:Q,columns:Ee,pagination:!1,pageSize:Z||10,searchable:!1,exportable:!1,rowActions:Oe,onRowEdit:v,onRowDelete:y?Se:void 0,rowEditPredicates:r(e),rowDeletePredicates:r(n),onRowClick:b,rowActionDefs:De?x:void 0,onRowActionDef:De?S:void 0};case`list`:return{type:`data-list`,data:Q};default:return{type:`div`,children:`No view configured`}}},[t,Q,Ee,d,Z,Oe,De,x,S,v,y,Se,b,ke,s,q]),je=j?`cursor-pointer select-none`:void 0,Me=j?()=>se(e=>!e):void 0,Ne=ee(F),Pe=!B&&R.length===0,Fe=A;return(0,c.jsxs)(r.Card,{className:(0,r.cn)(`shadow-none border-border/60 bg-transparent`,Pe&&`bg-muted/10`,p),children:[(0,c.jsx)(r.CardHeader,{className:(0,r.cn)(`py-3 px-4 sm:py-3 min-h-12 sm:min-h-0`,je),onClick:Me,children:(0,c.jsxs)(r.CardTitle,{className:`flex items-center justify-between gap-2 text-sm font-semibold`,children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[j&&(oe?(0,c.jsx)(i.ChevronRight,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,c.jsx)(i.ChevronDown,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})),(0,c.jsx)(Ne,{className:`h-4 w-4 text-muted-foreground shrink-0`,"aria-hidden":!0}),(0,c.jsx)(`span`,{className:(0,r.cn)(`truncate`,Pe&&`text-muted-foreground font-medium`),children:e}),(0,c.jsx)(r.Badge,{variant:`secondary`,className:(0,r.cn)(`text-xs font-normal h-5 px-1.5`,R.length===0&&`bg-muted text-muted-foreground`),"aria-label":`${R.length} records`,children:R.length}),Pe&&(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground/70 italic ml-1 truncate`,children:Y(`detail.noRelatedRecords`)})]}),(0,c.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[w&&(C??[]).map(e=>(0,c.jsx)(te,{action:e,onToolbarAction:w},e.name)),T&&(0,c.jsxs)(r.Button,{variant:Pe?`ghost`:`outline`,size:`sm`,disabled:le,onClick:e=>{e.stopPropagation(),fe(null),ce(!0)},className:`gap-1 h-9 sm:h-7 text-xs shadow-none`,children:[(0,c.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),T.label||Y(`detail.add`,{defaultValue:`Add`})]}),g&&(0,c.jsxs)(r.Button,{variant:Pe?`ghost`:`outline`,size:`sm`,onClick:e=>{e.stopPropagation(),g()},className:`gap-1 h-9 sm:h-7 text-xs shadow-none`,children:[(0,c.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),Y(`detail.new`)]})]})]})}),!oe&&!Pe&&(0,c.jsxs)(r.CardContent,{className:(0,r.cn)(`pt-0 pb-4 px-4`),children:[Fe&&(0,c.jsx)(`div`,{className:`mb-3`,children:(0,c.jsx)(r.Input,{placeholder:Y(`detail.filterPlaceholder`),value:K,onChange:e=>ie(e.target.value),className:`h-8 text-sm`})}),k&&Ee&&Ee.length>0&&R.length>0&&(0,c.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-3`,children:Ee.map(e=>{let t=e.accessorKey||e.field||e.name;if(!t)return null;let n=e.header||e.label||t,a=W===t;return(0,c.jsxs)(r.Button,{variant:a?`secondary`:`ghost`,size:`sm`,className:`gap-1 h-7 text-xs`,onClick:()=>be(t),children:[(0,c.jsx)(i.ArrowUpDown,{className:`h-3 w-3`}),n,a&&(G===`asc`?` ↑`:` ↓`)]},t)})}),B?(0,c.jsx)(`div`,{className:`flex items-center justify-center py-6 text-muted-foreground text-sm`,children:Y(`detail.loading`)}):(0,c.jsx)(a.SchemaRenderer,{schema:Ae}),Z>0&&X.length>Z&&(0,c.jsxs)(`div`,{className:`flex items-center justify-between mt-3 pt-3 border-t`,children:[(0,c.jsxs)(r.Button,{variant:`outline`,size:`sm`,className:`h-7 text-xs gap-1`,disabled:H===0,onClick:()=>U(e=>Math.max(0,e-1)),children:[(0,c.jsx)(i.ChevronLeft,{className:`h-3 w-3`}),Y(`detail.previousPage`)]}),(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:Y(`detail.pageOf`,{current:H+1,total:ye})}),(0,c.jsxs)(r.Button,{variant:`outline`,size:`sm`,className:`h-7 text-xs gap-1`,disabled:H>=ye-1,onClick:()=>U(e=>Math.min(ye-1,e+1)),children:[Y(`detail.nextPage`),(0,c.jsx)(i.ChevronRight,{className:`h-3 w-3`})]})]}),_&&!Pe&&Z>0&&X.length>Z&&(0,c.jsx)(`div`,{className:`mt-3 pt-3 border-t flex justify-center`,children:(0,c.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),_()},className:`text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1 transition-colors`,children:[Y(`detail.viewAll`),(0,c.jsx)(i.ExternalLink,{className:`h-3 w-3`})]})})]}),(0,c.jsx)(r.AlertDialog,{open:$!==null,onOpenChange:e=>{e||xe(null)},children:(0,c.jsxs)(r.AlertDialogContent,{children:[(0,c.jsxs)(r.AlertDialogHeader,{children:[(0,c.jsx)(r.AlertDialogTitle,{children:Y(`detail.deleteRowTitle`,{defaultValue:`Delete record`})}),(0,c.jsx)(r.AlertDialogDescription,{children:Y(`detail.deleteRowConfirmation`)})]}),(0,c.jsxs)(r.AlertDialogFooter,{children:[(0,c.jsx)(r.AlertDialogCancel,{children:Y(`detail.cancel`,{defaultValue:`Cancel`})}),(0,c.jsx)(r.AlertDialogAction,{onClick:Ce,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:Y(`detail.delete`,{defaultValue:`Delete`})})]})]})}),de&&(0,c.jsx)(`div`,{className:`mx-4 mb-3 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,role:`alert`,children:de}),T&&m&&(0,c.jsx)(o.RecordPickerDialog,{open:J,onOpenChange:e=>ce(e),multiple:!0,dataSource:m,objectName:T.picker.object,title:T.label||Y(`detail.add`,{defaultValue:`Add`}),onSelect:()=>{},onSelectRecords:e=>{we(e)}})]})},B=({group:e,data:t,className:a,objectSchema:o,objectName:s,isEditing:l=!1,onFieldChange:u,onEnterInlineEdit:d,autoFocusField:f,dataSource:p})=>{let m=e.collapsible??!0,[h,g]=n.useState(e.defaultCollapsed??!1),_=(0,c.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:e.sections.map((e,n)=>(0,c.jsx)(L,{section:e,data:t,objectSchema:o,objectName:s,isEditing:l,onFieldChange:u,onEnterInlineEdit:d,autoFocusField:f,dataSource:p},n))});return m?(0,c.jsxs)(r.Collapsible,{open:!h,onOpenChange:e=>g(!e),className:a,children:[(0,c.jsx)(r.CollapsibleTrigger,{asChild:!0,children:(0,c.jsxs)(`div`,{className:`flex items-center gap-2 pb-2 border-b cursor-pointer hover:bg-muted/50 transition-colors rounded-t-md px-2 py-1.5`,children:[h?(0,c.jsx)(i.ChevronRight,{className:`h-4 w-4 text-muted-foreground shrink-0`}):(0,c.jsx)(i.ChevronDown,{className:`h-4 w-4 text-muted-foreground shrink-0`}),e.icon&&(0,c.jsx)(`span`,{className:`text-muted-foreground`,children:e.icon}),(0,c.jsx)(`h3`,{className:`text-lg font-semibold`,children:e.title})]})}),e.description&&!h&&(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e.description}),(0,c.jsx)(r.CollapsibleContent,{children:(0,c.jsx)(`div`,{className:`mt-3`,children:_})})]}):(0,c.jsxs)(`div`,{className:(0,r.cn)(`space-y-3`,a),children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-2 pb-2 border-b`,children:[e.icon&&(0,c.jsx)(`span`,{className:`text-muted-foreground`,children:e.icon}),(0,c.jsx)(`h3`,{className:`text-lg font-semibold`,children:e.title})]}),e.description&&(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description}),_]})},V=({fields:e,data:t,className:n,objectName:s,objectSchema:l,dataSource:u})=>{let{fieldLabel:d}=(0,a.useSafeFieldLabel)(),{t:f}=D(),p=(0,a.useInlineEdit)(),m=p?.editing??!1,h=p?.canEdit??!1;if(!e.length||!t)return null;let g=m?e:e.filter(e=>{let n=t?.[e.name];return n!=null&&n!==``});return g.length===0?null:(0,c.jsx)(r.TooltipProvider,{children:(0,c.jsx)(`section`,{className:(0,r.cn)(`@container border-b border-border/60 pb-4`,n),"aria-label":`Record highlights`,children:(0,c.jsx)(`div`,{className:(0,r.cn)(`flex flex-wrap gap-y-4`),children:g.map(e=>{let n=t[e.name],a=l?.fields?.[e.name],g=e.type||a?.type,_=a?.reference_to||a?.reference,v={name:e.name,label:e.label,type:g||`text`,...a?.options&&{options:a.options},...a?.currency&&{currency:a.currency},...a?.currencyConfig&&{currencyConfig:a.currencyConfig},...a?.precision!==void 0&&{precision:a.precision},...a?.scale!==void 0&&{scale:a.scale},...a?.min!==void 0&&{min:a.min},...a?.max!==void 0&&{max:a.max},...a?.step!==void 0&&{step:a.step},...a?.format&&{format:a.format},..._&&{reference_to:_},...a?.reference_field&&{reference_field:a.reference_field},...a?.widget&&{widget:a.widget}},y=p?.draft?.[e.name],b=y===void 0?n:y,x=M.has(g),S=e.readonly===!0||a?.readonly===!0,C=j.has(e.name),w=h&&!x&&!S&&!C,T=m&&w,E=(0,o.getCellRenderer)((0,o.resolveCellRendererType)(v)||g||`text`),D=g===`number`||g===`integer`||g===`currency`||g===`percent`||g===`decimal`,O=g===`email`||g===`url`||g===`textarea`||g===`reference`||g===`lookup`||g===`master_detail`,k=g===`boolean`,A=b==null||b===``;return(0,c.jsxs)(`div`,{className:(0,r.cn)(`group flex flex-col gap-1 min-w-[7rem] px-5 border-l border-border/60 first:border-l-0 first:pl-0`,O||T?`basis-[16rem] max-w-[24rem]`:`basis-[9rem] max-w-[16rem]`),children:[(0,c.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:d(s||``,e.name,e.label)}),T?(0,c.jsx)(P,{field:v,value:b,onChange:t=>p.setField(e.name,t),dataSource:u,autoFocus:p.autoFocusField===e.name}):(0,c.jsxs)(`div`,{className:(0,r.cn)(`flex items-start justify-between gap-1`,w&&`cursor-pointer rounded-md -mx-1.5 px-1.5 hover:bg-muted/40 transition-colors`),onDoubleClick:w?()=>p.enter(e.name):void 0,title:w?f(`detail.editInlineHint`):void 0,children:[(0,c.jsx)(`div`,{className:`min-w-0 flex-1`,children:k?b?(0,c.jsxs)(`span`,{className:`inline-flex items-center gap-1 self-start rounded-full bg-emerald-500/10 px-2 py-0.5 text-xs font-medium text-emerald-600 ring-1 ring-inset ring-emerald-500/30 dark:text-emerald-400`,children:[(0,c.jsx)(i.Check,{className:`h-3 w-3`,"aria-hidden":!0}),`Yes`]}):(0,c.jsxs)(`span`,{className:`inline-flex items-center gap-1 self-start rounded-full bg-amber-500/10 px-2 py-0.5 text-xs font-medium text-amber-700 ring-1 ring-inset ring-amber-500/30 dark:text-amber-400`,children:[(0,c.jsx)(i.X,{className:`h-3 w-3`,"aria-hidden":!0}),`No`]}):A?(0,c.jsx)(`span`,{className:`block text-sm text-muted-foreground/60 select-none`,"aria-label":f(`detail.noValue`,{defaultValue:`No value`}),children:`—`}):(0,c.jsx)(`span`,{title:(Array.isArray(v.options)?v.options.find(e=>e?.value===b)?.label:void 0)??(typeof b==`string`||typeof b==`number`?String(b):void 0),className:(0,r.cn)(`block min-w-0 truncate text-sm font-semibold`,D&&`tabular-nums tracking-tight`),children:(0,c.jsx)(E,{value:b,field:v})})}),w&&(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-5 w-5 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity`,"aria-label":f(`detail.editInlineHint`),onClick:t=>{t.stopPropagation(),p.enter(e.name)},children:(0,c.jsx)(i.Pencil,{className:`h-3 w-3`})})}),(0,c.jsx)(r.TooltipContent,{children:f(`detail.editInlineHint`)})]})]})]},e.name)})})})})};function H(e){try{let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);return a<7?`${a}d ago`:t.toLocaleDateString()}catch{return e}}var U=({comments:e,onAddComment:t,onTogglePin:a,searchable:o=!1,className:s})=>{let{t:l}=D(),[u,d]=n.useState(``),[f,p]=n.useState(!1),[m,h]=n.useState(``),g=n.useCallback(async()=>{let e=u.trim();if(!(!e||!t)){p(!0);try{await t(e),d(``)}finally{p(!1)}}},[u,t]),_=n.useCallback(e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),g())},[g]),v=n.useMemo(()=>[...m.trim()?e.filter(e=>{let t=m.trim().toLowerCase();return e.text.toLowerCase().includes(t)||e.author.toLowerCase().includes(t)}):e].sort((e,t)=>e.pinned&&!t.pinned?-1:!e.pinned&&t.pinned?1:0),[e,m]);return(0,c.jsxs)(r.Card,{className:(0,r.cn)(``,s),children:[(0,c.jsx)(r.CardHeader,{children:(0,c.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,c.jsx)(i.MessageSquare,{className:`h-4 w-4`}),l(`detail.comments`),(0,c.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,e.length,`)`]})]})}),(0,c.jsxs)(r.CardContent,{className:`space-y-4`,children:[o&&(0,c.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,c.jsxs)(`div`,{className:`relative flex-1`,children:[(0,c.jsx)(i.Search,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,c.jsx)(`input`,{className:`w-full rounded-md border border-input bg-background pl-8 pr-8 py-1.5 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,placeholder:l(`detail.searchComments`),value:m,onChange:e=>h(e.target.value),"aria-label":l(`detail.searchComments`)}),m&&(0,c.jsx)(`button`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,onClick:()=>h(``),"aria-label":l(`detail.clearSearch`),type:`button`,children:(0,c.jsx)(i.X,{className:`h-3.5 w-3.5`})})]})}),t&&(0,c.jsxs)(`div`,{className:`flex gap-2`,children:[(0,c.jsx)(`textarea`,{className:`flex-1 min-h-[60px] rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring resize-none`,placeholder:l(`detail.addCommentPlaceholder`),value:u,onChange:e=>d(e.target.value),onKeyDown:_,disabled:f}),(0,c.jsx)(r.Button,{size:`icon`,variant:`default`,onClick:g,disabled:!u.trim()||f,className:`shrink-0 self-end`,children:(0,c.jsx)(i.Send,{className:`h-4 w-4`})})]}),v.length===0?(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:m.trim()?l(`detail.noMatchingComments`):l(`detail.noCommentsYet`)}):(0,c.jsx)(`div`,{className:`space-y-3`,children:v.map(e=>(0,c.jsxs)(`div`,{className:(0,r.cn)(`flex gap-3`,e.pinned&&`bg-muted/40 rounded-md p-2 -mx-2`),children:[(0,c.jsx)(`div`,{className:`shrink-0`,children:e.avatarUrl?(0,c.jsx)(`img`,{src:e.avatarUrl,alt:e.author,className:`h-8 w-8 rounded-full object-cover`}):(0,c.jsx)(`div`,{className:`h-8 w-8 rounded-full bg-muted flex items-center justify-center text-xs font-medium text-muted-foreground`,children:e.author.charAt(0).toUpperCase()})}),(0,c.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-2 mb-0.5`,children:[(0,c.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e.author}),(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:H(e.createdAt)}),e.pinned&&(0,c.jsxs)(`span`,{className:`text-xs text-amber-600 flex items-center gap-0.5`,children:[(0,c.jsx)(i.Pin,{className:`h-3 w-3`}),l(`detail.pinned`)]})]}),(0,c.jsx)(`p`,{className:`text-sm whitespace-pre-wrap break-words`,children:e.text}),a&&(0,c.jsxs)(`button`,{type:`button`,className:`mt-1 text-xs text-muted-foreground hover:text-foreground flex items-center gap-1`,onClick:()=>a(e.id),"aria-label":e.pinned?l(`detail.unpin`):l(`detail.pin`),children:[(0,c.jsx)(i.Pin,{className:`h-3 w-3`}),e.pinned?l(`detail.unpin`):l(`detail.pin`)]})]})]},e.id))})]})]})},W={field_change:i.Edit,create:i.PlusCircle,delete:i.Trash2,comment:i.MessageSquare,status_change:i.ArrowRightLeft},ne={field_change:`bg-blue-100 text-blue-600`,create:`bg-green-100 text-green-600`,delete:`bg-red-100 text-red-600`,comment:`bg-purple-100 text-purple-600`,status_change:`bg-amber-100 text-amber-600`};function G(e){try{let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);return a<7?`${a}d ago`:t.toLocaleDateString()}catch{return e}}function re(e){return e.description?e.description:e.type===`field_change`&&e.field?`Changed ${e.field.charAt(0).toUpperCase()+e.field.slice(1).replace(/_/g,` `)} from "${e.oldValue==null?`(empty)`:String(e.oldValue)}" to "${e.newValue==null?`(empty)`:String(e.newValue)}"`:e.type===`create`?`Created this record`:e.type===`delete`?`Deleted this record`:e.type===`status_change`&&e.field?`Changed status to "${e.newValue==null?`(empty)`:String(e.newValue)}"`:`Updated record`}var K={all:`All`,field_change:`Field Changes`,create:`Creates`,delete:`Deletes`,comment:`Comments`,status_change:`Status Changes`},ie=({activities:e,filterable:t=!1,defaultFilter:a=`all`,className:o})=>{let[s,l]=n.useState(a),u=n.useMemo(()=>s===`all`?e:e.filter(e=>e.type===s),[e,s]);return(0,c.jsxs)(r.Card,{className:(0,r.cn)(``,o),children:[(0,c.jsx)(r.CardHeader,{children:(0,c.jsxs)(r.CardTitle,{className:`flex items-center gap-2 text-base`,children:[(0,c.jsx)(i.Activity,{className:`h-4 w-4`}),`Activity`,(0,c.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,u.length,`)`]})]})}),(0,c.jsxs)(r.CardContent,{children:[t&&(0,c.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-4`,role:`group`,"aria-label":`Activity type filter`,children:Object.keys(K).map(e=>(0,c.jsxs)(`button`,{type:`button`,className:(0,r.cn)(`inline-flex items-center gap-1 rounded-full px-2.5 py-0.5 text-xs font-medium transition-colors`,s===e?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-muted/80`),onClick:()=>l(e),"aria-pressed":s===e,children:[e!==`all`&&n.createElement(W[e]||i.Edit,{className:`h-3 w-3`}),K[e]]},e))}),u.length===0?(0,c.jsx)(r.DataEmptyState,{title:`No activity recorded`,className:`py-6`}):(0,c.jsxs)(`div`,{className:`relative`,children:[(0,c.jsx)(`div`,{className:`absolute left-4 top-2 bottom-2 w-px bg-border`}),(0,c.jsx)(`div`,{className:`space-y-4`,children:u.map(e=>{let t=W[e.type]||i.Edit;return(0,c.jsxs)(`div`,{className:`flex gap-3 relative`,children:[(0,c.jsx)(`div`,{className:(0,r.cn)(`shrink-0 h-8 w-8 rounded-full flex items-center justify-center z-10`,ne[e.type]||`bg-gray-100 text-gray-600`),children:(0,c.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,c.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,c.jsxs)(`p`,{className:`text-sm`,children:[(0,c.jsx)(`span`,{className:`font-medium`,children:e.user}),` `,(0,c.jsx)(`span`,{className:`text-muted-foreground`,children:re(e)})]}),(0,c.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:G(e.timestamp)})]})]},e.id)})})]})]})]})},q={create:`default`,update:`secondary`,delete:`destructive`,restore:`outline`,login:`outline`,logout:`outline`,permission_change:`secondary`,config_change:`secondary`,export:`outline`,import:`outline`};function ae(e){if(!e)return``;let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}var oe=[[60,`second`],[60,`minute`],[24,`hour`],[7,`day`],[4.34524,`week`],[12,`month`],[1/0,`year`]];function se(e,t){if(!e)return``;let n=e instanceof Date?e:new Date(e);if(Number.isNaN(n.getTime()))return String(e);let r=(n.getTime()-Date.now())/1e3;for(let[n,i]of oe){if(Math.abs(r)<n)try{return new Intl.RelativeTimeFormat(t,{numeric:`auto`}).format(Math.round(r),i)}catch{return ae(e)}r/=n}return ae(e)}function J(e){if(!e)return`?`;let t=e.trim().split(/\s+/).filter(Boolean).slice(0,2);return t.length===0?`?`:t.map(e=>e.charAt(0).toUpperCase()).join(``)}function ce(e){if(e==null||e===``)return`—`;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function le({entries:e,loading:t,emptyText:n,className:i,locale:a}){return t?(0,c.jsx)(`div`,{className:(0,r.cn)(`space-y-3`,i),children:Array.from({length:4}).map((e,t)=>(0,c.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,c.jsx)(r.Skeleton,{className:`h-8 w-8 rounded-full`}),(0,c.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,c.jsx)(r.Skeleton,{className:`h-4 w-1/3`}),(0,c.jsx)(r.Skeleton,{className:`h-3 w-1/2`})]})]},t))}):!e||e.length===0?(0,c.jsx)(`div`,{className:(0,r.cn)(`flex items-center justify-center rounded-md border border-dashed py-10 text-sm text-muted-foreground`,i),children:n??`No history yet`}):(0,c.jsx)(r.TooltipProvider,{delayDuration:150,children:(0,c.jsx)(`ol`,{className:(0,r.cn)(`space-y-4`,i),children:e.map((e,t)=>{let n=(e.action??``).toLowerCase(),i=q[n]??`outline`,o=typeof e.user_name==`string`&&e.user_name.trim()||`Unknown user`,s=ae(e.created_at),l=se(e.created_at,a),u=typeof e.user_avatar==`string`?e.user_avatar:void 0;return(0,c.jsxs)(`li`,{className:`flex items-start gap-3`,children:[(0,c.jsxs)(r.Avatar,{className:`h-8 w-8 mt-0.5 shrink-0`,children:[u?(0,c.jsx)(r.AvatarImage,{src:u,alt:o}):null,(0,c.jsx)(r.AvatarFallback,{className:`text-[10px] font-medium`,children:J(e.user_name)})]}),(0,c.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,c.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1`,children:[(0,c.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:o}),e.action&&(0,c.jsx)(r.Badge,{variant:i,className:`text-[10px] uppercase tracking-wide`,children:e.action}),s&&(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground cursor-help`,"aria-label":s,children:l||s})}),(0,c.jsx)(r.TooltipContent,{children:s})]})]}),e.summary&&(0,c.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e.summary}),e.changes&&e.changes.length>0&&(n===`create`?(0,c.jsxs)(`details`,{className:`mt-1 group`,children:[(0,c.jsxs)(`summary`,{className:`cursor-pointer list-none text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1 select-none`,children:[(0,c.jsx)(`span`,{className:`transition-transform group-open:rotate-90`,children:`▸`}),(0,c.jsx)(`span`,{children:e.changes.length===1?`1 field populated`:`${e.changes.length} fields populated`})]}),(0,c.jsx)(`ul`,{className:`mt-1.5 space-y-0.5 text-xs text-muted-foreground pl-4`,children:e.changes.map(e=>(0,c.jsxs)(`li`,{className:`leading-relaxed`,children:[(0,c.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label||e.field}),`: `,(0,c.jsx)(`span`,{className:`text-foreground`,children:ce(e.to)})]},e.field))})]}):(0,c.jsx)(`ul`,{className:`mt-1.5 space-y-0.5 text-xs text-muted-foreground`,children:e.changes.map(e=>(0,c.jsxs)(`li`,{className:`leading-relaxed`,children:[(0,c.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label||e.field}),`: `,(0,c.jsx)(`span`,{className:`line-through opacity-70`,children:ce(e.from)}),` → `,(0,c.jsx)(`span`,{className:`text-foreground`,children:ce(e.to)})]},e.field))}))]})]},e.id??t)})})})}var ue={createdAt:`created_at`,createdBy:`created_by`,updatedAt:`updated_at`,updatedBy:`updated_by`};function de(e){if(!e)return null;if(e instanceof Date)return isNaN(e.getTime())?null:e;if(typeof e==`string`||typeof e==`number`){let t=new Date(e);return isNaN(t.getTime())?null:t}return null}function fe(e,t){let n=Date.now()-e.getTime(),r=Math.max(0,Math.floor(n/1e3));if(r<60)return t(`detail.justNow`);let i=Math.floor(r/60);if(i<60)return t(`detail.minutesAgo`,{count:i});let a=Math.floor(i/60);return a<24?t(`detail.hoursAgo`,{count:a}):t(`detail.daysAgo`,{count:Math.floor(a/24)})}function pe(e){try{return new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(e)}catch{return e.toISOString()}}var me=({value:e,objectSchema:t,fieldName:r})=>{if(e==null||e===``)return null;let i=t?.fields?.[r],a=i?.reference_to||i?.reference,s={name:r,type:i?.type||(a?`lookup`:`text`),...a&&{reference_to:a},...i?.reference_field&&{reference_field:i.reference_field}},l=(0,o.resolveCellRendererType)(s)||s.type;if(l){let t=(0,o.getCellRenderer)(l);if(t)return(0,c.jsx)(`span`,{className:`inline-flex items-center [&_a]:text-inherit [&_a]:hover:underline`,children:n.createElement(t,{value:e,field:s})})}return(0,c.jsx)(`span`,{children:String(e)})},he=({label:e,user:t,date:n,objectSchema:i,userField:a,t:o})=>{if(!t&&!n)return null;let s=n?(0,c.jsx)(r.TooltipProvider,{delayDuration:200,children:(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(`time`,{dateTime:n.toISOString(),className:`cursor-default underline decoration-dotted decoration-muted-foreground/40 underline-offset-2`,children:fe(n,o)})}),(0,c.jsx)(r.TooltipContent,{side:`top`,children:pe(n)})]})}):null;return(0,c.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,c.jsx)(`span`,{className:`text-muted-foreground/70`,children:e}),t?(0,c.jsx)(me,{value:t,objectSchema:i,fieldName:a}):null,t&&s?(0,c.jsx)(`span`,{className:`text-muted-foreground/40`,children:`·`}):null,s]})},ge=({data:e,objectSchema:t,objectName:n,className:i})=>{let{t:a}=D();if(!e)return null;let o=de(e[ue.createdAt]),s=de(e[ue.updatedAt]),l=e[ue.createdBy],u=e[ue.updatedBy],d=!!(o||l),f=o&&s&&Math.abs(s.getTime()-o.getTime())<2e3,p=!!(s||u)&&!(f&&(l!=null&&u!=null&&String(l)===String(u)||!u));return!d&&!p?null:(0,c.jsxs)(`div`,{className:(0,r.cn)(`mt-6 pt-3 border-t border-border/40`,`flex flex-wrap items-center gap-x-4 gap-y-1`,`text-xs text-muted-foreground`,i),"data-testid":`record-meta-footer`,children:[d&&(0,c.jsx)(he,{label:a(l?`detail.createdBy`:`detail.created`),user:l,date:o,objectSchema:t,userField:ue.createdBy,t:a}),p&&(0,c.jsx)(he,{label:a(u?`detail.updatedBy`:`detail.updated`),user:u,date:s,objectSchema:t,userField:ue.updatedBy,t:a})]})},Y=5,_e={};function ve(e,n,r,i){if(e&&typeof e==`object`){if(n.primaryField){let t=e[n.primaryField];if(t!=null&&t!==``)return String(t)}let i=(0,t.formatTitleTemplate)(r?.titleFormat,e);if(i)return i}if(e&&typeof e==`object`){let n=e.id??e._id,i=(0,t.getRecordDisplayName)(r,e,{deriveFromRecordKeys:!1});if(!(i===`Untitled`||n!=null&&i===`Record #${n}`))return i}if(n.title)return n.title;if(e&&typeof e==`object`){let t=e.id??e._id;if(t!=null&&String(t).trim()!==``)return`Record #${t}`}return i}var X=({schema:e,dataSource:o,className:s,onEdit:d,onDelete:f,onBack:p,inlineEdit:m=!1,discussionSlot:h,rightRail:g,objectLabel:_,onDataLoaded:v,isFavorite:y,onToggleFavorite:b})=>{let[x,S]=n.useState(e.data),[C,w]=n.useState(!e.data&&!!(e.api&&e.resourceId||o&&e.objectName&&e.resourceId)),[T,E]=n.useState(!1),O=y??T,k=(0,a.useInlineEdit)(),A=k?.editing??!1,j=k?.draft??_e,M=k?.autoFocusField??null,[N,P]=n.useState(null),[F,I]=n.useState(null),[ee,te]=n.useState(!1),[H,W]=n.useState(0),ne=(0,a.useDataInvalidation)(e.objectName||void 0,e.resourceId==null?void 0:String(e.resourceId)),[G,re]=n.useState(!1),{t:K}=D(),{currency:q}=(0,u.useLocalization)(),{fieldOptionLabel:ae}=(0,a.useSafeFieldLabel)(),oe=(0,r.useIsMobile)(),se=(0,l.usePermissions)(),J=n.useMemo(()=>{if(!se?.isLoaded||!e.objectName)return e;let t=t=>se.checkField(e.objectName,t,`read`),n=e=>e&&e.filter(e=>{let n=typeof e==`string`?e:e?.name;return!n||t(n)});return{...e,fields:n(e.fields),sections:e.sections?.map(e=>({...e,fields:n(e.fields)})),summaryFields:n(e.summaryFields)}},[e,se]);n.useEffect(()=>{x&&v&&v(x)},[x,v]);let ce=n.useMemo(()=>{if(J.summaryFields&&J.summaryFields.length>0)return[];let e=[...J.sections?.flatMap(e=>e.fields)||[],...J.fields||[]],t={};for(let n of e)t[n.name]||(t[n.name]=n);if(F?.fields)for(let[e,n]of Object.entries(F.fields))t[e]={...t[e]||{},...n,name:e};let n=e=>x?.[e]!==void 0&&x?.[e]!==null&&x?.[e]!==``,r=[],i=[`status`,`stage`,`state`,`phase`].find(e=>t[e]&&n(e))||Object.keys(t).find(e=>t[e]?.type===`select`&&n(e));i&&r.push(i);let a=Object.keys(t).find(e=>(t[e]?.type===`currency`||/amount|revenue|value|total|price/i.test(e))&&n(e));a&&!r.includes(a)&&r.push(a);let o=Object.keys(t).find(e=>(t[e]?.type===`date`||t[e]?.type===`datetime`)&&/close|due|start|end|expected/i.test(e)&&n(e));return o&&!r.includes(o)&&r.push(o),r},[J.summaryFields,J.sections,J.fields,F,x]),ue=J.summaryFields&&J.summaryFields.length>0?J.summaryFields:ce,de=n.useCallback(()=>{J.resourceId&&navigator.clipboard.writeText(String(J.resourceId)).then(()=>{te(!0),setTimeout(()=>te(!1),1500)})},[J.resourceId]);n.useEffect(()=>{let e=!0;if(J.data)return S(J.data),w(!1),o?.getObjectSchema&&J.objectName&&o.getObjectSchema(J.objectName).then(t=>{e&&I(t)}).catch(()=>{}),()=>{e=!1};if(o&&J.objectName&&J.resourceId){w(!0),I(null),S(null);let n=J.objectName,r=J.resourceId,i=`${n}-`,a=[...J.sections?.flatMap(e=>e.fields)||[],...J.fields||[]];(o.getObjectSchema?o.getObjectSchema(n).catch(()=>null):Promise.resolve(null)).then(s=>{if(!e)return;I(s);let c=(0,t.buildExpandFields)(s?.fields,a),l=c.length>0?{$expand:c}:void 0,u=l?o.findOne(n,r,l):o.findOne(n,r),d=()=>{let t=String(r),a=t.startsWith(i)?t.slice(i.length):`${i}${t}`;return(l?o.findOne(n,a,l):o.findOne(n,a)).then(t=>{e&&(S(t),w(!1))}).catch(()=>{e&&(S(null),w(!1))})};return u.catch(()=>null).then(t=>{if(e){if(t){S(t),w(!1);return}return d()}})}).catch(t=>{e&&(console.error(`Failed to fetch detail data:`,t),w(!1))})}else J.api&&J.resourceId&&(w(!0),fetch(`${J.api}/${J.resourceId}`).then(e=>e.json()).then(t=>{e&&S(t?.data||t)}).catch(e=>{console.error(`Failed to fetch detail data:`,e)}).finally(()=>{e&&w(!1)}));return()=>{e=!1}},[J.api,J.resourceId,J.objectName,o,J.sections,J.fields,H,ne]);let fe=n.useCallback(()=>{if(p)p();else if(J.onNavigate){let e=J.backUrl||(J.objectName?`/${J.objectName}`:`/`);J.onNavigate(e,{replace:!0})}else J.backUrl?window.location.href=J.backUrl:window.history.back()},[p,J]),pe=n.useCallback(()=>{d?d():J.onNavigate&&J.editUrl?J.onNavigate(J.editUrl):J.onNavigate&&J.objectName&&J.resourceId?J.onNavigate(`/${J.objectName}/${J.resourceId}/edit`):J.editUrl&&(window.location.href=J.editUrl)},[d,J]),me=n.useCallback(async()=>{if(!o?.cancelPendingApproval||!J.objectName||!J.resourceId){P(K(`detail.cancelApprovalUnavailable`));return}re(!0),P(null);try{if(await o.cancelPendingApproval(String(J.objectName),String(J.resourceId)),o.findOne)try{let e=await o.findOne(String(J.objectName),String(J.resourceId));e&&S(e)}catch{}W(e=>e+1);try{window.dispatchEvent(new CustomEvent(`objectui:record-changed`,{detail:{objectName:String(J.objectName),recordId:String(J.resourceId),reason:`approval-recalled`}}))}catch{}}catch(e){let t=(e?.message||e?.error||String(e??`Cancel failed`)).replace(/^\[[^\]]+\]\s*/,``).replace(/^[A-Z][A-Z0-9_]+:\s*/,``);P(`${K(`detail.cancelApprovalFailed`)}: ${t}`)}finally{re(!1)}},[o,J.objectName,J.resourceId,K]),he=n.useCallback(()=>{let e=J.deleteConfirmation||K(`detail.deleteConfirmation`);window.confirm(e)&&(f?.(),J.onNavigate&&J.objectName&&J.onNavigate(`/${J.objectName}`,{replace:!0}))},[f,J]),X=n.useCallback(()=>{navigator.share&&J.objectName&&J.resourceId?navigator.share({title:J.title||K(`detail.details`),text:`${J.objectName} #${J.resourceId}`,url:window.location.href}).catch(e=>console.log(`Share failed:`,e)):navigator.clipboard.writeText(window.location.href).then(()=>{console.log(`Link copied to clipboard`)})},[J]),Z=n.useCallback(()=>{let e=!O;b&&b(e),y===void 0&&E(e)},[O,y,b]),ye=k?.setField,Q=k&&k.canEdit?k.enter:void 0;n.useEffect(()=>{if(!J.recordNavigation)return;let e=J.recordNavigation,t=t=>{let n=t.target?.tagName;n===`INPUT`||n===`TEXTAREA`||t.target?.isContentEditable||(t.key===`ArrowLeft`&&e.currentIndex>0?(t.preventDefault(),e.onNavigate(e.recordIds[e.currentIndex-1])):t.key===`ArrowRight`&&e.currentIndex<e.recordIds.length-1&&(t.preventDefault(),e.onNavigate(e.recordIds[e.currentIndex+1])))};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[J.recordNavigation]);let be=n.useMemo(()=>J.related??[],[J.related]),$=n.useMemo(()=>{let e=[];return e.push({name:`sys_share`,label:K(`detail.share`),icon:`share-2`,type:`script`,onClick:X}),J.showEdit&&e.push({name:`sys_edit_mobile`,label:K(`detail.edit`),icon:`edit`,type:`script`,className:`sm:hidden`,onClick:pe}),J.showDelete&&e.push({name:`sys_delete`,label:K(`detail.delete`),icon:`trash-2`,type:`script`,variant:`destructive`,tags:[`separator-before`],onClick:he}),e},[K,J.showEdit,J.showDelete,X,pe,he]),xe=n.useMemo(()=>{let e=J.actions??[];if($.length===0)return e;let t=!1,n=e.map(e=>{let n=e;if(n&&typeof n==`object`&&n.type===`action:bar`&&(!n.location||n.location===`record_header`)){t=!0;let e=Array.isArray(n.systemActions)?n.systemActions:[];return{...n,systemActions:[...e,...$]}}return e});return t||n.push({type:`action:bar`,location:`record_header`,systemActions:$}),n},[J.actions,$]);return C||J.loading?(0,c.jsxs)(`div`,{className:(0,r.cn)(`space-y-4`,s),children:[(0,c.jsx)(r.Skeleton,{className:`h-10 w-full`}),(0,c.jsx)(r.Skeleton,{className:`h-64 w-full`}),(0,c.jsx)(r.Skeleton,{className:`h-48 w-full`})]}):!x&&!J.data?(0,c.jsxs)(`div`,{className:(0,r.cn)(`flex flex-col items-center justify-center py-16 text-center`,s),children:[(0,c.jsx)(`p`,{className:`text-lg font-semibold`,children:K(`detail.recordNotFound`)}),(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:K(`detail.recordNotFoundDescription`)}),(J.showBack??!0)&&(0,c.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:fe,className:`mt-4 gap-2`,children:[(0,c.jsx)(i.ArrowLeft,{className:`h-4 w-4`}),K(`detail.goBack`)]})]}):(0,c.jsx)(r.TooltipProvider,{children:(0,c.jsxs)(`div`,{className:(0,r.cn)(`space-y-6`,s),children:[J.showHeader!==!1&&(0,c.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start justify-between gap-3 sm:gap-4 pb-4 border-b`,children:[(0,c.jsxs)(`div`,{className:`flex items-start gap-2 sm:gap-3 flex-1 min-w-0`,children:[(J.showBack??!0)&&(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,onClick:fe,className:`shrink-0 mt-1`,children:(0,c.jsx)(i.ArrowLeft,{className:`h-4 w-4`})})}),(0,c.jsx)(r.TooltipContent,{children:K(`detail.back`)})]}),(0,c.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,c.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold truncate`,children:ve(x,J,F,K(`detail.details`))}),ue.map(e=>{let t=x?.[e];if(t==null||t===``)return null;let n=(J.sections||[]).flatMap(e=>e.fields).concat(J.fields||[]).find(t=>t.name===e),i=F?.fields?.[e],a=n?.type||i?.type,o=String(t),s=null;try{if(a===`currency`){let e=Number(t);if(!Number.isNaN(e)){let t=(0,u.resolveFieldCurrency)({...i,...n},q);o=t?new Intl.NumberFormat(void 0,{style:`currency`,currency:t,maximumFractionDigits:0}).format(e):new Intl.NumberFormat(void 0,{maximumFractionDigits:0}).format(e)}}else if(a===`date`||a===`datetime`){let e=new Date(t);Number.isNaN(e.getTime())||(o=a===`datetime`?e.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):e.toLocaleDateString(void 0,{dateStyle:`medium`}))}else if(a===`percent`){let e=Number(t);if(!Number.isNaN(e)){o=`${e}%`;let t=e<=1?e*100:e;s=Math.max(0,Math.min(100,t))}}else if(a===`select`||a===`status`||a===`multiselect`){let r=n?.options||i?.options,a=String(t);if(Array.isArray(r)){let e=r.find(e=>String(e?.value??e)===String(t));e?.label&&(a=e.label)}else if(r&&typeof r==`object`){let e=r[String(t)];e?.label&&(a=e.label)}o=J.objectName?ae(J.objectName,e,String(t),a):a}}catch{}return s===null?(0,c.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent hover:bg-primary/15`,"aria-label":`${e}: ${o}`,children:o},e):(0,c.jsxs)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent hover:bg-primary/15 gap-1.5 pl-2 pr-2`,"aria-label":`${e}: ${o}`,children:[(0,c.jsx)(`span`,{className:`relative inline-block h-1.5 w-12 rounded-full bg-primary/20 overflow-hidden`,"aria-hidden":!0,children:(0,c.jsx)(`span`,{className:`absolute inset-y-0 left-0 rounded-full bg-primary`,style:{width:`${s}%`}})}),o]},e)}),(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 shrink-0`,onClick:Z,"aria-label":K(O?`detail.removeFromFavorites`:`detail.addToFavorites`),children:O?(0,c.jsx)(i.Star,{className:`h-4 w-4 fill-yellow-400 text-yellow-400`}):(0,c.jsx)(i.Star,{className:`h-4 w-4 text-muted-foreground`})})}),(0,c.jsx)(r.TooltipContent,{children:K(O?`detail.removeFromFavorites`:`detail.addToFavorites`)})]})]}),J.objectName&&(0,c.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1 flex items-center gap-1`,children:[(0,c.jsx)(`span`,{className:`font-medium`,children:_||J.objectName}),J.resourceId&&(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-5 w-5 shrink-0 text-muted-foreground/60 hover:text-foreground`,onClick:de,"aria-label":K(`detail.copyRecordId`,{defaultValue:`Copy record ID`}),children:ee?(0,c.jsx)(i.Check,{className:`h-3 w-3 text-green-600`}):(0,c.jsx)(i.Copy,{className:`h-3 w-3`})})}),(0,c.jsx)(r.TooltipContent,{children:ee?K(`detail.copied`,{defaultValue:`Copied`}):K(`detail.copyRecordId`,{defaultValue:`Copy record ID`})})]})]})]})]}),(0,c.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 shrink-0 w-full sm:w-auto`,children:[J.recordNavigation&&(0,c.jsxs)(`div`,{className:`flex items-center gap-1 mr-2`,children:[(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:J.recordNavigation.currentIndex<=0,onClick:()=>{let e=J.recordNavigation;e.currentIndex>0&&e.onNavigate(e.recordIds[e.currentIndex-1])},children:(0,c.jsx)(i.ChevronLeft,{className:`h-4 w-4`})})}),(0,c.jsx)(r.TooltipContent,{children:K(`detail.previousRecord`)})]}),(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap px-1`,children:K(`detail.recordOf`,{current:J.recordNavigation.currentIndex+1,total:J.recordNavigation.recordIds.length})}),(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsx)(r.Button,{variant:`outline`,size:`icon`,className:`h-8 w-8`,disabled:J.recordNavigation.currentIndex>=J.recordNavigation.recordIds.length-1,onClick:()=>{let e=J.recordNavigation;e.currentIndex<e.recordIds.length-1&&e.onNavigate(e.recordIds[e.currentIndex+1])},children:(0,c.jsx)(i.ChevronRight,{className:`h-4 w-4`})})}),(0,c.jsx)(r.TooltipContent,{children:K(`detail.nextRecord`)})]})]}),J.showEdit&&(0,c.jsxs)(r.Tooltip,{children:[(0,c.jsx)(r.TooltipTrigger,{asChild:!0,children:(0,c.jsxs)(r.Button,{variant:`default`,onClick:pe,className:`gap-2 hidden sm:inline-flex`,children:[(0,c.jsx)(i.Edit,{className:`h-4 w-4`}),(0,c.jsx)(`span`,{className:`hidden sm:inline`,children:K(`detail.edit`)})]})}),(0,c.jsx)(r.TooltipContent,{children:K(`detail.editRecord`)})]}),xe.map((e,t)=>(0,c.jsx)(a.SchemaRenderer,{schema:e,data:x},`header-action-${t}`))]})]}),J.header&&(0,c.jsx)(`div`,{children:(0,c.jsx)(a.SchemaRenderer,{schema:J.header,data:x})}),J.highlightFields&&J.highlightFields.length>0&&(0,c.jsx)(V,{fields:J.highlightFields,data:x,objectName:J.objectName,objectSchema:F}),m&&J.showHeader===!1&&(()=>{let e=x?.approval_status,t=(k?.locked??!1)||e===`pending`||e===`in_approval`;return!t&&!N?null:(0,c.jsxs)(`div`,{className:`flex flex-col items-end gap-1`,children:[t&&(0,c.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,c.jsxs)(`span`,{role:`status`,className:`inline-flex items-center gap-1 rounded-md border border-amber-300 bg-amber-50 px-2 py-1 text-xs text-amber-800`,title:k?.lockedReason??K(`detail.lockedTooltip`),children:[(0,c.jsx)(i.Lock,{className:`h-3 w-3`}),(0,c.jsx)(`span`,{children:K(`detail.lockedByApproval`)})]}),o?.cancelPendingApproval&&(0,c.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:me,disabled:G,className:`gap-2 border-amber-300 text-amber-800 hover:bg-amber-50`,title:K(`detail.cancelApprovalTooltip`),children:[(0,c.jsx)(i.X,{className:`h-4 w-4`}),(0,c.jsx)(`span`,{children:K(G?`detail.cancelApprovalInFlight`:`detail.cancelApproval`)})]})]}),N&&(0,c.jsx)(`div`,{role:`alert`,className:`text-xs text-destructive bg-destructive/10 border border-destructive/20 rounded-md px-2 py-1 max-w-md text-right`,children:N})]})})(),J.autoTabs&&!J.tabs?.length?(()=>{let e=be.length>0,t=!!J.activities&&J.activities.length>0,n=!!h,i=!!J.history,a=[`details`,...e?[`related`]:[],...t?[`activity`]:[],...n?[`discussion`]:[],...i?[`history`]:[]],s=J.defaultTab,l=s&&a.includes(s)?s:`details`,u=J.onTabChange,d=(0,c.jsxs)(`div`,{className:`space-y-3 sm:space-y-4`,children:[J.sectionGroups&&J.sectionGroups.length>0&&J.sectionGroups.map((e,t)=>(0,c.jsx)(B,{group:e,data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:ye,onEnterInlineEdit:m?Q:void 0,autoFocusField:M,dataSource:o},t)),J.sections&&J.sections.length>0&&J.sections.map((e,t)=>(0,c.jsx)(L,{section:e,data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:ye,onEnterInlineEdit:m?Q:void 0,autoFocusField:M,dataSource:o},t)),J.fields&&J.fields.length>0&&!J.sections?.length&&(0,c.jsx)(L,{section:{fields:J.fields,columns:J.columns},data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:ye,onEnterInlineEdit:m?Q:void 0,autoFocusField:M,dataSource:o}),J.comments&&(0,c.jsx)(U,{comments:J.comments,onAddComment:J.onAddComment})]});return!e&&!t&&!n&&!i?(0,c.jsx)(`div`,{className:`mt-2`,children:d}):(0,c.jsxs)(r.Tabs,{defaultValue:l,onValueChange:u,className:`w-full`,children:[(0,c.jsxs)(r.TabsList,{className:`w-full justify-start border-b rounded-none bg-transparent p-0`,children:[(0,c.jsx)(r.TabsTrigger,{value:`details`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:K(`detail.details`)}),e&&(0,c.jsx)(r.TabsTrigger,{value:`related`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:(0,c.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[K(`detail.related`),(0,c.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:be.length})]})}),t&&(0,c.jsx)(r.TabsTrigger,{value:`activity`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:(0,c.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[K(`detail.activity`),(0,c.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:J.activities.length})]})}),n&&(0,c.jsx)(r.TabsTrigger,{value:`discussion`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:K(`detail.discussion`,{defaultValue:`Discussion`})}),i&&(0,c.jsx)(r.TabsTrigger,{value:`history`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent`,children:(0,c.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[K(`detail.history`,{defaultValue:`History`}),!J.history.loading&&J.history.entries.length>0&&(0,c.jsx)(r.Badge,{variant:`secondary`,className:`text-xs bg-primary/10 text-primary border-transparent`,children:J.history.entries.length})]})})]}),(0,c.jsx)(r.TabsContent,{value:`details`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:d}),e&&(0,c.jsx)(r.TabsContent,{value:`related`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:(0,c.jsx)(`div`,{className:`space-y-3`,children:be.map((e,t)=>(0,c.jsx)(z,{title:e.title,type:e.type,api:e.api,data:e.data,columns:e.columns,dataSource:o,objectName:e.api,referenceField:e.referenceField,icon:e.icon,onNew:e.onNew,onViewAll:e.onViewAll,onRowClick:e.onRowClick,onRowEdit:e.onRowEdit,onRowDelete:e.onRowDelete,collapsible:!0,defaultCollapsed:oe&&t>0,pageSize:Y},t))})}),t&&(0,c.jsx)(r.TabsContent,{value:`activity`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:(0,c.jsx)(ie,{activities:J.activities})}),n&&(0,c.jsx)(r.TabsContent,{value:`discussion`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:h}),i&&(0,c.jsx)(r.TabsContent,{value:`history`,className:`mt-4 motion-safe:data-[state=active]:animate-in motion-safe:data-[state=active]:fade-in-0 motion-safe:duration-150`,children:(0,c.jsx)(le,{entries:J.history.entries,loading:J.history.loading,emptyText:J.history.emptyText??K(`detail.historyEmpty`,{defaultValue:`No history yet`})})})]})})():(0,c.jsxs)(c.Fragment,{children:[J.sectionGroups&&J.sectionGroups.length>0&&(0,c.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:J.sectionGroups.map((e,t)=>(0,c.jsx)(B,{group:e,data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:ye,onEnterInlineEdit:m?Q:void 0,autoFocusField:M,dataSource:o},t))}),J.sections&&J.sections.length>0&&(0,c.jsx)(`div`,{className:`space-y-3 sm:space-y-4`,children:J.sections.map((e,t)=>(0,c.jsx)(L,{section:e,data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:ye,onEnterInlineEdit:m?Q:void 0,autoFocusField:M,dataSource:o},t))}),J.fields&&J.fields.length>0&&!J.sections?.length&&(0,c.jsx)(L,{section:{fields:J.fields,columns:J.columns},data:{...x,...j},objectSchema:F,objectName:J.objectName,isEditing:A,onFieldChange:ye,onEnterInlineEdit:m?Q:void 0,autoFocusField:M,dataSource:o}),J.tabs&&J.tabs.length>0&&(0,c.jsx)(R,{tabs:J.tabs,data:x}),be.length>0&&(0,c.jsxs)(`div`,{className:`space-y-3`,children:[(0,c.jsx)(`h2`,{className:`text-lg font-semibold`,children:K(`detail.related`)}),be.map((e,t)=>(0,c.jsx)(z,{title:e.title,type:e.type,api:e.api,data:e.data,columns:e.columns,dataSource:o,objectName:e.api,referenceField:e.referenceField,icon:e.icon,onNew:e.onNew,onViewAll:e.onViewAll,onRowClick:e.onRowClick,onRowEdit:e.onRowEdit,onRowDelete:e.onRowDelete,collapsible:!0,defaultCollapsed:oe&&t>0,pageSize:Y},t))]}),J.comments&&(0,c.jsx)(U,{comments:J.comments,onAddComment:J.onAddComment}),J.activities&&J.activities.length>0&&(0,c.jsx)(ie,{activities:J.activities})]}),(0,c.jsx)(ge,{data:{...x,...j},objectSchema:F,objectName:J.objectName}),J.footer&&(0,c.jsx)(`div`,{children:(0,c.jsx)(a.SchemaRenderer,{schema:J.footer,data:x})})]})})},Z=e=>typeof e==`string`?e:e&&typeof e==`object`&&(e.field||e.name)||null,ye=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},Q=({schema:e={},className:t,...n})=>{let r=(0,a.useRecordContext)(),{designer:i}=ye(n),o=r?.objectName||``,s=(0,l.usePermissions)(),{readableFields:d}=(0,l.useFieldPermissions)(o),{sectionLabel:f}=(0,a.useSafeFieldLabel)(),{language:p}=(0,u.useObjectTranslation)(),m=(0,a.useHighlightFieldNames)();if(!r)return(0,c.jsx)(`div`,{className:t,"data-record-details-placeholder":!0,...i,children:(0,c.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2 border border-dashed rounded`,children:`record:details — bind a record to preview`})});let h=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(h.length>0&&o&&!h.every(e=>s.can(o,e)))return(0,c.jsx)(`div`,{className:t,...i,role:`status`,"aria-live":`polite`,children:(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view details.`})});let g=e.layout===`inline`||e.layout===`compact`?`horizontal`:`vertical`,_=e.enforceFieldSecurity===!0,v=Array.isArray(e.redactFields)?e.redactFields:[],y=e=>{if(!e||!_&&v.length===0)return e;let t=e.map(Z).filter(e=>!!e),n=new Set((_&&o?d(t):t).filter(e=>!v.includes(e)));return e.filter(e=>{let t=Z(e);return!t||n.has(t)})},b=e=>typeof e==`string`?{name:e}:e&&typeof e==`object`&&!e.name&&e.field?{...e,name:e.field}:e,x=e=>Array.isArray(e)?e.map(b):e,S=new Set((Array.isArray(e.hideFields)?e.hideFields:[]).map(e=>typeof e==`string`?e:Z(e)).filter(e=>!!e));for(let e of m)S.add(e);let C=r.objectSchema,w=r.data??{},T=[C?.primaryField,`name`,`full_name`,`title`,`subject`,`display_name`,`label`].filter(e=>typeof e==`string`&&e.length>0);for(let e of T)if(w[e]!==void 0&&w[e]!==null&&w[e]!==``){S.add(e);break}let E=e=>!e||S.size===0?e:e.filter(e=>{let t=Z(e);return!t||!S.has(t)}),D=E(x(y(e.fields))),O=Array.isArray(e.sections)?e.sections.map(e=>{let t=e.title??e.label,n=t==null?void 0:(0,u.pickLocalized)(t,p),r=e.name&&o?f(o,e.name,n??e.name):n;return{...e,title:r,showBorder:e.showBorder??!!r,hideEmpty:e.hideEmpty??!0,fields:E(x(y(e.fields)))}}):e.sections,k=new Set([`system`,`append-only`,`better-auth`]),A=C?.managedBy,j=C?.userActions?.edit,M=(typeof j==`object`&&j?j.enabled:j)??!(A!=null&&k.has(A)),N=(e.inlineEdit??!0)&&M,P={type:`detail-view`,objectName:r.objectName,resourceId:r.recordId,data:r.data,layout:g,columns:e.columns,sections:O,fields:D,showBack:!1,showHeader:e.showHeader??!1,inlineEdit:N};return(0,c.jsx)(`div`,{className:t,...i,children:(0,c.jsx)(X,{schema:P,dataSource:r.dataSource,inlineEdit:N})})},be=e=>typeof e==`string`?e:e&&typeof e==`object`&&(e.field||e.name||e.key)||null,$=e=>e?.id??e?._id??null,xe=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},Se=({schema:e={},className:t,...r})=>{let i=(0,a.useRecordContext)(),{designer:s}=xe(r),d=(0,a.useSafeFieldLabel)(),{language:f}=(0,u.useObjectTranslation)(),p=e.objectName,m=p&&d.objectLabel?d.objectLabel({name:p,label:(0,o.humanizeLabel)(p)}):p?(0,o.humanizeLabel)(p):``,h=(0,u.pickLocalized)(e.title,f)||m||`Related`;if(!p)return(0,c.jsx)(`div`,{className:t,...s,children:(0,c.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2 border border-dashed rounded`,children:`record:related_list — missing objectName`})});let g=(0,l.usePermissions)(),{readableFields:_}=(0,l.useFieldPermissions)(p),v=e.relationshipValueField||`id`,y=v===`id`?i?.recordId??null:i?.data?.[v]??null,b=(0,a.useRelatedRecordActions)(),x=n.default.useMemo(()=>b?.resolve({objectName:p,relationshipField:e.relationshipField,parentId:y})??null,[b,p,e.relationshipField,y]);if(g.isLoaded&&!g.can(p,`read`))return null;let S=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(S.length>0&&!S.every(e=>g.can(p,e)))return(0,c.jsx)(`div`,{className:t,...s,role:`status`,"aria-live":`polite`,children:(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view related list.`})});let C=e.enforceFieldSecurity===!0,w=Array.isArray(e.redactFields)?e.redactFields:[],T=Array.isArray(e.columns)?e.columns:[],E=T;if(C||w.length>0){let e=T.map(be).filter(e=>!!e),t=new Set((C?_(e):e).filter(e=>!w.includes(e)));E=T.filter(e=>{let n=be(e);return!n||t.has(n)})}return(0,c.jsx)(`div`,{className:t,...s,children:(0,c.jsx)(z,{title:h,type:`table`,api:p,objectName:p,referenceField:e.relationshipField,parentId:y,columns:E,pageSize:e.limit,dataSource:i?.dataSource,add:e.add?{...e.add,label:(0,u.pickLocalized)(e.add.label,f)||void 0}:void 0,rowActions:x?.rowActions,onRowAction:x?.onRowAction,toolbarActions:x?.toolbarActions,onToolbarAction:x?.onToolbarAction,onNew:x?.onCreate,onRowClick:x?.onView?e=>{let t=$(e);t!=null&&x.onView(t,e)}:void 0,onRowEdit:x?.onEdit?e=>{let t=$(e);t!=null&&x.onEdit(t,e)}:void 0,onRowDelete:x?.onDelete?e=>{let t=$(e);if(t!=null)return x.onDelete(t,e)}:e.add&&i?.dataSource?async e=>{let t=e?.id??e?._id;t!=null&&await i.dataSource.delete?.(p,String(t))}:void 0})})},Ce=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},we=({schema:e={},className:t,...r})=>{let i=(0,a.useRecordContext)(),{designer:o}=Ce(r),s=i?.objectName||``,u=(0,l.usePermissions)(),{readableFields:d}=(0,l.useFieldPermissions)(s),f=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(f.length>0&&s&&!f.every(e=>u.can(s,e)))return(0,c.jsx)(`div`,{className:t,...o,role:`status`,"aria-live":`polite`,children:(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view highlights.`})});let p=(Array.isArray(e.fields)?e.fields:[]).map(e=>typeof e==`string`?{name:e}:{name:e?.name,label:e?.label,icon:e?.icon,type:e?.type}).filter(e=>typeof e.name==`string`&&e.name.length>0),m=e.enforceFieldSecurity===!0,h=Array.isArray(e.redactFields)?e.redactFields:[],g=m&&s?new Set(d(p.map(e=>e.name))):null,_=p.filter(e=>!(h.includes(e.name)||g&&!g.has(e.name)));return(0,a.useRegisterHighlightFields)(n.default.useId(),_.map(e=>e.name)),(0,c.jsx)(`div`,{className:t,...o,children:(0,c.jsx)(V,{fields:_,data:i?.data,objectName:i?.objectName,objectSchema:i?.objectSchema,dataSource:i?.dataSource})})},Te=({change:e,className:t})=>{let n=e.fieldLabel??e.field.charAt(0).toUpperCase()+e.field.slice(1).replace(/_/g,` `),a=e.oldDisplayValue??(e.oldValue==null?`(empty)`:String(e.oldValue)),o=e.newDisplayValue??(e.newValue==null?`(empty)`:String(e.newValue));return(0,c.jsxs)(`div`,{className:(0,r.cn)(`flex items-center gap-1.5 text-sm flex-wrap`,t),children:[(0,c.jsx)(`span`,{className:`font-medium text-foreground`,children:n}),(0,c.jsx)(`span`,{className:`text-muted-foreground line-through`,children:a}),(0,c.jsx)(i.ArrowRight,{className:`h-3 w-3 text-muted-foreground shrink-0`}),(0,c.jsx)(`span`,{className:`text-foreground`,children:o})]})},Ee=[`👍`,`❤️`,`🎉`,`😂`,`😮`,`😢`],De=({reactions:e,onToggleReaction:t,emojiOptions:a=Ee,className:o})=>{let[s,l]=n.useState(!1),u=n.useCallback(e=>{t?.(e),l(!1)},[t]);return(0,c.jsxs)(`div`,{className:(0,r.cn)(`flex items-center gap-1 flex-wrap`,o),children:[e.map(e=>(0,c.jsxs)(`button`,{type:`button`,className:(0,r.cn)(`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs border transition-colors`,e.reacted?`bg-primary/10 border-primary/30 text-primary`:`bg-muted border-border text-muted-foreground hover:bg-muted/80`),onClick:()=>u(e.emoji),disabled:!t,"aria-label":`${e.emoji} ${e.count} reaction${e.count===1?``:`s`}`,children:[(0,c.jsx)(`span`,{children:e.emoji}),(0,c.jsx)(`span`,{children:e.count})]},e.emoji)),t&&(0,c.jsxs)(`div`,{className:`relative`,children:[(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>l(!s),"aria-label":`Add reaction`,children:(0,c.jsx)(i.SmilePlus,{className:`h-3.5 w-3.5`})}),s&&(0,c.jsx)(`div`,{className:`absolute bottom-full mb-1 left-0 bg-popover border rounded-md shadow-md z-50 p-1.5 flex gap-1`,role:`listbox`,"aria-label":`Emoji picker`,children:a.map(t=>(0,c.jsx)(`button`,{type:`button`,className:`hover:bg-accent rounded p-1 text-base transition-colors`,onClick:()=>u(t),role:`option`,"aria-selected":e.some(e=>e.emoji===t&&e.reacted),children:t},t))})]})]})};function Oe(e,t){try{let n=new Date(e),r=new Date().getTime()-n.getTime(),i=Math.floor(r/6e4);if(i<1)return t(`detail.justNow`);if(i<60)return t(`detail.minutesAgo`,{count:i});let a=Math.floor(i/60);if(a<24)return t(`detail.hoursAgo`,{count:a});let o=Math.floor(a/24);return o<7?t(`detail.daysAgo`,{count:o}):n.toLocaleDateString()}catch{return e}}var ke=({parentItem:e,replies:t,onAddReply:a,showReplyInput:o=!0,className:s})=>{let{t:l}=D(),[u,d]=n.useState(!1),[f,p]=n.useState(``),[m,h]=n.useState(!1),g=n.useCallback(async()=>{let t=f.trim();if(!(!t||!a)){h(!0);try{await a(e.id,t),p(``)}finally{h(!1)}}},[f,a,e.id]),_=n.useCallback(e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),g())},[g]);return t.length===0&&!o?null:(0,c.jsxs)(`div`,{className:(0,r.cn)(`ml-10 mt-1`,s),children:[t.length>0&&(0,c.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors mb-1`,onClick:()=>d(!u),"aria-expanded":u,children:[u?(0,c.jsx)(i.ChevronDown,{className:`h-3 w-3`}):(0,c.jsx)(i.ChevronRight,{className:`h-3 w-3`}),(0,c.jsx)(i.MessageSquare,{className:`h-3 w-3`}),(0,c.jsx)(`span`,{children:t.length===1?l(`detail.replyCount`,{count:t.length}):l(`detail.replyCountPlural`,{count:t.length})})]}),u&&(0,c.jsx)(`div`,{className:`space-y-2 border-l-2 border-border pl-3`,children:t.map(e=>(0,c.jsxs)(`div`,{className:`flex gap-2`,children:[(0,c.jsx)(`div`,{className:`shrink-0`,children:e.actorAvatarUrl?(0,c.jsx)(`img`,{src:e.actorAvatarUrl,alt:e.actor,className:`h-6 w-6 rounded-full object-cover`}):(0,c.jsx)(`div`,{className:`h-6 w-6 rounded-full bg-muted flex items-center justify-center text-[10px] font-medium text-muted-foreground`,children:e.actor.charAt(0).toUpperCase()})}),(0,c.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,c.jsx)(`span`,{className:`text-xs font-medium`,children:e.actor}),(0,c.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:Oe(e.createdAt,l)})]}),(0,c.jsx)(`p`,{className:`text-xs whitespace-pre-wrap break-words`,children:e.body})]})]},e.id))}),o&&a&&(0,c.jsxs)(`div`,{className:`flex gap-1.5 mt-1.5`,children:[(0,c.jsx)(`input`,{className:`flex-1 rounded-md border border-input bg-background px-2 py-1 text-xs placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,placeholder:l(`detail.replyPlaceholder`),value:f,onChange:e=>p(e.target.value),onKeyDown:_,disabled:m}),(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 shrink-0`,onClick:g,disabled:!f.trim()||m,"aria-label":`Send reply`,children:(0,c.jsx)(i.Send,{className:`h-3 w-3`})})]})]})},Ae=({subscription:e,onToggle:t,className:a})=>{let{t:o}=D(),[s,l]=n.useState(!1),u=n.useCallback(async()=>{if(t){l(!0);try{await t(!e.subscribed)}finally{l(!1)}}},[t,e.subscribed]);return(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:(0,r.cn)(`h-8 w-8`,a),onClick:u,disabled:s||!t,"aria-label":e.subscribed?o(`detail.unsubscribeAriaLabel`):o(`detail.subscribeAriaLabel`),title:e.subscribed?o(`detail.subscribedTooltip`):o(`detail.unsubscribedTooltip`),children:e.subscribed?(0,c.jsx)(i.Bell,{className:`h-4 w-4 text-primary`}):(0,c.jsx)(i.BellOff,{className:`h-4 w-4 text-muted-foreground`})})};function je(e){let t=e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/```([\s\S]*?)```/g,`<pre class="bg-muted rounded p-2 text-xs font-mono my-1 overflow-x-auto">$1</pre>`).replace(/`([^`]+)`/g,`<code class="bg-muted rounded px-1 py-0.5 text-xs font-mono">$1</code>`).replace(/\*\*(.+?)\*\*/g,`<strong>$1</strong>`).replace(/\*(.+?)\*/g,`<em>$1</em>`).replace(/@(\w+)/g,`<span class="text-primary font-medium">@$1</span>`).replace(/^- (.+)$/gm,`<li class="ml-4 list-disc">$1</li>`).replace(/\n/g,`<br/>`);return t=t.replace(/(<li[^>]*>.*?<\/li>(?:<br\/>)?)+/g,e=>`<ul class="my-1">${e.replace(/<br\/>/g,``)}</ul>`),t}var Me=({value:e,onChange:t,onSubmit:a,mentionSuggestions:o=[],placeholder:s,className:l,disabled:u=!1,extraSlot:d,canSubmitEmpty:f=!1})=>{let{t:p}=D(),[m,h]=n.useState(!1),[g,_]=n.useState(!1),[v,y]=n.useState(``),[b,x]=n.useState(0),S=n.useRef(null),C=n.useMemo(()=>{if(!v)return o;let e=v.toLowerCase();return o.filter(t=>t.label.toLowerCase().includes(e))},[v,o]),w=n.useCallback((n,r=``)=>{let i=S.current;if(!i)return;let a=i.selectionStart,o=i.selectionEnd,s=e.slice(a,o);t(e.slice(0,a)+n+s+r+e.slice(o)),requestAnimationFrame(()=>{i.focus();let e=a+n.length+s.length;i.setSelectionRange(e,e)})},[e,t]),T=n.useCallback(()=>w(`**`,`**`),[w]),E=n.useCallback(()=>w(`*`,`*`),[w]),O=n.useCallback(()=>w(`
2
2
  - `,``),[w]),k=n.useCallback(()=>w("`","`"),[w]),A=n.useCallback(()=>{w(`@`,``),_(!0),y(``),x(0)},[w]),j=n.useCallback(n=>{let r=S.current;if(!r)return;let i=r.selectionStart,a=e.slice(0,i).lastIndexOf(`@`);a!==-1&&t(e.slice(0,a)+`@${n.label} `+e.slice(i)),_(!1),y(``),requestAnimationFrame(()=>r.focus())},[e,t]),M=n.useCallback(e=>{let n=e.target.value;t(n);let r=e.target.selectionStart,i=n.slice(0,r),a=i.lastIndexOf(`@`);if(a!==-1){let e=i.slice(a+1),t=a>0?i[a-1]:` `;if(/\s/.test(t)&&!/\s/.test(e)){_(!0),y(e),x(0);return}}_(!1)},[t]),N=n.useCallback(e=>{if(g&&C.length>0){if(e.key===`ArrowDown`){e.preventDefault(),x(e=>e<C.length-1?e+1:0);return}if(e.key===`ArrowUp`){e.preventDefault(),x(e=>e>0?e-1:C.length-1);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault(),j(C[b]);return}if(e.key===`Escape`){_(!1);return}}e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),a?.())},[g,C,b,j,a]);return(0,c.jsxs)(`div`,{className:(0,r.cn)(`border rounded-md`,l),children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-0.5 px-2 py-1.5 border-b bg-muted/30`,children:[(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:T,disabled:u||m,title:p(`detail.bold`),children:(0,c.jsx)(i.Bold,{className:`h-3.5 w-3.5`})}),(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:E,disabled:u||m,title:p(`detail.italic`),children:(0,c.jsx)(i.Italic,{className:`h-3.5 w-3.5`})}),(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:O,disabled:u||m,title:p(`detail.listFormat`),children:(0,c.jsx)(i.List,{className:`h-3.5 w-3.5`})}),(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:k,disabled:u||m,title:p(`detail.inlineCode`),children:(0,c.jsx)(i.Code,{className:`h-3.5 w-3.5`})}),(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:A,disabled:u||m,title:p(`detail.mentionSomeone`),children:(0,c.jsx)(i.AtSign,{className:`h-3.5 w-3.5`})}),(0,c.jsx)(`div`,{className:`flex-1`}),(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>h(!m),title:p(m?`detail.edit`:`detail.preview`),children:m?(0,c.jsx)(i.Edit,{className:`h-3.5 w-3.5`}):(0,c.jsx)(i.Eye,{className:`h-3.5 w-3.5`})}),a&&(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:a,disabled:u||!f&&!e.trim(),title:p(`detail.submitComment`),children:(0,c.jsx)(i.Send,{className:`h-3.5 w-3.5`})})]}),(0,c.jsx)(`div`,{className:`relative`,children:m?(0,c.jsx)(`div`,{className:`min-h-[80px] px-3 py-2 text-sm prose prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:je(e)}}):(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(`textarea`,{ref:S,className:`w-full min-h-[80px] px-3 py-2 text-sm bg-transparent resize-none focus:outline-none placeholder:text-muted-foreground`,placeholder:s??p(`detail.writeComment`),value:e,onChange:M,onKeyDown:N,disabled:u}),g&&C.length>0&&(0,c.jsx)(`div`,{className:`absolute left-2 bottom-full mb-1 w-56 bg-popover border rounded-md shadow-md z-50 max-h-40 overflow-y-auto`,children:C.map((e,t)=>(0,c.jsxs)(`button`,{type:`button`,className:(0,r.cn)(`w-full text-left px-3 py-1.5 text-sm flex items-center gap-2 hover:bg-accent transition-colors`,t===b&&`bg-accent`),onMouseDown:t=>{t.preventDefault(),j(e)},children:[e.avatarUrl?(0,c.jsx)(`img`,{src:e.avatarUrl,alt:e.label,className:`h-5 w-5 rounded-full object-cover`}):(0,c.jsx)(`div`,{className:`h-5 w-5 rounded-full bg-muted flex items-center justify-center text-[10px] font-medium`,children:e.label.charAt(0).toUpperCase()}),(0,c.jsx)(`span`,{children:e.label})]},e.id))})]})}),d&&(0,c.jsx)(`div`,{className:`border-t px-2 py-2 bg-muted/20`,children:d})]})};function Ne(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Pe(e){return e.startsWith(`image/`)}function Fe(e){return Pe(e)?i.Image:e.includes(`pdf`)||e.includes(`document`)||e.includes(`text`)?i.FileText:e.includes(`zip`)||e.includes(`archive`)||e.includes(`compressed`)?i.FileArchive:i.File}var Ie=({attachments:e,onUpload:t,onRemove:a,className:o,readOnly:s=!1})=>{let{t:l}=D(),[u,d]=n.useState(!1),f=n.useRef(null),p=n.useCallback(e=>{e.preventDefault(),e.stopPropagation(),d(!0)},[]),m=n.useCallback(e=>{e.preventDefault(),e.stopPropagation(),d(!1)},[]),h=n.useCallback(e=>{e.preventDefault(),e.stopPropagation(),d(!1),t&&e.dataTransfer.files.length>0&&t(e.dataTransfer.files)},[t]),g=n.useCallback(e=>{t&&e.target.files&&e.target.files.length>0&&(t(e.target.files),e.target.value=``)},[t]);return(0,c.jsxs)(`div`,{className:(0,r.cn)(`space-y-2`,o),children:[t&&!s&&(0,c.jsxs)(`div`,{className:(0,r.cn)(`border-2 border-dashed rounded-md px-4 py-3 text-center transition-colors cursor-pointer`,u?`border-primary bg-primary/5`:`border-muted-foreground/25 hover:border-muted-foreground/40`),onDragOver:p,onDragLeave:m,onDrop:h,onClick:()=>f.current?.click(),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),f.current?.click())},children:[(0,c.jsx)(i.Upload,{className:`h-5 w-5 mx-auto text-muted-foreground mb-1`}),(0,c.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`detail.dropFilesToUpload`)}),(0,c.jsx)(`input`,{ref:f,type:`file`,multiple:!0,className:`hidden`,onChange:g})]}),e.length>0&&(0,c.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,c.jsx)(i.Paperclip,{className:`h-3 w-3`}),(0,c.jsx)(`span`,{children:e.length===1?l(`detail.attachmentCount`,{count:e.length}):l(`detail.attachmentCountPlural`,{count:e.length})})]}),(0,c.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.map(e=>{let t=Pe(e.type),n=Fe(e.type);return(0,c.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border px-2.5 py-2 bg-muted/30 group`,children:[t&&(e.thumbnailUrl||e.url)?(0,c.jsx)(`img`,{src:e.thumbnailUrl||e.url,alt:e.name,className:`h-10 w-10 rounded object-cover shrink-0`}):(0,c.jsx)(`div`,{className:`h-10 w-10 rounded bg-muted flex items-center justify-center shrink-0`,children:(0,c.jsx)(n,{className:`h-5 w-5 text-muted-foreground`})}),(0,c.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,c.jsx)(`p`,{className:`text-xs font-medium truncate`,children:e.name}),(0,c.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:Ne(e.size)})]}),a&&!s&&(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity`,onClick:()=>a(e.id),title:l(`detail.removeAttachment`),children:(0,c.jsx)(i.X,{className:`h-3.5 w-3.5`})})]},e.id)})})]})]})},Le={comment:i.MessageSquare,field_change:i.Edit,task:i.CheckSquare,event:i.Calendar,system:i.Zap,email:i.Mail,call:i.Phone},Re={comment:`bg-purple-100 text-purple-600`,field_change:`bg-blue-100 text-blue-600`,task:`bg-green-100 text-green-600`,event:`bg-amber-100 text-amber-600`,system:`bg-gray-100 text-gray-600`,email:`bg-indigo-100 text-indigo-600`,call:`bg-teal-100 text-teal-600`};function ze(e){return[{value:`all`,label:e(`detail.allActivity`)},{value:`comments_only`,label:e(`detail.commentsOnly`)},{value:`changes_only`,label:e(`detail.fieldChangesFilter`)},{value:`tasks_only`,label:e(`detail.tasksOnly`)}]}function Be(e,t){try{let n=new Date(e),r=new Date().getTime()-n.getTime(),i=Math.floor(r/6e4);if(i<1)return t(`detail.justNow`);if(i<60)return t(`detail.minutesAgo`,{count:i});let a=Math.floor(i/60);if(a<24)return t(`detail.hoursAgo`,{count:a});let o=Math.floor(a/24);return o<7?t(`detail.daysAgo`,{count:o}):n.toLocaleDateString()}catch{return e}}function Ve(e,t){switch(t){case`comments_only`:return e.filter(e=>e.type===`comment`);case`changes_only`:return e.filter(e=>e.type===`field_change`);case`tasks_only`:return e.filter(e=>e.type===`task`);default:return e}}var He=({items:e,config:t,filterMode:a,onFilterChange:o,hasMore:s=!1,onLoadMore:l,loading:u=!1,onAddComment:d,onAddReply:f,onToggleReaction:p,subscription:m,onToggleSubscription:h,collapseWhenEmpty:g=!1,mentionSuggestions:_,onUploadAttachments:v,titleLabel:y,emptyLabel:b,className:x})=>{let{t:S}=D(),[C,w]=n.useState(`all`),[T,E]=n.useState(``),[O,k]=n.useState(!1),[A,j]=n.useState(!1),[M,N]=n.useState([]),[P,F]=n.useState(!1),I=a??C,L=t?.showFilterToggle!==!1,R=t?.showCommentInput!==!1&&!!d,ee=t?.enableReactions??!1,te=t?.enableThreading??!1,z=t?.showSubscriptionToggle??!1,B=n.useMemo(()=>Ve(e,I),[e,I]),V=n.useMemo(()=>te?B.filter(e=>!e.parentId):B,[B,te]),H=n.useMemo(()=>{if(!te)return new Map;let e=new Map;for(let t of B)if(t.parentId){let n=e.get(t.parentId)??[];n.push(t),e.set(t.parentId,n)}return e},[B,te]),U=n.useCallback(e=>{o?o(e):w(e)},[o]),W=n.useCallback(async()=>{let e=T.trim();if(d&&!(!e&&M.length===0)){k(!0);try{await d(e,M.length>0?M:void 0),E(``),N([])}finally{k(!1)}}},[T,M,d]),ne=n.useCallback(async e=>{if(!(!v||e.length===0)){F(!0);try{let t=await v(e);Array.isArray(t)&&t.length>0&&N(e=>[...e,...t])}finally{F(!1)}}},[v]),G=n.useCallback(e=>{N(t=>t.filter(t=>t.id!==e))},[]),re=n.useCallback(async()=>{if(l){j(!0);try{await l()}finally{j(!1)}}},[l]);return(0,c.jsxs)(`section`,{className:(0,r.cn)(`border-t border-border/60 pt-5`,x),"aria-label":`Discussion`,children:[(0,c.jsx)(`header`,{className:`mb-4`,children:(0,c.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,c.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold leading-none tracking-tight`,children:[(0,c.jsx)(i.Activity,{className:`h-4 w-4`}),y??S(`detail.activity`),(0,c.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,B.length,`)`]})]}),(0,c.jsx)(`div`,{className:`flex items-center gap-1`,children:z&&m&&(0,c.jsx)(Ae,{subscription:m,onToggle:h})})]})}),(0,c.jsxs)(`div`,{className:`space-y-4`,children:[L&&(0,c.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,c.jsxs)(r.Select,{value:I,onValueChange:e=>U(e),children:[(0,c.jsx)(r.SelectTrigger,{"aria-label":S(`detail.filterActivity`),className:`h-8 w-auto min-w-[140px] py-1 text-sm`,children:(0,c.jsx)(r.SelectValue,{})}),(0,c.jsx)(r.SelectContent,{children:ze(S).map(e=>(0,c.jsx)(r.SelectItem,{value:e.value,children:e.label},e.value))})]})}),R&&(0,c.jsx)(Me,{value:T,onChange:E,onSubmit:W,mentionSuggestions:_,placeholder:S(`detail.leaveCommentPlaceholder`),disabled:O,canSubmitEmpty:M.length>0,extraSlot:v?(0,c.jsx)(Ie,{attachments:M,onUpload:ne,onRemove:G,readOnly:O||P}):M.length>0?(0,c.jsx)(Ie,{attachments:M,onRemove:G,readOnly:O}):void 0}),B.length===0?g?null:(0,c.jsx)(r.DataEmptyState,{title:b??S(`detail.noActivity`),className:`py-6`}):(0,c.jsxs)(`div`,{className:`relative`,children:[(0,c.jsx)(`div`,{className:`absolute left-4 top-2 bottom-2 w-px bg-border`}),(0,c.jsx)(`div`,{className:`space-y-4`,children:V.map(e=>{let t=Le[e.type]||i.Zap,n=Re[e.type]||`bg-gray-100 text-gray-600`,a=H.get(e.id)??[];return(0,c.jsxs)(`div`,{children:[(0,c.jsxs)(`div`,{className:`flex gap-3 relative`,children:[(0,c.jsx)(`div`,{className:(0,r.cn)(`shrink-0 h-8 w-8 rounded-full flex items-center justify-center z-10`,n),children:e.actorAvatarUrl?(0,c.jsx)(`img`,{src:e.actorAvatarUrl,alt:e.actor,className:`h-8 w-8 rounded-full object-cover`}):(0,c.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,c.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-2 mb-0.5`,children:[(0,c.jsx)(`span`,{className:`text-sm font-medium`,children:e.actor}),e.source&&(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:S(`detail.via`,{source:e.source})}),(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:Be(e.createdAt,S)}),e.edited&&(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:S(`detail.edited`)}),e.pinned&&(0,c.jsxs)(`span`,{className:`text-xs text-amber-600`,children:[`📌 `,S(`detail.pinned`)]})]}),e.body&&(0,c.jsx)(`p`,{className:`text-sm whitespace-pre-wrap break-words text-muted-foreground`,children:e.body}),e.sourceObject&&e.sourceId!=null&&(0,c.jsxs)(`a`,{href:`/objects/${e.sourceObject}/${e.sourceId}`,className:`mt-1 inline-flex items-center gap-1 text-xs text-primary hover:underline`,"data-testid":`activity-source-link`,children:[S(`detail.viewSource`),(0,c.jsx)(`span`,{"aria-hidden":!0,children:`→`})]}),e.type===`field_change`&&e.fieldChanges&&(0,c.jsx)(`div`,{className:`space-y-1 mt-1`,children:e.fieldChanges.map((e,t)=>(0,c.jsx)(Te,{change:e},t))}),ee&&e.reactions&&e.reactions.length>0&&(0,c.jsx)(`div`,{className:`mt-1.5`,children:(0,c.jsx)(De,{reactions:e.reactions,onToggleReaction:p?t=>p(e.id,t):void 0})}),ee&&(!e.reactions||e.reactions.length===0)&&p&&(0,c.jsx)(`div`,{className:`mt-1.5`,children:(0,c.jsx)(De,{reactions:[],onToggleReaction:t=>p(e.id,t)})})]})]}),te&&(e.replyCount??0)>0&&(0,c.jsx)(ke,{parentItem:e,replies:a,onAddReply:f,showReplyInput:!!f})]},e.id)})})]}),s&&(0,c.jsx)(`div`,{className:`text-center pt-2`,children:(0,c.jsxs)(r.Button,{variant:`ghost`,size:`sm`,onClick:re,disabled:A,"aria-label":S(`detail.loadMore`),children:[A?(0,c.jsx)(i.Loader2,{className:`h-4 w-4 animate-spin mr-1`}):(0,c.jsx)(i.ChevronDown,{className:`h-4 w-4 mr-1`}),S(`detail.loadMore`)]})})]})]})},Ue=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},We=({schema:e={},className:t,...n})=>{(0,a.useRecordContext)();let{designer:r}=Ue(n);return(0,c.jsx)(`div`,{className:t,...r,children:(0,c.jsx)(He,{items:[],config:e})})},Ge=({config:e,items:t,hasMore:a,onLoadMore:o,loading:s,onAddComment:l,onAddReply:u,onToggleReaction:d,subscription:f,onToggleSubscription:p,filterMode:m,onFilterChange:h,collapseWhenEmpty:g=!1,mentionSuggestions:_,onUploadAttachments:v,className:y})=>{let b=e?.position??`right`,x=e?.width??`360px`,S=e?.collapsible??!0,C=g&&t.length===0||(e?.defaultCollapsed??!1),{t:w}=D(),[T,E]=n.useState(C);return b===`right`||b===`left`?T&&S?(0,c.jsx)(`div`,{className:(0,r.cn)(`flex items-start pt-4`,b===`right`?`border-l`:`border-r`,y),children:(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-8 w-8 mx-1`,onClick:()=>E(!1),"aria-label":w(`detail.openDiscussion`),children:(0,c.jsx)(i.PanelRightOpen,{className:`h-4 w-4`})})}):(0,c.jsxs)(`div`,{className:(0,r.cn)(`flex flex-col overflow-hidden`,b===`right`?`border-l`:`border-r`,y),style:{width:x,minWidth:x},children:[(0,c.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b`,children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,c.jsx)(i.MessageSquare,{className:`h-4 w-4`}),(0,c.jsx)(`span`,{className:`text-sm font-medium`,children:w(`detail.discussion`)})]}),S&&(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>E(!0),"aria-label":w(`detail.closeDiscussion`),children:(0,c.jsx)(i.X,{className:`h-3.5 w-3.5`})})]}),(0,c.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,c.jsx)(He,{items:t,config:e?.feed,hasMore:a,onLoadMore:o,loading:s,onAddComment:l,onAddReply:u,onToggleReaction:d,subscription:f,onToggleSubscription:p,filterMode:m,onFilterChange:h,collapseWhenEmpty:g,mentionSuggestions:_,onUploadAttachments:v,titleLabel:w(`detail.discussion`),emptyLabel:w(`detail.noCommentsYet`),className:`border-0 shadow-none`})})]}):(0,c.jsx)(`div`,{className:(0,r.cn)(``,y),children:S&&T?(0,c.jsxs)(r.Button,{variant:`ghost`,className:`w-full justify-start gap-2 text-muted-foreground`,onClick:()=>E(!1),"aria-label":w(`detail.showDiscussion`,{count:t.length}),children:[(0,c.jsx)(i.MessageSquare,{className:`h-4 w-4`}),(0,c.jsx)(`span`,{children:w(`detail.showDiscussion`,{count:t.length})})]}):(0,c.jsxs)(`div`,{children:[S&&(0,c.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,c.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,c.jsx)(i.MessageSquare,{className:`h-4 w-4`}),w(`detail.discussion`)]}),(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>E(!0),"aria-label":w(`detail.hideDiscussion`),children:(0,c.jsx)(i.PanelRightClose,{className:`h-3.5 w-3.5`})})]}),(0,c.jsx)(He,{items:t,config:e?.feed,hasMore:a,onLoadMore:o,loading:s,onAddComment:l,onAddReply:u,onToggleReaction:d,subscription:f,onToggleSubscription:p,filterMode:m,onFilterChange:h,collapseWhenEmpty:g,mentionSuggestions:_,onUploadAttachments:v,titleLabel:w(`detail.discussion`),emptyLabel:w(`detail.noCommentsYet`)})]})})},Ke=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},qe=({schema:e={},className:t,...n})=>{(0,a.useRecordContext)();let r=(0,a.useDiscussionContext)(),{designer:i}=Ke(n),o={position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0},...e};return(0,c.jsx)(`div`,{className:t,...i,children:(0,c.jsx)(Ge,{items:r?.items||[],config:o,onAddComment:r?.onAddComment,onAddReply:r?.onAddReply,onToggleReaction:r?.onToggleReaction,mentionSuggestions:r?.mentionSuggestions,onUploadAttachments:r?.onUploadAttachments})})},Je=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},Ye=({schema:e={},className:t,...i})=>{let o=(0,a.useRecordContext)(),{translateOptions:s}=(0,a.useSafeFieldLabel)(),{designer:l}=Je(i),u=Array.isArray(e.stages)?e.stages:[],d=e.statusField,f=n.default.useMemo(()=>{if(u.length===0||!d||!o?.objectName)return u;let e=s(o.objectName,d,u);return Array.isArray(e)&&e.length===u.length?u.map((t,n)=>({...t,label:e[n]?.label??t.label})):u},[u,d,o?.objectName,s]),p=d&&o?.data?o.data[d]:void 0,m=/(^|[_-\s])(closed_)?(lost|failed?|cancell?ed|失败|流失|丢单|败)([_-\s]|$)/i,h=/(^|[_-\s])(closed_)?(won|success|成交|赢|完成)([_-\s]|$)/i,g=f.map(e=>{if(e.terminal)return e.terminal;let t=`${String(e.value??``)} ${String(e.label??``)}`;if(m.test(t))return`lost`;if(h.test(t))return`won`}),_=g.findIndex(e=>e===`lost`),v=_===-1?f:f.slice(0,_),y=_===-1?[]:f.slice(_),b=_===-1?g:g.slice(0,_),x=f.findIndex(e=>e.value===p);x<0&&(x=-1);let S=_!==-1&&x>=_;if(f.length===0)return(0,c.jsx)(`div`,{className:t,...l,children:(0,c.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2 border border-dashed rounded`,children:`record:path — no stages configured`})});let C=v.length-1;return(0,c.jsxs)(`div`,{className:(0,r.cn)(`w-full`,t),...l,children:[(0,c.jsxs)(`div`,{className:`hidden sm:flex w-full items-stretch gap-2`,role:`list`,"aria-label":e.aria?.label||`Record path`,children:[(0,c.jsx)(`div`,{className:`flex flex-1 items-stretch gap-1.5`,children:v.map((e,t)=>{let n=!S&&x>=0&&t<x,i=!S&&t===x,a=b[t]===`won`&&t===C;return(0,c.jsx)(`div`,{role:`listitem`,"aria-current":i?`step`:void 0,className:(0,r.cn)(`relative flex-1 min-w-0 px-4 py-2 text-xs font-medium text-center rounded-xl`,i&&`bg-primary text-primary-foreground shadow-sm`,n&&`bg-emerald-500/15 text-emerald-800 dark:text-emerald-200`,!i&&!n&&a&&`bg-emerald-500/10 text-emerald-700/85 dark:text-emerald-300/85`,!i&&!n&&!a&&`bg-muted text-muted-foreground`),children:(0,c.jsxs)(`span`,{className:`inline-flex items-center justify-center gap-1.5 truncate`,children:[n&&(0,c.jsx)(`span`,{"aria-hidden":!0,className:`text-emerald-600 dark:text-emerald-400 font-semibold`,children:`✓`}),a&&!i&&(0,c.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`🏆`}),e.label]})},`${e.value}-${t}`)})}),y.length>0&&(0,c.jsx)(`div`,{className:`flex items-stretch gap-1 pl-2 border-l border-border/40`,"aria-label":`Alternative terminal stages`,children:y.map((e,t)=>{let n=_+t===x;return(0,c.jsx)(`div`,{role:`listitem`,"aria-current":n?`step`:void 0,className:(0,r.cn)(`shrink-0 px-3 py-2 text-xs font-medium rounded-md border whitespace-nowrap`,n&&`bg-destructive text-destructive-foreground border-destructive shadow-sm ring-1 ring-destructive/40`,!n&&`bg-destructive/5 text-destructive/85 border-destructive/20`),children:(0,c.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,c.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`✗`}),e.label]})},`${e.value}-lost-${t}`)})})]}),(0,c.jsx)(`div`,{className:`flex sm:hidden w-full items-stretch gap-1 overflow-x-auto pb-1 -mx-1 px-1 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,role:`list`,"aria-label":e.aria?.label||`Record path`,children:f.map((e,t)=>{let n=g[t]===`lost`,i=!n&&!S&&x>=0&&t<x,a=t===x;return(0,c.jsx)(`div`,{role:`listitem`,"aria-current":a?`step`:void 0,className:(0,r.cn)(`shrink-0 px-3 py-1.5 rounded-full text-xs font-medium border whitespace-nowrap`,n&&a&&`bg-destructive text-destructive-foreground border-destructive shadow-sm`,n&&!a&&`bg-destructive/5 text-destructive/85 border-destructive/20`,!n&&a&&`bg-primary text-primary-foreground border-primary shadow-sm ring-1 ring-primary/40`,!n&&i&&`bg-emerald-500/15 text-emerald-800 dark:text-emerald-200 border-emerald-500/30`,!n&&!a&&!i&&`bg-background text-foreground/85 border-border/60`),children:(0,c.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[n&&(0,c.jsx)(`span`,{"aria-hidden":!0,className:`opacity-70`,children:`✗`}),!n&&i&&(0,c.jsx)(`span`,{"aria-hidden":!0,className:`text-emerald-600 dark:text-emerald-400 font-semibold`,children:`✓`}),e.label]})},`${e.value}-${t}-m`)})})]})},Xe=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},Ze=({schema:e={},className:t,...n})=>{let i=(0,a.useRecordContext)(),{designer:o}=Xe(n),s=(0,l.usePermissions)(),{language:d}=(0,u.useObjectTranslation)(),f=(0,a.useSafeFieldLabel)(),p=Array.isArray(e.actions)?e.actions:Array.isArray(e.properties?.actions)?e.properties.actions:[],m=Array.isArray(e.actionNames)?e.actionNames:Array.isArray(e.properties?.actionNames)?e.properties.actionNames:[],h=i?.objectName||``,g=m.length>0?m:Array.isArray(p)&&p.every(e=>typeof e==`string`)?p:[],_=g.length>0&&!!h,{item:v}=(0,a.useMetadataItem)(`object`,_?h:null),y=_?(()=>{let e=Array.isArray(v?.actions)?v.actions:[],t=new Map(e.map(e=>[e.name,e]));return g.map(e=>t.get(e)).filter(e=>!!e)})():Array.isArray(p)?p:[],b=Array.isArray(e.requiredPermissions)?e.requiredPermissions:[];if(b.length>0&&h&&!b.every(e=>s.can(h,e)))return(0,c.jsx)(`div`,{className:t,...o,role:`status`,"aria-live":`polite`,children:(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Insufficient permissions to view quick actions.`})});let x=e.location||`record_header`,{getActionsForLocation:S,executeAction:C}=(0,a.useActionEngine)({actions:y,context:{record:i?.data,recordId:i?.recordId,objectName:i?.objectName}}),w=y.length>0?S(x):[];if(w.length===0)return(0,c.jsx)(`div`,{className:t,...o,children:(0,c.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2 border border-dashed rounded`,children:`record:quick_actions — no actions configured`})});let T=e.align||`end`,E=T===`start`?`justify-start`:T===`center`?`justify-center`:`justify-end`;return(0,c.jsx)(`div`,{className:(0,r.cn)(`flex flex-wrap items-center gap-2`,x===`record_header`&&!e.inline&&`-mt-12 sm:-mt-14 mb-2 relative z-10`,E,t),role:`toolbar`,"aria-label":e.aria?.label||`Quick actions`,...o,children:w.map((t,n)=>(0,c.jsx)(Qe,{action:t,record:i?.data,variant:t.variant||e.variant||`default`,size:t.size||e.size||`sm`,label:(()=>{let e=(0,u.pickLocalized)(t.label,d)||t.name||`Action ${n+1}`;return t.name?f.actionLabel(h||void 0,t.name,e):e})(),onRun:async()=>{typeof t.onClick==`function`?await t.onClick():t.name&&await C(t.name)}},t.name||`qa-${n}`))})};function Qe({action:e,record:t,variant:o,size:s,label:l,onRun:u}){let[d,f]=n.default.useState(!1),p=n.default.useMemo(()=>({record:t||{}}),[t]),m=(0,a.toPredicateInput)(e.disabled),h=(0,a.useCondition)(typeof m==`string`?m:void 0,p);return(0,c.jsxs)(r.Button,{variant:o,size:s,disabled:(typeof m==`string`?h:m===!0)||d,onClick:async()=>{f(!0);try{await u()}finally{f(!1)}},children:[d&&(0,c.jsx)(i.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),l]})}var $e=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},et=new Set([`created`,`updated`,`assigned`,`shared`,`deleted`]),tt=({schema:e={},className:t,...r})=>{let{designer:i}=$e(r),o=(0,a.useRecordContext)(),s=Array.isArray(e.entries)?e.entries:Array.isArray(e.properties?.entries)?e.properties.entries:void 0,l=e.loading??e.properties?.loading,u=e.emptyText??e.properties?.emptyText,d=Number(e.limit??e.properties?.limit??50)||50,f=o?.objectName,p=o?.data?.id??o?.data?._id??o?.recordId,m=o?.dataSource,h=s===void 0&&!!m?.find&&!!f&&p!=null,[g,_]=n.default.useState(null),[v,y]=n.default.useState(!1);n.default.useEffect(()=>{if(!h)return;let e=!1;return y(!0),Promise.resolve(m.find(`sys_activity`,{$filter:{object_name:f,record_id:p},$orderby:{timestamp:`desc`},$top:Math.max(1,d)})).then(t=>{if(e)return;let n=(t?.data??t?.records??[]).filter(e=>et.has(e?.type)).map(e=>{let t=e.timestamp;return(!t||t===`NOW()`||Number.isNaN(Date.parse(t)))&&(t=e.created_at),{id:e.id,created_at:t,action:e.type,user_name:e.actor_name??null,user_avatar:e.actor_avatar_url??null,summary:e.summary??null}});_(n)}).catch(()=>{e||_([])}).finally(()=>{e||y(!1)}),()=>{e=!0}},[h,m,f,p,d]);let b=s??g??[],x=l??(h&&g===null?v||!0:!1);return(0,c.jsx)(`div`,{className:t,...i,children:(0,c.jsx)(le,{entries:b,loading:x,emptyText:u})})},nt=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}},rt=e=>e.replace(/[_-]+/g,` `).replace(/\b\w/g,e=>e.toUpperCase()).trim(),it=(e,t)=>t&&e?.[t]!=null&&e[t]!==``?String(e[t]):e?.name||e?.title||e?.subject||e?.label||e?.email||e?.username||e?.code||e?.slug||e?.provider_id||e?.user_agent||e?.ip_address||e?.id||`—`,at=({schema:e={},className:t,...o})=>{let l=(0,a.useRecordContext)(),u=(0,a.useSafeFieldLabel)(),{t:d}=D(),{designer:f}=nt(o),p=(0,s.useParams)().appName,m=Array.isArray(e.entries)?e.entries:Array.isArray(e.properties?.entries)?e.properties.entries:[],h=l?.recordId,g=l?.dataSource,[_,v]=n.default.useState({}),y=n.default.useRef(null),[b,x]=n.default.useState(!1),S=n.default.useRef(!0);n.default.useEffect(()=>(S.current=!0,()=>{S.current=!1}),[]);let C=n.default.useRef(``);n.default.useEffect(()=>{if(b)return;let e=y.current;if(!e||typeof IntersectionObserver>`u`){x(!0);return}let t=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&x(!0)},{rootMargin:`200px`});return t.observe(e),()=>t.disconnect()},[b]);let w=JSON.stringify(m.map(e=>`${e.objectName}:${e.relationshipField}:${e.limit??3}`));if(n.default.useEffect(()=>{if(!b||!g?.find||!h||m.length===0)return;let e=`${h}::${w}`;if(C.current===e)return;C.current=e,v(e=>{let t={...e};for(let n of m)t[n.objectName]={loading:!0,total:0,items:e[n.objectName]?.items||[]};return t});let t=async e=>{let t=e.objectName;try{let n=await g.find(e.objectName,{$filter:{[e.relationshipField]:h},$top:e.limit??3,$count:!0});if(!S.current)return;let r=Array.isArray(n)?n:n?.data||[],i=typeof n?.total==`number`?n.total:typeof n?.count==`number`?n.count:r.length;v(e=>({...e,[t]:{loading:!1,total:i,items:r}}))}catch(e){if(!S.current)return;v(n=>({...n,[t]:{loading:!1,total:0,items:[],error:String(e?.message||e)}}))}},n=[...m],r=async()=>{for(;S.current;){let e=n.shift();if(!e)return;await t(e)}},i=Array.from({length:Math.min(3,n.length)},()=>r());Promise.all(i)},[b,g,h,w]),m.length===0)return null;let T=e.hideEmpty!==!1,[E,O]=n.default.useState(!1),k=new Set(m.filter(e=>{let t=_[e.objectName];return T&&t&&!t.loading&&!t.error&&t.total===0}).map(e=>e.objectName)),A=m.filter(e=>E||!k.has(e.objectName)),j=m.filter(e=>k.has(e.objectName)).map(e=>e.title||(u?.objectLabel?u.objectLabel({name:e.objectName,label:rt(e.objectName)}):rt(e.objectName)));return(0,c.jsxs)(`div`,{ref:y,className:(0,r.cn)(`flex flex-col gap-3`,e.className,t),...f,children:[A.map(e=>{let t=e.objectName,n=_[t]||{loading:!0,total:0,items:[]};return(0,c.jsxs)(r.Card,{className:`overflow-hidden`,children:[(0,c.jsxs)(r.CardHeader,{className:`flex flex-row items-center justify-between gap-2 py-3 px-4 space-y-0 border-b`,children:[(0,c.jsx)(r.CardTitle,{className:`text-sm font-semibold tracking-tight truncate`,children:e.title||(u?.objectLabel?u.objectLabel({name:e.objectName,label:rt(e.objectName)}):rt(e.objectName))}),(0,c.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[!n.loading&&(0,c.jsx)(r.Badge,{variant:`secondary`,className:`tabular-nums`,children:n.total}),p&&h&&(0,c.jsx)(s.Link,{to:`/apps/${p}/${e.objectName}?filter%5B${e.relationshipField}%5D=${encodeURIComponent(String(h))}`,className:`text-[11px] font-medium text-muted-foreground hover:text-foreground transition-colors`,title:d(`detail.viewAll`,{defaultValue:`View all`}),children:d(`detail.viewAll`,{defaultValue:`View all`})})]})]}),(0,c.jsx)(r.CardContent,{className:`p-0`,children:n.loading?(0,c.jsxs)(`div`,{className:`space-y-1.5 p-3`,children:[(0,c.jsx)(r.Skeleton,{className:`h-3.5 w-4/5`}),(0,c.jsx)(r.Skeleton,{className:`h-3.5 w-3/5`}),(0,c.jsx)(r.Skeleton,{className:`h-3.5 w-2/3`})]}):n.items.length===0?(0,c.jsx)(`p`,{className:`px-4 py-3 text-xs text-muted-foreground`,children:d(`detail.noRecords`)}):(0,c.jsx)(`ul`,{className:`divide-y`,children:n.items.map(t=>{let n=t.id||t._id,r=it(t,e.displayField),a=n?`../${e.objectName}/record/${encodeURIComponent(String(n))}`:void 0;return(0,c.jsx)(`li`,{className:`px-4 py-2`,children:a?(0,c.jsxs)(s.Link,{to:a,className:`group flex items-center justify-between gap-2 text-xs hover:text-foreground text-muted-foreground transition-colors`,children:[(0,c.jsx)(`span`,{className:`truncate`,children:r}),(0,c.jsx)(i.ChevronRight,{className:`h-3 w-3 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity`})]}):(0,c.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:r})},String(n||r))})})})]},t)}),!E&&j.length>0&&(0,c.jsxs)(`button`,{type:`button`,onClick:()=>O(!0),className:`self-start inline-flex items-center gap-1.5 text-[11px] text-muted-foreground hover:text-foreground transition-colors px-2.5 py-1 rounded-md border border-dashed border-border/60 hover:border-border bg-background`,title:j.join(` · `),children:[(0,c.jsx)(`span`,{children:d(`detail.showEmptyRelated`,{defaultValue:`+ {{count}} empty`,count:j.length})}),(0,c.jsxs)(`span`,{className:`truncate max-w-[180px] text-muted-foreground/70`,children:[`(`,j.join(` · `),`)`]})]})]})},ot={info:{wrap:`border-blue-300/60 bg-blue-50 text-blue-900 dark:border-blue-700/40 dark:bg-blue-950/30 dark:text-blue-100 [&>svg]:text-blue-600 dark:[&>svg]:text-blue-300`,icon:`Info`},warning:{wrap:`border-amber-300/60 bg-amber-50 text-amber-900 dark:border-amber-700/40 dark:bg-amber-950/30 dark:text-amber-100 [&>svg]:text-amber-600 dark:[&>svg]:text-amber-300`,icon:`AlertTriangle`},error:{wrap:`border-destructive/60 bg-destructive/10 text-destructive dark:bg-destructive/20 [&>svg]:text-destructive`,icon:`AlertCircle`},success:{wrap:`border-emerald-300/60 bg-emerald-50 text-emerald-900 dark:border-emerald-700/40 dark:bg-emerald-950/30 dark:text-emerald-100 [&>svg]:text-emerald-600 dark:[&>svg]:text-emerald-300`,icon:`CheckCircle2`}};function st(e){let t=e?.properties??{};return{...e,...t}}var ct=({schema:e={},className:t})=>{let i=st(e),o=(0,a.useRecordContext)(),s=o?.data,l=o?.objectName||``,d=o?.recordId??s?.id,{language:f}=(0,u.useObjectTranslation)(),p=(0,u.pickLocalized)(i.title,f),m=(0,u.pickLocalized)(i.body,f),h=(0,u.pickLocalized)(i.action?.label,f),g=[`info`,`warning`,`error`,`success`].includes(i.severity)?i.severity:`info`,_=ot[g],v=i.icon||_.icon,y=(0,a.toPredicateInput)(i.visible),b=(0,a.useCondition)(y,{record:s}),x=n.useMemo(()=>{if(!i.dismissible)return null;let e=i.dismissKey||(0,u.pickLocalized)(i.title,`en`)||g;return`os.record-alert:${l}:${d??`_`}:${e}`},[i.dismissible,i.dismissKey,i.title,g,l,d]),[S,C]=n.useState(()=>{if(!x||typeof window>`u`)return!1;try{return window.localStorage.getItem(x)===`1`}catch{return!1}}),w=i.action?.actionName,{item:T}=(0,a.useMetadataItem)(`object`,w&&l?l:null),E=n.useMemo(()=>{if(!(!w||!T?.actions))return T.actions.find(e=>e.name===w)},[w,T]),{executeAction:D}=(0,a.useActionEngine)({actions:n.useMemo(()=>E?[E]:[],[E]),context:{record:s,recordId:d,objectName:l}});return S||!s||Object.keys(s).length===0||y!==void 0&&!b?null:(0,c.jsxs)(r.Alert,{className:(0,r.cn)(`relative pr-12`,_.wrap,t),role:g===`error`?`alert`:`status`,"aria-live":g===`error`?`assertive`:`polite`,children:[(0,c.jsx)(r.LazyIcon,{name:v,className:`h-4 w-4`,"aria-hidden":`true`}),p?(0,c.jsx)(r.AlertTitle,{children:p}):null,m||E?(0,c.jsxs)(r.AlertDescription,{children:[m?(0,c.jsx)(`p`,{className:`mb-2 last:mb-0`,children:m}):null,E?(0,c.jsx)(r.Button,{size:`sm`,variant:i.action?.variant||(g===`error`?`destructive`:`default`),onClick:()=>{E?.name&&D(E.name)},children:h||E.label||E.name}):null]}):null,i.dismissible?(0,c.jsx)(`button`,{type:`button`,onClick:()=>{if(C(!0),x)try{window.localStorage.setItem(x,`1`)}catch{}},"aria-label":`Dismiss`,className:`absolute right-3 top-3 inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground/80 hover:bg-foreground/5 hover:text-foreground focus:outline-none focus:ring-2 focus:ring-ring`,children:(0,c.jsx)(r.LazyIcon,{name:`X`,className:`h-4 w-4`,"aria-hidden":`true`})}):null]})},lt=e=>{if(e==null)return`—`;if(typeof e==`string`)return e.length>0?e:`""`;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e)}catch{return String(e)}},ut=e=>{if(typeof e!=`string`||e.length===0)return null;let t=/\d{4}-\d{2}-\d{2}[ T]/.test(e)?e.replace(` `,`T`):e,n=new Date(t);if(Number.isNaN(n.getTime()))return null;try{return n.toLocaleString()}catch{return n.toISOString()}},dt=({open:e,conflict:t,onReload:n,onOverwrite:a,onCancel:o,busy:s=!1})=>{let{t:l}=D(),u=t?.label||t?.field||``,d=t?lt(t.pendingValue):``,f=t?lt(t.currentValue):``,p=t?.currentRecord??{},m=(()=>{let e=[p.updated_by_name,p.updated_by_label];for(let t of e)if(typeof t==`string`&&t.length>0)return t;let t=p.updated_by;return typeof t!=`string`||t.length===0||t.length>=16&&!/\s/.test(t)&&/^[A-Za-z0-9_-]+$/.test(t)?null:t})(),h=ut(p.updated_at??t?.currentVersion),[g,_]=l(`detail.concurrentUpdateDescription`,{field:`{{field}}`}).split(`{{field}}`);return(0,c.jsx)(r.AlertDialog,{open:e,onOpenChange:e=>{!e&&!s&&o()},children:(0,c.jsxs)(r.AlertDialogContent,{className:`max-w-lg`,children:[(0,c.jsx)(r.AlertDialogHeader,{children:(0,c.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,c.jsx)(`span`,{className:`inline-flex h-9 w-9 flex-none items-center justify-center rounded-full bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-300`,"aria-hidden":`true`,children:(0,c.jsx)(i.AlertTriangle,{className:`h-5 w-5`})}),(0,c.jsxs)(`div`,{className:`flex-1`,children:[(0,c.jsx)(r.AlertDialogTitle,{children:l(`detail.concurrentUpdateTitle`)}),(0,c.jsxs)(r.AlertDialogDescription,{className:`mt-1`,children:[g,(0,c.jsx)(`strong`,{className:`font-semibold`,children:u}),_]})]})]})}),(0,c.jsxs)(`div`,{className:`space-y-2 text-sm`,children:[(0,c.jsxs)(`div`,{className:`rounded-md border border-amber-200/70 bg-amber-50/60 p-3 dark:border-amber-500/30 dark:bg-amber-500/10`,children:[(0,c.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-amber-800 dark:text-amber-300`,children:l(`detail.concurrentUpdateYourEdit`)}),(0,c.jsx)(`div`,{className:`mt-1 break-all font-mono text-foreground`,children:d})]}),(0,c.jsxs)(`div`,{className:`rounded-md border border-sky-200/70 bg-sky-50/60 p-3 dark:border-sky-500/30 dark:bg-sky-500/10`,children:[(0,c.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,c.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-sky-800 dark:text-sky-300`,children:l(`detail.concurrentUpdateCurrentValue`)}),(m||h)&&(0,c.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[m&&(0,c.jsx)(`span`,{children:l(`detail.concurrentUpdateUpdatedBy`,{name:m})}),m&&h&&(0,c.jsx)(`span`,{children:` · `}),h&&(0,c.jsx)(`span`,{children:l(`detail.concurrentUpdateUpdatedAt`,{when:h})})]})]}),(0,c.jsx)(`div`,{className:`mt-1 break-all font-mono text-foreground`,children:f})]})]}),(0,c.jsxs)(r.AlertDialogFooter,{className:`gap-2 sm:gap-2`,children:[(0,c.jsx)(`button`,{type:`button`,disabled:s,onClick:o,className:(0,r.cn)((0,r.buttonVariants)({variant:`ghost`}),`mt-2 sm:mt-0`),children:l(`detail.concurrentUpdateCancel`)}),(0,c.jsx)(`button`,{type:`button`,disabled:s,onClick:a,className:(0,r.cn)((0,r.buttonVariants)({variant:`outline`}),`mt-2 sm:mt-0 text-destructive border-destructive/40 hover:bg-destructive/10 hover:text-destructive`),children:l(`detail.concurrentUpdateOverwrite`)}),(0,c.jsx)(`button`,{type:`button`,disabled:s,onClick:n,autoFocus:!0,className:(0,r.cn)((0,r.buttonVariants)({variant:`default`}),`mt-2 sm:mt-0`),children:l(`detail.concurrentUpdateReload`)})]})]})})};function ft(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.code===`CONCURRENT_UPDATE`||t.name===`ConcurrentUpdateError`}function pt(e){let t=e?.message||e?.error||String(e??`Save failed`);return String(t).replace(/^\[[^\]]+\]\s*/,``).replace(/^[A-Z][A-Z0-9_]+:\s*/,``)}async function mt(e,t,n,r,i){if(typeof e?.update==`function`)await e.update(t,n,r,i);else if(typeof e?.updateOne==`function`)await e.updateOne(t,n,r,i);else if(typeof e?.patch==`function`)await e.patch(t,n,r,i);else throw Error(`[InlineEditSaveBar] DataSource exposes no update/updateOne/patch method; cannot persist inline edit`)}var ht=({dataSource:e,objectName:t,recordId:o,data:s,refresh:l,fieldLabelFor:u,onFieldSave:d,locked:f=!1,lockedHint:p,className:m})=>{let{t:h}=D(),g=(0,a.useInlineEdit)(),[_,v]=n.useState(null),[y,b]=n.useState(!1),x=!!e&&!!t&&o!=null,S=n.useCallback((e,t)=>{let n=Object.keys(e),r=t?.currentRecord??null;if(n.length===1){let i=n[0];return{field:i,label:u?.(i),pendingValue:e[i],currentValue:r?r[i]:void 0,currentVersion:t?.currentVersion,currentRecord:r}}let i=r?Object.fromEntries(n.map(e=>[e,r[e]])):void 0;return{field:n.join(`, `),label:h(`detail.concurrentUpdateRecordLabel`,{defaultValue:`this record`}),pendingValue:e,currentValue:i,currentVersion:t?.currentVersion,currentRecord:r}},[u,h]),C=n.useCallback(async()=>{if(!g)return;let n=g.draft,r=Object.entries(n);if(r.length===0){g.reset();return}g.setSaving(!0),g.setError(null);try{if(d)for(let[e,t]of r)await d(e,t);else if(x){let r=typeof s?.updated_at==`string`?s.updated_at:void 0;await mt(e,t,o,n,r?{ifMatch:r}:void 0),await l?.()}g.reset()}catch(e){ft(e)&&x?v(S(n,e)):g.setError(pt(e))}finally{g.setSaving(!1)}},[g,d,x,s,e,t,o,l,S]),w=n.useCallback(()=>{v(null),b(!1)},[]),T=n.useCallback(async()=>{b(!0);try{await l?.()}finally{g?.reset(),w()}},[l,g,w]),E=n.useCallback(async()=>{if(!_||!x){w();return}b(!0);try{await mt(e,t,o,g?.draft??{},_.currentVersion?{ifMatch:_.currentVersion}:void 0),await l?.(),g?.reset()}catch(e){g?.setError(pt(e))}finally{w()}},[_,x,g,e,t,o,l,w]),O=!!g?.editing,k=!!g?.saving,A=g?.cancel,j=!!_;return n.useEffect(()=>{if(!O)return;let e=e=>{if(e.key===`Enter`&&(e.metaKey||e.ctrlKey)){if(k||f||j)return;e.preventDefault(),C();return}if(e.key===`Escape`){if(e.defaultPrevented||k||j||document.querySelector(`[data-radix-popper-content-wrapper], [role="dialog"][data-state="open"], [role="alertdialog"][data-state="open"]`))return;e.preventDefault(),A?.()}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[O,k,f,j,C,A]),!g||!g.editing?null:(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(`div`,{className:(0,r.cn)(`sticky bottom-0 z-30 mt-4 flex flex-wrap items-center justify-end gap-2 rounded-md border bg-background/95 px-3 py-2 shadow-sm backdrop-blur supports-[backdrop-filter]:bg-background/80`,m),role:`region`,"aria-label":h(`detail.editFieldsInline`),children:[g.error&&(0,c.jsx)(`div`,{role:`alert`,className:`mr-auto max-w-md rounded-md border border-destructive/20 bg-destructive/10 px-2 py-1 text-xs text-destructive`,children:g.error}),(0,c.jsxs)(r.Button,{variant:`ghost`,size:`sm`,onClick:g.cancel,disabled:g.saving,className:`gap-2`,children:[(0,c.jsx)(i.X,{className:`h-4 w-4`}),(0,c.jsx)(`span`,{children:h(`detail.cancel`)})]}),(0,c.jsxs)(r.Button,{variant:`default`,size:`sm`,onClick:C,disabled:g.saving||f,className:`gap-2`,title:f?p:void 0,children:[g.saving?(0,c.jsx)(i.Loader2,{className:`h-4 w-4 animate-spin`}):(0,c.jsx)(i.Check,{className:`h-4 w-4`}),(0,c.jsx)(`span`,{children:g.saving?h(`detail.saving`):h(`detail.save`)})]})]}),(0,c.jsx)(dt,{open:!!_,conflict:_,busy:y,onCancel:w,onReload:T,onOverwrite:E})]})},gt=new Set([`id`,`_id`,`__v`,`created_at`,`updated_at`,`createdAt`,`updatedAt`,`created_by`,`updated_by`,`organization_id`,`tenant_id`,`owner_id`,`deleted_at`,`is_deleted`]),_t=480,vt=95;function yt({open:e,onClose:t,title:i,record:o,objectName:s,recordId:l,dataSource:u,objectSchema:d,width:f=`min(960px, 60vw)`,columns:p=2,systemFields:m=gt,onFieldSave:h,onDelete:g,resizable:_=!0,fullPageHref:v}){let{t:y}=D(),b=`objectui.drawerWidth.${s}`,[x,S]=n.default.useState(()=>{if(typeof window>`u`||!_)return null;try{let e=window.localStorage.getItem(b);if(e){let t=parseInt(e,10);if(Number.isFinite(t)&&t>=_t)return t}}catch{}return null}),C=n.default.useMemo(()=>_&&x!=null?`${x}px`:typeof f==`number`?`${f}px`:f,[_,x,f]),w=C?{width:C,maxWidth:C}:void 0,T=n.default.useRef(null),E=n.default.useCallback(e=>{if(!_)return;e.preventDefault();let t=x??(typeof window<`u`?Math.min(window.innerWidth*.6,960):720);T.current={startX:e.clientX,startWidth:t};let n=e=>{let t=T.current;if(!t)return;let n=t.startX-e.clientX,r=typeof window<`u`?window.innerWidth*vt/100:1600,i=Math.min(r,Math.max(_t,t.startWidth+n));S(Math.round(i))},r=()=>{T.current,T.current=null,window.removeEventListener(`pointermove`,n),window.removeEventListener(`pointerup`,r),window.removeEventListener(`pointercancel`,r);try{S(e=>(e!=null&&window.localStorage.setItem(b,String(e)),e))}catch{}};window.addEventListener(`pointermove`,n),window.addEventListener(`pointerup`,r),window.addEventListener(`pointercancel`,r)},[_,x,b]),O=d?.fields??{},k=(Object.keys(O).length?Object.keys(O):Object.keys(o)).filter(e=>!m.has(e)&&!e.startsWith(`__`)).filter(e=>e in o).filter(e=>!O[e]?.hidden).map(e=>{let t=O[e]||{},n=t.type===`lookup`||t.type===`master_detail`||t.type===`reference`;return{name:e,label:t.label,type:t.type,readonly:!!t.readonly||n,options:t.options,currency:t.currency,precision:t.precision,scale:t.scale,format:t.format,reference_to:t.reference_to??t.reference??t.referenceTo??t.target,reference_field:t.reference_field??t.referenceField,required:t.required,validation:t.validation,placeholder:t.placeholder,description:t.description}});return(0,c.jsx)(r.Sheet,{open:e,onOpenChange:e=>{e||t()},children:(0,c.jsxs)(r.SheetContent,{side:`right`,className:`w-full overflow-y-auto p-0 sm:!max-w-none`,style:w,onOpenAutoFocus:e=>e.preventDefault(),children:[_&&(0,c.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize drawer`,onPointerDown:E,className:`hidden sm:block absolute left-0 top-0 h-full w-1.5 cursor-col-resize select-none bg-transparent hover:bg-primary/30 active:bg-primary/50 transition-colors z-10`}),(0,c.jsx)(r.SheetHeader,{className:`sr-only`,children:(0,c.jsx)(r.SheetTitle,{children:i})}),(0,c.jsx)(`div`,{className:`px-6 pt-6 pb-6`,children:(0,c.jsxs)(a.InlineEditProvider,{canEdit:!!h,children:[(0,c.jsx)(X,{dataSource:u,inlineEdit:!!h,schema:{type:`detail-view`,objectName:s,resourceId:String(l),data:o,showDelete:!!g,columns:p,fields:k,actions:v?[{type:`action:bar`,location:`record_header`,systemActions:[{name:`sys_open_new_tab`,label:y(`detail.openInNewTab`),icon:`external-link`,type:`script`,onClick:()=>window.open(v,`_blank`,`noopener`)}]}]:void 0},onDelete:g?async()=>{try{await g(),t()}catch(e){console.error(`[RecordDetailDrawer] delete failed:`,e)}}:void 0}),(0,c.jsx)(ht,{onFieldSave:h?async(e,t)=>{try{await h(e,t)}catch(e){throw console.error(`[RecordDetailDrawer] inline field save failed:`,e),e}}:void 0})]})})]})})}function bt(e,t){if(typeof window>`u`)return null;let n=window.location.pathname,r=`/${e}`,i=n.indexOf(r);return`${i>=0?n.slice(0,i):n.replace(/\/$/,``)}/${e}/record/${encodeURIComponent(String(t))}`}var xt=({objectName:e,relationshipField:t,fields:a,onCreateRecord:o,onLinkRecord:s,onSearch:l,existingRecords:u=[],className:d})=>{let[f,p]=n.useState(!1),[m,h]=n.useState(`create`),[g,_]=n.useState({}),[v,y]=n.useState(``),[b,x]=n.useState(u),[S,C]=n.useState(!1),[w,T]=n.useState(!1),E=n.useMemo(()=>{if(!v.trim())return b;let e=v.toLowerCase();return b.filter(t=>t.label.toLowerCase().includes(e)||t.description?.toLowerCase().includes(e))},[v,b]),D=n.useCallback(async e=>{if(y(e),l&&e.trim().length>=2){T(!0);try{let t=await l(e);x(t)}finally{T(!1)}}},[l]),O=n.useCallback((e,t)=>{_(n=>({...n,[e]:t}))},[]),k=n.useCallback(async()=>{if(o){C(!0);try{await o({...g,[t]:!0}),_({}),p(!1)}finally{C(!1)}}},[o,g,t]),A=n.useCallback(async e=>{if(s){C(!0);try{await s(e),y(``),p(!1)}finally{C(!1)}}},[s]),j=n.useMemo(()=>a.filter(e=>e.required).every(e=>g[e.name]?.toString().trim()),[a,g]);return f?(0,c.jsxs)(r.Card,{className:(0,r.cn)(``,d),children:[(0,c.jsx)(r.CardHeader,{className:`pb-3`,children:(0,c.jsxs)(r.CardTitle,{className:`flex items-center justify-between text-sm`,children:[(0,c.jsxs)(`span`,{children:[m===`create`?`Create`:`Link`,` `,e]}),(0,c.jsx)(r.Button,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>p(!1),children:(0,c.jsx)(i.X,{className:`h-3.5 w-3.5`})})]})}),(0,c.jsx)(r.CardContent,{children:(0,c.jsxs)(r.Tabs,{value:m,onValueChange:h,children:[(0,c.jsxs)(r.TabsList,{className:`mb-3 w-full`,children:[o&&(0,c.jsxs)(r.TabsTrigger,{value:`create`,className:`flex-1 gap-1.5`,children:[(0,c.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),`Create New`]}),s&&(0,c.jsxs)(r.TabsTrigger,{value:`link`,className:`flex-1 gap-1.5`,children:[(0,c.jsx)(i.Link,{className:`h-3.5 w-3.5`}),`Link Existing`]})]}),o&&(0,c.jsxs)(r.TabsContent,{value:`create`,className:`space-y-3 mt-0`,children:[a.map(e=>(0,c.jsxs)(`div`,{children:[(0,c.jsxs)(`label`,{className:`text-xs font-medium text-muted-foreground mb-1 block`,children:[e.label,e.required&&(0,c.jsx)(`span`,{className:`text-destructive ml-0.5`,children:`*`})]}),(0,c.jsx)(r.Input,{type:e.type===`number`?`number`:e.type===`date`?`date`:`text`,placeholder:e.placeholder||`Enter ${e.label.toLowerCase()}`,value:g[e.name]||``,onChange:t=>O(e.name,t.target.value),className:`h-8 text-sm`})]},e.name)),(0,c.jsxs)(`div`,{className:`flex justify-end gap-2 pt-1`,children:[(0,c.jsx)(r.Button,{variant:`ghost`,size:`sm`,onClick:()=>p(!1),children:`Cancel`}),(0,c.jsxs)(r.Button,{size:`sm`,onClick:k,disabled:!j||S,className:`gap-1.5`,children:[S&&(0,c.jsx)(i.Loader2,{className:`h-3.5 w-3.5 animate-spin`}),`Create`]})]})]}),s&&(0,c.jsxs)(r.TabsContent,{value:`link`,className:`space-y-3 mt-0`,children:[(0,c.jsxs)(`div`,{className:`relative`,children:[(0,c.jsx)(i.Search,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,c.jsx)(r.Input,{placeholder:`Search ${e}…`,value:v,onChange:e=>D(e.target.value),className:`h-8 text-sm pl-8`})]}),(0,c.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:w?(0,c.jsxs)(`div`,{className:`flex items-center justify-center py-4 text-sm text-muted-foreground`,children:[(0,c.jsx)(i.Loader2,{className:`h-4 w-4 animate-spin mr-2`}),`Searching…`]}):E.length===0?(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:v?`No records found`:`Type to search records`}):E.map(e=>(0,c.jsxs)(`button`,{type:`button`,className:`w-full text-left px-3 py-2 rounded-md hover:bg-accent text-sm transition-colors`,onClick:()=>A(e.id),disabled:S,children:[(0,c.jsx)(`span`,{className:`font-medium`,children:e.label}),e.description&&(0,c.jsx)(`span`,{className:`block text-xs text-muted-foreground mt-0.5`,children:e.description})]},e.id))})]})]})})]}):(0,c.jsxs)(`div`,{className:(0,r.cn)(`flex gap-2`,d),children:[o&&(0,c.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>{h(`create`),p(!0)},className:`gap-1.5`,children:[(0,c.jsx)(i.Plus,{className:`h-3.5 w-3.5`}),`New `,e]}),s&&(0,c.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>{h(`link`),p(!0)},className:`gap-1.5`,children:[(0,c.jsx)(i.Link,{className:`h-3.5 w-3.5`}),`Link Existing`]})]})};function St(e,t){if(e==null)return[`(empty)`];switch(t){case`json`:try{let t=typeof e==`string`?JSON.parse(e):e;return JSON.stringify(t,null,2).split(`
3
3
  `)}catch{return String(e).split(`
4
4
  `)}case`boolean`:return[String(!!e)];case`number`:return[String(e)];case`date`:try{return[new Date(e).toLocaleString()]}catch{return[String(e)]}default:return String(e).split(`
@@ -1 +1 @@
1
- {"version":3,"file":"record-details.d.ts","sourceRoot":"","sources":["../../src/renderers/record-details.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAepE,MAAM,WAAW,0BAA0B;IACzC,MAAM,CAAC,EAAE,2BAA2B,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB;AAED,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,0BAA0B,CAuOtE,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"record-details.d.ts","sourceRoot":"","sources":["../../src/renderers/record-details.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAepE,MAAM,WAAW,0BAA0B;IACzC,MAAM,CAAC,EAAE,2BAA2B,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB;AAED,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,0BAA0B,CA8OtE,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useDetailTranslation.d.ts","sourceRoot":"","sources":["../src/useDetailTranslation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,OAAO,EAAE,MAAM;aAQE,MAAM,YAAY,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;EA0B3D;AAED;;;GAGG;AACH,eAAO,MAAM,2BAA2B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA+I9D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,oBAAoB;aArLd,MAAM,YAAY,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;CAwL3D,CAAC"}
1
+ {"version":3,"file":"useDetailTranslation.d.ts","sourceRoot":"","sources":["../src/useDetailTranslation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,OAAO,EAAE,MAAM;aAQE,MAAM,YAAY,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;EA0B3D;AAED;;;GAGG;AACH,eAAO,MAAM,2BAA2B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAuJ9D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,oBAAoB;aA7Ld,MAAM,YAAY,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;CAgM3D,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/plugin-detail",
3
- "version": "14.1.0",
3
+ "version": "16.0.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "DetailView plugin for Object UI - comprehensive detail page with sections, tabs, and related lists",
@@ -24,19 +24,19 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "@objectstack/spec": "^14.6.0",
27
+ "@objectstack/spec": "^15.1.1",
28
28
  "lucide-react": "^1.24.0",
29
- "@object-ui/i18n": "14.1.0"
29
+ "@object-ui/i18n": "16.0.0"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "react": "^18.0.0 || ^19.0.0",
33
33
  "react-dom": "^18.0.0 || ^19.0.0",
34
- "@object-ui/components": "^14.1.0",
35
- "@object-ui/core": "^14.1.0",
36
- "@object-ui/fields": "^14.1.0",
37
- "@object-ui/permissions": "^14.1.0",
38
- "@object-ui/react": "^14.1.0",
39
- "@object-ui/types": "^14.1.0"
34
+ "@object-ui/components": "^16.0.0",
35
+ "@object-ui/core": "^16.0.0",
36
+ "@object-ui/fields": "^16.0.0",
37
+ "@object-ui/permissions": "^16.0.0",
38
+ "@object-ui/react": "^16.0.0",
39
+ "@object-ui/types": "^16.0.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/react": "19.2.17",
@@ -46,11 +46,11 @@
46
46
  "vite": "^8.1.4",
47
47
  "vite-plugin-dts": "^5.0.3",
48
48
  "vitest": "^4.1.10",
49
- "@object-ui/components": "14.1.0",
50
- "@object-ui/core": "14.1.0",
51
- "@object-ui/fields": "14.1.0",
52
- "@object-ui/react": "14.1.0",
53
- "@object-ui/types": "14.1.0"
49
+ "@object-ui/components": "16.0.0",
50
+ "@object-ui/core": "16.0.0",
51
+ "@object-ui/fields": "16.0.0",
52
+ "@object-ui/react": "16.0.0",
53
+ "@object-ui/types": "16.0.0"
54
54
  },
55
55
  "keywords": [
56
56
  "objectui",