serverside_pivot 0.0.0-stage → 0.0.91

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 (185) hide show
  1. package/README.md +182 -3
  2. package/dist/react/chunks/ContextMenu-Bt5_3bmD.mjs +192 -0
  3. package/dist/react/chunks/DetailDrawer-Eb4EpVHG.mjs +37 -0
  4. package/dist/react/chunks/DetailSidePanel-BTcHOiKr.mjs +36 -0
  5. package/dist/react/chunks/DetailSurfaceContent-B3ZNKh7q.mjs +200 -0
  6. package/dist/react/chunks/ECharts2dRenderer-C3Qv0uAa.mjs +3299 -0
  7. package/dist/react/chunks/ECharts3dRenderer-BB_7-fOt.mjs +21573 -0
  8. package/dist/react/chunks/EditSidePanel-C2cAvxlK.mjs +298 -0
  9. package/dist/react/chunks/InlineDetailPanel-BXLAw1o3.mjs +41 -0
  10. package/dist/react/chunks/PivotCharts-Bw6Swoa3.mjs +4252 -0
  11. package/dist/react/chunks/ReportEditor-D4V0ry2B.mjs +1726 -0
  12. package/dist/react/chunks/SidebarPanel-xO59p_2o.mjs +3339 -0
  13. package/dist/react/chunks/SparklineDetailGraph-Bu85X7OJ.mjs +200 -0
  14. package/dist/react/chunks/installCanvasRenderer-B7sfDGoL.mjs +21281 -0
  15. package/dist/react/chunks/react-CPZZxtSo.mjs +26999 -0
  16. package/dist/react/chunks/xlsx.mini.min-vfxHk3Ry.mjs +7996 -0
  17. package/dist/react/components/Charts/ChartRenderers.d.ts +73 -0
  18. package/dist/react/components/Charts/ChartWorkspace.d.ts +38 -0
  19. package/dist/react/components/Charts/ECharts2dRenderer.d.ts +5 -0
  20. package/dist/react/components/Charts/ECharts3dRenderer.d.ts +6 -0
  21. package/dist/react/components/Charts/PivotCharts.d.ts +9 -0
  22. package/dist/react/components/Charts/chartEnhancements.d.ts +66 -0
  23. package/dist/react/components/Charts/chartExportPresentation.d.ts +19 -0
  24. package/dist/react/components/Charts/chartMath.d.ts +4 -0
  25. package/dist/react/components/Charts/useChartExportMenu.d.ts +12 -0
  26. package/dist/react/components/DashTanstackPivot.react.d.ts +372 -0
  27. package/dist/react/components/Filters/ColumnFilter.d.ts +13 -0
  28. package/dist/react/components/Filters/DateRangeFilter.d.ts +8 -0
  29. package/dist/react/components/Filters/FilterPopover.d.ts +14 -0
  30. package/dist/react/components/Filters/MultiSelectFilter.d.ts +12 -0
  31. package/dist/react/components/Filters/NumericRangeFilter.d.ts +8 -0
  32. package/dist/react/components/Notification.d.ts +7 -0
  33. package/dist/react/components/PivotAppBar.d.ts +2 -0
  34. package/dist/react/components/PivotErrorBoundary.d.ts +15 -0
  35. package/dist/react/components/PivotSmallComponents.d.ts +6 -0
  36. package/dist/react/components/PivotWorkspace.d.ts +19 -0
  37. package/dist/react/components/PivotWorkspaceCanvas.d.ts +5 -0
  38. package/dist/react/components/PivotWorkspaceControls.d.ts +12 -0
  39. package/dist/react/components/PivotWorkspaceShell.d.ts +12 -0
  40. package/dist/react/components/RuntimeDataError.d.ts +7 -0
  41. package/dist/react/components/Sidebar/ColumnTreeItem.d.ts +14 -0
  42. package/dist/react/components/Sidebar/ReportEditor.d.ts +21 -0
  43. package/dist/react/components/Sidebar/SidebarFilterItem.d.ts +14 -0
  44. package/dist/react/components/Sidebar/SidebarPanel.d.ts +2 -0
  45. package/dist/react/components/Sidebar/ToolPanelSection.d.ts +14 -0
  46. package/dist/react/components/Sidebar/customCategoryUtils.d.ts +62 -0
  47. package/dist/react/components/Sidebar/formulaUtils.d.ts +22 -0
  48. package/dist/react/components/SkeletonRow.d.ts +6 -0
  49. package/dist/react/components/Table/ContextMenu.d.ts +9 -0
  50. package/dist/react/components/Table/DetailDrawer.d.ts +12 -0
  51. package/dist/react/components/Table/DetailSidePanel.d.ts +12 -0
  52. package/dist/react/components/Table/DetailSurfaceContent.d.ts +12 -0
  53. package/dist/react/components/Table/EditSidePanel.d.ts +21 -0
  54. package/dist/react/components/Table/EditableCell.d.ts +29 -0
  55. package/dist/react/components/Table/InlineDetailPanel.d.ts +14 -0
  56. package/dist/react/components/Table/PivotTableBody.d.ts +9 -0
  57. package/dist/react/components/Table/SparklineCell.d.ts +17 -0
  58. package/dist/react/components/Table/SparklineDetailGraph.d.ts +5 -0
  59. package/dist/react/components/Table/StatusBar.d.ts +8 -0
  60. package/dist/react/contexts/PivotConfigContext.d.ts +34 -0
  61. package/dist/react/contexts/PivotThemeContext.d.ts +7 -0
  62. package/dist/react/contexts/PivotValueDisplayContext.d.ts +10 -0
  63. package/dist/react/hooks/useCellInteraction.d.ts +31 -0
  64. package/dist/react/hooks/useChartState.d.ts +76 -0
  65. package/dist/react/hooks/useColumnDefs.d.ts +82 -0
  66. package/dist/react/hooks/useColumnVirtualizer.d.ts +30 -0
  67. package/dist/react/hooks/useDetailDrillThrough.d.ts +38 -0
  68. package/dist/react/hooks/useFilteredData.d.ts +2 -0
  69. package/dist/react/hooks/useFormatState.d.ts +44 -0
  70. package/dist/react/hooks/usePersistence.d.ts +5 -0
  71. package/dist/react/hooks/usePivotFieldInteractions.d.ts +28 -0
  72. package/dist/react/hooks/usePivotNormalization.d.ts +483 -0
  73. package/dist/react/hooks/usePivotRenderCounter.d.ts +1 -0
  74. package/dist/react/hooks/usePivotTransactions.d.ts +29 -0
  75. package/dist/react/hooks/useRenderHelpers.d.ts +85 -0
  76. package/dist/react/hooks/useReportMode.d.ts +32 -0
  77. package/dist/react/hooks/useRowCache.d.ts +19 -0
  78. package/dist/react/hooks/useRuntimeDataCommit.d.ts +26 -0
  79. package/dist/react/hooks/useRuntimeProfiling.d.ts +19 -0
  80. package/dist/react/hooks/useRuntimeTransport.d.ts +24 -0
  81. package/dist/react/hooks/useServerSideRowModel.d.ts +50 -0
  82. package/dist/react/hooks/useServerSideViewportController.d.ts +64 -0
  83. package/dist/react/hooks/useSidebarUI.d.ts +37 -0
  84. package/dist/react/hooks/useStickyStyles.d.ts +24 -0
  85. package/dist/react/index.mjs +16 -0
  86. package/dist/react/presentation/headerFormatting.d.ts +13 -0
  87. package/dist/react/presentation/safeCellContent.d.ts +16 -0
  88. package/dist/react/react.d.ts +8 -0
  89. package/dist/react/runtime/PivotRuntimeRoot.d.ts +7 -0
  90. package/dist/react/runtime/cellSelectionAnchor.d.ts +45 -0
  91. package/dist/react/runtime/client/clientPivotTransport.d.ts +28 -0
  92. package/dist/react/runtime/client/clientResponsePostProcessor.d.ts +20 -0
  93. package/dist/react/runtime/client/clientSqlPlanner.d.ts +5 -0
  94. package/dist/react/runtime/client/duckdbWasmExecutor.d.ts +36 -0
  95. package/dist/react/runtime/client/index.d.ts +6 -0
  96. package/dist/react/runtime/client/modeResolver.d.ts +16 -0
  97. package/dist/react/runtime/client/types.d.ts +202 -0
  98. package/dist/react/runtime/createRuntimeCellPresentation.d.ts +7 -0
  99. package/dist/react/runtime/createRuntimeExportCommands.d.ts +77 -0
  100. package/dist/react/runtime/createRuntimeRowPinCommand.d.ts +9 -0
  101. package/dist/react/runtime/createWorkspacePresentation.d.ts +7 -0
  102. package/dist/react/runtime/displayColumnOrder.d.ts +4 -0
  103. package/dist/react/runtime/httpTransport.d.ts +65 -0
  104. package/dist/react/runtime/runtime-contract.generated.d.ts +48 -0
  105. package/dist/react/runtime/runtime-response-contract.generated.d.ts +34 -0
  106. package/dist/react/runtime/runtimeContract.d.ts +115 -0
  107. package/dist/react/runtime/runtimeDomains.d.ts +642 -0
  108. package/dist/react/runtime/runtimeDomains.type-test.d.ts +1 -0
  109. package/dist/react/runtime/runtimeResponseDedup.d.ts +36 -0
  110. package/dist/react/runtime/useChartWorkspacePresentation.d.ts +50 -0
  111. package/dist/react/runtime/useCommandRuntime.d.ts +3 -0
  112. package/dist/react/runtime/useCommandRuntimeStage.d.ts +1 -0
  113. package/dist/react/runtime/useCoreRuntime.d.ts +3 -0
  114. package/dist/react/runtime/useCoreRuntimeStage.d.ts +3 -0
  115. package/dist/react/runtime/useRuntimeCellSelection.d.ts +44 -0
  116. package/dist/react/runtime/useRuntimeChartCanvasCommands.d.ts +36 -0
  117. package/dist/react/runtime/useRuntimeChartCanvasResize.d.ts +13 -0
  118. package/dist/react/runtime/useRuntimeChartCanvasVerticalResize.d.ts +9 -0
  119. package/dist/react/runtime/useRuntimeChartDefinitionCommands.d.ts +14 -0
  120. package/dist/react/runtime/useRuntimeChartFloatingInteractions.d.ts +28 -0
  121. package/dist/react/runtime/useRuntimeChartModels.d.ts +69 -0
  122. package/dist/react/runtime/useRuntimeChartPanelSizing.d.ts +12 -0
  123. package/dist/react/runtime/useRuntimeChartRequestDispatch.d.ts +7 -0
  124. package/dist/react/runtime/useRuntimeClipboardExportPresentation.d.ts +159 -0
  125. package/dist/react/runtime/useRuntimeClipboardPaste.d.ts +7 -0
  126. package/dist/react/runtime/useRuntimeColorScalePresentation.d.ts +55 -0
  127. package/dist/react/runtime/useRuntimeColumnAutoSizing.d.ts +26 -0
  128. package/dist/react/runtime/useRuntimeColumnCommands.d.ts +22 -0
  129. package/dist/react/runtime/useRuntimeColumnMeasurement.d.ts +16 -0
  130. package/dist/react/runtime/useRuntimeDataRetry.d.ts +12 -0
  131. package/dist/react/runtime/useRuntimeDisplayNavigation.d.ts +17 -0
  132. package/dist/react/runtime/useRuntimeEditCellIdentity.d.ts +22 -0
  133. package/dist/react/runtime/useRuntimeEditChangeTracking.d.ts +28 -0
  134. package/dist/react/runtime/useRuntimeEditComparisonState.d.ts +35 -0
  135. package/dist/react/runtime/useRuntimeEditDispatch.d.ts +47 -0
  136. package/dist/react/runtime/useRuntimeEditOwnership.d.ts +32 -0
  137. package/dist/react/runtime/useRuntimeEditPresentation.d.ts +32 -0
  138. package/dist/react/runtime/useRuntimeEditStatePersistence.d.ts +28 -0
  139. package/dist/react/runtime/useRuntimeExportState.d.ts +20 -0
  140. package/dist/react/runtime/useRuntimeFilterPopover.d.ts +23 -0
  141. package/dist/react/runtime/useRuntimeLayoutHistory.d.ts +44 -0
  142. package/dist/react/runtime/useRuntimeOptimisticCellState.d.ts +27 -0
  143. package/dist/react/runtime/useRuntimeRequestSession.d.ts +79 -0
  144. package/dist/react/runtime/useRuntimeResponseLifecycle.d.ts +47 -0
  145. package/dist/react/runtime/useRuntimeResponsePostCommit.d.ts +15 -0
  146. package/dist/react/runtime/useRuntimeRowEditSessions.d.ts +28 -0
  147. package/dist/react/runtime/useRuntimeRowEditing.d.ts +18 -0
  148. package/dist/react/runtime/useRuntimeRowSelection.d.ts +14 -0
  149. package/dist/react/runtime/useRuntimeSelectionFormatting.d.ts +36 -0
  150. package/dist/react/runtime/useRuntimeStructuralSync.d.ts +65 -0
  151. package/dist/react/runtime/useRuntimeViewRestoreScroll.d.ts +9 -0
  152. package/dist/react/runtime/useRuntimeViewSnapshot.d.ts +203 -0
  153. package/dist/react/runtime/useRuntimeViewportTableData.d.ts +23 -0
  154. package/dist/react/runtime/useTransportRuntime.d.ts +12 -0
  155. package/dist/react/runtime/useViewportRuntime.d.ts +3 -0
  156. package/dist/react/runtime/useViewportRuntimeStage.d.ts +1 -0
  157. package/dist/react/runtime/useWorkspaceRuntime.d.ts +3 -0
  158. package/dist/react/runtime/useWorkspaceRuntimeStage.d.ts +1 -0
  159. package/dist/react/runtime/useWorkspaceStatusPresentation.d.ts +115 -0
  160. package/dist/react/runtime/workspaceViewModel.d.ts +7 -0
  161. package/dist/react/utils/Icons.d.ts +46 -0
  162. package/dist/react/utils/chartModelBuilders.d.ts +236 -0
  163. package/dist/react/utils/columnOrder.d.ts +12 -0
  164. package/dist/react/utils/dataBars.d.ts +7 -0
  165. package/dist/react/utils/domEvents.d.ts +1 -0
  166. package/dist/react/utils/editing.d.ts +47 -0
  167. package/dist/react/utils/exportUtils.d.ts +121 -0
  168. package/dist/react/utils/fieldPanelLayout.d.ts +61 -0
  169. package/dist/react/utils/filterOptions.d.ts +4 -0
  170. package/dist/react/utils/formatting.d.ts +1 -0
  171. package/dist/react/utils/helpers.d.ts +20 -0
  172. package/dist/react/utils/horizontalViewport.d.ts +12 -0
  173. package/dist/react/utils/layoutRows.d.ts +3 -0
  174. package/dist/react/utils/measureAxis.d.ts +22 -0
  175. package/dist/react/utils/pivotLayoutUtils.d.ts +2 -0
  176. package/dist/react/utils/pivotProfiler.d.ts +4 -0
  177. package/dist/react/utils/rawTableTsv.d.ts +21 -0
  178. package/dist/react/utils/reportEditorSelection.d.ts +23 -0
  179. package/dist/react/utils/rowSpanning.d.ts +6 -0
  180. package/dist/react/utils/savedReports.d.ts +7 -0
  181. package/dist/react/utils/sorting.d.ts +14 -0
  182. package/dist/react/utils/sparklineDetail.d.ts +8 -0
  183. package/dist/react/utils/sparklines.d.ts +78 -0
  184. package/dist/react/utils/styles.d.ts +957 -0
  185. package/package.json +114 -6
@@ -0,0 +1,1726 @@
1
+ import t, { useState as H, useRef as ke, useMemo as z, useCallback as B, useEffect as $e } from "react";
2
+ import { a9 as Et, am as St, y as v, an as Ct, ab as wt, Y as M, ao as At } from "./react-CPZZxtSo.mjs";
3
+ const ae = () => `r${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`, Xe = [
4
+ { value: "eq", label: "Equals" },
5
+ { value: "not_eq", label: "Not equals" },
6
+ { value: "in", label: "In list" },
7
+ { value: "not_in", label: "Not in list" },
8
+ { value: "contains", label: "Contains" },
9
+ { value: "not_contains", label: "Does not contain" },
10
+ { value: "gt", label: "Greater than" },
11
+ { value: "gte", label: "Greater or equal" },
12
+ { value: "lt", label: "Less than" },
13
+ { value: "lte", label: "Less or equal" }
14
+ ], de = /* @__PURE__ */ new Set(["in", "not_in"]), kt = {
15
+ eq: "=",
16
+ not_eq: "!=",
17
+ in: "in",
18
+ not_in: "not in",
19
+ contains: "contains",
20
+ not_contains: "not contains",
21
+ gt: ">",
22
+ gte: ">=",
23
+ lt: "<",
24
+ lte: "<="
25
+ }, $t = /* @__PURE__ */ new Set([
26
+ "depth",
27
+ "_id",
28
+ "_path",
29
+ "_levelLabel",
30
+ "_levelField",
31
+ "_pathFields",
32
+ "_has_children",
33
+ "_is_expanded",
34
+ "__col_schema"
35
+ ]), T = "default", Be = "branch:", Qe = ["", "solid", "dashed", "dotted", "double"], Ue = (e = "") => ({ _id: ae(), field: e, operator: "eq", value: "", values: [] }), Pe = () => ({ op: "AND", clauses: [] }), Ft = () => ({ _id: ae(), label: "", condition: Pe(), child: null }), me = (e = {}) => {
36
+ const l = e && typeof e == "object" ? e : {}, n = Number(l.indent), a = Number(l.borderWidth), r = typeof l.borderStyle == "string" && Qe.includes(l.borderStyle) ? l.borderStyle : "";
37
+ return {
38
+ indent: Number.isFinite(n) && n >= 0 ? Math.floor(n) : "",
39
+ bold: l.bold === !0,
40
+ showSubtotal: l.showSubtotal !== !1,
41
+ rowColor: typeof l.rowColor == "string" ? l.rowColor : "",
42
+ labelPrefix: typeof l.labelPrefix == "string" ? l.labelPrefix : "",
43
+ labelSuffix: typeof l.labelSuffix == "string" ? l.labelSuffix : "",
44
+ numberFormat: typeof l.numberFormat == "string" ? l.numberFormat : "",
45
+ borderStyle: r,
46
+ borderColor: typeof l.borderColor == "string" ? l.borderColor : "",
47
+ borderWidth: Number.isFinite(a) && a > 0 ? Math.floor(a) : ""
48
+ };
49
+ }, G = (e = "") => ({
50
+ _id: ae(),
51
+ field: e,
52
+ label: "",
53
+ topN: null,
54
+ sortBy: null,
55
+ sortDir: "desc",
56
+ sortAbs: !1,
57
+ filters: null,
58
+ format: me(),
59
+ defaultChild: null,
60
+ branches: []
61
+ }), Bt = (e) => !e || typeof e.field != "string" || !e.field ? null : {
62
+ _id: typeof e._id == "string" ? e._id : ae(),
63
+ field: e.field,
64
+ operator: Xe.some((l) => l.value === e.operator) ? e.operator : "eq",
65
+ value: e.value !== void 0 && e.value !== null ? String(e.value) : "",
66
+ values: Array.isArray(e.values) ? e.values.map(String).filter(Boolean) : []
67
+ }, Le = (e) => ({
68
+ op: e && e.op === "OR" ? "OR" : "AND",
69
+ clauses: Array.isArray(e && e.clauses) ? e.clauses.map(Bt).filter(Boolean) : []
70
+ }), De = (e) => !e || typeof e != "object" ? null : {
71
+ _id: typeof e._id == "string" ? e._id : ae(),
72
+ label: typeof e.label == "string" ? e.label : "",
73
+ condition: Le(e.condition),
74
+ sourceRowPath: Array.isArray(e.sourceRowPath) ? e.sourceRowPath.map(String).filter(Boolean) : [],
75
+ sourcePathFields: Array.isArray(e.sourcePathFields) ? e.sourcePathFields.map(String).filter(Boolean) : [],
76
+ child: e.child ? V(e.child) : null
77
+ };
78
+ function V(e) {
79
+ if (!e || typeof e != "object") return null;
80
+ let l = Array.isArray(e.branches) ? e.branches.map(De).filter(Boolean) : [];
81
+ l.length === 0 && e.childrenByValue && typeof e.childrenByValue == "object" && (l = Object.entries(e.childrenByValue).filter(([a]) => a).map(([a, r]) => De({
82
+ label: a,
83
+ condition: { op: "AND", clauses: [{ field: e.field || "", operator: "eq", value: a, values: [] }] },
84
+ child: r
85
+ })).filter(Boolean));
86
+ const n = e.filters && typeof e.filters == "object" ? Le(e.filters) : null;
87
+ return {
88
+ _id: typeof e._id == "string" ? e._id : ae(),
89
+ field: typeof e.field == "string" ? e.field : "",
90
+ label: typeof e.label == "string" ? e.label : "",
91
+ topN: Number.isFinite(Number(e.topN)) && Number(e.topN) > 0 ? Math.floor(Number(e.topN)) : null,
92
+ sortBy: typeof e.sortBy == "string" && e.sortBy.trim() ? e.sortBy.trim() : null,
93
+ sortDir: e.sortDir === "asc" ? "asc" : "desc",
94
+ sortAbs: e.sortAbs === !0,
95
+ filters: n && n.clauses.length > 0 ? n : null,
96
+ format: me(e.format),
97
+ defaultChild: e.defaultChild ? V(e.defaultChild) : null,
98
+ branches: l
99
+ };
100
+ }
101
+ const _e = (e) => `${Be}${e}`, Se = (e) => {
102
+ if (typeof e != "string" || !e.startsWith(Be)) return -1;
103
+ const l = parseInt(e.slice(Be.length), 10);
104
+ return Number.isFinite(l) ? l : -1;
105
+ }, Dt = (e, l) => {
106
+ const n = new Set(
107
+ (l || []).filter((a) => a && a.field && a.agg).map((a) => a.agg === "formula" ? a.field : `${a.field}_${a.agg}`)
108
+ );
109
+ return (e || []).filter((a) => a && typeof a == "string" && !$t.has(a) && (!a.startsWith("_") || wt(a)) && !n.has(a));
110
+ }, Rt = (e) => {
111
+ const l = [
112
+ { value: "", label: "(default)" },
113
+ { value: "__field__", label: "Field value (A→Z / Z→A)" }
114
+ ];
115
+ return (e || []).forEach((n) => {
116
+ if (!n || !n.field || !n.agg) return;
117
+ const a = n.agg === "formula" ? n.field : `${n.field}_${n.agg}`, r = n.agg === "formula" ? n.label || M(n.field) : `${M(n.field)} (${At(n.agg, n.weightField)})`;
118
+ l.push({ value: a, label: r });
119
+ }), l;
120
+ }, Ce = (e) => !e || !e.clauses || e.clauses.length === 0 ? "No filter" : e.clauses.map((l) => {
121
+ const n = M(l.field), a = kt[l.operator] || l.operator;
122
+ if (de.has(l.operator)) {
123
+ const r = l.values.slice(0, 3), i = l.values.length > 3 ? ` +${l.values.length - 3}` : "";
124
+ return `${n} ${a} [${r.join(", ")}${i}]`;
125
+ }
126
+ return `${n} ${a} ${l.value || "..."}`;
127
+ }).join(` ${e.op} `), et = (e, l) => {
128
+ if (!e) return "";
129
+ const n = (l || []).find((a) => a.value === e);
130
+ return n ? n.label : M(e);
131
+ }, tt = (e) => e ? e.label && e.label.trim() ? e.label.trim() : e.field ? M(e.field) : "Select field" : "Select field", Nt = (e) => !e || !e.field ? !1 : de.has(e.operator) ? Array.isArray(e.values) && e.values.length > 0 : e.value !== void 0 && e.value !== null && String(e.value).trim() !== "", Re = (e) => !!(e && Array.isArray(e.clauses) && e.clauses.length > 0) && e.clauses.every(Nt), Ke = (e, l) => {
132
+ if (!e || !l || typeof l != "object") return !1;
133
+ const n = l[e.field], a = n == null ? "" : String(n), r = e.value === void 0 || e.value === null ? "" : String(e.value), i = Array.isArray(e.values) ? e.values.map(String) : [], s = Number(a), f = Number(r);
134
+ switch (e.operator) {
135
+ case "not_eq":
136
+ return a !== r;
137
+ case "in":
138
+ return i.includes(a);
139
+ case "not_in":
140
+ return !i.includes(a);
141
+ case "contains":
142
+ return a.toLowerCase().includes(r.toLowerCase());
143
+ case "not_contains":
144
+ return !a.toLowerCase().includes(r.toLowerCase());
145
+ case "gt":
146
+ return Number.isFinite(s) && Number.isFinite(f) && s > f;
147
+ case "gte":
148
+ return Number.isFinite(s) && Number.isFinite(f) && s >= f;
149
+ case "lt":
150
+ return Number.isFinite(s) && Number.isFinite(f) && s < f;
151
+ case "lte":
152
+ return Number.isFinite(s) && Number.isFinite(f) && s <= f;
153
+ case "eq":
154
+ default:
155
+ return a === r;
156
+ }
157
+ }, Ye = (e, l) => {
158
+ if (!Re(e) || !Array.isArray(l) || l.length === 0) return !0;
159
+ const n = l.filter((r) => r && typeof r == "object" && !r._isTotal && !r._isOther);
160
+ return n.some((r) => e.clauses.every((i) => Object.prototype.hasOwnProperty.call(r, i.field))) ? n.some((r) => e.op === "OR" ? e.clauses.some((i) => Ke(i, r)) : e.clauses.every((i) => Ke(i, r))) : !0;
161
+ }, It = (e, l) => {
162
+ if (!Array.isArray(e) || e.length === 0 || !Array.isArray(l) || l.length === 0) return !0;
163
+ const n = e.map(String).join("|||");
164
+ return l.some((a) => a && typeof a == "object" && a._path === n);
165
+ }, Ge = (e, {
166
+ allFields: l = [],
167
+ valConfigs: n = [],
168
+ data: a = []
169
+ } = {}) => {
170
+ const r = [], i = [], s = (n || []).some((y) => y && y.field && y.agg), f = new Set(Array.isArray(l) ? l : []), m = /* @__PURE__ */ new Map(), g = Array.isArray(a) ? a : [], F = (y, w) => {
171
+ const c = y.trim().toLowerCase();
172
+ if (c) {
173
+ if (m.has(c)) {
174
+ r.push(`Duplicate header "${y}" at ${w}; already used at ${m.get(c)}.`);
175
+ return;
176
+ }
177
+ m.set(c, w);
178
+ }
179
+ }, N = (y, w, c = /* @__PURE__ */ new Set()) => {
180
+ if (!y) return;
181
+ const E = y._id || `${w}:${y.field || ""}`;
182
+ if (c.has(E)) {
183
+ r.push(`Circular row override detected at ${w}.`);
184
+ return;
185
+ }
186
+ const h = new Set(c);
187
+ h.add(E), y.field ? f.size > 0 && !f.has(y.field) && r.push(`Field "${M(y.field)}" at ${w} is no longer available.`) : r.push(`Missing field at ${w}.`), F(tt(y), w), y.topN && !s && r.push(`Top-N at ${w} needs at least one measure selected.`), y.filters && !Re(y.filters) ? r.push(`Level filter at ${w} has incomplete rules.`) : y.filters && !Ye(y.filters, g) && r.push(`Level filter at ${w} does not match any loaded rows.`), y.defaultChild && N(y.defaultChild, `${w} > Default children`, h), (y.branches || []).forEach((u, D) => {
188
+ const R = u.label && u.label.trim() ? u.label.trim() : `Row override ${D + 1}`, x = `${w} > ${R}`;
189
+ Re(u.condition) ? Ye(u.condition, g) || r.push(`Row override "${R}" does not match any loaded rows.`) : r.push(`Row override "${R}" needs a complete row rule.`), Array.isArray(u.sourcePathFields) && u.sourcePathFields.length > 0 && u.sourcePathFields[u.sourcePathFields.length - 1] !== y.field && r.push(`Row override "${R}" was created for another level and no longer points to this row path.`), It(u.sourceRowPath, g) || i.push(`Row override "${R}" points to a row path that is not in the current loaded rows.`), u.child && N(u.child, `${x} > Custom children`, h), u.child || i.push(`Row override "${R}" has no Custom children; it only renames the matching row.`);
190
+ });
191
+ };
192
+ return e ? N(e, "Level 1") : r.push("Report needs at least Level 1."), { errors: r, warnings: i, valid: r.length === 0 };
193
+ }, Pt = (e) => !e || !e.branchBadge ? `Level ${e ? e.levelNumber : 1}` : e.branchDepth === 0 ? `Override children ${e.branchBadge}` : `Override child level ${e.branchBadge}.${e.branchDepth + 1}`, ne = (e, l) => {
194
+ let n = e;
195
+ for (let a = 0; n && a < l.length; a += 1) {
196
+ const r = l[a];
197
+ if (r === T)
198
+ n = n.defaultChild || null;
199
+ else {
200
+ const i = Se(r);
201
+ n = i >= 0 && n.branches[i] ? n.branches[i].child : null;
202
+ }
203
+ }
204
+ return n || null;
205
+ }, Fe = (e, l, n) => {
206
+ const a = ne(e, l);
207
+ return a && a.branches[n] ? a.branches[n] : null;
208
+ }, O = (e, l, n) => {
209
+ if (!e) return e;
210
+ const a = (r, i) => {
211
+ if (!r) return r;
212
+ if (i >= l.length) return V(n(r));
213
+ const s = l[i];
214
+ if (s === T)
215
+ return V({
216
+ ...r,
217
+ defaultChild: a(r.defaultChild, i + 1)
218
+ });
219
+ const f = Se(s);
220
+ return f < 0 || f >= r.branches.length ? r : V({
221
+ ...r,
222
+ branches: r.branches.map((m, g) => g === f ? { ...m, child: a(m.child, i + 1) } : m)
223
+ });
224
+ };
225
+ return a(e, 0);
226
+ }, ve = (e, l, n, a) => e && O(e, l, (r) => n < 0 || n >= r.branches.length ? r : {
227
+ ...r,
228
+ branches: r.branches.map((i, s) => s === n ? De(a(i)) : i)
229
+ }), Lt = (e) => {
230
+ if (!e) return [];
231
+ const l = [], n = (a, r) => {
232
+ a && (l.push({
233
+ kind: "node",
234
+ node: a,
235
+ nodePath: r.nodePath,
236
+ depth: r.depth,
237
+ levelNumber: r.levelNumber,
238
+ branchBadge: r.branchBadge,
239
+ branchDepth: r.branchDepth
240
+ }), a.branches.forEach((i, s) => {
241
+ const f = `${r.levelNumber}.${s + 1}`;
242
+ l.push({
243
+ kind: "branch",
244
+ branch: i,
245
+ nodePath: r.nodePath,
246
+ branchIndex: s,
247
+ depth: r.depth + 1,
248
+ badge: f
249
+ }), i.child && n(i.child, {
250
+ nodePath: [...r.nodePath, _e(s)],
251
+ depth: r.depth + 2,
252
+ levelNumber: r.levelNumber + 1,
253
+ branchBadge: f,
254
+ branchDepth: 0
255
+ });
256
+ }), a.defaultChild && n(a.defaultChild, {
257
+ nodePath: [...r.nodePath, T],
258
+ depth: r.depth + 1,
259
+ levelNumber: r.levelNumber + 1,
260
+ branchBadge: r.branchBadge,
261
+ branchDepth: r.branchBadge ? r.branchDepth + 1 : 0
262
+ }));
263
+ };
264
+ return n(e, {
265
+ nodePath: [],
266
+ depth: 0,
267
+ levelNumber: 1,
268
+ branchBadge: null,
269
+ branchDepth: 0
270
+ }), l;
271
+ }, le = (e = []) => e.join(">"), we = (e = [], l = []) => le(e) === le(l), Q = (e) => e == null ? "" : String(e), Z = (e) => e ? e.type === "node" ? `node:${le(e.path)}` : e.type === "branch" ? `branch:${le(e.nodePath)}:${e.branchIndex}` : e.type === "rowPath" ? `rowPath:${le(e.nodePath)}:${e.field}:${Q(e.value)}` : "" : "", Ee = (e, l) => (e || []).find((n) => n.kind === "node" && we(n.nodePath, l)) || null, lt = (e, l, n) => (e || []).find((a) => a.kind === "branch" && we(a.nodePath, l) && a.branchIndex === n) || null, Ze = (e, l, n) => {
272
+ if (!e || !l) return !1;
273
+ const a = Q(n);
274
+ return (e.condition && Array.isArray(e.condition.clauses) ? e.condition.clauses : []).some((i) => !i || i.field !== l ? !1 : i.operator === "eq" || i.operator === "=" ? Q(i.value) === a : i.operator === "in" ? Array.isArray(i.values) && i.values.map(Q).includes(a) : !1);
275
+ }, _t = (e, l, n, a = "") => ({
276
+ ...Ft(),
277
+ label: Q(n || l),
278
+ condition: {
279
+ op: "AND",
280
+ clauses: [{
281
+ ...Ue(e),
282
+ operator: "eq",
283
+ value: Q(l),
284
+ values: []
285
+ }]
286
+ },
287
+ child: G(a)
288
+ }), Oe = (e) => {
289
+ if (!e) return null;
290
+ try {
291
+ return V(JSON.parse(JSON.stringify(e)));
292
+ } catch {
293
+ return V(e);
294
+ }
295
+ }, Ne = (e) => Array.from({ length: Math.max(0, e) }, () => T), We = (e, l = 1, n = []) => {
296
+ const a = [];
297
+ let r = e, i = 0, s = Array.isArray(n) ? [...n] : [];
298
+ for (; r; )
299
+ a.push({
300
+ node: r,
301
+ path: [...s],
302
+ index: i,
303
+ levelNumber: l + i
304
+ }), r = r.defaultChild || null, s = [...s, T], i += 1;
305
+ return a;
306
+ }, Ot = (e) => e ? { ...Oe(e), defaultChild: null } : null, Wt = (e) => {
307
+ if (!Array.isArray(e) || e.length === 0) return null;
308
+ let l = null;
309
+ for (let n = e.length - 1; n >= 0; n -= 1)
310
+ l = V({
311
+ ...Ot(e[n]),
312
+ defaultChild: l
313
+ });
314
+ return l;
315
+ }, rt = (e, l, n) => {
316
+ const a = We(e).map((s) => s.node);
317
+ if (l < 0 || n < 0 || l >= a.length || n >= a.length || l === n)
318
+ return e;
319
+ const r = [...a], [i] = r.splice(l, 1);
320
+ return r.splice(n, 0, i), Wt(r);
321
+ }, zt = (e) => {
322
+ const l = Oe(e);
323
+ return !l || !l.field ? null : l;
324
+ }, Tt = (e, l) => l ? l.type === "node" ? Ee(e, l.path) : l.type === "branch" ? lt(e, l.nodePath, l.branchIndex) : null : null, jt = (e, l) => {
325
+ if (!l) return [];
326
+ const n = [], a = (s) => {
327
+ const f = Ee(e, s);
328
+ f && n.push(f);
329
+ }, r = (s, f) => {
330
+ const m = lt(e, s, f);
331
+ m && n.push(m);
332
+ }, i = (s) => {
333
+ if (a([]), !Array.isArray(s) || s.length === 0) return;
334
+ let f = [];
335
+ s.forEach((m) => {
336
+ if (m === T) {
337
+ f = [...f, m], a(f);
338
+ return;
339
+ }
340
+ const g = Se(m);
341
+ g >= 0 && (r(f, g), f = [...f, m], a(f));
342
+ });
343
+ };
344
+ return l.type === "node" ? (i(l.path), n) : (i(l.nodePath), r(l.nodePath, l.branchIndex), n);
345
+ }, Mt = (e, l) => {
346
+ if (!l) return [];
347
+ if (l.type === "node") {
348
+ const a = [], r = Ee(e, [...l.path, T]);
349
+ r && a.push(r);
350
+ const i = (e || []).filter((s) => s.kind === "branch" && we(s.nodePath, l.path)).sort((s, f) => s.branchIndex - f.branchIndex);
351
+ return [...a, ...i];
352
+ }
353
+ const n = Ee(e, [...l.nodePath, _e(l.branchIndex)]);
354
+ return n ? [n] : [];
355
+ }, q = (e, l = {}) => ({
356
+ border: `1px solid ${e.border}`,
357
+ borderRadius: "10px",
358
+ padding: "8px 10px",
359
+ fontSize: "12px",
360
+ lineHeight: 1.4,
361
+ background: e.background || "#fff",
362
+ color: e.text,
363
+ outline: "none",
364
+ width: "100%",
365
+ ...l
366
+ }), j = (e, l = !1, n = !1) => ({
367
+ display: "inline-flex",
368
+ alignItems: "center",
369
+ justifyContent: "center",
370
+ gap: "6px",
371
+ background: n ? "#FEF2F2" : l ? `${e.primary || "#2563EB"}12` : e.hover || "#F9FAFB",
372
+ border: `1px solid ${n ? "#FECACA" : l ? `${e.primary || "#2563EB"}45` : e.border}`,
373
+ borderRadius: "9px",
374
+ padding: "7px 11px",
375
+ fontSize: "11px",
376
+ fontWeight: 700,
377
+ color: n ? "#B91C1C" : l ? e.primary || "#2563EB" : e.textSec,
378
+ cursor: "pointer"
379
+ }), L = (e) => ({
380
+ fontSize: "9px",
381
+ fontWeight: 800,
382
+ textTransform: "uppercase",
383
+ letterSpacing: "0.08em",
384
+ color: e.textSec,
385
+ display: "flex",
386
+ alignItems: "center",
387
+ gap: "6px",
388
+ marginBottom: "10px"
389
+ }), pe = (e) => ({
390
+ border: `1px solid ${e.border}`,
391
+ borderRadius: "14px",
392
+ background: e.surfaceBg || e.background || "#fff",
393
+ padding: "14px",
394
+ display: "flex",
395
+ flexDirection: "column",
396
+ gap: "12px"
397
+ }), Ht = (e) => ({
398
+ borderTop: `2px solid ${e.textSec || "#334155"}`,
399
+ paddingTop: "14px",
400
+ display: "flex",
401
+ flexDirection: "column",
402
+ gap: "12px"
403
+ }), nt = (e, l, n) => ({
404
+ width: `calc(100% - ${n * 14}px)`,
405
+ marginLeft: `${n * 14}px`,
406
+ border: `1px solid ${l ? e.primary || "#2563EB" : e.border}`,
407
+ borderRadius: "12px",
408
+ background: l ? e.select || `${e.primary || "#2563EB"}14` : e.surfaceBg || e.background || "#fff",
409
+ padding: "12px",
410
+ textAlign: "left",
411
+ cursor: "pointer",
412
+ display: "flex",
413
+ flexDirection: "column",
414
+ gap: "7px"
415
+ });
416
+ function X({ children: e, theme: l, tone: n = "neutral" }) {
417
+ const a = n === "primary" ? { background: `${l.primary || "#2563EB"}12`, border: `${l.primary || "#2563EB"}30`, color: l.primary || "#2563EB" } : { background: l.hover || "#F3F4F6", border: l.border, color: l.textSec };
418
+ return /* @__PURE__ */ t.createElement(
419
+ "span",
420
+ {
421
+ style: {
422
+ display: "inline-flex",
423
+ alignItems: "center",
424
+ gap: "4px",
425
+ padding: "3px 7px",
426
+ borderRadius: "999px",
427
+ fontSize: "10px",
428
+ fontWeight: 700,
429
+ border: `1px solid ${a.border}`,
430
+ background: a.background,
431
+ color: a.color
432
+ }
433
+ },
434
+ e
435
+ );
436
+ }
437
+ function re({
438
+ theme: e,
439
+ title: l,
440
+ description: n,
441
+ icon: a,
442
+ action: r = null,
443
+ sectionId: i,
444
+ children: s
445
+ }) {
446
+ return /* @__PURE__ */ t.createElement("section", { "data-report-section": i || l, style: Ht(e) }, /* @__PURE__ */ t.createElement("div", { style: { display: "flex", alignItems: "flex-start", justifyContent: "space-between", gap: "12px" } }, /* @__PURE__ */ t.createElement("div", { style: { display: "flex", alignItems: "flex-start", gap: "8px", minWidth: 0 } }, /* @__PURE__ */ t.createElement("div", { style: { color: e.textSec, display: "flex", alignItems: "center", paddingTop: "1px", flexShrink: 0 } }, a), /* @__PURE__ */ t.createElement("div", { style: { minWidth: 0 } }, /* @__PURE__ */ t.createElement("div", { style: { fontSize: "13px", fontWeight: 900, color: e.text } }, l), n && /* @__PURE__ */ t.createElement("div", { style: { fontSize: "11px", color: e.textSec, lineHeight: 1.45, marginTop: "2px" } }, n))), r && /* @__PURE__ */ t.createElement("div", { style: { flexShrink: 0 } }, r)), /* @__PURE__ */ t.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "10px" } }, s));
447
+ }
448
+ function Ie({ condition: e, allFields: l, getFieldLabel: n = M, onSave: a, onClose: r, theme: i, title: s, description: f }) {
449
+ const [m, g] = H(() => Le(e)), F = q(i), N = B(() => {
450
+ g((c) => ({ ...c, clauses: [...c.clauses, Ue(l[0] || "")] }));
451
+ }, [l]), y = B((c, E) => {
452
+ g((h) => ({
453
+ ...h,
454
+ clauses: h.clauses.map((u, D) => D === c ? { ...u, ...E } : u)
455
+ }));
456
+ }, []), w = B((c) => {
457
+ g((E) => ({
458
+ ...E,
459
+ clauses: E.clauses.filter((h, u) => u !== c)
460
+ }));
461
+ }, []);
462
+ return /* @__PURE__ */ t.createElement(
463
+ "div",
464
+ {
465
+ style: {
466
+ position: "fixed",
467
+ inset: 0,
468
+ zIndex: 9999,
469
+ background: "rgba(15, 23, 42, 0.45)",
470
+ display: "flex",
471
+ alignItems: "center",
472
+ justifyContent: "center"
473
+ },
474
+ onClick: r
475
+ },
476
+ /* @__PURE__ */ t.createElement(
477
+ "div",
478
+ {
479
+ style: {
480
+ ...pe(i),
481
+ width: "520px",
482
+ maxWidth: "95vw",
483
+ maxHeight: "85vh",
484
+ overflowY: "auto",
485
+ boxShadow: "0 24px 64px rgba(15, 23, 42, 0.22)"
486
+ },
487
+ onClick: (c) => c.stopPropagation()
488
+ },
489
+ /* @__PURE__ */ t.createElement("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "10px" } }, /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: { fontSize: "14px", fontWeight: 800, color: i.text } }, s || "Edit row override rule"), /* @__PURE__ */ t.createElement("div", { style: { fontSize: "12px", color: i.textSec, marginTop: "2px" } }, f || "Add one or more clauses to decide when this row override should be used.")), /* @__PURE__ */ t.createElement("button", { type: "button", onClick: r, style: { background: "none", border: "none", cursor: "pointer", color: i.textSec } }, /* @__PURE__ */ t.createElement(v.Close, null))),
490
+ m.clauses.length > 1 && /* @__PURE__ */ t.createElement("div", { style: { display: "flex", gap: "6px", alignItems: "center", flexWrap: "wrap" } }, /* @__PURE__ */ t.createElement("span", { style: { fontSize: "11px", color: i.textSec, fontWeight: 700 } }, "Match:"), ["AND", "OR"].map((c) => /* @__PURE__ */ t.createElement(
491
+ "button",
492
+ {
493
+ key: c,
494
+ type: "button",
495
+ onClick: () => g((E) => ({ ...E, op: c })),
496
+ style: {
497
+ padding: "5px 12px",
498
+ borderRadius: "999px",
499
+ fontSize: "11px",
500
+ fontWeight: 800,
501
+ border: "none",
502
+ cursor: "pointer",
503
+ background: m.op === c ? i.primary || "#2563EB" : i.hover || "#F3F4F6",
504
+ color: m.op === c ? "#fff" : i.textSec
505
+ }
506
+ },
507
+ c
508
+ ))),
509
+ /* @__PURE__ */ t.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "8px" } }, m.clauses.length === 0 && /* @__PURE__ */ t.createElement("div", { style: { fontSize: "12px", color: i.textSec, fontStyle: "italic" } }, "No clauses means this row override matches every row at this level."), m.clauses.map((c, E) => /* @__PURE__ */ t.createElement(
510
+ "div",
511
+ {
512
+ key: c._id,
513
+ style: {
514
+ border: `1px solid ${i.border}`,
515
+ borderRadius: "12px",
516
+ background: i.hover || "#F8FAFC",
517
+ padding: "10px",
518
+ display: "flex",
519
+ gap: "8px",
520
+ alignItems: "flex-start"
521
+ }
522
+ },
523
+ /* @__PURE__ */ t.createElement("div", { style: { width: "32px", paddingTop: "6px", textAlign: "center", fontSize: "10px", fontWeight: 800, color: i.textSec } }, E > 0 ? m.op : ""),
524
+ /* @__PURE__ */ t.createElement("div", { style: { flex: 1, display: "flex", flexDirection: "column", gap: "8px" } }, /* @__PURE__ */ t.createElement("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" } }, /* @__PURE__ */ t.createElement(
525
+ "select",
526
+ {
527
+ value: c.field,
528
+ onChange: (h) => y(E, { field: h.target.value }),
529
+ style: { ...F, flex: 1, minWidth: "140px" }
530
+ },
531
+ l.map((h) => /* @__PURE__ */ t.createElement("option", { key: h, value: h }, n(h)))
532
+ ), /* @__PURE__ */ t.createElement(
533
+ "select",
534
+ {
535
+ value: c.operator,
536
+ onChange: (h) => {
537
+ const u = h.target.value, D = de.has(u), R = de.has(c.operator);
538
+ y(E, {
539
+ operator: u,
540
+ values: D ? R ? c.values : c.value ? [c.value] : [] : c.values,
541
+ value: D ? c.value : c.values[0] || c.value || ""
542
+ });
543
+ },
544
+ style: { ...F, width: "160px", flexShrink: 0 }
545
+ },
546
+ Xe.map((h) => /* @__PURE__ */ t.createElement("option", { key: h.value, value: h.value }, h.label))
547
+ )), de.has(c.operator) ? /* @__PURE__ */ t.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "8px" } }, c.values.length > 0 && /* @__PURE__ */ t.createElement("div", { style: { display: "flex", flexWrap: "wrap", gap: "6px" } }, c.values.map((h, u) => /* @__PURE__ */ t.createElement(X, { key: `${c._id}-${u}`, theme: i, tone: "primary" }, /* @__PURE__ */ t.createElement("span", null, h), /* @__PURE__ */ t.createElement(
548
+ "button",
549
+ {
550
+ type: "button",
551
+ onClick: () => y(E, {
552
+ values: c.values.filter((D, R) => R !== u)
553
+ }),
554
+ style: { background: "none", border: "none", padding: 0, cursor: "pointer", color: "inherit", lineHeight: 1 }
555
+ },
556
+ "x"
557
+ )))), /* @__PURE__ */ t.createElement(
558
+ "input",
559
+ {
560
+ placeholder: "Type a value and press Enter",
561
+ style: F,
562
+ onKeyDown: (h) => {
563
+ const u = h.target.value.trim();
564
+ h.key === "Enter" && u && (c.values.includes(u) || y(E, { values: [...c.values, u] }), h.target.value = "", h.preventDefault());
565
+ }
566
+ }
567
+ )) : /* @__PURE__ */ t.createElement(
568
+ "input",
569
+ {
570
+ value: c.value,
571
+ onChange: (h) => y(E, { value: h.target.value }),
572
+ placeholder: "Value",
573
+ style: F
574
+ }
575
+ )),
576
+ /* @__PURE__ */ t.createElement(
577
+ "button",
578
+ {
579
+ type: "button",
580
+ onClick: () => w(E),
581
+ style: { background: "none", border: "none", cursor: "pointer", color: "#B91C1C", padding: "6px" }
582
+ },
583
+ /* @__PURE__ */ t.createElement(v.Delete, null)
584
+ )
585
+ ))),
586
+ /* @__PURE__ */ t.createElement(
587
+ "button",
588
+ {
589
+ type: "button",
590
+ onClick: N,
591
+ style: {
592
+ ...j(i),
593
+ width: "100%",
594
+ borderStyle: "dashed"
595
+ }
596
+ },
597
+ /* @__PURE__ */ t.createElement(v.Add, null),
598
+ " Add clause"
599
+ ),
600
+ /* @__PURE__ */ t.createElement("div", { style: { display: "flex", justifyContent: "flex-end", gap: "8px", borderTop: `1px solid ${i.border}`, paddingTop: "12px" } }, /* @__PURE__ */ t.createElement("button", { type: "button", onClick: r, style: j(i) }, "Cancel"), /* @__PURE__ */ t.createElement(
601
+ "button",
602
+ {
603
+ type: "button",
604
+ onClick: () => {
605
+ a(m), r();
606
+ },
607
+ style: {
608
+ background: i.primary || "#2563EB",
609
+ border: "none",
610
+ borderRadius: "9px",
611
+ padding: "8px 14px",
612
+ fontSize: "12px",
613
+ fontWeight: 800,
614
+ color: "#fff",
615
+ cursor: "pointer"
616
+ }
617
+ },
618
+ "Apply"
619
+ ))
620
+ )
621
+ );
622
+ }
623
+ function at({ value: e, onChange: l, theme: n }) {
624
+ const a = me(e), r = q(n), i = (s) => l(me({ ...a, ...s }));
625
+ return /* @__PURE__ */ t.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "10px" } }, /* @__PURE__ */ t.createElement("div", { style: L(n) }, "Presentation"), /* @__PURE__ */ t.createElement("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: "8px" } }, /* @__PURE__ */ t.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "5px", fontSize: "11px", color: n.textSec } }, "Indent px", /* @__PURE__ */ t.createElement("input", { type: "number", min: "0", value: a.indent, onChange: (s) => i({ indent: s.target.value }), placeholder: "Auto", style: r })), /* @__PURE__ */ t.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "5px", fontSize: "11px", color: n.textSec } }, "Row color", /* @__PURE__ */ t.createElement("input", { value: a.rowColor, onChange: (s) => i({ rowColor: s.target.value }), placeholder: "#F8FAFC", style: r })), /* @__PURE__ */ t.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "5px", fontSize: "11px", color: n.textSec } }, "Label prefix", /* @__PURE__ */ t.createElement("input", { value: a.labelPrefix, onChange: (s) => i({ labelPrefix: s.target.value }), placeholder: "Optional", style: r })), /* @__PURE__ */ t.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "5px", fontSize: "11px", color: n.textSec } }, "Label suffix", /* @__PURE__ */ t.createElement("input", { value: a.labelSuffix, onChange: (s) => i({ labelSuffix: s.target.value }), placeholder: "Optional", style: r })), /* @__PURE__ */ t.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "5px", fontSize: "11px", color: n.textSec, gridColumn: "1 / -1" } }, "Number format override", /* @__PURE__ */ t.createElement("input", { value: a.numberFormat, onChange: (s) => i({ numberFormat: s.target.value }), placeholder: "fixed:2, percent, currency:$", style: r }))), /* @__PURE__ */ t.createElement("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: "8px" } }, /* @__PURE__ */ t.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "5px", fontSize: "11px", color: n.textSec } }, "Border", /* @__PURE__ */ t.createElement("select", { value: a.borderStyle, onChange: (s) => i({ borderStyle: s.target.value }), style: r }, Qe.map((s) => /* @__PURE__ */ t.createElement("option", { key: s || "none", value: s }, s || "None")))), /* @__PURE__ */ t.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "5px", fontSize: "11px", color: n.textSec } }, "Border color", /* @__PURE__ */ t.createElement("input", { value: a.borderColor, onChange: (s) => i({ borderColor: s.target.value }), placeholder: "#CBD5E1", style: r })), /* @__PURE__ */ t.createElement("label", { style: { display: "flex", flexDirection: "column", gap: "5px", fontSize: "11px", color: n.textSec } }, "Width", /* @__PURE__ */ t.createElement("input", { type: "number", min: "1", value: a.borderWidth, onChange: (s) => i({ borderWidth: s.target.value }), placeholder: "1", style: r }))), /* @__PURE__ */ t.createElement("div", { style: { display: "flex", gap: "14px", flexWrap: "wrap" } }, /* @__PURE__ */ t.createElement("label", { style: { display: "inline-flex", alignItems: "center", gap: "7px", fontSize: "12px", color: n.text, fontWeight: 700 } }, /* @__PURE__ */ t.createElement("input", { type: "checkbox", checked: a.bold, onChange: (s) => i({ bold: s.target.checked }) }), "Bold row"), /* @__PURE__ */ t.createElement("label", { style: { display: "inline-flex", alignItems: "center", gap: "7px", fontSize: "12px", color: n.text, fontWeight: 700 } }, /* @__PURE__ */ t.createElement("input", { type: "checkbox", checked: a.showSubtotal, onChange: (s) => i({ showSubtotal: s.target.checked }) }), "Show subtotal/other rows")));
626
+ }
627
+ function Vt({ validation: e, theme: l }) {
628
+ const n = e && Array.isArray(e.errors) ? e.errors : [], a = e && Array.isArray(e.warnings) ? e.warnings : [];
629
+ return n.length === 0 && a.length === 0 ? null : /* @__PURE__ */ t.createElement("div", { "data-report-validation": "true", style: { border: `1px solid ${n.length > 0 ? "#FCA5A5" : "#FDE68A"}`, borderRadius: "12px", padding: "10px 12px", background: n.length > 0 ? "#FEF2F2" : "#FFFBEB", color: n.length > 0 ? "#991B1B" : "#92400E", fontSize: "11px", lineHeight: 1.45, display: "flex", flexDirection: "column", gap: "6px" } }, n.length > 0 && /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: { fontWeight: 900, marginBottom: "4px" } }, "Fix before applying or saving"), n.map((r) => /* @__PURE__ */ t.createElement("div", { key: `err:${r}` }, r))), a.length > 0 && /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: { fontWeight: 900, marginBottom: "4px" } }, "Warnings"), a.map((r) => /* @__PURE__ */ t.createElement("div", { key: `warn:${r}` }, r))));
630
+ }
631
+ function qt({ debug: e, theme: l }) {
632
+ if (!e || typeof e != "object") return null;
633
+ const n = [
634
+ ["Matched level", e.matchedLevel || e.levelLabel || ""],
635
+ ["Field", e.levelField || ""],
636
+ ["Row path", Array.isArray(e.pathValues) ? e.pathValues.join(" > ") : e.rowPath || ""],
637
+ ["Children source", e.childrenSource || "Default children"],
638
+ ["Rule", e.matchedCondition || ""]
639
+ ].filter(([, a]) => a);
640
+ return n.length === 0 ? null : /* @__PURE__ */ t.createElement("div", { "data-report-debug-inspector": "true", style: { border: `1px solid ${l.border}`, borderRadius: "12px", padding: "10px", background: l.hover || "#F8FAFC", display: "flex", flexDirection: "column", gap: "7px" } }, /* @__PURE__ */ t.createElement("div", { style: L(l) }, "Why Is This Row Here?"), n.map(([a, r]) => /* @__PURE__ */ t.createElement("div", { key: a, style: { display: "flex", justifyContent: "space-between", gap: "10px", fontSize: "11px" } }, /* @__PURE__ */ t.createElement("span", { style: { color: l.textSec, fontWeight: 800 } }, a), /* @__PURE__ */ t.createElement("span", { style: { color: l.text, textAlign: "right", overflowWrap: "anywhere" } }, r))));
641
+ }
642
+ function ot({
643
+ title: e,
644
+ summary: l,
645
+ theme: n,
646
+ defaultOpen: a = !1,
647
+ children: r
648
+ }) {
649
+ const [i, s] = H(a);
650
+ return /* @__PURE__ */ t.createElement(
651
+ "div",
652
+ {
653
+ "data-report-level-collapsible": "true",
654
+ "data-report-level-collapsed": i ? "false" : "true",
655
+ style: {
656
+ border: `1px solid ${n.border}`,
657
+ borderRadius: "12px",
658
+ background: n.surfaceBg || n.background || "#fff",
659
+ overflow: "hidden"
660
+ }
661
+ },
662
+ /* @__PURE__ */ t.createElement(
663
+ "button",
664
+ {
665
+ type: "button",
666
+ onClick: () => s((f) => !f),
667
+ style: {
668
+ width: "100%",
669
+ border: "none",
670
+ background: i ? n.hover || "#F8FAFC" : "transparent",
671
+ color: n.text,
672
+ cursor: "pointer",
673
+ padding: "10px 12px",
674
+ display: "flex",
675
+ alignItems: "center",
676
+ gap: "8px",
677
+ textAlign: "left"
678
+ },
679
+ "aria-expanded": i
680
+ },
681
+ /* @__PURE__ */ t.createElement("span", { style: { display: "inline-flex", color: n.textSec, flexShrink: 0 } }, i ? /* @__PURE__ */ t.createElement(v.ChevronDown, null) : /* @__PURE__ */ t.createElement(v.ChevronRight, null)),
682
+ /* @__PURE__ */ t.createElement("span", { style: { flex: 1, minWidth: 0 } }, /* @__PURE__ */ t.createElement("span", { style: { display: "block", fontSize: "12px", fontWeight: 900, color: n.text } }, e), l && /* @__PURE__ */ t.createElement("span", { style: { display: "block", fontSize: "11px", color: n.textSec, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", marginTop: "2px" } }, l))
683
+ ),
684
+ i && /* @__PURE__ */ t.createElement("div", { style: { borderTop: `1px solid ${n.border}`, padding: "12px", display: "flex", flexDirection: "column", gap: "12px" } }, r)
685
+ );
686
+ }
687
+ function Jt({ item: e, selected: l, theme: n, sortByOptions: a, getFieldLabel: r = M, onSelect: i }) {
688
+ const s = e.node, f = Pt(e), m = s.field ? r(s.field) : "Select field", g = tt(s), F = et(s.sortBy, a);
689
+ return /* @__PURE__ */ t.createElement("button", { type: "button", onClick: i, style: nt(n, l, e.depth) }, /* @__PURE__ */ t.createElement("div", { style: { display: "flex", alignItems: "flex-start", justifyContent: "space-between", gap: "10px" } }, /* @__PURE__ */ t.createElement("div", { style: { minWidth: 0, display: "flex", flexDirection: "column", gap: "7px" } }, /* @__PURE__ */ t.createElement("div", { style: { display: "flex", alignItems: "center", gap: "6px", flexWrap: "wrap" } }, /* @__PURE__ */ t.createElement(X, { theme: n, tone: e.branchBadge ? "primary" : "neutral" }, f), /* @__PURE__ */ t.createElement("span", { style: { fontSize: "12px", fontWeight: 800, color: n.text } }, m)), /* @__PURE__ */ t.createElement("div", { style: { fontSize: "11px", color: n.textSec } }, "Header: ", g), /* @__PURE__ */ t.createElement("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" } }, /* @__PURE__ */ t.createElement(X, { theme: n }, s.topN ? `Top ${s.topN}` : "All rows"), /* @__PURE__ */ t.createElement(X, { theme: n }, F ? `Sort ${s.sortDir}${s.sortAbs ? " |abs|" : ""} by ${F}` : "Default sort"), s.defaultChild && /* @__PURE__ */ t.createElement(X, { theme: n }, "Has next level"), s.branches.length > 0 && /* @__PURE__ */ t.createElement(X, { theme: n, tone: "primary" }, s.branches.length, " row override", s.branches.length === 1 ? "" : "s"))), /* @__PURE__ */ t.createElement("span", { style: { color: l ? n.primary || "#2563EB" : n.textSec, flexShrink: 0 } }, /* @__PURE__ */ t.createElement(v.ChevronRight, null))));
690
+ }
691
+ function Kt({ item: e, selected: l, theme: n, onSelect: a }) {
692
+ const r = e.branch, i = r.label && r.label.trim() ? r.label.trim() : "Display original label";
693
+ return /* @__PURE__ */ t.createElement("button", { type: "button", onClick: a, style: nt(n, l, e.depth) }, /* @__PURE__ */ t.createElement("div", { style: { display: "flex", alignItems: "flex-start", justifyContent: "space-between", gap: "10px" } }, /* @__PURE__ */ t.createElement("div", { style: { minWidth: 0, display: "flex", flexDirection: "column", gap: "7px" } }, /* @__PURE__ */ t.createElement("div", { style: { display: "flex", alignItems: "center", gap: "6px", flexWrap: "wrap" } }, /* @__PURE__ */ t.createElement(X, { theme: n, tone: "primary" }, `Row override ${e.badge}`), /* @__PURE__ */ t.createElement("span", { style: { fontSize: "12px", fontWeight: 800, color: n.text } }, i)), /* @__PURE__ */ t.createElement("div", { style: { fontSize: "11px", color: n.textSec, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, Ce(r.condition)), /* @__PURE__ */ t.createElement("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" } }, /* @__PURE__ */ t.createElement(X, { theme: n }, r.child ? "Custom children" : "Default children"))), /* @__PURE__ */ t.createElement("span", { style: { color: l ? n.primary || "#2563EB" : n.textSec, flexShrink: 0 } }, /* @__PURE__ */ t.createElement(v.ChevronRight, null))));
694
+ }
695
+ function it({
696
+ item: e,
697
+ selected: l,
698
+ theme: n,
699
+ sortByOptions: a,
700
+ getFieldLabel: r = M,
701
+ onSelect: i,
702
+ onDragStart: s,
703
+ onDragOver: f,
704
+ onDrop: m
705
+ }) {
706
+ const g = e.node, F = g.field ? r(g.field) : "Select field", N = g.label && g.label.trim() ? g.label.trim() : F, y = et(g.sortBy, a);
707
+ return /* @__PURE__ */ t.createElement(
708
+ "button",
709
+ {
710
+ type: "button",
711
+ draggable: !0,
712
+ onDragStart: s,
713
+ onDragOver: f,
714
+ onDrop: m,
715
+ onClick: i,
716
+ style: {
717
+ width: "100%",
718
+ border: `1px solid ${l ? n.primary || "#2563EB" : n.border}`,
719
+ borderRadius: "12px",
720
+ background: l ? n.select || `${n.primary || "#2563EB"}14` : n.surfaceBg || n.background || "#fff",
721
+ padding: "10px 12px",
722
+ textAlign: "left",
723
+ cursor: "pointer",
724
+ display: "flex",
725
+ alignItems: "center",
726
+ gap: "10px"
727
+ }
728
+ },
729
+ /* @__PURE__ */ t.createElement("span", { style: { cursor: "grab", display: "inline-flex" } }, /* @__PURE__ */ t.createElement(v.DragIndicator, null)),
730
+ /* @__PURE__ */ t.createElement("div", { style: { flex: 1, minWidth: 0 } }, /* @__PURE__ */ t.createElement("div", { style: { display: "flex", alignItems: "center", gap: "7px", minWidth: 0 } }, /* @__PURE__ */ t.createElement("span", { style: { fontSize: "11px", fontWeight: 800, color: n.textSec, flexShrink: 0 } }, "Level ", e.levelNumber), /* @__PURE__ */ t.createElement("span", { style: { fontSize: "12px", fontWeight: 800, color: n.text, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, N)), /* @__PURE__ */ t.createElement("div", { style: { fontSize: "11px", color: n.textSec, marginTop: "3px", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, F, y ? ` · ${g.sortDir === "asc" ? "Asc" : "Desc"}${g.sortAbs ? " |abs|" : ""} by ${y}` : "", g.topN ? ` · Top ${g.topN}` : "", g.filters && g.filters.clauses && g.filters.clauses.length > 0 ? ` · ${g.filters.clauses.length} filter${g.filters.clauses.length === 1 ? "" : "s"}` : "")),
731
+ /* @__PURE__ */ t.createElement("span", { style: { color: l ? n.primary || "#2563EB" : n.textSec, flexShrink: 0 } }, /* @__PURE__ */ t.createElement(v.ChevronRight, null))
732
+ );
733
+ }
734
+ function Yt({
735
+ item: e,
736
+ node: l,
737
+ allFields: n,
738
+ getFieldLabel: a = M,
739
+ sortByOptions: r,
740
+ theme: i,
741
+ onUpdate: s,
742
+ onApply: f,
743
+ onRemove: m,
744
+ onEditFilter: g,
745
+ titleLabel: F = "Title",
746
+ canRemove: N = !0
747
+ }) {
748
+ const y = q(i), w = e && e.levelNumber ? `Level ${e.levelNumber}` : "Level", c = !!(l.filters && l.filters.clauses && l.filters.clauses.length > 0), h = [
749
+ l.field ? a(l.field) : "Select field",
750
+ l.label && l.label.trim() ? `Title: ${l.label.trim()}` : null,
751
+ l.topN ? `Top ${l.topN}` : null,
752
+ c ? `${l.filters.clauses.length} filter${l.filters.clauses.length === 1 ? "" : "s"}` : null
753
+ ].filter(Boolean);
754
+ return /* @__PURE__ */ t.createElement("div", { style: pe(i) }, /* @__PURE__ */ t.createElement("div", { style: { display: "flex", alignItems: "flex-start", justifyContent: "space-between", gap: "12px" } }, /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: { fontSize: "14px", fontWeight: 800, color: i.text } }, w)), /* @__PURE__ */ t.createElement("div", { style: { display: "flex", gap: "8px", flexShrink: 0 } }, /* @__PURE__ */ t.createElement(
755
+ "button",
756
+ {
757
+ type: "button",
758
+ onClick: f,
759
+ style: {
760
+ background: i.primary || "#2563EB",
761
+ border: "none",
762
+ borderRadius: "9px",
763
+ padding: "8px 14px",
764
+ fontSize: "12px",
765
+ fontWeight: 800,
766
+ color: "#fff",
767
+ cursor: "pointer"
768
+ }
769
+ },
770
+ "Apply"
771
+ ), N && /* @__PURE__ */ t.createElement("button", { type: "button", onClick: m, style: j(i, !1, !0) }, /* @__PURE__ */ t.createElement(v.Delete, null), " ", e && e.path && e.path.length === 0 ? "Clear report" : "Remove level"))), /* @__PURE__ */ t.createElement(
772
+ ot,
773
+ {
774
+ title: `${w} settings`,
775
+ summary: h.join(" · "),
776
+ theme: i,
777
+ defaultOpen: !1
778
+ },
779
+ /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: L(i) }, "Break Down By"), /* @__PURE__ */ t.createElement(
780
+ "select",
781
+ {
782
+ value: l.field,
783
+ onChange: (u) => s({ ...l, field: u.target.value }),
784
+ style: y
785
+ },
786
+ /* @__PURE__ */ t.createElement("option", { value: "" }, "Select field..."),
787
+ n.map((u) => /* @__PURE__ */ t.createElement("option", { key: u, value: u }, a(u)))
788
+ )),
789
+ /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: L(i) }, F), /* @__PURE__ */ t.createElement(
790
+ "input",
791
+ {
792
+ value: l.label,
793
+ onChange: (u) => s({ ...l, label: u.target.value }),
794
+ placeholder: l.field ? a(l.field) : "Label for this level",
795
+ style: y
796
+ }
797
+ )),
798
+ /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: L(i) }, "Ranking And Sort"), /* @__PURE__ */ t.createElement("div", { style: { display: "grid", gridTemplateColumns: "82px 1fr 42px 42px", gap: "8px", alignItems: "stretch" } }, /* @__PURE__ */ t.createElement(
799
+ "input",
800
+ {
801
+ type: "number",
802
+ min: "1",
803
+ value: l.topN || "",
804
+ onChange: (u) => {
805
+ const D = u.target.value === "" ? null : parseInt(u.target.value, 10);
806
+ s({ ...l, topN: D && D > 0 ? D : null });
807
+ },
808
+ placeholder: "All",
809
+ style: { ...y, textAlign: "center" }
810
+ }
811
+ ), /* @__PURE__ */ t.createElement(
812
+ "select",
813
+ {
814
+ value: l.sortBy || "",
815
+ onChange: (u) => s({ ...l, sortBy: u.target.value || null }),
816
+ style: y
817
+ },
818
+ r.map((u) => /* @__PURE__ */ t.createElement("option", { key: u.value, value: u.value }, u.label))
819
+ ), /* @__PURE__ */ t.createElement(
820
+ "button",
821
+ {
822
+ type: "button",
823
+ onClick: () => s({ ...l, sortAbs: !l.sortAbs }),
824
+ style: {
825
+ border: `1px solid ${l.sortAbs ? i.primary || "#2563EB" : i.border}`,
826
+ borderRadius: "10px",
827
+ background: l.sortAbs ? `${i.primary || "#2563EB"}18` : i.hover || "#F3F4F6",
828
+ color: l.sortAbs ? i.primary || "#2563EB" : i.text,
829
+ cursor: "pointer",
830
+ display: "flex",
831
+ alignItems: "center",
832
+ justifyContent: "center",
833
+ fontSize: "11px",
834
+ fontWeight: 700
835
+ },
836
+ title: "Sort by absolute value (ignores sign)"
837
+ },
838
+ "|a|"
839
+ ), /* @__PURE__ */ t.createElement(
840
+ "button",
841
+ {
842
+ type: "button",
843
+ onClick: () => s({ ...l, sortDir: l.sortDir === "asc" ? "desc" : "asc" }),
844
+ style: {
845
+ border: `1px solid ${i.border}`,
846
+ borderRadius: "10px",
847
+ background: i.hover || "#F3F4F6",
848
+ color: i.text,
849
+ cursor: "pointer",
850
+ display: "flex",
851
+ alignItems: "center",
852
+ justifyContent: "center"
853
+ },
854
+ title: l.sortDir === "asc" ? "Ascending" : "Descending"
855
+ },
856
+ l.sortDir === "asc" ? /* @__PURE__ */ t.createElement(v.SortAsc, null) : /* @__PURE__ */ t.createElement(v.SortDesc, null)
857
+ ))),
858
+ /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: L(i) }, "Level Filter"), /* @__PURE__ */ t.createElement("div", { style: { display: "flex", gap: "8px", alignItems: "stretch" } }, /* @__PURE__ */ t.createElement(
859
+ "button",
860
+ {
861
+ type: "button",
862
+ onClick: g,
863
+ style: q(i, {
864
+ flex: 1,
865
+ display: "flex",
866
+ alignItems: "center",
867
+ gap: "8px",
868
+ textAlign: "left",
869
+ cursor: "pointer",
870
+ background: c ? `${i.primary || "#2563EB"}08` : i.hover || "#F8FAFC",
871
+ borderColor: c ? `${i.primary || "#2563EB"}45` : void 0
872
+ })
873
+ },
874
+ /* @__PURE__ */ t.createElement(v.Filter, null),
875
+ /* @__PURE__ */ t.createElement("span", { style: { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", flex: 1 } }, c ? Ce(l.filters) : "No filter (show all rows)")
876
+ ), c && /* @__PURE__ */ t.createElement(
877
+ "button",
878
+ {
879
+ type: "button",
880
+ onClick: () => s({ ...l, filters: null }),
881
+ style: {
882
+ border: `1px solid ${i.border}`,
883
+ borderRadius: "10px",
884
+ background: i.hover || "#F3F4F6",
885
+ color: "#B91C1C",
886
+ cursor: "pointer",
887
+ display: "flex",
888
+ alignItems: "center",
889
+ justifyContent: "center",
890
+ padding: "0 10px",
891
+ flexShrink: 0
892
+ },
893
+ title: "Clear filter"
894
+ },
895
+ /* @__PURE__ */ t.createElement(v.Close, null)
896
+ )), /* @__PURE__ */ t.createElement("div", { style: { fontSize: "11px", color: i.textSec, marginTop: "6px", lineHeight: 1.4 } }, `Rows that don't match the filter are grouped into "Others" to keep totals intact.`)),
897
+ /* @__PURE__ */ t.createElement(
898
+ at,
899
+ {
900
+ value: l.format,
901
+ theme: i,
902
+ onChange: (u) => s({ ...l, format: u })
903
+ }
904
+ )
905
+ ));
906
+ }
907
+ function Gt({
908
+ draft: e,
909
+ allFields: l,
910
+ getFieldLabel: n = M,
911
+ sortByOptions: a,
912
+ theme: r,
913
+ onChange: i,
914
+ onApply: s,
915
+ onCancel: f
916
+ }) {
917
+ const [m, g] = H(null), [F, N] = H(!1), y = e && e.child ? e.child : G(""), w = Array.isArray(e && e.selectedPath) ? e.selectedPath : [], c = ne(y, w) || y, E = !!(c.filters && c.filters.clauses && c.filters.clauses.length > 0), h = We(y, e.childLevelNumber || 2), u = Math.max(0, w.length), D = (e && Number.isFinite(Number(e.childLevelNumber)) ? Number(e.childLevelNumber) : 2) + w.length, R = q(r), x = [
918
+ c.field ? n(c.field) : "Select field",
919
+ e.title && e.title.trim() ? `Title: ${e.title.trim()}` : null,
920
+ c.topN ? `Top ${c.topN}` : null,
921
+ E ? `${c.filters.clauses.length} filter${c.filters.clauses.length === 1 ? "" : "s"}` : null
922
+ ].filter(Boolean), C = (d) => {
923
+ i({
924
+ ...e,
925
+ child: O(y, w, () => d)
926
+ });
927
+ }, J = (d) => {
928
+ i({
929
+ ...e,
930
+ selectedPath: Ne(d)
931
+ });
932
+ }, ue = () => {
933
+ const d = [...w, T];
934
+ i({
935
+ ...e,
936
+ child: O(y, w, (k) => ({
937
+ ...k,
938
+ defaultChild: k.defaultChild || G("")
939
+ })),
940
+ selectedPath: d
941
+ });
942
+ }, oe = () => {
943
+ i({
944
+ ...e,
945
+ child: O(y, w, (d) => ({
946
+ ...d,
947
+ defaultChild: null
948
+ }))
949
+ });
950
+ }, fe = (d, k) => {
951
+ d === null || d === k || (i({
952
+ ...e,
953
+ child: rt(y, d, k),
954
+ selectedPath: Ne(k)
955
+ }), g(null));
956
+ };
957
+ return /* @__PURE__ */ t.createElement(t.Fragment, null, /* @__PURE__ */ t.createElement("div", { style: pe(r) }, /* @__PURE__ */ t.createElement("div", { style: { display: "flex", alignItems: "flex-start", justifyContent: "space-between", gap: "12px" } }, /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: { fontSize: "14px", fontWeight: 800, color: r.text } }, e.rowLabel || "Selected row"), /* @__PURE__ */ t.createElement("div", { style: { fontSize: "12px", color: r.textSec, marginTop: "2px" } }, "Override applies to this row only.")), /* @__PURE__ */ t.createElement("div", { style: { display: "flex", gap: "8px", flexShrink: 0 } }, /* @__PURE__ */ t.createElement("button", { type: "button", onClick: f, style: j(r) }, /* @__PURE__ */ t.createElement(v.Close, null), " Close"), /* @__PURE__ */ t.createElement(
958
+ "button",
959
+ {
960
+ type: "button",
961
+ onClick: s,
962
+ style: {
963
+ background: r.primary || "#2563EB",
964
+ border: "none",
965
+ borderRadius: "9px",
966
+ padding: "8px 14px",
967
+ fontSize: "12px",
968
+ fontWeight: 800,
969
+ color: "#fff",
970
+ cursor: "pointer"
971
+ }
972
+ },
973
+ "Apply"
974
+ ))), /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: L(r) }, "Level"), /* @__PURE__ */ t.createElement("div", { style: { fontSize: "12px", fontWeight: 800, color: r.text } }, `Level ${D}`)), /* @__PURE__ */ t.createElement(qt, { debug: e.request && e.request.debug, theme: r }), h.length > 1 && /* @__PURE__ */ t.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "8px" } }, h.map((d) => /* @__PURE__ */ t.createElement(
975
+ it,
976
+ {
977
+ key: `draft-level:${d.index}:${d.node._id}`,
978
+ item: d,
979
+ selected: u === d.index,
980
+ theme: r,
981
+ sortByOptions: a,
982
+ getFieldLabel: n,
983
+ onSelect: () => J(d.index),
984
+ onDragStart: (k) => {
985
+ g(d.index), k.dataTransfer.effectAllowed = "move";
986
+ },
987
+ onDragOver: (k) => k.preventDefault(),
988
+ onDrop: (k) => {
989
+ k.preventDefault(), fe(m, d.index);
990
+ }
991
+ }
992
+ ))), /* @__PURE__ */ t.createElement(
993
+ ot,
994
+ {
995
+ title: `Level ${D} settings`,
996
+ summary: x.join(" · "),
997
+ theme: r,
998
+ defaultOpen: !1
999
+ },
1000
+ /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: L(r) }, "Title"), /* @__PURE__ */ t.createElement(
1001
+ "input",
1002
+ {
1003
+ value: e.title,
1004
+ onChange: (d) => i({ ...e, title: d.target.value }),
1005
+ placeholder: e.rowLabel || "Row title",
1006
+ style: R
1007
+ }
1008
+ )),
1009
+ /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: L(r) }, "Break Down By"), /* @__PURE__ */ t.createElement(
1010
+ "select",
1011
+ {
1012
+ value: c.field,
1013
+ onChange: (d) => C({ ...c, field: d.target.value }),
1014
+ style: R
1015
+ },
1016
+ /* @__PURE__ */ t.createElement("option", { value: "" }, "Select field..."),
1017
+ l.map((d) => /* @__PURE__ */ t.createElement("option", { key: d, value: d }, n(d)))
1018
+ )),
1019
+ /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: L(r) }, "Ranking And Sort"), /* @__PURE__ */ t.createElement("div", { style: { display: "grid", gridTemplateColumns: "82px 1fr 42px 42px", gap: "8px", alignItems: "stretch" } }, /* @__PURE__ */ t.createElement(
1020
+ "input",
1021
+ {
1022
+ type: "number",
1023
+ min: "1",
1024
+ value: c.topN || "",
1025
+ onChange: (d) => {
1026
+ const k = d.target.value === "" ? null : parseInt(d.target.value, 10);
1027
+ C({ ...c, topN: k && k > 0 ? k : null });
1028
+ },
1029
+ placeholder: "All",
1030
+ style: { ...R, textAlign: "center" }
1031
+ }
1032
+ ), /* @__PURE__ */ t.createElement(
1033
+ "select",
1034
+ {
1035
+ value: c.sortBy || "",
1036
+ onChange: (d) => C({ ...c, sortBy: d.target.value || null }),
1037
+ style: R
1038
+ },
1039
+ a.map((d) => /* @__PURE__ */ t.createElement("option", { key: d.value, value: d.value }, d.label))
1040
+ ), /* @__PURE__ */ t.createElement(
1041
+ "button",
1042
+ {
1043
+ type: "button",
1044
+ onClick: () => C({ ...c, sortAbs: !c.sortAbs }),
1045
+ style: {
1046
+ border: `1px solid ${c.sortAbs ? r.primary || "#2563EB" : r.border}`,
1047
+ borderRadius: "10px",
1048
+ background: c.sortAbs ? `${r.primary || "#2563EB"}18` : r.hover || "#F3F4F6",
1049
+ color: c.sortAbs ? r.primary || "#2563EB" : r.text,
1050
+ cursor: "pointer",
1051
+ display: "flex",
1052
+ alignItems: "center",
1053
+ justifyContent: "center",
1054
+ fontSize: "11px",
1055
+ fontWeight: 700
1056
+ },
1057
+ title: "Sort by absolute value (ignores sign)"
1058
+ },
1059
+ "|a|"
1060
+ ), /* @__PURE__ */ t.createElement(
1061
+ "button",
1062
+ {
1063
+ type: "button",
1064
+ onClick: () => C({ ...c, sortDir: c.sortDir === "asc" ? "desc" : "asc" }),
1065
+ style: {
1066
+ border: `1px solid ${r.border}`,
1067
+ borderRadius: "10px",
1068
+ background: r.hover || "#F3F4F6",
1069
+ color: r.text,
1070
+ cursor: "pointer",
1071
+ display: "flex",
1072
+ alignItems: "center",
1073
+ justifyContent: "center"
1074
+ },
1075
+ title: c.sortDir === "asc" ? "Ascending" : "Descending"
1076
+ },
1077
+ c.sortDir === "asc" ? /* @__PURE__ */ t.createElement(v.SortAsc, null) : /* @__PURE__ */ t.createElement(v.SortDesc, null)
1078
+ ))),
1079
+ /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: L(r) }, "Filter (this row's children only)"), /* @__PURE__ */ t.createElement("div", { style: { display: "flex", gap: "8px", alignItems: "stretch" } }, /* @__PURE__ */ t.createElement(
1080
+ "button",
1081
+ {
1082
+ type: "button",
1083
+ onClick: () => N(!0),
1084
+ style: q(r, {
1085
+ flex: 1,
1086
+ display: "flex",
1087
+ alignItems: "center",
1088
+ gap: "8px",
1089
+ textAlign: "left",
1090
+ cursor: "pointer",
1091
+ background: E ? `${r.primary || "#2563EB"}08` : r.hover || "#F8FAFC",
1092
+ borderColor: E ? `${r.primary || "#2563EB"}45` : void 0
1093
+ })
1094
+ },
1095
+ /* @__PURE__ */ t.createElement(v.Filter, null),
1096
+ /* @__PURE__ */ t.createElement("span", { style: { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", flex: 1 } }, E ? Ce(c.filters) : "No filter (show all children)")
1097
+ ), E && /* @__PURE__ */ t.createElement(
1098
+ "button",
1099
+ {
1100
+ type: "button",
1101
+ onClick: () => C({ ...c, filters: null }),
1102
+ style: {
1103
+ border: `1px solid ${r.border}`,
1104
+ borderRadius: "10px",
1105
+ background: r.hover || "#F3F4F6",
1106
+ color: "#B91C1C",
1107
+ cursor: "pointer",
1108
+ display: "flex",
1109
+ alignItems: "center",
1110
+ justifyContent: "center",
1111
+ padding: "0 10px",
1112
+ flexShrink: 0
1113
+ },
1114
+ title: "Clear filter"
1115
+ },
1116
+ /* @__PURE__ */ t.createElement(v.Close, null)
1117
+ )), /* @__PURE__ */ t.createElement("div", { style: { fontSize: "11px", color: r.textSec, marginTop: "6px", lineHeight: 1.4 } }, 'Filtered-out children are grouped into "Others" to keep totals intact.')),
1118
+ /* @__PURE__ */ t.createElement(
1119
+ at,
1120
+ {
1121
+ value: c.format,
1122
+ theme: r,
1123
+ onChange: (d) => C({ ...c, format: d })
1124
+ }
1125
+ ),
1126
+ /* @__PURE__ */ t.createElement("div", { style: { display: "flex", flexWrap: "wrap", gap: "8px" } }, /* @__PURE__ */ t.createElement(
1127
+ "button",
1128
+ {
1129
+ type: "button",
1130
+ onClick: ue,
1131
+ disabled: !c.field,
1132
+ style: { ...j(r, !!c.defaultChild), opacity: c.field ? 1 : 0.5 }
1133
+ },
1134
+ /* @__PURE__ */ t.createElement(v.Add, null),
1135
+ " ",
1136
+ c.defaultChild ? "Open next level" : "Add next level"
1137
+ ), c.defaultChild && /* @__PURE__ */ t.createElement("button", { type: "button", onClick: oe, style: j(r, !1, !0) }, /* @__PURE__ */ t.createElement(v.Delete, null), " Remove next level"))
1138
+ )), F && /* @__PURE__ */ t.createElement(
1139
+ Ie,
1140
+ {
1141
+ title: `Filter children of "${e.rowLabel || "this row"}"`,
1142
+ description: "Only children matching this filter are shown. Filtered-out rows are grouped into 'Others' to keep totals intact.",
1143
+ condition: c.filters || Pe(),
1144
+ allFields: l,
1145
+ getFieldLabel: n,
1146
+ theme: r,
1147
+ onSave: (d) => {
1148
+ C({
1149
+ ...c,
1150
+ filters: d.clauses.length > 0 ? d : null
1151
+ });
1152
+ },
1153
+ onClose: () => N(!1)
1154
+ }
1155
+ ));
1156
+ }
1157
+ function Zt({
1158
+ item: e,
1159
+ branch: l,
1160
+ theme: n,
1161
+ onUpdate: a,
1162
+ onEditCondition: r,
1163
+ onOpenCustomChildren: i,
1164
+ onRemoveCustomChildren: s,
1165
+ onRemove: f
1166
+ }) {
1167
+ const m = q(n), g = Ce(l.condition);
1168
+ return /* @__PURE__ */ t.createElement("div", { style: pe(n) }, /* @__PURE__ */ t.createElement("div", { style: { display: "flex", alignItems: "flex-start", justifyContent: "space-between", gap: "12px" } }, /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: { fontSize: "14px", fontWeight: 800, color: n.text } }, `Row override ${e.badge}`), /* @__PURE__ */ t.createElement("div", { style: { fontSize: "12px", color: n.textSec, marginTop: "2px" } }, "Use a row override when matching rows need a different label or child breakdown.")), /* @__PURE__ */ t.createElement("button", { type: "button", onClick: f, style: j(n, !1, !0) }, /* @__PURE__ */ t.createElement(v.Delete, null), " Remove override")), /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: L(n) }, "Display As"), /* @__PURE__ */ t.createElement(
1169
+ "input",
1170
+ {
1171
+ value: l.label,
1172
+ onChange: (F) => a({ ...l, label: F.target.value }),
1173
+ placeholder: "Label to show for matching rows",
1174
+ style: m
1175
+ }
1176
+ )), /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: L(n) }, "Rule"), /* @__PURE__ */ t.createElement(
1177
+ "button",
1178
+ {
1179
+ type: "button",
1180
+ onClick: r,
1181
+ title: g,
1182
+ style: {
1183
+ ...q(n),
1184
+ display: "flex",
1185
+ alignItems: "center",
1186
+ gap: "8px",
1187
+ textAlign: "left",
1188
+ cursor: "pointer",
1189
+ background: n.hover || "#F8FAFC"
1190
+ }
1191
+ },
1192
+ /* @__PURE__ */ t.createElement(v.Filter, null),
1193
+ /* @__PURE__ */ t.createElement("span", { style: { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, g)
1194
+ )), /* @__PURE__ */ t.createElement("div", { style: { display: "flex", flexWrap: "wrap", gap: "8px" } }, /* @__PURE__ */ t.createElement("button", { type: "button", onClick: i, style: j(n, !!l.child) }, /* @__PURE__ */ t.createElement(v.Add, null), " ", l.child ? "Open Custom children" : "Add Custom children"), l.child && /* @__PURE__ */ t.createElement("button", { type: "button", onClick: s, style: j(n, !1, !0) }, /* @__PURE__ */ t.createElement(v.Delete, null), " Remove Custom children")), /* @__PURE__ */ t.createElement(
1195
+ "div",
1196
+ {
1197
+ style: {
1198
+ borderRadius: "10px",
1199
+ padding: "10px 12px",
1200
+ background: n.hover || "#F8FAFC",
1201
+ color: n.textSec,
1202
+ fontSize: "11px",
1203
+ lineHeight: 1.5
1204
+ }
1205
+ },
1206
+ "Override applies to this row only. Rows without this override continue with Default children."
1207
+ ));
1208
+ }
1209
+ function Ut({
1210
+ reportDef: e,
1211
+ setReportDef: l,
1212
+ availableFields: n,
1213
+ customDimensions: a = [],
1214
+ theme: r,
1215
+ data: i = [],
1216
+ valConfigs: s,
1217
+ colFields: f,
1218
+ setColFields: m,
1219
+ setValConfigs: g,
1220
+ savedReports: F,
1221
+ setSavedReports: N,
1222
+ activeReportId: y,
1223
+ setActiveReportId: w,
1224
+ showNotification: c,
1225
+ requestedSelection: E = null,
1226
+ showReportConfigColumn: h = !0,
1227
+ setShowReportConfigColumn: u
1228
+ }) {
1229
+ const [D, R] = H(""), [x, C] = H(null), [J, ue] = H(null), [oe, fe] = H(null), [d, k] = H(null), [st, ze] = H(null), ye = ke(null), ie = ke(!1), Te = ke(null), b = z(
1230
+ () => e && e.root ? V(e.root) : null,
1231
+ [e]
1232
+ ), W = z(
1233
+ () => Dt(n, s),
1234
+ [n, s]
1235
+ ), U = B(
1236
+ (o) => Et(o, a),
1237
+ [a]
1238
+ ), xe = z(
1239
+ () => Rt(s),
1240
+ [s]
1241
+ ), K = z(
1242
+ () => Ge(b, { allFields: W, valConfigs: s, data: i }),
1243
+ [b, W, s, i]
1244
+ ), $ = B((o) => {
1245
+ l((p) => {
1246
+ const S = p && typeof p == "object" ? p : {}, A = S.root ? V(S.root) : null, P = typeof o == "function" ? o(A) : o;
1247
+ return { ...S, root: P };
1248
+ });
1249
+ }, [l]), ee = z(() => Lt(b), [b]), I = z(() => We(b), [b]), se = z(
1250
+ () => Tt(ee, x),
1251
+ [ee, x]
1252
+ );
1253
+ z(
1254
+ () => jt(ee, x),
1255
+ [ee, x]
1256
+ ), z(
1257
+ () => Mt(ee, x),
1258
+ [ee, x]
1259
+ );
1260
+ const te = z(() => {
1261
+ if (!b || !x) return null;
1262
+ if (x.type === "node") {
1263
+ const o = ne(b, x.path);
1264
+ return o ? { type: "node", node: o } : null;
1265
+ }
1266
+ if (x.type === "branch") {
1267
+ const o = Fe(b, x.nodePath, x.branchIndex);
1268
+ return o ? { type: "branch", branch: o } : null;
1269
+ }
1270
+ return null;
1271
+ }, [b, x]), Ae = z(() => !J || !b ? null : Fe(b, J.nodePath, J.branchIndex), [J, b]), je = B((o) => {
1272
+ if (!o || o.type !== "rowPath" || !b) return !1;
1273
+ const p = Array.isArray(o.nodePath) ? o.nodePath : [], S = ne(b, p);
1274
+ if (!S) return !1;
1275
+ const A = Array.isArray(S.branches) ? S.branches : [], P = A.findIndex((ce) => Ze(ce, o.field, o.value)), _ = P >= 0 ? A[P] : null, be = _ && _.child ? _.child : S.defaultChild || G(""), Y = Q(o.label || o.value);
1276
+ return k({
1277
+ request: o,
1278
+ nodePath: p,
1279
+ branchIndex: P,
1280
+ rowLabel: Y,
1281
+ title: _ && _.label ? _.label : Y,
1282
+ child: Oe(be) || G(""),
1283
+ selectedPath: [],
1284
+ childLevelNumber: Number.isFinite(Number(o.levelNumber)) ? Number(o.levelNumber) + 1 : 2
1285
+ }), C({ type: "node", path: p }), !0;
1286
+ }, [b]);
1287
+ $e(() => {
1288
+ if (!b) {
1289
+ x !== null && C(null);
1290
+ return;
1291
+ }
1292
+ if (x) {
1293
+ if (x.type === "node") {
1294
+ ne(b, x.path) || C({ type: "node", path: [] });
1295
+ return;
1296
+ }
1297
+ Fe(b, x.nodePath, x.branchIndex) || C({ type: "node", path: x.nodePath });
1298
+ }
1299
+ }, [b, x]);
1300
+ const ge = B(() => {
1301
+ const o = ye.current;
1302
+ !o || typeof o.scrollIntoView != "function" || window.requestAnimationFrame(() => {
1303
+ o.scrollIntoView({ block: "start", behavior: "smooth" });
1304
+ });
1305
+ }, []);
1306
+ $e(() => {
1307
+ if (E && Te.current !== E) {
1308
+ if (Te.current = E, ie.current = !0, E.type === "rowPath") {
1309
+ je(E) || (ie.current = !1);
1310
+ return;
1311
+ }
1312
+ if (Z(E) === Z(x)) {
1313
+ ie.current = !1, ge();
1314
+ return;
1315
+ }
1316
+ C(E);
1317
+ }
1318
+ }, [je, E, ge, x]), $e(() => {
1319
+ ie.current && (ie.current = !1, ge());
1320
+ }, [ge, x]);
1321
+ const Me = B((o, p) => {
1322
+ $((S) => O(S, o, () => p));
1323
+ }, [$]), He = B((o, p, S) => {
1324
+ $((A) => ve(A, o, p, () => S));
1325
+ }, [$]), ct = B((o) => {
1326
+ const p = G(o);
1327
+ $(p), k(null), C({ type: "node", path: [] });
1328
+ }, [$]);
1329
+ B((o, p) => {
1330
+ p || $((S) => O(S, o, (A) => ({
1331
+ ...A,
1332
+ defaultChild: G("")
1333
+ }))), C({ type: "node", path: [...o, T] });
1334
+ }, [$]), B((o) => {
1335
+ $((p) => O(p, o, (S) => ({
1336
+ ...S,
1337
+ defaultChild: null
1338
+ }))), C({ type: "node", path: o });
1339
+ }, [$]);
1340
+ const dt = B((o, p, S) => {
1341
+ S || $((A) => ve(A, o, p, (P) => ({
1342
+ ...P,
1343
+ child: G(W[0] || "")
1344
+ }))), C({ type: "node", path: [...o, _e(p)] });
1345
+ }, [W, $]), pt = B((o, p) => {
1346
+ $((S) => ve(S, o, p, (A) => ({
1347
+ ...A,
1348
+ child: null
1349
+ }))), C({ type: "branch", nodePath: o, branchIndex: p });
1350
+ }, [$]), ut = B((o) => {
1351
+ if (o.length === 0) {
1352
+ $(null), k(null), C(null);
1353
+ return;
1354
+ }
1355
+ const p = o.slice(0, -1), S = o[o.length - 1];
1356
+ if (S === T) {
1357
+ $((P) => O(P, p, (_) => ({
1358
+ ..._,
1359
+ defaultChild: null
1360
+ }))), C({ type: "node", path: p });
1361
+ return;
1362
+ }
1363
+ const A = Se(S);
1364
+ A >= 0 && ($((P) => ve(P, p, A, (_) => ({
1365
+ ..._,
1366
+ child: null
1367
+ }))), C({ type: "branch", nodePath: p, branchIndex: A }));
1368
+ }, [$]), ft = B((o, p) => {
1369
+ $((S) => O(S, o, (A) => ({
1370
+ ...A,
1371
+ branches: A.branches.filter((P, _) => _ !== p)
1372
+ }))), C({ type: "node", path: o });
1373
+ }, [$]), yt = B((o) => {
1374
+ k(null), C({ type: "node", path: o });
1375
+ }, []), Ve = B((o) => {
1376
+ if (o) {
1377
+ if (k(null), o.kind === "branch") {
1378
+ C({ type: "branch", nodePath: o.nodePath, branchIndex: o.branchIndex });
1379
+ return;
1380
+ }
1381
+ C({ type: "node", path: o.nodePath });
1382
+ }
1383
+ }, []), xt = B(() => {
1384
+ if (!b || !I.length) return;
1385
+ const o = I[I.length - 1];
1386
+ if (!o || !o.node || !o.node.field) return;
1387
+ const p = [...o.path, T];
1388
+ k(null), $((S) => O(S, o.path, (A) => ({
1389
+ ...A,
1390
+ defaultChild: A.defaultChild || G("")
1391
+ }))), C({ type: "node", path: p });
1392
+ }, [I, b, $]), gt = B((o, p) => {
1393
+ o === null || o === p || ($((S) => rt(S, o, p)), C({ type: "node", path: Ne(p) }), ze(null));
1394
+ }, [$]), bt = B(() => {
1395
+ k(null), C(null);
1396
+ }, []), ht = B(() => {
1397
+ if (!K.valid) {
1398
+ c && c(K.errors[0] || "Fix report validation errors before applying.", "error");
1399
+ return;
1400
+ }
1401
+ C(null);
1402
+ }, [K, c]), vt = B(() => {
1403
+ if (!d || !d.request) return;
1404
+ const o = d.request, p = Array.isArray(d.nodePath) ? d.nodePath : [], S = zt(d.child), A = {
1405
+ ..._t(o.field, o.value, d.title || d.rowLabel, ""),
1406
+ label: Q(d.title || d.rowLabel || o.value),
1407
+ sourceRowPath: Array.isArray(o.pathValues) ? o.pathValues.map(String).filter(Boolean) : [],
1408
+ sourcePathFields: Array.isArray(o.pathFields) ? o.pathFields.map(String).filter(Boolean) : [],
1409
+ child: S
1410
+ }, P = (Y) => {
1411
+ const ce = Array.isArray(Y.branches) ? Y.branches : [], Je = ce.findIndex((he) => Ze(he, o.field, o.value));
1412
+ return Je >= 0 ? {
1413
+ ...Y,
1414
+ branches: ce.map((he, mt) => mt === Je ? { ...A, _id: he._id || A._id } : he)
1415
+ } : {
1416
+ ...Y,
1417
+ branches: [...ce, A]
1418
+ };
1419
+ }, _ = O(b, p, P), be = Ge(_, { allFields: W, valConfigs: s, data: i });
1420
+ if (!be.valid) {
1421
+ c && c(be.errors[0] || "Fix report validation errors before applying.", "error");
1422
+ return;
1423
+ }
1424
+ $((Y) => O(Y, p, P)), k(null), C(null), c && c(`Applied settings for ${d.rowLabel || "row"}`, "info");
1425
+ }, [W, i, b, d, $, c, s]), qe = B(() => {
1426
+ if (!b || !b.field) return;
1427
+ if (!K.valid) {
1428
+ c && c(K.errors[0] || "Fix report validation errors before saving.", "error");
1429
+ return;
1430
+ }
1431
+ const o = `report-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`, p = D.trim() || `Report ${(F || []).length + 1}`;
1432
+ N([
1433
+ ...F || [],
1434
+ {
1435
+ id: o,
1436
+ name: p,
1437
+ reportDef: JSON.parse(JSON.stringify(e)),
1438
+ layout: St(f, s),
1439
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
1440
+ }
1441
+ ]), w(o), R(""), c && c(`Report "${p}" saved`, "info");
1442
+ }, [f, s, e, D, K, b, F, w, N, c]);
1443
+ return /* @__PURE__ */ t.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "18px", padding: "2px 0 8px" } }, (F || []).length > 0 && /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: L(r) }, /* @__PURE__ */ t.createElement(v.Save, null), " Saved Reports"), /* @__PURE__ */ t.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "6px" } }, (F || []).map((o) => /* @__PURE__ */ t.createElement(
1444
+ "div",
1445
+ {
1446
+ key: o.id,
1447
+ onClick: () => {
1448
+ Ct(o, { setReportDef: l, setActiveReportId: w, setColFields: m, setValConfigs: g }), k(null), C({ type: "node", path: [] });
1449
+ },
1450
+ style: {
1451
+ display: "flex",
1452
+ alignItems: "center",
1453
+ gap: "8px",
1454
+ padding: "8px 10px",
1455
+ borderRadius: "10px",
1456
+ cursor: "pointer",
1457
+ background: o.id === y ? r.select || `${r.primary || "#2563EB"}14` : r.hover || "#F9FAFB",
1458
+ border: `1px solid ${o.id === y ? r.primary || "#2563EB" : r.border}`
1459
+ }
1460
+ },
1461
+ /* @__PURE__ */ t.createElement(v.Report, null),
1462
+ /* @__PURE__ */ t.createElement("div", { style: { flex: 1, minWidth: 0, fontSize: "12px", fontWeight: 700, color: r.text, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, o.name),
1463
+ /* @__PURE__ */ t.createElement(
1464
+ "button",
1465
+ {
1466
+ type: "button",
1467
+ onClick: (p) => {
1468
+ p.stopPropagation(), N((S) => (S || []).filter((A) => A.id !== o.id)), y === o.id && w(null);
1469
+ },
1470
+ style: { background: "none", border: "none", cursor: "pointer", color: "#B91C1C", padding: "2px", flexShrink: 0 }
1471
+ },
1472
+ /* @__PURE__ */ t.createElement(v.Delete, null)
1473
+ )
1474
+ )))), /* @__PURE__ */ t.createElement(
1475
+ re,
1476
+ {
1477
+ theme: r,
1478
+ sectionId: "report-levels",
1479
+ title: "Report Levels",
1480
+ description: "Default hierarchy applied to every row unless a row override changes its children.",
1481
+ icon: /* @__PURE__ */ t.createElement(v.ReportLevel, null),
1482
+ action: b && /* @__PURE__ */ t.createElement("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap", justifyContent: "flex-end" } }, typeof u == "function" && /* @__PURE__ */ t.createElement(
1483
+ "button",
1484
+ {
1485
+ type: "button",
1486
+ onClick: () => u((o) => o === !1),
1487
+ style: j(r, h !== !1, !1),
1488
+ title: h !== !1 ? "Hide row gear column" : "Show row gear column"
1489
+ },
1490
+ /* @__PURE__ */ t.createElement(v.Settings, null),
1491
+ " ",
1492
+ h !== !1 ? "Hide row gears" : "Show row gears"
1493
+ ), /* @__PURE__ */ t.createElement(
1494
+ "button",
1495
+ {
1496
+ type: "button",
1497
+ onClick: xt,
1498
+ disabled: !I.length || !I[I.length - 1].node.field,
1499
+ style: {
1500
+ ...j(r, !1, !1),
1501
+ opacity: !I.length || !I[I.length - 1].node.field ? 0.5 : 1,
1502
+ pointerEvents: !I.length || !I[I.length - 1].node.field ? "none" : "auto"
1503
+ }
1504
+ },
1505
+ /* @__PURE__ */ t.createElement(v.Add, null),
1506
+ " Add next level"
1507
+ ))
1508
+ },
1509
+ b ? /* @__PURE__ */ t.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "8px" } }, I.map((o) => /* @__PURE__ */ t.createElement(
1510
+ it,
1511
+ {
1512
+ key: `default-level:${o.index}:${o.node._id}`,
1513
+ item: o,
1514
+ selected: !d && Z(x) === Z({ type: "node", path: o.path }),
1515
+ theme: r,
1516
+ sortByOptions: xe,
1517
+ getFieldLabel: U,
1518
+ onSelect: () => yt(o.path),
1519
+ onDragStart: (p) => {
1520
+ ze(o.index), p.dataTransfer.effectAllowed = "move";
1521
+ },
1522
+ onDragOver: (p) => p.preventDefault(),
1523
+ onDrop: (p) => {
1524
+ p.preventDefault(), gt(st, o.index);
1525
+ }
1526
+ }
1527
+ ))) : /* @__PURE__ */ t.createElement("div", { style: pe(r) }, /* @__PURE__ */ t.createElement("div", { style: { fontSize: "14px", fontWeight: 800, color: r.text } }, "Level 1"), /* @__PURE__ */ t.createElement("div", null, /* @__PURE__ */ t.createElement("div", { style: L(r) }, "Break Down By"), /* @__PURE__ */ t.createElement(
1528
+ "select",
1529
+ {
1530
+ value: "",
1531
+ onChange: (o) => {
1532
+ o.target.value && ct(o.target.value);
1533
+ },
1534
+ style: q(r)
1535
+ },
1536
+ /* @__PURE__ */ t.createElement("option", { value: "" }, "Select field..."),
1537
+ W.map((o) => /* @__PURE__ */ t.createElement("option", { key: o, value: o }, U(o)))
1538
+ )))
1539
+ ), b && /* @__PURE__ */ t.createElement(
1540
+ re,
1541
+ {
1542
+ theme: r,
1543
+ sectionId: "report-outline",
1544
+ title: "Report Outline",
1545
+ description: "Default levels plus every row override, shown as a separate map of Default children.",
1546
+ icon: /* @__PURE__ */ t.createElement(v.Report, null)
1547
+ },
1548
+ /* @__PURE__ */ t.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "8px" } }, ee.map((o) => o.kind === "branch" ? /* @__PURE__ */ t.createElement(
1549
+ Kt,
1550
+ {
1551
+ key: `outline-branch:${le(o.nodePath)}:${o.branchIndex}:${o.branch._id}`,
1552
+ item: o,
1553
+ selected: !d && Z(x) === Z({
1554
+ type: "branch",
1555
+ nodePath: o.nodePath,
1556
+ branchIndex: o.branchIndex
1557
+ }),
1558
+ theme: r,
1559
+ onSelect: () => Ve(o)
1560
+ }
1561
+ ) : /* @__PURE__ */ t.createElement(
1562
+ Jt,
1563
+ {
1564
+ key: `outline-node:${le(o.nodePath)}:${o.node._id}`,
1565
+ item: o,
1566
+ selected: !d && Z(x) === Z({ type: "node", path: o.nodePath }),
1567
+ theme: r,
1568
+ sortByOptions: xe,
1569
+ getFieldLabel: U,
1570
+ onSelect: () => Ve(o)
1571
+ }
1572
+ )))
1573
+ ), b && d && /* @__PURE__ */ t.createElement("div", { ref: ye }, /* @__PURE__ */ t.createElement(
1574
+ re,
1575
+ {
1576
+ theme: r,
1577
+ sectionId: "selected-row",
1578
+ title: "Selected Row",
1579
+ description: "Configure Custom children for the row gear you clicked.",
1580
+ icon: /* @__PURE__ */ t.createElement(v.Settings, null)
1581
+ },
1582
+ /* @__PURE__ */ t.createElement(
1583
+ Gt,
1584
+ {
1585
+ draft: d,
1586
+ allFields: W,
1587
+ getFieldLabel: U,
1588
+ sortByOptions: xe,
1589
+ theme: r,
1590
+ onChange: k,
1591
+ onApply: vt,
1592
+ onCancel: bt
1593
+ }
1594
+ )
1595
+ )), b && !d && x && te && te.type === "node" && /* @__PURE__ */ t.createElement("div", { ref: ye }, /* @__PURE__ */ t.createElement(
1596
+ re,
1597
+ {
1598
+ theme: r,
1599
+ sectionId: "selected-level",
1600
+ title: "Selected Level",
1601
+ description: "Edit the selected default level or override child level.",
1602
+ icon: /* @__PURE__ */ t.createElement(v.Edit, null)
1603
+ },
1604
+ /* @__PURE__ */ t.createElement(
1605
+ Yt,
1606
+ {
1607
+ item: I.find((o) => we(o.path, x.path)) || (se ? { ...se, path: se.nodePath } : { path: x.path, levelNumber: x.path.length + 1 }),
1608
+ node: te.node,
1609
+ allFields: W,
1610
+ getFieldLabel: U,
1611
+ sortByOptions: xe,
1612
+ theme: r,
1613
+ onUpdate: (o) => Me(x.path, o),
1614
+ onApply: ht,
1615
+ onRemove: () => ut(x.path),
1616
+ onEditFilter: () => fe(x.path),
1617
+ titleLabel: "Title"
1618
+ }
1619
+ )
1620
+ )), b && !d && x && te && te.type === "branch" && se && /* @__PURE__ */ t.createElement("div", { ref: ye }, /* @__PURE__ */ t.createElement(
1621
+ re,
1622
+ {
1623
+ theme: r,
1624
+ sectionId: "row-override",
1625
+ title: "Row Override",
1626
+ description: "Override applies to this row only. Configure its rule and Custom children.",
1627
+ icon: /* @__PURE__ */ t.createElement(v.Settings, null)
1628
+ },
1629
+ /* @__PURE__ */ t.createElement(
1630
+ Zt,
1631
+ {
1632
+ item: se,
1633
+ branch: te.branch,
1634
+ theme: r,
1635
+ onUpdate: (o) => He(x.nodePath, x.branchIndex, o),
1636
+ onEditCondition: () => ue({ nodePath: x.nodePath, branchIndex: x.branchIndex }),
1637
+ onOpenCustomChildren: () => dt(x.nodePath, x.branchIndex, !!te.branch.child),
1638
+ onRemoveCustomChildren: () => pt(x.nodePath, x.branchIndex),
1639
+ onRemove: () => ft(x.nodePath, x.branchIndex)
1640
+ }
1641
+ )
1642
+ )), /* @__PURE__ */ t.createElement(
1643
+ re,
1644
+ {
1645
+ theme: r,
1646
+ sectionId: "save-report",
1647
+ title: "Save Report",
1648
+ description: "Store the current report levels and row overrides.",
1649
+ icon: /* @__PURE__ */ t.createElement(v.Save, null)
1650
+ },
1651
+ /* @__PURE__ */ t.createElement(Vt, { validation: K, theme: r }),
1652
+ /* @__PURE__ */ t.createElement("div", { style: { display: "flex", gap: "8px" } }, /* @__PURE__ */ t.createElement(
1653
+ "input",
1654
+ {
1655
+ value: D,
1656
+ onChange: (o) => R(o.target.value),
1657
+ onKeyDown: (o) => {
1658
+ o.key === "Enter" && qe();
1659
+ },
1660
+ placeholder: "Report name...",
1661
+ style: { ...q(r), flex: 1 }
1662
+ }
1663
+ ), /* @__PURE__ */ t.createElement(
1664
+ "button",
1665
+ {
1666
+ type: "button",
1667
+ onClick: qe,
1668
+ disabled: !b || !b.field || !K.valid,
1669
+ style: {
1670
+ display: "inline-flex",
1671
+ alignItems: "center",
1672
+ gap: "6px",
1673
+ background: r.primary || "#2563EB",
1674
+ border: "none",
1675
+ borderRadius: "9px",
1676
+ padding: "8px 14px",
1677
+ fontSize: "12px",
1678
+ fontWeight: 800,
1679
+ color: "#fff",
1680
+ cursor: "pointer",
1681
+ opacity: !b || !b.field || !K.valid ? 0.5 : 1
1682
+ }
1683
+ },
1684
+ /* @__PURE__ */ t.createElement(v.Save, null),
1685
+ " Save"
1686
+ ))
1687
+ ), J && Ae && /* @__PURE__ */ t.createElement(
1688
+ Ie,
1689
+ {
1690
+ condition: Ae.condition,
1691
+ allFields: W,
1692
+ getFieldLabel: U,
1693
+ theme: r,
1694
+ onSave: (o) => {
1695
+ He(J.nodePath, J.branchIndex, {
1696
+ ...Ae,
1697
+ condition: o
1698
+ });
1699
+ },
1700
+ onClose: () => ue(null)
1701
+ }
1702
+ ), oe && (() => {
1703
+ const o = ne(b, oe);
1704
+ return o ? /* @__PURE__ */ t.createElement(
1705
+ Ie,
1706
+ {
1707
+ title: "Edit level filter",
1708
+ description: "Rows that don't match are grouped into 'Others' to keep totals intact. Applies to this level and all its children.",
1709
+ condition: o.filters || Pe(),
1710
+ allFields: W,
1711
+ getFieldLabel: U,
1712
+ theme: r,
1713
+ onSave: (p) => {
1714
+ Me(oe, {
1715
+ ...o,
1716
+ filters: p.clauses.length > 0 ? p : null
1717
+ });
1718
+ },
1719
+ onClose: () => fe(null)
1720
+ }
1721
+ ) : null;
1722
+ })());
1723
+ }
1724
+ export {
1725
+ Ut as ReportEditor
1726
+ };