react-semaphor 0.1.564 → 0.1.565

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 (132) hide show
  1. package/DATA_APP_SDK.md +3 -3
  2. package/README.md +2 -2
  3. package/dist/analytics-protocol/index.js +8 -8
  4. package/dist/assistant-context/index.js +3 -2
  5. package/dist/brand-studio/index.js +28 -29
  6. package/dist/briefings/index.js +4 -4
  7. package/dist/chunks/{assistant-chat-D1BEEHUF.js → assistant-chat-DNfb5fbF.js} +204 -204
  8. package/dist/chunks/{bookmark-impact-XOsVUAqW.js → bookmark-impact-CHr7b1J2.js} +2 -2
  9. package/dist/chunks/bookmark-state-ByODVqee.js +1613 -0
  10. package/dist/chunks/card-filter-builder-CcEcfaYz.js +4100 -0
  11. package/dist/chunks/{switch-BW4yXSYs.js → code-editor-DJNOsgJH.js} +463 -442
  12. package/dist/chunks/{comparison-window-caption-D1EUXzaR.js → comparison-window-caption-CMLb3mut.js} +451 -419
  13. package/dist/chunks/{dashboard-DfYsASNd.js → dashboard-CtIfxycc.js} +1 -1
  14. package/dist/chunks/dashboard-briefing-launcher-D3mc6peE.js +4910 -0
  15. package/dist/chunks/{dashboard-controls-CJ8Dz50D.js → dashboard-controls-BFv0zdws.js} +692 -682
  16. package/dist/chunks/{dashboard-json-D3uZxGO-.js → dashboard-json-CXn_3OYb.js} +4 -4
  17. package/dist/chunks/{dates-EvDtT25n.js → dates-DcRxw17S.js} +12 -12
  18. package/dist/chunks/{edit-dashboard-visual-CgHJXBQv.js → edit-dashboard-visual-Y6HatqBd.js} +7704 -10337
  19. package/dist/chunks/filter-reach-copy-DbggA5B7.js +4673 -0
  20. package/dist/chunks/{filter-value-text-CPwFkrMz.js → filter-value-text-7zhmth1S.js} +2 -2
  21. package/dist/chunks/{index-CAgf2x4E.js → index-DDa_rklN.js} +68 -63
  22. package/dist/chunks/{layout-grid-BM65viQh.js → layout-grid-0hIlqEtk.js} +1 -1
  23. package/dist/chunks/{list-filter-BoeLBfL3.js → list-filter-DkgoCeBm.js} +1 -1
  24. package/dist/chunks/{matrix-analytical-definition-hEucouWM.js → matrix-analytical-definition-C9xB_T84.js} +18 -18
  25. package/dist/chunks/{matrix-card-CCh9JjP1.js → matrix-card-BSUeSXpD.js} +2 -2
  26. package/dist/chunks/{matrix-member-presentation-DsAUbuoL.js → matrix-member-presentation-DZNgQpUq.js} +1 -1
  27. package/dist/chunks/{matrix-operation-contract-DsLdFdSa.js → matrix-operation-contract-Eb6elidS.js} +1 -1
  28. package/dist/chunks/{metric-comparison-Bnso1cm1.js → metric-comparison-ChXUFaZu.js} +1 -1
  29. package/dist/chunks/{palette-p1XSJFgB.js → palette-4vf2BEEg.js} +1 -1
  30. package/dist/chunks/{pivot-result-contract-expectations-B53jqszr.js → pivot-result-contract-expectations-Ddh1rNz5.js} +4 -4
  31. package/dist/chunks/{pivot-result-identity-Dq5jm-EC.js → pivot-result-identity-BlbLrqaC.js} +1 -1
  32. package/dist/chunks/{report-preferences-dialog-DMqxSU4X.js → report-preferences-dialog-Db-b04B4.js} +122 -131
  33. package/dist/chunks/{report-runtime-context-BITkNSDa.js → report-runtime-context-DnA_PiKo.js} +1 -1
  34. package/dist/chunks/resolve-dashboard-input-context-C18J-YZC.js +21394 -0
  35. package/dist/chunks/{save-CHV1B1fL.js → save-D6pHmSSP.js} +1 -1
  36. package/dist/chunks/saved-dashboard-context-DhC_EVus.js +629 -0
  37. package/dist/chunks/{selection-reducer-Bz5aywT4.js → selection-reducer-OaJ-N5uN.js} +1 -1
  38. package/dist/chunks/{semaphor-ready-indicator-CFeCIuaw.js → semaphor-ready-indicator-T6TsiBMT.js} +80634 -80503
  39. package/dist/chunks/{shelf-drop-preview-context-cEyVkKTF.js → shelf-drop-preview-context-CNWL_b0S.js} +407 -407
  40. package/dist/chunks/{source-entity-resolution-DdDVXFB8.js → source-entity-resolution-DF6GulDn.js} +1 -1
  41. package/dist/chunks/stored-dashboard-IdmtrNkA.js +5026 -0
  42. package/dist/chunks/{table-export-sheet-bSXxGn-v.js → table-export-sheet--DUKWk6o.js} +1 -1
  43. package/dist/chunks/{temporal-input-presentation-sk9gqLi6.js → temporal-input-presentation--2r9BLr0.js} +392 -377
  44. package/dist/chunks/{token-types-BUK06hU2.js → token-types-C8JymO8s.js} +1 -1
  45. package/dist/chunks/{upload-BnmuyPqW.js → upload-Cf3wXZT8.js} +1 -1
  46. package/dist/chunks/{validators-BIM0FE31.js → validators-wtjw0aw6.js} +7 -7
  47. package/dist/chunks/variable-draft-3xseULxR.js +241 -0
  48. package/dist/dashboard/index.js +2 -2
  49. package/dist/dashboard-authoring/index.js +2206 -1705
  50. package/dist/data-app-sdk/index.js +4 -4
  51. package/dist/data-app-sdk-adapters/index.js +2 -2
  52. package/dist/data-app-sdk-validation/index.js +5 -5
  53. package/dist/format-utils/index.js +174 -167
  54. package/dist/index.js +189 -187
  55. package/dist/pdf-export-policy/index.js +80 -28
  56. package/dist/pdf-table-layout/index.js +65 -65
  57. package/dist/report-runtime-context/index.js +1 -1
  58. package/dist/style.css +1 -1
  59. package/dist/surfboard/index.js +2 -2
  60. package/dist/types/briefings/attachment-outcomes.d.ts +1 -1
  61. package/dist/types/components/dashboard-variables/data-variables-menu.d.ts +8 -0
  62. package/dist/types/components/dashboard-variables/variable-editor-host.d.ts +1 -0
  63. package/dist/types/components/index.d.ts +2 -0
  64. package/dist/types/index.js +5 -5
  65. package/dist/types/lib/dashboard-inputs/build-normalized-dashboard-inputs.d.ts +62 -0
  66. package/dist/types/lib/dashboard-inputs/dashboard-filter-mapping-authoring.d.ts +33 -2
  67. package/dist/types/lib/dashboard-inputs/filter-settings.d.ts +7 -2
  68. package/dist/types/lib/dashboard-inputs/prepare-loaded-dashboard.d.ts +4 -2
  69. package/dist/types/lib/dashboard-variables/data-text.d.ts +33 -0
  70. package/dist/types/lib/dashboard-variables/types.d.ts +207 -0
  71. package/dist/types/lib/document/document-edits.d.ts +16 -1
  72. package/dist/types/lib/document/document-panel-target.d.ts +1 -1
  73. package/dist/types/lib/document/document-section-query-options.d.ts +29 -0
  74. package/dist/types/lib/document/document-table-data-policy.d.ts +0 -1
  75. package/dist/types/lib/hooks/use-dashboard-frame-query.d.ts +92 -0
  76. package/dist/types/lib/query-context/build-card-query-context.d.ts +6 -0
  77. package/dist/types/lib/query-context/describe-card-execution-snapshot.d.ts +1 -0
  78. package/dist/types/lib/query-context/use-semantic-execution-payload-for-cards.d.ts +24 -0
  79. package/dist/types/lib/stores/dashboard-store.d.ts +36 -0
  80. package/dist/types/lib/text-variables/temporal-input-text.d.ts +28 -0
  81. package/dist/types/lib/text-variables/text-variable-types.d.ts +72 -0
  82. package/dist/types/lib/types/common-types.d.ts +155 -51
  83. package/dist/types/lib/utils/card-definition.d.ts +2 -2
  84. package/dist/types/shared/assistant-context/index.d.ts +1 -1
  85. package/dist/types/shared/assistant-context/saved-dashboard-context.d.ts +51 -1
  86. package/dist/types/shared/dashboard-authoring/card-query-request.d.ts +7 -1
  87. package/dist/types/shared/dashboard-authoring/card-settings/resolve-card-highlights.d.ts +10 -0
  88. package/dist/types/shared/dashboard-authoring/changes/card-query-part.d.ts +1 -0
  89. package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +1087 -430
  90. package/dist/types/shared/dashboard-authoring/changes/diagnostics.d.ts +18 -1
  91. package/dist/types/shared/dashboard-authoring/changes/resolve-dashboard-changes.d.ts +1 -1
  92. package/dist/types/shared/dashboard-authoring/conditional-formatting/kpi.d.ts +10 -0
  93. package/dist/types/shared/dashboard-authoring/conditional-formatting/schema.d.ts +40 -40
  94. package/dist/types/shared/dashboard-authoring/control-execution-contract.d.ts +16 -16
  95. package/dist/types/shared/dashboard-authoring/dashboard-card-source-index.d.ts +1 -0
  96. package/dist/types/shared/dashboard-authoring/dashboard-filter-targets.d.ts +29 -0
  97. package/dist/types/shared/dashboard-authoring/dashboard-input-scope.d.ts +7 -4
  98. package/dist/types/shared/dashboard-authoring/dashboard-variable-card.d.ts +159 -0
  99. package/dist/types/shared/dashboard-authoring/dashboard-variable-changes.d.ts +61 -0
  100. package/dist/types/shared/dashboard-authoring/document-section-cards.d.ts +7 -0
  101. package/dist/types/shared/dashboard-authoring/filter-model/index.d.ts +2 -0
  102. package/dist/types/shared/dashboard-authoring/filter-model/read-dashboard-filter-model.d.ts +10 -0
  103. package/dist/types/shared/dashboard-authoring/index.d.ts +6 -0
  104. package/dist/types/shared/dashboard-authoring/measure-calculations/comparison.d.ts +2 -0
  105. package/dist/types/shared/dashboard-authoring/operations/operation-sentences.d.ts +1 -1
  106. package/dist/types/shared/dashboard-authoring/operations/operation-types.d.ts +50 -3
  107. package/dist/types/shared/dashboard-authoring/outline/outline-dashboard.d.ts +48 -1
  108. package/dist/types/shared/dashboard-authoring/outline/outline-filters.d.ts +2 -2
  109. package/dist/types/shared/dashboard-authoring/text-card-words/blocks.d.ts +87 -13
  110. package/dist/types/shared/dashboard-authoring/text-card-words/chip-colors.d.ts +23 -0
  111. package/dist/types/shared/dashboard-authoring/text-card-words/index.d.ts +90 -8
  112. package/dist/types/shared/dashboard-authoring/text-card-words/rich-content.d.ts +31 -3
  113. package/dist/types/shared/dashboard-authoring/text-card-words/variable-words.d.ts +8 -0
  114. package/dist/types/shared/dashboard-authoring/variable-draft.d.ts +125 -0
  115. package/dist/types/shared/dashboard-authoring/variable-editability.d.ts +24 -0
  116. package/dist/types/shared/dashboard-authoring/variable-references.d.ts +39 -0
  117. package/dist/types/shared/format-utils/document-print.d.ts +4 -2
  118. package/dist/types/shared/format-utils/index.d.ts +1 -0
  119. package/dist/types/shared/format-utils/pdf-capacity-lines.d.ts +17 -0
  120. package/dist/types/shared/format-utils/pdf-delivery.d.ts +8 -1
  121. package/dist/types/shared/format-utils/pdf-export-policy.d.ts +74 -6
  122. package/dist/types/shared/format-utils/presentation-execution.d.ts +9 -0
  123. package/package.json +2 -2
  124. package/src/data-app-sdk/README.md +3 -3
  125. package/dist/chunks/bookmark-state-CWeoGbrx.js +0 -743
  126. package/dist/chunks/braces-DzgoQC64.js +0 -23
  127. package/dist/chunks/dashboard-briefing-launcher-lvYfJoUQ.js +0 -3878
  128. package/dist/chunks/filter-reach-copy-Cmb05jlE.js +0 -3965
  129. package/dist/chunks/global-date-filter-utils-ruJYwjgZ.js +0 -16733
  130. package/dist/chunks/resolve-dashboard-input-context-i_jCSYae.js +0 -8214
  131. package/dist/chunks/saved-dashboard-context-Dg3oDmH_.js +0 -564
  132. package/dist/chunks/use-create-flow-overlay-state-Dl6DCxh8.js +0 -1436
@@ -0,0 +1,4100 @@
1
+ import { c as Ue, B as j, X as ce, s as Ne, l as un, a3 as mn, o as at, p as rt, q as st, r as ot, a4 as Ot, z as Oe, n as le, t as xe, u as ge, v as be, w as ve, x as re, P as it, a as lt, d as dt, L as pn, y as fn } from "./code-editor-DJNOsgJH.js";
2
+ import { jsx as t, jsxs as l, Fragment as fe } from "react/jsx-runtime";
3
+ import * as _e from "react";
4
+ import vt, { useMemo as Q, useState as H, useRef as Ae, useCallback as ne, useEffect as de, forwardRef as hn, Fragment as xn } from "react";
5
+ import { aU as ct, u as ut, a6 as se, bX as _t, cs as X, ct as gn, bT as Ie, cu as Ge, cv as Vt, cw as bn, bN as Ve, cx as vn, a7 as Rt, bu as yn, bv as Nn, bx as Cn, bn as wn, cy as kn, i as Sn, cz as Dn, cA as yt, bM as Et, cB as In, cC as Mt, cD as zt, cE as Tn, cF as Ln, cG as An, cH as $n, cI as Fn, cJ as On, cK as _n, bo as Vn, cL as Nt, cM as qt, cN as Rn, br as En, cO as Mn, cP as zn, cQ as qn, cR as ye, cS as jt, cT as jn, cU as Un, cV as Gn, cW as Bn, cX as Wn, cY as Kn, cZ as Je, c_ as he, c$ as et, d0 as tt, d1 as nt, d2 as Qn, d3 as Re, d4 as Ee, d5 as Me, d6 as ze, d7 as Ut, d8 as Gt, d9 as Bt } from "./semaphor-ready-indicator-T6TsiBMT.js";
6
+ import { D as Hn } from "./token-types-C8JymO8s.js";
7
+ import { eW as Wt, eX as Yn, eY as Pn, eZ as Xn, e_ as Zn, e$ as Jn, f0 as $e, f1 as Ct, f2 as wt, f3 as Qe, f4 as He, f5 as ea, f6 as ta, f7 as kt, f8 as na, f9 as aa, fa as Fe, fb as ra, fc as St, fd as Kt, fe as Qt, ff as Ht, fg as Yt, fh as sa, fi as oa, fj as Dt, fk as ia, fl as It, fm as la, fn as da, fo as ca, fp as ua, fq as Ye, a as qe, fr as Pe, fs as ma, ft as pa, fu as fa, fv as ha } from "./resolve-dashboard-input-context-C18J-YZC.js";
8
+ import "./index-CuHybtft.js";
9
+ import { u as Pt } from "./validators-wtjw0aw6.js";
10
+ import "./matrix-operation-contract-Eb6elidS.js";
11
+ import "./analytics-base-schemas-BaIQrEzX.js";
12
+ import "zod";
13
+ import "../value-format-preferences/index.js";
14
+ import { c as M } from "./_commonjsHelpers-DimLPMtv.js";
15
+ import { U as xa } from "./upload-Cf3wXZT8.js";
16
+ import { S as Xt } from "./filter-reach-copy-DbggA5B7.js";
17
+ /**
18
+ * @license lucide-react v0.453.0 - ISC
19
+ *
20
+ * This source code is licensed under the ISC license.
21
+ * See the LICENSE file in the root directory of this source tree.
22
+ */
23
+ const ga = Ue("Boxes", [
24
+ [
25
+ "path",
26
+ {
27
+ d: "M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z",
28
+ key: "lc1i9w"
29
+ }
30
+ ],
31
+ ["path", { d: "m7 16.5-4.74-2.85", key: "1o9zyk" }],
32
+ ["path", { d: "m7 16.5 5-3", key: "va8pkn" }],
33
+ ["path", { d: "M7 16.5v5.17", key: "jnp8gn" }],
34
+ [
35
+ "path",
36
+ {
37
+ d: "M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z",
38
+ key: "8zsnat"
39
+ }
40
+ ],
41
+ ["path", { d: "m17 16.5-5-3", key: "8arw3v" }],
42
+ ["path", { d: "m17 16.5 4.74-2.85", key: "8rfmw" }],
43
+ ["path", { d: "M17 16.5v5.17", key: "k6z78m" }],
44
+ [
45
+ "path",
46
+ {
47
+ d: "M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z",
48
+ key: "1xygjf"
49
+ }
50
+ ],
51
+ ["path", { d: "M12 8 7.26 5.15", key: "1vbdud" }],
52
+ ["path", { d: "m12 8 4.74-2.85", key: "3rx089" }],
53
+ ["path", { d: "M12 13.5V8", key: "1io7kd" }]
54
+ ]);
55
+ /**
56
+ * @license lucide-react v0.453.0 - ISC
57
+ *
58
+ * This source code is licensed under the ISC license.
59
+ * See the LICENSE file in the root directory of this source tree.
60
+ */
61
+ const Nr = Ue("FilterX", [
62
+ ["path", { d: "M13.013 3H2l8 9.46V19l4 2v-8.54l.9-1.055", key: "1fi1da" }],
63
+ ["path", { d: "m22 3-5 5", key: "12jva0" }],
64
+ ["path", { d: "m17 3 5 5", key: "k36vhe" }]
65
+ ]);
66
+ /**
67
+ * @license lucide-react v0.453.0 - ISC
68
+ *
69
+ * This source code is licensed under the ISC license.
70
+ * See the LICENSE file in the root directory of this source tree.
71
+ */
72
+ const ba = Ue("Library", [
73
+ ["path", { d: "m16 6 4 14", key: "ji33uf" }],
74
+ ["path", { d: "M12 6v14", key: "1n7gus" }],
75
+ ["path", { d: "M8 8v12", key: "1gg7y9" }],
76
+ ["path", { d: "M4 4v16", key: "6qkkli" }]
77
+ ]);
78
+ /**
79
+ * @license lucide-react v0.453.0 - ISC
80
+ *
81
+ * This source code is licensed under the ISC license.
82
+ * See the LICENSE file in the root directory of this source tree.
83
+ */
84
+ const va = Ue("Link2", [
85
+ ["path", { d: "M9 17H7A5 5 0 0 1 7 7h2", key: "8i5ue5" }],
86
+ ["path", { d: "M15 7h2a5 5 0 1 1 0 10h-2", key: "1b9ql8" }],
87
+ ["line", { x1: "8", x2: "16", y1: "12", y2: "12", key: "1jonct" }]
88
+ ]);
89
+ function ya(e, n, a) {
90
+ switch (e) {
91
+ case "none":
92
+ return !1;
93
+ case "include":
94
+ return a.includes(n);
95
+ case "exclude":
96
+ return !a.includes(n);
97
+ case "all":
98
+ default:
99
+ return !0;
100
+ }
101
+ }
102
+ function Na({
103
+ mode: e,
104
+ currentDomainId: n,
105
+ scopedDomainIds: a,
106
+ hasSelectedEntities: o
107
+ }) {
108
+ return e === "all" ? !1 : e === "none" ? !!n || o : n ? !ya(e, n, a) : o;
109
+ }
110
+ function Zt(e) {
111
+ const { tokenProps: n } = ct(), a = ut((r) => r.authToken) || e;
112
+ se(
113
+ (r) => r.selectedConnectionId
114
+ ), se(
115
+ (r) => {
116
+ var p, f;
117
+ return (f = (p = r == null ? void 0 : r.card) == null ? void 0 : p.dataSource) == null ? void 0 : f.connectionId;
118
+ }
119
+ );
120
+ const {
121
+ refetch: o,
122
+ isPending: u,
123
+ data: d,
124
+ isLoading: c,
125
+ isError: i
126
+ } = _t({
127
+ queryKey: ["semantic-domains"],
128
+ queryFn: () => Wt(
129
+ `${n.apiServiceUrl}/v1/domains`,
130
+ (a == null ? void 0 : a.accessToken) || ""
131
+ ),
132
+ enabled: !!(a != null && a.accessToken)
133
+ // Only fetch if authToken is present
134
+ });
135
+ return {
136
+ isPending: u,
137
+ error: i,
138
+ semanticDomainsData: d,
139
+ semanticDomains: (d == null ? void 0 : d.domains) || [],
140
+ isSemanticDomainsLoading: c,
141
+ isSemanticDomainsError: i,
142
+ refetchSemanticDomains: o
143
+ };
144
+ }
145
+ function Jt(e) {
146
+ const n = mt(e);
147
+ return n.size === 1 ? [...n][0] : void 0;
148
+ }
149
+ function mt(e) {
150
+ const n = /* @__PURE__ */ new Set();
151
+ for (const a of e)
152
+ "domainId" in a && typeof a.domainId == "string" && a.domainId && n.add(a.domainId);
153
+ return n;
154
+ }
155
+ function Ca(e, n) {
156
+ if (e.some(
157
+ (d) => X(d, n)
158
+ ))
159
+ return e.filter(
160
+ (d) => !X(d, n)
161
+ );
162
+ const o = mt(e);
163
+ return e.some(
164
+ (d) => !("domainId" in d)
165
+ ) || [...o].some((d) => d !== n.domainId) ? [n] : [...e, n];
166
+ }
167
+ function wa(e, n) {
168
+ const a = Jt(n), o = mt(e), u = e.some(
169
+ (c) => !("domainId" in c)
170
+ );
171
+ if (a && (u || [...o].some(
172
+ (c) => c !== a
173
+ )))
174
+ return n;
175
+ const d = [...e];
176
+ for (const c of n)
177
+ d.some((i) => X(i, c)) || d.push(c);
178
+ return d;
179
+ }
180
+ function ka({
181
+ domainAccess: e,
182
+ search: n,
183
+ scopeDomainId: a,
184
+ selectedEntities: o,
185
+ onSelectionChange: u
186
+ }) {
187
+ const { semanticDomains: d, isSemanticDomainsLoading: c } = Zt(), i = Q(() => Da(d, e), [d, e]), r = Q(() => a ? i.filter((f) => f.id === a) : i, [i, a]);
188
+ if (c && r.length === 0)
189
+ return /* @__PURE__ */ t("div", { className: "px-3 py-4 text-[11px] text-muted-foreground", children: "Loading semantic domains…" });
190
+ if (r.length === 0)
191
+ return null;
192
+ const p = !!a;
193
+ return /* @__PURE__ */ l("div", { children: [
194
+ /* @__PURE__ */ t(en, { label: "Semantic Domains" }),
195
+ r.map((f) => /* @__PURE__ */ t(
196
+ Sa,
197
+ {
198
+ domain: f,
199
+ search: n,
200
+ forceExpanded: p,
201
+ selectedEntities: o,
202
+ onSelectionChange: u
203
+ },
204
+ f.id
205
+ ))
206
+ ] });
207
+ }
208
+ function Sa({
209
+ domain: e,
210
+ search: n,
211
+ forceExpanded: a,
212
+ selectedEntities: o,
213
+ onSelectionChange: u
214
+ }) {
215
+ const [d, c] = H(!1), i = d || n.length > 0 || !!a, { datasets: r, isPending: p } = gn(
216
+ i ? e.id : void 0
217
+ ), f = Q(() => {
218
+ if (!n) return r;
219
+ const O = n.trim().toLowerCase();
220
+ return r.filter(
221
+ (T) => `${T.label ?? ""} ${T.name ?? ""} ${T.description ?? ""}`.toLowerCase().includes(O)
222
+ );
223
+ }, [r, n]), k = n.length > 0 && f.length > 0, y = d || k || !!a, h = r.length, N = Q(() => f.filter(
224
+ (O) => o.some(
225
+ (T) => X(T, Le(O))
226
+ )
227
+ ).length, [f, o]), S = Q(
228
+ () => f.map(Le),
229
+ [f]
230
+ ), w = S.length > 0 && S.every(
231
+ (O) => o.some((T) => X(T, O))
232
+ ), V = () => {
233
+ if (S.length !== 0) {
234
+ if (w) {
235
+ u(
236
+ o.filter(
237
+ (O) => !S.some(
238
+ (T) => X(O, T)
239
+ )
240
+ )
241
+ );
242
+ return;
243
+ }
244
+ u(
245
+ wa(
246
+ o,
247
+ S
248
+ )
249
+ );
250
+ }
251
+ }, U = (O) => {
252
+ const T = Le(O);
253
+ u(
254
+ Ca(
255
+ o,
256
+ T
257
+ )
258
+ );
259
+ };
260
+ return n.length > 0 && !k && !p ? null : /* @__PURE__ */ l("div", { children: [
261
+ /* @__PURE__ */ l("div", { className: "flex items-center rounded-[4px] px-3 py-1.5 transition-colors hover:bg-muted/50", children: [
262
+ /* @__PURE__ */ l(
263
+ "button",
264
+ {
265
+ type: "button",
266
+ onClick: () => c((O) => !O),
267
+ className: "flex min-w-0 flex-1 items-center gap-1.5 text-left",
268
+ children: [
269
+ /* @__PURE__ */ t(
270
+ Ie,
271
+ {
272
+ className: M(
273
+ "h-3 w-3 shrink-0 text-muted-foreground transition-transform",
274
+ y && "rotate-90"
275
+ ),
276
+ strokeWidth: 1.75
277
+ }
278
+ ),
279
+ /* @__PURE__ */ t("span", { className: "truncate text-[13px] font-medium text-foreground", children: e.label || e.name }),
280
+ h > 0 && /* @__PURE__ */ l("span", { className: "shrink-0 text-[11px] text-muted-foreground", children: [
281
+ "· ",
282
+ h,
283
+ " dataset",
284
+ h === 1 ? "" : "s",
285
+ " · curated"
286
+ ] })
287
+ ]
288
+ }
289
+ ),
290
+ y && !p && S.length > 0 && /* @__PURE__ */ t(
291
+ "button",
292
+ {
293
+ type: "button",
294
+ onClick: V,
295
+ className: "ml-2 shrink-0 rounded-[3px] px-1.5 py-0.5 text-[10.5px] font-medium text-muted-foreground hover:bg-background hover:text-foreground",
296
+ children: w ? "Clear" : "Select all"
297
+ }
298
+ ),
299
+ /* @__PURE__ */ t("span", { className: "ml-auto font-mono text-[10px] tabular-nums text-muted-foreground", children: N > 0 ? N : "" })
300
+ ] }),
301
+ y && /* @__PURE__ */ t("ul", { className: "space-y-px pb-1", children: p && r.length === 0 ? /* @__PURE__ */ t("li", { className: "px-9 py-1.5 text-[11px] text-muted-foreground", children: "Loading datasets…" }) : f.length === 0 ? /* @__PURE__ */ t("li", { className: "px-9 py-1.5 text-[11px] text-muted-foreground", children: "No datasets in this domain." }) : f.map((O) => {
302
+ const T = Le(O), Y = o.some(
303
+ (Z) => X(Z, T)
304
+ );
305
+ return /* @__PURE__ */ t("li", { children: /* @__PURE__ */ l("label", { className: "flex cursor-pointer items-start gap-2 rounded-[4px] px-9 py-1.5 transition-colors hover:bg-muted/40", children: [
306
+ /* @__PURE__ */ t(
307
+ Ge,
308
+ {
309
+ checked: Y,
310
+ onCheckedChange: () => U(O),
311
+ className: "mt-[3px] h-3.5 w-3.5 shrink-0"
312
+ }
313
+ ),
314
+ /* @__PURE__ */ l("div", { className: "min-w-0 flex-1", children: [
315
+ /* @__PURE__ */ l("div", { className: "flex items-baseline gap-1.5", children: [
316
+ /* @__PURE__ */ t("span", { className: "truncate text-[13px] text-foreground", children: O.label || O.name }),
317
+ /* @__PURE__ */ t("span", { className: "shrink-0 font-mono text-[10px] uppercase tracking-[0.06em] text-muted-foreground/70", children: O.type === "virtual" ? "virtual" : "dataset" })
318
+ ] }),
319
+ O.description && /* @__PURE__ */ t("p", { className: "mt-0.5 text-[11px] leading-[1.4] text-muted-foreground", children: O.description })
320
+ ] })
321
+ ] }) }, O.id);
322
+ }) })
323
+ ] });
324
+ }
325
+ function en({ label: e }) {
326
+ return /* @__PURE__ */ t("div", { className: "px-3 pb-1.5 pt-2.5", children: /* @__PURE__ */ t("p", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: e }) });
327
+ }
328
+ function Da(e, n) {
329
+ if (!n || n.mode === "all") return e;
330
+ const a = new Set(n.domainIds ?? []);
331
+ return n.mode === "include" ? e.filter((o) => a.has(o.id)) : n.mode === "exclude" ? e.filter((o) => !a.has(o.id)) : [];
332
+ }
333
+ function Le(e) {
334
+ return {
335
+ id: e.id,
336
+ datasetType: e.type,
337
+ name: e.name || e.table,
338
+ label: e.label,
339
+ domainId: e.domainId,
340
+ description: e.description,
341
+ database: e.database,
342
+ schema: e.schema,
343
+ table: e.table,
344
+ type: "dataset",
345
+ connectionId: e.connectionId,
346
+ connectionType: e.connectionType,
347
+ dialect: e.dialect,
348
+ datamodelId: e.datamodelId,
349
+ sql: e.sql
350
+ };
351
+ }
352
+ function Ia({
353
+ search: e,
354
+ scopeConnectionId: n,
355
+ selectedEntities: a,
356
+ onSelectionChange: o
357
+ }) {
358
+ const { connections: u, isConnectionsLoading: d } = Vt(), c = Q(() => n ? u.filter((r) => r.id === n) : u, [u, n]);
359
+ if (d && c.length === 0)
360
+ return /* @__PURE__ */ t("div", { className: "px-3 py-4 text-[11px] text-muted-foreground", children: "Loading connections…" });
361
+ if (c.length === 0)
362
+ return null;
363
+ const i = !!n;
364
+ return /* @__PURE__ */ l("div", { children: [
365
+ /* @__PURE__ */ t(en, { label: "Direct Sources" }),
366
+ c.map((r) => /* @__PURE__ */ t(
367
+ Ta,
368
+ {
369
+ connection: r,
370
+ search: e,
371
+ forceExpanded: i,
372
+ selectedEntities: a,
373
+ onSelectionChange: o
374
+ },
375
+ r.id
376
+ ))
377
+ ] });
378
+ }
379
+ function Ta({
380
+ connection: e,
381
+ search: n,
382
+ forceExpanded: a,
383
+ selectedEntities: o,
384
+ onSelectionChange: u
385
+ }) {
386
+ var N;
387
+ const [d, c] = H(!1), i = d || n.length > 0 || !!a, r = ((N = e.capabilities) == null ? void 0 : N.path) ?? [], p = r.includes("database"), f = r.includes("schema"), k = e.type === "upload", y = e.type === "url", h = Q(
388
+ () => o.filter((S) => S.connectionId === e.id).length,
389
+ [o, e.id]
390
+ );
391
+ return /* @__PURE__ */ l("div", { className: "border-b border-border/60 last:border-b-0", children: [
392
+ /* @__PURE__ */ l(
393
+ "button",
394
+ {
395
+ type: "button",
396
+ onClick: () => c((S) => !S),
397
+ className: "flex w-full items-center gap-2 px-4 py-1.5 text-left transition-colors hover:bg-muted/40",
398
+ children: [
399
+ /* @__PURE__ */ t(
400
+ Ie,
401
+ {
402
+ className: M(
403
+ "h-3 w-3 shrink-0 text-muted-foreground transition-transform",
404
+ i && "rotate-90"
405
+ ),
406
+ strokeWidth: 1.75
407
+ }
408
+ ),
409
+ /* @__PURE__ */ t("span", { className: "truncate text-[13px] font-medium text-foreground/90", children: e.name }),
410
+ /* @__PURE__ */ l("span", { className: "truncate text-[11px] text-muted-foreground", children: [
411
+ "· ",
412
+ e.type
413
+ ] }),
414
+ /* @__PURE__ */ t("span", { className: "ml-auto shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground", children: h > 0 ? h : "" })
415
+ ]
416
+ }
417
+ ),
418
+ i && /* @__PURE__ */ l(fe, { children: [
419
+ k ? /* @__PURE__ */ t(
420
+ La,
421
+ {
422
+ connection: e,
423
+ selectedEntities: o,
424
+ onSelectionChange: u
425
+ }
426
+ ) : y ? /* @__PURE__ */ t(
427
+ Aa,
428
+ {
429
+ connection: e,
430
+ selectedEntities: o,
431
+ onSelectionChange: u
432
+ }
433
+ ) : p ? /* @__PURE__ */ t(
434
+ $a,
435
+ {
436
+ connection: e,
437
+ requiresSchema: f,
438
+ search: n,
439
+ selectedEntities: o,
440
+ onSelectionChange: u
441
+ }
442
+ ) : f ? /* @__PURE__ */ t(
443
+ tn,
444
+ {
445
+ connection: e,
446
+ databaseName: "",
447
+ search: n,
448
+ selectedEntities: o,
449
+ onSelectionChange: u
450
+ }
451
+ ) : /* @__PURE__ */ t(
452
+ pt,
453
+ {
454
+ connection: e,
455
+ databaseName: "",
456
+ schemaName: "",
457
+ search: n,
458
+ selectedEntities: o,
459
+ onSelectionChange: u
460
+ }
461
+ ),
462
+ !k && !y && /* @__PURE__ */ t(
463
+ Fa,
464
+ {
465
+ connection: e,
466
+ search: n,
467
+ selectedEntities: o,
468
+ onSelectionChange: u
469
+ }
470
+ )
471
+ ] })
472
+ ] });
473
+ }
474
+ function La({
475
+ connection: e,
476
+ selectedEntities: n,
477
+ onSelectionChange: a
478
+ }) {
479
+ const o = `upload-source-${e.id}`, u = n.filter(
480
+ (i) => i.connectionId === e.id && (i.type === "upload" || i.type === "file")
481
+ ), d = (i) => {
482
+ if (!(i != null && i.length)) return;
483
+ const r = Array.from(i).map((p) => ({
484
+ id: `file-${Date.now()}-${Math.random()}`,
485
+ name: p.name,
486
+ type: "upload",
487
+ connectionId: e.id,
488
+ connectionType: e.type,
489
+ label: p.name,
490
+ description: `Uploaded ${(/* @__PURE__ */ new Date()).toLocaleString()}`,
491
+ originalName: p.name,
492
+ file: p
493
+ }));
494
+ a([...n, ...r]);
495
+ }, c = (i) => {
496
+ a(
497
+ n.filter(
498
+ (r) => !("id" in r && r.id === i && r.connectionId === e.id && (r.type === "upload" || r.type === "file"))
499
+ )
500
+ );
501
+ };
502
+ return /* @__PURE__ */ l("div", { className: "space-y-2 px-8 py-2", children: [
503
+ /* @__PURE__ */ l("div", { className: "rounded-[6px] border border-dashed border-border bg-muted/20 p-4 text-center", children: [
504
+ /* @__PURE__ */ t(xa, { className: "mx-auto mb-2 h-5 w-5 text-muted-foreground" }),
505
+ /* @__PURE__ */ t("p", { className: "text-[12px] text-muted-foreground", children: "Add CSV, JSON, or Excel files." }),
506
+ /* @__PURE__ */ t(
507
+ "input",
508
+ {
509
+ id: o,
510
+ type: "file",
511
+ multiple: !0,
512
+ className: "hidden",
513
+ onChange: (i) => d(i.target.files),
514
+ accept: ".csv,.json,.xlsx,.xls"
515
+ }
516
+ ),
517
+ /* @__PURE__ */ t(
518
+ j,
519
+ {
520
+ type: "button",
521
+ variant: "outline",
522
+ size: "sm",
523
+ className: "mt-2 h-7 text-[12px]",
524
+ onClick: () => {
525
+ var i;
526
+ return (i = document.getElementById(o)) == null ? void 0 : i.click();
527
+ },
528
+ children: "Select files"
529
+ }
530
+ )
531
+ ] }),
532
+ u.length > 0 && /* @__PURE__ */ t("ul", { className: "space-y-1", children: u.map((i) => /* @__PURE__ */ l(
533
+ "li",
534
+ {
535
+ className: "flex items-center gap-2 rounded-[5px] border border-border bg-background px-2 py-1.5",
536
+ children: [
537
+ /* @__PURE__ */ t(bn, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
538
+ /* @__PURE__ */ t("span", { className: "min-w-0 flex-1 truncate text-[12px]", children: i.originalName || i.name }),
539
+ /* @__PURE__ */ t(
540
+ "button",
541
+ {
542
+ type: "button",
543
+ "aria-label": `Remove ${i.originalName || i.name}`,
544
+ onClick: () => c(i.id),
545
+ className: "inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-muted hover:text-foreground",
546
+ children: /* @__PURE__ */ t(ce, { className: "h-3 w-3" })
547
+ }
548
+ )
549
+ ]
550
+ },
551
+ i.id
552
+ )) })
553
+ ] });
554
+ }
555
+ function Aa({
556
+ connection: e,
557
+ selectedEntities: n,
558
+ onSelectionChange: a
559
+ }) {
560
+ const [o, u] = H(""), [d, c] = H(""), [i, r] = H("api"), p = n.filter(
561
+ (y) => y.connectionId === e.id && y.type === "url"
562
+ ), f = () => {
563
+ const y = o.trim(), h = d.trim();
564
+ if (!y || !h) return;
565
+ const N = {
566
+ id: `url-${Date.now()}-${Math.random()}`,
567
+ name: y,
568
+ type: "url",
569
+ connectionId: e.id,
570
+ connectionType: e.type,
571
+ label: y,
572
+ description: `URL source of type ${i}`,
573
+ originalName: y,
574
+ url: h,
575
+ sourceType: i
576
+ };
577
+ a([...n, N]), u(""), c(""), r("api");
578
+ }, k = (y) => {
579
+ a(
580
+ n.filter(
581
+ (h) => !("id" in h && h.id === y && h.connectionId === e.id && h.type === "url")
582
+ )
583
+ );
584
+ };
585
+ return /* @__PURE__ */ l("div", { className: "space-y-2 px-8 py-2", children: [
586
+ /* @__PURE__ */ l("div", { className: "space-y-2 rounded-[6px] border border-border bg-muted/20 p-3", children: [
587
+ /* @__PURE__ */ t(
588
+ Ne,
589
+ {
590
+ value: o,
591
+ onChange: (y) => u(y.target.value),
592
+ placeholder: "Source name",
593
+ className: "h-7 text-[12px]"
594
+ }
595
+ ),
596
+ /* @__PURE__ */ t(
597
+ Ne,
598
+ {
599
+ value: d,
600
+ onChange: (y) => c(y.target.value),
601
+ placeholder: "https://api.example.com/data",
602
+ className: "h-7 text-[12px]"
603
+ }
604
+ ),
605
+ /* @__PURE__ */ l("div", { className: "flex items-center gap-2", children: [
606
+ /* @__PURE__ */ l(
607
+ "select",
608
+ {
609
+ value: i,
610
+ onChange: (y) => r(y.target.value),
611
+ className: "h-7 flex-1 rounded-control border border-input bg-background px-2 text-[12px]",
612
+ children: [
613
+ /* @__PURE__ */ t("option", { value: "api", children: "API endpoint" }),
614
+ /* @__PURE__ */ t("option", { value: "csv", children: "CSV file" }),
615
+ /* @__PURE__ */ t("option", { value: "json", children: "JSON file" })
616
+ ]
617
+ }
618
+ ),
619
+ /* @__PURE__ */ l(
620
+ j,
621
+ {
622
+ type: "button",
623
+ size: "sm",
624
+ className: "h-7 text-[12px]",
625
+ disabled: !o.trim() || !d.trim(),
626
+ onClick: f,
627
+ children: [
628
+ /* @__PURE__ */ t(Ve, { className: "mr-1 h-3 w-3" }),
629
+ "Add"
630
+ ]
631
+ }
632
+ )
633
+ ] })
634
+ ] }),
635
+ p.length > 0 && /* @__PURE__ */ t("ul", { className: "space-y-1", children: p.map((y) => /* @__PURE__ */ l(
636
+ "li",
637
+ {
638
+ className: "flex items-center gap-2 rounded-[5px] border border-border bg-background px-2 py-1.5",
639
+ children: [
640
+ /* @__PURE__ */ t(vn, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
641
+ /* @__PURE__ */ l("div", { className: "min-w-0 flex-1", children: [
642
+ /* @__PURE__ */ t("p", { className: "truncate text-[12px]", children: y.name }),
643
+ /* @__PURE__ */ t("p", { className: "truncate text-[11px] text-muted-foreground", children: y.url })
644
+ ] }),
645
+ /* @__PURE__ */ t(
646
+ "button",
647
+ {
648
+ type: "button",
649
+ "aria-label": `Remove ${y.name}`,
650
+ onClick: () => k(y.id),
651
+ className: "inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-muted hover:text-foreground",
652
+ children: /* @__PURE__ */ t(ce, { className: "h-3 w-3" })
653
+ }
654
+ )
655
+ ]
656
+ },
657
+ y.id
658
+ )) })
659
+ ] });
660
+ }
661
+ function $a({
662
+ connection: e,
663
+ requiresSchema: n,
664
+ search: a,
665
+ selectedEntities: o,
666
+ onSelectionChange: u
667
+ }) {
668
+ var i;
669
+ const d = Be("/v1/databases", { connection_id: e.id }, [
670
+ "databases",
671
+ e.id
672
+ ]);
673
+ if (d.isLoading)
674
+ return /* @__PURE__ */ t("div", { className: "px-8 py-1.5 text-[11px] text-muted-foreground", children: "Loading databases…" });
675
+ const c = ((i = d.data) == null ? void 0 : i.databases) ?? [];
676
+ return c.length === 0 ? /* @__PURE__ */ t("div", { className: "px-8 py-1.5 text-[11px] text-muted-foreground", children: "No databases." }) : /* @__PURE__ */ t("div", { children: c.map((r) => /* @__PURE__ */ t(
677
+ nn,
678
+ {
679
+ label: r.database_name,
680
+ indentLevel: 1,
681
+ search: a,
682
+ renderChildren: (p) => p && (n ? /* @__PURE__ */ t(
683
+ tn,
684
+ {
685
+ connection: e,
686
+ databaseName: r.database_name,
687
+ search: a,
688
+ selectedEntities: o,
689
+ onSelectionChange: u
690
+ }
691
+ ) : /* @__PURE__ */ t(
692
+ pt,
693
+ {
694
+ connection: e,
695
+ databaseName: r.database_name,
696
+ schemaName: "",
697
+ search: a,
698
+ selectedEntities: o,
699
+ onSelectionChange: u
700
+ }
701
+ ))
702
+ },
703
+ r.database_name
704
+ )) });
705
+ }
706
+ function tn({
707
+ connection: e,
708
+ databaseName: n,
709
+ search: a,
710
+ selectedEntities: o,
711
+ onSelectionChange: u
712
+ }) {
713
+ var i;
714
+ const d = Be(
715
+ "/v1/schemas",
716
+ {
717
+ connection_id: e.id,
718
+ database_name: n || "NA"
719
+ },
720
+ ["schemas", e.id, n],
721
+ !!e.id
722
+ );
723
+ if (d.isLoading)
724
+ return /* @__PURE__ */ t("div", { className: "px-8 py-1.5 text-[11px] text-muted-foreground", children: "Loading schemas…" });
725
+ const c = ((i = d.data) == null ? void 0 : i.schemas) ?? [];
726
+ return c.length === 0 ? /* @__PURE__ */ t("div", { className: "px-8 py-1.5 text-[11px] text-muted-foreground", children: "No schemas." }) : /* @__PURE__ */ t("div", { children: c.map((r) => /* @__PURE__ */ t(
727
+ nn,
728
+ {
729
+ label: r.schema_name,
730
+ indentLevel: n ? 2 : 1,
731
+ search: a,
732
+ renderChildren: (p) => p && /* @__PURE__ */ t(
733
+ pt,
734
+ {
735
+ connection: e,
736
+ databaseName: n,
737
+ schemaName: r.schema_name,
738
+ search: a,
739
+ selectedEntities: o,
740
+ onSelectionChange: u
741
+ }
742
+ )
743
+ },
744
+ r.schema_name
745
+ )) });
746
+ }
747
+ function pt({
748
+ connection: e,
749
+ databaseName: n,
750
+ schemaName: a,
751
+ search: o,
752
+ selectedEntities: u,
753
+ onSelectionChange: d
754
+ }) {
755
+ const c = Be(
756
+ "/v1/tables",
757
+ {
758
+ connection_id: e.id,
759
+ database_name: n || void 0,
760
+ schema_name: a || void 0
761
+ },
762
+ ["tables", e.id, n, a]
763
+ ), i = Q(() => {
764
+ var S;
765
+ const h = ((S = c.data) == null ? void 0 : S.tables) ?? [];
766
+ if (!o) return h;
767
+ const N = o.trim().toLowerCase();
768
+ return h.filter((w) => w.table_name.toLowerCase().includes(N));
769
+ }, [c.data, o]), r = (h, N) => ({
770
+ connectionId: e.id,
771
+ connectionType: e.type,
772
+ type: "table",
773
+ dialect: e.dialect,
774
+ database: n || void 0,
775
+ schema: a || void 0,
776
+ name: h,
777
+ dbObjectType: N == null ? void 0 : N.toLowerCase()
778
+ });
779
+ if (c.isLoading)
780
+ return /* @__PURE__ */ t("div", { className: "px-10 py-1.5 text-[11px] text-muted-foreground", children: "Loading tables…" });
781
+ if (i.length === 0)
782
+ return o ? null : /* @__PURE__ */ t("div", { className: "px-10 py-1.5 text-[11px] text-muted-foreground", children: "No tables." });
783
+ const p = i.map(
784
+ (h) => r(h.table_name, h.table_type)
785
+ ), f = p.length > 0 && p.every(
786
+ (h) => u.some((N) => X(N, h))
787
+ ), k = (h, N) => {
788
+ const S = r(h, N), w = u.some(
789
+ (V) => X(V, S)
790
+ );
791
+ d(
792
+ w ? u.filter((V) => !X(V, S)) : [...u, S]
793
+ );
794
+ }, y = () => {
795
+ if (p.length === 0) return;
796
+ if (f) {
797
+ d(
798
+ u.filter(
799
+ (N) => !p.some(
800
+ (S) => X(N, S)
801
+ )
802
+ )
803
+ );
804
+ return;
805
+ }
806
+ const h = [...u];
807
+ for (const N of p)
808
+ h.some((S) => X(S, N)) || h.push(N);
809
+ d(h);
810
+ };
811
+ return /* @__PURE__ */ l("ul", { children: [
812
+ /* @__PURE__ */ l("li", { className: "flex items-center justify-between gap-2 py-1 pl-12 pr-4", children: [
813
+ /* @__PURE__ */ l("span", { className: "text-[10.5px] font-medium uppercase tracking-[0.06em] text-muted-foreground", children: [
814
+ i.length,
815
+ " table",
816
+ i.length === 1 ? "" : "s"
817
+ ] }),
818
+ /* @__PURE__ */ t(
819
+ "button",
820
+ {
821
+ type: "button",
822
+ onClick: y,
823
+ className: "rounded-[3px] px-1.5 py-0.5 text-[10.5px] font-medium text-muted-foreground hover:bg-muted hover:text-foreground",
824
+ children: f ? "Clear" : "Select all"
825
+ }
826
+ )
827
+ ] }),
828
+ i.map((h) => {
829
+ const N = r(h.table_name, h.table_type), S = u.some(
830
+ (w) => X(w, N)
831
+ );
832
+ return /* @__PURE__ */ t("li", { children: /* @__PURE__ */ l("label", { className: "flex cursor-pointer items-center gap-2.5 py-1.5 pl-12 pr-4 transition-colors hover:bg-muted/40", children: [
833
+ /* @__PURE__ */ t(
834
+ Ge,
835
+ {
836
+ checked: S,
837
+ onCheckedChange: () => k(h.table_name, h.table_type),
838
+ className: "h-3.5 w-3.5 shrink-0"
839
+ }
840
+ ),
841
+ /* @__PURE__ */ t(
842
+ un,
843
+ {
844
+ className: "h-3.5 w-3.5 shrink-0 text-muted-foreground",
845
+ strokeWidth: 1.75
846
+ }
847
+ ),
848
+ /* @__PURE__ */ l("div", { className: "flex min-w-0 flex-1 items-baseline gap-1.5", children: [
849
+ /* @__PURE__ */ t("span", { className: "truncate text-[13px] text-foreground/90", children: h.table_name }),
850
+ /* @__PURE__ */ t("span", { className: "shrink-0 font-mono text-[10px] uppercase tracking-[0.06em] text-muted-foreground/70", children: h.table_type ?? "table" })
851
+ ] })
852
+ ] }) }, h.table_name);
853
+ })
854
+ ] });
855
+ }
856
+ function Fa({
857
+ connection: e,
858
+ search: n,
859
+ selectedEntities: a,
860
+ onSelectionChange: o
861
+ }) {
862
+ const u = Be("/v1/datamodels", { connection_id: e.id }, [
863
+ "datamodels",
864
+ e.id
865
+ ]), d = Q(() => {
866
+ var p;
867
+ const i = ((p = u.data) == null ? void 0 : p.datamodels) ?? [];
868
+ if (!n) return i;
869
+ const r = n.trim().toLowerCase();
870
+ return i.filter(
871
+ (f) => `${f.label ?? ""} ${f.name ?? ""} ${f.description ?? ""}`.toLowerCase().includes(r)
872
+ );
873
+ }, [u.data, n]);
874
+ if (u.isLoading || d.length === 0) return null;
875
+ const c = (i) => {
876
+ const r = {
877
+ id: i.id,
878
+ name: i.name,
879
+ label: i.label || "",
880
+ description: i.description || "",
881
+ connectionId: e.id,
882
+ connectionType: e.type,
883
+ type: "model",
884
+ dialect: i.dialect ?? e.dialect,
885
+ database: i.database || "",
886
+ schema: i.schema || ""
887
+ }, p = a.some(
888
+ (f) => X(f, r)
889
+ );
890
+ o(
891
+ p ? a.filter((f) => !X(f, r)) : [...a, r]
892
+ );
893
+ };
894
+ return /* @__PURE__ */ l("div", { children: [
895
+ /* @__PURE__ */ t("div", { className: "px-8 pb-1 pt-2", children: /* @__PURE__ */ t("p", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Data models" }) }),
896
+ /* @__PURE__ */ t("ul", { children: d.map((i) => {
897
+ const r = {
898
+ id: i.id,
899
+ name: i.name,
900
+ label: i.label || "",
901
+ description: i.description || "",
902
+ connectionId: e.id,
903
+ connectionType: e.type,
904
+ type: "model",
905
+ dialect: i.dialect ?? e.dialect,
906
+ database: i.database || "",
907
+ schema: i.schema || ""
908
+ }, p = a.some(
909
+ (f) => X(f, r)
910
+ );
911
+ return /* @__PURE__ */ t("li", { children: /* @__PURE__ */ l("label", { className: "flex cursor-pointer items-start gap-2.5 py-1.5 pl-12 pr-4 transition-colors hover:bg-muted/40", children: [
912
+ /* @__PURE__ */ t(
913
+ Ge,
914
+ {
915
+ checked: p,
916
+ onCheckedChange: () => c(i),
917
+ className: "mt-[2px] h-3.5 w-3.5 shrink-0"
918
+ }
919
+ ),
920
+ /* @__PURE__ */ t(
921
+ ga,
922
+ {
923
+ className: "mt-[2px] h-3.5 w-3.5 shrink-0 text-muted-foreground",
924
+ strokeWidth: 1.75
925
+ }
926
+ ),
927
+ /* @__PURE__ */ l("div", { className: "min-w-0 flex-1", children: [
928
+ /* @__PURE__ */ l("div", { className: "flex items-baseline gap-1.5", children: [
929
+ /* @__PURE__ */ t("span", { className: "truncate text-[13px] text-foreground/90", children: i.label || i.name }),
930
+ /* @__PURE__ */ t("span", { className: "shrink-0 font-mono text-[10px] uppercase tracking-[0.06em] text-muted-foreground/70", children: "model" })
931
+ ] }),
932
+ i.description && /* @__PURE__ */ t("p", { className: "mt-0.5 line-clamp-2 text-[11px] leading-[1.4] text-muted-foreground", children: i.description })
933
+ ] })
934
+ ] }) }, i.id);
935
+ }) })
936
+ ] });
937
+ }
938
+ function nn({
939
+ label: e,
940
+ indentLevel: n,
941
+ search: a,
942
+ renderChildren: o
943
+ }) {
944
+ const [u, d] = H(!1), c = u || a.length > 0;
945
+ return /* @__PURE__ */ l("div", { children: [
946
+ /* @__PURE__ */ l(
947
+ "button",
948
+ {
949
+ type: "button",
950
+ onClick: () => d((r) => !r),
951
+ className: M(
952
+ "flex h-6 w-full items-center gap-1.5 pr-4 text-left transition-colors hover:bg-muted/40",
953
+ n === 1 ? "pl-8" : "pl-10"
954
+ ),
955
+ children: [
956
+ /* @__PURE__ */ t(
957
+ Ie,
958
+ {
959
+ className: M(
960
+ "h-2.5 w-2.5 shrink-0 text-muted-foreground transition-transform",
961
+ c && "rotate-90"
962
+ ),
963
+ strokeWidth: 1.75
964
+ }
965
+ ),
966
+ /* @__PURE__ */ t("span", { className: "truncate font-mono text-[11px] text-muted-foreground", children: e })
967
+ ]
968
+ }
969
+ ),
970
+ o(c)
971
+ ] });
972
+ }
973
+ function Be(e, n, a, o = !0) {
974
+ const { tokenProps: u } = ct(), d = ut((i) => i.authToken), c = Q(
975
+ () => Object.fromEntries(
976
+ Object.entries(n).filter(([, i]) => i !== void 0)
977
+ ),
978
+ [n]
979
+ );
980
+ return _t({
981
+ queryKey: a,
982
+ queryFn: () => Wt(
983
+ `${u.apiServiceUrl}${e}`,
984
+ (d == null ? void 0 : d.accessToken) || "",
985
+ c
986
+ ),
987
+ enabled: o && !!(d != null && d.accessToken) && Object.values(c).every((i) => i.length > 0)
988
+ });
989
+ }
990
+ function Oa(e) {
991
+ return e.type === "dataset" && e.label || e.name;
992
+ }
993
+ function _a(e, n) {
994
+ if (!(e.type !== "dataset" || !e.domainId || !n))
995
+ return n.get(e.domainId);
996
+ }
997
+ function Va({
998
+ selectedEntities: e,
999
+ onDeselectEntity: n,
1000
+ semanticDomainLabels: a
1001
+ }) {
1002
+ return e.length === 0 ? null : /* @__PURE__ */ t("div", { className: "flex flex-wrap gap-1", children: e.map((o, u) => /* @__PURE__ */ t(
1003
+ Ra,
1004
+ {
1005
+ entity: o,
1006
+ semanticDomainLabels: a,
1007
+ onDeselect: n
1008
+ },
1009
+ `${o.type}-${o.name}-${u}`
1010
+ )) });
1011
+ }
1012
+ function Ra({
1013
+ entity: e,
1014
+ semanticDomainLabels: n,
1015
+ onDeselect: a
1016
+ }) {
1017
+ const o = Oa(e), u = _a(e, n), d = u ? `${o} from ${u}` : o;
1018
+ return /* @__PURE__ */ l(
1019
+ "span",
1020
+ {
1021
+ className: "inline-flex items-center gap-1 rounded-control border border-input bg-muted/50 py-0.5 pl-1.5 pr-0.5 text-[11px] text-foreground/80",
1022
+ title: d,
1023
+ children: [
1024
+ /* @__PURE__ */ l("span", { className: "max-w-[180px] truncate", children: [
1025
+ o,
1026
+ u ? /* @__PURE__ */ l("span", { className: "text-muted-foreground", children: [
1027
+ " · ",
1028
+ u
1029
+ ] }) : null
1030
+ ] }),
1031
+ /* @__PURE__ */ t(
1032
+ "button",
1033
+ {
1034
+ type: "button",
1035
+ onClick: (c) => {
1036
+ c.stopPropagation(), a(e);
1037
+ },
1038
+ "aria-label": `Remove ${d}`,
1039
+ className: "inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-control text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
1040
+ children: /* @__PURE__ */ t(ce, { className: "h-2.5 w-2.5" })
1041
+ }
1042
+ )
1043
+ ]
1044
+ }
1045
+ );
1046
+ }
1047
+ function Xe(e) {
1048
+ if (e != null && e.length)
1049
+ return e.every((n) => n.type === "dataset") ? "semanticDomain" : e.every((n) => n.type === "url") ? "url" : e.every(
1050
+ (n) => n.type === "upload" || n.type === "file"
1051
+ ) ? "upload" : "database";
1052
+ }
1053
+ function Cr({
1054
+ open: e,
1055
+ onOpenChange: n,
1056
+ dataSource: a,
1057
+ incomingSelectedEntities: o,
1058
+ onDataSourceChange: u
1059
+ }) {
1060
+ var Se, me;
1061
+ const { tokenProps: d } = ct(), c = d.config, i = d.semanticDomainAccess || Hn, [r, p] = H([]), [f, k] = H(""), [y, h] = H("all"), [N, S] = H(
1062
+ void 0
1063
+ ), w = Ae(!1), { updateDataSource: V } = Rt(), U = u ?? V, O = i.mode, T = (c == null ? void 0 : c.showDirectSource) !== !1, Y = O === "include" || O === "exclude" || !T, Z = O !== "all", m = T && !Y, I = Y ? "semanticDomain" : a.mode, A = !T, D = O === "include" && (((Se = i.domainIds) == null ? void 0 : Se.length) || 0) === 1 ? (me = i.domainIds) == null ? void 0 : me[0] : void 0, b = ne(
1064
+ ($) => {
1065
+ w.current = !0, U({
1066
+ ...a,
1067
+ connectionId: (a == null ? void 0 : a.connectionId) || "",
1068
+ connectionType: (a == null ? void 0 : a.connectionType) || "",
1069
+ mode: $,
1070
+ selectedEntities: (a == null ? void 0 : a.selectedEntities) || [],
1071
+ ...$ !== "semanticDomain" && { semanticDomainId: void 0 }
1072
+ });
1073
+ },
1074
+ [a, U]
1075
+ ), x = ne(
1076
+ ($) => {
1077
+ U({
1078
+ ...a,
1079
+ ...$
1080
+ });
1081
+ },
1082
+ [a, U]
1083
+ );
1084
+ de(() => {
1085
+ var v;
1086
+ if (Y && a.mode !== "semanticDomain") {
1087
+ b("semanticDomain");
1088
+ return;
1089
+ }
1090
+ if (!Z || I !== "semanticDomain") return;
1091
+ const $ = i.domainIds ?? [], ae = (((v = a.selectedEntities) == null ? void 0 : v.length) ?? 0) > 0, s = ((r == null ? void 0 : r.length) ?? 0) > 0;
1092
+ Na({
1093
+ mode: O,
1094
+ currentDomainId: a.semanticDomainId,
1095
+ scopedDomainIds: $,
1096
+ hasSelectedEntities: ae
1097
+ }) && (x({
1098
+ semanticDomainId: void 0,
1099
+ selectedEntities: []
1100
+ }), s && p([]));
1101
+ }, [
1102
+ Y,
1103
+ Z,
1104
+ I,
1105
+ a.mode,
1106
+ a.semanticDomainId,
1107
+ a.selectedEntities,
1108
+ r,
1109
+ i.domainIds,
1110
+ O,
1111
+ x,
1112
+ b
1113
+ ]), de(() => {
1114
+ D && !a.semanticDomainId && x({ semanticDomainId: D });
1115
+ }, [D, a.semanticDomainId, x]), de(() => {
1116
+ if (!e) {
1117
+ w.current = !1, k(""), S(void 0), h(Y ? "semantic" : "all");
1118
+ return;
1119
+ }
1120
+ w.current || (p([...o || []]), S(
1121
+ Xe(o)
1122
+ ));
1123
+ }, [e, o, Y]);
1124
+ const z = ($) => {
1125
+ w.current = !0, p(
1126
+ r.filter((ae) => !X(ae, $))
1127
+ );
1128
+ }, C = ne(
1129
+ ($, ae) => {
1130
+ w.current = !0, p($), S(
1131
+ ae ?? Xe($)
1132
+ );
1133
+ },
1134
+ []
1135
+ ), G = () => {
1136
+ var ae, s;
1137
+ const $ = Xe(r) ?? N ?? I;
1138
+ if ($ === "semanticDomain") {
1139
+ const g = Jt(r) || a.semanticDomainId, v = ((ae = r == null ? void 0 : r[0]) == null ? void 0 : ae.connectionId) || a.connectionId, L = ((s = r == null ? void 0 : r[0]) == null ? void 0 : s.connectionType) || a.connectionType;
1140
+ U({
1141
+ ...a,
1142
+ mode: "semanticDomain",
1143
+ semanticDomainId: g,
1144
+ connectionId: v,
1145
+ connectionType: L,
1146
+ selectedEntities: r
1147
+ });
1148
+ } else if ($ === "upload" || $ === "url") {
1149
+ const g = r == null ? void 0 : r[0];
1150
+ U({
1151
+ ...a,
1152
+ mode: $,
1153
+ semanticDomainId: void 0,
1154
+ connectionId: (g == null ? void 0 : g.connectionId) || a.connectionId,
1155
+ connectionType: (g == null ? void 0 : g.connectionType) || a.connectionType,
1156
+ selectedEntities: r
1157
+ });
1158
+ } else {
1159
+ const g = r == null ? void 0 : r[0];
1160
+ U({
1161
+ ...a,
1162
+ mode: "database",
1163
+ semanticDomainId: void 0,
1164
+ connectionId: (g == null ? void 0 : g.connectionId) || a.connectionId,
1165
+ connectionType: (g == null ? void 0 : g.connectionType) || a.connectionType,
1166
+ selectedEntities: r
1167
+ });
1168
+ }
1169
+ n(!1);
1170
+ }, { semanticDomains: _ } = Zt(), { connections: K } = Vt(), ee = Q(
1171
+ () => new Map(
1172
+ _.map(($) => [
1173
+ $.id,
1174
+ $.label || $.name
1175
+ ])
1176
+ ),
1177
+ [_]
1178
+ ), q = ($) => {
1179
+ h($), $ === "semantic" || $.startsWith("domain:") ? a.mode !== "semanticDomain" && b("semanticDomain") : ($ === "direct" || $.startsWith("conn:")) && a.mode === "semanticDomain" && b("database");
1180
+ }, J = y.startsWith("domain:"), te = y.startsWith("conn:"), We = J ? y.slice(7) : void 0, Ke = te ? y.slice(5) : void 0, oe = !m || y === "all" || y === "semantic" || J, Te = T && !Y && (y === "all" || y === "direct" || te), ue = ((o == null ? void 0 : o.length) ?? 0) > 0, Ce = r.length === 0 && !ue, we = r.length === 0 && ue ? "Clear" : "Add", ke = A ? "Select dataset" : "Add data";
1181
+ return /* @__PURE__ */ t(yn, { open: e, onOpenChange: n, children: /* @__PURE__ */ l(
1182
+ Nn,
1183
+ {
1184
+ showCloseButton: !1,
1185
+ className: "flex h-[560px] w-[620px] max-w-[620px] flex-col gap-0 overflow-hidden rounded-[6px] border border-border bg-popover p-0",
1186
+ children: [
1187
+ /* @__PURE__ */ t(mn, { children: /* @__PURE__ */ t(Cn, { children: ke }) }),
1188
+ /* @__PURE__ */ l("div", { className: "flex items-start justify-between border-b border-border px-4 py-2.5", children: [
1189
+ /* @__PURE__ */ l("div", { children: [
1190
+ /* @__PURE__ */ t("p", { className: "text-[14px] font-semibold text-foreground", children: ke }),
1191
+ /* @__PURE__ */ t("p", { className: "text-[11px] text-muted-foreground", children: A ? "Choose a curated dataset to analyze" : "Search your semantic domains and connections" })
1192
+ ] }),
1193
+ /* @__PURE__ */ t(
1194
+ "button",
1195
+ {
1196
+ type: "button",
1197
+ onClick: () => n(!1),
1198
+ "aria-label": "Close",
1199
+ className: "inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-[4px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
1200
+ children: /* @__PURE__ */ t(ce, { className: "h-3.5 w-3.5" })
1201
+ }
1202
+ )
1203
+ ] }),
1204
+ /* @__PURE__ */ l("div", { className: "border-b border-border px-4 py-2.5", children: [
1205
+ /* @__PURE__ */ l("div", { className: "flex h-7 items-center gap-1.5 rounded-control border border-input bg-background px-2 focus-within:border-ring", children: [
1206
+ /* @__PURE__ */ t(wn, { className: "h-3 w-3 shrink-0 text-muted-foreground" }),
1207
+ /* @__PURE__ */ t(
1208
+ "input",
1209
+ {
1210
+ type: "text",
1211
+ value: f,
1212
+ onChange: ($) => k($.target.value),
1213
+ placeholder: "Search datasets, tables, views, models",
1214
+ className: "h-full w-full bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground/60 focus:outline-none"
1215
+ }
1216
+ ),
1217
+ f && /* @__PURE__ */ t(
1218
+ "button",
1219
+ {
1220
+ type: "button",
1221
+ onClick: () => k(""),
1222
+ "aria-label": "Clear search",
1223
+ className: "inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-control text-muted-foreground hover:bg-muted hover:text-foreground",
1224
+ children: /* @__PURE__ */ t(ce, { className: "h-3 w-3" })
1225
+ }
1226
+ )
1227
+ ] }),
1228
+ m && // Horizontal scroll strip — chips stay on a single row
1229
+ // regardless of how many sources exist. Mock canon: the
1230
+ // chip rail never grows the picker's header height.
1231
+ /* @__PURE__ */ t("div", { className: "-mx-4 mt-2 overflow-x-auto px-4 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden", children: /* @__PURE__ */ l("div", { className: "flex w-max items-center gap-1", children: [
1232
+ /* @__PURE__ */ t(
1233
+ De,
1234
+ {
1235
+ label: "All",
1236
+ active: y === "all",
1237
+ onClick: () => q("all")
1238
+ }
1239
+ ),
1240
+ (_.length > 0 || K.length > 0) && /* @__PURE__ */ l(fe, { children: [
1241
+ /* @__PURE__ */ t(
1242
+ De,
1243
+ {
1244
+ label: "Semantic",
1245
+ active: y === "semantic",
1246
+ onClick: () => q("semantic")
1247
+ }
1248
+ ),
1249
+ /* @__PURE__ */ t(
1250
+ De,
1251
+ {
1252
+ label: "Direct",
1253
+ active: y === "direct",
1254
+ onClick: () => q("direct")
1255
+ }
1256
+ ),
1257
+ /* @__PURE__ */ t("span", { className: "shrink-0 px-0.5 text-muted-foreground/50", children: "·" })
1258
+ ] }),
1259
+ _.map(($) => /* @__PURE__ */ t(
1260
+ De,
1261
+ {
1262
+ label: $.label || $.name,
1263
+ active: y === `domain:${$.id}`,
1264
+ onClick: () => q(`domain:${$.id}`)
1265
+ },
1266
+ `domain:${$.id}`
1267
+ )),
1268
+ K.map(($) => /* @__PURE__ */ t(
1269
+ De,
1270
+ {
1271
+ label: $.name,
1272
+ active: y === `conn:${$.id}`,
1273
+ onClick: () => q(`conn:${$.id}`)
1274
+ },
1275
+ `conn:${$.id}`
1276
+ ))
1277
+ ] }) })
1278
+ ] }),
1279
+ /* @__PURE__ */ l("div", { className: "flex-1 overflow-y-auto py-1", children: [
1280
+ oe && /* @__PURE__ */ t(
1281
+ ka,
1282
+ {
1283
+ domainAccess: i,
1284
+ search: f,
1285
+ scopeDomainId: We,
1286
+ selectedEntities: r,
1287
+ onSelectionChange: ($) => C($, "semanticDomain")
1288
+ }
1289
+ ),
1290
+ Te && /* @__PURE__ */ t(
1291
+ Ia,
1292
+ {
1293
+ search: f,
1294
+ scopeConnectionId: Ke,
1295
+ selectedEntities: r,
1296
+ onSelectionChange: ($) => C($)
1297
+ }
1298
+ )
1299
+ ] }),
1300
+ /* @__PURE__ */ l("div", { className: "flex flex-col gap-0.5 border-t border-border px-4 py-2.5", children: [
1301
+ /* @__PURE__ */ l("div", { className: "flex items-center justify-between gap-3", children: [
1302
+ /* @__PURE__ */ l("div", { className: "flex items-center gap-1.5 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: [
1303
+ /* @__PURE__ */ t("span", { children: "Selected" }),
1304
+ /* @__PURE__ */ l("span", { className: "font-mono tabular-nums text-muted-foreground/70", children: [
1305
+ "· ",
1306
+ r.length
1307
+ ] })
1308
+ ] }),
1309
+ /* @__PURE__ */ l("div", { className: "flex items-center gap-1.5", children: [
1310
+ /* @__PURE__ */ t(
1311
+ "button",
1312
+ {
1313
+ type: "button",
1314
+ onClick: () => n(!1),
1315
+ className: "inline-flex h-7 items-center rounded-control px-2.5 text-[12px] font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
1316
+ children: "Cancel"
1317
+ }
1318
+ ),
1319
+ /* @__PURE__ */ l(
1320
+ "button",
1321
+ {
1322
+ type: "button",
1323
+ onClick: G,
1324
+ disabled: Ce,
1325
+ className: M(
1326
+ "inline-flex h-7 items-center gap-1.5 rounded-control bg-primary px-2.5 text-[12px] font-medium text-primary-foreground transition-colors hover:bg-primary/90",
1327
+ Ce && "cursor-not-allowed opacity-50 hover:bg-primary"
1328
+ ),
1329
+ children: [
1330
+ /* @__PURE__ */ t("span", { children: we }),
1331
+ r.length > 0 && /* @__PURE__ */ l("span", { className: "font-mono tabular-nums text-primary-foreground/70", children: [
1332
+ "· ",
1333
+ r.length
1334
+ ] })
1335
+ ]
1336
+ }
1337
+ )
1338
+ ] })
1339
+ ] }),
1340
+ r.length > 0 && /* @__PURE__ */ t(
1341
+ Va,
1342
+ {
1343
+ selectedEntities: r,
1344
+ onDeselectEntity: z,
1345
+ semanticDomainLabels: ee
1346
+ }
1347
+ )
1348
+ ] })
1349
+ ]
1350
+ }
1351
+ ) });
1352
+ }
1353
+ function De({
1354
+ label: e,
1355
+ active: n,
1356
+ onClick: a
1357
+ }) {
1358
+ return /* @__PURE__ */ t(
1359
+ "button",
1360
+ {
1361
+ type: "button",
1362
+ onClick: a,
1363
+ "aria-pressed": n,
1364
+ className: M(
1365
+ "inline-flex h-6 shrink-0 items-center whitespace-nowrap rounded-control px-2 text-[11px] font-medium transition-colors",
1366
+ n ? "bg-primary text-primary-foreground hover:bg-primary/90" : "text-muted-foreground hover:bg-muted hover:text-foreground"
1367
+ ),
1368
+ children: e
1369
+ }
1370
+ );
1371
+ }
1372
+ function wr() {
1373
+ const e = se((c) => c.card.dataSource), {
1374
+ setSelectedConnectionId: n,
1375
+ setSelectedDatabaseName: a,
1376
+ setSelectedSchemaName: o,
1377
+ setSelectedTableName: u,
1378
+ setSelectedDatamodelId: d
1379
+ } = Rt();
1380
+ de(() => {
1381
+ var h;
1382
+ if (!e) return;
1383
+ const { tableName: c, schemaName: i, databaseName: r, connectionId: p } = kn(e), f = (h = e.selectedEntities) == null ? void 0 : h[0], y = (f == null ? void 0 : f.type) === "model" && "id" in f ? f.id : "";
1384
+ n(p || ""), a(r || ""), o(i || ""), u(c || ""), d(y);
1385
+ }, [
1386
+ e,
1387
+ n,
1388
+ a,
1389
+ o,
1390
+ u,
1391
+ d
1392
+ ]);
1393
+ }
1394
+ function kr({
1395
+ type: e,
1396
+ isLinked: n,
1397
+ className: a,
1398
+ showLabel: o = !1,
1399
+ showLocal: u = !1
1400
+ }) {
1401
+ const d = ut((S) => S.selectedFrameId), c = Sn((S) => S.selectedVisual), i = se((S) => S.frame);
1402
+ let r;
1403
+ if (e)
1404
+ r = e;
1405
+ else if (n !== void 0)
1406
+ r = n ? "linked" : "library";
1407
+ else if (!!!(i != null && i.visualId || c != null && c.id) && d)
1408
+ r = "local";
1409
+ else if (c && !d)
1410
+ r = "library";
1411
+ else if (i != null && i.visualId && d)
1412
+ r = "linked";
1413
+ else if (c != null && c.id && d)
1414
+ r = "library";
1415
+ else
1416
+ return null;
1417
+ if (r === "local" && !u)
1418
+ return null;
1419
+ const p = {
1420
+ local: "border-slate-200/70 bg-slate-50/80 text-slate-700 shadow-sm hover:bg-slate-100/80 dark:border-slate-700 dark:bg-slate-900/70 dark:text-slate-200 dark:hover:bg-slate-800/80",
1421
+ linked: "border-purple-200/70 bg-gradient-to-r from-purple-50/50 to-purple-100/30 text-purple-900 shadow-sm hover:from-purple-100/60 hover:to-purple-100/50 hover:shadow-md dark:border-purple-800/50 dark:from-purple-950/40 dark:to-purple-900/30 dark:text-purple-100 dark:hover:from-purple-950/60 dark:hover:to-purple-900/50",
1422
+ library: "border-blue-200/70 bg-gradient-to-r from-blue-50/50 to-blue-100/30 text-blue-900 shadow-sm hover:from-blue-100/60 hover:to-blue-100/50 hover:shadow-md dark:border-blue-800/50 dark:from-blue-950/40 dark:to-blue-900/30 dark:text-blue-100 dark:hover:from-blue-950/60 dark:hover:to-blue-900/50"
1423
+ }, f = {
1424
+ local: "Local to this dashboard: Changes made here only affect this dashboard copy.",
1425
+ linked: "Linked to library: Changes made here update the library visual and all linked instances.",
1426
+ library: "Library visual: Share and reuse this visual across multiple dashboards."
1427
+ }, k = {
1428
+ local: "border-slate-200 bg-slate-50 text-slate-900 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100",
1429
+ linked: "border-purple-200 bg-purple-50 text-purple-900 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-100",
1430
+ library: "border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-100"
1431
+ }, y = {
1432
+ local: "fill-slate-50 dark:fill-slate-900",
1433
+ linked: "fill-purple-50 dark:fill-purple-950",
1434
+ library: "fill-blue-50 dark:fill-blue-950"
1435
+ }, h = {
1436
+ local: /* @__PURE__ */ t("span", { className: "h-2 w-2 rounded-full bg-current/70" }),
1437
+ linked: /* @__PURE__ */ t(va, { className: "h-3.5 w-3.5" }),
1438
+ library: /* @__PURE__ */ t(ba, { className: "h-3.5 w-3.5" })
1439
+ }, N = {
1440
+ local: "Local",
1441
+ linked: "Linked",
1442
+ library: "Library"
1443
+ };
1444
+ return /* @__PURE__ */ t(at, { children: /* @__PURE__ */ l(rt, { delayDuration: 300, children: [
1445
+ /* @__PURE__ */ t(st, { asChild: !0, children: /* @__PURE__ */ l(
1446
+ Dn,
1447
+ {
1448
+ variant: "outline",
1449
+ className: M(
1450
+ "cursor-help select-none transition-all",
1451
+ p[r],
1452
+ a
1453
+ ),
1454
+ children: [
1455
+ h[r],
1456
+ o && /* @__PURE__ */ t("span", { className: "ml-1 text-xs font-medium leading-none", children: N[r] })
1457
+ ]
1458
+ }
1459
+ ) }),
1460
+ /* @__PURE__ */ l(
1461
+ ot,
1462
+ {
1463
+ side: "bottom",
1464
+ className: M("max-w-xs", k[r]),
1465
+ children: [
1466
+ /* @__PURE__ */ t(Ot, { className: y[r] }),
1467
+ /* @__PURE__ */ t("p", { children: f[r] })
1468
+ ]
1469
+ }
1470
+ )
1471
+ ] }) });
1472
+ }
1473
+ const Ea = hn(
1474
+ ({
1475
+ side: e = "bottom",
1476
+ children: n,
1477
+ className: a,
1478
+ tooltip: o,
1479
+ onClick: u,
1480
+ openDelay: d = 300,
1481
+ buttonProps: c,
1482
+ disabled: i,
1483
+ ...r
1484
+ }, p) => /* @__PURE__ */ t(at, { children: /* @__PURE__ */ l(rt, { delayDuration: d, children: [
1485
+ /* @__PURE__ */ t(st, { asChild: !0, children: /* @__PURE__ */ t(
1486
+ j,
1487
+ {
1488
+ disabled: i,
1489
+ ref: p,
1490
+ size: "sm",
1491
+ variant: "ghost",
1492
+ onClick: u,
1493
+ ...r,
1494
+ ...c,
1495
+ className: M(`${Yn}`, a),
1496
+ children: n
1497
+ }
1498
+ ) }),
1499
+ o && /* @__PURE__ */ l(
1500
+ ot,
1501
+ {
1502
+ side: e,
1503
+ sideOffset: 10,
1504
+ className: M(
1505
+ "border-foreground/20 bg-foreground text-background"
1506
+ ),
1507
+ children: [
1508
+ o,
1509
+ /* @__PURE__ */ t(Ot, { className: "fill-foreground" })
1510
+ ]
1511
+ }
1512
+ )
1513
+ ] }) })
1514
+ );
1515
+ Ea.displayName = "IconButton";
1516
+ function Ma(e, n) {
1517
+ var r, p;
1518
+ const a = e.qualifiedFieldName || e.name, o = e.qualifiedFieldName ? e.qualifiedFieldName.split(".").slice(0, -1).join(".") : e.qualifiedEntityName || e.entityName, u = n.connectionId || ((r = n.dataSource) == null ? void 0 : r.connectionId) || "", d = Pn(e), c = Xn(
1519
+ n.dataSource,
1520
+ {
1521
+ connectionId: u,
1522
+ connectionType: (p = n.dataSource) == null ? void 0 : p.connectionType
1523
+ },
1524
+ e
1525
+ ), i = Zn(n.dataSource, c, e) || "";
1526
+ return {
1527
+ column: a,
1528
+ title: Xt(e),
1529
+ dataType: e.dataType,
1530
+ ...e.nativeDataType ? { nativeDataType: e.nativeDataType } : {},
1531
+ table: e.entityName || "",
1532
+ database: i,
1533
+ qualifiedTableName: o,
1534
+ connectionId: u,
1535
+ operation: "in",
1536
+ sql: "",
1537
+ fieldMeta: d,
1538
+ semanticContext: c
1539
+ };
1540
+ }
1541
+ function an(e) {
1542
+ const { control: n, onChange: a } = e;
1543
+ return /* @__PURE__ */ l("div", { className: "flex flex-col gap-1.5", children: [
1544
+ /* @__PURE__ */ t(le, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Label" }),
1545
+ /* @__PURE__ */ t(
1546
+ Ne,
1547
+ {
1548
+ size: "xs",
1549
+ value: n.label,
1550
+ placeholder: "Control label",
1551
+ onChange: (o) => a(o.target.value)
1552
+ }
1553
+ )
1554
+ ] });
1555
+ }
1556
+ function za(e) {
1557
+ const { currentStep: n, labels: a } = e;
1558
+ return /* @__PURE__ */ t("div", { className: "sticky top-0 z-10 -mx-1 border-b border-border/60 bg-background/95 px-1 pb-2.5 pt-1 backdrop-blur supports-[backdrop-filter]:bg-background/85", children: /* @__PURE__ */ t("div", { className: "flex flex-wrap items-center gap-2 sm:gap-2.5", children: a.map((o, u) => {
1559
+ const d = u + 1, c = d === n, i = d < n;
1560
+ return /* @__PURE__ */ l(xn, { children: [
1561
+ /* @__PURE__ */ l("div", { className: "flex items-center gap-1.5", children: [
1562
+ /* @__PURE__ */ t(
1563
+ "span",
1564
+ {
1565
+ className: M(
1566
+ "flex h-5 w-5 items-center justify-center rounded-full border text-[10px] font-medium tabular-nums",
1567
+ c ? "border-foreground bg-foreground text-background" : i ? "border-foreground/30 bg-foreground/10 text-foreground" : "border-border/60 bg-background text-muted-foreground"
1568
+ ),
1569
+ children: d
1570
+ }
1571
+ ),
1572
+ /* @__PURE__ */ t(
1573
+ "span",
1574
+ {
1575
+ className: M(
1576
+ "text-[12px]",
1577
+ c ? "font-medium text-foreground" : "text-muted-foreground"
1578
+ ),
1579
+ children: o
1580
+ }
1581
+ )
1582
+ ] }),
1583
+ u < a.length - 1 ? /* @__PURE__ */ t(
1584
+ "span",
1585
+ {
1586
+ className: "h-px w-4 bg-border/60 sm:w-6",
1587
+ "aria-hidden": "true"
1588
+ }
1589
+ ) : null
1590
+ ] }, o);
1591
+ }) }) });
1592
+ }
1593
+ function je(e) {
1594
+ const { secondary: n, tertiary: a, primary: o } = e;
1595
+ return /* @__PURE__ */ l("div", { className: "sticky bottom-0 z-10 -mx-1 flex justify-end gap-2 border-t bg-background/95 px-1 pb-1 pt-3 backdrop-blur supports-[backdrop-filter]:bg-background/85", children: [
1596
+ n,
1597
+ a,
1598
+ o
1599
+ ] });
1600
+ }
1601
+ function qa(e) {
1602
+ const { control: n, scope: a, detail: o } = e;
1603
+ return /* @__PURE__ */ l("div", { className: "flex items-start gap-2.5 rounded-control border border-border/60 bg-muted/30 px-3 py-2.5", children: [
1604
+ /* @__PURE__ */ t(On, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground" }),
1605
+ /* @__PURE__ */ l("div", { className: "min-w-0 space-y-0.5", children: [
1606
+ /* @__PURE__ */ t("div", { className: "text-[13px] font-medium text-foreground", children: n.label }),
1607
+ /* @__PURE__ */ l("div", { className: "text-[12px] text-muted-foreground", children: [
1608
+ Kt(n.type).label,
1609
+ " ·",
1610
+ " ",
1611
+ Ht(n),
1612
+ " ·",
1613
+ " ",
1614
+ Qt(a, n.placement)
1615
+ ] }),
1616
+ o ? /* @__PURE__ */ t("div", { className: "text-[12px] text-muted-foreground", children: o }) : null
1617
+ ] })
1618
+ ] });
1619
+ }
1620
+ function Tt(e) {
1621
+ const {
1622
+ control: n,
1623
+ defaultValue: a,
1624
+ availableFieldChoices: o,
1625
+ availableMetricChoices: u,
1626
+ previewControlDefinitions: d,
1627
+ previewControlValues: c,
1628
+ onControlChange: i,
1629
+ onLabelChange: r,
1630
+ onDefaultValueChange: p,
1631
+ onBack: f,
1632
+ onNext: k,
1633
+ nextDisabled: y
1634
+ } = e;
1635
+ return /* @__PURE__ */ l("div", { className: "space-y-3", children: [
1636
+ /* @__PURE__ */ t(an, { control: n, onChange: r }),
1637
+ /* @__PURE__ */ t(
1638
+ Mt,
1639
+ {
1640
+ control: n,
1641
+ availableFieldChoices: o,
1642
+ availableMetricChoices: u,
1643
+ previewControlDefinitions: d,
1644
+ previewControlValues: c,
1645
+ controlLifecycle: "create",
1646
+ onChange: i
1647
+ }
1648
+ ),
1649
+ /* @__PURE__ */ t(
1650
+ zt,
1651
+ {
1652
+ control: n,
1653
+ value: a,
1654
+ onChange: p,
1655
+ allowNoDefault: !0,
1656
+ allowCardDefault: !0,
1657
+ hint: "This is the value viewers will see first.",
1658
+ previewControlDefinitions: d,
1659
+ previewControlValues: c
1660
+ }
1661
+ ),
1662
+ /* @__PURE__ */ t(
1663
+ je,
1664
+ {
1665
+ secondary: /* @__PURE__ */ t(j, { type: "button", variant: "outline", size: "xs", onClick: f, children: "Back" }),
1666
+ primary: /* @__PURE__ */ t(
1667
+ j,
1668
+ {
1669
+ type: "button",
1670
+ size: "xs",
1671
+ onClick: k,
1672
+ disabled: y,
1673
+ children: "Next"
1674
+ }
1675
+ )
1676
+ }
1677
+ )
1678
+ ] });
1679
+ }
1680
+ const ja = /* @__PURE__ */ new Set([
1681
+ "grain_selector",
1682
+ "aggregation_selector",
1683
+ "field_selector",
1684
+ "metric_selector"
1685
+ ]);
1686
+ function Lt(e) {
1687
+ const { text: n, ariaLabel: a } = e, [o, u] = H(!1);
1688
+ return /* @__PURE__ */ l(
1689
+ "button",
1690
+ {
1691
+ type: "button",
1692
+ "aria-label": a,
1693
+ onClick: async () => {
1694
+ try {
1695
+ await navigator.clipboard.writeText(n), u(!0), setTimeout(() => u(!1), 1200);
1696
+ } catch (d) {
1697
+ console.error("Failed to copy", d);
1698
+ }
1699
+ },
1700
+ className: "group flex w-full items-center justify-between gap-2 rounded-control bg-muted/40 px-2 py-1 text-left transition-colors hover:bg-muted/60 focus-visible:bg-muted/60 focus-visible:outline-none",
1701
+ children: [
1702
+ /* @__PURE__ */ t("code", { className: "min-w-0 truncate font-mono text-[12px] text-foreground", children: n }),
1703
+ /* @__PURE__ */ t("span", { className: "shrink-0 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100", children: o ? "Copied" : "Click to copy" })
1704
+ ]
1705
+ }
1706
+ );
1707
+ }
1708
+ function At(e) {
1709
+ const {
1710
+ control: n,
1711
+ scope: a,
1712
+ createdReference: o,
1713
+ explorerContent: u,
1714
+ sqlDescription: d,
1715
+ summaryDetail: c,
1716
+ onBack: i,
1717
+ onCancel: r,
1718
+ onDone: p
1719
+ } = e, f = ja.has(n.type), k = o.match(/\[\[param\.(.+?)\]\]/), y = k ? `{{ param('${k[1]}') }}` : "";
1720
+ return /* @__PURE__ */ l("div", { className: "space-y-4", children: [
1721
+ /* @__PURE__ */ t(
1722
+ qa,
1723
+ {
1724
+ control: n,
1725
+ scope: a,
1726
+ detail: c
1727
+ }
1728
+ ),
1729
+ /* @__PURE__ */ l("div", { className: "space-y-2", children: [
1730
+ /* @__PURE__ */ t("p", { className: "text-[13px] font-medium text-foreground", children: "How cards use this control" }),
1731
+ /* @__PURE__ */ l("div", { className: "divide-y divide-border/60 overflow-hidden rounded-control border border-border/60", children: [
1732
+ f ? /* @__PURE__ */ l("div", { className: "space-y-1 px-3 py-2.5", children: [
1733
+ /* @__PURE__ */ t("p", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Explorer cards" }),
1734
+ /* @__PURE__ */ t("div", { className: "text-[12px] text-muted-foreground", children: u })
1735
+ ] }) : null,
1736
+ /* @__PURE__ */ l("div", { className: "space-y-1.5 px-3 py-2.5", children: [
1737
+ /* @__PURE__ */ t("p", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "SQL cards" }),
1738
+ /* @__PURE__ */ t(
1739
+ Lt,
1740
+ {
1741
+ text: o,
1742
+ ariaLabel: "Copy SQL control reference"
1743
+ }
1744
+ ),
1745
+ y ? /* @__PURE__ */ t(
1746
+ Lt,
1747
+ {
1748
+ text: y,
1749
+ ariaLabel: "Copy Jinja control reference"
1750
+ }
1751
+ ) : null,
1752
+ /* @__PURE__ */ l("p", { className: "text-[12px] text-muted-foreground", children: [
1753
+ d,
1754
+ " ",
1755
+ /* @__PURE__ */ t(
1756
+ "a",
1757
+ {
1758
+ href: "https://docs.semaphor.cloud/docs/concepts/template-expressions",
1759
+ target: "_blank",
1760
+ rel: "noreferrer",
1761
+ className: "underline underline-offset-2 hover:text-foreground",
1762
+ children: "Template expressions docs"
1763
+ }
1764
+ ),
1765
+ "."
1766
+ ] })
1767
+ ] })
1768
+ ] })
1769
+ ] }),
1770
+ /* @__PURE__ */ t(
1771
+ je,
1772
+ {
1773
+ secondary: /* @__PURE__ */ t(j, { type: "button", variant: "outline", size: "xs", onClick: i, children: "Back" }),
1774
+ tertiary: /* @__PURE__ */ t(j, { type: "button", variant: "outline", size: "xs", onClick: r, children: "Cancel" }),
1775
+ primary: /* @__PURE__ */ t(j, { type: "button", size: "xs", onClick: p, children: "Done" })
1776
+ }
1777
+ )
1778
+ ] });
1779
+ }
1780
+ function Ua(e) {
1781
+ const n = $e(
1782
+ e.scope,
1783
+ e.existingControls,
1784
+ e.reservedIds
1785
+ ), a = e.type === n.type ? {
1786
+ ...n,
1787
+ label: Ye[e.type]
1788
+ } : {
1789
+ ...Yt({
1790
+ controls: [
1791
+ {
1792
+ ...n,
1793
+ label: Ye[e.type]
1794
+ }
1795
+ ],
1796
+ controlId: n.id,
1797
+ nextType: e.type
1798
+ }).controls[0],
1799
+ label: Ye[e.type]
1800
+ };
1801
+ return {
1802
+ step: 2,
1803
+ control: a,
1804
+ defaultValue: Fe(a, void 0)
1805
+ };
1806
+ }
1807
+ function Sr({
1808
+ scope: e,
1809
+ controls: n,
1810
+ reservedControlIds: a,
1811
+ defaultValues: o,
1812
+ onChange: u,
1813
+ emptyMessage: d,
1814
+ initialCreateFlow: c = !1,
1815
+ usageByControlId: i,
1816
+ availableFieldChoices: r,
1817
+ availableMetricChoices: p,
1818
+ structuralParticipants: f,
1819
+ structuralParticipantIdsByControlId: k,
1820
+ card: y,
1821
+ allowedControlTypes: h,
1822
+ onCreateFlowActiveChange: N,
1823
+ onCreateFlowComplete: S
1824
+ }) {
1825
+ const w = Q(
1826
+ () => new Set(a || []),
1827
+ [a]
1828
+ ), V = sa(e), U = Jn(e), [O, T] = H(
1829
+ null
1830
+ ), [Y, Z] = H(
1831
+ null
1832
+ ), [m, I] = H(
1833
+ () => c ? {
1834
+ step: 1,
1835
+ control: $e(e, n, Array.from(w))
1836
+ } : null
1837
+ ), A = Ae({}), D = Ae(void 0), b = Ae(c), x = Q(() => {
1838
+ const s = Ct({ scope: e, card: y });
1839
+ if (!h)
1840
+ return s;
1841
+ const g = new Set(h);
1842
+ return s.filter((v) => g.has(v.value));
1843
+ }, [h, y, e]), z = ne(
1844
+ (s) => {
1845
+ const g = Ct({
1846
+ scope: e,
1847
+ card: y,
1848
+ includeType: h ? void 0 : s
1849
+ });
1850
+ if (!h)
1851
+ return g;
1852
+ const v = new Set(h);
1853
+ return g.filter((L) => v.has(L.value));
1854
+ },
1855
+ [h, y, e]
1856
+ ), C = ne(
1857
+ (s) => e === "dashboard" && (s === "field_selector" || s === "metric_selector"),
1858
+ [e]
1859
+ ), G = Q(
1860
+ () => m ? wt(
1861
+ f || [],
1862
+ m.control.type
1863
+ ) : [],
1864
+ [m, f]
1865
+ ), _ = Q(() => {
1866
+ if (!m)
1867
+ return {
1868
+ fields: r || [],
1869
+ metrics: p || []
1870
+ };
1871
+ if (!C(m.control.type))
1872
+ return {
1873
+ fields: r || [],
1874
+ metrics: p || []
1875
+ };
1876
+ const s = m.selectedCardIds || [], g = Qe({
1877
+ controlType: m.control.type,
1878
+ participants: f || [],
1879
+ selectedCardIds: s
1880
+ });
1881
+ return {
1882
+ fields: m.control.type === "field_selector" ? g.choices.map((v) => ({
1883
+ option: v,
1884
+ target: g.fieldTargetMap[v.value]
1885
+ })) : [],
1886
+ metrics: m.control.type === "metric_selector" ? g.choices.map((v) => ({
1887
+ option: v,
1888
+ target: g.metricTargetMap[v.value]
1889
+ })) : []
1890
+ };
1891
+ }, [
1892
+ r,
1893
+ p,
1894
+ m,
1895
+ C,
1896
+ f
1897
+ ]);
1898
+ de(() => {
1899
+ N == null || N(!!m);
1900
+ }, [m, N]), de(() => {
1901
+ const s = c && !b.current;
1902
+ b.current = c, s && (I({
1903
+ step: 1,
1904
+ control: $e(e, n, Array.from(w))
1905
+ }), Z(null), T(null));
1906
+ }, [n, c, w, e]);
1907
+ const K = (s) => {
1908
+ if (!C(s.type))
1909
+ return {
1910
+ fields: r || [],
1911
+ metrics: p || []
1912
+ };
1913
+ const g = (k == null ? void 0 : k[s.id]) || [];
1914
+ if (g.length === 0)
1915
+ return {
1916
+ fields: r || [],
1917
+ metrics: p || []
1918
+ };
1919
+ const v = Qe({
1920
+ controlType: s.type,
1921
+ participants: f || [],
1922
+ selectedCardIds: g
1923
+ });
1924
+ return {
1925
+ fields: s.type === "field_selector" ? v.choices.map((L) => ({
1926
+ option: L,
1927
+ target: v.fieldTargetMap[L.value]
1928
+ })) : [],
1929
+ metrics: s.type === "metric_selector" ? v.choices.map((L) => ({
1930
+ option: L,
1931
+ target: v.metricTargetMap[L.value]
1932
+ })) : []
1933
+ };
1934
+ }, ee = (s) => {
1935
+ if (!C(s.control.type))
1936
+ return {
1937
+ nextControl: s.control,
1938
+ cardBindingsById: void 0
1939
+ };
1940
+ const g = (k == null ? void 0 : k[s.control.id]) || [], v = Qe({
1941
+ controlType: s.control.type,
1942
+ participants: f || [],
1943
+ selectedCardIds: s.nextSelectedCardIds
1944
+ }), L = ca({
1945
+ control: s.control,
1946
+ choices: v.choices
1947
+ }), R = Object.fromEntries(
1948
+ g.filter((E) => !s.nextSelectedCardIds.includes(E)).map((E) => [E, void 0])
1949
+ );
1950
+ return s.nextSelectedCardIds.length > 0 && L.source.kind === "manual" && L.source.options.length > 0 && Object.assign(
1951
+ R,
1952
+ It({
1953
+ control: L,
1954
+ participants: f || [],
1955
+ selectedCardIds: s.nextSelectedCardIds,
1956
+ matrixTargetIds: s.matrixTargetIds
1957
+ })
1958
+ ), {
1959
+ nextControl: L,
1960
+ cardBindingsById: R
1961
+ };
1962
+ }, q = ne(
1963
+ (s, g = o, v = { type: "update" }) => {
1964
+ const L = s.map((R) => (He({
1965
+ control: R,
1966
+ defaultValues: g
1967
+ }), ea(
1968
+ R
1969
+ )));
1970
+ u(L, g, v);
1971
+ },
1972
+ [o, u]
1973
+ ), J = (s, g) => {
1974
+ const v = n.find(
1975
+ (W) => W.id === s
1976
+ );
1977
+ let L = n.map((W) => W.id !== s ? W : g(W));
1978
+ const R = L.find(
1979
+ (W) => W.id === s
1980
+ );
1981
+ let E, F;
1982
+ if (R && (!v || la({ control: v }, { control: R })) && e === "dashboard" && (R.type === "field_selector" || R.type === "metric_selector")) {
1983
+ const W = (k == null ? void 0 : k[R.id]) || [], pe = ee({
1984
+ control: R,
1985
+ nextSelectedCardIds: W
1986
+ });
1987
+ L = L.map(
1988
+ (ie) => ie.id === s ? pe.nextControl : ie
1989
+ ), E = pe.cardBindingsById, F = [R.id];
1990
+ } else if (v && (!R || !da(R.type)) && e === "dashboard" && (v.type === "field_selector" || v.type === "metric_selector")) {
1991
+ const W = (k == null ? void 0 : k[v.id]) || [];
1992
+ E = Object.fromEntries(
1993
+ W.map((pe) => [pe, void 0])
1994
+ ), F = [v.id];
1995
+ }
1996
+ const B = L.find(
1997
+ (W) => W.id === s
1998
+ );
1999
+ let P = o;
2000
+ if (v && B) {
2001
+ const W = He({
2002
+ control: v,
2003
+ defaultValues: o
2004
+ });
2005
+ v.source.kind === "manual" && B.source.kind === "sql_query" && (A.current[s] = W);
2006
+ const pe = W === void 0 && v.source.kind === "sql_query" && B.source.kind === "manual" ? A.current[s] : W, ie = Dt({
2007
+ previousControl: v,
2008
+ nextControl: B,
2009
+ currentDefaultValue: pe
2010
+ });
2011
+ B.source.kind === "manual" && (A.current[s] = ie), o && (P = { ...o }, ie === void 0 ? delete P[s] : P[s] = ie), L = L.map(
2012
+ (bt) => bt.id === s ? { ...B, defaultValue: ie } : bt
2013
+ );
2014
+ }
2015
+ q(L, P, {
2016
+ type: "update",
2017
+ cardBindingsById: E,
2018
+ affectedBindingControlIds: F
2019
+ });
2020
+ }, te = (s, g) => {
2021
+ if (!g.trim())
2022
+ return;
2023
+ const v = ua(g);
2024
+ if (v === s || w.has(v) || n.some(
2025
+ (E) => E.id === v && E.id !== s
2026
+ ))
2027
+ return;
2028
+ const L = n.map(
2029
+ (E) => E.id === s ? { ...E, id: v } : E
2030
+ );
2031
+ if (!o) {
2032
+ q(L, void 0, {
2033
+ type: "rename",
2034
+ oldId: s,
2035
+ newId: v
2036
+ });
2037
+ return;
2038
+ }
2039
+ const R = { ...o };
2040
+ Object.prototype.hasOwnProperty.call(R, s) && (R[v] = R[s], delete R[s]), q(L, R, {
2041
+ type: "rename",
2042
+ oldId: s,
2043
+ newId: v
2044
+ });
2045
+ }, We = (s) => {
2046
+ const g = n.filter((L) => L.id !== s);
2047
+ if (!o) {
2048
+ q(g, void 0, { type: "remove", controlId: s });
2049
+ return;
2050
+ }
2051
+ const v = { ...o };
2052
+ delete v[s], q(g, v, { type: "remove", controlId: s });
2053
+ }, Ke = ne(() => {
2054
+ D.current = void 0, I({
2055
+ step: 1,
2056
+ control: $e(e, n, Array.from(w))
2057
+ }), Z(null), T(null);
2058
+ }, [n, w, e]), oe = (s) => {
2059
+ I(
2060
+ (g) => g && (() => {
2061
+ const v = s(g.control);
2062
+ g.control.source.kind === "manual" && v.source.kind === "sql_query" && (D.current = g.defaultValue);
2063
+ const L = g.defaultValue === void 0 && g.control.source.kind === "sql_query" && v.source.kind === "manual" ? D.current : g.defaultValue, R = Dt({
2064
+ previousControl: g.control,
2065
+ nextControl: v,
2066
+ currentDefaultValue: L
2067
+ });
2068
+ return v.source.kind === "manual" && (D.current = R), {
2069
+ ...g,
2070
+ control: v,
2071
+ defaultValue: R
2072
+ };
2073
+ })()
2074
+ );
2075
+ }, Te = (s) => {
2076
+ I(
2077
+ (g) => g && (g.control.source.kind === "manual" && (D.current = s), {
2078
+ ...g,
2079
+ defaultValue: s
2080
+ })
2081
+ );
2082
+ }, ue = (() => {
2083
+ if (!m)
2084
+ return !1;
2085
+ if (m.step === 2 && C(m.control.type))
2086
+ return (m.selectedCardIds || []).length > 0 && ta({
2087
+ participants: f || [],
2088
+ selectedCardIds: m.selectedCardIds || [],
2089
+ control: m.control,
2090
+ selected: m.matrixTargetIds
2091
+ });
2092
+ if (m.step !== 2 && m.step !== 3 || !m.control.label.trim())
2093
+ return !1;
2094
+ const g = m.control.source.kind === "sql_query" ? m.control : kt(m.control);
2095
+ if (g.source.kind === "manual" && (na(g) && g.source.options.length === 0 || g.source.options.some(
2096
+ (L) => L.label.trim().length === 0 || L.value.trim().length === 0
2097
+ )))
2098
+ return !1;
2099
+ if (g.source.kind === "sql_query") {
2100
+ const { connectionId: v, sql: L, valueColumn: R } = g.source;
2101
+ return v.trim().length > 0 && L.trim().length > 0 && R.trim().length > 0;
2102
+ }
2103
+ return aa(
2104
+ Fe(g, m.defaultValue)
2105
+ );
2106
+ })(), Ce = () => {
2107
+ var E;
2108
+ if (!m)
2109
+ return;
2110
+ const s = kt(m.control), g = ia({
2111
+ label: s.label,
2112
+ fallbackId: s.id,
2113
+ existingControls: n,
2114
+ reservedIds: Array.from(w)
2115
+ }), v = {
2116
+ ...s,
2117
+ id: g
2118
+ }, L = e === "dashboard" && (v.type === "field_selector" || v.type === "metric_selector") && ((E = m.selectedCardIds) != null && E.length) ? It({
2119
+ control: v,
2120
+ participants: f || [],
2121
+ selectedCardIds: m.selectedCardIds,
2122
+ matrixTargetIds: m.matrixTargetIds
2123
+ }) : void 0, R = Fe(
2124
+ v,
2125
+ m.defaultValue
2126
+ );
2127
+ I({
2128
+ step: e === "dashboard" && (v.type === "field_selector" || v.type === "metric_selector") ? 4 : 3,
2129
+ control: v,
2130
+ defaultValue: R,
2131
+ createdControlId: g,
2132
+ selectedCardIds: m.selectedCardIds,
2133
+ matrixTargetIds: m.matrixTargetIds,
2134
+ cardBindingsById: L
2135
+ });
2136
+ }, we = ne(() => {
2137
+ I(null);
2138
+ }, []), ke = ne(() => {
2139
+ if (!(m != null && m.createdControlId)) {
2140
+ I(null);
2141
+ return;
2142
+ }
2143
+ const s = m.control, g = m.createdControlId, v = Fe(
2144
+ s,
2145
+ m.defaultValue
2146
+ );
2147
+ if (o) {
2148
+ const L = { ...o };
2149
+ v === void 0 ? delete L[g] : L[g] = v, q(
2150
+ [
2151
+ ...n,
2152
+ {
2153
+ ...s,
2154
+ defaultValue: v
2155
+ }
2156
+ ],
2157
+ L,
2158
+ {
2159
+ type: "add",
2160
+ cardBindingsById: m.cardBindingsById
2161
+ }
2162
+ );
2163
+ } else
2164
+ q(
2165
+ [
2166
+ ...n,
2167
+ {
2168
+ ...s,
2169
+ defaultValue: v
2170
+ }
2171
+ ],
2172
+ void 0,
2173
+ {
2174
+ type: "add",
2175
+ cardBindingsById: m.cardBindingsById
2176
+ }
2177
+ );
2178
+ Z(g), I(null), S == null || S();
2179
+ }, [n, m, o, q, S]), gt = m ? C(m.control.type) ? ["Choose type", "Select cards", "Configure", "Finish"] : ["Choose type", "Configure", "Finish"] : [], Se = m != null && m.createdControlId ? `[[param.${m.createdControlId}]]` : m ? `[[param.${ra(m.control.label) || m.control.id}]]` : "", me = St({
2180
+ controls: n,
2181
+ defaultValues: o
2182
+ }), $ = m ? [...n, m.control] : n, ae = m ? St({
2183
+ controls: $,
2184
+ defaultValues: o,
2185
+ overrides: [
2186
+ {
2187
+ controlId: m.control.id,
2188
+ value: m.defaultValue
2189
+ }
2190
+ ]
2191
+ }) : me;
2192
+ return /* @__PURE__ */ l("div", { className: "space-y-4", children: [
2193
+ m ? /* @__PURE__ */ l("div", { className: "space-y-4 pb-1", children: [
2194
+ /* @__PURE__ */ t(
2195
+ za,
2196
+ {
2197
+ currentStep: m.step,
2198
+ labels: gt
2199
+ }
2200
+ ),
2201
+ m.step === 1 && (() => {
2202
+ const s = /* @__PURE__ */ new Set([
2203
+ "grain_selector",
2204
+ "aggregation_selector",
2205
+ "field_selector",
2206
+ "metric_selector"
2207
+ ]), g = /* @__PURE__ */ new Set([
2208
+ // Temporarily hide these from the add-control dialog while
2209
+ // keeping the shared definitions for existing controls.
2210
+ "date",
2211
+ "text"
2212
+ ]), v = x.filter(
2213
+ (E) => !s.has(E.value) && !g.has(E.value)
2214
+ ), L = x.filter(
2215
+ (E) => s.has(E.value)
2216
+ ), R = (E) => /* @__PURE__ */ l(
2217
+ "button",
2218
+ {
2219
+ type: "button",
2220
+ className: "rounded-control border border-border/60 bg-background px-3 py-2.5 text-left transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:outline-none",
2221
+ onClick: () => I(
2222
+ Ua({
2223
+ scope: e,
2224
+ existingControls: n,
2225
+ reservedIds: Array.from(w),
2226
+ type: E.value
2227
+ })
2228
+ ),
2229
+ children: [
2230
+ /* @__PURE__ */ t("div", { className: "text-[13px] font-medium text-foreground", children: E.label }),
2231
+ /* @__PURE__ */ t("p", { className: "mt-0.5 text-[12px] text-muted-foreground", children: E.description })
2232
+ ]
2233
+ },
2234
+ E.value
2235
+ );
2236
+ return /* @__PURE__ */ l("div", { className: "space-y-4", children: [
2237
+ e === "card" && (y == null ? void 0 : y.sql) == null ? /* @__PURE__ */ t("p", { className: "text-[12px] text-muted-foreground", children: "Explorer cards support displayed metric, group by field, aggregation, and time grain controls here." }) : null,
2238
+ v.length > 0 && /* @__PURE__ */ l("div", { className: "space-y-1.5", children: [
2239
+ /* @__PURE__ */ t("p", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Input controls" }),
2240
+ /* @__PURE__ */ t("div", { className: "grid gap-1.5 sm:grid-cols-2", children: v.map(R) })
2241
+ ] }),
2242
+ L.length > 0 && /* @__PURE__ */ l("div", { className: "space-y-1.5", children: [
2243
+ /* @__PURE__ */ t("p", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Data-driven controls" }),
2244
+ /* @__PURE__ */ t("div", { className: "grid gap-1.5 sm:grid-cols-2", children: L.map(R) })
2245
+ ] }),
2246
+ /* @__PURE__ */ t(
2247
+ je,
2248
+ {
2249
+ secondary: /* @__PURE__ */ t(
2250
+ j,
2251
+ {
2252
+ type: "button",
2253
+ variant: "outline",
2254
+ size: "xs",
2255
+ onClick: we,
2256
+ children: "Back to controls"
2257
+ }
2258
+ )
2259
+ }
2260
+ )
2261
+ ] });
2262
+ })(),
2263
+ m.step === 2 && C(m.control.type) && /* @__PURE__ */ l("div", { className: "space-y-3", children: [
2264
+ /* @__PURE__ */ l("div", { className: "space-y-3", children: [
2265
+ /* @__PURE__ */ t(
2266
+ an,
2267
+ {
2268
+ control: m.control,
2269
+ onChange: (s) => oe((g) => ({
2270
+ ...g,
2271
+ label: s
2272
+ }))
2273
+ }
2274
+ ),
2275
+ /* @__PURE__ */ t("p", { className: "text-[12px] text-muted-foreground", children: "Choose which cards should respond to this shared control." })
2276
+ ] }),
2277
+ G.length === 0 ? /* @__PURE__ */ t("div", { className: "rounded-control border border-border/60 bg-muted/30 px-3 py-2.5 text-[12px] text-muted-foreground", children: "No eligible cards are available yet. Add compatible metrics or group-by fields to cards first." }) : /* @__PURE__ */ t("div", { className: "space-y-1 rounded-control border border-border/60 bg-background p-2", children: G.map((s) => {
2278
+ const g = (m.selectedCardIds || []).includes(s.cardId);
2279
+ return /* @__PURE__ */ l(
2280
+ "label",
2281
+ {
2282
+ className: "flex items-start gap-2 rounded-control px-1.5 py-1 text-[13px] hover:bg-muted/40",
2283
+ children: [
2284
+ /* @__PURE__ */ t(
2285
+ Ge,
2286
+ {
2287
+ checked: g,
2288
+ onCheckedChange: (v) => I(
2289
+ (L) => L && {
2290
+ ...L,
2291
+ selectedCardIds: v === !0 ? [
2292
+ ...L.selectedCardIds || [],
2293
+ s.cardId
2294
+ ] : (L.selectedCardIds || []).filter(
2295
+ (R) => R !== s.cardId
2296
+ )
2297
+ }
2298
+ )
2299
+ }
2300
+ ),
2301
+ /* @__PURE__ */ l("div", { className: "min-w-0", children: [
2302
+ /* @__PURE__ */ t("div", { className: "font-medium text-foreground", children: s.title }),
2303
+ /* @__PURE__ */ t("div", { className: "text-[12px] text-muted-foreground", children: m.control.type === "field_selector" ? `${s.fieldChoices.length} compatible group-by fields` : `${s.metricChoices.length} compatible metrics` })
2304
+ ] })
2305
+ ]
2306
+ },
2307
+ s.cardId
2308
+ );
2309
+ }) }),
2310
+ /* @__PURE__ */ t(
2311
+ yt,
2312
+ {
2313
+ participants: G,
2314
+ selectedCardIds: m.selectedCardIds || [],
2315
+ control: m.control,
2316
+ selected: m.matrixTargetIds,
2317
+ onChange: (s, g) => I((v) => v && { ...v, matrixTargetIds: { ...v.matrixTargetIds, [s]: g } })
2318
+ }
2319
+ ),
2320
+ /* @__PURE__ */ t(
2321
+ je,
2322
+ {
2323
+ secondary: /* @__PURE__ */ t(
2324
+ j,
2325
+ {
2326
+ type: "button",
2327
+ variant: "outline",
2328
+ size: "xs",
2329
+ onClick: () => I(
2330
+ (s) => s && {
2331
+ ...s,
2332
+ step: 1,
2333
+ selectedCardIds: []
2334
+ }
2335
+ ),
2336
+ children: "Back"
2337
+ }
2338
+ ),
2339
+ primary: /* @__PURE__ */ t(
2340
+ j,
2341
+ {
2342
+ type: "button",
2343
+ size: "xs",
2344
+ onClick: () => I(
2345
+ (s) => s && {
2346
+ ...s,
2347
+ step: 3
2348
+ }
2349
+ ),
2350
+ disabled: !ue,
2351
+ children: "Next"
2352
+ }
2353
+ )
2354
+ }
2355
+ )
2356
+ ] }),
2357
+ m.step === 2 && !C(m.control.type) && /* @__PURE__ */ t(
2358
+ Tt,
2359
+ {
2360
+ control: m.control,
2361
+ defaultValue: m.defaultValue,
2362
+ availableFieldChoices: _.fields,
2363
+ availableMetricChoices: _.metrics,
2364
+ previewControlDefinitions: $,
2365
+ previewControlValues: ae,
2366
+ onControlChange: (s) => oe(() => s),
2367
+ onLabelChange: (s) => oe((g) => ({
2368
+ ...g,
2369
+ label: s
2370
+ })),
2371
+ onDefaultValueChange: Te,
2372
+ onBack: () => I(
2373
+ (s) => s && {
2374
+ ...s,
2375
+ step: 1
2376
+ }
2377
+ ),
2378
+ onNext: Ce,
2379
+ nextDisabled: !ue
2380
+ }
2381
+ ),
2382
+ m.step === 3 && C(m.control.type) && /* @__PURE__ */ t(
2383
+ Tt,
2384
+ {
2385
+ control: m.control,
2386
+ defaultValue: m.defaultValue,
2387
+ availableFieldChoices: _.fields,
2388
+ availableMetricChoices: _.metrics,
2389
+ previewControlDefinitions: $,
2390
+ previewControlValues: ae,
2391
+ onControlChange: (s) => oe(() => s),
2392
+ onLabelChange: (s) => oe((g) => ({
2393
+ ...g,
2394
+ label: s
2395
+ })),
2396
+ onDefaultValueChange: Te,
2397
+ onBack: () => I(
2398
+ (s) => s && {
2399
+ ...s,
2400
+ step: 2
2401
+ }
2402
+ ),
2403
+ onNext: Ce,
2404
+ nextDisabled: !ue
2405
+ }
2406
+ ),
2407
+ m.step === 3 && !C(m.control.type) && /* @__PURE__ */ t(
2408
+ At,
2409
+ {
2410
+ control: m.control,
2411
+ scope: e,
2412
+ createdReference: Se,
2413
+ explorerContent: /* @__PURE__ */ l(fe, { children: [
2414
+ "Open the card and use",
2415
+ " ",
2416
+ /* @__PURE__ */ t("span", { className: "font-medium text-foreground", children: "Settings → Controls" }),
2417
+ " ",
2418
+ "to choose what this control changes."
2419
+ ] }),
2420
+ sqlDescription: "Reference this control directly in the SQL editor.",
2421
+ onBack: () => I(
2422
+ (s) => s && {
2423
+ ...s,
2424
+ step: 2
2425
+ }
2426
+ ),
2427
+ onCancel: we,
2428
+ onDone: ke
2429
+ }
2430
+ ),
2431
+ m.step === 4 && C(m.control.type) && /* @__PURE__ */ t(
2432
+ At,
2433
+ {
2434
+ control: m.control,
2435
+ scope: e,
2436
+ createdReference: Se,
2437
+ summaryDetail: /* @__PURE__ */ l(fe, { children: [
2438
+ "Used by ",
2439
+ (m.selectedCardIds || []).length,
2440
+ " selected card",
2441
+ (m.selectedCardIds || []).length === 1 ? "" : "s"
2442
+ ] }),
2443
+ explorerContent: /* @__PURE__ */ t(fe, { children: "Selected cards have been set up to respond to this control automatically." }),
2444
+ sqlDescription: "SQL cards can still reference this control directly in the SQL editor.",
2445
+ onBack: () => I(
2446
+ (s) => s && {
2447
+ ...s,
2448
+ step: 3
2449
+ }
2450
+ ),
2451
+ onCancel: we,
2452
+ onDone: ke
2453
+ }
2454
+ )
2455
+ ] }) : null,
2456
+ !m && n.length === 0 ? /* @__PURE__ */ t("div", { className: "rounded-md border border-dashed p-3 text-sm text-muted-foreground", children: d }) : null,
2457
+ !m && n.map((s) => {
2458
+ const g = K(s), v = i == null ? void 0 : i[s.id], L = He({
2459
+ control: s,
2460
+ defaultValues: o
2461
+ }), R = Y === s.id, E = "inline-flex shrink-0 items-center rounded-[4px] border border-border/60 bg-muted/40 px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground";
2462
+ return /* @__PURE__ */ l(
2463
+ "div",
2464
+ {
2465
+ className: "rounded-control border border-border/60",
2466
+ children: [
2467
+ /* @__PURE__ */ l("div", { className: "flex items-center gap-2 px-3 py-2.5", children: [
2468
+ /* @__PURE__ */ l(
2469
+ "button",
2470
+ {
2471
+ type: "button",
2472
+ className: "flex min-w-0 flex-1 items-start gap-2 rounded-control text-left focus:outline-none focus-visible:bg-muted/40",
2473
+ onClick: () => Z(
2474
+ (F) => F === s.id ? null : s.id
2475
+ ),
2476
+ children: [
2477
+ R ? /* @__PURE__ */ t(Oe, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground" }) : /* @__PURE__ */ t(Ie, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
2478
+ /* @__PURE__ */ l("div", { className: "min-w-0", children: [
2479
+ /* @__PURE__ */ l("div", { className: "flex flex-wrap items-center gap-1.5", children: [
2480
+ /* @__PURE__ */ t("span", { className: "truncate text-[13px] font-medium text-foreground", children: s.label || "Untitled control" }),
2481
+ /* @__PURE__ */ t("span", { className: E, children: Kt(s.type).label }),
2482
+ /* @__PURE__ */ t("span", { className: E, children: Qt(e, s.placement) })
2483
+ ] }),
2484
+ /* @__PURE__ */ l("div", { className: "mt-0.5 text-[12px] text-muted-foreground", children: [
2485
+ Ht(s),
2486
+ v != null && v.status ? ` · ${v.status}` : ""
2487
+ ] })
2488
+ ] })
2489
+ ]
2490
+ }
2491
+ ),
2492
+ /* @__PURE__ */ t(
2493
+ j,
2494
+ {
2495
+ type: "button",
2496
+ size: "xs",
2497
+ variant: "ghost",
2498
+ className: "h-7 w-7 shrink-0 p-0 text-muted-foreground",
2499
+ onClick: () => We(s.id),
2500
+ "aria-label": `Remove ${s.label}`,
2501
+ children: /* @__PURE__ */ t(Et, { className: "h-3.5 w-3.5" })
2502
+ }
2503
+ )
2504
+ ] }),
2505
+ R && /* @__PURE__ */ l("div", { className: "space-y-4 border-t border-border/60 px-3 py-3", children: [
2506
+ /* @__PURE__ */ l("div", { className: "grid gap-3 md:grid-cols-3", children: [
2507
+ /* @__PURE__ */ l("div", { className: "flex flex-col gap-1.5", children: [
2508
+ /* @__PURE__ */ t(le, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Label" }),
2509
+ /* @__PURE__ */ t(
2510
+ Ne,
2511
+ {
2512
+ size: "xs",
2513
+ value: s.label,
2514
+ placeholder: "Control label",
2515
+ onChange: (F) => J(s.id, (B) => ({
2516
+ ...B,
2517
+ label: F.target.value
2518
+ }))
2519
+ }
2520
+ )
2521
+ ] }),
2522
+ /* @__PURE__ */ l("div", { className: "flex flex-col gap-1.5", children: [
2523
+ /* @__PURE__ */ t(le, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Type" }),
2524
+ /* @__PURE__ */ l(
2525
+ xe,
2526
+ {
2527
+ value: s.type,
2528
+ onValueChange: (F) => {
2529
+ const B = Yt({
2530
+ controls: n,
2531
+ controlId: s.id,
2532
+ nextType: F,
2533
+ defaultValues: o
2534
+ });
2535
+ q(B.controls, B.defaultValues);
2536
+ },
2537
+ children: [
2538
+ /* @__PURE__ */ t(ge, { size: "xs", children: /* @__PURE__ */ t(be, {}) }),
2539
+ /* @__PURE__ */ t(ve, { children: z(s.type).map(
2540
+ (F) => /* @__PURE__ */ t(
2541
+ re,
2542
+ {
2543
+ value: F.value,
2544
+ children: F.label
2545
+ },
2546
+ F.value
2547
+ )
2548
+ ) })
2549
+ ]
2550
+ }
2551
+ )
2552
+ ] }),
2553
+ /* @__PURE__ */ l("div", { className: "flex flex-col gap-1.5", children: [
2554
+ /* @__PURE__ */ t(le, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Show in" }),
2555
+ /* @__PURE__ */ l(
2556
+ xe,
2557
+ {
2558
+ value: s.placement || U,
2559
+ onValueChange: (F) => J(s.id, (B) => ({
2560
+ ...B,
2561
+ placement: F
2562
+ })),
2563
+ children: [
2564
+ /* @__PURE__ */ t(ge, { size: "xs", children: /* @__PURE__ */ t(be, {}) }),
2565
+ /* @__PURE__ */ t(ve, { children: V.map((F) => /* @__PURE__ */ t(re, { value: F.value, children: F.label }, F.value)) })
2566
+ ]
2567
+ }
2568
+ )
2569
+ ] })
2570
+ ] }),
2571
+ C(s.type) ? /* @__PURE__ */ l(fe, { children: [
2572
+ /* @__PURE__ */ t(
2573
+ In,
2574
+ {
2575
+ type: s.type,
2576
+ participants: wt(
2577
+ f || [],
2578
+ s.type
2579
+ ).map((F) => ({
2580
+ cardId: F.cardId,
2581
+ title: F.title,
2582
+ choiceCount: s.type === "field_selector" ? F.fieldChoices.length : F.metricChoices.length
2583
+ })),
2584
+ selectedCardIds: (k == null ? void 0 : k[s.id]) || [],
2585
+ onChange: (F) => {
2586
+ const B = ee({
2587
+ control: s,
2588
+ nextSelectedCardIds: F
2589
+ }), P = n.map(
2590
+ (W) => W.id === s.id ? B.nextControl : W
2591
+ );
2592
+ q(P, o, {
2593
+ type: "update",
2594
+ cardBindingsById: B.cardBindingsById
2595
+ });
2596
+ }
2597
+ }
2598
+ ),
2599
+ /* @__PURE__ */ t(
2600
+ yt,
2601
+ {
2602
+ participants: f || [],
2603
+ selectedCardIds: (k == null ? void 0 : k[s.id]) || [],
2604
+ control: s,
2605
+ onChange: (F, B) => {
2606
+ const P = ee({
2607
+ control: s,
2608
+ nextSelectedCardIds: (k == null ? void 0 : k[s.id]) || [],
2609
+ matrixTargetIds: { [F]: B }
2610
+ });
2611
+ q(
2612
+ n.map((W) => W.id === s.id ? P.nextControl : W),
2613
+ o,
2614
+ { type: "update", cardBindingsById: P.cardBindingsById }
2615
+ );
2616
+ }
2617
+ }
2618
+ )
2619
+ ] }) : null,
2620
+ /* @__PURE__ */ t(
2621
+ Mt,
2622
+ {
2623
+ control: s,
2624
+ availableFieldChoices: g.fields,
2625
+ availableMetricChoices: g.metrics,
2626
+ previewControlDefinitions: n,
2627
+ previewControlValues: me,
2628
+ controlLifecycle: "edit",
2629
+ onChange: (F) => J(s.id, () => F)
2630
+ }
2631
+ ),
2632
+ s.initialValueStrategy === "saved_default" && /* @__PURE__ */ t(
2633
+ zt,
2634
+ {
2635
+ control: s,
2636
+ value: L,
2637
+ allowNoDefault: !0,
2638
+ allowCardDefault: !0,
2639
+ previewControlDefinitions: n,
2640
+ previewControlValues: me,
2641
+ onChange: (F) => {
2642
+ const B = n.map(
2643
+ (P) => P.id === s.id ? { ...P, defaultValue: F } : P
2644
+ );
2645
+ if (s.source.kind === "manual" && (A.current[s.id] = F), o) {
2646
+ const P = { ...o };
2647
+ F === void 0 ? delete P[s.id] : P[s.id] = F, q(B, P);
2648
+ return;
2649
+ }
2650
+ q(B, void 0);
2651
+ }
2652
+ }
2653
+ ),
2654
+ /* @__PURE__ */ l(
2655
+ Tn,
2656
+ {
2657
+ open: O === s.id,
2658
+ onOpenChange: (F) => T(F ? s.id : null),
2659
+ children: [
2660
+ /* @__PURE__ */ t(Ln, { asChild: !0, children: /* @__PURE__ */ l(
2661
+ j,
2662
+ {
2663
+ type: "button",
2664
+ variant: "ghost",
2665
+ size: "xs",
2666
+ className: "-ml-2 gap-1 text-muted-foreground hover:text-foreground",
2667
+ children: [
2668
+ O === s.id ? /* @__PURE__ */ t(Oe, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ t(Ie, { className: "h-3.5 w-3.5" }),
2669
+ "Advanced"
2670
+ ]
2671
+ }
2672
+ ) }),
2673
+ /* @__PURE__ */ l(An, { className: "space-y-3 pt-2", children: [
2674
+ /* @__PURE__ */ l("div", { className: "grid gap-3 md:grid-cols-2", children: [
2675
+ /* @__PURE__ */ l("div", { className: "flex flex-col gap-1.5", children: [
2676
+ /* @__PURE__ */ t(le, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Variable name" }),
2677
+ /* @__PURE__ */ t(
2678
+ $n,
2679
+ {
2680
+ controlId: s.id,
2681
+ onCommit: (F) => te(s.id, F)
2682
+ },
2683
+ s.id
2684
+ )
2685
+ ] }),
2686
+ /* @__PURE__ */ l("div", { className: "flex flex-col gap-1.5", children: [
2687
+ /* @__PURE__ */ t(le, { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Initial value" }),
2688
+ /* @__PURE__ */ l(
2689
+ xe,
2690
+ {
2691
+ value: s.initialValueStrategy,
2692
+ onValueChange: (F) => J(s.id, (B) => ({
2693
+ ...B,
2694
+ initialValueStrategy: F
2695
+ })),
2696
+ children: [
2697
+ /* @__PURE__ */ t(ge, { size: "xs", children: /* @__PURE__ */ t(be, {}) }),
2698
+ /* @__PURE__ */ t(ve, { children: oa.map((F) => /* @__PURE__ */ t(
2699
+ re,
2700
+ {
2701
+ value: F.value,
2702
+ children: F.label
2703
+ },
2704
+ F.value
2705
+ )) })
2706
+ ]
2707
+ }
2708
+ )
2709
+ ] })
2710
+ ] }),
2711
+ /* @__PURE__ */ t(
2712
+ Fn,
2713
+ {
2714
+ control: s,
2715
+ onChange: (F) => J(s.id, () => F)
2716
+ }
2717
+ )
2718
+ ] })
2719
+ ]
2720
+ }
2721
+ )
2722
+ ] })
2723
+ ]
2724
+ },
2725
+ s.id
2726
+ );
2727
+ }),
2728
+ !m && /* @__PURE__ */ l(
2729
+ j,
2730
+ {
2731
+ type: "button",
2732
+ variant: "outline",
2733
+ size: "xs",
2734
+ onClick: Ke,
2735
+ children: [
2736
+ /* @__PURE__ */ t(Ve, { className: "h-3.5 w-3.5" }),
2737
+ "Add control"
2738
+ ]
2739
+ }
2740
+ )
2741
+ ] });
2742
+ }
2743
+ function Dr(e) {
2744
+ const {
2745
+ open: n,
2746
+ onOpenChange: a,
2747
+ initialCreateFlowActive: o = !1,
2748
+ dismissMode: u = "passive"
2749
+ } = e, d = n !== void 0, [c, i] = H(!1), [r, p] = H(
2750
+ o
2751
+ ), f = d ? n : c, k = ne(
2752
+ (N) => {
2753
+ !N && r && u === "passive" || (d || i(N), N || p(!1), a == null || a(N));
2754
+ },
2755
+ [d, r, u, a]
2756
+ ), y = ne(() => {
2757
+ d || i(!1), p(!1), a == null || a(!1);
2758
+ }, [d, a]);
2759
+ de(() => {
2760
+ f || p(!1);
2761
+ }, [f]);
2762
+ const h = ne(
2763
+ (N) => {
2764
+ r && N.preventDefault();
2765
+ },
2766
+ [r]
2767
+ );
2768
+ return {
2769
+ forceClose: y,
2770
+ handleOpenChange: k,
2771
+ isCreateFlowActive: r,
2772
+ preventPassiveDismissDuringCreate: h,
2773
+ resolvedOpen: f,
2774
+ setIsCreateFlowActive: p
2775
+ };
2776
+ }
2777
+ function rn(e) {
2778
+ const {
2779
+ relativeMeta: n,
2780
+ latestValue: a,
2781
+ ...o
2782
+ } = e;
2783
+ return o;
2784
+ }
2785
+ function ft(e, n) {
2786
+ const a = rn(e);
2787
+ return n.relativeMeta ? { ...a, value: n.value, relativeMeta: n.relativeMeta } : { ...a, value: n.value };
2788
+ }
2789
+ function Ga(e, n) {
2790
+ const a = n === "in" || n === "not in" || n === "between" || n === "not between" ? [] : n === "isNull" || n === "isNotNull" ? null : "";
2791
+ return ft({ ...e, operator: n }, { value: a });
2792
+ }
2793
+ function Ba(e, n) {
2794
+ const a = qe(n.dataType) === "date";
2795
+ return ft(
2796
+ { ...e, field: n, operator: a ? "between" : "=" },
2797
+ { value: "" }
2798
+ );
2799
+ }
2800
+ function Wa({
2801
+ initialFilters: e,
2802
+ availableFields: n,
2803
+ onChange: a
2804
+ } = {}) {
2805
+ const [o, u] = H(
2806
+ e || {
2807
+ id: `group-${Date.now()}`,
2808
+ logicalOperator: "AND",
2809
+ negate: !1,
2810
+ conditions: [],
2811
+ groups: []
2812
+ }
2813
+ ), d = (I) => {
2814
+ u(I), a == null || a(I);
2815
+ };
2816
+ se((I) => I.card.dataSource);
2817
+ const { filterableFields: c, isLoading: i } = _n(), r = n || c || [], p = {
2818
+ id: "default",
2819
+ qualifiedFieldName: "default",
2820
+ name: "default",
2821
+ dataType: "string",
2822
+ label: "Default",
2823
+ entityId: "default",
2824
+ entityName: "Default",
2825
+ entityType: "table"
2826
+ }, f = (I) => {
2827
+ const A = (D) => {
2828
+ if (D.id === I) {
2829
+ const b = r[0] || p, x = qe(b.dataType) === "date";
2830
+ return {
2831
+ ...D,
2832
+ conditions: [
2833
+ ...D.conditions,
2834
+ {
2835
+ id: `condition-${Date.now()}`,
2836
+ field: b,
2837
+ operator: x ? "between" : "=",
2838
+ value: x ? [] : ""
2839
+ }
2840
+ ]
2841
+ };
2842
+ }
2843
+ return {
2844
+ ...D,
2845
+ groups: D.groups.map(A)
2846
+ };
2847
+ };
2848
+ d(A(o));
2849
+ }, k = (I) => {
2850
+ const A = (D) => {
2851
+ if (D.id === I) {
2852
+ const b = r[0] || p, x = qe(b.dataType) === "date";
2853
+ return {
2854
+ ...D,
2855
+ groups: [
2856
+ ...D.groups,
2857
+ {
2858
+ id: `group-${Date.now()}`,
2859
+ logicalOperator: "AND",
2860
+ negate: !1,
2861
+ conditions: [
2862
+ {
2863
+ id: `condition-${Date.now()}`,
2864
+ field: b,
2865
+ operator: x ? "between" : "=",
2866
+ value: x ? [] : ""
2867
+ }
2868
+ ],
2869
+ groups: []
2870
+ }
2871
+ ]
2872
+ };
2873
+ }
2874
+ return {
2875
+ ...D,
2876
+ groups: D.groups.map(A)
2877
+ };
2878
+ };
2879
+ d(A(o));
2880
+ }, y = (I, A) => {
2881
+ const D = (b) => b.id === I ? {
2882
+ ...b,
2883
+ conditions: b.conditions.filter((x) => x.id !== A)
2884
+ } : {
2885
+ ...b,
2886
+ groups: b.groups.map(D)
2887
+ };
2888
+ d(D(o));
2889
+ }, h = (I, A) => {
2890
+ const D = (b) => b.id === I ? {
2891
+ ...b,
2892
+ groups: b.groups.filter((x) => x.id !== A)
2893
+ } : {
2894
+ ...b,
2895
+ groups: b.groups.map(D)
2896
+ };
2897
+ d(D(o));
2898
+ }, N = (I, A, D) => {
2899
+ const b = (x) => x.id === I ? {
2900
+ ...x,
2901
+ conditions: x.conditions.map(
2902
+ (z) => z.id === A ? D(z) : z
2903
+ )
2904
+ } : {
2905
+ ...x,
2906
+ groups: x.groups.map(b)
2907
+ };
2908
+ d(b(o));
2909
+ }, S = (I, A, D) => N(I, A, (b) => ({
2910
+ ..."value" in D || "operator" in D || "field" in D ? rn(b) : b,
2911
+ ...D
2912
+ })), w = (I, A, D) => N(I, A, () => D), V = Vn(), U = (I, A) => {
2913
+ const D = (b) => b.id === I ? {
2914
+ ...b,
2915
+ logicalOperator: A
2916
+ } : {
2917
+ ...b,
2918
+ groups: b.groups.map(D)
2919
+ };
2920
+ d(D(o));
2921
+ }, O = (I, A) => {
2922
+ const D = (b) => b.id === I ? {
2923
+ ...b,
2924
+ negate: A
2925
+ } : {
2926
+ ...b,
2927
+ groups: b.groups.map(D)
2928
+ };
2929
+ d(D(o));
2930
+ }, T = (I, A, D) => {
2931
+ const b = (x) => x.id === I ? {
2932
+ ...x,
2933
+ conditions: Nt(x.conditions, A, D)
2934
+ } : {
2935
+ ...x,
2936
+ groups: x.groups.map(b)
2937
+ };
2938
+ d(b(o));
2939
+ }, Y = (I, A, D) => {
2940
+ const b = (x) => x.id === I ? {
2941
+ ...x,
2942
+ groups: Nt(x.groups, A, D)
2943
+ } : {
2944
+ ...x,
2945
+ groups: x.groups.map(b)
2946
+ };
2947
+ d(b(o));
2948
+ }, Z = (I) => {
2949
+ if (!I || I.conditions.length === 0 && I.groups.length === 0)
2950
+ return "-- No filters defined";
2951
+ const A = (b) => {
2952
+ let x = "";
2953
+ typeof b.field == "object" ? x = b.field.entityName ? `${b.field.entityName}.${b.field.name}` : b.field.name : x = String(b.field);
2954
+ const z = b.operator;
2955
+ let C = b.value;
2956
+ if (b.latestValue && z === "=")
2957
+ return `${x} = ${qt} /* the latest value each time the card runs */`;
2958
+ if (b.relativeMeta && (z === "between" || z === "not between")) {
2959
+ const G = z === "between" ? "BETWEEN" : "NOT BETWEEN", { label: _, range: K } = Rn(b.relativeMeta, {
2960
+ tz: (V == null ? void 0 : V.tz) ?? "UTC",
2961
+ weekStart: (V == null ? void 0 : V.weekStart) ?? 1,
2962
+ anchor: (V == null ? void 0 : V.anchor) ?? "now"
2963
+ });
2964
+ return K ? `${x} ${G} '${K.start.toISOString()}' AND '${K.end.toISOString()}' /* ${_}: dates update each time the card runs */` : Pt(b.relativeMeta) ? `${x} ${G} ${_} /* dates count back from the latest data each time the card runs */` : `${x} ${G} ${_} /* dates follow your calendar each time the card runs */`;
2965
+ }
2966
+ if (b.field.dataType === "string" && !["in", "not in"].includes(b.operator))
2967
+ typeof C == "string" ? C = `'${C}'` : Array.isArray(C) && (C = `'${C.join(", ")}'`);
2968
+ else if (b.field.dataType === "date" || b.field.dataType === "datetime" || b.field.dataType === "timestamp")
2969
+ if (b.operator === "between" && Array.isArray(C) && C.length === 2) {
2970
+ const G = C[0] ? `'${C[0]}'` : "NULL", _ = C[1] ? `'${C[1]}'` : "NULL";
2971
+ return `${x} BETWEEN ${G} AND ${_}`;
2972
+ } else if ((b.operator === "in" || b.operator === "not in") && Array.isArray(C)) {
2973
+ const G = C.map((_) => _ ? `'${_}'` : "NULL").join(", ");
2974
+ return `${x} ${z} (${G})`;
2975
+ } else typeof C == "string" || C instanceof Date ? C = `'${C}'` : Array.isArray(C) && C.length > 0 && (C = `'${C[0]}'`);
2976
+ else if (["in", "not in"].includes(b.operator)) {
2977
+ let G = [];
2978
+ Array.isArray(C) ? G = C.map(
2979
+ (_) => typeof _ == "string" ? `'${_}'` : String(_)
2980
+ ) : typeof C == "string" ? G = C.split(",").map((_) => {
2981
+ const K = _.trim();
2982
+ return b.field.dataType === "string" ? `'${K}'` : K;
2983
+ }) : typeof C == "number" && (G = [String(C)]), C = `(${G.join(", ")})`;
2984
+ }
2985
+ switch (z) {
2986
+ case "contains":
2987
+ return typeof C == "string" ? `${x} LIKE '%${C.replace(/'/g, "")}'` : `${x} LIKE '%${String(C)}'`;
2988
+ case "startsWith":
2989
+ return typeof C == "string" ? `${x} LIKE '${C.replace(/'/g, "")}%'` : `${x} LIKE '${String(C)}%'`;
2990
+ case "endsWith":
2991
+ return typeof C == "string" ? `${x} LIKE '%${C.replace(/'/g, "")}'` : `${x} LIKE '%${String(C)}'`;
2992
+ case "isNull":
2993
+ return `${x} IS NULL`;
2994
+ case "isNotNull":
2995
+ return `${x} IS NOT NULL`;
2996
+ default:
2997
+ return `${x} ${z} ${C}`;
2998
+ }
2999
+ }, D = (b) => {
3000
+ const x = b.conditions.map(A), z = b.groups.map(
3001
+ (K) => D(K)
3002
+ ), C = [...x, ...z].filter(Boolean);
3003
+ if (C.length === 0) return "";
3004
+ const G = C.join(` ${b.logicalOperator} `), _ = C.length > 1 ? `(${G})` : G;
3005
+ return b.negate ? `NOT ${_}` : _;
3006
+ };
3007
+ return D(I);
3008
+ }, m = o.conditions.length > 0 || o.groups.length > 0;
3009
+ return {
3010
+ currentFilters: o,
3011
+ setCurrentFilters: d,
3012
+ availableFields: r,
3013
+ isLoading: i,
3014
+ addCondition: f,
3015
+ addGroup: k,
3016
+ removeCondition: y,
3017
+ removeGroup: h,
3018
+ updateConditionFields: S,
3019
+ replaceCondition: w,
3020
+ updateGroupOperator: U,
3021
+ updateGroupNegate: O,
3022
+ reorderConditions: T,
3023
+ reorderGroups: Y,
3024
+ generateSQLPreview: Z,
3025
+ hasAnyFilters: m
3026
+ };
3027
+ }
3028
+ function Ka({
3029
+ children: e,
3030
+ className: n,
3031
+ delayDuration: a
3032
+ }) {
3033
+ return /* @__PURE__ */ t(at, { children: /* @__PURE__ */ l(rt, { delayDuration: a, children: [
3034
+ /* @__PURE__ */ t(st, { asChild: !0, children: /* @__PURE__ */ t(
3035
+ "div",
3036
+ {
3037
+ className: M(
3038
+ "w-[200px] overflow-hidden text-ellipsis whitespace-nowrap text-sm",
3039
+ n
3040
+ ),
3041
+ children: e
3042
+ }
3043
+ ) }),
3044
+ /* @__PURE__ */ t(ot, { children: e })
3045
+ ] }) });
3046
+ }
3047
+ function Qa({
3048
+ value: e,
3049
+ onValueChange: n,
3050
+ availableFields: a,
3051
+ placeholder: o = "Select field",
3052
+ className: u
3053
+ }) {
3054
+ const [d, c] = vt.useState(!1), i = vt.useMemo(
3055
+ () => new Set(e ? [e.id] : []),
3056
+ [e]
3057
+ ), r = e ? Xt(e) : null;
3058
+ return /* @__PURE__ */ l(it, { modal: !0, open: d, onOpenChange: c, children: [
3059
+ /* @__PURE__ */ t(lt, { asChild: !0, children: /* @__PURE__ */ l(
3060
+ j,
3061
+ {
3062
+ variant: "outline",
3063
+ size: "xs",
3064
+ role: "combobox",
3065
+ "aria-expanded": d,
3066
+ title: e ? `${e.entityName}.${e.name}` : void 0,
3067
+ className: M(
3068
+ "min-w-0 justify-between gap-1.5 font-normal",
3069
+ !e && "text-muted-foreground",
3070
+ u
3071
+ ),
3072
+ children: [
3073
+ r ? /* @__PURE__ */ t(Ka, { className: "w-auto min-w-0 flex-1 text-left text-[12px]", children: r }) : /* @__PURE__ */ t("span", { className: "min-w-0 flex-1 truncate text-left", children: o }),
3074
+ /* @__PURE__ */ t(En, { className: "h-3.5 w-3.5 shrink-0 opacity-50" })
3075
+ ]
3076
+ }
3077
+ ) }),
3078
+ /* @__PURE__ */ t(
3079
+ dt,
3080
+ {
3081
+ className: "flex w-80 flex-col rounded-control p-1.5",
3082
+ align: "start",
3083
+ onOpenAutoFocus: (p) => {
3084
+ var f, k;
3085
+ p.preventDefault(), (k = (f = p.currentTarget) == null ? void 0 : f.querySelector('input[type="text"]')) == null || k.focus();
3086
+ },
3087
+ children: /* @__PURE__ */ t(
3088
+ Mn,
3089
+ {
3090
+ fields: a,
3091
+ selectedIds: i,
3092
+ onSelect: (p) => {
3093
+ n(p), c(!1);
3094
+ },
3095
+ density: "compact",
3096
+ listLabel: "Fields",
3097
+ listClassName: "max-h-80"
3098
+ }
3099
+ )
3100
+ }
3101
+ )
3102
+ ] });
3103
+ }
3104
+ function sn(e, n) {
3105
+ var p;
3106
+ const a = se((f) => f.card.dataSource), o = se(
3107
+ (f) => f.card.connectionId
3108
+ ), u = se(
3109
+ (f) => f.selectedConnectionId
3110
+ ), d = n ? n.dataSource : a, c = n ? n.connectionId || ((p = n.dataSource) == null ? void 0 : p.connectionId) : u || (a == null ? void 0 : a.connectionId) || o, i = Q(
3111
+ () => ({
3112
+ id: `card-filter-option:${e.id}`,
3113
+ ...Ma(e, { dataSource: d, connectionId: c })
3114
+ }),
3115
+ [c, d, e]
3116
+ ), r = Q(
3117
+ () => zn({ filter: i }),
3118
+ [i]
3119
+ );
3120
+ return qn(i, {
3121
+ inputContext: r,
3122
+ currentSelectionPolicy: "exclude"
3123
+ });
3124
+ }
3125
+ function Ha({
3126
+ field: e,
3127
+ source: n,
3128
+ selected: a,
3129
+ onChange: o,
3130
+ placeholder: u = "Select values…",
3131
+ className: d
3132
+ }) {
3133
+ const [c, i] = _e.useState(!1), r = sn(e, n), p = _e.useMemo(
3134
+ () => new Set(a.map((h) => ye(h))),
3135
+ [a]
3136
+ ), f = (h) => {
3137
+ var N, S;
3138
+ return ((S = (N = r.allRecords.find((w) => ye(w.value) === ye(h))) == null ? void 0 : N.label) == null ? void 0 : S.toString()) ?? h;
3139
+ }, k = (h) => {
3140
+ o(a.filter((N) => N !== h));
3141
+ }, y = (h) => {
3142
+ i(h), !h && r.query && r.setQuery("");
3143
+ };
3144
+ return /* @__PURE__ */ t("div", { className: M("w-full", d), children: /* @__PURE__ */ l(it, { open: c, onOpenChange: y, modal: !0, children: [
3145
+ /* @__PURE__ */ t(lt, { asChild: !0, children: /* @__PURE__ */ l(
3146
+ j,
3147
+ {
3148
+ variant: "outline",
3149
+ size: "xs",
3150
+ role: "combobox",
3151
+ "aria-expanded": c,
3152
+ className: "h-auto min-h-7 w-full justify-between gap-1.5 px-2 py-0.5 font-normal",
3153
+ children: [
3154
+ /* @__PURE__ */ t("div", { className: "flex min-w-0 flex-1 flex-wrap gap-1", children: a.length > 0 ? a.map((h) => {
3155
+ const N = f(h);
3156
+ return (
3157
+ // Selected values render as small square chips (4px
3158
+ // radius), not pills. Pill badges are reserved for
3159
+ // avatars and status dots.
3160
+ /* @__PURE__ */ l(
3161
+ "span",
3162
+ {
3163
+ className: "inline-flex max-w-full items-center gap-1 rounded-[4px] border border-border/70 bg-muted/40 px-1.5 py-0.5 text-[11px] leading-[14px] text-foreground",
3164
+ children: [
3165
+ /* @__PURE__ */ t("span", { className: "truncate", children: N }),
3166
+ /* @__PURE__ */ t(
3167
+ "span",
3168
+ {
3169
+ role: "button",
3170
+ tabIndex: 0,
3171
+ "aria-label": `Remove ${N}`,
3172
+ className: "shrink-0 rounded-[2px] text-muted-foreground outline-none hover:text-foreground focus-visible:ring-1 focus-visible:ring-ring",
3173
+ onKeyDown: (S) => {
3174
+ S.key === "Enter" && k(h);
3175
+ },
3176
+ onMouseDown: (S) => {
3177
+ S.preventDefault(), S.stopPropagation();
3178
+ },
3179
+ onClick: (S) => {
3180
+ S.stopPropagation(), k(h);
3181
+ },
3182
+ children: /* @__PURE__ */ t(ce, { className: "h-3 w-3" })
3183
+ }
3184
+ )
3185
+ ]
3186
+ },
3187
+ h
3188
+ )
3189
+ );
3190
+ }) : /* @__PURE__ */ t("span", { className: "truncate text-muted-foreground", children: u }) }),
3191
+ /* @__PURE__ */ t(Oe, { className: "h-3.5 w-3.5 shrink-0 opacity-50" })
3192
+ ]
3193
+ }
3194
+ ) }),
3195
+ /* @__PURE__ */ t(
3196
+ dt,
3197
+ {
3198
+ className: "w-[var(--radix-popover-trigger-width)] min-w-[240px] rounded-control p-1.5",
3199
+ align: "start",
3200
+ onOpenAutoFocus: (h) => {
3201
+ var N, S;
3202
+ h.preventDefault(), (S = (N = h.currentTarget) == null ? void 0 : N.querySelector('input[type="text"]')) == null || S.focus();
3203
+ },
3204
+ children: /* @__PURE__ */ t(
3205
+ jt,
3206
+ {
3207
+ records: r.displayRecords,
3208
+ selectedIdentities: p,
3209
+ onToggle: (h) => {
3210
+ const N = String(h.value);
3211
+ a.includes(N) ? k(N) : o([...a, N]);
3212
+ },
3213
+ browse: r,
3214
+ searchPlaceholder: `Search ${(e.label || e.name).toLowerCase()}`,
3215
+ listLabel: e.label || e.name,
3216
+ density: "compact"
3217
+ }
3218
+ )
3219
+ }
3220
+ )
3221
+ ] }) });
3222
+ }
3223
+ function Ya({
3224
+ field: e,
3225
+ source: n,
3226
+ value: a,
3227
+ onChange: o,
3228
+ placeholder: u = "Select value…",
3229
+ className: d
3230
+ }) {
3231
+ var y, h;
3232
+ const [c, i] = _e.useState(!1), r = sn(e, n), p = _e.useMemo(
3233
+ () => new Set(a ? [ye(a)] : []),
3234
+ [a]
3235
+ ), f = a ? ((h = (y = r.allRecords.find(
3236
+ (N) => ye(N.value) === ye(a)
3237
+ )) == null ? void 0 : y.label) == null ? void 0 : h.toString()) ?? a : "", k = (N) => {
3238
+ i(N), !N && r.query && r.setQuery("");
3239
+ };
3240
+ return /* @__PURE__ */ l(it, { open: c, onOpenChange: k, modal: !0, children: [
3241
+ /* @__PURE__ */ t(lt, { asChild: !0, children: /* @__PURE__ */ l(
3242
+ j,
3243
+ {
3244
+ variant: "outline",
3245
+ size: "xs",
3246
+ role: "combobox",
3247
+ "aria-expanded": c,
3248
+ className: M(
3249
+ "min-w-0 flex-1 justify-between gap-1.5 px-2 font-normal",
3250
+ d
3251
+ ),
3252
+ children: [
3253
+ /* @__PURE__ */ t(
3254
+ "span",
3255
+ {
3256
+ className: M("truncate", !a && "text-muted-foreground"),
3257
+ children: a ? f : u
3258
+ }
3259
+ ),
3260
+ /* @__PURE__ */ t(Oe, { className: "h-3.5 w-3.5 shrink-0 opacity-50" })
3261
+ ]
3262
+ }
3263
+ ) }),
3264
+ /* @__PURE__ */ t(
3265
+ dt,
3266
+ {
3267
+ className: "w-[var(--radix-popover-trigger-width)] min-w-[240px] rounded-control p-1.5",
3268
+ align: "start",
3269
+ onOpenAutoFocus: (N) => {
3270
+ var S, w;
3271
+ N.preventDefault(), (w = (S = N.currentTarget) == null ? void 0 : S.querySelector('input[type="text"]')) == null || w.focus();
3272
+ },
3273
+ children: /* @__PURE__ */ t(
3274
+ jt,
3275
+ {
3276
+ records: r.displayRecords,
3277
+ selectedIdentities: p,
3278
+ onToggle: (N) => {
3279
+ o(String(N.value)), k(!1);
3280
+ },
3281
+ selectionMode: "single",
3282
+ browse: r,
3283
+ searchPlaceholder: `Search ${(e.label || e.name).toLowerCase()}`,
3284
+ listLabel: e.label || e.name,
3285
+ density: "compact"
3286
+ }
3287
+ )
3288
+ }
3289
+ )
3290
+ ] });
3291
+ }
3292
+ function Pa({
3293
+ value: e,
3294
+ operator: n,
3295
+ relativeMeta: a,
3296
+ latestValue: o,
3297
+ onChange: u,
3298
+ className: d
3299
+ }) {
3300
+ const c = jn(), i = Un(), r = n === "between" || n === "not between", p = Q(() => {
3301
+ if (!r || !a) return;
3302
+ const w = i(a);
3303
+ return {
3304
+ ...w,
3305
+ tooltip: w.dates ? void 0 : Pt(a) ? Gn : Bn
3306
+ };
3307
+ }, [r, a, i]), f = Q(() => {
3308
+ if (r) {
3309
+ if (p) {
3310
+ const { range: w } = p;
3311
+ return w ? { from: w.start, to: w.end } : void 0;
3312
+ }
3313
+ if (e && Array.isArray(e) && e.length === 2) {
3314
+ const w = Pe(e[0], c, "start"), V = Pe(e[1], c, "end");
3315
+ if (w && V)
3316
+ return { from: w, to: V };
3317
+ }
3318
+ }
3319
+ }, [e, r, p, c]), k = Q(() => {
3320
+ if (!e || r || o) return;
3321
+ const w = Array.isArray(e) ? e[0] : e;
3322
+ return Pe(w, c, "start");
3323
+ }, [e, r, o, c]), y = (w) => n === "<=" || n === ">" ? pa(w, c) : fa(w, c);
3324
+ return /* @__PURE__ */ t(
3325
+ Wn,
3326
+ {
3327
+ value: r ? f : void 0,
3328
+ selectionMode: r ? "range" : "single",
3329
+ singleValue: r ? void 0 : k,
3330
+ singleValueLabel: !r && o ? qt : void 0,
3331
+ onChange: (w) => {
3332
+ if (w != null && w.from && w.to) {
3333
+ u({ value: [w.from.toISOString(), w.to.toISOString()] });
3334
+ return;
3335
+ }
3336
+ u({ value: [] });
3337
+ },
3338
+ onSingleChange: (w) => {
3339
+ if (!w) {
3340
+ u({ value: "" });
3341
+ return;
3342
+ }
3343
+ const V = y(w), U = ma(V, n, {
3344
+ timezone: c
3345
+ });
3346
+ u({ value: typeof U == "string" ? U : U.toISOString() });
3347
+ },
3348
+ onRelativeSelect: r ? (w, V) => {
3349
+ if (!w.from || !w.to) {
3350
+ u({ value: [] });
3351
+ return;
3352
+ }
3353
+ u({
3354
+ value: [w.from.toISOString(), w.to.toISOString()],
3355
+ relativeMeta: V
3356
+ });
3357
+ } : void 0,
3358
+ relativeValue: r ? a : void 0,
3359
+ relativeSummary: p,
3360
+ supplementalFooter: r ? /* @__PURE__ */ l("p", { className: "flex items-center gap-1.5 border-t border-border px-3 py-2 text-[11px] text-muted-foreground", children: [
3361
+ /* @__PURE__ */ t(Kn, { className: "h-3 w-3 shrink-0", "aria-hidden": "true" }),
3362
+ "Presets and Relative update each time the card runs. Static dates stay fixed."
3363
+ ] }) : void 0,
3364
+ timezone: c,
3365
+ showRelativeTab: r,
3366
+ className: M("min-w-0", d),
3367
+ buttonClassName: "h-7 text-[12px] [&>span]:text-[12px]",
3368
+ placeholder: "Select date…"
3369
+ }
3370
+ );
3371
+ }
3372
+ const Xa = (e) => e.conditions.length > 0 || e.groups.length > 0, ht = [
3373
+ "contains",
3374
+ "startsWith",
3375
+ "endsWith",
3376
+ "like",
3377
+ "not like"
3378
+ ], Za = [
3379
+ "=",
3380
+ "!=",
3381
+ ">",
3382
+ ">=",
3383
+ "<",
3384
+ "<=",
3385
+ ...ht,
3386
+ "in",
3387
+ "not in",
3388
+ "isNull",
3389
+ "isNotNull"
3390
+ ], Ja = [
3391
+ "=",
3392
+ "!=",
3393
+ ...ht,
3394
+ "in",
3395
+ "not in",
3396
+ "isNull",
3397
+ "isNotNull"
3398
+ ], er = [
3399
+ "=",
3400
+ "!=",
3401
+ ">",
3402
+ ">=",
3403
+ "<",
3404
+ "<=",
3405
+ "in",
3406
+ "not in",
3407
+ "isNull",
3408
+ "isNotNull"
3409
+ ], tr = ["=", "!=", "isNull", "isNotNull"], nr = [
3410
+ "between",
3411
+ // Default operator for dates
3412
+ "=",
3413
+ "!=",
3414
+ "<",
3415
+ "<=",
3416
+ ">",
3417
+ ">=",
3418
+ "isNull",
3419
+ "isNotNull"
3420
+ ], ar = {
3421
+ "=": "Equals",
3422
+ "!=": "Not equals",
3423
+ ">": "Greater than",
3424
+ ">=": "Greater than or equal",
3425
+ "<": "Less than",
3426
+ "<=": "Less than or equal",
3427
+ contains: "Contains",
3428
+ startsWith: "Starts with",
3429
+ endsWith: "Ends with",
3430
+ like: "Like",
3431
+ "not like": "Not like",
3432
+ in: "In",
3433
+ "not in": "Not in",
3434
+ between: "Between",
3435
+ isNull: "Is null",
3436
+ isNotNull: "Is not null",
3437
+ "not between": "Not between"
3438
+ };
3439
+ function Ze(e) {
3440
+ return ar[e] || ha(e);
3441
+ }
3442
+ function rr(e) {
3443
+ switch (e) {
3444
+ case "string":
3445
+ return Ja;
3446
+ case "number":
3447
+ return er;
3448
+ case "boolean":
3449
+ return tr;
3450
+ case "date":
3451
+ return nr;
3452
+ default:
3453
+ return Za;
3454
+ }
3455
+ }
3456
+ const on = "w-[68px] shrink-0", $t = "group-data-[inline]/filters:w-auto group-data-[inline]/filters:min-w-0 group-data-[inline]/filters:flex-1 group-data-[inline]/filters:shrink", xt = "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";
3457
+ function ln({
3458
+ value: e,
3459
+ onValueChange: n,
3460
+ "aria-label": a
3461
+ }) {
3462
+ return /* @__PURE__ */ l(
3463
+ xe,
3464
+ {
3465
+ value: e,
3466
+ onValueChange: (o) => n(o),
3467
+ children: [
3468
+ /* @__PURE__ */ t(
3469
+ ge,
3470
+ {
3471
+ size: "xs",
3472
+ "aria-label": a,
3473
+ className: M(on, "font-medium"),
3474
+ children: /* @__PURE__ */ t(be, {})
3475
+ }
3476
+ ),
3477
+ /* @__PURE__ */ l(ve, { className: "min-w-[var(--radix-select-trigger-width)]", children: [
3478
+ /* @__PURE__ */ t(re, { value: "AND", className: "text-[12px] font-medium", children: "AND" }),
3479
+ /* @__PURE__ */ t(re, { value: "OR", className: "text-[12px] font-medium", children: "OR" })
3480
+ ] })
3481
+ ]
3482
+ }
3483
+ );
3484
+ }
3485
+ function dn({
3486
+ condition: e,
3487
+ index: n,
3488
+ groupId: a,
3489
+ groupLogicalOperator: o,
3490
+ onRemoveCondition: u,
3491
+ onUpdateGroupOperator: d,
3492
+ availableFields: c,
3493
+ source: i,
3494
+ updateConditionFields: r,
3495
+ replaceCondition: p
3496
+ }) {
3497
+ const {
3498
+ attributes: f,
3499
+ listeners: k,
3500
+ setNodeRef: y,
3501
+ transform: h,
3502
+ transition: N,
3503
+ isDragging: S
3504
+ } = Ut({ id: e.id }), w = {
3505
+ transform: Gt.Transform.toString(h),
3506
+ transition: N
3507
+ }, V = qe(e.field.dataType), U = e.operator === "isNull" || e.operator === "isNotNull", O = e.operator === "in" || e.operator === "not in";
3508
+ return /* @__PURE__ */ l(
3509
+ "div",
3510
+ {
3511
+ ref: y,
3512
+ style: w,
3513
+ className: M(
3514
+ "flex items-center gap-2 rounded-control px-1.5 py-1 transition-colors hover:bg-muted/40",
3515
+ S && "z-50 opacity-50"
3516
+ ),
3517
+ children: [
3518
+ /* @__PURE__ */ t(
3519
+ "button",
3520
+ {
3521
+ type: "button",
3522
+ ...f,
3523
+ ...k,
3524
+ "aria-label": "Drag to reorder condition",
3525
+ className: "flex h-7 w-5 shrink-0 cursor-grab items-center justify-center rounded-control text-muted-foreground/60 hover:text-foreground focus-visible:outline-none active:cursor-grabbing",
3526
+ children: /* @__PURE__ */ t(Bt, { className: "h-3.5 w-3.5" })
3527
+ }
3528
+ ),
3529
+ n > 0 ? /* @__PURE__ */ t(
3530
+ ln,
3531
+ {
3532
+ value: o,
3533
+ onValueChange: (T) => d(a, T),
3534
+ "aria-label": "Logical operator"
3535
+ }
3536
+ ) : /* @__PURE__ */ t("span", { className: M(on, "text-center", xt), children: "Where" }),
3537
+ /* @__PURE__ */ t(
3538
+ Qa,
3539
+ {
3540
+ value: e.field,
3541
+ onValueChange: (T) => {
3542
+ p(
3543
+ a,
3544
+ e.id,
3545
+ Ba(e, T)
3546
+ );
3547
+ },
3548
+ availableFields: c,
3549
+ placeholder: "Select field",
3550
+ className: M("w-60 shrink-0", $t)
3551
+ }
3552
+ ),
3553
+ /* @__PURE__ */ l(
3554
+ xe,
3555
+ {
3556
+ value: e.operator,
3557
+ onValueChange: (T) => p(
3558
+ a,
3559
+ e.id,
3560
+ Ga(e, T)
3561
+ ),
3562
+ children: [
3563
+ /* @__PURE__ */ t(
3564
+ ge,
3565
+ {
3566
+ size: "xs",
3567
+ "aria-label": "Operator",
3568
+ className: M("w-40 shrink-0", $t),
3569
+ children: /* @__PURE__ */ t(be, { children: e.operator ? Ze(e.operator) : "" })
3570
+ }
3571
+ ),
3572
+ /* @__PURE__ */ t(ve, { children: rr(V).map((T) => /* @__PURE__ */ t(re, { value: T, children: Ze(T) }, T)) })
3573
+ ]
3574
+ }
3575
+ ),
3576
+ U ? /* @__PURE__ */ t("div", { className: "min-w-0 flex-1" }) : V === "string" ? O ? /* @__PURE__ */ t(
3577
+ Ha,
3578
+ {
3579
+ field: e.field,
3580
+ source: i,
3581
+ selected: Array.isArray(e.value) && e.value.every((T) => typeof T == "string") ? e.value : [],
3582
+ onChange: (T) => r(a, e.id, {
3583
+ value: T
3584
+ }),
3585
+ placeholder: "Select values…",
3586
+ className: "min-w-0 flex-1"
3587
+ }
3588
+ ) : ht.includes(e.operator) ? /* @__PURE__ */ t(
3589
+ Ne,
3590
+ {
3591
+ size: "xs",
3592
+ value: typeof e.value == "string" ? e.value : "",
3593
+ onChange: (T) => r(a, e.id, {
3594
+ value: T.target.value
3595
+ }),
3596
+ className: "min-w-0 flex-1",
3597
+ placeholder: `${Ze(e.operator)}…`
3598
+ }
3599
+ ) : /* @__PURE__ */ t(
3600
+ Ya,
3601
+ {
3602
+ field: e.field,
3603
+ source: i,
3604
+ value: typeof e.value == "string" ? e.value : "",
3605
+ onChange: (T) => r(a, e.id, { value: T }),
3606
+ placeholder: "Select value…",
3607
+ className: "min-w-0 flex-1"
3608
+ }
3609
+ ) : V === "boolean" ? /* @__PURE__ */ l(
3610
+ xe,
3611
+ {
3612
+ value: typeof e.value == "boolean" ? String(e.value) : "",
3613
+ onValueChange: (T) => r(a, e.id, {
3614
+ value: T === "true"
3615
+ }),
3616
+ children: [
3617
+ /* @__PURE__ */ t(ge, { size: "xs", className: "min-w-0 flex-1", children: /* @__PURE__ */ t(be, { placeholder: "Select value…" }) }),
3618
+ /* @__PURE__ */ l(ve, { children: [
3619
+ /* @__PURE__ */ t(re, { value: "true", children: "True" }),
3620
+ /* @__PURE__ */ t(re, { value: "false", children: "False" })
3621
+ ] })
3622
+ ]
3623
+ }
3624
+ ) : V === "date" ? (
3625
+ // Date fields use CardDateFilter which:
3626
+ // - Formats dates as ISO strings for backend compatibility
3627
+ // - Handles different operators (=, !=, >, <, between, in, etc.)
3628
+ // - Saves relative choices ("This month") with the range
3629
+ /* @__PURE__ */ t(
3630
+ Pa,
3631
+ {
3632
+ value: e.value,
3633
+ operator: e.operator,
3634
+ relativeMeta: e.relativeMeta,
3635
+ latestValue: e.latestValue === !0,
3636
+ onChange: (T) => p(
3637
+ a,
3638
+ e.id,
3639
+ ft(e, T)
3640
+ ),
3641
+ className: "min-w-0 flex-1"
3642
+ }
3643
+ )
3644
+ ) : /* @__PURE__ */ t(
3645
+ Ne,
3646
+ {
3647
+ size: "xs",
3648
+ value: typeof e.value == "string" || typeof e.value == "number" ? e.value : "",
3649
+ onChange: (T) => r(a, e.id, {
3650
+ value: T.target.value
3651
+ }),
3652
+ className: "min-w-0 flex-1",
3653
+ placeholder: O ? "value1, value2, value3" : "Value"
3654
+ }
3655
+ ),
3656
+ /* @__PURE__ */ t(
3657
+ j,
3658
+ {
3659
+ variant: "ghost",
3660
+ size: "xs",
3661
+ "aria-label": "Remove condition",
3662
+ className: "h-7 w-7 shrink-0 p-0 text-muted-foreground hover:text-foreground",
3663
+ onClick: () => u(a, e.id),
3664
+ children: /* @__PURE__ */ t(ce, { className: "h-3.5 w-3.5" })
3665
+ }
3666
+ )
3667
+ ]
3668
+ }
3669
+ );
3670
+ }
3671
+ const Ft = "group-data-[inline]/filters:h-auto group-data-[inline]/filters:gap-1 group-data-[inline]/filters:border-0 group-data-[inline]/filters:bg-transparent group-data-[inline]/filters:px-0 group-data-[inline]/filters:py-0.5 group-data-[inline]/filters:text-[11px] group-data-[inline]/filters:font-medium group-data-[inline]/filters:text-muted-foreground group-data-[inline]/filters:shadow-none group-data-[inline]/filters:underline-offset-2 group-data-[inline]/filters:hover:bg-transparent group-data-[inline]/filters:hover:text-foreground group-data-[inline]/filters:hover:underline";
3672
+ function cn({
3673
+ onAddCondition: e,
3674
+ onAddGroup: n
3675
+ }) {
3676
+ return /* @__PURE__ */ l("div", { className: "mt-2 flex items-center gap-1.5 group-data-[inline]/filters:mt-1 group-data-[inline]/filters:gap-3", children: [
3677
+ /* @__PURE__ */ l(
3678
+ j,
3679
+ {
3680
+ type: "button",
3681
+ size: "xs",
3682
+ variant: "outline",
3683
+ className: M("gap-1.5", Ft),
3684
+ onClick: e,
3685
+ children: [
3686
+ /* @__PURE__ */ t(Ve, { className: "h-3 w-3" }),
3687
+ "Add condition"
3688
+ ]
3689
+ }
3690
+ ),
3691
+ n && /* @__PURE__ */ l(
3692
+ j,
3693
+ {
3694
+ type: "button",
3695
+ size: "xs",
3696
+ variant: "ghost",
3697
+ className: M("gap-1.5 text-muted-foreground hover:text-foreground", Ft),
3698
+ onClick: n,
3699
+ children: [
3700
+ /* @__PURE__ */ t(Ve, { className: "h-3 w-3" }),
3701
+ "Add group"
3702
+ ]
3703
+ }
3704
+ )
3705
+ ] });
3706
+ }
3707
+ function sr({
3708
+ group: e,
3709
+ depth: n,
3710
+ parentGroupId: a,
3711
+ onUpdateGroupOperator: o,
3712
+ onUpdateGroupNegate: u,
3713
+ onRemoveGroup: d,
3714
+ onRemoveCondition: c,
3715
+ onReorderConditions: i,
3716
+ onReorderGroups: r,
3717
+ onAddCondition: p,
3718
+ onAddGroup: f,
3719
+ availableFields: k,
3720
+ source: y,
3721
+ renderFilterGroup: h,
3722
+ updateConditionFields: N,
3723
+ replaceCondition: S
3724
+ }) {
3725
+ const {
3726
+ attributes: w,
3727
+ listeners: V,
3728
+ setNodeRef: U,
3729
+ transform: O,
3730
+ transition: T,
3731
+ isDragging: Y
3732
+ } = Ut({ id: e.id }), Z = {
3733
+ transform: Gt.Transform.toString(O),
3734
+ transition: T
3735
+ }, m = (A) => {
3736
+ const { active: D, over: b } = A;
3737
+ if (b && D.id !== b.id) {
3738
+ const x = e.conditions.findIndex(
3739
+ (C) => C.id === D.id
3740
+ ), z = e.conditions.findIndex(
3741
+ (C) => C.id === b.id
3742
+ );
3743
+ x !== -1 && z !== -1 && i(e.id, x, z);
3744
+ }
3745
+ }, I = (A) => {
3746
+ const { active: D, over: b } = A;
3747
+ if (b && D.id !== b.id && a) {
3748
+ const x = e.groups.findIndex((C) => C.id === D.id), z = e.groups.findIndex((C) => C.id === b.id);
3749
+ x !== -1 && z !== -1 && r(a, x, z);
3750
+ }
3751
+ };
3752
+ return /* @__PURE__ */ l(
3753
+ "div",
3754
+ {
3755
+ ref: U,
3756
+ style: Z,
3757
+ className: M(
3758
+ n > 0 && "mt-2 overflow-hidden rounded-[6px] border border-border/60",
3759
+ Y && "z-50 opacity-50"
3760
+ ),
3761
+ children: [
3762
+ n > 0 && /* @__PURE__ */ l("div", { className: "flex items-center justify-between gap-2 border-b border-border/60 bg-muted/40 px-2 py-1", children: [
3763
+ /* @__PURE__ */ l("div", { className: "flex items-center gap-1.5", children: [
3764
+ /* @__PURE__ */ t(
3765
+ "button",
3766
+ {
3767
+ type: "button",
3768
+ ...w,
3769
+ ...V,
3770
+ "aria-label": "Drag to reorder group",
3771
+ className: "flex h-7 w-5 shrink-0 cursor-grab items-center justify-center rounded-control text-muted-foreground/60 hover:text-foreground focus-visible:outline-none active:cursor-grabbing",
3772
+ children: /* @__PURE__ */ t(Bt, { className: "h-3.5 w-3.5" })
3773
+ }
3774
+ ),
3775
+ /* @__PURE__ */ t(
3776
+ j,
3777
+ {
3778
+ type: "button",
3779
+ variant: e.negate ? "default" : "outline",
3780
+ size: "xs",
3781
+ "aria-pressed": e.negate,
3782
+ className: "px-2",
3783
+ onClick: () => u(e.id, !e.negate),
3784
+ children: "NOT"
3785
+ }
3786
+ ),
3787
+ /* @__PURE__ */ t(
3788
+ ln,
3789
+ {
3790
+ value: e.logicalOperator,
3791
+ onValueChange: (A) => o(e.id, A),
3792
+ "aria-label": "Group logical operator"
3793
+ }
3794
+ ),
3795
+ /* @__PURE__ */ t("span", { className: xt, children: "Group" })
3796
+ ] }),
3797
+ /* @__PURE__ */ t(
3798
+ j,
3799
+ {
3800
+ type: "button",
3801
+ variant: "ghost",
3802
+ size: "xs",
3803
+ "aria-label": "Remove group",
3804
+ className: "h-7 w-7 p-0 text-muted-foreground hover:text-foreground",
3805
+ onClick: () => a && d(a, e.id),
3806
+ children: /* @__PURE__ */ t(Et, { className: "h-3.5 w-3.5" })
3807
+ }
3808
+ )
3809
+ ] }),
3810
+ /* @__PURE__ */ l("div", { className: M(n > 0 && "p-2"), children: [
3811
+ /* @__PURE__ */ t(
3812
+ Re,
3813
+ {
3814
+ sensors: Je(
3815
+ he(nt),
3816
+ he(tt, {
3817
+ coordinateGetter: et
3818
+ })
3819
+ ),
3820
+ collisionDetection: Ee,
3821
+ onDragEnd: m,
3822
+ children: /* @__PURE__ */ t(
3823
+ Me,
3824
+ {
3825
+ items: e.conditions.map((A) => A.id),
3826
+ strategy: ze,
3827
+ children: /* @__PURE__ */ t("div", { className: "space-y-0.5", children: e.conditions.map((A, D) => /* @__PURE__ */ t(
3828
+ dn,
3829
+ {
3830
+ condition: A,
3831
+ index: D,
3832
+ groupId: e.id,
3833
+ groupLogicalOperator: e.logicalOperator,
3834
+ onRemoveCondition: c,
3835
+ onUpdateGroupOperator: o,
3836
+ availableFields: k,
3837
+ source: y,
3838
+ updateConditionFields: N,
3839
+ replaceCondition: S
3840
+ },
3841
+ A.id
3842
+ )) })
3843
+ }
3844
+ )
3845
+ }
3846
+ ),
3847
+ /* @__PURE__ */ t(
3848
+ Re,
3849
+ {
3850
+ sensors: Je(
3851
+ he(nt),
3852
+ he(tt, {
3853
+ coordinateGetter: et
3854
+ })
3855
+ ),
3856
+ collisionDetection: Ee,
3857
+ onDragEnd: I,
3858
+ children: /* @__PURE__ */ t(
3859
+ Me,
3860
+ {
3861
+ items: e.groups.map((A) => A.id),
3862
+ strategy: ze,
3863
+ children: e.groups.map(
3864
+ (A) => h(A, n + 1, e.id)
3865
+ )
3866
+ }
3867
+ )
3868
+ }
3869
+ ),
3870
+ e.conditions.length === 0 && e.groups.length === 0 && /* @__PURE__ */ t("p", { className: "rounded-control border border-dashed border-border/60 px-3 py-2 text-center text-[11.5px] text-muted-foreground", children: "No conditions in this group." }),
3871
+ /* @__PURE__ */ t(
3872
+ cn,
3873
+ {
3874
+ onAddCondition: () => p(e.id),
3875
+ onAddGroup: () => f(e.id)
3876
+ }
3877
+ )
3878
+ ] })
3879
+ ]
3880
+ }
3881
+ );
3882
+ }
3883
+ function Ir({
3884
+ filters: e,
3885
+ availableFields: n,
3886
+ source: a,
3887
+ onSave: o,
3888
+ onClearAll: u,
3889
+ onCancel: d,
3890
+ onChange: c
3891
+ }) {
3892
+ const i = c !== void 0, {
3893
+ currentFilters: r,
3894
+ availableFields: p,
3895
+ isLoading: f,
3896
+ addCondition: k,
3897
+ addGroup: y,
3898
+ removeCondition: h,
3899
+ removeGroup: N,
3900
+ updateConditionFields: S,
3901
+ replaceCondition: w,
3902
+ updateGroupOperator: V,
3903
+ updateGroupNegate: U,
3904
+ reorderConditions: O,
3905
+ reorderGroups: T,
3906
+ generateSQLPreview: Y,
3907
+ hasAnyFilters: Z
3908
+ } = Wa({
3909
+ initialFilters: e,
3910
+ availableFields: n,
3911
+ ...c ? {
3912
+ onChange: (x) => c(Xa(x) ? x : null)
3913
+ } : {}
3914
+ }), m = Je(
3915
+ he(nt),
3916
+ he(tt, {
3917
+ coordinateGetter: et
3918
+ })
3919
+ ), [I, A] = H(!1), D = (x, z = 0, C) => {
3920
+ if (z === 0) {
3921
+ const G = x.conditions.length === 0 && x.groups.length === 0;
3922
+ return /* @__PURE__ */ l("div", { children: [
3923
+ /* @__PURE__ */ t(
3924
+ Re,
3925
+ {
3926
+ sensors: m,
3927
+ collisionDetection: Ee,
3928
+ onDragEnd: (_) => {
3929
+ const { active: K, over: ee } = _;
3930
+ if (ee && K.id !== ee.id) {
3931
+ const q = x.conditions.findIndex(
3932
+ (te) => te.id === K.id
3933
+ ), J = x.conditions.findIndex(
3934
+ (te) => te.id === ee.id
3935
+ );
3936
+ q !== -1 && J !== -1 && O(x.id, q, J);
3937
+ }
3938
+ },
3939
+ children: /* @__PURE__ */ t(
3940
+ Me,
3941
+ {
3942
+ items: x.conditions.map((_) => _.id),
3943
+ strategy: ze,
3944
+ children: /* @__PURE__ */ t("div", { className: "space-y-0.5", children: x.conditions.map((_, K) => /* @__PURE__ */ t(
3945
+ dn,
3946
+ {
3947
+ condition: _,
3948
+ index: K,
3949
+ groupId: x.id,
3950
+ groupLogicalOperator: x.logicalOperator,
3951
+ onRemoveCondition: h,
3952
+ onUpdateGroupOperator: V,
3953
+ availableFields: p,
3954
+ source: a,
3955
+ updateConditionFields: S,
3956
+ replaceCondition: w
3957
+ },
3958
+ _.id
3959
+ )) })
3960
+ }
3961
+ )
3962
+ }
3963
+ ),
3964
+ /* @__PURE__ */ t(
3965
+ Re,
3966
+ {
3967
+ sensors: m,
3968
+ collisionDetection: Ee,
3969
+ onDragEnd: (_) => {
3970
+ const { active: K, over: ee } = _;
3971
+ if (ee && K.id !== ee.id) {
3972
+ const q = x.groups.findIndex(
3973
+ (te) => te.id === K.id
3974
+ ), J = x.groups.findIndex(
3975
+ (te) => te.id === ee.id
3976
+ );
3977
+ q !== -1 && J !== -1 && T(x.id, q, J);
3978
+ }
3979
+ },
3980
+ children: /* @__PURE__ */ t(
3981
+ Me,
3982
+ {
3983
+ items: x.groups.map((_) => _.id),
3984
+ strategy: ze,
3985
+ children: x.groups.map(
3986
+ (_) => D(_, z + 1, x.id)
3987
+ )
3988
+ }
3989
+ )
3990
+ }
3991
+ ),
3992
+ G && !i && /* @__PURE__ */ t("p", { className: "rounded-control border border-dashed border-border/60 px-3 py-2 text-center text-[11.5px] text-muted-foreground", children: "No filters yet. Add a condition to limit the rows this card shows." }),
3993
+ /* @__PURE__ */ t(
3994
+ cn,
3995
+ {
3996
+ onAddCondition: () => k(x.id),
3997
+ onAddGroup: (
3998
+ // In place, grouping is offered once there are two conditions to group,
3999
+ // not as a mode to switch on first.
4000
+ (i ? x.conditions.length + x.groups.length >= 2 : I) ? () => y(x.id) : void 0
4001
+ )
4002
+ }
4003
+ )
4004
+ ] }, x.id);
4005
+ }
4006
+ return /* @__PURE__ */ t(
4007
+ sr,
4008
+ {
4009
+ group: x,
4010
+ depth: z,
4011
+ parentGroupId: C,
4012
+ onUpdateGroupOperator: V,
4013
+ onUpdateGroupNegate: U,
4014
+ onRemoveGroup: N,
4015
+ onRemoveCondition: h,
4016
+ onReorderConditions: O,
4017
+ onReorderGroups: T,
4018
+ onAddCondition: k,
4019
+ onAddGroup: y,
4020
+ availableFields: p,
4021
+ source: a,
4022
+ renderFilterGroup: D,
4023
+ updateConditionFields: S,
4024
+ replaceCondition: w
4025
+ },
4026
+ x.id
4027
+ );
4028
+ }, b = Qn(e);
4029
+ return /* @__PURE__ */ l("div", { className: M("group/filters", i ? "flex flex-col" : "flex min-h-0 flex-1 flex-col"), "data-inline": i || void 0, children: [
4030
+ /* @__PURE__ */ l("div", { className: i ? "" : "min-h-0 flex-1 overflow-y-auto px-3 py-3", children: [
4031
+ f ? /* @__PURE__ */ l("div", { className: "flex items-center justify-center gap-2 py-6 text-[12px] text-muted-foreground", children: [
4032
+ /* @__PURE__ */ t(pn, { className: "h-3.5 w-3.5 animate-spin" }),
4033
+ "Loading columns…"
4034
+ ] }) : D(r),
4035
+ !i && /* @__PURE__ */ l("div", { className: "mt-3 flex items-center gap-2 border-t border-border/60 pt-3", children: [
4036
+ /* @__PURE__ */ t(
4037
+ fn,
4038
+ {
4039
+ size: "xs",
4040
+ id: "advanced-mode",
4041
+ checked: I,
4042
+ onCheckedChange: (x) => A(x)
4043
+ }
4044
+ ),
4045
+ /* @__PURE__ */ t(
4046
+ le,
4047
+ {
4048
+ htmlFor: "advanced-mode",
4049
+ className: "text-[12px] font-normal leading-none text-foreground",
4050
+ children: "Advanced mode"
4051
+ }
4052
+ ),
4053
+ /* @__PURE__ */ t("span", { className: "text-[11px] text-muted-foreground", children: "Nest conditions in groups" })
4054
+ ] }),
4055
+ Z && !i && /* @__PURE__ */ l("div", { className: "mt-3 border-t border-border/60 pt-3", children: [
4056
+ /* @__PURE__ */ t("div", { className: M("mb-1.5", xt), children: "Where clause" }),
4057
+ /* @__PURE__ */ t("pre", { className: "overflow-x-auto whitespace-pre-wrap break-words rounded-[6px] border border-border bg-muted/40 px-3 py-2 font-mono text-[12px] leading-[1.55] text-foreground", children: Y(r) })
4058
+ ] })
4059
+ ] }),
4060
+ i ? null : /* @__PURE__ */ l("div", { className: "flex shrink-0 items-center justify-between gap-2 border-t border-border px-3 py-2.5", children: [
4061
+ /* @__PURE__ */ t("div", { children: b > 0 && /* @__PURE__ */ t(
4062
+ j,
4063
+ {
4064
+ size: "xs",
4065
+ variant: "ghost",
4066
+ className: "text-muted-foreground hover:text-foreground",
4067
+ onClick: () => u == null ? void 0 : u(),
4068
+ children: "Clear all"
4069
+ }
4070
+ ) }),
4071
+ /* @__PURE__ */ l("div", { className: "flex items-center gap-1.5", children: [
4072
+ /* @__PURE__ */ t(j, { size: "xs", variant: "ghost", onClick: () => d == null ? void 0 : d(), children: "Cancel" }),
4073
+ /* @__PURE__ */ t(
4074
+ j,
4075
+ {
4076
+ size: "xs",
4077
+ onClick: () => o == null ? void 0 : o(Z ? r : null),
4078
+ children: "Apply filters"
4079
+ }
4080
+ )
4081
+ ] })
4082
+ ] })
4083
+ ] });
4084
+ }
4085
+ export {
4086
+ Cr as A,
4087
+ Sr as C,
4088
+ Nr as F,
4089
+ Ea as I,
4090
+ ba as L,
4091
+ kr as V,
4092
+ va as a,
4093
+ wr as b,
4094
+ Ir as c,
4095
+ Zt as d,
4096
+ Ma as e,
4097
+ _a as g,
4098
+ Jt as i,
4099
+ Dr as u
4100
+ };