serverside_pivot 0.0.95 → 0.0.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/react/chunks/ContextMenu-DJuS4qTZ.mjs +198 -0
  2. package/dist/react/chunks/{DetailDrawer-DCKIxSpW.mjs → DetailDrawer-DgKSC5Vu.mjs} +1 -1
  3. package/dist/react/chunks/{DetailSidePanel-DgUWPBQk.mjs → DetailSidePanel-CC5Dugyl.mjs} +1 -1
  4. package/dist/react/chunks/{DetailSurfaceContent-BEL6xuaZ.mjs → DetailSurfaceContent-CrQVHlcU.mjs} +52 -53
  5. package/dist/react/chunks/{ECharts2dRenderer-Dgkp9_1P.mjs → ECharts2dRenderer-46gLrUdf.mjs} +1 -1
  6. package/dist/react/chunks/{ECharts3dRenderer-70VOp8V0.mjs → ECharts3dRenderer-Dg4ta5Bl.mjs} +1 -1
  7. package/dist/react/chunks/{EditSidePanel-CygqVXLX.mjs → EditSidePanel-CkShaByb.mjs} +1 -1
  8. package/dist/react/chunks/{InlineDetailPanel-BUBRWdFW.mjs → InlineDetailPanel-mnwjoD0I.mjs} +1 -1
  9. package/dist/react/chunks/{PivotCharts-VX5-mEEp.mjs → PivotCharts-MX-Z7DlR.mjs} +1207 -1193
  10. package/dist/react/chunks/{ReportEditor-B5j-CU9-.mjs → ReportEditor-U0E42xKL.mjs} +506 -480
  11. package/dist/react/chunks/SidebarPanel-BzRW1Kgq.mjs +3944 -0
  12. package/dist/react/chunks/{SparklineDetailGraph-Cfe2KcOp.mjs → SparklineDetailGraph-35Tim_8B.mjs} +1 -1
  13. package/dist/react/chunks/{installCanvasRenderer-C4h5pc1p.mjs → installCanvasRenderer-DRq0xpXO.mjs} +1 -1
  14. package/dist/react/chunks/react-CL4GbEOd.mjs +33206 -0
  15. package/dist/react/chunks/{xlsx.mini.min-CzdkdH3N.mjs → xlsx.mini.min-kfIgXMVB.mjs} +1 -1
  16. package/dist/react/components/DashTanstackPivot.react.d.ts +4 -0
  17. package/dist/react/components/ShimmerFallback.d.ts +11 -0
  18. package/dist/react/components/ThemedSelect.d.ts +8 -0
  19. package/dist/react/contexts/PivotThemeContext.d.ts +1 -0
  20. package/dist/react/hooks/useColumnDefs.d.ts +1 -1
  21. package/dist/react/hooks/useRenderHelpers.d.ts +1 -1
  22. package/dist/react/hooks/useServerSideRowModel.d.ts +1 -1
  23. package/dist/react/index.mjs +5 -5
  24. package/dist/react/react.d.ts +1 -1
  25. package/dist/react/runtime/client/clientPivotTransport.d.ts +1 -0
  26. package/dist/react/runtime/client/duckdbWasmExecutor.d.ts +3 -0
  27. package/dist/react/runtime/client/types.d.ts +12 -0
  28. package/dist/react/runtime/runtimeDomains.d.ts +94 -2
  29. package/dist/react/runtime/useRuntimeColumnAutoSizing.d.ts +1 -1
  30. package/dist/react/runtime/useRuntimeViewSnapshot.d.ts +1 -1
  31. package/dist/react/utils/dataBars.d.ts +1 -0
  32. package/dist/react/utils/domEvents.d.ts +1 -0
  33. package/dist/react/utils/helpers.d.ts +5 -0
  34. package/dist/react/utils/pivotLayoutUtils.d.ts +4 -0
  35. package/dist/react/utils/sorting.d.ts +1 -1
  36. package/package.json +1 -1
  37. package/dist/react/chunks/ContextMenu-1G-o1ms9.mjs +0 -195
  38. package/dist/react/chunks/SidebarPanel-LXUE6nPd.mjs +0 -3742
  39. package/dist/react/chunks/react-CDa-ADnG.mjs +0 -31199
@@ -0,0 +1,3944 @@
1
+ import e, { useState as ve, useRef as ur, useEffect as dr } from "react";
2
+ import { I as F, _ as Se, $ as Nr, a0 as Ur, a1 as kt, a2 as at, a3 as jr, a4 as Vr, a5 as Kr, a6 as He, a7 as it, a8 as st, F as Yr, a9 as Zr, aa as Gr, ab as Xr, ac as qe, ad as pr, ae as qr, af as Xt, T as re, ag as Jr, ah as Qr, ai as en, aj as qt, ak as tn, al as rn } from "./react-CL4GbEOd.mjs";
3
+ const nn = ({ column: r, theme: n, styles: o, onFilter: a, currentFilter: l, options: p, optionMeta: f, onSearchOptions: S, onLoadMoreOptions: g, onOpen: z }) => {
4
+ const [s, x] = ve(!1), W = l && (l.conditions || l.value), P = () => x(!1), M = () => {
5
+ const A = !s;
6
+ x(A), A && typeof z == "function" && z(r.id);
7
+ };
8
+ return /* @__PURE__ */ e.createElement("div", { style: { display: "flex", flexDirection: "column" } }, /* @__PURE__ */ e.createElement(
9
+ "div",
10
+ {
11
+ style: {
12
+ ...o.columnItem,
13
+ cursor: "pointer",
14
+ background: s ? n.select : "transparent",
15
+ borderLeft: W ? `3px solid ${n.primary}` : "3px solid transparent"
16
+ },
17
+ onClick: M
18
+ },
19
+ /* @__PURE__ */ e.createElement("span", { style: { marginRight: "8px", opacity: 0.7, display: "flex" } }, s ? /* @__PURE__ */ e.createElement(F.ChevronDown, null) : /* @__PURE__ */ e.createElement(F.ChevronRight, null)),
20
+ /* @__PURE__ */ e.createElement("span", { style: { flex: 1, fontWeight: 500, display: "flex", alignItems: "center", gap: "6px" } }, W && /* @__PURE__ */ e.createElement(F.Filter, { style: { fontSize: "12px", color: n.primary } }), Se(typeof r.header == "string" ? r.header : r.columnDef && typeof r.columnDef.header == "string" ? r.columnDef.header : r.id))
21
+ ), s && /* @__PURE__ */ e.createElement("div", { style: { padding: "8px", borderBottom: `1px solid ${n.border}44` } }, /* @__PURE__ */ e.createElement(
22
+ Nr,
23
+ {
24
+ column: r,
25
+ onFilter: a,
26
+ currentFilter: l,
27
+ options: p,
28
+ optionMeta: f,
29
+ onSearchOptions: S,
30
+ onLoadMoreOptions: g,
31
+ theme: n,
32
+ onClose: P
33
+ }
34
+ )));
35
+ }, St = ({ title: r, children: n, items: o, renderItem: a, theme: l, styles: p, initialExpanded: f = !0, count: S, onDrop: g, sectionId: z }) => {
36
+ const [s, x] = ve(f), [W, P] = ve(f), [M, A] = ve(f), [y, C] = ve(!1), D = ur(null);
37
+ dr(() => {
38
+ if (s) {
39
+ P(!0);
40
+ const w = setTimeout(() => A(!0), 220);
41
+ return () => clearTimeout(w);
42
+ }
43
+ A(!1);
44
+ const k = setTimeout(() => P(!1), 220);
45
+ return () => clearTimeout(k);
46
+ }, [s]);
47
+ const T = Ur({
48
+ count: o ? o.length : 0,
49
+ getScrollElement: () => D.current,
50
+ estimateSize: () => 32,
51
+ overscan: 10,
52
+ enabled: !!o && (s || W)
53
+ }), U = (k) => {
54
+ k.preventDefault(), C(!0);
55
+ }, R = () => {
56
+ C(!1);
57
+ }, O = (k) => {
58
+ k.preventDefault(), C(!1);
59
+ const w = k.dataTransfer.getData("text/plain");
60
+ g && w && g(w, z);
61
+ }, i = (k) => {
62
+ (k.key === "Enter" || k.key === " ") && (k.preventDefault(), x(
63
+ /** @param {any} [prev] @returns {any} */
64
+ (w) => !w
65
+ ));
66
+ };
67
+ return /* @__PURE__ */ e.createElement(
68
+ "div",
69
+ {
70
+ "data-is-over": y ? "true" : void 0,
71
+ style: {
72
+ ...p.toolPanelSection,
73
+ flex: s ? "0 1 auto" : "0 0 auto",
74
+ minHeight: s ? "40px" : "32px",
75
+ overflow: "hidden",
76
+ // Prevent overlap
77
+ borderRadius: y ? "8px" : void 0,
78
+ background: y ? l.select || "rgba(37,99,235,0.08)" : void 0,
79
+ boxShadow: y ? `inset 0 0 0 1.5px ${l.primary}` : void 0,
80
+ transition: "background-color 140ms ease, box-shadow 140ms ease"
81
+ },
82
+ onDragOver: U,
83
+ onDragLeave: R,
84
+ onDrop: O
85
+ },
86
+ /* @__PURE__ */ e.createElement(
87
+ "div",
88
+ {
89
+ role: "button",
90
+ tabIndex: 0,
91
+ "aria-expanded": s,
92
+ className: "sp-btn sp-btn-ghost",
93
+ style: { ...p.toolPanelSectionHeader, borderRadius: "6px" },
94
+ onClick: () => x(!s),
95
+ onKeyDown: i
96
+ },
97
+ /* @__PURE__ */ e.createElement("span", { style: {
98
+ marginRight: "8px",
99
+ opacity: 0.72,
100
+ display: "inline-flex",
101
+ alignItems: "center",
102
+ transform: s ? "rotate(90deg)" : "rotate(0deg)",
103
+ transition: "transform 160ms var(--sp-ease-apple, cubic-bezier(0.22, 1, 0.36, 1))"
104
+ } }, /* @__PURE__ */ e.createElement(F.ChevronRight, null)),
105
+ /* @__PURE__ */ e.createElement("span", { style: { flex: 1 } }, r),
106
+ S !== void 0 && /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", opacity: 0.7, background: l.hover, padding: "2px 7px", borderRadius: "10px", fontVariantNumeric: "tabular-nums" } }, S)
107
+ ),
108
+ /* @__PURE__ */ e.createElement(
109
+ "div",
110
+ {
111
+ className: "sp-disclosure-grid",
112
+ "data-expanded": s ? "true" : "false",
113
+ style: { pointerEvents: s ? "auto" : "none" }
114
+ },
115
+ /* @__PURE__ */ e.createElement(
116
+ "div",
117
+ {
118
+ ref: D,
119
+ className: "sp-disclosure-inner",
120
+ style: {
121
+ ...p.toolPanelList,
122
+ maxHeight: "300px",
123
+ overflowY: s && M ? "auto" : "hidden"
124
+ }
125
+ },
126
+ o ? /* @__PURE__ */ e.createElement("div", { style: {
127
+ height: `${T.getTotalSize()}px`,
128
+ width: "100%",
129
+ position: "relative"
130
+ } }, T.getVirtualItems().map(
131
+ /** @param {any} [virtualRow] @returns {any} */
132
+ (k) => /* @__PURE__ */ e.createElement(
133
+ "div",
134
+ {
135
+ key: k.index,
136
+ style: {
137
+ position: "absolute",
138
+ top: 0,
139
+ left: 0,
140
+ width: "100%",
141
+ height: `${k.size}px`,
142
+ transform: `translateY(${k.start}px)`
143
+ }
144
+ },
145
+ a(o[k.index], k.index)
146
+ )
147
+ )) : n
148
+ )
149
+ )
150
+ );
151
+ }, fr = ({ column: r, level: n, theme: o, styles: a, handlePinColumn: l, colSearch: p, selectedCols: f, setSelectedCols: S, onDrop: g, sectionId: z }) => {
152
+ const [s, x] = ve(n < 1), [W, P] = ve(!1), [M, A] = ve(!1), y = ur(null), C = r.columns && r.columns.length > 0, D = r.columnDef.header;
153
+ let T = typeof D == "string" ? D : r.id;
154
+ typeof T == "string" && T.startsWith("group_") && (T = r.id.replace("group_", "").split("|||").pop() || T), r.headerVal && (T = r.headerVal), T = Se(T);
155
+ const U = r.getIsPinned(), R = r.getIsVisible(), O = C ? kt(r) : [r.id], i = O.length > 0 && O.every((E) => f.has(E)), k = !i && O.some((E) => f.has(E));
156
+ if (dr(() => {
157
+ y.current && (y.current.indeterminate = k);
158
+ }, [k]), p && !T.toLowerCase().includes(p.toLowerCase()))
159
+ if (C) {
160
+ const E = (j) => {
161
+ const Z = j.columnDef.header;
162
+ return (typeof Z == "string" ? Z : j.id).toLowerCase().includes(p.toLowerCase()) ? !0 : j.columns ? j.columns.some(E) : !1;
163
+ };
164
+ if (!E(r)) return null;
165
+ } else
166
+ return null;
167
+ const w = (E) => {
168
+ E.stopPropagation();
169
+ const j = new Set(f), Z = C ? kt(r) : [r.id];
170
+ Z.every(
171
+ /** @param {any} [id] @returns {any} */
172
+ (J) => j.has(J)
173
+ ) ? Z.forEach(
174
+ /** @param {any} [id] @returns {any} */
175
+ (J) => j.delete(J)
176
+ ) : Z.forEach(
177
+ /** @param {any} [id] @returns {any} */
178
+ (J) => j.add(J)
179
+ ), S(j);
180
+ }, B = (E) => {
181
+ if (E.stopPropagation(), C) {
182
+ const j = jr(r), Z = j.some(
183
+ /** @param {any} [c] @returns {any} */
184
+ (V) => !V.getIsVisible()
185
+ );
186
+ j.forEach(
187
+ /** @param {any} [c] @returns {any} */
188
+ (V) => V.toggleVisibility(Z)
189
+ );
190
+ } else
191
+ r.toggleVisibility();
192
+ }, _ = (E, j) => {
193
+ E.stopPropagation(), l(r.id, j);
194
+ }, N = (E) => {
195
+ A(!0), E.dataTransfer.setData("text/plain", r.id), E.dataTransfer.effectAllowed = "move";
196
+ }, L = () => {
197
+ A(!1);
198
+ }, m = (E) => {
199
+ E.preventDefault(), E.stopPropagation();
200
+ const j = E.dataTransfer.getData("text/plain");
201
+ j && g && j !== r.id && g(j, z, r.id);
202
+ }, $ = (E) => {
203
+ E.key === "Enter" ? B(E) : E.key === " " ? (E.preventDefault(), w(E)) : E.altKey && E.key === "ArrowLeft" ? (E.preventDefault(), l(r.id, "left")) : E.altKey && E.key === "ArrowRight" ? (E.preventDefault(), l(r.id, "right")) : E.altKey && E.key === "ArrowDown" && (E.preventDefault(), l(r.id, !1));
204
+ };
205
+ return /* @__PURE__ */ e.createElement(
206
+ "div",
207
+ {
208
+ style: { display: "flex", flexDirection: "column", opacity: M ? 0.5 : 1 },
209
+ draggable: !C,
210
+ onDragStart: N,
211
+ onDragEnd: L,
212
+ onDragOver: (E) => E.preventDefault(),
213
+ onDrop: m,
214
+ role: "treeitem",
215
+ "aria-selected": i || k,
216
+ "aria-expanded": s
217
+ },
218
+ /* @__PURE__ */ e.createElement(
219
+ "div",
220
+ {
221
+ style: {
222
+ ...a.columnItem,
223
+ paddingLeft: `${n * 12 + 8}px`,
224
+ // Reduced indentation step
225
+ background: i || k ? o.select : W ? o.hover : "transparent",
226
+ borderLeft: U ? `3px solid ${o.primary}` : "3px solid transparent"
227
+ },
228
+ onMouseEnter: (E) => !(i || k) && P(!0),
229
+ onMouseLeave: (E) => !(i || k) && P(!1),
230
+ tabIndex: 0,
231
+ onKeyDown: $
232
+ },
233
+ /* @__PURE__ */ e.createElement(
234
+ "input",
235
+ {
236
+ ref: y,
237
+ type: "checkbox",
238
+ checked: i,
239
+ onChange: w,
240
+ onClick: (E) => E.stopPropagation(),
241
+ style: { margin: 0, cursor: "pointer", pointerEvents: "auto" },
242
+ tabIndex: -1
243
+ }
244
+ ),
245
+ !C && /* @__PURE__ */ e.createElement("span", { style: { cursor: "grab", display: "flex", opacity: 0.7, marginRight: "4px" } }, /* @__PURE__ */ e.createElement(F.DragIndicator, null)),
246
+ C ? /* @__PURE__ */ e.createElement(
247
+ "span",
248
+ {
249
+ role: "button",
250
+ tabIndex: 0,
251
+ "aria-expanded": s,
252
+ "aria-label": s ? `Collapse ${T}` : `Expand ${T}`,
253
+ onClick: () => x(!s),
254
+ onKeyDown: (E) => {
255
+ (E.key === "Enter" || E.key === " ") && (E.preventDefault(), x(!s));
256
+ },
257
+ style: { cursor: "pointer", display: "flex", opacity: 0.7, marginRight: "4px" }
258
+ },
259
+ s ? /* @__PURE__ */ e.createElement(F.ChevronDown, null) : /* @__PURE__ */ e.createElement(F.ChevronRight, null)
260
+ ) : /* @__PURE__ */ e.createElement("span", { style: { width: "20px" } }),
261
+ /* @__PURE__ */ e.createElement(
262
+ "span",
263
+ {
264
+ onClick: B,
265
+ style: {
266
+ cursor: "pointer",
267
+ display: "flex",
268
+ color: R ? o.primary : o.textSec,
269
+ opacity: R ? 1 : 0.5,
270
+ marginRight: "4px"
271
+ },
272
+ title: R ? "Hide Column" : "Show Column",
273
+ "aria-label": R ? "Hide Column" : "Show Column"
274
+ },
275
+ R ? /* @__PURE__ */ e.createElement(F.Visibility, null) : /* @__PURE__ */ e.createElement(F.VisibilityOff, null)
276
+ ),
277
+ /* @__PURE__ */ e.createElement(
278
+ "span",
279
+ {
280
+ style: {
281
+ flex: 1,
282
+ overflow: "hidden",
283
+ textOverflow: "ellipsis",
284
+ whiteSpace: "nowrap",
285
+ fontWeight: C ? 600 : 400,
286
+ cursor: C ? "pointer" : "default",
287
+ color: R ? o.text : o.textSec,
288
+ opacity: R ? 1 : 0.6,
289
+ display: "flex",
290
+ alignItems: "center"
291
+ },
292
+ onClick: () => C && x(!s),
293
+ title: T
294
+ },
295
+ C && /* @__PURE__ */ e.createElement(F.Group, { style: { marginRight: "6px", fontSize: "14px", opacity: 0.8 } }),
296
+ T
297
+ ),
298
+ !C && /* @__PURE__ */ e.createElement("div", { className: "pin-controls" }, /* @__PURE__ */ e.createElement("button", { onClick: (E) => _(E, "left"), title: "Pin Column Left", "aria-label": "Pin Column Left" }, /* @__PURE__ */ e.createElement(F.PinLeft, null)), /* @__PURE__ */ e.createElement("button", { onClick: (E) => _(E, !1), title: "Unpin Column", "aria-label": "Unpin Column" }, /* @__PURE__ */ e.createElement(F.Unpin, null)), /* @__PURE__ */ e.createElement("button", { onClick: (E) => _(E, "right"), title: "Pin Column Right", "aria-label": "Pin Column Right" }, /* @__PURE__ */ e.createElement(F.PinRight, null)))
299
+ ),
300
+ C && s && /* @__PURE__ */ e.createElement("div", { style: { display: "flex", flexDirection: "column" } }, r.columns.filter(
301
+ /** @param {any} [child] @returns {any} */
302
+ (E) => at(E, z)
303
+ ).map(
304
+ /** @param {any} [child] @returns {any} */
305
+ (E) => /* @__PURE__ */ e.createElement(
306
+ fr,
307
+ {
308
+ key: E.id,
309
+ column: E,
310
+ level: n + 1,
311
+ theme: o,
312
+ styles: a,
313
+ handlePinColumn: l,
314
+ colSearch: p,
315
+ selectedCols: f,
316
+ setSelectedCols: S,
317
+ onDrop: g,
318
+ sectionId: z
319
+ }
320
+ )
321
+ ))
322
+ );
323
+ }, mr = /\b[A-Za-z_][A-Za-z0-9_]*\b/g, gr = /^[A-Za-z_][A-Za-z0-9_]*$/, ct = /\[([^\]]+)\]/g, ln = /* @__PURE__ */ new Set(["abs", "round", "ceil", "floor", "max", "min", "int", "float"]), an = /* @__PURE__ */ new Set(["True", "False", "None", "and", "or", "not", "if", "else", "in", "is"]), Fe = {
324
+ type: "line",
325
+ metric: "last",
326
+ showCurrentValue: !0,
327
+ showDelta: !0,
328
+ compact: !1,
329
+ hideColumns: !1,
330
+ placement: "before",
331
+ source: "pivot",
332
+ displayMode: "trend"
333
+ };
334
+ function xr(r) {
335
+ return String(r || "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
336
+ }
337
+ function Me(r, n = "formula") {
338
+ const a = String(r || "").trim().toLowerCase().replace(/\s+/g, "").replace(/[^a-z0-9_]/g, "") || String(n || "formula").toLowerCase().replace(/[^a-z0-9_]/g, "") || "formula";
339
+ return /^[a-z_]/.test(a) ? a : `f_${a}`;
340
+ }
341
+ function q(r) {
342
+ return !r || typeof r != "object" ? "" : String(
343
+ r.formulaRef || Me(r.label || "", r.field || "formula") || r.field || ""
344
+ ).trim();
345
+ }
346
+ function Ne(r) {
347
+ const n = String(r || "").trim().toLowerCase();
348
+ return ["columns", "display", "displayed", "displayed_columns", "rendered", "rendered_columns"].includes(n) ? "columns" : "measures";
349
+ }
350
+ function $e(r) {
351
+ return Ne(r) === "columns";
352
+ }
353
+ const on = [
354
+ { value: "eq", label: "Equals" },
355
+ { value: "ne", label: "Does not equal" },
356
+ { value: "contains", label: "Contains" },
357
+ { value: "starts_with", label: "Starts with" },
358
+ { value: "ends_with", label: "Ends with" },
359
+ { value: "gt", label: ">" },
360
+ { value: "gte", label: ">=" },
361
+ { value: "lt", label: "<" },
362
+ { value: "lte", label: "<=" },
363
+ { value: "in", label: "In list" },
364
+ { value: "not_in", label: "Not in list" },
365
+ { value: "is_null", label: "Is empty" },
366
+ { value: "is_not_null", label: "Is not empty" }
367
+ ], Jt = /* @__PURE__ */ new Set(["in", "not_in"]), sn = /* @__PURE__ */ new Set(["is_null", "is_not_null"]);
368
+ function yr(r) {
369
+ return { field: r && r[0] || "", operator: "eq", value: "", values: [], caseSensitive: !1 };
370
+ }
371
+ function br(r, n = 0) {
372
+ return {
373
+ id: `rule-${Date.now().toString(36)}-${n}`,
374
+ label: n === 0 ? "Group A" : `Group ${n + 1}`,
375
+ condition: { op: "AND", clauses: [yr(r)] }
376
+ };
377
+ }
378
+ function Qt(r, n = null) {
379
+ if (n) {
380
+ const a = He([n])[0] || n;
381
+ return { ...JSON.parse(JSON.stringify(a)), __editingField: a.field, __editingId: a.id };
382
+ }
383
+ const o = it(`category_${Date.now().toString(36)}`);
384
+ return {
385
+ id: o,
386
+ field: st(o),
387
+ name: "New Category",
388
+ fallbackLabel: "Other",
389
+ order: "creation",
390
+ rules: [br(r, 0)],
391
+ __isNew: !0
392
+ };
393
+ }
394
+ function cn(r, n) {
395
+ if (!n) return "string";
396
+ const o = Array.isArray(r) ? r.slice(0, 250) : [];
397
+ for (let a = 0; a < o.length; a += 1) {
398
+ const l = o[a];
399
+ if (!l || typeof l != "object") continue;
400
+ const p = l[n];
401
+ if (!(p == null || p === "")) {
402
+ if (typeof p == "number" && Number.isFinite(p)) return "number";
403
+ if (p instanceof Date && !Number.isNaN(p.getTime())) return "date";
404
+ if (typeof p == "string") {
405
+ const f = p.trim();
406
+ if (!f) continue;
407
+ if (Number.isFinite(Number(f))) return "number";
408
+ const S = Date.parse(f);
409
+ return !Number.isNaN(S) && /[-/T:]/.test(f) ? "date" : "string";
410
+ }
411
+ }
412
+ }
413
+ return "string";
414
+ }
415
+ const ot = (r, n, o) => (Array.isArray(n) ? n : []).filter((a) => cn(r, a) === o);
416
+ function un(r, n) {
417
+ const a = ot(n, r, "date")[0] || r[0] || "", l = it(`${a || "date"}_month`);
418
+ return {
419
+ id: l,
420
+ field: st(l),
421
+ kind: "date_group",
422
+ name: a ? `${Se(a)} Month` : "Date Month",
423
+ sourceField: a,
424
+ granularity: "month",
425
+ fiscalYearStartMonth: 1,
426
+ fallbackLabel: "No date",
427
+ __isNew: !0
428
+ };
429
+ }
430
+ function dn(r, n) {
431
+ const a = ot(n, r, "number")[0] || r[0] || "", l = it(`${a || "number"}_bins`);
432
+ return {
433
+ id: l,
434
+ field: st(l),
435
+ kind: "number_group",
436
+ name: a ? `${Se(a)} Bins` : "Number Bins",
437
+ sourceField: a,
438
+ binSize: 10,
439
+ minValue: "",
440
+ maxValue: "",
441
+ precision: 0,
442
+ fallbackLabel: "No value",
443
+ __isNew: !0
444
+ };
445
+ }
446
+ const er = (r) => String(r || "").split(",").map((n) => n.trim()).filter(Boolean), tr = (r) => String(r || "").trim().replace(/\s+/g, " ").toLowerCase(), Er = (r) => r && (r.__editingField || r.field) ? r.__editingField || r.field : "";
447
+ function pn(r, n) {
448
+ const o = Array.isArray(r) ? r : [], a = Er(n);
449
+ if (!a) return o;
450
+ const l = o.findIndex(
451
+ /** @param {any} [dimension] @returns {any} */
452
+ (p) => p && p.field === a
453
+ );
454
+ return l >= 0 ? o.slice(0, l) : o;
455
+ }
456
+ function rr(r) {
457
+ const n = [];
458
+ return (r && Array.isArray(r.rules) ? r.rules : []).forEach(
459
+ /** @param {any} [rule] @returns {any} */
460
+ (o) => {
461
+ (o && o.condition && Array.isArray(o.condition.clauses) ? o.condition.clauses : []).forEach(
462
+ /** @param {any} [clause] @returns {any} */
463
+ (l) => {
464
+ l && l.field && n.push(l.field);
465
+ }
466
+ );
467
+ }
468
+ ), Array.from(new Set(n));
469
+ }
470
+ function fn(r, n) {
471
+ const o = (Array.isArray(r) ? r : []).filter((a) => a && typeof a == "object").filter((a) => !a._isTotal && a._path !== "__grand_total__" && a._path !== "__color_scale_stats__");
472
+ return Vr(o, n || []);
473
+ }
474
+ function mn(r, n) {
475
+ return !Array.isArray(r) || r.length === 0 || !Array.isArray(n) || n.length === 0 ? !1 : n.every((o) => r.some((a) => a && Object.prototype.hasOwnProperty.call(a, o)));
476
+ }
477
+ const gn = (r, n) => (n && Array.isArray(n.rules) ? n.rules : []).map(
478
+ /** @param {any} [rule] @returns {any} */
479
+ (o) => ({
480
+ label: o && o.label ? o.label : "Rule",
481
+ count: r.reduce(
482
+ /** @param {any} [matches] @param {any} [row] @returns {any} */
483
+ (a, l) => Kr(l, o.condition) ? a + 1 : a,
484
+ 0
485
+ )
486
+ })
487
+ ), xn = e.lazy(() => import(
488
+ /* webpackChunkName: "pivot-report-editor" */
489
+ "./ReportEditor-U0E42xKL.mjs"
490
+ ).then((r) => ({
491
+ default: r.ReportEditor
492
+ }))), yn = (r) => /* @__PURE__ */ e.createElement(e.Suspense, { fallback: /* @__PURE__ */ e.createElement("div", { role: "status", style: { padding: "16px" } }, "Loading report builder…") }, /* @__PURE__ */ e.createElement(xn, { ...r }));
493
+ function nr({
494
+ availableFields: r,
495
+ customDimensions: n,
496
+ setCustomDimensions: o,
497
+ data: a,
498
+ theme: l,
499
+ showNotification: p,
500
+ getFieldLabel: f,
501
+ onDeleteField: S
502
+ }) {
503
+ const g = e.useMemo(
504
+ () => (r || []).filter(
505
+ /** @param {any} [field] @returns {any} */
506
+ (i) => i && !pr(i)
507
+ ),
508
+ [r]
509
+ ), z = e.useMemo(
510
+ () => He(n || []),
511
+ [n]
512
+ ), [s, x] = e.useState(null), W = e.useMemo(
513
+ () => pn(z, s),
514
+ [s, z]
515
+ ), P = e.useMemo(() => {
516
+ const i = /* @__PURE__ */ new Set(), k = [];
517
+ return g.forEach(
518
+ /** @param {any} [field] @returns {any} */
519
+ (w) => {
520
+ w && !i.has(w) && (i.add(w), k.push(w));
521
+ }
522
+ ), W.forEach(
523
+ /** @param {any} [dimension] @returns {any} */
524
+ (w) => {
525
+ w && w.field && !i.has(w.field) && (i.add(w.field), k.push(w.field));
526
+ }
527
+ ), k;
528
+ }, [W, g]), M = e.useMemo(
529
+ () => {
530
+ const i = ot(a, g, "date");
531
+ return i.length > 0 ? i : g;
532
+ },
533
+ [g, a]
534
+ ), A = e.useMemo(
535
+ () => {
536
+ const i = ot(a, g, "number");
537
+ return i.length > 0 ? i : g;
538
+ },
539
+ [g, a]
540
+ ), y = e.useMemo(
541
+ () => fn(a, W),
542
+ [W, a]
543
+ ), C = e.useMemo(() => ({
544
+ border: `1px solid ${l.border}`,
545
+ background: l.background,
546
+ color: l.text,
547
+ borderRadius: "8px",
548
+ fontSize: "12px",
549
+ padding: "7px 8px",
550
+ outline: "none",
551
+ minWidth: 0
552
+ }), [l.background, l.border, l.text]), D = e.useCallback((i = "default") => ({
553
+ border: i === "primary" ? `1px solid ${l.primary}` : `1px solid ${l.border}`,
554
+ background: i === "primary" ? l.primary || "#2563EB" : l.hover || "#F8FAFC",
555
+ color: i === "primary" ? "#fff" : l.text,
556
+ borderRadius: "8px",
557
+ fontSize: "11px",
558
+ fontWeight: 700,
559
+ padding: "6px 9px",
560
+ cursor: "pointer",
561
+ display: "inline-flex",
562
+ alignItems: "center",
563
+ gap: "5px"
564
+ }), [l.border, l.hover, l.primary, l.text]);
565
+ e.useEffect(() => {
566
+ if (!s) return;
567
+ const i = (k) => {
568
+ k.key === "Escape" && (k.preventDefault(), x(null));
569
+ };
570
+ return window.addEventListener("keydown", i), () => window.removeEventListener("keydown", i);
571
+ }, [s]);
572
+ const T = e.useCallback((i, k) => {
573
+ x(
574
+ /** @param {any} [current] @returns {any} */
575
+ (w) => {
576
+ if (!w) return w;
577
+ const B = [...w.rules || []];
578
+ return B[i] = typeof k == "function" ? k(B[i]) : k, { ...w, rules: B };
579
+ }
580
+ );
581
+ }, []), U = e.useCallback((i, k, w) => {
582
+ T(
583
+ i,
584
+ /** @param {any} [rule] @returns {any} */
585
+ (B) => {
586
+ const _ = B.condition || { op: "AND", clauses: [] }, N = [..._.clauses || []];
587
+ return N[k] = { ...N[k], ...w }, { ...B, condition: { ..._, clauses: N } };
588
+ }
589
+ );
590
+ }, [T]), R = e.useCallback(() => {
591
+ const i = He([s])[0];
592
+ if (!i || !i.name) {
593
+ p && p("A grouped field needs a name.", "warning");
594
+ return;
595
+ }
596
+ if (i.kind === "category" && (!i.rules || i.rules.length === 0)) {
597
+ p && p("A category needs at least one valid rule.", "warning");
598
+ return;
599
+ }
600
+ if ((i.kind === "date_group" || i.kind === "number_group") && !i.sourceField) {
601
+ p && p("Choose the source field to group.", "warning");
602
+ return;
603
+ }
604
+ const k = Er(s), w = tr(i.name);
605
+ if (z.some(
606
+ /** @param {any} [dimension] @returns {any} */
607
+ (_) => _ && _.field !== k && tr(_.name) === w
608
+ )) {
609
+ p && p(`A category named "${i.name}" already exists.`, "warning");
610
+ return;
611
+ }
612
+ if (i.kind === "category") {
613
+ const _ = new Set(P);
614
+ if (rr(i).find(
615
+ /** @param {any} [field] @returns {any} */
616
+ (m) => !_.has(m)
617
+ )) {
618
+ p && p("A category can only use base fields or categories defined before it.", "warning");
619
+ return;
620
+ }
621
+ const L = rr(i);
622
+ if (mn(y, L)) {
623
+ const m = gn(y, i).find(
624
+ /** @param {any} [summary] @returns {any} */
625
+ ($) => $.count === 0
626
+ );
627
+ if (m) {
628
+ p && p(`"${m.label}" does not match any current row. Adjust the condition before applying.`, "warning");
629
+ return;
630
+ }
631
+ }
632
+ }
633
+ if (i.kind === "date_group" && !M.includes(i.sourceField)) {
634
+ p && p("Choose a date field for date grouping.", "warning");
635
+ return;
636
+ }
637
+ if (i.kind === "number_group") {
638
+ if (!A.includes(i.sourceField)) {
639
+ p && p("Choose a numeric field for number grouping.", "warning");
640
+ return;
641
+ }
642
+ if (!Number.isFinite(Number(i.binSize)) || Number(i.binSize) <= 0) {
643
+ p && p("Number bins need a positive bin size.", "warning");
644
+ return;
645
+ }
646
+ }
647
+ o(
648
+ /** @param {any} [previous] @returns {any} */
649
+ (_) => [...He(_ || []).filter(
650
+ /** @param {any} [dimension] @returns {any} */
651
+ (m) => m.id !== i.id && m.field !== i.field && m.field !== k
652
+ ), i]
653
+ ), x(null), p && p(`Applied ${i.name}.`, "success");
654
+ }, [P, M, s, z, A, o, p, y]), O = e.useCallback((i) => {
655
+ const k = He([i])[0];
656
+ k && (o(
657
+ /** @param {any} [previous] @returns {any} */
658
+ (w) => He(w || []).filter(
659
+ /** @param {any} [item] @returns {any} */
660
+ (B) => B.field !== k.field
661
+ )
662
+ ), typeof S == "function" && S(k.field), s && s.field === k.field && x(null), p && p(`Removed ${k.name}.`, "success"));
663
+ }, [s, S, o, p]);
664
+ return /* @__PURE__ */ e.createElement("div", { style: {
665
+ border: `1px solid ${l.border}`,
666
+ background: l.headerBg || l.surfaceInset || l.background,
667
+ borderRadius: "12px",
668
+ padding: "10px",
669
+ marginBottom: "14px",
670
+ display: "flex",
671
+ flexDirection: "column",
672
+ gap: "10px"
673
+ } }, /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "8px" } }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "11px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px", fontWeight: 800 } }, "Custom Categories"), /* @__PURE__ */ e.createElement("div", { style: { fontSize: "11px", color: l.textSec, marginTop: "2px" } }, "Named filter rules that become fields.")), /* @__PURE__ */ e.createElement(
674
+ "button",
675
+ {
676
+ type: "button",
677
+ onClick: () => x(Qt(P)),
678
+ style: { ...D("primary"), whiteSpace: "nowrap", flexShrink: 0 }
679
+ },
680
+ "+ Category"
681
+ )), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" } }, /* @__PURE__ */ e.createElement(
682
+ "button",
683
+ {
684
+ type: "button",
685
+ onClick: () => x(un(g, a)),
686
+ disabled: M.length === 0,
687
+ style: { ...D(), opacity: M.length === 0 ? 0.5 : 1, cursor: M.length === 0 ? "not-allowed" : "pointer" },
688
+ title: M.length === 0 ? "No date fields detected" : "Create date buckets"
689
+ },
690
+ /* @__PURE__ */ e.createElement(F.Group, null),
691
+ " Date Group"
692
+ ), /* @__PURE__ */ e.createElement(
693
+ "button",
694
+ {
695
+ type: "button",
696
+ onClick: () => x(dn(g, a)),
697
+ disabled: A.length === 0,
698
+ style: { ...D(), opacity: A.length === 0 ? 0.5 : 1, cursor: A.length === 0 ? "not-allowed" : "pointer" },
699
+ title: A.length === 0 ? "No numeric fields detected" : "Create numeric bins"
700
+ },
701
+ /* @__PURE__ */ e.createElement(F.NumberFormat, null),
702
+ " Number Bins"
703
+ )), z.length > 0 && /* @__PURE__ */ e.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "6px" } }, z.map(
704
+ /** @param {any} [dimension] @returns {any} */
705
+ (i) => {
706
+ const k = i.kind || "category", w = k === "date_group" ? `${f(i.sourceField)} by ${i.granularity}` : k === "number_group" ? `${f(i.sourceField)} every ${i.binSize}` : `${i.rules.length} rule${i.rules.length === 1 ? "" : "s"} | fallback: ${i.fallbackLabel}`;
707
+ return /* @__PURE__ */ e.createElement(
708
+ "div",
709
+ {
710
+ key: i.field,
711
+ style: {
712
+ border: `1px solid ${l.border}`,
713
+ background: l.background,
714
+ borderRadius: "10px",
715
+ padding: "8px",
716
+ display: "flex",
717
+ alignItems: "center",
718
+ gap: "8px"
719
+ }
720
+ },
721
+ k === "number_group" ? /* @__PURE__ */ e.createElement(F.NumberFormat, null) : /* @__PURE__ */ e.createElement(F.Branch, null),
722
+ /* @__PURE__ */ e.createElement("div", { style: { minWidth: 0, flex: 1 } }, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "12px", fontWeight: 800, color: l.text, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, i.name), /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: l.textSec } }, w)),
723
+ /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => x(Qt(g, i)), style: D() }, /* @__PURE__ */ e.createElement(F.Edit, null), " Edit"),
724
+ /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => O(i), style: { ...D(), color: "#B91C1C" } }, /* @__PURE__ */ e.createElement(F.Delete, null))
725
+ );
726
+ }
727
+ )), s && /* @__PURE__ */ e.createElement(
728
+ "div",
729
+ {
730
+ role: "presentation",
731
+ onMouseDown: (i) => {
732
+ i.target === i.currentTarget && x(null);
733
+ },
734
+ style: {
735
+ position: "fixed",
736
+ inset: 0,
737
+ zIndex: 1e4,
738
+ background: "rgba(15, 23, 42, 0.38)",
739
+ backdropFilter: "blur(4px)",
740
+ display: "flex",
741
+ alignItems: "center",
742
+ justifyContent: "center",
743
+ padding: "24px"
744
+ }
745
+ },
746
+ /* @__PURE__ */ e.createElement(
747
+ "div",
748
+ {
749
+ role: "dialog",
750
+ "aria-modal": "true",
751
+ "aria-label": s.kind === "date_group" || s.kind === "number_group" ? s.__editingField ? "Edit grouped field" : "Add grouped field" : s.__editingField ? "Edit custom category" : "Add custom category",
752
+ style: {
753
+ width: "min(780px, calc(100vw - 32px))",
754
+ maxHeight: "calc(100vh - 48px)",
755
+ border: `1px solid ${l.primary || "#2563EB"}55`,
756
+ background: l.background,
757
+ color: l.text,
758
+ borderRadius: "16px",
759
+ boxShadow: "0 24px 80px rgba(15, 23, 42, 0.28)",
760
+ overflow: "hidden"
761
+ }
762
+ },
763
+ /* @__PURE__ */ e.createElement("div", { style: {
764
+ padding: "14px 16px",
765
+ borderBottom: `1px solid ${l.border}`,
766
+ background: l.headerBg || l.surfaceInset || l.background,
767
+ display: "flex",
768
+ alignItems: "center",
769
+ justifyContent: "space-between",
770
+ gap: "12px"
771
+ } }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "13px", fontWeight: 900, color: l.text } }, s.kind === "date_group" || s.kind === "number_group" ? s.__editingField ? "Edit Grouped Field" : "Add Grouped Field" : s.__editingField ? "Edit Custom Category" : "Add Custom Category"), /* @__PURE__ */ e.createElement("div", { style: { fontSize: "11px", color: l.textSec, marginTop: "2px" } }, s.kind === "date_group" ? "Create calendar buckets from a date field." : s.kind === "number_group" ? "Create fixed-width numeric bins from a number field." : "Rules can use base fields and categories defined before this one.")), /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => x(null), style: { ...D(), padding: "6px 8px" }, "aria-label": "Close category editor" }, /* @__PURE__ */ e.createElement(F.Close, null))),
772
+ /* @__PURE__ */ e.createElement("div", { style: {
773
+ padding: "14px",
774
+ overflowY: "auto",
775
+ maxHeight: "calc(100vh - 128px)",
776
+ display: "flex",
777
+ flexDirection: "column",
778
+ gap: "10px"
779
+ } }, /* @__PURE__ */ e.createElement("div", { style: { display: "grid", gridTemplateColumns: "1fr 120px 150px", gap: "8px" } }, /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Category Name", /* @__PURE__ */ e.createElement(
780
+ "input",
781
+ {
782
+ value: s.name || "",
783
+ onChange: (i) => {
784
+ const k = i.target.value, w = s.id || it(k);
785
+ x({ ...s, name: k, id: w, field: s.field || st(w) });
786
+ },
787
+ style: C,
788
+ placeholder: "Example: Priority Segment"
789
+ }
790
+ )), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Else", /* @__PURE__ */ e.createElement(
791
+ "input",
792
+ {
793
+ value: s.fallbackLabel || "",
794
+ onChange: (i) => x({ ...s, fallbackLabel: i.target.value }),
795
+ style: C,
796
+ placeholder: "Other"
797
+ }
798
+ )), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Member Order", /* @__PURE__ */ e.createElement(
799
+ re,
800
+ {
801
+ size: "sm",
802
+ "aria-label": "Member Order",
803
+ value: s.order || "creation",
804
+ onChange: (i) => x({ ...s, order: i.target.value }),
805
+ style: { ...C, width: "100%" }
806
+ },
807
+ /* @__PURE__ */ e.createElement("option", { value: "creation" }, "Creation Order"),
808
+ /* @__PURE__ */ e.createElement("option", { value: "alpha" }, "Alphabetical (A→Z)"),
809
+ /* @__PURE__ */ e.createElement("option", { value: "alpha_desc" }, "Alphabetical (Z→A)"),
810
+ /* @__PURE__ */ e.createElement("option", { value: "numeric" }, "Numeric (0→9)"),
811
+ /* @__PURE__ */ e.createElement("option", { value: "numeric_desc" }, "Numeric (9→0)")
812
+ ))), s.kind === "date_group" && /* @__PURE__ */ e.createElement("div", { style: {
813
+ border: `1px solid ${l.border}`,
814
+ borderRadius: "10px",
815
+ padding: "10px",
816
+ background: l.hover || "#F8FAFC",
817
+ display: "grid",
818
+ gridTemplateColumns: "1.4fr 1fr 1fr",
819
+ gap: "8px"
820
+ } }, /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Date Field", /* @__PURE__ */ e.createElement(
821
+ re,
822
+ {
823
+ size: "sm",
824
+ "aria-label": "Date Field",
825
+ value: s.sourceField || "",
826
+ onChange: (i) => x({
827
+ ...s,
828
+ sourceField: i.target.value,
829
+ name: s.__isNew ? `${f(i.target.value)} ${Se(s.granularity || "month")}` : s.name
830
+ }),
831
+ style: { ...C, width: "100%" }
832
+ },
833
+ M.map(
834
+ /** @param {any} [field] @returns {any} */
835
+ (i) => /* @__PURE__ */ e.createElement("option", { key: i, value: i }, f(i))
836
+ )
837
+ )), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Date Part", /* @__PURE__ */ e.createElement(
838
+ re,
839
+ {
840
+ size: "sm",
841
+ "aria-label": "Date Part",
842
+ value: s.granularity || "month",
843
+ onChange: (i) => x({ ...s, granularity: i.target.value }),
844
+ style: { ...C, width: "100%" }
845
+ },
846
+ Array.from(Qr).map((i) => /* @__PURE__ */ e.createElement("option", { key: i, value: i }, Se(i)))
847
+ )), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Fiscal Start", /* @__PURE__ */ e.createElement(
848
+ re,
849
+ {
850
+ size: "sm",
851
+ "aria-label": "Fiscal Start",
852
+ value: s.fiscalYearStartMonth || 1,
853
+ onChange: (i) => x({ ...s, fiscalYearStartMonth: Number(i.target.value) }),
854
+ style: { ...C, width: "100%" }
855
+ },
856
+ ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"].map((i, k) => /* @__PURE__ */ e.createElement("option", { key: i, value: k + 1 }, i))
857
+ ))), s.kind === "number_group" && /* @__PURE__ */ e.createElement("div", { style: {
858
+ border: `1px solid ${l.border}`,
859
+ borderRadius: "10px",
860
+ padding: "10px",
861
+ background: l.hover || "#F8FAFC",
862
+ display: "grid",
863
+ gridTemplateColumns: "1.4fr 0.8fr 0.8fr 0.8fr 0.7fr",
864
+ gap: "8px"
865
+ } }, /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Number Field", /* @__PURE__ */ e.createElement(
866
+ re,
867
+ {
868
+ size: "sm",
869
+ "aria-label": "Number Field",
870
+ value: s.sourceField || "",
871
+ onChange: (i) => x({
872
+ ...s,
873
+ sourceField: i.target.value,
874
+ name: s.__isNew ? `${f(i.target.value)} Bins` : s.name
875
+ }),
876
+ style: { ...C, width: "100%" }
877
+ },
878
+ A.map(
879
+ /** @param {any} [field] @returns {any} */
880
+ (i) => /* @__PURE__ */ e.createElement("option", { key: i, value: i }, f(i))
881
+ )
882
+ )), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Bin Size", /* @__PURE__ */ e.createElement(
883
+ "input",
884
+ {
885
+ type: "number",
886
+ value: s.binSize === void 0 ? "" : s.binSize,
887
+ onChange: (i) => x({ ...s, binSize: i.target.value }),
888
+ style: C
889
+ }
890
+ )), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Min", /* @__PURE__ */ e.createElement(
891
+ "input",
892
+ {
893
+ type: "number",
894
+ value: s.minValue === null || s.minValue === void 0 ? "" : s.minValue,
895
+ onChange: (i) => x({ ...s, minValue: i.target.value }),
896
+ style: C
897
+ }
898
+ )), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Max", /* @__PURE__ */ e.createElement(
899
+ "input",
900
+ {
901
+ type: "number",
902
+ value: s.maxValue === null || s.maxValue === void 0 ? "" : s.maxValue,
903
+ onChange: (i) => x({ ...s, maxValue: i.target.value }),
904
+ style: C
905
+ }
906
+ )), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "10px", fontWeight: 800, color: l.textSec, textTransform: "uppercase", letterSpacing: "0.4px" } }, "Decimals", /* @__PURE__ */ e.createElement(
907
+ "input",
908
+ {
909
+ type: "number",
910
+ min: "0",
911
+ max: "8",
912
+ value: s.precision === null || s.precision === void 0 ? "" : s.precision,
913
+ onChange: (i) => x({ ...s, precision: i.target.value }),
914
+ style: C
915
+ }
916
+ ))), (!s.kind || s.kind === "category") && (s.rules || []).map(
917
+ /** @param {any} [rule] @param {any} [ruleIndex] @returns {any} */
918
+ (i, k) => {
919
+ const w = i.condition || { op: "AND", clauses: [] }, B = w.clauses || [];
920
+ return /* @__PURE__ */ e.createElement("div", { key: i.id || k, style: {
921
+ border: `1px solid ${l.border}`,
922
+ borderRadius: "10px",
923
+ padding: "8px",
924
+ background: l.hover || "#F8FAFC",
925
+ display: "flex",
926
+ flexDirection: "column",
927
+ gap: "8px"
928
+ } }, /* @__PURE__ */ e.createElement("div", { style: { display: "grid", gridTemplateColumns: "1fr 78px 28px", gap: "8px", alignItems: "center" } }, /* @__PURE__ */ e.createElement(
929
+ "input",
930
+ {
931
+ value: i.label || "",
932
+ onChange: (_) => T(k, { ...i, label: _.target.value }),
933
+ style: C,
934
+ placeholder: "Category value"
935
+ }
936
+ ), /* @__PURE__ */ e.createElement(
937
+ re,
938
+ {
939
+ size: "sm",
940
+ "aria-label": "Rule condition combiner",
941
+ value: w.op || "AND",
942
+ onChange: (_) => T(k, { ...i, condition: { ...w, op: _.target.value } }),
943
+ style: C
944
+ },
945
+ /* @__PURE__ */ e.createElement("option", { value: "AND" }, "AND"),
946
+ /* @__PURE__ */ e.createElement("option", { value: "OR" }, "OR")
947
+ ), /* @__PURE__ */ e.createElement(
948
+ "button",
949
+ {
950
+ type: "button",
951
+ onClick: () => x({ ...s, rules: (s.rules || []).filter(
952
+ /** @param {any} [_] @param {any} [index] @returns {any} */
953
+ (_, N) => N !== k
954
+ ) }),
955
+ style: { ...D(), padding: "6px", justifyContent: "center", color: "#B91C1C" },
956
+ title: "Remove rule"
957
+ },
958
+ /* @__PURE__ */ e.createElement(F.Close, null)
959
+ )), B.map(
960
+ /** @param {any} [clause] @param {any} [clauseIndex] @returns {any} */
961
+ (_, N) => {
962
+ const L = sn.has(_.operator), m = Jt.has(_.operator);
963
+ return /* @__PURE__ */ e.createElement("div", { key: `${i.id || k}:${N}`, style: { display: "grid", gridTemplateColumns: L ? "1fr 130px 28px" : "1fr 130px 1fr 28px", gap: "6px", alignItems: "center" } }, /* @__PURE__ */ e.createElement(
964
+ re,
965
+ {
966
+ size: "sm",
967
+ "aria-label": "Clause field",
968
+ value: _.field || "",
969
+ onChange: ($) => U(k, N, { field: $.target.value }),
970
+ style: { ...C, width: "100%" }
971
+ },
972
+ P.map(
973
+ /** @param {any} [field] @returns {any} */
974
+ ($) => /* @__PURE__ */ e.createElement("option", { key: $, value: $ }, f($))
975
+ )
976
+ ), /* @__PURE__ */ e.createElement(
977
+ re,
978
+ {
979
+ size: "sm",
980
+ "aria-label": "Clause operator",
981
+ value: _.operator || "eq",
982
+ onChange: ($) => {
983
+ const E = $.target.value;
984
+ U(k, N, {
985
+ operator: E,
986
+ values: Jt.has(E) ? _.values && _.values.length ? _.values : er(_.value) : _.values
987
+ });
988
+ },
989
+ style: { ...C, width: "100%" }
990
+ },
991
+ on.map(($) => /* @__PURE__ */ e.createElement("option", { key: $.value, value: $.value }, $.label))
992
+ ), !L && /* @__PURE__ */ e.createElement(
993
+ "input",
994
+ {
995
+ value: m ? (_.values || []).join(", ") : _.value || "",
996
+ onChange: ($) => U(k, N, m ? { values: er($.target.value), value: $.target.value } : { value: $.target.value }),
997
+ style: C,
998
+ placeholder: m ? "A, B, C" : "Value"
999
+ }
1000
+ ), /* @__PURE__ */ e.createElement(
1001
+ "button",
1002
+ {
1003
+ type: "button",
1004
+ onClick: () => T(k, {
1005
+ ...i,
1006
+ condition: {
1007
+ ...w,
1008
+ clauses: B.filter(
1009
+ /** @param {any} [_] @param {any} [index] @returns {any} */
1010
+ ($, E) => E !== N
1011
+ )
1012
+ }
1013
+ }),
1014
+ style: { ...D(), padding: "6px", justifyContent: "center", color: "#B91C1C" },
1015
+ title: "Remove condition"
1016
+ },
1017
+ /* @__PURE__ */ e.createElement(F.Close, null)
1018
+ ));
1019
+ }
1020
+ ), /* @__PURE__ */ e.createElement(
1021
+ "button",
1022
+ {
1023
+ type: "button",
1024
+ onClick: () => T(k, {
1025
+ ...i,
1026
+ condition: {
1027
+ ...w,
1028
+ clauses: [...B, yr(P)]
1029
+ }
1030
+ }),
1031
+ style: { ...D(), alignSelf: "flex-start" }
1032
+ },
1033
+ "+ Condition"
1034
+ ));
1035
+ }
1036
+ ), (!s.kind || s.kind === "category") && /* @__PURE__ */ e.createElement(
1037
+ "button",
1038
+ {
1039
+ type: "button",
1040
+ onClick: () => x({
1041
+ ...s,
1042
+ rules: [...s.rules || [], br(P, (s.rules || []).length)]
1043
+ }),
1044
+ style: { ...D(), alignSelf: "flex-start" }
1045
+ },
1046
+ "+ Rule"
1047
+ ), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", justifyContent: "flex-end", gap: "8px" } }, /* @__PURE__ */ e.createElement("button", { type: "button", onClick: () => x(null), style: D() }, "Cancel"), /* @__PURE__ */ e.createElement("button", { type: "button", onClick: R, style: D("primary") }, s.kind === "date_group" || s.kind === "number_group" ? "Apply Group" : "Apply Category")))
1048
+ )
1049
+ ));
1050
+ }
1051
+ function hr(r) {
1052
+ const n = [], o = /* @__PURE__ */ new Set();
1053
+ return String(r || "").replace(ct, (a, l) => {
1054
+ const p = String(l || "").trim();
1055
+ return p && !o.has(p) && (n.push(p), o.add(p)), "";
1056
+ }), n;
1057
+ }
1058
+ function lr(r, n = []) {
1059
+ const o = String(r || ""), a = [], l = /* @__PURE__ */ new Set(), p = (g) => {
1060
+ const z = String(g || "").trim();
1061
+ !z || l.has(z) || (a.push(z), l.add(z));
1062
+ };
1063
+ hr(o).forEach(p);
1064
+ let f = o.replace(ct, " ");
1065
+ return (Array.isArray(n) ? n : Array.from(n || [])).map((g) => String(g || "").trim()).filter((g) => g && !gr.test(g)).sort((g, z) => z.length - g.length).forEach(
1066
+ /** @param {any} [reference] @returns {any} */
1067
+ (g) => {
1068
+ const z = new RegExp(`(^|[^A-Za-z0-9_])${xr(g)}(?=$|[^A-Za-z0-9_])`, "g");
1069
+ f = f.replace(
1070
+ z,
1071
+ /** @param {any} [match] @param {any} [prefix] @returns {any} */
1072
+ (s, x) => (p(g), `${x} `)
1073
+ );
1074
+ }
1075
+ ), f.replace(
1076
+ mr,
1077
+ /** @param {any} [token] @param {any} [offset] @returns {any} */
1078
+ (g, z) => {
1079
+ const s = f.slice(z + g.length).trimStart();
1080
+ return an.has(g) || ln.has(g) && s.startsWith("(") || p(g), g;
1081
+ }
1082
+ ), a;
1083
+ }
1084
+ function ie(r) {
1085
+ const n = String(r || "").trim();
1086
+ return n ? `[${n}]` : "";
1087
+ }
1088
+ function ze(r) {
1089
+ const n = String(r || "").trim();
1090
+ return n ? gr.test(n) ? n : `[${n}]` : "";
1091
+ }
1092
+ function bn(r, n, o = "formula") {
1093
+ const a = Me(r, o), l = new Set(
1094
+ (Array.isArray(n) ? n : []).map((S) => S ? S.agg === "formula" ? q(S) : S.field : null).filter(Boolean).map((S) => String(S).toLowerCase())
1095
+ );
1096
+ if (!l.has(a)) return a;
1097
+ let p = 2, f = `${a}${p}`;
1098
+ for (; l.has(f); )
1099
+ p += 1, f = `${a}${p}`;
1100
+ return f;
1101
+ }
1102
+ function En(r, n, o) {
1103
+ if (!r || !n || n === o) return r;
1104
+ const a = ze(o), l = [];
1105
+ let f = String(r).replace(ct, (S, g) => String(g || "").trim() === n ? a : (l.push(S), `@@${l.length - 1}@@`)).replace(new RegExp(`\\b${xr(n)}\\b`, "g"), a);
1106
+ return l.forEach((S, g) => {
1107
+ f = f.replace(`@@${g}@@`, S);
1108
+ }), f;
1109
+ }
1110
+ function wt(r, n, o) {
1111
+ r(
1112
+ /** @param {any} [prev] @returns {any} */
1113
+ (a) => {
1114
+ const l = [...a];
1115
+ return l[n] ? (l[n] = o(l[n]), l) : a;
1116
+ }
1117
+ );
1118
+ }
1119
+ function ar(r) {
1120
+ return !r || typeof r.closest != "function" ? !1 : !!r.closest('button, input, select, textarea, [contenteditable="true"]');
1121
+ }
1122
+ function hn(r) {
1123
+ if (!r || typeof r != "object") return "";
1124
+ const n = r.field === void 0 || r.field === null ? "" : String(r.field), o = r.agg === void 0 || r.agg === null ? "" : String(r.agg);
1125
+ return `${n}::${o}`;
1126
+ }
1127
+ function Ct(r) {
1128
+ const n = rn(r);
1129
+ return n ? {
1130
+ ...Fe,
1131
+ ...n,
1132
+ header: n.header || "",
1133
+ color: n.color || "",
1134
+ positiveColor: n.positiveColor || "",
1135
+ negativeColor: n.negativeColor || ""
1136
+ } : null;
1137
+ }
1138
+ function vn(r) {
1139
+ const n = {
1140
+ ...Fe,
1141
+ ...r || {}
1142
+ }, o = {
1143
+ type: n.type || Fe.type,
1144
+ metric: n.metric || Fe.metric,
1145
+ showCurrentValue: n.showCurrentValue !== !1,
1146
+ showDelta: n.showDelta !== !1,
1147
+ compact: !!n.compact,
1148
+ hideColumns: !!n.hideColumns,
1149
+ placement: "before",
1150
+ source: n.source === "field" ? "field" : "pivot",
1151
+ displayMode: n.displayMode === "value" ? "value" : "trend"
1152
+ };
1153
+ return ["header", "color", "positiveColor", "negativeColor"].forEach((a) => {
1154
+ const l = typeof n[a] == "string" ? n[a].trim() : "";
1155
+ l && (o[a] = l);
1156
+ }), Number.isFinite(Number(n.areaOpacity)) && (o.areaOpacity = Math.max(0.02, Math.min(0.45, Number(n.areaOpacity)))), o;
1157
+ }
1158
+ function vr(r, n = []) {
1159
+ const o = String(r && r.agg || "").trim().toLowerCase(), a = Array.isArray(n) && n.length > 0, l = o === "array_agg", p = o !== "array_agg" && a;
1160
+ return {
1161
+ canUseFieldSeries: l,
1162
+ canUsePivotSeries: p,
1163
+ canUseAny: l || p,
1164
+ defaultSource: l ? "field" : p ? "pivot" : null
1165
+ };
1166
+ }
1167
+ function Dt(r, n) {
1168
+ return !n || !n.canUseAny ? !1 : r === "field" ? n.canUseFieldSeries : n.canUsePivotSeries;
1169
+ }
1170
+ function Sr(r, n) {
1171
+ const o = vn(r);
1172
+ return !n || !n.canUseAny ? null : Dt(o.source, n) ? o : {
1173
+ ...o,
1174
+ source: n.defaultSource
1175
+ };
1176
+ }
1177
+ function Rt(r) {
1178
+ if (!Array.isArray(r) || r.length === 0) return "";
1179
+ const n = r.map((o) => o && ze(o.field)).filter(Boolean);
1180
+ return n.length === 0 ? "" : n.length === 1 ? `${n[0]} * 100` : `${n[0]} - ${n[1]}`;
1181
+ }
1182
+ function or(r) {
1183
+ const n = (Array.isArray(r) ? r : []).map((o) => o && o.id).filter(Boolean);
1184
+ return n.length === 0 ? "" : n.length === 1 ? `${ie(n[0])} * 100` : `${ie(n[0])} - ${ie(n[1])}`;
1185
+ }
1186
+ function Sn(r) {
1187
+ const n = new Set(
1188
+ (Array.isArray(r) ? r : []).map((a) => a && a.field).filter(Boolean)
1189
+ );
1190
+ let o = 1;
1191
+ for (; n.has(`formula_${o}`); ) o += 1;
1192
+ return `formula_${o}`;
1193
+ }
1194
+ function kn(r, n, o = null, a = null, l = "measures", p = [], f = []) {
1195
+ const S = String(r || "").trim(), g = $e(l);
1196
+ if (!S)
1197
+ return {
1198
+ tone: "warning",
1199
+ text: g ? "Enter a formula using bracketed rendered columns. Example: [Cash Equity_day_pnl_sum] - [ETF_day_pnl_sum]" : "Enter a formula using value fields. Example: sales - [day pnl]"
1200
+ };
1201
+ let z = 0;
1202
+ for (const R of S)
1203
+ if (R === "(" && (z += 1), R === ")" && (z -= 1), z < 0)
1204
+ return { tone: "warning", text: "Parentheses are unbalanced." };
1205
+ if (z !== 0)
1206
+ return { tone: "warning", text: "Parentheses are unbalanced." };
1207
+ if (g) {
1208
+ const R = Array.isArray(p) ? p : [], O = new Set(
1209
+ R.map(
1210
+ /** @param {any} [option] @returns {any} */
1211
+ (B) => B && B.id
1212
+ ).filter(Boolean)
1213
+ ), i = hr(S);
1214
+ if (i.length === 0)
1215
+ return {
1216
+ tone: "warning",
1217
+ text: "Insert at least one rendered column reference like [column_id]."
1218
+ };
1219
+ const k = S.replace(ct, ""), w = Array.from(new Set(k.match(mr) || []));
1220
+ if (w.length > 0)
1221
+ return {
1222
+ tone: "warning",
1223
+ text: `Rendered columns must use brackets: ${w.join(", ")}`
1224
+ };
1225
+ if (O.size > 0) {
1226
+ const B = i.filter(
1227
+ /** @param {any} [columnId] @returns {any} */
1228
+ (_) => !O.has(_)
1229
+ );
1230
+ if (B.length > 0)
1231
+ return {
1232
+ tone: "warning",
1233
+ text: `Unknown rendered columns: ${B.join(", ")}`
1234
+ };
1235
+ }
1236
+ return o && i.includes(o) ? {
1237
+ tone: "warning",
1238
+ text: "A displayed-column formula cannot reference its own output column."
1239
+ } : {
1240
+ tone: "success",
1241
+ text: `Using rendered columns: ${i.join(", ")}`
1242
+ };
1243
+ }
1244
+ const s = Array.isArray(n) ? n.filter((R) => R && R.field) : [];
1245
+ if (s.length === 0)
1246
+ return {
1247
+ tone: "warning",
1248
+ text: "Add at least one value or formula reference before creating formulas."
1249
+ };
1250
+ const x = s.filter(
1251
+ /** @param {any} [config] @returns {any} */
1252
+ (R) => R.agg === "formula"
1253
+ ), W = /* @__PURE__ */ new Map();
1254
+ x.forEach(
1255
+ /** @param {any} [config] @returns {any} */
1256
+ (R) => {
1257
+ const O = R.field === o ? Me(a || q(R), R.field) : q(R);
1258
+ O && (W.set(O, O), W.set(O.toLowerCase(), O));
1259
+ }
1260
+ );
1261
+ const P = s.filter(
1262
+ /** @param {any} [config] @returns {any} */
1263
+ (R) => R.agg !== "formula"
1264
+ ).map(
1265
+ /** @param {any} [config] @returns {any} */
1266
+ (R) => R.field
1267
+ ).filter(Boolean), M = new Set(P), A = /* @__PURE__ */ new Set([...P, ...x.map(
1268
+ /** @param {any} [config] @returns {any} */
1269
+ (R) => R.field === o ? Me(a || q(R), R.field) : q(R)
1270
+ ).filter(Boolean), ...Array.isArray(f) ? f : []]), y = Array.from(A), C = lr(S, y), D = C.map(
1271
+ /** @param {any} [token] @returns {any} */
1272
+ (R) => W.get(R) || W.get(R.toLowerCase()) || R
1273
+ ), T = D.filter(
1274
+ /** @param {any} [token] @returns {any} */
1275
+ (R) => !A.has(R) && !M.has(R)
1276
+ );
1277
+ if (T.length > 0)
1278
+ return {
1279
+ tone: "warning",
1280
+ text: `Unknown fields: ${T.join(", ")}`
1281
+ };
1282
+ const U = o ? Me(a || o, o) : null;
1283
+ if (o && U && s.some(
1284
+ /** @param {any} [config] @returns {any} */
1285
+ (O) => {
1286
+ if (!O || O.field === o) return !1;
1287
+ const i = O.agg === "formula" ? q(O) : O.field;
1288
+ return String(i || "").toLowerCase() === U.toLowerCase();
1289
+ }
1290
+ ))
1291
+ return {
1292
+ tone: "warning",
1293
+ text: `Reference key "${U}" is already in use.`
1294
+ };
1295
+ if (U && D.includes(U))
1296
+ return {
1297
+ tone: "warning",
1298
+ text: "A formula cannot reference itself."
1299
+ };
1300
+ if (o && U) {
1301
+ const R = {};
1302
+ x.forEach(
1303
+ /** @param {any} [config] @returns {any} */
1304
+ (w) => {
1305
+ const B = w.field === o ? U : q(w), _ = w.field === o ? S : String(w.formula || ""), N = lr(_, y).map(
1306
+ /** @param {any} [token] @returns {any} */
1307
+ (L) => W.get(L) || W.get(L.toLowerCase()) || L
1308
+ ).filter(
1309
+ /** @param {any} [token] @returns {any} */
1310
+ (L) => L !== B && x.some(
1311
+ /** @param {any} [candidate] @returns {any} */
1312
+ (m) => q(m) === L || m.field === o && U === L
1313
+ )
1314
+ );
1315
+ R[B] = N;
1316
+ }
1317
+ );
1318
+ const O = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), k = (w) => {
1319
+ if (O.has(w)) return !0;
1320
+ if (i.has(w)) return !1;
1321
+ O.add(w);
1322
+ const B = R[w] || [];
1323
+ for (const _ of B)
1324
+ if (k(_)) return !0;
1325
+ return O.delete(w), i.add(w), !1;
1326
+ };
1327
+ if (k(U))
1328
+ return {
1329
+ tone: "warning",
1330
+ text: "Circular formula reference detected."
1331
+ };
1332
+ }
1333
+ return C.length === 0 ? {
1334
+ tone: "warning",
1335
+ text: "Insert at least one measure or formula reference."
1336
+ } : {
1337
+ tone: "success",
1338
+ text: `Using ${D.join(", ")}`
1339
+ };
1340
+ }
1341
+ function wn(r) {
1342
+ if (!Array.isArray(r) || r.length === 0) return [];
1343
+ const n = r.map((o) => o && ze(o.field)).filter(Boolean);
1344
+ return n.length === 0 ? [] : n.length === 1 ? [{ label: "Scale x100", value: `${n[0]} * 100` }] : [
1345
+ { label: "Difference", value: `${n[0]} - ${n[1]}` },
1346
+ { label: "Ratio %", value: `(${n[0]} / ${n[1]}) * 100` },
1347
+ { label: "Margin %", value: `((${n[0]} - ${n[1]}) / ${n[0]}) * 100` }
1348
+ ];
1349
+ }
1350
+ function Cn(r) {
1351
+ const n = (Array.isArray(r) ? r : []).map((o) => o && o.id).filter(Boolean);
1352
+ return n.length === 0 ? [] : n.length === 1 ? [{ label: "Scale x100", value: `${ie(n[0])} * 100` }] : [
1353
+ { label: "Difference", value: `${ie(n[0])} - ${ie(n[1])}` },
1354
+ { label: "Ratio %", value: `(${ie(n[0])} / ${ie(n[1])}) * 100` },
1355
+ { label: "Spread %", value: `((${ie(n[0])} - ${ie(n[1])}) / ${ie(n[0])}) * 100` }
1356
+ ];
1357
+ }
1358
+ function Rn(r, n) {
1359
+ const o = {
1360
+ muted: {
1361
+ text: r.textSec,
1362
+ border: r.border,
1363
+ background: r.headerSubtleBg || r.background
1364
+ },
1365
+ success: {
1366
+ text: r.primary,
1367
+ border: `${r.primary}33`,
1368
+ background: `${r.primary}10`
1369
+ },
1370
+ warning: {
1371
+ text: "#B45309",
1372
+ border: "#F59E0B55",
1373
+ background: "#F59E0B12"
1374
+ }
1375
+ };
1376
+ return o[n] || o.muted;
1377
+ }
1378
+ function Dn({ item: r, idx: n, setValConfigs: o, theme: a, colFields: l = [], onClose: p }) {
1379
+ const f = e.useMemo(
1380
+ () => Ct(r && r.sparkline) || { ...Fe },
1381
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1382
+ [r && r.sparkline]
1383
+ ), S = e.useMemo(
1384
+ () => vr(r, l),
1385
+ [l, r]
1386
+ ), g = e.useMemo(() => {
1387
+ const y = [];
1388
+ return S.canUsePivotSeries && y.push({ value: "pivot", label: "Linked pivot" }), S.canUseFieldSeries && y.push({ value: "field", label: "Series field" }), y;
1389
+ }, [S]), z = Dt(f.source || "pivot", S) ? f.source || "pivot" : S.defaultSource, s = e.useCallback((y) => {
1390
+ wt(
1391
+ o,
1392
+ n,
1393
+ /** @param {any} [current] @returns {any} */
1394
+ (C) => {
1395
+ const D = Ct(C.sparkline) || { ...Fe }, T = Sr({ ...D, ...y }, S);
1396
+ return T ? {
1397
+ ...C,
1398
+ sparkline: T
1399
+ } : C;
1400
+ }
1401
+ );
1402
+ }, [S, n, o]), x = e.useCallback((y) => y.stopPropagation(), []), W = [
1403
+ { value: "line", label: "Line" },
1404
+ { value: "area", label: "Area" },
1405
+ { value: "column", label: "Column" },
1406
+ { value: "bar", label: "Bar" }
1407
+ ], P = {
1408
+ background: a.background,
1409
+ border: `1px solid ${a.border}`,
1410
+ borderRadius: "5px",
1411
+ color: a.text,
1412
+ fontSize: "11px",
1413
+ padding: "4px 7px",
1414
+ outline: "none",
1415
+ width: "100%",
1416
+ boxSizing: "border-box"
1417
+ }, M = {
1418
+ fontSize: "10px",
1419
+ fontWeight: 700,
1420
+ letterSpacing: "0.06em",
1421
+ color: a.textSec,
1422
+ textTransform: "uppercase",
1423
+ marginBottom: "6px",
1424
+ display: "block"
1425
+ }, A = {
1426
+ marginBottom: "14px"
1427
+ };
1428
+ return /* @__PURE__ */ e.createElement(
1429
+ "div",
1430
+ {
1431
+ style: { position: "fixed", inset: 0, background: "rgba(0,0,0,0.45)", zIndex: 9999, display: "flex", alignItems: "center", justifyContent: "center" },
1432
+ onMouseDown: x,
1433
+ onClick: p
1434
+ },
1435
+ /* @__PURE__ */ e.createElement(
1436
+ "div",
1437
+ {
1438
+ onClick: x,
1439
+ style: {
1440
+ background: a.background,
1441
+ border: `1px solid ${a.border}`,
1442
+ borderRadius: "12px",
1443
+ boxShadow: "0 8px 32px rgba(0,0,0,0.22)",
1444
+ width: "320px",
1445
+ maxHeight: "80vh",
1446
+ overflow: "auto",
1447
+ padding: "18px 20px 16px",
1448
+ fontFamily: "'Inter', ui-sans-serif, system-ui, sans-serif"
1449
+ }
1450
+ },
1451
+ /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: "16px" } }, /* @__PURE__ */ e.createElement("span", { style: { fontSize: "13px", fontWeight: 700, color: a.text } }, "Sparkline Column"), /* @__PURE__ */ e.createElement(
1452
+ "button",
1453
+ {
1454
+ type: "button",
1455
+ onClick: p,
1456
+ style: { background: "none", border: "none", cursor: "pointer", color: a.textSec, fontSize: "18px", lineHeight: 1, padding: "2px 4px" }
1457
+ },
1458
+ "×"
1459
+ )),
1460
+ /* @__PURE__ */ e.createElement("div", { style: A }, /* @__PURE__ */ e.createElement("span", { style: M }, "Data source"), g.length > 0 ? /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "4px" } }, g.map(
1461
+ /** @param {any} p0 @returns {any} */
1462
+ ({ value: y, label: C }) => /* @__PURE__ */ e.createElement(
1463
+ "button",
1464
+ {
1465
+ key: y,
1466
+ type: "button",
1467
+ onClick: () => s({ source: y }),
1468
+ style: {
1469
+ flex: 1,
1470
+ padding: "4px 0",
1471
+ fontSize: "11px",
1472
+ fontWeight: 600,
1473
+ borderRadius: "6px",
1474
+ cursor: "pointer",
1475
+ border: `1px solid ${z === y ? a.primary : a.border}`,
1476
+ background: z === y ? `${a.primary}18` : a.headerSubtleBg || a.background,
1477
+ color: z === y ? a.primary : a.textSec
1478
+ }
1479
+ },
1480
+ C
1481
+ )
1482
+ )), /* @__PURE__ */ e.createElement("div", { style: { marginTop: "5px", fontSize: "10px", color: a.textSec, lineHeight: 1.4 } }, z === "pivot" ? "Trend values are collected across the pivot columns. Source value cells stay numeric unless hidden." : "Each cell already contains the full data series for its row.")) : /* @__PURE__ */ e.createElement(
1483
+ "div",
1484
+ {
1485
+ "data-value-sparkline-unavailable": "true",
1486
+ style: {
1487
+ padding: "7px 8px",
1488
+ borderRadius: "6px",
1489
+ border: `1px solid ${a.warning || "#F59E0B"}55`,
1490
+ background: `${a.warning || "#F59E0B"}12`,
1491
+ color: a.text,
1492
+ fontSize: "10px",
1493
+ lineHeight: 1.45
1494
+ }
1495
+ },
1496
+ "Add a column field for linked trends, or use the Series aggregation for field data."
1497
+ )),
1498
+ z === "field" && /* @__PURE__ */ e.createElement("div", { style: A }, /* @__PURE__ */ e.createElement("span", { style: M }, "Cell display"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "4px" } }, [
1499
+ { value: "trend", label: "Trendline" },
1500
+ { value: "value", label: "Value" }
1501
+ ].map(({ value: y, label: C }) => /* @__PURE__ */ e.createElement(
1502
+ "button",
1503
+ {
1504
+ key: y,
1505
+ type: "button",
1506
+ onClick: () => s({ displayMode: y }),
1507
+ style: {
1508
+ flex: 1,
1509
+ padding: "4px 0",
1510
+ fontSize: "11px",
1511
+ fontWeight: 600,
1512
+ borderRadius: "6px",
1513
+ cursor: "pointer",
1514
+ border: `1px solid ${(f.displayMode || "trend") === y ? a.primary : a.border}`,
1515
+ background: (f.displayMode || "trend") === y ? `${a.primary}18` : a.headerSubtleBg || a.background,
1516
+ color: (f.displayMode || "trend") === y ? a.primary : a.textSec
1517
+ }
1518
+ },
1519
+ C
1520
+ ))), /* @__PURE__ */ e.createElement("div", { style: { marginTop: "5px", fontSize: "10px", color: a.textSec, lineHeight: 1.4 } }, (f.displayMode || "trend") === "value" ? "Show the selected summary metric from the series." : "Draw the series in the cell.")),
1521
+ /* @__PURE__ */ e.createElement("div", { style: A }, /* @__PURE__ */ e.createElement("span", { style: M }, "Chart type"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "4px" } }, W.map(({ value: y, label: C }) => /* @__PURE__ */ e.createElement(
1522
+ "button",
1523
+ {
1524
+ key: y,
1525
+ type: "button",
1526
+ onClick: () => s({ type: y }),
1527
+ style: {
1528
+ flex: 1,
1529
+ padding: "4px 0",
1530
+ fontSize: "11px",
1531
+ fontWeight: 600,
1532
+ borderRadius: "6px",
1533
+ cursor: "pointer",
1534
+ border: `1px solid ${f.type === y ? a.primary : a.border}`,
1535
+ background: f.type === y ? `${a.primary}18` : a.headerSubtleBg || a.background,
1536
+ color: f.type === y ? a.primary : a.textSec
1537
+ }
1538
+ },
1539
+ C
1540
+ )))),
1541
+ /* @__PURE__ */ e.createElement("div", { style: A }, /* @__PURE__ */ e.createElement("span", { style: M }, "Summary metric"), /* @__PURE__ */ e.createElement(
1542
+ re,
1543
+ {
1544
+ size: "sm",
1545
+ "aria-label": "Summary metric",
1546
+ value: f.metric,
1547
+ onChange: (y) => s({ metric: y.target.value }),
1548
+ style: { ...P, cursor: "pointer", width: "100%" }
1549
+ },
1550
+ /* @__PURE__ */ e.createElement("option", { value: "last" }, "Last value"),
1551
+ /* @__PURE__ */ e.createElement("option", { value: "first" }, "First value"),
1552
+ /* @__PURE__ */ e.createElement("option", { value: "min" }, "Minimum"),
1553
+ /* @__PURE__ */ e.createElement("option", { value: "max" }, "Maximum"),
1554
+ /* @__PURE__ */ e.createElement("option", { value: "avg" }, "Average"),
1555
+ /* @__PURE__ */ e.createElement("option", { value: "sum" }, "Sum"),
1556
+ /* @__PURE__ */ e.createElement("option", { value: "delta" }, "Delta (last − first)")
1557
+ )),
1558
+ /* @__PURE__ */ e.createElement("div", { style: A }, /* @__PURE__ */ e.createElement("span", { style: M }, "Display"), /* @__PURE__ */ e.createElement("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: "6px" } }, [
1559
+ { key: "showCurrentValue", label: "Value label" },
1560
+ { key: "showDelta", label: "Delta label" },
1561
+ { key: "compact", label: "Compact cell" },
1562
+ { key: "hideColumns", label: "Hide source values" }
1563
+ ].map(({ key: y, label: C }) => /* @__PURE__ */ e.createElement("label", { key: y, style: { display: "flex", alignItems: "center", gap: "5px", fontSize: "11px", color: a.text, cursor: "pointer", userSelect: "none" } }, /* @__PURE__ */ e.createElement(
1564
+ "input",
1565
+ {
1566
+ type: "checkbox",
1567
+ checked: !!f[y],
1568
+ onChange: (D) => s({ [y]: D.target.checked }),
1569
+ style: { accentColor: a.primary, width: "13px", height: "13px", cursor: "pointer" }
1570
+ }
1571
+ ), C))), f.hideColumns && /* @__PURE__ */ e.createElement("div", { style: { marginTop: "6px", fontSize: "10px", color: a.textSec, background: `${a.primary}10`, border: `1px solid ${a.primary}30`, borderRadius: "6px", padding: "5px 8px", lineHeight: 1.4 } }, "Source value columns are hidden; the trend column remains."), !f.hideColumns && z === "pivot" && /* @__PURE__ */ e.createElement("div", { style: { marginTop: "6px", fontSize: "10px", color: a.textSec, background: a.headerSubtleBg || a.background, border: `1px solid ${a.border}`, borderRadius: "6px", padding: "5px 8px", lineHeight: 1.4 } }, "Source value columns stay numeric; the trend column is added beside them.")),
1572
+ z === "pivot" && /* @__PURE__ */ e.createElement("div", { style: A }, /* @__PURE__ */ e.createElement("span", { style: M }, "Position"), /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: a.textSec, lineHeight: 1.4, background: a.headerSubtleBg || a.background, border: `1px solid ${a.border}`, borderRadius: "6px", padding: "6px 8px" } }, "Trend columns are placed before the matching value columns.")),
1573
+ /* @__PURE__ */ e.createElement("div", { style: A }, /* @__PURE__ */ e.createElement("span", { style: M }, "Colors"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "6px" } }, [
1574
+ { key: "color", label: "Line / fill color", always: !0 },
1575
+ { key: "positiveColor", label: "Positive bar color", always: !1 },
1576
+ { key: "negativeColor", label: "Negative bar color", always: !1 }
1577
+ ].filter(({ always: y }) => y || f.type === "column" || f.type === "bar").map(({ key: y, label: C }) => /* @__PURE__ */ e.createElement("div", { key: y }, /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: a.textSec, marginBottom: "3px", display: "block" } }, C), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "5px", alignItems: "center" } }, /* @__PURE__ */ e.createElement(
1578
+ "input",
1579
+ {
1580
+ type: "color",
1581
+ value: f[y] || (y === "negativeColor" ? "#B91C1C" : y === "positiveColor" ? "#2F855A" : "#2563EB"),
1582
+ onChange: (D) => s({ [y]: D.target.value }),
1583
+ style: { width: "28px", height: "26px", padding: "1px 2px", border: `1px solid ${a.border}`, borderRadius: "4px", cursor: "pointer", background: "none" }
1584
+ }
1585
+ ), /* @__PURE__ */ e.createElement(
1586
+ "input",
1587
+ {
1588
+ type: "text",
1589
+ value: f[y] || "",
1590
+ onChange: (D) => s({ [y]: D.target.value }),
1591
+ placeholder: "Auto",
1592
+ style: { ...P, flex: 1 }
1593
+ }
1594
+ ), f[y] && /* @__PURE__ */ e.createElement(
1595
+ "button",
1596
+ {
1597
+ type: "button",
1598
+ onClick: () => s({ [y]: "" }),
1599
+ style: { background: "none", border: "none", cursor: "pointer", color: a.textSec, fontSize: "14px", lineHeight: 1, padding: "2px" },
1600
+ title: "Reset to auto"
1601
+ },
1602
+ "×"
1603
+ )))))),
1604
+ f.type === "area" && /* @__PURE__ */ e.createElement("div", { style: A }, /* @__PURE__ */ e.createElement("span", { style: M }, "Area fill opacity"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "8px" } }, /* @__PURE__ */ e.createElement(
1605
+ "input",
1606
+ {
1607
+ type: "range",
1608
+ min: "0.02",
1609
+ max: "0.45",
1610
+ step: "0.01",
1611
+ value: f.areaOpacity != null ? f.areaOpacity : 0.14,
1612
+ onChange: (y) => s({ areaOpacity: Number(y.target.value) }),
1613
+ style: { flex: 1, accentColor: a.primary }
1614
+ }
1615
+ ), /* @__PURE__ */ e.createElement("span", { style: { fontSize: "11px", color: a.textSec, minWidth: "32px", textAlign: "right" } }, Math.round((f.areaOpacity != null ? f.areaOpacity : 0.14) * 100), "%"))),
1616
+ /* @__PURE__ */ e.createElement("div", { style: A }, /* @__PURE__ */ e.createElement("span", { style: M }, "Column header label"), /* @__PURE__ */ e.createElement(
1617
+ "input",
1618
+ {
1619
+ type: "text",
1620
+ value: f.header || "",
1621
+ onChange: (y) => s({ header: y.target.value }),
1622
+ placeholder: "Auto (e.g. Sales Trend)",
1623
+ style: P
1624
+ }
1625
+ )),
1626
+ /* @__PURE__ */ e.createElement("div", { style: { display: "flex", justifyContent: "flex-end" } }, /* @__PURE__ */ e.createElement(
1627
+ "button",
1628
+ {
1629
+ type: "button",
1630
+ onClick: p,
1631
+ style: {
1632
+ background: a.primary,
1633
+ color: "#fff",
1634
+ border: "none",
1635
+ borderRadius: "7px",
1636
+ padding: "6px 18px",
1637
+ fontSize: "12px",
1638
+ fontWeight: 700,
1639
+ cursor: "pointer"
1640
+ }
1641
+ },
1642
+ "Done"
1643
+ ))
1644
+ )
1645
+ );
1646
+ }
1647
+ function kr({ item: r, idx: n, setValConfigs: o, theme: a, colFields: l = [], fixedSparklineValueKeySet: p = /* @__PURE__ */ new Set(), showNotification: f }) {
1648
+ const [S, g] = e.useState(!1), z = Ct(r && r.sparkline), s = hn(r), x = !!(s && p && p.has(s)), W = e.useMemo(
1649
+ () => vr(r, l),
1650
+ [l, r]
1651
+ ), P = !!z, M = !!(z && Dt(z.source || "pivot", W)), A = e.useCallback((T) => T.stopPropagation(), []), y = e.useCallback(() => {
1652
+ let T = !1;
1653
+ return wt(
1654
+ o,
1655
+ n,
1656
+ /** @param {any} [current] @returns {any} */
1657
+ (U) => {
1658
+ const R = Sr(
1659
+ U.sparkline || Fe,
1660
+ W
1661
+ );
1662
+ return R ? (T = !0, { ...U, sparkline: R }) : U;
1663
+ }
1664
+ ), T;
1665
+ }, [W, n, o]), C = e.useCallback((T) => {
1666
+ if (T.stopPropagation(), P) {
1667
+ if (x) {
1668
+ f && f("This trend is defined by the app. You can adjust its settings, but not remove it here.", "info");
1669
+ return;
1670
+ }
1671
+ wt(
1672
+ o,
1673
+ n,
1674
+ /** @param {any} [current] @returns {any} */
1675
+ (U) => ({ ...U, sparkline: !1 })
1676
+ ), f && f("Removed trend column.", "info");
1677
+ } else W.canUseAny && y() ? (g(!0), f && f("Trend column enabled.", "success")) : f && f("Trend needs a column field, or a Series aggregation for field data.", "warning");
1678
+ }, [W.canUseAny, P, y, n, x, o, f]), D = e.useCallback((T) => {
1679
+ if (T.stopPropagation(), !W.canUseAny) {
1680
+ f && f("Trend settings are not available for this value selection.", "warning");
1681
+ return;
1682
+ }
1683
+ y(), g(!0);
1684
+ }, [W.canUseAny, y, f]);
1685
+ return P ? /* @__PURE__ */ e.createElement(
1686
+ "div",
1687
+ {
1688
+ "data-value-sparkline-controls": "true",
1689
+ "data-value-sparkline-available": W.canUseAny ? "true" : "false",
1690
+ "data-value-sparkline-enabled": M ? "true" : "false",
1691
+ onMouseDown: A,
1692
+ onClick: A,
1693
+ style: { marginTop: "6px", paddingTop: "6px", borderTop: `1px solid ${a.border}`, width: "100%", display: "flex", alignItems: "center", gap: "6px" }
1694
+ },
1695
+ /* @__PURE__ */ e.createElement(
1696
+ "button",
1697
+ {
1698
+ type: "button",
1699
+ "data-value-sparkline-settings": "true",
1700
+ onClick: D,
1701
+ style: {
1702
+ border: `1px solid ${a.border}`,
1703
+ background: a.headerSubtleBg || a.background,
1704
+ color: a.textSec,
1705
+ borderRadius: "6px",
1706
+ cursor: "pointer",
1707
+ padding: "3px 8px",
1708
+ fontSize: "10px",
1709
+ lineHeight: "16px",
1710
+ fontWeight: 600,
1711
+ flexShrink: 0
1712
+ },
1713
+ title: "Configure sparkline"
1714
+ },
1715
+ "Settings"
1716
+ ),
1717
+ x && /* @__PURE__ */ e.createElement(
1718
+ "span",
1719
+ {
1720
+ "data-value-sparkline-fixed": "true",
1721
+ style: { fontSize: "10px", color: a.textSec, flexShrink: 0 },
1722
+ title: "This trend is defined by the app"
1723
+ },
1724
+ "App trend"
1725
+ ),
1726
+ !x && /* @__PURE__ */ e.createElement(
1727
+ "button",
1728
+ {
1729
+ type: "button",
1730
+ "data-value-sparkline-toggle": "true",
1731
+ onClick: C,
1732
+ style: {
1733
+ border: `1px solid ${a.border}`,
1734
+ background: a.background,
1735
+ color: a.textSec,
1736
+ borderRadius: "6px",
1737
+ cursor: "pointer",
1738
+ padding: "3px 8px",
1739
+ fontSize: "10px",
1740
+ lineHeight: "16px",
1741
+ fontWeight: 600,
1742
+ flexShrink: 0
1743
+ },
1744
+ title: "Remove trend"
1745
+ },
1746
+ "Remove Trend"
1747
+ ),
1748
+ M && !S && /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: a.primary, flex: 1, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, (r.sparkline && r.sparkline.source) === "field" ? `series ${(r.sparkline && r.sparkline.displayMode) === "value" ? "value" : "trend"}` : "linked pivot", " | ", ["line", "area", "column", "bar"].includes(r.sparkline && r.sparkline.type) ? r.sparkline.type : "line", " | ", r.sparkline && r.sparkline.metric || "last"),
1749
+ S && /* @__PURE__ */ e.createElement(
1750
+ Dn,
1751
+ {
1752
+ item: r,
1753
+ idx: n,
1754
+ setValConfigs: o,
1755
+ theme: a,
1756
+ colFields: l,
1757
+ onClose: () => g(!1)
1758
+ }
1759
+ )
1760
+ ) : null;
1761
+ }
1762
+ function ir({ item: r, idx: n, selected: o, onSelect: a, onRemove: l, setValConfigs: p, theme: f, styles: S, dropLine: g, zoneId: z, valueSelectStyle: s, colFields: x = [], fixedSparklineValueKeySet: W = /* @__PURE__ */ new Set(), showNotification: P, serverError: M = null }) {
1763
+ const A = o ? `${f.primary}77` : M ? "#F59E0B88" : f.border, y = o ? f.headerBg || `${f.primary}0f` : f.background || "transparent", C = String(r.formula || "").trim() || "Empty formula";
1764
+ return /* @__PURE__ */ e.createElement(
1765
+ "div",
1766
+ {
1767
+ onClick: () => a(r.field),
1768
+ style: {
1769
+ ...S.chip,
1770
+ border: `1px solid ${A}`,
1771
+ background: y,
1772
+ borderLeft: o ? `3px solid ${f.primary}` : "3px solid transparent",
1773
+ boxShadow: "none",
1774
+ cursor: "pointer",
1775
+ flexWrap: "wrap",
1776
+ alignItems: "flex-start"
1777
+ },
1778
+ title: "Select formula"
1779
+ },
1780
+ g && g.zone === z && g.idx === n && /* @__PURE__ */ e.createElement("div", { className: "sp-drop-line", style: { ...S.dropLine, top: -2 } }),
1781
+ /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "8px", minWidth: 0, flex: 1 } }, /* @__PURE__ */ e.createElement(F.DragIndicator, null), /* @__PURE__ */ e.createElement("span", { style: {
1782
+ fontSize: "10px",
1783
+ fontWeight: 700,
1784
+ color: f.primary,
1785
+ background: `${f.primary}18`,
1786
+ borderRadius: "999px",
1787
+ padding: "3px 7px",
1788
+ letterSpacing: "0.5px",
1789
+ flexShrink: 0
1790
+ } }, "fx"), /* @__PURE__ */ e.createElement("div", { style: { minWidth: 0, flex: 1 } }, /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "8px", minWidth: 0 } }, /* @__PURE__ */ e.createElement("b", { style: { fontWeight: 600, display: "block", minWidth: 0, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, r.label || "Formula"), /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: f.textSec, fontFamily: "monospace", flexShrink: 0 } }, q(r)), /* @__PURE__ */ e.createElement("span", { style: { fontSize: "9px", color: f.textSec, border: `1px solid ${f.border}`, borderRadius: "999px", padding: "1px 6px", flexShrink: 0 } }, $e(r.formulaScope) ? "columns" : "values")), /* @__PURE__ */ e.createElement("div", { style: {
1791
+ marginTop: "2px",
1792
+ fontSize: "10px",
1793
+ lineHeight: 1.35,
1794
+ color: f.textSec,
1795
+ fontFamily: "monospace",
1796
+ whiteSpace: "nowrap",
1797
+ overflow: "hidden",
1798
+ textOverflow: "ellipsis"
1799
+ } }, "=", C), M && /* @__PURE__ */ e.createElement("div", { style: { marginTop: "2px", fontSize: "9px", color: "#B45309" } }, "⚠ ", An[M] || M))),
1800
+ /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "4px", marginLeft: "8px", alignItems: "center", flexShrink: 0 } }, o && /* @__PURE__ */ e.createElement("span", { style: {
1801
+ fontSize: "9px",
1802
+ color: f.primary,
1803
+ background: `${f.primary}14`,
1804
+ borderRadius: "999px",
1805
+ padding: "2px 6px",
1806
+ flexShrink: 0
1807
+ } }, "Active"), /* @__PURE__ */ e.createElement(
1808
+ "span",
1809
+ {
1810
+ onClick: (D) => {
1811
+ D.stopPropagation(), l(n);
1812
+ },
1813
+ style: { cursor: "pointer", color: "#9CA3AF", display: "flex", alignItems: "center" }
1814
+ },
1815
+ /* @__PURE__ */ e.createElement(F.Close, null)
1816
+ )),
1817
+ /* @__PURE__ */ e.createElement(
1818
+ kr,
1819
+ {
1820
+ item: r,
1821
+ idx: n,
1822
+ setValConfigs: p,
1823
+ theme: f,
1824
+ valueSelectStyle: s,
1825
+ colFields: x,
1826
+ fixedSparklineValueKeySet: W,
1827
+ showNotification: P
1828
+ }
1829
+ ),
1830
+ g && g.zone === z && g.idx === n + 1 && /* @__PURE__ */ e.createElement("div", { className: "sp-drop-line", style: { ...S.dropLine, bottom: -2 } })
1831
+ );
1832
+ }
1833
+ const An = {
1834
+ self_reference: "Formula references itself (server)",
1835
+ circular_reference: "Circular dependency with another formula (server)",
1836
+ expression_error: "Expression could not be evaluated (server)",
1837
+ missing_reference: "Unknown field reference (server)"
1838
+ };
1839
+ function $n({ item: r, idx: n, valConfigs: o, setValConfigs: a, theme: l, onClose: p, onRemove: f, displayedColumnOptions: S = [], availableRawFields: g = [], serverError: z = null }) {
1840
+ const s = e.useRef(null), [x, W] = e.useState({
1841
+ label: r.label || "",
1842
+ formula: r.formula || "",
1843
+ formulaRef: q(r),
1844
+ formulaScope: Ne(r.formulaScope)
1845
+ }), P = e.useRef(r);
1846
+ P.current = r, e.useEffect(() => {
1847
+ const m = P.current;
1848
+ W({
1849
+ label: m.label || "",
1850
+ formula: m.formula || "",
1851
+ formulaRef: q(m),
1852
+ formulaScope: Ne(m.formulaScope)
1853
+ });
1854
+ }, [r.field]), e.useEffect(() => {
1855
+ if (!s.current) return;
1856
+ s.current.focus();
1857
+ const m = s.current.value.length;
1858
+ s.current.setSelectionRange(m, m);
1859
+ }, [r.field]);
1860
+ const M = e.useMemo(
1861
+ () => o.filter(
1862
+ /** @param {any} [config] @returns {any} */
1863
+ (m) => m && m.field
1864
+ ),
1865
+ [o]
1866
+ ), A = e.useMemo(
1867
+ () => M.filter(
1868
+ /** @param {any} [config] @returns {any} */
1869
+ (m) => m.agg !== "formula"
1870
+ ),
1871
+ [M]
1872
+ ), y = e.useMemo(
1873
+ () => M.filter(
1874
+ /** @param {any} [config] @returns {any} */
1875
+ (m) => m.agg === "formula" && m.field !== r.field
1876
+ ),
1877
+ [r.field, M]
1878
+ ), C = e.useMemo(
1879
+ () => (Array.isArray(S) ? S : []).filter((m) => m && m.id && m.id !== r.field),
1880
+ [S, r.field]
1881
+ ), D = e.useMemo(
1882
+ () => {
1883
+ const m = new Set(M.map(
1884
+ /** @param {any} [c] @returns {any} */
1885
+ ($) => $.field
1886
+ ).filter(Boolean));
1887
+ return (Array.isArray(g) ? g : []).filter(($) => !m.has($));
1888
+ },
1889
+ [g, M]
1890
+ ), T = e.useMemo(
1891
+ () => kn(
1892
+ x.formula,
1893
+ M,
1894
+ r.field,
1895
+ x.formulaRef,
1896
+ x.formulaScope,
1897
+ C,
1898
+ D
1899
+ ),
1900
+ [C, x.formula, x.formulaRef, x.formulaScope, r.field, M, D]
1901
+ ), U = e.useMemo(
1902
+ () => Rn(l, T.tone),
1903
+ [T.tone, l]
1904
+ ), R = e.useMemo(
1905
+ () => $e(x.formulaScope) ? Cn(C) : wn(A),
1906
+ [C, x.formulaScope, A]
1907
+ ), O = e.useMemo(
1908
+ () => $e(x.formulaScope) ? or(C) || "[column_id] - [other_column_id]" : Rt(A) || `${ze(x.formulaRef || r.field)} * 100`,
1909
+ [C, x.formulaRef, x.formulaScope, r.field, A]
1910
+ ), i = x.label !== (r.label || "") || x.formula !== (r.formula || "") || x.formulaRef !== q(r) || x.formulaScope !== Ne(r.formulaScope), k = e.useCallback(() => {
1911
+ const m = Me(x.formulaRef, r.field);
1912
+ a(
1913
+ /** @param {any} [prev] @returns {any} */
1914
+ ($) => {
1915
+ const E = [...$], j = E[n];
1916
+ if (!j) return $;
1917
+ const Z = q(j);
1918
+ let V = m;
1919
+ const J = new Set(
1920
+ E.filter((K, Q) => K && Q !== n).map((K) => K.agg === "formula" ? q(K) : K.field).filter(Boolean).map((K) => String(K).toLowerCase())
1921
+ );
1922
+ if (J.has(V.toLowerCase())) {
1923
+ let K = 2, Q = `${V}${K}`;
1924
+ for (; J.has(Q.toLowerCase()); )
1925
+ K += 1, Q = `${V}${K}`;
1926
+ V = Q;
1927
+ }
1928
+ if (E[n] = {
1929
+ ...j,
1930
+ label: x.label,
1931
+ formula: x.formula,
1932
+ formulaRef: V,
1933
+ formulaScope: x.formulaScope
1934
+ }, Z && Z !== V)
1935
+ for (let K = 0; K < E.length; K += 1) {
1936
+ if (K === n) continue;
1937
+ const Q = E[K];
1938
+ !Q || Q.agg !== "formula" || !Q.formula || (E[K] = {
1939
+ ...Q,
1940
+ formula: En(Q.formula, Z, V)
1941
+ });
1942
+ }
1943
+ return E;
1944
+ }
1945
+ );
1946
+ }, [x.formula, x.formulaRef, x.formulaScope, x.label, n, r.field, a]), w = e.useCallback(() => {
1947
+ W({
1948
+ label: r.label || "",
1949
+ formula: r.formula || "",
1950
+ formulaRef: q(r),
1951
+ formulaScope: Ne(r.formulaScope)
1952
+ }), p();
1953
+ }, [r.field, r.formula, r.formulaRef, r.formulaScope, r.label, p]), B = e.useCallback((m) => {
1954
+ const $ = s.current;
1955
+ if (!$) return;
1956
+ const E = x.formula || "", j = $.selectionStart ?? E.length, Z = $.selectionEnd ?? E.length, V = `${E.slice(0, j)}${m}${E.slice(Z)}`;
1957
+ W(
1958
+ /** @param {any} [prev] @returns {any} */
1959
+ (K) => ({ ...K, formula: V })
1960
+ );
1961
+ const J = j + m.length;
1962
+ setTimeout(() => {
1963
+ s.current && (s.current.focus(), s.current.setSelectionRange(J, J));
1964
+ }, 0);
1965
+ }, [x.formula]), _ = e.useCallback(() => {
1966
+ k(), p();
1967
+ }, [k, p]), N = {
1968
+ border: `1px solid ${l.border}`,
1969
+ background: l.background,
1970
+ color: l.text,
1971
+ borderRadius: "999px",
1972
+ cursor: "pointer",
1973
+ padding: "3px 9px",
1974
+ fontSize: "10px",
1975
+ lineHeight: "16px"
1976
+ }, L = {
1977
+ border: `1px solid ${l.border}`,
1978
+ background: l.headerSubtleBg || l.background,
1979
+ color: l.text,
1980
+ borderRadius: "6px",
1981
+ cursor: "pointer",
1982
+ padding: "3px 8px",
1983
+ fontSize: "10px",
1984
+ lineHeight: "16px",
1985
+ fontFamily: "monospace"
1986
+ };
1987
+ return /* @__PURE__ */ e.createElement(
1988
+ "div",
1989
+ {
1990
+ onClick: w,
1991
+ style: {
1992
+ position: "fixed",
1993
+ inset: 0,
1994
+ zIndex: 10006,
1995
+ background: "rgba(2, 6, 23, 0.45)",
1996
+ display: "flex",
1997
+ alignItems: "center",
1998
+ justifyContent: "center",
1999
+ padding: "24px"
2000
+ }
2001
+ },
2002
+ /* @__PURE__ */ e.createElement(
2003
+ "div",
2004
+ {
2005
+ onClick: (m) => m.stopPropagation(),
2006
+ onKeyDown: (m) => {
2007
+ m.key === "Escape" && w(), (m.ctrlKey || m.metaKey) && m.key === "Enter" && _();
2008
+ },
2009
+ style: {
2010
+ width: "min(760px, 92vw)",
2011
+ maxHeight: "80vh",
2012
+ overflowY: "auto",
2013
+ background: l.surfaceBg || l.background || "#fff",
2014
+ border: `1px solid ${l.border}`,
2015
+ borderRadius: l.radius || "16px",
2016
+ boxShadow: l.shadowMd || "0 18px 40px rgba(0,0,0,0.28)",
2017
+ padding: "18px"
2018
+ }
2019
+ },
2020
+ /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "12px", marginBottom: "14px" } }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "15px", fontWeight: 800, color: l.text } }, "Formula Editor"), /* @__PURE__ */ e.createElement("div", { style: { fontSize: "11px", color: l.textSec } }, "Use a stable reference key for formulas. Renaming the key updates dependent formulas.")), /* @__PURE__ */ e.createElement(
2021
+ "button",
2022
+ {
2023
+ type: "button",
2024
+ onClick: w,
2025
+ style: {
2026
+ border: `1px solid ${l.border}`,
2027
+ background: l.headerSubtleBg || l.background,
2028
+ color: l.text,
2029
+ borderRadius: "8px",
2030
+ padding: "7px 10px",
2031
+ fontSize: "11px",
2032
+ fontWeight: 700,
2033
+ cursor: "pointer"
2034
+ }
2035
+ },
2036
+ "Close"
2037
+ )),
2038
+ /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "12px", flexWrap: "wrap", marginBottom: "12px" } }, /* @__PURE__ */ e.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "4px", flex: 1, minWidth: "180px" } }, /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px" } }, "Label"), /* @__PURE__ */ e.createElement(
2039
+ "input",
2040
+ {
2041
+ value: x.label,
2042
+ onChange: (m) => W(
2043
+ /** @param {any} [prev] @returns {any} */
2044
+ ($) => ({ ...$, label: m.target.value })
2045
+ ),
2046
+ placeholder: "Formula label",
2047
+ style: {
2048
+ border: `1px solid ${l.border}`,
2049
+ background: l.background,
2050
+ color: l.text,
2051
+ borderRadius: "8px",
2052
+ padding: "8px 10px",
2053
+ fontSize: "12px",
2054
+ fontWeight: 600,
2055
+ outline: "none"
2056
+ }
2057
+ }
2058
+ )), /* @__PURE__ */ e.createElement("label", { style: { minWidth: "180px", flex: "0 0 auto", display: "flex", flexDirection: "column", gap: "4px" } }, /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px" } }, "Reference key"), /* @__PURE__ */ e.createElement(
2059
+ "input",
2060
+ {
2061
+ value: x.formulaRef,
2062
+ onChange: (m) => W(
2063
+ /** @param {any} [prev] @returns {any} */
2064
+ ($) => ({ ...$, formulaRef: Me(m.target.value, r.field) })
2065
+ ),
2066
+ placeholder: "formula1",
2067
+ style: {
2068
+ border: `1px solid ${l.border}`,
2069
+ background: l.headerSubtleBg || l.background,
2070
+ color: l.text,
2071
+ borderRadius: "8px",
2072
+ padding: "8px 10px",
2073
+ fontSize: "12px",
2074
+ fontFamily: "monospace",
2075
+ outline: "none"
2076
+ }
2077
+ }
2078
+ )), /* @__PURE__ */ e.createElement("label", { style: { minWidth: "180px", flex: "0 0 auto", display: "flex", flexDirection: "column", gap: "4px" } }, /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px" } }, "Formula type"), /* @__PURE__ */ e.createElement(
2079
+ re,
2080
+ {
2081
+ size: "sm",
2082
+ "aria-label": "Formula type",
2083
+ value: x.formulaScope,
2084
+ onChange: (m) => {
2085
+ const $ = Ne(m.target.value);
2086
+ W(
2087
+ /** @param {any} [prev] @returns {any} */
2088
+ (E) => ({
2089
+ ...E,
2090
+ formulaScope: $,
2091
+ formula: E.formula || ($ === "columns" ? or(C) : Rt(A))
2092
+ })
2093
+ );
2094
+ },
2095
+ style: {
2096
+ border: `1px solid ${l.border}`,
2097
+ background: l.headerSubtleBg || l.background,
2098
+ color: l.text,
2099
+ borderRadius: "8px",
2100
+ padding: "8px 10px",
2101
+ fontSize: "12px",
2102
+ outline: "none",
2103
+ width: "100%"
2104
+ }
2105
+ },
2106
+ /* @__PURE__ */ e.createElement("option", { value: "measures" }, "Value formula"),
2107
+ /* @__PURE__ */ e.createElement("option", { value: "columns" }, "Displayed columns")
2108
+ ))),
2109
+ /* @__PURE__ */ e.createElement("div", { style: { marginBottom: "12px" } }, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px", marginBottom: "4px" } }, "Formula"), /* @__PURE__ */ e.createElement(
2110
+ "textarea",
2111
+ {
2112
+ ref: s,
2113
+ value: x.formula,
2114
+ onChange: (m) => W(
2115
+ /** @param {any} [prev] @returns {any} */
2116
+ ($) => ({ ...$, formula: m.target.value })
2117
+ ),
2118
+ placeholder: O,
2119
+ rows: 4,
2120
+ style: {
2121
+ width: "100%",
2122
+ boxSizing: "border-box",
2123
+ resize: "vertical",
2124
+ border: `1px solid ${l.border}`,
2125
+ background: l.background,
2126
+ color: l.text,
2127
+ borderRadius: "10px",
2128
+ fontFamily: "monospace",
2129
+ fontSize: "12px",
2130
+ lineHeight: 1.5,
2131
+ padding: "10px 12px",
2132
+ outline: "none"
2133
+ }
2134
+ }
2135
+ )),
2136
+ /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "8px", flexWrap: "wrap", marginBottom: "12px" } }, /* @__PURE__ */ e.createElement("div", { style: {
2137
+ padding: "5px 9px",
2138
+ borderRadius: "999px",
2139
+ border: `1px solid ${U.border}`,
2140
+ background: U.background,
2141
+ color: U.text,
2142
+ fontSize: "10px",
2143
+ lineHeight: "14px"
2144
+ } }, T.text), /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: l.textSec } }, "Ctrl/Cmd + Enter applies")),
2145
+ /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap", marginBottom: "12px" } }, R.map(
2146
+ /** @param {any} [template] @returns {any} */
2147
+ (m) => /* @__PURE__ */ e.createElement(
2148
+ "button",
2149
+ {
2150
+ key: m.label,
2151
+ type: "button",
2152
+ onClick: () => W(
2153
+ /** @param {any} [prev] @returns {any} */
2154
+ ($) => ({ ...$, formula: m.value })
2155
+ ),
2156
+ style: N
2157
+ },
2158
+ m.label
2159
+ )
2160
+ ), ["+", "-", "*", "/", "(", ")", "* 100"].map((m) => /* @__PURE__ */ e.createElement(
2161
+ "button",
2162
+ {
2163
+ key: m,
2164
+ type: "button",
2165
+ onMouseDown: ($) => $.preventDefault(),
2166
+ onClick: () => B(m),
2167
+ style: L
2168
+ },
2169
+ m
2170
+ ))),
2171
+ /* @__PURE__ */ e.createElement("div", { style: { display: "grid", gridTemplateColumns: "1fr", gap: "12px", marginBottom: "14px" } }, $e(x.formulaScope) ? /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px", marginBottom: "6px" } }, "Rendered Columns"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" } }, C.map(
2172
+ /** @param {any} [column] @returns {any} */
2173
+ (m) => /* @__PURE__ */ e.createElement(
2174
+ "button",
2175
+ {
2176
+ key: m.id,
2177
+ type: "button",
2178
+ onMouseDown: ($) => $.preventDefault(),
2179
+ onClick: () => B(ie(m.id)),
2180
+ style: N,
2181
+ title: `Insert ${m.id}`
2182
+ },
2183
+ m.label || m.id
2184
+ )
2185
+ ), C.length === 0 && /* @__PURE__ */ e.createElement("span", { style: { fontSize: "11px", color: l.textSec } }, "Render the pivot once, or type a bracketed column id directly."))) : /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px", marginBottom: "6px" } }, "Measures"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" } }, A.map(
2186
+ /** @param {any} [config] @returns {any} */
2187
+ (m) => /* @__PURE__ */ e.createElement(
2188
+ "button",
2189
+ {
2190
+ key: m.field,
2191
+ type: "button",
2192
+ onMouseDown: ($) => $.preventDefault(),
2193
+ onClick: () => B(ze(m.field)),
2194
+ style: N,
2195
+ title: `Insert ${m.field}`
2196
+ },
2197
+ m.field
2198
+ )
2199
+ ))), !$e(x.formulaScope) && y.length > 0 && /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px", marginBottom: "6px" } }, "Formula References"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" } }, y.map(
2200
+ /** @param {any} [config] @returns {any} */
2201
+ (m) => /* @__PURE__ */ e.createElement(
2202
+ "button",
2203
+ {
2204
+ key: m.field,
2205
+ type: "button",
2206
+ onMouseDown: ($) => $.preventDefault(),
2207
+ onClick: () => B(ze(q(m))),
2208
+ style: N,
2209
+ title: `${q(m)}${m.label ? ` (${m.label})` : ""}`
2210
+ },
2211
+ q(m)
2212
+ )
2213
+ ))), !$e(x.formulaScope) && D.length > 0 && /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: l.textSec, textTransform: "uppercase", letterSpacing: "0.5px", marginBottom: "6px" } }, "Data Fields (auto-aggregated as sum)"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" } }, D.map(
2214
+ /** @param {any} [f] @returns {any} */
2215
+ (m) => /* @__PURE__ */ e.createElement(
2216
+ "button",
2217
+ {
2218
+ key: m,
2219
+ type: "button",
2220
+ onMouseDown: ($) => $.preventDefault(),
2221
+ onClick: () => B(ze(m)),
2222
+ style: { ...N, borderColor: `${l.primary}66`, color: l.primary, background: `${l.primary}0d` },
2223
+ title: `Insert: ${m}`
2224
+ },
2225
+ Se(m)
2226
+ )
2227
+ )))),
2228
+ /* @__PURE__ */ e.createElement("div", { style: { display: "flex", justifyContent: "space-between", gap: "8px", flexWrap: "wrap" } }, /* @__PURE__ */ e.createElement(
2229
+ "button",
2230
+ {
2231
+ type: "button",
2232
+ onClick: () => {
2233
+ f(n), p();
2234
+ },
2235
+ style: {
2236
+ border: `1px solid ${l.border}`,
2237
+ background: l.background,
2238
+ color: l.textSec,
2239
+ borderRadius: "8px",
2240
+ padding: "8px 12px",
2241
+ fontSize: "11px",
2242
+ fontWeight: 700,
2243
+ cursor: "pointer"
2244
+ }
2245
+ },
2246
+ "Delete Formula"
2247
+ ), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" } }, /* @__PURE__ */ e.createElement(
2248
+ "button",
2249
+ {
2250
+ type: "button",
2251
+ onClick: w,
2252
+ style: {
2253
+ border: `1px solid ${l.border}`,
2254
+ background: l.background,
2255
+ color: l.textSec,
2256
+ borderRadius: "8px",
2257
+ padding: "8px 12px",
2258
+ fontSize: "11px",
2259
+ fontWeight: 700,
2260
+ cursor: "pointer"
2261
+ }
2262
+ },
2263
+ "Cancel"
2264
+ ), /* @__PURE__ */ e.createElement(
2265
+ "button",
2266
+ {
2267
+ type: "button",
2268
+ onClick: _,
2269
+ disabled: !i,
2270
+ style: {
2271
+ border: `1px solid ${i ? `${l.primary}66` : l.border}`,
2272
+ background: i ? `${l.primary}14` : l.background,
2273
+ color: i ? l.primary : l.textSec,
2274
+ borderRadius: "8px",
2275
+ padding: "8px 12px",
2276
+ fontSize: "11px",
2277
+ fontWeight: 700,
2278
+ cursor: i ? "pointer" : "default",
2279
+ opacity: i ? 1 : 0.7
2280
+ }
2281
+ },
2282
+ "Apply"
2283
+ )))
2284
+ )
2285
+ );
2286
+ }
2287
+ function sr({
2288
+ panelId: r,
2289
+ panelLabel: n,
2290
+ size: o,
2291
+ onSizeChange: a,
2292
+ getSidebarWidth: l = null,
2293
+ onSidebarWidthChange: p = null,
2294
+ theme: f,
2295
+ outerStyle: S = {},
2296
+ contentStyle: g = {},
2297
+ children: z
2298
+ }) {
2299
+ const s = e.useRef(null), x = e.useRef(null), W = e.useRef(null), P = e.useRef(null), M = e.useRef(null), A = e.useRef(null), y = e.useRef(null), [C, D] = e.useState(null), [T, U] = e.useState(null), R = e.useMemo(() => en(r), [r]), O = e.useMemo(
2300
+ () => qt(r, o),
2301
+ [r, o]
2302
+ ), i = e.useRef(O);
2303
+ i.current = O;
2304
+ const k = e.useMemo(() => C ? qt(r, {
2305
+ width: C.width !== void 0 ? C.width : O.width,
2306
+ height: C.height !== void 0 ? C.height : O.height
2307
+ }) : O, [C, r, O]), w = e.useCallback((L = !0) => {
2308
+ if (x.current) {
2309
+ const m = x.current;
2310
+ x.current = null, m(L);
2311
+ }
2312
+ }, []);
2313
+ e.useEffect(() => (() => w(!1)), [w]);
2314
+ const B = e.useCallback((L, m) => {
2315
+ if (!s.current || typeof a != "function") return;
2316
+ L.preventDefault(), L.stopPropagation(), w(!1);
2317
+ const $ = s.current.getBoundingClientRect(), E = s.current.parentElement ? s.current.parentElement.getBoundingClientRect() : $, j = typeof l == "function" ? Number(l()) : NaN, Z = Number.isFinite(j) ? Math.max(200, Math.min(600, Math.round(j))) : null, V = Z !== null ? Math.max(0, Math.round(Z - E.width)) : 0, J = typeof p == "function" && Z !== null;
2318
+ Z !== null && (i.current.width === null || A.current === null) && (A.current = Z, y.current = V);
2319
+ const K = Z !== null ? A.current !== null ? Math.min(Z, A.current) : Z : null, Q = y.current !== null ? y.current : V, At = J ? Math.max(R.minWidth, Math.min(R.maxWidth, 600 - Q)) : Math.max(R.minWidth, Math.min(R.maxWidth, Math.floor(E.width))), ne = {
2320
+ startX: L.clientX,
2321
+ startY: L.clientY,
2322
+ startWidth: $.width,
2323
+ startHeight: $.height,
2324
+ startParentWidth: Math.floor(E.width),
2325
+ startSidebarWidth: Z,
2326
+ baseSidebarWidth: K,
2327
+ chromeWidth: Q,
2328
+ canExpandSidebar: J,
2329
+ maxWidth: At,
2330
+ initialWidthProp: i.current.width
2331
+ }, ke = document.body.style.cursor, _e = document.body.style.userSelect;
2332
+ document.body.style.cursor = m === "both" ? "nwse-resize" : m === "width" ? "ew-resize" : "ns-resize", document.body.style.userSelect = "none", P.current = null, M.current = null, U(m);
2333
+ const we = () => {
2334
+ W.current = null, P.current && D(P.current), M.current !== null && typeof p == "function" && (p(M.current), M.current = null);
2335
+ }, pe = (fe) => {
2336
+ const me = fe.clientX - ne.startX, be = fe.clientY - ne.startY, Ue = {};
2337
+ if (m === "width" || m === "both" && (ne.initialWidthProp !== null || Math.abs(me) >= 3)) {
2338
+ const Ee = Math.max(R.minWidth, Math.min(ne.maxWidth, Math.round(ne.startWidth + me)));
2339
+ if (Ue.width = Ee, s.current && (s.current.style.width = `${Ee}px`), ne.canExpandSidebar) {
2340
+ const ut = ne.baseSidebarWidth !== null ? ne.baseSidebarWidth : ne.startSidebarWidth, dt = Math.max(
2341
+ ut,
2342
+ Math.min(600, Ee + ne.chromeWidth)
2343
+ );
2344
+ M.current = dt;
2345
+ }
2346
+ }
2347
+ if (m === "height" || m === "both") {
2348
+ const Ee = Math.max(R.minHeight, Math.min(R.maxHeight, Math.round(ne.startHeight + be)));
2349
+ Ue.height = Ee, s.current && (s.current.style.height = `${Ee}px`);
2350
+ }
2351
+ Object.keys(Ue).length !== 0 && (P.current = Ue, typeof window < "u" && typeof window.requestAnimationFrame == "function" ? W.current === null && (W.current = window.requestAnimationFrame(we)) : we());
2352
+ }, Ce = (fe = !0) => {
2353
+ W.current !== null && typeof window < "u" && typeof window.cancelAnimationFrame == "function" && (window.cancelAnimationFrame(W.current), W.current = null), document.body.style.cursor = ke, document.body.style.userSelect = _e, window.removeEventListener("mousemove", pe), window.removeEventListener("mouseup", se), window.removeEventListener("blur", se);
2354
+ const me = P.current, be = M.current;
2355
+ P.current = null, M.current = null, U(null), D(null), fe ? (be !== null && typeof p == "function" && p(be), me && a(r, me)) : s.current && (s.current.style.width = i.current.width === null ? "100%" : `${i.current.width}px`, s.current.style.height = `${i.current.height}px`);
2356
+ }, se = () => w(!0);
2357
+ x.current = Ce, window.addEventListener("mousemove", pe), window.addEventListener("mouseup", se), window.addEventListener("blur", se);
2358
+ }, [
2359
+ l,
2360
+ R.maxHeight,
2361
+ R.maxWidth,
2362
+ R.minHeight,
2363
+ R.minWidth,
2364
+ p,
2365
+ a,
2366
+ r,
2367
+ w
2368
+ ]), _ = e.useCallback((L, m) => {
2369
+ m && (m.preventDefault(), m.stopPropagation()), w(!1), typeof a == "function" && (L === "width" ? (a(r, { width: null }), A.current !== null && typeof p == "function" && (p(A.current), A.current = null, y.current = null)) : L === "height" ? a(r, { height: null }) : (a(r, { width: null, height: null }), A.current !== null && typeof p == "function" && (p(A.current), A.current = null, y.current = null)));
2370
+ }, [p, a, r, w]), N = `${f.primary}55`;
2371
+ return /* @__PURE__ */ e.createElement(
2372
+ "div",
2373
+ {
2374
+ ref: s,
2375
+ style: {
2376
+ position: "relative",
2377
+ flexShrink: 0,
2378
+ width: k.width === null ? "100%" : `${k.width}px`,
2379
+ maxWidth: "100%",
2380
+ height: `${k.height}px`,
2381
+ minHeight: `${R.minHeight}px`,
2382
+ maxHeight: `${R.maxHeight}px`,
2383
+ boxSizing: "border-box",
2384
+ overflow: "hidden",
2385
+ ...S
2386
+ }
2387
+ },
2388
+ /* @__PURE__ */ e.createElement(
2389
+ "div",
2390
+ {
2391
+ style: {
2392
+ width: "100%",
2393
+ height: "100%",
2394
+ overflow: "auto",
2395
+ boxSizing: "border-box",
2396
+ ...g
2397
+ }
2398
+ },
2399
+ z
2400
+ ),
2401
+ /* @__PURE__ */ e.createElement(
2402
+ "div",
2403
+ {
2404
+ className: "sp-resize-handle",
2405
+ "data-resizing": T === "width" ? "true" : void 0,
2406
+ onMouseDown: (L) => B(L, "width"),
2407
+ onDoubleClick: (L) => _("width", L),
2408
+ style: {
2409
+ position: "absolute",
2410
+ top: 0,
2411
+ right: 0,
2412
+ bottom: "12px",
2413
+ width: "10px",
2414
+ cursor: "ew-resize",
2415
+ zIndex: 4,
2416
+ touchAction: "none",
2417
+ display: "flex",
2418
+ alignItems: "center",
2419
+ justifyContent: "flex-end",
2420
+ paddingRight: "2px"
2421
+ },
2422
+ title: `Resize ${n} width`
2423
+ },
2424
+ /* @__PURE__ */ e.createElement("span", { className: "sp-resize-pill", "aria-hidden": "true", style: { width: "2px", height: "24px", borderRadius: "999px", background: N, opacity: 0.45, pointerEvents: "none" } })
2425
+ ),
2426
+ /* @__PURE__ */ e.createElement(
2427
+ "div",
2428
+ {
2429
+ className: "sp-resize-handle",
2430
+ "data-resizing": T === "height" ? "true" : void 0,
2431
+ onMouseDown: (L) => B(L, "height"),
2432
+ onDoubleClick: (L) => _("height", L),
2433
+ style: {
2434
+ position: "absolute",
2435
+ left: 0,
2436
+ right: "12px",
2437
+ bottom: 0,
2438
+ height: "10px",
2439
+ cursor: "ns-resize",
2440
+ zIndex: 4,
2441
+ touchAction: "none",
2442
+ display: "flex",
2443
+ alignItems: "flex-end",
2444
+ justifyContent: "center",
2445
+ paddingBottom: "2px"
2446
+ },
2447
+ title: `Resize ${n} height`
2448
+ },
2449
+ /* @__PURE__ */ e.createElement("span", { className: "sp-resize-pill", "aria-hidden": "true", style: { width: "28px", height: "2px", borderRadius: "999px", background: N, opacity: 0.45, pointerEvents: "none" } })
2450
+ ),
2451
+ /* @__PURE__ */ e.createElement(
2452
+ "div",
2453
+ {
2454
+ className: "sp-resize-handle",
2455
+ "data-resizing": T === "both" ? "true" : void 0,
2456
+ onMouseDown: (L) => B(L, "both"),
2457
+ onDoubleClick: (L) => _("both", L),
2458
+ style: {
2459
+ position: "absolute",
2460
+ right: 0,
2461
+ bottom: 0,
2462
+ width: "14px",
2463
+ height: "14px",
2464
+ cursor: "nwse-resize",
2465
+ zIndex: 5,
2466
+ touchAction: "none"
2467
+ },
2468
+ title: `Resize ${n}`
2469
+ },
2470
+ /* @__PURE__ */ e.createElement(
2471
+ "div",
2472
+ {
2473
+ className: "sp-resize-pill",
2474
+ "aria-hidden": "true",
2475
+ style: {
2476
+ position: "absolute",
2477
+ right: "4px",
2478
+ bottom: "4px",
2479
+ width: "3px",
2480
+ height: "3px",
2481
+ borderRadius: "999px",
2482
+ background: N,
2483
+ opacity: 0.55,
2484
+ boxShadow: `-4px 0 0 ${N}, 0 -4px 0 ${N}, -4px -4px 0 ${N}`,
2485
+ pointerEvents: "none"
2486
+ }
2487
+ }
2488
+ )
2489
+ )
2490
+ );
2491
+ }
2492
+ function cr({ measureAxis: r, setMeasureAxis: n, theme: o, valueSelectStyle: a, regularValueCount: l }) {
2493
+ const p = e.useMemo(() => qe(r), [r]), f = e.useCallback((g) => {
2494
+ typeof n == "function" && n(
2495
+ /** @param {any} [previous] @returns {any} */
2496
+ (z) => ({
2497
+ ...qe(z),
2498
+ ...typeof g == "function" ? g(qe(z)) : g
2499
+ })
2500
+ );
2501
+ }, [n]), S = {
2502
+ ...a,
2503
+ width: "112px",
2504
+ padding: "3px 6px",
2505
+ fontSize: "10px"
2506
+ };
2507
+ return /* @__PURE__ */ e.createElement("div", { style: {
2508
+ display: "flex",
2509
+ alignItems: "center",
2510
+ gap: "6px",
2511
+ flexWrap: "wrap",
2512
+ padding: "6px",
2513
+ border: `1px solid ${o.border}`,
2514
+ borderRadius: o.radiusSm || "6px",
2515
+ background: o.surfaceInset || o.headerSubtleBg || o.background
2516
+ } }, /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: o.textSec, fontWeight: 700, textTransform: "uppercase" } }, "Values as"), /* @__PURE__ */ e.createElement(
2517
+ re,
2518
+ {
2519
+ size: "sm",
2520
+ value: p.placement,
2521
+ onChange: (g) => f({ placement: g.target.value }),
2522
+ style: { ...a, width: "104px" },
2523
+ title: "Values placement"
2524
+ },
2525
+ /* @__PURE__ */ e.createElement("option", { value: "none" }, "Columns"),
2526
+ /* @__PURE__ */ e.createElement("option", { value: "rows" }, "Rows"),
2527
+ /* @__PURE__ */ e.createElement("option", { value: "columns" }, "Column Axis")
2528
+ ), p.placement !== "none" && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(
2529
+ "input",
2530
+ {
2531
+ value: p.labelField,
2532
+ onChange: (g) => f({ labelField: g.target.value }),
2533
+ style: S,
2534
+ title: "Measure label field"
2535
+ }
2536
+ ), /* @__PURE__ */ e.createElement(
2537
+ "input",
2538
+ {
2539
+ value: p.valueField,
2540
+ onChange: (g) => f({ valueField: g.target.value }),
2541
+ style: { ...S, width: "82px" },
2542
+ title: "Measure value field"
2543
+ }
2544
+ ), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", alignItems: "center", gap: "4px", fontSize: "10px", color: o.textSec } }, /* @__PURE__ */ e.createElement(
2545
+ "input",
2546
+ {
2547
+ type: "checkbox",
2548
+ checked: p.suppressEmptyMembers,
2549
+ onChange: (g) => f({ suppressEmptyMembers: g.target.checked })
2550
+ }
2551
+ ), "Empty"), /* @__PURE__ */ e.createElement("label", { style: { display: "flex", alignItems: "center", gap: "4px", fontSize: "10px", color: o.textSec } }, /* @__PURE__ */ e.createElement(
2552
+ "input",
2553
+ {
2554
+ type: "checkbox",
2555
+ checked: p.suppressZeroMembers,
2556
+ onChange: (g) => f({ suppressZeroMembers: g.target.checked })
2557
+ }
2558
+ ), "Zero")), /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: o.textSec } }, l, " selected"));
2559
+ }
2560
+ const _n = e.memo(
2561
+ /** @param {any} p0 @returns {any} */
2562
+ function({
2563
+ sidebarTab: n,
2564
+ setSidebarTab: o,
2565
+ rowFields: a,
2566
+ setRowFields: l,
2567
+ colFields: p,
2568
+ setColFields: f,
2569
+ valConfigs: S,
2570
+ setValConfigs: g,
2571
+ measureAxis: z = {},
2572
+ setMeasureAxis: s = null,
2573
+ columnVisibility: x,
2574
+ setColumnVisibility: W,
2575
+ columnPinning: P,
2576
+ setColumnPinning: M,
2577
+ availableFields: A,
2578
+ table: y,
2579
+ pinningPresets: C,
2580
+ showNotification: D,
2581
+ filterAnchorEl: T,
2582
+ setFilterAnchorEl: U,
2583
+ colSearch: R,
2584
+ setColSearch: O,
2585
+ colTypeFilter: i,
2586
+ setColTypeFilter: k,
2587
+ selectedCols: w,
2588
+ setSelectedCols: B,
2589
+ dropLine: _,
2590
+ onDragStart: N,
2591
+ onDragOver: L,
2592
+ onDrop: m,
2593
+ onDragEnd: $,
2594
+ onKeyboardFieldDrop: E,
2595
+ handleHeaderFilter: j,
2596
+ handleFilterClick: Z,
2597
+ requestFilterOptions: V,
2598
+ handleExpandAllRows: J,
2599
+ handlePinColumn: K,
2600
+ toggleAllColumnsPinned: Q,
2601
+ activeFilterCol: At,
2602
+ closeFilterPopover: ne,
2603
+ filterOptions: ke,
2604
+ filterOptionMeta: _e = {},
2605
+ clientFilterOptionMap: we = {},
2606
+ data: pe,
2607
+ sidebarWidth: Ce,
2608
+ setSidebarWidth: se,
2609
+ fieldPanelSizes: fe,
2610
+ setFieldPanelSizes: me,
2611
+ fixedSparklineValueKeys: be = [],
2612
+ sparklineFields: Ue = null,
2613
+ displayedColumnOptions: Ee = [],
2614
+ reportEditorSelection: ut = null,
2615
+ showReportConfigColumn: dt = !0,
2616
+ setShowReportConfigColumn: wr = null,
2617
+ formulaErrors: We = {},
2618
+ serverSide: Je = !1
2619
+ }) {
2620
+ Yr("SidebarPanel");
2621
+ const { theme: c, styles: Y } = Zr(), {
2622
+ filters: ce,
2623
+ setFilters: pt,
2624
+ pivotMode: Cr,
2625
+ reportDef: Rr,
2626
+ setReportDef: Dr,
2627
+ savedReports: Ar,
2628
+ setSavedReports: $r,
2629
+ activeReportId: zr,
2630
+ setActiveReportId: Fr,
2631
+ customDimensions: je,
2632
+ setCustomDimensions: $t
2633
+ } = Gr(), [Qe, zt] = e.useState({ columnId: null, anchorEl: null }), [Te, Ie] = e.useState(null), [ge, Re] = e.useState(null), [De, ft] = e.useState("report"), et = e.useRef(null), [Mr, tt] = e.useState(null), ue = e.useRef(null), Ft = e.useRef(0), Ve = e.useRef(null), xe = e.useRef(null), [X, mt] = e.useState(null), [gt, Mt] = e.useState(""), xt = e.useMemo(
2634
+ () => new Set(Array.isArray(be) ? be : []),
2635
+ [be]
2636
+ ), ee = e.useCallback(
2637
+ (t) => Xr(t, je),
2638
+ [je]
2639
+ ), _t = e.useMemo(
2640
+ () => qe(z),
2641
+ [z]
2642
+ ), he = _t.labelField || "Measure Name", Be = e.useMemo(
2643
+ () => (A || []).filter(
2644
+ /** @param {any} [field] @returns {any} */
2645
+ (t) => t
2646
+ ),
2647
+ [A]
2648
+ ), te = e.useMemo(
2649
+ () => Be.filter(
2650
+ /** @param {any} [field] @returns {any} */
2651
+ (t) => t && !pr(t)
2652
+ ),
2653
+ [Be]
2654
+ ), Ke = Array.isArray(S) && S.length > 0 && he && !Be.includes(he), Le = e.useMemo(
2655
+ () => Ke ? [he, ...Be] : Be,
2656
+ [Be, he, Ke]
2657
+ ), Ye = gt.trim().toLowerCase(), rt = e.useCallback((t) => {
2658
+ if (!Ye) return !0;
2659
+ const d = Ke && t === he ? "measure name measure names metric metrics value values" : "";
2660
+ return String(t || "").toLowerCase().includes(Ye) || String(ee(t) || "").toLowerCase().includes(Ye) || d.includes(Ye);
2661
+ }, [ee, he, Ye, Ke]), yt = e.useMemo(
2662
+ () => Le.length > 8 ? Le.filter(rt) : Le,
2663
+ [Le, rt]
2664
+ ), bt = e.useMemo(
2665
+ () => te.length > 8 ? te.filter(rt) : te,
2666
+ [te, rt]
2667
+ ), Wt = e.useCallback((t) => {
2668
+ l(
2669
+ /** @param {any} [prev] @returns {any} */
2670
+ (d) => (d || []).filter(
2671
+ /** @param {any} [item] @returns {any} */
2672
+ (u) => u !== t
2673
+ )
2674
+ ), f(
2675
+ /** @param {any} [prev] @returns {any} */
2676
+ (d) => (d || []).filter(
2677
+ /** @param {any} [item] @returns {any} */
2678
+ (u) => u !== t
2679
+ )
2680
+ ), g(
2681
+ /** @param {any} [prev] @returns {any} */
2682
+ (d) => (d || []).filter(
2683
+ /** @param {any} [item] @returns {any} */
2684
+ (u) => !(u && u.field === t)
2685
+ )
2686
+ ), pt(
2687
+ /** @param {any} [prev] @returns {any} */
2688
+ (d) => {
2689
+ if (!d || !Object.prototype.hasOwnProperty.call(d, t)) return d;
2690
+ const u = { ...d };
2691
+ return delete u[t], u;
2692
+ }
2693
+ );
2694
+ }, [f, pt, l, g]), _r = e.useCallback((t) => {
2695
+ const d = ue.current;
2696
+ if (!d) return;
2697
+ const u = 60, b = 12, h = d.getBoundingClientRect(), I = t.clientY, G = I - h.top, v = h.bottom - I;
2698
+ let H = 0;
2699
+ if (G < u && G >= 0 ? H = -1 : v < u && v >= 0 && (H = 1), H === 0) {
2700
+ xe.current && (cancelAnimationFrame(xe.current), xe.current = null);
2701
+ return;
2702
+ }
2703
+ const le = () => {
2704
+ ue.current && (ue.current.scrollTop += H * b, xe.current = requestAnimationFrame(le));
2705
+ };
2706
+ xe.current || (xe.current = requestAnimationFrame(le));
2707
+ }, []), Tt = e.useCallback(() => {
2708
+ xe.current && (cancelAnimationFrame(xe.current), xe.current = null);
2709
+ }, []), de = e.useMemo(
2710
+ () => S.filter(
2711
+ /** @param {any} [config] @returns {any} */
2712
+ (t) => t && t.agg === "formula"
2713
+ ),
2714
+ [S]
2715
+ ), Ae = e.useMemo(
2716
+ () => de.length,
2717
+ [de]
2718
+ ), Pe = e.useMemo(
2719
+ () => S.filter(
2720
+ /** @param {any} [config] @returns {any} */
2721
+ (t) => t && t.agg !== "formula"
2722
+ ).length,
2723
+ [S]
2724
+ ), Wr = e.useMemo(() => [
2725
+ { id: "rows", label: "Rows", icon: /* @__PURE__ */ e.createElement(F.List, null) },
2726
+ { id: "cols", label: "Columns", icon: /* @__PURE__ */ e.createElement(F.Columns, null) },
2727
+ { id: "vals", label: "Values", icon: /* @__PURE__ */ e.createElement(F.Sigma, null) },
2728
+ { id: "filter", label: "Filters", icon: /* @__PURE__ */ e.createElement(F.Filter, null) }
2729
+ ], []), Ze = e.useMemo(() => ({
2730
+ filter: Object.keys(ce || {}).filter((t) => t !== "global"),
2731
+ rows: a || [],
2732
+ cols: p || [],
2733
+ vals: S || []
2734
+ }), [p, ce, a, S]), nt = e.useCallback(() => {
2735
+ X && D && D("Keyboard move cancelled.", "info"), mt(null);
2736
+ }, [X, D]), It = e.useCallback((t, d, u, b) => {
2737
+ if (typeof E != "function") return;
2738
+ mt({ field: t, zone: d, idx: u, label: b }), D && D(`Picked up ${b}. Focus a target field or zone and press Enter.`, "info");
2739
+ }, [E, D]), lt = e.useCallback((t, d = null) => {
2740
+ if (!X || typeof E != "function") return !1;
2741
+ const u = Ze[t] || [], b = Number(d), h = Number.isFinite(b) ? Math.max(0, Math.min(Math.floor(b), u.length)) : u.length, I = E({
2742
+ field: X.field,
2743
+ srcZone: X.zone,
2744
+ srcIdx: X.idx,
2745
+ targetZone: t,
2746
+ targetIdx: h,
2747
+ source: "layout:keyboard-drop"
2748
+ });
2749
+ return I !== !1 && (D && D(`Moved ${X.label}.`, "success"), mt(null)), I !== !1;
2750
+ }, [X, E, D, Ze]), Bt = e.useCallback((t, d, u, b, h) => {
2751
+ if (!ar(t.target)) {
2752
+ if (t.key === "Escape") {
2753
+ t.preventDefault(), t.stopPropagation(), nt();
2754
+ return;
2755
+ }
2756
+ t.key !== "Enter" && t.key !== " " || (t.preventDefault(), t.stopPropagation(), X ? lt(u, b) : It(d, u, b, h));
2757
+ }
2758
+ }, [nt, lt, X, It]), Tr = e.useCallback((t, d) => {
2759
+ if (!ar(t.target)) {
2760
+ if (t.key === "Escape") {
2761
+ t.preventDefault(), t.stopPropagation(), nt();
2762
+ return;
2763
+ }
2764
+ !X || t.key !== "Enter" && t.key !== " " || (t.preventDefault(), t.stopPropagation(), lt(d, (Ze[d] || []).length));
2765
+ }
2766
+ }, [nt, lt, X, Ze]), Ir = e.useCallback((t) => {
2767
+ t.preventDefault();
2768
+ const d = t.clientX, u = Ce || 288;
2769
+ Ve.current = { startX: d, startWidth: u };
2770
+ const b = document.body.style.cursor, h = document.body.style.userSelect;
2771
+ document.body.style.cursor = "col-resize", document.body.style.userSelect = "none";
2772
+ const I = (v) => {
2773
+ if (!Ve.current) return;
2774
+ const H = v.clientX - Ve.current.startX, le = Math.max(200, Math.min(600, Ve.current.startWidth + H));
2775
+ se(le);
2776
+ }, G = () => {
2777
+ Ve.current = null, document.body.style.cursor = b, document.body.style.userSelect = h, window.removeEventListener("mousemove", I), window.removeEventListener("mouseup", G), window.removeEventListener("blur", G);
2778
+ };
2779
+ window.addEventListener("mousemove", I), window.addEventListener("mouseup", G), window.addEventListener("blur", G);
2780
+ }, [Ce, se]), Lt = e.useCallback(() => ue.current ? ue.current.getBoundingClientRect().width : Ce || 288, [Ce]), Pt = e.useCallback((t) => {
2781
+ if (typeof se != "function") return;
2782
+ const d = Math.max(200, Math.min(600, Math.round(t)));
2783
+ se(
2784
+ /** @param {any} [prev] @returns {any} */
2785
+ (u) => u === d ? u : d
2786
+ );
2787
+ }, [se]), Ot = e.useCallback((t, d) => {
2788
+ typeof me == "function" && me(
2789
+ /** @param {any} [prev] @returns {any} */
2790
+ (u) => {
2791
+ const b = qr(u, t, d), h = u && u[t] ? u[t] : null, I = b[t];
2792
+ return h && h.width === I.width && h.height === I.height ? u : b;
2793
+ }
2794
+ );
2795
+ }, [me]), Ht = Y.dropZone && Y.dropZone.padding || "8px", Nt = e.useMemo(() => {
2796
+ const t = { ...Y.dropZone || {} };
2797
+ return delete t.minHeight, delete t.maxHeight, delete t.overflowY, delete t.padding, delete t.border, delete t.boxShadow, t;
2798
+ }, [Y.dropZone]), Ut = e.useCallback((t) => {
2799
+ if (ke && ke[t]) return ke[t];
2800
+ if (we && we[t]) return we[t];
2801
+ if (!y || !y.getColumn) return [];
2802
+ if (!y.getColumn(t)) return [];
2803
+ const u = /* @__PURE__ */ new Set();
2804
+ return (y.getCoreRowModel ? y.getCoreRowModel().rows : []).forEach(
2805
+ /** @param {any} [row] @returns {any} */
2806
+ (h) => {
2807
+ const I = h.getValue(t);
2808
+ I != null && I !== "" && u.add(I);
2809
+ }
2810
+ ), Array.from(u).sort((h, I) => String(h).localeCompare(String(I), void 0, { numeric: !0, sensitivity: "base" }));
2811
+ }, [we, ke, y]), ye = e.useMemo(() => ({
2812
+ border: `1px solid ${c.border}`,
2813
+ background: c.headerSubtleBg || c.surfaceInset || c.background,
2814
+ color: c.text,
2815
+ cursor: "pointer",
2816
+ borderRadius: c.radiusSm || "8px",
2817
+ fontSize: "9px",
2818
+ lineHeight: 1.2,
2819
+ padding: "1px 4px",
2820
+ minHeight: "20px",
2821
+ outline: "none"
2822
+ }), [c.background, c.border, c.headerSubtleBg, c.radiusSm, c.surfaceInset, c.text]), jt = e.useCallback((t, d) => {
2823
+ g(
2824
+ /** @param {any} [prev] @returns {any} */
2825
+ (u) => {
2826
+ const b = [...u], h = b[t];
2827
+ if (!h) return u;
2828
+ if (Xt(d) && !h.weightField) {
2829
+ const I = Array.isArray(te) && te.length > 0 ? te.find((H) => H !== h.field) || te[0] : "", G = typeof window < "u" ? window.prompt(
2830
+ `Weight field for weighted average of ${Se(h.field)}`,
2831
+ h.weightField || I || ""
2832
+ ) : h.weightField || I || "", v = typeof G == "string" ? G.trim() : "";
2833
+ return v ? Array.isArray(te) && te.length > 0 && !te.includes(v) ? (D && D(`Unknown weight field: ${v}`, "warning"), u) : (b[t] = { ...h, agg: d, weightField: v }, b) : (D && D("Weighted average requires a weight field.", "warning"), u);
2834
+ }
2835
+ return b[t] = { ...h, agg: d }, b;
2836
+ }
2837
+ );
2838
+ }, [te, g, D]), Br = e.useCallback((t, d) => {
2839
+ if (!d) {
2840
+ D && D("Weighted average requires a weight field.", "warning");
2841
+ return;
2842
+ }
2843
+ g(
2844
+ /** @param {any} [prev] @returns {any} */
2845
+ (u) => {
2846
+ const b = [...u], h = b[t];
2847
+ return h ? (b[t] = { ...h, weightField: d }, b) : u;
2848
+ }
2849
+ );
2850
+ }, [g, D]), Lr = e.useCallback((t, d) => {
2851
+ g(
2852
+ /** @param {any} [prev] @returns {any} */
2853
+ (u) => {
2854
+ const b = [...u], h = b[t];
2855
+ return h ? (b[t] = {
2856
+ ...h,
2857
+ windowFn: d === "none" ? null : d
2858
+ }, b) : u;
2859
+ }
2860
+ );
2861
+ }, [g]), Vt = e.useCallback(() => {
2862
+ const t = Sn(S), d = S.filter(
2863
+ /** @param {any} [config] @returns {any} */
2864
+ (I) => I && I.agg !== "formula"
2865
+ ), u = `Formula ${Ae + 1}`, b = Rt(d), h = bn(u, S, t);
2866
+ Ie(t), Re(t), g(
2867
+ /** @param {any} [prev] @returns {any} */
2868
+ (I) => [
2869
+ ...I,
2870
+ {
2871
+ field: t,
2872
+ agg: "formula",
2873
+ label: u,
2874
+ formula: b,
2875
+ formulaRef: h,
2876
+ formulaScope: "measures"
2877
+ }
2878
+ ]
2879
+ ), D && (d.length === 0 ? D("Added a formula column. Add at least one regular value measure to reference in it.", "warning") : D(`Added ${u}.`, "success"));
2880
+ }, [Ae, Re, g, Ie, D, S]), Pr = (t, d) => {
2881
+ t.stopPropagation(), ue.current && (Ft.current = ue.current.scrollTop), zt(
2882
+ /** @param {any} [prev] @returns {any} */
2883
+ (u) => u.columnId === d ? { columnId: null, anchorEl: null } : { columnId: d, anchorEl: t.currentTarget }
2884
+ ), V && V(d);
2885
+ }, Or = () => zt({ columnId: null, anchorEl: null });
2886
+ e.useEffect(() => {
2887
+ ue.current && Qe.columnId && (ue.current.scrollTop = Ft.current);
2888
+ }, [ke, Qe.columnId]), e.useEffect(() => {
2889
+ if (de.length === 0) {
2890
+ Te !== null && Ie(null), ge !== null && Re(null);
2891
+ return;
2892
+ }
2893
+ de.some(
2894
+ /** @param {any} [config] @returns {any} */
2895
+ (d) => d.field === Te
2896
+ ) || Ie(de[de.length - 1].field), ge && !de.some(
2897
+ /** @param {any} [config] @returns {any} */
2898
+ (d) => d.field === ge
2899
+ ) && Re(null);
2900
+ }, [Te, de, ge]);
2901
+ const Et = e.useMemo(
2902
+ () => S.findIndex(
2903
+ /** @param {any} [config] @returns {any} */
2904
+ (t) => t && t.agg === "formula" && t.field === ge
2905
+ ),
2906
+ [ge, S]
2907
+ ), ht = Et >= 0 ? S[Et] : null, Kt = e.useCallback((t) => {
2908
+ Ie(t), Re(t);
2909
+ }, []), Ge = e.useCallback((t) => {
2910
+ const d = S[t] && S[t].agg === "formula" ? S[t].field : null;
2911
+ if (g(
2912
+ /** @param {any} [prev] @returns {any} */
2913
+ (u) => u.filter(
2914
+ /** @param {any} [_] @param {any} [index] @returns {any} */
2915
+ (b, h) => h !== t
2916
+ )
2917
+ ), d && d === Te) {
2918
+ const u = de.find(
2919
+ /** @param {any} [config] @returns {any} */
2920
+ (b) => b.field !== d
2921
+ );
2922
+ Ie(u ? u.field : null);
2923
+ }
2924
+ d && d === ge && Re(null);
2925
+ }, [Te, de, ge, g, S]), Oe = Cr === "report", Yt = Math.max(Ce || 288, Oe ? 380 : 0), Zt = (t, d) => {
2926
+ if (t <= 8) return null;
2927
+ const u = gt.trim().length > 0;
2928
+ return /* @__PURE__ */ e.createElement("div", { style: {
2929
+ display: "flex",
2930
+ alignItems: "center",
2931
+ gap: "6px",
2932
+ margin: "0 2px 8px",
2933
+ padding: "5px 8px",
2934
+ border: `1px solid ${c.border}`,
2935
+ borderRadius: c.radiusSm || "8px",
2936
+ background: c.headerSubtleBg || c.surfaceInset || c.background
2937
+ } }, /* @__PURE__ */ e.createElement(F.Search, { style: { flexShrink: 0, color: c.textSec } }), /* @__PURE__ */ e.createElement(
2938
+ "input",
2939
+ {
2940
+ type: "search",
2941
+ "aria-label": "Search available fields",
2942
+ placeholder: `Search ${t} fields...`,
2943
+ value: gt,
2944
+ onChange: (b) => Mt(b.target.value),
2945
+ style: {
2946
+ flex: 1,
2947
+ minWidth: 0,
2948
+ border: "none",
2949
+ outline: "none",
2950
+ background: "transparent",
2951
+ color: c.text,
2952
+ fontSize: "12px"
2953
+ }
2954
+ }
2955
+ ), u && /* @__PURE__ */ e.createElement(
2956
+ "button",
2957
+ {
2958
+ type: "button",
2959
+ "aria-label": "Clear available field search",
2960
+ title: "Clear search",
2961
+ onClick: () => Mt(""),
2962
+ style: {
2963
+ border: "none",
2964
+ background: "transparent",
2965
+ color: c.textSec,
2966
+ cursor: "pointer",
2967
+ padding: 0,
2968
+ display: "flex",
2969
+ alignItems: "center"
2970
+ }
2971
+ },
2972
+ /* @__PURE__ */ e.createElement(F.Close, null)
2973
+ ), u && /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: c.textSec, whiteSpace: "nowrap" } }, d, "/", t));
2974
+ };
2975
+ return /* @__PURE__ */ e.createElement("div", { style: { position: "relative", display: "flex", flexShrink: 0 } }, /* @__PURE__ */ e.createElement("div", { ref: ue, style: { ...Y.sidebar, width: `${Yt}px`, minWidth: `${Yt}px` }, role: "complementary", "aria-label": "Tool Panel", onDragOver: _r, onDragLeave: Tt, onDrop: Tt }, /* @__PURE__ */ e.createElement(
2976
+ "div",
2977
+ {
2978
+ id: "pivot-sidebar-keyboard-dnd-help",
2979
+ style: { position: "absolute", width: 1, height: 1, padding: 0, margin: -1, overflow: "hidden", clip: "rect(0 0 0 0)", whiteSpace: "nowrap", border: 0 }
2980
+ },
2981
+ "Press Enter or Space on a field to pick it up. Focus a target field or zone and press Enter or Space to drop it. Press Escape to cancel."
2982
+ ), Oe ? /* @__PURE__ */ e.createElement("div", { role: "tablist", "aria-label": "Report Panel Tabs", style: { position: "relative", display: "grid", gridTemplateColumns: "repeat(3, 1fr)", borderBottom: `1px solid ${c.border}`, marginBottom: "16px" } }, [
2983
+ { id: "report", label: "Builder", icon: /* @__PURE__ */ e.createElement(F.Report, null) },
2984
+ { id: "fields", label: "Fields", icon: /* @__PURE__ */ e.createElement(F.Sigma, null) },
2985
+ { id: "columns", label: "Columns", icon: /* @__PURE__ */ e.createElement(F.Columns, null) }
2986
+ ].map((t, d, u) => /* @__PURE__ */ e.createElement(
2987
+ "div",
2988
+ {
2989
+ key: t.id,
2990
+ role: "tab",
2991
+ tabIndex: 0,
2992
+ "aria-selected": De === t.id,
2993
+ className: "sp-tab",
2994
+ onClick: () => ft(t.id),
2995
+ onKeyDown: (b) => {
2996
+ if (b.key === "Enter" || b.key === " ")
2997
+ b.preventDefault(), ft(t.id);
2998
+ else if (b.key === "ArrowRight" || b.key === "ArrowLeft") {
2999
+ b.preventDefault();
3000
+ const h = b.key === "ArrowRight" ? 1 : -1, I = u[(d + h + u.length) % u.length];
3001
+ I && ft(I.id);
3002
+ }
3003
+ },
3004
+ style: {
3005
+ padding: "8px 10px",
3006
+ cursor: "pointer",
3007
+ justifyContent: "center",
3008
+ fontWeight: De === t.id ? 600 : 400,
3009
+ color: De === t.id ? c.primary : c.textSec,
3010
+ display: "flex",
3011
+ alignItems: "center",
3012
+ gap: "5px",
3013
+ fontSize: "13px"
3014
+ }
3015
+ },
3016
+ t.icon,
3017
+ t.label
3018
+ )), /* @__PURE__ */ e.createElement(
3019
+ "div",
3020
+ {
3021
+ "aria-hidden": "true",
3022
+ style: {
3023
+ position: "absolute",
3024
+ bottom: "-1px",
3025
+ left: 0,
3026
+ width: "33.3333%",
3027
+ height: "2px",
3028
+ borderRadius: "2px 2px 0 0",
3029
+ background: c.primary,
3030
+ transform: `translateX(${Math.max(0, ["report", "fields", "columns"].indexOf(De)) * 100}%)`,
3031
+ transition: "transform 200ms var(--sp-ease-apple, cubic-bezier(0.22, 1, 0.36, 1))",
3032
+ pointerEvents: "none"
3033
+ }
3034
+ }
3035
+ )) : /* @__PURE__ */ e.createElement("div", { role: "tablist", "aria-label": "Tool Panel Tabs", style: { position: "relative", display: "grid", gridTemplateColumns: "repeat(3, 1fr)", borderBottom: `1px solid ${c.border}`, marginBottom: "16px" } }, /* @__PURE__ */ e.createElement(
3036
+ "div",
3037
+ {
3038
+ role: "tab",
3039
+ tabIndex: 0,
3040
+ "aria-selected": n === "fields",
3041
+ className: "sp-tab",
3042
+ onClick: () => o("fields"),
3043
+ onKeyDown: (t) => {
3044
+ t.key === "Enter" || t.key === " " ? (t.preventDefault(), o("fields")) : t.key === "ArrowRight" ? (t.preventDefault(), o("filters")) : t.key === "ArrowLeft" && (t.preventDefault(), o("columns"));
3045
+ },
3046
+ style: {
3047
+ padding: "8px 10px",
3048
+ cursor: "pointer",
3049
+ textAlign: "center",
3050
+ fontWeight: n === "fields" ? 600 : 400,
3051
+ color: n === "fields" ? c.primary : c.textSec
3052
+ }
3053
+ },
3054
+ "Fields"
3055
+ ), /* @__PURE__ */ e.createElement(
3056
+ "div",
3057
+ {
3058
+ role: "tab",
3059
+ tabIndex: 0,
3060
+ "aria-selected": n === "filters",
3061
+ className: "sp-tab",
3062
+ onClick: () => o("filters"),
3063
+ onKeyDown: (t) => {
3064
+ t.key === "Enter" || t.key === " " ? (t.preventDefault(), o("filters")) : t.key === "ArrowRight" ? (t.preventDefault(), o("columns")) : t.key === "ArrowLeft" && (t.preventDefault(), o("fields"));
3065
+ },
3066
+ style: {
3067
+ padding: "8px 10px",
3068
+ cursor: "pointer",
3069
+ fontWeight: n === "filters" ? 600 : 400,
3070
+ color: n === "filters" ? c.primary : c.textSec,
3071
+ display: "flex",
3072
+ alignItems: "center",
3073
+ justifyContent: "center",
3074
+ gap: "6px"
3075
+ }
3076
+ },
3077
+ "Filters",
3078
+ Object.keys(ce).length > 0 && /* @__PURE__ */ e.createElement("div", { style: { width: "6px", height: "6px", borderRadius: "50%", background: "#d32f2f" } })
3079
+ ), /* @__PURE__ */ e.createElement(
3080
+ "div",
3081
+ {
3082
+ role: "tab",
3083
+ tabIndex: 0,
3084
+ "aria-selected": n === "columns",
3085
+ className: "sp-tab",
3086
+ onClick: () => o("columns"),
3087
+ onKeyDown: (t) => {
3088
+ t.key === "Enter" || t.key === " " ? (t.preventDefault(), o("columns")) : t.key === "ArrowRight" ? (t.preventDefault(), o("fields")) : t.key === "ArrowLeft" && (t.preventDefault(), o("filters"));
3089
+ },
3090
+ style: {
3091
+ padding: "8px 10px",
3092
+ cursor: "pointer",
3093
+ textAlign: "center",
3094
+ fontWeight: n === "columns" ? 600 : 400,
3095
+ color: n === "columns" ? c.primary : c.textSec
3096
+ }
3097
+ },
3098
+ "Columns"
3099
+ ), /* @__PURE__ */ e.createElement(
3100
+ "div",
3101
+ {
3102
+ "aria-hidden": "true",
3103
+ style: {
3104
+ position: "absolute",
3105
+ bottom: "-1px",
3106
+ left: 0,
3107
+ width: "33.3333%",
3108
+ height: "2px",
3109
+ borderRadius: "2px 2px 0 0",
3110
+ background: c.primary,
3111
+ transform: `translateX(${Math.max(0, ["fields", "filters", "columns"].indexOf(n)) * 100}%)`,
3112
+ transition: "transform 200ms var(--sp-ease-apple, cubic-bezier(0.22, 1, 0.36, 1))",
3113
+ pointerEvents: "none"
3114
+ }
3115
+ }
3116
+ )), Oe && De === "report" ? /* @__PURE__ */ e.createElement("div", { style: { flex: 1, overflowY: "auto", padding: "0 12px 12px" } }, /* @__PURE__ */ e.createElement(
3117
+ yn,
3118
+ {
3119
+ reportDef: Rr,
3120
+ setReportDef: Dr,
3121
+ availableFields: A,
3122
+ customDimensions: je,
3123
+ theme: c,
3124
+ styles: Y,
3125
+ data: pe,
3126
+ valConfigs: S,
3127
+ colFields: p,
3128
+ setColFields: f,
3129
+ setValConfigs: g,
3130
+ savedReports: Ar,
3131
+ setSavedReports: $r,
3132
+ activeReportId: zr,
3133
+ setActiveReportId: Fr,
3134
+ showNotification: D,
3135
+ requestedSelection: ut,
3136
+ showReportConfigColumn: dt,
3137
+ setShowReportConfigColumn: wr
3138
+ }
3139
+ )) : Oe && De === "fields" ? /* @__PURE__ */ e.createElement("div", { style: { padding: "0 4px" } }, /* @__PURE__ */ e.createElement(
3140
+ nr,
3141
+ {
3142
+ availableFields: A,
3143
+ customDimensions: je,
3144
+ setCustomDimensions: $t,
3145
+ data: pe,
3146
+ theme: c,
3147
+ showNotification: D,
3148
+ getFieldLabel: ee,
3149
+ onDeleteField: Wt
3150
+ }
3151
+ ), /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: c.textSec, textTransform: "uppercase", letterSpacing: "0.5px", marginBottom: "6px", padding: "0 2px" } }, /* @__PURE__ */ e.createElement(F.Database, { style: { verticalAlign: "middle", marginRight: "4px" } }), "Available Fields — click to add"), Zt(te.length, bt.length), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px", marginBottom: "14px" } }, bt.map(
3152
+ /** @param {any} [f] @returns {any} */
3153
+ (t) => {
3154
+ const d = S.some(
3155
+ /** @param {any} [c] @returns {any} */
3156
+ (u) => u && u.field === t && u.agg !== "formula"
3157
+ );
3158
+ return /* @__PURE__ */ e.createElement(
3159
+ "div",
3160
+ {
3161
+ key: t,
3162
+ onClick: () => {
3163
+ d || g(
3164
+ /** @param {any} [prev] @returns {any} */
3165
+ (u) => [...u, { field: t, agg: "sum", label: ee(t) }]
3166
+ );
3167
+ },
3168
+ style: {
3169
+ padding: "3px 9px",
3170
+ fontSize: "11px",
3171
+ lineHeight: 1.4,
3172
+ fontWeight: 500,
3173
+ borderRadius: "999px",
3174
+ border: `1px solid ${d || c.isDark ? c.border : "#D7DDEA"}`,
3175
+ background: d ? c.select || c.headerBg : c.isDark ? c.background : "#ffffff",
3176
+ color: d ? c.primary : c.text,
3177
+ cursor: d ? "default" : "pointer",
3178
+ opacity: d ? 0.6 : 1,
3179
+ userSelect: "none"
3180
+ },
3181
+ title: d ? `${ee(t)} already in values` : `Add ${ee(t)} to values`
3182
+ },
3183
+ ee(t),
3184
+ d ? " ✓" : ""
3185
+ );
3186
+ }
3187
+ ), te.length > 8 && bt.length === 0 && /* @__PURE__ */ e.createElement("div", { style: { width: "100%", padding: "8px 2px", fontSize: "11px", color: c.textSec } }, "No fields match the current search.")), /* @__PURE__ */ e.createElement("div", { style: { borderTop: `1px solid ${c.border}`, paddingTop: "10px", marginBottom: "8px" } }, /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "8px", padding: "0 2px 8px 2px", flexWrap: "wrap" } }, /* @__PURE__ */ e.createElement("button", { type: "button", onClick: Vt, style: { border: `1px solid ${c.primary}66`, background: `${c.primary}12`, color: c.primary, borderRadius: "999px", cursor: "pointer", padding: "4px 10px", fontSize: "11px", fontWeight: 700 } }, "+ Add Formula"), /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: c.textSec } }, Pe, " value", Pe === 1 ? "" : "s", " · ", Ae, " formula", Ae === 1 ? "" : "s")), /* @__PURE__ */ e.createElement(
3188
+ cr,
3189
+ {
3190
+ measureAxis: z,
3191
+ setMeasureAxis: s,
3192
+ theme: c,
3193
+ valueSelectStyle: ye,
3194
+ regularValueCount: Pe
3195
+ }
3196
+ )), S.map(
3197
+ /** @param {any} [item] @param {any} [idx] @returns {any} */
3198
+ (t, d) => {
3199
+ const u = t && t.agg === "formula";
3200
+ if (!t) return null;
3201
+ const b = Mr === d;
3202
+ return /* @__PURE__ */ e.createElement(
3203
+ "div",
3204
+ {
3205
+ key: t.field || d,
3206
+ draggable: !0,
3207
+ onDragStart: () => {
3208
+ et.current = d;
3209
+ },
3210
+ onDragOver: (h) => {
3211
+ h.preventDefault(), tt(d);
3212
+ },
3213
+ onDragLeave: () => tt(null),
3214
+ onDrop: (h) => {
3215
+ h.preventDefault();
3216
+ const I = et.current;
3217
+ tt(null), et.current = null, !(I === null || I === d) && g(
3218
+ /** @param {any} [prev] @returns {any} */
3219
+ (G) => {
3220
+ const v = [...G], [H] = v.splice(I, 1);
3221
+ return v.splice(d, 0, H), v;
3222
+ }
3223
+ );
3224
+ },
3225
+ onDragEnd: () => {
3226
+ et.current = null, tt(null);
3227
+ },
3228
+ style: { marginBottom: "6px", borderTop: b ? `2px solid ${c.primary}` : "2px solid transparent", cursor: "grab" }
3229
+ },
3230
+ u ? /* @__PURE__ */ e.createElement(ir, { item: t, idx: d, selected: t.field === ge, onSelect: Kt, onRemove: Ge, setValConfigs: g, theme: c, styles: Y, dropLine: null, zoneId: "vals", valueSelectStyle: ye, colFields: p, fixedSparklineValueKeySet: xt, showNotification: D, serverError: We && We[t.field] || null }) : /* @__PURE__ */ e.createElement("div", { style: { ...Y.chip, flexWrap: "wrap", alignItems: "flex-start" } }, /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "8px", minWidth: 0, flex: 1 } }, /* @__PURE__ */ e.createElement(F.DragIndicator, { style: { flexShrink: 0, opacity: 0.4 } }), /* @__PURE__ */ e.createElement("b", { style: { fontWeight: 500, minWidth: 0, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, ee(t.field))), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "4px", marginLeft: "8px", flexWrap: "nowrap", flexShrink: 0 } }, /* @__PURE__ */ e.createElement(re, { size: "sm", "aria-label": "Aggregation", value: t.agg, onClick: (h) => h.stopPropagation(), onChange: (h) => jt(d, h.target.value), style: { ...ye, width: "78px" } }, /* @__PURE__ */ e.createElement("option", { value: "sum" }, "Sum"), /* @__PURE__ */ e.createElement("option", { value: "avg" }, "Avg"), /* @__PURE__ */ e.createElement("option", { value: "count" }, "Cnt"), /* @__PURE__ */ e.createElement("option", { value: "min" }, "Min"), /* @__PURE__ */ e.createElement("option", { value: "max" }, "Max"), /* @__PURE__ */ e.createElement("option", { value: "weighted_avg" }, "WAvg")), /* @__PURE__ */ e.createElement("span", { onClick: () => Ge(d), style: { cursor: "pointer", color: "#9CA3AF", display: "flex", alignItems: "center" } }, /* @__PURE__ */ e.createElement(F.Close, null))))
3231
+ );
3232
+ }
3233
+ ), S.length === 0 && /* @__PURE__ */ e.createElement("div", { style: { opacity: 0.5, fontSize: "11px", padding: "12px", textAlign: "center" } }, "No value fields. Click a field above or add a formula.")) : !Oe && n === "filters" ? /* @__PURE__ */ e.createElement("div", { style: { flex: 1, overflowY: "auto", display: "flex", flexDirection: "column", padding: "8px" } }, /* @__PURE__ */ e.createElement("div", { style: { marginBottom: "10px", display: "flex", alignItems: "center", background: c.background, borderRadius: "6px", padding: "4px 8px", border: `1px solid ${c.border}` } }, /* @__PURE__ */ e.createElement(F.Search, null), /* @__PURE__ */ e.createElement(
3234
+ "input",
3235
+ {
3236
+ placeholder: "Search columns...",
3237
+ value: R,
3238
+ onChange: (t) => O(t.target.value),
3239
+ style: { border: "none", background: "transparent", marginLeft: "10px", outline: "none", width: "100%", color: c.text, fontSize: "13px" }
3240
+ }
3241
+ )), (() => {
3242
+ const u = A.map(
3243
+ /** @param {any} [field] @returns {any} */
3244
+ (b) => {
3245
+ const h = y.getColumn(b);
3246
+ return h || { id: b, header: ee(b), columnDef: { header: ee(b) } };
3247
+ }
3248
+ ).filter(
3249
+ /** @param {any} [col] @returns {any} */
3250
+ (b) => {
3251
+ const h = b.columnDef && typeof b.columnDef.header == "string" ? b.columnDef.header : typeof b.header == "string" ? b.header : b.id;
3252
+ return String(h).toLowerCase().includes(R.toLowerCase()) || b.id.toLowerCase().includes(R.toLowerCase());
3253
+ }
3254
+ );
3255
+ return /* @__PURE__ */ e.createElement("div", { style: { display: "flex", flexDirection: "column" } }, u.map(
3256
+ /** @param {any} [col] @returns {any} */
3257
+ (b) => /* @__PURE__ */ e.createElement(
3258
+ nn,
3259
+ {
3260
+ key: b.id,
3261
+ column: b,
3262
+ theme: c,
3263
+ styles: Y,
3264
+ onFilter: (
3265
+ /** @param {any} [val] @returns {any} */
3266
+ ((h) => j(b.id, h))
3267
+ ),
3268
+ currentFilter: ce[b.id],
3269
+ options: Ut(b.id),
3270
+ optionMeta: _e && _e[b.id],
3271
+ onSearchOptions: Je ? (
3272
+ /** @param {any} [search] @returns {any} */
3273
+ ((h) => V && V(b.id, { search: h, offset: 0 }))
3274
+ ) : void 0,
3275
+ onLoadMoreOptions: Je ? (
3276
+ /** @param {any} [search] @param {any} [offset] @returns {any} */
3277
+ ((h, I) => V && V(b.id, { search: h, offset: I }))
3278
+ ) : void 0,
3279
+ onOpen: V
3280
+ }
3281
+ )
3282
+ ));
3283
+ })()) : (Oe ? De !== "columns" : n !== "columns") ? /* @__PURE__ */ e.createElement(e.Fragment, null, n === "fields" && /* @__PURE__ */ e.createElement("div", { style: { flexShrink: 0 } }, /* @__PURE__ */ e.createElement(
3284
+ nr,
3285
+ {
3286
+ availableFields: A,
3287
+ customDimensions: je,
3288
+ setCustomDimensions: $t,
3289
+ data: pe,
3290
+ theme: c,
3291
+ showNotification: D,
3292
+ getFieldLabel: ee,
3293
+ onDeleteField: Wt
3294
+ }
3295
+ ), /* @__PURE__ */ e.createElement("div", { style: Y.sectionTitleSm }, /* @__PURE__ */ e.createElement(F.Database, null), " Available Fields"), Zt(Le.length, yt.length), /* @__PURE__ */ e.createElement(
3296
+ sr,
3297
+ {
3298
+ panelId: "availableFields",
3299
+ panelLabel: "Available Fields",
3300
+ size: fe && fe.availableFields,
3301
+ onSizeChange: Ot,
3302
+ getSidebarWidth: Lt,
3303
+ onSidebarWidthChange: Pt,
3304
+ theme: c,
3305
+ outerStyle: Nt,
3306
+ contentStyle: {
3307
+ display: "flex",
3308
+ flexWrap: "wrap",
3309
+ gap: "4px",
3310
+ alignContent: "flex-start",
3311
+ padding: "2px 12px 12px 2px"
3312
+ }
3313
+ },
3314
+ yt.map(
3315
+ /** @param {any} [f] @returns {any} */
3316
+ (t) => {
3317
+ const d = Ke && t === he, u = d ? "Measure Names" : ee(t), b = d ? "measureAxis" : "pool";
3318
+ return /* @__PURE__ */ e.createElement(
3319
+ "div",
3320
+ {
3321
+ key: d ? `__measure_axis__${t}` : t,
3322
+ draggable: !0,
3323
+ "data-sidebar-field-chip": d ? "measure-axis-label" : "available",
3324
+ role: "button",
3325
+ tabIndex: 0,
3326
+ "aria-describedby": "pivot-sidebar-keyboard-dnd-help",
3327
+ "aria-grabbed": X && X.zone === b && X.field === t ? "true" : "false",
3328
+ "aria-label": `Move ${u}`,
3329
+ onDragStart: (h) => N(h, t, b),
3330
+ onDragEnd: $,
3331
+ onKeyDown: (h) => Bt(h, t, b, -1, u),
3332
+ title: d ? "Drag to Rows or Columns to show measure names" : `Move ${ee(t)}`,
3333
+ style: {
3334
+ padding: "4px 8px",
3335
+ fontSize: "11px",
3336
+ lineHeight: 1.2,
3337
+ fontWeight: d ? 700 : 500,
3338
+ fontFamily: "'Inter', ui-sans-serif, system-ui, sans-serif",
3339
+ borderRadius: c.radiusSm || c.radius || "10px",
3340
+ border: d ? `1px dashed ${c.primary}` : `1px solid ${c.isDark ? c.border : "#D7DDEA"}`,
3341
+ background: d ? `${c.primary}12` : c.isDark ? c.background : c.surfaceInset || "#ffffff",
3342
+ color: d ? c.primary : c.isDark ? c.text : "#334155",
3343
+ display: "inline-flex",
3344
+ alignItems: "center",
3345
+ gap: "4px",
3346
+ boxShadow: c.isDark ? "none" : c.shadowInset || "0 1px 2px rgba(0,0,0,0.04)",
3347
+ cursor: "grab",
3348
+ userSelect: "none",
3349
+ minHeight: "24px"
3350
+ }
3351
+ },
3352
+ d && /* @__PURE__ */ e.createElement(F.Sigma, null),
3353
+ u
3354
+ );
3355
+ }
3356
+ ),
3357
+ Le.length > 8 && yt.length === 0 && /* @__PURE__ */ e.createElement("div", { style: { width: "100%", padding: "8px 2px", fontSize: "11px", color: c.textSec } }, "No fields match the current search.")
3358
+ )), Wr.map(
3359
+ /** @param {any} [zone] @returns {any} */
3360
+ (t) => {
3361
+ const d = Ze[t.id] || [];
3362
+ return /* @__PURE__ */ e.createElement("div", { key: t.id, style: { marginBottom: "20px", flexShrink: 0 } }, /* @__PURE__ */ e.createElement("div", { style: Y.sectionTitle }, t.icon, t.label), t.id === "vals" && /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "8px", padding: "0 4px 8px 4px", flexWrap: "wrap" } }, /* @__PURE__ */ e.createElement(
3363
+ "button",
3364
+ {
3365
+ type: "button",
3366
+ onClick: Vt,
3367
+ style: {
3368
+ border: `1px solid ${c.primary}66`,
3369
+ background: `${c.primary}12`,
3370
+ color: c.primary,
3371
+ borderRadius: "999px",
3372
+ cursor: "pointer",
3373
+ padding: "4px 10px",
3374
+ fontSize: "11px",
3375
+ fontWeight: 700
3376
+ }
3377
+ },
3378
+ "+ Add Formula"
3379
+ ), /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: c.textSec } }, Pe, " value measure", Pe === 1 ? "" : "s", " available"), Ae > 0 && /* @__PURE__ */ e.createElement("span", { style: { fontSize: "10px", color: c.textSec } }, Ae, " formula", Ae === 1 ? "" : "s"), /* @__PURE__ */ e.createElement(
3380
+ cr,
3381
+ {
3382
+ measureAxis: z,
3383
+ setMeasureAxis: s,
3384
+ theme: c,
3385
+ valueSelectStyle: ye,
3386
+ regularValueCount: Pe
3387
+ }
3388
+ )), t.id === "rows" && a.length > 0 && /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "4px", padding: "0 4px 6px 4px" } }, /* @__PURE__ */ e.createElement(
3389
+ "button",
3390
+ {
3391
+ title: "Expand all hierarchy levels",
3392
+ onClick: () => J(!0),
3393
+ style: { flex: 1, border: `1px solid ${c.primary}`, background: c.select, cursor: "pointer", padding: "3px 6px", fontSize: "11px", color: c.primary, borderRadius: "4px", fontWeight: 600 }
3394
+ },
3395
+ "+ Expand All"
3396
+ ), /* @__PURE__ */ e.createElement(
3397
+ "button",
3398
+ {
3399
+ title: "Collapse all rows",
3400
+ onClick: () => J(!1),
3401
+ style: { flex: 1, border: `1px solid ${c.border}`, background: c.background, cursor: "pointer", padding: "3px 6px", fontSize: "11px", color: c.textSec, borderRadius: "4px" }
3402
+ },
3403
+ "- Collapse All"
3404
+ )), /* @__PURE__ */ e.createElement(
3405
+ sr,
3406
+ {
3407
+ panelId: t.id,
3408
+ panelLabel: t.label,
3409
+ size: fe && fe[t.id],
3410
+ onSizeChange: Ot,
3411
+ getSidebarWidth: Lt,
3412
+ onSidebarWidthChange: Pt,
3413
+ theme: c,
3414
+ outerStyle: Nt,
3415
+ contentStyle: { padding: `${Ht} 12px 12px ${Ht}` }
3416
+ },
3417
+ /* @__PURE__ */ e.createElement(
3418
+ "div",
3419
+ {
3420
+ "data-sidebar-drop-zone": t.id,
3421
+ role: "group",
3422
+ tabIndex: 0,
3423
+ "aria-label": `${t.label} drop zone`,
3424
+ "aria-describedby": "pivot-sidebar-keyboard-dnd-help",
3425
+ onKeyDown: (u) => Tr(u, t.id),
3426
+ onDragOver: (u) => {
3427
+ u.target === u.currentTarget ? L(u, t.id, d.length) : (u.preventDefault(), u.dataTransfer && (u.dataTransfer.dropEffect = "move"));
3428
+ },
3429
+ onDrop: (u) => m(u, t.id)
3430
+ },
3431
+ d.map(
3432
+ /** @param {any} [item] @param {any} [idx] @returns {any} */
3433
+ (u, b) => {
3434
+ const h = t.id === "vals" ? u.field : u, I = t.id === "vals" ? u.agg === "formula" ? u.label || "Formula" : ee(u.field) : ee(u), G = (t.id === "rows" || t.id === "cols") && h === he && _t.placement !== "none";
3435
+ return /* @__PURE__ */ e.createElement(
3436
+ "div",
3437
+ {
3438
+ key: b,
3439
+ draggable: !0,
3440
+ "data-sidebar-field-chip": "zone",
3441
+ role: "button",
3442
+ tabIndex: 0,
3443
+ "aria-describedby": "pivot-sidebar-keyboard-dnd-help",
3444
+ "aria-grabbed": X && X.zone === t.id && X.idx === b ? "true" : "false",
3445
+ "aria-label": `Move ${I}`,
3446
+ onKeyDown: (v) => Bt(v, u, t.id, b, I),
3447
+ onDragStart: (v) => N(v, u, t.id, b),
3448
+ onDragOver: (v) => L(v, t.id, b),
3449
+ onDragEnd: $
3450
+ },
3451
+ t.id === "vals" && u.agg === "formula" ? /* @__PURE__ */ e.createElement(
3452
+ ir,
3453
+ {
3454
+ item: u,
3455
+ idx: b,
3456
+ selected: u.field === Te,
3457
+ onSelect: Kt,
3458
+ onRemove: Ge,
3459
+ setValConfigs: g,
3460
+ theme: c,
3461
+ styles: Y,
3462
+ dropLine: _,
3463
+ zoneId: t.id,
3464
+ valueSelectStyle: ye,
3465
+ colFields: p,
3466
+ fixedSparklineValueKeySet: xt,
3467
+ showNotification: D,
3468
+ serverError: We && We[u.field] || null
3469
+ }
3470
+ ) : /* @__PURE__ */ e.createElement("div", { style: {
3471
+ ...Y.chip,
3472
+ ...t.id === "vals" ? { flexWrap: "wrap", alignItems: "flex-start" } : {}
3473
+ } }, _ && _.zone === t.id && _.idx === b && /* @__PURE__ */ e.createElement("div", { className: "sp-drop-line", style: { ...Y.dropLine, top: -2 } }), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "8px", minWidth: 0, flex: 1 } }, /* @__PURE__ */ e.createElement(F.DragIndicator, null), /* @__PURE__ */ e.createElement("b", { style: { fontWeight: 500, display: "block", minWidth: 0, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, I)), t.id === "vals" && /* @__PURE__ */ e.createElement("div", { style: { display: "flex", alignItems: "center", gap: "4px", marginLeft: "8px", flexWrap: "nowrap", flexShrink: 0 } }, /* @__PURE__ */ e.createElement(re, { size: "sm", value: u.agg, onClick: (v) => v.stopPropagation(), onChange: (v) => jt(b, v.target.value), style: { ...ye, width: "78px" }, title: "Aggregation" }, /* @__PURE__ */ e.createElement("option", { value: "sum" }, "Sum"), /* @__PURE__ */ e.createElement("option", { value: "avg" }, "Avg"), /* @__PURE__ */ e.createElement("option", { value: "count" }, "Cnt"), /* @__PURE__ */ e.createElement("option", { value: "min" }, "Min"), /* @__PURE__ */ e.createElement("option", { value: "max" }, "Max"), /* @__PURE__ */ e.createElement("option", { value: "weighted_avg" }, "WAvg"), /* @__PURE__ */ e.createElement("option", { value: "array_agg" }, "Series")), Xt(u.agg) && /* @__PURE__ */ e.createElement(re, { size: "sm", value: u.weightField || "", onClick: (v) => v.stopPropagation(), onChange: (v) => Br(b, v.target.value), style: { ...ye, width: "96px" }, title: "Weight field" }, /* @__PURE__ */ e.createElement("option", { value: "", disabled: !0 }, "Weight"), te.map(
3474
+ /** @param {any} [fieldName] @returns {any} */
3475
+ (v) => /* @__PURE__ */ e.createElement("option", { key: v, value: v }, ee(v))
3476
+ )), /* @__PURE__ */ e.createElement(re, { size: "sm", "aria-label": "Window calculation", value: u.windowFn || "none", onClick: (v) => v.stopPropagation(), onChange: (v) => Lr(b, v.target.value), style: { ...ye, width: "68px" } }, /* @__PURE__ */ e.createElement("option", { value: "none" }, "Norm"), /* @__PURE__ */ e.createElement("option", { value: "percent_of_row" }, "%Row"), /* @__PURE__ */ e.createElement("option", { value: "percent_of_col" }, "%Col"), /* @__PURE__ */ e.createElement("option", { value: "percent_of_grand_total" }, "%Tot"))), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "4px", marginLeft: "auto", alignItems: "center" } }, t.id === "filter" && /* @__PURE__ */ e.createElement("div", { onClick: (v) => Pr(v, h), style: { cursor: "pointer", display: "flex", alignItems: "center", padding: "2px", borderRadius: "4px" } }, /* @__PURE__ */ e.createElement(F.Filter, null)), /* @__PURE__ */ e.createElement("span", { onClick: () => {
3477
+ if (G && typeof s == "function") {
3478
+ s(
3479
+ /** @param {any} [previous] @returns {any} */
3480
+ (v) => ({
3481
+ ...qe(v),
3482
+ placement: "none"
3483
+ })
3484
+ ), t.id === "rows" && l(
3485
+ /** @param {any} [p] @returns {any} */
3486
+ (v) => Array.isArray(v) ? v.filter(
3487
+ /** @param {any} [x] @returns {any} */
3488
+ (H) => H !== h
3489
+ ) : v
3490
+ ), t.id === "cols" && f(
3491
+ /** @param {any} [p] @returns {any} */
3492
+ (v) => Array.isArray(v) ? v.filter(
3493
+ /** @param {any} [x] @returns {any} */
3494
+ (H) => H !== h
3495
+ ) : v
3496
+ );
3497
+ return;
3498
+ }
3499
+ if (t.id === "filter") {
3500
+ const v = { ...ce };
3501
+ delete v[h], pt(v);
3502
+ }
3503
+ t.id === "rows" && l(
3504
+ /** @param {any} [p] @returns {any} */
3505
+ (v) => v.filter(
3506
+ /** @param {any} [x] @returns {any} */
3507
+ (H) => H !== h
3508
+ )
3509
+ ), t.id === "cols" && f(
3510
+ /** @param {any} [p] @returns {any} */
3511
+ (v) => v.filter(
3512
+ /** @param {any} [x] @returns {any} */
3513
+ (H) => H !== h
3514
+ )
3515
+ ), t.id === "vals" && Ge(b);
3516
+ }, className: "sp-chip-remove", style: { cursor: "pointer", color: "#9CA3AF", display: "flex", alignItems: "center" } }, /* @__PURE__ */ e.createElement(F.Close, null))), t.id === "filter" && Qe.columnId === h && /* @__PURE__ */ e.createElement(
3517
+ Jr,
3518
+ {
3519
+ column: { header: I, id: h },
3520
+ anchorEl: Qe.anchorEl,
3521
+ onClose: Or,
3522
+ onFilter: (
3523
+ /** @param {any} [filterValue] @returns {any} */
3524
+ ((v) => j(h, v))
3525
+ ),
3526
+ currentFilter: ce[h],
3527
+ options: Ut(h),
3528
+ optionMeta: _e && _e[h],
3529
+ onSearchOptions: Je ? (
3530
+ /** @param {any} [search] @returns {any} */
3531
+ ((v) => V && V(h, { search: v, offset: 0 }))
3532
+ ) : void 0,
3533
+ onLoadMoreOptions: Je ? (
3534
+ /** @param {any} [search] @param {any} [offset] @returns {any} */
3535
+ ((v, H) => V && V(h, { search: v, offset: H }))
3536
+ ) : void 0,
3537
+ theme: c
3538
+ }
3539
+ ), t.id === "vals" && /* @__PURE__ */ e.createElement(
3540
+ kr,
3541
+ {
3542
+ item: u,
3543
+ idx: b,
3544
+ setValConfigs: g,
3545
+ theme: c,
3546
+ valueSelectStyle: ye,
3547
+ colFields: p,
3548
+ fixedSparklineValueKeySet: xt,
3549
+ showNotification: D
3550
+ }
3551
+ ), _ && _.zone === t.id && _.idx === b + 1 && /* @__PURE__ */ e.createElement("div", { className: "sp-drop-line", style: { ...Y.dropLine, bottom: -2 } })),
3552
+ t.id === "filter" && ce[h] && ce[h].conditions && /* @__PURE__ */ e.createElement("div", { style: { fontSize: "10px", color: c.primary, padding: "0 8px 4px 8px", marginTop: "-4px" } }, ce[h].conditions.map(
3553
+ /** @param {any} [c] @returns {any} */
3554
+ (v) => `${v.type}: ${v.value}${v.caseSensitive ? " (Match Case)" : ""}`
3555
+ ).join(` ${ce[h].operator} `))
3556
+ );
3557
+ }
3558
+ ),
3559
+ d.length === 0 && /* @__PURE__ */ e.createElement("div", { style: { opacity: 0.5, fontSize: "11px", padding: "8px", textAlign: "center", pointerEvents: "none" } }, "Drag fields here"),
3560
+ /* @__PURE__ */ e.createElement("div", { style: { height: 20 }, onDragOver: (u) => L(u, t.id, d.length), onDrop: (u) => m(u, t.id) })
3561
+ )
3562
+ ));
3563
+ }
3564
+ )) : /* @__PURE__ */ e.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "16px", height: "100%", overflow: "hidden" } }, /* @__PURE__ */ e.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "10px", padding: "10px", background: c.headerSubtleBg || c.headerBg, border: `1px solid ${c.border}`, borderRadius: "10px" } }, /* @__PURE__ */ e.createElement("div", { className: "sp-search-shell", style: { display: "flex", alignItems: "center", background: c.surfaceBg || c.background, borderRadius: "8px", padding: "7px 10px", border: `1px solid ${c.border}` } }, /* @__PURE__ */ e.createElement(F.Search, null), /* @__PURE__ */ e.createElement(
3565
+ "input",
3566
+ {
3567
+ placeholder: "Search columns...",
3568
+ value: R,
3569
+ onChange: (t) => O(t.target.value),
3570
+ style: {
3571
+ border: "none",
3572
+ background: "transparent",
3573
+ marginLeft: "8px",
3574
+ outline: "none",
3575
+ width: "100%",
3576
+ color: c.text,
3577
+ fontSize: "13px",
3578
+ fontWeight: 500
3579
+ }
3580
+ }
3581
+ ), R && /* @__PURE__ */ e.createElement(
3582
+ "button",
3583
+ {
3584
+ type: "button",
3585
+ className: "sp-btn sp-btn-ghost",
3586
+ "aria-label": "Clear column search",
3587
+ onClick: () => O(""),
3588
+ style: {
3589
+ cursor: "pointer",
3590
+ display: "inline-flex",
3591
+ alignItems: "center",
3592
+ justifyContent: "center",
3593
+ border: "none",
3594
+ color: c.textSec,
3595
+ padding: "4px",
3596
+ borderRadius: "6px",
3597
+ background: c.hover
3598
+ }
3599
+ },
3600
+ /* @__PURE__ */ e.createElement(F.Close, null)
3601
+ )), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" } }, [
3602
+ { value: "all", label: "All", Icon: F.TypeAll },
3603
+ { value: "number", label: "Numbers", Icon: F.TypeNumber },
3604
+ { value: "string", label: "Text", Icon: F.TypeText },
3605
+ { value: "date", label: "Dates", Icon: F.TypeDate }
3606
+ ].map((t) => {
3607
+ const d = i === t.value, u = t.Icon;
3608
+ return /* @__PURE__ */ e.createElement(
3609
+ "button",
3610
+ {
3611
+ key: t.value,
3612
+ type: "button",
3613
+ className: `sp-btn ${d ? "sp-btn-primary" : "sp-btn-subtle"}`,
3614
+ onClick: () => k(t.value),
3615
+ style: {
3616
+ padding: "6px 10px",
3617
+ borderRadius: "8px",
3618
+ border: `1px solid ${d ? c.primary : c.border}`,
3619
+ background: d ? c.primary : c.surfaceBg || c.background,
3620
+ color: d ? "#fff" : c.text,
3621
+ cursor: "pointer",
3622
+ fontSize: "11px",
3623
+ fontWeight: 600,
3624
+ display: "inline-flex",
3625
+ alignItems: "center",
3626
+ gap: "5px",
3627
+ boxShadow: d ? "0 2px 6px rgba(0,0,0,0.12)" : "none"
3628
+ }
3629
+ },
3630
+ /* @__PURE__ */ e.createElement(u, null),
3631
+ /* @__PURE__ */ e.createElement("span", null, t.label)
3632
+ );
3633
+ }))), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "6px", padding: "0 8px" } }, /* @__PURE__ */ e.createElement(
3634
+ "button",
3635
+ {
3636
+ onClick: () => y.toggleAllColumnsVisible(!0),
3637
+ style: {
3638
+ ...Y.btn,
3639
+ padding: "8px 12px",
3640
+ fontSize: "11px",
3641
+ flex: 1,
3642
+ justifyContent: "center",
3643
+ background: c.background,
3644
+ fontWeight: 600,
3645
+ boxShadow: "0 1px 2px rgba(0,0,0,0.05)",
3646
+ transition: "all 0.2s"
3647
+ },
3648
+ onMouseEnter: (t) => t.currentTarget.style.boxShadow = "0 2px 4px rgba(0,0,0,0.1)",
3649
+ onMouseLeave: (t) => t.currentTarget.style.boxShadow = "0 1px 2px rgba(0,0,0,0.05)"
3650
+ },
3651
+ /* @__PURE__ */ e.createElement(F.Visibility, { style: { fontSize: "14px" } }),
3652
+ /* @__PURE__ */ e.createElement("span", null, "Show All")
3653
+ ), /* @__PURE__ */ e.createElement(
3654
+ "button",
3655
+ {
3656
+ onClick: () => y.toggleAllColumnsVisible(!1),
3657
+ style: {
3658
+ ...Y.btn,
3659
+ padding: "8px 12px",
3660
+ fontSize: "11px",
3661
+ flex: 1,
3662
+ justifyContent: "center",
3663
+ background: c.background,
3664
+ fontWeight: 600,
3665
+ boxShadow: "0 1px 2px rgba(0,0,0,0.05)",
3666
+ transition: "all 0.2s"
3667
+ },
3668
+ onMouseEnter: (t) => t.currentTarget.style.boxShadow = "0 2px 4px rgba(0,0,0,0.1)",
3669
+ onMouseLeave: (t) => t.currentTarget.style.boxShadow = "0 1px 2px rgba(0,0,0,0.05)"
3670
+ },
3671
+ /* @__PURE__ */ e.createElement(F.VisibilityOff, { style: { fontSize: "14px" } }),
3672
+ /* @__PURE__ */ e.createElement("span", null, "Hide All")
3673
+ ), /* @__PURE__ */ e.createElement(
3674
+ "button",
3675
+ {
3676
+ onClick: () => Q(!1),
3677
+ style: {
3678
+ ...Y.btn,
3679
+ padding: "8px 12px",
3680
+ fontSize: "11px",
3681
+ flex: 1,
3682
+ justifyContent: "center",
3683
+ background: c.background,
3684
+ fontWeight: 600,
3685
+ boxShadow: "0 1px 2px rgba(0,0,0,0.05)",
3686
+ transition: "all 0.2s"
3687
+ },
3688
+ onMouseEnter: (t) => t.currentTarget.style.boxShadow = "0 2px 4px rgba(0,0,0,0.1)",
3689
+ onMouseLeave: (t) => t.currentTarget.style.boxShadow = "0 1px 2px rgba(0,0,0,0.05)"
3690
+ },
3691
+ /* @__PURE__ */ e.createElement(F.Unpin, { style: { fontSize: "14px" } }),
3692
+ /* @__PURE__ */ e.createElement("span", null, "Unpin All")
3693
+ )), w.size > 0 && /* @__PURE__ */ e.createElement("div", { style: {
3694
+ display: "flex",
3695
+ flexDirection: "column",
3696
+ gap: "8px",
3697
+ background: `linear-gradient(135deg, ${c.select}ee, ${c.select}dd)`,
3698
+ padding: "12px",
3699
+ borderRadius: "8px",
3700
+ border: `2px solid ${c.primary}66`,
3701
+ boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
3702
+ margin: "0 8px"
3703
+ } }, /* @__PURE__ */ e.createElement("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" } }, /* @__PURE__ */ e.createElement("span", { style: {
3704
+ fontSize: "12px",
3705
+ fontWeight: 700,
3706
+ padding: "4px 10px",
3707
+ color: c.primary,
3708
+ background: c.background,
3709
+ borderRadius: "6px",
3710
+ boxShadow: "0 1px 2px rgba(0,0,0,0.05)"
3711
+ } }, w.size, " Column", w.size > 1 ? "s" : "", " Selected"), /* @__PURE__ */ e.createElement(
3712
+ "button",
3713
+ {
3714
+ onClick: () => B(/* @__PURE__ */ new Set()),
3715
+ style: {
3716
+ border: "none",
3717
+ background: c.background,
3718
+ cursor: "pointer",
3719
+ display: "flex",
3720
+ color: c.textSec,
3721
+ padding: "4px",
3722
+ borderRadius: "4px",
3723
+ transition: "all 0.2s"
3724
+ },
3725
+ onMouseEnter: (t) => t.currentTarget.style.background = c.hover,
3726
+ onMouseLeave: (t) => t.currentTarget.style.background = c.background
3727
+ },
3728
+ /* @__PURE__ */ e.createElement(F.Close, null)
3729
+ )), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" } }, /* @__PURE__ */ e.createElement(
3730
+ "button",
3731
+ {
3732
+ onClick: () => {
3733
+ Array.from(w).forEach((t) => K(t, "left")), B(/* @__PURE__ */ new Set());
3734
+ },
3735
+ style: {
3736
+ ...Y.btn,
3737
+ padding: "6px 12px",
3738
+ fontSize: "11px",
3739
+ background: c.background,
3740
+ flex: 1,
3741
+ justifyContent: "center",
3742
+ fontWeight: 600,
3743
+ boxShadow: "0 1px 2px rgba(0,0,0,0.05)",
3744
+ transition: "all 0.2s"
3745
+ },
3746
+ onMouseEnter: (t) => t.currentTarget.style.boxShadow = "0 2px 4px rgba(0,0,0,0.1)",
3747
+ onMouseLeave: (t) => t.currentTarget.style.boxShadow = "0 1px 2px rgba(0,0,0,0.05)"
3748
+ },
3749
+ /* @__PURE__ */ e.createElement(F.PinLeft, null),
3750
+ /* @__PURE__ */ e.createElement("span", null, "Pin Left")
3751
+ ), /* @__PURE__ */ e.createElement(
3752
+ "button",
3753
+ {
3754
+ onClick: () => {
3755
+ Array.from(w).forEach((t) => K(t, !1)), B(/* @__PURE__ */ new Set());
3756
+ },
3757
+ style: {
3758
+ ...Y.btn,
3759
+ padding: "6px 12px",
3760
+ fontSize: "11px",
3761
+ background: c.background,
3762
+ flex: 1,
3763
+ justifyContent: "center",
3764
+ fontWeight: 600,
3765
+ boxShadow: "0 1px 2px rgba(0,0,0,0.05)",
3766
+ transition: "all 0.2s"
3767
+ },
3768
+ onMouseEnter: (t) => t.currentTarget.style.boxShadow = "0 2px 4px rgba(0,0,0,0.1)",
3769
+ onMouseLeave: (t) => t.currentTarget.style.boxShadow = "0 1px 2px rgba(0,0,0,0.05)"
3770
+ },
3771
+ /* @__PURE__ */ e.createElement(F.Unpin, null),
3772
+ /* @__PURE__ */ e.createElement("span", null, "Unpin")
3773
+ ), /* @__PURE__ */ e.createElement(
3774
+ "button",
3775
+ {
3776
+ onClick: () => {
3777
+ Array.from(w).forEach((t) => K(t, "right")), B(/* @__PURE__ */ new Set());
3778
+ },
3779
+ style: {
3780
+ ...Y.btn,
3781
+ padding: "6px 12px",
3782
+ fontSize: "11px",
3783
+ background: c.background,
3784
+ flex: 1,
3785
+ justifyContent: "center",
3786
+ fontWeight: 600,
3787
+ boxShadow: "0 1px 2px rgba(0,0,0,0.05)",
3788
+ transition: "all 0.2s"
3789
+ },
3790
+ onMouseEnter: (t) => t.currentTarget.style.boxShadow = "0 2px 4px rgba(0,0,0,0.1)",
3791
+ onMouseLeave: (t) => t.currentTarget.style.boxShadow = "0 1px 2px rgba(0,0,0,0.05)"
3792
+ },
3793
+ /* @__PURE__ */ e.createElement(F.PinRight, null),
3794
+ /* @__PURE__ */ e.createElement("span", null, "Pin Right")
3795
+ ))), /* @__PURE__ */ e.createElement("div", { style: { flex: 1, overflowY: "auto", display: "flex", flexDirection: "column" } }, (() => {
3796
+ const d = y.getAllColumns().filter(
3797
+ /** @param {any} [c] @returns {any} */
3798
+ (v) => !v.parent && v.id !== "no_data"
3799
+ ).filter(
3800
+ /** @param {any} [col] @returns {any} */
3801
+ (v) => {
3802
+ if (i === "all") return !0;
3803
+ let H = "string";
3804
+ if (S.find(
3805
+ /** @param {any} [v] @returns {any} */
3806
+ (ae) => v.id.includes(ae.field)
3807
+ ))
3808
+ H = "number";
3809
+ else if (pe && pe.length > 0) {
3810
+ const ae = pe[0];
3811
+ let oe = ae[v.id];
3812
+ if (oe === void 0 && v.accessorFn)
3813
+ try {
3814
+ oe = v.accessorFn(ae);
3815
+ } catch {
3816
+ }
3817
+ typeof oe == "number" ? H = "number" : oe instanceof Date ? H = "date" : typeof oe == "string" && (!isNaN(Number(oe)) && oe.trim() !== "" ? H = "number" : !isNaN(Date.parse(oe)) && oe.includes("-") && (H = "date"));
3818
+ }
3819
+ return H === i;
3820
+ }
3821
+ ), u = d.filter(
3822
+ /** @param {any} [c] @returns {any} */
3823
+ (v) => at(v, "left")
3824
+ ), b = d.filter(
3825
+ /** @param {any} [c] @returns {any} */
3826
+ (v) => at(v, "right")
3827
+ ), h = d.filter(
3828
+ /** @param {any} [c] @returns {any} */
3829
+ (v) => at(v, "unpinned")
3830
+ ), I = (v, H) => v.map(
3831
+ /** @param {any} [column] @returns {any} */
3832
+ (le) => /* @__PURE__ */ e.createElement(
3833
+ fr,
3834
+ {
3835
+ key: le.id,
3836
+ column: le,
3837
+ level: 0,
3838
+ theme: c,
3839
+ styles: Y,
3840
+ handlePinColumn: K,
3841
+ colSearch: R,
3842
+ selectedCols: w,
3843
+ setSelectedCols: B,
3844
+ onDrop: G,
3845
+ sectionId: H
3846
+ }
3847
+ )
3848
+ ), G = (v, H, le) => {
3849
+ let ae;
3850
+ const oe = P || { left: [], right: [] };
3851
+ if (le) {
3852
+ const Xe = H === "left" ? oe.left : H === "right" ? oe.right : null;
3853
+ if (Xe) {
3854
+ if (ae = Xe.indexOf(le), ae === -1) {
3855
+ const vt = y.getColumn(le);
3856
+ if (vt && tn(vt)) {
3857
+ const Gt = kt(vt).find(
3858
+ /** @param {any} [id] @returns {any} */
3859
+ (Hr) => Xe.includes(Hr)
3860
+ );
3861
+ Gt && (ae = Xe.indexOf(Gt));
3862
+ }
3863
+ }
3864
+ ae === -1 && (ae = void 0);
3865
+ }
3866
+ }
3867
+ H === "left" ? K(v, "left", ae) : H === "right" ? K(v, "right", ae) : K(v, !1);
3868
+ };
3869
+ return /* @__PURE__ */ e.createElement(e.Fragment, null, u.length > 0 && /* @__PURE__ */ e.createElement(
3870
+ St,
3871
+ {
3872
+ title: "Pinned Left",
3873
+ count: u.length,
3874
+ theme: c,
3875
+ styles: Y,
3876
+ sectionId: "left",
3877
+ onDrop: G
3878
+ },
3879
+ I(u, "left")
3880
+ ), b.length > 0 && /* @__PURE__ */ e.createElement(
3881
+ St,
3882
+ {
3883
+ title: "Pinned Right",
3884
+ count: b.length,
3885
+ theme: c,
3886
+ styles: Y,
3887
+ sectionId: "right",
3888
+ onDrop: G
3889
+ },
3890
+ I(b, "right")
3891
+ ), /* @__PURE__ */ e.createElement(
3892
+ St,
3893
+ {
3894
+ title: "Columns",
3895
+ count: h.length,
3896
+ theme: c,
3897
+ styles: Y,
3898
+ sectionId: "unpinned",
3899
+ onDrop: G
3900
+ },
3901
+ I(h, "unpinned")
3902
+ ));
3903
+ })()), C && C.length > 0 && /* @__PURE__ */ e.createElement("div", { style: { padding: "8px", borderTop: `1px solid ${c.border}` } }, /* @__PURE__ */ e.createElement("div", { style: Y.sectionTitle }, "Pinning Presets"), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: "4px", flexWrap: "wrap" } }, C.map(
3904
+ /** @param {any} [preset] @param {any} [i] @returns {any} */
3905
+ (t, d) => /* @__PURE__ */ e.createElement(
3906
+ "button",
3907
+ {
3908
+ key: d,
3909
+ onClick: () => {
3910
+ M(t.config), D(`Applied preset: ${t.name}`);
3911
+ },
3912
+ style: { ...Y.btn, fontSize: "11px", background: c.headerBg }
3913
+ },
3914
+ t.name
3915
+ )
3916
+ ))), /* @__PURE__ */ e.createElement("div", { style: { fontSize: "11px", color: c.textSec, fontStyle: "italic", padding: "8px", background: c.headerBg, borderTop: `1px solid ${c.border}44` } }, /* @__PURE__ */ e.createElement(F.Lock, { style: { verticalAlign: "middle", marginRight: "4px", opacity: 0.5 } }), "Drag columns or use pin icons to freeze areas."))), ht && /* @__PURE__ */ e.createElement(
3917
+ $n,
3918
+ {
3919
+ item: ht,
3920
+ idx: Et,
3921
+ valConfigs: S,
3922
+ setValConfigs: g,
3923
+ theme: c,
3924
+ onClose: () => Re(null),
3925
+ onRemove: Ge,
3926
+ displayedColumnOptions: Ee,
3927
+ availableRawFields: te,
3928
+ serverError: We && We[ht.field] || null
3929
+ }
3930
+ ), /* @__PURE__ */ e.createElement(
3931
+ "div",
3932
+ {
3933
+ className: "sp-resize-handle",
3934
+ onMouseDown: Ir,
3935
+ title: "Drag to resize panel",
3936
+ style: { position: "absolute", right: -2, top: 0, bottom: 0, width: "9px", cursor: "col-resize", zIndex: 10, background: "transparent", display: "flex", alignItems: "center", justifyContent: "center" }
3937
+ },
3938
+ /* @__PURE__ */ e.createElement("span", { className: "sp-resize-pill", "aria-hidden": "true", style: { width: "2px", height: "100%", borderRadius: "999px", background: c.border, opacity: 0.55, pointerEvents: "none" } })
3939
+ ));
3940
+ }
3941
+ );
3942
+ export {
3943
+ _n as SidebarPanel
3944
+ };