@nivaro/react 0.3.57 → 0.3.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/components/fields/RelationField.js +110 -80
  2. package/dist/full.css +1 -1
  3. package/dist/hooks/useRelationOptions.js +1 -0
  4. package/dist/hooks/useSessionRecorder.js +1 -1
  5. package/dist/index.d.ts +37 -2
  6. package/dist/index.js +523 -520
  7. package/dist/shared/components/CollectionBrowserView.js +2693 -2619
  8. package/dist/shared/components/DataTable.js +538 -495
  9. package/dist/shared/components/ItemEditForm.js +4559 -4386
  10. package/dist/shared/components/PageRenderer.js +537 -508
  11. package/dist/shared/components/ProfileView.js +716 -715
  12. package/dist/shared/components/QueryTable.js +74 -74
  13. package/dist/shared/components/RecordReadView.js +367 -364
  14. package/dist/shared/components/ReportView.js +64 -39
  15. package/dist/shared/components/WidgetSlot.js +543 -520
  16. package/dist/shared/components/alerts/AlertManagerView.js +324 -317
  17. package/dist/shared/components/alerts/types.js +37 -14
  18. package/dist/shared/components/cbv/row-focus.js +19 -0
  19. package/dist/shared/components/help-videos/HelpVideoPlayer.js +152 -147
  20. package/dist/shared/components/integrations/console/SignalCard.js +59 -59
  21. package/dist/shared/components/integrations/console/tone.js +52 -30
  22. package/dist/shared/components/item-edit/CatalogPickerField.js +525 -505
  23. package/dist/shared/components/item-edit/FieldRenderer.js +22 -20
  24. package/dist/shared/components/item-edit/FieldRow.js +175 -173
  25. package/dist/shared/components/item-edit/GridBulkEditDialog.js +55 -54
  26. package/dist/shared/components/item-edit/InlineTableField.js +2487 -2442
  27. package/dist/shared/components/item-edit/M2MCombobox.js +321 -295
  28. package/dist/shared/components/item-edit/MidairCollisionDialog.js +1 -1
  29. package/dist/shared/components/item-edit/PlanGrid.js +973 -894
  30. package/dist/shared/components/item-edit/QuickCreateButton.js +335 -106
  31. package/dist/shared/components/item-edit/RecordLiveSync.js +77 -75
  32. package/dist/shared/components/item-edit/RelationCombobox.js +452 -335
  33. package/dist/shared/components/item-edit/RelationGroupedCombobox.js +262 -141
  34. package/dist/shared/components/item-edit/SummaryPanel.js +385 -358
  35. package/dist/shared/components/item-edit/duplicate-rehearsal.js +47 -0
  36. package/dist/shared/components/item-edit/line-midair.js +82 -75
  37. package/dist/shared/components/item-edit/option-disambiguate.js +44 -32
  38. package/dist/shared/components/item-edit/related-missing.js +45 -0
  39. package/dist/shared/components/item-edit/save-outcome.js +9 -7
  40. package/dist/shared/components/notifications/NotificationRulesEditor.js +130 -123
  41. package/dist/shared/components/panels/AccessDeniedPanel.js +52 -48
  42. package/dist/shared/components/panels/ItemLockBanner.js +213 -211
  43. package/dist/shared/components/panels/PipelinePanel.js +1140 -1053
  44. package/dist/shared/components/panels/RecordIntegrityBanner.js +114 -86
  45. package/dist/shared/components/panels/RevisionsPanel.js +316 -299
  46. package/dist/shared/components/panels/TaskPanel.js +265 -249
  47. package/dist/shared/components/panels/landing-state.js +27 -0
  48. package/dist/shared/components/pipeline/PipelineEditorView.js +110 -92
  49. package/dist/shared/components/profile/AiMemoryCard.js +12 -10
  50. package/dist/shared/components/queue/OwnerAvatars.js +80 -41
  51. package/dist/shared/components/queue/QueueQuickFilters.js +52 -52
  52. package/dist/shared/components/queue/QueueWorklist.js +1050 -1026
  53. package/dist/shared/components/queue/group-sums.js +27 -0
  54. package/dist/shared/components/queue/live-state-aspect.js +9 -5
  55. package/dist/shared/components/widgets/ReviewListWidget.js +175 -154
  56. package/dist/shared/lib/back-closes.js +25 -0
  57. package/dist/shared/lib/display-prefs.js +60 -52
  58. package/dist/shared/lib/draft-store.js +71 -48
  59. package/dist/shared/lib/expression.js +53 -53
  60. package/dist/shared/lib/form-usage-beacon.js +7 -7
  61. package/dist/shared/lib/list-page-memory.js +63 -0
  62. package/dist/shared/lib/live.js +44 -44
  63. package/dist/shared/lib/money-input.js +45 -0
  64. package/dist/shared/lib/own-writes.js +76 -28
  65. package/dist/shared/lib/request-gate.js +110 -109
  66. package/dist/shared/lib/sanitize-html.js +10 -6
  67. package/dist/shared/lib/staged-row-labels.js +18 -0
  68. package/dist/shared/lib/validation-rules.js +34 -19
  69. package/package.json +1 -1
@@ -1,527 +1,590 @@
1
- import { jsx as t, jsxs as d, Fragment as Xt } from "react/jsx-runtime";
2
- import { useQueryClient as ea, useQuery as ce } from "@tanstack/react-query";
3
- import { ChevronDown as $t, ChevronRight as Ct, Lock as ta, MoreHorizontal as aa, Split as St, Undo2 as la, History as na, Trash2 as ra, Plus as sa } from "lucide-react";
4
- import { useRef as $e, useEffect as pe, useMemo as G, useCallback as ee, useState as H } from "react";
5
- import { toast as de } from "sonner";
6
- import { useNivaroClient as oa, useParentDraft as ia, useItemEditAuth as da } from "../../context.js";
7
- import { get as ue, post as rt } from "../../lib/commands.js";
8
- import { useAfterIdle as ca } from "../../lib/defer.js";
9
- import { evaluateNumeric as at } from "../../lib/expression.js";
10
- import { userErrorMessage as ua } from "../../lib/safe-error.js";
11
- import { cn as B, formatRelative as pa } from "../../lib/utils.js";
12
- import { NumberDraftInput as ma } from "../ui/number-draft-input.js";
13
- import { Popover as it, PopoverTrigger as dt, PopoverContent as ct } from "../ui/popover.js";
14
- import { resolveCompareEndpoint as ha, useCompareSeries as fa, compareColumnClosed as xa, planLabel as Pt, closedThroughLabel as ga, CompareProposalBanner as ya, CompareStripChips as ba, GridStatChip as _t, monthLabel as st, extraSeriesValue as we, SeriesFigurePopover as Ot, monthLabelLong as Ee, unitWord as ka } from "./CompareSeries.js";
15
- import { useO2MStaging as va, useLiveRows as Na } from "./O2MStagingContext.js";
16
- import { usePlanGridHost as wa } from "./PlanGridHost.js";
17
- import { RowHistorySheet as $a } from "./RowHistorySheet.js";
18
- import { RowWatchButton as Ca } from "./RowWatchButton.js";
19
- const Ie = "unclassified", I = (v) => Number(v) || 0, T = (v) => Math.round(v * 100) / 100;
20
- function D(v) {
21
- const n = Math.abs(v - Math.round(v)) < 5e-3;
22
- return v.toLocaleString("en-US", {
1
+ import { jsx as t, jsxs as c, Fragment as ra } from "react/jsx-runtime";
2
+ import { useQueryClient as sa, useQuery as he } from "@tanstack/react-query";
3
+ import { ChevronDown as Lt, ChevronRight as Mt, Lock as oa, MoreHorizontal as ia, Split as Et, Undo2 as da, History as ca, Trash2 as ua, Plus as pa } from "lucide-react";
4
+ import { useRef as me, useEffect as ue, useMemo as Z, useCallback as ee, useState as W } from "react";
5
+ import { toast as ie } from "sonner";
6
+ import { useNivaroClient as ma, useParentDraft as ha, useItemEditAuth as fa } from "../../context.js";
7
+ import { get as fe, post as ot } from "../../lib/commands.js";
8
+ import { useAfterIdle as xa } from "../../lib/defer.js";
9
+ import { evaluateNumeric as nt } from "../../lib/expression.js";
10
+ import { parseMoneyInput as ct } from "../../lib/money-input.js";
11
+ import { userErrorMessage as ga } from "../../lib/safe-error.js";
12
+ import { registerStagedRowLabel as ya } from "../../lib/staged-row-labels.js";
13
+ import { cn as D, formatRelative as ba } from "../../lib/utils.js";
14
+ import { NumberDraftInput as ka } from "../ui/number-draft-input.js";
15
+ import { Popover as ut, PopoverTrigger as pt, PopoverContent as mt } from "../ui/popover.js";
16
+ import { resolveCompareEndpoint as va, useCompareSeries as Na, compareColumnClosed as wa, planLabel as It, closedThroughLabel as $a, CompareProposalBanner as Ca, CompareStripChips as Sa, GridStatChip as Tt, monthLabel as it, extraSeriesValue as Ce, SeriesFigurePopover as Pt, monthLabelLong as je, unitWord as _a } from "./CompareSeries.js";
17
+ import { useO2MStaging as Oa, useLiveRows as Ra } from "./O2MStagingContext.js";
18
+ import { usePlanGridHost as La } from "./PlanGridHost.js";
19
+ import { RowHistorySheet as Ma } from "./RowHistorySheet.js";
20
+ import { RowWatchButton as Ea } from "./RowWatchButton.js";
21
+ const ze = "unclassified", B = (b) => Number(b) || 0, F = (b) => Math.round(b * 100) / 100;
22
+ function z(b) {
23
+ const n = Math.abs(b - Math.round(b)) < 5e-3;
24
+ return b.toLocaleString("en-US", {
23
25
  style: "currency",
24
26
  currency: "USD",
25
27
  minimumFractionDigits: n ? 0 : 2,
26
28
  maximumFractionDigits: n ? 0 : 2
27
29
  });
28
30
  }
29
- function qt(v) {
30
- const n = v.replace(/[$,\s]/g, "");
31
- if (n === "" || n === "-" || n === "—") return 0;
32
- const p = /^\(.*\)$/.test(n), g = Number(p ? n.slice(1, -1) : n);
33
- return Number.isFinite(g) ? T(p ? -g : g) : null;
31
+ function Bt(b) {
32
+ const n = ct(b);
33
+ return n.ok ? n.value : null;
34
34
  }
35
- function Sa(v, n) {
36
- return v[0] === "item" && v.length >= 3 && String(v[2]) === String(n);
35
+ function Dt(b) {
36
+ const n = ct(b);
37
+ return n.ok ? "Enter an amount of zero or more" : n.error;
37
38
  }
38
- function _a(v) {
39
- const { column: n, actual: p, openColumns: g, mode: o } = v, C = v.targetRow != null, R = T(I(v.row[n]) - p), K = { [n]: T(p) }, F = v.targetRow ?? v.row, L = C ? {} : K;
40
- if (o === "none" || Math.abs(R) < 5e-3 || g.length === 0)
41
- return { patch: K, moved: 0, unabsorbed: o === "none" ? 0 : R, targets: [] };
42
- let f, k;
43
- if (o === "next" ? (f = [g[0]], k = [1]) : o === "weighted" ? (f = g.filter((x) => I(F[x]) > 5e-3), k = f.map((x) => I(F[x])), f.length === 0 && C && R > 0 && (f = g, k = f.map(() => 1))) : (f = g, k = f.map(() => 1)), f.length === 0) return { patch: K, moved: 0, unabsorbed: R, targets: [] };
44
- const S = k.reduce((x, j) => x + j, 0) || 1;
45
- let b = R;
46
- if (f.forEach((x, j) => {
47
- const N = j === f.length - 1 ? b : T(R * k[j] / S), y = Math.max(0, T(I(F[x]) + N)), i = T(y - I(F[x]));
48
- L[x] = y, b = T(b - i);
49
- }), Math.abs(b) >= 5e-3 && b < 0)
50
- for (const x of f) {
51
- if (Math.abs(b) < 5e-3) break;
52
- const j = Math.min(L[x], -b);
53
- L[x] = T(L[x] - j), b = T(b + j);
39
+ function Ta(b, n, x, f = {}) {
40
+ const i = b ? Object.keys(x).filter((M) => Math.abs(B(x[M]) - B(b[M])) < 5e-3) : [];
41
+ if (i.length === 0) return { merge: { ...x, ...f }, replace: null };
42
+ const k = Object.fromEntries(
43
+ Object.entries({ ...n ?? {}, ...x, ...f }).filter(([M]) => !i.includes(M))
44
+ );
45
+ return {
46
+ merge: null,
47
+ replace: Object.keys(k).some((M) => !M.startsWith("_")) ? k : null
48
+ };
49
+ }
50
+ function Pa(b, n) {
51
+ return b[0] === "item" && b.length >= 3 && String(b[2]) === String(n);
52
+ }
53
+ function ja(b) {
54
+ const { column: n, actual: x, openColumns: f, mode: i } = b, k = b.targetRow != null, M = F(B(b.row[n]) - x), E = { [n]: F(x) }, K = b.targetRow ?? b.row, L = k ? {} : E;
55
+ if (i === "none" || Math.abs(M) < 5e-3 || f.length === 0)
56
+ return { patch: E, moved: 0, unabsorbed: i === "none" ? 0 : M, targets: [] };
57
+ let p, N;
58
+ if (i === "next" ? (p = [f[0]], N = [1]) : i === "weighted" ? (p = f.filter((g) => B(K[g]) > 5e-3), N = p.map((g) => B(K[g])), p.length === 0 && k && M > 0 && (p = f, N = p.map(() => 1))) : (p = f, N = p.map(() => 1)), p.length === 0) return { patch: E, moved: 0, unabsorbed: M, targets: [] };
59
+ const v = N.reduce((g, j) => g + j, 0) || 1;
60
+ let y = M;
61
+ if (p.forEach((g, j) => {
62
+ const C = j === p.length - 1 ? y : F(M * N[j] / v), q = Math.max(0, F(B(K[g]) + C)), s = F(q - B(K[g]));
63
+ L[g] = q, y = F(y - s);
64
+ }), Math.abs(y) >= 5e-3 && y < 0)
65
+ for (const g of p) {
66
+ if (Math.abs(y) < 5e-3) break;
67
+ const j = Math.min(L[g], -y);
68
+ L[g] = F(L[g] - j), y = F(y + j);
54
69
  }
55
- return C ? {
56
- patch: K,
70
+ return k ? {
71
+ patch: E,
57
72
  targetPatch: L,
58
- moved: T(R - b),
59
- unabsorbed: b,
60
- targets: f
61
- } : { patch: L, moved: T(R - b), unabsorbed: b, targets: f };
73
+ moved: F(M - y),
74
+ unabsorbed: y,
75
+ targets: p
76
+ } : { patch: L, moved: F(M - y), unabsorbed: y, targets: p };
62
77
  }
63
- const Lt = 176, Rt = 112, Mt = 128, be = "sticky left-0 z-[2] bg-white dark:bg-[hsl(var(--card))] border-r border-slate-200 dark:border-border", ke = "sticky right-0 z-[2] bg-white dark:bg-[hsl(var(--card))] border-l border-slate-200 dark:border-border", Ce = "bg-slate-50 dark:bg-white/[0.035]";
64
- function Ya(v) {
78
+ const jt = 176, qt = 112, At = 128, Ne = "sticky left-0 z-[2] bg-white dark:bg-[hsl(var(--card))] border-r border-slate-200 dark:border-border", we = "sticky right-0 z-[2] bg-white dark:bg-[hsl(var(--card))] border-l border-slate-200 dark:border-border", Se = "bg-slate-50 dark:bg-white/[0.035]";
79
+ function il(b) {
65
80
  const {
66
81
  relatedCollection: n,
67
- manyField: p,
68
- parentId: g,
69
- config: o,
70
- compareSeries: C,
71
- stats: R,
72
- sumCap: K,
73
- remaining: F,
82
+ manyField: x,
83
+ parentId: f,
84
+ config: i,
85
+ compareSeries: k,
86
+ stats: M,
87
+ sumCap: E,
88
+ remaining: K,
74
89
  readOnly: L = !1,
75
- showHistory: f = !0,
76
- emptyLabel: k
77
- } = v, S = oa(), b = ea(), x = va(), j = Na(), E = ia(), N = E == null ? void 0 : E.draft, { isAdmin: y } = da(), i = !g || g === "new", z = !L && !!x, m = o.value_fields, M = o.total_field ?? null, {
78
- data: P = [],
79
- isLoading: se,
80
- dataUpdatedAt: ve
81
- } = ce({
82
- queryKey: ["o2m-rows", n, p, g, ""],
83
- queryFn: () => S.request(
84
- ue(`/items/${n}`, { filter: JSON.stringify({ [p]: { _eq: g } }), limit: 200 })
90
+ showHistory: p = !0,
91
+ emptyLabel: N
92
+ } = b, v = ma(), y = sa(), g = Oa(), j = Ra(), I = ha(), C = I == null ? void 0 : I.draft, { isAdmin: q } = fa(), s = !f || f === "new", O = !L && !!g, h = i.value_fields, R = i.total_field ?? null, {
93
+ data: T = [],
94
+ isLoading: de,
95
+ dataUpdatedAt: re
96
+ } = he({
97
+ queryKey: ["o2m-rows", n, x, f, ""],
98
+ queryFn: () => v.request(
99
+ fe(`/items/${n}`, { filter: JSON.stringify({ [x]: { _eq: f } }), limit: 200 })
85
100
  ).then((e) => e.data ?? []),
86
- enabled: !i,
101
+ enabled: !s,
87
102
  staleTime: 3e4
88
- }), q = ca(2e3), { data: le = {} } = ce({
89
- queryKey: ["o2m-cell-provenance", n, p, g, ve],
90
- queryFn: () => S.request(
91
- ue("/revisions/o2m-cell-provenance", {
103
+ }), A = xa(2e3), { data: le = {} } = he({
104
+ queryKey: ["o2m-cell-provenance", n, x, f, re],
105
+ queryFn: () => v.request(
106
+ fe("/revisions/o2m-cell-provenance", {
92
107
  collection: n,
93
- many_field: p,
94
- parent_id: g
108
+ many_field: x,
109
+ parent_id: f
95
110
  })
96
111
  ).then((e) => e.data ?? {}),
97
- enabled: q && f && !i && P.length > 0,
112
+ enabled: A && p && !s && T.length > 0,
98
113
  staleTime: 6e4,
99
114
  placeholderData: (e) => e
100
- }), V = (e, a) => e.id ? `${n}:${e.id}:${a}` : void 0, oe = (e, a) => {
115
+ }), V = (e, a) => e.id ? `${n}:${e.id}:${a}` : void 0, ce = (e, a) => {
101
116
  var l;
102
117
  return e.id && !e.edited ? (l = le[e.id]) == null ? void 0 : l[a] : void 0;
103
- }, w = $e(null), me = (e, a) => {
118
+ }, w = me(null), xe = (e, a) => {
104
119
  !e || typeof window > "u" || window.dispatchEvent(new CustomEvent("nvr:cell-editing", { detail: { cell: e, state: a } }));
105
- }, jt = (e) => {
106
- var l, r, s;
107
- const a = ((s = (r = (l = e.target) == null ? void 0 : l.closest) == null ? void 0 : r.call(l, "[data-grid-cell]")) == null ? void 0 : s.getAttribute("data-grid-cell")) ?? null;
108
- a !== w.current && (w.current && me(w.current, "end"), w.current = a, a && me(a, "start"));
109
- }, Ft = (e) => {
120
+ }, zt = (e) => {
121
+ var l, r, o;
122
+ const a = ((o = (r = (l = e.target) == null ? void 0 : l.closest) == null ? void 0 : r.call(l, "[data-grid-cell]")) == null ? void 0 : o.getAttribute("data-grid-cell")) ?? null;
123
+ a !== w.current && (w.current && xe(w.current, "end"), w.current = a, a && xe(a, "start"));
124
+ }, Ut = (e) => {
110
125
  var a, l;
111
- (l = (a = e.relatedTarget) == null ? void 0 : a.closest) != null && l.call(a, "[data-grid-cell]") || (w.current && me(w.current, "end"), w.current = null);
126
+ (l = (a = e.relatedTarget) == null ? void 0 : a.closest) != null && l.call(a, "[data-grid-cell]") || (w.current && xe(w.current, "end"), w.current = null);
112
127
  };
113
- pe(
128
+ ue(
114
129
  () => () => {
115
- w.current && me(w.current, "end");
130
+ w.current && xe(w.current, "end");
116
131
  },
117
132
  []
118
133
  );
119
- const Pe = G(
120
- () => C != null && C.endpoint ? ha(C.endpoint, N) : null,
121
- [C == null ? void 0 : C.endpoint, N]
122
- ), Be = fa({
123
- client: S,
124
- endpoint: Pe,
125
- enabled: !!C && !i
126
- }), c = C && !i ? Be.data ?? null : null, he = G(() => !o.split_endpoint || i ? null : o.split_endpoint.replace(
134
+ const qe = Z(
135
+ () => k != null && k.endpoint ? va(k.endpoint, C) : null,
136
+ [k == null ? void 0 : k.endpoint, C]
137
+ ), Ae = Na({
138
+ client: v,
139
+ endpoint: qe,
140
+ enabled: !!k && !s
141
+ }), u = k && !s ? Ae.data ?? null : null, ht = Ae.refetch, Fe = me(0);
142
+ ue(() => {
143
+ if (!(!re || !k || s)) {
144
+ if (Fe.current === 0) {
145
+ Fe.current = re;
146
+ return;
147
+ }
148
+ re !== Fe.current && (Fe.current = re, ht());
149
+ }
150
+ }, [re, ht, k, s]);
151
+ const ge = Z(() => !i.split_endpoint || s ? null : i.split_endpoint.replace(
127
152
  /\$parent\.([A-Za-z_][A-Za-z0-9_]*)/g,
128
- (e, a) => String(a === "id" ? g : (N == null ? void 0 : N[a]) ?? "")
129
- ), [o.split_endpoint, i, g, N]), De = G(() => ["plan-grid-split-info", he], [he]), { data: ie = null } = ce({
130
- queryKey: De,
131
- queryFn: () => S.request(ue(he)).then((e) => e.data ?? null).catch(() => null),
132
- enabled: !!he,
153
+ (e, a) => String(a === "id" ? f : (C == null ? void 0 : C[a]) ?? "")
154
+ ), [i.split_endpoint, s, f, C]), Ue = Z(() => ["plan-grid-split-info", ge], [ge]), { data: pe = null } = he({
155
+ queryKey: Ue,
156
+ queryFn: () => v.request(fe(ge)).then((e) => e.data ?? null).catch(() => null),
157
+ enabled: !!ge,
133
158
  staleTime: 3e4
134
- }), { data: ut = {} } = ce({
135
- queryKey: ["plan-grid-categories", o.category_collection, o.category_label_field],
159
+ }), { data: ft = {} } = he({
160
+ queryKey: ["plan-grid-categories", i.category_collection, i.category_label_field],
136
161
  queryFn: async () => {
137
- const e = o.category_label_field ?? "name", a = await S.request(
138
- ue(`/items/${o.category_collection}`, { fields: `id,${e}`, limit: 100 })
162
+ const e = i.category_label_field ?? "name", a = await v.request(
163
+ fe(`/items/${i.category_collection}`, { fields: `id,${e}`, limit: 100 })
139
164
  );
140
165
  return Object.fromEntries((a.data ?? []).map((l) => [String(l.id), String(l[e] ?? l.id)]));
141
166
  },
142
- enabled: !!o.category_collection,
167
+ enabled: !!i.category_collection,
143
168
  staleTime: 10 * 6e4
144
- }), Se = ee(
145
- (e) => e === Ie ? o.unclassified_label ?? "Unclassified" : ut[e] ?? `#${e}`,
146
- [ut, o.unclassified_label]
147
- ), ze = G(() => (o.categories ?? []).map(String), [o.categories]), Ue = (x == null ? void 0 : x.getPendingRows(n, p)) ?? [], fe = x == null ? void 0 : x.getPendingEdits(n, p), xe = x == null ? void 0 : x.getPendingDeletes(n, p), qe = Ue.length + ((fe == null ? void 0 : fe.size) ?? 0) + ((xe == null ? void 0 : xe.size) ?? 0), pt = $e(qe);
148
- pe(() => {
149
- const e = pt.current;
150
- if (pt.current = qe, i || !(e > 0 && qe === 0)) return;
151
- const a = () => void b.invalidateQueries({ predicate: (r) => Sa(r.queryKey, g) });
169
+ }), ye = ee(
170
+ (e) => e === ze ? i.unclassified_label ?? "Unclassified" : ft[e] ?? `#${e}`,
171
+ [ft, i.unclassified_label]
172
+ ), We = Z(() => (i.categories ?? []).map(String), [i.categories]), He = (g == null ? void 0 : g.getPendingRows(n, x)) ?? [], se = g == null ? void 0 : g.getPendingEdits(n, x), be = g == null ? void 0 : g.getPendingDeletes(n, x), Ke = He.length + ((se == null ? void 0 : se.size) ?? 0) + ((be == null ? void 0 : be.size) ?? 0), xt = me(Ke);
173
+ ue(() => {
174
+ const e = xt.current;
175
+ if (xt.current = Ke, s || !(e > 0 && Ke === 0)) return;
176
+ const a = () => void y.invalidateQueries({ predicate: (r) => Pa(r.queryKey, f) });
152
177
  a();
153
178
  const l = setTimeout(a, 2e3);
154
179
  return () => clearTimeout(l);
155
- }, [qe, i, g, b]);
156
- const Z = G(() => {
180
+ }, [Ke, s, f, y]);
181
+ const J = Z(() => {
157
182
  const e = [], a = (l) => l && typeof l == "object" && "id" in l ? l.id : l;
158
- for (const l of P) {
183
+ for (const l of T) {
159
184
  const r = String(l.id);
160
- if (xe != null && xe.has(r)) continue;
161
- const s = fe == null ? void 0 : fe.get(r), u = s ? { ...l, ...s } : l, O = a(u[o.category_field]);
185
+ if (be != null && be.has(r)) continue;
186
+ const o = se == null ? void 0 : se.get(r), m = o ? { ...l, ...o } : l, _ = a(m[i.category_field]);
162
187
  e.push({
163
188
  uid: `s:${r}`,
164
189
  id: r,
165
190
  pendingIndex: null,
166
- key: String(a(u[o.key_field]) ?? ""),
167
- cat: O == null || O === "" ? null : String(O),
168
- values: u,
169
- edited: !!s && Object.keys(s).some((U) => !U.startsWith("_")),
191
+ key: String(a(m[i.key_field]) ?? ""),
192
+ cat: _ == null || _ === "" ? null : String(_),
193
+ values: m,
194
+ edited: !!o && Object.keys(o).some((U) => !U.startsWith("_")),
170
195
  isNew: !1
171
196
  });
172
197
  }
173
- return Ue.forEach((l, r) => {
174
- const s = a(l[o.category_field]);
198
+ return He.forEach((l, r) => {
199
+ const o = a(l[i.category_field]);
175
200
  e.push({
176
201
  uid: `p:${r}`,
177
202
  id: null,
178
203
  pendingIndex: r,
179
- key: String(a(l[o.key_field]) ?? ""),
180
- cat: s == null || s === "" ? null : String(s),
204
+ key: String(a(l[i.key_field]) ?? ""),
205
+ cat: o == null || o === "" ? null : String(o),
181
206
  values: l,
182
207
  edited: !1,
183
208
  isNew: !0
184
209
  });
185
210
  }), e;
186
- }, [P, Ue, fe, xe, o.key_field, o.category_field]), Y = ee(
187
- (e) => T(m.reduce((a, l) => a + I(e[l]), 0)),
188
- [m]
189
- ), re = G(() => {
211
+ }, [T, He, se, be, i.key_field, i.category_field]), gt = me(J);
212
+ gt.current = J;
213
+ const yt = me(() => "");
214
+ ue(
215
+ () => ya(n, (e) => {
216
+ const a = gt.current.find((l) => l.id === e);
217
+ return a ? yt.current(a) : null;
218
+ }),
219
+ [n]
220
+ );
221
+ const Y = ee(
222
+ (e) => F(h.reduce((a, l) => a + B(e[l]), 0)),
223
+ [h]
224
+ ), oe = Z(() => {
190
225
  const e = /* @__PURE__ */ new Map();
191
- for (const a of Z) {
226
+ for (const a of J) {
192
227
  if (!a.key) continue;
193
228
  let l = e.get(a.key);
194
229
  l || (l = { key: a.key, mode: "top", top: null, cats: [] }, e.set(a.key, l)), a.cat == null ? l.top = l.top ?? a : l.cats.push(a);
195
230
  }
196
231
  for (const a of e.values())
197
232
  a.cats.length && (a.mode = "split", a.cats.sort((l, r) => {
198
- const s = ze.indexOf(l.cat), u = ze.indexOf(r.cat);
199
- return (s < 0 ? 99 : s) - (u < 0 ? 99 : u);
233
+ const o = We.indexOf(l.cat), m = We.indexOf(r.cat);
234
+ return (o < 0 ? 99 : o) - (m < 0 ? 99 : m);
200
235
  }));
201
- for (const a of (c == null ? void 0 : c.rows) ?? []) {
236
+ for (const a of (u == null ? void 0 : u.rows) ?? []) {
202
237
  const l = String(a.key);
203
- e.has(l) || m.some((r) => Math.abs(I(a.values[r])) >= 5e-3) && e.set(l, { key: l, mode: "ghost", top: null, cats: [] });
238
+ e.has(l) || h.some((r) => Math.abs(B(a.values[r])) >= 5e-3) && e.set(l, { key: l, mode: "ghost", top: null, cats: [] });
204
239
  }
205
240
  return [...e.values()].sort(
206
241
  (a, l) => Number(a.key) - Number(l.key) || a.key.localeCompare(l.key)
207
242
  );
208
- }, [Z, c, m, ze]), _e = G(
209
- () => Z.map((e) => M ? { ...e.values, [M]: Y(e.values) } : e.values),
210
- [Z, M, Y]
211
- ), ge = j == null ? void 0 : j.report;
212
- pe(() => {
213
- if (ge) {
214
- if (se) {
215
- ge(n, p, null);
243
+ }, [J, u, h, We]), _e = Z(
244
+ () => J.map((e) => R ? { ...e.values, [R]: Y(e.values) } : e.values),
245
+ [J, R, Y]
246
+ ), ke = j == null ? void 0 : j.report;
247
+ ue(() => {
248
+ if (ke) {
249
+ if (de) {
250
+ ke(n, x, null);
216
251
  return;
217
252
  }
218
- ge(n, p, _e);
253
+ ke(n, x, _e);
219
254
  }
220
- }, [ge, n, p, _e, se]);
221
- const mt = $e(() => {
255
+ }, [ke, n, x, _e, de]);
256
+ const bt = me(() => {
222
257
  });
223
- mt.current = () => ge == null ? void 0 : ge(n, p, null), pe(() => () => mt.current(), []);
258
+ bt.current = () => ke == null ? void 0 : ke(n, x, null), ue(() => () => bt.current(), []);
224
259
  const Oe = ee(
225
260
  (e) => {
226
- if (e.startsWith("$parent.")) return (N == null ? void 0 : N[e.slice(8)]) ?? 0;
261
+ if (e.startsWith("$parent.")) return (C == null ? void 0 : C[e.slice(8)]) ?? 0;
227
262
  if (e.startsWith("$sum.")) {
228
263
  const a = e.slice(5);
229
- return _e.reduce((l, r) => l + I(r[a]), 0);
264
+ return _e.reduce((l, r) => l + B(r[a]), 0);
230
265
  }
231
- return e === "$count" ? _e.length : N == null ? void 0 : N[e];
266
+ return e === "$count" ? _e.length : C == null ? void 0 : C[e];
232
267
  },
233
- [N, _e]
234
- ), ht = G(
235
- () => (R ?? []).map((e) => ({ ...e, result: at(e.value, Oe) })),
236
- [R, Oe]
237
- ), He = G(
238
- () => T(Z.reduce((e, a) => e + Y(a.values), 0)),
239
- [Z, Y]
240
- ), Le = G(() => ie ? ie.categories.filter((e) => e.cap > 5e-3 || Z.some((a) => a.cat === String(e.id))).map((e) => {
241
- const a = T(
242
- Z.filter((l) => l.cat === String(e.id)).reduce((l, r) => l + Y(r.values), 0)
268
+ [C, _e]
269
+ ), kt = Z(
270
+ () => (M ?? []).map((e) => ({ ...e, result: nt(e.value, Oe) })),
271
+ [M, Oe]
272
+ ), Qe = Z(
273
+ () => F(J.reduce((e, a) => e + Y(a.values), 0)),
274
+ [J, Y]
275
+ ), Re = Z(() => pe ? pe.categories.filter((e) => e.cap > 5e-3 || J.some((a) => a.cat === String(e.id))).map((e) => {
276
+ const a = F(
277
+ J.filter((l) => l.cat === String(e.id)).reduce((l, r) => l + Y(r.values), 0)
243
278
  );
244
279
  return {
245
280
  id: String(e.id),
246
281
  label: e.label,
247
282
  cap: e.cap,
248
283
  planned: a,
249
- left: T(e.cap - a)
284
+ left: F(e.cap - a)
250
285
  };
251
- }) : [], [ie, Z, Y]), J = ee(
252
- (e, a) => xa(c, e, a),
253
- [c]
254
- ), je = ee(
255
- (e, a) => !z || J(e, a) && !!(c != null && c.closed_locked) && !y,
256
- [z, J, c == null ? void 0 : c.closed_locked, y]
257
- ), Re = ee(
286
+ }) : [], [pe, J, Y]), G = ee(
287
+ (e, a) => wa(u, e, a),
288
+ [u]
289
+ ), Ie = ee(
290
+ (e, a) => !O || G(e, a) && !!(u != null && u.closed_locked) && !q,
291
+ [O, G, u == null ? void 0 : u.closed_locked, q]
292
+ ), Le = ee(
258
293
  (e, a, l) => {
259
- var u, O, U;
260
- const r = c == null ? void 0 : c.rows.find((A) => String(A.key) === e);
294
+ var m, _, U;
295
+ const r = u == null ? void 0 : u.rows.find((P) => String(P.key) === e);
261
296
  if (!r) return { value: 0, details: [] };
262
- if (a == null) return { value: I(r.values[l]), details: ((u = r.details) == null ? void 0 : u[l]) ?? [] };
263
- const s = (O = r.by_category) == null ? void 0 : O[a];
264
- return { value: I(s == null ? void 0 : s.values[l]), details: ((U = s == null ? void 0 : s.details) == null ? void 0 : U[l]) ?? [] };
297
+ if (a == null) return { value: B(r.values[l]), details: ((m = r.details) == null ? void 0 : m[l]) ?? [] };
298
+ const o = (_ = r.by_category) == null ? void 0 : _[a];
299
+ return { value: B(o == null ? void 0 : o.values[l]), details: ((U = o == null ? void 0 : o.details) == null ? void 0 : U[l]) ?? [] };
265
300
  },
266
- [c]
267
- ), [ft, We] = H(null), X = ee(
301
+ [u]
302
+ ), [vt, Ve] = W(null), X = ee(
268
303
  (e, a, l, r) => {
269
- if (!x) return !1;
270
- const s = (r == null ? void 0 : r.credit) ?? 0, u = { ...e.values, ...a }, O = Y(e.values), U = Y(u);
271
- if (U - s > O + 5e-3) {
272
- if (K) {
273
- const A = at(K.cap, Oe), _ = T(He - O + U - s);
274
- if (A != null && _ > A + 5e-3)
275
- return We(
276
- `${K.message ?? `${K.label ?? "The total"} cannot exceed ${D(A)}`} — this would reach ${D(_)}, ${D(T(_ - A))} over.`
304
+ if (!g) return !1;
305
+ const o = (r == null ? void 0 : r.credit) ?? 0, m = { ...e.values, ...a }, _ = Y(e.values), U = Y(m);
306
+ if (U - o > _ + 5e-3) {
307
+ if (E) {
308
+ const P = nt(E.cap, Oe), $ = F(Qe - _ + U - o);
309
+ if (P != null && $ > P + 5e-3)
310
+ return Ve(
311
+ `${E.message ?? `${E.label ?? "The total"} cannot exceed ${z(P)}`} — this would reach ${z($)}, ${z(F($ - P))} over.`
277
312
  ), !1;
278
313
  }
279
314
  if (e.cat != null) {
280
- const A = Le.find((_) => _.id === e.cat);
281
- if (A) {
282
- const _ = T(A.planned - O + U - s);
283
- if (_ > A.cap + 5e-3)
284
- return We(
285
- `${A.label} would reach ${D(_)} — ${D(T(_ - A.cap))} over its ${D(A.cap)}.`
315
+ const P = Re.find(($) => $.id === e.cat);
316
+ if (P) {
317
+ const $ = F(P.planned - _ + U - o);
318
+ if ($ > P.cap + 5e-3)
319
+ return Ve(
320
+ `${P.label} would reach ${z($)} — ${z(F($ - P.cap))} over its ${z(P.cap)}.`
286
321
  ), !1;
287
322
  }
288
323
  }
289
324
  }
290
- return We(null), e.id ? x.queueEdit(n, p, e.id, {
291
- ...a,
292
- ...l ? { _change_reason: l } : {},
293
- ...r != null && r.early ? { __flush_early: !0 } : {}
294
- }) : e.pendingIndex != null && x.updateRow(n, p, e.pendingIndex, {
325
+ if (Ve(null), e.id) {
326
+ const P = {
327
+ ...l ? { _change_reason: l } : {},
328
+ ...r != null && r.early ? { __flush_early: !0 } : {}
329
+ }, $ = Ta(
330
+ T.find((H) => String(H.id) === e.id),
331
+ se == null ? void 0 : se.get(e.id),
332
+ a,
333
+ P
334
+ );
335
+ $.merge ? g.queueEdit(n, x, e.id, $.merge) : (g.cancelPendingEdit(n, x, e.id), $.replace && g.queueEdit(n, x, e.id, $.replace));
336
+ } else e.pendingIndex != null && g.updateRow(n, x, e.pendingIndex, {
295
337
  ...e.values,
296
338
  ...a,
297
339
  ...l ? { _change_reason: l } : {}
298
- }), !0;
340
+ });
341
+ return !0;
299
342
  },
300
- [x, Y, K, Oe, He, Le, n, p]
343
+ [
344
+ g,
345
+ Y,
346
+ E,
347
+ Oe,
348
+ Qe,
349
+ Re,
350
+ n,
351
+ x,
352
+ T,
353
+ se
354
+ ]
301
355
  ), Me = ee(
302
356
  (e, a, l, r) => {
303
- x && x.queueRow(n, p, {
304
- [o.key_field]: e,
305
- ...r != null ? { [o.category_field]: /^\d+$/.test(r) ? Number(r) : r } : {},
306
- ...Object.fromEntries(m.map((s) => [s, (a == null ? void 0 : a[s]) ?? 0])),
357
+ g && g.queueRow(n, x, {
358
+ [i.key_field]: e,
359
+ ...r != null ? { [i.category_field]: /^\d+$/.test(r) ? Number(r) : r } : {},
360
+ ...Object.fromEntries(h.map((o) => [o, (a == null ? void 0 : a[o]) ?? 0])),
307
361
  ...l ? { _change_reason: l } : {}
308
362
  });
309
363
  },
310
- [x, n, p, o.key_field, o.category_field, m]
311
- ), { data: Qe } = ce({
312
- queryKey: ["plan-grid-keys", o.key_collection],
313
- queryFn: () => S.request(
314
- ue(`/items/${o.key_collection}`, { fields: "id", sort: "-id", limit: 200 })
364
+ [g, n, x, i.key_field, i.category_field, h]
365
+ ), { data: Je } = he({
366
+ queryKey: ["plan-grid-keys", i.key_collection],
367
+ queryFn: () => v.request(
368
+ fe(`/items/${i.key_collection}`, { fields: "id", sort: "-id", limit: 200 })
315
369
  ).then((e) => (e.data ?? []).map((a) => a.id)),
316
- enabled: !!o.key_collection && !!(c != null && c.closed_through),
370
+ enabled: !!i.key_collection && !!(u != null && u.closed_through),
317
371
  staleTime: 10 * 6e4
318
- }), Ve = ee(
372
+ }), Ge = ee(
319
373
  (e, a) => {
320
374
  const l = Number(e);
321
375
  if (!Number.isInteger(l)) return null;
322
- const r = String(l + 1), s = m.filter((A) => !J(r, A)), u = re.find((A) => A.key === r);
323
- let O = null, U = null;
324
- return o.key_collection && Qe && !Qe.some((A) => String(A) === r) ? U = `${r} is not set up yet` : s.length === 0 ? U = `${r} has no open period either` : (u == null ? void 0 : u.mode) === "split" ? a == null ? U = `${r} is planned by category and this line is not` : O = u.cats.find((A) => A.cat === a) ?? null : (u == null ? void 0 : u.mode) === "top" && (a != null ? U = `${r} is planned as one line and this one is by category` : O = u.top), { key: r, cat: a, openColumns: s, row: O, blocked: U };
376
+ const r = String(l + 1), o = h.filter((P) => !G(r, P)), m = oe.find((P) => P.key === r);
377
+ let _ = null, U = null;
378
+ return i.key_collection && Je && !Je.some((P) => String(P) === r) ? U = `${r} is not set up yet` : o.length === 0 ? U = `${r} has no open period either` : (m == null ? void 0 : m.mode) === "split" ? a == null ? U = `${r} is planned by category and this line is not` : _ = m.cats.find((P) => P.cat === a) ?? null : (m == null ? void 0 : m.mode) === "top" && (a != null ? U = `${r} is planned as one line and this one is by category` : _ = m.top), { key: r, cat: a, openColumns: o, row: _, blocked: U };
325
379
  },
326
- [m, J, re, o.key_collection, Qe]
327
- ), Je = ee(
380
+ [h, G, oe, i.key_collection, Je]
381
+ ), Ze = ee(
328
382
  (e, a, l, r) => {
329
383
  if (!r || Object.keys(r.patch).length === 0) return X(e, a, l);
330
- const s = T(Y({ ...e.values, ...a }) - Y(e.values)), u = r.target.row, O = T(
331
- Y({ ...(u == null ? void 0 : u.values) ?? {}, ...r.patch }) - Y((u == null ? void 0 : u.values) ?? {})
384
+ const o = F(Y({ ...e.values, ...a }) - Y(e.values)), m = r.target.row, _ = F(
385
+ Y({ ...(m == null ? void 0 : m.values) ?? {}, ...r.patch }) - Y((m == null ? void 0 : m.values) ?? {})
332
386
  );
333
- return s <= 0 ? u ? X(u, r.patch, l, { credit: -s }) ? X(e, a, l, { early: !0 }) : !1 : O > -s + 5e-3 || !X(e, a, l, { early: !0 }) ? !1 : (Me(Number(r.target.key), r.patch, l, r.target.cat), !0) : u ? X(e, a, l, { credit: -O }) ? X(u, r.patch, l, { early: !0 }) : !1 : X(e, a, l);
387
+ return o <= 0 ? m ? X(m, r.patch, l, { credit: -o }) ? X(e, a, l, { early: !0 }) : !1 : _ > -o + 5e-3 || !X(e, a, l, { early: !0 }) ? !1 : (Me(Number(r.target.key), r.patch, l, r.target.cat), !0) : m ? X(e, a, l, { credit: -_ }) ? X(m, r.patch, l, { early: !0 }) : !1 : X(e, a, l);
334
388
  },
335
389
  [X, Y, Me]
336
- ), At = ee(
390
+ ), Wt = ee(
337
391
  (e) => {
338
- if (!x) return;
392
+ if (!g) return;
339
393
  const a = [...e.top ? [e.top] : [], ...e.cats];
340
- for (const l of a.filter((r) => r.pendingIndex != null).sort((r, s) => (s.pendingIndex ?? 0) - (r.pendingIndex ?? 0)))
341
- x.removeRow(n, p, l.pendingIndex);
342
- for (const l of a) l.id && x.queueDelete(n, p, l.id);
394
+ for (const l of a.filter((r) => r.pendingIndex != null).sort((r, o) => (o.pendingIndex ?? 0) - (r.pendingIndex ?? 0)))
395
+ g.removeRow(n, x, l.pendingIndex);
396
+ for (const l of a) l.id && g.queueDelete(n, x, l.id);
343
397
  },
344
- [x, n, p]
345
- ), Kt = ee(() => {
346
- b.invalidateQueries({ queryKey: ["o2m-rows", n, p, g] }), b.invalidateQueries({ queryKey: De }), Pe && b.invalidateQueries({ queryKey: ["o2m-compare", Pe] });
347
- }, [b, n, p, g, De, Pe]), Ge = $e(null), ye = G(() => {
398
+ [g, n, x]
399
+ ), Ht = ee(() => {
400
+ y.invalidateQueries({ queryKey: ["o2m-rows", n, x, f] }), y.invalidateQueries({ queryKey: Ue }), qe && y.invalidateQueries({ queryKey: ["o2m-compare", qe] });
401
+ }, [y, n, x, f, Ue, qe]), Ye = me(null), ve = Z(() => {
348
402
  const e = [];
349
- for (const a of re)
403
+ for (const a of oe)
350
404
  if (a.mode === "top" && a.top && e.push(a.top.uid), a.mode === "split") for (const l of a.cats) e.push(l.uid);
351
405
  return e;
352
- }, [re]), xt = ee((e, a) => {
406
+ }, [oe]), Nt = ee((e, a) => {
353
407
  var r;
354
- const l = (r = Ge.current) == null ? void 0 : r.querySelector(`[data-pg-cell="${e}:${a}"]`);
408
+ const l = (r = Ye.current) == null ? void 0 : r.querySelector(`[data-pg-cell="${e}:${a}"]`);
355
409
  return l ? (l.focus(), l.select(), !0) : !1;
356
- }, []), gt = ee(
410
+ }, []), wt = ee(
357
411
  (e, a, l, r) => {
358
- let s = ye.indexOf(e), u = m.indexOf(a);
359
- for (let O = 0; O < 40; O++)
360
- if (s += l, u += r, s < 0 || s >= ye.length || u < 0 || u >= m.length || xt(ye[s], m[u])) return;
412
+ let o = ve.indexOf(e), m = h.indexOf(a);
413
+ for (let _ = 0; _ < 40; _++)
414
+ if (o += l, m += r, o < 0 || o >= ve.length || m < 0 || m >= h.length || Nt(ve[o], h[m])) return;
361
415
  },
362
- [ye, m, xt]
363
- ), yt = ee(
416
+ [ve, h, Nt]
417
+ ), $t = ee(
364
418
  (e, a, l) => {
365
419
  const r = l.replace(/\r/g, "").split(`
366
- `).filter((U) => U.trim() !== ""), s = ye.indexOf(e.uid), u = m.indexOf(a);
367
- let O = 0;
368
- r.forEach((U, A) => {
369
- const _ = Z.find((te) => te.uid === ye[s + A]);
370
- if (!_) return;
371
- const W = {};
372
- U.split(" ").forEach((te, h) => {
373
- const $ = m[u + h];
374
- if (!$ || je(_.key, $)) return;
375
- const ae = qt(te);
376
- ae == null || ae < 0 || (W[$] = ae);
377
- }), Object.keys(W).length && X(_, W) && (O += Object.keys(W).length);
378
- }), O && de.success(`Pasted ${O} ${O === 1 ? "figure" : "figures"}`);
420
+ `).filter((P) => P.trim() !== ""), o = ve.indexOf(e.uid), m = h.indexOf(a);
421
+ let _ = 0;
422
+ const U = [];
423
+ r.forEach((P, $) => {
424
+ const H = J.find((d) => d.uid === ve[o + $]);
425
+ if (!H) return;
426
+ const te = {};
427
+ P.split(" ").forEach((d, S) => {
428
+ const ae = h[m + S];
429
+ if (!ae || Ie(H.key, ae)) return;
430
+ const Pe = Bt(d);
431
+ if (Pe == null || Pe < 0) {
432
+ U.push(d.trim());
433
+ return;
434
+ }
435
+ te[ae] = Pe;
436
+ }), Object.keys(te).length && X(H, te) && (_ += Object.keys(te).length);
437
+ }), U.length && ie.error(
438
+ `${U.length} pasted ${U.length === 1 ? "cell was" : "cells were"} left out — ${Dt(U[0])}`
439
+ ), _ && ie.success(`Pasted ${_} ${_ === 1 ? "figure" : "figures"}`);
379
440
  },
380
- [ye, m, Z, je, X]
381
- ), [It, bt] = H(/* @__PURE__ */ new Set()), Ze = $e(null);
382
- pe(() => {
441
+ [ve, h, J, Ie, X]
442
+ ), [Qt, Ct] = W(/* @__PURE__ */ new Set()), Xe = me(null);
443
+ ue(() => {
383
444
  const e = (a) => {
384
445
  const l = a.detail;
385
446
  if (!l || l.collection !== n || l.rowId == null) return;
386
- const r = Z.find((s) => s.id === String(l.rowId));
387
- r && (l.handled = !0, Ze.current !== r.id && (Ze.current = r.id, window.setTimeout(() => {
388
- Ze.current = null;
389
- }, 8e3), bt((s) => {
390
- if (!s.has(r.key)) return s;
391
- const u = new Set(s);
392
- return u.delete(r.key), u;
447
+ const r = J.find((o) => o.id === String(l.rowId));
448
+ r && (l.handled = !0, Xe.current !== r.id && (Xe.current = r.id, window.setTimeout(() => {
449
+ Xe.current = null;
450
+ }, 8e3), Ct((o) => {
451
+ if (!o.has(r.key)) return o;
452
+ const m = new Set(o);
453
+ return m.delete(r.key), m;
393
454
  }), window.setTimeout(() => {
394
- var u;
395
- const s = (u = Ge.current) == null ? void 0 : u.querySelector(`[data-o2m-row="${n}:${r.id}"]`);
396
- s && (s.scrollIntoView({ block: "center", behavior: "smooth" }), s.classList.remove("nvr-row-flash"), s.offsetWidth, s.classList.add("nvr-row-flash"));
455
+ var m;
456
+ const o = (m = Ye.current) == null ? void 0 : m.querySelector(`[data-o2m-row="${n}:${r.id}"]`);
457
+ o && (o.scrollIntoView({ block: "center", behavior: "smooth" }), o.classList.remove("nvr-row-flash"), o.offsetWidth, o.classList.add("nvr-row-flash"));
397
458
  }, 60)));
398
459
  };
399
460
  return window.addEventListener("nvr:grid-open-row", e), () => window.removeEventListener("nvr:grid-open-row", e);
400
- }, [n, Z]);
401
- const [Bt, Dt] = H(() => {
461
+ }, [n, J]);
462
+ const [Vt, Jt] = W(() => {
402
463
  try {
403
464
  return new Set(
404
- JSON.parse(localStorage.getItem(`nvr_pg_dismissed:${n}:${g}`) ?? "[]")
465
+ JSON.parse(localStorage.getItem(`nvr_pg_dismissed:${n}:${f}`) ?? "[]")
405
466
  );
406
467
  } catch {
407
468
  return /* @__PURE__ */ new Set();
408
469
  }
409
- }), kt = ((c == null ? void 0 : c.proposals) ?? []).filter((e) => !Bt.has(e.id)), vt = (e, a) => {
410
- Dt((l) => {
470
+ }), St = ((u == null ? void 0 : u.proposals) ?? []).filter((e) => !Vt.has(e.id)), _t = (e, a) => {
471
+ Jt((l) => {
411
472
  const r = new Set(l).add(e.id);
412
473
  if (a)
413
474
  try {
414
- localStorage.setItem(`nvr_pg_dismissed:${n}:${g}`, JSON.stringify([...r]));
475
+ localStorage.setItem(`nvr_pg_dismissed:${n}:${f}`, JSON.stringify([...r]));
415
476
  } catch {
416
477
  }
417
478
  return r;
418
479
  });
419
- }, zt = (e) => {
480
+ }, Gt = (e) => {
420
481
  let a = 0;
421
482
  for (const l of e.rows) {
422
- const r = String(l.key), s = re.find((_) => _.key === r);
423
- if ((s == null ? void 0 : s.mode) === "split" != (l.category != null)) continue;
424
- const u = e.mode === "add", O = Object.fromEntries(
483
+ const r = String(l.key), o = oe.find(($) => $.key === r);
484
+ if ((o == null ? void 0 : o.mode) === "split" != (l.category != null)) continue;
485
+ const m = e.mode === "add", _ = Object.fromEntries(
425
486
  Object.entries(l.values).filter(
426
- ([_, W]) => m.includes(_) && !J(r, _) && (u ? I(W) !== 0 : I(W) > 0)
487
+ ([$, H]) => h.includes($) && !G(r, $) && (m ? B(H) !== 0 : B(H) > 0)
427
488
  )
428
- ), U = (_) => Object.fromEntries(
429
- Object.entries(O).map(([W, te]) => [W, Math.max(0, T(I(_ == null ? void 0 : _[W]) + I(te)))]).filter(([W, te]) => Math.abs(te - I(_ == null ? void 0 : _[W])) >= 5e-3)
430
- ), A = l.category != null ? s == null ? void 0 : s.cats.find((_) => String(_.cat) === String(l.category)) : null;
489
+ ), U = ($) => Object.fromEntries(
490
+ Object.entries(_).map(([H, te]) => [H, Math.max(0, F(B($ == null ? void 0 : $[H]) + B(te)))]).filter(([H, te]) => Math.abs(te - B($ == null ? void 0 : $[H])) >= 5e-3)
491
+ ), P = l.category != null ? o == null ? void 0 : o.cats.find(($) => String($.cat) === String(l.category)) : null;
431
492
  if (l.category != null) {
432
- if (!A) continue;
433
- const _ = u ? U(A.values) : Object.fromEntries(Object.entries(O).filter(([W]) => I(A.values[W]) === 0));
434
- Object.keys(_).length && X(A, _, e.change_reason) && (a += Object.keys(_).length);
435
- } else if (s != null && s.top) {
436
- const _ = u ? U(s.top.values) : Object.fromEntries(Object.entries(O).filter(([W]) => {
493
+ if (!P) continue;
494
+ const $ = m ? U(P.values) : Object.fromEntries(Object.entries(_).filter(([H]) => B(P.values[H]) === 0));
495
+ Object.keys($).length && X(P, $, e.change_reason) && (a += Object.keys($).length);
496
+ } else if (o != null && o.top) {
497
+ const $ = m ? U(o.top.values) : Object.fromEntries(Object.entries(_).filter(([H]) => {
437
498
  var te;
438
- return I((te = s.top) == null ? void 0 : te.values[W]) === 0;
499
+ return B((te = o.top) == null ? void 0 : te.values[H]) === 0;
439
500
  }));
440
- Object.keys(_).length && X(s.top, _, e.change_reason) && (a += Object.keys(_).length);
441
- } else Object.keys(O).length && !(u && Object.values(O).every((_) => I(_) < 0)) && (Me(l.key, u ? U(void 0) : O, e.change_reason), a += Object.keys(O).length);
501
+ Object.keys($).length && X(o.top, $, e.change_reason) && (a += Object.keys($).length);
502
+ } else Object.keys(_).length && !(m && Object.values(_).every(($) => B($) < 0)) && (Me(l.key, m ? U(void 0) : _, e.change_reason), a += Object.keys(_).length);
442
503
  }
443
- a ? de.success(
504
+ a ? ie.success(
444
505
  `${e.label}: ${a} ${a === 1 ? "figure" : "figures"} staged — Save to keep them`
445
- ) : de.message(
506
+ ) : ie.message(
446
507
  e.mode === "add" ? "Nothing to move — no open period could take it" : "Nothing to fill — those periods already hold a figure"
447
- ), vt(e, !1);
448
- }, [Q, Ye] = H(null), Fe = wa(), Xe = Q && (Fe != null && Fe.renderRowHistory) ? Fe.renderRowHistory({
508
+ ), _t(e, !1);
509
+ }, [Q, et] = W(null), Be = La(), tt = Q && (Be != null && Be.renderRowHistory) ? Be.renderRowHistory({
449
510
  collection: n,
450
- parentId: g,
511
+ parentId: f,
451
512
  rowId: Q.id,
452
513
  key: Q.key,
453
514
  category: Q.cat,
454
- categoryLabel: (e) => Se(String(e)),
455
- onClose: () => Ye(null)
456
- }) : null, { data: Ut = [], isLoading: Ht } = ce({
515
+ categoryLabel: (e) => ye(String(e)),
516
+ onClose: () => et(null)
517
+ }) : null, { data: Zt = [], isLoading: Yt } = he({
457
518
  queryKey: ["o2m-row-revisions", n, Q == null ? void 0 : Q.id],
458
- queryFn: () => S.request(
459
- ue("/revisions", { collection: n, item: String(Q == null ? void 0 : Q.id) })
519
+ queryFn: () => v.request(
520
+ fe("/revisions", { collection: n, item: String(Q == null ? void 0 : Q.id) })
460
521
  ).then((e) => e.data ?? []),
461
- enabled: !!(Q != null && Q.id) && Xe == null,
522
+ enabled: !!(Q != null && Q.id) && tt == null,
462
523
  staleTime: 15e3
463
- }), { data: Nt = [] } = ce({
524
+ }), { data: Ot = [] } = he({
464
525
  queryKey: ["plan-grid-fields", n],
465
- queryFn: () => S.request(ue(`/field-config/${n}`)).then((e) => e.data ?? []),
526
+ queryFn: () => v.request(fe(`/field-config/${n}`)).then((e) => e.data ?? []),
466
527
  enabled: !!Q,
467
528
  staleTime: 5 * 6e4
468
- }), [et, Wt] = H(!1), wt = re.some((e) => e.mode === "split"), Ae = Pt(c), Ne = (c == null ? void 0 : c.label) ?? (C == null ? void 0 : C.label) ?? "Actual", Ke = ga(c == null ? void 0 : c.closed_through), Te = c != null && c.closed_through ? Number(c.closed_through.split("-")[0]) : null, Qt = G(() => {
529
+ }), [at, Xt] = W(!1), Rt = oe.some((e) => e.mode === "split"), Ee = It(u);
530
+ yt.current = (e) => `${e.key} ${Ee.toLowerCase()}${e.cat != null ? ` · ${ye(e.cat)}` : ""}`;
531
+ const $e = (u == null ? void 0 : u.label) ?? (k == null ? void 0 : k.label) ?? "Actual", De = $a(u == null ? void 0 : u.closed_through), Te = u != null && u.closed_through ? Number(u.closed_through.split("-")[0]) : null, ea = Z(() => {
469
532
  if (Te == null) return null;
470
- const e = m.filter((a) => J(String(Te), a));
533
+ const e = h.filter((a) => G(String(Te), a));
471
534
  return e[e.length - 1] ?? null;
472
- }, [Te, m, J]), Vt = G(
473
- () => new Set(re.filter((e) => e.mode !== "ghost").map((e) => e.key)),
474
- [re]
475
- ), Jt = F ? at(F, Oe) : null, Gt = (e) => {
476
- let a = Jt ?? 0;
535
+ }, [Te, h, G]), ta = Z(
536
+ () => new Set(oe.filter((e) => e.mode !== "ghost").map((e) => e.key)),
537
+ [oe]
538
+ ), aa = K ? nt(K, Oe) : null, la = (e) => {
539
+ let a = aa ?? 0;
477
540
  if (e.cat != null) {
478
- const u = Le.find((O) => O.id === e.cat);
479
- u && (a = Math.min(a, u.left));
541
+ const m = Re.find((_) => _.id === e.cat);
542
+ m && (a = Math.min(a, m.left));
480
543
  }
481
- const l = m.filter((u) => !J(e.key, u) && I(e.values[u]) === 0);
544
+ const l = h.filter((m) => !G(e.key, m) && B(e.values[m]) === 0);
482
545
  if (a < 5e-3 || l.length === 0) {
483
- de.message(
546
+ ie.message(
484
547
  a < 5e-3 ? "Nothing is left to spread" : "No empty open periods on this line"
485
548
  );
486
549
  return;
487
550
  }
488
- const r = Math.floor(a / l.length * 100) / 100, s = {};
489
- l.forEach((u, O) => {
490
- s[u] = O === l.length - 1 ? T(a - r * (l.length - 1)) : r;
491
- }), X(e, s) && de.success(`${D(a)} spread over ${l.length} open periods`);
492
- }, tt = G(() => {
551
+ const r = Math.floor(a / l.length * 100) / 100, o = {};
552
+ l.forEach((m, _) => {
553
+ o[m] = _ === l.length - 1 ? F(a - r * (l.length - 1)) : r;
554
+ }), X(e, o) && ie.success(`${z(a)} spread over ${l.length} open periods`);
555
+ }, lt = Z(() => {
493
556
  const e = {}, a = {};
494
- for (const l of m)
495
- e[l] = T(Z.reduce((r, s) => r + I(s.values[l]), 0)), a[l] = T(((c == null ? void 0 : c.rows) ?? []).reduce((r, s) => r + I(s.values[l]), 0));
557
+ for (const l of h)
558
+ e[l] = F(J.reduce((r, o) => r + B(o.values[l]), 0)), a[l] = F(((u == null ? void 0 : u.rows) ?? []).reduce((r, o) => r + B(o.values[l]), 0));
496
559
  return { planBy: e, actualBy: a };
497
- }, [m, Z, c]), Zt = Lt + m.length * Rt + Mt;
498
- return !i && se ? /* @__PURE__ */ t("div", { className: "space-y-1.5", "data-plan-grid-loading": !0, children: [0, 1, 2].map((e) => /* @__PURE__ */ t(
560
+ }, [h, J, u]), na = jt + h.length * qt + At;
561
+ return !s && de ? /* @__PURE__ */ t("div", { className: "space-y-1.5", "data-plan-grid-loading": !0, children: [0, 1, 2].map((e) => /* @__PURE__ */ t(
499
562
  "div",
500
563
  {
501
564
  className: "h-8 animate-pulse rounded",
502
565
  style: { background: "hsl(var(--nvr-skeleton))" }
503
566
  },
504
567
  e
505
- )) }) : /* @__PURE__ */ d("div", { ref: Ge, "data-plan-grid": n, className: "min-w-0", children: [
506
- c && kt.length > 0 && z && /* @__PURE__ */ t(
507
- ya,
568
+ )) }) : /* @__PURE__ */ c("div", { ref: Ye, "data-plan-grid": n, className: "min-w-0", children: [
569
+ u && St.length > 0 && O && /* @__PURE__ */ t(
570
+ Ca,
508
571
  {
509
- proposals: kt,
510
- onApply: zt,
511
- onDismiss: (e) => vt(e, !0)
572
+ proposals: St,
573
+ onApply: Gt,
574
+ onDismiss: (e) => _t(e, !0)
512
575
  }
513
576
  ),
514
- (ht.length > 0 || C) && /* @__PURE__ */ d("div", { className: "mb-2 flex flex-wrap items-center gap-1.5", "data-o2m-stats": !0, children: [
577
+ (kt.length > 0 || k) && /* @__PURE__ */ c("div", { className: "mb-2 flex flex-wrap items-center gap-1.5", "data-o2m-stats": !0, children: [
515
578
  /* @__PURE__ */ t(
516
- ba,
579
+ Sa,
517
580
  {
518
- data: c,
519
- loading: !!C && !i && Be.isLoading,
520
- error: !!C && !i && Be.isError
581
+ data: u,
582
+ loading: !!k && !s && Ae.isLoading,
583
+ error: !!k && !s && Ae.isError
521
584
  }
522
585
  ),
523
- ht.map((e) => /* @__PURE__ */ t(
524
- _t,
586
+ kt.map((e) => /* @__PURE__ */ t(
587
+ Tt,
525
588
  {
526
589
  label: e.label,
527
590
  value: e.result,
@@ -530,26 +593,26 @@ function Ya(v) {
530
593
  },
531
594
  e.label
532
595
  )),
533
- Le.length > 1 && wt && /* @__PURE__ */ d(
596
+ Re.length > 1 && Rt && /* @__PURE__ */ c(
534
597
  "button",
535
598
  {
536
599
  type: "button",
537
600
  "data-plan-grid-categories-toggle": !0,
538
- "aria-expanded": et,
539
- onClick: () => Wt((e) => !e),
601
+ "aria-expanded": at,
602
+ onClick: () => Xt((e) => !e),
540
603
  className: "inline-flex h-[28px] items-center gap-1 rounded-md px-2 text-[11.5px] font-medium text-slate-600 hover:bg-muted dark:text-slate-300",
541
604
  children: [
542
- et ? /* @__PURE__ */ t($t, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ t(Ct, { className: "h-3.5 w-3.5" }),
605
+ at ? /* @__PURE__ */ t(Lt, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ t(Mt, { className: "h-3.5 w-3.5" }),
543
606
  "By category"
544
607
  ]
545
608
  }
546
609
  )
547
610
  ] }),
548
- et && wt && /* @__PURE__ */ t("div", { className: "mb-2 flex flex-wrap gap-1.5", "data-plan-grid-categories": !0, children: Le.map((e) => /* @__PURE__ */ t(
549
- _t,
611
+ at && Rt && /* @__PURE__ */ t("div", { className: "mb-2 flex flex-wrap gap-1.5", "data-plan-grid-categories": !0, children: Re.map((e) => /* @__PURE__ */ t(
612
+ Tt,
550
613
  {
551
614
  dataKey: `category:${e.id}`,
552
- label: `${e.label} left of ${D(e.cap)}`,
615
+ label: `${e.label} left of ${z(e.cap)}`,
553
616
  value: e.left,
554
617
  format: "currency",
555
618
  negative: e.left < -5e-3
@@ -561,56 +624,56 @@ function Ya(v) {
561
624
  {
562
625
  className: "overflow-x-auto rounded-lg border border-slate-200 dark:border-border",
563
626
  "data-plan-grid-scroll": !0,
564
- onFocusCapture: jt,
565
- onBlurCapture: Ft,
566
- children: /* @__PURE__ */ d(
627
+ onFocusCapture: zt,
628
+ onBlurCapture: Ut,
629
+ children: /* @__PURE__ */ c(
567
630
  "table",
568
631
  {
569
632
  className: "border-separate border-spacing-0 text-[12px] tabular-nums",
570
- style: { width: "100%", minWidth: Zt, tableLayout: "fixed" },
633
+ style: { width: "100%", minWidth: na, tableLayout: "fixed" },
571
634
  children: [
572
- /* @__PURE__ */ d("colgroup", { children: [
573
- /* @__PURE__ */ t("col", { style: { width: Lt } }),
574
- m.map((e) => /* @__PURE__ */ t("col", { style: { width: Rt } }, e)),
575
- /* @__PURE__ */ t("col", { style: { width: Mt } })
635
+ /* @__PURE__ */ c("colgroup", { children: [
636
+ /* @__PURE__ */ t("col", { style: { width: jt } }),
637
+ h.map((e) => /* @__PURE__ */ t("col", { style: { width: qt } }, e)),
638
+ /* @__PURE__ */ t("col", { style: { width: At } })
576
639
  ] }),
577
- /* @__PURE__ */ t("thead", { children: /* @__PURE__ */ d("tr", { children: [
640
+ /* @__PURE__ */ t("thead", { children: /* @__PURE__ */ c("tr", { children: [
578
641
  /* @__PURE__ */ t(
579
642
  "th",
580
643
  {
581
- className: B(
582
- be,
644
+ className: D(
645
+ Ne,
583
646
  "z-[3] border-b px-3 py-1.5 text-left text-[10.5px] font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400"
584
647
  ),
585
- children: lt(o.key_field)
648
+ children: rt(i.key_field)
586
649
  }
587
650
  ),
588
- m.map((e) => {
589
- const a = Te != null && J(String(Te), e);
651
+ h.map((e) => {
652
+ const a = Te != null && G(String(Te), e);
590
653
  return /* @__PURE__ */ t(
591
654
  "th",
592
655
  {
593
- className: B(
656
+ className: D(
594
657
  "border-b border-slate-200 px-2.5 py-1.5 text-right text-[10.5px] font-semibold uppercase tracking-wide text-slate-500 dark:border-border dark:text-slate-400",
595
- a && Ce
658
+ a && Se
596
659
  ),
597
- children: /* @__PURE__ */ d("span", { className: "inline-flex items-center justify-end gap-1", children: [
598
- e === Qt && /* @__PURE__ */ t(
660
+ children: /* @__PURE__ */ c("span", { className: "inline-flex items-center justify-end gap-1", children: [
661
+ e === ea && /* @__PURE__ */ t(
599
662
  "span",
600
663
  {
601
664
  "data-plan-grid-lock": !0,
602
- "data-tip": `Closed through ${Ke ?? ""}${c != null && c.closed_rule ? ` — ${c.closed_rule}` : ""}`,
665
+ "data-tip": `Closed through ${De ?? ""}${u != null && u.closed_rule ? ` — ${u.closed_rule}` : ""}`,
603
666
  className: "inline-flex",
604
667
  children: /* @__PURE__ */ t(
605
- ta,
668
+ oa,
606
669
  {
607
670
  className: "h-3 w-3",
608
- "aria-label": `Closed through ${Ke ?? ""}`
671
+ "aria-label": `Closed through ${De ?? ""}`
609
672
  }
610
673
  )
611
674
  }
612
675
  ),
613
- st(e)
676
+ it(e)
614
677
  ] })
615
678
  },
616
679
  e
@@ -619,67 +682,67 @@ function Ya(v) {
619
682
  /* @__PURE__ */ t(
620
683
  "th",
621
684
  {
622
- className: B(
623
- ke,
685
+ className: D(
686
+ we,
624
687
  "z-[3] border-b px-3 py-1.5 text-right text-[10.5px] font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400"
625
688
  ),
626
- children: o.total_label ?? "Total"
689
+ children: i.total_label ?? "Total"
627
690
  }
628
691
  )
629
692
  ] }) }),
630
- re.length === 0 && /* @__PURE__ */ t("tbody", { children: /* @__PURE__ */ t("tr", { children: /* @__PURE__ */ d(
693
+ oe.length === 0 && /* @__PURE__ */ t("tbody", { children: /* @__PURE__ */ t("tr", { children: /* @__PURE__ */ c(
631
694
  "td",
632
695
  {
633
- colSpan: m.length + 2,
696
+ colSpan: h.length + 2,
634
697
  className: "px-3 py-6 text-[12.5px] text-slate-500 dark:text-slate-400",
635
698
  children: [
636
- `No ${(k ?? "rows").toLowerCase()} yet.`,
637
- z ? ` Add a ${lt(o.key_field).toLowerCase()} to start planning.` : ""
699
+ `No ${(N ?? "rows").toLowerCase()} yet.`,
700
+ O ? ` Add a ${rt(i.key_field).toLowerCase()} to start planning.` : ""
638
701
  ]
639
702
  }
640
703
  ) }) }),
641
- re.map((e, a) => {
642
- var _, W, te;
643
- const l = !It.has(e.key), r = (h) => {
644
- var $;
645
- return e.mode === "split" ? T(e.cats.reduce((ae, Yt) => ae + I(Yt.values[h]), 0)) : I(($ = e.top) == null ? void 0 : $.values[h]);
646
- }, s = T(m.reduce((h, $) => h + r($), 0)), u = m.some(
647
- (h) => Math.abs(Re(e.key, Ie, h).value) >= 5e-3
648
- ), O = ((c == null ? void 0 : c.series) ?? []).filter(
649
- (h) => m.some(($) => Math.abs(we(h, e.key, $) ?? 0) >= 5e-3)
650
- ), U = m.some((h) => Math.abs(Re(e.key, null, h).value) >= 5e-3), A = (((_ = e.top) == null ? void 0 : _.edited) || ((W = e.top) == null ? void 0 : W.isNew) || e.cats.some((h) => h.edited || h.isNew)) ?? !1;
651
- return /* @__PURE__ */ d(
704
+ oe.map((e, a) => {
705
+ var $, H, te;
706
+ const l = !Qt.has(e.key), r = (d) => {
707
+ var S;
708
+ return e.mode === "split" ? F(e.cats.reduce((ae, Pe) => ae + B(Pe.values[d]), 0)) : B((S = e.top) == null ? void 0 : S.values[d]);
709
+ }, o = F(h.reduce((d, S) => d + r(S), 0)), m = h.some(
710
+ (d) => Math.abs(Le(e.key, ze, d).value) >= 5e-3
711
+ ), _ = ((u == null ? void 0 : u.series) ?? []).filter(
712
+ (d) => h.some((S) => Math.abs(Ce(d, e.key, S) ?? 0) >= 5e-3)
713
+ ), U = h.some((d) => Math.abs(Le(e.key, null, d).value) >= 5e-3), P = ((($ = e.top) == null ? void 0 : $.edited) || ((H = e.top) == null ? void 0 : H.isNew) || e.cats.some((d) => d.edited || d.isNew)) ?? !1;
714
+ return /* @__PURE__ */ c(
652
715
  "tbody",
653
716
  {
654
717
  "data-plan-block": e.key,
655
718
  "data-plan-mode": e.mode,
656
- className: B(a > 0 && "pg-block"),
719
+ className: D(a > 0 && "pg-block"),
657
720
  children: [
658
- /* @__PURE__ */ d(
721
+ /* @__PURE__ */ c(
659
722
  "tr",
660
723
  {
661
724
  "data-o2m-row": (te = e.top) != null && te.id ? `${n}:${e.top.id}` : void 0,
662
- className: B(
725
+ className: D(
663
726
  a > 0 && "[&>td]:border-t [&>td]:border-slate-200 dark:[&>td]:border-border"
664
727
  ),
665
728
  children: [
666
- /* @__PURE__ */ t("td", { className: B(be, "px-2 py-1"), children: /* @__PURE__ */ d("div", { className: "flex items-center gap-1", children: [
729
+ /* @__PURE__ */ t("td", { className: D(Ne, "px-2 py-1"), children: /* @__PURE__ */ c("div", { className: "flex items-center gap-1", children: [
667
730
  e.mode === "split" ? /* @__PURE__ */ t(
668
731
  "button",
669
732
  {
670
733
  type: "button",
671
734
  "aria-expanded": l,
672
735
  "aria-label": `${l ? "Collapse" : "Expand"} ${e.key}`,
673
- onClick: () => bt((h) => {
674
- const $ = new Set(h);
675
- return $.has(e.key) ? $.delete(e.key) : $.add(e.key), $;
736
+ onClick: () => Ct((d) => {
737
+ const S = new Set(d);
738
+ return S.has(e.key) ? S.delete(e.key) : S.add(e.key), S;
676
739
  }),
677
740
  className: "rounded p-0.5 text-slate-500 hover:bg-muted",
678
- children: l ? /* @__PURE__ */ t($t, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ t(Ct, { className: "h-3.5 w-3.5" })
741
+ children: l ? /* @__PURE__ */ t(Lt, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ t(Mt, { className: "h-3.5 w-3.5" })
679
742
  }
680
743
  ) : /* @__PURE__ */ t("span", { className: "w-[18px]" }),
681
744
  /* @__PURE__ */ t("span", { className: "text-[13px] font-semibold text-slate-900 dark:text-slate-100", children: e.key }),
682
- A && /* @__PURE__ */ t(
745
+ P && /* @__PURE__ */ t(
683
746
  "span",
684
747
  {
685
748
  "data-plan-edited": !0,
@@ -687,38 +750,38 @@ function Ya(v) {
687
750
  className: "h-1.5 w-1.5 rounded-full bg-amber-500"
688
751
  }
689
752
  ),
690
- /* @__PURE__ */ t("span", { className: "ml-auto text-[10.5px] font-medium text-slate-500 dark:text-slate-400", children: e.mode === "ghost" ? "" : Ae }),
691
- z && e.mode !== "ghost" && /* @__PURE__ */ t(
692
- Ra,
753
+ /* @__PURE__ */ t("span", { className: "ml-auto text-[10.5px] font-medium text-slate-500 dark:text-slate-400", children: e.mode === "ghost" ? "" : Ee }),
754
+ O && e.mode !== "ghost" && /* @__PURE__ */ t(
755
+ Fa,
693
756
  {
694
757
  block: e,
695
- config: o,
696
- canSplit: !!he && !!(ie != null && ie.can_split) && !i,
697
- splitUnavailable: he && ie && !ie.can_split && !i ? (() => {
698
- const h = ie.categories.filter(($) => $.cap > 5e-3);
699
- return h.length === 1 ? `Every line on this record is ${h[0].label} — there is nothing to split between.` : "This record has no categorised lines yet — add lines first.";
758
+ config: i,
759
+ canSplit: !!ge && !!(pe != null && pe.can_split) && !s,
760
+ splitUnavailable: ge && pe && !pe.can_split && !s ? (() => {
761
+ const d = pe.categories.filter((S) => S.cap > 5e-3);
762
+ return d.length === 1 ? `Every line on this record is ${d[0].label} — there is nothing to split between.` : "This record has no categorised lines yet — add lines first.";
700
763
  })() : null,
701
- splitBase: he,
702
- client: S,
703
- cols: m,
704
- catLabel: Se,
705
- showHistory: f,
706
- onHistory: Ye,
707
- onSpread: F ? Gt : null,
708
- onRemove: () => At(e),
709
- onDone: Kt,
764
+ splitBase: ge,
765
+ client: v,
766
+ cols: h,
767
+ catLabel: ye,
768
+ showHistory: p,
769
+ onHistory: et,
770
+ onSpread: K ? la : null,
771
+ onRemove: () => Wt(e),
772
+ onDone: Ht,
710
773
  rc: n
711
774
  }
712
775
  )
713
776
  ] }) }),
714
- e.mode === "ghost" ? /* @__PURE__ */ d(
777
+ e.mode === "ghost" ? /* @__PURE__ */ c(
715
778
  "td",
716
779
  {
717
- colSpan: m.length,
780
+ colSpan: h.length,
718
781
  className: "px-3 py-1 text-[12px] text-slate-500 dark:text-slate-400",
719
782
  children: [
720
- `No ${Ae.toLowerCase()} for ${e.key}`,
721
- z && /* @__PURE__ */ t(
783
+ `No ${Ee.toLowerCase()} for ${e.key}`,
784
+ O && /* @__PURE__ */ t(
722
785
  "button",
723
786
  {
724
787
  type: "button",
@@ -730,114 +793,114 @@ function Ya(v) {
730
793
  )
731
794
  ]
732
795
  }
733
- ) : m.map((h) => {
734
- const $ = J(e.key, h);
796
+ ) : h.map((d) => {
797
+ const S = G(e.key, d);
735
798
  return e.mode === "split" ? /* @__PURE__ */ t(
736
799
  "td",
737
800
  {
738
- className: B(
801
+ className: D(
739
802
  "px-2.5 py-1 text-right font-semibold text-slate-900 dark:text-slate-100",
740
- $ && Ce
803
+ S && Se
741
804
  ),
742
- children: /* @__PURE__ */ t(ne, { n: r(h) })
805
+ children: /* @__PURE__ */ t(ne, { n: r(d) })
743
806
  },
744
- h
807
+ d
745
808
  ) : /* @__PURE__ */ t(
746
- Tt,
809
+ Ft,
747
810
  {
748
811
  row: e.top,
749
- col: h,
750
- closed: $,
751
- prov: oe(e.top, h),
752
- cellKey: V(e.top, h),
753
- locked: je(e.key, h),
754
- lockedTip: $ ? (c == null ? void 0 : c.closed_locked_message) ?? "This period is closed" : void 0,
755
- onCommit: (ae) => X(e.top, { [h]: ae }),
756
- onMove: gt,
757
- onPaste: yt
812
+ col: d,
813
+ closed: S,
814
+ prov: ce(e.top, d),
815
+ cellKey: V(e.top, d),
816
+ locked: Ie(e.key, d),
817
+ lockedTip: S ? (u == null ? void 0 : u.closed_locked_message) ?? "This period is closed" : void 0,
818
+ onCommit: (ae) => X(e.top, { [d]: ae }),
819
+ onMove: wt,
820
+ onPaste: $t
758
821
  },
759
- h
822
+ d
760
823
  );
761
824
  }),
762
825
  /* @__PURE__ */ t(
763
826
  "td",
764
827
  {
765
- className: B(
766
- ke,
828
+ className: D(
829
+ we,
767
830
  "px-3 py-1 text-right font-semibold text-slate-900 dark:text-slate-100"
768
831
  ),
769
- children: e.mode === "ghost" ? "" : /* @__PURE__ */ t(ne, { n: s })
832
+ children: e.mode === "ghost" ? "" : /* @__PURE__ */ t(ne, { n: o })
770
833
  }
771
834
  )
772
835
  ]
773
836
  }
774
837
  ),
775
- c && /* @__PURE__ */ t(
776
- nt,
838
+ u && /* @__PURE__ */ t(
839
+ st,
777
840
  {
778
- label: Ne,
841
+ label: $e,
779
842
  blockKey: e.key,
780
843
  cat: null,
781
- cols: m,
782
- compare: c,
844
+ cols: h,
845
+ compare: u,
783
846
  planOf: r,
784
- actualFor: Re,
785
- isClosed: J,
847
+ actualFor: Le,
848
+ isClosed: G,
786
849
  row: e.mode === "top" ? e.top : null,
787
- canReconcile: z && e.mode === "top",
788
- onReconcile: Je,
789
- carryFor: Ve
850
+ canReconcile: O && e.mode === "top",
851
+ onReconcile: Ze,
852
+ carryFor: Ge
790
853
  }
791
854
  ),
792
- e.mode !== "split" && O.map((h) => /* @__PURE__ */ d("tr", { "data-compare-series": h.key, children: [
793
- /* @__PURE__ */ t("td", { className: B(be, "px-2 py-0.5"), children: /* @__PURE__ */ t(
855
+ e.mode !== "split" && _.map((d) => /* @__PURE__ */ c("tr", { "data-compare-series": d.key, children: [
856
+ /* @__PURE__ */ t("td", { className: D(Ne, "px-2 py-0.5"), children: /* @__PURE__ */ t(
794
857
  "span",
795
858
  {
796
- "data-tip": h.hint ?? "",
859
+ "data-tip": d.hint ?? "",
797
860
  className: "block pl-[22px] text-right text-[10.5px] font-medium text-slate-500 dark:text-slate-400",
798
- children: h.label
861
+ children: d.label
799
862
  }
800
863
  ) }),
801
- m.map(($) => /* @__PURE__ */ t(
864
+ h.map((S) => /* @__PURE__ */ t(
802
865
  "td",
803
866
  {
804
- className: B(
867
+ className: D(
805
868
  "px-2.5 py-0.5 text-right text-[11.5px] text-slate-500 dark:text-slate-400",
806
- J(e.key, $) && Ce
869
+ G(e.key, S) && Se
807
870
  ),
808
- children: Math.abs(we(h, e.key, $) ?? 0) >= 5e-3 ? /* @__PURE__ */ t(
809
- Ot,
871
+ children: Math.abs(Ce(d, e.key, S) ?? 0) >= 5e-3 ? /* @__PURE__ */ t(
872
+ Pt,
810
873
  {
811
- series: h,
812
- value: we(h, e.key, $) ?? 0,
813
- periodLabel: `${Ee($)} ${e.key}`,
814
- children: /* @__PURE__ */ t(ne, { n: we(h, e.key, $) ?? 0, muted: !0 })
874
+ series: d,
875
+ value: Ce(d, e.key, S) ?? 0,
876
+ periodLabel: `${je(S)} ${e.key}`,
877
+ children: /* @__PURE__ */ t(ne, { n: Ce(d, e.key, S) ?? 0, muted: !0 })
815
878
  }
816
879
  ) : /* @__PURE__ */ t(ne, { n: 0, muted: !0 })
817
880
  },
818
- $
881
+ S
819
882
  )),
820
883
  /* @__PURE__ */ t(
821
884
  "td",
822
885
  {
823
- className: B(
824
- ke,
886
+ className: D(
887
+ we,
825
888
  "px-3 py-0.5 text-right text-[11.5px] text-slate-500 dark:text-slate-400"
826
889
  ),
827
890
  children: /* @__PURE__ */ t(
828
- Ot,
891
+ Pt,
829
892
  {
830
- series: h,
831
- value: T(
832
- m.reduce(($, ae) => $ + (we(h, e.key, ae) ?? 0), 0)
893
+ series: d,
894
+ value: F(
895
+ h.reduce((S, ae) => S + (Ce(d, e.key, ae) ?? 0), 0)
833
896
  ),
834
897
  periodLabel: String(e.key),
835
898
  whole: !0,
836
899
  children: /* @__PURE__ */ t(
837
900
  ne,
838
901
  {
839
- n: T(
840
- m.reduce(($, ae) => $ + (we(h, e.key, ae) ?? 0), 0)
902
+ n: F(
903
+ h.reduce((S, ae) => S + (Ce(d, e.key, ae) ?? 0), 0)
841
904
  ),
842
905
  muted: !0
843
906
  }
@@ -846,83 +909,84 @@ function Ya(v) {
846
909
  )
847
910
  }
848
911
  )
849
- ] }, h.key)),
850
- e.mode === "split" && l && e.cats.map((h) => /* @__PURE__ */ d(Oa, { children: [
851
- /* @__PURE__ */ d(
912
+ ] }, d.key)),
913
+ e.mode === "split" && l && e.cats.map((d) => /* @__PURE__ */ c(qa, { children: [
914
+ /* @__PURE__ */ c(
852
915
  "tr",
853
916
  {
854
- "data-o2m-row": h.id ? `${n}:${h.id}` : void 0,
855
- "data-plan-category": h.cat ?? "",
917
+ "data-o2m-row": d.id ? `${n}:${d.id}` : void 0,
918
+ "data-plan-category": d.cat ?? "",
856
919
  children: [
857
- /* @__PURE__ */ t("td", { className: B(be, "px-2 py-1"), children: /* @__PURE__ */ d("div", { className: "flex items-center gap-1 pl-[22px]", children: [
858
- /* @__PURE__ */ t("span", { className: "truncate text-[12.5px] font-medium text-slate-800 dark:text-slate-100", children: Se(h.cat) }),
859
- (h.edited || h.isNew) && /* @__PURE__ */ t("span", { className: "h-1.5 w-1.5 rounded-full bg-amber-500" }),
860
- /* @__PURE__ */ t("span", { className: "ml-auto text-[10.5px] font-medium text-slate-500 dark:text-slate-400", children: Ae })
920
+ /* @__PURE__ */ t("td", { className: D(Ne, "px-2 py-1"), children: /* @__PURE__ */ c("div", { className: "flex items-center gap-1 pl-[22px]", children: [
921
+ /* @__PURE__ */ t("span", { className: "truncate text-[12.5px] font-medium text-slate-800 dark:text-slate-100", children: ye(d.cat) }),
922
+ (d.edited || d.isNew) && /* @__PURE__ */ t("span", { className: "h-1.5 w-1.5 rounded-full bg-amber-500" }),
923
+ /* @__PURE__ */ t("span", { className: "ml-auto text-[10.5px] font-medium text-slate-500 dark:text-slate-400", children: Ee })
861
924
  ] }) }),
862
- m.map(($) => /* @__PURE__ */ t(
863
- Tt,
925
+ h.map((S) => /* @__PURE__ */ t(
926
+ Ft,
864
927
  {
865
- row: h,
866
- col: $,
867
- closed: J(e.key, $),
868
- prov: oe(h, $),
869
- cellKey: V(h, $),
870
- locked: je(e.key, $),
871
- lockedTip: J(e.key, $) ? (c == null ? void 0 : c.closed_locked_message) ?? "This period is closed" : void 0,
872
- onCommit: (ae) => X(h, { [$]: ae }),
873
- onMove: gt,
874
- onPaste: yt
928
+ row: d,
929
+ rowLabel: d.cat != null ? ye(String(d.cat)) : void 0,
930
+ col: S,
931
+ closed: G(e.key, S),
932
+ prov: ce(d, S),
933
+ cellKey: V(d, S),
934
+ locked: Ie(e.key, S),
935
+ lockedTip: G(e.key, S) ? (u == null ? void 0 : u.closed_locked_message) ?? "This period is closed" : void 0,
936
+ onCommit: (ae) => X(d, { [S]: ae }),
937
+ onMove: wt,
938
+ onPaste: $t
875
939
  },
876
- $
940
+ S
877
941
  )),
878
942
  /* @__PURE__ */ t(
879
943
  "td",
880
944
  {
881
- className: B(
882
- ke,
945
+ className: D(
946
+ we,
883
947
  "px-3 py-1 text-right font-medium text-slate-800 dark:text-slate-100"
884
948
  ),
885
- children: /* @__PURE__ */ t(ne, { n: Y(h.values) })
949
+ children: /* @__PURE__ */ t(ne, { n: Y(d.values) })
886
950
  }
887
951
  )
888
952
  ]
889
953
  }
890
954
  ),
891
- c && U && /* @__PURE__ */ t(
892
- nt,
955
+ u && U && /* @__PURE__ */ t(
956
+ st,
893
957
  {
894
- label: Ne,
958
+ label: $e,
895
959
  blockKey: e.key,
896
- cat: h.cat,
897
- cols: m,
898
- compare: c,
899
- planOf: ($) => I(h.values[$]),
900
- actualFor: Re,
901
- isClosed: J,
902
- row: h,
903
- canReconcile: z,
904
- onReconcile: Je,
905
- carryFor: Ve,
960
+ cat: d.cat,
961
+ cols: h,
962
+ compare: u,
963
+ planOf: (S) => B(d.values[S]),
964
+ actualFor: Le,
965
+ isClosed: G,
966
+ row: d,
967
+ canReconcile: O,
968
+ onReconcile: Ze,
969
+ carryFor: Ge,
906
970
  indent: !0
907
971
  }
908
972
  )
909
- ] }, h.uid)),
910
- e.mode === "split" && l && c && u && /* @__PURE__ */ t(
911
- nt,
973
+ ] }, d.uid)),
974
+ e.mode === "split" && l && u && m && /* @__PURE__ */ t(
975
+ st,
912
976
  {
913
- label: `${Se(Ie)} · ${Ne.toLowerCase()}`,
914
- tip: `${Ne} the source could not place in a category — it counts in the ${e.key} total only.`,
977
+ label: `${ye(ze)} · ${$e.toLowerCase()}`,
978
+ tip: `${$e} the source could not place in a category — it counts in the ${e.key} total only.`,
915
979
  blockKey: e.key,
916
- cat: Ie,
917
- cols: m,
918
- compare: c,
980
+ cat: ze,
981
+ cols: h,
982
+ compare: u,
919
983
  planOf: () => 0,
920
- actualFor: Re,
921
- isClosed: J,
984
+ actualFor: Le,
985
+ isClosed: G,
922
986
  row: null,
923
987
  canReconcile: !1,
924
- onReconcile: Je,
925
- carryFor: Ve,
988
+ onReconcile: Ze,
989
+ carryFor: Ge,
926
990
  indent: !0,
927
991
  plain: !0
928
992
  }
@@ -932,49 +996,49 @@ function Ya(v) {
932
996
  e.key
933
997
  );
934
998
  }),
935
- re.length > 1 && /* @__PURE__ */ d("tfoot", { children: [
936
- /* @__PURE__ */ d("tr", { className: "[&>td]:border-t [&>td]:border-slate-300 dark:[&>td]:border-border", children: [
937
- /* @__PURE__ */ t("td", { className: B(be, "px-2 py-1.5"), children: /* @__PURE__ */ d("div", { className: "flex items-center pl-[22px]", children: [
999
+ oe.length > 1 && /* @__PURE__ */ c("tfoot", { children: [
1000
+ /* @__PURE__ */ c("tr", { className: "[&>td]:border-t [&>td]:border-slate-300 dark:[&>td]:border-border", children: [
1001
+ /* @__PURE__ */ t("td", { className: D(Ne, "px-2 py-1.5"), children: /* @__PURE__ */ c("div", { className: "flex items-center pl-[22px]", children: [
938
1002
  /* @__PURE__ */ t("span", { className: "text-[12px] font-semibold text-slate-900 dark:text-slate-100", children: "All" }),
939
- /* @__PURE__ */ t("span", { className: "ml-auto text-[10.5px] font-medium text-slate-500 dark:text-slate-400", children: Ae })
1003
+ /* @__PURE__ */ t("span", { className: "ml-auto text-[10.5px] font-medium text-slate-500 dark:text-slate-400", children: Ee })
940
1004
  ] }) }),
941
- m.map((e) => /* @__PURE__ */ t(
1005
+ h.map((e) => /* @__PURE__ */ t(
942
1006
  "td",
943
1007
  {
944
1008
  className: "px-2.5 py-1.5 text-right font-semibold text-slate-900 dark:text-slate-100",
945
- children: /* @__PURE__ */ t(ne, { n: tt.planBy[e] })
1009
+ children: /* @__PURE__ */ t(ne, { n: lt.planBy[e] })
946
1010
  },
947
1011
  e
948
1012
  )),
949
1013
  /* @__PURE__ */ t(
950
1014
  "td",
951
1015
  {
952
- className: B(
953
- ke,
1016
+ className: D(
1017
+ we,
954
1018
  "px-3 py-1.5 text-right font-semibold text-slate-900 dark:text-slate-100"
955
1019
  ),
956
- children: /* @__PURE__ */ t(ne, { n: He })
1020
+ children: /* @__PURE__ */ t(ne, { n: Qe })
957
1021
  }
958
1022
  )
959
1023
  ] }),
960
- c && /* @__PURE__ */ d("tr", { children: [
961
- /* @__PURE__ */ t("td", { className: B(be, "px-2 pb-1.5 pt-0"), children: /* @__PURE__ */ t("span", { className: "block text-right text-[10.5px] font-medium text-slate-500 dark:text-slate-400", children: Ne }) }),
962
- m.map((e) => /* @__PURE__ */ t(
1024
+ u && /* @__PURE__ */ c("tr", { children: [
1025
+ /* @__PURE__ */ t("td", { className: D(Ne, "px-2 pb-1.5 pt-0"), children: /* @__PURE__ */ t("span", { className: "block text-right text-[10.5px] font-medium text-slate-500 dark:text-slate-400", children: $e }) }),
1026
+ h.map((e) => /* @__PURE__ */ t(
963
1027
  "td",
964
1028
  {
965
1029
  className: "px-2.5 pb-1.5 pt-0 text-right text-[11.5px] text-slate-600 dark:text-slate-300",
966
- children: /* @__PURE__ */ t(ne, { n: tt.actualBy[e], muted: !0 })
1030
+ children: /* @__PURE__ */ t(ne, { n: lt.actualBy[e], muted: !0 })
967
1031
  },
968
1032
  e
969
1033
  )),
970
1034
  /* @__PURE__ */ t(
971
1035
  "td",
972
1036
  {
973
- className: B(
974
- ke,
1037
+ className: D(
1038
+ we,
975
1039
  "px-3 pb-1.5 pt-0 text-right text-[11.5px] text-slate-600 dark:text-slate-300"
976
1040
  ),
977
- children: /* @__PURE__ */ t(ne, { n: T(m.reduce((e, a) => e + tt.actualBy[a], 0)), muted: !0 })
1041
+ children: /* @__PURE__ */ t(ne, { n: F(h.reduce((e, a) => e + lt.actualBy[a], 0)), muted: !0 })
978
1042
  }
979
1043
  )
980
1044
  ] })
@@ -984,49 +1048,49 @@ function Ya(v) {
984
1048
  )
985
1049
  }
986
1050
  ),
987
- ft && /* @__PURE__ */ t(
1051
+ vt && /* @__PURE__ */ t(
988
1052
  "p",
989
1053
  {
990
1054
  role: "alert",
991
1055
  "data-plan-grid-notice": !0,
992
1056
  className: "mt-1.5 text-[12px] font-medium text-red-700 dark:text-red-300",
993
- children: ft
1057
+ children: vt
994
1058
  }
995
1059
  ),
996
- z && /* @__PURE__ */ d("div", { className: "mt-2 flex items-center gap-2", children: [
1060
+ O && /* @__PURE__ */ c("div", { className: "mt-2 flex items-center gap-2", children: [
997
1061
  /* @__PURE__ */ t(
998
- Ea,
1062
+ Ba,
999
1063
  {
1000
- config: o,
1001
- client: S,
1002
- used: Vt,
1064
+ config: i,
1065
+ client: v,
1066
+ used: ta,
1003
1067
  onAdd: (e) => Me(e),
1004
- label: `Add ${lt(o.key_field).toLowerCase()}`
1068
+ label: `Add ${rt(i.key_field).toLowerCase()}`
1005
1069
  }
1006
1070
  ),
1007
- (c == null ? void 0 : c.closed_locked) && !y && Ke && /* @__PURE__ */ t("span", { className: "text-[11.5px] text-slate-500 dark:text-slate-400", children: `Periods through ${Ke} are closed — open a highlighted ${Ne.toLowerCase()} figure to reconcile one.` })
1071
+ (u == null ? void 0 : u.closed_locked) && !q && De && /* @__PURE__ */ t("span", { className: "text-[11.5px] text-slate-500 dark:text-slate-400", children: `Periods through ${De} are closed — open a highlighted ${$e.toLowerCase()} figure to reconcile one.` })
1008
1072
  ] }),
1009
- Xe,
1010
- Q && Xe == null && /* @__PURE__ */ t(
1011
- $a,
1073
+ tt,
1074
+ Q && tt == null && /* @__PURE__ */ t(
1075
+ Ma,
1012
1076
  {
1013
1077
  open: !0,
1014
1078
  onOpenChange: (e) => {
1015
- e || Ye(null);
1079
+ e || et(null);
1016
1080
  },
1017
- rowTitle: `${Q.key}${Q.cat ? ` · ${Se(Q.cat)}` : ""}`,
1018
- revisions: Ut,
1019
- loading: Ht,
1020
- fields: Nt,
1021
- displayCols: Nt.filter(
1022
- (e) => m.includes(e.field) || e.field === o.category_field
1081
+ rowTitle: `${Q.key}${Q.cat ? ` · ${ye(Q.cat)}` : ""}`,
1082
+ revisions: Zt,
1083
+ loading: Yt,
1084
+ fields: Ot,
1085
+ displayCols: Ot.filter(
1086
+ (e) => h.includes(e.field) || e.field === i.category_field
1023
1087
  ),
1024
- parentField: p,
1088
+ parentField: x,
1025
1089
  m2oRelMap: /* @__PURE__ */ new Map(),
1026
1090
  relations: [],
1027
1091
  collection: n,
1028
1092
  m2oDisplays: {},
1029
- client: S,
1093
+ client: v,
1030
1094
  allowRestore: !1,
1031
1095
  onRestore: () => {
1032
1096
  }
@@ -1034,84 +1098,97 @@ function Ya(v) {
1034
1098
  )
1035
1099
  ] });
1036
1100
  }
1037
- function lt(v) {
1038
- return v.replace(/_/g, " ").replace(/^\w/, (n) => n.toUpperCase());
1101
+ function rt(b) {
1102
+ return b.replace(/_/g, " ").replace(/^\w/, (n) => n.toUpperCase());
1039
1103
  }
1040
- function Oa(v) {
1041
- return /* @__PURE__ */ t(Xt, { children: v.children });
1104
+ function qa(b) {
1105
+ return /* @__PURE__ */ t(ra, { children: b.children });
1042
1106
  }
1043
- function ne(v) {
1044
- return Math.abs(v.n) < 5e-3 ? /* @__PURE__ */ t("span", { className: "text-slate-400 dark:text-slate-500", children: "—" }) : /* @__PURE__ */ t("span", { children: D(v.n) });
1107
+ function ne(b) {
1108
+ return Math.abs(b.n) < 5e-3 ? /* @__PURE__ */ t("span", { className: "text-slate-400 dark:text-slate-500", children: "—" }) : /* @__PURE__ */ t("span", { children: z(b.n) });
1045
1109
  }
1046
- function Tt(v) {
1047
- const { row: n, col: p, closed: g, locked: o, lockedTip: C, prov: R, cellKey: K, onCommit: F, onMove: L, onPaste: f } = v, k = I(n.values[p]), S = R ? `${Ee(p)} · changed ${pa(R.at)} by ${R.who}${R.reason ? `
1048
- Reason: “${R.reason}”` : ""}` : void 0, b = R != null && R.reason ? /* @__PURE__ */ t(
1110
+ function Ft(b) {
1111
+ const {
1112
+ row: n,
1113
+ rowLabel: x,
1114
+ col: f,
1115
+ closed: i,
1116
+ locked: k,
1117
+ lockedTip: M,
1118
+ prov: E,
1119
+ cellKey: K,
1120
+ onCommit: L,
1121
+ onMove: p,
1122
+ onPaste: N
1123
+ } = b, v = B(n.values[f]), y = E ? `${je(f)} · changed ${ba(E.at)} by ${E.who}${E.reason ? `
1124
+ Reason: “${E.reason}”` : ""}` : void 0, g = E != null && E.reason ? /* @__PURE__ */ t(
1049
1125
  "span",
1050
1126
  {
1051
1127
  "aria-hidden": "true",
1052
1128
  "data-cell-reason": !0,
1053
1129
  className: "pointer-events-none absolute left-0 top-0 h-0 w-0 border-r-[6px] border-t-[6px] border-r-transparent border-t-nvr-cyan"
1054
1130
  }
1055
- ) : null, [x, j] = H(null), E = $e(!1);
1056
- if (o)
1057
- return /* @__PURE__ */ d(
1131
+ ) : null, [j, I] = W(null), C = me(!1);
1132
+ if (k)
1133
+ return /* @__PURE__ */ c(
1058
1134
  "td",
1059
1135
  {
1060
- "data-plan-locked": g ? "closed" : "readonly",
1061
- "data-tip": [C, S].filter(Boolean).join(`
1136
+ "data-plan-locked": i ? "closed" : "readonly",
1137
+ "data-tip": [M, y].filter(Boolean).join(`
1062
1138
  `) || void 0,
1063
1139
  "data-grid-cell": K,
1064
- className: B(
1140
+ className: D(
1065
1141
  "relative px-2.5 py-1 text-right text-slate-700 dark:text-slate-200",
1066
- g && Ce
1142
+ i && Se
1067
1143
  ),
1068
1144
  children: [
1069
- b,
1070
- /* @__PURE__ */ t(ne, { n: k })
1145
+ g,
1146
+ /* @__PURE__ */ t(ne, { n: v })
1071
1147
  ]
1072
1148
  }
1073
1149
  );
1074
- const N = () => {
1075
- if (x == null) return;
1076
- const y = qt(x);
1077
- if (j(null), E.current) {
1078
- E.current = !1;
1150
+ const q = () => {
1151
+ if (j == null) return;
1152
+ const s = Bt(j);
1153
+ if (I(null), C.current) {
1154
+ C.current = !1;
1079
1155
  return;
1080
1156
  }
1081
- if (y == null || y < 0) {
1082
- de.error("Enter an amount of zero or more");
1157
+ if (s == null || s < 0) {
1158
+ ie.error(Dt(j));
1083
1159
  return;
1084
1160
  }
1085
- Math.abs(y - k) < 5e-3 || F(y);
1161
+ const O = ct(j);
1162
+ O.ok && O.rounded && ie.message(`Rounded to ${z(s)} — amounts are kept to the cent`), !(Math.abs(s - v) < 5e-3) && L(s);
1086
1163
  };
1087
- return /* @__PURE__ */ d(
1164
+ return /* @__PURE__ */ c(
1088
1165
  "td",
1089
1166
  {
1090
- className: B("relative p-0", g && Ce),
1167
+ className: D("relative p-0", i && Se),
1091
1168
  "data-grid-cell": K,
1092
- "data-tip": S,
1169
+ "data-tip": y,
1093
1170
  children: [
1094
- b,
1171
+ g,
1095
1172
  /* @__PURE__ */ t(
1096
1173
  "input",
1097
1174
  {
1098
- "data-pg-cell": `${n.uid}:${p}`,
1099
- "aria-label": `${Ee(p)} ${n.key}`,
1175
+ "data-pg-cell": `${n.uid}:${f}`,
1176
+ "aria-label": `${je(f)} ${n.key}${x ? ` · ${x}` : ""}`,
1100
1177
  inputMode: "decimal",
1101
- value: x ?? (k === 0 ? "" : D(k)),
1178
+ value: j ?? (v === 0 ? "" : z(v)),
1102
1179
  placeholder: "—",
1103
- onFocus: (y) => {
1104
- j(k === 0 ? "" : String(k)), requestAnimationFrame(() => y.target.select());
1180
+ onFocus: (s) => {
1181
+ I(v === 0 ? "" : String(v)), requestAnimationFrame(() => s.target.select());
1105
1182
  },
1106
- onChange: (y) => j(y.target.value),
1107
- onBlur: N,
1108
- onPaste: (y) => {
1109
- const i = y.clipboardData.getData("text");
1110
- /[\t\n]/.test(i.trim()) && (y.preventDefault(), E.current = !0, y.target.blur(), f(n, p, i));
1183
+ onChange: (s) => I(s.target.value),
1184
+ onBlur: q,
1185
+ onPaste: (s) => {
1186
+ const O = s.clipboardData.getData("text");
1187
+ /[\t\n]/.test(O.trim()) && (s.preventDefault(), C.current = !0, s.target.blur(), N(n, f, O));
1111
1188
  },
1112
- onKeyDown: (y) => {
1113
- const i = y.currentTarget, z = i.selectionStart === 0 && i.selectionEnd === 0, m = i.selectionStart === i.value.length && i.selectionEnd === i.value.length;
1114
- y.key === "Enter" || y.key === "ArrowDown" ? (y.preventDefault(), N(), L(n.uid, p, 1, 0)) : y.key === "ArrowUp" ? (y.preventDefault(), N(), L(n.uid, p, -1, 0)) : y.key === "ArrowLeft" && z ? (y.preventDefault(), N(), L(n.uid, p, 0, -1)) : y.key === "ArrowRight" && m ? (y.preventDefault(), N(), L(n.uid, p, 0, 1)) : y.key === "Escape" && (E.current = !0, i.blur());
1189
+ onKeyDown: (s) => {
1190
+ const O = s.currentTarget, h = O.selectionStart === 0 && O.selectionEnd === 0, R = O.selectionStart === O.value.length && O.selectionEnd === O.value.length;
1191
+ s.key === "Enter" || s.key === "ArrowDown" ? (s.preventDefault(), q(), p(n.uid, f, 1, 0)) : s.key === "ArrowUp" ? (s.preventDefault(), q(), p(n.uid, f, -1, 0)) : s.key === "ArrowLeft" && h ? (s.preventDefault(), q(), p(n.uid, f, 0, -1)) : s.key === "ArrowRight" && R ? (s.preventDefault(), q(), p(n.uid, f, 0, 1)) : s.key === "Escape" && (C.current = !0, O.blur());
1115
1192
  },
1116
1193
  className: "h-[30px] w-full bg-transparent px-2.5 text-right text-[12px] tabular-nums text-slate-900 outline-none placeholder:text-slate-400 hover:bg-muted/60 focus:bg-white focus:shadow-[inset_0_0_0_2px_rgb(var(--nvr-cyan-rgb))] dark:text-slate-100 dark:placeholder:text-slate-500 dark:focus:bg-[hsl(var(--background))]"
1117
1194
  }
@@ -1120,69 +1197,69 @@ Reason: “${R.reason}”` : ""}` : void 0, b = R != null && R.reason ? /* @__PU
1120
1197
  }
1121
1198
  );
1122
1199
  }
1123
- function nt(v) {
1200
+ function st(b) {
1124
1201
  const {
1125
1202
  label: n,
1126
- tip: p,
1127
- blockKey: g,
1128
- cat: o,
1129
- cols: C,
1130
- compare: R,
1131
- planOf: K,
1132
- actualFor: F,
1203
+ tip: x,
1204
+ blockKey: f,
1205
+ cat: i,
1206
+ cols: k,
1207
+ compare: M,
1208
+ planOf: E,
1209
+ actualFor: K,
1133
1210
  isClosed: L,
1134
- row: f,
1135
- canReconcile: k,
1136
- onReconcile: S,
1137
- carryFor: b,
1138
- plain: x
1139
- } = v, j = T(C.reduce((E, N) => E + F(g, o, N).value, 0));
1140
- return /* @__PURE__ */ d("tr", { "data-plan-actual": o ?? "all", children: [
1141
- /* @__PURE__ */ t("td", { className: B(be, "px-2 pb-1 pt-0"), children: /* @__PURE__ */ t(
1211
+ row: p,
1212
+ canReconcile: N,
1213
+ onReconcile: v,
1214
+ carryFor: y,
1215
+ plain: g
1216
+ } = b, j = F(k.reduce((I, C) => I + K(f, i, C).value, 0));
1217
+ return /* @__PURE__ */ c("tr", { "data-plan-actual": i ?? "all", children: [
1218
+ /* @__PURE__ */ t("td", { className: D(Ne, "px-2 pb-1 pt-0"), children: /* @__PURE__ */ t(
1142
1219
  "span",
1143
1220
  {
1144
- "data-tip": p,
1221
+ "data-tip": x,
1145
1222
  className: "block text-right text-[10.5px] font-medium text-slate-500 dark:text-slate-400",
1146
1223
  children: n
1147
1224
  }
1148
1225
  ) }),
1149
- C.map((E) => {
1150
- const N = L(g, E), y = F(g, o, E), i = K(E), z = !x && N && Math.abs(y.value - i) >= 5e-3, m = !x && !N && y.value > i + 5e-3;
1226
+ k.map((I) => {
1227
+ const C = L(f, I), q = K(f, i, I), s = E(I), O = !g && C && Math.abs(q.value - s) >= 5e-3, h = !g && !C && q.value > s + 5e-3;
1151
1228
  return /* @__PURE__ */ t(
1152
1229
  "td",
1153
1230
  {
1154
- "data-compare-cell": E,
1155
- className: B("px-2.5 pb-1 pt-0 text-right text-[11.5px]", N && Ce),
1156
- children: Math.abs(y.value) < 5e-3 && !z ? /* @__PURE__ */ t("span", { className: "text-slate-400 dark:text-slate-500", children: "—" }) : /* @__PURE__ */ t(
1157
- La,
1231
+ "data-compare-cell": I,
1232
+ className: D("px-2.5 pb-1 pt-0 text-right text-[11.5px]", C && Se),
1233
+ children: Math.abs(q.value) < 5e-3 && !O ? /* @__PURE__ */ t("span", { className: "text-slate-400 dark:text-slate-500", children: "—" }) : /* @__PURE__ */ t(
1234
+ Aa,
1158
1235
  {
1159
- title: `${Ee(E)} ${g}`,
1160
- compare: R,
1236
+ title: `${je(I)} ${f}`,
1237
+ compare: M,
1161
1238
  actualName: n,
1162
- actual: y.value,
1163
- planned: i,
1164
- closed: N,
1165
- plain: !!x,
1166
- details: y.details,
1167
- tone: z ? "warn" : m ? "danger" : "neutral",
1168
- reconcile: z && k && f ? {
1169
- row: f,
1170
- column: E,
1171
- openColumns: C.filter((M) => !L(g, M)),
1172
- carry: (b == null ? void 0 : b(g, o)) ?? null,
1173
- onApply: (M, P, se) => S(f, M, P, se)
1239
+ actual: q.value,
1240
+ planned: s,
1241
+ closed: C,
1242
+ plain: !!g,
1243
+ details: q.details,
1244
+ tone: O ? "warn" : h ? "danger" : "neutral",
1245
+ reconcile: O && N && p ? {
1246
+ row: p,
1247
+ column: I,
1248
+ openColumns: k.filter((R) => !L(f, R)),
1249
+ carry: (y == null ? void 0 : y(f, i)) ?? null,
1250
+ onApply: (R, T, de) => v(p, R, T, de)
1174
1251
  } : null
1175
1252
  }
1176
1253
  )
1177
1254
  },
1178
- E
1255
+ I
1179
1256
  );
1180
1257
  }),
1181
1258
  /* @__PURE__ */ t(
1182
1259
  "td",
1183
1260
  {
1184
- className: B(
1185
- ke,
1261
+ className: D(
1262
+ we,
1186
1263
  "px-3 pb-1 pt-0 text-right text-[11.5px] text-slate-600 dark:text-slate-300"
1187
1264
  ),
1188
1265
  children: /* @__PURE__ */ t(ne, { n: j, muted: !0 })
@@ -1190,120 +1267,120 @@ function nt(v) {
1190
1267
  )
1191
1268
  ] });
1192
1269
  }
1193
- const Et = {
1270
+ const Kt = {
1194
1271
  warn: "text-amber-700 dark:text-amber-300 font-medium",
1195
1272
  danger: "text-red-700 dark:text-red-300 font-medium",
1196
1273
  neutral: "text-slate-600 dark:text-slate-300"
1197
1274
  };
1198
- function La(v) {
1199
- var V, oe;
1200
- const { title: n, compare: p, actualName: g, actual: o, planned: C, closed: R, plain: K, details: F, tone: L, reconcile: f } = v, [k, S] = H(!1), [b, x] = H("next"), [j, E] = H(""), N = Pt(p), y = T(C - o), i = f && f.openColumns.length === 0 && f.carry && !f.carry.blocked ? f.carry : null, z = f && f.openColumns.length === 0 ? ((V = f.carry) == null ? void 0 : V.blocked) ?? null : null, m = i ? ((oe = i.row) == null ? void 0 : oe.values) ?? {} : (f == null ? void 0 : f.row.values) ?? {}, M = i ? i.openColumns : (f == null ? void 0 : f.openColumns) ?? [], P = G(
1275
+ function Aa(b) {
1276
+ var V, ce;
1277
+ const { title: n, compare: x, actualName: f, actual: i, planned: k, closed: M, plain: E, details: K, tone: L, reconcile: p } = b, [N, v] = W(!1), [y, g] = W("next"), [j, I] = W(""), C = It(x), q = F(k - i), s = p && p.openColumns.length === 0 && p.carry && !p.carry.blocked ? p.carry : null, O = p && p.openColumns.length === 0 ? ((V = p.carry) == null ? void 0 : V.blocked) ?? null : null, h = s ? ((ce = s.row) == null ? void 0 : ce.values) ?? {} : (p == null ? void 0 : p.row.values) ?? {}, R = s ? s.openColumns : (p == null ? void 0 : p.openColumns) ?? [], T = Z(
1201
1278
  () => {
1202
1279
  var w;
1203
- return f ? _a({
1204
- row: f.row.values,
1205
- column: f.column,
1206
- actual: o,
1207
- openColumns: i ? i.openColumns : f.openColumns,
1208
- mode: b,
1209
- ...i ? { targetRow: ((w = i.row) == null ? void 0 : w.values) ?? {} } : {}
1280
+ return p ? ja({
1281
+ row: p.row.values,
1282
+ column: p.column,
1283
+ actual: i,
1284
+ openColumns: s ? s.openColumns : p.openColumns,
1285
+ mode: y,
1286
+ ...s ? { targetRow: ((w = s.row) == null ? void 0 : w.values) ?? {} } : {}
1210
1287
  }) : null;
1211
1288
  },
1212
- [f, i, o, b]
1213
- ), se = P ? P.targetPatch ?? P.patch : {}, ve = M.some((w) => I(m[w]) > 5e-3), q = G(() => {
1214
- const w = `Reconciled ${n} to ${g.toLowerCase()} (${D(o)})`;
1215
- if (!P || Math.abs(P.moved) < 5e-3) return w;
1216
- const me = `${P.targets.length === 1 ? Ee(P.targets[0]) : `${P.targets.length} open periods`}${i ? ` ${i.key}` : ""}`;
1217
- return P.moved > 0 ? `${w} — moved ${D(P.moved)} to ${me}` : `${w} — took ${D(-P.moved)} from ${me}`;
1218
- }, [n, g, o, P, i]);
1219
- pe(() => {
1220
- k && E(q);
1221
- }, [k, q]);
1222
- const le = f ? [
1289
+ [p, s, i, y]
1290
+ ), de = T ? T.targetPatch ?? T.patch : {}, re = R.some((w) => B(h[w]) > 5e-3), A = Z(() => {
1291
+ const w = `Reconciled ${n} to ${f.toLowerCase()} (${z(i)})`;
1292
+ if (!T || Math.abs(T.moved) < 5e-3) return w;
1293
+ const xe = `${T.targets.length === 1 ? je(T.targets[0]) : `${T.targets.length} open periods`}${s ? ` ${s.key}` : ""}`;
1294
+ return T.moved > 0 ? `${w} — moved ${z(T.moved)} to ${xe}` : `${w} — took ${z(-T.moved)} from ${xe}`;
1295
+ }, [n, f, i, T, s]);
1296
+ ue(() => {
1297
+ N && I(A);
1298
+ }, [N, A]);
1299
+ const le = p ? [
1223
1300
  {
1224
1301
  key: "next",
1225
- label: M[0] ? `Next open period (${st(M[0])}${i ? ` ${i.key}` : ""})` : "Next open period",
1226
- disabled: M.length === 0
1302
+ label: R[0] ? `Next open period (${it(R[0])}${s ? ` ${s.key}` : ""})` : "Next open period",
1303
+ disabled: R.length === 0
1227
1304
  },
1228
1305
  {
1229
1306
  key: "even",
1230
- label: i ? `Evenly over ${i.key}'s open periods` : "Evenly over every open period",
1231
- disabled: M.length === 0
1307
+ label: s ? `Evenly over ${s.key}'s open periods` : "Evenly over every open period",
1308
+ disabled: R.length === 0
1232
1309
  },
1233
1310
  {
1234
1311
  key: "weighted",
1235
- label: i ? `In proportion to the ${N.toLowerCase()} already in ${i.key}` : `In proportion to the ${N.toLowerCase()} already there`,
1236
- disabled: !ve
1312
+ label: s ? `In proportion to the ${C.toLowerCase()} already in ${s.key}` : `In proportion to the ${C.toLowerCase()} already there`,
1313
+ disabled: !re
1237
1314
  },
1238
1315
  { key: "none", label: "Nowhere — drop it from the plan" }
1239
1316
  ] : [];
1240
- return /* @__PURE__ */ d(it, { open: k, onOpenChange: S, children: [
1241
- /* @__PURE__ */ t(dt, { asChild: !0, children: /* @__PURE__ */ t(
1317
+ return /* @__PURE__ */ c(ut, { open: N, onOpenChange: v, children: [
1318
+ /* @__PURE__ */ t(pt, { asChild: !0, children: /* @__PURE__ */ t(
1242
1319
  "button",
1243
1320
  {
1244
1321
  type: "button",
1245
1322
  "data-compare-details": !0,
1246
1323
  "data-tip": "",
1247
1324
  "data-plan-off": L === "warn" ? "true" : void 0,
1248
- className: B(
1325
+ className: D(
1249
1326
  "rounded px-0.5 underline-offset-2 hover:underline focus-visible:underline",
1250
- Et[L]
1327
+ Kt[L]
1251
1328
  ),
1252
- children: D(o)
1329
+ children: z(i)
1253
1330
  }
1254
1331
  ) }),
1255
- /* @__PURE__ */ d(ct, { align: "end", sideOffset: 6, className: "w-[360px] p-0 text-[12px]", children: [
1256
- /* @__PURE__ */ d("div", { className: "border-b border-slate-200 px-3 py-2 dark:border-border", children: [
1332
+ /* @__PURE__ */ c(mt, { align: "end", sideOffset: 6, className: "w-[360px] p-0 text-[12px]", children: [
1333
+ /* @__PURE__ */ c("div", { className: "border-b border-slate-200 px-3 py-2 dark:border-border", children: [
1257
1334
  /* @__PURE__ */ t("p", { className: "text-[12.5px] font-semibold text-slate-900 dark:text-slate-100", children: n }),
1258
- /* @__PURE__ */ d("dl", { className: "mt-1 grid grid-cols-3 gap-2 tabular-nums", children: [
1259
- !K && /* @__PURE__ */ d("div", { children: [
1260
- /* @__PURE__ */ t("dt", { className: "text-[10.5px] text-slate-500 dark:text-slate-400", children: N }),
1261
- /* @__PURE__ */ t("dd", { className: "font-medium text-slate-800 dark:text-slate-100", children: D(C) })
1335
+ /* @__PURE__ */ c("dl", { className: "mt-1 grid grid-cols-3 gap-2 tabular-nums", children: [
1336
+ !E && /* @__PURE__ */ c("div", { children: [
1337
+ /* @__PURE__ */ t("dt", { className: "text-[10.5px] text-slate-500 dark:text-slate-400", children: C }),
1338
+ /* @__PURE__ */ t("dd", { className: "font-medium text-slate-800 dark:text-slate-100", children: z(k) })
1262
1339
  ] }),
1263
- /* @__PURE__ */ d("div", { children: [
1264
- /* @__PURE__ */ t("dt", { className: "text-[10.5px] text-slate-500 dark:text-slate-400", children: g }),
1265
- /* @__PURE__ */ t("dd", { className: "font-medium text-slate-800 dark:text-slate-100", children: D(o) })
1340
+ /* @__PURE__ */ c("div", { children: [
1341
+ /* @__PURE__ */ t("dt", { className: "text-[10.5px] text-slate-500 dark:text-slate-400", children: f }),
1342
+ /* @__PURE__ */ t("dd", { className: "font-medium text-slate-800 dark:text-slate-100", children: z(i) })
1266
1343
  ] }),
1267
- !K && /* @__PURE__ */ d("div", { children: [
1268
- /* @__PURE__ */ t("dt", { className: "text-[10.5px] text-slate-500 dark:text-slate-400", children: R ? "Difference" : "Still to come" }),
1344
+ !E && /* @__PURE__ */ c("div", { children: [
1345
+ /* @__PURE__ */ t("dt", { className: "text-[10.5px] text-slate-500 dark:text-slate-400", children: M ? "Difference" : "Still to come" }),
1269
1346
  /* @__PURE__ */ t(
1270
1347
  "dd",
1271
1348
  {
1272
- className: B(
1349
+ className: D(
1273
1350
  "font-medium",
1274
- Math.abs(y) < 5e-3 ? "text-slate-800 dark:text-slate-100" : Et[L === "neutral" ? "neutral" : L]
1351
+ Math.abs(q) < 5e-3 ? "text-slate-800 dark:text-slate-100" : Kt[L === "neutral" ? "neutral" : L]
1275
1352
  ),
1276
- children: D(y)
1353
+ children: z(q)
1277
1354
  }
1278
1355
  )
1279
1356
  ] })
1280
1357
  ] })
1281
1358
  ] }),
1282
- F.length > 0 && /* @__PURE__ */ t("ul", { className: "max-h-[168px] overflow-y-auto px-3 py-1.5", children: F.map((w) => /* @__PURE__ */ d("li", { className: "flex items-baseline gap-2 py-0.5", children: [
1283
- /* @__PURE__ */ d("span", { className: "min-w-0 flex-1 truncate text-slate-700 dark:text-slate-200", children: [
1359
+ K.length > 0 && /* @__PURE__ */ t("ul", { className: "max-h-[168px] overflow-y-auto px-3 py-1.5", children: K.map((w) => /* @__PURE__ */ c("li", { className: "flex items-baseline gap-2 py-0.5", children: [
1360
+ /* @__PURE__ */ c("span", { className: "min-w-0 flex-1 truncate text-slate-700 dark:text-slate-200", children: [
1284
1361
  w.label,
1285
1362
  w.sub ? /* @__PURE__ */ t("span", { className: "text-slate-500 dark:text-slate-400", children: ` · ${w.sub}` }) : null
1286
1363
  ] }),
1287
- /* @__PURE__ */ t("span", { className: "tabular-nums text-slate-800 dark:text-slate-100", children: D(w.amount) })
1364
+ /* @__PURE__ */ t("span", { className: "tabular-nums text-slate-800 dark:text-slate-100", children: z(w.amount) })
1288
1365
  ] }, String(w.id))) }),
1289
- F.length === 0 && /* @__PURE__ */ t("p", { className: "px-3 py-2 text-slate-500 dark:text-slate-400", children: `No ${ka(p, 2)} behind this figure.` }),
1290
- f && P && /* @__PURE__ */ d(
1366
+ K.length === 0 && /* @__PURE__ */ t("p", { className: "px-3 py-2 text-slate-500 dark:text-slate-400", children: `No ${_a(x, 2)} behind this figure.` }),
1367
+ p && T && /* @__PURE__ */ c(
1291
1368
  "div",
1292
1369
  {
1293
1370
  className: "border-t border-slate-200 px-3 py-2 dark:border-border",
1294
1371
  "data-plan-reconcile": !0,
1295
1372
  children: [
1296
- /* @__PURE__ */ t("p", { className: "font-medium text-slate-900 dark:text-slate-100", children: `Set the ${N.toLowerCase()} to ${D(o)} and put the ${D(Math.abs(y))} ${y > 0 ? "left over" : "shortfall"}…` }),
1373
+ /* @__PURE__ */ t("p", { className: "font-medium text-slate-900 dark:text-slate-100", children: `Set the ${C.toLowerCase()} to ${z(i)} and put the ${z(Math.abs(q))} ${q > 0 ? "left over" : "shortfall"}…` }),
1297
1374
  /* @__PURE__ */ t(
1298
1375
  "div",
1299
1376
  {
1300
1377
  className: "mt-1.5 space-y-1",
1301
1378
  role: "radiogroup",
1302
1379
  "aria-label": "Where the difference goes",
1303
- children: le.map((w) => /* @__PURE__ */ d(
1380
+ children: le.map((w) => /* @__PURE__ */ c(
1304
1381
  "label",
1305
1382
  {
1306
- className: B(
1383
+ className: D(
1307
1384
  "flex cursor-pointer items-center gap-2",
1308
1385
  w.disabled && "cursor-not-allowed opacity-50"
1309
1386
  ),
@@ -1315,8 +1392,8 @@ function La(v) {
1315
1392
  name: "pg-reconcile",
1316
1393
  "data-plan-reconcile-mode": w.key,
1317
1394
  disabled: w.disabled,
1318
- checked: b === w.key,
1319
- onChange: () => x(w.key),
1395
+ checked: y === w.key,
1396
+ onChange: () => g(w.key),
1320
1397
  className: "accent-[rgb(var(--nvr-cyan-rgb))]"
1321
1398
  }
1322
1399
  ),
@@ -1327,41 +1404,41 @@ function La(v) {
1327
1404
  ))
1328
1405
  }
1329
1406
  ),
1330
- i && b !== "none" && /* @__PURE__ */ t(
1407
+ s && y !== "none" && /* @__PURE__ */ t(
1331
1408
  "p",
1332
1409
  {
1333
1410
  className: "mt-1.5 text-[11.5px] text-slate-600 dark:text-slate-300",
1334
- "data-plan-reconcile-carry": i.key,
1335
- children: i.row ? `Every period of this row is closed, so it goes to ${i.key}.` : `Every period of this row is closed and ${i.key} has no row for this line — one is added, and shows as pending until you save.`
1411
+ "data-plan-reconcile-carry": s.key,
1412
+ children: s.row ? `Every period of this row is closed, so it goes to ${s.key}.` : `Every period of this row is closed and ${s.key} has no row for this line — one is added, and shows as pending until you save.`
1336
1413
  }
1337
1414
  ),
1338
- z && /* @__PURE__ */ t(
1415
+ O && /* @__PURE__ */ t(
1339
1416
  "p",
1340
1417
  {
1341
1418
  className: "mt-1.5 text-[11.5px] text-amber-700 dark:text-amber-300",
1342
1419
  "data-plan-reconcile-blocked": !0,
1343
- children: `Every period of this row is closed, and ${z} — the difference can only be dropped from here.`
1420
+ children: `Every period of this row is closed, and ${O} — the difference can only be dropped from here.`
1344
1421
  }
1345
1422
  ),
1346
- P.targets.length > 0 && /* @__PURE__ */ d(
1423
+ T.targets.length > 0 && /* @__PURE__ */ c(
1347
1424
  "p",
1348
1425
  {
1349
1426
  className: "mt-1.5 text-[11.5px] tabular-nums text-slate-600 dark:text-slate-300",
1350
1427
  "data-plan-reconcile-preview": !0,
1351
1428
  children: [
1352
- P.targets.slice(0, 6).map(
1353
- (w) => `${st(w)}${i ? ` ${i.key}` : ""} ${D(I(m[w]))} → ${D(se[w])}`
1429
+ T.targets.slice(0, 6).map(
1430
+ (w) => `${it(w)}${s ? ` ${s.key}` : ""} ${z(B(h[w]))} → ${z(de[w])}`
1354
1431
  ).join(" · "),
1355
- P.targets.length > 6 ? ` · +${P.targets.length - 6} more` : ""
1432
+ T.targets.length > 6 ? ` · +${T.targets.length - 6} more` : ""
1356
1433
  ]
1357
1434
  }
1358
1435
  ),
1359
- b !== "none" && Math.abs(P.unabsorbed) >= 5e-3 && /* @__PURE__ */ t("p", { className: "mt-1 text-[11.5px] text-amber-700 dark:text-amber-300", children: `${D(Math.abs(P.unabsorbed))} has nowhere to go — it leaves the ${N.toLowerCase()}.` }),
1436
+ y !== "none" && Math.abs(T.unabsorbed) >= 5e-3 && /* @__PURE__ */ t("p", { className: "mt-1 text-[11.5px] text-amber-700 dark:text-amber-300", children: `${z(Math.abs(T.unabsorbed))} has nowhere to go — it leaves the ${C.toLowerCase()}.` }),
1360
1437
  /* @__PURE__ */ t(
1361
1438
  "textarea",
1362
1439
  {
1363
1440
  value: j,
1364
- onChange: (w) => E(w.target.value),
1441
+ onChange: (w) => I(w.target.value),
1365
1442
  rows: 2,
1366
1443
  "aria-label": "Reason",
1367
1444
  className: "mt-2 w-full resize-none rounded-md border border-slate-200 bg-background px-2 py-1 text-[12px] text-slate-800 outline-none focus:border-slate-400 dark:border-border dark:text-slate-100"
@@ -1373,10 +1450,10 @@ function La(v) {
1373
1450
  type: "button",
1374
1451
  "data-plan-reconcile-apply": !0,
1375
1452
  onClick: () => {
1376
- const w = i && P.targetPatch && Object.keys(P.targetPatch).length > 0 ? { target: i, patch: P.targetPatch } : void 0;
1377
- f.onApply(P.patch, j.trim() || q, w) && (de.success(
1378
- w ? `Reconcile staged across ${n.split(" ").pop()} and ${i == null ? void 0 : i.key} — Save to keep it` : "Reconcile staged — Save to keep it"
1379
- ), S(!1));
1453
+ const w = s && T.targetPatch && Object.keys(T.targetPatch).length > 0 ? { target: s, patch: T.targetPatch } : void 0;
1454
+ p.onApply(T.patch, j.trim() || A, w) && (ie.success(
1455
+ w ? `Reconcile staged across ${n.split(" ").pop()} and ${s == null ? void 0 : s.key} — Save to keep it` : "Reconcile staged — Save to keep it"
1456
+ ), v(!1));
1380
1457
  },
1381
1458
  className: "rounded-md bg-nvr-cyan px-3 py-1 text-[12px] font-medium text-white",
1382
1459
  children: "Stage it"
@@ -1388,144 +1465,144 @@ function La(v) {
1388
1465
  ] })
1389
1466
  ] });
1390
1467
  }
1391
- function Ra(v) {
1468
+ function Fa(b) {
1392
1469
  const {
1393
1470
  block: n,
1394
- config: p,
1395
- canSplit: g,
1396
- splitUnavailable: o,
1397
- splitBase: C,
1398
- client: R,
1399
- cols: K,
1400
- catLabel: F,
1471
+ config: x,
1472
+ canSplit: f,
1473
+ splitUnavailable: i,
1474
+ splitBase: k,
1475
+ client: M,
1476
+ cols: E,
1477
+ catLabel: K,
1401
1478
  showHistory: L,
1402
- onHistory: f,
1403
- onSpread: k,
1404
- onRemove: S,
1405
- onDone: b,
1406
- rc: x
1407
- } = v, [j, E] = H(!1), [N, y] = H("menu");
1408
- pe(() => {
1409
- j && y("menu");
1479
+ onHistory: p,
1480
+ onSpread: N,
1481
+ onRemove: v,
1482
+ onDone: y,
1483
+ rc: g
1484
+ } = b, [j, I] = W(!1), [C, q] = W("menu");
1485
+ ue(() => {
1486
+ j && q("menu");
1410
1487
  }, [j]);
1411
- const i = [...n.top ? [n.top] : [], ...n.cats], z = i.some((M) => M.edited || M.isNew), m = "flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-[12.5px] text-slate-700 hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50 dark:text-slate-200";
1412
- return /* @__PURE__ */ d(it, { open: j, onOpenChange: E, children: [
1413
- /* @__PURE__ */ t(dt, { asChild: !0, children: /* @__PURE__ */ t(
1488
+ const s = [...n.top ? [n.top] : [], ...n.cats], O = s.some((R) => R.edited || R.isNew), h = "flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-[12.5px] text-slate-700 hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50 dark:text-slate-200";
1489
+ return /* @__PURE__ */ c(ut, { open: j, onOpenChange: I, children: [
1490
+ /* @__PURE__ */ t(pt, { asChild: !0, children: /* @__PURE__ */ t(
1414
1491
  "button",
1415
1492
  {
1416
1493
  type: "button",
1417
1494
  "data-plan-menu": n.key,
1418
1495
  "aria-label": `Actions for ${n.key}`,
1419
1496
  className: "rounded p-0.5 text-slate-500 hover:bg-muted hover:text-slate-800 dark:hover:text-slate-100",
1420
- children: /* @__PURE__ */ t(aa, { className: "h-3.5 w-3.5" })
1497
+ children: /* @__PURE__ */ t(ia, { className: "h-3.5 w-3.5" })
1421
1498
  }
1422
1499
  ) }),
1423
- /* @__PURE__ */ d(
1424
- ct,
1500
+ /* @__PURE__ */ c(
1501
+ mt,
1425
1502
  {
1426
1503
  align: "start",
1427
1504
  sideOffset: 6,
1428
- className: B("p-1.5", N === "split" ? "w-[440px]" : "w-[300px]"),
1505
+ className: D("p-1.5", C === "split" ? "w-[440px]" : "w-[300px]"),
1429
1506
  children: [
1430
- N === "menu" && /* @__PURE__ */ d("div", { children: [
1431
- n.mode === "top" && g && /* @__PURE__ */ d(
1507
+ C === "menu" && /* @__PURE__ */ c("div", { children: [
1508
+ n.mode === "top" && f && /* @__PURE__ */ c(
1432
1509
  "button",
1433
1510
  {
1434
1511
  type: "button",
1435
1512
  "data-plan-split": n.key,
1436
- disabled: z,
1437
- onClick: () => y("split"),
1438
- className: m,
1513
+ disabled: O,
1514
+ onClick: () => q("split"),
1515
+ className: h,
1439
1516
  children: [
1440
- /* @__PURE__ */ t(St, { className: "h-3.5 w-3.5" }),
1441
- p.split_label ?? "Plan by category"
1517
+ /* @__PURE__ */ t(Et, { className: "h-3.5 w-3.5" }),
1518
+ x.split_label ?? "Plan by category"
1442
1519
  ]
1443
1520
  }
1444
1521
  ),
1445
- n.mode === "top" && !g && o && /* @__PURE__ */ d("div", { "data-plan-split-unavailable": !0, className: "px-2 py-1.5", children: [
1446
- /* @__PURE__ */ d("p", { className: "flex items-center gap-2 text-[12.5px] text-slate-400 dark:text-slate-500", children: [
1447
- /* @__PURE__ */ t(St, { className: "h-3.5 w-3.5" }),
1448
- p.split_label ?? "Plan by category"
1522
+ n.mode === "top" && !f && i && /* @__PURE__ */ c("div", { "data-plan-split-unavailable": !0, className: "px-2 py-1.5", children: [
1523
+ /* @__PURE__ */ c("p", { className: "flex items-center gap-2 text-[12.5px] text-slate-400 dark:text-slate-500", children: [
1524
+ /* @__PURE__ */ t(Et, { className: "h-3.5 w-3.5" }),
1525
+ x.split_label ?? "Plan by category"
1449
1526
  ] }),
1450
- /* @__PURE__ */ t("p", { className: "mt-0.5 pl-[22px] text-[11px] text-slate-500 dark:text-slate-400", children: o })
1527
+ /* @__PURE__ */ t("p", { className: "mt-0.5 pl-[22px] text-[11px] text-slate-500 dark:text-slate-400", children: i })
1451
1528
  ] }),
1452
- n.mode === "split" && C && /* @__PURE__ */ d(
1529
+ n.mode === "split" && k && /* @__PURE__ */ c(
1453
1530
  "button",
1454
1531
  {
1455
1532
  type: "button",
1456
1533
  "data-plan-merge": n.key,
1457
- disabled: z,
1458
- onClick: () => y("merge"),
1459
- className: m,
1534
+ disabled: O,
1535
+ onClick: () => q("merge"),
1536
+ className: h,
1460
1537
  children: [
1461
- /* @__PURE__ */ t(la, { className: "h-3.5 w-3.5" }),
1462
- p.merge_label ?? "Merge back to one line"
1538
+ /* @__PURE__ */ t(da, { className: "h-3.5 w-3.5" }),
1539
+ x.merge_label ?? "Merge back to one line"
1463
1540
  ]
1464
1541
  }
1465
1542
  ),
1466
- z && (n.mode === "split" || g) && /* @__PURE__ */ t("p", { className: "px-2 pb-1 text-[11px] text-slate-500 dark:text-slate-400", children: "Save your changes to this block first." }),
1467
- k && i.map((M) => /* @__PURE__ */ d(
1543
+ O && (n.mode === "split" || f) && /* @__PURE__ */ t("p", { className: "px-2 pb-1 text-[11px] text-slate-500 dark:text-slate-400", children: "Save your changes to this block first." }),
1544
+ N && s.map((R) => /* @__PURE__ */ c(
1468
1545
  "button",
1469
1546
  {
1470
1547
  type: "button",
1471
- "data-plan-spread": M.uid,
1548
+ "data-plan-spread": R.uid,
1472
1549
  onClick: () => {
1473
- k(M), E(!1);
1550
+ N(R), I(!1);
1474
1551
  },
1475
- className: m,
1552
+ className: h,
1476
1553
  children: [
1477
1554
  /* @__PURE__ */ t("span", { className: "w-3.5" }),
1478
- `Spread what is left${M.cat ? ` · ${F(M.cat)}` : ""}`
1555
+ `Spread what is left${R.cat ? ` · ${K(R.cat)}` : ""}`
1479
1556
  ]
1480
1557
  },
1481
- M.uid
1558
+ R.uid
1482
1559
  )),
1483
- L && i.filter((M) => M.id).map((M) => /* @__PURE__ */ d("div", { className: "flex items-center", children: [
1484
- /* @__PURE__ */ d(
1560
+ L && s.filter((R) => R.id).map((R) => /* @__PURE__ */ c("div", { className: "flex items-center", children: [
1561
+ /* @__PURE__ */ c(
1485
1562
  "button",
1486
1563
  {
1487
1564
  type: "button",
1488
1565
  onClick: () => {
1489
- f(M), E(!1);
1566
+ p(R), I(!1);
1490
1567
  },
1491
- className: m,
1568
+ className: h,
1492
1569
  children: [
1493
- /* @__PURE__ */ t(na, { className: "h-3.5 w-3.5" }),
1494
- `History${M.cat ? ` · ${F(M.cat)}` : ""}`
1570
+ /* @__PURE__ */ t(ca, { className: "h-3.5 w-3.5" }),
1571
+ `History${R.cat ? ` · ${K(R.cat)}` : ""}`
1495
1572
  ]
1496
1573
  }
1497
1574
  ),
1498
1575
  /* @__PURE__ */ t(
1499
- Ca,
1576
+ Ea,
1500
1577
  {
1501
- collection: x,
1502
- rowId: M.id,
1503
- rowLabel: `${n.key}${M.cat ? ` ${F(M.cat)}` : ""}`
1578
+ collection: g,
1579
+ rowId: R.id,
1580
+ rowLabel: `${n.key}${R.cat ? ` ${K(R.cat)}` : ""}`
1504
1581
  }
1505
1582
  )
1506
- ] }, M.uid)),
1507
- /* @__PURE__ */ d(
1583
+ ] }, R.uid)),
1584
+ /* @__PURE__ */ c(
1508
1585
  "button",
1509
1586
  {
1510
1587
  type: "button",
1511
1588
  "data-plan-remove": n.key,
1512
- onClick: () => y("remove"),
1513
- className: B(m, "text-red-700 dark:text-red-300"),
1589
+ onClick: () => q("remove"),
1590
+ className: D(h, "text-red-700 dark:text-red-300"),
1514
1591
  children: [
1515
- /* @__PURE__ */ t(ra, { className: "h-3.5 w-3.5" }),
1592
+ /* @__PURE__ */ t(ua, { className: "h-3.5 w-3.5" }),
1516
1593
  `Remove ${n.key}`
1517
1594
  ]
1518
1595
  }
1519
1596
  )
1520
1597
  ] }),
1521
- N === "remove" && /* @__PURE__ */ d("div", { className: "p-1.5", children: [
1598
+ C === "remove" && /* @__PURE__ */ c("div", { className: "p-1.5", children: [
1522
1599
  /* @__PURE__ */ t("p", { className: "text-[12.5px] text-slate-700 dark:text-slate-200", children: `Remove the ${n.key} plan? It leaves with the next Save.` }),
1523
- /* @__PURE__ */ d("div", { className: "mt-2 flex justify-end gap-2", children: [
1600
+ /* @__PURE__ */ c("div", { className: "mt-2 flex justify-end gap-2", children: [
1524
1601
  /* @__PURE__ */ t(
1525
1602
  "button",
1526
1603
  {
1527
1604
  type: "button",
1528
- onClick: () => y("menu"),
1605
+ onClick: () => q("menu"),
1529
1606
  className: "rounded-md px-2.5 py-1 text-[12px] text-slate-600 hover:bg-muted dark:text-slate-300",
1530
1607
  children: "Keep it"
1531
1608
  }
@@ -1536,7 +1613,7 @@ function Ra(v) {
1536
1613
  type: "button",
1537
1614
  "data-plan-remove-confirm": !0,
1538
1615
  onClick: () => {
1539
- S(), E(!1);
1616
+ v(), I(!1);
1540
1617
  },
1541
1618
  className: "rounded-md bg-red-600 px-2.5 py-1 text-[12px] font-medium text-white",
1542
1619
  children: "Remove"
@@ -1544,30 +1621,30 @@ function Ra(v) {
1544
1621
  )
1545
1622
  ] })
1546
1623
  ] }),
1547
- N === "split" && C && n.top && /* @__PURE__ */ t(
1548
- Ma,
1624
+ C === "split" && k && n.top && /* @__PURE__ */ t(
1625
+ Ka,
1549
1626
  {
1550
1627
  block: n,
1551
- config: p,
1552
- splitBase: C,
1553
- client: R,
1554
- cols: K,
1555
- onCancel: () => y("menu"),
1628
+ config: x,
1629
+ splitBase: k,
1630
+ client: M,
1631
+ cols: E,
1632
+ onCancel: () => q("menu"),
1556
1633
  onDone: () => {
1557
- E(!1), b();
1634
+ I(!1), y();
1558
1635
  }
1559
1636
  }
1560
1637
  ),
1561
- N === "merge" && C && /* @__PURE__ */ t(
1562
- Ta,
1638
+ C === "merge" && k && /* @__PURE__ */ t(
1639
+ Ia,
1563
1640
  {
1564
1641
  block: n,
1565
- config: p,
1566
- splitBase: C,
1567
- client: R,
1568
- onCancel: () => y("menu"),
1642
+ config: x,
1643
+ splitBase: k,
1644
+ client: M,
1645
+ onCancel: () => q("menu"),
1569
1646
  onDone: () => {
1570
- E(!1), b();
1647
+ I(!1), y();
1571
1648
  }
1572
1649
  }
1573
1650
  )
@@ -1576,146 +1653,146 @@ function Ra(v) {
1576
1653
  )
1577
1654
  ] });
1578
1655
  }
1579
- function ot(v) {
1580
- return ua(v, "Something went wrong");
1656
+ function dt(b) {
1657
+ return ga(b, "Something went wrong");
1581
1658
  }
1582
- function Ma(v) {
1583
- var se, ve;
1584
- const { block: n, config: p, splitBase: g, client: o, cols: C, onCancel: R, onDone: K } = v, F = Number.isFinite(Number(n.key)) ? Number(n.key) : n.key, [L, f] = H(null), [k, S] = H(null), [b, x] = H(null), [j, E] = H(!1), [N, y] = H(""), i = JSON.stringify(L);
1585
- pe(() => {
1586
- let q = !0;
1659
+ function Ka(b) {
1660
+ var de, re;
1661
+ const { block: n, config: x, splitBase: f, client: i, cols: k, onCancel: M, onDone: E } = b, K = Number.isFinite(Number(n.key)) ? Number(n.key) : n.key, [L, p] = W(null), [N, v] = W(null), [y, g] = W(null), [j, I] = W(!1), [C, q] = W(""), s = JSON.stringify(L);
1662
+ ue(() => {
1663
+ let A = !0;
1587
1664
  const le = window.setTimeout(
1588
1665
  () => {
1589
- o.request(
1590
- rt(`${g}/split`, {
1591
- [p.key_field]: F,
1666
+ i.request(
1667
+ ot(`${f}/split`, {
1668
+ [x.key_field]: K,
1592
1669
  preview: !0,
1593
1670
  ...L ? { shares: L } : {}
1594
1671
  })
1595
1672
  ).then((V) => {
1596
- q && (S(V.data), x(null), L || f(
1673
+ A && (v(V.data), g(null), L || p(
1597
1674
  Object.fromEntries(
1598
- V.data.categories.map((oe) => [String(oe.id), Math.round(oe.share * 1e3) / 10])
1675
+ V.data.categories.map((ce) => [String(ce.id), Math.round(ce.share * 1e3) / 10])
1599
1676
  )
1600
1677
  ));
1601
- }).catch((V) => q && x(ot(V)));
1678
+ }).catch((V) => A && g(dt(V)));
1602
1679
  },
1603
1680
  L ? 250 : 0
1604
1681
  );
1605
1682
  return () => {
1606
- q = !1, window.clearTimeout(le);
1683
+ A = !1, window.clearTimeout(le);
1607
1684
  };
1608
- }, [i, g]);
1609
- const z = (k == null ? void 0 : k.categories.map((q) => q.label).join(" / ")) ?? "", m = `Split the ${n.key} plan into ${z}`, M = async () => {
1610
- E(!0);
1685
+ }, [s, f]);
1686
+ const O = (N == null ? void 0 : N.categories.map((A) => A.label).join(" / ")) ?? "", h = `Split the ${n.key} plan into ${O}`, R = async () => {
1687
+ I(!0);
1611
1688
  try {
1612
- await o.request(
1613
- rt(`${g}/split`, {
1614
- [p.key_field]: F,
1689
+ await i.request(
1690
+ ot(`${f}/split`, {
1691
+ [x.key_field]: K,
1615
1692
  shares: L ?? void 0,
1616
- reason: N.trim() || m
1693
+ reason: C.trim() || h
1617
1694
  })
1618
- ), de.success(`${n.key} is now planned by ${z}`), K();
1619
- } catch (q) {
1620
- x(ot(q));
1695
+ ), ie.success(`${n.key} is now planned by ${O}`), E();
1696
+ } catch (A) {
1697
+ g(dt(A));
1621
1698
  } finally {
1622
- E(!1);
1699
+ I(!1);
1623
1700
  }
1624
- }, P = (q) => T(C.reduce((le, V) => le + I(q[V]), 0));
1625
- return /* @__PURE__ */ d("div", { className: "p-1.5", "data-plan-split-pane": !0, children: [
1626
- /* @__PURE__ */ t("p", { className: "text-[12.5px] font-semibold text-slate-900 dark:text-slate-100", children: `${p.split_label ?? "Plan by category"} · ${n.key}` }),
1701
+ }, T = (A) => F(k.reduce((le, V) => le + B(A[V]), 0));
1702
+ return /* @__PURE__ */ c("div", { className: "p-1.5", "data-plan-split-pane": !0, children: [
1703
+ /* @__PURE__ */ t("p", { className: "text-[12.5px] font-semibold text-slate-900 dark:text-slate-100", children: `${x.split_label ?? "Plan by category"} · ${n.key}` }),
1627
1704
  /* @__PURE__ */ t("p", { className: "mt-0.5 text-[11.5px] text-slate-600 dark:text-slate-300", children: "Every period is divided by these shares. Closed periods keep their totals; open ones can be changed in the grid afterwards." }),
1628
- !k && !b && /* @__PURE__ */ t(
1705
+ !N && !y && /* @__PURE__ */ t(
1629
1706
  "div",
1630
1707
  {
1631
1708
  className: "mt-2 h-16 animate-pulse rounded",
1632
1709
  style: { background: "hsl(var(--nvr-skeleton))" }
1633
1710
  }
1634
1711
  ),
1635
- k && (((se = k.share_sets) == null ? void 0 : se.length) ?? 0) > 1 && /* @__PURE__ */ d("div", { className: "mt-2 flex flex-wrap items-center gap-1", "data-plan-share-sets": !0, children: [
1712
+ N && (((de = N.share_sets) == null ? void 0 : de.length) ?? 0) > 1 && /* @__PURE__ */ c("div", { className: "mt-2 flex flex-wrap items-center gap-1", "data-plan-share-sets": !0, children: [
1636
1713
  /* @__PURE__ */ t("span", { className: "text-[11px] text-slate-500 dark:text-slate-400", children: "Shares from" }),
1637
- (ve = k.share_sets) == null ? void 0 : ve.map((q) => {
1714
+ (re = N.share_sets) == null ? void 0 : re.map((A) => {
1638
1715
  const le = Object.fromEntries(
1639
- Object.entries(q.shares).map(([oe, w]) => [oe, Math.round(w * 1e3) / 10])
1640
- ), V = JSON.stringify(le) === i;
1716
+ Object.entries(A.shares).map(([ce, w]) => [ce, Math.round(w * 1e3) / 10])
1717
+ ), V = JSON.stringify(le) === s;
1641
1718
  return /* @__PURE__ */ t(
1642
1719
  "button",
1643
1720
  {
1644
1721
  type: "button",
1645
- "data-plan-share-set": q.key,
1722
+ "data-plan-share-set": A.key,
1646
1723
  "aria-pressed": V,
1647
- "data-tip": q.hint ?? "",
1648
- onClick: () => f(le),
1724
+ "data-tip": A.hint ?? "",
1725
+ onClick: () => p(le),
1649
1726
  className: `h-6 rounded-md border px-1.5 text-[11px] font-medium ${V ? "border-transparent bg-nvr-cyan text-white" : "border-slate-200 text-slate-600 hover:bg-muted dark:border-border dark:text-slate-300"}`,
1650
- children: q.label
1727
+ children: A.label
1651
1728
  },
1652
- q.key
1729
+ A.key
1653
1730
  );
1654
1731
  })
1655
1732
  ] }),
1656
- k && /* @__PURE__ */ d("table", { className: "mt-2 w-full text-[12px] tabular-nums", children: [
1657
- /* @__PURE__ */ t("thead", { children: /* @__PURE__ */ d("tr", { className: "text-left text-[10.5px] text-slate-500 dark:text-slate-400", children: [
1733
+ N && /* @__PURE__ */ c("table", { className: "mt-2 w-full text-[12px] tabular-nums", children: [
1734
+ /* @__PURE__ */ t("thead", { children: /* @__PURE__ */ c("tr", { className: "text-left text-[10.5px] text-slate-500 dark:text-slate-400", children: [
1658
1735
  /* @__PURE__ */ t("th", { className: "py-1 font-medium", children: "Category" }),
1659
1736
  /* @__PURE__ */ t("th", { className: "py-1 text-right font-medium", children: "Share" }),
1660
1737
  /* @__PURE__ */ t("th", { className: "py-1 text-right font-medium", children: `${n.key} plan` }),
1661
1738
  /* @__PURE__ */ t("th", { className: "py-1 text-right font-medium", children: "Ceiling" })
1662
1739
  ] }) }),
1663
- /* @__PURE__ */ d("tbody", { children: [
1664
- k.categories.map((q) => /* @__PURE__ */ d("tr", { className: "border-t border-slate-100 dark:border-border", children: [
1665
- /* @__PURE__ */ t("td", { className: "py-1 text-slate-800 dark:text-slate-100", children: q.label }),
1666
- /* @__PURE__ */ d("td", { className: "py-1 text-right", children: [
1740
+ /* @__PURE__ */ c("tbody", { children: [
1741
+ N.categories.map((A) => /* @__PURE__ */ c("tr", { className: "border-t border-slate-100 dark:border-border", children: [
1742
+ /* @__PURE__ */ t("td", { className: "py-1 text-slate-800 dark:text-slate-100", children: A.label }),
1743
+ /* @__PURE__ */ c("td", { className: "py-1 text-right", children: [
1667
1744
  /* @__PURE__ */ t(
1668
- ma,
1745
+ ka,
1669
1746
  {
1670
1747
  bare: !0,
1671
1748
  type: "text",
1672
1749
  allowNegative: !1,
1673
- "data-plan-share": String(q.id),
1674
- "aria-label": `${q.label} share`,
1675
- value: (L == null ? void 0 : L[String(q.id)]) ?? "",
1676
- onValue: (le) => f((V) => ({ ...V ?? {}, [String(q.id)]: le ?? 0 })),
1750
+ "data-plan-share": String(A.id),
1751
+ "aria-label": `${A.label} share`,
1752
+ value: (L == null ? void 0 : L[String(A.id)]) ?? "",
1753
+ onValue: (le) => p((V) => ({ ...V ?? {}, [String(A.id)]: le ?? 0 })),
1677
1754
  className: "h-6 w-16 rounded border border-slate-200 bg-background px-1.5 text-right text-[12px] outline-none focus:border-slate-400 dark:border-border"
1678
1755
  }
1679
1756
  ),
1680
1757
  /* @__PURE__ */ t("span", { className: "ml-0.5 text-slate-500", children: "%" })
1681
1758
  ] }),
1682
- /* @__PURE__ */ t("td", { className: "py-1 text-right text-slate-800 dark:text-slate-100", children: D(P(q.values)) }),
1683
- /* @__PURE__ */ t("td", { className: "py-1 text-right text-slate-500 dark:text-slate-400", children: D(q.cap) })
1684
- ] }, String(q.id))),
1685
- /* @__PURE__ */ d("tr", { className: "border-t border-slate-200 font-medium dark:border-border", children: [
1686
- /* @__PURE__ */ t("td", { className: "py-1 text-slate-800 dark:text-slate-100", children: p.total_label ?? "Total" }),
1759
+ /* @__PURE__ */ t("td", { className: "py-1 text-right text-slate-800 dark:text-slate-100", children: z(T(A.values)) }),
1760
+ /* @__PURE__ */ t("td", { className: "py-1 text-right text-slate-500 dark:text-slate-400", children: z(A.cap) })
1761
+ ] }, String(A.id))),
1762
+ /* @__PURE__ */ c("tr", { className: "border-t border-slate-200 font-medium dark:border-border", children: [
1763
+ /* @__PURE__ */ t("td", { className: "py-1 text-slate-800 dark:text-slate-100", children: x.total_label ?? "Total" }),
1687
1764
  /* @__PURE__ */ t("td", {}),
1688
- /* @__PURE__ */ t("td", { className: "py-1 text-right text-slate-800 dark:text-slate-100", children: D(P(k.original)) }),
1765
+ /* @__PURE__ */ t("td", { className: "py-1 text-right text-slate-800 dark:text-slate-100", children: z(T(N.original)) }),
1689
1766
  /* @__PURE__ */ t("td", {})
1690
1767
  ] })
1691
1768
  ] })
1692
1769
  ] }),
1693
- (b || (k == null ? void 0 : k.blocked)) && /* @__PURE__ */ t(
1770
+ (y || (N == null ? void 0 : N.blocked)) && /* @__PURE__ */ t(
1694
1771
  "p",
1695
1772
  {
1696
1773
  role: "alert",
1697
1774
  "data-plan-split-blocked": !0,
1698
1775
  className: "mt-1.5 text-[11.5px] font-medium text-red-700 dark:text-red-300",
1699
- children: b ?? (k == null ? void 0 : k.blocked)
1776
+ children: y ?? (N == null ? void 0 : N.blocked)
1700
1777
  }
1701
1778
  ),
1702
1779
  /* @__PURE__ */ t(
1703
1780
  "textarea",
1704
1781
  {
1705
- value: N,
1706
- onChange: (q) => y(q.target.value),
1707
- placeholder: m,
1782
+ value: C,
1783
+ onChange: (A) => q(A.target.value),
1784
+ placeholder: h,
1708
1785
  rows: 2,
1709
1786
  "aria-label": "Reason",
1710
1787
  className: "mt-2 w-full resize-none rounded-md border border-slate-200 bg-background px-2 py-1 text-[12px] text-slate-800 outline-none focus:border-slate-400 dark:border-border dark:text-slate-100"
1711
1788
  }
1712
1789
  ),
1713
- /* @__PURE__ */ d("div", { className: "mt-1.5 flex justify-end gap-2", children: [
1790
+ /* @__PURE__ */ c("div", { className: "mt-1.5 flex justify-end gap-2", children: [
1714
1791
  /* @__PURE__ */ t(
1715
1792
  "button",
1716
1793
  {
1717
1794
  type: "button",
1718
- onClick: R,
1795
+ onClick: M,
1719
1796
  className: "rounded-md px-2.5 py-1 text-[12px] text-slate-600 hover:bg-muted dark:text-slate-300",
1720
1797
  children: "Back"
1721
1798
  }
@@ -1725,8 +1802,8 @@ function Ma(v) {
1725
1802
  {
1726
1803
  type: "button",
1727
1804
  "data-plan-split-apply": !0,
1728
- disabled: j || !k || !!k.blocked,
1729
- onClick: M,
1805
+ disabled: j || !N || !!N.blocked,
1806
+ onClick: R,
1730
1807
  className: "rounded-md bg-nvr-cyan px-3 py-1 text-[12px] font-medium text-white disabled:opacity-50",
1731
1808
  children: j ? "Splitting…" : "Split it"
1732
1809
  }
@@ -1734,29 +1811,29 @@ function Ma(v) {
1734
1811
  ] })
1735
1812
  ] });
1736
1813
  }
1737
- function Ta(v) {
1738
- const { block: n, config: p, splitBase: g, client: o, onCancel: C, onDone: R } = v, K = Number.isFinite(Number(n.key)) ? Number(n.key) : n.key, [F, L] = H(""), [f, k] = H(!1), [S, b] = H(null), x = `Merged the ${n.key} plan back to one line`;
1739
- return /* @__PURE__ */ d("div", { className: "p-1.5", "data-plan-merge-pane": !0, children: [
1740
- /* @__PURE__ */ t("p", { className: "text-[12.5px] font-semibold text-slate-900 dark:text-slate-100", children: `${p.merge_label ?? "Merge back to one line"} · ${n.key}` }),
1814
+ function Ia(b) {
1815
+ const { block: n, config: x, splitBase: f, client: i, onCancel: k, onDone: M } = b, E = Number.isFinite(Number(n.key)) ? Number(n.key) : n.key, [K, L] = W(""), [p, N] = W(!1), [v, y] = W(null), g = `Merged the ${n.key} plan back to one line`;
1816
+ return /* @__PURE__ */ c("div", { className: "p-1.5", "data-plan-merge-pane": !0, children: [
1817
+ /* @__PURE__ */ t("p", { className: "text-[12.5px] font-semibold text-slate-900 dark:text-slate-100", children: `${x.merge_label ?? "Merge back to one line"} · ${n.key}` }),
1741
1818
  /* @__PURE__ */ t("p", { className: "mt-0.5 text-[11.5px] text-slate-600 dark:text-slate-300", children: "The category lines are added together, period by period. Their history stays on the record." }),
1742
- S && /* @__PURE__ */ t("p", { role: "alert", className: "mt-1.5 text-[11.5px] font-medium text-red-700 dark:text-red-300", children: S }),
1819
+ v && /* @__PURE__ */ t("p", { role: "alert", className: "mt-1.5 text-[11.5px] font-medium text-red-700 dark:text-red-300", children: v }),
1743
1820
  /* @__PURE__ */ t(
1744
1821
  "textarea",
1745
1822
  {
1746
- value: F,
1823
+ value: K,
1747
1824
  onChange: (j) => L(j.target.value),
1748
- placeholder: x,
1825
+ placeholder: g,
1749
1826
  rows: 2,
1750
1827
  "aria-label": "Reason",
1751
1828
  className: "mt-2 w-full resize-none rounded-md border border-slate-200 bg-background px-2 py-1 text-[12px] text-slate-800 outline-none focus:border-slate-400 dark:border-border dark:text-slate-100"
1752
1829
  }
1753
1830
  ),
1754
- /* @__PURE__ */ d("div", { className: "mt-1.5 flex justify-end gap-2", children: [
1831
+ /* @__PURE__ */ c("div", { className: "mt-1.5 flex justify-end gap-2", children: [
1755
1832
  /* @__PURE__ */ t(
1756
1833
  "button",
1757
1834
  {
1758
1835
  type: "button",
1759
- onClick: C,
1836
+ onClick: k,
1760
1837
  className: "rounded-md px-2.5 py-1 text-[12px] text-slate-600 hover:bg-muted dark:text-slate-300",
1761
1838
  children: "Back"
1762
1839
  }
@@ -1766,79 +1843,79 @@ function Ta(v) {
1766
1843
  {
1767
1844
  type: "button",
1768
1845
  "data-plan-merge-apply": !0,
1769
- disabled: f,
1846
+ disabled: p,
1770
1847
  onClick: async () => {
1771
- k(!0);
1848
+ N(!0);
1772
1849
  try {
1773
- await o.request(
1774
- rt(`${g}/merge`, {
1775
- [p.key_field]: K,
1776
- reason: F.trim() || x
1850
+ await i.request(
1851
+ ot(`${f}/merge`, {
1852
+ [x.key_field]: E,
1853
+ reason: K.trim() || g
1777
1854
  })
1778
- ), de.success(`${n.key} is one line again`), R();
1855
+ ), ie.success(`${n.key} is one line again`), M();
1779
1856
  } catch (j) {
1780
- b(ot(j));
1857
+ y(dt(j));
1781
1858
  } finally {
1782
- k(!1);
1859
+ N(!1);
1783
1860
  }
1784
1861
  },
1785
1862
  className: "rounded-md bg-nvr-cyan px-3 py-1 text-[12px] font-medium text-white disabled:opacity-50",
1786
- children: f ? "Merging…" : "Merge it"
1863
+ children: p ? "Merging…" : "Merge it"
1787
1864
  }
1788
1865
  )
1789
1866
  ] })
1790
1867
  ] });
1791
1868
  }
1792
- function Ea(v) {
1793
- const { config: n, client: p, used: g, onAdd: o, label: C } = v, [R, K] = H(!1), [F, L] = H(""), { data: f = [] } = ce({
1869
+ function Ba(b) {
1870
+ const { config: n, client: x, used: f, onAdd: i, label: k } = b, [M, E] = W(!1), [K, L] = W(""), { data: p = [] } = he({
1794
1871
  queryKey: ["plan-grid-keys", n.key_collection],
1795
- queryFn: () => p.request(
1796
- ue(`/items/${n.key_collection}`, { fields: "id", sort: "-id", limit: 200 })
1797
- ).then((S) => (S.data ?? []).map((b) => b.id)),
1798
- enabled: R && !!n.key_collection,
1872
+ queryFn: () => x.request(
1873
+ fe(`/items/${n.key_collection}`, { fields: "id", sort: "-id", limit: 200 })
1874
+ ).then((v) => (v.data ?? []).map((y) => y.id)),
1875
+ enabled: M && !!n.key_collection,
1799
1876
  staleTime: 10 * 6e4
1800
- }), k = f.filter((S) => !g.has(String(S)));
1801
- return /* @__PURE__ */ d(it, { open: R, onOpenChange: K, children: [
1802
- /* @__PURE__ */ t(dt, { asChild: !0, children: /* @__PURE__ */ d(
1877
+ }), N = p.filter((v) => !f.has(String(v)));
1878
+ return /* @__PURE__ */ c(ut, { open: M, onOpenChange: E, children: [
1879
+ /* @__PURE__ */ t(pt, { asChild: !0, children: /* @__PURE__ */ c(
1803
1880
  "button",
1804
1881
  {
1805
1882
  type: "button",
1806
1883
  "data-plan-add": !0,
1807
1884
  className: "inline-flex h-7 items-center gap-1 rounded-md border border-slate-200 px-2 text-[12px] font-medium text-slate-700 hover:bg-muted dark:border-border dark:text-slate-200",
1808
1885
  children: [
1809
- /* @__PURE__ */ t(sa, { className: "h-3.5 w-3.5" }),
1810
- C
1886
+ /* @__PURE__ */ t(pa, { className: "h-3.5 w-3.5" }),
1887
+ k
1811
1888
  ]
1812
1889
  }
1813
1890
  ) }),
1814
- /* @__PURE__ */ t(ct, { align: "start", sideOffset: 6, className: "w-[200px] p-1.5", children: n.key_collection ? /* @__PURE__ */ d("ul", { className: "max-h-[220px] overflow-y-auto", children: [
1815
- k.length === 0 && /* @__PURE__ */ t("li", { className: "px-2 py-1.5 text-[12px] text-slate-500", children: "Every one is already here." }),
1816
- k.map((S) => /* @__PURE__ */ t("li", { children: /* @__PURE__ */ t(
1891
+ /* @__PURE__ */ t(mt, { align: "start", sideOffset: 6, className: "w-[200px] p-1.5", children: n.key_collection ? /* @__PURE__ */ c("ul", { className: "max-h-[220px] overflow-y-auto", children: [
1892
+ N.length === 0 && /* @__PURE__ */ t("li", { className: "px-2 py-1.5 text-[12px] text-slate-500", children: "Every one is already here." }),
1893
+ N.map((v) => /* @__PURE__ */ t("li", { children: /* @__PURE__ */ t(
1817
1894
  "button",
1818
1895
  {
1819
1896
  type: "button",
1820
- "data-plan-add-key": String(S),
1897
+ "data-plan-add-key": String(v),
1821
1898
  onClick: () => {
1822
- o(S), K(!1);
1899
+ i(v), E(!1);
1823
1900
  },
1824
1901
  className: "w-full rounded px-2 py-1.5 text-left text-[12.5px] text-slate-700 hover:bg-muted dark:text-slate-200",
1825
- children: String(S)
1902
+ children: String(v)
1826
1903
  }
1827
- ) }, String(S)))
1904
+ ) }, String(v)))
1828
1905
  ] }) : /* @__PURE__ */ t(
1829
1906
  "form",
1830
1907
  {
1831
- onSubmit: (S) => {
1832
- S.preventDefault();
1833
- const b = F.trim();
1834
- !b || g.has(b) || (o(Number.isFinite(Number(b)) ? Number(b) : b), L(""), K(!1));
1908
+ onSubmit: (v) => {
1909
+ v.preventDefault();
1910
+ const y = K.trim();
1911
+ !y || f.has(y) || (i(Number.isFinite(Number(y)) ? Number(y) : y), L(""), E(!1));
1835
1912
  },
1836
1913
  children: /* @__PURE__ */ t(
1837
1914
  "input",
1838
1915
  {
1839
- value: F,
1840
- onChange: (S) => L(S.target.value),
1841
- "aria-label": C,
1916
+ value: K,
1917
+ onChange: (v) => L(v.target.value),
1918
+ "aria-label": k,
1842
1919
  className: "h-7 w-full rounded border border-slate-200 bg-background px-2 text-[12.5px] outline-none focus:border-slate-400 dark:border-border"
1843
1920
  }
1844
1921
  )
@@ -1847,9 +1924,11 @@ function Ea(v) {
1847
1924
  ] });
1848
1925
  }
1849
1926
  export {
1850
- Ya as PlanGridField,
1851
- D as fmtFigure,
1852
- Sa as isParentItemKey,
1853
- qt as parseFigure,
1854
- _a as reconcilePatch
1927
+ il as PlanGridField,
1928
+ Dt as figureError,
1929
+ z as fmtFigure,
1930
+ Pa as isParentItemKey,
1931
+ Ta as nextStagedEdit,
1932
+ Bt as parseFigure,
1933
+ ja as reconcilePatch
1855
1934
  };