@nivaro/react 0.3.10 → 0.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useNivaroForm.js +1 -1
  3. package/dist/hooks/useSessionRecorder.js +1 -1
  4. package/dist/index.d.ts +34 -3
  5. package/dist/shared/components/CollectionBrowserView.js +1546 -1477
  6. package/dist/shared/components/ItemEditForm.js +4332 -4195
  7. package/dist/shared/components/PageRenderer.js +512 -465
  8. package/dist/shared/components/QueryStatStrip.js +74 -70
  9. package/dist/shared/components/ReportView.js +818 -827
  10. package/dist/shared/components/SheetHeaderBody.js +16 -14
  11. package/dist/shared/components/item-edit/CatalogPickerField.js +1029 -933
  12. package/dist/shared/components/item-edit/FieldRenderer.js +161 -156
  13. package/dist/shared/components/item-edit/FieldRow.js +20 -19
  14. package/dist/shared/components/item-edit/FilePickerField.js +52 -40
  15. package/dist/shared/components/item-edit/GroupSection.js +221 -221
  16. package/dist/shared/components/item-edit/InlineGridField.js +41 -41
  17. package/dist/shared/components/item-edit/InlineTableField.js +2249 -2238
  18. package/dist/shared/components/item-edit/M2MCombobox.js +46 -44
  19. package/dist/shared/components/item-edit/NestedRelationEditor.js +11 -11
  20. package/dist/shared/components/item-edit/QuickPicker.js +263 -216
  21. package/dist/shared/components/item-edit/RelationCombobox.js +285 -245
  22. package/dist/shared/components/item-edit/RichTextEditorImpl.js +42 -32
  23. package/dist/shared/components/item-edit/RowHistorySheet.js +130 -134
  24. package/dist/shared/components/item-edit/SummaryPanel.js +305 -279
  25. package/dist/shared/components/item-edit/helpers.js +133 -134
  26. package/dist/shared/components/item-edit/line-qty.js +57 -0
  27. package/dist/shared/components/item-edit/option-disambiguate.js +53 -0
  28. package/dist/shared/components/panels/AddendumLinesDiff.js +87 -90
  29. package/dist/shared/components/panels/CommentPanel.js +350 -315
  30. package/dist/shared/components/panels/ItemLockBanner.js +297 -230
  31. package/dist/shared/components/panels/PipelinePanel.js +719 -701
  32. package/dist/shared/components/queue/QueueQuickFilters.js +43 -41
  33. package/dist/shared/components/queue/QueueWorklist.js +1005 -935
  34. package/dist/shared/components/widgets/ReviewListWidget.js +99 -93
  35. package/dist/shared/lib/obligation-banner.js +14 -13
  36. package/dist/shared/lib/obligation-reason-text.js +13 -0
  37. package/dist/shared/lib/query-filter-seed.js +34 -11
  38. package/dist/shared/lib/sanitize-html.js +24 -15
  39. package/dist/shared/lib/sheet-def.js +38 -22
  40. package/dist/shared/lib/unique-options.js +10 -0
  41. package/dist/shared/lib/utils.js +57 -43
  42. package/dist/shared/lib/validation-rules.js +58 -34
  43. package/package.json +1 -1
@@ -1,81 +1,83 @@
1
- import { jsxs as c, jsx as n, Fragment as kt } from "react/jsx-runtime";
2
- import { useQueryClient as hr, useQuery as B, useQueries as wt } from "@tanstack/react-query";
3
- import { Search as Xe, Loader2 as ae, ChevronRight as Nt, Star as Ke, AlertTriangle as Ce, AlertCircle as xr, X as et, ChevronDown as gr } from "lucide-react";
4
- import { useState as re, useRef as Je, useMemo as P, useEffect as Se, Fragment as Re } from "react";
5
- import { createPortal as yr } from "react-dom";
6
- import { useNivaroClient as vt, useParentDraft as kr, useReimportHandler as wr } from "../../context.js";
7
- import { canOpenCatalogItem as Dt, openCatalogItem as Ht } from "../../lib/catalog-item-open.js";
8
- import { get as E, patch as Qt, del as Nr, post as Vt } from "../../lib/commands.js";
9
- import { evaluateBoolean as vr } from "../../lib/expression.js";
10
- import { useLiveRefetchInterval as _r } from "../../lib/live-queries.js";
11
- import { submissionLineErrors as Sr, normalizeIdent as qr } from "../../lib/submission-errors.js";
12
- import { titleCase as te, cn as V, matchesAllTokens as $r } from "../../lib/utils.js";
13
- import { ImportFromFileButton as jr } from "../import/ImportFromFileButton.js";
14
- import { applyDisplayTemplate as qe } from "./helpers.js";
15
- import { evalClientFormula as Ae } from "./InlineTableField.js";
16
- import { resolveM2MRelatedCollection as Fr } from "./M2MCombobox.js";
17
- import { useO2MStaging as Tr } from "./O2MStagingContext.js";
18
- import { RelationCombobox as Or } from "./RelationCombobox.js";
19
- const It = (m, x) => {
20
- let S = m;
21
- for (const q of x.split(".")) {
22
- if (S == null || typeof S != "object") return;
23
- S = S[q];
1
+ import { jsxs as c, jsx as n, Fragment as _t } from "react/jsx-runtime";
2
+ import { useQueryClient as Nr, useQuery as J, useQueries as St } from "@tanstack/react-query";
3
+ import { Search as st, Loader2 as oe, ChevronRight as qt, Star as Qe, AlertTriangle as Je, AlertCircle as Mt, X as at, ChevronDown as vr } from "lucide-react";
4
+ import { useState as Y, useRef as ze, useMemo as O, useEffect as je, Fragment as Ce } from "react";
5
+ import { createPortal as _r } from "react-dom";
6
+ import { useNivaroClient as $t, useParentDraft as Sr, useReimportHandler as qr } from "../../context.js";
7
+ import { canOpenCatalogItem as Zt, openCatalogItem as Gt } from "../../lib/catalog-item-open.js";
8
+ import { get as P, patch as Wt, del as $r, post as It } from "../../lib/commands.js";
9
+ import { evaluateBoolean as jr } from "../../lib/expression.js";
10
+ import { useLiveRefetchInterval as Fr } from "../../lib/live-queries.js";
11
+ import { submissionLineErrors as Tr, normalizeIdent as Or } from "../../lib/submission-errors.js";
12
+ import { titleCase as re, cn as z, matchesAllTokens as Pr } from "../../lib/utils.js";
13
+ import { ImportFromFileButton as Rr } from "../import/ImportFromFileButton.js";
14
+ import { Popover as Lr, PopoverAnchor as Er, PopoverContent as Ar } from "../ui/popover.js";
15
+ import { applyDisplayTemplate as Fe } from "./helpers.js";
16
+ import { evalClientFormula as Ke } from "./InlineTableField.js";
17
+ import { isIntegerFieldType as Cr, checkNumberEntry as Kr, mergePendingQtyRow as Jr } from "./line-qty.js";
18
+ import { resolveM2MRelatedCollection as Qr } from "./M2MCombobox.js";
19
+ import { useO2MStaging as zr } from "./O2MStagingContext.js";
20
+ import { RelationCombobox as Br } from "./RelationCombobox.js";
21
+ const Xt = (u, g) => {
22
+ let _ = u;
23
+ for (const q of g.split(".")) {
24
+ if (_ == null || typeof _ != "object") return;
25
+ _ = _[q];
24
26
  }
25
- return S;
27
+ return _;
26
28
  };
27
- async function tt(m, x, S) {
29
+ async function it(u, g, _) {
28
30
  const q = [];
29
31
  for (let l = 1; l <= 50; l++) {
30
- const h = await m.request(E(x, { ...S, limit: 1e3, page: l })).then((p) => p.data ?? []);
31
- if (q.push(...h), h.length < 1e3) break;
32
+ const x = await u.request(P(g, { ..._, limit: 1e3, page: l })).then((h) => h.data ?? []);
33
+ if (q.push(...x), x.length < 1e3) break;
32
34
  }
33
35
  return q;
34
36
  }
35
- function ze(m, x) {
36
- const S = {};
37
+ function Be(u, g) {
38
+ const _ = {};
37
39
  let q = !1;
38
- const l = (h) => {
39
- if (typeof h == "string" && h.startsWith("$parent.")) {
40
- const p = x == null ? void 0 : x[h.slice(8)];
41
- return p == null || p === "" ? (q = !0, h) : p;
40
+ const l = (x) => {
41
+ if (typeof x == "string" && x.startsWith("$parent.")) {
42
+ const h = g == null ? void 0 : g[x.slice(8)];
43
+ return h == null || h === "" ? (q = !0, x) : h;
42
44
  }
43
- return Array.isArray(h) ? h.map(l) : h && typeof h == "object" ? Object.fromEntries(Object.entries(h).map(([p, $]) => [p, l($)])) : h;
45
+ return Array.isArray(x) ? x.map(l) : x && typeof x == "object" ? Object.fromEntries(Object.entries(x).map(([h, $]) => [h, l($)])) : x;
44
46
  };
45
- for (const [h, p] of Object.entries(m ?? {}))
46
- if (typeof p == "string" && p.startsWith("$parent.")) {
47
- const $ = x == null ? void 0 : x[p.slice(8)];
47
+ for (const [x, h] of Object.entries(u ?? {}))
48
+ if (typeof h == "string" && h.startsWith("$parent.")) {
49
+ const $ = g == null ? void 0 : g[h.slice(8)];
48
50
  if ($ == null || $ === "") {
49
51
  q = !0;
50
52
  continue;
51
53
  }
52
- S[h] = { _eq: $ };
53
- } else p && typeof p == "object" ? S[h] = l(p) : S[h] = { _eq: p };
54
- return q ? null : S;
54
+ _[x] = { _eq: $ };
55
+ } else h && typeof h == "object" ? _[x] = l(h) : _[x] = { _eq: h };
56
+ return q ? null : _;
55
57
  }
56
- function Ut(m, x) {
57
- if (!m) return !0;
58
- for (const [S, q] of Object.entries(m)) {
59
- const l = x == null ? void 0 : x[S], h = l == null ? null : String(l), p = q && typeof q == "object" ? q : { _eq: q };
60
- for (const [$, f] of Object.entries(p))
58
+ function Yt(u, g) {
59
+ if (!u) return !0;
60
+ for (const [_, q] of Object.entries(u)) {
61
+ const l = g == null ? void 0 : g[_], x = l == null ? null : String(l), h = q && typeof q == "object" ? q : { _eq: q };
62
+ for (const [$, p] of Object.entries(h))
61
63
  switch ($) {
62
64
  case "_eq":
63
- if (h !== String(f)) return !1;
65
+ if (x !== String(p)) return !1;
64
66
  break;
65
67
  case "_neq":
66
- if (h === String(f)) return !1;
68
+ if (x === String(p)) return !1;
67
69
  break;
68
70
  case "_in":
69
- if (!Array.isArray(f) || !f.map(String).includes(h ?? "")) return !1;
71
+ if (!Array.isArray(p) || !p.map(String).includes(x ?? "")) return !1;
70
72
  break;
71
73
  case "_nin":
72
- if (Array.isArray(f) && f.map(String).includes(h ?? "")) return !1;
74
+ if (Array.isArray(p) && p.map(String).includes(x ?? "")) return !1;
73
75
  break;
74
76
  case "_null":
75
- if (h !== null) return !1;
77
+ if (x !== null) return !1;
76
78
  break;
77
79
  case "_nnull":
78
- if (h === null) return !1;
80
+ if (x === null) return !1;
79
81
  break;
80
82
  default:
81
83
  return !1;
@@ -83,440 +85,444 @@ function Ut(m, x) {
83
85
  }
84
86
  return !0;
85
87
  }
86
- const Lr = 2e3;
87
- function en({
88
- relatedCollection: m,
89
- manyField: x,
90
- parentId: S,
88
+ const Vr = 2e3;
89
+ function bn({
90
+ relatedCollection: u,
91
+ manyField: g,
92
+ parentId: _,
91
93
  parentCollection: q,
92
94
  config: l,
93
- readOnly: h = !1
95
+ readOnly: x = !1
94
96
  }) {
95
- var Kt, Jt;
96
- const p = vt(), $ = hr(), f = Tr(), R = kr(), Z = wr(), U = l.editable_fields ?? [], K = S === "new", D = l.qty_field ?? "quantity", [de, ne] = re(/* @__PURE__ */ new Set()), he = Je(!1), [J, xe] = re(""), [be, G] = re({}), [se, w] = re(/* @__PURE__ */ new Set()), { data: O = [], isPending: L } = B({
97
- queryKey: ["collection-relations", m],
98
- queryFn: () => p.request(E(`/collections/${m}`)).then((e) => {
97
+ var Vt, Dt, Ut;
98
+ const h = $t(), $ = Nr(), p = zr(), L = Sr(), Z = qr(), B = l.editable_fields ?? [], A = _ === "new", V = l.qty_field ?? "quantity", [ce, ne] = Y(/* @__PURE__ */ new Set()), ye = ze(!1), [C, ke] = Y(""), [pe, G] = Y({}), [se, v] = Y(/* @__PURE__ */ new Set()), [F, j] = Y({}), { data: D = [], isPending: K } = J({
99
+ queryKey: ["collection-relations", u],
100
+ queryFn: () => h.request(P(`/collections/${u}`)).then((e) => {
99
101
  var t;
100
102
  return ((t = e.data) == null ? void 0 : t.relations) ?? [];
101
103
  }),
102
104
  staleTime: 10 * 6e4
103
- }), b = P(
105
+ }), b = O(
104
106
  () => {
105
107
  var e;
106
- return ((e = O.find(
107
- (t) => t.many_collection === m && t.many_field === l.item_field && !t.junction_field
108
+ return ((e = D.find(
109
+ (t) => t.many_collection === u && t.many_field === l.item_field && !t.junction_field
108
110
  )) == null ? void 0 : e.one_collection) ?? null;
109
111
  },
110
- [O, m, l.item_field]
111
- ), { data: j } = B({
112
+ [D, u, l.item_field]
113
+ ), { data: me = [] } = J({
114
+ queryKey: ["field-config", u, null],
115
+ queryFn: () => h.request(P(`/field-config/${u}`)).then((e) => e.data ?? []),
116
+ staleTime: 6e4
117
+ }), X = ((Vt = me.find((e) => e.field === V)) == null ? void 0 : Vt.type) ?? null, { data: U } = J({
112
118
  queryKey: ["col-meta", b],
113
- queryFn: () => p.request(
114
- E(`/collections/${b}`)
119
+ queryFn: () => h.request(
120
+ P(`/collections/${b}`)
115
121
  ).then((e) => e.data),
116
122
  enabled: !!b,
117
123
  staleTime: 3e5
118
- }), F = j == null ? void 0 : j.display_template, T = P(() => {
124
+ }), H = U == null ? void 0 : U.display_template, R = O(() => {
119
125
  const e = l.section_by.split(".")[0];
120
- return ((j == null ? void 0 : j.relations) ?? []).find(
126
+ return ((U == null ? void 0 : U.relations) ?? []).find(
121
127
  (t) => t.one_collection === b && t.one_field === e && !!t.junction_field
122
128
  ) ?? null;
123
- }, [j, b, l.section_by]), z = (T == null ? void 0 : T.many_collection) ?? null, { data: ge = [] } = B({
124
- queryKey: ["collection-relations", z],
125
- queryFn: () => p.request(E(`/collections/${z}`)).then((e) => {
129
+ }, [U, b, l.section_by]), ue = (R == null ? void 0 : R.many_collection) ?? null, { data: Ve = [] } = J({
130
+ queryKey: ["collection-relations", ue],
131
+ queryFn: () => h.request(P(`/collections/${ue}`)).then((e) => {
126
132
  var t;
127
133
  return ((t = e.data) == null ? void 0 : t.relations) ?? [];
128
134
  }),
129
- enabled: !!z,
135
+ enabled: !!ue,
130
136
  staleTime: 10 * 6e4
131
- }), A = P(() => {
132
- if (!(T != null && T.many_field) || !z) return null;
133
- const e = String(T.junction_field), t = ge.find(
134
- (a) => a.many_collection === z && a.many_field === e
135
- ), r = Fr(t);
137
+ }), Q = O(() => {
138
+ if (!(R != null && R.many_field) || !ue) return null;
139
+ const e = String(R.junction_field), t = Ve.find(
140
+ (s) => s.many_collection === ue && s.many_field === e
141
+ ), r = Qr(t);
136
142
  return r ? {
137
- junction: z,
138
- fkToItem: T.many_field,
143
+ junction: ue,
144
+ fkToItem: R.many_field,
139
145
  fkToSection: e,
140
146
  target: r,
141
147
  labelPath: l.section_by.split(".").slice(1).join(".") || "id"
142
148
  } : null;
143
- }, [T, z, ge, l.section_by]), X = R == null ? void 0 : R.draft, { resolvedFilter: we, resolvedSectionFilter: ye, resolvedLinkFilter: ie, missingParents: ce } = P(() => {
149
+ }, [R, ue, Ve, l.section_by]), ee = L == null ? void 0 : L.draft, { resolvedFilter: Te, resolvedSectionFilter: he, resolvedLinkFilter: ae, missingParents: xe } = O(() => {
144
150
  const e = [], t = (o) => {
145
151
  if (typeof o == "string" && o.startsWith("$parent.")) {
146
- const s = o.slice(8), u = X == null ? void 0 : X[s];
147
- return u == null || u === "" ? (e.push(s), o) : u;
152
+ const i = o.slice(8), y = ee == null ? void 0 : ee[i];
153
+ return y == null || y === "" ? (e.push(i), o) : y;
148
154
  }
149
- return Array.isArray(o) ? o.map(t) : o && typeof o == "object" ? Object.fromEntries(Object.entries(o).map(([s, u]) => [s, t(u)])) : o;
150
- }, r = l.filter ? t(l.filter) : void 0, a = l.section_filter ? t(l.section_filter) : void 0, d = l.link_filter ? t(l.link_filter) : void 0;
155
+ return Array.isArray(o) ? o.map(t) : o && typeof o == "object" ? Object.fromEntries(Object.entries(o).map(([i, y]) => [i, t(y)])) : o;
156
+ }, r = l.filter ? t(l.filter) : void 0, s = l.section_filter ? t(l.section_filter) : void 0, m = l.link_filter ? t(l.link_filter) : void 0;
151
157
  return {
152
158
  resolvedFilter: r,
153
- resolvedSectionFilter: a,
154
- resolvedLinkFilter: d,
159
+ resolvedSectionFilter: s,
160
+ resolvedLinkFilter: m,
155
161
  missingParents: [...new Set(e)]
156
162
  };
157
- }, [l.filter, l.section_filter, l.link_filter, X]), je = P(() => {
158
- if (!T || !ye && !ie) return we;
163
+ }, [l.filter, l.section_filter, l.link_filter, ee]), Oe = O(() => {
164
+ if (!R || !he && !ae) return Te;
159
165
  const e = {
160
- ...ye ?? {},
161
- ...ie ? { _link: ie } : {}
162
- }, t = { [T.one_field]: { _some: e } };
163
- return we ? { _and: [we, t] } : t;
164
- }, [T, ye, ie, we]), ee = P(() => {
166
+ ...he ?? {},
167
+ ...ae ? { _link: ae } : {}
168
+ }, t = { [R.one_field]: { _some: e } };
169
+ return Te ? { _and: [Te, t] } : t;
170
+ }, [R, he, ae, Te]), a = O(() => {
165
171
  const e = /* @__PURE__ */ new Set(["id"]);
166
- j && !T && e.add(l.section_by);
167
- for (const t of [...(F ?? "").matchAll(/\{\{([\w.]+)\}\}/g)]) e.add(t[1]);
172
+ U && !R && e.add(l.section_by);
173
+ for (const t of [...(H ?? "").matchAll(/\{\{([\w.]+)\}\}/g)]) e.add(t[1]);
168
174
  for (const t of Object.values(l.copy_fields ?? {})) e.add(t);
169
175
  for (const t of l.columns ?? []) e.add(t.field);
170
176
  return [...e].join(",");
171
- }, [F, j, T, l.section_by, l.copy_fields, l.columns]), Be = JSON.stringify(je ?? null), { data: ke = [], isLoading: Fe } = B(
177
+ }, [H, U, R, l.section_by, l.copy_fields, l.columns]), w = JSON.stringify(Oe ?? null), { data: E = [], isLoading: ie } = J(
172
178
  {
173
- queryKey: ["catalog-picker", b, ee, Be],
174
- queryFn: () => p.request(
175
- E(`/items/${b}`, {
176
- limit: Lr,
177
- fields: ee,
178
- ...je ? { filter: JSON.stringify(je) } : {}
179
+ queryKey: ["catalog-picker", b, a, w],
180
+ queryFn: () => h.request(
181
+ P(`/items/${b}`, {
182
+ limit: Vr,
183
+ fields: a,
184
+ ...Oe ? { filter: JSON.stringify(Oe) } : {}
179
185
  })
180
186
  ).then((e) => e.data ?? []),
181
187
  // Wait for the catalog meta: a to-many section path both narrows this
182
188
  // read and must stay out of its `fields=`.
183
- enabled: !!b && !!j && ce.length === 0 && (!T || !!A),
189
+ enabled: !!b && !!U && xe.length === 0 && (!R || !!Q),
184
190
  staleTime: 6e4
185
191
  }
186
- ), i = JSON.stringify(ye ?? null), { data: y = [], isLoading: H } = B({
187
- queryKey: ["catalog-sections", A == null ? void 0 : A.target, A == null ? void 0 : A.labelPath, i],
192
+ ), te = JSON.stringify(he ?? null), { data: I = [], isLoading: M } = J({
193
+ queryKey: ["catalog-sections", Q == null ? void 0 : Q.target, Q == null ? void 0 : Q.labelPath, te],
188
194
  queryFn: async () => {
189
- const e = A;
190
- return (await tt(p, `/items/${e.target}`, {
195
+ const e = Q;
196
+ return (await it(h, `/items/${e.target}`, {
191
197
  fields: `id,${e.labelPath}`,
192
- ...ye ? { filter: JSON.stringify(ye) } : {}
198
+ ...he ? { filter: JSON.stringify(he) } : {}
193
199
  })).map((r) => ({
194
200
  id: String(r.id),
195
- name: String(It(r, e.labelPath) ?? "").trim()
201
+ name: String(Xt(r, e.labelPath) ?? "").trim()
196
202
  }));
197
203
  },
198
- enabled: !!A && ce.length === 0,
204
+ enabled: !!Q && xe.length === 0,
199
205
  staleTime: 6e4
200
- }), I = P(() => y.map((e) => e.id), [y]), { data: W = [], isLoading: le } = B({
206
+ }), W = O(() => I.map((e) => e.id), [I]), { data: we = [], isLoading: Ne } = J({
201
207
  queryKey: [
202
208
  "catalog-section-links",
203
- A == null ? void 0 : A.junction,
204
- I.join(","),
205
- JSON.stringify(ie ?? null)
209
+ Q == null ? void 0 : Q.junction,
210
+ W.join(","),
211
+ JSON.stringify(ae ?? null)
206
212
  ],
207
213
  queryFn: async () => {
208
- const e = A, t = [];
209
- for (let r = 0; r < I.length; r += 200) {
210
- const a = I.slice(r, r + 200), d = await tt(p, `/items/${e.junction}`, {
214
+ const e = Q, t = [];
215
+ for (let r = 0; r < W.length; r += 200) {
216
+ const s = W.slice(r, r + 200), m = await it(h, `/items/${e.junction}`, {
211
217
  fields: `${e.fkToItem},${e.fkToSection}`,
212
218
  filter: JSON.stringify(
213
- ie ? { _and: [{ [e.fkToSection]: { _in: a } }, ie] } : { [e.fkToSection]: { _in: a } }
219
+ ae ? { _and: [{ [e.fkToSection]: { _in: s } }, ae] } : { [e.fkToSection]: { _in: s } }
214
220
  )
215
221
  });
216
- for (const o of d)
222
+ for (const o of m)
217
223
  o[e.fkToItem] == null || o[e.fkToSection] == null || t.push({ item: String(o[e.fkToItem]), section: String(o[e.fkToSection]) });
218
224
  }
219
225
  return t;
220
226
  },
221
- enabled: !!A && I.length > 0,
227
+ enabled: !!Q && W.length > 0,
222
228
  staleTime: 6e4
223
- }), Q = P(() => {
224
- const e = new Map(y.map((r) => [r.id, r.name])), t = /* @__PURE__ */ new Map();
225
- for (const r of W) {
226
- const a = e.get(r.section);
227
- if (!a) continue;
228
- const d = t.get(r.item) ?? [];
229
- d.includes(a) || d.push(a), t.set(r.item, d);
229
+ }), jt = O(() => {
230
+ const e = new Map(I.map((r) => [r.id, r.name])), t = /* @__PURE__ */ new Map();
231
+ for (const r of we) {
232
+ const s = e.get(r.section);
233
+ if (!s) continue;
234
+ const m = t.get(r.item) ?? [];
235
+ m.includes(s) || m.push(s), t.set(r.item, m);
230
236
  }
231
237
  return t;
232
- }, [y, W]), Y = !!T && (!A || H || I.length > 0 && le), me = P(() => {
238
+ }, [I, we]), De = !!R && (!Q || M || W.length > 0 && Ne), Ue = O(() => {
233
239
  const e = /* @__PURE__ */ new Map();
234
- for (const t of ke) e.set(String(t.id), t);
240
+ for (const t of E) e.set(String(t.id), t);
235
241
  return e;
236
- }, [ke]), { data: M = [] } = B({
237
- queryKey: ["o2m-rows", m, x, S],
238
- queryFn: () => p.request(
239
- E(`/items/${m}`, {
240
- filter: JSON.stringify({ [x]: { _eq: S } }),
242
+ }, [E]), { data: ve = [] } = J({
243
+ queryKey: ["o2m-rows", u, g, _],
244
+ queryFn: () => h.request(
245
+ P(`/items/${u}`, {
246
+ filter: JSON.stringify({ [g]: { _eq: _ } }),
241
247
  limit: 1e3
242
248
  })
243
249
  ).then((e) => e.data ?? []),
244
- enabled: !K,
250
+ enabled: !A,
245
251
  staleTime: 15e3
246
- }), Te = !K && !!f, Ne = f ? f.getPendingRows(m, x) : [], Qe = Te ? f.getPendingEdits(m, x) : /* @__PURE__ */ new Map(), Mt = JSON.stringify([...Qe.entries()]), Ve = P(
247
- () => Qe.size === 0 ? M : M.map((e) => {
248
- const t = Qe.get(String(e.id));
252
+ }), Pe = !A && !!p, Se = p ? p.getPendingRows(u, g) : [], He = Pe ? p.getPendingEdits(u, g) : /* @__PURE__ */ new Map(), er = JSON.stringify([...He.entries()]), Me = O(
253
+ () => He.size === 0 ? ve : ve.map((e) => {
254
+ const t = He.get(String(e.id));
249
255
  return t ? { ...e, ...t } : e;
250
256
  }),
251
- [M, Mt]
252
- ), Ue = !K && f ? f.getPendingDeletes(m, x) : /* @__PURE__ */ new Set(), De = P(() => {
257
+ [ve, er]
258
+ ), We = !A && p ? p.getPendingDeletes(u, g) : /* @__PURE__ */ new Set(), Ie = O(() => {
253
259
  const e = /* @__PURE__ */ new Map();
254
- for (const t of Ve) {
260
+ for (const t of Me) {
255
261
  const r = t[l.item_field];
256
262
  r != null && e.set(String(r), t);
257
263
  }
258
264
  return e;
259
- }, [Ve, l.item_field]), rt = P(() => {
265
+ }, [Me, l.item_field]), lt = O(() => {
260
266
  const e = /* @__PURE__ */ new Map();
261
- return Ne.forEach((t, r) => {
262
- const a = t[l.item_field];
263
- a != null && e.set(String(a), r);
267
+ return Se.forEach((t, r) => {
268
+ const s = t[l.item_field];
269
+ s != null && e.set(String(s), r);
264
270
  }), e;
265
- }, [Ne, l.item_field]), oe = P(() => {
266
- const e = Ne.filter((a) => a[l.item_field] != null).map((a) => ({ key: String(a[l.item_field]), row: a }));
267
- if (K) return e;
268
- const t = Ve.filter((a) => a[l.item_field] != null).map((a) => ({ key: String(a[l.item_field]), row: a })), r = new Set(t.map((a) => a.key));
269
- return [...t, ...e.filter((a) => !r.has(a.key))];
270
- }, [K, Ne, Ve, l.item_field]), He = P(
271
- () => oe.filter((e) => !me.has(e.key)).map((e) => e.key),
272
- [oe, me]
273
- ), { data: _t = [] } = B({
274
- queryKey: ["catalog-picker-labels", b, ee, He.join(",")],
275
- queryFn: () => p.request(
276
- E(`/items/${b}`, {
277
- filter: JSON.stringify({ id: { _in: He } }),
278
- fields: ee,
279
- limit: He.length
271
+ }, [Se, l.item_field]), de = O(() => {
272
+ const e = Se.filter((s) => s[l.item_field] != null).map((s) => ({ key: String(s[l.item_field]), row: s }));
273
+ if (A) return e;
274
+ const t = Me.filter((s) => s[l.item_field] != null).map((s) => ({ key: String(s[l.item_field]), row: s })), r = new Set(t.map((s) => s.key));
275
+ return [...t, ...e.filter((s) => !r.has(s.key))];
276
+ }, [A, Se, Me, l.item_field]), Ye = O(
277
+ () => de.filter((e) => !Ue.has(e.key)).map((e) => e.key),
278
+ [de, Ue]
279
+ ), { data: Ft = [] } = J({
280
+ queryKey: ["catalog-picker-labels", b, a, Ye.join(",")],
281
+ queryFn: () => h.request(
282
+ P(`/items/${b}`, {
283
+ filter: JSON.stringify({ id: { _in: Ye } }),
284
+ fields: a,
285
+ limit: Ye.length
280
286
  })
281
287
  ).then((e) => e.data ?? []),
282
- enabled: !!b && He.length > 0,
288
+ enabled: !!b && Ye.length > 0,
283
289
  staleTime: 6e4
284
- }), { data: pe = [] } = B({
290
+ }), { data: ge = [] } = J({
285
291
  queryKey: ["pinned-items", b],
286
- queryFn: () => p.request(E(`/pinned/${b}`)).then((e) => e.data ?? []),
292
+ queryFn: () => h.request(P(`/pinned/${b}`)).then((e) => e.data ?? []),
287
293
  enabled: !!b && !!l.favorites,
288
294
  staleTime: 6e4
289
- }), nt = P(() => new Set(pe), [pe]), { data: Oe = [] } = B({
290
- queryKey: ["pinned-item-rows", b, ee, pe.join(",")],
291
- queryFn: () => p.request(
292
- E(`/items/${b}`, {
293
- filter: JSON.stringify({ id: { _in: pe } }),
294
- fields: ee,
295
- limit: pe.length
295
+ }), ot = O(() => new Set(ge), [ge]), { data: Re = [] } = J({
296
+ queryKey: ["pinned-item-rows", b, a, ge.join(",")],
297
+ queryFn: () => h.request(
298
+ P(`/items/${b}`, {
299
+ filter: JSON.stringify({ id: { _in: ge } }),
300
+ fields: a,
301
+ limit: ge.length
296
302
  })
297
303
  ).then((e) => e.data ?? []),
298
- enabled: !!b && !!l.favorites && pe.length > 0,
304
+ enabled: !!b && !!l.favorites && ge.length > 0,
299
305
  staleTime: 6e4
300
- }), [Ie, St] = re(/* @__PURE__ */ new Set());
301
- async function qt(e) {
302
- if (!(!b || Ie.has(e))) {
303
- St((t) => new Set(t).add(e));
306
+ }), [Ze, Tt] = Y(/* @__PURE__ */ new Set());
307
+ async function Ot(e) {
308
+ if (!(!b || Ze.has(e))) {
309
+ Tt((t) => new Set(t).add(e));
304
310
  try {
305
- await p.request(Vt(`/pinned/${b}/${e}/toggle`)).catch(() => {
311
+ await h.request(It(`/pinned/${b}/${e}/toggle`)).catch(() => {
306
312
  }), await $.invalidateQueries({ queryKey: ["pinned-items", b] });
307
313
  } finally {
308
- St((t) => {
314
+ Tt((t) => {
309
315
  const r = new Set(t);
310
316
  return r.delete(e), r;
311
317
  });
312
318
  }
313
319
  }
314
320
  }
315
- const [Wt, $t] = re(!1), jt = Je(null), st = (e) => l.favorites ? /* @__PURE__ */ n(
321
+ const [tr, Pt] = Y(!1), Rt = ze(null), dt = (e) => l.favorites ? /* @__PURE__ */ n(
316
322
  "button",
317
323
  {
318
324
  type: "button",
319
- title: nt.has(e) ? "Remove from favorites" : "Add to favorites",
320
- disabled: Ie.has(e),
325
+ title: ot.has(e) ? "Remove from favorites" : "Add to favorites",
326
+ disabled: Ze.has(e),
321
327
  onClick: (t) => {
322
- t.stopPropagation(), qt(e);
328
+ t.stopPropagation(), Ot(e);
323
329
  },
324
330
  className: "shrink-0 rounded p-0.5 transition-colors",
325
- children: Ie.has(e) ? /* @__PURE__ */ n(ae, { className: "h-3.5 w-3.5 animate-spin text-amber-400" }) : /* @__PURE__ */ n(
326
- Ke,
331
+ children: Ze.has(e) ? /* @__PURE__ */ n(oe, { className: "h-3.5 w-3.5 animate-spin text-amber-400" }) : /* @__PURE__ */ n(
332
+ Qe,
327
333
  {
328
- className: V(
334
+ className: z(
329
335
  "h-3.5 w-3.5",
330
- nt.has(e) ? "fill-amber-400 text-amber-400" : "text-slate-300 hover:text-amber-400"
336
+ ot.has(e) ? "fill-amber-400 text-amber-400" : "text-slate-300 hover:text-amber-400"
331
337
  )
332
338
  }
333
339
  )
334
340
  }
335
- ) : null, [at, Yt] = re("");
336
- Se(() => {
337
- const e = setTimeout(() => Yt(J), 300);
341
+ ) : null, [ct, rr] = Y("");
342
+ je(() => {
343
+ const e = setTimeout(() => rr(C), 300);
338
344
  return () => clearTimeout(e);
339
- }, [J]);
340
- const Zt = P(() => {
345
+ }, [C]);
346
+ const nr = O(() => {
341
347
  var t;
342
- const e = (t = [...(F ?? "").matchAll(/\{\{([\w.]+)\}\}/g)][0]) == null ? void 0 : t[1];
348
+ const e = (t = [...(H ?? "").matchAll(/\{\{([\w.]+)\}\}/g)][0]) == null ? void 0 : t[1];
343
349
  return e && !e.includes(".") ? e : "id";
344
- }, [F]), { data: Gt = [], isFetching: it } = B({
345
- queryKey: ["catalog-full-search", b, ee, at],
346
- queryFn: () => p.request(
347
- E(`/items/${b}`, {
348
- search: at,
349
- fields: ee,
350
+ }, [H]), { data: sr = [], isFetching: mt } = J({
351
+ queryKey: ["catalog-full-search", b, a, ct],
352
+ queryFn: () => h.request(
353
+ P(`/items/${b}`, {
354
+ search: ct,
355
+ fields: a,
350
356
  limit: 25,
351
- sort: Zt
357
+ sort: nr
352
358
  })
353
359
  ).then((e) => e.data ?? []),
354
- enabled: !!b && at.trim().length > 0,
360
+ enabled: !!b && ct.trim().length > 0,
355
361
  staleTime: 3e4,
356
362
  placeholderData: (e) => e
357
- }), ve = Gt, Me = P(() => {
363
+ }), qe = sr, Ge = O(() => {
358
364
  const e = /* @__PURE__ */ new Set();
359
- for (const t of ke) e.add(String(t.id));
360
- for (const t of oe) e.add(t.key);
361
- for (const t of pe) e.add(t);
362
- for (const t of ve) e.add(String(t.id));
365
+ for (const t of E) e.add(String(t.id));
366
+ for (const t of de) e.add(t.key);
367
+ for (const t of ge) e.add(t);
368
+ for (const t of qe) e.add(String(t.id));
363
369
  return [...e];
364
- }, [ke, oe, pe, ve]), Ft = wt({
370
+ }, [E, de, ge, qe]), Lt = St({
365
371
  queries: (l.related_columns ?? []).map((e) => {
366
- const t = ze(e.match, X);
372
+ const t = Be(e.match, ee);
367
373
  return {
368
374
  queryKey: [
369
375
  "catalog-related",
370
376
  e.key,
371
377
  e.collection,
372
378
  JSON.stringify(t),
373
- Me.join(",")
379
+ Ge.join(",")
374
380
  ],
375
381
  queryFn: async () => {
376
- const r = {}, a = e.aggregate === "sum", d = a ? 150 : 400;
377
- for (let o = 0; o < Me.length; o += d) {
378
- const s = Me.slice(o, o + d);
379
- let u = 1;
382
+ const r = {}, s = e.aggregate === "sum", m = s ? 150 : 400;
383
+ for (let o = 0; o < Ge.length; o += m) {
384
+ const i = Ge.slice(o, o + m);
385
+ let y = 1;
380
386
  for (; ; ) {
381
- const N = await p.request(
382
- E(`/items/${e.collection}`, {
383
- limit: a ? 1e3 : s.length,
384
- ...a ? { page: u } : {},
387
+ const d = await h.request(
388
+ P(`/items/${e.collection}`, {
389
+ limit: s ? 1e3 : i.length,
390
+ ...s ? { page: y } : {},
385
391
  fields: `${e.item_field},${e.value_field}`,
386
- filter: JSON.stringify({ ...t, [e.item_field]: { _in: s } })
392
+ filter: JSON.stringify({ ...t, [e.item_field]: { _in: i } })
387
393
  })
388
- ).then((k) => k.data ?? []);
389
- for (const k of N) {
390
- const v = k[e.item_field];
391
- if (v != null)
392
- if (a) {
393
- const _ = Number(k[e.value_field]);
394
- r[String(v)] = (Number(r[String(v)]) || 0) + (Number.isNaN(_) ? 0 : _);
394
+ ).then((f) => f.data ?? []);
395
+ for (const f of d) {
396
+ const N = f[e.item_field];
397
+ if (N != null)
398
+ if (s) {
399
+ const T = Number(f[e.value_field]);
400
+ r[String(N)] = (Number(r[String(N)]) || 0) + (Number.isNaN(T) ? 0 : T);
395
401
  } else
396
- r[String(v)] = k[e.value_field];
402
+ r[String(N)] = f[e.value_field];
397
403
  }
398
- if (!a || N.length < 1e3) break;
399
- u += 1;
404
+ if (!s || d.length < 1e3) break;
405
+ y += 1;
400
406
  }
401
407
  }
402
408
  return r;
403
409
  },
404
- enabled: !!b && t !== null && Me.length > 0,
410
+ enabled: !!b && t !== null && Ge.length > 0,
405
411
  staleTime: 3e4
406
412
  };
407
413
  })
408
- }), lt = (e, t) => {
409
- var a, d;
414
+ }), ut = (e, t) => {
415
+ var s, m;
410
416
  const r = (l.related_columns ?? []).findIndex((o) => o.key === e);
411
417
  if (r !== -1)
412
- return (d = (a = Ft[r]) == null ? void 0 : a.data) == null ? void 0 : d[t];
413
- }, ot = (e) => {
414
- var u;
418
+ return (m = (s = Lt[r]) == null ? void 0 : s.data) == null ? void 0 : m[t];
419
+ }, ft = (e) => {
420
+ var y;
415
421
  const t = l.qty_warning;
416
422
  if (!t) return null;
417
- const r = fe(e) ?? 0;
423
+ const r = be(e) ?? 0;
418
424
  if (r <= 0) return null;
419
- const a = (l.related_columns ?? []).findIndex((N) => N.key === t.column);
420
- if (a === -1) return null;
421
- const d = (u = Ft[a]) == null ? void 0 : u.data;
422
- if (d === void 0) return null;
423
- const o = d[e], s = o == null || o === "" ? 0 : Number(o);
424
- return Number.isNaN(s) ? null : r > s ? { available: s, qty: r } : null;
425
- }, Xt = (e) => {
425
+ const s = (l.related_columns ?? []).findIndex((d) => d.key === t.column);
426
+ if (s === -1) return null;
427
+ const m = (y = Lt[s]) == null ? void 0 : y.data;
428
+ if (m === void 0) return null;
429
+ const o = m[e], i = o == null || o === "" ? 0 : Number(o);
430
+ return Number.isNaN(i) ? null : r > i ? { available: i, qty: r } : null;
431
+ }, ar = (e) => {
426
432
  const t = l.row_flags ?? [];
427
433
  if (t.length === 0) return [];
428
434
  const r = [];
429
- for (const a of t)
430
- if (!(!(a != null && a.when) || !a.label))
435
+ for (const s of t)
436
+ if (!(!(s != null && s.when) || !s.label))
431
437
  try {
432
- const d = a.when.replace(/\{\{\s*([A-Za-z_][A-Za-z0-9_.]*)\s*\}\}/g, "$1");
433
- vr(d, e) && r.push(a.label);
438
+ const m = s.when.replace(/\{\{\s*([A-Za-z_][A-Za-z0-9_.]*)\s*\}\}/g, "$1");
439
+ jr(m, e) && r.push(s.label);
434
440
  } catch {
435
441
  }
436
442
  return r;
437
- }, dt = l.qty_warning ? l.qty_warning.label ?? ((Kt = (l.related_columns ?? []).find((e) => {
443
+ }, bt = l.qty_warning ? l.qty_warning.label ?? ((Dt = (l.related_columns ?? []).find((e) => {
438
444
  var t;
439
445
  return e.key === ((t = l.qty_warning) == null ? void 0 : t.column);
440
- })) == null ? void 0 : Kt.label) ?? te(l.qty_warning.column) : "", er = !!l.submission_errors, We = P(
446
+ })) == null ? void 0 : Dt.label) ?? re(l.qty_warning.column) : "", ir = !!l.submission_errors, Xe = O(
441
447
  () => {
442
448
  var e;
443
449
  return typeof l.submission_errors == "object" && Array.isArray((e = l.submission_errors) == null ? void 0 : e.match_fields) ? l.submission_errors.match_fields.filter((t) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(t)) : [];
444
450
  },
445
451
  [l.submission_errors]
446
- ), tr = _r(6e4), { data: Tt } = B({
447
- queryKey: ["erp-submissions", q ?? "", String(S)],
448
- queryFn: () => p.request(E(`/erp-submissions/${q}/${encodeURIComponent(S)}`)).then((e) => e.data ?? []),
449
- enabled: er && !K && !!q,
452
+ ), lr = Fr(6e4), { data: Et } = J({
453
+ queryKey: ["erp-submissions", q ?? "", String(_)],
454
+ queryFn: () => h.request(P(`/erp-submissions/${q}/${encodeURIComponent(_)}`)).then((e) => e.data ?? []),
455
+ enabled: ir && !A && !!q,
450
456
  staleTime: 15e3,
451
- refetchInterval: tr
452
- }), ct = P(() => {
453
- const e = (Tt ?? [])[0];
454
- return !e || e.status !== "failed" ? null : Sr(e.payload, e.last_error);
455
- }, [Tt]), rr = oe.map((e) => e.key).join(","), { data: mt } = B({
456
- queryKey: ["catalog-suberr-idents", b, We.join(","), rr],
457
+ refetchInterval: lr
458
+ }), pt = O(() => {
459
+ const e = (Et ?? [])[0];
460
+ return !e || e.status !== "failed" ? null : Tr(e.payload, e.last_error);
461
+ }, [Et]), or = de.map((e) => e.key).join(","), { data: ht } = J({
462
+ queryKey: ["catalog-suberr-idents", b, Xe.join(","), or],
457
463
  queryFn: async () => {
458
- const e = oe.map((r) => r.key);
464
+ const e = de.map((r) => r.key);
459
465
  if (e.length === 0) return {};
460
- const t = await p.request(
461
- E(`/items/${b}`, {
466
+ const t = await h.request(
467
+ P(`/items/${b}`, {
462
468
  limit: e.length,
463
- fields: ["id", ...We].join(","),
469
+ fields: ["id", ...Xe].join(","),
464
470
  filter: JSON.stringify({ id: { _in: e } })
465
471
  })
466
472
  ).then((r) => r.data ?? []);
467
473
  return Object.fromEntries(t.map((r) => [String(r.id), r]));
468
474
  },
469
- enabled: !!b && !!ct && We.length > 0 && oe.length > 0,
475
+ enabled: !!b && !!pt && Xe.length > 0 && de.length > 0,
470
476
  staleTime: 6e4
471
- }), nr = (e) => {
472
- if (!ct) return null;
473
- const t = mt == null ? void 0 : mt[e], r = [
474
- Ct(e),
475
- ...We.map((a) => {
476
- const d = (t == null ? void 0 : t[a]) ?? _e(e)[a];
477
- return d != null && d !== "" ? String(d) : null;
477
+ }), dr = (e) => {
478
+ if (!pt) return null;
479
+ const t = ht == null ? void 0 : ht[e], r = [
480
+ Bt(e),
481
+ ...Xe.map((s) => {
482
+ const m = (t == null ? void 0 : t[s]) ?? $e(e)[s];
483
+ return m != null && m !== "" ? String(m) : null;
478
484
  })
479
- ].filter((a) => !!a).map(qr);
480
- return ct.reasonFor(r);
481
- }, Ye = l.summary_fields ?? [], sr = M.map((e) => String(e.id)).join(","), ar = wt({
482
- queries: Ye.filter((e) => e.m2m).map((e) => ({
483
- queryKey: ["catalog-summary-m2m", e.field, e.m2m.junction, sr],
485
+ ].filter((s) => !!s).map(Or);
486
+ return pt.reasonFor(r);
487
+ }, et = l.summary_fields ?? [], cr = ve.map((e) => String(e.id)).join(","), mr = St({
488
+ queries: et.filter((e) => e.m2m).map((e) => ({
489
+ queryKey: ["catalog-summary-m2m", e.field, e.m2m.junction, cr],
484
490
  queryFn: async () => {
485
- const t = M.map((k) => String(k.id));
491
+ const t = ve.map((f) => String(f.id));
486
492
  if (t.length === 0) return {};
487
- const r = e.m2m, a = await p.request(
488
- E(`/items/${r.junction}`, {
493
+ const r = e.m2m, s = await h.request(
494
+ P(`/items/${r.junction}`, {
489
495
  limit: 1e3,
490
496
  fields: `${r.fk_to_child},${r.related_field}`,
491
497
  filter: JSON.stringify({ [r.fk_to_child]: { _in: t } })
492
498
  })
493
- ).then((k) => k.data ?? []).catch(() => []), d = [...new Set(a.map((k) => String(k[r.related_field])))], o = r.label_field ?? "name", s = d.length ? await p.request(
494
- E(`/items/${r.related_collection}`, {
499
+ ).then((f) => f.data ?? []).catch(() => []), m = [...new Set(s.map((f) => String(f[r.related_field])))], o = r.label_field ?? "name", i = m.length ? await h.request(
500
+ P(`/items/${r.related_collection}`, {
495
501
  limit: 500,
496
502
  fields: `id,${o}`,
497
- filter: JSON.stringify({ id: { _in: d } })
503
+ filter: JSON.stringify({ id: { _in: m } })
498
504
  })
499
- ).then((k) => k.data ?? []).catch(() => []) : [], u = new Map(s.map((k) => [String(k.id), String(k[o] ?? k.id)])), N = {};
500
- for (const k of a) {
501
- const v = String(k[r.fk_to_child]), _ = u.get(String(k[r.related_field]));
502
- _ && (N[v] = N[v] ? `${N[v]}, ${_}` : _);
505
+ ).then((f) => f.data ?? []).catch(() => []) : [], y = new Map(i.map((f) => [String(f.id), String(f[o] ?? f.id)])), d = {};
506
+ for (const f of s) {
507
+ const N = String(f[r.fk_to_child]), T = y.get(String(f[r.related_field]));
508
+ T && (d[N] = d[N] ? `${d[N]}, ${T}` : T);
503
509
  }
504
- return N;
510
+ return d;
505
511
  },
506
- enabled: !K && M.length > 0,
512
+ enabled: !A && ve.length > 0,
507
513
  staleTime: 15e3
508
514
  }))
509
- }), ir = (e, t) => {
510
- var d, o;
515
+ }), ur = (e, t) => {
516
+ var m, o;
511
517
  if (!e.m2m) return t.row[e.field];
512
- const r = Ye.filter((s) => s.m2m).findIndex((s) => s.field === e.field);
518
+ const r = et.filter((i) => i.m2m).findIndex((i) => i.field === e.field);
513
519
  if (r === -1) return;
514
- const a = t.row.id;
515
- if (a != null)
516
- return (o = (d = ar[r]) == null ? void 0 : d.data) == null ? void 0 : o[String(a)];
517
- }, lr = !!((Jt = l.fulfilment) != null && Jt.shipped_field) && (l.fulfilment.show_when ? Ut(l.fulfilment.show_when, X) : !0), or = (e) => {
518
- if (!lr || !l.fulfilment) return null;
519
- const t = Number(e[l.fulfilment.qty_field ?? D] ?? 0) || 0, r = Number(e[l.fulfilment.shipped_field] ?? 0) || 0, a = t > 0 && r >= t ? {
520
+ const s = t.row.id;
521
+ if (s != null)
522
+ return (o = (m = mr[r]) == null ? void 0 : m.data) == null ? void 0 : o[String(s)];
523
+ }, fr = !!((Ut = l.fulfilment) != null && Ut.shipped_field) && (l.fulfilment.show_when ? Yt(l.fulfilment.show_when, ee) : !0), br = (e) => {
524
+ if (!fr || !l.fulfilment) return null;
525
+ const t = Number(e[l.fulfilment.qty_field ?? V] ?? 0) || 0, r = Number(e[l.fulfilment.shipped_field] ?? 0) || 0, s = t > 0 && r >= t ? {
520
526
  dot: "bg-emerald-500",
521
527
  text: "text-emerald-700 dark:text-emerald-400",
522
528
  label: "Shipped"
@@ -533,15 +539,15 @@ function en({
533
539
  "span",
534
540
  {
535
541
  className: "inline-flex items-center gap-1.5 whitespace-nowrap",
536
- "data-catalog-fulfilment": a.label.split(" ")[0].toLowerCase(),
542
+ "data-catalog-fulfilment": s.label.split(" ")[0].toLowerCase(),
537
543
  title: `${l.fulfilment.label ?? "Warehouse"} · ${r} of ${t} shipped`,
538
544
  children: [
539
- /* @__PURE__ */ n("span", { "aria-hidden": !0, className: `h-1.5 w-1.5 rounded-full ${a.dot}` }),
540
- /* @__PURE__ */ n("span", { className: `text-[11px] font-medium ${a.text}`, children: a.label })
545
+ /* @__PURE__ */ n("span", { "aria-hidden": !0, className: `h-1.5 w-1.5 rounded-full ${s.dot}` }),
546
+ /* @__PURE__ */ n("span", { className: `text-[11px] font-medium ${s.text}`, children: s.label })
541
547
  ]
542
548
  }
543
549
  );
544
- }, Ot = l.columns ?? [], Lt = l.related_columns ?? [], ut = Ot.filter((e) => !e.summary_only), ft = Lt.filter((e) => !e.summary_only), Pt = Ot.filter((e) => !e.sections_only), Et = Lt.filter((e) => !e.sections_only), Rt = ut.length > 0 || ft.length > 0, bt = Je(null), At = (e) => {
550
+ }, At = l.columns ?? [], Ct = l.related_columns ?? [], xt = At.filter((e) => !e.summary_only), gt = Ct.filter((e) => !e.summary_only), Kt = At.filter((e) => !e.sections_only), Jt = Ct.filter((e) => !e.sections_only), Qt = xt.length > 0 || gt.length > 0, yt = ze(null), zt = (e) => {
545
551
  let t = e.parentElement;
546
552
  for (; t; ) {
547
553
  const r = getComputedStyle(t);
@@ -551,14 +557,14 @@ function en({
551
557
  }
552
558
  t = t.parentElement;
553
559
  }
554
- }, dr = (e) => {
555
- bt.current = e, e && At(e);
560
+ }, pr = (e) => {
561
+ yt.current = e, e && zt(e);
556
562
  };
557
- Se(() => {
563
+ je(() => {
558
564
  let e = 0;
559
565
  const t = () => {
560
566
  e || (e = requestAnimationFrame(() => {
561
- e = 0, bt.current && At(bt.current);
567
+ e = 0, yt.current && zt(yt.current);
562
568
  }));
563
569
  };
564
570
  return window.addEventListener("scroll", t, !0), () => {
@@ -567,74 +573,74 @@ function en({
567
573
  }, []);
568
574
  const Le = (e, t) => {
569
575
  let r = e;
570
- for (const a of t.split(".")) {
576
+ for (const s of t.split(".")) {
571
577
  if (r == null || typeof r != "object") return;
572
- r = r[a];
578
+ r = r[s];
573
579
  }
574
580
  return r;
575
- }, ue = (e, t) => {
581
+ }, fe = (e, t) => {
576
582
  if (t === "presence")
577
583
  return e == null || e === "" || Number(e) === 0 ? "No" : "Yes";
578
584
  if (e == null || e === "") return "—";
579
585
  const r = Number(e);
580
586
  return t === "currency" ? Number.isNaN(r) ? String(e) : r.toLocaleString(void 0, { style: "currency", currency: "USD" }) : t === "number" ? Number.isNaN(r) ? String(e) : r.toLocaleString(void 0, { maximumFractionDigits: 2 }) : String(e);
581
- }, pt = (e, t) => /* @__PURE__ */ c(kt, { children: [
582
- ut.map((r) => /* @__PURE__ */ n(
587
+ }, kt = (e, t) => /* @__PURE__ */ c(_t, { children: [
588
+ xt.map((r) => /* @__PURE__ */ n(
583
589
  "span",
584
590
  {
585
- className: V(
591
+ className: z(
586
592
  "truncate text-slate-500 dark:text-slate-400",
587
593
  r.format ? "w-20 shrink-0 text-right" : "min-w-0 flex-1"
588
594
  ),
589
- children: ue(Le(t, r.field), r.format)
595
+ children: fe(Le(t, r.field), r.format)
590
596
  },
591
597
  r.field
592
598
  )),
593
- ft.map((r) => /* @__PURE__ */ n(
599
+ gt.map((r) => /* @__PURE__ */ n(
594
600
  "span",
595
601
  {
596
602
  className: "w-20 shrink-0 truncate text-right text-slate-500 dark:text-slate-400",
597
- children: ue(lt(r.key, e), r.format)
603
+ children: fe(ut(r.key, e), r.format)
598
604
  },
599
605
  r.key
600
606
  ))
601
- ] }), ht = Rt ? "w-36 shrink-0 truncate text-slate-700 dark:text-slate-200" : "min-w-0 flex-1 truncate text-slate-700 dark:text-slate-200", cr = Dt(b), Ze = (e, t, r) => cr ? /* @__PURE__ */ n(
607
+ ] }), wt = Qt ? "w-36 shrink-0 truncate text-slate-700 dark:text-slate-200" : "min-w-0 flex-1 truncate text-slate-700 dark:text-slate-200", hr = Zt(b), tt = (e, t, r) => hr ? /* @__PURE__ */ n(
602
608
  "button",
603
609
  {
604
610
  type: "button",
605
- onClick: () => b && Ht(b, e, X),
611
+ onClick: () => b && Gt(b, e, ee),
606
612
  title: "View stock & planning detail",
607
- className: V(
613
+ className: z(
608
614
  r,
609
615
  "text-left underline decoration-slate-300 decoration-1 underline-offset-2 hover:text-[#009abe] hover:decoration-[#009abe] dark:decoration-slate-600"
610
616
  ),
611
617
  children: t
612
618
  }
613
- ) : /* @__PURE__ */ n("span", { className: r, children: t }), Ct = (e) => {
614
- const t = me.get(e) ?? _t.find((r) => String(r.id) === e) ?? Oe.find((r) => String(r.id) === e);
615
- return t ? qe(F, t) : `#${e}`;
616
- }, _e = (e) => me.get(e) ?? _t.find((t) => String(t.id) === e) ?? Oe.find((t) => String(t.id) === e) ?? { id: e }, fe = (e) => {
617
- var a;
618
- const t = K ? void 0 : De.get(e);
619
- if (t) return Ue.has(String(t.id)) ? null : Number(t[D] ?? 0);
620
- const r = rt.get(e);
621
- return r === void 0 ? null : Number(((a = Ne[r]) == null ? void 0 : a[D]) ?? 0);
622
- }, mr = (e) => {
619
+ ) : /* @__PURE__ */ n("span", { className: r, children: t }), Bt = (e) => {
620
+ const t = Ue.get(e) ?? Ft.find((r) => String(r.id) === e) ?? Re.find((r) => String(r.id) === e);
621
+ return t ? Fe(H, t) : `#${e}`;
622
+ }, $e = (e) => Ue.get(e) ?? Ft.find((t) => String(t.id) === e) ?? Re.find((t) => String(t.id) === e) ?? { id: e }, be = (e) => {
623
+ var s;
624
+ const t = A ? void 0 : Ie.get(e);
625
+ if (t) return We.has(String(t.id)) ? null : Number(t[V] ?? 0);
626
+ const r = lt.get(e);
627
+ return r === void 0 ? null : Number(((s = Se[r]) == null ? void 0 : s[V]) ?? 0);
628
+ }, xr = (e) => {
623
629
  let t = e;
624
630
  for (const r of l.section_by.split(".")) {
625
631
  if (t == null || typeof t != "object") return "";
626
632
  t = t[r];
627
633
  }
628
634
  return String(t ?? "").trim();
629
- }, Ge = P(() => {
630
- if (Y) return [];
631
- J.trim().toLowerCase();
635
+ }, rt = O(() => {
636
+ if (De) return [];
637
+ C.trim().toLowerCase();
632
638
  const e = /* @__PURE__ */ new Map();
633
- for (const t of ke) {
634
- const r = qe(F, t), a = T ? Q.get(String(t.id)) ?? [] : [mr(t)];
635
- if (!(T && ie && a.length === 0))
636
- for (const d of a.length ? a : [""]) {
637
- const o = d || "Uncategorized";
639
+ for (const t of E) {
640
+ const r = Fe(H, t), s = R ? jt.get(String(t.id)) ?? [] : [xr(t)];
641
+ if (!(R && ae && s.length === 0))
642
+ for (const m of s.length ? s : [""]) {
643
+ const o = m || "Uncategorized";
638
644
  e.has(o) || e.set(o, []), e.get(o).push({ id: String(t.id), label: r, row: t });
639
645
  }
640
646
  }
@@ -642,318 +648,398 @@ function en({
642
648
  ([t], [r]) => t === "Uncategorized" ? 1 : r === "Uncategorized" ? -1 : t.localeCompare(r)
643
649
  ).map(([t, r]) => ({
644
650
  name: t,
645
- items: r.sort((a, d) => a.label.localeCompare(d.label))
651
+ items: r.sort((s, m) => s.label.localeCompare(m.label))
646
652
  }));
647
653
  }, [
648
- ke,
649
- F,
650
- J,
654
+ E,
655
+ H,
656
+ C,
651
657
  l.section_by,
652
- T,
653
- Q,
654
- Y,
655
- ie
658
+ R,
659
+ jt,
660
+ De,
661
+ ae
656
662
  ]);
657
- if (!he.current && Ge.length > 0) {
658
- he.current = !0;
663
+ if (!ye.current && rt.length > 0) {
664
+ ye.current = !0;
659
665
  const e = /* @__PURE__ */ new Set();
660
- for (const t of Ge)
661
- t.items.some((a) => (fe(a.id) ?? 0) > 0) || e.add(t.name);
666
+ for (const t of rt)
667
+ t.items.some((s) => (be(s.id) ?? 0) > 0) || e.add(t.name);
662
668
  ne(e);
663
669
  }
664
- async function ur(e) {
670
+ async function gr(e) {
665
671
  const t = {};
666
672
  for (const r of l.related_columns ?? []) {
667
673
  if (!r.copy_to) continue;
668
- let a = lt(r.key, e);
669
- if (a === void 0) {
670
- const d = ze(r.match, X);
671
- if (d === null) continue;
672
- a = await p.request(
673
- E(`/items/${r.collection}`, {
674
+ let s = ut(r.key, e);
675
+ if (s === void 0) {
676
+ const m = Be(r.match, ee);
677
+ if (m === null) continue;
678
+ s = await h.request(
679
+ P(`/items/${r.collection}`, {
674
680
  limit: 1,
675
681
  fields: `${r.item_field},${r.value_field}`,
676
- filter: JSON.stringify({ ...d, [r.item_field]: { _eq: e } })
682
+ filter: JSON.stringify({ ...m, [r.item_field]: { _eq: e } })
677
683
  })
678
684
  ).then((o) => {
679
- var s, u;
680
- return (u = (s = o.data) == null ? void 0 : s[0]) == null ? void 0 : u[r.value_field];
685
+ var i, y;
686
+ return (y = (i = o.data) == null ? void 0 : i[0]) == null ? void 0 : y[r.value_field];
681
687
  }).catch(() => {
682
688
  });
683
689
  }
684
- a != null && (t[r.copy_to] = a);
690
+ s != null && (t[r.copy_to] = s);
685
691
  }
686
692
  return t;
687
693
  }
688
- function Pe(e, t, r, a = {}) {
689
- const d = {
694
+ function Ee(e, t, r, s = {}) {
695
+ const m = {
690
696
  [l.item_field]: r.id ?? e,
691
- [D]: t
697
+ [V]: t
692
698
  };
693
- for (const [o, s] of Object.entries(l.copy_fields ?? {}))
694
- r[s] !== void 0 && (d[o] = r[s]);
695
- Object.assign(d, a);
696
- for (const [o, s] of Object.entries(l.compute_fields ?? {})) {
697
- const u = Ae(s, d);
698
- u !== null && (d[o] = u);
699
+ for (const [o, i] of Object.entries(l.copy_fields ?? {}))
700
+ r[i] !== void 0 && (m[o] = r[i]);
701
+ Object.assign(m, s);
702
+ for (const [o, i] of Object.entries(l.compute_fields ?? {})) {
703
+ const y = Ke(i, m);
704
+ y !== null && (m[o] = y);
699
705
  }
700
- return d;
706
+ return m;
701
707
  }
702
- async function xt(e, t, r) {
703
- const a = t.trim() === "" ? 0 : Number(t);
704
- if (Number.isNaN(a) || a < 0 || (fe(e) ?? 0) === a) return;
705
- const o = a > 0 ? await ur(e) : {};
706
- if (Te && f) {
707
- const s = De.get(e);
708
- if ((s == null ? void 0 : s.id) != null) {
709
- const u = String(s.id);
710
- if (a === 0) {
711
- f.cancelPendingEdit(m, x, u), f.queueDelete(m, x, u);
708
+ async function nt(e, t, r, s = {}) {
709
+ const m = Kr(t, { type: X, min: 0, label: "Quantity" });
710
+ if (!m.ok) {
711
+ j((d) => ({ ...d, [e]: { kind: "error", message: m.message } }));
712
+ return;
713
+ }
714
+ const o = m.value ?? 0;
715
+ if ((be(e) ?? 0) === o) return;
716
+ if (o === 0 && !s.confirmedRemove) {
717
+ j((d) => ({ ...d, [e]: { kind: "remove", row: r } }));
718
+ return;
719
+ }
720
+ const y = o > 0 ? await gr(e) : {};
721
+ if (Pe && p) {
722
+ const d = Ie.get(e);
723
+ if ((d == null ? void 0 : d.id) != null) {
724
+ const f = String(d.id);
725
+ if (o === 0) {
726
+ p.cancelPendingEdit(u, g, f), p.queueDelete(u, g, f);
712
727
  return;
713
728
  }
714
- Ue.has(u) && f.cancelPendingDelete(m, x, u);
715
- const N = Pe(e, a, r, o);
716
- for (const _ of U)
717
- s[_] != null && s[_] !== "" && (N[_] = s[_]);
718
- for (const [_, g] of Object.entries(l.compute_fields ?? {})) {
719
- const C = Ae(g, { ...s, ...N });
720
- C !== null && (N[_] = C);
729
+ We.has(f) && p.cancelPendingDelete(u, g, f);
730
+ const N = Ee(e, o, r, y);
731
+ for (const S of B)
732
+ d[S] != null && d[S] !== "" && (N[S] = d[S]);
733
+ for (const [S, le] of Object.entries(l.compute_fields ?? {})) {
734
+ const _e = Ke(le, { ...d, ...N });
735
+ _e !== null && (N[S] = _e);
721
736
  }
722
- const k = M.find((_) => String(_.id) === u) ?? {}, v = Object.fromEntries(
723
- Object.entries(N).filter(([_, g]) => String(g ?? "") !== String(k[_] ?? ""))
737
+ const T = ve.find((S) => String(S.id) === f) ?? {}, k = Object.fromEntries(
738
+ Object.entries(N).filter(([S, le]) => String(le ?? "") !== String(T[S] ?? ""))
724
739
  );
725
- Object.keys(v).length === 0 ? f.cancelPendingEdit(m, x, u) : (f.cancelPendingEdit(m, x, u), f.queueEdit(m, x, u, v));
740
+ Object.keys(k).length === 0 ? p.cancelPendingEdit(u, g, f) : (p.cancelPendingEdit(u, g, f), p.queueEdit(u, g, f, k));
726
741
  return;
727
742
  }
728
743
  }
729
- if (K || Te) {
730
- const s = rt.get(e);
731
- a === 0 ? s !== void 0 && (f == null || f.removeRow(m, x, s)) : s !== void 0 ? f == null || f.updateRow(m, x, s, {
732
- ...Ne[s],
733
- ...Pe(e, a, r, o)
734
- }) : f == null || f.queueRow(
735
- m,
736
- x,
737
- Pe(e, a, r, o)
744
+ if (A || Pe) {
745
+ const d = lt.get(e);
746
+ o === 0 ? d !== void 0 && (p == null || p.removeRow(u, g, d)) : d !== void 0 ? p == null || p.updateRow(
747
+ u,
748
+ g,
749
+ d,
750
+ Jr(
751
+ Se[d],
752
+ Ee(e, o, r, y),
753
+ B,
754
+ l.compute_fields
755
+ )
756
+ ) : p == null || p.queueRow(
757
+ u,
758
+ g,
759
+ Ee(e, o, r, y)
738
760
  );
739
761
  return;
740
762
  }
741
- w((s) => new Set(s).add(e));
763
+ v((d) => new Set(d).add(e));
742
764
  try {
743
- const s = De.get(e);
744
- if (a === 0)
745
- (s == null ? void 0 : s.id) != null && await p.request(Nr(`/items/${m}/${s.id}`));
746
- else if ((s == null ? void 0 : s.id) != null) {
747
- const u = Pe(e, a, r, o);
748
- for (const _ of U)
749
- s[_] != null && s[_] !== "" && (u[_] = s[_]);
750
- for (const [_, g] of Object.entries(l.compute_fields ?? {})) {
751
- const C = Ae(g, { ...s, ...u });
752
- C !== null && (u[_] = C);
765
+ const d = Ie.get(e);
766
+ if (o === 0)
767
+ (d == null ? void 0 : d.id) != null && await h.request($r(`/items/${u}/${d.id}`));
768
+ else if ((d == null ? void 0 : d.id) != null) {
769
+ const f = Ee(e, o, r, y);
770
+ for (const S of B)
771
+ d[S] != null && d[S] !== "" && (f[S] = d[S]);
772
+ for (const [S, le] of Object.entries(l.compute_fields ?? {})) {
773
+ const _e = Ke(le, { ...d, ...f });
774
+ _e !== null && (f[S] = _e);
753
775
  }
754
- const N = { ...s, ...u }, { id: k, ...v } = N;
755
- await p.request(Qt(`/items/${m}/${s.id}`, v));
776
+ const N = { ...d, ...f }, { id: T, ...k } = N;
777
+ await h.request(Wt(`/items/${u}/${d.id}`, k));
756
778
  } else
757
- await p.request(
758
- Vt(`/items/${m}`, {
759
- [x]: S,
760
- ...Pe(e, a, r, o)
779
+ await h.request(
780
+ It(`/items/${u}`, {
781
+ [g]: _,
782
+ ...Ee(e, o, r, y)
761
783
  })
762
784
  );
763
- $.invalidateQueries({ queryKey: ["o2m-rows", m, x, S] });
785
+ $.invalidateQueries({ queryKey: ["o2m-rows", u, g, _] });
764
786
  } catch {
765
787
  } finally {
766
- w((s) => {
767
- const u = new Set(s);
768
- return u.delete(e), u;
788
+ v((d) => {
789
+ const f = new Set(d);
790
+ return f.delete(e), f;
769
791
  });
770
792
  }
771
793
  }
772
- async function fr(e, t, r) {
773
- const a = r.trim() === "" ? null : Number(r);
774
- if (r.trim() !== "" && Number.isNaN(a)) return;
775
- const d = (s) => {
776
- const u = { ...s, [t]: a };
777
- for (const [N, k] of Object.entries(l.compute_fields ?? {})) {
778
- const v = Ae(k, u);
779
- v !== null && (u[N] = v);
794
+ async function yr(e, t, r) {
795
+ const s = r.trim() === "" ? null : Number(r);
796
+ if (r.trim() !== "" && Number.isNaN(s)) return;
797
+ const m = (i) => {
798
+ const y = { ...i, [t]: s };
799
+ for (const [d, f] of Object.entries(l.compute_fields ?? {})) {
800
+ const N = Ke(f, y);
801
+ N !== null && (y[d] = N);
780
802
  }
781
- return u;
782
- }, o = K ? void 0 : De.get(e);
803
+ return y;
804
+ }, o = A ? void 0 : Ie.get(e);
783
805
  if ((o == null ? void 0 : o.id) == null) {
784
- const s = rt.get(e);
785
- if (s === void 0) return;
786
- f == null || f.updateRow(m, x, s, d(Ne[s]));
806
+ const i = lt.get(e);
807
+ if (i === void 0) return;
808
+ p == null || p.updateRow(u, g, i, m(Se[i]));
787
809
  return;
788
810
  }
789
- if (Te && f) {
790
- const s = d(o), u = M.find((k) => String(k.id) === String(o.id)) ?? {}, N = Object.fromEntries(
791
- Object.entries(s).filter(
792
- ([k, v]) => k !== "id" && String(v ?? "") !== String(u[k] ?? "")
811
+ if (Pe && p) {
812
+ const i = m(o), y = ve.find((f) => String(f.id) === String(o.id)) ?? {}, d = Object.fromEntries(
813
+ Object.entries(i).filter(
814
+ ([f, N]) => f !== "id" && String(N ?? "") !== String(y[f] ?? "")
793
815
  )
794
816
  );
795
- f.cancelPendingEdit(m, x, String(o.id)), Object.keys(N).length > 0 && f.queueEdit(m, x, String(o.id), N);
817
+ p.cancelPendingEdit(u, g, String(o.id)), Object.keys(d).length > 0 && p.queueEdit(u, g, String(o.id), d);
796
818
  return;
797
819
  }
798
- w((s) => new Set(s).add(e));
820
+ v((i) => new Set(i).add(e));
799
821
  try {
800
- const { id: s, ...u } = d(o);
801
- await p.request(Qt(`/items/${m}/${o.id}`, u)), $.invalidateQueries({ queryKey: ["o2m-rows", m, x, S] });
822
+ const { id: i, ...y } = m(o);
823
+ await h.request(Wt(`/items/${u}/${o.id}`, y)), $.invalidateQueries({ queryKey: ["o2m-rows", u, g, _] });
802
824
  } catch {
803
825
  } finally {
804
- w((s) => {
805
- const u = new Set(s);
806
- return u.delete(e), u;
826
+ v((i) => {
827
+ const y = new Set(i);
828
+ return y.delete(e), y;
807
829
  });
808
830
  }
809
831
  }
810
- async function br(e) {
832
+ async function kr(e) {
811
833
  if (e == null || e === "" || !b) return;
812
- const t = String(e), r = _e(t);
813
- let a = r;
814
- Object.keys(r).length <= 1 && (a = await p.request(
815
- E(`/items/${b}`, {
834
+ const t = String(e), r = $e(t);
835
+ let s = r;
836
+ Object.keys(r).length <= 1 && (s = await h.request(
837
+ P(`/items/${b}`, {
816
838
  filter: JSON.stringify({ id: { _eq: e } }),
817
- fields: ee,
839
+ fields: a,
818
840
  limit: 1
819
841
  })
820
842
  ).then((o) => {
821
- var s;
822
- return ((s = o.data) == null ? void 0 : s[0]) ?? { id: e };
843
+ var i;
844
+ return ((i = o.data) == null ? void 0 : i[0]) ?? { id: e };
823
845
  }).catch(() => ({ id: e })));
824
- const d = (fe(t) ?? 0) + 1;
825
- await xt(t, String(d), a);
846
+ const m = (be(t) ?? 0) + 1;
847
+ await nt(t, String(m), s);
826
848
  }
827
- const pr = oe.length, gt = Object.keys(l.copy_fields ?? {}), yt = Object.keys(l.compute_fields ?? {}), Ee = (e, t) => {
828
- const r = fe(e);
829
- if (h)
849
+ const wr = de.length, Nt = Object.keys(l.copy_fields ?? {}), vt = Object.keys(l.compute_fields ?? {}), Ae = (e, t) => {
850
+ const r = be(e);
851
+ if (x)
830
852
  return /* @__PURE__ */ n("span", { className: "inline-block w-20 shrink-0 text-right tabular-nums text-slate-700 dark:text-slate-200", children: r && r > 0 ? r : "—" });
831
- const a = be[e], d = a !== void 0 ? a : r && r > 0 ? String(r) : "";
832
- return /* @__PURE__ */ n(
853
+ const s = pe[e], m = s !== void 0 ? s : r && r > 0 ? String(r) : "", o = F[e], i = () => j((d) => {
854
+ if (!(e in d)) return d;
855
+ const f = { ...d };
856
+ return delete f[e], f;
857
+ }), y = /* @__PURE__ */ n(
833
858
  "input",
834
859
  {
835
860
  type: "number",
836
861
  min: 0,
837
- disabled: h,
838
- value: d,
862
+ step: Cr(X) ? 1 : "any",
863
+ disabled: x,
864
+ value: m,
839
865
  placeholder: "0",
840
- onChange: (o) => G((s) => ({ ...s, [e]: o.target.value })),
841
- onBlur: (o) => {
842
- const s = o.target.value;
843
- G((u) => {
844
- const N = { ...u };
845
- return delete N[e], N;
846
- }), xt(e, s, t);
866
+ "aria-invalid": (o == null ? void 0 : o.kind) === "error" || void 0,
867
+ onFocus: i,
868
+ onChange: (d) => G((f) => ({ ...f, [e]: d.target.value })),
869
+ onBlur: (d) => {
870
+ const f = d.target.value;
871
+ G((N) => {
872
+ const T = { ...N };
873
+ return delete T[e], T;
874
+ }), nt(e, f, t);
847
875
  },
848
- onKeyDown: (o) => {
849
- o.key === "Enter" && o.currentTarget.blur();
876
+ onKeyDown: (d) => {
877
+ d.key === "Enter" && d.currentTarget.blur();
850
878
  },
851
- className: "h-7 w-20 shrink-0 rounded border border-slate-200 bg-white px-2 text-right text-[12px] outline-none focus:border-nvr-cyan disabled:opacity-50 dark:border-border dark:bg-background"
879
+ className: z(
880
+ "h-7 w-20 shrink-0 rounded border border-slate-200 bg-white px-2 text-right text-[12px] outline-none focus:border-nvr-cyan disabled:opacity-50 dark:border-border dark:bg-background",
881
+ (o == null ? void 0 : o.kind) === "error" && "border-red-400 dark:border-red-600"
882
+ )
852
883
  }
853
884
  );
885
+ return /* @__PURE__ */ c(Lr, { open: !!o, onOpenChange: (d) => !d && i(), children: [
886
+ /* @__PURE__ */ n(Er, { asChild: !0, children: y }),
887
+ /* @__PURE__ */ c(
888
+ Ar,
889
+ {
890
+ align: "end",
891
+ side: "bottom",
892
+ className: "w-auto max-w-[260px] p-2.5 text-[12px]",
893
+ onOpenAutoFocus: (d) => {
894
+ (o == null ? void 0 : o.kind) === "error" && d.preventDefault();
895
+ },
896
+ children: [
897
+ (o == null ? void 0 : o.kind) === "error" && /* @__PURE__ */ c(
898
+ "p",
899
+ {
900
+ role: "alert",
901
+ className: "flex items-start gap-1.5 text-red-600 dark:text-red-400",
902
+ "data-catalog-qty-error": !0,
903
+ children: [
904
+ /* @__PURE__ */ n(Mt, { className: "mt-px h-3.5 w-3.5 shrink-0" }),
905
+ o.message,
906
+ r && r > 0 ? ` — still ${r}` : ""
907
+ ]
908
+ }
909
+ ),
910
+ (o == null ? void 0 : o.kind) === "remove" && /* @__PURE__ */ c("div", { "data-catalog-qty-remove": !0, children: [
911
+ /* @__PURE__ */ n("p", { className: "text-slate-700 dark:text-slate-200", children: "Remove this line?" }),
912
+ /* @__PURE__ */ c("div", { className: "mt-2 flex justify-end gap-1.5", children: [
913
+ /* @__PURE__ */ n(
914
+ "button",
915
+ {
916
+ type: "button",
917
+ onClick: i,
918
+ className: "h-6 rounded border border-slate-200 px-2 text-[11px] text-slate-600 hover:bg-muted dark:border-border dark:text-slate-300",
919
+ children: "Keep"
920
+ }
921
+ ),
922
+ /* @__PURE__ */ n(
923
+ "button",
924
+ {
925
+ type: "button",
926
+ onClick: () => {
927
+ const d = o.row;
928
+ i(), nt(e, "0", d, { confirmedRemove: !0 });
929
+ },
930
+ className: "h-6 rounded bg-red-600 px-2 text-[11px] font-medium text-white hover:bg-red-700",
931
+ children: "Remove"
932
+ }
933
+ )
934
+ ] })
935
+ ] })
936
+ ]
937
+ }
938
+ )
939
+ ] });
854
940
  };
855
- return !b && L ? /* @__PURE__ */ c("div", { className: "space-y-2 py-1", "aria-busy": "true", children: [
941
+ return !b && K ? /* @__PURE__ */ c("div", { className: "space-y-2 py-1", "aria-busy": "true", children: [
856
942
  /* @__PURE__ */ n("div", { className: "h-8 w-full animate-pulse rounded bg-slate-100 dark:bg-[hsl(var(--nvr-skeleton))]" }),
857
943
  /* @__PURE__ */ n("div", { className: "h-8 w-2/3 animate-pulse rounded bg-slate-100 dark:bg-[hsl(var(--nvr-skeleton))]" })
858
944
  ] }) : b ? /* @__PURE__ */ c("div", { className: "space-y-3", children: [
859
- !h && /* @__PURE__ */ c(kt, { children: [
945
+ !x && /* @__PURE__ */ c(_t, { children: [
860
946
  /* @__PURE__ */ c("div", { className: "rounded-lg border border-slate-200 text-[12px] dark:border-border", children: [
861
947
  /* @__PURE__ */ c("div", { className: "flex items-center gap-2 border-b border-slate-200 px-3 py-2 dark:border-border", children: [
862
- /* @__PURE__ */ n(Xe, { className: "h-3.5 w-3.5 shrink-0 text-slate-400" }),
948
+ /* @__PURE__ */ n(st, { className: "h-3.5 w-3.5 shrink-0 text-slate-400" }),
863
949
  /* @__PURE__ */ n(
864
950
  "input",
865
951
  {
866
- value: J,
867
- onChange: (e) => xe(e.target.value),
952
+ value: C,
953
+ onChange: (e) => ke(e.target.value),
868
954
  placeholder: "Search catalog…",
869
955
  className: "w-full bg-transparent text-[12px] outline-none placeholder:text-slate-400"
870
956
  }
871
957
  ),
872
958
  /* @__PURE__ */ c("span", { className: "shrink-0 rounded border border-slate-200 bg-slate-50 px-1.5 py-0.5 text-[10px] font-medium text-slate-500 dark:border-border dark:bg-muted dark:text-slate-400", children: [
873
- pr,
959
+ wr,
874
960
  " picked"
875
961
  ] })
876
962
  ] }),
877
- Rt && // Sticky: the catalog list is tall and the page scroller carries it —
963
+ Qt && // Sticky: the catalog list is tall and the page scroller carries it —
878
964
  // without this the labels scroll away and favorites/section rows
879
965
  // read as headerless columns. Opaque bg (not the /60 tint) so rows
880
966
  // never bleed through while pinned.
881
967
  /* @__PURE__ */ c(
882
968
  "div",
883
969
  {
884
- ref: dr,
970
+ ref: pr,
885
971
  className: "sticky top-0 z-[5] flex items-center gap-2 border-b border-slate-200 bg-slate-50 px-3 py-1 text-[10px] font-medium uppercase tracking-wide text-slate-400 dark:border-border dark:bg-muted",
886
972
  children: [
887
973
  l.favorites && /* @__PURE__ */ n("span", { className: "w-[18px] shrink-0" }),
888
974
  /* @__PURE__ */ n("span", { className: "w-36 shrink-0", children: "Item" }),
889
- ut.map((e) => /* @__PURE__ */ n(
975
+ xt.map((e) => /* @__PURE__ */ n(
890
976
  "span",
891
977
  {
892
978
  className: e.format ? "w-20 shrink-0 text-right" : "min-w-0 flex-1",
893
- children: e.label ?? te(e.field.split(".")[0])
979
+ children: e.label ?? re(e.field.split(".")[0])
894
980
  },
895
981
  e.field
896
982
  )),
897
- ft.map((e) => /* @__PURE__ */ n("span", { className: "w-20 shrink-0 text-right", children: e.label ?? te(e.key) }, e.key)),
983
+ gt.map((e) => /* @__PURE__ */ n("span", { className: "w-20 shrink-0 text-right", children: e.label ?? re(e.key) }, e.key)),
898
984
  /* @__PURE__ */ n("span", { className: "w-20 shrink-0 text-right", children: "Qty" })
899
985
  ]
900
986
  }
901
987
  ),
902
- J.trim().length > 0 && ve.length === 0 && it && /* @__PURE__ */ c("div", { className: "flex items-center justify-center gap-2 border-b border-slate-100 px-3 py-3 text-slate-400 dark:border-border/50", children: [
903
- /* @__PURE__ */ n(ae, { className: "h-3.5 w-3.5 animate-spin" }),
988
+ C.trim().length > 0 && qe.length === 0 && mt && /* @__PURE__ */ c("div", { className: "flex items-center justify-center gap-2 border-b border-slate-100 px-3 py-3 text-slate-400 dark:border-border/50", children: [
989
+ /* @__PURE__ */ n(oe, { className: "h-3.5 w-3.5 animate-spin" }),
904
990
  " Searching the catalog…"
905
991
  ] }),
906
- J.trim().length > 0 && ve.length === 0 && !it && /* @__PURE__ */ c("p", { className: "px-3 py-4 text-center text-slate-400", children: [
992
+ C.trim().length > 0 && qe.length === 0 && !mt && /* @__PURE__ */ c("p", { className: "px-3 py-4 text-center text-slate-400", children: [
907
993
  'No CIFAs match "',
908
- J.trim(),
994
+ C.trim(),
909
995
  '"'
910
996
  ] }),
911
- J.trim().length > 0 && ve.length > 0 && /* @__PURE__ */ c(Re, { children: [
997
+ C.trim().length > 0 && qe.length > 0 && /* @__PURE__ */ c(Ce, { children: [
912
998
  /* @__PURE__ */ c("div", { className: "flex w-full items-center gap-1.5 border-b border-t border-slate-200 bg-sky-50/70 px-2 py-1.5 dark:border-border dark:bg-sky-900/10", children: [
913
- /* @__PURE__ */ n(Xe, { className: "h-3 w-3 shrink-0 text-sky-500" }),
999
+ /* @__PURE__ */ n(st, { className: "h-3 w-3 shrink-0 text-sky-500" }),
914
1000
  /* @__PURE__ */ n("span", { className: "text-[11px] font-semibold text-slate-600 dark:text-slate-300", children: "Search results" }),
915
- /* @__PURE__ */ n("span", { className: "rounded border border-slate-200 bg-white px-1.5 py-0.5 text-[10px] font-medium text-slate-500 dark:border-border dark:bg-background dark:text-slate-400", children: ve.length }),
1001
+ /* @__PURE__ */ n("span", { className: "rounded border border-slate-200 bg-white px-1.5 py-0.5 text-[10px] font-medium text-slate-500 dark:border-border dark:bg-background dark:text-slate-400", children: qe.length }),
916
1002
  /* @__PURE__ */ n("span", { className: "text-[10px] text-slate-400", children: "across the entire catalog — enter a quantity to add" }),
917
- it && /* @__PURE__ */ n(ae, { className: "h-3 w-3 shrink-0 animate-spin text-slate-400" })
1003
+ mt && /* @__PURE__ */ n(oe, { className: "h-3 w-3 shrink-0 animate-spin text-slate-400" })
918
1004
  ] }),
919
- ve.map((e, t) => {
920
- const r = String(e.id), a = fe(r);
1005
+ qe.map((e, t) => {
1006
+ const r = String(e.id), s = be(r);
921
1007
  return /* @__PURE__ */ c(
922
1008
  "div",
923
1009
  {
924
- className: V(
1010
+ className: z(
925
1011
  "flex items-center gap-2 border-b border-slate-100 px-3 py-1 dark:border-border/50",
926
1012
  t % 2 === 0 ? "bg-white dark:bg-background" : "bg-slate-50/50 dark:bg-muted/30",
927
- (a ?? 0) > 0 && "bg-nvr-cyan/5"
1013
+ (s ?? 0) > 0 && "bg-nvr-cyan/5"
928
1014
  ),
929
1015
  children: [
930
- st(r),
931
- Ze(r, qe(F, e), ht),
932
- pt(r, e),
933
- se.has(r) && /* @__PURE__ */ n(ae, { className: "h-3 w-3 shrink-0 animate-spin text-slate-400" }),
934
- Ee(r, e)
1016
+ dt(r),
1017
+ tt(r, Fe(H, e), wt),
1018
+ kt(r, e),
1019
+ se.has(r) && /* @__PURE__ */ n(oe, { className: "h-3 w-3 shrink-0 animate-spin text-slate-400" }),
1020
+ Ae(r, e)
935
1021
  ]
936
1022
  },
937
1023
  r
938
1024
  );
939
1025
  })
940
1026
  ] }),
941
- ce.length > 0 && !J.trim() && /* @__PURE__ */ c("p", { className: "px-3 py-6 text-center text-slate-400", children: [
1027
+ xe.length > 0 && !C.trim() && /* @__PURE__ */ c("p", { className: "px-3 py-6 text-center text-slate-400", children: [
942
1028
  "Search the full catalog above, or select",
943
1029
  " ",
944
- ce.map((e) => {
1030
+ xe.map((e) => {
945
1031
  var t;
946
- return ((t = R == null ? void 0 : R.fieldLabels) == null ? void 0 : t[e]) ?? te(e);
1032
+ return ((t = L == null ? void 0 : L.fieldLabels) == null ? void 0 : t[e]) ?? re(e);
947
1033
  }).join(", "),
948
1034
  " ",
949
1035
  "to browse by category"
950
1036
  ] }),
951
- ce.length === 0 && (Fe || Y) && /* @__PURE__ */ c("div", { className: "flex items-center justify-center gap-2 py-6 text-slate-400", children: [
952
- /* @__PURE__ */ n(ae, { className: "h-4 w-4 animate-spin" }),
1037
+ xe.length === 0 && (ie || De) && /* @__PURE__ */ c("div", { className: "flex items-center justify-center gap-2 py-6 text-slate-400", children: [
1038
+ /* @__PURE__ */ n(oe, { className: "h-4 w-4 animate-spin" }),
953
1039
  " Loading catalog…"
954
1040
  ] }),
955
- ce.length === 0 && !Fe && !Y && Ge.length === 0 && /* @__PURE__ */ n("p", { className: "px-3 py-6 text-center text-slate-400", children: "No catalog items" }),
956
- l.favorites && /* @__PURE__ */ c(Re, { children: [
1041
+ xe.length === 0 && !ie && !De && rt.length === 0 && /* @__PURE__ */ n("p", { className: "px-3 py-6 text-center text-slate-400", children: "No catalog items" }),
1042
+ l.favorites && /* @__PURE__ */ c(Ce, { children: [
957
1043
  /* @__PURE__ */ c("div", { className: "flex w-full items-center gap-1.5 border-b border-slate-200 bg-amber-50/70 px-2 py-1 dark:border-border dark:bg-amber-900/10", children: [
958
1044
  /* @__PURE__ */ c(
959
1045
  "button",
@@ -966,82 +1052,82 @@ function en({
966
1052
  className: "flex min-w-0 flex-1 items-center gap-1.5 py-0.5 text-left",
967
1053
  children: [
968
1054
  /* @__PURE__ */ n(
969
- Nt,
1055
+ qt,
970
1056
  {
971
- className: V(
1057
+ className: z(
972
1058
  "h-3 w-3 shrink-0 text-slate-400 transition-transform",
973
- !de.has("__favorites__") && "rotate-90"
1059
+ !ce.has("__favorites__") && "rotate-90"
974
1060
  )
975
1061
  }
976
1062
  ),
977
- /* @__PURE__ */ n(Ke, { className: "h-3 w-3 shrink-0 fill-amber-400 text-amber-400" }),
1063
+ /* @__PURE__ */ n(Qe, { className: "h-3 w-3 shrink-0 fill-amber-400 text-amber-400" }),
978
1064
  /* @__PURE__ */ n("span", { className: "text-[11px] font-semibold text-slate-600 dark:text-slate-300", children: "Favorites" }),
979
- /* @__PURE__ */ n("span", { className: "rounded border border-slate-200 bg-white px-1.5 py-0.5 text-[10px] font-medium text-slate-500 dark:border-border dark:bg-background dark:text-slate-400", children: Oe.length })
1065
+ /* @__PURE__ */ n("span", { className: "rounded border border-slate-200 bg-white px-1.5 py-0.5 text-[10px] font-medium text-slate-500 dark:border-border dark:bg-background dark:text-slate-400", children: Re.length })
980
1066
  ]
981
1067
  }
982
1068
  ),
983
1069
  /* @__PURE__ */ n(
984
1070
  "button",
985
1071
  {
986
- ref: jt,
1072
+ ref: Rt,
987
1073
  type: "button",
988
- onClick: () => $t(!0),
1074
+ onClick: () => Pt(!0),
989
1075
  className: "shrink-0 rounded border border-amber-200 bg-white px-2 py-0.5 text-[10px] font-semibold text-amber-700 transition-colors hover:border-amber-300 hover:bg-amber-50 dark:border-amber-400/30 dark:bg-transparent dark:text-amber-300 dark:hover:bg-amber-400/10",
990
1076
  children: "Manage"
991
1077
  }
992
1078
  )
993
1079
  ] }),
994
- !de.has("__favorites__") && Oe.length === 0 && /* @__PURE__ */ n("p", { className: "border-b border-slate-100 px-3 py-2 text-center text-[11px] text-slate-400 dark:border-border/50", children: "No favorites yet — Manage lets you search the full catalog and star items." }),
995
- !de.has("__favorites__") && Oe.map((e, t) => {
996
- const r = String(e.id), a = fe(r), d = ot(r);
1080
+ !ce.has("__favorites__") && Re.length === 0 && /* @__PURE__ */ n("p", { className: "border-b border-slate-100 px-3 py-2 text-center text-[11px] text-slate-400 dark:border-border/50", children: "No favorites yet — Manage lets you search the full catalog and star items." }),
1081
+ !ce.has("__favorites__") && Re.map((e, t) => {
1082
+ const r = String(e.id), s = be(r), m = ft(r);
997
1083
  return /* @__PURE__ */ c(
998
1084
  "div",
999
1085
  {
1000
- className: V(
1086
+ className: z(
1001
1087
  "flex items-center gap-2 border-b border-slate-100 px-3 py-1 dark:border-border/50",
1002
1088
  t % 2 === 0 ? "bg-white dark:bg-background" : "bg-slate-50/50 dark:bg-muted/30",
1003
- (a ?? 0) > 0 && "bg-nvr-cyan/5",
1004
- d && "bg-amber-50 dark:bg-amber-900/15"
1089
+ (s ?? 0) > 0 && "bg-nvr-cyan/5",
1090
+ m && "bg-amber-50 dark:bg-amber-900/15"
1005
1091
  ),
1006
1092
  children: [
1007
- st(r),
1008
- Ze(r, qe(F, e), ht),
1009
- pt(r, e),
1010
- d && /* @__PURE__ */ n(
1011
- Ce,
1093
+ dt(r),
1094
+ tt(r, Fe(H, e), wt),
1095
+ kt(r, e),
1096
+ m && /* @__PURE__ */ n(
1097
+ Je,
1012
1098
  {
1013
1099
  className: "h-3.5 w-3.5 shrink-0 text-amber-500",
1014
- "aria-label": `${dt} ${d.available} — ${d.qty} requested`
1100
+ "aria-label": `${bt} ${m.available} — ${m.qty} requested`
1015
1101
  }
1016
1102
  ),
1017
- se.has(r) && /* @__PURE__ */ n(ae, { className: "h-3 w-3 shrink-0 animate-spin text-slate-400" }),
1018
- Ee(r, e)
1103
+ se.has(r) && /* @__PURE__ */ n(oe, { className: "h-3 w-3 shrink-0 animate-spin text-slate-400" }),
1104
+ Ae(r, e)
1019
1105
  ]
1020
1106
  },
1021
1107
  r
1022
1108
  );
1023
1109
  })
1024
1110
  ] }),
1025
- ce.length === 0 && Ge.map((e) => {
1026
- const t = de.has(e.name), r = e.items.reduce(
1027
- (a, d) => a + ((fe(d.id) ?? 0) > 0 ? 1 : 0),
1111
+ xe.length === 0 && rt.map((e) => {
1112
+ const t = ce.has(e.name), r = e.items.reduce(
1113
+ (s, m) => s + ((be(m.id) ?? 0) > 0 ? 1 : 0),
1028
1114
  0
1029
1115
  );
1030
- return /* @__PURE__ */ c(Re, { children: [
1116
+ return /* @__PURE__ */ c(Ce, { children: [
1031
1117
  /* @__PURE__ */ c(
1032
1118
  "button",
1033
1119
  {
1034
1120
  type: "button",
1035
- onClick: () => ne((a) => {
1036
- const d = new Set(a);
1037
- return d.has(e.name) ? d.delete(e.name) : d.add(e.name), d;
1121
+ onClick: () => ne((s) => {
1122
+ const m = new Set(s);
1123
+ return m.has(e.name) ? m.delete(e.name) : m.add(e.name), m;
1038
1124
  }),
1039
1125
  className: "flex w-full items-center gap-1.5 border-b border-slate-200 bg-slate-100/80 px-2 py-1.5 text-left dark:border-border dark:bg-muted",
1040
1126
  children: [
1041
1127
  /* @__PURE__ */ n(
1042
- Nt,
1128
+ qt,
1043
1129
  {
1044
- className: V(
1130
+ className: z(
1045
1131
  "h-3 w-3 shrink-0 text-slate-400 transition-transform",
1046
1132
  !t && "rotate-90"
1047
1133
  )
@@ -1056,48 +1142,48 @@ function en({
1056
1142
  ]
1057
1143
  }
1058
1144
  ),
1059
- !t && e.items.map((a, d) => {
1060
- const o = fe(a.id), s = ot(a.id);
1145
+ !t && e.items.map((s, m) => {
1146
+ const o = be(s.id), i = ft(s.id);
1061
1147
  return /* @__PURE__ */ c(
1062
1148
  "div",
1063
1149
  {
1064
- className: V(
1150
+ className: z(
1065
1151
  "flex items-center gap-2 border-b border-slate-100 px-3 py-1 dark:border-border/50",
1066
- d % 2 === 0 ? "bg-white dark:bg-background" : "bg-slate-50/50 dark:bg-muted/30",
1152
+ m % 2 === 0 ? "bg-white dark:bg-background" : "bg-slate-50/50 dark:bg-muted/30",
1067
1153
  (o ?? 0) > 0 && "bg-nvr-cyan/5",
1068
- s && "bg-amber-50 dark:bg-amber-900/15"
1154
+ i && "bg-amber-50 dark:bg-amber-900/15"
1069
1155
  ),
1070
1156
  children: [
1071
- st(a.id),
1072
- Ze(a.id, a.label, ht),
1073
- pt(a.id, a.row),
1074
- s && /* @__PURE__ */ n(
1075
- Ce,
1157
+ dt(s.id),
1158
+ tt(s.id, s.label, wt),
1159
+ kt(s.id, s.row),
1160
+ i && /* @__PURE__ */ n(
1161
+ Je,
1076
1162
  {
1077
1163
  className: "h-3.5 w-3.5 shrink-0 text-amber-500",
1078
- "aria-label": `${dt} ${s.available} — ${s.qty} requested`
1164
+ "aria-label": `${bt} ${i.available} — ${i.qty} requested`
1079
1165
  }
1080
1166
  ),
1081
- se.has(a.id) && /* @__PURE__ */ n(ae, { className: "h-3 w-3 shrink-0 animate-spin text-slate-400" }),
1082
- Ee(a.id, a.row)
1167
+ se.has(s.id) && /* @__PURE__ */ n(oe, { className: "h-3 w-3 shrink-0 animate-spin text-slate-400" }),
1168
+ Ae(s.id, s.row)
1083
1169
  ]
1084
1170
  },
1085
- a.id
1171
+ s.id
1086
1172
  );
1087
1173
  })
1088
1174
  ] }, e.name);
1089
1175
  })
1090
1176
  ] }),
1091
- (l.builders ?? []).filter((e) => Ut(e.show_when, X)).map((e) => /* @__PURE__ */ n(
1092
- Pr,
1177
+ (l.builders ?? []).filter((e) => Yt(e.show_when, ee)).map((e) => /* @__PURE__ */ n(
1178
+ Dr,
1093
1179
  {
1094
1180
  builder: e,
1095
1181
  defaultItemField: l.item_field,
1096
1182
  catalogCol: b,
1097
- catalogFields: ee,
1098
- tmpl: F,
1099
- qtyInput: Ee,
1100
- currentQty: fe
1183
+ catalogFields: a,
1184
+ tmpl: H,
1185
+ qtyInput: Ae,
1186
+ currentQty: be
1101
1187
  },
1102
1188
  e.label
1103
1189
  ))
@@ -1105,9 +1191,9 @@ function en({
1105
1191
  /* @__PURE__ */ c("div", { className: "rounded-lg border border-slate-200 text-[12px] dark:border-border", children: [
1106
1192
  /* @__PURE__ */ c("div", { className: "flex items-center justify-between gap-2 border-b border-slate-200 bg-slate-50 px-3 py-2 dark:border-border dark:bg-muted", children: [
1107
1193
  /* @__PURE__ */ n("span", { className: "text-[11px] font-semibold text-slate-600 dark:text-slate-300", children: "Summary" }),
1108
- !h && /* @__PURE__ */ c("div", { className: "flex items-center gap-2", onClick: (e) => e.stopPropagation(), children: [
1109
- l.upload_template && !K && Z && q && /* @__PURE__ */ n(
1110
- jr,
1194
+ !x && /* @__PURE__ */ c("div", { className: "flex items-center gap-2", onClick: (e) => e.stopPropagation(), children: [
1195
+ l.upload_template && !A && Z && q && /* @__PURE__ */ n(
1196
+ Rr,
1111
1197
  {
1112
1198
  collection: q,
1113
1199
  templateFilter: (e) => {
@@ -1123,255 +1209,265 @@ function en({
1123
1209
  }
1124
1210
  ),
1125
1211
  /* @__PURE__ */ n("div", { className: "w-64", children: /* @__PURE__ */ n(
1126
- Or,
1212
+ Br,
1127
1213
  {
1128
1214
  collection: b,
1129
1215
  value: null,
1130
- onChange: (e) => void br(e),
1216
+ onChange: (e) => void kr(e),
1131
1217
  placeholder: "+ Add any item…"
1132
1218
  }
1133
1219
  ) })
1134
1220
  ] })
1135
1221
  ] }),
1136
- oe.length === 0 ? /* @__PURE__ */ n("p", { className: "px-3 py-4 text-center text-slate-400", children: "Nothing picked yet" }) : (() => {
1137
- const e = Pt.filter((s) => !s.format), t = e[0], r = e.slice(1), a = Pt.filter((s) => !!s.format), d = (s, u) => u === "presence" ? s == null || s === "" || Number(s) === 0 ? "No" : "Yes" : s === !0 || s === "true" ? "✓" : s === !1 || s === "false" || s == null || s === "" ? "—" : ue(s, u), o = (s) => /* @__PURE__ */ n("span", { className: "w-20 shrink-0 text-right text-[11px] font-medium text-slate-500", children: s });
1222
+ de.length === 0 ? /* @__PURE__ */ n("p", { className: "px-3 py-4 text-center text-slate-400", children: "Nothing picked yet" }) : (() => {
1223
+ const e = Kt.filter((i) => !i.format), t = e[0], r = e.slice(1), s = Kt.filter((i) => !!i.format), m = (i, y) => y === "presence" ? i == null || i === "" || Number(i) === 0 ? "No" : "Yes" : i === !0 || i === "true" ? "✓" : i === !1 || i === "false" || i == null || i === "" ? "—" : fe(i, y), o = (i) => /* @__PURE__ */ n("span", { className: "w-20 shrink-0 text-right text-[11px] font-medium text-slate-500", children: i });
1138
1224
  return /* @__PURE__ */ c("div", { children: [
1139
1225
  /* @__PURE__ */ c("div", { className: "flex items-center gap-2 border-b border-slate-200 px-3 py-1.5 dark:border-border", children: [
1140
1226
  /* @__PURE__ */ n("span", { className: "flex-1 text-[11px] font-medium text-slate-500", children: "Item" }),
1141
- gt.map((s) => /* @__PURE__ */ n(Re, { children: o(te(s)) }, s)),
1142
- o(te(D)),
1143
- yt.map((s) => /* @__PURE__ */ n(Re, { children: o(te(s)) }, s)),
1144
- !h && /* @__PURE__ */ n("span", { className: "w-6 shrink-0" })
1227
+ Nt.map((i) => /* @__PURE__ */ n(Ce, { children: o(re(i)) }, i)),
1228
+ o(re(V)),
1229
+ vt.map((i) => /* @__PURE__ */ n(Ce, { children: o(re(i)) }, i)),
1230
+ !x && /* @__PURE__ */ n("span", { className: "w-6 shrink-0" })
1145
1231
  ] }),
1146
- oe.map((s, u) => {
1147
- const N = s.row.id != null ? String(s.row.id) : null, k = N != null && Ue.has(N), v = k ? null : ot(s.key), _ = k ? null : nr(s.key);
1232
+ de.map((i, y) => {
1233
+ const d = i.row.id != null ? String(i.row.id) : null, f = d != null && We.has(d), N = f ? null : ft(i.key), T = f ? null : dr(i.key);
1148
1234
  return /* @__PURE__ */ c(
1149
1235
  "div",
1150
1236
  {
1151
- className: V(
1237
+ className: z(
1152
1238
  "border-b border-slate-100 px-3 py-2 last:border-b-0 dark:border-border/50",
1153
- u % 2 === 0 ? "bg-white dark:bg-background" : "bg-slate-50/50 dark:bg-muted/30",
1154
- v && "bg-amber-50 dark:bg-amber-900/15",
1155
- _ && "bg-red-50/70 dark:bg-red-900/15",
1156
- k && "opacity-60"
1239
+ y % 2 === 0 ? "bg-white dark:bg-background" : "bg-slate-50/50 dark:bg-muted/30",
1240
+ N && "bg-amber-50 dark:bg-amber-900/15",
1241
+ T && "bg-red-50/70 dark:bg-red-900/15",
1242
+ f && "opacity-60"
1157
1243
  ),
1158
1244
  children: [
1159
1245
  /* @__PURE__ */ c(
1160
1246
  "div",
1161
1247
  {
1162
- className: V(
1248
+ className: z(
1163
1249
  "flex items-center gap-2",
1164
- k && "line-through decoration-slate-400"
1250
+ f && "line-through decoration-slate-400"
1165
1251
  ),
1166
1252
  children: [
1167
- Ze(
1168
- s.key,
1169
- Ct(s.key),
1253
+ tt(
1254
+ i.key,
1255
+ Bt(i.key),
1170
1256
  "shrink-0 font-semibold text-slate-800 dark:text-slate-100"
1171
1257
  ),
1172
- Te && !k && (N == null || Qe.has(N)) && /* @__PURE__ */ n(
1258
+ Pe && !f && (d == null || He.has(d)) && /* @__PURE__ */ n(
1173
1259
  "span",
1174
1260
  {
1175
- "data-catalog-staged": N == null ? "new" : "edited",
1261
+ "data-catalog-staged": d == null ? "new" : "edited",
1176
1262
  "data-tip": "Applies when you save the record",
1177
1263
  className: "shrink-0 rounded bg-amber-100 px-1.5 py-px text-[10px] font-semibold text-amber-800 dark:bg-amber-400/15 dark:text-amber-300",
1178
- children: N == null ? "New" : "Edited"
1264
+ children: d == null ? "New" : "Edited"
1179
1265
  }
1180
1266
  ),
1181
- _ && /* @__PURE__ */ n(
1267
+ T && /* @__PURE__ */ n(
1182
1268
  "span",
1183
1269
  {
1184
1270
  className: "shrink-0",
1185
1271
  "data-tip": `This line was in the failed submission
1186
- ${_}`,
1272
+ ${T}`,
1187
1273
  "data-submission-error": !0,
1188
- children: /* @__PURE__ */ n(xr, { className: "h-3.5 w-3.5 text-red-500", strokeWidth: 2 })
1274
+ children: /* @__PURE__ */ n(Mt, { className: "h-3.5 w-3.5 text-red-500", strokeWidth: 2 })
1189
1275
  }
1190
1276
  ),
1191
1277
  t && /* @__PURE__ */ n(
1192
1278
  "span",
1193
1279
  {
1194
1280
  className: "min-w-0 flex-1 truncate text-slate-600 dark:text-slate-300",
1195
- title: String(Le(_e(s.key), t.field) ?? ""),
1196
- children: ue(Le(_e(s.key), t.field), void 0)
1281
+ title: String(Le($e(i.key), t.field) ?? ""),
1282
+ children: fe(Le($e(i.key), t.field), void 0)
1197
1283
  }
1198
1284
  ),
1199
1285
  !t && /* @__PURE__ */ n("span", { className: "flex-1" }),
1200
- r.map((g) => {
1201
- const C = Le(_e(s.key), g.field);
1202
- return C == null || C === "" ? null : /* @__PURE__ */ n(
1286
+ r.map((k) => {
1287
+ const S = Le($e(i.key), k.field);
1288
+ return S == null || S === "" ? null : /* @__PURE__ */ n(
1203
1289
  "span",
1204
1290
  {
1205
1291
  className: "shrink-0 rounded bg-slate-100 px-1.5 py-0.5 text-[10.5px] font-medium text-slate-600 dark:bg-muted dark:text-slate-300",
1206
- children: String(C)
1292
+ children: String(S)
1207
1293
  },
1208
- g.field
1294
+ k.field
1209
1295
  );
1210
1296
  }),
1211
- gt.map(
1212
- (g) => {
1213
- var C;
1214
- return U.includes(g) && !h ? /* @__PURE__ */ n(
1297
+ Nt.map(
1298
+ (k) => {
1299
+ var S;
1300
+ return B.includes(k) && !x ? /* @__PURE__ */ n(
1215
1301
  "input",
1216
1302
  {
1217
1303
  type: "number",
1218
1304
  min: 0,
1219
1305
  step: "any",
1220
- defaultValue: s.row[g] == null ? "" : String(s.row[g]),
1221
- onBlur: ($e) => void fr(s.key, g, $e.target.value),
1222
- onKeyDown: ($e) => {
1223
- $e.key === "Enter" && $e.currentTarget.blur();
1306
+ defaultValue: i.row[k] == null ? "" : String(i.row[k]),
1307
+ onBlur: (le) => void yr(i.key, k, le.target.value),
1308
+ onKeyDown: (le) => {
1309
+ le.key === "Enter" && le.currentTarget.blur();
1224
1310
  },
1225
1311
  className: "h-7 w-20 shrink-0 rounded border border-slate-200 bg-white px-2 text-right text-[12px] outline-none focus:border-nvr-cyan dark:border-border dark:bg-background"
1226
1312
  },
1227
- `${s.key}:${g}:${String(s.row[g] ?? "")}`
1313
+ `${i.key}:${k}:${String(i.row[k] ?? "")}`
1228
1314
  ) : /* @__PURE__ */ n(
1229
1315
  "span",
1230
1316
  {
1231
1317
  className: "w-20 shrink-0 text-right tabular-nums text-slate-600 dark:text-slate-300",
1232
- children: ue(s.row[g], (C = l.field_formats) == null ? void 0 : C[g])
1318
+ children: fe(i.row[k], (S = l.field_formats) == null ? void 0 : S[k])
1233
1319
  },
1234
- g
1320
+ k
1235
1321
  );
1236
1322
  }
1237
1323
  ),
1238
1324
  /* @__PURE__ */ c("span", { className: "inline-flex w-20 shrink-0 items-center justify-end gap-1", children: [
1239
- se.has(s.key) && /* @__PURE__ */ n(ae, { className: "h-3 w-3 animate-spin text-slate-400" }),
1240
- Ee(s.key, _e(s.key))
1325
+ se.has(i.key) && /* @__PURE__ */ n(oe, { className: "h-3 w-3 animate-spin text-slate-400" }),
1326
+ Ae(i.key, $e(i.key))
1241
1327
  ] }),
1242
- yt.map((g) => {
1243
- var zt, Bt;
1244
- const C = s.row[g], $e = C != null && C !== "" ? C : Ae(((zt = l.compute_fields) == null ? void 0 : zt[g]) ?? "", s.row);
1328
+ vt.map((k) => {
1329
+ var _e, Ht;
1330
+ if (f)
1331
+ return /* @__PURE__ */ n(
1332
+ "span",
1333
+ {
1334
+ "data-tip": "Not counted — this line is removed when you save",
1335
+ className: "w-20 shrink-0 text-right tabular-nums text-slate-400 dark:text-slate-500",
1336
+ children: "—"
1337
+ },
1338
+ k
1339
+ );
1340
+ const S = i.row[k], le = S != null && S !== "" ? S : Ke(((_e = l.compute_fields) == null ? void 0 : _e[k]) ?? "", i.row);
1245
1341
  return /* @__PURE__ */ n(
1246
1342
  "span",
1247
1343
  {
1248
1344
  className: "w-20 shrink-0 text-right tabular-nums text-slate-600 dark:text-slate-300",
1249
- children: ue($e, (Bt = l.field_formats) == null ? void 0 : Bt[g])
1345
+ children: fe(le, (Ht = l.field_formats) == null ? void 0 : Ht[k])
1250
1346
  },
1251
- g
1347
+ k
1252
1348
  );
1253
1349
  }),
1254
- !h && k && /* @__PURE__ */ n(
1350
+ !x && f && /* @__PURE__ */ n(
1255
1351
  "button",
1256
1352
  {
1257
1353
  type: "button",
1258
- onClick: () => f == null ? void 0 : f.cancelPendingDelete(m, x, N),
1354
+ onClick: () => p == null ? void 0 : p.cancelPendingDelete(u, g, d),
1259
1355
  className: "shrink-0 rounded px-1.5 py-0.5 text-[11px] font-medium text-nvr-navy underline dark:text-nvr-cyan",
1260
1356
  children: "Undo"
1261
1357
  }
1262
1358
  ),
1263
- !h && !k && /* @__PURE__ */ n(
1359
+ !x && !f && /* @__PURE__ */ n(
1264
1360
  "button",
1265
1361
  {
1266
1362
  type: "button",
1267
1363
  title: "Remove (applies on Save)",
1268
1364
  onClick: () => {
1269
- if (!K && f && N != null) {
1270
- f.queueDelete(m, x, N);
1365
+ if (!A && p && d != null) {
1366
+ p.queueDelete(u, g, d);
1271
1367
  return;
1272
1368
  }
1273
- xt(s.key, "0", {});
1369
+ nt(i.key, "0", {}, { confirmedRemove: !0 });
1274
1370
  },
1275
1371
  className: "w-6 shrink-0 rounded p-0.5 text-slate-300 transition-colors hover:text-red-500",
1276
- children: /* @__PURE__ */ n(et, { className: "mx-auto h-3.5 w-3.5" })
1372
+ children: /* @__PURE__ */ n(at, { className: "mx-auto h-3.5 w-3.5" })
1277
1373
  }
1278
1374
  )
1279
1375
  ]
1280
1376
  }
1281
1377
  ),
1282
- (a.length > 0 || Et.length > 0 || Ye.length > 0) && /* @__PURE__ */ c("div", { className: "mt-1 flex flex-wrap items-baseline gap-x-4 gap-y-0.5 pl-0.5 text-[11px]", children: [
1283
- a.map((g) => /* @__PURE__ */ c("span", { className: "whitespace-nowrap", children: [
1284
- /* @__PURE__ */ n("span", { className: "text-slate-500 dark:text-muted-foreground", children: g.label ?? te(g.field.split(".")[0]) }),
1378
+ (s.length > 0 || Jt.length > 0 || et.length > 0) && /* @__PURE__ */ c("div", { className: "mt-1 flex flex-wrap items-baseline gap-x-4 gap-y-0.5 pl-0.5 text-[11px]", children: [
1379
+ s.map((k) => /* @__PURE__ */ c("span", { className: "whitespace-nowrap", children: [
1380
+ /* @__PURE__ */ n("span", { className: "text-slate-500 dark:text-muted-foreground", children: k.label ?? re(k.field.split(".")[0]) }),
1285
1381
  " ",
1286
- /* @__PURE__ */ n("span", { className: "font-medium tabular-nums text-slate-700 dark:text-slate-200", children: d(Le(_e(s.key), g.field), g.format) })
1287
- ] }, g.field)),
1288
- Et.map((g) => /* @__PURE__ */ c("span", { className: "whitespace-nowrap", children: [
1289
- /* @__PURE__ */ n("span", { className: "text-slate-500 dark:text-muted-foreground", children: g.label ?? te(g.key) }),
1382
+ /* @__PURE__ */ n("span", { className: "font-medium tabular-nums text-slate-700 dark:text-slate-200", children: m(Le($e(i.key), k.field), k.format) })
1383
+ ] }, k.field)),
1384
+ Jt.map((k) => /* @__PURE__ */ c("span", { className: "whitespace-nowrap", children: [
1385
+ /* @__PURE__ */ n("span", { className: "text-slate-500 dark:text-muted-foreground", children: k.label ?? re(k.key) }),
1290
1386
  " ",
1291
- /* @__PURE__ */ n("span", { className: "font-medium tabular-nums text-slate-700 dark:text-slate-200", children: d(lt(g.key, s.key), g.format) })
1292
- ] }, g.key)),
1293
- or(s.row),
1294
- Xt(s.row).map((g) => /* @__PURE__ */ c(
1387
+ /* @__PURE__ */ n("span", { className: "font-medium tabular-nums text-slate-700 dark:text-slate-200", children: m(ut(k.key, i.key), k.format) })
1388
+ ] }, k.key)),
1389
+ br(i.row),
1390
+ ar(i.row).map((k) => /* @__PURE__ */ c(
1295
1391
  "span",
1296
1392
  {
1297
1393
  className: "inline-flex items-center gap-1 whitespace-nowrap rounded bg-amber-50 px-1.5 py-px text-[10.5px] font-medium text-amber-700 dark:bg-amber-500/10 dark:text-amber-300",
1298
- "data-catalog-row-flag": g,
1394
+ "data-catalog-row-flag": k,
1299
1395
  children: [
1300
- /* @__PURE__ */ n(Ce, { className: "h-3 w-3" }),
1301
- g
1396
+ /* @__PURE__ */ n(Je, { className: "h-3 w-3" }),
1397
+ k
1302
1398
  ]
1303
1399
  },
1304
- g
1400
+ k
1305
1401
  )),
1306
- Ye.map((g) => {
1307
- const C = ir(g, s);
1402
+ et.map((k) => {
1403
+ const S = ur(k, i);
1308
1404
  return /* @__PURE__ */ c("span", { className: "whitespace-nowrap", children: [
1309
- /* @__PURE__ */ n("span", { className: "text-slate-500 dark:text-muted-foreground", children: g.label ?? te(g.field) }),
1405
+ /* @__PURE__ */ n("span", { className: "text-slate-500 dark:text-muted-foreground", children: k.label ?? re(k.field) }),
1310
1406
  " ",
1311
- /* @__PURE__ */ n("span", { className: "font-medium text-slate-700 dark:text-slate-200", children: d(C, g.format) })
1312
- ] }, g.field);
1407
+ /* @__PURE__ */ n("span", { className: "font-medium text-slate-700 dark:text-slate-200", children: m(S, k.format) })
1408
+ ] }, k.field);
1313
1409
  })
1314
1410
  ] }),
1315
- v && /* @__PURE__ */ c("p", { className: "mt-1 flex items-center gap-1 pl-0.5 text-[11px] font-medium text-amber-600 dark:text-amber-400", children: [
1316
- /* @__PURE__ */ n(Ce, { className: "h-3 w-3 shrink-0" }),
1317
- dt,
1411
+ N && /* @__PURE__ */ c("p", { className: "mt-1 flex items-center gap-1 pl-0.5 text-[11px] font-medium text-amber-600 dark:text-amber-400", children: [
1412
+ /* @__PURE__ */ n(Je, { className: "h-3 w-3 shrink-0" }),
1413
+ bt,
1318
1414
  " is ",
1319
- ue(v.available, "number"),
1415
+ fe(N.available, "number"),
1320
1416
  " —",
1321
1417
  " ",
1322
- ue(v.qty, "number"),
1418
+ fe(N.qty, "number"),
1323
1419
  " requested"
1324
1420
  ] }),
1325
- k && /* @__PURE__ */ n("p", { className: "mt-1 pl-0.5 text-[11px] text-red-500", children: "Removed — applies when you save" })
1421
+ f && /* @__PURE__ */ n("p", { className: "mt-1 pl-0.5 text-[11px] text-red-500", children: "Removed — applies when you save" })
1326
1422
  ]
1327
1423
  },
1328
- s.key
1424
+ i.key
1329
1425
  );
1330
1426
  }),
1331
1427
  (() => {
1332
- const s = oe.filter((v) => {
1333
- const _ = v.row.id != null ? String(v.row.id) : null;
1334
- return !(_ != null && Ue.has(_));
1335
- }), u = (v) => s.reduce((_, g) => {
1336
- const C = Number(g.row[v]);
1337
- return _ + (Number.isFinite(C) ? C : 0);
1338
- }, 0), N = (v) => {
1339
- var _;
1340
- return ((_ = l.field_formats) == null ? void 0 : _[v]) ?? "number";
1341
- }, k = (v) => /* @__PURE__ */ n(
1428
+ const i = de.filter((N) => {
1429
+ const T = N.row.id != null ? String(N.row.id) : null;
1430
+ return !(T != null && We.has(T));
1431
+ }), y = (N) => i.reduce((T, k) => {
1432
+ const S = Number(k.row[N]);
1433
+ return T + (Number.isFinite(S) ? S : 0);
1434
+ }, 0), d = (N) => {
1435
+ var T;
1436
+ return ((T = l.field_formats) == null ? void 0 : T[N]) ?? "number";
1437
+ }, f = (N) => /* @__PURE__ */ n(
1342
1438
  "span",
1343
1439
  {
1344
1440
  className: "w-20 shrink-0 text-right text-[12px] font-semibold tabular-nums text-slate-800 dark:text-slate-100",
1345
- children: ue(u(v), N(v))
1441
+ children: fe(y(N), d(N))
1346
1442
  },
1347
- v
1443
+ N
1348
1444
  );
1349
1445
  return /* @__PURE__ */ c("div", { className: "flex items-center gap-2 border-t border-slate-200 bg-slate-50 px-3 py-1.5 dark:border-border dark:bg-muted/40", children: [
1350
1446
  /* @__PURE__ */ n("span", { className: "flex-1 text-[11px] font-semibold uppercase tracking-wide text-slate-500", children: "Total" }),
1351
- gt.map((v) => /* @__PURE__ */ n("span", { className: "w-20 shrink-0" }, v)),
1352
- /* @__PURE__ */ n("span", { className: "w-20 shrink-0 text-right text-[12px] font-semibold tabular-nums text-slate-800 dark:text-slate-100", children: ue(u(D), "number") }),
1353
- yt.map(k),
1354
- !h && /* @__PURE__ */ n("span", { className: "w-6 shrink-0" })
1447
+ Nt.map((N) => /* @__PURE__ */ n("span", { className: "w-20 shrink-0" }, N)),
1448
+ /* @__PURE__ */ n("span", { className: "w-20 shrink-0 text-right text-[12px] font-semibold tabular-nums text-slate-800 dark:text-slate-100", children: fe(y(V), "number") }),
1449
+ vt.map(f),
1450
+ !x && /* @__PURE__ */ n("span", { className: "w-6 shrink-0" })
1355
1451
  ] });
1356
1452
  })()
1357
1453
  ] });
1358
1454
  })()
1359
1455
  ] }),
1360
- Wt && b && /* @__PURE__ */ n(
1361
- Rr,
1456
+ tr && b && /* @__PURE__ */ n(
1457
+ Hr,
1362
1458
  {
1363
1459
  catalogCol: b,
1364
- tmpl: F,
1460
+ tmpl: H,
1365
1461
  sectionBy: l.section_by,
1366
- sectionM2M: A,
1367
- pinnedSet: nt,
1368
- pinnedIds: pe,
1369
- savingIds: Ie,
1462
+ sectionM2M: Q,
1463
+ pinnedSet: ot,
1464
+ pinnedIds: ge,
1465
+ savingIds: Ze,
1370
1466
  relatedCols: (l.favorites_manager_columns ?? []).map((e) => (l.related_columns ?? []).find((t) => t.key === e)).filter((e) => !!e),
1371
- parentDraft: X,
1372
- onToggle: (e) => void qt(e),
1373
- onClose: () => $t(!1),
1374
- anchor: jt.current
1467
+ parentDraft: ee,
1468
+ onToggle: (e) => void Ot(e),
1469
+ onClose: () => Pt(!1),
1470
+ anchor: Rt.current
1375
1471
  }
1376
1472
  )
1377
1473
  ] }) : /* @__PURE__ */ c("p", { className: "py-1 text-[12px] text-slate-400", children: [
@@ -1379,72 +1475,72 @@ ${_}`,
1379
1475
  l.item_field,
1380
1476
  '" does not resolve to an M2O relation on',
1381
1477
  " ",
1382
- m
1478
+ u
1383
1479
  ] });
1384
1480
  }
1385
- function Pr({
1386
- builder: m,
1387
- defaultItemField: x,
1388
- catalogCol: S,
1481
+ function Dr({
1482
+ builder: u,
1483
+ defaultItemField: g,
1484
+ catalogCol: _,
1389
1485
  catalogFields: q,
1390
1486
  tmpl: l,
1391
- qtyInput: h,
1392
- currentQty: p
1487
+ qtyInput: x,
1488
+ currentQty: h
1393
1489
  }) {
1394
- const $ = vt(), f = m.item_field ?? x, [R, Z] = re(!1), [U, K] = re({}), D = P(
1490
+ const $ = $t(), p = u.item_field ?? g, [L, Z] = Y(!1), [B, A] = Y({}), V = O(
1395
1491
  () => [
1396
1492
  "id",
1397
- f,
1398
- ...m.attributes.flatMap((w) => [`${w.field}.id`, `${w.field}.${w.label_field}`])
1493
+ p,
1494
+ ...u.attributes.flatMap((v) => [`${v.field}.id`, `${v.field}.${v.label_field}`])
1399
1495
  ].join(","),
1400
- [f, m.attributes]
1401
- ), { data: de = [], isLoading: ne } = B({
1496
+ [p, u.attributes]
1497
+ ), { data: ce = [], isLoading: ne } = J({
1402
1498
  queryKey: [
1403
1499
  "catalog-builder",
1404
- m.collection,
1405
- D,
1406
- JSON.stringify(m.filter ?? null)
1500
+ u.collection,
1501
+ V,
1502
+ JSON.stringify(u.filter ?? null)
1407
1503
  ],
1408
1504
  queryFn: () => $.request(
1409
- E(`/items/${m.collection}`, {
1505
+ P(`/items/${u.collection}`, {
1410
1506
  limit: 2e3,
1411
- fields: D,
1412
- ...m.filter ? { filter: JSON.stringify(m.filter) } : {}
1507
+ fields: V,
1508
+ ...u.filter ? { filter: JSON.stringify(u.filter) } : {}
1413
1509
  })
1414
- ).then((w) => w.data ?? []),
1415
- enabled: R,
1510
+ ).then((v) => v.data ?? []),
1511
+ enabled: L,
1416
1512
  staleTime: 6e4
1417
- }), he = (w, O) => {
1418
- var b;
1419
- const L = w[O];
1420
- if (L == null) return null;
1421
- if (typeof L == "object") {
1422
- const j = L, F = ((b = m.attributes.find((T) => T.field === O)) == null ? void 0 : b.label_field) ?? "id";
1423
- return { id: String(j.id ?? ""), label: String(j[F] ?? j.id ?? "") };
1513
+ }), ye = (v, F) => {
1514
+ var D;
1515
+ const j = v[F];
1516
+ if (j == null) return null;
1517
+ if (typeof j == "object") {
1518
+ const K = j, b = ((D = u.attributes.find((me) => me.field === F)) == null ? void 0 : D.label_field) ?? "id";
1519
+ return { id: String(K.id ?? ""), label: String(K[b] ?? K.id ?? "") };
1424
1520
  }
1425
- return { id: String(L), label: String(L) };
1426
- }, J = (w) => de.filter(
1427
- (O) => m.attributes.slice(0, w).every((L) => {
1428
- var j;
1429
- const b = U[L.field];
1430
- return b ? ((j = he(O, L.field)) == null ? void 0 : j.id) === b : !0;
1521
+ return { id: String(j), label: String(j) };
1522
+ }, C = (v) => ce.filter(
1523
+ (F) => u.attributes.slice(0, v).every((j) => {
1524
+ var K;
1525
+ const D = B[j.field];
1526
+ return D ? ((K = ye(F, j.field)) == null ? void 0 : K.id) === D : !0;
1431
1527
  })
1432
- ), xe = m.attributes.every((w) => U[w.field]), be = xe ? de.find(
1433
- (w) => m.attributes.every((O) => {
1434
- var L;
1435
- return ((L = he(w, O.field)) == null ? void 0 : L.id) === U[O.field];
1528
+ ), ke = u.attributes.every((v) => B[v.field]), pe = ke ? ce.find(
1529
+ (v) => u.attributes.every((F) => {
1530
+ var j;
1531
+ return ((j = ye(v, F.field)) == null ? void 0 : j.id) === B[F.field];
1436
1532
  })
1437
- ) : void 0, G = (be == null ? void 0 : be[f]) != null ? String(be[f]) : null, { data: se } = B({
1438
- queryKey: ["catalog-builder-item", S, q, G],
1533
+ ) : void 0, G = (pe == null ? void 0 : pe[p]) != null ? String(pe[p]) : null, { data: se } = J({
1534
+ queryKey: ["catalog-builder-item", _, q, G],
1439
1535
  queryFn: () => $.request(
1440
- E(`/items/${S}`, {
1536
+ P(`/items/${_}`, {
1441
1537
  filter: JSON.stringify({ id: { _eq: G } }),
1442
1538
  fields: q,
1443
1539
  limit: 1
1444
1540
  })
1445
- ).then((w) => {
1446
- var O;
1447
- return ((O = w.data) == null ? void 0 : O[0]) ?? null;
1541
+ ).then((v) => {
1542
+ var F;
1543
+ return ((F = v.data) == null ? void 0 : F[0]) ?? null;
1448
1544
  }),
1449
1545
  enabled: !!G,
1450
1546
  staleTime: 6e4
@@ -1454,316 +1550,316 @@ function Pr({
1454
1550
  "button",
1455
1551
  {
1456
1552
  type: "button",
1457
- onClick: () => Z((w) => !w),
1553
+ onClick: () => Z((v) => !v),
1458
1554
  className: "flex w-full items-center gap-1.5 rounded-t-lg bg-slate-100/80 px-2 py-1.5 text-left dark:bg-muted",
1459
1555
  children: [
1460
1556
  /* @__PURE__ */ n(
1461
- Nt,
1557
+ qt,
1462
1558
  {
1463
- className: V(
1559
+ className: z(
1464
1560
  "h-3 w-3 shrink-0 text-slate-400 transition-transform",
1465
- R && "rotate-90"
1561
+ L && "rotate-90"
1466
1562
  )
1467
1563
  }
1468
1564
  ),
1469
- /* @__PURE__ */ n("span", { className: "text-[11px] font-semibold text-slate-600 dark:text-slate-300", children: m.label })
1565
+ /* @__PURE__ */ n("span", { className: "text-[11px] font-semibold text-slate-600 dark:text-slate-300", children: u.label })
1470
1566
  ]
1471
1567
  }
1472
1568
  ),
1473
- R && /* @__PURE__ */ n("div", { className: "space-y-2 border-t border-slate-200 p-3 dark:border-border", children: ne ? /* @__PURE__ */ c("div", { className: "flex items-center gap-2 py-2 text-slate-400", children: [
1474
- /* @__PURE__ */ n(ae, { className: "h-4 w-4 animate-spin" }),
1569
+ L && /* @__PURE__ */ n("div", { className: "space-y-2 border-t border-slate-200 p-3 dark:border-border", children: ne ? /* @__PURE__ */ c("div", { className: "flex items-center gap-2 py-2 text-slate-400", children: [
1570
+ /* @__PURE__ */ n(oe, { className: "h-4 w-4 animate-spin" }),
1475
1571
  " Loading options…"
1476
1572
  ] }) : /* @__PURE__ */ c("div", { className: "flex flex-wrap items-end gap-3", children: [
1477
- m.attributes.map((w, O) => {
1478
- const L = /* @__PURE__ */ new Map();
1479
- for (const j of J(O)) {
1480
- const F = he(j, w.field);
1481
- F != null && F.id && L.set(F.id, F.label);
1573
+ u.attributes.map((v, F) => {
1574
+ const j = /* @__PURE__ */ new Map();
1575
+ for (const K of C(F)) {
1576
+ const b = ye(K, v.field);
1577
+ b != null && b.id && j.set(b.id, b.label);
1482
1578
  }
1483
- const b = [...L.entries()].sort(
1484
- ([, j], [, F]) => j.localeCompare(F, void 0, { numeric: !0 })
1579
+ const D = [...j.entries()].sort(
1580
+ ([, K], [, b]) => K.localeCompare(b, void 0, { numeric: !0 })
1485
1581
  );
1486
1582
  return /* @__PURE__ */ n(
1487
- Er,
1583
+ Ur,
1488
1584
  {
1489
- label: te(w.field),
1490
- value: U[w.field] ?? null,
1491
- valueLabel: U[w.field] ? L.get(U[w.field]) ?? U[w.field] : null,
1492
- options: b,
1493
- disabled: O > 0 && !U[m.attributes[O - 1].field],
1494
- onChange: (j) => K((F) => {
1495
- const T = {};
1496
- for (let z = 0; z < O; z++) {
1497
- const ge = m.attributes[z].field;
1498
- F[ge] && (T[ge] = F[ge]);
1585
+ label: re(v.field),
1586
+ value: B[v.field] ?? null,
1587
+ valueLabel: B[v.field] ? j.get(B[v.field]) ?? B[v.field] : null,
1588
+ options: D,
1589
+ disabled: F > 0 && !B[u.attributes[F - 1].field],
1590
+ onChange: (K) => A((b) => {
1591
+ const me = {};
1592
+ for (let X = 0; X < F; X++) {
1593
+ const U = u.attributes[X].field;
1594
+ b[U] && (me[U] = b[U]);
1499
1595
  }
1500
- return j && (T[w.field] = j), T;
1596
+ return K && (me[v.field] = K), me;
1501
1597
  })
1502
1598
  },
1503
- w.field
1599
+ v.field
1504
1600
  );
1505
1601
  }),
1506
- /* @__PURE__ */ n("div", { className: "flex min-h-[28px] flex-1 items-center gap-2", children: G && se ? /* @__PURE__ */ c(kt, { children: [
1507
- /* @__PURE__ */ n("span", { className: "min-w-0 flex-1 truncate text-slate-700 dark:text-slate-200", children: qe(l, se) }),
1508
- (p(G) ?? 0) > 0 && /* @__PURE__ */ n("span", { className: "rounded bg-nvr-cyan/10 px-1.5 py-0.5 text-[10px] font-semibold text-[#009abe]", children: "picked" }),
1509
- h(G, se)
1510
- ] }) : xe ? /* @__PURE__ */ n("span", { className: "text-slate-400", children: "No matching item for this combination" }) : /* @__PURE__ */ n("span", { className: "text-slate-400", children: "Pick each attribute to resolve an item" }) })
1602
+ /* @__PURE__ */ n("div", { className: "flex min-h-[28px] flex-1 items-center gap-2", children: G && se ? /* @__PURE__ */ c(_t, { children: [
1603
+ /* @__PURE__ */ n("span", { className: "min-w-0 flex-1 truncate text-slate-700 dark:text-slate-200", children: Fe(l, se) }),
1604
+ (h(G) ?? 0) > 0 && /* @__PURE__ */ n("span", { className: "rounded bg-nvr-cyan/10 px-1.5 py-0.5 text-[10px] font-semibold text-[#009abe]", children: "picked" }),
1605
+ x(G, se)
1606
+ ] }) : ke ? /* @__PURE__ */ n("span", { className: "text-slate-400", children: "No matching item for this combination" }) : /* @__PURE__ */ n("span", { className: "text-slate-400", children: "Pick each attribute to resolve an item" }) })
1511
1607
  ] }) })
1512
1608
  ] });
1513
1609
  }
1514
- function Er({
1515
- label: m,
1516
- value: x,
1517
- valueLabel: S,
1610
+ function Ur({
1611
+ label: u,
1612
+ value: g,
1613
+ valueLabel: _,
1518
1614
  options: q,
1519
1615
  disabled: l,
1520
- onChange: h
1616
+ onChange: x
1521
1617
  }) {
1522
- const [p, $] = re(!1), f = Je(null);
1523
- return Se(() => {
1524
- if (!p) return;
1525
- const R = (Z) => {
1526
- f.current && !f.current.contains(Z.target) && $(!1);
1618
+ const [h, $] = Y(!1), p = ze(null);
1619
+ return je(() => {
1620
+ if (!h) return;
1621
+ const L = (Z) => {
1622
+ p.current && !p.current.contains(Z.target) && $(!1);
1527
1623
  };
1528
- return document.addEventListener("mousedown", R), () => document.removeEventListener("mousedown", R);
1529
- }, [p]), /* @__PURE__ */ c("div", { ref: f, className: "relative", children: [
1530
- /* @__PURE__ */ n("p", { className: "mb-1 text-[10px] font-medium text-slate-500 dark:text-slate-400", children: m }),
1624
+ return document.addEventListener("mousedown", L), () => document.removeEventListener("mousedown", L);
1625
+ }, [h]), /* @__PURE__ */ c("div", { ref: p, className: "relative", children: [
1626
+ /* @__PURE__ */ n("p", { className: "mb-1 text-[10px] font-medium text-slate-500 dark:text-slate-400", children: u }),
1531
1627
  /* @__PURE__ */ c(
1532
1628
  "button",
1533
1629
  {
1534
1630
  type: "button",
1535
1631
  disabled: l,
1536
- onClick: () => $((R) => !R),
1632
+ onClick: () => $((L) => !L),
1537
1633
  className: "flex w-44 items-center justify-between rounded border border-slate-200 bg-white px-2 py-1.5 text-left text-[12px] text-slate-700 hover:border-slate-300 disabled:opacity-50 dark:border-border dark:bg-background dark:text-slate-200",
1538
1634
  children: [
1539
- /* @__PURE__ */ n("span", { className: V("truncate", !S && "text-slate-400"), children: S ?? "Select…" }),
1540
- /* @__PURE__ */ n(gr, { className: "h-3.5 w-3.5 shrink-0 text-slate-400" })
1635
+ /* @__PURE__ */ n("span", { className: z("truncate", !_ && "text-slate-400"), children: _ ?? "Select…" }),
1636
+ /* @__PURE__ */ n(vr, { className: "h-3.5 w-3.5 shrink-0 text-slate-400" })
1541
1637
  ]
1542
1638
  }
1543
1639
  ),
1544
- p && /* @__PURE__ */ c("div", { className: "absolute z-50 mt-1 max-h-52 w-44 overflow-y-auto rounded-md border border-border bg-popover py-1 shadow-md", children: [
1545
- x && /* @__PURE__ */ c(
1640
+ h && /* @__PURE__ */ c("div", { className: "absolute z-50 mt-1 max-h-52 w-44 overflow-y-auto rounded-md border border-border bg-popover py-1 shadow-md", children: [
1641
+ g && /* @__PURE__ */ c(
1546
1642
  "button",
1547
1643
  {
1548
1644
  type: "button",
1549
1645
  onClick: () => {
1550
- h(null), $(!1);
1646
+ x(null), $(!1);
1551
1647
  },
1552
1648
  className: "flex w-full items-center gap-1.5 border-b border-slate-100 px-2 py-1 text-left text-[12px] text-slate-500 hover:bg-muted dark:border-border dark:text-slate-400",
1553
1649
  children: [
1554
- /* @__PURE__ */ n(et, { className: "h-3 w-3 text-slate-400" }),
1650
+ /* @__PURE__ */ n(at, { className: "h-3 w-3 text-slate-400" }),
1555
1651
  " Clear"
1556
1652
  ]
1557
1653
  }
1558
1654
  ),
1559
- q.map(([R, Z]) => /* @__PURE__ */ n(
1655
+ q.map(([L, Z]) => /* @__PURE__ */ n(
1560
1656
  "button",
1561
1657
  {
1562
1658
  type: "button",
1563
1659
  onClick: () => {
1564
- h(R), $(!1);
1660
+ x(L), $(!1);
1565
1661
  },
1566
- className: V(
1662
+ className: z(
1567
1663
  "block w-full truncate px-2 py-1 text-left text-[12px] hover:bg-muted",
1568
- R === x ? "font-medium text-nvr-cyan" : "text-slate-700 dark:text-slate-200"
1664
+ L === g ? "font-medium text-nvr-cyan" : "text-slate-700 dark:text-slate-200"
1569
1665
  ),
1570
1666
  children: Z
1571
1667
  },
1572
- R
1668
+ L
1573
1669
  ))
1574
1670
  ] })
1575
1671
  ] });
1576
1672
  }
1577
- function Rr({
1578
- catalogCol: m,
1579
- tmpl: x,
1580
- sectionBy: S,
1673
+ function Hr({
1674
+ catalogCol: u,
1675
+ tmpl: g,
1676
+ sectionBy: _,
1581
1677
  sectionM2M: q,
1582
1678
  pinnedSet: l,
1583
- pinnedIds: h,
1584
- savingIds: p,
1679
+ pinnedIds: x,
1680
+ savingIds: h,
1585
1681
  relatedCols: $,
1586
- parentDraft: f,
1587
- onToggle: R,
1682
+ parentDraft: p,
1683
+ onToggle: L,
1588
1684
  onClose: Z,
1589
- anchor: U
1685
+ anchor: B
1590
1686
  }) {
1591
- const K = vt(), [D, de] = re(""), [ne, he] = re(""), [J, xe] = re(1), be = Je(null);
1592
- Se(() => {
1593
- const i = setTimeout(() => he(D), 300);
1594
- return () => clearTimeout(i);
1595
- }, [D]), Se(() => xe(1), [ne]), Se(() => {
1596
- var i;
1597
- (i = be.current) == null || i.focus();
1598
- }, []), Se(() => {
1599
- const i = (y) => {
1600
- y.key === "Escape" && (y.stopPropagation(), Z());
1687
+ const A = $t(), [V, ce] = Y(""), [ne, ye] = Y(""), [C, ke] = Y(1), pe = ze(null);
1688
+ je(() => {
1689
+ const a = setTimeout(() => ye(V), 300);
1690
+ return () => clearTimeout(a);
1691
+ }, [V]), je(() => ke(1), [ne]), je(() => {
1692
+ var a;
1693
+ (a = pe.current) == null || a.focus();
1694
+ }, []), je(() => {
1695
+ const a = (w) => {
1696
+ w.key === "Escape" && (w.stopPropagation(), Z());
1601
1697
  };
1602
- return window.addEventListener("keydown", i, !0), () => window.removeEventListener("keydown", i, !0);
1698
+ return window.addEventListener("keydown", a, !0), () => window.removeEventListener("keydown", a, !0);
1603
1699
  }, [Z]);
1604
- const G = P(() => {
1605
- var y;
1606
- const i = (y = [...(x ?? "").matchAll(/\{\{([\w.]+)\}\}/g)][0]) == null ? void 0 : y[1];
1607
- return i && !i.includes(".") ? i : "id";
1608
- }, [x]), se = !q && S.includes(".") ? `*,${S}` : "*", w = 50, { data: O, isFetching: L } = B({
1609
- queryKey: ["favorites-manager-list", m, ne, G, J],
1610
- queryFn: () => K.request(
1611
- E(`/items/${m}`, {
1700
+ const G = O(() => {
1701
+ var w;
1702
+ const a = (w = [...(g ?? "").matchAll(/\{\{([\w.]+)\}\}/g)][0]) == null ? void 0 : w[1];
1703
+ return a && !a.includes(".") ? a : "id";
1704
+ }, [g]), se = !q && _.includes(".") ? `*,${_}` : "*", v = 50, { data: F, isFetching: j } = J({
1705
+ queryKey: ["favorites-manager-list", u, ne, G, C],
1706
+ queryFn: () => A.request(
1707
+ P(`/items/${u}`, {
1612
1708
  fields: se,
1613
- limit: w,
1614
- page: J,
1709
+ limit: v,
1710
+ page: C,
1615
1711
  sort: G,
1616
1712
  ...ne.trim() ? { search: ne } : {}
1617
1713
  })
1618
1714
  ),
1619
1715
  staleTime: 3e4,
1620
- placeholderData: (i) => i
1621
- }), b = ((O == null ? void 0 : O.data) ?? []).filter((i) => !l.has(String(i.id))), j = (O == null ? void 0 : O.total) ?? b.length, F = Math.max(1, Math.ceil(j / w)), { data: T = [] } = B({
1622
- queryKey: ["favorites-manager-pinned", m, se, h.join(",")],
1623
- queryFn: () => K.request(
1624
- E(`/items/${m}`, {
1625
- filter: JSON.stringify({ id: { _in: h } }),
1716
+ placeholderData: (a) => a
1717
+ }), D = ((F == null ? void 0 : F.data) ?? []).filter((a) => !l.has(String(a.id))), K = (F == null ? void 0 : F.total) ?? D.length, b = Math.max(1, Math.ceil(K / v)), { data: me = [] } = J({
1718
+ queryKey: ["favorites-manager-pinned", u, se, x.join(",")],
1719
+ queryFn: () => A.request(
1720
+ P(`/items/${u}`, {
1721
+ filter: JSON.stringify({ id: { _in: x } }),
1626
1722
  fields: se,
1627
- limit: h.length,
1723
+ limit: x.length,
1628
1724
  sort: G
1629
1725
  })
1630
- ).then((i) => i.data ?? []),
1631
- enabled: h.length > 0,
1726
+ ).then((a) => a.data ?? []),
1727
+ enabled: x.length > 0,
1632
1728
  staleTime: 3e4
1633
- }), z = P(() => {
1634
- const i = /* @__PURE__ */ new Set();
1635
- for (const y of b) i.add(String(y.id));
1636
- for (const y of h) i.add(y);
1637
- return [...i];
1638
- }, [b, h]), { data: ge = /* @__PURE__ */ new Map() } = B({
1639
- queryKey: ["favorites-manager-sections", q == null ? void 0 : q.junction, z.join(",")],
1729
+ }), X = O(() => {
1730
+ const a = /* @__PURE__ */ new Set();
1731
+ for (const w of D) a.add(String(w.id));
1732
+ for (const w of x) a.add(w);
1733
+ return [...a];
1734
+ }, [D, x]), { data: U = /* @__PURE__ */ new Map() } = J({
1735
+ queryKey: ["favorites-manager-sections", q == null ? void 0 : q.junction, X.join(",")],
1640
1736
  queryFn: async () => {
1641
- const i = q, y = await tt(K, `/items/${i.junction}`, {
1642
- fields: `${i.fkToItem},${i.fkToSection}`,
1643
- filter: JSON.stringify({ [i.fkToItem]: { _in: z } })
1644
- }), H = [...new Set(y.map((Q) => String(Q[i.fkToSection])))], I = H.length ? await tt(K, `/items/${i.target}`, {
1645
- fields: `id,${i.labelPath}`,
1646
- filter: JSON.stringify({ id: { _in: H } })
1647
- }) : [], W = new Map(
1648
- I.map((Q) => [String(Q.id), String(It(Q, i.labelPath) ?? "")])
1649
- ), le = /* @__PURE__ */ new Map();
1650
- for (const Q of y) {
1651
- const Y = W.get(String(Q[i.fkToSection]));
1652
- if (!Y) continue;
1653
- const me = String(Q[i.fkToItem]), M = le.get(me) ?? [];
1654
- M.includes(Y) || M.push(Y), le.set(me, M);
1737
+ const a = q, w = await it(A, `/items/${a.junction}`, {
1738
+ fields: `${a.fkToItem},${a.fkToSection}`,
1739
+ filter: JSON.stringify({ [a.fkToItem]: { _in: X } })
1740
+ }), E = [...new Set(w.map((M) => String(M[a.fkToSection])))], ie = E.length ? await it(A, `/items/${a.target}`, {
1741
+ fields: `id,${a.labelPath}`,
1742
+ filter: JSON.stringify({ id: { _in: E } })
1743
+ }) : [], te = new Map(
1744
+ ie.map((M) => [String(M.id), String(Xt(M, a.labelPath) ?? "")])
1745
+ ), I = /* @__PURE__ */ new Map();
1746
+ for (const M of w) {
1747
+ const W = te.get(String(M[a.fkToSection]));
1748
+ if (!W) continue;
1749
+ const we = String(M[a.fkToItem]), Ne = I.get(we) ?? [];
1750
+ Ne.includes(W) || Ne.push(W), I.set(we, Ne);
1655
1751
  }
1656
- return le;
1752
+ return I;
1657
1753
  },
1658
- enabled: !!q && z.length > 0,
1754
+ enabled: !!q && X.length > 0,
1659
1755
  staleTime: 6e4
1660
- }), A = (i) => x ? qe(x, i) : String(i.cifa_number ?? i.name ?? `#${i.id}`), X = (i) => {
1661
- const y = i.description ?? i.long_description ?? i.name;
1662
- return typeof y == "string" && y.trim() && y.trim() !== A(i) ? y : "";
1663
- }, we = (i) => {
1664
- if (q) return (ge.get(String(i.id)) ?? []).join(", ");
1665
- if (!S) return "";
1666
- const y = qe(`{{${S}}}`, i);
1667
- return y === `{{${S}}}` ? "" : y;
1668
- }, ye = (i, y) => {
1669
- if (y === "presence")
1670
- return i == null || i === "" || Number(i) === 0 ? "No" : "Yes";
1671
- if (i == null || i === "") return "—";
1672
- const H = Number(i);
1673
- return y === "currency" && Number.isFinite(H) ? H.toLocaleString("en-US", { style: "currency", currency: "USD" }) : y === "number" && Number.isFinite(H) ? H.toLocaleString() : String(i);
1674
- }, ie = wt({
1675
- queries: $.map((i) => {
1676
- const y = ze(i.match, f);
1756
+ }), H = (a) => g ? Fe(g, a) : String(a.cifa_number ?? a.name ?? `#${a.id}`), R = (a) => {
1757
+ const w = a.description ?? a.long_description ?? a.name;
1758
+ return typeof w == "string" && w.trim() && w.trim() !== H(a) ? w : "";
1759
+ }, ue = (a) => {
1760
+ if (q) return (U.get(String(a.id)) ?? []).join(", ");
1761
+ if (!_) return "";
1762
+ const w = Fe(`{{${_}}}`, a);
1763
+ return w === `{{${_}}}` ? "" : w;
1764
+ }, Ve = (a, w) => {
1765
+ if (w === "presence")
1766
+ return a == null || a === "" || Number(a) === 0 ? "No" : "Yes";
1767
+ if (a == null || a === "") return "—";
1768
+ const E = Number(a);
1769
+ return w === "currency" && Number.isFinite(E) ? E.toLocaleString("en-US", { style: "currency", currency: "USD" }) : w === "number" && Number.isFinite(E) ? E.toLocaleString() : String(a);
1770
+ }, Q = St({
1771
+ queries: $.map((a) => {
1772
+ const w = Be(a.match, p);
1677
1773
  return {
1678
1774
  queryKey: [
1679
1775
  "favorites-manager-related",
1680
- i.key,
1681
- i.collection,
1682
- JSON.stringify(y),
1683
- z.join(",")
1776
+ a.key,
1777
+ a.collection,
1778
+ JSON.stringify(w),
1779
+ X.join(",")
1684
1780
  ],
1685
1781
  queryFn: async () => {
1686
- const H = await K.request(
1687
- E(`/items/${i.collection}`, {
1688
- filter: JSON.stringify({ [i.item_field]: { _in: z }, ...y ?? {} }),
1689
- fields: `${i.item_field},${i.value_field}`,
1782
+ const E = await A.request(
1783
+ P(`/items/${a.collection}`, {
1784
+ filter: JSON.stringify({ [a.item_field]: { _in: X }, ...w ?? {} }),
1785
+ fields: `${a.item_field},${a.value_field}`,
1690
1786
  limit: 1e3
1691
1787
  })
1692
- ).then((W) => W.data ?? []), I = /* @__PURE__ */ new Map();
1693
- for (const W of H) {
1694
- const le = String(W[i.item_field]), Q = W[i.value_field], Y = I.get(le);
1695
- Y === void 0 ? I.set(le, Q) : Number.isFinite(Number(Y)) && Number.isFinite(Number(Q)) && I.set(le, Number(Y) + Number(Q));
1788
+ ).then((te) => te.data ?? []), ie = /* @__PURE__ */ new Map();
1789
+ for (const te of E) {
1790
+ const I = String(te[a.item_field]), M = te[a.value_field], W = ie.get(I);
1791
+ W === void 0 ? ie.set(I, M) : Number.isFinite(Number(W)) && Number.isFinite(Number(M)) && ie.set(I, Number(W) + Number(M));
1696
1792
  }
1697
- return I;
1793
+ return ie;
1698
1794
  },
1699
- enabled: z.length > 0 && (i.match === void 0 || y !== null),
1795
+ enabled: X.length > 0 && (a.match === void 0 || w !== null),
1700
1796
  staleTime: 3e4
1701
1797
  };
1702
1798
  })
1703
- }), ce = $.filter(
1704
- (i) => i.match !== void 0 && ze(i.match, f) === null
1705
- ), je = (i) => {
1706
- const y = l.has(i);
1799
+ }), ee = $.filter(
1800
+ (a) => a.match !== void 0 && Be(a.match, p) === null
1801
+ ), Te = (a) => {
1802
+ const w = l.has(a);
1707
1803
  return /* @__PURE__ */ n(
1708
1804
  "button",
1709
1805
  {
1710
1806
  type: "button",
1711
- title: y ? "Remove from favorites" : "Add to favorites",
1712
- disabled: p.has(i),
1713
- onClick: () => R(i),
1807
+ title: w ? "Remove from favorites" : "Add to favorites",
1808
+ disabled: h.has(a),
1809
+ onClick: () => L(a),
1714
1810
  className: "shrink-0 rounded p-1 transition-colors hover:bg-amber-100/60 dark:hover:bg-amber-400/10",
1715
- children: p.has(i) ? /* @__PURE__ */ n(ae, { className: "h-4 w-4 animate-spin text-amber-400" }) : /* @__PURE__ */ n(
1716
- Ke,
1811
+ children: h.has(a) ? /* @__PURE__ */ n(oe, { className: "h-4 w-4 animate-spin text-amber-400" }) : /* @__PURE__ */ n(
1812
+ Qe,
1717
1813
  {
1718
- className: V(
1814
+ className: z(
1719
1815
  "h-4 w-4",
1720
- y ? "fill-amber-400 text-amber-400" : "text-slate-300 hover:text-amber-400"
1816
+ w ? "fill-amber-400 text-amber-400" : "text-slate-300 hover:text-amber-400"
1721
1817
  )
1722
1818
  }
1723
1819
  )
1724
1820
  }
1725
1821
  );
1726
- }, ee = (i, y) => /* @__PURE__ */ n("tr", { children: /* @__PURE__ */ n("td", { colSpan: 4 + $.length, className: V("border-b px-3 py-1.5", y), children: i }) }), Be = (i, y) => {
1727
- const H = String(i.id), I = X(i);
1822
+ }, he = (a, w) => /* @__PURE__ */ n("tr", { children: /* @__PURE__ */ n("td", { colSpan: 4 + $.length, className: z("border-b px-3 py-1.5", w), children: a }) }), ae = (a, w) => {
1823
+ const E = String(a.id), ie = R(a);
1728
1824
  return /* @__PURE__ */ c(
1729
1825
  "tr",
1730
1826
  {
1731
- className: V(
1827
+ className: z(
1732
1828
  "border-b border-slate-100 dark:border-border/50",
1733
- y % 2 === 0 ? "bg-white dark:bg-background" : "bg-slate-50/50 dark:bg-muted/30"
1829
+ w % 2 === 0 ? "bg-white dark:bg-background" : "bg-slate-50/50 dark:bg-muted/30"
1734
1830
  ),
1735
1831
  children: [
1736
- /* @__PURE__ */ n("td", { className: "px-2 py-1", children: je(H) }),
1737
- /* @__PURE__ */ n("td", { className: "px-2 py-1 font-medium tabular-nums text-slate-700 dark:text-slate-200", children: Dt(m) ? /* @__PURE__ */ n(
1832
+ /* @__PURE__ */ n("td", { className: "px-2 py-1", children: Te(E) }),
1833
+ /* @__PURE__ */ n("td", { className: "px-2 py-1 font-medium tabular-nums text-slate-700 dark:text-slate-200", children: Zt(u) ? /* @__PURE__ */ n(
1738
1834
  "button",
1739
1835
  {
1740
1836
  type: "button",
1741
- onClick: () => Ht(m, H, f),
1837
+ onClick: () => Gt(u, E, p),
1742
1838
  title: "View stock & planning detail",
1743
1839
  className: "text-left underline decoration-slate-300 decoration-1 underline-offset-2 hover:text-[#009abe] hover:decoration-[#009abe] dark:decoration-slate-600",
1744
- children: A(i)
1840
+ children: H(a)
1745
1841
  }
1746
- ) : A(i) }),
1747
- /* @__PURE__ */ n("td", { className: "max-w-0 px-2 py-1", children: /* @__PURE__ */ n("p", { className: "truncate text-slate-600 dark:text-slate-300", "data-tip": I || void 0, children: I || "—" }) }),
1748
- /* @__PURE__ */ n("td", { className: "px-2 py-1", children: /* @__PURE__ */ n("p", { className: "truncate text-slate-500 dark:text-slate-400", children: we(i) || "—" }) }),
1749
- $.map((W, le) => {
1750
- var me, M;
1751
- const Q = W.match !== void 0 && ze(W.match, f) === null, Y = Q || (M = (me = ie[le]) == null ? void 0 : me.data) == null ? void 0 : M.get(H);
1842
+ ) : H(a) }),
1843
+ /* @__PURE__ */ n("td", { className: "max-w-0 px-2 py-1", children: /* @__PURE__ */ n("p", { className: "truncate text-slate-600 dark:text-slate-300", "data-tip": ie || void 0, children: ie || "—" }) }),
1844
+ /* @__PURE__ */ n("td", { className: "px-2 py-1", children: /* @__PURE__ */ n("p", { className: "truncate text-slate-500 dark:text-slate-400", children: ue(a) || "—" }) }),
1845
+ $.map((te, I) => {
1846
+ var we, Ne;
1847
+ const M = te.match !== void 0 && Be(te.match, p) === null, W = M || (Ne = (we = Q[I]) == null ? void 0 : we.data) == null ? void 0 : Ne.get(E);
1752
1848
  return /* @__PURE__ */ n(
1753
1849
  "td",
1754
1850
  {
1755
1851
  className: "whitespace-nowrap px-2 py-1 text-right tabular-nums text-slate-600 dark:text-slate-300",
1756
- children: Q ? "—" : ye(Y, W.format)
1852
+ children: M ? "—" : Ve(W, te.format)
1757
1853
  },
1758
- W.key
1854
+ te.key
1759
1855
  );
1760
1856
  })
1761
1857
  ]
1762
1858
  },
1763
- H
1859
+ E
1764
1860
  );
1765
- }, ke = (U == null ? void 0 : U.closest('[role="dialog"]')) ?? document.body, Fe = D.trim() ? T.filter((i) => $r(`${A(i)} ${X(i)} ${we(i)}`, D)) : T;
1766
- return yr(
1861
+ }, xe = (B == null ? void 0 : B.closest('[role="dialog"]')) ?? document.body, Oe = V.trim() ? me.filter((a) => Pr(`${H(a)} ${R(a)} ${ue(a)}`, V)) : me;
1862
+ return _r(
1767
1863
  /* @__PURE__ */ c("div", { className: "fixed inset-0 z-[125]", role: "presentation", children: [
1768
1864
  /* @__PURE__ */ n(
1769
1865
  "div",
@@ -1781,7 +1877,7 @@ function Rr({
1781
1877
  className: "absolute inset-y-0 right-0 flex flex-col border-l border-slate-200 bg-white shadow-2xl motion-safe:animate-in motion-safe:slide-in-from-right dark:border-border dark:bg-background",
1782
1878
  children: [
1783
1879
  /* @__PURE__ */ c("div", { className: "flex items-start gap-2.5 border-b border-slate-200 px-4 py-3 dark:border-border", children: [
1784
- /* @__PURE__ */ n(Ke, { className: "mt-0.5 h-4 w-4 shrink-0 fill-amber-400 text-amber-400" }),
1880
+ /* @__PURE__ */ n(Qe, { className: "mt-0.5 h-4 w-4 shrink-0 fill-amber-400 text-amber-400" }),
1785
1881
  /* @__PURE__ */ c("div", { className: "min-w-0 flex-1", children: [
1786
1882
  /* @__PURE__ */ n("p", { className: "text-[13px] font-semibold text-slate-800 dark:text-slate-100", children: "CIFA favorites" }),
1787
1883
  /* @__PURE__ */ n("p", { className: "text-[11px] leading-snug text-slate-500 dark:text-slate-400", children: "Browse the full catalog and star items — favorites appear at the top of every request's item list." })
@@ -1793,37 +1889,37 @@ function Rr({
1793
1889
  onClick: Z,
1794
1890
  className: "shrink-0 rounded p-1 text-slate-400 transition-colors hover:bg-slate-100 hover:text-slate-600 dark:hover:bg-white/[0.06]",
1795
1891
  "aria-label": "Close",
1796
- children: /* @__PURE__ */ n(et, { className: "h-4 w-4" })
1892
+ children: /* @__PURE__ */ n(at, { className: "h-4 w-4" })
1797
1893
  }
1798
1894
  )
1799
1895
  ] }),
1800
1896
  /* @__PURE__ */ c("div", { className: "border-b border-slate-200 px-3 py-2 dark:border-border", children: [
1801
1897
  /* @__PURE__ */ c("div", { className: "flex items-center gap-2 rounded-md border border-slate-200 bg-slate-50 px-2.5 py-1.5 focus-within:border-nvr-cyan focus-within:bg-white dark:border-border dark:bg-muted/40 dark:focus-within:bg-background", children: [
1802
- /* @__PURE__ */ n(Xe, { className: "h-3.5 w-3.5 shrink-0 text-slate-400" }),
1898
+ /* @__PURE__ */ n(st, { className: "h-3.5 w-3.5 shrink-0 text-slate-400" }),
1803
1899
  /* @__PURE__ */ n(
1804
1900
  "input",
1805
1901
  {
1806
- ref: be,
1807
- value: D,
1808
- onChange: (i) => de(i.target.value),
1902
+ ref: pe,
1903
+ value: V,
1904
+ onChange: (a) => ce(a.target.value),
1809
1905
  placeholder: "Search by number or description…",
1810
1906
  className: "min-w-0 flex-1 bg-transparent text-[12px] text-slate-700 outline-none placeholder:text-slate-400 dark:text-slate-200"
1811
1907
  }
1812
1908
  ),
1813
- D && /* @__PURE__ */ n(
1909
+ V && /* @__PURE__ */ n(
1814
1910
  "button",
1815
1911
  {
1816
1912
  type: "button",
1817
- onClick: () => de(""),
1913
+ onClick: () => ce(""),
1818
1914
  className: "shrink-0 text-slate-400 hover:text-slate-600",
1819
1915
  "aria-label": "Clear search",
1820
- children: /* @__PURE__ */ n(et, { className: "h-3.5 w-3.5" })
1916
+ children: /* @__PURE__ */ n(at, { className: "h-3.5 w-3.5" })
1821
1917
  }
1822
1918
  )
1823
1919
  ] }),
1824
- ce.length > 0 && /* @__PURE__ */ c("p", { className: "mt-1.5 flex items-center gap-1 text-[10px] text-amber-600 dark:text-amber-400", children: [
1825
- /* @__PURE__ */ n(Ce, { className: "h-3 w-3 shrink-0" }),
1826
- ce.map((i) => i.label ?? te(i.key)).join(", "),
1920
+ ee.length > 0 && /* @__PURE__ */ c("p", { className: "mt-1.5 flex items-center gap-1 text-[10px] text-amber-600 dark:text-amber-400", children: [
1921
+ /* @__PURE__ */ n(Je, { className: "h-3 w-3 shrink-0" }),
1922
+ ee.map((a) => a.label ?? re(a.key)).join(", "),
1827
1923
  " fill in once the form's warehouse selection is made."
1828
1924
  ] })
1829
1925
  ] }),
@@ -1833,43 +1929,43 @@ function Rr({
1833
1929
  /* @__PURE__ */ n("col", { className: "w-[88px]" }),
1834
1930
  /* @__PURE__ */ n("col", {}),
1835
1931
  /* @__PURE__ */ n("col", { className: "w-[130px]" }),
1836
- $.map((i) => /* @__PURE__ */ n("col", { className: "w-[86px]" }, i.key))
1932
+ $.map((a) => /* @__PURE__ */ n("col", { className: "w-[86px]" }, a.key))
1837
1933
  ] }),
1838
1934
  /* @__PURE__ */ n("thead", { className: "sticky top-0 z-[1]", children: /* @__PURE__ */ c("tr", { className: "bg-slate-100 text-left text-[10px] font-semibold uppercase tracking-wide text-slate-500 dark:bg-muted dark:text-slate-400", children: [
1839
1935
  /* @__PURE__ */ n("th", { className: "px-2 py-1.5", "aria-label": "Favorite" }),
1840
1936
  /* @__PURE__ */ n("th", { className: "px-2 py-1.5", children: "CIFA #" }),
1841
1937
  /* @__PURE__ */ n("th", { className: "px-2 py-1.5", children: "Description" }),
1842
1938
  /* @__PURE__ */ n("th", { className: "px-2 py-1.5", children: "Category" }),
1843
- $.map((i) => /* @__PURE__ */ n("th", { className: "px-2 py-1.5 text-right", children: i.label ?? te(i.key) }, i.key))
1939
+ $.map((a) => /* @__PURE__ */ n("th", { className: "px-2 py-1.5 text-right", children: a.label ?? re(a.key) }, a.key))
1844
1940
  ] }) }),
1845
- /* @__PURE__ */ c("tbody", { className: V(L && "opacity-50 transition-opacity"), children: [
1846
- ee(
1941
+ /* @__PURE__ */ c("tbody", { className: z(j && "opacity-50 transition-opacity"), children: [
1942
+ he(
1847
1943
  /* @__PURE__ */ c("span", { className: "flex items-center gap-1.5", children: [
1848
- /* @__PURE__ */ n(Ke, { className: "h-3 w-3 shrink-0 fill-amber-400 text-amber-400" }),
1944
+ /* @__PURE__ */ n(Qe, { className: "h-3 w-3 shrink-0 fill-amber-400 text-amber-400" }),
1849
1945
  /* @__PURE__ */ n("span", { className: "text-[11px] font-semibold text-slate-600 dark:text-slate-300", children: "Your favorites" }),
1850
- /* @__PURE__ */ n("span", { className: "rounded border border-slate-200 bg-white px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-slate-500 dark:border-border dark:bg-background dark:text-slate-400", children: h.length })
1946
+ /* @__PURE__ */ n("span", { className: "rounded border border-slate-200 bg-white px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-slate-500 dark:border-border dark:bg-background dark:text-slate-400", children: x.length })
1851
1947
  ] }),
1852
1948
  "border-slate-200 bg-amber-50/70 dark:border-border dark:bg-amber-900/10"
1853
1949
  ),
1854
- Fe.length === 0 && /* @__PURE__ */ n("tr", { children: /* @__PURE__ */ n(
1950
+ Oe.length === 0 && /* @__PURE__ */ n("tr", { children: /* @__PURE__ */ n(
1855
1951
  "td",
1856
1952
  {
1857
1953
  colSpan: 4 + $.length,
1858
1954
  className: "border-b border-slate-100 px-4 py-3 text-center text-[11px] text-slate-400 dark:border-border/50",
1859
- children: h.length === 0 ? "No favorites yet — star the items you order most." : "No favorites match your search."
1955
+ children: x.length === 0 ? "No favorites yet — star the items you order most." : "No favorites match your search."
1860
1956
  }
1861
1957
  ) }),
1862
- Fe.map((i, y) => Be(i, y)),
1863
- ee(
1958
+ Oe.map((a, w) => ae(a, w)),
1959
+ he(
1864
1960
  /* @__PURE__ */ c("span", { className: "flex items-center gap-1.5", children: [
1865
- /* @__PURE__ */ n(Xe, { className: "h-3 w-3 shrink-0 text-slate-400" }),
1961
+ /* @__PURE__ */ n(st, { className: "h-3 w-3 shrink-0 text-slate-400" }),
1866
1962
  /* @__PURE__ */ n("span", { className: "text-[11px] font-semibold text-slate-600 dark:text-slate-300", children: "All CIFAs" }),
1867
- /* @__PURE__ */ n("span", { className: "rounded border border-slate-200 bg-white px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-slate-500 dark:border-border dark:bg-background dark:text-slate-400", children: j.toLocaleString() }),
1868
- L && /* @__PURE__ */ n(ae, { className: "h-3 w-3 animate-spin text-slate-400" })
1963
+ /* @__PURE__ */ n("span", { className: "rounded border border-slate-200 bg-white px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-slate-500 dark:border-border dark:bg-background dark:text-slate-400", children: K.toLocaleString() }),
1964
+ j && /* @__PURE__ */ n(oe, { className: "h-3 w-3 animate-spin text-slate-400" })
1869
1965
  ] }),
1870
1966
  "border-t border-slate-200 bg-slate-50 dark:border-border dark:bg-muted/40"
1871
1967
  ),
1872
- !L && b.length === 0 && /* @__PURE__ */ n("tr", { children: /* @__PURE__ */ n(
1968
+ !j && D.length === 0 && /* @__PURE__ */ n("tr", { children: /* @__PURE__ */ n(
1873
1969
  "td",
1874
1970
  {
1875
1971
  colSpan: 4 + $.length,
@@ -1877,19 +1973,19 @@ function Rr({
1877
1973
  children: ne.trim() ? `No CIFAs match "${ne}".` : "No catalog items."
1878
1974
  }
1879
1975
  ) }),
1880
- b.map((i, y) => Be(i, y))
1976
+ D.map((a, w) => ae(a, w))
1881
1977
  ] })
1882
1978
  ] }) }),
1883
- F > 1 && /* @__PURE__ */ c("div", { className: "flex shrink-0 items-center justify-between border-t border-slate-200 px-3 py-2 dark:border-border", children: [
1979
+ b > 1 && /* @__PURE__ */ c("div", { className: "flex shrink-0 items-center justify-between border-t border-slate-200 px-3 py-2 dark:border-border", children: [
1884
1980
  /* @__PURE__ */ c("span", { className: "flex items-center gap-2 text-[10px] tabular-nums text-slate-400", children: [
1885
- (J - 1) * w + 1,
1981
+ (C - 1) * v + 1,
1886
1982
  "–",
1887
- Math.min(J * w, j),
1983
+ Math.min(C * v, K),
1888
1984
  " of",
1889
1985
  " ",
1890
- j.toLocaleString(),
1891
- L && /* @__PURE__ */ c("span", { className: "flex items-center gap-1 text-slate-500", children: [
1892
- /* @__PURE__ */ n(ae, { className: "h-3 w-3 animate-spin" }),
1986
+ K.toLocaleString(),
1987
+ j && /* @__PURE__ */ c("span", { className: "flex items-center gap-1 text-slate-500", children: [
1988
+ /* @__PURE__ */ n(oe, { className: "h-3 w-3 animate-spin" }),
1893
1989
  " Loading…"
1894
1990
  ] })
1895
1991
  ] }),
@@ -1898,23 +1994,23 @@ function Rr({
1898
1994
  "button",
1899
1995
  {
1900
1996
  type: "button",
1901
- disabled: J <= 1 || L,
1902
- onClick: () => xe((i) => Math.max(1, i - 1)),
1997
+ disabled: C <= 1 || j,
1998
+ onClick: () => ke((a) => Math.max(1, a - 1)),
1903
1999
  className: "rounded border border-slate-200 px-2 py-0.5 text-[11px] text-slate-600 transition-colors hover:bg-slate-50 disabled:opacity-40 dark:border-border dark:text-slate-300 dark:hover:bg-white/[0.04]",
1904
2000
  children: "‹ Prev"
1905
2001
  }
1906
2002
  ),
1907
2003
  /* @__PURE__ */ c("span", { className: "px-1 text-[10px] tabular-nums text-slate-400", children: [
1908
- J,
2004
+ C,
1909
2005
  " / ",
1910
- F.toLocaleString()
2006
+ b.toLocaleString()
1911
2007
  ] }),
1912
2008
  /* @__PURE__ */ n(
1913
2009
  "button",
1914
2010
  {
1915
2011
  type: "button",
1916
- disabled: J >= F || L,
1917
- onClick: () => xe((i) => Math.min(F, i + 1)),
2012
+ disabled: C >= b || j,
2013
+ onClick: () => ke((a) => Math.min(b, a + 1)),
1918
2014
  className: "rounded border border-slate-200 px-2 py-0.5 text-[11px] text-slate-600 transition-colors hover:bg-slate-50 disabled:opacity-40 dark:border-border dark:text-slate-300 dark:hover:bg-white/[0.04]",
1919
2015
  children: "Next ›"
1920
2016
  }
@@ -1925,10 +2021,10 @@ function Rr({
1925
2021
  }
1926
2022
  )
1927
2023
  ] }),
1928
- ke
2024
+ xe
1929
2025
  );
1930
2026
  }
1931
2027
  export {
1932
- en as CatalogPickerField,
1933
- Ut as matchesShowWhen
2028
+ bn as CatalogPickerField,
2029
+ Yt as matchesShowWhen
1934
2030
  };