@nivaro/react 0.3.88 → 0.3.90

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.
@@ -1,49 +1,49 @@
1
- import { jsxs as i, Fragment as Ne, jsx as t } from "react/jsx-runtime";
2
- import { useQueryClient as Ue, useQuery as V, useQueries as Te, useMutation as pe } from "@tanstack/react-query";
3
- import { FileDiff as Ze, ChevronDown as et, Paperclip as Qe, Loader2 as tt, Upload as rt } from "lucide-react";
4
- import { useState as O, useRef as Me, useEffect as Be, useMemo as oe, Fragment as Ce, useCallback as Ee, memo as nt } from "react";
5
- import { toast as z } from "sonner";
6
- import { useNivaroClient as xe, useItemEditAuth as at } from "../../context.js";
7
- import { get as U, post as ve, del as lt } from "../../lib/commands.js";
8
- import { sanitizeHtml as st } from "../../lib/sanitize-html.js";
1
+ import { jsxs as i, Fragment as Ne, jsx as r } from "react/jsx-runtime";
2
+ import { useQueryClient as Be, useQuery as V, useQueries as Le, useMutation as pe } from "@tanstack/react-query";
3
+ import { FileDiff as tt, ChevronDown as rt, Paperclip as Ie, Loader2 as nt, Upload as at } from "lucide-react";
4
+ import { useState as R, useRef as Pe, useEffect as Je, useMemo as de, Fragment as Se, useCallback as Ke, memo as lt } from "react";
5
+ import { toast as E } from "sonner";
6
+ import { useNivaroClient as xe, useItemEditAuth as st } from "../../context.js";
7
+ import { get as L, post as ve, del as it } from "../../lib/commands.js";
8
+ import { sanitizeHtml as ot } from "../../lib/sanitize-html.js";
9
9
  import { titleCase as fe } from "../../lib/utils.js";
10
- import { DocumentAutofillButton as it } from "../import/DocumentAutofillButton.js";
11
- import { FieldRenderer as ot } from "../item-edit/FieldRenderer.js";
12
- import { useFileDownload as dt } from "../item-edit/file-download.js";
13
- import { evalClientFormula as ct } from "../item-edit/InlineTableField.js";
14
- import { parseRollupParentFilter as Le, matchesRollupFilter as mt, computeLiveRollup as Ie, parseRollupSources as Je } from "../item-edit/live-rollups.js";
15
- import { useLocalLiveRows as ut, LiveRowsContext as pt, O2MStagingContext as ft, useLiveRows as ht } from "../item-edit/O2MStagingContext.js";
16
- import { Button as I } from "../ui/button.js";
17
- import { Input as Pe } from "../ui/input.js";
10
+ import { DocumentAutofillButton as dt } from "../import/DocumentAutofillButton.js";
11
+ import { FieldRenderer as ct } from "../item-edit/FieldRenderer.js";
12
+ import { useFileDownload as mt } from "../item-edit/file-download.js";
13
+ import { evalClientFormula as ut } from "../item-edit/InlineTableField.js";
14
+ import { parseRollupParentFilter as ze, matchesRollupFilter as pt, computeLiveRollup as We, parseRollupSources as He } from "../item-edit/live-rollups.js";
15
+ import { useLocalLiveRows as ft, LiveRowsContext as ht, O2MStagingContext as xt, useLiveRows as bt } from "../item-edit/O2MStagingContext.js";
16
+ import { Button as Q } from "../ui/button.js";
17
+ import { Input as je } from "../ui/input.js";
18
18
  import { Label as he } from "../ui/label.js";
19
- import { Sheet as xt, SheetContent as bt, SheetHeader as gt, SheetTitle as vt } from "../ui/sheet.js";
20
- import { Skeleton as le } from "../ui/skeleton.js";
21
- import { Textarea as yt } from "../ui/textarea.js";
22
- import { AddendumCompare as Nt } from "./AddendumCompare.js";
23
- import { AddendumLinesDiff as Ke } from "./AddendumLinesDiff.js";
24
- import { resolveAddendumAmounts as kt } from "./addendum-summary.js";
25
- const ye = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }), _t = (r) => r.replace(/<[^>]+>/g, " ").replace(/&nbsp;/g, " ").replace(/\s+/g, " ").trim();
26
- function ze(r) {
27
- const c = Number(r);
28
- return !r || Number.isNaN(c) || c === 0 ? null : /* @__PURE__ */ i(
19
+ import { Sheet as gt, SheetContent as vt, SheetHeader as yt, SheetTitle as Nt } from "../ui/sheet.js";
20
+ import { Skeleton as re } from "../ui/skeleton.js";
21
+ import { Textarea as kt } from "../ui/textarea.js";
22
+ import { AddendumCompare as _t } from "./AddendumCompare.js";
23
+ import { AddendumLinesDiff as Ue } from "./AddendumLinesDiff.js";
24
+ import { resolveAddendumAmounts as wt } from "./addendum-summary.js";
25
+ const ye = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }), Ct = (t) => t.replace(/<[^>]+>/g, " ").replace(/&nbsp;/g, " ").replace(/\s+/g, " ").trim();
26
+ function Qe(t) {
27
+ const m = Number(t);
28
+ return !t || Number.isNaN(m) || m === 0 ? null : /* @__PURE__ */ i(
29
29
  "span",
30
30
  {
31
- className: T(
31
+ className: D(
32
32
  "inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-medium tabular-nums",
33
- c > 0 ? "bg-emerald-50 text-emerald-700 dark:bg-emerald-500/10 dark:text-emerald-400" : "bg-red-50 text-red-600 dark:bg-red-500/10 dark:text-red-400"
33
+ m > 0 ? "bg-emerald-50 text-emerald-700 dark:bg-emerald-500/10 dark:text-emerald-400" : "bg-red-50 text-red-600 dark:bg-red-500/10 dark:text-red-400"
34
34
  ),
35
35
  children: [
36
- c > 0 ? "+" : "−",
37
- ye.format(Math.abs(c))
36
+ m > 0 ? "+" : "−",
37
+ ye.format(Math.abs(m))
38
38
  ]
39
39
  }
40
40
  );
41
41
  }
42
- function wt({ amounts: r }) {
43
- const { previous: c, next: N, change: h } = r, k = h != null && h !== 0, u = [
42
+ function St({ amounts: t }) {
43
+ const { previous: m, next: N, change: b } = t, _ = b != null && b !== 0, p = [
44
44
  {
45
45
  label: "Previous",
46
- value: c == null ? "—" : ye.format(c),
46
+ value: m == null ? "—" : ye.format(m),
47
47
  className: "text-slate-500 dark:text-slate-400"
48
48
  },
49
49
  {
@@ -53,20 +53,20 @@ function wt({ amounts: r }) {
53
53
  },
54
54
  {
55
55
  label: "Change",
56
- value: h == null ? "—" : k ? `${h > 0 ? "+" : "−"}${ye.format(Math.abs(h))}` : "No change",
57
- className: k ? h > 0 ? "font-semibold text-emerald-600 dark:text-emerald-400" : "font-semibold text-red-600 dark:text-red-400" : "text-slate-500 dark:text-slate-400"
56
+ value: b == null ? "—" : _ ? `${b > 0 ? "+" : "−"}${ye.format(Math.abs(b))}` : "No change",
57
+ className: _ ? b > 0 ? "font-semibold text-emerald-600 dark:text-emerald-400" : "font-semibold text-red-600 dark:text-red-400" : "text-slate-500 dark:text-slate-400"
58
58
  }
59
59
  ];
60
- return /* @__PURE__ */ t("div", { className: "flex flex-wrap items-start gap-x-8 gap-y-2", children: u.map((x) => /* @__PURE__ */ i("div", { className: "min-w-0", children: [
61
- /* @__PURE__ */ t("p", { className: T("text-[13px] leading-5 tabular-nums", x.className), children: x.value }),
62
- /* @__PURE__ */ t("p", { className: "text-[11px] leading-4 text-slate-400 dark:text-slate-500", children: x.label })
63
- ] }, x.label)) });
60
+ return /* @__PURE__ */ r("div", { className: "flex flex-wrap items-start gap-x-8 gap-y-2", children: p.map((g) => /* @__PURE__ */ i("div", { className: "min-w-0", children: [
61
+ /* @__PURE__ */ r("p", { className: D("text-[13px] leading-5 tabular-nums", g.className), children: g.value }),
62
+ /* @__PURE__ */ r("p", { className: "text-[11px] leading-4 text-slate-400 dark:text-slate-500", children: g.label })
63
+ ] }, g.label)) });
64
64
  }
65
- const We = "grid grid-cols-1 items-baseline text-[12.5px] sm:grid-cols-[140px_minmax(0,1fr)] sm:gap-x-6 sm:gap-y-2.5", de = "text-[12px] text-slate-500 dark:text-slate-400", ce = "mb-2.5 min-w-0 text-slate-700 sm:mb-0 dark:text-slate-200";
66
- function T(...r) {
67
- return r.filter(Boolean).join(" ");
65
+ const Ve = "grid grid-cols-1 items-baseline text-[12.5px] sm:grid-cols-[140px_minmax(0,1fr)] sm:gap-x-6 sm:gap-y-2.5", ce = "text-[12px] text-slate-500 dark:text-slate-400", me = "mb-2.5 min-w-0 text-slate-700 sm:mb-0 dark:text-slate-200";
66
+ function D(...t) {
67
+ return t.filter(Boolean).join(" ");
68
68
  }
69
- const Ae = {
69
+ const Me = {
70
70
  draft: {
71
71
  badge: "bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-400",
72
72
  dot: "bg-slate-400"
@@ -87,41 +87,41 @@ const Ae = {
87
87
  badge: "bg-amber-50 text-amber-700 dark:bg-amber-500/10 dark:text-amber-400",
88
88
  dot: "bg-amber-500"
89
89
  }
90
- }, Ct = (r, c) => Math.round(Number(r) * 100) === Math.round(Number(c) * 100);
91
- function St(r, c, N) {
92
- if (!N || r.computed_type !== "rollup" || !r.computed_formula) return r;
93
- const h = Ie(Je(r.computed_formula), N.rows);
94
- return h === null || c != null && Ct(c, h) ? r : {
95
- ...r,
90
+ }, $t = (t, m) => Math.round(Number(t) * 100) === Math.round(Number(m) * 100);
91
+ function qt(t, m, N) {
92
+ if (!N || t.computed_type !== "rollup" || !t.computed_formula) return t;
93
+ const b = We(He(t.computed_formula), N.rows);
94
+ return b === null || m != null && $t(m, b) ? t : {
95
+ ...t,
96
96
  options: {
97
- ...r.options ?? {},
98
- __live_delta: { original: c, live: h }
97
+ ...t.options ?? {},
98
+ __live_delta: { original: m, live: b }
99
99
  }
100
100
  };
101
101
  }
102
- function $t({
103
- current: r,
104
- value: c,
102
+ function Ft({
103
+ current: t,
104
+ value: m,
105
105
  onChange: N,
106
- currentLabel: h,
107
- newLabel: k
106
+ currentLabel: b,
107
+ newLabel: _
108
108
  }) {
109
- const [u, x] = O(() => {
110
- const v = Number(c);
111
- return !Number.isFinite(v) || Math.round(v * 100) === Math.round(r * 100) ? "" : String(Math.round((v - r) * 100) / 100);
112
- }), _ = u.trim() === "" ? 0 : Number(u), f = Number.isFinite(_), $ = f ? Math.round((r + _) * 100) / 100 : r, m = (v) => v.toLocaleString("en-US", { style: "currency", currency: "USD" });
109
+ const [p, g] = R(() => {
110
+ const y = Number(m);
111
+ return !Number.isFinite(y) || Math.round(y * 100) === Math.round(t * 100) ? "" : String(Math.round((y - t) * 100) / 100);
112
+ }), w = p.trim() === "" ? 0 : Number(p), h = Number.isFinite(w), $ = h ? Math.round((t + w) * 100) / 100 : t, u = (y) => y.toLocaleString("en-US", { style: "currency", currency: "USD" });
113
113
  return /* @__PURE__ */ i("div", { className: "space-y-1.5", children: [
114
114
  /* @__PURE__ */ i("div", { className: "flex items-center gap-0", children: [
115
- /* @__PURE__ */ t("span", { className: "flex h-9 items-center rounded-l-md border border-r-0 border-slate-200 bg-slate-50 px-2.5 text-[13px] text-slate-500 dark:border-border dark:bg-muted", children: "$" }),
116
- /* @__PURE__ */ t(
117
- Pe,
115
+ /* @__PURE__ */ r("span", { className: "flex h-9 items-center rounded-l-md border border-r-0 border-slate-200 bg-slate-50 px-2.5 text-[13px] text-slate-500 dark:border-border dark:bg-muted", children: "$" }),
116
+ /* @__PURE__ */ r(
117
+ je,
118
118
  {
119
- value: u,
120
- onChange: (v) => {
121
- const w = v.target.value;
122
- x(w);
123
- const S = w.trim() === "" ? 0 : Number(w);
124
- Number.isFinite(S) && N(Math.round((r + S) * 100) / 100);
119
+ value: p,
120
+ onChange: (y) => {
121
+ const S = y.target.value;
122
+ g(S);
123
+ const B = S.trim() === "" ? 0 : Number(S);
124
+ Number.isFinite(B) && N(Math.round((t + B) * 100) / 100);
125
125
  },
126
126
  placeholder: "Negative numbers to decrease",
127
127
  className: "h-9 rounded-l-none text-[13px]"
@@ -130,289 +130,289 @@ function $t({
130
130
  ] }),
131
131
  /* @__PURE__ */ i("p", { className: "text-[12px]", children: [
132
132
  /* @__PURE__ */ i("span", { className: "font-medium text-slate-600 dark:text-slate-300", children: [
133
- h ?? "Current REQ Amount",
133
+ b ?? "Current REQ Amount",
134
134
  ":"
135
135
  ] }),
136
136
  " ",
137
- /* @__PURE__ */ t("span", { className: "tabular-nums text-slate-700 dark:text-slate-200", children: m(r) }),
138
- /* @__PURE__ */ t("span", { className: "mx-2 text-slate-300", children: "·" }),
137
+ /* @__PURE__ */ r("span", { className: "tabular-nums text-slate-700 dark:text-slate-200", children: u(t) }),
138
+ /* @__PURE__ */ r("span", { className: "mx-2 text-slate-300", children: "·" }),
139
139
  /* @__PURE__ */ i("span", { className: "font-medium text-slate-600 dark:text-slate-300", children: [
140
- k ?? "New REQ Total",
140
+ _ ?? "New REQ Total",
141
141
  ":"
142
142
  ] }),
143
143
  " ",
144
- /* @__PURE__ */ t(
144
+ /* @__PURE__ */ r(
145
145
  "span",
146
146
  {
147
- className: "tabular-nums font-semibold " + ($ > r ? "text-emerald-600 dark:text-emerald-400" : $ < r ? "text-red-600 dark:text-red-400" : "text-slate-700 dark:text-slate-200"),
148
- children: m($)
147
+ className: "tabular-nums font-semibold " + ($ > t ? "text-emerald-600 dark:text-emerald-400" : $ < t ? "text-red-600 dark:text-red-400" : "text-slate-700 dark:text-slate-200"),
148
+ children: u($)
149
149
  }
150
150
  ),
151
- !f && /* @__PURE__ */ t("span", { className: "ml-2 text-[11px] text-red-500", children: "Enter a number" })
151
+ !h && /* @__PURE__ */ r("span", { className: "ml-2 text-[11px] text-red-500", children: "Enter a number" })
152
152
  ] })
153
153
  ] });
154
154
  }
155
- const qt = nt(function({
156
- configuredFields: c,
155
+ const At = lt(function({
156
+ configuredFields: m,
157
157
  fieldMap: N,
158
- formData: h,
159
- onFieldChange: k,
160
- relations: u,
161
- collection: x,
162
- prefillParentId: _,
163
- parentData: f
158
+ formData: b,
159
+ onFieldChange: _,
160
+ relations: p,
161
+ collection: g,
162
+ prefillParentId: w,
163
+ parentData: h
164
164
  }) {
165
- const $ = ht();
166
- return c.length === 0 ? /* @__PURE__ */ t("div", { className: "rounded-lg border border-dashed border-slate-200 bg-slate-50 px-4 py-6 text-center dark:border-border dark:bg-muted/30", children: /* @__PURE__ */ t("p", { className: "text-[12px] text-slate-400 dark:text-slate-500", children: "No fields configured for addendum. Set up the field list in Data Model → Layouts → Addendum Form." }) }) : /* @__PURE__ */ i("div", { className: "border-t border-slate-100 dark:border-border pt-3", children: [
167
- /* @__PURE__ */ t("p", { className: "mb-3 text-[11px] font-semibold uppercase tracking-wide text-slate-400 dark:text-slate-500", children: "Proposed changes" }),
168
- /* @__PURE__ */ t("div", { className: "space-y-3", children: c.map((m) => {
169
- const v = N[m.field], w = m.label_override ?? fe((v == null ? void 0 : v.field) ?? m.field);
170
- if (!v)
165
+ const $ = bt();
166
+ return m.length === 0 ? /* @__PURE__ */ r("div", { className: "rounded-lg border border-dashed border-slate-200 bg-slate-50 px-4 py-6 text-center dark:border-border dark:bg-muted/30", children: /* @__PURE__ */ r("p", { className: "text-[12px] text-slate-400 dark:text-slate-500", children: "No fields configured for addendum. Set up the field list in Data Model → Layouts → Addendum Form." }) }) : /* @__PURE__ */ i("div", { className: "border-t border-slate-100 dark:border-border pt-3", children: [
167
+ /* @__PURE__ */ r("p", { className: "mb-3 text-[11px] font-semibold uppercase tracking-wide text-slate-400 dark:text-slate-500", children: "Proposed changes" }),
168
+ /* @__PURE__ */ r("div", { className: "space-y-3", children: m.map((u) => {
169
+ const y = N[u.field], S = u.label_override ?? fe((y == null ? void 0 : y.field) ?? u.field);
170
+ if (!y)
171
171
  return /* @__PURE__ */ i("div", { children: [
172
- /* @__PURE__ */ t(he, { className: "mb-1 block text-[11px] font-medium text-slate-600 dark:text-slate-400", children: w }),
173
- /* @__PURE__ */ t(
174
- Pe,
172
+ /* @__PURE__ */ r(he, { className: "mb-1 block text-[11px] font-medium text-slate-600 dark:text-slate-400", children: S }),
173
+ /* @__PURE__ */ r(
174
+ je,
175
175
  {
176
- value: String(h[m.field] ?? ""),
177
- onChange: (j) => k(m.field, j.target.value),
176
+ value: String(b[u.field] ?? ""),
177
+ onChange: (I) => _(u.field, I.target.value),
178
178
  className: "h-8 text-[12px]"
179
179
  }
180
180
  )
181
- ] }, m.field);
182
- const D = (typeof m.overrides == "string" ? (() => {
181
+ ] }, u.field);
182
+ const k = (typeof u.overrides == "string" ? (() => {
183
183
  try {
184
- return JSON.parse(m.overrides);
184
+ return JSON.parse(u.overrides);
185
185
  } catch {
186
186
  return {};
187
187
  }
188
- })() : m.overrides ?? {}).options ?? {};
189
- if (D.entry_mode === "delta") {
190
- const j = Number((f == null ? void 0 : f[m.field]) ?? 0);
188
+ })() : u.overrides ?? {}).options ?? {};
189
+ if (k.entry_mode === "delta") {
190
+ const I = Number((h == null ? void 0 : h[u.field]) ?? 0);
191
191
  return /* @__PURE__ */ i("div", { children: [
192
- /* @__PURE__ */ t(he, { className: "mb-1 block text-[11px] font-medium text-slate-600 dark:text-slate-400", children: w }),
193
- /* @__PURE__ */ t(
194
- $t,
192
+ /* @__PURE__ */ r(he, { className: "mb-1 block text-[11px] font-medium text-slate-600 dark:text-slate-400", children: S }),
193
+ /* @__PURE__ */ r(
194
+ Ft,
195
195
  {
196
- current: Number.isFinite(j) ? j : 0,
197
- value: h[m.field],
198
- onChange: (P) => k(m.field, P),
199
- currentLabel: typeof D.current_label == "string" ? D.current_label : void 0,
200
- newLabel: typeof D.new_label == "string" ? D.new_label : void 0
196
+ current: Number.isFinite(I) ? I : 0,
197
+ value: b[u.field],
198
+ onChange: (q) => _(u.field, q),
199
+ currentLabel: typeof k.current_label == "string" ? k.current_label : void 0,
200
+ newLabel: typeof k.new_label == "string" ? k.new_label : void 0
201
201
  }
202
202
  )
203
- ] }, m.field);
203
+ ] }, u.field);
204
204
  }
205
205
  return /* @__PURE__ */ i("div", { children: [
206
- /* @__PURE__ */ t(he, { className: "mb-1 block text-[11px] font-medium text-slate-600 dark:text-slate-400", children: w }),
207
- /* @__PURE__ */ t(
208
- ot,
206
+ /* @__PURE__ */ r(he, { className: "mb-1 block text-[11px] font-medium text-slate-600 dark:text-slate-400", children: S }),
207
+ /* @__PURE__ */ r(
208
+ ct,
209
209
  {
210
- field: St(v, h[m.field], $),
211
- value: h[m.field],
212
- onChange: (j) => k(m.field, j),
213
- relations: u,
214
- collection: x,
210
+ field: qt(y, b[u.field], $),
211
+ value: b[u.field],
212
+ onChange: (I) => _(u.field, I),
213
+ relations: p,
214
+ collection: g,
215
215
  itemId: "new",
216
- prefillParentId: _
216
+ prefillParentId: w
217
217
  }
218
218
  )
219
- ] }, m.field);
219
+ ] }, u.field);
220
220
  }) })
221
221
  ] });
222
222
  });
223
- function Ft({ addendumId: r }) {
224
- const c = xe(), { data: N, isLoading: h } = V({
225
- queryKey: ["pipeline-instance", "nivaro_addendums", r],
226
- queryFn: () => c.request(U(`/pipelines/instance/nivaro_addendums/${r}`)).then((x) => x.data),
223
+ function Mt({ addendumId: t }) {
224
+ const m = xe(), { data: N, isLoading: b } = V({
225
+ queryKey: ["pipeline-instance", "nivaro_addendums", t],
226
+ queryFn: () => m.request(L(`/pipelines/instance/nivaro_addendums/${t}`)).then((g) => g.data),
227
227
  staleTime: 1e4
228
228
  });
229
- if (h) return /* @__PURE__ */ t(le, { className: "h-8 w-full" });
229
+ if (b) return /* @__PURE__ */ r(re, { className: "h-8 w-full" });
230
230
  if (!(N != null && N.instance))
231
- return /* @__PURE__ */ t("p", { className: "text-[12px] text-slate-400 italic", children: "No workflow instance found." });
232
- const { instance: k } = N, u = k.current_state_obj;
231
+ return /* @__PURE__ */ r("p", { className: "text-[12px] text-slate-400 italic", children: "No workflow instance found." });
232
+ const { instance: _ } = N, p = _.current_state_obj;
233
233
  return /* @__PURE__ */ i("div", { className: "space-y-3", children: [
234
- u && /* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
235
- /* @__PURE__ */ t("span", { className: "text-[11px] text-slate-500", children: "Current state:" }),
236
- /* @__PURE__ */ t(
234
+ p && /* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
235
+ /* @__PURE__ */ r("span", { className: "text-[11px] text-slate-500", children: "Current state:" }),
236
+ /* @__PURE__ */ r(
237
237
  "span",
238
238
  {
239
239
  className: "inline-flex items-center rounded-full px-2.5 py-0.5 text-[11px] font-medium",
240
240
  style: {
241
- backgroundColor: u.color ? `${u.color}22` : "#f1f5f9",
242
- color: u.color ?? "#475569",
243
- border: `1px solid ${u.color ? `${u.color}44` : "#e2e8f0"}`
241
+ backgroundColor: p.color ? `${p.color}22` : "#f1f5f9",
242
+ color: p.color ?? "#475569",
243
+ border: `1px solid ${p.color ? `${p.color}44` : "#e2e8f0"}`
244
244
  },
245
- children: u.label
245
+ children: p.label
246
246
  }
247
247
  )
248
248
  ] }),
249
- k.completed_at && /* @__PURE__ */ t("p", { className: "text-[11px] text-slate-400 italic", children: "Workflow complete." })
249
+ _.completed_at && /* @__PURE__ */ r("p", { className: "text-[11px] text-slate-400 italic", children: "Workflow complete." })
250
250
  ] });
251
251
  }
252
- function At({
253
- collection: r,
254
- itemId: c,
252
+ function Pt({
253
+ collection: t,
254
+ itemId: m,
255
255
  assignments: N,
256
- workflowTemplateId: h,
257
- resolvedLayoutId: k,
258
- fields: u,
259
- relations: x,
260
- parentData: _,
261
- onClose: f,
256
+ workflowTemplateId: b,
257
+ resolvedLayoutId: _,
258
+ fields: p,
259
+ relations: g,
260
+ parentData: w,
261
+ onClose: h,
262
262
  onCreated: $
263
263
  }) {
264
- const m = xe(), v = N.filter(
264
+ const u = xe(), y = N.filter(
265
265
  (a) => !String(a.field).startsWith("__") && (a.is_visible || a.is_visible === 1)
266
- ), [w, S] = O(""), [D, j] = O(""), [P, J] = O([]), [ee, A] = O(0), G = Me(null), M = async (a) => {
266
+ ), [S, B] = R(""), [k, I] = R(""), [q, Y] = R([]), [J, A] = R(0), G = Pe(null), P = async (a) => {
267
267
  if (a.length !== 0) {
268
268
  A((s) => s + a.length);
269
269
  for (const s of a)
270
270
  try {
271
- const d = await m.upload(s);
272
- J((o) => [...o, { id: String(d.id), name: s.name }]);
271
+ const f = await u.upload(s);
272
+ Y((d) => [...d, { id: String(f.id), name: s.name }]);
273
273
  } catch {
274
- z.error(`Failed to upload ${s.name}`);
274
+ E.error(`Failed to upload ${s.name}`);
275
275
  } finally {
276
- A((d) => d - 1);
276
+ A((f) => f - 1);
277
277
  }
278
278
  }
279
- }, [te, E] = O(() => {
279
+ }, [K, X] = R(() => {
280
280
  const a = {};
281
- for (const s of v) {
282
- const d = typeof s.overrides == "string" ? (() => {
281
+ for (const s of y) {
282
+ const f = typeof s.overrides == "string" ? (() => {
283
283
  try {
284
284
  return JSON.parse(s.overrides);
285
285
  } catch {
286
286
  return {};
287
287
  }
288
- })() : s.overrides ?? {}, o = (d == null ? void 0 : d.prefill_from_parent) !== !1;
289
- a[s.field] = o ? _[s.field] ?? null : null;
288
+ })() : s.overrides ?? {}, d = (f == null ? void 0 : f.prefill_from_parent) !== !1;
289
+ a[s.field] = d ? w[s.field] ?? null : null;
290
290
  }
291
291
  return a;
292
- }), me = oe(() => {
292
+ }), W = de(() => {
293
293
  const a = {};
294
- for (const s of u) a[s.field] = s;
294
+ for (const s of p) a[s.field] = s;
295
295
  return a;
296
- }, [u]), X = Ee((a, s) => {
297
- E((d) => ({ ...d, [a]: s }));
298
- }, []), W = Ee(
296
+ }, [p]), ne = Ke((a, s) => {
297
+ X((f) => ({ ...f, [a]: s }));
298
+ }, []), ae = Ke(
299
299
  (a) => {
300
- E((s) => ({ ...s, ...a.values })), !w.trim() && a.summary && S(a.summary.slice(0, 120));
301
- for (const [s, d] of Object.entries(a.lines_by_alias)) {
302
- const o = x.find(
303
- (C) => C.one_collection === r && !C.junction_field && (C.one_field === s || C.many_collection === s)
300
+ X((s) => ({ ...s, ...a.values })), !S.trim() && a.summary && B(a.summary.slice(0, 120));
301
+ for (const [s, f] of Object.entries(a.lines_by_alias)) {
302
+ const d = g.find(
303
+ (C) => C.one_collection === t && !C.junction_field && (C.one_field === s || C.many_collection === s)
304
304
  );
305
- if (!(o != null && o.many_collection) || !o.many_field) continue;
306
- const b = o.many_field, y = `${o.many_collection}.${b}`;
307
- L((C) => {
308
- const q = new Map(C);
309
- return q.set(y, [
310
- ...q.get(y) ?? [],
311
- ...d.map((ae) => ({ ...ae.values, [b]: c }))
312
- ]), q;
305
+ if (!(d != null && d.many_collection) || !d.many_field) continue;
306
+ const c = d.many_field, x = `${d.many_collection}.${c}`;
307
+ z((C) => {
308
+ const M = new Map(C);
309
+ return M.set(x, [
310
+ ...M.get(x) ?? [],
311
+ ...f.map((oe) => ({ ...oe.values, [c]: m }))
312
+ ]), M;
313
313
  });
314
314
  }
315
- a.file_id && J((s) => [...s, { id: a.file_id, name: a.document_name }]);
315
+ a.file_id && Y((s) => [...s, { id: a.file_id, name: a.document_name }]);
316
316
  },
317
- [r, c, x, w]
318
- ), [Y, L] = O(
317
+ [t, m, g, S]
318
+ ), [j, z] = R(
319
319
  /* @__PURE__ */ new Map()
320
- ), [re, se] = O(/* @__PURE__ */ new Map()), [ne, ie] = O(/* @__PURE__ */ new Map()), Z = Me(Y);
321
- Be(() => {
322
- Z.current = Y;
323
- }, [Y]);
324
- const Q = ut(), R = oe(
320
+ ), [Z, le] = R(/* @__PURE__ */ new Map()), [se, te] = R(/* @__PURE__ */ new Map()), ie = Pe(j);
321
+ Je(() => {
322
+ ie.current = j;
323
+ }, [j]);
324
+ const O = ft(), ee = de(
325
325
  () => ({
326
- getPendingRows: (a, s) => Y.get(`${a}.${s}`) ?? [],
327
- queueRow: (a, s, d) => L((o) => {
328
- const b = new Map(o), y = `${a}.${s}`;
329
- return b.set(y, [...b.get(y) ?? [], d]), b;
326
+ getPendingRows: (a, s) => j.get(`${a}.${s}`) ?? [],
327
+ queueRow: (a, s, f) => z((d) => {
328
+ const c = new Map(d), x = `${a}.${s}`;
329
+ return c.set(x, [...c.get(x) ?? [], f]), c;
330
330
  }),
331
- removeRow: (a, s, d) => L((o) => {
332
- const b = new Map(o), y = `${a}.${s}`, C = [...b.get(y) ?? []];
333
- return C.splice(d, 1), b.set(y, C), b;
331
+ removeRow: (a, s, f) => z((d) => {
332
+ const c = new Map(d), x = `${a}.${s}`, C = [...c.get(x) ?? []];
333
+ return C.splice(f, 1), c.set(x, C), c;
334
334
  }),
335
- updateRow: (a, s, d, o) => L((b) => {
336
- const y = new Map(b), C = `${a}.${s}`, q = [...y.get(C) ?? []];
337
- return q[d] = { ...q[d], ...o }, y.set(C, q), y;
335
+ updateRow: (a, s, f, d) => z((c) => {
336
+ const x = new Map(c), C = `${a}.${s}`, M = [...x.get(C) ?? []];
337
+ return M[f] = { ...M[f], ...d }, x.set(C, M), x;
338
338
  }),
339
- reorderRows: (a, s, d, o) => L((b) => {
340
- const y = new Map(b), C = `${a}.${s}`, q = [...y.get(C) ?? []], [ae] = q.splice(d, 1);
341
- return q.splice(o, 0, ae), y.set(C, q), y;
339
+ reorderRows: (a, s, f, d) => z((c) => {
340
+ const x = new Map(c), C = `${a}.${s}`, M = [...x.get(C) ?? []], [oe] = M.splice(f, 1);
341
+ return M.splice(d, 0, oe), x.set(C, M), x;
342
342
  }),
343
- getPendingEdits: (a, s) => re.get(`${a}.${s}`) ?? /* @__PURE__ */ new Map(),
344
- getPendingDeletes: (a, s) => ne.get(`${a}.${s}`) ?? /* @__PURE__ */ new Set(),
345
- queueEdit: (a, s, d, o) => se((b) => {
346
- const y = new Map(b), C = `${a}.${s}`, q = new Map(y.get(C) ?? []);
347
- return q.set(d, { ...q.get(d) ?? {}, ...o }), y.set(C, q), y;
343
+ getPendingEdits: (a, s) => Z.get(`${a}.${s}`) ?? /* @__PURE__ */ new Map(),
344
+ getPendingDeletes: (a, s) => se.get(`${a}.${s}`) ?? /* @__PURE__ */ new Set(),
345
+ queueEdit: (a, s, f, d) => le((c) => {
346
+ const x = new Map(c), C = `${a}.${s}`, M = new Map(x.get(C) ?? []);
347
+ return M.set(f, { ...M.get(f) ?? {}, ...d }), x.set(C, M), x;
348
348
  }),
349
- queueDelete: (a, s, d) => ie((o) => {
350
- const b = new Map(o), y = `${a}.${s}`;
351
- return b.set(y, /* @__PURE__ */ new Set([...b.get(y) ?? [], d])), b;
349
+ queueDelete: (a, s, f) => te((d) => {
350
+ const c = new Map(d), x = `${a}.${s}`;
351
+ return c.set(x, /* @__PURE__ */ new Set([...c.get(x) ?? [], f])), c;
352
352
  }),
353
- cancelPendingEdit: (a, s, d) => se((o) => {
354
- const b = new Map(o), y = `${a}.${s}`, C = new Map(b.get(y) ?? []);
355
- return C.delete(d), b.set(y, C), b;
353
+ cancelPendingEdit: (a, s, f) => le((d) => {
354
+ const c = new Map(d), x = `${a}.${s}`, C = new Map(c.get(x) ?? []);
355
+ return C.delete(f), c.set(x, C), c;
356
356
  }),
357
- cancelPendingDelete: (a, s, d) => ie((o) => {
358
- const b = new Map(o), y = `${a}.${s}`, C = new Set(b.get(y) ?? []);
359
- return C.delete(d), b.set(y, C), b;
357
+ cancelPendingDelete: (a, s, f) => te((d) => {
358
+ const c = new Map(d), x = `${a}.${s}`, C = new Set(c.get(x) ?? []);
359
+ return C.delete(f), c.set(x, C), c;
360
360
  })
361
361
  }),
362
- [Y, re, ne]
363
- ), p = pe({
362
+ [j, Z, se]
363
+ ), o = pe({
364
364
  mutationFn: () => {
365
365
  const a = {};
366
- for (const [s, d] of Object.entries(te)) {
367
- const o = me[s];
368
- (o == null ? void 0 : o.computed_type) === "rollup" || (o == null ? void 0 : o.computed_type) === "write" || d !== void 0 && String(d ?? "") !== String(_[s] ?? "") && (a[s] = d);
366
+ for (const [s, f] of Object.entries(K)) {
367
+ const d = W[s];
368
+ (d == null ? void 0 : d.computed_type) === "rollup" || (d == null ? void 0 : d.computed_type) === "write" || f !== void 0 && String(f ?? "") !== String(w[s] ?? "") && (a[s] = f);
369
369
  }
370
- for (const s of v) {
371
- const d = x.find(
372
- (o) => o.one_collection === r && !o.junction_field && (o.one_field === s.field || o.many_collection === s.field)
370
+ for (const s of y) {
371
+ const f = g.find(
372
+ (d) => d.one_collection === t && !d.junction_field && (d.one_field === s.field || d.many_collection === s.field)
373
373
  );
374
- if (d != null && d.many_collection && d.many_field) {
375
- const o = (Z.current.get(`${d.many_collection}.${d.many_field}`) ?? []).map(({ __prefilled: b, ...y }) => y);
376
- o.length > 0 && (a[s.field] = o);
374
+ if (f != null && f.many_collection && f.many_field) {
375
+ const d = (ie.current.get(`${f.many_collection}.${f.many_field}`) ?? []).map(({ __prefilled: c, ...x }) => x);
376
+ d.length > 0 && (a[s.field] = d);
377
377
  }
378
378
  }
379
- return m.request(
379
+ return u.request(
380
380
  ve("/addendums", {
381
- parent_collection: r,
382
- parent_id: c,
383
- title: w.trim(),
384
- description: D.trim() || void 0,
385
- workflow_template_id: h ?? void 0,
386
- addendum_layout_id: k,
381
+ parent_collection: t,
382
+ parent_id: m,
383
+ title: S.trim(),
384
+ description: k.trim() || void 0,
385
+ workflow_template_id: b ?? void 0,
386
+ addendum_layout_id: _,
387
387
  data: a,
388
- fields_schema: v.map((s) => s.field),
389
- attachments: P.length > 0 ? P.map((s) => s.id) : void 0
388
+ fields_schema: y.map((s) => s.field),
389
+ attachments: q.length > 0 ? q.map((s) => s.id) : void 0
390
390
  })
391
391
  );
392
392
  },
393
393
  onSuccess: (a) => {
394
394
  var s;
395
- z.success("Addendum created"), $(((s = a == null ? void 0 : a.data) == null ? void 0 : s.id) != null ? String(a.data.id) : null), f();
395
+ E.success("Addendum created"), $(((s = a == null ? void 0 : a.data) == null ? void 0 : s.id) != null ? String(a.data.id) : null), h();
396
396
  },
397
- onError: () => z.error("Failed to create addendum")
397
+ onError: () => E.error("Failed to create addendum")
398
398
  });
399
- return /* @__PURE__ */ t(pt.Provider, { value: Q, children: /* @__PURE__ */ t(ft.Provider, { value: R, children: /* @__PURE__ */ i("div", { className: "flex h-full flex-col", children: [
400
- /* @__PURE__ */ i(gt, { className: "shrink-0 border-b border-slate-200 px-5 py-4 dark:border-border", children: [
401
- /* @__PURE__ */ t(vt, { className: "text-[14px] font-semibold text-slate-900 dark:text-slate-100", children: "New Addendum" }),
402
- /* @__PURE__ */ t("p", { className: "mt-0.5 text-[12px] text-slate-500 dark:text-slate-400", children: "Propose changes to this record. Fields are pre-filled with current values — edit what's changing." })
399
+ return /* @__PURE__ */ r(ht.Provider, { value: O, children: /* @__PURE__ */ r(xt.Provider, { value: ee, children: /* @__PURE__ */ i("div", { className: "flex h-full flex-col", children: [
400
+ /* @__PURE__ */ i(yt, { className: "shrink-0 border-b border-slate-200 px-5 py-4 dark:border-border", children: [
401
+ /* @__PURE__ */ r(Nt, { className: "text-[14px] font-semibold text-slate-900 dark:text-slate-100", children: "New Addendum" }),
402
+ /* @__PURE__ */ r("p", { className: "mt-0.5 text-[12px] text-slate-500 dark:text-slate-400", children: "Propose changes to this record. Fields are pre-filled with current values — edit what's changing." })
403
403
  ] }),
404
404
  /* @__PURE__ */ i("div", { className: "flex-1 overflow-y-auto px-5 py-4 space-y-4", children: [
405
405
  /* @__PURE__ */ i("div", { className: "space-y-3", children: [
406
406
  /* @__PURE__ */ i("div", { children: [
407
407
  /* @__PURE__ */ i(he, { className: "mb-1 block text-[11px] font-medium text-slate-600 dark:text-slate-400", children: [
408
408
  "Title ",
409
- /* @__PURE__ */ t("span", { className: "text-red-500", children: "*" })
409
+ /* @__PURE__ */ r("span", { className: "text-red-500", children: "*" })
410
410
  ] }),
411
- /* @__PURE__ */ t(
412
- Pe,
411
+ /* @__PURE__ */ r(
412
+ je,
413
413
  {
414
- value: w,
415
- onChange: (a) => S(a.target.value),
414
+ value: S,
415
+ onChange: (a) => B(a.target.value),
416
416
  className: "h-8 text-[12px]",
417
417
  placeholder: "Brief description of this addendum",
418
418
  autoFocus: !0
@@ -420,12 +420,12 @@ function At({
420
420
  )
421
421
  ] }),
422
422
  /* @__PURE__ */ i("div", { children: [
423
- /* @__PURE__ */ t(he, { className: "mb-1 block text-[11px] font-medium text-slate-600 dark:text-slate-400", children: "Notes" }),
424
- /* @__PURE__ */ t(
425
- yt,
423
+ /* @__PURE__ */ r(he, { className: "mb-1 block text-[11px] font-medium text-slate-600 dark:text-slate-400", children: "Notes" }),
424
+ /* @__PURE__ */ r(
425
+ kt,
426
426
  {
427
- value: D,
428
- onChange: (a) => j(a.target.value),
427
+ value: k,
428
+ onChange: (a) => I(a.target.value),
429
429
  rows: 2,
430
430
  className: "text-[12px]",
431
431
  placeholder: "Why is this change needed?"
@@ -433,8 +433,8 @@ function At({
433
433
  )
434
434
  ] }),
435
435
  /* @__PURE__ */ i("div", { children: [
436
- /* @__PURE__ */ t(he, { className: "mb-1 block text-[11px] font-medium text-slate-600 dark:text-slate-400", children: "Attachments" }),
437
- /* @__PURE__ */ t(
436
+ /* @__PURE__ */ r(he, { className: "mb-1 block text-[11px] font-medium text-slate-600 dark:text-slate-400", children: "Attachments" }),
437
+ /* @__PURE__ */ r(
438
438
  "input",
439
439
  {
440
440
  ref: G,
@@ -442,23 +442,23 @@ function At({
442
442
  multiple: !0,
443
443
  className: "hidden",
444
444
  onChange: (a) => {
445
- M(Array.from(a.target.files ?? [])), a.target.value = "";
445
+ P(Array.from(a.target.files ?? [])), a.target.value = "";
446
446
  }
447
447
  }
448
448
  ),
449
449
  /* @__PURE__ */ i("div", { className: "flex flex-wrap items-center gap-1.5", children: [
450
- P.map((a) => /* @__PURE__ */ i(
450
+ q.map((a) => /* @__PURE__ */ i(
451
451
  "span",
452
452
  {
453
453
  className: "inline-flex max-w-[240px] items-center gap-1 rounded border border-slate-200 bg-slate-50 px-2 py-1 text-[11px] text-slate-700 dark:border-border dark:bg-muted dark:text-slate-200",
454
454
  children: [
455
- /* @__PURE__ */ t(Qe, { className: "h-3 w-3 shrink-0 text-slate-400" }),
456
- /* @__PURE__ */ t("span", { className: "truncate", children: a.name }),
457
- /* @__PURE__ */ t(
455
+ /* @__PURE__ */ r(Ie, { className: "h-3 w-3 shrink-0 text-slate-400" }),
456
+ /* @__PURE__ */ r("span", { className: "truncate", children: a.name }),
457
+ /* @__PURE__ */ r(
458
458
  "button",
459
459
  {
460
460
  type: "button",
461
- onClick: () => J((s) => s.filter((d) => d.id !== a.id)),
461
+ onClick: () => Y((s) => s.filter((f) => f.id !== a.id)),
462
462
  className: "shrink-0 text-slate-400 hover:text-red-500",
463
463
  children: "×"
464
464
  }
@@ -475,145 +475,145 @@ function At({
475
475
  var a;
476
476
  return (a = G.current) == null ? void 0 : a.click();
477
477
  },
478
- disabled: ee > 0,
478
+ disabled: J > 0,
479
479
  className: "inline-flex items-center gap-1.5 rounded-md border border-slate-200 px-2.5 py-1 text-[11px] font-medium text-slate-600 hover:border-slate-300 hover:text-slate-800 disabled:opacity-50 dark:border-border dark:text-slate-300 dark:hover:text-slate-100",
480
480
  children: [
481
- ee > 0 ? /* @__PURE__ */ t(tt, { className: "h-3 w-3 animate-spin" }) : /* @__PURE__ */ t(rt, { className: "h-3 w-3" }),
482
- ee > 0 ? "Uploading…" : "Upload"
481
+ J > 0 ? /* @__PURE__ */ r(nt, { className: "h-3 w-3 animate-spin" }) : /* @__PURE__ */ r(at, { className: "h-3 w-3" }),
482
+ J > 0 ? "Uploading…" : "Upload"
483
483
  ]
484
484
  }
485
485
  ),
486
- /* @__PURE__ */ t(
487
- it,
486
+ /* @__PURE__ */ r(
487
+ dt,
488
488
  {
489
- collection: r,
490
- layoutId: k,
489
+ collection: t,
490
+ layoutId: _,
491
491
  label: "Fill from document",
492
- onApply: W,
492
+ onApply: ae,
493
493
  className: "h-7 px-2.5 text-[11px]"
494
494
  }
495
495
  )
496
496
  ] })
497
497
  ] })
498
498
  ] }),
499
- /* @__PURE__ */ t(
500
- qt,
499
+ /* @__PURE__ */ r(
500
+ At,
501
501
  {
502
- parentData: _,
503
- configuredFields: v,
504
- fieldMap: me,
505
- formData: te,
506
- onFieldChange: X,
507
- relations: x,
508
- collection: r,
509
- prefillParentId: c
502
+ parentData: w,
503
+ configuredFields: y,
504
+ fieldMap: W,
505
+ formData: K,
506
+ onFieldChange: ne,
507
+ relations: g,
508
+ collection: t,
509
+ prefillParentId: m
510
510
  }
511
511
  )
512
512
  ] }),
513
513
  /* @__PURE__ */ i("div", { className: "shrink-0 flex items-center justify-end gap-2 border-t border-slate-200 px-5 py-3 dark:border-border", children: [
514
- /* @__PURE__ */ t(I, { variant: "outline", size: "sm", className: "h-8 text-[12px]", onClick: f, children: "Cancel" }),
515
- /* @__PURE__ */ t(
516
- I,
514
+ /* @__PURE__ */ r(Q, { variant: "outline", size: "sm", className: "h-8 text-[12px]", onClick: h, children: "Cancel" }),
515
+ /* @__PURE__ */ r(
516
+ Q,
517
517
  {
518
518
  size: "sm",
519
519
  className: "h-8 bg-nvr-cyan text-[12px] font-medium text-white hover:bg-nvr-cyan/90",
520
- disabled: !w.trim() || p.isPending,
521
- onClick: () => p.mutate(),
522
- children: p.isPending ? "Creating…" : "Create Addendum"
520
+ disabled: !S.trim() || o.isPending,
521
+ onClick: () => o.mutate(),
522
+ children: o.isPending ? "Creating…" : "Create Addendum"
523
523
  }
524
524
  )
525
525
  ] })
526
526
  ] }) }) });
527
527
  }
528
- function Mt({ addendum: r }) {
528
+ function jt({ addendum: t }) {
529
529
  var $;
530
- const c = xe(), N = [r.created_by, r.approved_by].filter(Boolean), { data: h = {} } = V({
530
+ const m = xe(), N = [t.created_by, t.approved_by].filter(Boolean), { data: b = {} } = V({
531
531
  queryKey: ["addendum-users", ...N.sort()],
532
532
  queryFn: async () => {
533
- const m = await c.request(
534
- U("/items/nivaro_users", {
533
+ const u = await m.request(
534
+ L("/items/nivaro_users", {
535
535
  filter: JSON.stringify({ id: { _in: N } }),
536
536
  fields: "id,first_name,last_name"
537
537
  })
538
- ).then((v) => v.data ?? []);
538
+ ).then((y) => y.data ?? []);
539
539
  return Object.fromEntries(
540
- m.map((v) => [
541
- String(v.id).toUpperCase(),
542
- [v.first_name, v.last_name].filter(Boolean).join(" ")
540
+ u.map((y) => [
541
+ String(y.id).toUpperCase(),
542
+ [y.first_name, y.last_name].filter(Boolean).join(" ")
543
543
  ])
544
544
  );
545
545
  },
546
546
  enabled: N.length > 0,
547
547
  staleTime: 3e5
548
- }), k = (m) => m && h[String(m).toUpperCase()] || null, u = (m) => m ? new Date(m).toLocaleDateString("en-US", { year: "numeric", month: "short", day: "numeric" }) : null, x = k(r.created_by), _ = k(r.approved_by), f = [];
549
- return r.timeline_impact_days != null && Number(r.timeline_impact_days) !== 0 && f.push({
548
+ }), _ = (u) => u && b[String(u).toUpperCase()] || null, p = (u) => u ? new Date(u).toLocaleDateString("en-US", { year: "numeric", month: "short", day: "numeric" }) : null, g = _(t.created_by), w = _(t.approved_by), h = [];
549
+ return t.timeline_impact_days != null && Number(t.timeline_impact_days) !== 0 && h.push({
550
550
  label: "Timeline impact",
551
- value: `${r.timeline_impact_days > 0 ? "+" : ""}${r.timeline_impact_days} days`
552
- }), r.created_at && f.push({
551
+ value: `${t.timeline_impact_days > 0 ? "+" : ""}${t.timeline_impact_days} days`
552
+ }), t.created_at && h.push({
553
553
  label: "Created",
554
- value: [u(r.created_at), x].filter(Boolean).join(" · ")
555
- }), r.status === "approved" && (r.approved_at || _) && f.push({
554
+ value: [p(t.created_at), g].filter(Boolean).join(" · ")
555
+ }), t.status === "approved" && (t.approved_at || w) && h.push({
556
556
  label: "Approved",
557
- value: [u(r.approved_at), _].filter(Boolean).join(" · ")
558
- }), f.length === 0 && !r.description && !(($ = r.attachments) != null && $.length) ? null : /* @__PURE__ */ i("dl", { className: T(We, "px-4 py-3.5"), children: [
559
- f.map((m) => /* @__PURE__ */ i(Ce, { children: [
560
- /* @__PURE__ */ t("dt", { className: de, children: m.label }),
561
- /* @__PURE__ */ t("dd", { className: ce, children: m.value })
562
- ] }, m.label)),
563
- r.description && /* @__PURE__ */ i(Ne, { children: [
564
- /* @__PURE__ */ t("dt", { className: de, children: "Justification" }),
565
- /* @__PURE__ */ t("dd", { className: ce, children: /^\s*</.test(r.description) ? /* @__PURE__ */ t(
557
+ value: [p(t.approved_at), w].filter(Boolean).join(" · ")
558
+ }), h.length === 0 && !t.description && !(($ = t.attachments) != null && $.length) ? null : /* @__PURE__ */ i("dl", { className: D(Ve, "px-4 py-3.5"), children: [
559
+ h.map((u) => /* @__PURE__ */ i(Se, { children: [
560
+ /* @__PURE__ */ r("dt", { className: ce, children: u.label }),
561
+ /* @__PURE__ */ r("dd", { className: me, children: u.value })
562
+ ] }, u.label)),
563
+ t.description && /* @__PURE__ */ i(Ne, { children: [
564
+ /* @__PURE__ */ r("dt", { className: ce, children: "Justification" }),
565
+ /* @__PURE__ */ r("dd", { className: me, children: /^\s*</.test(t.description) ? /* @__PURE__ */ r(
566
566
  "div",
567
567
  {
568
568
  className: "nvr-addendum-reason max-w-[75ch] leading-relaxed [&_a]:text-nvr-cyan [&_a]:underline [&_li]:ml-4 [&_ol]:list-decimal [&_p]:mb-1 [&_ul]:list-disc",
569
- dangerouslySetInnerHTML: { __html: st(r.description) }
569
+ dangerouslySetInnerHTML: { __html: ot(t.description) }
570
570
  }
571
- ) : /* @__PURE__ */ t("p", { className: "max-w-[75ch] whitespace-pre-wrap leading-relaxed", children: r.description }) })
571
+ ) : /* @__PURE__ */ r("p", { className: "max-w-[75ch] whitespace-pre-wrap leading-relaxed", children: t.description }) })
572
572
  ] }),
573
- /* @__PURE__ */ t(Pt, { ids: r.attachments })
573
+ /* @__PURE__ */ r(Rt, { ids: t.attachments })
574
574
  ] });
575
575
  }
576
- function Pt({ ids: r }) {
577
- const c = xe(), N = dt(), h = Array.isArray(r) ? r.filter(Boolean) : [], { data: k = [] } = V({
578
- queryKey: ["addendum-files", ...h],
576
+ function Rt({ ids: t }) {
577
+ const m = xe(), N = mt(), b = Array.isArray(t) ? t.filter(Boolean) : [], { data: _ = [] } = V({
578
+ queryKey: ["addendum-files", ...b],
579
579
  queryFn: () => Promise.all(
580
- h.map(
581
- (u) => c.request(U(`/files/${u}/meta`)).then((x) => {
582
- var _, f, $, m, v, w;
580
+ b.map(
581
+ (p) => m.request(L(`/files/${p}/meta`)).then((g) => {
582
+ var w, h, $, u, y, S;
583
583
  return {
584
- id: u,
585
- filename: ((_ = x.data) == null ? void 0 : _.filename_download) ?? ((f = x.data) == null ? void 0 : f.filename) ?? (($ = x.data) == null ? void 0 : $.title) ?? null,
586
- size: ((m = x.data) == null ? void 0 : m.filesize) ?? null,
587
- type: ((v = x.data) == null ? void 0 : v.type) ?? null,
588
- missing: !!((w = x.data) != null && w.missing_at)
584
+ id: p,
585
+ filename: ((w = g.data) == null ? void 0 : w.filename_download) ?? ((h = g.data) == null ? void 0 : h.filename) ?? (($ = g.data) == null ? void 0 : $.title) ?? null,
586
+ size: ((u = g.data) == null ? void 0 : u.filesize) ?? null,
587
+ type: ((y = g.data) == null ? void 0 : y.type) ?? null,
588
+ missing: !!((S = g.data) != null && S.missing_at)
589
589
  };
590
- }).catch(() => ({ id: u, filename: null, size: null, type: null, missing: !1 }))
590
+ }).catch(() => ({ id: p, filename: null, size: null, type: null, missing: !1 }))
591
591
  )
592
592
  ),
593
- enabled: h.length > 0,
593
+ enabled: b.length > 0,
594
594
  staleTime: 3e5
595
595
  });
596
- return h.length === 0 ? null : /* @__PURE__ */ i(Ne, { children: [
597
- /* @__PURE__ */ t("dt", { className: de, children: "Attachments" }),
598
- /* @__PURE__ */ i("dd", { className: T(ce, "flex flex-wrap gap-x-4 gap-y-1"), children: [
599
- k.length === 0 && /* @__PURE__ */ i("span", { className: "text-slate-400 dark:text-slate-500", children: [
600
- h.length,
596
+ return b.length === 0 ? null : /* @__PURE__ */ i(Ne, { children: [
597
+ /* @__PURE__ */ r("dt", { className: ce, children: "Attachments" }),
598
+ /* @__PURE__ */ i("dd", { className: D(me, "flex flex-wrap gap-x-4 gap-y-1"), children: [
599
+ _.length === 0 && /* @__PURE__ */ i("span", { className: "text-slate-400 dark:text-slate-500", children: [
600
+ b.length,
601
601
  " ",
602
- h.length === 1 ? "file" : "files",
602
+ b.length === 1 ? "file" : "files",
603
603
  "…"
604
604
  ] }),
605
- k.map((u) => (
605
+ _.map((p) => (
606
606
  // Every file click downloads (2026-11-08): no in-app preview.
607
607
  /* @__PURE__ */ i(
608
608
  "a",
609
609
  {
610
- href: `${c.fileUrl(u.id)}?download=1`,
611
- download: u.filename || !0,
612
- onClick: N(`${c.fileUrl(u.id)}?download=1`, u.filename),
610
+ href: `${m.fileUrl(p.id)}?download=1`,
611
+ download: p.filename || !0,
612
+ onClick: N(`${m.fileUrl(p.id)}?download=1`, p.filename),
613
613
  title: "Download",
614
614
  className: "inline-flex min-w-0 items-center gap-1.5 rounded text-slate-700 underline-offset-2 transition-colors hover:text-nvr-cyan hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/40 dark:text-slate-200",
615
615
  children: [
616
- u.missing && /* @__PURE__ */ t(
616
+ p.missing && /* @__PURE__ */ r(
617
617
  "span",
618
618
  {
619
619
  className: "rounded bg-red-500/10 px-1 py-px text-[9px] font-semibold uppercase tracking-wide text-red-600 dark:text-red-400",
@@ -621,256 +621,256 @@ function Pt({ ids: r }) {
621
621
  children: "missing"
622
622
  }
623
623
  ),
624
- /* @__PURE__ */ t(Qe, { className: "h-3 w-3 shrink-0 text-slate-400" }),
625
- /* @__PURE__ */ t("span", { className: "max-w-[320px] truncate", children: u.filename ?? `File ${u.id.slice(0, 8)}…` })
624
+ /* @__PURE__ */ r(Ie, { className: "h-3 w-3 shrink-0 text-slate-400" }),
625
+ /* @__PURE__ */ r("span", { className: "max-w-[320px] truncate", children: p.filename ?? `File ${p.id.slice(0, 8)}…` })
626
626
  ]
627
627
  },
628
- u.id
628
+ p.id
629
629
  )
630
630
  ))
631
631
  ] })
632
632
  ] });
633
633
  }
634
- function jt({
635
- addendum: r,
636
- configuredFields: c,
634
+ function Ot({
635
+ addendum: t,
636
+ configuredFields: m,
637
637
  onRefresh: N,
638
- isActive: h,
639
- relations: k = [],
640
- parentCollection: u,
641
- parentId: x,
642
- fieldMap: _ = {}
638
+ isActive: b,
639
+ relations: _ = [],
640
+ parentCollection: p,
641
+ parentId: g,
642
+ fieldMap: w = {}
643
643
  }) {
644
- var je, Re;
645
- const f = xe(), [$, m] = O(!1), v = r.workflow_template_id && ["draft", "review"].includes(r.status) ? "in approvals" : r.status, w = v === "in approvals" ? Ae.review : Ae[r.status] ?? Ae.draft, S = r.data ?? {}, j = Object.keys(S).filter((e) => Array.isArray(S[e])).map((e) => c.find((n) => n.field === e) ?? { field: e }).map((e) => {
646
- const n = k.find(
647
- (l) => l.one_collection === u && !l.junction_field && (l.one_field === e.field || l.many_collection === e.field)
644
+ var Re, Oe, De;
645
+ const h = xe(), [$, u] = R(!1), y = !!t.workflow_template_id && ["draft", "review"].includes(t.status), S = y ? ((Re = t.workflow_state) == null ? void 0 : Re.label) ?? "in approvals" : t.status, B = y ? Me.review : Me[t.status] ?? Me.draft, k = t.data ?? {}, q = Object.keys(k).filter((e) => Array.isArray(k[e])).map((e) => m.find((n) => n.field === e) ?? { field: e }).map((e) => {
646
+ const n = _.find(
647
+ (l) => l.one_collection === p && !l.junction_field && (l.one_field === e.field || l.many_collection === e.field)
648
648
  );
649
649
  return { field: e.field, rel: n };
650
650
  }).filter((e) => {
651
651
  var n, l;
652
652
  return ((n = e.rel) == null ? void 0 : n.many_collection) && ((l = e.rel) == null ? void 0 : l.many_field);
653
- }), P = Te({
654
- queries: j.map(({ rel: e }) => ({
655
- queryKey: ["o2m-rows", e.many_collection, e.many_field, x],
656
- queryFn: () => f.request(
657
- U(`/items/${e.many_collection}`, {
658
- filter: JSON.stringify({ [e.many_field]: { _eq: x } }),
653
+ }), Y = Le({
654
+ queries: q.map(({ rel: e }) => ({
655
+ queryKey: ["o2m-rows", e.many_collection, e.many_field, g],
656
+ queryFn: () => h.request(
657
+ L(`/items/${e.many_collection}`, {
658
+ filter: JSON.stringify({ [e.many_field]: { _eq: g } }),
659
659
  limit: 200
660
660
  })
661
661
  ).then((n) => n.data ?? []),
662
662
  staleTime: 3e4,
663
- enabled: !!x
663
+ enabled: !!g
664
664
  }))
665
- }), J = ["approved", "reverted"].includes(r.status), { data: ee } = V({
666
- queryKey: ["addendum-lines", r.id],
667
- queryFn: () => f.request(U(`/addendums/${r.id}/lines`)).then((e) => e.data ?? {}),
665
+ }), J = ["approved", "reverted"].includes(t.status), { data: A } = V({
666
+ queryKey: ["addendum-lines", t.id],
667
+ queryFn: () => h.request(L(`/addendums/${t.id}/lines`)).then((e) => e.data ?? {}),
668
668
  enabled: $ && J,
669
669
  staleTime: 6e4
670
- }), A = Object.fromEntries(
671
- P.map((e, n) => [
672
- j[n].field,
670
+ }), G = Object.fromEntries(
671
+ Y.map((e, n) => [
672
+ q[n].field,
673
673
  e.data ?? null
674
674
  ])
675
- ), G = pe({
676
- mutationFn: () => f.request(ve(`/addendums/${r.id}/approve`)),
675
+ ), P = pe({
676
+ mutationFn: () => h.request(ve(`/addendums/${t.id}/approve`)),
677
677
  onSuccess: () => {
678
- N(), z.success("Addendum approved — changes applied to record");
678
+ N(), E.success("Addendum approved — changes applied to record");
679
679
  },
680
680
  onError: (e) => {
681
- var l, g;
682
- const n = (g = (l = e == null ? void 0 : e.response) == null ? void 0 : l.data) == null ? void 0 : g.error;
683
- z.error(n ?? "Failed to approve");
681
+ var l, v;
682
+ const n = (v = (l = e == null ? void 0 : e.response) == null ? void 0 : l.data) == null ? void 0 : v.error;
683
+ E.error(n ?? "Failed to approve");
684
684
  }
685
- }), M = pe({
686
- mutationFn: () => f.request(ve(`/addendums/${r.id}/revert`)),
685
+ }), K = pe({
686
+ mutationFn: () => h.request(ve(`/addendums/${t.id}/revert`)),
687
687
  onSuccess: () => {
688
- Y(), z.success("Addendum reverted — the record is back to its pre-approval values");
688
+ z(), E.success("Addendum reverted — the record is back to its pre-approval values");
689
689
  },
690
690
  onError: (e) => {
691
- var l, g;
692
- const n = (g = (l = e == null ? void 0 : e.response) == null ? void 0 : l.data) == null ? void 0 : g.error;
693
- z.error(n ?? "Failed to revert", { duration: 1e4 });
691
+ var l, v;
692
+ const n = (v = (l = e == null ? void 0 : e.response) == null ? void 0 : l.data) == null ? void 0 : v.error;
693
+ E.error(n ?? "Failed to revert", { duration: 1e4 });
694
694
  }
695
- }), [te, E] = O(!1), [me, X] = O(!1), W = Ue(), Y = () => {
696
- N(), W.invalidateQueries({ queryKey: ["addendums"] }), W.invalidateQueries({ queryKey: ["item-actions"] }), W.invalidateQueries({ queryKey: ["ext-item-actions"] }), W.invalidateQueries({ queryKey: ["pipeline-all-owners"] }), W.invalidateQueries({ queryKey: ["item"] }), W.invalidateQueries({ queryKey: ["o2m-rows"] }), W.invalidateQueries({ queryKey: ["pipeline-instance"] });
697
- }, L = pe({
698
- mutationFn: () => f.request(lt(`/addendums/${r.id}`)),
695
+ }), [X, W] = R(!1), [ne, ae] = R(!1), j = Be(), z = () => {
696
+ N(), j.invalidateQueries({ queryKey: ["addendums"] }), j.invalidateQueries({ queryKey: ["item-actions"] }), j.invalidateQueries({ queryKey: ["ext-item-actions"] }), j.invalidateQueries({ queryKey: ["pipeline-all-owners"] }), j.invalidateQueries({ queryKey: ["item"] }), j.invalidateQueries({ queryKey: ["o2m-rows"] }), j.invalidateQueries({ queryKey: ["pipeline-instance"] });
697
+ }, Z = pe({
698
+ mutationFn: () => h.request(it(`/addendums/${t.id}`)),
699
699
  onSuccess: () => {
700
- Y(), z.success("Addendum deleted");
700
+ z(), E.success("Addendum deleted");
701
701
  },
702
702
  onError: (e) => {
703
- var l, g;
704
- const n = (g = (l = e == null ? void 0 : e.response) == null ? void 0 : l.data) == null ? void 0 : g.error;
705
- z.error(n ?? "Failed to delete", { duration: 1e4 });
703
+ var l, v;
704
+ const n = (v = (l = e == null ? void 0 : e.response) == null ? void 0 : l.data) == null ? void 0 : v.error;
705
+ E.error(n ?? "Failed to delete", { duration: 1e4 });
706
706
  }
707
- }), { isAdmin: re } = at(), se = pe({
708
- mutationFn: () => f.request(ve(`/addendums/${r.id}/reject`)),
707
+ }), { isAdmin: le } = st(), se = pe({
708
+ mutationFn: () => h.request(ve(`/addendums/${t.id}/reject`)),
709
709
  onSuccess: () => {
710
- N(), z.success("Addendum rejected");
710
+ N(), E.success("Addendum rejected");
711
711
  },
712
- onError: () => z.error("Failed to reject")
713
- }), ne = pe({
714
- mutationFn: () => f.request(ve(`/addendums/${r.id}/submit`)),
712
+ onError: () => E.error("Failed to reject")
713
+ }), te = pe({
714
+ mutationFn: () => h.request(ve(`/addendums/${t.id}/submit`)),
715
715
  onSuccess: () => {
716
- N(), z.success("Submitted for review");
716
+ N(), E.success("Submitted for review");
717
717
  },
718
- onError: () => z.error("Failed to submit")
719
- }), ie = c.filter((e) => S[e.field] !== void 0), Z = (e) => e.computed_type === "rollup" ? Je(e.computed_formula) : [], Q = (e) => {
720
- const n = k.find(
721
- (l) => l.one_collection === u && l.many_collection === e.related_collection && l.many_field === e.fk_field && !l.junction_field
718
+ onError: () => E.error("Failed to submit")
719
+ }), ie = m.filter((e) => k[e.field] !== void 0), O = (e) => e.computed_type === "rollup" ? He(e.computed_formula) : [], ee = (e) => {
720
+ const n = _.find(
721
+ (l) => l.one_collection === p && l.many_collection === e.related_collection && l.many_field === e.fk_field && !l.junction_field
722
722
  );
723
723
  return n ? n.one_field ?? n.many_collection : null;
724
- }, R = oe(
725
- () => Object.values(_).filter((e) => {
726
- const n = Z(e);
724
+ }, o = de(
725
+ () => Object.values(w).filter((e) => {
726
+ const n = O(e);
727
727
  return n.length > 0 && !n.some((l) => l.recursive) && n.every((l) => {
728
- const g = Q(l);
729
- return !!g && Array.isArray(S[g]);
728
+ const v = ee(l);
729
+ return !!v && Array.isArray(k[v]);
730
730
  });
731
731
  }),
732
732
  // biome-ignore lint/correctness/useExhaustiveDependencies: helpers close over relations/parentCollection
733
- [_, S, k, u]
734
- ), p = oe(
733
+ [w, k, _, p]
734
+ ), a = de(
735
735
  () => [
736
736
  ...new Set(
737
- R.flatMap((e) => Z(e).map((n) => n.related_collection))
737
+ o.flatMap((e) => O(e).map((n) => n.related_collection))
738
738
  )
739
739
  ],
740
- [R]
741
- ), a = Te({
742
- queries: p.map((e) => ({
740
+ [o]
741
+ ), s = Le({
742
+ queries: a.map((e) => ({
743
743
  queryKey: ["field-config", e, null],
744
- queryFn: () => f.request(U(`/field-config/${e}`)).then((n) => n.data ?? []),
744
+ queryFn: () => h.request(L(`/field-config/${e}`)).then((n) => n.data ?? []),
745
745
  staleTime: 6e4
746
746
  }))
747
- }), s = a.map((e) => e.dataUpdatedAt).join(","), d = ie.filter((e) => {
748
- const n = S[e.field];
749
- return n != null && typeof n == "object" || n == null ? !1 : !k.some(
750
- (l) => l.one_collection === u && (l.one_field === e.field || l.many_collection === e.field)
747
+ }), f = s.map((e) => e.dataUpdatedAt).join(","), d = ie.filter((e) => {
748
+ const n = k[e.field];
749
+ return n != null && typeof n == "object" || n == null ? !1 : !_.some(
750
+ (l) => l.one_collection === p && (l.one_field === e.field || l.many_collection === e.field)
751
751
  );
752
- }), { data: o } = V({
752
+ }), { data: c } = V({
753
753
  queryKey: [
754
754
  "addendum-current",
755
- u,
756
- x,
755
+ p,
756
+ g,
757
757
  d.map((e) => e.field).join(","),
758
- R.map((e) => e.field).join(",")
758
+ o.map((e) => e.field).join(",")
759
759
  ],
760
- queryFn: () => f.request(
761
- U(`/items/${u}/${x}`, {
760
+ queryFn: () => h.request(
761
+ L(`/items/${p}/${g}`, {
762
762
  fields: [
763
763
  .../* @__PURE__ */ new Set([
764
764
  "id",
765
765
  ...d.map((e) => e.field),
766
766
  // The rollups themselves (current figure) plus any parent_filter
767
767
  // columns that decide whether the rollup applies to this record.
768
- ...R.flatMap((e) => [
768
+ ...o.flatMap((e) => [
769
769
  e.field,
770
- ...Object.keys(Le(e.computed_formula) ?? {})
770
+ ...Object.keys(ze(e.computed_formula) ?? {})
771
771
  ])
772
772
  ])
773
773
  ].join(",")
774
774
  })
775
775
  ).then((e) => e.data ?? null).catch(() => null),
776
- enabled: !!u && !!x && (d.length > 0 || R.length > 0),
776
+ enabled: !!p && !!g && (d.length > 0 || o.length > 0),
777
777
  staleTime: 15e3
778
- }), b = oe(() => {
778
+ }), x = de(() => {
779
779
  const e = /* @__PURE__ */ new Map(), n = new Map(
780
- p.map((l, g) => {
780
+ a.map((l, v) => {
781
781
  var F;
782
782
  return [
783
783
  l,
784
- (F = a[g]) == null ? void 0 : F.data
784
+ (F = s[v]) == null ? void 0 : F.data
785
785
  ];
786
786
  })
787
787
  );
788
- for (const l of R) {
789
- const g = Le(l.computed_formula);
790
- if (g && o && !mt(o, g)) continue;
788
+ for (const l of o) {
789
+ const v = ze(l.computed_formula);
790
+ if (v && c && !pt(c, v)) continue;
791
791
  const F = /* @__PURE__ */ new Map();
792
792
  let H = !0;
793
- for (const B of Z(l)) {
794
- const ge = Q(B), ue = n.get(B.related_collection);
793
+ for (const U of O(l)) {
794
+ const ge = ee(U), ue = n.get(U.related_collection);
795
795
  if (!ge || !ue) {
796
796
  H = !1;
797
797
  break;
798
798
  }
799
- const Ge = ue.filter((we) => we.computed_type === "write" && !!we.computed_formula), Xe = S[ge].map((we) => {
800
- const Fe = { ...we };
801
- for (const Oe of Ge) {
802
- const De = ct(String(Oe.computed_formula), Fe);
803
- De !== null && (Fe[Oe.field] = De);
799
+ const Ze = ue.filter((Ce) => Ce.computed_type === "write" && !!Ce.computed_formula), et = k[ge].map((Ce) => {
800
+ const Ae = { ...Ce };
801
+ for (const Te of Ze) {
802
+ const Ee = ut(String(Te.computed_formula), Ae);
803
+ Ee !== null && (Ae[Te.field] = Ee);
804
804
  }
805
- return Fe;
805
+ return Ae;
806
806
  });
807
- F.set(`${B.related_collection}.${B.fk_field}`, Xe);
807
+ F.set(`${U.related_collection}.${U.fk_field}`, et);
808
808
  }
809
809
  if (!H) continue;
810
- const K = Ie(Z(l), F);
811
- K !== null && e.set(l.field, Math.round(K * 100) / 100);
810
+ const T = We(O(l), F);
811
+ T !== null && e.set(l.field, Math.round(T * 100) / 100);
812
812
  }
813
813
  return e;
814
- }, [R, p, s, S, o]), y = (e, n) => n ? e.filter((l) => {
815
- const g = n.find((F) => String(F.id) === String(l.id));
816
- return g ? Object.keys(l).some(
817
- (F) => F !== "id" && String(l[F] ?? "") !== String(g[F] ?? "")
814
+ }, [o, a, f, k, c]), C = (e, n) => n ? e.filter((l) => {
815
+ const v = n.find((F) => String(F.id) === String(l.id));
816
+ return v ? Object.keys(l).some(
817
+ (F) => F !== "id" && String(l[F] ?? "") !== String(v[F] ?? "")
818
818
  ) : !0;
819
- }).length : e.length, q = [
819
+ }).length : e.length, oe = [
820
820
  ...ie.filter((e) => {
821
- const n = S[e.field];
821
+ const n = k[e.field];
822
822
  if (n == null || n === "") return !1;
823
823
  if (Array.isArray(n))
824
- return y(n, A[e.field]) > 0;
825
- const l = _[e.field];
826
- return !((l == null ? void 0 : l.computed_type) === "rollup" || (l == null ? void 0 : l.computed_type) === "write" || o && e.field in o && String(o[e.field] ?? "") === String(n));
824
+ return C(n, G[e.field]) > 0;
825
+ const l = w[e.field];
826
+ return !((l == null ? void 0 : l.computed_type) === "rollup" || (l == null ? void 0 : l.computed_type) === "write" || c && e.field in c && String(c[e.field] ?? "") === String(n));
827
827
  }).map((e) => ({
828
828
  field: e.field,
829
829
  label_override: e.label_override ?? null,
830
- value: S[e.field]
830
+ value: k[e.field]
831
831
  })),
832
- ...R.flatMap(
833
- (e) => b.has(e.field) && !(o && o[e.field] != null && Number(o[e.field]) === b.get(e.field)) ? [
832
+ ...o.flatMap(
833
+ (e) => x.has(e.field) && !(c && c[e.field] != null && Number(c[e.field]) === x.get(e.field)) ? [
834
834
  {
835
835
  field: e.field,
836
836
  label_override: e.label ?? null,
837
- value: b.get(e.field)
837
+ value: x.get(e.field)
838
838
  }
839
839
  ] : []
840
840
  )
841
- ], ae = q.length, He = (e, n) => {
842
- var g;
843
- const l = (g = _[e]) == null ? void 0 : g.type;
841
+ ], ke = oe.length, Ye = (e, n) => {
842
+ var v;
843
+ const l = (v = w[e]) == null ? void 0 : v.type;
844
844
  return l && ["integer", "bigInteger", "decimal", "float", "number"].includes(l) ? !0 : n != null && n !== "" && !Array.isArray(n) && !Number.isNaN(Number(n));
845
- }, Se = (e) => {
845
+ }, $e = (e) => {
846
846
  var l;
847
- const n = (l = _[e]) == null ? void 0 : l.options;
847
+ const n = (l = w[e]) == null ? void 0 : l.options;
848
848
  return n && typeof n == "object" && n.format === "currency" ? !0 : /amount|cost|price|total|budget|spend/i.test(e);
849
- }, $e = (e, n) => Se(e) ? ye.format(Number(n)) : new Intl.NumberFormat("en-US").format(Number(n)), Ve = oe(() => {
850
- if (r.cost_impact != null && Number(r.cost_impact) !== 0 || !o) return null;
849
+ }, qe = (e, n) => $e(e) ? ye.format(Number(n)) : new Intl.NumberFormat("en-US").format(Number(n)), Ge = de(() => {
850
+ if (t.cost_impact != null && Number(t.cost_impact) !== 0 || !c) return null;
851
851
  for (const e of d) {
852
- if (!Se(e.field)) continue;
853
- const n = Number(S[e.field]), l = Number(o[e.field]);
852
+ if (!$e(e.field)) continue;
853
+ const n = Number(k[e.field]), l = Number(c[e.field]);
854
854
  if (!Number.isNaN(n) && !Number.isNaN(l) && n !== l) return n - l;
855
855
  }
856
856
  return null;
857
- }, [r.cost_impact, o, d, S]), ke = oe(() => {
858
- if (!o) return null;
857
+ }, [t.cost_impact, c, d, k]), _e = de(() => {
858
+ if (!c) return null;
859
859
  const e = [
860
- ...d.map((n) => [n.field, Number(S[n.field])]),
861
- ...b.entries()
860
+ ...d.map((n) => [n.field, Number(k[n.field])]),
861
+ ...x.entries()
862
862
  ].flatMap(([n, l]) => {
863
- const g = o[n];
864
- return !Se(n) || g == null || g === "" ? [] : Number.isNaN(Number(g)) || Number.isNaN(l) ? [] : [{ field: n, previous: Number(g), next: l }];
863
+ const v = c[n];
864
+ return !$e(n) || v == null || v === "" ? [] : Number.isNaN(Number(v)) || Number.isNaN(l) ? [] : [{ field: n, previous: Number(v), next: l }];
865
865
  });
866
866
  return e.find((n) => n.previous !== n.next) ?? e[0] ?? null;
867
- }, [o, d, S, b]), _e = kt(r, ke), qe = _e.previous != null || _e.next != null || _e.change != null, be = qe ? (ke == null ? void 0 : ke.field) ?? null : null, Ye = be ? ((je = q.find((e) => e.field === be)) == null ? void 0 : je.label_override) ?? ((Re = _[be]) == null ? void 0 : Re.label) ?? fe(be) : "Amount";
867
+ }, [c, d, k, x]), we = wt(t, _e), Fe = we.previous != null || we.next != null || we.change != null, be = Fe ? (_e == null ? void 0 : _e.field) ?? null : null, Xe = be ? ((Oe = oe.find((e) => e.field === be)) == null ? void 0 : Oe.label_override) ?? ((De = w[be]) == null ? void 0 : De.label) ?? fe(be) : "Amount";
868
868
  return /* @__PURE__ */ i(
869
869
  "div",
870
870
  {
871
- className: T(
871
+ className: D(
872
872
  "overflow-hidden rounded-lg border bg-white transition-shadow hover:shadow-sm dark:bg-card",
873
- h ? "border-amber-300 dark:border-amber-500/40" : "border-slate-200 dark:border-border"
873
+ b ? "border-amber-300 dark:border-amber-500/40" : "border-slate-200 dark:border-border"
874
874
  ),
875
875
  children: [
876
876
  /* @__PURE__ */ i(
@@ -878,36 +878,36 @@ function jt({
878
878
  {
879
879
  type: "button",
880
880
  className: "flex w-full items-start gap-3 px-4 py-3 text-left",
881
- onClick: () => m((e) => !e),
881
+ onClick: () => u((e) => !e),
882
882
  children: [
883
- /* @__PURE__ */ t("span", { className: T("mt-0.5 h-2 w-2 shrink-0 rounded-full", w.dot) }),
883
+ /* @__PURE__ */ r("span", { className: D("mt-0.5 h-2 w-2 shrink-0 rounded-full", B.dot) }),
884
884
  /* @__PURE__ */ i("div", { className: "flex-1 min-w-0", children: [
885
885
  /* @__PURE__ */ i("div", { className: "flex items-center gap-2 flex-wrap", children: [
886
- /* @__PURE__ */ t("span", { className: "text-[13px] font-semibold text-slate-800 dark:text-slate-100 truncate", children: r.title }),
887
- /* @__PURE__ */ t(
886
+ /* @__PURE__ */ r("span", { className: "text-[13px] font-semibold text-slate-800 dark:text-slate-100 truncate", children: t.title }),
887
+ /* @__PURE__ */ r(
888
888
  "span",
889
889
  {
890
- className: T(
890
+ className: D(
891
891
  "inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium",
892
- w.badge
892
+ B.badge
893
893
  ),
894
- children: v
894
+ children: S
895
895
  }
896
896
  ),
897
- ae > 0 && /* @__PURE__ */ i("span", { className: "text-[11px] text-slate-400 dark:text-slate-500", children: [
898
- ae,
897
+ ke > 0 && /* @__PURE__ */ i("span", { className: "text-[11px] text-slate-400 dark:text-slate-500", children: [
898
+ ke,
899
899
  " field",
900
- ae !== 1 ? "s" : "",
900
+ ke !== 1 ? "s" : "",
901
901
  " changed"
902
902
  ] }),
903
- ze(r.cost_impact) ?? ze(Ve)
903
+ Qe(t.cost_impact) ?? Qe(Ge)
904
904
  ] }),
905
- r.description && !$ && /* @__PURE__ */ t("p", { className: "mt-0.5 text-[12px] text-slate-500 dark:text-slate-400 line-clamp-1", children: _t(r.description) })
905
+ t.description && !$ && /* @__PURE__ */ r("p", { className: "mt-0.5 text-[12px] text-slate-500 dark:text-slate-400 line-clamp-1", children: Ct(t.description) })
906
906
  ] }),
907
- /* @__PURE__ */ t(
907
+ /* @__PURE__ */ r(
908
908
  "span",
909
909
  {
910
- className: T(
910
+ className: D(
911
911
  "shrink-0 text-[10px] text-slate-400 transition-transform",
912
912
  $ && "rotate-180"
913
913
  ),
@@ -918,18 +918,18 @@ function jt({
918
918
  }
919
919
  ),
920
920
  $ && /* @__PURE__ */ i("div", { className: "border-t border-slate-100 dark:border-border", children: [
921
- /* @__PURE__ */ t(Mt, { addendum: r }),
922
- (ae > 0 || qe) && /* @__PURE__ */ i("section", { className: "border-t border-slate-100 px-4 py-3.5 dark:border-border", children: [
923
- /* @__PURE__ */ t("h4", { className: "mb-3 text-[12.5px] font-semibold text-slate-800 dark:text-slate-100", children: J ? "Changes" : "Proposed changes" }),
924
- /* @__PURE__ */ i("dl", { className: We, children: [
925
- qe && /* @__PURE__ */ i(Ne, { children: [
926
- /* @__PURE__ */ t("dt", { className: de, children: Ye }),
927
- /* @__PURE__ */ t("dd", { className: ce, children: /* @__PURE__ */ t(wt, { amounts: _e }) })
921
+ /* @__PURE__ */ r(jt, { addendum: t }),
922
+ (ke > 0 || Fe) && /* @__PURE__ */ i("section", { className: "border-t border-slate-100 px-4 py-3.5 dark:border-border", children: [
923
+ /* @__PURE__ */ r("h4", { className: "mb-3 text-[12.5px] font-semibold text-slate-800 dark:text-slate-100", children: J ? "Changes" : "Proposed changes" }),
924
+ /* @__PURE__ */ i("dl", { className: Ve, children: [
925
+ Fe && /* @__PURE__ */ i(Ne, { children: [
926
+ /* @__PURE__ */ r("dt", { className: ce, children: Xe }),
927
+ /* @__PURE__ */ r("dd", { className: me, children: /* @__PURE__ */ r(St, { amounts: we }) })
928
928
  ] }),
929
- q.map((e) => {
930
- var g;
929
+ oe.map((e) => {
930
+ var v;
931
931
  const n = e.value;
932
- if (e.field === be || Array.isArray(n) && A[e.field]) return null;
932
+ if (e.field === be || Array.isArray(n) && G[e.field]) return null;
933
933
  let l;
934
934
  if (n == null)
935
935
  l = "—";
@@ -937,162 +937,162 @@ function jt({
937
937
  l = `${n.length} row${n.length === 1 ? "" : "s"}`;
938
938
  else if (typeof n == "object")
939
939
  l = JSON.stringify(n).slice(0, 60);
940
- else if (He(e.field, n)) {
941
- const F = Number(n), H = o == null ? void 0 : o[e.field], K = H != null && H !== "" && !Number.isNaN(Number(H)) ? Number(H) : null, B = K != null ? F - K : 0;
940
+ else if (Ye(e.field, n)) {
941
+ const F = Number(n), H = c == null ? void 0 : c[e.field], T = H != null && H !== "" && !Number.isNaN(Number(H)) ? Number(H) : null, U = T != null ? F - T : 0;
942
942
  l = /* @__PURE__ */ i("span", { className: "inline-flex flex-wrap items-baseline gap-x-1.5 tabular-nums", children: [
943
- K != null && K !== F && /* @__PURE__ */ t("span", { className: "text-slate-400 line-through decoration-slate-300 dark:text-slate-500 dark:decoration-slate-600", children: $e(e.field, K) }),
943
+ T != null && T !== F && /* @__PURE__ */ r("span", { className: "text-slate-400 line-through decoration-slate-300 dark:text-slate-500 dark:decoration-slate-600", children: qe(e.field, T) }),
944
944
  /* @__PURE__ */ i("span", { className: "font-medium text-foreground", children: [
945
- K != null && K !== F && /* @__PURE__ */ t("span", { className: "mr-1 font-normal text-slate-400", "aria-hidden": "true", children: "→" }),
946
- $e(e.field, F)
945
+ T != null && T !== F && /* @__PURE__ */ r("span", { className: "mr-1 font-normal text-slate-400", "aria-hidden": "true", children: "→" }),
946
+ qe(e.field, F)
947
947
  ] }),
948
- B !== 0 && /* @__PURE__ */ i(
948
+ U !== 0 && /* @__PURE__ */ i(
949
949
  "span",
950
950
  {
951
- className: T(
951
+ className: D(
952
952
  "rounded-full px-1.5 py-px text-[10px] font-medium",
953
- B > 0 ? "bg-emerald-50 text-emerald-700 dark:bg-emerald-500/10 dark:text-emerald-400" : "bg-red-50 text-red-600 dark:bg-red-500/10 dark:text-red-400"
953
+ U > 0 ? "bg-emerald-50 text-emerald-700 dark:bg-emerald-500/10 dark:text-emerald-400" : "bg-red-50 text-red-600 dark:bg-red-500/10 dark:text-red-400"
954
954
  ),
955
955
  children: [
956
- B > 0 ? "+" : "−",
957
- $e(e.field, Math.abs(B))
956
+ U > 0 ? "+" : "−",
957
+ qe(e.field, Math.abs(U))
958
958
  ]
959
959
  }
960
960
  )
961
961
  ] });
962
962
  } else
963
963
  l = String(n);
964
- return /* @__PURE__ */ i(Ce, { children: [
965
- /* @__PURE__ */ t("dt", { className: de, children: e.label_override ?? ((g = _[e.field]) == null ? void 0 : g.label) ?? fe(e.field) }),
966
- /* @__PURE__ */ t("dd", { className: T(ce, "break-words"), children: l })
964
+ return /* @__PURE__ */ i(Se, { children: [
965
+ /* @__PURE__ */ r("dt", { className: ce, children: e.label_override ?? ((v = w[e.field]) == null ? void 0 : v.label) ?? fe(e.field) }),
966
+ /* @__PURE__ */ r("dd", { className: D(me, "break-words"), children: l })
967
967
  ] }, e.field);
968
968
  }),
969
- J && Object.entries(ee ?? {}).map(([e, n]) => {
970
- var l, g;
971
- return /* @__PURE__ */ i(Ce, { children: [
972
- /* @__PURE__ */ t("dt", { className: de, children: ((l = _[e]) == null ? void 0 : l.label) ?? fe(e) }),
973
- /* @__PURE__ */ t("dd", { className: ce, children: /* @__PURE__ */ t(
974
- Ke,
969
+ J && Object.entries(A ?? {}).map(([e, n]) => {
970
+ var l, v;
971
+ return /* @__PURE__ */ i(Se, { children: [
972
+ /* @__PURE__ */ r("dt", { className: ce, children: ((l = w[e]) == null ? void 0 : l.label) ?? fe(e) }),
973
+ /* @__PURE__ */ r("dd", { className: me, children: /* @__PURE__ */ r(
974
+ Ue,
975
975
  {
976
- client: f,
976
+ client: h,
977
977
  childCollection: n.collection,
978
978
  fkField: n.fk,
979
979
  proposed: n.after,
980
980
  original: n.before,
981
981
  ignoreMissing: !0,
982
- label: ((g = _[e]) == null ? void 0 : g.label) ?? fe(e)
982
+ label: ((v = w[e]) == null ? void 0 : v.label) ?? fe(e)
983
983
  }
984
984
  ) })
985
985
  ] }, `applied-${e}`);
986
986
  }),
987
- j.map(({ field: e, rel: n }) => {
988
- var B, ge;
989
- const l = S[e], g = j.findIndex((ue) => ue.field === e), F = A[e] ?? ((B = P[g]) != null && B.isLoading ? null : []);
987
+ q.map(({ field: e, rel: n }) => {
988
+ var U, ge;
989
+ const l = k[e], v = q.findIndex((ue) => ue.field === e), F = G[e] ?? ((U = Y[v]) != null && U.isLoading ? null : []);
990
990
  if (J || !Array.isArray(l) || !F || !(n != null && n.many_collection) || !n.many_field)
991
991
  return null;
992
- const H = c.find((ue) => ue.field === e), K = (H == null ? void 0 : H.label_override) ?? ((ge = _[e]) == null ? void 0 : ge.label) ?? fe(e);
993
- return /* @__PURE__ */ i(Ce, { children: [
994
- /* @__PURE__ */ t("dt", { className: de, children: K }),
995
- /* @__PURE__ */ t("dd", { className: ce, children: /* @__PURE__ */ t(
996
- Ke,
992
+ const H = m.find((ue) => ue.field === e), T = (H == null ? void 0 : H.label_override) ?? ((ge = w[e]) == null ? void 0 : ge.label) ?? fe(e);
993
+ return /* @__PURE__ */ i(Se, { children: [
994
+ /* @__PURE__ */ r("dt", { className: ce, children: T }),
995
+ /* @__PURE__ */ r("dd", { className: me, children: /* @__PURE__ */ r(
996
+ Ue,
997
997
  {
998
- client: f,
998
+ client: h,
999
999
  childCollection: n.many_collection,
1000
1000
  fkField: n.many_field,
1001
1001
  proposed: l,
1002
1002
  original: F,
1003
- label: K
1003
+ label: T
1004
1004
  }
1005
1005
  ) })
1006
1006
  ] }, `lines-${e}`);
1007
1007
  })
1008
1008
  ] })
1009
1009
  ] }),
1010
- r.workflow_template_id && /* @__PURE__ */ i("div", { className: "border-t border-slate-100 dark:border-border px-4 py-3.5", children: [
1011
- /* @__PURE__ */ t("h4", { className: "mb-3 text-[12.5px] font-semibold text-slate-800 dark:text-slate-100", children: "Workflow" }),
1012
- /* @__PURE__ */ t(Ft, { addendumId: r.id }),
1013
- re && /* @__PURE__ */ t("div", { className: "mt-2 flex items-center justify-end gap-2", children: r.status === "approved" ? r.legacy_id != null ? null : te ? /* @__PURE__ */ i("span", { className: "flex items-center gap-1.5", children: [
1014
- /* @__PURE__ */ t("span", { className: "text-[11px] text-amber-600 dark:text-amber-400", children: "Roll every applied change back?" }),
1015
- /* @__PURE__ */ t(
1016
- I,
1010
+ t.workflow_template_id && /* @__PURE__ */ i("div", { className: "border-t border-slate-100 dark:border-border px-4 py-3.5", children: [
1011
+ /* @__PURE__ */ r("h4", { className: "mb-3 text-[12.5px] font-semibold text-slate-800 dark:text-slate-100", children: "Workflow" }),
1012
+ /* @__PURE__ */ r(Mt, { addendumId: t.id }),
1013
+ le && /* @__PURE__ */ r("div", { className: "mt-2 flex items-center justify-end gap-2", children: t.status === "approved" ? t.legacy_id != null ? null : X ? /* @__PURE__ */ i("span", { className: "flex items-center gap-1.5", children: [
1014
+ /* @__PURE__ */ r("span", { className: "text-[11px] text-amber-600 dark:text-amber-400", children: "Roll every applied change back?" }),
1015
+ /* @__PURE__ */ r(
1016
+ Q,
1017
1017
  {
1018
1018
  size: "sm",
1019
1019
  className: "h-6 bg-amber-600 px-2 text-[11px] text-white hover:bg-amber-700",
1020
- disabled: M.isPending,
1020
+ disabled: K.isPending,
1021
1021
  onClick: () => {
1022
- M.mutate(), E(!1);
1022
+ K.mutate(), W(!1);
1023
1023
  },
1024
- children: M.isPending ? "Reverting…" : "Revert"
1024
+ children: K.isPending ? "Reverting…" : "Revert"
1025
1025
  }
1026
1026
  ),
1027
- /* @__PURE__ */ t(
1028
- I,
1027
+ /* @__PURE__ */ r(
1028
+ Q,
1029
1029
  {
1030
1030
  size: "sm",
1031
1031
  variant: "ghost",
1032
1032
  className: "h-6 px-2 text-[11px]",
1033
- onClick: () => E(!1),
1033
+ onClick: () => W(!1),
1034
1034
  children: "Cancel"
1035
1035
  }
1036
1036
  )
1037
- ] }) : /* @__PURE__ */ t(
1037
+ ] }) : /* @__PURE__ */ r(
1038
1038
  "button",
1039
1039
  {
1040
1040
  type: "button",
1041
1041
  "data-tip": "Admin only — restores the record to its pre-approval values through the normal revision trail; the addendum stays as a reverted record of what happened",
1042
- onClick: () => E(!0),
1042
+ onClick: () => W(!0),
1043
1043
  className: "text-[11px] text-slate-400 underline decoration-dotted underline-offset-2 hover:text-amber-600",
1044
1044
  children: "Revert…"
1045
1045
  }
1046
- ) : me ? /* @__PURE__ */ i("span", { className: "flex items-center gap-1.5", children: [
1047
- /* @__PURE__ */ t("span", { className: "text-[11px] text-red-600 dark:text-red-400", children: "Delete this addendum and its approval workflow?" }),
1048
- /* @__PURE__ */ t(
1049
- I,
1046
+ ) : ne ? /* @__PURE__ */ i("span", { className: "flex items-center gap-1.5", children: [
1047
+ /* @__PURE__ */ r("span", { className: "text-[11px] text-red-600 dark:text-red-400", children: "Delete this addendum and its approval workflow?" }),
1048
+ /* @__PURE__ */ r(
1049
+ Q,
1050
1050
  {
1051
1051
  size: "sm",
1052
1052
  className: "h-6 bg-red-600 px-2 text-[11px] text-white hover:bg-red-700",
1053
- disabled: L.isPending,
1053
+ disabled: Z.isPending,
1054
1054
  onClick: () => {
1055
- L.mutate(), X(!1);
1055
+ Z.mutate(), ae(!1);
1056
1056
  },
1057
- children: L.isPending ? "Deleting…" : "Delete"
1057
+ children: Z.isPending ? "Deleting…" : "Delete"
1058
1058
  }
1059
1059
  ),
1060
- /* @__PURE__ */ t(
1061
- I,
1060
+ /* @__PURE__ */ r(
1061
+ Q,
1062
1062
  {
1063
1063
  size: "sm",
1064
1064
  variant: "ghost",
1065
1065
  className: "h-6 px-2 text-[11px]",
1066
- onClick: () => X(!1),
1066
+ onClick: () => ae(!1),
1067
1067
  children: "Cancel"
1068
1068
  }
1069
1069
  )
1070
- ] }) : /* @__PURE__ */ t(
1070
+ ] }) : /* @__PURE__ */ r(
1071
1071
  "button",
1072
1072
  {
1073
1073
  type: "button",
1074
1074
  "data-tip": "Admin only — removes the addendum and its approval workflow; nothing has applied to the record yet",
1075
- onClick: () => X(!0),
1075
+ onClick: () => ae(!0),
1076
1076
  className: "text-[11px] text-slate-400 underline decoration-dotted underline-offset-2 hover:text-red-600",
1077
1077
  children: "Delete addendum…"
1078
1078
  }
1079
1079
  ) })
1080
1080
  ] }),
1081
1081
  /* @__PURE__ */ i("div", { className: "flex items-center justify-end gap-2 border-t border-slate-100 dark:border-border px-4 py-2.5", children: [
1082
- r.status === "draft" && !r.workflow_template_id && /* @__PURE__ */ t(
1083
- I,
1082
+ t.status === "draft" && !t.workflow_template_id && /* @__PURE__ */ r(
1083
+ Q,
1084
1084
  {
1085
1085
  size: "sm",
1086
1086
  variant: "outline",
1087
1087
  className: "h-7 text-[11px]",
1088
- onClick: () => ne.mutate(),
1089
- disabled: ne.isPending,
1090
- children: ne.isPending ? "Submitting…" : "Submit for Review"
1088
+ onClick: () => te.mutate(),
1089
+ disabled: te.isPending,
1090
+ children: te.isPending ? "Submitting…" : "Submit for Review"
1091
1091
  }
1092
1092
  ),
1093
- r.status === "review" && !r.workflow_template_id && /* @__PURE__ */ i(Ne, { children: [
1094
- /* @__PURE__ */ t(
1095
- I,
1093
+ t.status === "review" && !t.workflow_template_id && /* @__PURE__ */ i(Ne, { children: [
1094
+ /* @__PURE__ */ r(
1095
+ Q,
1096
1096
  {
1097
1097
  size: "sm",
1098
1098
  variant: "outline",
@@ -1102,49 +1102,49 @@ function jt({
1102
1102
  children: "Reject"
1103
1103
  }
1104
1104
  ),
1105
- /* @__PURE__ */ t(
1106
- I,
1105
+ /* @__PURE__ */ r(
1106
+ Q,
1107
1107
  {
1108
1108
  size: "sm",
1109
1109
  className: "h-7 bg-emerald-600 text-[11px] text-white hover:bg-emerald-700",
1110
- onClick: () => G.mutate(),
1111
- disabled: G.isPending,
1112
- children: G.isPending ? "Approving…" : "Approve"
1110
+ onClick: () => P.mutate(),
1111
+ disabled: P.isPending,
1112
+ children: P.isPending ? "Approving…" : "Approve"
1113
1113
  }
1114
1114
  )
1115
1115
  ] }),
1116
- !r.workflow_template_id && (r.status === "approved" || r.status === "rejected") && /* @__PURE__ */ t("span", { className: "text-[11px] text-slate-400 dark:text-slate-500 italic", children: r.status === "approved" ? "Changes applied to record" : "No changes applied" }),
1117
- r.status === "reverted" && /* @__PURE__ */ t("span", { className: "text-[11px] italic text-amber-600 dark:text-amber-400", children: "Reverted — the applied changes were rolled back" }),
1118
- re && r.status === "approved" && r.legacy_id == null && (te ? /* @__PURE__ */ i("span", { className: "ml-auto flex items-center gap-1.5", children: [
1119
- /* @__PURE__ */ t("span", { className: "text-[11px] text-amber-600 dark:text-amber-400", children: "Roll every applied change back?" }),
1120
- /* @__PURE__ */ t(
1121
- I,
1116
+ !t.workflow_template_id && (t.status === "approved" || t.status === "rejected") && /* @__PURE__ */ r("span", { className: "text-[11px] text-slate-400 dark:text-slate-500 italic", children: t.status === "approved" ? "Changes applied to record" : "No changes applied" }),
1117
+ t.status === "reverted" && /* @__PURE__ */ r("span", { className: "text-[11px] italic text-amber-600 dark:text-amber-400", children: "Reverted — the applied changes were rolled back" }),
1118
+ le && t.status === "approved" && t.legacy_id == null && (X ? /* @__PURE__ */ i("span", { className: "ml-auto flex items-center gap-1.5", children: [
1119
+ /* @__PURE__ */ r("span", { className: "text-[11px] text-amber-600 dark:text-amber-400", children: "Roll every applied change back?" }),
1120
+ /* @__PURE__ */ r(
1121
+ Q,
1122
1122
  {
1123
1123
  size: "sm",
1124
1124
  className: "h-7 bg-amber-600 text-[11px] text-white hover:bg-amber-700",
1125
- disabled: M.isPending,
1125
+ disabled: K.isPending,
1126
1126
  onClick: () => {
1127
- M.mutate(), E(!1);
1127
+ K.mutate(), W(!1);
1128
1128
  },
1129
- children: M.isPending ? "Reverting…" : "Revert"
1129
+ children: K.isPending ? "Reverting…" : "Revert"
1130
1130
  }
1131
1131
  ),
1132
- /* @__PURE__ */ t(
1133
- I,
1132
+ /* @__PURE__ */ r(
1133
+ Q,
1134
1134
  {
1135
1135
  size: "sm",
1136
1136
  variant: "ghost",
1137
1137
  className: "h-7 text-[11px]",
1138
- onClick: () => E(!1),
1138
+ onClick: () => W(!1),
1139
1139
  children: "Cancel"
1140
1140
  }
1141
1141
  )
1142
- ] }) : /* @__PURE__ */ t(
1142
+ ] }) : /* @__PURE__ */ r(
1143
1143
  "button",
1144
1144
  {
1145
1145
  type: "button",
1146
1146
  "data-tip": "Admin only — restores the record to its pre-approval values through the normal revision trail; the addendum stays as a reverted record of what happened",
1147
- onClick: () => E(!0),
1147
+ onClick: () => W(!0),
1148
1148
  className: "ml-auto text-[11px] text-slate-400 underline decoration-dotted underline-offset-2 hover:text-amber-600",
1149
1149
  children: "Revert…"
1150
1150
  }
@@ -1155,65 +1155,65 @@ function jt({
1155
1155
  }
1156
1156
  );
1157
1157
  }
1158
- function ar({
1159
- collection: r,
1160
- item: c,
1158
+ function sr({
1159
+ collection: t,
1160
+ item: m,
1161
1161
  addendumLayoutId: N,
1162
- canCreate: h = !0,
1163
- onActiveCountChange: k,
1164
- onApplied: u,
1165
- onCreated: x,
1166
- defaultExpanded: _ = !0
1162
+ canCreate: b = !0,
1163
+ onActiveCountChange: _,
1164
+ onApplied: p,
1165
+ onCreated: g,
1166
+ defaultExpanded: w = !0
1167
1167
  }) {
1168
- const f = xe(), $ = Ue(), [m, v] = O(!1), [w, S] = O(!_), [D, j] = O(!1), {
1169
- data: P = [],
1170
- isLoading: J,
1171
- refetch: ee
1168
+ const h = xe(), $ = Be(), [u, y] = R(!1), [S, B] = R(!w), [k, I] = R(!1), {
1169
+ data: q = [],
1170
+ isLoading: Y,
1171
+ refetch: J
1172
1172
  } = V({
1173
- queryKey: ["addendums", r, c],
1174
- queryFn: () => f.request(U(`/addendums/${r}/${c}`)).then((p) => p.data ?? []),
1173
+ queryKey: ["addendums", t, m],
1174
+ queryFn: () => h.request(L(`/addendums/${t}/${m}`)).then((o) => o.data ?? []),
1175
1175
  // The form reads this key first (staleTime 30 s); with none here the panel,
1176
1176
  // mounting just after, counted that answer stale and fetched it again.
1177
1177
  // Live sync and the panel's own writes invalidate it.
1178
1178
  staleTime: 3e4
1179
1179
  }), { data: A, isLoading: G } = V({
1180
- queryKey: ["addendum-layout", r, N ?? "default"],
1180
+ queryKey: ["addendum-layout", t, N ?? "default"],
1181
1181
  queryFn: async () => {
1182
- const p = await f.request(U("/collection-layouts", { collection: r })).then((a) => (a.data ?? []).filter((s) => s.layout_type === "addendum"));
1183
- return N != null ? p.find((a) => a.id === N) ?? null : p[0] ?? null;
1182
+ const o = await h.request(L("/collection-layouts", { collection: t })).then((a) => (a.data ?? []).filter((s) => s.layout_type === "addendum"));
1183
+ return N != null ? o.find((a) => a.id === N) ?? null : o[0] ?? null;
1184
1184
  },
1185
1185
  staleTime: 300 * 1e3
1186
- }), M = N ?? (A == null ? void 0 : A.id) ?? null, te = !!M && (m || P.length > 0), { data: E = [], isPending: me } = V({
1187
- queryKey: ["addendum-layout-assignments", M],
1188
- queryFn: () => M ? f.request(
1189
- U(`/collection-layouts/${M}/assignments`)
1190
- ).then((p) => p.data ?? []) : Promise.resolve([]),
1191
- enabled: te,
1186
+ }), P = N ?? (A == null ? void 0 : A.id) ?? null, K = !!P && (u || q.length > 0), { data: X = [], isPending: W } = V({
1187
+ queryKey: ["addendum-layout-assignments", P],
1188
+ queryFn: () => P ? h.request(
1189
+ L(`/collection-layouts/${P}/assignments`)
1190
+ ).then((o) => o.data ?? []) : Promise.resolve([]),
1191
+ enabled: K,
1192
1192
  staleTime: 300 * 1e3
1193
- }), { data: X = [], isPending: W } = V({
1194
- queryKey: ["collection-fields", r, M],
1195
- queryFn: () => f.request(
1196
- U(
1197
- `/field-config/${r}`,
1198
- M ? { layout_id: String(M) } : void 0
1193
+ }), { data: ne = [], isPending: ae } = V({
1194
+ queryKey: ["collection-fields", t, P],
1195
+ queryFn: () => h.request(
1196
+ L(
1197
+ `/field-config/${t}`,
1198
+ P ? { layout_id: String(P) } : void 0
1199
1199
  )
1200
- ).then((p) => p.data ?? []),
1201
- enabled: te,
1200
+ ).then((o) => o.data ?? []),
1201
+ enabled: K,
1202
1202
  staleTime: 300 * 1e3
1203
- }), Y = m && M != null && (me || W), { data: L = [] } = V({
1204
- queryKey: ["relations", r],
1205
- queryFn: () => f.request(U(`/data-model/relations/for/${r}`)).then((p) => p.data ?? []),
1203
+ }), j = u && P != null && (W || ae), { data: z = [] } = V({
1204
+ queryKey: ["relations", t],
1205
+ queryFn: () => h.request(L(`/data-model/relations/for/${t}`)).then((o) => o.data ?? []),
1206
1206
  staleTime: 300 * 1e3
1207
- }), { data: re, isLoading: se } = V({
1208
- queryKey: ["item", r, c],
1209
- queryFn: () => f.request(U(`/items/${r}/${c}`)).then((p) => p.data ?? {}),
1210
- enabled: m,
1207
+ }), { data: Z, isLoading: le } = V({
1208
+ queryKey: ["item", t, m],
1209
+ queryFn: () => h.request(L(`/items/${t}/${m}`)).then((o) => o.data ?? {}),
1210
+ enabled: u,
1211
1211
  staleTime: 0
1212
- }), ne = () => {
1213
- $.invalidateQueries({ queryKey: ["addendums", r, c] }), ee(), u == null || u();
1214
- }, ie = (p) => {
1215
- $.invalidateQueries({ queryKey: ["addendums", r, c] }), ee();
1216
- const a = E.find((d) => String(d.field) === "__pdf__");
1212
+ }), se = () => {
1213
+ $.invalidateQueries({ queryKey: ["addendums", t, m] }), J(), p == null || p();
1214
+ }, te = (o) => {
1215
+ $.invalidateQueries({ queryKey: ["addendums", t, m] }), J();
1216
+ const a = X.find((f) => String(f.field) === "__pdf__");
1217
1217
  let s = null;
1218
1218
  if (a != null && a.overrides)
1219
1219
  try {
@@ -1221,77 +1221,77 @@ function ar({
1221
1221
  } catch {
1222
1222
  s = null;
1223
1223
  }
1224
- x == null || x({ id: p, pdfSlot: s });
1225
- }, Z = E.filter(
1226
- (p) => !String(p.field).startsWith("__") && (p.is_visible || p.is_visible === 1)
1227
- ), Q = P.filter(
1228
- (p) => !["approved", "rejected", "reverted"].includes(p.status)
1229
- ).length, R = Me(k);
1230
- return R.current = k, Be(() => {
1231
- var p;
1232
- (p = R.current) == null || p.call(R, Q);
1233
- }, [Q]), !h && (J || P.length === 0) ? null : /* @__PURE__ */ i(Ne, { children: [
1224
+ g == null || g({ id: o, pdfSlot: s });
1225
+ }, ie = X.filter(
1226
+ (o) => !String(o.field).startsWith("__") && (o.is_visible || o.is_visible === 1)
1227
+ ), O = q.filter(
1228
+ (o) => !["approved", "rejected", "reverted"].includes(o.status)
1229
+ ).length, ee = Pe(_);
1230
+ return ee.current = _, Je(() => {
1231
+ var o;
1232
+ (o = ee.current) == null || o.call(ee, O);
1233
+ }, [O]), !b && (Y || q.length === 0) ? null : /* @__PURE__ */ i(Ne, { children: [
1234
1234
  /* @__PURE__ */ i(
1235
1235
  "div",
1236
1236
  {
1237
- className: T(
1237
+ className: D(
1238
1238
  "overflow-hidden rounded-xl border bg-white dark:bg-card",
1239
- Q > 0 ? "border-amber-300 dark:border-amber-500/40" : "border-slate-200 dark:border-border"
1239
+ O > 0 ? "border-amber-300 dark:border-amber-500/40" : "border-slate-200 dark:border-border"
1240
1240
  ),
1241
1241
  children: [
1242
1242
  /* @__PURE__ */ i(
1243
1243
  "div",
1244
1244
  {
1245
- className: T(
1245
+ className: D(
1246
1246
  "flex items-center justify-between px-4 py-3 cursor-pointer select-none",
1247
- !w && (Q > 0 ? "border-b border-amber-200 dark:border-amber-500/30" : "border-b border-slate-200 dark:border-border")
1247
+ !S && (O > 0 ? "border-b border-amber-200 dark:border-amber-500/30" : "border-b border-slate-200 dark:border-border")
1248
1248
  ),
1249
- onClick: () => S((p) => !p),
1249
+ onClick: () => B((o) => !o),
1250
1250
  children: [
1251
1251
  /* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
1252
- /* @__PURE__ */ t(Ze, { className: "h-3.5 w-3.5 shrink-0 text-slate-400 dark:text-slate-500" }),
1253
- /* @__PURE__ */ t("h3", { className: "text-[13px] font-medium text-slate-800 dark:text-slate-200", children: "Addendums" }),
1254
- Q > 0 && /* @__PURE__ */ i("span", { className: "inline-flex items-center gap-1 rounded-full bg-amber-50 px-2 py-0.5 text-[11px] font-medium text-amber-700 border border-amber-200 dark:bg-amber-500/10 dark:text-amber-400 dark:border-amber-500/20", children: [
1255
- /* @__PURE__ */ t("span", { className: "h-1.5 w-1.5 rounded-full bg-amber-400 animate-pulse" }),
1256
- Q,
1252
+ /* @__PURE__ */ r(tt, { className: "h-3.5 w-3.5 shrink-0 text-slate-400 dark:text-slate-500" }),
1253
+ /* @__PURE__ */ r("h3", { className: "text-[13px] font-medium text-slate-800 dark:text-slate-200", children: "Addendums" }),
1254
+ O > 0 && /* @__PURE__ */ i("span", { className: "inline-flex items-center gap-1 rounded-full bg-amber-50 px-2 py-0.5 text-[11px] font-medium text-amber-700 border border-amber-200 dark:bg-amber-500/10 dark:text-amber-400 dark:border-amber-500/20", children: [
1255
+ /* @__PURE__ */ r("span", { className: "h-1.5 w-1.5 rounded-full bg-amber-400 animate-pulse" }),
1256
+ O,
1257
1257
  " in review"
1258
1258
  ] }),
1259
- P.length >= 2 && !w && /* @__PURE__ */ t(
1259
+ q.length >= 2 && !S && /* @__PURE__ */ r(
1260
1260
  "button",
1261
1261
  {
1262
1262
  type: "button",
1263
- onClick: (p) => {
1264
- p.stopPropagation(), j((a) => !a);
1263
+ onClick: (o) => {
1264
+ o.stopPropagation(), I((a) => !a);
1265
1265
  },
1266
- className: T(
1266
+ className: D(
1267
1267
  "ml-1 rounded-md border px-2 py-0.5 text-[11px] font-medium transition-colors",
1268
- D ? "border-nvr-cyan bg-nvr-cyan/10 text-[#0b7ea6] dark:text-nvr-cyan" : "border-slate-200 text-slate-500 hover:border-slate-400 hover:text-slate-700 dark:border-border dark:text-slate-400"
1268
+ k ? "border-nvr-cyan bg-nvr-cyan/10 text-[#0b7ea6] dark:text-nvr-cyan" : "border-slate-200 text-slate-500 hover:border-slate-400 hover:text-slate-700 dark:border-border dark:text-slate-400"
1269
1269
  ),
1270
1270
  "data-tip": "Every addendum side by side — amount moved, fields touched, lines changed, running total",
1271
- "aria-pressed": D,
1272
- children: D ? "Cards" : "Compare"
1271
+ "aria-pressed": k,
1272
+ children: k ? "Cards" : "Compare"
1273
1273
  }
1274
1274
  )
1275
1275
  ] }),
1276
1276
  /* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
1277
- h && (!(A != null && A.single_active_addendum) || Q === 0) && /* @__PURE__ */ t(
1278
- I,
1277
+ b && (!(A != null && A.single_active_addendum) || O === 0) && /* @__PURE__ */ r(
1278
+ Q,
1279
1279
  {
1280
1280
  size: "sm",
1281
1281
  variant: "outline",
1282
1282
  className: "h-7 text-[12px]",
1283
- onClick: (p) => {
1284
- p.stopPropagation(), v(!0);
1283
+ onClick: (o) => {
1284
+ o.stopPropagation(), y(!0);
1285
1285
  },
1286
1286
  children: "+ New Addendum"
1287
1287
  }
1288
1288
  ),
1289
- /* @__PURE__ */ t(
1290
- et,
1289
+ /* @__PURE__ */ r(
1290
+ rt,
1291
1291
  {
1292
- className: T(
1292
+ className: D(
1293
1293
  "h-3.5 w-3.5 shrink-0 text-slate-400 transition-transform duration-150",
1294
- w && "-rotate-90"
1294
+ S && "-rotate-90"
1295
1295
  )
1296
1296
  }
1297
1297
  )
@@ -1299,66 +1299,66 @@ function ar({
1299
1299
  ]
1300
1300
  }
1301
1301
  ),
1302
- !w && !A && !G && /* @__PURE__ */ i("div", { className: "px-4 py-4 text-center", children: [
1303
- /* @__PURE__ */ t("p", { className: "text-[12px] text-slate-400", children: "No addendum form configured." }),
1304
- /* @__PURE__ */ t("p", { className: "text-[11px] text-slate-300 dark:text-slate-600", children: 'Create an "Addendum Form" layout in Data Model → Layouts to enable addendum creation.' })
1302
+ !S && !A && !G && /* @__PURE__ */ i("div", { className: "px-4 py-4 text-center", children: [
1303
+ /* @__PURE__ */ r("p", { className: "text-[12px] text-slate-400", children: "No addendum form configured." }),
1304
+ /* @__PURE__ */ r("p", { className: "text-[11px] text-slate-300 dark:text-slate-600", children: 'Create an "Addendum Form" layout in Data Model → Layouts to enable addendum creation.' })
1305
1305
  ] }),
1306
- !w && (A || G) && (J ? /* @__PURE__ */ i("div", { className: "p-4 space-y-2", children: [
1307
- /* @__PURE__ */ t(le, { className: "h-12 w-full" }),
1308
- /* @__PURE__ */ t(le, { className: "h-12 w-full" })
1309
- ] }) : P.length === 0 ? /* @__PURE__ */ i("div", { className: "px-4 py-8 text-center", children: [
1310
- /* @__PURE__ */ t("p", { className: "text-[12px] text-slate-400 dark:text-slate-500", children: "No addendum attached to this record" }),
1311
- /* @__PURE__ */ t("p", { className: "mt-0.5 text-[11px] text-slate-300 dark:text-slate-600", children: "Addendums propose changes that go through a review process before being applied." })
1312
- ] }) : D && P.length >= 2 ? /* @__PURE__ */ t("div", { className: "p-3", children: /* @__PURE__ */ t(
1313
- Nt,
1306
+ !S && (A || G) && (Y ? /* @__PURE__ */ i("div", { className: "p-4 space-y-2", children: [
1307
+ /* @__PURE__ */ r(re, { className: "h-12 w-full" }),
1308
+ /* @__PURE__ */ r(re, { className: "h-12 w-full" })
1309
+ ] }) : q.length === 0 ? /* @__PURE__ */ i("div", { className: "px-4 py-8 text-center", children: [
1310
+ /* @__PURE__ */ r("p", { className: "text-[12px] text-slate-400 dark:text-slate-500", children: "No addendum attached to this record" }),
1311
+ /* @__PURE__ */ r("p", { className: "mt-0.5 text-[11px] text-slate-300 dark:text-slate-600", children: "Addendums propose changes that go through a review process before being applied." })
1312
+ ] }) : k && q.length >= 2 ? /* @__PURE__ */ r("div", { className: "p-3", children: /* @__PURE__ */ r(
1313
+ _t,
1314
1314
  {
1315
- client: f,
1316
- addendums: P,
1317
- parentCollection: r,
1318
- parentId: c,
1319
- relations: L,
1320
- fieldMap: Object.fromEntries(X.map((p) => [p.field, p]))
1315
+ client: h,
1316
+ addendums: q,
1317
+ parentCollection: t,
1318
+ parentId: m,
1319
+ relations: z,
1320
+ fieldMap: Object.fromEntries(ne.map((o) => [o.field, o]))
1321
1321
  }
1322
- ) }) : /* @__PURE__ */ t("div", { className: "p-3 space-y-2", children: P.map((p) => /* @__PURE__ */ t(
1323
- jt,
1322
+ ) }) : /* @__PURE__ */ r("div", { className: "p-3 space-y-2", children: q.map((o) => /* @__PURE__ */ r(
1323
+ Ot,
1324
1324
  {
1325
- addendum: p,
1326
- configuredFields: Z,
1327
- onRefresh: ne,
1328
- isActive: !["approved", "rejected", "reverted"].includes(p.status),
1329
- relations: L,
1330
- parentCollection: r,
1331
- parentId: c,
1332
- fieldMap: Object.fromEntries(X.map((a) => [a.field, a]))
1325
+ addendum: o,
1326
+ configuredFields: ie,
1327
+ onRefresh: se,
1328
+ isActive: !["approved", "rejected", "reverted"].includes(o.status),
1329
+ relations: z,
1330
+ parentCollection: t,
1331
+ parentId: m,
1332
+ fieldMap: Object.fromEntries(ne.map((a) => [a.field, a]))
1333
1333
  },
1334
- p.id
1334
+ o.id
1335
1335
  )) }))
1336
1336
  ]
1337
1337
  }
1338
1338
  ),
1339
- /* @__PURE__ */ t(xt, { open: m, onOpenChange: v, children: /* @__PURE__ */ t(bt, { side: "right", className: "w-[80vw] sm:max-w-[80vw] p-0 flex flex-col", children: m && (se || Y) ? /* @__PURE__ */ i("div", { className: "flex flex-col gap-3 p-6", children: [
1340
- /* @__PURE__ */ t(le, { className: "h-6 w-48" }),
1341
- /* @__PURE__ */ t(le, { className: "h-9 w-full" }),
1342
- /* @__PURE__ */ t(le, { className: "h-9 w-full" }),
1343
- /* @__PURE__ */ t(le, { className: "h-9 w-full" }),
1344
- /* @__PURE__ */ t(le, { className: "h-9 w-3/4" })
1345
- ] }) : m && re ? /* @__PURE__ */ t(
1346
- At,
1339
+ /* @__PURE__ */ r(gt, { open: u, onOpenChange: y, children: /* @__PURE__ */ r(vt, { side: "right", className: "w-[80vw] sm:max-w-[80vw] p-0 flex flex-col", children: u && (le || j) ? /* @__PURE__ */ i("div", { className: "flex flex-col gap-3 p-6", children: [
1340
+ /* @__PURE__ */ r(re, { className: "h-6 w-48" }),
1341
+ /* @__PURE__ */ r(re, { className: "h-9 w-full" }),
1342
+ /* @__PURE__ */ r(re, { className: "h-9 w-full" }),
1343
+ /* @__PURE__ */ r(re, { className: "h-9 w-full" }),
1344
+ /* @__PURE__ */ r(re, { className: "h-9 w-3/4" })
1345
+ ] }) : u && Z ? /* @__PURE__ */ r(
1346
+ Pt,
1347
1347
  {
1348
- collection: r,
1349
- itemId: c,
1350
- assignments: E,
1348
+ collection: t,
1349
+ itemId: m,
1350
+ assignments: X,
1351
1351
  workflowTemplateId: (A == null ? void 0 : A.workflow_template_id) ?? null,
1352
- resolvedLayoutId: M,
1353
- fields: X,
1354
- relations: L,
1355
- parentData: re,
1356
- onClose: () => v(!1),
1357
- onCreated: ie
1352
+ resolvedLayoutId: P,
1353
+ fields: ne,
1354
+ relations: z,
1355
+ parentData: Z,
1356
+ onClose: () => y(!1),
1357
+ onCreated: te
1358
1358
  }
1359
1359
  ) : null }) })
1360
1360
  ] });
1361
1361
  }
1362
1362
  export {
1363
- ar as AddendumPanel
1363
+ sr as AddendumPanel
1364
1364
  };