serverside_pivot 0.0.95 → 0.0.98

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