drizzle-cube 0.2.5 → 0.2.8

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 (122) hide show
  1. package/dist/client/charts.js +15 -15
  2. package/dist/client/chunks/{chart-activitygridchart-BzL97Vnm.js → chart-activitygridchart-Cz4bEf3V.js} +219 -217
  3. package/dist/client/chunks/chart-activitygridchart-Cz4bEf3V.js.map +1 -0
  4. package/dist/client/chunks/{chart-activitygridchart-config-48WqIofo.js → chart-activitygridchart-config-BngZDVh_.js} +96 -90
  5. package/dist/client/chunks/chart-activitygridchart-config-BngZDVh_.js.map +1 -0
  6. package/dist/client/chunks/{chart-areachart-BtH3SvAM.js → chart-areachart-DLdolSnU.js} +3 -3
  7. package/dist/client/chunks/{chart-areachart-BtH3SvAM.js.map → chart-areachart-DLdolSnU.js.map} +1 -1
  8. package/dist/client/chunks/{chart-areachart-config-D8taXdn1.js → chart-areachart-config-DWN1E5ej.js} +2 -2
  9. package/dist/client/chunks/{chart-areachart-config-D8taXdn1.js.map → chart-areachart-config-DWN1E5ej.js.map} +1 -1
  10. package/dist/client/chunks/chart-barchart-Bdjz8DJp.js +171 -0
  11. package/dist/client/chunks/chart-barchart-Bdjz8DJp.js.map +1 -0
  12. package/dist/client/chunks/{chart-barchart-config-DjRZBtLb.js → chart-barchart-config-DZA0xTns.js} +2 -2
  13. package/dist/client/chunks/{chart-barchart-config-DjRZBtLb.js.map → chart-barchart-config-DZA0xTns.js.map} +1 -1
  14. package/dist/client/chunks/{chart-bubblechart-Lj_PnppP.js → chart-bubblechart-BlQkmqkI.js} +2 -2
  15. package/dist/client/chunks/{chart-bubblechart-Lj_PnppP.js.map → chart-bubblechart-BlQkmqkI.js.map} +1 -1
  16. package/dist/client/chunks/{chart-bubblechart-config-C6ck2qmg.js → chart-bubblechart-config-C79lfDSO.js} +2 -2
  17. package/dist/client/chunks/{chart-bubblechart-config-C6ck2qmg.js.map → chart-bubblechart-config-C79lfDSO.js.map} +1 -1
  18. package/dist/client/chunks/{chart-charttooltip-D9BKscsw.js → chart-charttooltip-k8soCd2n.js} +2 -2
  19. package/dist/client/chunks/{chart-charttooltip-D9BKscsw.js.map → chart-charttooltip-k8soCd2n.js.map} +1 -1
  20. package/dist/client/chunks/chart-datatable-Mo4gYCwa.js +249 -0
  21. package/dist/client/chunks/chart-datatable-Mo4gYCwa.js.map +1 -0
  22. package/dist/client/chunks/{chart-datatable-config-B5z0SlOJ.js → chart-datatable-config-DqGw99R3.js} +2 -2
  23. package/dist/client/chunks/{chart-datatable-config-B5z0SlOJ.js.map → chart-datatable-config-DqGw99R3.js.map} +1 -1
  24. package/dist/client/chunks/{chart-kpidelta-Bx-stIIk.js → chart-kpidelta-CTcuIO9G.js} +3 -3
  25. package/dist/client/chunks/{chart-kpidelta-Bx-stIIk.js.map → chart-kpidelta-CTcuIO9G.js.map} +1 -1
  26. package/dist/client/chunks/{chart-kpidelta-config-CnZfi_P2.js → chart-kpidelta-config-B-Y-LHmd.js} +2 -2
  27. package/dist/client/chunks/{chart-kpidelta-config-CnZfi_P2.js.map → chart-kpidelta-config-B-Y-LHmd.js.map} +1 -1
  28. package/dist/client/chunks/{chart-kpinumber-config-CVikHojM.js → chart-kpinumber-config-BaNaJMI6.js} +2 -2
  29. package/dist/client/chunks/{chart-kpinumber-config-CVikHojM.js.map → chart-kpinumber-config-BaNaJMI6.js.map} +1 -1
  30. package/dist/client/chunks/{chart-kpinumber-BrXgyKGP.js → chart-kpinumber-slEXt8C-.js} +5 -5
  31. package/dist/client/chunks/{chart-kpinumber-BrXgyKGP.js.map → chart-kpinumber-slEXt8C-.js.map} +1 -1
  32. package/dist/client/chunks/{chart-kpitext-config-B2MovXSw.js → chart-kpitext-config-BNywYqEW.js} +2 -2
  33. package/dist/client/chunks/{chart-kpitext-config-B2MovXSw.js.map → chart-kpitext-config-BNywYqEW.js.map} +1 -1
  34. package/dist/client/chunks/{chart-kpitext-_2tnYN_z.js → chart-kpitext-giq03TOK.js} +3 -3
  35. package/dist/client/chunks/{chart-kpitext-_2tnYN_z.js.map → chart-kpitext-giq03TOK.js.map} +1 -1
  36. package/dist/client/chunks/{chart-linechart-DBdIULsM.js → chart-linechart-BfnU6L-D.js} +4 -4
  37. package/dist/client/chunks/{chart-linechart-DBdIULsM.js.map → chart-linechart-BfnU6L-D.js.map} +1 -1
  38. package/dist/client/chunks/{chart-linechart-config-CVBVB7nS.js → chart-linechart-config-BL_1mjHF.js} +2 -2
  39. package/dist/client/chunks/{chart-linechart-config-CVBVB7nS.js.map → chart-linechart-config-BL_1mjHF.js.map} +1 -1
  40. package/dist/client/chunks/{chart-markdownchart-config-Cq5Sxrgq.js → chart-markdownchart-config-DtZOfYu4.js} +2 -2
  41. package/dist/client/chunks/{chart-markdownchart-config-Cq5Sxrgq.js.map → chart-markdownchart-config-DtZOfYu4.js.map} +1 -1
  42. package/dist/client/chunks/{chart-piechart-CzesCpZ_.js → chart-piechart-CZRDQxeB.js} +3 -3
  43. package/dist/client/chunks/{chart-piechart-CzesCpZ_.js.map → chart-piechart-CZRDQxeB.js.map} +1 -1
  44. package/dist/client/chunks/{chart-piechart-config-Bdd31Gdi.js → chart-piechart-config-Bg4jeIFo.js} +2 -2
  45. package/dist/client/chunks/{chart-piechart-config-Bdd31Gdi.js.map → chart-piechart-config-Bg4jeIFo.js.map} +1 -1
  46. package/dist/client/chunks/{chart-radarchart-B3WUEiTh.js → chart-radarchart-D5yRnY9j.js} +3 -3
  47. package/dist/client/chunks/{chart-radarchart-B3WUEiTh.js.map → chart-radarchart-D5yRnY9j.js.map} +1 -1
  48. package/dist/client/chunks/{chart-radarchart-config-BWyfn0ij.js → chart-radarchart-config-d6dLkI7B.js} +2 -2
  49. package/dist/client/chunks/{chart-radarchart-config-BWyfn0ij.js.map → chart-radarchart-config-d6dLkI7B.js.map} +1 -1
  50. package/dist/client/chunks/{chart-radialbarchart-DBiRcLd9.js → chart-radialbarchart-Djtcn7aH.js} +3 -3
  51. package/dist/client/chunks/{chart-radialbarchart-DBiRcLd9.js.map → chart-radialbarchart-Djtcn7aH.js.map} +1 -1
  52. package/dist/client/chunks/{chart-radialbarchart-config-lU2_NQCD.js → chart-radialbarchart-config-BGf97-BV.js} +2 -2
  53. package/dist/client/chunks/{chart-radialbarchart-config-lU2_NQCD.js.map → chart-radialbarchart-config-BGf97-BV.js.map} +1 -1
  54. package/dist/client/chunks/{chart-scatterchart-C_D9OqA1.js → chart-scatterchart-C83KgqYY.js} +2 -2
  55. package/dist/client/chunks/{chart-scatterchart-C_D9OqA1.js.map → chart-scatterchart-C83KgqYY.js.map} +1 -1
  56. package/dist/client/chunks/{chart-scatterchart-config-DtLnut1M.js → chart-scatterchart-config-DEIB74ot.js} +2 -2
  57. package/dist/client/chunks/{chart-scatterchart-config-DtLnut1M.js.map → chart-scatterchart-config-DEIB74ot.js.map} +1 -1
  58. package/dist/client/chunks/{chart-treemapchart-DJqy3Sy7.js → chart-treemapchart-BDKnKGTz.js} +3 -3
  59. package/dist/client/chunks/{chart-treemapchart-DJqy3Sy7.js.map → chart-treemapchart-BDKnKGTz.js.map} +1 -1
  60. package/dist/client/chunks/{chart-treemapchart-config-BEiIWQnR.js → chart-treemapchart-config-ppKPTB96.js} +2 -2
  61. package/dist/client/chunks/{chart-treemapchart-config-BEiIWQnR.js.map → chart-treemapchart-config-ppKPTB96.js.map} +1 -1
  62. package/dist/client/chunks/{charts-DFbr7EGW.js → charts-MJLpxe3r.js} +42 -42
  63. package/dist/client/chunks/{charts-DFbr7EGW.js.map → charts-MJLpxe3r.js.map} +1 -1
  64. package/dist/client/chunks/components-CXA6-jJq.js +9845 -0
  65. package/dist/client/chunks/components-CXA6-jJq.js.map +1 -0
  66. package/dist/client/chunks/{icons-D6z-_9sa.js → icons-B2XSxpVK.js} +213 -181
  67. package/dist/client/chunks/icons-B2XSxpVK.js.map +1 -0
  68. package/dist/client/chunks/{index-_pVwmFVW.js → index-CSeLP8gq.js} +2 -2
  69. package/dist/client/chunks/{index-_pVwmFVW.js.map → index-CSeLP8gq.js.map} +1 -1
  70. package/dist/client/components/AnalysisBuilder/AnalysisAxisDropZone.d.ts +27 -0
  71. package/dist/client/components/AnalysisBuilder/AnalysisChartConfigPanel.d.ts +21 -0
  72. package/dist/client/components/AnalysisBuilder/AnalysisFilterGroup.d.ts +20 -0
  73. package/dist/client/components/AnalysisBuilder/AnalysisFilterItem.d.ts +16 -0
  74. package/dist/client/components/AnalysisBuilder/AnalysisFilterSection.d.ts +12 -0
  75. package/dist/client/components/AnalysisBuilder/AnalysisQueryPanel.d.ts +10 -0
  76. package/dist/client/components/AnalysisBuilder/AnalysisResultsPanel.d.ts +12 -0
  77. package/dist/client/components/AnalysisBuilder/BreakdownItemCard.d.ts +10 -0
  78. package/dist/client/components/AnalysisBuilder/BreakdownSection.d.ts +8 -0
  79. package/dist/client/components/AnalysisBuilder/FieldDetailPanel.d.ts +4 -0
  80. package/dist/client/components/AnalysisBuilder/FieldSearchItem.d.ts +6 -0
  81. package/dist/client/components/AnalysisBuilder/FieldSearchModal.d.ts +2 -0
  82. package/dist/client/components/AnalysisBuilder/MetricItemCard.d.ts +9 -0
  83. package/dist/client/components/AnalysisBuilder/MetricsSection.d.ts +8 -0
  84. package/dist/client/components/AnalysisBuilder/index.d.ts +3 -0
  85. package/dist/client/components/AnalysisBuilder/types.d.ts +366 -0
  86. package/dist/client/components/AnalysisBuilder/utils.d.ts +103 -0
  87. package/dist/client/components/ChartTypeSelector.d.ts +6 -1
  88. package/dist/client/components/DashboardGrid.d.ts +3 -2
  89. package/dist/client/components/DashboardPortletCard.d.ts +63 -0
  90. package/dist/client/components/QueryBuilder/CubeMetaExplorer.d.ts +2 -2
  91. package/dist/client/components/QueryBuilder/QueryPanel.d.ts +2 -2
  92. package/dist/client/components/QueryBuilder/types.d.ts +7 -138
  93. package/dist/client/components/RowManagedLayout.d.ts +19 -0
  94. package/dist/client/components/charts/DataTable.d.ts +1 -1
  95. package/dist/client/components.js +16 -9148
  96. package/dist/client/components.js.map +1 -1
  97. package/dist/client/hooks.js +2 -2
  98. package/dist/client/icons/types.d.ts +6 -0
  99. package/dist/client/icons.js +1 -1
  100. package/dist/client/index.d.ts +1 -0
  101. package/dist/client/index.js +3202 -49
  102. package/dist/client/index.js.map +1 -1
  103. package/dist/client/providers/CubeProvider.d.ts +4 -2
  104. package/dist/client/providers.js +1 -1
  105. package/dist/client/shared/chartDefaults.d.ts +64 -0
  106. package/dist/client/shared/components/QueryAnalysisPanel.d.ts +7 -0
  107. package/dist/client/shared/index.d.ts +10 -0
  108. package/dist/client/shared/types.d.ts +134 -0
  109. package/dist/client/shared/utils.d.ts +101 -0
  110. package/dist/client/styles.css +1 -1
  111. package/dist/client/types.d.ts +20 -0
  112. package/dist/client/utils/index.d.ts +1 -0
  113. package/dist/client/utils/pivotUtils.d.ts +78 -0
  114. package/dist/client-bundle-stats.html +1 -1
  115. package/package.json +1 -1
  116. package/dist/client/chunks/chart-activitygridchart-BzL97Vnm.js.map +0 -1
  117. package/dist/client/chunks/chart-activitygridchart-config-48WqIofo.js.map +0 -1
  118. package/dist/client/chunks/chart-barchart-DX6DIoIp.js +0 -177
  119. package/dist/client/chunks/chart-barchart-DX6DIoIp.js.map +0 -1
  120. package/dist/client/chunks/chart-datatable-BaECYDn2.js +0 -57
  121. package/dist/client/chunks/chart-datatable-BaECYDn2.js.map +0 -1
  122. package/dist/client/chunks/icons-D6z-_9sa.js.map +0 -1
@@ -1,52 +1,3205 @@
1
- import { AnalyticsDashboard as r, AnalyticsPortlet as s, DashboardEditModal as t, DashboardGrid as o, Modal as i, PortletContainer as n, PortletEditModal as l, QueryBuilder as d } from "./components.js";
2
- import { L as c } from "./chunks/chart-chartcontainer-CdwzIKP1.js";
3
- import { L as g, c as p, f as y, g as T, i as m, p as u, a as b } from "./chunks/charts-DFbr7EGW.js";
4
- import { n as f, T as x, y as D, r as E, g as L, v as M, B as P, z as A, A as S, x as v, u as B, w as V } from "./chunks/chart-activitygridchart-BzL97Vnm.js";
5
- import { ScrollContainerProvider as z, useScrollContainer as F } from "./providers.js";
6
- import { useCubeQuery as R } from "./hooks.js";
7
- import { D as k, g as G, h as H, a as N, b as O, d as U, e as j, f as q, r as J, c as K, s as W } from "./chunks/chart-activitygridchart-config-48WqIofo.js";
1
+ import { F as Be, D as Te, c as ct, C as it } from "./chunks/components-CXA6-jJq.js";
2
+ import { a as $r, A as Or, e as Mr, b as Er, M as Lr, P as _r, d as Br, Q as jr } from "./chunks/components-CXA6-jJq.js";
3
+ import { L as qr } from "./chunks/chart-chartcontainer-CdwzIKP1.js";
4
+ import { i as dt, L as $e, g as ot } from "./chunks/charts-MJLpxe3r.js";
5
+ import { c as Gr, f as Qr, b as zr, p as Jr, a as Hr } from "./chunks/charts-MJLpxe3r.js";
6
+ import { jsxs as a, jsx as t, Fragment as ut } from "react/jsx-runtime";
7
+ import Oe, { memo as je, useState as B, useRef as ce, useMemo as H, useEffect as Z, useCallback as E, forwardRef as mt, useImperativeHandle as ht } from "react";
8
+ import { u as xt } from "./chunks/chart-activitygridchart-Cz4bEf3V.js";
9
+ import { n as Wr, T as Yr, y as Xr, r as Zr, g as Ur, v as es, B as ts, z as rs, A as ss, x as ns, w as as } from "./chunks/chart-activitygridchart-Cz4bEf3V.js";
10
+ import { useDebounce as ft, useFilterValues as bt, useCubeQuery as pt } from "./hooks.js";
11
+ import { b as I, a as xe, c as ke } from "./chunks/chart-activitygridchart-config-BngZDVh_.js";
12
+ import { D as cs, g as is, d as ds, f as os, h as us, r as ms, e as hs, s as xs } from "./chunks/chart-activitygridchart-config-BngZDVh_.js";
13
+ import { ScrollContainerProvider as bs, useScrollContainer as ps } from "./providers.js";
14
+ function Ve(e, r) {
15
+ if (!r) return null;
16
+ for (const s of r.cubes) {
17
+ const l = s.measures.find((d) => d.name === e);
18
+ if (l)
19
+ return { field: l, cubeName: s.name, fieldType: "measure" };
20
+ const n = s.dimensions.find((d) => d.name === e);
21
+ if (n)
22
+ return {
23
+ field: n,
24
+ cubeName: s.name,
25
+ fieldType: n.type === "time" ? "timeDimension" : "dimension"
26
+ };
27
+ }
28
+ return null;
29
+ }
30
+ function gt(e, r) {
31
+ const s = Ve(e, r);
32
+ return s && (s.field.title || s.field.shortTitle) || e;
33
+ }
34
+ function qe(e, r) {
35
+ if (!e) return [];
36
+ const s = [];
37
+ for (const l of e.cubes)
38
+ if (r === "metrics")
39
+ for (const n of l.measures)
40
+ s.push({
41
+ name: n.name,
42
+ title: n.title || n.shortTitle || n.name,
43
+ shortTitle: n.shortTitle || n.title || n.name,
44
+ type: n.type,
45
+ description: n.description,
46
+ cubeName: l.name,
47
+ fieldType: "measure"
48
+ });
49
+ else if (r === "breakdown")
50
+ for (const n of l.dimensions) {
51
+ const d = n.type === "time";
52
+ s.push({
53
+ name: n.name,
54
+ title: n.title || n.shortTitle || n.name,
55
+ shortTitle: n.shortTitle || n.title || n.name,
56
+ type: n.type,
57
+ description: n.description,
58
+ cubeName: l.name,
59
+ fieldType: d ? "timeDimension" : "dimension"
60
+ });
61
+ }
62
+ else {
63
+ for (const n of l.measures)
64
+ s.push({
65
+ name: n.name,
66
+ title: n.title || n.shortTitle || n.name,
67
+ shortTitle: n.shortTitle || n.title || n.name,
68
+ type: n.type,
69
+ description: n.description,
70
+ cubeName: l.name,
71
+ fieldType: "measure"
72
+ });
73
+ for (const n of l.dimensions) {
74
+ const d = n.type === "time";
75
+ s.push({
76
+ name: n.name,
77
+ title: n.title || n.shortTitle || n.name,
78
+ shortTitle: n.shortTitle || n.title || n.name,
79
+ type: n.type,
80
+ description: n.description,
81
+ cubeName: l.name,
82
+ fieldType: d ? "timeDimension" : "dimension"
83
+ });
84
+ }
85
+ }
86
+ return s;
87
+ }
88
+ function vt(e, r, s) {
89
+ let l = e;
90
+ if (s && s !== "all" && (l = l.filter((n) => n.cubeName === s)), r.trim()) {
91
+ const n = r.toLowerCase();
92
+ l = l.filter(
93
+ (d) => d.name.toLowerCase().includes(n) || d.title.toLowerCase().includes(n) || (d.description?.toLowerCase().includes(n) ?? !1)
94
+ );
95
+ }
96
+ return l;
97
+ }
98
+ function yt(e) {
99
+ const r = /* @__PURE__ */ new Map();
100
+ for (const s of e) {
101
+ const l = r.get(s.cubeName) || [];
102
+ l.push(s), r.set(s.cubeName, l);
103
+ }
104
+ return r;
105
+ }
106
+ const Pe = "drizzle-cube-recent-fields", Nt = 10;
107
+ function Ge() {
108
+ try {
109
+ const e = localStorage.getItem(Pe);
110
+ if (e)
111
+ return JSON.parse(e);
112
+ } catch {
113
+ }
114
+ return { metrics: [], breakdowns: [] };
115
+ }
116
+ function wt(e, r) {
117
+ try {
118
+ const s = Ge(), n = s[r].filter((d) => d !== e);
119
+ n.unshift(e), s[r] = n.slice(0, Nt), localStorage.setItem(Pe, JSON.stringify(s));
120
+ } catch {
121
+ }
122
+ }
123
+ function kt(e, r, s) {
124
+ if (!e || s.length === 0) return [];
125
+ const l = qe(e, r), n = [];
126
+ for (const d of s) {
127
+ const y = l.find((k) => k.name === d);
128
+ y && n.push(y);
129
+ }
130
+ return n;
131
+ }
132
+ function Dt(e) {
133
+ return e ? e.cubes.map((r) => r.name) : [];
134
+ }
135
+ function ve(e, r) {
136
+ return r && r.cubes.find((l) => l.name === e)?.title || e;
137
+ }
138
+ const Ct = I("check");
139
+ function Tt({
140
+ field: e,
141
+ isSelected: r,
142
+ isFocused: s,
143
+ onClick: l,
144
+ onMouseEnter: n,
145
+ ...d
146
+ }) {
147
+ const y = () => {
148
+ if (e.fieldType === "measure") {
149
+ const f = xe(e.type);
150
+ return f ? /* @__PURE__ */ t(f, { className: "w-4 h-4" }) : null;
151
+ } else if (e.fieldType === "timeDimension") {
152
+ const f = ke("time");
153
+ return f ? /* @__PURE__ */ t(f, { className: "w-4 h-4" }) : null;
154
+ } else {
155
+ const f = ke("dimension");
156
+ return f ? /* @__PURE__ */ t(f, { className: "w-4 h-4" }) : null;
157
+ }
158
+ }, k = () => e.fieldType === "measure" ? "bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300" : e.fieldType === "timeDimension" ? "bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300" : "bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300", o = () => e.fieldType === "measure" ? e.type.charAt(0).toUpperCase() + e.type.slice(1) : e.fieldType === "timeDimension" ? "Time" : "Dim";
159
+ return /* @__PURE__ */ a(
160
+ "button",
161
+ {
162
+ onClick: l,
163
+ onMouseEnter: n,
164
+ className: `w-full text-left px-3 py-2 rounded-lg flex items-center gap-3 transition-colors group ${s ? "bg-dc-primary/10 ring-1 ring-dc-primary" : r ? "bg-dc-success/10" : "hover:bg-dc-surface-hover"}`,
165
+ ...d,
166
+ children: [
167
+ /* @__PURE__ */ t(
168
+ "span",
169
+ {
170
+ className: `shrink-0 w-8 h-8 flex items-center justify-center rounded-md ${e.fieldType === "measure" ? "bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400" : e.fieldType === "timeDimension" ? "bg-purple-100 dark:bg-purple-900/30 text-purple-600 dark:text-purple-400" : "bg-green-100 dark:bg-green-900/30 text-green-600 dark:text-green-400"}`,
171
+ children: y()
172
+ }
173
+ ),
174
+ /* @__PURE__ */ a("div", { className: "flex-1 min-w-0", children: [
175
+ /* @__PURE__ */ t("div", { className: "text-sm font-medium text-dc-text truncate", children: e.title }),
176
+ /* @__PURE__ */ t("div", { className: "text-xs text-dc-text-muted truncate", children: e.name })
177
+ ] }),
178
+ /* @__PURE__ */ t(
179
+ "span",
180
+ {
181
+ className: `shrink-0 px-2 py-0.5 rounded text-xs font-medium ${k()}`,
182
+ children: o()
183
+ }
184
+ ),
185
+ r && /* @__PURE__ */ t("span", { className: "shrink-0 w-5 h-5 flex items-center justify-center rounded-full bg-dc-success text-white", children: /* @__PURE__ */ t(Ct, { className: "w-3 h-3" }) })
186
+ ]
187
+ }
188
+ );
189
+ }
190
+ const Me = je(Tt);
191
+ function St({ field: e }) {
192
+ if (!e)
193
+ return /* @__PURE__ */ t("div", { className: "p-6 text-center text-dc-text-muted", children: /* @__PURE__ */ t("p", { className: "text-sm", children: "Hover over a field to see details" }) });
194
+ const r = () => {
195
+ if (e.fieldType === "measure") {
196
+ const n = xe(e.type);
197
+ return n ? /* @__PURE__ */ t(n, { className: "w-6 h-6" }) : null;
198
+ } else if (e.fieldType === "timeDimension") {
199
+ const n = ke("time");
200
+ return n ? /* @__PURE__ */ t(n, { className: "w-6 h-6" }) : null;
201
+ } else {
202
+ const n = ke("dimension");
203
+ return n ? /* @__PURE__ */ t(n, { className: "w-6 h-6" }) : null;
204
+ }
205
+ }, s = () => e.fieldType === "measure" ? "bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400" : e.fieldType === "timeDimension" ? "bg-purple-100 dark:bg-purple-900/30 text-purple-600 dark:text-purple-400" : "bg-green-100 dark:bg-green-900/30 text-green-600 dark:text-green-400", l = () => e.fieldType === "measure" ? {
206
+ count: "Count",
207
+ countDistinct: "Count Distinct",
208
+ countDistinctApprox: "Count Distinct (Approx)",
209
+ sum: "Sum",
210
+ avg: "Average",
211
+ min: "Minimum",
212
+ max: "Maximum",
213
+ runningTotal: "Running Total",
214
+ number: "Number"
215
+ }[e.type] || e.type : e.fieldType === "timeDimension" ? "Time Dimension" : {
216
+ string: "Text",
217
+ number: "Number",
218
+ boolean: "Boolean",
219
+ geo: "Geographic"
220
+ }[e.type] || "Dimension";
221
+ return /* @__PURE__ */ a("div", { className: "p-4", children: [
222
+ /* @__PURE__ */ a("div", { className: "flex items-start gap-3 mb-4", children: [
223
+ /* @__PURE__ */ t(
224
+ "span",
225
+ {
226
+ className: `shrink-0 w-12 h-12 flex items-center justify-center rounded-lg ${s()}`,
227
+ children: r()
228
+ }
229
+ ),
230
+ /* @__PURE__ */ a("div", { className: "flex-1 min-w-0", children: [
231
+ /* @__PURE__ */ t("h3", { className: "text-base font-semibold text-dc-text leading-tight", children: e.title }),
232
+ /* @__PURE__ */ t("p", { className: "text-xs text-dc-text-muted mt-0.5 truncate", children: e.name })
233
+ ] })
234
+ ] }),
235
+ e.description && /* @__PURE__ */ t("div", { className: "mb-4", children: /* @__PURE__ */ t("p", { className: "text-sm text-dc-text-secondary leading-relaxed", children: e.description }) }),
236
+ /* @__PURE__ */ a("div", { className: "space-y-3 pt-4 border-t border-dc-border", children: [
237
+ /* @__PURE__ */ a("div", { className: "flex items-center justify-between", children: [
238
+ /* @__PURE__ */ t("span", { className: "text-xs text-dc-text-muted", children: "Type" }),
239
+ /* @__PURE__ */ t("span", { className: "text-sm text-dc-text font-medium", children: l() })
240
+ ] }),
241
+ /* @__PURE__ */ a("div", { className: "flex items-center justify-between", children: [
242
+ /* @__PURE__ */ t("span", { className: "text-xs text-dc-text-muted", children: "Cube" }),
243
+ /* @__PURE__ */ t("span", { className: "text-sm text-dc-text font-medium", children: e.cubeName })
244
+ ] }),
245
+ /* @__PURE__ */ a("div", { className: "flex items-center justify-between", children: [
246
+ /* @__PURE__ */ t("span", { className: "text-xs text-dc-text-muted", children: "Category" }),
247
+ /* @__PURE__ */ t(
248
+ "span",
249
+ {
250
+ className: `text-xs px-2 py-0.5 rounded font-medium ${e.fieldType === "measure" ? "bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300" : e.fieldType === "timeDimension" ? "bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300" : "bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300"}`,
251
+ children: e.fieldType === "measure" ? "Measure" : e.fieldType === "timeDimension" ? "Time Dimension" : "Dimension"
252
+ }
253
+ )
254
+ ] })
255
+ ] }),
256
+ /* @__PURE__ */ t("div", { className: "mt-6 p-3 bg-dc-surface rounded-lg", children: /* @__PURE__ */ a("p", { className: "text-xs text-dc-text-muted", children: [
257
+ "Press ",
258
+ /* @__PURE__ */ t("kbd", { className: "px-1 py-0.5 bg-dc-surface-tertiary rounded text-xs", children: "Enter" }),
259
+ " or click to add this field to your query."
260
+ ] }) })
261
+ ] });
262
+ }
263
+ const At = je(St), Ft = I("search"), It = I("close");
264
+ function Qe({
265
+ isOpen: e,
266
+ onClose: r,
267
+ onSelect: s,
268
+ mode: l,
269
+ schema: n,
270
+ selectedFields: d,
271
+ recentFields: y
272
+ }) {
273
+ const [k, o] = B(""), [f, m] = B(null), [g, h] = B(null), [N, v] = B(-1), [S, D] = B(null), O = ce(null), A = ce(null), M = H(() => {
274
+ if (y) return y;
275
+ const i = Ge();
276
+ return l === "metrics" ? i.metrics : i.breakdowns;
277
+ }, [y, l]), F = l, C = H(() => qe(n, F), [n, F]), q = H(() => Dt(n), [n]), Y = H(() => vt(C, k, f), [C, k, f]), Q = H(() => yt(Y), [Y]), P = H(() => k.trim() ? [] : kt(n, F, M).filter(
278
+ (i) => !f || i.cubeName === f
279
+ ), [n, F, M, k, f]), z = H(() => {
280
+ const i = [...P];
281
+ return Q.forEach((p) => {
282
+ i.push(...p);
283
+ }), i;
284
+ }, [P, Q]);
285
+ Z(() => {
286
+ e && O.current && O.current.focus();
287
+ }, [e]), Z(() => {
288
+ e || (o(""), m(null), h(null), v(-1), D(null));
289
+ }, [e]);
290
+ const J = E(
291
+ (i, p = !1) => {
292
+ wt(i.name, l === "metrics" ? "metrics" : "breakdowns");
293
+ const $ = {
294
+ name: i.name,
295
+ title: i.title,
296
+ shortTitle: i.shortTitle,
297
+ type: i.type,
298
+ description: i.description
299
+ };
300
+ s($, i.fieldType, i.cubeName, p);
301
+ },
302
+ [l, s]
303
+ ), K = E(
304
+ (i, p, $ = !1) => {
305
+ if ($ && S !== null && S !== p) {
306
+ const L = Math.min(S, p), W = Math.max(S, p);
307
+ for (let X = L; X <= W; X++) {
308
+ const U = z[X];
309
+ U && !d.includes(U.name) && J(U, !0);
310
+ }
311
+ } else $ ? J(i, !0) : J(i, !1);
312
+ D(p);
313
+ },
314
+ [z, S, J, d]
315
+ ), c = E(
316
+ (i) => {
317
+ if (z.length !== 0)
318
+ switch (i.key) {
319
+ case "ArrowDown":
320
+ i.preventDefault(), v((p) => {
321
+ const $ = Math.min(p + 1, z.length - 1);
322
+ return h(z[$]), $;
323
+ });
324
+ break;
325
+ case "ArrowUp":
326
+ i.preventDefault(), v((p) => {
327
+ const $ = Math.max(p - 1, 0);
328
+ return h(z[$]), $;
329
+ });
330
+ break;
331
+ case "Enter":
332
+ i.preventDefault(), N >= 0 && z[N] && K(z[N], N, i.shiftKey);
333
+ break;
334
+ case "Escape":
335
+ i.preventDefault(), r();
336
+ break;
337
+ }
338
+ },
339
+ [z, N, K, r]
340
+ );
341
+ if (Z(() => {
342
+ if (N >= 0 && A.current) {
343
+ const i = A.current.querySelector(
344
+ `[data-field-index="${N}"]`
345
+ );
346
+ i && i.scrollIntoView({ block: "nearest", behavior: "smooth" });
347
+ }
348
+ }, [N]), !e) return null;
349
+ const x = l === "metrics" ? "Search metrics..." : l === "filter" ? "Search fields to filter..." : "Search dimensions...", u = l === "metrics" ? "Select a Metric" : l === "filter" ? "Select a Field to Filter" : "Select a Dimension", b = N >= 0 && z[N] ? `field-option-${z[N].name.replace(/\./g, "-")}` : void 0;
350
+ return /* @__PURE__ */ t(
351
+ "div",
352
+ {
353
+ className: "fixed inset-0 z-50 flex items-center justify-center bg-black/50",
354
+ onClick: r,
355
+ role: "presentation",
356
+ children: /* @__PURE__ */ a(
357
+ "div",
358
+ {
359
+ role: "dialog",
360
+ "aria-modal": "true",
361
+ "aria-label": u,
362
+ className: "bg-dc-surface shadow-xl w-full h-full md:rounded-lg md:w-auto md:max-w-5xl md:h-[80vh] md:max-h-[700px] flex flex-col overflow-hidden",
363
+ onClick: (i) => i.stopPropagation(),
364
+ onKeyDown: c,
365
+ children: [
366
+ /* @__PURE__ */ a("div", { className: "shrink-0 border-b border-dc-border", children: [
367
+ /* @__PURE__ */ a("div", { className: "flex items-center px-4 py-3 gap-3", children: [
368
+ /* @__PURE__ */ t(Ft, { className: "w-5 h-5 text-dc-text-muted", "aria-hidden": !0 }),
369
+ /* @__PURE__ */ t(
370
+ "input",
371
+ {
372
+ ref: O,
373
+ type: "text",
374
+ value: k,
375
+ onChange: (i) => {
376
+ o(i.target.value), v(-1);
377
+ },
378
+ placeholder: x,
379
+ className: "flex-1 bg-transparent border-none outline-none text-dc-text placeholder-dc-text-muted text-lg",
380
+ "aria-label": x,
381
+ "aria-controls": "field-search-results",
382
+ "aria-activedescendant": b,
383
+ role: "combobox",
384
+ "aria-expanded": "true",
385
+ "aria-autocomplete": "list"
386
+ }
387
+ ),
388
+ /* @__PURE__ */ t(
389
+ "button",
390
+ {
391
+ onClick: r,
392
+ className: "p-1 text-dc-text-secondary hover:text-dc-text rounded",
393
+ "aria-label": "Close dialog",
394
+ children: /* @__PURE__ */ t(It, { className: "w-5 h-5", "aria-hidden": !0 })
395
+ }
396
+ )
397
+ ] }),
398
+ q.length > 1 && /* @__PURE__ */ t("div", { className: "md:hidden px-4 pb-3", children: /* @__PURE__ */ a(
399
+ "select",
400
+ {
401
+ value: f || "",
402
+ onChange: (i) => m(i.target.value || null),
403
+ className: "w-full px-3 py-2 bg-dc-surface border border-dc-border rounded-lg text-sm text-dc-text focus:outline-none focus:ring-1 focus:ring-dc-primary",
404
+ "aria-label": "Filter by cube",
405
+ children: [
406
+ /* @__PURE__ */ t("option", { value: "", children: "All Cubes" }),
407
+ q.map((i) => /* @__PURE__ */ t("option", { value: i, children: ve(i, n) }, i))
408
+ ]
409
+ }
410
+ ) })
411
+ ] }),
412
+ /* @__PURE__ */ a("div", { className: "flex-1 flex overflow-hidden", children: [
413
+ /* @__PURE__ */ t(
414
+ "nav",
415
+ {
416
+ className: "hidden md:block w-48 shrink-0 border-r border-dc-border overflow-y-auto bg-dc-surface-secondary",
417
+ "aria-label": "Filter by cube",
418
+ children: /* @__PURE__ */ a("div", { className: "p-2", role: "group", "aria-label": "Cube categories", children: [
419
+ /* @__PURE__ */ t(
420
+ "button",
421
+ {
422
+ onClick: () => m(null),
423
+ className: `w-full text-left px-3 py-2 rounded-md text-sm transition-colors ${f === null ? "bg-dc-primary/10 text-dc-primary font-medium" : "text-dc-text hover:bg-dc-surface-hover"}`,
424
+ "aria-pressed": f === null,
425
+ children: "All"
426
+ }
427
+ ),
428
+ q.map((i) => /* @__PURE__ */ t(
429
+ "button",
430
+ {
431
+ onClick: () => m(i),
432
+ className: `w-full text-left px-3 py-2 rounded-md text-sm transition-colors truncate ${f === i ? "bg-dc-primary/10 text-dc-primary font-medium" : "text-dc-text hover:bg-dc-surface-hover"}`,
433
+ title: ve(i, n),
434
+ "aria-pressed": f === i,
435
+ children: ve(i, n)
436
+ },
437
+ i
438
+ ))
439
+ ] })
440
+ }
441
+ ),
442
+ /* @__PURE__ */ t(
443
+ "div",
444
+ {
445
+ id: "field-search-results",
446
+ ref: A,
447
+ className: "flex-1 overflow-y-auto p-4",
448
+ role: "listbox",
449
+ "aria-label": "Available fields",
450
+ children: Y.length === 0 && P.length === 0 ? /* @__PURE__ */ a("div", { className: "text-center py-12 text-dc-text-muted", children: [
451
+ /* @__PURE__ */ t("p", { className: "text-lg mb-2", children: "No fields found" }),
452
+ /* @__PURE__ */ t("p", { className: "text-sm", children: k ? `No ${l === "metrics" ? "metrics" : "dimensions"} match "${k}"` : `No ${l === "metrics" ? "metrics" : "dimensions"} available` })
453
+ ] }) : /* @__PURE__ */ a("div", { className: "space-y-6", children: [
454
+ P.length > 0 && /* @__PURE__ */ a("div", { children: [
455
+ /* @__PURE__ */ t("h3", { className: "text-xs font-semibold text-dc-text-muted uppercase tracking-wider mb-2", children: "Recents" }),
456
+ /* @__PURE__ */ t("div", { className: "space-y-1", children: P.map((i, p) => /* @__PURE__ */ t(
457
+ Me,
458
+ {
459
+ field: i,
460
+ isSelected: d.includes(i.name),
461
+ isFocused: N === p,
462
+ onClick: ($) => K(i, p, $.shiftKey),
463
+ onMouseEnter: () => {
464
+ h(i), v(p);
465
+ },
466
+ "data-field-index": p
467
+ },
468
+ `recent-${i.name}`
469
+ )) })
470
+ ] }),
471
+ Array.from(Q.entries()).map(([i, p]) => /* @__PURE__ */ a("div", { children: [
472
+ /* @__PURE__ */ t("h3", { className: "text-xs font-semibold text-dc-text-muted uppercase tracking-wider mb-2", children: ve(i, n) }),
473
+ /* @__PURE__ */ t("div", { className: "space-y-1", children: p.map(($) => {
474
+ const L = P.length + Array.from(Q.entries()).slice(
475
+ 0,
476
+ Array.from(Q.keys()).indexOf(i)
477
+ ).reduce((W, [, X]) => W + X.length, 0) + p.indexOf($);
478
+ return /* @__PURE__ */ t(
479
+ Me,
480
+ {
481
+ field: $,
482
+ isSelected: d.includes($.name),
483
+ isFocused: N === L,
484
+ onClick: (W) => K($, L, W.shiftKey),
485
+ onMouseEnter: () => {
486
+ h($), v(L);
487
+ },
488
+ "data-field-index": L
489
+ },
490
+ $.name
491
+ );
492
+ }) })
493
+ ] }, i))
494
+ ] })
495
+ }
496
+ ),
497
+ /* @__PURE__ */ t("div", { className: "hidden md:block w-72 shrink-0 border-l border-dc-border bg-dc-surface-secondary overflow-y-auto", children: /* @__PURE__ */ t(At, { field: g }) })
498
+ ] }),
499
+ /* @__PURE__ */ a("div", { className: "shrink-0 border-t border-dc-border px-4 py-3 flex items-center justify-between text-sm text-dc-text-muted", children: [
500
+ /* @__PURE__ */ a("div", { children: [
501
+ /* @__PURE__ */ t("span", { className: "text-dc-text-secondary", children: Y.length }),
502
+ " ",
503
+ l === "metrics" ? "metrics" : l === "filter" ? "fields" : "dimensions",
504
+ " available"
505
+ ] }),
506
+ /* @__PURE__ */ a("div", { className: "hidden md:flex items-center gap-4", children: [
507
+ /* @__PURE__ */ a("span", { children: [
508
+ /* @__PURE__ */ t("kbd", { className: "px-1.5 py-0.5 bg-dc-surface-tertiary rounded text-xs", children: "↑↓" }),
509
+ " Navigate"
510
+ ] }),
511
+ /* @__PURE__ */ a("span", { children: [
512
+ /* @__PURE__ */ t("kbd", { className: "px-1.5 py-0.5 bg-dc-surface-tertiary rounded text-xs", children: "Enter" }),
513
+ " Select"
514
+ ] }),
515
+ /* @__PURE__ */ a("span", { children: [
516
+ /* @__PURE__ */ t("kbd", { className: "px-1.5 py-0.5 bg-dc-surface-tertiary rounded text-xs", children: "Shift" }),
517
+ "+Click Multi-select"
518
+ ] }),
519
+ /* @__PURE__ */ a("span", { children: [
520
+ /* @__PURE__ */ t("kbd", { className: "px-1.5 py-0.5 bg-dc-surface-tertiary rounded text-xs", children: "Esc" }),
521
+ " Close"
522
+ ] })
523
+ ] })
524
+ ] })
525
+ ]
526
+ }
527
+ )
528
+ }
529
+ );
530
+ }
531
+ function Rt(e) {
532
+ return "member" in e && "operator" in e && "values" in e;
533
+ }
534
+ function $t(e) {
535
+ return "type" in e && "filters" in e;
536
+ }
537
+ function Ot(e) {
538
+ const r = (s) => {
539
+ if (Rt(s))
540
+ return s;
541
+ if ($t(s)) {
542
+ const l = s.filters.map(r);
543
+ return s.type === "and" ? { and: l } : { or: l };
544
+ }
545
+ return s;
546
+ };
547
+ return e.map(r);
548
+ }
549
+ function Mt(e) {
550
+ const r = {};
551
+ return e.measures && e.measures.length > 0 && (r.measures = e.measures), e.dimensions && e.dimensions.length > 0 && (r.dimensions = e.dimensions), e.timeDimensions && e.timeDimensions.length > 0 && (r.timeDimensions = e.timeDimensions), e.filters && e.filters.length > 0 && (r.filters = e.filters), e.order && (r.order = e.order), e.limit && (r.limit = e.limit), e.offset && (r.offset = e.offset), e.segments && e.segments.length > 0 && (r.segments = e.segments), r;
552
+ }
553
+ function Et(e) {
554
+ const r = Mt(e);
555
+ return r.filters && r.filters.length > 0 && (r.filters = Ot(r.filters)), r;
556
+ }
557
+ function Lt(e) {
558
+ const r = [];
559
+ for (const [s, l] of Object.entries(Be))
560
+ l.fieldTypes.includes(e) && r.push({
561
+ operator: s,
562
+ label: l.label
563
+ });
564
+ return r;
565
+ }
566
+ function ye(e, r) {
567
+ const s = {
568
+ today: "today",
569
+ yesterday: "yesterday",
570
+ this_week: "this week",
571
+ this_month: "this month",
572
+ this_quarter: "this quarter",
573
+ this_year: "this year",
574
+ last_7_days: "last 7 days",
575
+ last_30_days: "last 30 days",
576
+ last_week: "last week",
577
+ last_month: "last month",
578
+ last_quarter: "last quarter",
579
+ last_year: "last year",
580
+ last_12_months: "last 12 months"
581
+ };
582
+ if (e.startsWith("last_n_") && r !== void 0 && r > 0) {
583
+ const l = e.replace("last_n_", ""), n = l.slice(0, -1);
584
+ return r === 1 ? `last ${n}` : `last ${r} ${l}`;
585
+ }
586
+ return s[e] || e;
587
+ }
588
+ function Ne(e) {
589
+ return e.startsWith("last_n_");
590
+ }
591
+ function Ee(e) {
592
+ return e.replace(/_/g, " ");
593
+ }
594
+ function _t(e) {
595
+ switch (e) {
596
+ case "most_dimensions":
597
+ return "bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300";
598
+ case "most_connected":
599
+ return "bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300";
600
+ case "alphabetical_fallback":
601
+ return "bg-amber-100 dark:bg-amber-900/30 text-amber-700 dark:text-amber-300";
602
+ case "single_cube":
603
+ return "bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300";
604
+ default:
605
+ return "bg-gray-100 dark:bg-gray-900/30 text-gray-700 dark:text-gray-300";
606
+ }
607
+ }
608
+ const Bt = ({ analysis: e }) => {
609
+ const r = I("info"), s = I("chevronRight"), l = I("warning"), n = I("table"), d = I("link"), y = I("success"), k = I("error");
610
+ return /* @__PURE__ */ a("div", { className: "bg-dc-surface-secondary border border-dc-border rounded-lg p-4 space-y-4", children: [
611
+ /* @__PURE__ */ a("div", { className: "border-b border-dc-border pb-3", children: [
612
+ /* @__PURE__ */ a("h4", { className: "text-sm font-semibold text-dc-text mb-2 flex items-center", children: [
613
+ /* @__PURE__ */ t(r, { className: "w-4 h-4 mr-2" }),
614
+ "Query Summary"
615
+ ] }),
616
+ /* @__PURE__ */ a("div", { className: "grid grid-cols-2 md:grid-cols-4 gap-2 text-xs", children: [
617
+ /* @__PURE__ */ a("div", { className: "bg-dc-surface p-2 rounded", children: [
618
+ /* @__PURE__ */ t("span", { className: "text-dc-text-muted", children: "Type:" }),
619
+ /* @__PURE__ */ t("span", { className: "ml-1 font-medium text-dc-text", children: Ee(e.querySummary.queryType) })
620
+ ] }),
621
+ /* @__PURE__ */ a("div", { className: "bg-dc-surface p-2 rounded", children: [
622
+ /* @__PURE__ */ t("span", { className: "text-dc-text-muted", children: "Cubes:" }),
623
+ /* @__PURE__ */ t("span", { className: "ml-1 font-medium text-dc-text", children: e.cubeCount })
624
+ ] }),
625
+ /* @__PURE__ */ a("div", { className: "bg-dc-surface p-2 rounded", children: [
626
+ /* @__PURE__ */ t("span", { className: "text-dc-text-muted", children: "Joins:" }),
627
+ /* @__PURE__ */ t("span", { className: "ml-1 font-medium text-dc-text", children: e.querySummary.joinCount })
628
+ ] }),
629
+ /* @__PURE__ */ a("div", { className: "bg-dc-surface p-2 rounded", children: [
630
+ /* @__PURE__ */ t("span", { className: "text-dc-text-muted", children: "CTEs:" }),
631
+ /* @__PURE__ */ t("span", { className: "ml-1 font-medium text-dc-text", children: e.querySummary.cteCount })
632
+ ] })
633
+ ] })
634
+ ] }),
635
+ /* @__PURE__ */ a("div", { className: "border-b border-dc-border pb-3", children: [
636
+ /* @__PURE__ */ a("h4", { className: "text-sm font-semibold text-dc-text mb-2 flex items-center", children: [
637
+ /* @__PURE__ */ t(n, { className: "w-4 h-4 mr-2" }),
638
+ "Primary Cube (FROM table)"
639
+ ] }),
640
+ /* @__PURE__ */ a("div", { className: "bg-dc-surface p-3 rounded text-sm", children: [
641
+ /* @__PURE__ */ a("div", { className: "flex items-center gap-2 mb-2 flex-wrap", children: [
642
+ /* @__PURE__ */ t("span", { className: "font-mono font-medium text-dc-primary", children: e.primaryCube.selectedCube }),
643
+ /* @__PURE__ */ t("span", { className: `text-xs px-2 py-0.5 rounded ${_t(e.primaryCube.reason)}`, children: Ee(e.primaryCube.reason) })
644
+ ] }),
645
+ /* @__PURE__ */ t("p", { className: "text-dc-text-secondary text-xs", children: e.primaryCube.explanation }),
646
+ e.primaryCube.candidates && e.primaryCube.candidates.length > 1 && /* @__PURE__ */ a("details", { className: "mt-2", children: [
647
+ /* @__PURE__ */ a("summary", { className: "text-xs text-dc-text-muted cursor-pointer hover:text-dc-text", children: [
648
+ "Show candidates (",
649
+ e.primaryCube.candidates.length,
650
+ ")"
651
+ ] }),
652
+ /* @__PURE__ */ t("div", { className: "mt-2 space-y-1 ml-2", children: e.primaryCube.candidates.map((o, f) => /* @__PURE__ */ a("div", { className: "text-xs flex items-center gap-2 flex-wrap", children: [
653
+ /* @__PURE__ */ t("span", { className: `font-mono ${o.cubeName === e.primaryCube.selectedCube ? "font-bold text-dc-primary" : "text-dc-text-muted"}`, children: o.cubeName }),
654
+ /* @__PURE__ */ a("span", { className: "text-dc-text-muted", children: [
655
+ "dims: ",
656
+ o.dimensionCount,
657
+ ", joins: ",
658
+ o.joinCount
659
+ ] }),
660
+ o.canReachAll ? /* @__PURE__ */ a("span", { className: "text-green-600 dark:text-green-400 flex items-center gap-0.5", children: [
661
+ /* @__PURE__ */ t(y, { className: "w-3 h-3" }),
662
+ "reachable"
663
+ ] }) : /* @__PURE__ */ a("span", { className: "text-red-600 dark:text-red-400 flex items-center gap-0.5", children: [
664
+ /* @__PURE__ */ t(k, { className: "w-3 h-3" }),
665
+ "cannot reach all"
666
+ ] })
667
+ ] }, f)) })
668
+ ] })
669
+ ] })
670
+ ] }),
671
+ e.joinPaths.length > 0 && /* @__PURE__ */ a("div", { className: "border-b border-dc-border pb-3", children: [
672
+ /* @__PURE__ */ a("h4", { className: "text-sm font-semibold text-dc-text mb-2 flex items-center", children: [
673
+ /* @__PURE__ */ t(d, { className: "w-4 h-4 mr-2" }),
674
+ "Join Paths"
675
+ ] }),
676
+ /* @__PURE__ */ t("div", { className: "space-y-2", children: e.joinPaths.map((o, f) => /* @__PURE__ */ a("div", { className: "bg-dc-surface p-3 rounded text-sm", children: [
677
+ /* @__PURE__ */ a("div", { className: "flex items-center gap-2 mb-2 flex-wrap", children: [
678
+ /* @__PURE__ */ t("span", { className: "font-mono text-dc-text-secondary", children: e.primaryCube.selectedCube }),
679
+ /* @__PURE__ */ t(s, { className: "w-4 h-4 text-dc-text-muted" }),
680
+ /* @__PURE__ */ t("span", { className: "font-mono font-medium text-dc-text", children: o.targetCube }),
681
+ o.pathFound ? /* @__PURE__ */ a("span", { className: "text-xs px-2 py-0.5 bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300 rounded", children: [
682
+ o.pathLength,
683
+ " step",
684
+ o.pathLength !== 1 ? "s" : ""
685
+ ] }) : /* @__PURE__ */ t("span", { className: "text-xs px-2 py-0.5 bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300 rounded", children: "No path" })
686
+ ] }),
687
+ o.pathFound && o.path && o.path.length > 0 && /* @__PURE__ */ t("div", { className: "space-y-1 ml-2", children: o.path.map((m, g) => /* @__PURE__ */ a("div", { className: "flex items-center gap-1 text-xs flex-wrap", children: [
688
+ /* @__PURE__ */ t("span", { className: "font-mono text-dc-text-secondary", children: m.fromCube }),
689
+ /* @__PURE__ */ t(s, { className: "w-3 h-3 text-dc-text-muted" }),
690
+ /* @__PURE__ */ t("span", { className: "font-mono text-dc-text", children: m.toCube }),
691
+ /* @__PURE__ */ a("span", { className: "text-dc-text-muted", children: [
692
+ "(",
693
+ m.relationship,
694
+ ", ",
695
+ m.joinType,
696
+ " join)"
697
+ ] }),
698
+ m.joinColumns.length > 0 && /* @__PURE__ */ a("span", { className: "text-dc-text-muted", children: [
699
+ "on ",
700
+ m.joinColumns.map((h) => `${h.sourceColumn}=${h.targetColumn}`).join(", ")
701
+ ] })
702
+ ] }, g)) }),
703
+ !o.pathFound && o.error && /* @__PURE__ */ t("p", { className: "text-xs text-red-600 dark:text-red-400 mt-1", children: o.error }),
704
+ o.visitedCubes && o.visitedCubes.length > 0 && !o.pathFound && /* @__PURE__ */ a("details", { className: "mt-1", children: [
705
+ /* @__PURE__ */ a("summary", { className: "text-xs text-dc-text-muted cursor-pointer hover:text-dc-text", children: [
706
+ "Cubes visited during search (",
707
+ o.visitedCubes.length,
708
+ ")"
709
+ ] }),
710
+ /* @__PURE__ */ t("div", { className: "mt-1 text-xs text-dc-text-muted ml-2", children: o.visitedCubes.join(" → ") })
711
+ ] })
712
+ ] }, f)) })
713
+ ] }),
714
+ e.preAggregations.length > 0 && /* @__PURE__ */ a("div", { className: "border-b border-dc-border pb-3", children: [
715
+ /* @__PURE__ */ a("h4", { className: "text-sm font-semibold text-dc-text mb-2 flex items-center", children: [
716
+ /* @__PURE__ */ t(n, { className: "w-4 h-4 mr-2" }),
717
+ "Pre-Aggregation CTEs"
718
+ ] }),
719
+ /* @__PURE__ */ t("div", { className: "space-y-2", children: e.preAggregations.map((o, f) => /* @__PURE__ */ a("div", { className: "bg-dc-surface p-3 rounded text-sm", children: [
720
+ /* @__PURE__ */ a("div", { className: "flex items-center gap-2 mb-1 flex-wrap", children: [
721
+ /* @__PURE__ */ t("span", { className: "font-mono font-medium text-dc-text", children: o.cubeName }),
722
+ /* @__PURE__ */ t("span", { className: "text-xs text-dc-text-muted", children: "as" }),
723
+ /* @__PURE__ */ t("code", { className: "text-xs bg-dc-surface-secondary px-1 rounded font-mono", children: o.cteAlias })
724
+ ] }),
725
+ /* @__PURE__ */ t("p", { className: "text-xs text-dc-text-secondary", children: o.reason }),
726
+ /* @__PURE__ */ a("div", { className: "mt-1 text-xs text-dc-text-muted", children: [
727
+ /* @__PURE__ */ t("span", { className: "font-medium", children: "Measures:" }),
728
+ " ",
729
+ o.measures.join(", ")
730
+ ] }),
731
+ o.joinKeys.length > 0 && /* @__PURE__ */ a("div", { className: "mt-1 text-xs text-dc-text-muted", children: [
732
+ /* @__PURE__ */ t("span", { className: "font-medium", children: "Join keys:" }),
733
+ " ",
734
+ o.joinKeys.map((m) => `${m.sourceColumn}=${m.targetColumn}`).join(", ")
735
+ ] })
736
+ ] }, f)) })
737
+ ] }),
738
+ e.warnings && e.warnings.length > 0 && /* @__PURE__ */ a("div", { children: [
739
+ /* @__PURE__ */ a("h4", { className: "text-sm font-semibold text-amber-600 dark:text-amber-400 mb-2 flex items-center", children: [
740
+ /* @__PURE__ */ t(l, { className: "w-4 h-4 mr-2" }),
741
+ "Warnings"
742
+ ] }),
743
+ /* @__PURE__ */ t("ul", { className: "list-disc list-inside text-xs text-amber-600 dark:text-amber-400 space-y-1", children: e.warnings.map((o, f) => /* @__PURE__ */ t("li", { children: o }, f)) })
744
+ ] }),
745
+ e.cubesInvolved.length > 0 && /* @__PURE__ */ a("div", { className: "text-xs text-dc-text-muted pt-2 border-t border-dc-border", children: [
746
+ /* @__PURE__ */ t("span", { className: "font-medium", children: "Cubes involved:" }),
747
+ " ",
748
+ e.cubesInvolved.join(", ")
749
+ ] })
750
+ ] });
751
+ };
752
+ function ze(e) {
753
+ return e.isTimeDimension;
754
+ }
755
+ function jt(e) {
756
+ return e.find(ze);
757
+ }
758
+ function Vt(e) {
759
+ return e.find((r) => !r.isTimeDimension);
760
+ }
761
+ function Fe(e) {
762
+ return e.filter((r) => !r.isTimeDimension);
763
+ }
764
+ function Je(e) {
765
+ return e.filter(ze);
766
+ }
767
+ function Ie(e, r, s) {
768
+ const l = r.length, n = Fe(s).length, d = Je(s).length, y = s.length;
769
+ switch (e) {
770
+ // Always available charts
771
+ case "table":
772
+ case "markdown":
773
+ return { available: !0 };
774
+ // Measure-only charts (KPI Number, KPI Text)
775
+ case "kpiNumber":
776
+ case "kpiText":
777
+ return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : { available: !0 };
778
+ // Bar chart - needs dimension for categories + measure for values
779
+ case "bar":
780
+ return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : y < 1 ? { available: !1, reason: "Requires at least 1 breakdown for categories" } : { available: !0 };
781
+ // KPI Delta - needs dimension for ordering + measure for values
782
+ case "kpiDelta":
783
+ return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : y < 1 ? { available: !1, reason: "Requires at least 1 breakdown for ordering" } : { available: !0 };
784
+ // Line and area charts - need dimension/time + measure
785
+ case "line":
786
+ case "area":
787
+ return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : y < 1 ? { available: !1, reason: "Requires a breakdown (dimension or time)" } : { available: !0 };
788
+ // Pie chart - needs dimension (not time) + measure
789
+ case "pie":
790
+ return l < 1 ? { available: !1, reason: "Requires 1 measure" } : n < 1 ? { available: !1, reason: "Requires 1 dimension (not time dimension)" } : { available: !0 };
791
+ // Scatter - needs measure + any breakdown
792
+ case "scatter":
793
+ return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : l < 2 && y < 1 ? { available: !1, reason: "Requires 2 measures or 1 measure + 1 breakdown" } : { available: !0 };
794
+ // Bubble - needs 2+ measures and 1+ dimension
795
+ case "bubble":
796
+ return l < 2 ? { available: !1, reason: "Requires at least 2 measures" } : n < 1 ? { available: !1, reason: "Requires at least 1 dimension" } : { available: !0 };
797
+ // Radar - needs dimension + measure
798
+ case "radar":
799
+ return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : n < 1 ? { available: !1, reason: "Requires at least 1 dimension" } : { available: !0 };
800
+ // Radial Bar - needs dimension + measure
801
+ case "radialBar":
802
+ return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : n < 1 ? { available: !1, reason: "Requires at least 1 dimension" } : { available: !0 };
803
+ // Treemap - needs dimension + measure
804
+ case "treemap":
805
+ return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : n < 1 ? { available: !1, reason: "Requires at least 1 dimension" } : { available: !0 };
806
+ // Activity Grid - needs time dimension + measure
807
+ case "activityGrid":
808
+ return l < 1 ? { available: !1, reason: "Requires at least 1 measure" } : d < 1 ? { available: !1, reason: "Requires a time dimension" } : { available: !0 };
809
+ default:
810
+ return { available: !0 };
811
+ }
812
+ }
813
+ function qt(e, r) {
814
+ const s = [
815
+ "activityGrid",
816
+ "area",
817
+ "bar",
818
+ "bubble",
819
+ "kpiDelta",
820
+ "kpiNumber",
821
+ "kpiText",
822
+ "line",
823
+ "markdown",
824
+ "pie",
825
+ "radar",
826
+ "radialBar",
827
+ "scatter",
828
+ "table",
829
+ "treemap"
830
+ ], l = {};
831
+ for (const n of s)
832
+ l[n] = Ie(n, e, r);
833
+ return l;
834
+ }
835
+ function He(e, r, s) {
836
+ if (Ie(s, e, r).available || e.length === 0 && r.length === 0)
837
+ return s;
838
+ const n = Je(r).length > 0, d = Fe(r).length > 0, y = e.length > 0;
839
+ return n && y ? "line" : d && y ? "bar" : y && !d && !n ? "kpiNumber" : "table";
840
+ }
841
+ function Se(e, r, s) {
842
+ const l = He(e, r, s), n = Pt(l, e, r);
843
+ return { chartType: l, chartConfig: n };
844
+ }
845
+ function Pt(e, r, s) {
846
+ const l = jt(s), n = Vt(s), d = Fe(s), y = s;
847
+ switch (e) {
848
+ case "line":
849
+ case "area":
850
+ return {
851
+ xAxis: l ? [l.field] : n ? [n.field] : [],
852
+ yAxis: r.map((k) => k.field),
853
+ series: d.length > 1 ? [d[1].field] : n && l ? [n.field] : []
854
+ };
855
+ case "bar":
856
+ return {
857
+ xAxis: n ? [n.field] : l ? [l.field] : [],
858
+ yAxis: r.map((k) => k.field),
859
+ series: d.length > 1 ? [d[1].field] : l && n ? [l.field] : []
860
+ };
861
+ case "pie":
862
+ return {
863
+ xAxis: n ? [n.field] : [],
864
+ yAxis: r.length > 0 ? [r[0].field] : []
865
+ };
866
+ case "scatter":
867
+ return r.length >= 2 ? {
868
+ xAxis: [r[0].field],
869
+ yAxis: [r[1].field],
870
+ series: n ? [n.field] : []
871
+ } : {
872
+ xAxis: y.length > 0 ? [y[0].field] : [],
873
+ yAxis: r.length > 0 ? [r[0].field] : [],
874
+ series: d.length > 1 ? [d[1].field] : []
875
+ };
876
+ case "bubble":
877
+ return {
878
+ xAxis: r.length > 0 ? [r[0].field] : [],
879
+ yAxis: r.length > 1 ? [r[1].field] : [],
880
+ sizeField: r.length > 2 ? r[2].field : r.length > 1 ? r[1].field : void 0,
881
+ series: n ? [n.field] : []
882
+ };
883
+ case "radar":
884
+ case "radialBar":
885
+ case "treemap":
886
+ return {
887
+ xAxis: n ? [n.field] : [],
888
+ yAxis: r.length > 0 ? [r[0].field] : []
889
+ };
890
+ case "activityGrid":
891
+ return {
892
+ dateField: l ? [l.field] : [],
893
+ valueField: r.length > 0 ? [r[0].field] : []
894
+ };
895
+ case "kpiNumber":
896
+ case "kpiDelta":
897
+ case "kpiText":
898
+ return {
899
+ yAxis: r.length > 0 ? [r[0].field] : []
900
+ };
901
+ case "table":
902
+ return {
903
+ xAxis: [
904
+ ...s.map((k) => k.field),
905
+ ...r.map((k) => k.field)
906
+ ]
907
+ };
908
+ case "markdown":
909
+ return {};
910
+ default:
911
+ return {
912
+ xAxis: y.length > 0 ? [y[0].field] : [],
913
+ yAxis: r.map((k) => k.field)
914
+ };
915
+ }
916
+ }
917
+ function Gt(e, r, s, l) {
918
+ if (l && Ie(s, e, r).available)
919
+ return null;
920
+ const n = He(e, r, s);
921
+ return n !== s ? n : null;
922
+ }
923
+ function Qt({
924
+ executionStatus: e,
925
+ executionResults: r,
926
+ executionError: s,
927
+ totalRowCount: l,
928
+ resultsStale: n = !1,
929
+ chartType: d = "line",
930
+ chartConfig: y = {},
931
+ displayConfig: k = {},
932
+ query: o,
933
+ activeView: f = "chart",
934
+ onActiveViewChange: m,
935
+ displayLimit: g = 100,
936
+ onDisplayLimitChange: h,
937
+ hasMetrics: N = !1,
938
+ // Debug props
939
+ debugQuery: v,
940
+ debugSql: S,
941
+ debugAnalysis: D,
942
+ debugLoading: O,
943
+ debugError: A
944
+ }) {
945
+ const [M, F] = B(!1);
946
+ Z(() => {
947
+ !N && f === "chart" && m("table");
948
+ }, [N, f, m]);
949
+ const C = I("success"), q = I("error"), Y = I("warning"), Q = I("table"), P = I("measure"), z = I("timeDimension"), J = I("codeBracket"), K = () => /* @__PURE__ */ t("div", { className: "h-full flex items-center justify-center", children: /* @__PURE__ */ a("div", { className: "text-center", children: [
950
+ /* @__PURE__ */ t(
951
+ "div",
952
+ {
953
+ className: "animate-spin rounded-full h-12 w-12 border-b-2 mx-auto mb-4",
954
+ style: { borderBottomColor: "var(--dc-primary)" }
955
+ }
956
+ ),
957
+ /* @__PURE__ */ t("div", { className: "text-sm font-semibold text-dc-text-secondary mb-1", children: "Executing Query..." }),
958
+ /* @__PURE__ */ t("div", { className: "text-xs text-dc-text-muted", children: "Running your query against the cube API" })
959
+ ] }) }), c = () => /* @__PURE__ */ t("div", { className: "h-full flex items-center justify-center p-4", children: /* @__PURE__ */ a("div", { className: "text-center max-w-md", children: [
960
+ /* @__PURE__ */ t(q, { className: "w-12 h-12 mx-auto text-red-500 mb-4" }),
961
+ /* @__PURE__ */ t("div", { className: "text-sm font-semibold text-dc-text mb-2", children: "Query Execution Failed" }),
962
+ /* @__PURE__ */ t("div", { className: "text-sm text-dc-text-secondary mb-4", children: "There was an error executing your query. Please check the query and try again." }),
963
+ s && /* @__PURE__ */ t("div", { className: "bg-red-50 border border-red-200 rounded-lg p-3 text-left", children: /* @__PURE__ */ t("div", { className: "text-xs font-mono text-red-800 break-words", children: s }) })
964
+ ] }) }), x = !!(o.measures && o.measures.length > 0 || o.dimensions && o.dimensions.length > 0 || o.timeDimensions && o.timeDimensions.length > 0), u = () => /* @__PURE__ */ t("div", { className: "h-full flex items-center justify-center", children: /* @__PURE__ */ a("div", { className: "text-center", children: [
965
+ /* @__PURE__ */ t(
966
+ "div",
967
+ {
968
+ className: "animate-spin rounded-full h-12 w-12 border-b-2 mx-auto mb-4",
969
+ style: { borderBottomColor: "var(--dc-primary)" }
970
+ }
971
+ ),
972
+ /* @__PURE__ */ t("div", { className: "text-sm font-semibold text-dc-text-secondary mb-1", children: "Preparing Query..." }),
973
+ /* @__PURE__ */ t("div", { className: "text-xs text-dc-text-muted", children: "Your query will execute shortly" })
974
+ ] }) }), b = () => /* @__PURE__ */ t("div", { className: "h-full flex items-center justify-center pt-6", children: /* @__PURE__ */ a("div", { className: "text-center mb-16", children: [
975
+ /* @__PURE__ */ t(z, { className: "w-12 h-12 mx-auto text-dc-text-muted mb-3" }),
976
+ /* @__PURE__ */ t("div", { className: "text-sm font-semibold text-dc-text-secondary mb-1", children: "No Results Yet" }),
977
+ /* @__PURE__ */ t("div", { className: "text-xs text-dc-text-muted", children: "Add metrics or breakdowns from the panel on the right to see results" })
978
+ ] }) }), i = () => /* @__PURE__ */ t("div", { className: "h-full flex items-center justify-center", children: /* @__PURE__ */ a("div", { className: "text-center", children: [
979
+ /* @__PURE__ */ t(C, { className: "w-12 h-12 mx-auto text-green-500 mb-3" }),
980
+ /* @__PURE__ */ t("div", { className: "text-sm font-semibold text-dc-text mb-1", children: "Query Successful" }),
981
+ /* @__PURE__ */ t("div", { className: "text-xs text-dc-text-muted", children: "No data returned from the query" })
982
+ ] }) }), p = () => !r || r.length === 0 ? /* @__PURE__ */ t("div", { className: "flex items-center justify-center h-full text-dc-text-muted", children: /* @__PURE__ */ a("div", { className: "text-center", children: [
983
+ /* @__PURE__ */ t(P, { className: "w-12 h-12 mx-auto mb-3 opacity-50" }),
984
+ /* @__PURE__ */ t("div", { className: "text-sm font-semibold mb-1", children: "No data to display" }),
985
+ /* @__PURE__ */ t("div", { className: "text-xs", children: "Run a query to see chart visualization" })
986
+ ] }) }) : dt(d) ? /* @__PURE__ */ t(
987
+ $e,
988
+ {
989
+ chartType: d,
990
+ data: r,
991
+ chartConfig: y,
992
+ displayConfig: k,
993
+ queryObject: o,
994
+ height: "100%",
995
+ fallback: /* @__PURE__ */ t("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ t("div", { className: "animate-pulse bg-dc-surface-secondary rounded w-full h-full" }) })
996
+ }
997
+ ) : /* @__PURE__ */ t("div", { className: "flex items-center justify-center h-full text-dc-text-muted", children: /* @__PURE__ */ a("div", { className: "text-center", children: [
998
+ /* @__PURE__ */ t(Y, { className: "w-12 h-12 mx-auto mb-3 opacity-50" }),
999
+ /* @__PURE__ */ t("div", { className: "text-sm font-semibold mb-1", children: "Unsupported chart type" }),
1000
+ /* @__PURE__ */ t("div", { className: "text-xs", children: d })
1001
+ ] }) }), $ = () => /* @__PURE__ */ a("div", { className: "p-4 space-y-4 overflow-auto h-full", children: [
1002
+ s && /* @__PURE__ */ a("div", { className: "bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded p-3", children: [
1003
+ /* @__PURE__ */ t("h4", { className: "text-sm font-semibold text-red-700 dark:text-red-400 mb-1", children: "Execution Error" }),
1004
+ /* @__PURE__ */ t("p", { className: "text-sm text-red-600 dark:text-red-300", children: s })
1005
+ ] }),
1006
+ /* @__PURE__ */ a("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1007
+ /* @__PURE__ */ a("div", { children: [
1008
+ /* @__PURE__ */ t("h4", { className: "text-sm font-semibold text-dc-text mb-2", children: "JSON Query" }),
1009
+ /* @__PURE__ */ t("pre", { className: "bg-dc-surface-secondary border border-dc-border rounded p-3 text-xs overflow-auto max-h-64 text-dc-text-secondary", children: v ? JSON.stringify(v, null, 2) : "No query" })
1010
+ ] }),
1011
+ /* @__PURE__ */ a("div", { children: [
1012
+ /* @__PURE__ */ t("h4", { className: "text-sm font-semibold text-dc-text mb-2", children: "Generated SQL" }),
1013
+ O ? /* @__PURE__ */ t("div", { className: "bg-dc-surface-secondary border border-dc-border rounded p-3 text-dc-text-muted text-sm", children: "Loading..." }) : A ? /* @__PURE__ */ t("div", { className: "text-red-500 text-sm bg-red-50 dark:bg-red-900/20 p-3 rounded border border-red-200 dark:border-red-800", children: A }) : S ? /* @__PURE__ */ a("pre", { className: "bg-dc-surface-secondary border border-dc-border rounded p-3 text-xs overflow-auto max-h-64 text-dc-text-secondary font-mono whitespace-pre-wrap", children: [
1014
+ S.sql,
1015
+ S.params && S.params.length > 0 && /* @__PURE__ */ a(ut, { children: [
1016
+ `
1017
+
1018
+ -- Parameters:
1019
+ `,
1020
+ JSON.stringify(S.params, null, 2)
1021
+ ] })
1022
+ ] }) : /* @__PURE__ */ t("div", { className: "bg-dc-surface-secondary border border-dc-border rounded p-3 text-dc-text-muted text-sm", children: "Add metrics to generate SQL" })
1023
+ ] })
1024
+ ] }),
1025
+ /* @__PURE__ */ a("div", { children: [
1026
+ /* @__PURE__ */ t("h4", { className: "text-sm font-semibold text-dc-text mb-2", children: "Query Analysis" }),
1027
+ O ? /* @__PURE__ */ t("div", { className: "bg-dc-surface-secondary border border-dc-border rounded p-3 text-dc-text-muted text-sm", children: "Loading..." }) : D ? /* @__PURE__ */ t("div", { className: "bg-dc-surface-secondary border border-dc-border rounded p-3", children: /* @__PURE__ */ t(Bt, { analysis: D }) }) : /* @__PURE__ */ t("div", { className: "bg-dc-surface-secondary border border-dc-border rounded p-3 text-dc-text-muted text-sm", children: A ? "Analysis unavailable due to error" : "Add metrics to see analysis" })
1028
+ ] })
1029
+ ] }), L = () => {
1030
+ if (!r || r.length === 0)
1031
+ return /* @__PURE__ */ t("div", { className: "flex items-center justify-center h-full text-dc-text-muted", children: /* @__PURE__ */ a("div", { className: "text-center", children: [
1032
+ /* @__PURE__ */ t(Q, { className: "w-12 h-12 mx-auto mb-3 opacity-50" }),
1033
+ /* @__PURE__ */ t("div", { className: "text-sm font-semibold mb-1", children: "No data to display" }),
1034
+ /* @__PURE__ */ t("div", { className: "text-xs", children: "Run a query to see table data" })
1035
+ ] }) });
1036
+ const ee = r.slice(0, g);
1037
+ return /* @__PURE__ */ t(
1038
+ $e,
1039
+ {
1040
+ chartType: "table",
1041
+ data: ee,
1042
+ queryObject: o,
1043
+ height: "100%",
1044
+ fallback: /* @__PURE__ */ t("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ t("div", { className: "animate-pulse bg-dc-surface-secondary rounded w-full h-full" }) })
1045
+ }
1046
+ );
1047
+ }, W = () => /* @__PURE__ */ t("div", { className: "absolute inset-0 flex items-center justify-center bg-dc-surface bg-opacity-75 z-10", children: /* @__PURE__ */ a("div", { className: "text-center", children: [
1048
+ /* @__PURE__ */ t(
1049
+ "div",
1050
+ {
1051
+ className: "animate-spin rounded-full h-10 w-10 border-b-2 mx-auto mb-2",
1052
+ style: { borderBottomColor: "var(--dc-primary)" }
1053
+ }
1054
+ ),
1055
+ /* @__PURE__ */ t("div", { className: "text-xs text-dc-text-secondary", children: "Refreshing results..." })
1056
+ ] }) }), X = () => !r || r.length === 0 ? i() : /* @__PURE__ */ a("div", { className: "h-full flex flex-col", children: [
1057
+ /* @__PURE__ */ a("div", { className: "px-4 py-2 border-b border-dc-border bg-dc-surface-secondary flex-shrink-0", children: [
1058
+ /* @__PURE__ */ a("div", { className: "flex items-center justify-between", children: [
1059
+ /* @__PURE__ */ a("div", { className: "flex items-center", children: [
1060
+ e === "refreshing" ? /* @__PURE__ */ t(
1061
+ "div",
1062
+ {
1063
+ className: "w-4 h-4 mr-2 rounded-full border-b-2 animate-spin",
1064
+ style: { borderBottomColor: "var(--dc-primary)" }
1065
+ }
1066
+ ) : /* @__PURE__ */ t(C, { className: "w-4 h-4 text-green-500 mr-2" }),
1067
+ /* @__PURE__ */ a("span", { className: "text-sm text-dc-text-secondary", children: [
1068
+ r.length,
1069
+ " row",
1070
+ r.length !== 1 ? "s" : "",
1071
+ l !== null && l > r.length && /* @__PURE__ */ a("span", { className: "text-dc-text-muted", children: [
1072
+ " of ",
1073
+ l.toLocaleString()
1074
+ ] }),
1075
+ n && /* @__PURE__ */ t("span", { className: "text-dc-warning ml-2", children: "• Results may be outdated" })
1076
+ ] })
1077
+ ] }),
1078
+ /* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
1079
+ f === "table" && !M && h && /* @__PURE__ */ a(
1080
+ "select",
1081
+ {
1082
+ value: g,
1083
+ onChange: (ee) => h(Number(ee.target.value)),
1084
+ className: "text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text focus:outline-none focus:ring-1 focus:ring-dc-primary",
1085
+ children: [
1086
+ /* @__PURE__ */ t("option", { value: 50, children: "50 rows" }),
1087
+ /* @__PURE__ */ t("option", { value: 100, children: "100 rows" }),
1088
+ /* @__PURE__ */ t("option", { value: 250, children: "250 rows" }),
1089
+ /* @__PURE__ */ t("option", { value: 500, children: "500 rows" })
1090
+ ]
1091
+ }
1092
+ ),
1093
+ /* @__PURE__ */ a(
1094
+ "button",
1095
+ {
1096
+ onClick: () => F(!M),
1097
+ className: `p-1.5 rounded transition-colors relative ${M ? "bg-dc-primary text-white" : "text-dc-text-secondary hover:text-dc-text hover:bg-dc-surface-hover"}`,
1098
+ title: M ? "Hide debug info" : "Show debug info",
1099
+ children: [
1100
+ /* @__PURE__ */ t(J, { className: "w-4 h-4" }),
1101
+ (s || A) && !M && /* @__PURE__ */ t("span", { className: "absolute -top-0.5 -right-0.5 w-2 h-2 bg-red-500 rounded-full" })
1102
+ ]
1103
+ }
1104
+ )
1105
+ ] })
1106
+ ] }),
1107
+ l !== null && l > 1e3 && /* @__PURE__ */ a("div", { className: "mt-2 bg-yellow-50 border border-yellow-200 rounded-lg p-2 flex items-start", children: [
1108
+ /* @__PURE__ */ t(Y, { className: "w-4 h-4 text-yellow-600 mr-2 shrink-0 mt-0.5" }),
1109
+ /* @__PURE__ */ a("div", { className: "text-xs text-yellow-800", children: [
1110
+ /* @__PURE__ */ t("span", { className: "font-semibold", children: "Large dataset:" }),
1111
+ " ",
1112
+ l.toLocaleString(),
1113
+ " rows. Consider adding filters to improve performance."
1114
+ ] })
1115
+ ] })
1116
+ ] }),
1117
+ /* @__PURE__ */ t("div", { className: "flex-1 min-h-0 relative overflow-auto", children: M ? $() : f === "chart" ? /* @__PURE__ */ t("div", { className: "p-4 h-full", children: p() }) : /* @__PURE__ */ t("div", { className: "h-full", children: L() }) }),
1118
+ !M && /* @__PURE__ */ t("div", { className: "px-4 py-3 border-t border-dc-border bg-dc-surface flex justify-center flex-shrink-0", children: /* @__PURE__ */ a("div", { className: "flex items-center bg-dc-surface-secondary border border-dc-border rounded-md overflow-hidden", children: [
1119
+ /* @__PURE__ */ a(
1120
+ "button",
1121
+ {
1122
+ onClick: () => N && m("chart"),
1123
+ disabled: !N,
1124
+ className: `flex items-center gap-1.5 px-4 py-1.5 text-sm font-medium transition-colors ${f === "chart" ? "bg-dc-primary text-white" : N ? "text-dc-text-secondary hover:bg-dc-surface-hover" : "text-dc-text-muted cursor-not-allowed opacity-50"}`,
1125
+ title: N ? "Chart view" : "Add metrics to enable chart view",
1126
+ children: [
1127
+ /* @__PURE__ */ t(P, { className: "w-4 h-4" }),
1128
+ "Chart"
1129
+ ]
1130
+ }
1131
+ ),
1132
+ /* @__PURE__ */ a(
1133
+ "button",
1134
+ {
1135
+ onClick: () => m("table"),
1136
+ className: `flex items-center gap-1.5 px-4 py-1.5 text-sm font-medium transition-colors ${f === "table" ? "bg-dc-primary text-white" : "text-dc-text-secondary hover:bg-dc-surface-hover"}`,
1137
+ title: "Table view",
1138
+ children: [
1139
+ /* @__PURE__ */ t(Q, { className: "w-4 h-4" }),
1140
+ "Table"
1141
+ ]
1142
+ }
1143
+ )
1144
+ ] }) })
1145
+ ] }), U = r !== null;
1146
+ return /* @__PURE__ */ a("div", { className: "h-full min-h-[400px] flex flex-col bg-dc-surface rounded-lg border border-dc-border relative", children: [
1147
+ e === "idle" && !x && b(),
1148
+ e === "idle" && x && !U && u(),
1149
+ e === "loading" && !U && K(),
1150
+ e === "error" && !U && c(),
1151
+ (e === "success" || U) && X(),
1152
+ (e === "loading" || e === "refreshing") && U && W()
1153
+ ] });
1154
+ }
1155
+ function zt({
1156
+ metric: e,
1157
+ fieldMeta: r,
1158
+ onRemove: s,
1159
+ sortDirection: l,
1160
+ sortPriority: n,
1161
+ onToggleSort: d
1162
+ }) {
1163
+ const y = I("close"), k = I("chevronUp"), o = I("chevronDown"), f = I("chevronUpDown"), m = r?.type || "count", g = xe(m) || I("measure"), h = r?.shortTitle || r?.title || e.field.split(".").pop() || e.field, N = e.field.split(".")[0], v = () => {
1164
+ switch (l) {
1165
+ case "asc":
1166
+ return k ? /* @__PURE__ */ t(k, { className: "w-4 h-4" }) : "↑";
1167
+ case "desc":
1168
+ return o ? /* @__PURE__ */ t(o, { className: "w-4 h-4" }) : "↓";
1169
+ default:
1170
+ return f ? /* @__PURE__ */ t(f, { className: "w-4 h-4" }) : "⇅";
1171
+ }
1172
+ }, S = () => {
1173
+ switch (l) {
1174
+ case "asc":
1175
+ return "Sorted ascending (click for descending)";
1176
+ case "desc":
1177
+ return "Sorted descending (click to remove)";
1178
+ default:
1179
+ return "Click to sort ascending";
1180
+ }
1181
+ };
1182
+ return /* @__PURE__ */ a("div", { className: "flex items-center gap-2 p-2 bg-dc-surface-secondary rounded-lg group hover:bg-dc-surface-tertiary transition-colors", children: [
1183
+ /* @__PURE__ */ t("span", { className: "w-6 h-6 flex items-center justify-center rounded bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400 flex-shrink-0", children: g && /* @__PURE__ */ t(g, { className: "w-4 h-4" }) }),
1184
+ /* @__PURE__ */ a("div", { className: "flex-1 min-w-0", children: [
1185
+ /* @__PURE__ */ t("div", { className: "text-sm text-dc-text truncate", title: e.field, children: h }),
1186
+ /* @__PURE__ */ t("div", { className: "text-xs text-dc-text-muted truncate", children: N })
1187
+ ] }),
1188
+ d && /* @__PURE__ */ a(
1189
+ "button",
1190
+ {
1191
+ onClick: d,
1192
+ className: `p-1 transition-opacity flex-shrink-0 flex items-center gap-0.5 ${l ? "opacity-100 text-dc-primary" : "opacity-0 group-hover:opacity-100 text-dc-text-muted hover:text-dc-primary"}`,
1193
+ title: S(),
1194
+ children: [
1195
+ v(),
1196
+ l && n && /* @__PURE__ */ a("span", { className: "text-xs font-medium", children: [
1197
+ "(",
1198
+ n,
1199
+ ")"
1200
+ ] })
1201
+ ]
1202
+ }
1203
+ ),
1204
+ /* @__PURE__ */ t(
1205
+ "button",
1206
+ {
1207
+ onClick: s,
1208
+ className: "p-1 text-dc-text-muted hover:text-dc-danger opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",
1209
+ title: "Remove metric",
1210
+ children: /* @__PURE__ */ t(y, { className: "w-4 h-4" })
1211
+ }
1212
+ )
1213
+ ] });
1214
+ }
1215
+ function Jt(e, r) {
1216
+ if (!r?.cubes) return null;
1217
+ const [s] = e.split("."), l = r.cubes.find((n) => n.name === s);
1218
+ return l && l.measures?.find((n) => n.name === e) || null;
1219
+ }
1220
+ function Ht(e) {
1221
+ switch (e) {
1222
+ case null:
1223
+ return "asc";
1224
+ case "asc":
1225
+ return "desc";
1226
+ case "desc":
1227
+ return null;
1228
+ default:
1229
+ return "asc";
1230
+ }
1231
+ }
1232
+ function Kt({
1233
+ metrics: e,
1234
+ schema: r,
1235
+ onAdd: s,
1236
+ onRemove: l,
1237
+ order: n,
1238
+ onOrderChange: d
1239
+ }) {
1240
+ const y = I("add"), k = H(() => n ? Object.keys(n) : [], [n]), o = H(() => e.map((f) => {
1241
+ const m = n?.[f.field] || null, g = m ? k.indexOf(f.field) + 1 : void 0;
1242
+ return {
1243
+ metric: f,
1244
+ fieldMeta: Jt(f.field, r),
1245
+ sortDirection: m,
1246
+ sortPriority: g
1247
+ };
1248
+ }), [e, r, n, k]);
1249
+ return /* @__PURE__ */ a("div", { children: [
1250
+ /* @__PURE__ */ a("div", { className: "flex items-center justify-between mb-3", children: [
1251
+ /* @__PURE__ */ t("h3", { className: "text-sm font-semibold text-dc-text", children: "Metrics" }),
1252
+ /* @__PURE__ */ t(
1253
+ "button",
1254
+ {
1255
+ onClick: s,
1256
+ className: "p-1 text-dc-text-secondary hover:text-dc-primary hover:bg-dc-surface-secondary rounded transition-colors",
1257
+ title: "Add metric",
1258
+ children: /* @__PURE__ */ t(y, { className: "w-5 h-5" })
1259
+ }
1260
+ )
1261
+ ] }),
1262
+ e.length === 0 ? /* @__PURE__ */ t(
1263
+ "button",
1264
+ {
1265
+ onClick: s,
1266
+ className: "w-full p-3 border-2 border-dashed border-dc-border rounded-lg text-dc-text-muted hover:border-dc-primary hover:text-dc-primary transition-colors",
1267
+ children: "+ Add Metric"
1268
+ }
1269
+ ) : /* @__PURE__ */ a("div", { className: "space-y-2", children: [
1270
+ o.map(({ metric: f, fieldMeta: m, sortDirection: g, sortPriority: h }) => /* @__PURE__ */ t(
1271
+ zt,
1272
+ {
1273
+ metric: f,
1274
+ fieldMeta: m,
1275
+ onRemove: () => l(f.id),
1276
+ sortDirection: g,
1277
+ sortPriority: h,
1278
+ onToggleSort: d ? () => {
1279
+ const N = Ht(g);
1280
+ d(f.field, N);
1281
+ } : void 0
1282
+ },
1283
+ f.id
1284
+ )),
1285
+ /* @__PURE__ */ t(
1286
+ "button",
1287
+ {
1288
+ onClick: s,
1289
+ className: "w-full p-2 text-sm text-dc-text-muted hover:text-dc-primary transition-colors",
1290
+ children: "+ Add Metric"
1291
+ }
1292
+ )
1293
+ ] })
1294
+ ] });
1295
+ }
1296
+ const Wt = [
1297
+ { value: "hour", label: "Hour" },
1298
+ { value: "day", label: "Day" },
1299
+ { value: "week", label: "Week" },
1300
+ { value: "month", label: "Month" },
1301
+ { value: "quarter", label: "Quarter" },
1302
+ { value: "year", label: "Year" }
1303
+ ];
1304
+ function Yt({
1305
+ breakdown: e,
1306
+ fieldMeta: r,
1307
+ onRemove: s,
1308
+ onGranularityChange: l,
1309
+ sortDirection: n,
1310
+ sortPriority: d,
1311
+ onToggleSort: y
1312
+ }) {
1313
+ const k = I("dimension"), o = I("timeDimension"), f = I("close"), m = I("chevronUp"), g = I("chevronDown"), h = I("chevronUpDown"), N = r?.shortTitle || r?.title || e.field.split(".").pop() || e.field, v = e.field.split(".")[0], S = e.isTimeDimension ? o : k, D = () => {
1314
+ switch (n) {
1315
+ case "asc":
1316
+ return m ? /* @__PURE__ */ t(m, { className: "w-4 h-4" }) : "↑";
1317
+ case "desc":
1318
+ return g ? /* @__PURE__ */ t(g, { className: "w-4 h-4" }) : "↓";
1319
+ default:
1320
+ return h ? /* @__PURE__ */ t(h, { className: "w-4 h-4" }) : "⇅";
1321
+ }
1322
+ }, O = () => {
1323
+ switch (n) {
1324
+ case "asc":
1325
+ return "Sorted ascending (click for descending)";
1326
+ case "desc":
1327
+ return "Sorted descending (click to remove)";
1328
+ default:
1329
+ return "Click to sort ascending";
1330
+ }
1331
+ };
1332
+ return /* @__PURE__ */ a("div", { className: "flex items-center gap-2 p-2 bg-dc-surface-secondary rounded-lg group hover:bg-dc-surface-tertiary transition-colors", children: [
1333
+ /* @__PURE__ */ t(S, { className: "w-4 h-4 text-dc-text-secondary flex-shrink-0" }),
1334
+ /* @__PURE__ */ a("div", { className: "flex-1 min-w-0", children: [
1335
+ /* @__PURE__ */ t("div", { className: "text-sm text-dc-text truncate", title: e.field, children: N }),
1336
+ /* @__PURE__ */ t("div", { className: "text-xs text-dc-text-muted truncate", children: v })
1337
+ ] }),
1338
+ e.isTimeDimension && l && /* @__PURE__ */ t(
1339
+ "select",
1340
+ {
1341
+ value: e.granularity || "day",
1342
+ onChange: (A) => l(A.target.value),
1343
+ onClick: (A) => A.stopPropagation(),
1344
+ className: "text-xs bg-dc-surface border border-dc-border rounded px-2 py-1 text-dc-text focus:outline-none focus:ring-1 focus:ring-dc-primary flex-shrink-0",
1345
+ children: Wt.map((A) => /* @__PURE__ */ t("option", { value: A.value, children: A.label }, A.value))
1346
+ }
1347
+ ),
1348
+ y && /* @__PURE__ */ a(
1349
+ "button",
1350
+ {
1351
+ onClick: y,
1352
+ className: `p-1 transition-opacity flex-shrink-0 flex items-center gap-0.5 ${n ? "opacity-100 text-dc-primary" : "opacity-0 group-hover:opacity-100 text-dc-text-muted hover:text-dc-primary"}`,
1353
+ title: O(),
1354
+ children: [
1355
+ D(),
1356
+ n && d && /* @__PURE__ */ a("span", { className: "text-xs font-medium", children: [
1357
+ "(",
1358
+ d,
1359
+ ")"
1360
+ ] })
1361
+ ]
1362
+ }
1363
+ ),
1364
+ /* @__PURE__ */ t(
1365
+ "button",
1366
+ {
1367
+ onClick: s,
1368
+ className: "p-1 text-dc-text-muted hover:text-dc-danger opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",
1369
+ title: "Remove breakdown",
1370
+ children: /* @__PURE__ */ t(f, { className: "w-4 h-4" })
1371
+ }
1372
+ )
1373
+ ] });
1374
+ }
1375
+ function Xt(e, r) {
1376
+ if (!r?.cubes) return null;
1377
+ const [s] = e.split("."), l = r.cubes.find((n) => n.name === s);
1378
+ return l && l.dimensions?.find((n) => n.name === e) || null;
1379
+ }
1380
+ function Zt(e) {
1381
+ switch (e) {
1382
+ case null:
1383
+ return "asc";
1384
+ case "asc":
1385
+ return "desc";
1386
+ case "desc":
1387
+ return null;
1388
+ default:
1389
+ return "asc";
1390
+ }
1391
+ }
1392
+ function Ut({
1393
+ breakdowns: e,
1394
+ schema: r,
1395
+ onAdd: s,
1396
+ onRemove: l,
1397
+ onGranularityChange: n,
1398
+ order: d,
1399
+ onOrderChange: y
1400
+ }) {
1401
+ const k = I("add"), o = H(() => d ? Object.keys(d) : [], [d]), f = H(() => e.map((m) => {
1402
+ const g = d?.[m.field] || null, h = g ? o.indexOf(m.field) + 1 : void 0;
1403
+ return {
1404
+ breakdown: m,
1405
+ fieldMeta: Xt(m.field, r),
1406
+ sortDirection: g,
1407
+ sortPriority: h
1408
+ };
1409
+ }), [e, r, d, o]);
1410
+ return /* @__PURE__ */ a("div", { children: [
1411
+ /* @__PURE__ */ a("div", { className: "flex items-center justify-between mb-3", children: [
1412
+ /* @__PURE__ */ t("h3", { className: "text-sm font-semibold text-dc-text", children: "Breakdown" }),
1413
+ /* @__PURE__ */ t(
1414
+ "button",
1415
+ {
1416
+ onClick: s,
1417
+ className: "p-1 text-dc-text-secondary hover:text-dc-primary hover:bg-dc-surface-secondary rounded transition-colors",
1418
+ title: "Add breakdown",
1419
+ children: /* @__PURE__ */ t(k, { className: "w-5 h-5" })
1420
+ }
1421
+ )
1422
+ ] }),
1423
+ e.length === 0 ? /* @__PURE__ */ t(
1424
+ "button",
1425
+ {
1426
+ onClick: s,
1427
+ className: "w-full p-3 border-2 border-dashed border-dc-border rounded-lg text-dc-text-muted hover:border-dc-primary hover:text-dc-primary transition-colors",
1428
+ children: "+ Add Breakdown"
1429
+ }
1430
+ ) : /* @__PURE__ */ a("div", { className: "space-y-2", children: [
1431
+ f.map(({ breakdown: m, fieldMeta: g, sortDirection: h, sortPriority: N }) => /* @__PURE__ */ t(
1432
+ Yt,
1433
+ {
1434
+ breakdown: m,
1435
+ fieldMeta: g,
1436
+ onRemove: () => l(m.id),
1437
+ onGranularityChange: m.isTimeDimension ? (v) => n(m.id, v) : void 0,
1438
+ sortDirection: h,
1439
+ sortPriority: N,
1440
+ onToggleSort: y ? () => {
1441
+ const v = Zt(h);
1442
+ y(m.field, v);
1443
+ } : void 0
1444
+ },
1445
+ m.id
1446
+ )),
1447
+ /* @__PURE__ */ t(
1448
+ "button",
1449
+ {
1450
+ onClick: s,
1451
+ className: "w-full p-2 text-sm text-dc-text-muted hover:text-dc-primary transition-colors",
1452
+ children: "+ Add Breakdown"
1453
+ }
1454
+ )
1455
+ ] })
1456
+ ] });
1457
+ }
1458
+ const Le = I("close"), Ae = I("chevronDown"), er = I("dimension"), tr = I("timeDimension"), rr = I("measure");
1459
+ function Ke({
1460
+ filter: e,
1461
+ schema: r,
1462
+ onRemove: s,
1463
+ onUpdate: l,
1464
+ depth: n = 0
1465
+ }) {
1466
+ const [d, y] = B(!1), [k, o] = B(!1), [f, m] = B(!1), [g, h] = B("this_month"), [N, v] = B(1), [S, D] = B(""), O = ce(null), A = ft(S, 300), M = Ve(e.member, r), F = M?.field.type || "string", C = F === "time", q = M?.fieldType === "measure", Y = M?.fieldType === "dimension", Q = gt(e.member, r), P = Be[e.operator], z = Lt(F), J = C && e.operator === "inDateRange", K = H(() => ["equals", "notEquals", "in", "notIn"].includes(e.operator) && Y && !C, [e.operator, Y, C]), {
1467
+ values: c,
1468
+ loading: x,
1469
+ error: u,
1470
+ searchValues: b
1471
+ } = bt(e.member, K);
1472
+ Z(() => {
1473
+ const w = (T) => {
1474
+ O.current && !O.current.contains(T.target) && (y(!1), o(!1), m(!1));
1475
+ };
1476
+ return document.addEventListener("mousedown", w), () => document.removeEventListener("mousedown", w);
1477
+ }, []), Z(() => {
1478
+ k && K && b && b("", !0);
1479
+ }, [k, K, b]), Z(() => {
1480
+ k && K && b && A !== void 0 && b(A);
1481
+ }, [A, k, K, b]), Z(() => {
1482
+ if (!(!J || !e.dateRange))
1483
+ if (Array.isArray(e.dateRange))
1484
+ h("custom");
1485
+ else {
1486
+ const w = e.dateRange.match(/^last (\d+) (days|weeks|months|quarters|years)$/);
1487
+ if (w) {
1488
+ const [, T, G] = w;
1489
+ h(`last_n_${G}`), v(parseInt(T) || 1);
1490
+ } else {
1491
+ let T = !1;
1492
+ for (const G of Te)
1493
+ if (G.value !== "custom" && !Ne(G.value) && ye(G.value) === e.dateRange) {
1494
+ h(G.value), T = !0;
1495
+ break;
1496
+ }
1497
+ T || h("custom");
1498
+ }
1499
+ }
1500
+ }, [e.dateRange, J]);
1501
+ const i = E((w) => {
1502
+ const T = {
1503
+ member: e.member,
1504
+ operator: w,
1505
+ values: []
1506
+ };
1507
+ l(T), y(!1);
1508
+ }, [e.member, l]), p = E((w) => {
1509
+ const T = e.values || [];
1510
+ P?.supportsMultipleValues ? T.includes(w) || l({ ...e, values: [...T, w] }) : (l({ ...e, values: [w] }), o(!1)), D("");
1511
+ }, [e, P?.supportsMultipleValues, l]), $ = E((w) => {
1512
+ const T = (e.values || []).filter((G) => G !== w);
1513
+ l({ ...e, values: T });
1514
+ }, [e, l]), L = E((w) => {
1515
+ const T = w.target.value;
1516
+ if (P?.valueType === "number") {
1517
+ const G = parseFloat(T);
1518
+ isNaN(G) ? (T === "" || T === "-") && l({ ...e, values: [] }) : l({ ...e, values: [G] });
1519
+ } else
1520
+ l({ ...e, values: T ? [T] : [] });
1521
+ }, [e, P?.valueType, l]), W = E((w) => {
1522
+ const T = parseFloat(w.target.value), G = e.values?.length >= 2 ? e.values : ["", ""], re = [isNaN(T) ? "" : T, G[1]].filter((me) => me !== "");
1523
+ l({ ...e, values: re });
1524
+ }, [e, l]), X = E((w) => {
1525
+ const T = parseFloat(w.target.value), re = [(e.values?.length >= 2 ? e.values : ["", ""])[0], isNaN(T) ? "" : T].filter((me) => me !== "");
1526
+ l({ ...e, values: re });
1527
+ }, [e, l]), U = E((w) => {
1528
+ const T = w.target.value;
1529
+ l({ ...e, values: T ? [T] : [] });
1530
+ }, [e, l]), ee = E((w) => {
1531
+ h(w), m(!1);
1532
+ let T;
1533
+ if (w === "custom") {
1534
+ const G = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
1535
+ T = [G, G];
1536
+ } else Ne(w) ? T = ye(w, N) : T = ye(w);
1537
+ l({ ...e, dateRange: T });
1538
+ }, [e, N, l]), oe = E((w) => {
1539
+ if (v(w), Ne(g)) {
1540
+ const T = ye(g, w);
1541
+ l({ ...e, dateRange: T });
1542
+ }
1543
+ }, [e, g, l]), ne = E((w) => {
1544
+ const T = w.target.value, re = (Array.isArray(e.dateRange) ? e.dateRange : [e.dateRange || "", ""])[1] || T;
1545
+ l({ ...e, dateRange: [T, re] });
1546
+ }, [e, l]), ae = E((w) => {
1547
+ const T = w.target.value, re = (Array.isArray(e.dateRange) ? e.dateRange : ["", e.dateRange || ""])[0] || T;
1548
+ l({ ...e, dateRange: [re, T] });
1549
+ }, [e, l]), te = z.find((w) => w.operator === e.operator)?.label || e.operator, ie = Te.find((w) => w.value === g)?.label || "Select range", ue = C ? tr : q ? rr : er, Ce = C ? "text-blue-500" : q ? "text-amber-500" : "text-green-500", fe = () => P?.requiresValues ? J ? /* @__PURE__ */ a("div", { className: "space-y-1.5", children: [
1550
+ /* @__PURE__ */ a("div", { className: "relative", children: [
1551
+ /* @__PURE__ */ a(
1552
+ "button",
1553
+ {
1554
+ onClick: () => {
1555
+ y(!1), o(!1), m(!f);
1556
+ },
1557
+ className: "w-full flex items-center justify-between text-left text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text hover:bg-dc-surface-hover",
1558
+ children: [
1559
+ /* @__PURE__ */ t("span", { className: "truncate", children: ie }),
1560
+ /* @__PURE__ */ t(Ae, { className: `w-3 h-3 text-dc-text-muted shrink-0 ml-1 transition-transform ${f ? "rotate-180" : ""}` })
1561
+ ]
1562
+ }
1563
+ ),
1564
+ f && /* @__PURE__ */ t("div", { className: "absolute z-30 left-0 right-0 mt-1 bg-dc-surface border border-dc-border rounded shadow-lg max-h-40 overflow-y-auto", children: Te.map((w) => /* @__PURE__ */ t(
1565
+ "button",
1566
+ {
1567
+ onClick: () => ee(w.value),
1568
+ className: `w-full text-left px-2 py-1.5 text-xs hover:bg-dc-surface-hover ${w.value === g ? "bg-dc-primary/10 text-dc-primary" : "text-dc-text"}`,
1569
+ children: w.label
1570
+ },
1571
+ w.value
1572
+ )) })
1573
+ ] }),
1574
+ Ne(g) && /* @__PURE__ */ a("div", { className: "flex items-center gap-1.5", children: [
1575
+ /* @__PURE__ */ t(
1576
+ "input",
1577
+ {
1578
+ type: "number",
1579
+ min: "1",
1580
+ max: "1000",
1581
+ value: N,
1582
+ onChange: (w) => oe(Math.max(1, parseInt(w.target.value) || 1)),
1583
+ className: "flex-1 text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text w-16"
1584
+ }
1585
+ ),
1586
+ /* @__PURE__ */ t("span", { className: "text-xs text-dc-text-muted", children: g.replace("last_n_", "") })
1587
+ ] }),
1588
+ g === "custom" && /* @__PURE__ */ a("div", { className: "flex items-center gap-1.5", children: [
1589
+ /* @__PURE__ */ t(
1590
+ "input",
1591
+ {
1592
+ type: "date",
1593
+ value: Array.isArray(e.dateRange) ? e.dateRange[0] : "",
1594
+ onChange: ne,
1595
+ className: "flex-1 text-xs border border-dc-border rounded px-1.5 py-1 bg-dc-surface text-dc-text"
1596
+ }
1597
+ ),
1598
+ /* @__PURE__ */ t("span", { className: "text-xs text-dc-text-muted", children: "to" }),
1599
+ /* @__PURE__ */ t(
1600
+ "input",
1601
+ {
1602
+ type: "date",
1603
+ value: Array.isArray(e.dateRange) ? e.dateRange[1] : "",
1604
+ onChange: ae,
1605
+ className: "flex-1 text-xs border border-dc-border rounded px-1.5 py-1 bg-dc-surface text-dc-text"
1606
+ }
1607
+ )
1608
+ ] })
1609
+ ] }) : e.operator === "between" || e.operator === "notBetween" ? /* @__PURE__ */ a("div", { className: "flex items-center gap-1.5", children: [
1610
+ /* @__PURE__ */ t(
1611
+ "input",
1612
+ {
1613
+ type: "number",
1614
+ value: e.values?.[0] ?? "",
1615
+ onChange: W,
1616
+ placeholder: "Min",
1617
+ className: "flex-1 text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text"
1618
+ }
1619
+ ),
1620
+ /* @__PURE__ */ t("span", { className: "text-xs text-dc-text-muted", children: "to" }),
1621
+ /* @__PURE__ */ t(
1622
+ "input",
1623
+ {
1624
+ type: "number",
1625
+ value: e.values?.[1] ?? "",
1626
+ onChange: X,
1627
+ placeholder: "Max",
1628
+ className: "flex-1 text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text"
1629
+ }
1630
+ )
1631
+ ] }) : P?.valueType === "date" ? /* @__PURE__ */ t(
1632
+ "input",
1633
+ {
1634
+ type: "date",
1635
+ value: e.values?.[0] || "",
1636
+ onChange: U,
1637
+ className: "w-full text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text"
1638
+ }
1639
+ ) : P?.valueType === "number" ? /* @__PURE__ */ t(
1640
+ "input",
1641
+ {
1642
+ type: "number",
1643
+ value: e.values?.[0] ?? "",
1644
+ onChange: L,
1645
+ placeholder: "Enter number",
1646
+ className: "w-full text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text"
1647
+ }
1648
+ ) : K ? /* @__PURE__ */ a("div", { className: "space-y-1.5", children: [
1649
+ e.values && e.values.length > 0 && /* @__PURE__ */ t("div", { className: "flex flex-wrap gap-1", children: e.values.map((w, T) => /* @__PURE__ */ a(
1650
+ "span",
1651
+ {
1652
+ className: "inline-flex items-center gap-0.5 bg-dc-primary/10 text-dc-primary text-xs px-1.5 py-0.5 rounded",
1653
+ children: [
1654
+ /* @__PURE__ */ t("span", { className: "max-w-[100px] truncate", children: String(w) }),
1655
+ /* @__PURE__ */ t(
1656
+ "button",
1657
+ {
1658
+ onClick: () => $(w),
1659
+ className: "hover:text-red-600",
1660
+ children: /* @__PURE__ */ t(Le, { className: "w-3 h-3" })
1661
+ }
1662
+ )
1663
+ ]
1664
+ },
1665
+ T
1666
+ )) }),
1667
+ /* @__PURE__ */ a("div", { className: "relative", children: [
1668
+ /* @__PURE__ */ a(
1669
+ "button",
1670
+ {
1671
+ onClick: () => {
1672
+ y(!1), m(!1), o(!k);
1673
+ },
1674
+ className: "w-full flex items-center justify-between text-left text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text hover:bg-dc-surface-hover",
1675
+ children: [
1676
+ /* @__PURE__ */ t("span", { className: "text-dc-text-muted truncate", children: x ? "Loading..." : "Select value..." }),
1677
+ /* @__PURE__ */ t(Ae, { className: `w-3 h-3 text-dc-text-muted shrink-0 ml-1 transition-transform ${k ? "rotate-180" : ""}` })
1678
+ ]
1679
+ }
1680
+ ),
1681
+ k && /* @__PURE__ */ a("div", { className: "absolute z-30 left-0 right-0 mt-1 bg-dc-surface border border-dc-border rounded shadow-lg max-h-48 overflow-hidden", children: [
1682
+ /* @__PURE__ */ t("div", { className: "p-1.5 border-b border-dc-border", children: /* @__PURE__ */ t(
1683
+ "input",
1684
+ {
1685
+ type: "text",
1686
+ value: S,
1687
+ onChange: (w) => D(w.target.value),
1688
+ placeholder: "Search...",
1689
+ className: "w-full text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text",
1690
+ autoFocus: !0
1691
+ }
1692
+ ) }),
1693
+ /* @__PURE__ */ t("div", { className: "max-h-36 overflow-y-auto", children: x ? /* @__PURE__ */ t("div", { className: "px-2 py-2 text-xs text-dc-text-muted", children: "Loading..." }) : u ? /* @__PURE__ */ a("div", { className: "px-2 py-2 text-xs text-red-600", children: [
1694
+ "Error: ",
1695
+ u
1696
+ ] }) : c.length === 0 ? /* @__PURE__ */ t("div", { className: "px-2 py-2 text-xs text-dc-text-muted", children: "No values found" }) : c.map((w, T) => {
1697
+ const G = e.values?.includes(w);
1698
+ return /* @__PURE__ */ a(
1699
+ "button",
1700
+ {
1701
+ onClick: () => p(w),
1702
+ className: `w-full text-left px-2 py-1.5 text-xs hover:bg-dc-surface-hover ${G ? "bg-dc-primary/10 text-dc-primary" : "text-dc-text"}`,
1703
+ children: [
1704
+ String(w),
1705
+ G && /* @__PURE__ */ t("span", { className: "float-right", children: "✓" })
1706
+ ]
1707
+ },
1708
+ `${w}-${T}`
1709
+ );
1710
+ }) })
1711
+ ] })
1712
+ ] })
1713
+ ] }) : /* @__PURE__ */ t(
1714
+ "input",
1715
+ {
1716
+ type: "text",
1717
+ value: e.values?.[0] ?? "",
1718
+ onChange: L,
1719
+ placeholder: "Enter value...",
1720
+ className: "w-full text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text placeholder-dc-text-muted"
1721
+ }
1722
+ ) : /* @__PURE__ */ t("div", { className: "text-xs text-dc-text-muted italic py-1", children: "No value required" });
1723
+ return /* @__PURE__ */ a(
1724
+ "div",
1725
+ {
1726
+ ref: O,
1727
+ className: `bg-dc-surface border border-dc-border rounded-lg p-2 ${n > 0 ? "ml-3" : ""}`,
1728
+ children: [
1729
+ /* @__PURE__ */ a("div", { className: "flex items-center justify-between mb-1.5", children: [
1730
+ /* @__PURE__ */ a("div", { className: "flex items-center gap-1.5 min-w-0", children: [
1731
+ /* @__PURE__ */ t(ue, { className: `w-3.5 h-3.5 ${Ce} shrink-0` }),
1732
+ /* @__PURE__ */ t("span", { className: "text-xs font-medium text-dc-text truncate", title: e.member, children: Q })
1733
+ ] }),
1734
+ /* @__PURE__ */ t(
1735
+ "button",
1736
+ {
1737
+ onClick: s,
1738
+ className: "text-dc-text-muted hover:text-red-600 transition-colors shrink-0 p-0.5",
1739
+ title: "Remove filter",
1740
+ children: /* @__PURE__ */ t(Le, { className: "w-3.5 h-3.5" })
1741
+ }
1742
+ )
1743
+ ] }),
1744
+ /* @__PURE__ */ a("div", { className: "relative mb-1.5", children: [
1745
+ /* @__PURE__ */ a(
1746
+ "button",
1747
+ {
1748
+ onClick: () => {
1749
+ o(!1), m(!1), y(!d);
1750
+ },
1751
+ className: "w-full flex items-center justify-between text-left text-xs border border-dc-border rounded px-2 py-1 bg-dc-surface text-dc-text hover:bg-dc-surface-hover",
1752
+ children: [
1753
+ /* @__PURE__ */ t("span", { className: "truncate", children: te }),
1754
+ /* @__PURE__ */ t(Ae, { className: `w-3 h-3 text-dc-text-muted shrink-0 ml-1 transition-transform ${d ? "rotate-180" : ""}` })
1755
+ ]
1756
+ }
1757
+ ),
1758
+ d && /* @__PURE__ */ t("div", { className: "absolute z-30 left-0 right-0 mt-1 bg-dc-surface border border-dc-border rounded shadow-lg max-h-40 overflow-y-auto", children: z.map((w) => /* @__PURE__ */ t(
1759
+ "button",
1760
+ {
1761
+ onClick: () => i(w.operator),
1762
+ className: `w-full text-left px-2 py-1.5 text-xs hover:bg-dc-surface-hover ${w.operator === e.operator ? "bg-dc-primary/10 text-dc-primary" : "text-dc-text"}`,
1763
+ children: w.label
1764
+ },
1765
+ w.operator
1766
+ )) })
1767
+ ] }),
1768
+ fe()
1769
+ ]
1770
+ }
1771
+ );
1772
+ }
1773
+ const sr = I("add"), nr = I("close");
1774
+ function ar(e) {
1775
+ return "member" in e && typeof e.member == "string";
1776
+ }
1777
+ function lr(e) {
1778
+ return "type" in e && (e.type === "and" || e.type === "or");
1779
+ }
1780
+ function We({
1781
+ group: e,
1782
+ schema: r,
1783
+ onUpdate: s,
1784
+ onRemove: l,
1785
+ onAddFilter: n,
1786
+ depth: d = 0,
1787
+ hideRemoveButton: y = !1
1788
+ }) {
1789
+ const [k, o] = B(!1), f = ce(null);
1790
+ Z(() => {
1791
+ const F = (C) => {
1792
+ f.current && !f.current.contains(C.target) && o(!1);
1793
+ };
1794
+ return document.addEventListener("mousedown", F), () => document.removeEventListener("mousedown", F);
1795
+ }, []);
1796
+ const m = E(() => {
1797
+ const F = e.type === "and" ? "or" : "and";
1798
+ s({ ...e, type: F });
1799
+ }, [e, s]), g = E((F, C) => {
1800
+ const q = [...e.filters];
1801
+ q[F] = C, s({ ...e, filters: q });
1802
+ }, [e, s]), h = E((F) => {
1803
+ const C = e.filters.filter((q, Y) => Y !== F);
1804
+ C.length === 0 ? l() : C.length === 1 && d > 0 ? s({ ...e, filters: C }) : s({ ...e, filters: C });
1805
+ }, [e, s, l, d]), N = E((F) => {
1806
+ const C = { type: F, filters: [] };
1807
+ s({ ...e, filters: [...e.filters, C] }), o(!1);
1808
+ }, [e, s]), v = E(() => {
1809
+ n([]), o(!1);
1810
+ }, [n]), S = E((F) => (C = []) => {
1811
+ n([F, ...C]);
1812
+ }, [n]), D = () => d % 2 === 0 ? "border-dc-border" : "border-slate-300 dark:border-slate-600", O = () => e.type === "and" ? "bg-blue-50/50 dark:bg-blue-900/10" : "bg-amber-50/50 dark:bg-amber-900/10", A = e.filters.length, M = A === 1 ? "condition" : "conditions";
1813
+ return /* @__PURE__ */ a("div", { className: `border ${D()} rounded-lg ${O()} ${d > 0 ? "ml-3" : ""}`, children: [
1814
+ /* @__PURE__ */ a("div", { className: "flex items-center justify-between px-2 py-1.5 border-b border-dc-border/50", children: [
1815
+ /* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
1816
+ /* @__PURE__ */ t(
1817
+ "button",
1818
+ {
1819
+ onClick: m,
1820
+ className: `px-2 py-0.5 text-xs font-semibold rounded transition-colors ${e.type === "and" ? "bg-blue-100 text-blue-700 hover:bg-blue-200 dark:bg-blue-800/50 dark:text-blue-300" : "bg-amber-100 text-amber-700 hover:bg-amber-200 dark:bg-amber-800/50 dark:text-amber-300"}`,
1821
+ title: `Click to switch to ${e.type === "and" ? "OR" : "AND"}`,
1822
+ children: e.type.toUpperCase()
1823
+ }
1824
+ ),
1825
+ /* @__PURE__ */ a("span", { className: "text-xs text-dc-text-muted", children: [
1826
+ A,
1827
+ " ",
1828
+ M
1829
+ ] })
1830
+ ] }),
1831
+ /* @__PURE__ */ a("div", { className: "flex items-center gap-1", children: [
1832
+ /* @__PURE__ */ a("div", { className: "relative", ref: f, children: [
1833
+ /* @__PURE__ */ t(
1834
+ "button",
1835
+ {
1836
+ onClick: () => o(!k),
1837
+ className: "p-1 text-dc-text-secondary hover:text-dc-primary hover:bg-dc-surface-hover rounded transition-colors",
1838
+ title: "Add condition",
1839
+ children: /* @__PURE__ */ t(sr, { className: "w-4 h-4" })
1840
+ }
1841
+ ),
1842
+ k && /* @__PURE__ */ a("div", { className: "absolute right-0 mt-1 z-40 bg-dc-surface border border-dc-border rounded shadow-lg py-1 min-w-[120px]", children: [
1843
+ /* @__PURE__ */ t(
1844
+ "button",
1845
+ {
1846
+ onClick: v,
1847
+ className: "w-full text-left px-3 py-1.5 text-xs text-dc-text hover:bg-dc-surface-hover",
1848
+ children: "Add Filter"
1849
+ }
1850
+ ),
1851
+ /* @__PURE__ */ t(
1852
+ "button",
1853
+ {
1854
+ onClick: () => N("and"),
1855
+ className: "w-full text-left px-3 py-1.5 text-xs text-dc-text hover:bg-dc-surface-hover",
1856
+ children: "Add AND Group"
1857
+ }
1858
+ ),
1859
+ /* @__PURE__ */ t(
1860
+ "button",
1861
+ {
1862
+ onClick: () => N("or"),
1863
+ className: "w-full text-left px-3 py-1.5 text-xs text-dc-text hover:bg-dc-surface-hover",
1864
+ children: "Add OR Group"
1865
+ }
1866
+ )
1867
+ ] })
1868
+ ] }),
1869
+ !y && /* @__PURE__ */ t(
1870
+ "button",
1871
+ {
1872
+ onClick: l,
1873
+ className: "p-1 text-dc-text-muted hover:text-red-600 transition-colors",
1874
+ title: "Remove group",
1875
+ children: /* @__PURE__ */ t(nr, { className: "w-4 h-4" })
1876
+ }
1877
+ )
1878
+ ] })
1879
+ ] }),
1880
+ /* @__PURE__ */ t("div", { className: "p-2 space-y-2", children: e.filters.length === 0 ? /* @__PURE__ */ a("div", { className: "text-center py-3", children: [
1881
+ /* @__PURE__ */ t("p", { className: "text-xs text-dc-text-muted mb-1", children: "No conditions in this group" }),
1882
+ /* @__PURE__ */ t(
1883
+ "button",
1884
+ {
1885
+ onClick: () => n([]),
1886
+ className: "text-xs text-dc-primary hover:underline",
1887
+ children: "Add a filter"
1888
+ }
1889
+ )
1890
+ ] }) : e.filters.map((F, C) => ar(F) ? /* @__PURE__ */ t(
1891
+ Ke,
1892
+ {
1893
+ filter: F,
1894
+ schema: r,
1895
+ onUpdate: (q) => g(C, q),
1896
+ onRemove: () => h(C),
1897
+ depth: d + 1
1898
+ },
1899
+ `filter-${C}`
1900
+ ) : lr(F) ? /* @__PURE__ */ t(
1901
+ We,
1902
+ {
1903
+ group: F,
1904
+ schema: r,
1905
+ onUpdate: (q) => g(C, q),
1906
+ onRemove: () => h(C),
1907
+ onAddFilter: S(C),
1908
+ depth: d + 1
1909
+ },
1910
+ `group-${C}`
1911
+ ) : null) })
1912
+ ] });
1913
+ }
1914
+ const cr = I("add");
1915
+ function De(e) {
1916
+ return "member" in e && typeof e.member == "string";
1917
+ }
1918
+ function de(e) {
1919
+ return "type" in e && (e.type === "and" || e.type === "or");
1920
+ }
1921
+ function Ye(e) {
1922
+ let r = 0;
1923
+ for (const s of e)
1924
+ De(s) ? r++ : de(s) && (r += Ye(s.filters));
1925
+ return r;
1926
+ }
1927
+ function Xe(e) {
1928
+ const r = [];
1929
+ for (const s of e)
1930
+ De(s) ? r.push(s.member) : de(s) && r.push(...Xe(s.filters));
1931
+ return r;
1932
+ }
1933
+ function Ze(e, r, s) {
1934
+ if (r.length === 0)
1935
+ return e.length === 0 ? [s] : e.length === 1 && De(e[0]) ? [{ type: "and", filters: [e[0], s] }] : e.length === 1 && de(e[0]) ? [{
1936
+ ...e[0],
1937
+ filters: [...e[0].filters, s]
1938
+ }] : [{ type: "and", filters: [...e, s] }];
1939
+ const [l, ...n] = r, d = [...e], y = d[l];
1940
+ return de(y) && (n.length === 0 ? d[l] = {
1941
+ ...y,
1942
+ filters: [...y.filters, s]
1943
+ } : d[l] = {
1944
+ ...y,
1945
+ filters: Ze(y.filters, n, s)
1946
+ }), d;
1947
+ }
1948
+ function ir({
1949
+ filters: e,
1950
+ schema: r,
1951
+ onFiltersChange: s
1952
+ }) {
1953
+ const [l, n] = B(!1), d = ce([]), y = Ye(e), k = Xe(e), o = E(
1954
+ (S, D, O) => {
1955
+ const M = S.type === "time" ? "inDateRange" : "equals", F = {
1956
+ member: S.name,
1957
+ operator: M,
1958
+ values: []
1959
+ }, C = Ze(e, d.current, F);
1960
+ s(C), n(!1), d.current = [];
1961
+ },
1962
+ [e, s]
1963
+ ), f = E(
1964
+ (S, D) => {
1965
+ const O = [...e];
1966
+ O[S] = D, s(O);
1967
+ },
1968
+ [e, s]
1969
+ ), m = E(
1970
+ (S) => {
1971
+ const D = e.filter((O, A) => A !== S);
1972
+ if (D.length === 1 && de(D[0])) {
1973
+ const O = D[0];
1974
+ if (O.filters.length === 1) {
1975
+ s([O.filters[0]]);
1976
+ return;
1977
+ }
1978
+ }
1979
+ s(D);
1980
+ },
1981
+ [e, s]
1982
+ ), g = E(() => {
1983
+ s([]);
1984
+ }, [s]), h = E(() => {
1985
+ d.current = [], n(!0);
1986
+ }, []), N = E((S) => (D = []) => {
1987
+ d.current = [...S, ...D], n(!0);
1988
+ }, []), v = (S, D, O = []) => {
1989
+ const A = [...O, D];
1990
+ return De(S) ? /* @__PURE__ */ t(
1991
+ Ke,
1992
+ {
1993
+ filter: S,
1994
+ schema: r,
1995
+ onUpdate: (M) => f(D, M),
1996
+ onRemove: () => m(D)
1997
+ },
1998
+ `filter-${A.join("-")}`
1999
+ ) : de(S) ? /* @__PURE__ */ t(
2000
+ We,
2001
+ {
2002
+ group: S,
2003
+ schema: r,
2004
+ onUpdate: (M) => f(D, M),
2005
+ onRemove: () => m(D),
2006
+ onAddFilter: N(A),
2007
+ hideRemoveButton: e.length === 1
2008
+ },
2009
+ `group-${A.join("-")}`
2010
+ ) : null;
2011
+ };
2012
+ return /* @__PURE__ */ a("div", { children: [
2013
+ /* @__PURE__ */ a("div", { className: "flex items-center justify-between mb-3", children: [
2014
+ /* @__PURE__ */ a("h3", { className: "text-sm font-semibold text-dc-text", children: [
2015
+ "Filter",
2016
+ y > 0 && /* @__PURE__ */ a("span", { className: "ml-1.5 text-xs font-normal text-dc-text-muted", children: [
2017
+ "(",
2018
+ y,
2019
+ ")"
2020
+ ] })
2021
+ ] }),
2022
+ /* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
2023
+ y > 0 && /* @__PURE__ */ t(
2024
+ "button",
2025
+ {
2026
+ onClick: g,
2027
+ className: "text-xs text-dc-text-muted hover:text-red-600 underline",
2028
+ children: "Clear all"
2029
+ }
2030
+ ),
2031
+ /* @__PURE__ */ t(
2032
+ "button",
2033
+ {
2034
+ onClick: h,
2035
+ className: "p-1 text-dc-text-secondary hover:text-dc-primary hover:bg-dc-surface-secondary rounded transition-colors",
2036
+ title: "Add filter",
2037
+ children: /* @__PURE__ */ t(cr, { className: "w-5 h-5" })
2038
+ }
2039
+ )
2040
+ ] })
2041
+ ] }),
2042
+ e.length === 0 ? /* @__PURE__ */ t("p", { className: "text-sm text-dc-text-muted", children: "No filters applied" }) : /* @__PURE__ */ t("div", { className: "space-y-2", children: e.map((S, D) => v(S, D)) }),
2043
+ /* @__PURE__ */ t(
2044
+ Qe,
2045
+ {
2046
+ isOpen: l,
2047
+ onClose: () => {
2048
+ n(!1), d.current = [];
2049
+ },
2050
+ onSelect: o,
2051
+ mode: "filter",
2052
+ schema: r,
2053
+ selectedFields: k
2054
+ }
2055
+ )
2056
+ ] });
2057
+ }
2058
+ const dr = I("close"), or = I("dimension"), ur = I("timeDimension"), mr = I("measure");
2059
+ function hr({
2060
+ config: e,
2061
+ fields: r,
2062
+ onDrop: s,
2063
+ onRemove: l,
2064
+ onDragStart: n,
2065
+ onDragEnd: d,
2066
+ onDragOver: y,
2067
+ onReorder: k,
2068
+ draggedItem: o,
2069
+ getFieldMeta: f
2070
+ }) {
2071
+ const { key: m, label: g, description: h, mandatory: N, maxItems: v, emptyText: S } = e, [D, O] = B(null), [A, M] = B(!1), [F, C] = B(!1), q = () => {
2072
+ let u = r.length;
2073
+ return o && o.fromAxis === m && (u = Math.max(0, r.length - 1)), !v || u < v;
2074
+ }, Y = () => {
2075
+ let u = r.length;
2076
+ return o && o.fromAxis === m && (u = Math.max(0, r.length - 1)), v && u >= v;
2077
+ }, Q = q(), P = Y();
2078
+ Oe.useEffect(() => {
2079
+ const u = () => {
2080
+ O(null), M(!1), C(!1);
2081
+ };
2082
+ return document.addEventListener("dragend", u), () => {
2083
+ document.removeEventListener("dragend", u);
2084
+ };
2085
+ }, []), Oe.useEffect(() => {
2086
+ o ? o.fromAxis !== m ? (C(!1), O(null)) : o.fromAxis === m && o.fromIndex !== void 0 && M(!1) : (O(null), M(!1), C(!1));
2087
+ }, [o, m]);
2088
+ const z = (u, b) => {
2089
+ o && o.fromAxis === m && o.fromIndex !== void 0 && (u.preventDefault(), u.stopPropagation(), O(b), C(!0));
2090
+ }, J = () => {
2091
+ O(null);
2092
+ }, K = (u, b) => {
2093
+ if (u.preventDefault(), u.stopPropagation(), O(null), C(!1), o && o.fromAxis === m && o.fromIndex !== void 0 && k) {
2094
+ k(o.fromIndex, b, m);
2095
+ return;
2096
+ }
2097
+ try {
2098
+ const i = JSON.parse(u.dataTransfer.getData("text/plain"));
2099
+ i.fromAxis === m && k && i.fromIndex !== void 0 && k(i.fromIndex, b, m);
2100
+ } catch {
2101
+ }
2102
+ }, c = (u) => {
2103
+ const b = u.split("."), i = b[0] || u, p = b[1] || u;
2104
+ return {
2105
+ title: p,
2106
+ shortTitle: p,
2107
+ cubeName: i,
2108
+ type: "dimension"
2109
+ // Default assumption
2110
+ };
2111
+ }, x = (u) => {
2112
+ if (u.type === "measure") {
2113
+ const b = xe(u.measureType || "count") || mr;
2114
+ return /* @__PURE__ */ t("span", { className: "w-6 h-6 flex items-center justify-center rounded bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400 flex-shrink-0", children: /* @__PURE__ */ t(b, { className: "w-4 h-4" }) });
2115
+ } else return u.type === "timeDimension" ? /* @__PURE__ */ t(ur, { className: "w-4 h-4 text-dc-text-secondary flex-shrink-0" }) : /* @__PURE__ */ t(or, { className: "w-4 h-4 text-dc-text-secondary flex-shrink-0" });
2116
+ };
2117
+ return /* @__PURE__ */ a("div", { className: "mb-3", children: [
2118
+ /* @__PURE__ */ a("div", { className: "mb-2", children: [
2119
+ /* @__PURE__ */ a("h4", { className: "text-sm font-medium text-dc-text flex items-center", children: [
2120
+ g,
2121
+ N && /* @__PURE__ */ t("span", { className: "text-red-500 ml-1", children: "*" })
2122
+ ] }),
2123
+ h && /* @__PURE__ */ t("div", { className: "text-xs text-dc-text-muted mt-0.5", children: h })
2124
+ ] }),
2125
+ /* @__PURE__ */ t(
2126
+ "div",
2127
+ {
2128
+ "data-axis-container": m,
2129
+ className: `min-h-[48px] border-2 border-dashed rounded-lg p-2 transition-all duration-300 ${A && (Q || v === 1) || F ? "shadow-lg border-solid animate-pulse" : P ? "bg-dc-surface-secondary" : "bg-dc-surface-secondary hover:bg-dc-surface-hover"}`,
2130
+ style: {
2131
+ borderColor: A && (Q || v === 1) || F ? "var(--dc-primary)" : "var(--dc-border)",
2132
+ backgroundColor: A && (Q || v === 1) || F ? "rgba(var(--dc-primary-rgb), 0.1)" : void 0
2133
+ },
2134
+ onDragOver: (u) => {
2135
+ if (o && o.fromAxis === m && o.fromIndex !== void 0)
2136
+ return;
2137
+ Q || v === 1 ? (M(!0), y(u)) : (u.preventDefault(), u.dataTransfer.dropEffect = "none");
2138
+ },
2139
+ onDragLeave: (u) => {
2140
+ const b = u.currentTarget.getBoundingClientRect(), i = u.clientX < b.left || u.clientX > b.right || u.clientY < b.top || u.clientY > b.bottom, p = u.relatedTarget, $ = p && !u.currentTarget.contains(p);
2141
+ (i || $ || u.currentTarget === u.target) && (M(!1), C(!1));
2142
+ },
2143
+ onDrop: (u) => {
2144
+ if (o && o.fromAxis === m && o.fromIndex !== void 0)
2145
+ return;
2146
+ Q || v === 1 ? s(u, m) : u.preventDefault(), M(!1), C(!1);
2147
+ },
2148
+ children: r.length === 0 ? /* @__PURE__ */ t("div", { className: "text-sm text-dc-text-muted text-center py-2", children: P ? "Maximum items reached" : S || "Drop fields here" }) : /* @__PURE__ */ t("div", { className: "space-y-2", children: r.map((u, b) => {
2149
+ const i = f ? f(u) : c(u), p = D === b, $ = o && o.field === u && o.fromAxis === m;
2150
+ return /* @__PURE__ */ a("div", { className: "relative ", children: [
2151
+ p && /* @__PURE__ */ t(
2152
+ "div",
2153
+ {
2154
+ className: "absolute -top-1 left-0 right-0 h-0.5 rounded-full z-10",
2155
+ style: { backgroundColor: "var(--dc-primary)" }
2156
+ }
2157
+ ),
2158
+ /* @__PURE__ */ a(
2159
+ "div",
2160
+ {
2161
+ draggable: !0,
2162
+ onDragStart: (L) => {
2163
+ n(L, u, m, b);
2164
+ },
2165
+ onDragEnd: d,
2166
+ onDragOver: (L) => z(L, b),
2167
+ onDragLeave: J,
2168
+ onDrop: (L) => K(L, b),
2169
+ className: `flex items-center gap-2 p-2 bg-dc-surface rounded-lg group hover:bg-dc-surface-tertiary transition-colors cursor-move ${$ ? "opacity-50 cursor-grabbing" : ""} ${p ? "mt-1" : ""}`,
2170
+ children: [
2171
+ x(i),
2172
+ /* @__PURE__ */ a("div", { className: "flex-1 min-w-0", children: [
2173
+ /* @__PURE__ */ t("div", { className: "text-sm text-dc-text truncate", title: u, children: i.shortTitle || i.title || u.split(".").pop() }),
2174
+ /* @__PURE__ */ t("div", { className: "text-xs text-dc-text-muted truncate", children: i.cubeName })
2175
+ ] }),
2176
+ /* @__PURE__ */ t(
2177
+ "button",
2178
+ {
2179
+ type: "button",
2180
+ onClick: () => l(u, m),
2181
+ className: "p-1 text-dc-text-muted hover:text-dc-danger opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",
2182
+ title: `Remove from ${g}`,
2183
+ children: /* @__PURE__ */ t(dr, { className: "w-4 h-4" })
2184
+ }
2185
+ )
2186
+ ]
2187
+ }
2188
+ )
2189
+ ] }, `${u}-${b}`);
2190
+ }) })
2191
+ }
2192
+ ),
2193
+ N && r.length === 0 && /* @__PURE__ */ t("div", { className: "text-xs text-red-500 mt-1", children: "This field is required" })
2194
+ ] });
2195
+ }
2196
+ const xr = I("measure"), fr = I("dimension"), br = I("timeDimension");
2197
+ function pr({
2198
+ chartType: e,
2199
+ chartConfig: r,
2200
+ displayConfig: s,
2201
+ metrics: l,
2202
+ breakdowns: n,
2203
+ colorPalette: d,
2204
+ schema: y,
2205
+ chartAvailability: k,
2206
+ onChartTypeChange: o,
2207
+ onChartConfigChange: f,
2208
+ onDisplayConfigChange: m
2209
+ }) {
2210
+ const [g, h] = B(null), N = H(
2211
+ () => ({
2212
+ measures: l.map((c) => c.field),
2213
+ dimensions: n.filter((c) => !c.isTimeDimension).map((c) => c.field),
2214
+ timeDimensions: n.filter((c) => c.isTimeDimension).map((c) => c.field)
2215
+ }),
2216
+ [l, n]
2217
+ ), v = H(
2218
+ () => ot(e, ct),
2219
+ [e]
2220
+ ), S = v.skipQuery === !0, D = (c) => {
2221
+ const x = r[c];
2222
+ return Array.isArray(x) ? x : typeof x == "string" ? [x] : [];
2223
+ };
2224
+ Z(() => {
2225
+ const c = [
2226
+ ...N.dimensions,
2227
+ ...N.timeDimensions,
2228
+ ...N.measures
2229
+ ];
2230
+ let x = !1;
2231
+ const u = { ...r };
2232
+ v.dropZones.forEach((b) => {
2233
+ const i = D(b.key), p = i.filter(($) => c.includes($));
2234
+ p.length !== i.length && (x = !0, p.length === 0 ? delete u[b.key] : b.maxItems === 1 ? u[b.key] = p[0] : u[b.key] = p);
2235
+ }), x && f(u);
2236
+ }, [N, r, v.dropZones, f]);
2237
+ const O = (c) => N.measures.includes(c) ? "measure" : N.timeDimensions.includes(c) ? "timeDimension" : "dimension", A = (c) => {
2238
+ if (!y?.cubes) return null;
2239
+ const [x] = c.split("."), u = y.cubes.find((p) => p.name === x);
2240
+ if (!u) return null;
2241
+ const b = u.measures?.find((p) => p.name === c);
2242
+ if (b) return { ...b, fieldType: "measure" };
2243
+ const i = u.dimensions?.find((p) => p.name === c);
2244
+ return i ? { ...i, fieldType: i.type === "time" ? "timeDimension" : "dimension" } : null;
2245
+ }, M = (c) => {
2246
+ const x = O(c), u = c.split("."), b = u[0] || c, i = u[1] || c, p = A(c), $ = n.find((L) => L.field === c);
2247
+ return p ? {
2248
+ title: p.title || i,
2249
+ shortTitle: p.shortTitle || p.title || i,
2250
+ cubeName: b,
2251
+ type: p.fieldType,
2252
+ measureType: p.fieldType === "measure" ? p.type : void 0
2253
+ } : $ ? {
2254
+ title: i,
2255
+ shortTitle: i,
2256
+ cubeName: b,
2257
+ type: $.isTimeDimension ? "timeDimension" : "dimension"
2258
+ } : {
2259
+ title: i,
2260
+ shortTitle: i,
2261
+ cubeName: b,
2262
+ type: x
2263
+ };
2264
+ }, F = (c, x, u, b) => {
2265
+ c.dataTransfer.setData("text/plain", JSON.stringify({ field: x, fromAxis: u, fromIndex: b })), h({ field: x, fromAxis: u, fromIndex: b });
2266
+ }, C = (c) => {
2267
+ c.preventDefault();
2268
+ }, q = () => {
2269
+ h(null);
2270
+ }, Y = (c, x) => {
2271
+ c.preventDefault();
2272
+ const u = JSON.parse(c.dataTransfer.getData("text/plain")), { field: b, fromAxis: i } = u, p = { ...r };
2273
+ if (i !== "available" && i !== x) {
2274
+ const W = p[i];
2275
+ if (Array.isArray(W)) {
2276
+ const X = W.filter((U) => U !== b);
2277
+ X.length === 0 ? delete p[i] : p[i] = X;
2278
+ } else W === b && delete p[i];
2279
+ }
2280
+ const $ = p[x];
2281
+ v.dropZones.find((W) => W.key === x)?.maxItems === 1 ? p[x] = b : Array.isArray($) ? $.includes(b) || (p[x] = [...$, b]) : p[x] = [b], h(null), f(p);
2282
+ }, Q = (c, x) => {
2283
+ const u = { ...r }, b = u[x];
2284
+ if (Array.isArray(b)) {
2285
+ const i = b.filter((p) => p !== c);
2286
+ i.length === 0 ? delete u[x] : u[x] = i;
2287
+ } else b === c && delete u[x];
2288
+ f(u);
2289
+ }, P = (c, x, u) => {
2290
+ const b = { ...r }, i = b[u];
2291
+ if (Array.isArray(i) && i.length > 1 && c !== x) {
2292
+ const p = [...i], [$] = p.splice(c, 1);
2293
+ p.splice(x, 0, $), b[u] = p, h(null), f(b);
2294
+ }
2295
+ }, J = (() => {
2296
+ const c = /* @__PURE__ */ new Set();
2297
+ return v.dropZones.forEach((x) => {
2298
+ D(x.key).forEach((u) => c.add(u));
2299
+ }), g && g.fromAxis !== "available" && c.add(g.field), {
2300
+ dimensions: N.dimensions.filter((x) => !c.has(x)),
2301
+ timeDimensions: N.timeDimensions.filter((x) => !c.has(x)),
2302
+ measures: N.measures.filter((x) => !c.has(x))
2303
+ };
2304
+ })(), K = J.dimensions.length > 0 || J.timeDimensions.length > 0 || J.measures.length > 0;
2305
+ return /* @__PURE__ */ a("div", { className: "space-y-6", children: [
2306
+ /* @__PURE__ */ a("div", { children: [
2307
+ /* @__PURE__ */ t("label", { className: "block text-sm font-medium text-dc-text mb-2", children: "Chart Type" }),
2308
+ /* @__PURE__ */ t(
2309
+ it,
2310
+ {
2311
+ selectedType: e,
2312
+ onTypeChange: o,
2313
+ availability: k,
2314
+ compact: !0
2315
+ }
2316
+ )
2317
+ ] }),
2318
+ !S && K && /* @__PURE__ */ a("div", { children: [
2319
+ /* @__PURE__ */ a("div", { className: "mb-2", children: [
2320
+ /* @__PURE__ */ t("h4", { className: "text-sm font-medium text-dc-text", children: "Unassigned Fields" }),
2321
+ /* @__PURE__ */ t("div", { className: "text-xs text-dc-text-muted mt-0.5", children: "Drag fields to chart axes below" })
2322
+ ] }),
2323
+ /* @__PURE__ */ t("div", { className: "border-2 border-dashed border-dc-border rounded-lg p-2 bg-dc-surface-secondary", children: /* @__PURE__ */ a("div", { className: "space-y-2", children: [
2324
+ J.measures.map((c) => {
2325
+ const x = M(c), u = g && g.field === c && g.fromAxis === "available", b = xe(x.measureType || "count") || xr;
2326
+ return /* @__PURE__ */ a(
2327
+ "div",
2328
+ {
2329
+ draggable: !0,
2330
+ onDragStart: (i) => F(i, c, "available"),
2331
+ onDragEnd: q,
2332
+ className: `flex items-center gap-2 p-2 bg-dc-surface rounded-lg hover:bg-dc-surface-tertiary transition-colors cursor-move ${u ? "opacity-50 cursor-grabbing" : ""}`,
2333
+ title: c,
2334
+ children: [
2335
+ /* @__PURE__ */ t("span", { className: "w-6 h-6 flex items-center justify-center rounded bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400 flex-shrink-0", children: /* @__PURE__ */ t(b, { className: "w-4 h-4" }) }),
2336
+ /* @__PURE__ */ a("div", { className: "flex-1 min-w-0", children: [
2337
+ /* @__PURE__ */ t("div", { className: "text-sm text-dc-text truncate", children: x.shortTitle }),
2338
+ /* @__PURE__ */ t("div", { className: "text-xs text-dc-text-muted truncate", children: x.cubeName })
2339
+ ] })
2340
+ ]
2341
+ },
2342
+ c
2343
+ );
2344
+ }),
2345
+ J.dimensions.map((c) => {
2346
+ const x = M(c), u = g && g.field === c && g.fromAxis === "available";
2347
+ return /* @__PURE__ */ a(
2348
+ "div",
2349
+ {
2350
+ draggable: !0,
2351
+ onDragStart: (b) => F(b, c, "available"),
2352
+ onDragEnd: q,
2353
+ className: `flex items-center gap-2 p-2 bg-dc-surface rounded-lg hover:bg-dc-surface-tertiary transition-colors cursor-move ${u ? "opacity-50 cursor-grabbing" : ""}`,
2354
+ title: c,
2355
+ children: [
2356
+ /* @__PURE__ */ t(fr, { className: "w-4 h-4 text-dc-text-secondary flex-shrink-0" }),
2357
+ /* @__PURE__ */ a("div", { className: "flex-1 min-w-0", children: [
2358
+ /* @__PURE__ */ t("div", { className: "text-sm text-dc-text truncate", children: x.shortTitle }),
2359
+ /* @__PURE__ */ t("div", { className: "text-xs text-dc-text-muted truncate", children: x.cubeName })
2360
+ ] })
2361
+ ]
2362
+ },
2363
+ c
2364
+ );
2365
+ }),
2366
+ J.timeDimensions.map((c) => {
2367
+ const x = M(c), u = g && g.field === c && g.fromAxis === "available";
2368
+ return /* @__PURE__ */ a(
2369
+ "div",
2370
+ {
2371
+ draggable: !0,
2372
+ onDragStart: (b) => F(b, c, "available"),
2373
+ onDragEnd: q,
2374
+ className: `flex items-center gap-2 p-2 bg-dc-surface rounded-lg hover:bg-dc-surface-tertiary transition-colors cursor-move ${u ? "opacity-50 cursor-grabbing" : ""}`,
2375
+ title: c,
2376
+ children: [
2377
+ /* @__PURE__ */ t(br, { className: "w-4 h-4 text-dc-text-secondary flex-shrink-0" }),
2378
+ /* @__PURE__ */ a("div", { className: "flex-1 min-w-0", children: [
2379
+ /* @__PURE__ */ t("div", { className: "text-sm text-dc-text truncate", children: x.shortTitle }),
2380
+ /* @__PURE__ */ t("div", { className: "text-xs text-dc-text-muted truncate", children: x.cubeName })
2381
+ ] })
2382
+ ]
2383
+ },
2384
+ c
2385
+ );
2386
+ })
2387
+ ] }) })
2388
+ ] }),
2389
+ !S && v.dropZones.length > 0 && /* @__PURE__ */ a("div", { children: [
2390
+ /* @__PURE__ */ t("h4", { className: "text-xs font-semibold text-dc-text-secondary mb-2", children: "Chart Configuration" }),
2391
+ /* @__PURE__ */ t("div", { className: "space-y-1", children: v.dropZones.map((c) => /* @__PURE__ */ t(
2392
+ hr,
2393
+ {
2394
+ config: c,
2395
+ fields: D(c.key),
2396
+ onDrop: Y,
2397
+ onRemove: Q,
2398
+ onDragStart: F,
2399
+ onDragEnd: q,
2400
+ onDragOver: C,
2401
+ onReorder: P,
2402
+ draggedItem: g,
2403
+ getFieldMeta: M
2404
+ },
2405
+ c.key
2406
+ )) })
2407
+ ] }),
2408
+ (v.displayOptions && v.displayOptions.length > 0 || v.displayOptionsConfig && v.displayOptionsConfig.length > 0) && /* @__PURE__ */ a("div", { children: [
2409
+ /* @__PURE__ */ t("h4", { className: "text-xs font-semibold text-dc-text-secondary mb-2", children: "Display Options" }),
2410
+ /* @__PURE__ */ a("div", { className: "space-y-2", children: [
2411
+ v.displayOptions?.includes("showLegend") && /* @__PURE__ */ a("label", { className: "flex items-center space-x-2", children: [
2412
+ /* @__PURE__ */ t(
2413
+ "input",
2414
+ {
2415
+ type: "checkbox",
2416
+ checked: s.showLegend ?? !0,
2417
+ onChange: (c) => m({
2418
+ ...s,
2419
+ showLegend: c.target.checked
2420
+ }),
2421
+ className: "rounded border-dc-border focus:ring-blue-500",
2422
+ style: { color: "var(--dc-primary)" }
2423
+ }
2424
+ ),
2425
+ /* @__PURE__ */ t("span", { className: "text-sm text-dc-text", children: "Show Legend" })
2426
+ ] }),
2427
+ v.displayOptions?.includes("showGrid") && /* @__PURE__ */ a("label", { className: "flex items-center space-x-2", children: [
2428
+ /* @__PURE__ */ t(
2429
+ "input",
2430
+ {
2431
+ type: "checkbox",
2432
+ checked: s.showGrid ?? !0,
2433
+ onChange: (c) => m({
2434
+ ...s,
2435
+ showGrid: c.target.checked
2436
+ }),
2437
+ className: "rounded border-dc-border focus:ring-blue-500",
2438
+ style: { color: "var(--dc-primary)" }
2439
+ }
2440
+ ),
2441
+ /* @__PURE__ */ t("span", { className: "text-sm text-dc-text", children: "Show Grid" })
2442
+ ] }),
2443
+ v.displayOptions?.includes("showTooltip") && /* @__PURE__ */ a("label", { className: "flex items-center space-x-2", children: [
2444
+ /* @__PURE__ */ t(
2445
+ "input",
2446
+ {
2447
+ type: "checkbox",
2448
+ checked: s.showTooltip ?? !0,
2449
+ onChange: (c) => m({
2450
+ ...s,
2451
+ showTooltip: c.target.checked
2452
+ }),
2453
+ className: "rounded border-dc-border focus:ring-blue-500",
2454
+ style: { color: "var(--dc-primary)" }
2455
+ }
2456
+ ),
2457
+ /* @__PURE__ */ t("span", { className: "text-sm text-dc-text", children: "Show Tooltip" })
2458
+ ] }),
2459
+ v.displayOptions?.includes("stacked") && /* @__PURE__ */ a("label", { className: "flex items-center space-x-2", children: [
2460
+ /* @__PURE__ */ t(
2461
+ "input",
2462
+ {
2463
+ type: "checkbox",
2464
+ checked: s.stacked ?? !1,
2465
+ onChange: (c) => m({
2466
+ ...s,
2467
+ stacked: c.target.checked
2468
+ }),
2469
+ className: "rounded border-dc-border focus:ring-blue-500",
2470
+ style: { color: "var(--dc-primary)" }
2471
+ }
2472
+ ),
2473
+ /* @__PURE__ */ t("span", { className: "text-sm text-dc-text", children: "Stacked" })
2474
+ ] }),
2475
+ v.displayOptions?.includes("hideHeader") && /* @__PURE__ */ a("label", { className: "flex items-center space-x-2", children: [
2476
+ /* @__PURE__ */ t(
2477
+ "input",
2478
+ {
2479
+ type: "checkbox",
2480
+ checked: s.hideHeader ?? !1,
2481
+ onChange: (c) => m({
2482
+ ...s,
2483
+ hideHeader: c.target.checked
2484
+ }),
2485
+ className: "rounded border-dc-border focus:ring-blue-500",
2486
+ style: { color: "var(--dc-primary)" }
2487
+ }
2488
+ ),
2489
+ /* @__PURE__ */ t("span", { className: "text-sm text-dc-text", children: "Hide Header" })
2490
+ ] }),
2491
+ v.displayOptionsConfig?.map((c) => /* @__PURE__ */ a("div", { className: "space-y-1", children: [
2492
+ c.type === "boolean" && /* @__PURE__ */ a("label", { className: "flex items-center space-x-2", children: [
2493
+ /* @__PURE__ */ t(
2494
+ "input",
2495
+ {
2496
+ type: "checkbox",
2497
+ checked: s[c.key] ?? c.defaultValue ?? !1,
2498
+ onChange: (x) => m({
2499
+ ...s,
2500
+ [c.key]: x.target.checked
2501
+ }),
2502
+ className: "rounded border-dc-border focus:ring-blue-500",
2503
+ style: { color: "var(--dc-primary)" }
2504
+ }
2505
+ ),
2506
+ /* @__PURE__ */ t("span", { className: "text-sm text-dc-text", children: c.label })
2507
+ ] }),
2508
+ c.type === "string" && /* @__PURE__ */ a("div", { className: "space-y-1", children: [
2509
+ /* @__PURE__ */ a("label", { className: "text-sm text-dc-text-secondary", children: [
2510
+ c.label,
2511
+ c.key === "content" && /* @__PURE__ */ t("span", { className: "text-xs text-dc-text-muted ml-1", children: "(only headers, lists and links)" })
2512
+ ] }),
2513
+ c.key === "content" ? /* @__PURE__ */ t(
2514
+ "textarea",
2515
+ {
2516
+ value: s[c.key] ?? c.defaultValue ?? "",
2517
+ onChange: (x) => m({
2518
+ ...s,
2519
+ [c.key]: x.target.value
2520
+ }),
2521
+ placeholder: c.placeholder,
2522
+ rows: 8,
2523
+ className: "w-full px-2 py-1 text-sm border border-dc-border rounded-sm focus:ring-blue-500 focus:border-blue-500 font-mono resize-y bg-dc-surface text-dc-text"
2524
+ }
2525
+ ) : /* @__PURE__ */ t(
2526
+ "input",
2527
+ {
2528
+ type: "text",
2529
+ value: s[c.key] ?? c.defaultValue ?? "",
2530
+ onChange: (x) => m({
2531
+ ...s,
2532
+ [c.key]: x.target.value
2533
+ }),
2534
+ placeholder: c.placeholder,
2535
+ className: "w-full px-2 py-1 text-sm border border-dc-border rounded-sm focus:ring-blue-500 focus:border-blue-500 bg-dc-surface text-dc-text"
2536
+ }
2537
+ ),
2538
+ c.description && /* @__PURE__ */ t("p", { className: "text-xs text-dc-text-muted", children: c.description })
2539
+ ] }),
2540
+ c.type === "paletteColor" && /* @__PURE__ */ a("div", { className: "space-y-1", children: [
2541
+ /* @__PURE__ */ t("label", { className: "text-sm text-dc-text-secondary", children: c.label }),
2542
+ /* @__PURE__ */ t("div", { className: "flex flex-wrap gap-2", children: d?.colors.map((x, u) => {
2543
+ const b = (s[c.key] ?? c.defaultValue ?? 0) === u;
2544
+ return /* @__PURE__ */ t(
2545
+ "button",
2546
+ {
2547
+ type: "button",
2548
+ onClick: () => m({
2549
+ ...s,
2550
+ [c.key]: u
2551
+ }),
2552
+ className: `w-8 h-8 rounded border-2 transition-all duration-200 hover:scale-110 focus:outline-hidden focus:ring-2 focus:ring-blue-500 focus:ring-offset-1 ${b ? "ring-2 ring-offset-1 scale-110" : "hover:border-dc-text-muted"}`,
2553
+ style: {
2554
+ backgroundColor: x,
2555
+ borderColor: b ? "var(--dc-primary)" : "var(--dc-border)"
2556
+ },
2557
+ title: `Color ${u + 1}: ${x}`
2558
+ },
2559
+ u
2560
+ );
2561
+ }) || [
2562
+ // Fallback if no palette available
2563
+ /* @__PURE__ */ t(
2564
+ "button",
2565
+ {
2566
+ type: "button",
2567
+ onClick: () => m({
2568
+ ...s,
2569
+ [c.key]: 0
2570
+ }),
2571
+ className: "w-8 h-8 rounded-sm border-2 ring-2 ring-offset-1",
2572
+ style: {
2573
+ backgroundColor: "#8884d8",
2574
+ borderColor: "var(--dc-primary)",
2575
+ boxShadow: "0 0 0 2px var(--dc-primary)"
2576
+ },
2577
+ title: "Default Color"
2578
+ },
2579
+ 0
2580
+ )
2581
+ ] }),
2582
+ c.description && /* @__PURE__ */ t("p", { className: "text-xs text-dc-text-muted", children: c.description })
2583
+ ] }),
2584
+ c.type === "number" && /* @__PURE__ */ a("div", { className: "space-y-1", children: [
2585
+ /* @__PURE__ */ t("label", { className: "text-sm text-dc-text-secondary", children: c.label }),
2586
+ /* @__PURE__ */ t(
2587
+ "input",
2588
+ {
2589
+ type: "number",
2590
+ value: s[c.key] ?? c.defaultValue ?? 0,
2591
+ onChange: (x) => m({
2592
+ ...s,
2593
+ [c.key]: x.target.value === "" ? void 0 : Number(x.target.value)
2594
+ }),
2595
+ placeholder: c.placeholder,
2596
+ min: c.min,
2597
+ max: c.max,
2598
+ step: c.step,
2599
+ className: "w-full px-2 py-1 text-sm border border-dc-border rounded-sm focus:ring-blue-500 focus:border-blue-500 bg-dc-surface text-dc-text"
2600
+ }
2601
+ ),
2602
+ c.description && /* @__PURE__ */ t("p", { className: "text-xs text-dc-text-muted", children: c.description })
2603
+ ] }),
2604
+ c.type === "select" && /* @__PURE__ */ a("div", { className: "space-y-1", children: [
2605
+ /* @__PURE__ */ t("label", { className: "text-sm text-dc-text-secondary", children: c.label }),
2606
+ /* @__PURE__ */ t(
2607
+ "select",
2608
+ {
2609
+ value: s[c.key] ?? c.defaultValue ?? "",
2610
+ onChange: (x) => m({
2611
+ ...s,
2612
+ [c.key]: x.target.value
2613
+ }),
2614
+ className: "w-full px-2 py-1 text-sm border border-dc-border rounded-sm focus:ring-blue-500 focus:border-blue-500 bg-dc-surface text-dc-text",
2615
+ children: c.options?.map((x) => /* @__PURE__ */ t("option", { value: x.value, children: x.label }, x.value))
2616
+ }
2617
+ ),
2618
+ c.description && /* @__PURE__ */ t("p", { className: "text-xs text-dc-text-muted", children: c.description })
2619
+ ] }),
2620
+ c.type === "color" && /* @__PURE__ */ a("div", { className: "space-y-1", children: [
2621
+ /* @__PURE__ */ t("label", { className: "text-sm text-dc-text-secondary", children: c.label }),
2622
+ /* @__PURE__ */ a("div", { className: "flex items-center space-x-2", children: [
2623
+ /* @__PURE__ */ t(
2624
+ "input",
2625
+ {
2626
+ type: "color",
2627
+ value: s[c.key] ?? c.defaultValue ?? "#8884d8",
2628
+ onChange: (x) => m({
2629
+ ...s,
2630
+ [c.key]: x.target.value
2631
+ }),
2632
+ className: "w-12 h-8 border border-dc-border rounded-sm cursor-pointer"
2633
+ }
2634
+ ),
2635
+ /* @__PURE__ */ t(
2636
+ "input",
2637
+ {
2638
+ type: "text",
2639
+ value: s[c.key] ?? c.defaultValue ?? "#8884d8",
2640
+ onChange: (x) => m({
2641
+ ...s,
2642
+ [c.key]: x.target.value
2643
+ }),
2644
+ placeholder: c.placeholder || "#8884d8",
2645
+ className: "flex-1 px-2 py-1 text-sm border border-dc-border rounded-sm focus:ring-blue-500 focus:border-blue-500 bg-dc-surface text-dc-text"
2646
+ }
2647
+ )
2648
+ ] }),
2649
+ c.description && /* @__PURE__ */ t("p", { className: "text-xs text-dc-text-muted", children: c.description })
2650
+ ] })
2651
+ ] }, c.key))
2652
+ ] })
2653
+ ] }),
2654
+ !S && N.measures.length === 0 && N.dimensions.length === 0 && N.timeDimensions.length === 0 && /* @__PURE__ */ t("div", { className: "text-center text-dc-text-muted text-sm py-4", children: /* @__PURE__ */ t("p", { children: "Add metrics and breakdowns in the Query tab to configure your chart." }) })
2655
+ ] });
2656
+ }
2657
+ function gr({
2658
+ metrics: e,
2659
+ breakdowns: r,
2660
+ filters: s,
2661
+ schema: l,
2662
+ activeTab: n,
2663
+ onActiveTabChange: d,
2664
+ onAddMetric: y,
2665
+ onRemoveMetric: k,
2666
+ onAddBreakdown: o,
2667
+ onRemoveBreakdown: f,
2668
+ onBreakdownGranularityChange: m,
2669
+ onFiltersChange: g,
2670
+ // Sorting
2671
+ order: h,
2672
+ onOrderChange: N,
2673
+ // Chart configuration
2674
+ chartType: v,
2675
+ chartConfig: S,
2676
+ displayConfig: D,
2677
+ chartAvailability: O,
2678
+ onChartTypeChange: A,
2679
+ onChartConfigChange: M,
2680
+ onDisplayConfigChange: F
2681
+ }) {
2682
+ return Z(() => {
2683
+ e.length === 0 && n === "chart" && d("query");
2684
+ }, [e.length, n, d]), /* @__PURE__ */ a("div", { className: "h-full flex flex-col bg-dc-surface", children: [
2685
+ /* @__PURE__ */ a("div", { className: "flex border-b border-dc-border flex-shrink-0", children: [
2686
+ /* @__PURE__ */ t(
2687
+ "button",
2688
+ {
2689
+ onClick: () => d("query"),
2690
+ className: `flex-1 px-4 py-3 text-sm font-medium transition-colors ${n === "query" ? "text-dc-primary border-b-2 border-dc-primary" : "text-dc-text-secondary hover:text-dc-text"}`,
2691
+ children: "Query"
2692
+ }
2693
+ ),
2694
+ /* @__PURE__ */ t(
2695
+ "button",
2696
+ {
2697
+ onClick: () => e.length > 0 && d("chart"),
2698
+ disabled: e.length === 0,
2699
+ className: `flex-1 px-4 py-3 text-sm font-medium transition-colors ${n === "chart" ? "text-dc-primary border-b-2 border-dc-primary" : e.length === 0 ? "text-dc-text-muted cursor-not-allowed opacity-50" : "text-dc-text-secondary hover:text-dc-text"}`,
2700
+ title: e.length === 0 ? "Add metrics to configure chart" : "Chart configuration",
2701
+ children: "Chart"
2702
+ }
2703
+ )
2704
+ ] }),
2705
+ /* @__PURE__ */ t("div", { className: "flex-1 overflow-auto p-4", children: n === "query" ? /* @__PURE__ */ a("div", { className: "space-y-6", children: [
2706
+ /* @__PURE__ */ t(
2707
+ Kt,
2708
+ {
2709
+ metrics: e,
2710
+ schema: l,
2711
+ onAdd: y,
2712
+ onRemove: k,
2713
+ order: h,
2714
+ onOrderChange: N
2715
+ }
2716
+ ),
2717
+ /* @__PURE__ */ t(
2718
+ ir,
2719
+ {
2720
+ filters: s,
2721
+ schema: l,
2722
+ onFiltersChange: g
2723
+ }
2724
+ ),
2725
+ /* @__PURE__ */ t(
2726
+ Ut,
2727
+ {
2728
+ breakdowns: r,
2729
+ schema: l,
2730
+ onAdd: o,
2731
+ onRemove: f,
2732
+ onGranularityChange: m,
2733
+ order: h,
2734
+ onOrderChange: N
2735
+ }
2736
+ )
2737
+ ] }) : n === "chart" ? (
2738
+ /* Chart Tab Content */
2739
+ /* @__PURE__ */ t(
2740
+ pr,
2741
+ {
2742
+ chartType: v,
2743
+ chartConfig: S,
2744
+ displayConfig: D,
2745
+ metrics: e,
2746
+ breakdowns: r,
2747
+ schema: l,
2748
+ chartAvailability: O,
2749
+ onChartTypeChange: A,
2750
+ onChartConfigChange: M,
2751
+ onDisplayConfigChange: F
2752
+ }
2753
+ )
2754
+ ) : null })
2755
+ ] });
2756
+ }
2757
+ const Ue = "drizzle-cube-analysis-builder-state", vr = 500;
2758
+ function he() {
2759
+ return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
2760
+ }
2761
+ function _e(e) {
2762
+ let r = "", s = e;
2763
+ do
2764
+ r = String.fromCharCode(65 + s % 26) + r, s = Math.floor(s / 26) - 1;
2765
+ while (s >= 0);
2766
+ return r;
2767
+ }
2768
+ function yr(e, r, s, l) {
2769
+ const n = {
2770
+ measures: e.map((d) => d.field),
2771
+ dimensions: r.filter((d) => !d.isTimeDimension).map((d) => d.field),
2772
+ timeDimensions: r.filter((d) => d.isTimeDimension).map((d) => ({
2773
+ dimension: d.field,
2774
+ granularity: d.granularity || "day"
2775
+ })),
2776
+ filters: s.length > 0 ? s : void 0,
2777
+ order: l && Object.keys(l).length > 0 ? l : void 0
2778
+ };
2779
+ return n.measures?.length === 0 && delete n.measures, n.dimensions?.length === 0 && delete n.dimensions, n.timeDimensions?.length === 0 && delete n.timeDimensions, n;
2780
+ }
2781
+ function we() {
2782
+ return {
2783
+ metrics: [],
2784
+ breakdowns: [],
2785
+ filters: [],
2786
+ validationStatus: "idle",
2787
+ validationError: null,
2788
+ executionStatus: "idle",
2789
+ executionResults: null,
2790
+ executionError: null,
2791
+ totalRowCount: null,
2792
+ resultsStale: !1
2793
+ };
2794
+ }
2795
+ function Nr(e) {
2796
+ if (e) return null;
2797
+ try {
2798
+ const r = localStorage.getItem(Ue);
2799
+ if (r)
2800
+ return JSON.parse(r);
2801
+ } catch {
2802
+ }
2803
+ return null;
2804
+ }
2805
+ const wr = mt(
2806
+ ({
2807
+ className: e = "",
2808
+ maxHeight: r,
2809
+ initialQuery: s,
2810
+ disableLocalStorage: l = !1,
2811
+ hideSettings: n = !1,
2812
+ onQueryChange: d,
2813
+ onChartConfigChange: y
2814
+ }, k) => {
2815
+ const o = l || !!s, { meta: f, cubeApi: m } = xt(), g = H(
2816
+ () => Nr(l),
2817
+ []
2818
+ // Only run once on mount
2819
+ ), [h, N] = B(() => s ? {
2820
+ ...we(),
2821
+ metrics: (s.measures || []).map((R, V) => ({
2822
+ id: he(),
2823
+ field: R,
2824
+ label: _e(V)
2825
+ })),
2826
+ breakdowns: [
2827
+ ...(s.dimensions || []).map((R) => ({
2828
+ id: he(),
2829
+ field: R,
2830
+ isTimeDimension: !1
2831
+ })),
2832
+ ...(s.timeDimensions || []).map((R) => ({
2833
+ id: he(),
2834
+ field: R.dimension,
2835
+ granularity: R.granularity,
2836
+ isTimeDimension: !0
2837
+ }))
2838
+ ],
2839
+ filters: s.filters || []
2840
+ } : g ? {
2841
+ ...we(),
2842
+ metrics: g.metrics || [],
2843
+ breakdowns: g.breakdowns || [],
2844
+ filters: g.filters || []
2845
+ } : we()), [v, S] = B(() => !s && g?.chartType ? g.chartType : "line"), [D, O] = B(() => !s && g?.chartConfig ? g.chartConfig : {}), [A, M] = B(() => !s && g?.displayConfig ? g.displayConfig : { showLegend: !0, showGrid: !0, showTooltip: !0 }), [F, C] = B(() => {
2846
+ if (s?.order)
2847
+ return s.order;
2848
+ if (!s && g?.order)
2849
+ return g.order;
2850
+ }), [q, Y] = B("query"), [Q, P] = B(() => !s && g?.activeView ? g.activeView : "chart"), [z, J] = B(100), [K, c] = B(!1), [x, u] = B({ sql: null, analysis: null, loading: !1, error: null }), [b, i] = B(!1), [p, $] = B("metrics"), L = H(
2851
+ () => yr(h.metrics, h.breakdowns, h.filters, F),
2852
+ [h.metrics, h.breakdowns, h.filters, F]
2853
+ ), W = H(() => JSON.stringify(L), [L]), [X, U] = B(null), ee = ce(null), oe = ce(""), ne = L.measures && L.measures.length > 0 || L.dimensions && L.dimensions.length > 0 || L.timeDimensions && L.timeDimensions.length > 0;
2854
+ Z(() => {
2855
+ if (W !== oe.current)
2856
+ return ee.current && clearTimeout(ee.current), ne ? ee.current = setTimeout(() => {
2857
+ oe.current = W, U(L);
2858
+ }, vr) : (oe.current = W, U(null)), () => {
2859
+ ee.current && clearTimeout(ee.current);
2860
+ };
2861
+ }, [W, L, ne]);
2862
+ const ae = H(() => X ? Et(X) : null, [X]), { resultSet: te, isLoading: ie, error: ue } = pt(ae, {
2863
+ skip: !ae,
2864
+ resetResultSetOnChange: !0
2865
+ }), Ce = H(() => X ? ie && !te ? "loading" : ie && te ? "refreshing" : ue ? "error" : te ? "success" : "idle" : "idle", [X, ie, ue, te]), fe = H(() => {
2866
+ if (!te) return null;
2867
+ try {
2868
+ return te.rawData();
2869
+ } catch {
2870
+ return null;
2871
+ }
2872
+ }, [te]), w = H(
2873
+ () => qt(h.metrics, h.breakdowns),
2874
+ [h.metrics, h.breakdowns]
2875
+ ), T = E((R) => ["xAxis", "yAxis", "series", "sizeField", "colorField", "dateField", "valueField"].every((_) => {
2876
+ const j = R[_];
2877
+ return j == null ? !0 : Array.isArray(j) ? j.length === 0 : typeof j == "string" ? j === "" : !1;
2878
+ }), []);
2879
+ Z(() => {
2880
+ if (h.metrics.length === 0 && h.breakdowns.length === 0)
2881
+ return;
2882
+ const R = Gt(
2883
+ h.metrics,
2884
+ h.breakdowns,
2885
+ v,
2886
+ K
2887
+ );
2888
+ if (R) {
2889
+ const { chartConfig: V } = Se(
2890
+ h.metrics,
2891
+ h.breakdowns,
2892
+ R
2893
+ );
2894
+ S(R), O(V), c(!1);
2895
+ } else if ((h.metrics.length > 0 || h.breakdowns.length > 0) && T(D)) {
2896
+ const { chartConfig: V } = Se(
2897
+ h.metrics,
2898
+ h.breakdowns,
2899
+ v
2900
+ );
2901
+ O(V);
2902
+ }
2903
+ }, [h.metrics, h.breakdowns, v, K, D, T]), Z(() => {
2904
+ if (!o)
2905
+ try {
2906
+ const R = {
2907
+ metrics: h.metrics,
2908
+ breakdowns: h.breakdowns,
2909
+ filters: h.filters,
2910
+ order: F,
2911
+ chartType: v,
2912
+ chartConfig: D,
2913
+ displayConfig: A,
2914
+ activeView: Q
2915
+ };
2916
+ localStorage.setItem(Ue, JSON.stringify(R));
2917
+ } catch {
2918
+ }
2919
+ }, [
2920
+ h.metrics,
2921
+ h.breakdowns,
2922
+ h.filters,
2923
+ F,
2924
+ v,
2925
+ D,
2926
+ A,
2927
+ Q,
2928
+ o
2929
+ ]), Z(() => {
2930
+ d && ne && d(L);
2931
+ }, [L, ne, d]), Z(() => {
2932
+ y && y({ chartType: v, chartConfig: D, displayConfig: A });
2933
+ }, [v, D, A, y]), Z(() => {
2934
+ if (!ne || !ae) {
2935
+ u({ sql: null, analysis: null, loading: !1, error: null });
2936
+ return;
2937
+ }
2938
+ let R = !1;
2939
+ return (async () => {
2940
+ u((_) => ({ ..._, loading: !0, error: null }));
2941
+ try {
2942
+ const _ = await m.dryRun(ae);
2943
+ R || u({
2944
+ sql: _.sql,
2945
+ analysis: _.analysis,
2946
+ loading: !1,
2947
+ error: null
2948
+ });
2949
+ } catch (_) {
2950
+ R || u({
2951
+ sql: null,
2952
+ analysis: null,
2953
+ loading: !1,
2954
+ error: _ instanceof Error ? _.message : "Failed to fetch debug info"
2955
+ });
2956
+ }
2957
+ })(), () => {
2958
+ R = !0;
2959
+ };
2960
+ }, [ae, m, ne]);
2961
+ const G = E(() => {
2962
+ $("metrics"), i(!0);
2963
+ }, []), re = E((R) => {
2964
+ const V = h.metrics.find((_) => _.id === R)?.field;
2965
+ N((_) => ({
2966
+ ..._,
2967
+ metrics: _.metrics.filter((j) => j.id !== R),
2968
+ resultsStale: !0
2969
+ })), V && C((_) => {
2970
+ if (!_ || !_[V]) return _;
2971
+ const j = { ..._ };
2972
+ return delete j[V], Object.keys(j).length > 0 ? j : void 0;
2973
+ });
2974
+ }, [h.metrics]), me = E(
2975
+ (R, V, _, j) => {
2976
+ if (p === "metrics" && V === "measure")
2977
+ N((se) => {
2978
+ const le = se.metrics.findIndex((pe) => pe.field === R.name);
2979
+ if (le >= 0)
2980
+ return {
2981
+ ...se,
2982
+ metrics: se.metrics.filter((pe, ge) => ge !== le),
2983
+ resultsStale: !0
2984
+ };
2985
+ const be = {
2986
+ id: he(),
2987
+ field: R.name,
2988
+ label: _e(se.metrics.length)
2989
+ };
2990
+ return {
2991
+ ...se,
2992
+ metrics: [...se.metrics, be],
2993
+ resultsStale: !0
2994
+ };
2995
+ });
2996
+ else if (p === "breakdown") {
2997
+ const se = V === "timeDimension";
2998
+ N((le) => {
2999
+ const be = le.breakdowns.findIndex((ge) => ge.field === R.name);
3000
+ if (be >= 0)
3001
+ return {
3002
+ ...le,
3003
+ breakdowns: le.breakdowns.filter((ge, lt) => lt !== be),
3004
+ resultsStale: !0
3005
+ };
3006
+ const pe = {
3007
+ id: he(),
3008
+ field: R.name,
3009
+ isTimeDimension: se,
3010
+ granularity: se ? "month" : void 0
3011
+ };
3012
+ return {
3013
+ ...le,
3014
+ breakdowns: [...le.breakdowns, pe],
3015
+ resultsStale: !0
3016
+ };
3017
+ });
3018
+ }
3019
+ j || i(!1);
3020
+ },
3021
+ [p]
3022
+ ), et = E(() => {
3023
+ $("breakdown"), i(!0);
3024
+ }, []), tt = E((R) => {
3025
+ const V = h.breakdowns.find((_) => _.id === R)?.field;
3026
+ N((_) => ({
3027
+ ..._,
3028
+ breakdowns: _.breakdowns.filter((j) => j.id !== R),
3029
+ resultsStale: !0
3030
+ })), V && C((_) => {
3031
+ if (!_ || !_[V]) return _;
3032
+ const j = { ..._ };
3033
+ return delete j[V], Object.keys(j).length > 0 ? j : void 0;
3034
+ });
3035
+ }, [h.breakdowns]), rt = E(
3036
+ (R, V) => {
3037
+ N((_) => ({
3038
+ ..._,
3039
+ breakdowns: _.breakdowns.map(
3040
+ (j) => j.id === R ? { ...j, granularity: V } : j
3041
+ ),
3042
+ resultsStale: !0
3043
+ }));
3044
+ },
3045
+ []
3046
+ ), st = E((R) => {
3047
+ N((V) => ({
3048
+ ...V,
3049
+ filters: R,
3050
+ resultsStale: !0
3051
+ }));
3052
+ }, []), nt = E(
3053
+ (R, V) => {
3054
+ C((_) => {
3055
+ const j = { ..._ || {} };
3056
+ return V === null ? delete j[R] : j[R] = V, Object.keys(j).length > 0 ? j : void 0;
3057
+ });
3058
+ },
3059
+ []
3060
+ ), Re = E(() => {
3061
+ N(we()), C(void 0), c(!1);
3062
+ }, []), at = E((R) => {
3063
+ S(R), c(!0);
3064
+ const { chartConfig: V } = Se(
3065
+ h.metrics,
3066
+ h.breakdowns,
3067
+ R
3068
+ );
3069
+ O(V);
3070
+ }, [h.metrics, h.breakdowns]);
3071
+ return ht(
3072
+ k,
3073
+ () => ({
3074
+ getCurrentQuery: () => L,
3075
+ getChartConfig: () => ({ chartType: v, chartConfig: D, displayConfig: A }),
3076
+ executeQuery: () => {
3077
+ },
3078
+ clearQuery: Re
3079
+ }),
3080
+ [L, v, D, A, Re]
3081
+ ), /* @__PURE__ */ a(
3082
+ "div",
3083
+ {
3084
+ className: `flex flex-col lg:flex-row bg-dc-surface ${e}`,
3085
+ style: r ? { height: r, maxHeight: r, overflow: "hidden" } : { height: "100%" },
3086
+ children: [
3087
+ /* @__PURE__ */ t("div", { className: "flex-1 min-w-0 border-r border-dc-border p-4 overflow-auto", children: /* @__PURE__ */ t(
3088
+ Qt,
3089
+ {
3090
+ executionStatus: Ce,
3091
+ executionResults: fe,
3092
+ executionError: ue?.message || null,
3093
+ totalRowCount: null,
3094
+ resultsStale: ie && fe !== null,
3095
+ chartType: v,
3096
+ chartConfig: D,
3097
+ displayConfig: A,
3098
+ query: L,
3099
+ schema: f,
3100
+ activeView: Q,
3101
+ onActiveViewChange: P,
3102
+ displayLimit: z,
3103
+ onDisplayLimitChange: J,
3104
+ hasMetrics: h.metrics.length > 0,
3105
+ debugQuery: ae,
3106
+ debugSql: x.sql,
3107
+ debugAnalysis: x.analysis,
3108
+ debugLoading: x.loading,
3109
+ debugError: x.error
3110
+ }
3111
+ ) }),
3112
+ /* @__PURE__ */ t("div", { className: "w-full lg:w-96 flex-shrink-0 h-full overflow-hidden", children: /* @__PURE__ */ t(
3113
+ gr,
3114
+ {
3115
+ metrics: h.metrics,
3116
+ breakdowns: h.breakdowns,
3117
+ filters: h.filters,
3118
+ schema: f,
3119
+ activeTab: q,
3120
+ onActiveTabChange: Y,
3121
+ onAddMetric: G,
3122
+ onRemoveMetric: re,
3123
+ onAddBreakdown: et,
3124
+ onRemoveBreakdown: tt,
3125
+ onBreakdownGranularityChange: rt,
3126
+ onFiltersChange: st,
3127
+ order: F,
3128
+ onOrderChange: nt,
3129
+ chartType: v,
3130
+ chartConfig: D,
3131
+ displayConfig: A,
3132
+ chartAvailability: w,
3133
+ onChartTypeChange: at,
3134
+ onChartConfigChange: O,
3135
+ onDisplayConfigChange: M,
3136
+ validationStatus: h.validationStatus,
3137
+ validationError: h.validationError
3138
+ }
3139
+ ) }),
3140
+ /* @__PURE__ */ t(
3141
+ Qe,
3142
+ {
3143
+ isOpen: b,
3144
+ onClose: () => i(!1),
3145
+ onSelect: me,
3146
+ mode: p,
3147
+ schema: f,
3148
+ selectedFields: [
3149
+ ...h.metrics.map((R) => R.field),
3150
+ ...h.breakdowns.map((R) => R.field)
3151
+ ]
3152
+ }
3153
+ )
3154
+ ]
3155
+ }
3156
+ );
3157
+ }
3158
+ );
3159
+ wr.displayName = "AnalysisBuilder";
8
3160
  export {
9
- r as AnalyticsDashboard,
10
- s as AnalyticsPortlet,
11
- f as CubeProvider,
12
- k as DEFAULT_ICONS,
13
- t as DashboardEditModal,
14
- o as DashboardGrid,
15
- g as LazyChart,
16
- c as LoadingIndicator,
17
- i as Modal,
18
- n as PortletContainer,
19
- l as PortletEditModal,
20
- d as QueryBuilder,
21
- z as ScrollContainerProvider,
22
- x as THEME_PRESETS,
23
- D as applyTheme,
24
- E as createCubeClient,
25
- p as createDashboardLayout,
26
- y as formatChartData,
27
- T as getAvailableChartTypes,
28
- G as getChartTypeIcon,
29
- H as getFieldTypeIcon,
30
- N as getIcon,
31
- O as getIconData,
32
- U as getIconRegistry,
33
- j as getIconsByCategory,
34
- q as getMeasureTypeIcon,
35
- L as getTheme,
36
- M as getThemeVariable,
37
- P as isDarkMode,
38
- m as isValidChartType,
39
- u as preloadChart,
40
- b as preloadCharts,
41
- J as registerIcons,
42
- K as resetIcons,
43
- A as resetTheme,
44
- W as setIcon,
45
- S as setTheme,
46
- v as setThemeVariable,
47
- B as useCubeContext,
48
- R as useCubeQuery,
49
- F as useScrollContainer,
50
- V as watchThemeChanges
3161
+ wr as AnalysisBuilder,
3162
+ $r as AnalyticsDashboard,
3163
+ Or as AnalyticsPortlet,
3164
+ Wr as CubeProvider,
3165
+ cs as DEFAULT_ICONS,
3166
+ Mr as DashboardEditModal,
3167
+ Er as DashboardGrid,
3168
+ $e as LazyChart,
3169
+ qr as LoadingIndicator,
3170
+ Lr as Modal,
3171
+ _r as PortletContainer,
3172
+ Br as PortletEditModal,
3173
+ jr as QueryBuilder,
3174
+ bs as ScrollContainerProvider,
3175
+ Yr as THEME_PRESETS,
3176
+ Xr as applyTheme,
3177
+ Zr as createCubeClient,
3178
+ Gr as createDashboardLayout,
3179
+ Qr as formatChartData,
3180
+ zr as getAvailableChartTypes,
3181
+ is as getChartTypeIcon,
3182
+ ke as getFieldTypeIcon,
3183
+ I as getIcon,
3184
+ ds as getIconData,
3185
+ os as getIconRegistry,
3186
+ us as getIconsByCategory,
3187
+ xe as getMeasureTypeIcon,
3188
+ Ur as getTheme,
3189
+ es as getThemeVariable,
3190
+ ts as isDarkMode,
3191
+ dt as isValidChartType,
3192
+ Jr as preloadChart,
3193
+ Hr as preloadCharts,
3194
+ ms as registerIcons,
3195
+ hs as resetIcons,
3196
+ rs as resetTheme,
3197
+ xs as setIcon,
3198
+ ss as setTheme,
3199
+ ns as setThemeVariable,
3200
+ xt as useCubeContext,
3201
+ pt as useCubeQuery,
3202
+ ps as useScrollContainer,
3203
+ as as watchThemeChanges
51
3204
  };
52
3205
  //# sourceMappingURL=index.js.map