@nivaro/react 0.3.146 → 0.3.148

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