react-semaphor 0.0.217 → 0.0.218

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.
@@ -1,5 +1,5 @@
1
1
  import { P as L, b as k, j as e, Q as Ns, R as Cs, U as S, V as ea, W as Ss, X as ks, Y as ws, Z as zs, _ as R, $ as le, a0 as sa, J as aa, O as Ae, a1 as _a, a2 as Ha, a3 as Ba, a4 as $a, a5 as Pa, a6 as Ka, a7 as Hs, a8 as Be, a9 as Ge, aa as ns, T as Fs, e as ta, g as Os, ab as Oe, ac as Me, f as X, ad as Te, ae as Le, af as $e, ag as De, ah as Y, ai as Ms, G as c, aj as Je, ak as Qe, al as Ua, am as We, w as na, v as la, t as ue, an as Ga, r as Ja, N as ra, s as Qa, ao as Wa, B as Ya, ap as ia, aq as Xa, L as Pe, S as Ts, z as Za, n as Bs, ar as gs, A as js, u as Ye, as as me, at as be, au as Ke, av as oa, aw as ca, ax as da, ay as ha, az as ma, aA as et, aB as st, aC as ua, aD as at, aE as tt, aF as nt, aG as lt, aH as rt, aI as bs, aJ as it, aK as He, aL as ys, aM as Fe, aN as vs, aO as $s, aP as ot, aQ as ct, aR as dt, aS as ht, aT as mt, aU as xs, aV as ut, aW as Ps, aX as xt, aY as Ks, aZ as pt, a_ as ft, a$ as gt, b0 as xa, l as jt, C as bt, E as Us, d as yt, h as vt, i as Nt, o as Ct, b1 as St, m as kt, H as wt, b2 as zt, b3 as Ft, b4 as Ot, b5 as ps, b6 as Mt, b7 as fs, b8 as Gs, K as Tt, b9 as Lt, ba as At, bb as Ls, bc as Ee, bd as pa, be as Dt, bf as Et, bg as It, bh as Vt, bi as qt, bj as Rt, bk as Ce, bl as _, bm as H, bn as As, bo as B, bp as Js, bq as _t, br as Ht, bs as Bt, bt as $t, bu as Qs, bv as Pt, bw as Kt, bx as Ut, by as Gt, bz as Jt, bA as Qt } from "./index-D_kbj8T-.js";
2
- import xe, { useState as T, useEffect as K, useMemo as Wt, useRef as Ue } from "react";
2
+ import xe, { useState as T, useEffect as U, useMemo as Wt, useRef as Ue } from "react";
3
3
  /**
4
4
  * @license lucide-react v0.379.0 - ISC
5
5
  *
@@ -471,7 +471,7 @@ function Cn() {
471
471
  ), u = k(
472
472
  (i) => i.actions.setBookmarkKey
473
473
  );
474
- K(() => {
474
+ U(() => {
475
475
  const i = Ae(o.id), x = JSON.parse(localStorage.getItem(i) || "[]");
476
476
  l(x);
477
477
  const f = x.find(
@@ -533,7 +533,7 @@ function Cn() {
533
533
  }
534
534
  function Sn() {
535
535
  const [s, n] = T(!1), a = k((h) => h.dashboard), t = k((h) => h.bookmarkKey);
536
- K(() => {
536
+ U(() => {
537
537
  if (!t) {
538
538
  n(!1);
539
539
  return;
@@ -883,9 +883,9 @@ function zn({
883
883
  schemaName: l,
884
884
  tableName: d
885
885
  }, V = [...p || [], z].filter(
886
- (F, U, G) => G.findIndex(
886
+ (F, P, G) => G.findIndex(
887
887
  (I) => I.connectinonId === F.connectinonId && I.tableName === F.tableName
888
- ) === U
888
+ ) === P
889
889
  );
890
890
  u(V), gs.success(`Added '${d}' to AI Scope`, {
891
891
  position: "top-right",
@@ -1064,7 +1064,7 @@ function Vs(s, n) {
1064
1064
  // Only fetch if authToken is present
1065
1065
  }), F = y == null ? void 0 : y.connections.find(
1066
1066
  (r) => r.id === o
1067
- ), U = F == null ? void 0 : F.type, G = (F == null ? void 0 : F.type) === "API" || (F == null ? void 0 : F.type) === "S3", {
1067
+ ), P = F == null ? void 0 : F.type, G = (F == null ? void 0 : F.type) === "API" || (F == null ? void 0 : F.type) === "S3", {
1068
1068
  data: I,
1069
1069
  isLoading: Z,
1070
1070
  isFetching: ae,
@@ -1079,7 +1079,7 @@ function Vs(s, n) {
1079
1079
  connection_id: o
1080
1080
  }
1081
1081
  ),
1082
- enabled: E(U)
1082
+ enabled: E(P)
1083
1083
  // !!selectedConnectionId && !isNonDbConnection, //currentConnection?.type !== 'API', // Only fetch if connectionId is present
1084
1084
  }), {
1085
1085
  data: $,
@@ -1121,12 +1121,12 @@ function Vs(s, n) {
1121
1121
  schema_name: l
1122
1122
  }
1123
1123
  ),
1124
- enabled: w(U)
1124
+ enabled: w(P)
1125
1125
  }), {
1126
1126
  data: ee,
1127
1127
  isLoading: ye,
1128
1128
  isFetching: ge,
1129
- isError: P
1129
+ isError: K
1130
1130
  } = me({
1131
1131
  queryKey: [
1132
1132
  "columns",
@@ -1148,7 +1148,7 @@ function Vs(s, n) {
1148
1148
  table_name: d
1149
1149
  }
1150
1150
  ),
1151
- enabled: N(U)
1151
+ enabled: N(P)
1152
1152
  // (!!selectedConnectionId &&
1153
1153
  // !!selectedDatabaseName &&
1154
1154
  // !!selectedSchemaName &&
@@ -1157,9 +1157,9 @@ function Vs(s, n) {
1157
1157
  //currentConnection?.type === 'API',
1158
1158
  // && currentConnection?.type !== 'API', // Only fetch if connectionId, database, and table is present
1159
1159
  });
1160
- K(() => {
1160
+ U(() => {
1161
1161
  p(a);
1162
- }, [ee, p, a]), K(() => {
1162
+ }, [ee, p, a]), U(() => {
1163
1163
  }, [
1164
1164
  G,
1165
1165
  f,
@@ -1184,7 +1184,7 @@ function Vs(s, n) {
1184
1184
  I && ((es = I == null ? void 0 : I.databases) == null ? void 0 : es.length) > 0, $ && ((qe = $ == null ? void 0 : $.schemas) == null ? void 0 : qe.length) > 0, ee && ((ss = ee == null ? void 0 : ee.columns) == null ? void 0 : ss.length) > 0 && (a = ee.columns.map((r) => ({
1185
1185
  ...r,
1186
1186
  data_type: r.data_type.toLowerCase()
1187
- }))), J && (a = []), (P || b) && (a = []);
1187
+ }))), J && (a = []), (K || b) && (a = []);
1188
1188
  const ke = y == null ? void 0 : y.connections.map(
1189
1189
  (r) => ({
1190
1190
  id: r.id,
@@ -1222,9 +1222,9 @@ function Vs(s, n) {
1222
1222
  isTableError: D,
1223
1223
  columns: a,
1224
1224
  isColumnsLoadingOrFetching: ye || ge,
1225
- isColumnsError: P,
1225
+ isColumnsError: K,
1226
1226
  isNonDbConnection: G,
1227
- connectionType: U,
1227
+ connectionType: P,
1228
1228
  tableName: re,
1229
1229
  schemaName: ie,
1230
1230
  handleConnectionChange: Ve,
@@ -1267,7 +1267,7 @@ function Na({
1267
1267
  isTableLoadingOrFetching: M,
1268
1268
  isTableError: V,
1269
1269
  connectionType: F,
1270
- isNonDbConnection: U,
1270
+ isNonDbConnection: P,
1271
1271
  handleConnectionChange: G,
1272
1272
  handleDatabaseChange: I,
1273
1273
  handleSchemaChange: Z,
@@ -1307,7 +1307,7 @@ function Na({
1307
1307
  );
1308
1308
  }
1309
1309
  function j() {
1310
- if (n && (!t || t === "none") && (!a || a === "none"))
1310
+ if (n && !P && (!t || t === "none") && (!a || a === "none"))
1311
1311
  return /* @__PURE__ */ e.jsxs("div", { className: "grid grid-cols-3", children: [
1312
1312
  /* @__PURE__ */ e.jsx("div", { className: "col-span-1 grid place-items-center", children: /* @__PURE__ */ e.jsx(Ke, {}) }),
1313
1313
  /* @__PURE__ */ e.jsx("div", { className: "col-span-1 grid place-items-center", children: /* @__PURE__ */ e.jsx(R, { children: "OR" }) }),
@@ -1574,7 +1574,7 @@ function Dn({
1574
1574
  Table Columns: ${N == null ? void 0 : N.map((v) => `${v.column_name} | ${v.data_type}`).join(", ")}
1575
1575
  User SQL: ${E}
1576
1576
  ${C && `Base Queries: ${JSON.stringify(C)} `}`, b = ` When the user asks for a specific chart please use the following query structure to generate the chart query. Do not make up the column names. Use only the table columns provided above for the query. Replace x-axis, y-axis, and lables with the appropriate column names.
1577
- Visual Query Syntax: ${An}`, { data: z, isLoading: M, isFetching: V, isError: F, refetch: U } = me({
1577
+ Visual Query Syntax: ${An}`, { data: z, isLoading: M, isFetching: V, isError: F, refetch: P } = me({
1578
1578
  queryKey: ["ai-query"],
1579
1579
  queryFn: () => be(
1580
1580
  "https://semaphor.cloud/api/v1/ai",
@@ -1607,9 +1607,9 @@ function Dn({
1607
1607
  return x("bar"), !1;
1608
1608
  return !0;
1609
1609
  }
1610
- K(() => {
1610
+ U(() => {
1611
1611
  z && w((v) => [...v, { role: "ai", content: z.response }]);
1612
- }, [z]), K(() => {
1612
+ }, [z]), U(() => {
1613
1613
  const v = setTimeout(() => {
1614
1614
  var j;
1615
1615
  l.current && (l.current.scroll({
@@ -1620,9 +1620,9 @@ function Dn({
1620
1620
  return () => clearTimeout(v);
1621
1621
  }, [f]);
1622
1622
  function I() {
1623
- a && (w((v) => [...v, { role: "user", content: a }]), G(a) && u(!0), t(""), U());
1623
+ a && (w((v) => [...v, { role: "user", content: a }]), G(a) && u(!0), t(""), P());
1624
1624
  }
1625
- K(() => {
1625
+ U(() => {
1626
1626
  o && (I(), h(!1));
1627
1627
  }, [o, h]);
1628
1628
  const Z = {
@@ -1901,7 +1901,7 @@ function $n() {
1901
1901
  k(
1902
1902
  (r) => r.actions.updateFrameCard
1903
1903
  );
1904
- const z = c((r) => r.selectedTableName), M = c((r) => r.card.sql), V = c((r) => r.card.python), F = rt(M, x), U = c((r) => r.selectedConnectionId), G = c((r) => r.frame), I = c((r) => r.filterValues), Z = c((r) => r.applyFilters), {
1904
+ const z = c((r) => r.selectedTableName), M = c((r) => r.card.sql), V = c((r) => r.card.python), F = rt(M, x), P = c((r) => r.selectedConnectionId), G = c((r) => r.frame), I = c((r) => r.filterValues), Z = c((r) => r.applyFilters), {
1905
1905
  setCardCustomCfg: ae,
1906
1906
  setQueryResultColumns: J,
1907
1907
  setFilterValues: te,
@@ -1915,7 +1915,7 @@ function $n() {
1915
1915
  ), se = c((r) => r.onClose), D = c((r) => r.actions.setCardData), Q = c((r) => r.actions.setSqlGen), ee = c((r) => r.runSql), ye = c((r) => r.actions.setRunSql), ge = c(
1916
1916
  (r) => r.actions.setIsSqlRunning
1917
1917
  ), {
1918
- data: P,
1918
+ data: K,
1919
1919
  isLoading: re,
1920
1920
  isFetching: ie,
1921
1921
  isSuccess: ve,
@@ -1929,7 +1929,7 @@ function $n() {
1929
1929
  "https://semaphor.cloud/api/v1/query",
1930
1930
  (i == null ? void 0 : i.accessToken) || "",
1931
1931
  {
1932
- connection_id: U,
1932
+ connection_id: P,
1933
1933
  sql: F,
1934
1934
  python: V === $s ? "" : V,
1935
1935
  active_filters: Z ? I : []
@@ -1938,22 +1938,22 @@ function $n() {
1938
1938
  enabled: !1,
1939
1939
  retry: !1
1940
1940
  });
1941
- K(() => {
1942
- if (P && (D(P.records), P.rowLimitExceeded && gs.error("Row limit (10,000) exceeded. Refine your query.", {
1941
+ U(() => {
1942
+ if (K && (D(K.records), K.rowLimitExceeded && gs.error("Row limit (10,000) exceeded. Refine your query.", {
1943
1943
  position: "top-center",
1944
1944
  richColors: !0
1945
- }), j((P == null ? void 0 : P.output) || ""), P.records.length > 0)) {
1946
- const { dimensionKeys: r } = bs(P.records);
1945
+ }), j((K == null ? void 0 : K.output) || ""), K.records.length > 0)) {
1946
+ const { dimensionKeys: r } = bs(K.records);
1947
1947
  J(r);
1948
1948
  }
1949
- }, [P, D, J, j]), K(() => {
1949
+ }, [K, D, J, j]), U(() => {
1950
1950
  ee && (ke(), ye(!1));
1951
- }, [ee, ke, ye]), K(() => {
1951
+ }, [ee, ke, ye]), U(() => {
1952
1952
  (re || ie) && ge(!0), (Se || ve) && ge(!1), Se ? (v(Ve.message), D([]), J([]), j("")) : v("");
1953
1953
  }, [
1954
1954
  re,
1955
1955
  ie,
1956
- P,
1956
+ K,
1957
1957
  j,
1958
1958
  Se,
1959
1959
  ve,
@@ -2009,7 +2009,7 @@ function $n() {
2009
2009
  };
2010
2010
  return `#${ms(ce)}${ms(de)}${ms(he)}`;
2011
2011
  }
2012
- K(() => {
2012
+ U(() => {
2013
2013
  const r = n.current, oe = a.current;
2014
2014
  if (r) {
2015
2015
  const Re = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light", Ne = w === "system" ? Re : w;
@@ -2393,7 +2393,7 @@ function ka({
2393
2393
  var m;
2394
2394
  xe.useState(0);
2395
2395
  const a = k((l) => l.themeStyle), t = c((l) => l.card), o = c((l) => l.actions.setCard);
2396
- if (K(() => {
2396
+ if (U(() => {
2397
2397
  }, [
2398
2398
  t.data,
2399
2399
  t.type,
@@ -2960,7 +2960,7 @@ function Ie() {
2960
2960
  var g;
2961
2961
  return (g = u.card.preferences) == null ? void 0 : g.filterOnClickColumnIndex;
2962
2962
  }
2963
- ), K(() => {
2963
+ ), U(() => {
2964
2964
  m && n(new Array(m.length).fill(!1));
2965
2965
  }, [m]);
2966
2966
  function l(u, g) {
@@ -3118,15 +3118,15 @@ function Da() {
3118
3118
  var O;
3119
3119
  return (O = j.card) == null ? void 0 : O.type;
3120
3120
  }), F = ["pie", "doughnut", "polarArea"].includes(V);
3121
- K(() => {
3122
- var j, O, q, fe, se, D, Q, ee, ye, ge, P, re, ie, ve;
3121
+ U(() => {
3122
+ var j, O, q, fe, se, D, Q, ee, ye, ge, K, re, ie, ve;
3123
3123
  m(Zs(a)), d(
3124
3124
  ((q = (O = (j = a == null ? void 0 : a.chartOptions) == null ? void 0 : j.scales) == null ? void 0 : O[o]) == null ? void 0 : q.min) === 0 ? 0 : ""
3125
3125
  ), u(((D = (se = (fe = a == null ? void 0 : a.chartOptions) == null ? void 0 : fe.scales) == null ? void 0 : se[o]) == null ? void 0 : D.max) || ""), x(
3126
3126
  ((ge = (ye = (ee = (Q = a == null ? void 0 : a.chartOptions) == null ? void 0 : Q.scales) == null ? void 0 : ee[o]) == null ? void 0 : ye.ticks) == null ? void 0 : ge.stepSize) || ""
3127
- ), w(((P = a == null ? void 0 : a.numberAxisFormat) == null ? void 0 : P.decimalPlaces) || 0), E(((re = a == null ? void 0 : a.numberAxisFormat) == null ? void 0 : re.suffix) || ""), A(((ie = a == null ? void 0 : a.numberAxisFormat) == null ? void 0 : ie.currency) || ""), z(((ve = a == null ? void 0 : a.numberAxisFormat) == null ? void 0 : ve.locale) || "");
3127
+ ), w(((K = a == null ? void 0 : a.numberAxisFormat) == null ? void 0 : K.decimalPlaces) || 0), E(((re = a == null ? void 0 : a.numberAxisFormat) == null ? void 0 : re.suffix) || ""), A(((ie = a == null ? void 0 : a.numberAxisFormat) == null ? void 0 : ie.currency) || ""), z(((ve = a == null ? void 0 : a.numberAxisFormat) == null ? void 0 : ve.locale) || "");
3128
3128
  }, [s, a, o]);
3129
- function U(j, O) {
3129
+ function P(j, O) {
3130
3130
  return O === "" || /^[0-9\b]+$/.test(O) ? Number(O) : Number(j);
3131
3131
  }
3132
3132
  function G() {
@@ -3191,7 +3191,7 @@ function Da() {
3191
3191
  {
3192
3192
  id: "min",
3193
3193
  value: l,
3194
- onChange: (j) => d((O) => U(O, j.target.value)),
3194
+ onChange: (j) => d((O) => P(O, j.target.value)),
3195
3195
  className: `col-span-1 h-8 w-full ${ze}`
3196
3196
  }
3197
3197
  ),
@@ -3199,7 +3199,7 @@ function Da() {
3199
3199
  le,
3200
3200
  {
3201
3201
  value: p,
3202
- onChange: (j) => u((O) => U(O, j.target.value)),
3202
+ onChange: (j) => u((O) => P(O, j.target.value)),
3203
3203
  id: "max",
3204
3204
  className: `col-span-1 h-8 w-full ${ze}`
3205
3205
  }
@@ -3211,7 +3211,7 @@ function Da() {
3211
3211
  le,
3212
3212
  {
3213
3213
  value: i,
3214
- onChange: (j) => x((O) => U(O, j.target.value)),
3214
+ onChange: (j) => x((O) => P(O, j.target.value)),
3215
3215
  id: "step-size",
3216
3216
  className: `col-span-1 h-8 w-full ${ze}`
3217
3217
  }
@@ -4289,9 +4289,9 @@ function xl() {
4289
4289
  }
4290
4290
  function pl({ authToken: s, onSave: n, onClose: a }) {
4291
4291
  const t = c((m) => m.actions.setOnSave), o = c((m) => m.actions.setOnClose), h = k((m) => m.actions.setAuthToken);
4292
- return K(() => {
4292
+ return U(() => {
4293
4293
  n && t(n), a && o(a);
4294
- }, [n, t, a, o]), K(() => {
4294
+ }, [n, t, a, o]), U(() => {
4295
4295
  s && s.accessToken && h(s);
4296
4296
  }, [s, h]), /* @__PURE__ */ e.jsxs(Ht, { className: "rounded-none", role: "editor-panel", children: [
4297
4297
  /* @__PURE__ */ e.jsx(Bt, { className: "rounded-none border-r-[1.5px]", children: /* @__PURE__ */ e.jsx(Na, {}) }),
@@ -158,7 +158,7 @@
158
158
  *
159
159
  * This source code is licensed under the ISC license.
160
160
  * See the LICENSE file in the root directory of this source tree.
161
- */const Fs=e.createLucideIcon("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);function Os(){const[s,n]=f.useState(""),[t,r]=f.useState(!1),[l,x]=f.useState(!1),u=e.useDashboardStore(c=>c.dashboard);function o(){const c=e.getDashbaordStateWithoutData(u),p=e.getBookmarkKey(u.id),d=JSON.parse(localStorage.getItem(p)||"[]");if(d.some(y=>y.name===s)){r(!0);return}d.push({name:s,template:c}),localStorage.setItem(p,JSON.stringify(d)),x(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:l,onOpenChange:x,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{variant:"outline",className:"h-7 p-2",size:"sm",children:[e.jsxRuntimeExports.jsx(e.Plus,{className:" mr-2 h-4 w-4",strokeWidth:1.5}),"Add Lens"]})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Add a Lens"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsxRuntimeExports.jsx("div",{className:"grid gap-4 py-4",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-right",children:"Name"}),e.jsxRuntimeExports.jsx(e.Input,{value:s,onChange:c=>{t&&r(!1),n(c.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),t&&e.jsxRuntimeExports.jsx("p",{className:"text-sm",children:"The bookmark name already exists. Use a differnet name."}),e.jsxRuntimeExports.jsx(e.DialogFooter,{children:e.jsxRuntimeExports.jsx(e.Button,{variant:"outline",type:"submit",disabled:!s,onClick:o,children:"Save"})})]})]})}function Ms(){const[s,n]=f.useState(!1),[t,r]=f.useState(""),l=e.useDashboardStore(a=>a.dashboard),x=e.useDashboardStore(a=>a.bookmarkKey),[u,o]=f.useState([]),c=e.useDashboardStore(a=>a.actions.setDashboard),p=e.useDashboardStore(a=>a.actions.setFilterValues),d=e.useDashboardStore(a=>a.actions.setBookmarkKey);f.useEffect(()=>{const a=e.getBookmarkKey(l.id),m=JSON.parse(localStorage.getItem(a)||"[]");o(m);const h=m.find(v=>v.default);h&&h.name===x&&r(h.name)},[s,l,x]);function j(a){if(a===t)return;const m=u.find(v=>v.name===a),h=m==null?void 0:m.template;h&&(c(h),p(m.filterValues||[]),d(a==="Original"?"":a)),r(a)}function y(a){const m=e.getBookmarkKey(l.id),v=JSON.parse(localStorage.getItem(m)||"[]").filter(S=>S.name!==a);localStorage.setItem(m,JSON.stringify(v)),o(v)}return e.jsxRuntimeExports.jsxs(e.DropdownMenu,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{variant:"outline",className:"h-7 p-2",children:e.jsxRuntimeExports.jsx(fs,{className:"h-4 w-4",strokeWidth:1.5})})}),e.jsxRuntimeExports.jsxs(e.DropdownMenuContent,{className:"w-56",children:[e.jsxRuntimeExports.jsx(e.DropdownMenuLabel,{children:"Lenses"}),e.jsxRuntimeExports.jsx(e.DropdownMenuSeparator,{}),e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioGroup,{value:t,onValueChange:j,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuRadioItem,{value:"Original",children:"Original"}),u.filter(a=>a.name!="Original").map((a,m)=>e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioItem,{className:"xbg-red-100 flex justify-between",value:a.name,defaultChecked:a.name===x,children:[e.jsxRuntimeExports.jsx("p",{children:a.name}),e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:h=>{h.preventDefault(),y(a.name)},className:"h-3 w-3 hover:cursor-pointer",strokeWidth:1.5})]},m))]})]})]})}function qs(){const[s,n]=f.useState(!1),t=e.useDashboardStore(x=>x.dashboard),r=e.useDashboardStore(x=>x.bookmarkKey);f.useEffect(()=>{if(!r){n(!1);return}const x=e.getBookmarkKey(t.id),o=JSON.parse(localStorage.getItem(x)||"[]").find(c=>c.name===r);n(o?o.default:!1)},[r,t.id]);function l(x){if(n(x),!r)return;const u=e.getBookmarkKey(t.id),c=JSON.parse(localStorage.getItem(u)||"[]").map(p=>(p.name===r?p.default=x:p.default=!1,p));console.log(c),localStorage.setItem(u,JSON.stringify(c))}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:s,onCheckedChange:l,id:"terms"}),e.jsxRuntimeExports.jsx("label",{htmlFor:"terms",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Set as default"})]})}function Bs(){const s=e.useDashboardStore(S=>S.bookmarkKey),n=e.useDashboardStore(S=>S.dashboard);e.useDashboardStore(S=>S.selectedSheetId);const t=e.useDashboardStore(S=>S.isDashboardEditing),r=e.useDashboardStore(S=>S.filterValues),l=e.useDashboardStore(S=>S.isVisualEditing),x=e.useDashboardStore(S=>S.showFilters);e.useDashboardStore(S=>S.showDashboardJSON);const u=e.useDashboardStore(S=>S.onSaveFunction),o=e.useDashboardStore(S=>S.actions.setShowFilters),{addFrame:c,setSelectedFrameId:p}=e.useDashboardStore(S=>S.actions),{getSelectedSheet:d,setIsDashboardEditing:j,setShowDashboardJSON:y}=e.useDashboardStore(S=>S.actions),a=d(),m=()=>{if(!t||!a)return;const S={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},z={id:e.v4(),cards:[S],activeCardId:S.id};c(a.id,z),p(z.id)},h=()=>{j(!0)};function v(){if(!s||s==="")return;const S=e.getDashbaordStateWithoutData(n),z=e.getBookmarkKey(n.id),R=JSON.parse(localStorage.getItem(z)||"[]"),A=R.findIndex(g=>g.name===s);A!==-1?R[A]={name:s,template:S,default:R[A].default,filterValues:r}:R.push({name:s,template:S,filterValues:r}),localStorage.setItem(z,JSON.stringify(R)),u==null||u(S)}return l?null:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-2 border-b bg-muted/50 px-2 py-2",role:"dashboard-controls",children:[!l&&e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:s}),!!s&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("span",{className:"text-muted-foreground",children:"|"}),e.jsxRuntimeExports.jsx(qs,{})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[t&&!l&&e.jsxRuntimeExports.jsx(Os,{}),!l&&e.jsxRuntimeExports.jsx(Ms,{}),t&&!l&&e.jsxRuntimeExports.jsxs(e.Button,{variant:"outline",className:"h-7 p-2",size:"sm",disabled:!t,onClick:m,children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Add Frame"]}),!t&&e.jsxRuntimeExports.jsx(e.Button,{variant:"outline",className:"h-7 p-2",onClick:h,size:"sm",children:e.jsxRuntimeExports.jsx($e,{className:"h-4 w-4",strokeWidth:1.5})}),t&&!l&&e.jsxRuntimeExports.jsx(e.Button,{variant:"outline",role:"close",className:"h-7 p-2",onClick:()=>{j(!1),y(!1)},size:"sm",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),t&&!l&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"outline",onClick:v,size:"sm",children:e.jsxRuntimeExports.jsx(As,{className:"h-4 w-4",strokeWidth:1.5})}),!x&&!l&&t&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"outline",onClick:()=>o(!0),size:"sm",children:e.jsxRuntimeExports.jsx(He,{className:"h-4 w-4",strokeWidth:1.5})}),!l&&t&&!1,!l&&!1]})]})}function ue({title:s,items:n,value:t,isLoading:r,isError:l,connectionTooltip:x,onChange:u,showNone:o=!1,className:c,showIcon:p=!0,disabled:d=!1}){const j=r?"Loading...":l?"Error":t;function y(){if(s==="Connection")return e.jsxRuntimeExports.jsx(ws,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(js,{className:"size-4"});if(s==="Schema")return e.jsxRuntimeExports.jsx(Ns,{className:"size-4"});if(s==="Table")return e.jsxRuntimeExports.jsx(e.Table,{className:"size-4"});if(s==="Dataset")return e.jsxRuntimeExports.jsx(ps,{className:"size-4"})}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[p&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:x?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:y()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:x})]}):y()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:d,value:j,onValueChange:u,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",c),children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:r?"Loading...":l?"Error":`Select ${s}`})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[r?e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Loading..."}):e.jsxRuntimeExports.jsx(e.SelectLabel,{children:s}),e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[o&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((a,m)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:a.id,children:a.name},m))]}),(r||l)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:j,children:j})]})})]})]})}function Vs({column:s}){const[n,t]=f.useState(!1),r=e.useEditorStore(d=>d.selectedTableName),l=e.useEditorStore(d=>d.selectedSchemaName),x=e.useEditorStore(d=>d.sqlGen),u=e.useEditorStore(d=>d.actions.setSqlGen),o=e.useEditorStore(d=>d.actions.setCardSql),c=e.useEditorStore(d=>d.actions.setRunSql);function p(d,j){const y=e.createSqlGenConfig(d,x,j);u(y);const a=e.getSql(y,e.fmt(l||""),e.fmt(r));a&&(o(a),c(!0)),t(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:n,onOpenChange:t,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.ChevronDown,{className:"h-4 w-4 cursor-pointer text-foreground/40"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{align:"center",className:"w-18 rounded-md p-0 shadow-none",children:e.jsxRuntimeExports.jsxs("ul",{className:"text-xs",children:[e.jsxRuntimeExports.jsx("li",{onClick:()=>p(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>p(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>p(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>p(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>p(s,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})})]})}function Qe({column:s}){return e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.$a093c7e1ec25a057$export$8c610744efcf8a1d,{asChild:!0,children:e.TEXT_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(Te,{className:"size-3"}):e.NUMBER_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(Rs,{className:"size-3"}):e.DATE_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(e.Calendar,{className:"size-3"}):e.BOOLEAN_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(Ts,{className:"size-3"}):e.jsxRuntimeExports.jsx(Is,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function _s({schemaName:s,tableName:n,columns:t,status:r}){const l=e.useEditorStore(g=>g.sqlGen),x=e.useEditorStore(g=>g.selectedConnectionId),u=e.useEditorStore(g=>g.selectedDatabaseName),o=e.useEditorStore(g=>g.selectedSchemaName),c=e.useEditorStore(g=>g.selectedTableName),p=e.useDashboardStore(g=>g.dashboard.aiScopeTables),{setAIScopeTables:d}=e.useDashboardStore(g=>g.actions),j=e.useEditorStore(g=>g.actions.setRunSql),y=e.useEditorStore(g=>g.actions.setSqlGen),a=e.useEditorStore(g=>g.actions.setIsShowingVisual),m=e.useEditorStore(g=>g.actions.setCardSql),{connectionType:h}=ve();function v(g){const C=e.createSqlGenConfig(g,l);y(C);const w=e.getSql(C,e.fmt(s),e.fmt(n));w&&(m(w),j(!0))}function S(){return(p==null?void 0:p.find(g=>g.connectinonId===x&&g.tableName===c))!==void 0}function z(g){if(g===!0&&c&&x){const C={connectinonId:x,connectionType:h,databaseName:u,schemaName:o,tableName:c},L=[...p||[],C].filter((N,M,q)=>q.findIndex(D=>D.connectinonId===N.connectinonId&&D.tableName===N.tableName)===M);d(L),e.Jt.success(`Added '${c}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const C=(p||[]).filter(w=>w.connectinonId!==x&&w.tableName!==c);d(C),e.Jt(`Removed '${c}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function R(){let C=e.getQualifiedTableName(s,n);(N=>N.charAt(0)===N.charAt(0).toUpperCase())(n)&&(C=`"${n}"`),a(!1);const L=h==="MSSQL"?`SELECT top 10 * FROM ${C}`:`SELECT * FROM ${C} LIMIT 10`;m(L),j(!0)}function A(){let C=e.getQualifiedTableName(s,n);(L=>L.charAt(0)===L.charAt(0).toUpperCase())(n)&&(C=`"${n}"`),a(!1),m(`SELECT COUNT(*) as count FROM ${C}`),j(!0)}return e.jsxRuntimeExports.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsxRuntimeExports.jsx(e.Toggle,{title:`${S()?"Remove from":"Add to"} AI Scope`,pressed:S(),onPressedChange:z,variant:"outline",className:"h-9 px-2",children:e.jsxRuntimeExports.jsx(e.Bot,{className:e.cn("size-4",{"text-primary":S(),"text-muted-foreground":!S()})})}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:R,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(Ds,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:A,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(zs,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"flex-1 basis-0 overflow-y-auto border-b border-t border-muted py-3",children:[t==null?void 0:t.map(g=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>v(g),className:e.cn("mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":e.isColumnInSqlGen(g,l)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(Qe,{column:g}),e.jsxRuntimeExports.jsx("span",{children:g.column_name})]}),e.NUMBER_DATA_TYPES.includes(g.data_type)&&e.jsxRuntimeExports.jsx("div",{onClick:C=>C.stopPropagation(),className:"flex items-center justify-end",children:e.jsxRuntimeExports.jsx(Vs,{column:g})})]},g.column_name)),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function ve(s,n){var Ee,fe,pe,ge,Re;let t=f.useMemo(()=>[],[]);const r=e.useSemaphorContext().authToken||s,l=e.useEditorStore(i=>i.selectedConnectionId),x=e.useEditorStore(i=>i.selectedDatamodelId),u=e.useEditorStore(i=>i.selectedDatabaseName),o=e.useEditorStore(i=>i.selectedSchemaName),c=e.useEditorStore(i=>i.selectedTableName),p=e.useEditorStore(i=>i.actions.setCurrentColumns),d=e.useEditorStore(i=>i.actions.setSelectedConnectionId),j=e.useEditorStore(i=>i.actions.setSelectedDatamodelId),y=e.useEditorStore(i=>i.actions.setSelectedDatabaseName),a=e.useEditorStore(i=>i.actions.setSelectedSchemaName),m=e.useEditorStore(i=>i.actions.setSelectedTableName),h=e.useEditorStore(i=>i.actions.setCardSql);function v(i){return l&&u&&o&&u!=="NA"?!0:l&&i==="API"?!1:!!(l&&i==="S3")}function S(i){return!!(l&&u&&u!=="NA"&&o&&c||l&&(i==="S3"||i==="API")||x&&x)}function z(i){return l&&i?!(i==="API"||i==="S3"):!1}const{data:R,isLoading:A,isError:g}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),{data:C,isLoading:w,isError:L}=e.useQuery({queryKey:["models",l],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/datamodels",(r==null?void 0:r.accessToken)||"",{connection_id:l}),enabled:!!(r!=null&&r.accessToken)&&!!l}),N=R==null?void 0:R.connections.find(i=>i.id===l),M=N==null?void 0:N.type,q=(N==null?void 0:N.type)==="API"||(N==null?void 0:N.type)==="S3",{data:D,isLoading:H,isFetching:K,isError:B,refetch:G}=e.useQuery({queryKey:["databases",l],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:l}),enabled:z(M)}),{data:F,isLoading:Q,isFetching:b,isError:E,refetch:k}=e.useQuery({queryKey:["schemas",l,u],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:l,database_name:u}),enabled:!!l&&!!u&&!q&&u!=="NA"}),{data:T,isLoading:se,isFetching:$,isError:I,refetch:V}=e.useQuery({queryKey:["tables",l,u,o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:l,database_name:u,schema_name:o}),enabled:v(M)}),{data:P,isLoading:ne,isFetching:te,isError:O}=e.useQuery({queryKey:["columns",l,u,x,o,c],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:l,datamodel_id:x||"",database_name:u,schema_name:o,table_name:c}),enabled:S(M)});f.useEffect(()=>{p(t)},[P,p,t]),f.useEffect(()=>{},[q,h,m,a,y,N]);const U=(N==null?void 0:N.type)==="API"?(Ee=N==null?void 0:N.type)==null?void 0:Ee.toLowerCase():c||"",J=q?"":o||"";function oe(i){a(i),m("")}function ae(i){y(i==="none"?"":i),a(""),m(""),i!=="none"&&i!==""&&j("")}function me(i){d(i)}function Oe(i){j(i==="none"?"":i),i!=="none"&&i!==""&&y("")}D&&((fe=D==null?void 0:D.databases)==null?void 0:fe.length)>0,F&&((pe=F==null?void 0:F.schemas)==null?void 0:pe.length)>0,P&&((ge=P==null?void 0:P.columns)==null?void 0:ge.length)>0&&(t=P.columns.map(i=>({...i,data_type:i.data_type.toLowerCase()}))),B&&(t=[]),(O||g)&&(t=[]);const le=R==null?void 0:R.connections.map(i=>({id:i.id,name:i.name,type:i.type})),Ne=(Re=C==null?void 0:C.datamodels)==null?void 0:Re.map(i=>({id:i.id,name:i.name})),je=D==null?void 0:D.databases.map(i=>({id:i.database_name,name:i.database_name})),ke=F==null?void 0:F.schemas.map(i=>({id:i.schema_name,name:i.schema_name})),we=T==null?void 0:T.tables.map(i=>({id:i.table_name,name:i.table_name}));return{connectionItems:le,isConnectionsLoading:A,isConnectionsError:g,modelItems:Ne,isModelsLoading:w,isModelsError:L,databaseItems:je,isDatabasesLoadingOrFetching:H||K,isDatabaseError:B,schemaItems:ke,isSchemaLoadingOrFetching:Q||b,isSchemaError:E,tableItems:we,isTableLoadingOrFetching:se||$,isTableError:I,columns:t,isColumnsLoadingOrFetching:ne||te,isColumnsError:O,isNonDbConnection:q,connectionType:M,tableName:U,schemaName:J,handleConnectionChange:me,handleDatamodelChange:Oe,handleDatabaseChange:ae,handleSchemaChange:oe}}function Ue({ColumnsComponent:s}){var $;const n=e.useEditorStore(I=>I.selectedConnectionId),t=e.useEditorStore(I=>I.selectedDatamodelId),r=e.useEditorStore(I=>I.selectedDatabaseName),l=e.useEditorStore(I=>I.selectedSchemaName),x=e.useEditorStore(I=>I.selectedTableName),u=e.useEditorStore(I=>I.actions.setSelectedTableName),{connectionItems:o,modelItems:c,schemaItems:p,databaseItems:d,tableItems:j,columns:y,isConnectionsLoading:a,isModelsLoading:m,isConnectionsError:h,isModelsError:v,isDatabasesLoadingOrFetching:S,isDatabaseError:z,isSchemaLoadingOrFetching:R,isSchemaError:A,isColumnsError:g,isColumnsLoadingOrFetching:C,isTableLoadingOrFetching:w,isTableError:L,connectionType:N,isNonDbConnection:M,handleConnectionChange:q,handleDatabaseChange:D,handleSchemaChange:H,handleDatamodelChange:K,tableName:B,schemaName:G}=ve();function F(){return s?s(G,B,y):e.jsxRuntimeExports.jsx(_s,{schemaName:G,tableName:B,columns:y,status:C?"Loading...":g?"Error":"Success"})}function Q(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function b(){if(!n||N==="S3"||N==="API")return null;if(!t||t==="none")return e.jsxRuntimeExports.jsx(ue,{showNone:!0,onChange:D,isError:z,isLoading:S,items:d,value:r||"",title:"Database"})}function E(){if(n&&(!r||r==="none")&&(!t||t==="none"))return e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3",children:[e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Separator,{})}),e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Label,{children:"OR"})}),e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Separator,{})})]})}function k(){if(!n||N==="S3"||N==="API")return null;if(!r||r==="none")return e.jsxRuntimeExports.jsx(ue,{showNone:!0,onChange:K,isError:v,isLoading:m,items:c,value:t||"",title:"Dataset"})}function T(){return!n||N==="S3"||N==="API"||!r||r==="none"?null:e.jsxRuntimeExports.jsx(ue,{onChange:H,isError:A,isLoading:R,items:p,value:l||"",title:"Schema"})}function se(){function I(){let V=!1;return N==="API"?(V=!1,V):((N==="S3"||n&&r&&r!=="none"&&l)&&(V=!0),V)}return I()?e.jsxRuntimeExports.jsx(ue,{onChange:u,isError:L,items:j,isLoading:w,value:x||"",title:"Table"}):null}return e.jsxRuntimeExports.jsxs("aside",{className:"xbg-red-100 flex grow flex-col justify-between",children:[e.jsxRuntimeExports.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsxRuntimeExports.jsx(ue,{items:o,title:"Connection",value:n||"",onChange:q,isLoading:a,isError:h,connectionTooltip:(($=o==null?void 0:o.find(I=>I.id===n))==null?void 0:$.type)||""}),k(),E(),b(),T(),se()]}),F(),e.jsxRuntimeExports.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxRuntimeExports.jsxs(e.Button,{onClick:Q,size:"sm",variant:"secondary",className:"w-full",children:[e.jsxRuntimeExports.jsx(Cs,{className:"mr-2 size-4"}),"Help"]})})]})}function Hs(s){const n=s.toUpperCase().indexOf("WHERE"),t=s.toUpperCase().indexOf("GROUP BY"),r=s.toUpperCase().indexOf("LIMIT"),l=s.toUpperCase().indexOf("ORDER BY");let x=s.length;if(l!==-1&&(x=l),r!==-1&&r<x&&(x=r),n!==-1){const u=s.substring(0,n),o=s.substring(n);return`${u} {{ filters | where }} AND ${o.substring(6)}`}else if(t!==-1){const u=s.substring(0,t),o=s.substring(t);return`${u} {{ filters | where }} ${o}`}else{const u=s.substring(0,x),o=s.substring(x);return`${u} {{ filters | where }} ${o}`}}function Ps({error:s,setShowAIDialog:n,setUserInputforAI:t,setTriggerAIRun:r}){return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{variant:"link",className:" p-0 h-5",children:e.jsxRuntimeExports.jsx(hs,{className:"h-4 w-4 text-red-500"})})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"start",className:" min-w-fit max-w-[500px]",children:e.jsxRuntimeExports.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxRuntimeExports.jsxs("div",{className:"grow space-y-1 flex flex-col ",children:[e.jsxRuntimeExports.jsxs(e.Button,{onClick:()=>{n(!0),t(s),r(!0)},size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(gs,{className:"h-4 w-4 mr-2"}),"Fix It"]}),e.jsxRuntimeExports.jsx(e.ScrollArea,{className:" min-h-0 max-h-[250px] overflow-scroll ",children:e.jsxRuntimeExports.jsx("p",{className:" overflow-auto text-sm leading-relaxed font-mono ",children:s})})]})})})]})}function $s({text:s,onCheckedChange:n,checked:t}){return e.jsxRuntimeExports.jsxs("div",{className:"xbg-red-100 ml-6 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:t,onCheckedChange:n}),e.jsxRuntimeExports.jsx("label",{className:"text-xs leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:s})]})}function Ks(){const{authToken:s}=e.useSemaphorContext(),n=e.useEditorStore(x=>x.selectedConnectionId),{data:t}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(s==null?void 0:s.accessToken)||""),enabled:!!(s!=null&&s.accessToken)}),r=t==null?void 0:t.connections.find(x=>x.id===n);return r==null?void 0:r.type}function Gs(){const{authToken:s}=e.useSemaphorContext(),n=f.useRef(null),t=e.useEditorStore(c=>c.applyFilters),[r,l]=f.useState(""),x=e.useEditorStore(c=>c.filterValues),u=e.useEditorStore(c=>c.card.sql),o=Ks();return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,onOpenChange:async c=>{if(!c)return;console.log("onOpenChange");const p=await e.postRequest("https://semaphor.cloud/api/v1/filter-sql",(s==null?void 0:s.accessToken)||"",{sql:u,active_filters:x,connection_type:o});console.log(p),p.sql?(console.log(p.records),l(p.sql)):l("Error")},children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:t&&e.jsxRuntimeExports.jsx("p",{className:"p-0 text-xs hover:cursor-pointer",children:"|  Filter Query"})}),e.jsxRuntimeExports.jsxs(e.HoverCardContent,{align:"end",className:"w-[600px]",children:[e.jsxRuntimeExports.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxRuntimeExports.jsx("div",{className:"rounded-sm bg-muted p-2",children:e.jsxRuntimeExports.jsxs("code",{ref:n,className:"font-mono text-sm",children:[r,e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{onClick:()=>e.copyToClipboard(n),className:"ml-3 inline-block h-4 w-4 opacity-70 hover:cursor-pointer hover:opacity-100"})]})})}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsxRuntimeExports.jsx(e.InfoCircledIcon,{className:"h-4 w-4 opacity-70"}),e.jsxRuntimeExports.jsx("span",{className:"text-xs text-muted-foreground",children:"A preview of the query with filters applied."})]})]})]})}const Qs=`
161
+ */const Fs=e.createLucideIcon("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);function Os(){const[s,n]=f.useState(""),[t,r]=f.useState(!1),[l,x]=f.useState(!1),u=e.useDashboardStore(c=>c.dashboard);function o(){const c=e.getDashbaordStateWithoutData(u),p=e.getBookmarkKey(u.id),d=JSON.parse(localStorage.getItem(p)||"[]");if(d.some(y=>y.name===s)){r(!0);return}d.push({name:s,template:c}),localStorage.setItem(p,JSON.stringify(d)),x(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:l,onOpenChange:x,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{variant:"outline",className:"h-7 p-2",size:"sm",children:[e.jsxRuntimeExports.jsx(e.Plus,{className:" mr-2 h-4 w-4",strokeWidth:1.5}),"Add Lens"]})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Add a Lens"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsxRuntimeExports.jsx("div",{className:"grid gap-4 py-4",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-right",children:"Name"}),e.jsxRuntimeExports.jsx(e.Input,{value:s,onChange:c=>{t&&r(!1),n(c.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),t&&e.jsxRuntimeExports.jsx("p",{className:"text-sm",children:"The bookmark name already exists. Use a differnet name."}),e.jsxRuntimeExports.jsx(e.DialogFooter,{children:e.jsxRuntimeExports.jsx(e.Button,{variant:"outline",type:"submit",disabled:!s,onClick:o,children:"Save"})})]})]})}function Ms(){const[s,n]=f.useState(!1),[t,r]=f.useState(""),l=e.useDashboardStore(a=>a.dashboard),x=e.useDashboardStore(a=>a.bookmarkKey),[u,o]=f.useState([]),c=e.useDashboardStore(a=>a.actions.setDashboard),p=e.useDashboardStore(a=>a.actions.setFilterValues),d=e.useDashboardStore(a=>a.actions.setBookmarkKey);f.useEffect(()=>{const a=e.getBookmarkKey(l.id),m=JSON.parse(localStorage.getItem(a)||"[]");o(m);const h=m.find(v=>v.default);h&&h.name===x&&r(h.name)},[s,l,x]);function j(a){if(a===t)return;const m=u.find(v=>v.name===a),h=m==null?void 0:m.template;h&&(c(h),p(m.filterValues||[]),d(a==="Original"?"":a)),r(a)}function y(a){const m=e.getBookmarkKey(l.id),v=JSON.parse(localStorage.getItem(m)||"[]").filter(S=>S.name!==a);localStorage.setItem(m,JSON.stringify(v)),o(v)}return e.jsxRuntimeExports.jsxs(e.DropdownMenu,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{variant:"outline",className:"h-7 p-2",children:e.jsxRuntimeExports.jsx(fs,{className:"h-4 w-4",strokeWidth:1.5})})}),e.jsxRuntimeExports.jsxs(e.DropdownMenuContent,{className:"w-56",children:[e.jsxRuntimeExports.jsx(e.DropdownMenuLabel,{children:"Lenses"}),e.jsxRuntimeExports.jsx(e.DropdownMenuSeparator,{}),e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioGroup,{value:t,onValueChange:j,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuRadioItem,{value:"Original",children:"Original"}),u.filter(a=>a.name!="Original").map((a,m)=>e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioItem,{className:"xbg-red-100 flex justify-between",value:a.name,defaultChecked:a.name===x,children:[e.jsxRuntimeExports.jsx("p",{children:a.name}),e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:h=>{h.preventDefault(),y(a.name)},className:"h-3 w-3 hover:cursor-pointer",strokeWidth:1.5})]},m))]})]})]})}function qs(){const[s,n]=f.useState(!1),t=e.useDashboardStore(x=>x.dashboard),r=e.useDashboardStore(x=>x.bookmarkKey);f.useEffect(()=>{if(!r){n(!1);return}const x=e.getBookmarkKey(t.id),o=JSON.parse(localStorage.getItem(x)||"[]").find(c=>c.name===r);n(o?o.default:!1)},[r,t.id]);function l(x){if(n(x),!r)return;const u=e.getBookmarkKey(t.id),c=JSON.parse(localStorage.getItem(u)||"[]").map(p=>(p.name===r?p.default=x:p.default=!1,p));console.log(c),localStorage.setItem(u,JSON.stringify(c))}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:s,onCheckedChange:l,id:"terms"}),e.jsxRuntimeExports.jsx("label",{htmlFor:"terms",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Set as default"})]})}function Bs(){const s=e.useDashboardStore(S=>S.bookmarkKey),n=e.useDashboardStore(S=>S.dashboard);e.useDashboardStore(S=>S.selectedSheetId);const t=e.useDashboardStore(S=>S.isDashboardEditing),r=e.useDashboardStore(S=>S.filterValues),l=e.useDashboardStore(S=>S.isVisualEditing),x=e.useDashboardStore(S=>S.showFilters);e.useDashboardStore(S=>S.showDashboardJSON);const u=e.useDashboardStore(S=>S.onSaveFunction),o=e.useDashboardStore(S=>S.actions.setShowFilters),{addFrame:c,setSelectedFrameId:p}=e.useDashboardStore(S=>S.actions),{getSelectedSheet:d,setIsDashboardEditing:j,setShowDashboardJSON:y}=e.useDashboardStore(S=>S.actions),a=d(),m=()=>{if(!t||!a)return;const S={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},z={id:e.v4(),cards:[S],activeCardId:S.id};c(a.id,z),p(z.id)},h=()=>{j(!0)};function v(){if(!s||s==="")return;const S=e.getDashbaordStateWithoutData(n),z=e.getBookmarkKey(n.id),R=JSON.parse(localStorage.getItem(z)||"[]"),A=R.findIndex(g=>g.name===s);A!==-1?R[A]={name:s,template:S,default:R[A].default,filterValues:r}:R.push({name:s,template:S,filterValues:r}),localStorage.setItem(z,JSON.stringify(R)),u==null||u(S)}return l?null:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-2 border-b bg-muted/50 px-2 py-2",role:"dashboard-controls",children:[!l&&e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:s}),!!s&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("span",{className:"text-muted-foreground",children:"|"}),e.jsxRuntimeExports.jsx(qs,{})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[t&&!l&&e.jsxRuntimeExports.jsx(Os,{}),!l&&e.jsxRuntimeExports.jsx(Ms,{}),t&&!l&&e.jsxRuntimeExports.jsxs(e.Button,{variant:"outline",className:"h-7 p-2",size:"sm",disabled:!t,onClick:m,children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Add Frame"]}),!t&&e.jsxRuntimeExports.jsx(e.Button,{variant:"outline",className:"h-7 p-2",onClick:h,size:"sm",children:e.jsxRuntimeExports.jsx($e,{className:"h-4 w-4",strokeWidth:1.5})}),t&&!l&&e.jsxRuntimeExports.jsx(e.Button,{variant:"outline",role:"close",className:"h-7 p-2",onClick:()=>{j(!1),y(!1)},size:"sm",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),t&&!l&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"outline",onClick:v,size:"sm",children:e.jsxRuntimeExports.jsx(As,{className:"h-4 w-4",strokeWidth:1.5})}),!x&&!l&&t&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"outline",onClick:()=>o(!0),size:"sm",children:e.jsxRuntimeExports.jsx(He,{className:"h-4 w-4",strokeWidth:1.5})}),!l&&t&&!1,!l&&!1]})]})}function ue({title:s,items:n,value:t,isLoading:r,isError:l,connectionTooltip:x,onChange:u,showNone:o=!1,className:c,showIcon:p=!0,disabled:d=!1}){const j=r?"Loading...":l?"Error":t;function y(){if(s==="Connection")return e.jsxRuntimeExports.jsx(ws,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(js,{className:"size-4"});if(s==="Schema")return e.jsxRuntimeExports.jsx(Ns,{className:"size-4"});if(s==="Table")return e.jsxRuntimeExports.jsx(e.Table,{className:"size-4"});if(s==="Dataset")return e.jsxRuntimeExports.jsx(ps,{className:"size-4"})}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[p&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:x?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:y()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:x})]}):y()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:d,value:j,onValueChange:u,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",c),children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:r?"Loading...":l?"Error":`Select ${s}`})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[r?e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Loading..."}):e.jsxRuntimeExports.jsx(e.SelectLabel,{children:s}),e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[o&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((a,m)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:a.id,children:a.name},m))]}),(r||l)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:j,children:j})]})})]})]})}function Vs({column:s}){const[n,t]=f.useState(!1),r=e.useEditorStore(d=>d.selectedTableName),l=e.useEditorStore(d=>d.selectedSchemaName),x=e.useEditorStore(d=>d.sqlGen),u=e.useEditorStore(d=>d.actions.setSqlGen),o=e.useEditorStore(d=>d.actions.setCardSql),c=e.useEditorStore(d=>d.actions.setRunSql);function p(d,j){const y=e.createSqlGenConfig(d,x,j);u(y);const a=e.getSql(y,e.fmt(l||""),e.fmt(r));a&&(o(a),c(!0)),t(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:n,onOpenChange:t,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.ChevronDown,{className:"h-4 w-4 cursor-pointer text-foreground/40"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{align:"center",className:"w-18 rounded-md p-0 shadow-none",children:e.jsxRuntimeExports.jsxs("ul",{className:"text-xs",children:[e.jsxRuntimeExports.jsx("li",{onClick:()=>p(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>p(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>p(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>p(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>p(s,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})})]})}function Qe({column:s}){return e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.$a093c7e1ec25a057$export$8c610744efcf8a1d,{asChild:!0,children:e.TEXT_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(Te,{className:"size-3"}):e.NUMBER_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(Rs,{className:"size-3"}):e.DATE_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(e.Calendar,{className:"size-3"}):e.BOOLEAN_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(Ts,{className:"size-3"}):e.jsxRuntimeExports.jsx(Is,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function _s({schemaName:s,tableName:n,columns:t,status:r}){const l=e.useEditorStore(g=>g.sqlGen),x=e.useEditorStore(g=>g.selectedConnectionId),u=e.useEditorStore(g=>g.selectedDatabaseName),o=e.useEditorStore(g=>g.selectedSchemaName),c=e.useEditorStore(g=>g.selectedTableName),p=e.useDashboardStore(g=>g.dashboard.aiScopeTables),{setAIScopeTables:d}=e.useDashboardStore(g=>g.actions),j=e.useEditorStore(g=>g.actions.setRunSql),y=e.useEditorStore(g=>g.actions.setSqlGen),a=e.useEditorStore(g=>g.actions.setIsShowingVisual),m=e.useEditorStore(g=>g.actions.setCardSql),{connectionType:h}=ve();function v(g){const C=e.createSqlGenConfig(g,l);y(C);const w=e.getSql(C,e.fmt(s),e.fmt(n));w&&(m(w),j(!0))}function S(){return(p==null?void 0:p.find(g=>g.connectinonId===x&&g.tableName===c))!==void 0}function z(g){if(g===!0&&c&&x){const C={connectinonId:x,connectionType:h,databaseName:u,schemaName:o,tableName:c},L=[...p||[],C].filter((N,O,q)=>q.findIndex(D=>D.connectinonId===N.connectinonId&&D.tableName===N.tableName)===O);d(L),e.Jt.success(`Added '${c}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const C=(p||[]).filter(w=>w.connectinonId!==x&&w.tableName!==c);d(C),e.Jt(`Removed '${c}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function R(){let C=e.getQualifiedTableName(s,n);(N=>N.charAt(0)===N.charAt(0).toUpperCase())(n)&&(C=`"${n}"`),a(!1);const L=h==="MSSQL"?`SELECT top 10 * FROM ${C}`:`SELECT * FROM ${C} LIMIT 10`;m(L),j(!0)}function A(){let C=e.getQualifiedTableName(s,n);(L=>L.charAt(0)===L.charAt(0).toUpperCase())(n)&&(C=`"${n}"`),a(!1),m(`SELECT COUNT(*) as count FROM ${C}`),j(!0)}return e.jsxRuntimeExports.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsxRuntimeExports.jsx(e.Toggle,{title:`${S()?"Remove from":"Add to"} AI Scope`,pressed:S(),onPressedChange:z,variant:"outline",className:"h-9 px-2",children:e.jsxRuntimeExports.jsx(e.Bot,{className:e.cn("size-4",{"text-primary":S(),"text-muted-foreground":!S()})})}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:R,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(Ds,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:A,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(zs,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"flex-1 basis-0 overflow-y-auto border-b border-t border-muted py-3",children:[t==null?void 0:t.map(g=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>v(g),className:e.cn("mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":e.isColumnInSqlGen(g,l)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(Qe,{column:g}),e.jsxRuntimeExports.jsx("span",{children:g.column_name})]}),e.NUMBER_DATA_TYPES.includes(g.data_type)&&e.jsxRuntimeExports.jsx("div",{onClick:C=>C.stopPropagation(),className:"flex items-center justify-end",children:e.jsxRuntimeExports.jsx(Vs,{column:g})})]},g.column_name)),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function ve(s,n){var Ee,fe,pe,ge,Re;let t=f.useMemo(()=>[],[]);const r=e.useSemaphorContext().authToken||s,l=e.useEditorStore(i=>i.selectedConnectionId),x=e.useEditorStore(i=>i.selectedDatamodelId),u=e.useEditorStore(i=>i.selectedDatabaseName),o=e.useEditorStore(i=>i.selectedSchemaName),c=e.useEditorStore(i=>i.selectedTableName),p=e.useEditorStore(i=>i.actions.setCurrentColumns),d=e.useEditorStore(i=>i.actions.setSelectedConnectionId),j=e.useEditorStore(i=>i.actions.setSelectedDatamodelId),y=e.useEditorStore(i=>i.actions.setSelectedDatabaseName),a=e.useEditorStore(i=>i.actions.setSelectedSchemaName),m=e.useEditorStore(i=>i.actions.setSelectedTableName),h=e.useEditorStore(i=>i.actions.setCardSql);function v(i){return l&&u&&o&&u!=="NA"?!0:l&&i==="API"?!1:!!(l&&i==="S3")}function S(i){return!!(l&&u&&u!=="NA"&&o&&c||l&&(i==="S3"||i==="API")||x&&x)}function z(i){return l&&i?!(i==="API"||i==="S3"):!1}const{data:R,isLoading:A,isError:g}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),{data:C,isLoading:w,isError:L}=e.useQuery({queryKey:["models",l],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/datamodels",(r==null?void 0:r.accessToken)||"",{connection_id:l}),enabled:!!(r!=null&&r.accessToken)&&!!l}),N=R==null?void 0:R.connections.find(i=>i.id===l),O=N==null?void 0:N.type,q=(N==null?void 0:N.type)==="API"||(N==null?void 0:N.type)==="S3",{data:D,isLoading:H,isFetching:K,isError:B,refetch:G}=e.useQuery({queryKey:["databases",l],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:l}),enabled:z(O)}),{data:F,isLoading:Q,isFetching:b,isError:E,refetch:k}=e.useQuery({queryKey:["schemas",l,u],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:l,database_name:u}),enabled:!!l&&!!u&&!q&&u!=="NA"}),{data:T,isLoading:se,isFetching:$,isError:I,refetch:V}=e.useQuery({queryKey:["tables",l,u,o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:l,database_name:u,schema_name:o}),enabled:v(O)}),{data:P,isLoading:ne,isFetching:te,isError:M}=e.useQuery({queryKey:["columns",l,u,x,o,c],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:l,datamodel_id:x||"",database_name:u,schema_name:o,table_name:c}),enabled:S(O)});f.useEffect(()=>{p(t)},[P,p,t]),f.useEffect(()=>{},[q,h,m,a,y,N]);const U=(N==null?void 0:N.type)==="API"?(Ee=N==null?void 0:N.type)==null?void 0:Ee.toLowerCase():c||"",J=q?"":o||"";function oe(i){a(i),m("")}function ae(i){y(i==="none"?"":i),a(""),m(""),i!=="none"&&i!==""&&j("")}function me(i){d(i)}function Oe(i){j(i==="none"?"":i),i!=="none"&&i!==""&&y("")}D&&((fe=D==null?void 0:D.databases)==null?void 0:fe.length)>0,F&&((pe=F==null?void 0:F.schemas)==null?void 0:pe.length)>0,P&&((ge=P==null?void 0:P.columns)==null?void 0:ge.length)>0&&(t=P.columns.map(i=>({...i,data_type:i.data_type.toLowerCase()}))),B&&(t=[]),(M||g)&&(t=[]);const le=R==null?void 0:R.connections.map(i=>({id:i.id,name:i.name,type:i.type})),Ne=(Re=C==null?void 0:C.datamodels)==null?void 0:Re.map(i=>({id:i.id,name:i.name})),je=D==null?void 0:D.databases.map(i=>({id:i.database_name,name:i.database_name})),ke=F==null?void 0:F.schemas.map(i=>({id:i.schema_name,name:i.schema_name})),we=T==null?void 0:T.tables.map(i=>({id:i.table_name,name:i.table_name}));return{connectionItems:le,isConnectionsLoading:A,isConnectionsError:g,modelItems:Ne,isModelsLoading:w,isModelsError:L,databaseItems:je,isDatabasesLoadingOrFetching:H||K,isDatabaseError:B,schemaItems:ke,isSchemaLoadingOrFetching:Q||b,isSchemaError:E,tableItems:we,isTableLoadingOrFetching:se||$,isTableError:I,columns:t,isColumnsLoadingOrFetching:ne||te,isColumnsError:M,isNonDbConnection:q,connectionType:O,tableName:U,schemaName:J,handleConnectionChange:me,handleDatamodelChange:Oe,handleDatabaseChange:ae,handleSchemaChange:oe}}function Ue({ColumnsComponent:s}){var $;const n=e.useEditorStore(I=>I.selectedConnectionId),t=e.useEditorStore(I=>I.selectedDatamodelId),r=e.useEditorStore(I=>I.selectedDatabaseName),l=e.useEditorStore(I=>I.selectedSchemaName),x=e.useEditorStore(I=>I.selectedTableName),u=e.useEditorStore(I=>I.actions.setSelectedTableName),{connectionItems:o,modelItems:c,schemaItems:p,databaseItems:d,tableItems:j,columns:y,isConnectionsLoading:a,isModelsLoading:m,isConnectionsError:h,isModelsError:v,isDatabasesLoadingOrFetching:S,isDatabaseError:z,isSchemaLoadingOrFetching:R,isSchemaError:A,isColumnsError:g,isColumnsLoadingOrFetching:C,isTableLoadingOrFetching:w,isTableError:L,connectionType:N,isNonDbConnection:O,handleConnectionChange:q,handleDatabaseChange:D,handleSchemaChange:H,handleDatamodelChange:K,tableName:B,schemaName:G}=ve();function F(){return s?s(G,B,y):e.jsxRuntimeExports.jsx(_s,{schemaName:G,tableName:B,columns:y,status:C?"Loading...":g?"Error":"Success"})}function Q(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function b(){if(!n||N==="S3"||N==="API")return null;if(!t||t==="none")return e.jsxRuntimeExports.jsx(ue,{showNone:!0,onChange:D,isError:z,isLoading:S,items:d,value:r||"",title:"Database"})}function E(){if(n&&!O&&(!r||r==="none")&&(!t||t==="none"))return e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3",children:[e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Separator,{})}),e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Label,{children:"OR"})}),e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Separator,{})})]})}function k(){if(!n||N==="S3"||N==="API")return null;if(!r||r==="none")return e.jsxRuntimeExports.jsx(ue,{showNone:!0,onChange:K,isError:v,isLoading:m,items:c,value:t||"",title:"Dataset"})}function T(){return!n||N==="S3"||N==="API"||!r||r==="none"?null:e.jsxRuntimeExports.jsx(ue,{onChange:H,isError:A,isLoading:R,items:p,value:l||"",title:"Schema"})}function se(){function I(){let V=!1;return N==="API"?(V=!1,V):((N==="S3"||n&&r&&r!=="none"&&l)&&(V=!0),V)}return I()?e.jsxRuntimeExports.jsx(ue,{onChange:u,isError:L,items:j,isLoading:w,value:x||"",title:"Table"}):null}return e.jsxRuntimeExports.jsxs("aside",{className:"xbg-red-100 flex grow flex-col justify-between",children:[e.jsxRuntimeExports.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsxRuntimeExports.jsx(ue,{items:o,title:"Connection",value:n||"",onChange:q,isLoading:a,isError:h,connectionTooltip:(($=o==null?void 0:o.find(I=>I.id===n))==null?void 0:$.type)||""}),k(),E(),b(),T(),se()]}),F(),e.jsxRuntimeExports.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxRuntimeExports.jsxs(e.Button,{onClick:Q,size:"sm",variant:"secondary",className:"w-full",children:[e.jsxRuntimeExports.jsx(Cs,{className:"mr-2 size-4"}),"Help"]})})]})}function Hs(s){const n=s.toUpperCase().indexOf("WHERE"),t=s.toUpperCase().indexOf("GROUP BY"),r=s.toUpperCase().indexOf("LIMIT"),l=s.toUpperCase().indexOf("ORDER BY");let x=s.length;if(l!==-1&&(x=l),r!==-1&&r<x&&(x=r),n!==-1){const u=s.substring(0,n),o=s.substring(n);return`${u} {{ filters | where }} AND ${o.substring(6)}`}else if(t!==-1){const u=s.substring(0,t),o=s.substring(t);return`${u} {{ filters | where }} ${o}`}else{const u=s.substring(0,x),o=s.substring(x);return`${u} {{ filters | where }} ${o}`}}function Ps({error:s,setShowAIDialog:n,setUserInputforAI:t,setTriggerAIRun:r}){return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{variant:"link",className:" p-0 h-5",children:e.jsxRuntimeExports.jsx(hs,{className:"h-4 w-4 text-red-500"})})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"start",className:" min-w-fit max-w-[500px]",children:e.jsxRuntimeExports.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxRuntimeExports.jsxs("div",{className:"grow space-y-1 flex flex-col ",children:[e.jsxRuntimeExports.jsxs(e.Button,{onClick:()=>{n(!0),t(s),r(!0)},size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(gs,{className:"h-4 w-4 mr-2"}),"Fix It"]}),e.jsxRuntimeExports.jsx(e.ScrollArea,{className:" min-h-0 max-h-[250px] overflow-scroll ",children:e.jsxRuntimeExports.jsx("p",{className:" overflow-auto text-sm leading-relaxed font-mono ",children:s})})]})})})]})}function $s({text:s,onCheckedChange:n,checked:t}){return e.jsxRuntimeExports.jsxs("div",{className:"xbg-red-100 ml-6 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:t,onCheckedChange:n}),e.jsxRuntimeExports.jsx("label",{className:"text-xs leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:s})]})}function Ks(){const{authToken:s}=e.useSemaphorContext(),n=e.useEditorStore(x=>x.selectedConnectionId),{data:t}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(s==null?void 0:s.accessToken)||""),enabled:!!(s!=null&&s.accessToken)}),r=t==null?void 0:t.connections.find(x=>x.id===n);return r==null?void 0:r.type}function Gs(){const{authToken:s}=e.useSemaphorContext(),n=f.useRef(null),t=e.useEditorStore(c=>c.applyFilters),[r,l]=f.useState(""),x=e.useEditorStore(c=>c.filterValues),u=e.useEditorStore(c=>c.card.sql),o=Ks();return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,onOpenChange:async c=>{if(!c)return;console.log("onOpenChange");const p=await e.postRequest("https://semaphor.cloud/api/v1/filter-sql",(s==null?void 0:s.accessToken)||"",{sql:u,active_filters:x,connection_type:o});console.log(p),p.sql?(console.log(p.records),l(p.sql)):l("Error")},children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:t&&e.jsxRuntimeExports.jsx("p",{className:"p-0 text-xs hover:cursor-pointer",children:"|  Filter Query"})}),e.jsxRuntimeExports.jsxs(e.HoverCardContent,{align:"end",className:"w-[600px]",children:[e.jsxRuntimeExports.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxRuntimeExports.jsx("div",{className:"rounded-sm bg-muted p-2",children:e.jsxRuntimeExports.jsxs("code",{ref:n,className:"font-mono text-sm",children:[r,e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{onClick:()=>e.copyToClipboard(n),className:"ml-3 inline-block h-4 w-4 opacity-70 hover:cursor-pointer hover:opacity-100"})]})})}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsxRuntimeExports.jsx(e.InfoCircledIcon,{className:"h-4 w-4 opacity-70"}),e.jsxRuntimeExports.jsx("span",{className:"text-xs text-muted-foreground",children:"A preview of the query with filters applied."})]})]})]})}const Qs=`
162
162
 
163
163
  Use the following syntax to create a chart query. Please replace the x-axis, y-axis, stack-by, label, and measure with the actual column names of the table.
164
164
 
@@ -212,4 +212,4 @@ SELECT label, measure FROM table
212
212
  Table Columns: ${S==null?void 0:S.map(b=>`${b.column_name} | ${b.data_type}`).join(", ")}
213
213
  User SQL: ${z}
214
214
  ${y&&`Base Queries: ${JSON.stringify(y)} `}`,g=` When the user asks for a specific chart please use the following query structure to generate the chart query. Do not make up the column names. Use only the table columns provided above for the query. Replace x-axis, y-axis, and lables with the appropriate column names.
215
- Visual Query Syntax: ${Qs}`,{data:C,isLoading:w,isFetching:L,isError:N,refetch:M}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(c==null?void 0:c.accessToken)||"",{user_content:`userContent: ${A} ${p?g:""}`}),enabled:!1});function q(b){if(b.toLowerCase().includes("bar"))m("bar");else if(b.toLowerCase().includes("line"))m("line");else if(b.toLowerCase().includes("bubble"))m("bubble");else if(b.toLowerCase().includes("scatter"))m("scatter");else if(b.toLowerCase().includes("stacked"))m("stackedBar");else if(b.toLowerCase().includes("pie"))m("pie");else if(b.toLowerCase().includes("donut")||b.toLowerCase().includes("doughnut"))m("doughnut");else if(b.toLowerCase().includes("radar"))m("radar");else return m("bar"),!1;return!0}f.useEffect(()=>{C&&v(b=>[...b,{role:"ai",content:C.response}])},[C]),f.useEffect(()=>{const b=setTimeout(()=>{var E;o.current&&(o.current.scroll({top:o.current.scrollHeight,behavior:"smooth"}),(E=u.current)==null||E.focus())},100);return()=>clearTimeout(b)},[h]);function D(){t&&(v(b=>[...b,{role:"user",content:t}]),q(t)&&d(!0),r(""),M())}f.useEffect(()=>{l&&(D(),x(!1))},[l,x]);const H={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},K={fontFamily:"monospace",fontSize:14,lineHeight:1.6},B={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},G={p:({node:b,...E})=>e.jsxRuntimeExports.jsx("p",{style:H,...E}),code:({node:b,...E})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...E}),pre:({node:b,...E})=>e.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:K,children:[e.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:E.children}),e.jsxRuntimeExports.jsxs("div",{className:"flex justify-start gap-2",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:F,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:k=>{const T=F(k);T&&(n(!1),j(T),a(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:b,...E})=>e.jsxRuntimeExports.jsx("li",{style:B,...E})};function F(b){const E=b.currentTarget.closest("pre");if(!E)return;const k=E.textContent||E.innerText;return navigator.clipboard.writeText(k).then(()=>console.log("Text copied to clipboard")).catch(T=>console.error("Error in copying text: ",T)),k}function Q(){return h==null?void 0:h.map((b,E)=>b.role==="user"?e.jsxRuntimeExports.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[e.jsxRuntimeExports.jsx(Fs,{className:"mr-2 h-5 w-5"}),e.jsxRuntimeExports.jsx("div",{children:b.content})]},E):b.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:G,children:C==null?void 0:C.response.replace(/DuckDB/gi,"Semaphor")},E):e.jsxRuntimeExports.jsx("div",{},E))}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",className:"w-full justify-start border font-normal text-muted-foreground focus-visible:ring-0 focus-visible:ring-offset-0",variant:"secondary",children:"Type your question here..."})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[625px] md:min-w-[625px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Assistant"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"What can I help you with?"})]}),e.jsxRuntimeExports.jsx("div",{ref:o,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:e.jsxRuntimeExports.jsx("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:Q()})}),e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsxs("div",{className:"flex w-full items-center rounded-md border",children:[e.jsxRuntimeExports.jsx(e.Textarea,{autoFocus:!0,ref:u,onKeyDown:b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),r(""),D())},placeholder:"Type your question here...",onFocus:b=>{const E=b.target,k=E.value.length;E.setSelectionRange(k,k)},className:e.cn("max-h-10 min-h-7 resize-none border-none focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"),disabled:w||L,value:t,onChange:b=>r(b.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:D,children:!w&&!L?e.jsxRuntimeExports.jsx(e.PaperPlaneIcon,{}):e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var Je={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},qe=f.createContext&&f.createContext(Je),Js=["attr","size","title"];function Ws(s,n){if(s==null)return{};var t=Ys(s,n),r,l;if(Object.getOwnPropertySymbols){var x=Object.getOwnPropertySymbols(s);for(l=0;l<x.length;l++)r=x[l],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(t[r]=s[r])}return t}function Ys(s,n){if(s==null)return{};var t={},r=Object.keys(s),l,x;for(x=0;x<r.length;x++)l=r[x],!(n.indexOf(l)>=0)&&(t[l]=s[l]);return t}function Se(){return Se=Object.assign?Object.assign.bind():function(s){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(s[r]=t[r])}return s},Se.apply(this,arguments)}function Be(s,n){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(s);n&&(r=r.filter(function(l){return Object.getOwnPropertyDescriptor(s,l).enumerable})),t.push.apply(t,r)}return t}function ye(s){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?Be(Object(t),!0).forEach(function(r){Xs(s,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):Be(Object(t)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(t,r))})}return s}function Xs(s,n,t){return n=Zs(n),n in s?Object.defineProperty(s,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[n]=t,s}function Zs(s){var n=et(s,"string");return typeof n=="symbol"?n:String(n)}function et(s,n){if(typeof s!="object"||s===null)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var r=t.call(s,n||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(s)}function We(s){return s&&s.map((n,t)=>f.createElement(n.tag,ye({key:t},n.attr),We(n.child)))}function ee(s){return n=>f.createElement(st,Se({attr:ye({},s.attr)},n),We(s.child))}function st(s){var n=t=>{var{attr:r,size:l,title:x}=s,u=Ws(s,Js),o=l||t.size||"1em",c;return t.className&&(c=t.className),s.className&&(c=(c?c+" ":"")+s.className),f.createElement("svg",Se({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,r,u,{className:c,style:ye(ye({color:s.color||t.color},t.style),s.style),height:o,width:o,xmlns:"http://www.w3.org/2000/svg"}),x&&f.createElement("title",null,x),s.children)};return qe!==void 0?f.createElement(qe.Consumer,null,t=>n(t)):n(Je)}function tt(s){return ee({tag:"svg",attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(s)}function rt(){const{theme:s}=e.useTheme(),n=f.useRef(),t=f.useRef(),[r,l]=f.useState(!1),[x,u]=f.useState(!1),[o,c]=f.useState(!1),[p,d]=f.useState(""),[j,y]=f.useState(!1),{authToken:a}=e.useSemaphorContext();e.useDashboardStore(i=>i.selectedSheetId);const m=e.useDashboardStore(i=>i.dashboard.baseQueries),h=e.useEditorStore(i=>i.card),v=e.useDashboardStore(i=>i.theme),S=e.useEditorStore(i=>i.isShowingVisual),z=e.useEditorStore(i=>i.selectedConnectionId),R=e.useEditorStore(i=>i.selectedDatabaseName),A=e.useEditorStore(i=>i.selectedDatamodelId),g=e.useEditorStore(i=>i.selectedSchemaName);e.useDashboardStore(i=>i.actions.updateFrameCard);const C=e.useEditorStore(i=>i.selectedTableName),w=e.useEditorStore(i=>i.card.sql),L=e.useEditorStore(i=>i.card.python),N=e.resolveBaseQuery(w,m),M=e.useEditorStore(i=>i.selectedConnectionId),q=e.useEditorStore(i=>i.frame),D=e.useEditorStore(i=>i.filterValues),H=e.useEditorStore(i=>i.applyFilters),{setCardCustomCfg:K,setQueryResultColumns:B,setFilterValues:G,setCardSql:F,setCardPython:Q,setQueryError:b,setPythonStdOut:E,setCardPreferences:k}=e.useEditorStore(i=>i.actions),T=e.useEditorStore(i=>i.onSave),se=e.useEditorStore(i=>i.actions.setApplyFilters),$=e.useEditorStore(i=>i.onClose),I=e.useEditorStore(i=>i.actions.setCardData),V=e.useEditorStore(i=>i.actions.setSqlGen),P=e.useEditorStore(i=>i.runSql),ne=e.useEditorStore(i=>i.actions.setRunSql),te=e.useEditorStore(i=>i.actions.setIsSqlRunning),{data:O,isLoading:U,isFetching:J,isSuccess:oe,isError:ae,error:me,status:Oe,refetch:le}=e.useQuery({queryKey:[N,L],queryFn:()=>e.postRequest("https://semaphor.cloud/api/v1/query",(a==null?void 0:a.accessToken)||"",{connection_id:M,sql:N,python:L===e.PYTHON_DEFAULT_CODE?"":L,active_filters:H?D:[]}),enabled:!1,retry:!1});f.useEffect(()=>{if(O&&(I(O.records),O.rowLimitExceeded&&e.Jt.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),E((O==null?void 0:O.output)||""),O.records.length>0)){const{dimensionKeys:i}=e.getKeys(O.records);B(i)}},[O,I,B,E]),f.useEffect(()=>{P&&(le(),ne(!1))},[P,le,ne]),f.useEffect(()=>{(U||J)&&te(!0),(ae||oe)&&te(!1),ae?(b(me.message),I([]),B([]),E("")):b("")},[U,J,O,E,ae,oe,te,I,B,b,me]);function Ne(){F(""),I([]),V({}),K(""),k({})}const je=i=>{t.current=i};function ke(){let i=w;w&&!w.includes("{{")&&(i=Hs(w),F(i));const W={...h,lastSelectedSchema:g,lastSelectedDatamodelId:A,lastSelectedDatabase:R,lastSelectedTable:C,connectionId:z,type:S?h.type:"table",sql:i,customCfg:S?h.customCfg:null},he=q.cards.map(ie=>ie.id===h.id?W:ie);T==null||T({...q,cards:he})}function we(){$==null||$()}function Ee(i){const W=getComputedStyle(document.documentElement).getPropertyValue(i);return fe(W)}function fe(i){const[W,he,ie]=i.split(" "),_=parseFloat(W),ls=parseFloat(he),cs=parseFloat(ie),xs=ls/100,Me=cs/100,re=(1-Math.abs(2*Me-1))*xs,ce=re*(1-Math.abs(_/60%2-1)),Ae=Me-re/2;let Y=0,X=0,Z=0;0<=_&&_<60?(Y=re,X=ce,Z=0):60<=_&&_<120?(Y=ce,X=re,Z=0):120<=_&&_<180?(Y=0,X=re,Z=ce):180<=_&&_<240?(Y=0,X=ce,Z=re):240<=_&&_<300?(Y=ce,X=0,Z=re):300<=_&&_<360&&(Y=re,X=0,Z=ce),Y=Math.round((Y+Ae)*255),X=Math.round((X+Ae)*255),Z=Math.round((Z+Ae)*255);const Ie=us=>{const ze=us.toString(16);return ze.length==1?"0"+ze:ze};return`#${Ie(Y)}${Ie(X)}${Ie(Z)}`}f.useEffect(()=>{const i=n.current,W=t.current;if(i){const he=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",ie=v==="system"?he:v;i.editor.defineTheme("default",{base:ie==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":ie==="light"?"#ffffff":Ee("--semaphor-background")}}),i.editor.setTheme("default")}return W&&i&&W.addCommand(i.KeyMod.Shift|i.KeyCode.Enter,function(){return console.log("Executing query..."),le(),!1}),()=>{}},[s,v,n.current]);function pe(i){n.current=i}function ge(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[x&&e.jsxRuntimeExports.jsx("div",{className:"xbg-yellow-100 relative flex w-1/3 min-w-0 grow overflow-hidden border-l p-1 text-xs",role:"editor-filter-container",children:e.jsxRuntimeExports.jsxs("div",{className:"w-[99%]",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[e.jsxRuntimeExports.jsx($s,{checked:H,onCheckedChange:()=>se(!H),text:"Apply Filters"}),e.jsxRuntimeExports.jsx(Gs,{}),D&&x&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>u(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",onChange:i=>{if(i)try{JSON.parse(i),G(JSON.parse(i))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(D,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),D&&!x&&e.jsxRuntimeExports.jsx(He,{onClick:()=>u(!0),className:e.cn("absolute bottom-4 right-6 h-3 w-3 text-foreground/50 hover:cursor-pointer hover:text-foreground",{"font-bold text-red-800":H})})]})}function Re(){return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"1",order:1,defaultSize:r?20:100,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{role:"sql-container",className:"relative flex w-[99%]",children:e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",className:"pt-3",onChange:i=>{F(i)},value:w,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",defaultValue:"SELECT * FROM table",beforeMount:pe,onMount:je})}),r&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),r&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{role:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"pt-3",theme:"default",onChange:i=>{Q(i&&i.trim()||"")},value:L||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",beforeMount:pe,onMount:je})}),e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"python"})]})]})]})}return e.jsxRuntimeExports.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxRuntimeExports.jsxs("div",{role:"sql-editor",className:"relative flex grow justify-between overflow-y-scroll",children:[Re(),ge()]}),e.jsxRuntimeExports.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{title:"Shift + Enter",disabled:U||J,onClick:()=>{le()},className:"shrink-0",size:"sm",variant:"outline",children:[U||J?e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(ks,{className:"mr-2 h-4 w-4"}),"Run"]}),ae&&e.jsxRuntimeExports.jsx(Ps,{error:me.message,setShowAIDialog:c,setTriggerAIRun:y,setUserInputforAI:d}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:Ne,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(Es,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:r,onPressedChange:i=>l(i),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(tt,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(Us,{open:o,setOpen:c,userInput:p,triggerAIRun:j,setTriggerAIRun:y,setUserInput:i=>d(i)})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{onClick:ke,size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:we,className:"w-full",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"mr-2 size-4"}),"Close"]})]})]})]})}function nt({data:s}){var u;const[n,t]=f.useState([]),l=Object.keys(s[0]).map(o=>({accessorKey:o,header:({column:c})=>{const p=c.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>c.toggleSorting(c.getIsSorted()==="asc"),children:[o,p==="asc"?e.jsxRuntimeExports.jsx(e.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):p==="desc"?e.jsxRuntimeExports.jsx(e.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),x=e.useReactTable({data:s,columns:l,getCoreRowModel:e.getCoreRowModel(),getPaginationRowModel:e.getPaginationRowModel(),onSortingChange:t,getSortedRowModel:e.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsxRuntimeExports.jsxs(e.Table$1,{children:[e.jsxRuntimeExports.jsx(e.TableHeader,{children:x.getHeaderGroups().map(o=>e.jsxRuntimeExports.jsx(e.TableRow,{children:o.headers.map(c=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 bg-muted",children:c.isPlaceholder?null:e.flexRender(c.column.columnDef.header,c.getContext())},c.id))},o.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(u=x.getRowModel().rows)!=null&&u.length?x.getRowModel().rows.map(o=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":o.getIsSelected()&&"selected",children:o.getVisibleCells().map(c=>e.jsxRuntimeExports.jsx(e.TableCell,{children:e.flexRender(c.column.columnDef.cell,c.getContext())},c.id))},o.id)):e.jsxRuntimeExports.jsx(e.TableRow,{children:e.jsxRuntimeExports.jsx(e.TableCell,{colSpan:l.length,className:"h-24 text-center",children:"No results."})})})]})}function Ye({className:s,...n}){var u;f.useState(0);const t=e.useDashboardStore(o=>o.themeStyle),r=e.useEditorStore(o=>o.card),l=e.useEditorStore(o=>o.actions.setCard);if(f.useEffect(()=>{},[r.data,r.type,r.cfg,r.customCfg,t,r.preferences]),!r.id)return null;let x;return r.data&&r.data.length>0&&(x=e.createChartConfig({data:r.data,cardType:r.type,cfg:r.cfg,customCfg:r.customCfg,preferences:r.preferences})),e.jsxRuntimeExports.jsxs(e.Card,{role:"editor-visual-card",className:e.cn("relative flex h-full flex-col rounded-none",s),...n,children:[e.jsxRuntimeExports.jsxs(e.CardHeader,{className:"py-4",children:[e.jsxRuntimeExports.jsx(e.Editable,{text:r.title,onSave:o=>l({...r,title:o}),children:e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:r.title})})},r.title),e.jsxRuntimeExports.jsx(e.Editable,{text:r.description||"",onSave:o=>l({...r,description:o}),children:e.jsxRuntimeExports.jsxs(e.CardDescription,{children:[" ",r.description]})},r.description)]}),e.jsxRuntimeExports.jsxs(e.CardContent,{className:"flex grow flex-col pb-3",children:[r.type!=="table"&&x&&e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:x},JSON.stringify(x)+JSON.stringify(r.preferences)+((u=r==null?void 0:r.preferences)==null?void 0:u.customVisualCode)),r.type==="table"&&r.data&&r.data.length>0&&e.jsxRuntimeExports.jsx(e.$57acba87d6e25586$export$ccf8d8d7bbf3c2cc,{className:"flex min-h-0 flex-1 grow basis-0",children:e.jsxRuntimeExports.jsx(e.TableVisual,{card:r,data:r==null?void 0:r.data})})]})]})}function ot(){const[s,n]=f.useState(!1),[t,r]=f.useState(""),[l,x]=f.useState(""),[u,o]=f.useState(""),[c,p]=f.useState(""),d=e.useEditorStore(R=>R.card),j=e.useEditorStore(R=>R.card.customCfg),{setCardCustomCfg:y,setCustomVisualCode:a}=e.useEditorActions();function m(R){var C,w;const A={...R,data:{...R==null?void 0:R.data,datasets:(w=(C=R==null?void 0:R.data)==null?void 0:C.datasets)==null?void 0:w.map(L=>({...L,data:[]}))}};return JSON.stringify(A,null,1)}function h(){var A,g;if(!d.data||d.data.length===0)return;const R=e.createChartConfig({data:d.data,cardType:d.type,cfg:d.cfg,preferences:d.preferences});R&&(r(JSON.stringify(R,null,1)),(A=d==null?void 0:d.preferences)!=null&&A.customVisualCode&&o((g=d==null?void 0:d.preferences)==null?void 0:g.customVisualCode),j&&x(JSON.stringify(j,null,1)))}function v(){if(u&&a(u),!!l)try{const R=JSON.parse(l);return R?(y(R),p(""),x(""),R):void 0}catch(R){console.log(R),p("Invalid JSON")}}function S(){x(""),y(null)}function z(){let R;if(j){const A=e._.cloneDeep(d.cfg),g=e._.merge(A,j);return R=m(g),R}return t?(R=m(JSON.parse(t)),R):""}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{onClick:h,className:` ${j&&"border-foreground/50 dark:border-foreground/70"}`,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.Settings,{className:"h-4 w-4"})})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{className:"",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Customize Card"}),e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:e.jsxRuntimeExports.jsx(bs,{onClick:()=>{navigator.clipboard.writeText(d.id)},className:"size-3 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{side:"right",align:"center",children:e.jsxRuntimeExports.jsx("p",{className:"text-xs",children:"Copy Card ID"})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogDescription,{children:["See the configuration options and documentation",e.jsxRuntimeExports.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex grow gap-2",children:[e.jsxRuntimeExports.jsx(Ye,{className:"w-1/2 rounded shadow-none"}),e.jsxRuntimeExports.jsxs(e.Tabs,{defaultValue:"custom-config",className:"flex w-1/2 flex-col",children:[e.jsxRuntimeExports.jsxs(e.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsxRuntimeExports.jsxs(e.TabsTrigger,{value:"custom-config",children:[j&&e.jsxRuntimeExports.jsx(e.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),j?"Custom Config":"Default Config"]}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"output",children:"Output"}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"custom-code",children:"Custom Code"})]}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"bg-red-x mt-0 grow rounded-b border border-t-0 p-2",value:"output",children:e.jsxRuntimeExports.jsx(e.Textarea,{disabled:!0,value:t,className:"h-full resize-none border-none font-mono focus-visible:ring-0 focus-visible:ring-offset-0"})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-config",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"json",value:z(),onChange:R=>x(R)})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-code",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"javascript",value:u,onChange:R=>o(R||"")})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:c}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!j,onClick:S,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:v,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>n(!1),variant:"outline",children:"Close"})]})]})]})}function Xe(s){return ee({tag:"svg",attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M926.8 397.1l-396-288a31.81 31.81 0 0 0-37.6 0l-396 288a31.99 31.99 0 0 0-11.6 35.8l151.3 466a32 32 0 0 0 30.4 22.1h489.5c13.9 0 26.1-8.9 30.4-22.1l151.3-466c4.2-13.2-.5-27.6-11.7-35.8zM838.6 417l-98.5 32-200-144.7V199.9L838.6 417zM466 567.2l-89.1 122.3-55.2-169.2L466 567.2zm-116.3-96.8L484 373.3v140.8l-134.3-43.7zM512 599.2l93.9 128.9H418.1L512 599.2zm28.1-225.9l134.2 97.1L540.1 514V373.3zM558 567.2l144.3-46.9-55.2 169.2L558 567.2zm-74-367.3v104.4L283.9 449l-98.5-32L484 199.9zM169.3 470.8l86.5 28.1 80.4 246.4-53.8 73.9-113.1-348.4zM327.1 853l50.3-69h269.3l50.3 69H327.1zm414.5-33.8l-53.8-73.9 80.4-246.4 86.5-28.1-113.1 348.4z"},child:[]}]})(s)}function Ze(s){return ee({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M137.39,24.06A16,16,0,0,0,120,40V80.67a15.86,15.86,0,0,0,13.25,15.76A32,32,0,1,1,96,129.68c-.41-8.22,1.27-15,5-20.26h0a15.86,15.86,0,0,0-1.69-20.47L71.69,60.68a16,16,0,0,0-23.63,1.1A103.6,103.6,0,0,0,55,202.05,103.24,103.24,0,0,0,128,232h1.49A104.3,104.3,0,0,0,232,129.48C232.75,75.18,191.19,28.88,137.39,24.06ZM60.32,71.94l27.61,28.19,0,.06A43.29,43.29,0,0,0,80.44,120H40.36A87.13,87.13,0,0,1,60.32,71.94ZM40.37,136h40.3A48,48,0,0,0,120,175.34v40.3A88,88,0,0,1,40.37,136Zm149.77,54.14A87.45,87.45,0,0,1,136,215.61V175.34a47.55,47.55,0,0,0,24.73-12.23A48,48,0,0,0,136,80.66L136,40c45.52,4.08,80.67,43.28,80,89.25A87.45,87.45,0,0,1,190.14,190.14Z"},child:[]}]})(s)}function es(s){return ee({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(s)}function ss(s){return ee({tag:"svg",attr:{viewBox:"0 0 24 24",strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},child:[]},{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(s)}function ts(s){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(s)}function rs(s){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M4 9h4v11H4zM4 4h4v4H4zM10 7h4v4h-4zM16 10h4v4h-4zM16 15h4v5h-4zM10 12h4v8h-4z"},child:[]}]})(s)}function ns(s){return ee({tag:"svg",attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(s)}function os(s){return ee({tag:"svg",attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M217 25v14h78V25h-78zm0 32v46h14V71h50v32h14V57h-78zm32 32v14h14V89h-14zm-64 32v46h30v-46h-30zm48 0v14h46v-14h-46zm64 0v46h30v-46h-30zm-64 32v14h46v-14h-46zm-80 32v46h62v-46h-62zm80 0v14h46v-14h-46zm64 0v46h62v-46h-62zm-64 32v14h46v-14h-46zm-112 32v46h94v-46h-94zm112 0v14h46v-14h-46zm64 0v46h94v-46h-94zm-64 32v14h46v-14h-46zM89 313v46h126v-46H89zm144 0v14h46v-14h-46zm64 0v46h126v-46H297zm-64 32v14h46v-14h-46zM57 377v46h158v-46H57zm176 0v14h46v-14h-46zm64 0v46h158v-46H297zm-64 32v14h46v-14h-46zM25 441v46h190v-46H25zm208 0v14h46v-14h-46zm64 0v46h190v-46H297zm-64 32v14h46v-14h-46z"},child:[]}]})(s)}function it(){const[s,n]=f.useState(!1),t=e.useEditorStore(c=>c.card.type),{setCardType:r,setCardPreferences:l,setChartOrientation:x}=e.useEditorStore(c=>c.actions),u=e.useEditorStore(c=>c.actions.setCardCustomCfg);function o(c){u(null),l({}),r(c),n(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(at,{className:"h-4 w-4",chartType:t})})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-50",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 place-items-center",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(De,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Le,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(rs,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ts,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ge,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ss,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ke,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ze,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Xe,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(es,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(os,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Pe,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Table,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ns,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Te,{className:"size-4"})})]})})]})}function at({chartType:s,className:n}){switch(s){case"bar":return e.jsxRuntimeExports.jsx(De,{className:n});case"line":return e.jsxRuntimeExports.jsx(Le,{className:n});case"pie":return e.jsxRuntimeExports.jsx(Ke,{className:n});case"radar":return e.jsxRuntimeExports.jsx(Xe,{className:n});case"scatter":return e.jsxRuntimeExports.jsx(Ge,{className:n});case"bubble":return e.jsxRuntimeExports.jsx(ss,{className:n});case"doughnut":return e.jsxRuntimeExports.jsx(Ze,{className:n});case"stackedBar":return e.jsxRuntimeExports.jsx(rs,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsxRuntimeExports.jsx(ts,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(es,{className:n});case"pyramid":return e.jsxRuntimeExports.jsx(os,{className:n});case"range":return e.jsxRuntimeExports.jsx(Pe,{className:n});case"kpi":return e.jsxRuntimeExports.jsx(ns,{className:n});case"text":return e.jsxRuntimeExports.jsx(Te,{className:n});default:return e.jsxRuntimeExports.jsx(e.Table,{className:n})}}function lt(){const s=e.useEditorStore(t=>t.card.refreshInterval),n=e.useEditorStore(t=>t.actions.setCardRefreshInterval);return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(ds,{className:"w-4 h-4"})})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-[200px]",children:e.jsxRuntimeExports.jsx("div",{className:"grid gap-4",children:e.jsxRuntimeExports.jsx("div",{className:"grid gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-5 items-center gap-1",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-3",htmlFor:"width",children:"Refresh Every"}),e.jsxRuntimeExports.jsx(e.Input,{value:s||"",onChange:t=>n(t.target.value),id:"width",placeholder:"30s",className:"col-span-2 h-7 focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0"})]})})})})]})}function Ve(){e.useEditorStore(o=>o.frame);const s=e.useEditorStore(o=>o.card),n=e.useEditorStore(o=>o.card.data),t=e.useEditorStore(o=>o.isShowingVisual),r=e.useEditorStore(o=>o.isSqlRunning),l=e.useEditorStore(o=>o.queryError),x=e.useEditorStore(o=>o.pythonStdOut);if(e.useEditorStore(o=>o.onSave),e.useEditorStore(o=>o.onClose),e.useEditorStore(o=>o.actions.setCardSql),e.useEditorStore(o=>o.actions.setCardType),e.useEditorStore(o=>o.actions.setSqlGen),!s)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function u(){return s.type==="kpi"?e.jsxRuntimeExports.jsx("div",{className:"flex grow items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.KPICard,{isLoading:r,card:s})})}):s.type==="text"?e.jsxRuntimeExports.jsx("div",{className:"flex grow items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.TextCard,{isLoading:r,card:s})})}):e.jsxRuntimeExports.jsx(Ye,{className:"grow border-none shadow-none"})}return e.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col pt-3",children:[r&&e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"absolute bottom-0 left-0 right-0 top-0 z-10 m-auto h-10 w-10 animate-spin text-foreground/10"}),e.jsxRuntimeExports.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[t&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsx(it,{}),s.type!=="table"&&e.jsxRuntimeExports.jsx(ot,{}),e.jsxRuntimeExports.jsx(lt,{})]}),e.jsxRuntimeExports.jsx(xt,{})]}),t?u():e.jsxRuntimeExports.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[x&&e.jsxRuntimeExports.jsx(ct,{}),s.data&&s.data.length>0&&e.jsxRuntimeExports.jsx(nt,{data:n||[]}),l&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-sm",children:l})]})]})}function ct(){const s=e.useEditorStore(t=>t.pythonStdOut);if(!s)return null;const n=s.replace(/\n/g,"<br>");return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("p",{className:"font-mono text-sm",children:"Output:"}),e.jsxRuntimeExports.jsx("div",{dangerouslySetInnerHTML:{__html:n},className:"bg-muted p-2 font-mono text-sm"}),e.jsxRuntimeExports.jsx(e.Separator,{className:"mb-2"})]})}function xt(){const s=e.useEditorStore(t=>t.isShowingVisual),n=e.useEditorStore(t=>t.actions.setIsShowingVisual);return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"visualize",children:"Chart"}),e.jsxRuntimeExports.jsx(e.Switch,{checked:s,onCheckedChange:()=>n(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function de(){const[s,n]=f.useState([]);e.useEditorStore(d=>d.card.cfg);const t=e.useEditorStore(d=>d.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:l,setCardPreferences:x}=e.useEditorStore(d=>d.actions),u=e.useEditorStore(d=>d.queryResultColumns);e.useEditorStore(d=>{var j;return(j=d.card.preferences)==null?void 0:j.filterOnClickColumnIndex}),f.useEffect(()=>{u&&n(new Array(u.length).fill(!1))},[u]);function o(d,j){var y,a;j?t!=null&&t.onClickFilter&&((y=t==null?void 0:t.onClickFilter)==null?void 0:y.length)>0?x({...t,onClickFilter:[...t.onClickFilter,{columnIndex:d,expression:""}]}):x({...t,onClickFilter:[{columnIndex:d,expression:""}]}):(x({...t,onClickFilter:(a=t==null?void 0:t.onClickFilter)==null?void 0:a.filter(m=>m.columnIndex!==d)}),n(m=>{const h=[...m];return h[d]=!1,h}))}function c(d,j){var a;const y=(a=t==null?void 0:t.onClickFilter)==null?void 0:a.map(m=>m.columnIndex===d?{...m,expression:j.target.value}:m);x({...t,onClickFilter:y})}function p(d){var j,y,a,m;if(s!=null&&s[d]||(y=(j=t==null?void 0:t.onClickFilter)==null?void 0:j.find(h=>h.columnIndex===d))!=null&&y.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(m=(a=t==null?void 0:t.onClickFilter)==null?void 0:a.find(h=>h.columnIndex===d))==null?void 0:m.expression,onChange:h=>c(d,h),type:"text",className:" h-9 w-full focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0 font-mono text-xs",placeholder:"Expression"})}return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:u==null?void 0:u.map((d,j)=>{var y,a;return e.jsxRuntimeExports.jsx("div",{className:"flex items-center justify-between space-y-2 xbg-red-100 group",children:e.jsxRuntimeExports.jsxs("div",{className:" grow",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center py-2 space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((y=t==null?void 0:t.onClickFilter)!=null&&y.find(m=>m.columnIndex===j)),onCheckedChange:m=>o(j,m)}),e.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:d}),e.jsxRuntimeExports.jsx("div",{className:"flex gap-2 items-center ",children:((a=t==null?void 0:t.onClickFilter)==null?void 0:a.find(m=>m.columnIndex===j))&&e.jsxRuntimeExports.jsx($e,{onClick:()=>{n(m=>{const h=[...m];return h[j]=!m[j],h})},className:" invisible group-hover:visible size-3 text-gray-400 cursor-pointer"})})]}),p(j)]})},d)})})}function Ce(){var u,o,c;const s=e.useEditorStore(p=>p.card.preferences),n=e.useEditorStore(p=>p.card.cfg),{setCardCfg:t,setCardPreferences:r,setChartOrientation:l}=e.useEditorStore(p=>p.actions);(u=n==null?void 0:n.options)!=null&&u.indexAxis;function x(p){l(p)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((o=s==null?void 0:s.chartOptions)==null?void 0:o.indexAxis)||((c=n==null?void 0:n.options)==null?void 0:c.indexAxis)||"x",onValueChange:x,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"x",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"y",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const xe="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function _e(s,n){var r,l,x;const t=e.getNumberAxis(s,n);return((x=(l=(r=s==null?void 0:s.chartOptions)==null?void 0:r.scales)==null?void 0:l[t])==null?void 0:x.type)||"linear"}function is(){var K,B,G,F,Q,b;const[s,n]=f.useState(!1),t=e.useEditorStore(E=>{var k;return(k=E.card)==null?void 0:k.preferences}),r=e.useEditorStore(E=>{var k;return(k=E.card)==null?void 0:k.cfg}),l=e.getNumberAxis(t,r),[x,u]=f.useState(_e(t)),[o,c]=f.useState(((G=(B=(K=t==null?void 0:t.chartOptions)==null?void 0:K.scales)==null?void 0:B[l])==null?void 0:G.min)||""),[p,d]=f.useState(((b=(Q=(F=t==null?void 0:t.chartOptions)==null?void 0:F.scales)==null?void 0:Q[l])==null?void 0:b.max)||""),[j,y]=f.useState(o||p?"custom":"auto"),[a,m]=f.useState(""),[h,v]=f.useState(0),[S,z]=f.useState(""),[R,A]=f.useState(""),[g,C]=f.useState(""),w=e.useEditorStore(E=>E.actions.setCardPreferences),L=e.useEditorStore(E=>{var k;return(k=E.card)==null?void 0:k.type}),N=["pie","doughnut","polarArea"].includes(L);f.useEffect(()=>{var E,k,T,se,$,I,V,P,ne,te,O,U,J,oe;u(_e(t)),c(((T=(k=(E=t==null?void 0:t.chartOptions)==null?void 0:E.scales)==null?void 0:k[l])==null?void 0:T.min)===0?0:""),d(((I=($=(se=t==null?void 0:t.chartOptions)==null?void 0:se.scales)==null?void 0:$[l])==null?void 0:I.max)||""),m(((te=(ne=(P=(V=t==null?void 0:t.chartOptions)==null?void 0:V.scales)==null?void 0:P[l])==null?void 0:ne.ticks)==null?void 0:te.stepSize)||""),v(((O=t==null?void 0:t.numberAxisFormat)==null?void 0:O.decimalPlaces)||0),z(((U=t==null?void 0:t.numberAxisFormat)==null?void 0:U.suffix)||""),A(((J=t==null?void 0:t.numberAxisFormat)==null?void 0:J.currency)||""),C(((oe=t==null?void 0:t.numberAxisFormat)==null?void 0:oe.locale)||"")},[s,t,l]);function M(E,k){return k===""||/^[0-9\b]+$/.test(k)?Number(k):Number(E)}function q(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsxRuntimeExports.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxRuntimeExports.jsx(e.Input,{value:R,placeholder:"USD",onChange:E=>A(E.target.value),id:"currency",className:`col-span-2 h-8 w-full ${xe}`}),e.jsxRuntimeExports.jsx(e.Input,{value:g,placeholder:"en-US",onChange:E=>C(E.target.value),id:"locale",className:`col-span-2 h-8 w-full ${xe}`})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsxRuntimeExports.jsx(e.Input,{value:h,onChange:E=>v(Number(E.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${xe}`})]})]})}function D(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"range",children:"Range"}),e.jsxRuntimeExports.jsx(e.Input,{id:"min",value:o,onChange:E=>c(k=>M(k,E.target.value)),className:`col-span-1 h-8 w-full ${xe}`}),e.jsxRuntimeExports.jsx(e.Input,{value:p,onChange:E=>d(k=>M(k,E.target.value)),id:"max",className:`col-span-1 h-8 w-full ${xe}`})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsxRuntimeExports.jsx(e.Input,{value:a,onChange:E=>m(k=>M(k,E.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${xe}`})]})]})}function H(){var T;let E={};j==="custom"&&(E={min:o,max:p,ticks:{stepSize:a}});const k={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(T=t==null?void 0:t.chartOptions)==null?void 0:T.scales,[l]:{type:x,...x==="linear"?E:{}}}},numberAxisFormat:{decimalPlaces:h,suffix:S,currency:R,locale:g}};console.log(k),w(k)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:E=>n(E),children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.SliderIcon,{className:"size-4 cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{align:"center",className:"max-w-65",children:e.jsxRuntimeExports.jsxs("div",{className:"grid gap-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsxRuntimeExports.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale",children:"Type"}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:N,value:x,onValueChange:E=>u(E),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{id:"type",children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Option"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"linear",children:"Linear"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),x=="linear"&&e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxRuntimeExports.jsxs(e.RadioGroup,{disabled:N,id:"scale-option",value:j,onValueChange:E=>y(E),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"auto",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"custom",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),j==="custom"&&x=="linear"&&D(),q(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:H,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function ut({idx:s}){var o;const n=e.useEditorStore(c=>{var p;return(p=c.card)==null?void 0:p.preferences}),t=e.useEditorStore(c=>{var p;return(p=c.card.preferences)==null?void 0:p.datasetOptions}),r=e.useEditorStore(c=>c.actions.setCardPreferences),l=(o=n==null?void 0:n.chartOptions)==null?void 0:o.indexAxis,x=t==null?void 0:t.find(c=>c.idx===s);function u(c,p){(c==="end"||c==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const d={display:c!=="none",align:c,anchor:c,clamp:!0};if(!x)r({...n,datasetOptions:[...t||[],{idx:p,datalabels:d}]});else{const j={...x};j.datalabels=d;const y=t==null?void 0:t.map(a=>a.idx===p?j:a);r({...n,datasetOptions:y})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(Ls,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-fit p-1",children:e.jsxRuntimeExports.jsxs("div",{className:"flex gap-1",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("none",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(e.X,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(Ss,{className:e.cn("h-4 w-4",{"rotate-90":l==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(vs,{className:e.cn("h-4 w-4",{"rotate-90":l==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(ys,{className:e.cn("h-4 w-4",{"rotate-90":l==="y"})})})]})})]})}function as(){const s=e.useEditorStore(c=>c.card),n=e.useEditorStore(c=>{var p,d,j;return(j=(d=(p=c==null?void 0:c.card)==null?void 0:p.preferences)==null?void 0:d.chartOptions)==null?void 0:j.indexAxis}),t=n==="y"?"Y axis":"X axis",r=n==="y"?"X axis":"Y axis",{keys:l,metricKeys:x,dimensionKeys:u}=e.getKeys(s.data||[]);let o=x;if(["stackedBar","stackedLine"].includes(s.type)){const c=e.pivotData({dataArray:s.data||[],groupKey:u[0],pivotKey:u[1],valueKey:o[0]}),{metricKeys:p}=e.getKeys(c);o=p}return l.length===0?null:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:t}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:e.jsxRuntimeExports.jsx("div",{className:"rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:e.jsxRuntimeExports.jsx("p",{children:u[0]})})})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-5",children:[e.jsxRuntimeExports.jsx(e.Label,{children:r}),e.jsxRuntimeExports.jsx(is,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:o.map((c,p)=>e.jsxRuntimeExports.jsx(dt,{col:c,idx:p},c))})]})]})}function dt({col:s,idx:n}){const t=e.useEditorStore(o=>{var c;return(c=o.card)==null?void 0:c.preferences}),r=e.useEditorStore(o=>{var c;return(c=o.card.preferences)==null?void 0:c.datasetOptions}),l=r==null?void 0:r.find(o=>o.idx===n),{setCardPreferences:x}=e.useEditorStore(o=>o.actions);function u(o){if(!l)x({...t,datasetOptions:[...r||[],{idx:n,type:o==="area"?"line":o,fill:o==="area"?"origin":""}]});else{const c={...l};c.type=o==="area"?"line":o,c.fill=o==="area"?"origin":"";const p=r==null?void 0:r.map(d=>d.idx===n?c:d);x({...t,datasetOptions:p})}}return e.jsxRuntimeExports.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:[e.jsxRuntimeExports.jsx("p",{children:s}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx(De,{onClick:()=>u("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(Le,{onClick:()=>u("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ms,{onClick:()=>u("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(e.Separator,{orientation:"vertical",className:"invisible size-4 cursor-pointer py-2 text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ut,{idx:n})]})]})}function mt({cardType:s}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis1 - number"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis2 - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#line-chart",children:"example"})," in the docs."]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(Ce,{}),e.jsxRuntimeExports.jsx(as,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(de,{})})]})]})})}function Fe(){var l,x,u;const s=e.useEditorStore(o=>o.card.cfg),n=e.useEditorStore(o=>o.actions.setCardCfg),t=e.useEditorStore(o=>o.card.type);function r(o){var d;const c={datalabels:{display:o!=="none",align:o,anchor:o,clamp:!0}},p={...s,options:{...s==null?void 0:s.options,plugins:{...(d=s==null?void 0:s.options)==null?void 0:d.plugins,...c}}};n(p),console.log(o)}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxRuntimeExports.jsx("label",{className:"font-medium",children:"Data Labels"}),!["pyramid"].includes(t)&&e.jsxRuntimeExports.jsx(is,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(u=(x=(l=s==null?void 0:s.options)==null?void 0:l.plugins)==null?void 0:x.datalabels)==null?void 0:u.anchor,onValueChange:r,defaultValue:"none",children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:"Select position"})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Data Labels"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"start",children:"Start"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"center",children:"Center"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"end",children:"End"})]})})]})]})}function pt({cardType:s}){function n(t){const r="SELECT label, [group], x-axis, y-axis, radius FROM table",l="SELECT label, [group], x-axis, y-axis FROM table";return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("div",{className:"bg-muted px-2 py-1 rounded text-xs",children:t==="bubble"?r:l}),e.jsxRuntimeExports.jsxs("ul",{className:" ml-6 list-disc [&>li]:mt-2 text-xs",children:[e.jsxRuntimeExports.jsx("li",{children:"label - category"}),e.jsxRuntimeExports.jsx("li",{children:"group - category"}),e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - category"}),t==="bubble"&&e.jsxRuntimeExports.jsx("li",{children:"radius - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:x=>x.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})}return e.jsxRuntimeExports.jsx("div",{className:"px-6 py-2 space-y-6",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:" space-y-4 font-mono text-xs ",children:n(s)})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(Fe,{})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(de,{})})]})]})})}const ht={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},jt={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Et(){const s=e.useEditorStore(n=>n.card.type);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 p-6",children:[e.jsxRuntimeExports.jsx(e.Accordion,{className:" ",type:"single",collapsible:!0,children:ft(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(Ce,{})}),e.jsxRuntimeExports.jsx("div",{children:!["kpi"].includes(s)&&e.jsxRuntimeExports.jsx(Fe,{})}),e.jsxRuntimeExports.jsx("div",{children:!["kpi"].includes(s)&&e.jsxRuntimeExports.jsx(de,{})})]})}function ft(s){if(["line","bar"].includes(s))return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsx("p",{children:"Chart Query"})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(ht,null,2)})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsxRuntimeExports.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(jt,null,2)})]})]})]});if(s==="bubble")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsxRuntimeExports.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(s==="scatter")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(s))return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:[e.jsxRuntimeExports.jsx("span",{children:s==="polarArea"?"Polar":s.charAt(0).toUpperCase()+s.slice(1)})," ","chart query"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function gt(){var c,p,d,j,y;const s=e.useEditorStore(a=>a.card.preferences),n=e.useEditorStore(a=>a.actions.setCardPreferences),t=e.useEditorStore(a=>a.actions.setNumberFormat);e.useEditorStore(a=>{var m,h;return(h=(m=a.card.preferences)==null?void 0:m.formatNumber)==null?void 0:h.decimalPlaces});const r=e.useEditorStore(a=>{var m,h;return(h=(m=a.card.preferences)==null?void 0:m.formatNumber)==null?void 0:h.locale}),l=e.useEditorStore(a=>{var m,h;return(h=(m=a.card.preferences)==null?void 0:m.formatNumber)==null?void 0:h.currency});e.useEditorStore(a=>a.actions.setFilterOnClickField);const x=e.useEditorStore(a=>{var m,h;return(h=(m=a.card.preferences)==null?void 0:m.formatNumber)==null?void 0:h.colorRanges})||[],u=e.useEditorStore(a=>a.actions.setColorRanges),o=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(a=>a.currency))];return e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((c=s==null?void 0:s.formatNumber)!=null&&c.enabled),onCheckedChange:a=>{n({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:a}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Format Number"})]}),((p=s==null?void 0:s.formatNumber)==null?void 0:p.enabled)===!0&&e.jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Locale"}),e.jsxRuntimeExports.jsxs(e.Select,{value:r||"en-US",onValueChange:a=>{var m,h,v;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((h=s==null?void 0:s.formatNumber)==null?void 0:h.currency)||"",a||"en-US",((v=s==null?void 0:s.formatNumber)==null?void 0:v.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Format"}),e.LOCALE_CURRENCY_PAIRS.map(a=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:a.locale,children:a.locale},a.locale))]})})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Currency"}),e.jsxRuntimeExports.jsxs(e.Select,{value:l||"none",onValueChange:a=>{var m,h,v;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,a==="none"?"":a,((h=s==null?void 0:s.formatNumber)==null?void 0:h.locale)||"",((v=s==null?void 0:s.formatNumber)==null?void 0:v.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),o.map(a=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:a,children:a},a))]})})]})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Decimals"}),e.jsxRuntimeExports.jsxs(e.Select,{value:((j=(d=s==null?void 0:s.formatNumber)==null?void 0:d.decimalPlaces)==null?void 0:j.toString())||"0",onValueChange:a=>{var m,h,v;return t(Number(a),((m=s==null?void 0:s.formatNumber)==null?void 0:m.currency)||"",((h=s==null?void 0:s.formatNumber)==null?void 0:h.locale)||"",((v=s==null?void 0:s.formatNumber)==null?void 0:v.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:["0","1","2","3","4"].map(a=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:a,children:a},a))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((y=s==null?void 0:s.formatNumber)==null?void 0:y.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:a=>{var m,h,v;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((h=s==null?void 0:s.formatNumber)==null?void 0:h.currency)||"",((v=s==null?void 0:s.formatNumber)==null?void 0:v.locale)||"",a.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:x,setColorRanges:u})]})]})}function Rt(){return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{type:"single",collapsible:!0,children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"font-mono",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"current - number"}),e.jsxRuntimeExports.jsx("li",{children:"previous - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#kpi",children:"example"})," in the docs."]})]})]})}),e.jsxRuntimeExports.jsx("section",{className:"",children:e.jsxRuntimeExports.jsx(gt,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}function bt(){var r;const s=e.useEditorStore(l=>l.card.preferences),{setCardPreferences:n}=e.useEditorStore(l=>l.actions);function t(l){n({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:l==="dynamic"}})}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:(r=s==null?void 0:s.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:t,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"static",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function be({cardType:s,docContent:n,suffix:t="Chart"}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} ${t}`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{children:n||e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"label - category"}),e.jsxRuntimeExports.jsx("li",{children:"measure - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[s==="range"&&e.jsxRuntimeExports.jsx(Ce,{}),s!=="text"&&e.jsxRuntimeExports.jsx(Fe,{}),s==="text"&&e.jsxRuntimeExports.jsx(bt,{})]})]}),!["range","text"].includes(s)&&e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(de,{})})]})]})})}function St(){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Stacked Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"stack by - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#stacked-chart",children:"example"})," in the docs."]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(Ce,{}),e.jsxRuntimeExports.jsx(as,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(de,{})})]})]})})}function yt({}){const s=e.useEditorStore(r=>{var l;return(l=r.card)==null?void 0:l.preferences}),n=e.useEditorStore(r=>r.actions.setCardPreferences),t=r=>{n({...s,allowDownload:r})};return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(de,{})})]})}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{onCheckedChange:t,id:"allow-download"}),e.jsxRuntimeExports.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const vt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pyramid-chart",children:"example"})," in the docs."]})]}),Ct=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#range-charts",children:"example"})," in the docs."]})]}),Nt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#text-visual",children:"example"})," in the docs."]})]});function kt(){const s=e.useEditorStore(t=>t.card.type);function n(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx(St,{});case"pyramid":return e.jsxRuntimeExports.jsx(be,{docContent:vt,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(Rt,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(mt,{cardType:t});case"range":return e.jsxRuntimeExports.jsx(be,{docContent:Ct,cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(be,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(pt,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(yt,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(be,{docContent:Nt,cardType:t,suffix:"Visual"});default:return e.jsxRuntimeExports.jsx(Et,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:n(s)})}function wt(){const s=e.useEditorStore(n=>n.isShowingVisual);return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsxRuntimeExports.jsx(e.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsxRuntimeExports.jsx(rt,{})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:s?e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"horizontal",children:[e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsx(e.ResizablePanel,{className:"flex min-w-[275px]",minSize:20,defaultSize:25,maxSize:30,children:e.jsxRuntimeExports.jsx(kt,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx(Ve,{})})]}):e.jsxRuntimeExports.jsx(Ve,{})})]})}function At({authToken:s,onSave:n,onClose:t}){const r=e.useEditorStore(u=>u.actions.setOnSave),l=e.useEditorStore(u=>u.actions.setOnClose),x=e.useDashboardStore(u=>u.actions.setAuthToken);return f.useEffect(()=>{n&&r(n),t&&l(t)},[n,r,t,l]),f.useEffect(()=>{s&&s.accessToken&&x(s)},[s,x]),e.jsxRuntimeExports.jsxs(e.EditorPanel,{className:"rounded-none",role:"editor-panel",children:[e.jsxRuntimeExports.jsx(e.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsxRuntimeExports.jsx(Ue,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(wt,{})})]})}function It(){e.useDashboardStore(u=>u.selectedCardId);const s=e.useDashboardStore(u=>u.selectedSheetId),{setIsVisualEditing:n}=e.useDashboardStore(u=>u.actions),t=e.useDashboardStore(u=>u.isVisualEditing),r=e.useDashboardStore(u=>u.actions.updateFrame);function l(u){s&&(r(s,u),n(!1))}function x(){n(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{block:t,hidden:!t}),children:e.jsxRuntimeExports.jsx(At,{onSave:l,onClose:x})})}function zt({columns:s,tableName:n}){const t=e.useEditorStore(a=>a.selectedConnectionId),r=e.useEditorStore(a=>a.selectedDatamodelId),l=e.useEditorStore(a=>a.selectedDatabaseName),x=e.useEditorStore(a=>a.selectedSchemaName),u=e.useEditorStore(a=>a.selectedTableName),o=e.useDashboardStore(a=>a.dashboard.filters)||[],c=e.useDashboardStore(a=>a.actions.addFilter),p=e.useDashboardStore(a=>a.actions.removeFilter),d=e.useDashboardStore(a=>a.actions.removeFilterValue),{modelItems:j}=ve();function y(a){var C;const m=e.fmt(a.column_name),h=e.fmt(l||""),v=e.fmt(x||""),S=e.fmt(n);let z=e.getQualifiedTableName(v,S),R=`${z}.${m}`;const A=(C=j==null?void 0:j.find(w=>w.id===r))==null?void 0:C.name;r&&r!=="none"&&(R=`d.${A}.${m}`,z=`d.${A}`),console.log("find",R,S,h);const g=o==null?void 0:o.find(w=>w.column===R&&w.table===S&&(w.database===h||w.database===l));if(g)d(g.id),p(g.id);else{if(n==="api"&&t){c({id:e.v4(),column:R,title:a.column_name,dataType:a.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:e.getDefaultFilterSql(a.data_type,z,m)});return}c({id:e.v4(),column:R,title:a.column_name,dataType:a.data_type,table:u||"",database:l||"",connectionId:t||"",operation:"in",sql:e.getDefaultFilterSql(a.data_type,z,m)})}}return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 flex-1 basis-0 flex-col overflow-scroll px-3",children:s==null?void 0:s.map(a=>{const m=o==null?void 0:o.find(h=>h.column===e.fmt(a.column_name)&&h.table===u&&h.database===l);return e.jsxRuntimeExports.jsx("div",{onClick:()=>y(a),className:e.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":m}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(Qe,{column:a}),e.jsxRuntimeExports.jsx("span",{children:a.column_name})]})},a.column_name)})})}function Dt(){e.useDashboardStore(n=>n.showFilters);const s=e.useDashboardStore(n=>n.actions.setShowFilters);return e.jsxRuntimeExports.jsxs("section",{className:"relative flex grow flex-col border-l px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-lg",children:"Filters"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>s(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{})})]}),e.jsxRuntimeExports.jsx("div",{className:"flex grow",children:e.jsxRuntimeExports.jsx(Ue,{ColumnsComponent:(n,t,r)=>e.jsxRuntimeExports.jsx(zt,{schemaName:n,tableName:t,columns:r})})})]})}function Lt(){e.useDashboardStore(t=>t.dashboard);const s=e.useDashboardStore(t=>t.showFilters),n=e.useDashboardStore(t=>t.isVisualEditing);return e.useDashboardStore(t=>t.bookmarkKey),e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("grow",{hidden:n,flex:!n}),children:[e.jsxRuntimeExports.jsx(e.DashboardTabs,{}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(Dt,{})})]})}function Tt(){const s=e.useDashboardStore(r=>r.dashboard),n=e.useDashboardStore(r=>r.actions.setDashboard),t=e.useDashboardStore(r=>r.showDashboardJSON);return e.useDashboardStore(r=>r.actions.setShowDashboardJSON),e.jsxRuntimeExports.jsx("div",{className:e.cn(" p-2",{hidden:!t}),children:e.jsxRuntimeExports.jsx(e.de,{onChange:r=>{if(r)try{JSON.parse(r),n(JSON.parse(r))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto ",value:JSON.stringify(s,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})})}function Ft({showControls:s=!1,showFooter:n=!0,...t}){return e.jsxRuntimeExports.jsxs(e.SemaphorContextProvider,{dashboardProps:t,children:[e.jsxRuntimeExports.jsx(e.Te,{}),e.jsxRuntimeExports.jsxs(e.UXProvider,{children:[e.jsxRuntimeExports.jsx(Tt,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(Bs,{}),e.jsxRuntimeExports.jsx(It,{}),e.jsxRuntimeExports.jsx(Lt,{})]})]})]})}exports.DashboardPlus=Ft;exports.SelectComponent=ue;exports.useEditorAside=ve;
215
+ Visual Query Syntax: ${Qs}`,{data:C,isLoading:w,isFetching:L,isError:N,refetch:O}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(c==null?void 0:c.accessToken)||"",{user_content:`userContent: ${A} ${p?g:""}`}),enabled:!1});function q(b){if(b.toLowerCase().includes("bar"))m("bar");else if(b.toLowerCase().includes("line"))m("line");else if(b.toLowerCase().includes("bubble"))m("bubble");else if(b.toLowerCase().includes("scatter"))m("scatter");else if(b.toLowerCase().includes("stacked"))m("stackedBar");else if(b.toLowerCase().includes("pie"))m("pie");else if(b.toLowerCase().includes("donut")||b.toLowerCase().includes("doughnut"))m("doughnut");else if(b.toLowerCase().includes("radar"))m("radar");else return m("bar"),!1;return!0}f.useEffect(()=>{C&&v(b=>[...b,{role:"ai",content:C.response}])},[C]),f.useEffect(()=>{const b=setTimeout(()=>{var E;o.current&&(o.current.scroll({top:o.current.scrollHeight,behavior:"smooth"}),(E=u.current)==null||E.focus())},100);return()=>clearTimeout(b)},[h]);function D(){t&&(v(b=>[...b,{role:"user",content:t}]),q(t)&&d(!0),r(""),O())}f.useEffect(()=>{l&&(D(),x(!1))},[l,x]);const H={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},K={fontFamily:"monospace",fontSize:14,lineHeight:1.6},B={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},G={p:({node:b,...E})=>e.jsxRuntimeExports.jsx("p",{style:H,...E}),code:({node:b,...E})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...E}),pre:({node:b,...E})=>e.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:K,children:[e.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:E.children}),e.jsxRuntimeExports.jsxs("div",{className:"flex justify-start gap-2",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:F,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:k=>{const T=F(k);T&&(n(!1),j(T),a(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:b,...E})=>e.jsxRuntimeExports.jsx("li",{style:B,...E})};function F(b){const E=b.currentTarget.closest("pre");if(!E)return;const k=E.textContent||E.innerText;return navigator.clipboard.writeText(k).then(()=>console.log("Text copied to clipboard")).catch(T=>console.error("Error in copying text: ",T)),k}function Q(){return h==null?void 0:h.map((b,E)=>b.role==="user"?e.jsxRuntimeExports.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[e.jsxRuntimeExports.jsx(Fs,{className:"mr-2 h-5 w-5"}),e.jsxRuntimeExports.jsx("div",{children:b.content})]},E):b.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:G,children:C==null?void 0:C.response.replace(/DuckDB/gi,"Semaphor")},E):e.jsxRuntimeExports.jsx("div",{},E))}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",className:"w-full justify-start border font-normal text-muted-foreground focus-visible:ring-0 focus-visible:ring-offset-0",variant:"secondary",children:"Type your question here..."})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[625px] md:min-w-[625px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Assistant"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"What can I help you with?"})]}),e.jsxRuntimeExports.jsx("div",{ref:o,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:e.jsxRuntimeExports.jsx("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:Q()})}),e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsxs("div",{className:"flex w-full items-center rounded-md border",children:[e.jsxRuntimeExports.jsx(e.Textarea,{autoFocus:!0,ref:u,onKeyDown:b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),r(""),D())},placeholder:"Type your question here...",onFocus:b=>{const E=b.target,k=E.value.length;E.setSelectionRange(k,k)},className:e.cn("max-h-10 min-h-7 resize-none border-none focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"),disabled:w||L,value:t,onChange:b=>r(b.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:D,children:!w&&!L?e.jsxRuntimeExports.jsx(e.PaperPlaneIcon,{}):e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var Je={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},qe=f.createContext&&f.createContext(Je),Js=["attr","size","title"];function Ws(s,n){if(s==null)return{};var t=Ys(s,n),r,l;if(Object.getOwnPropertySymbols){var x=Object.getOwnPropertySymbols(s);for(l=0;l<x.length;l++)r=x[l],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(t[r]=s[r])}return t}function Ys(s,n){if(s==null)return{};var t={},r=Object.keys(s),l,x;for(x=0;x<r.length;x++)l=r[x],!(n.indexOf(l)>=0)&&(t[l]=s[l]);return t}function Se(){return Se=Object.assign?Object.assign.bind():function(s){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(s[r]=t[r])}return s},Se.apply(this,arguments)}function Be(s,n){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(s);n&&(r=r.filter(function(l){return Object.getOwnPropertyDescriptor(s,l).enumerable})),t.push.apply(t,r)}return t}function ye(s){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?Be(Object(t),!0).forEach(function(r){Xs(s,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):Be(Object(t)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(t,r))})}return s}function Xs(s,n,t){return n=Zs(n),n in s?Object.defineProperty(s,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[n]=t,s}function Zs(s){var n=et(s,"string");return typeof n=="symbol"?n:String(n)}function et(s,n){if(typeof s!="object"||s===null)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var r=t.call(s,n||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(s)}function We(s){return s&&s.map((n,t)=>f.createElement(n.tag,ye({key:t},n.attr),We(n.child)))}function ee(s){return n=>f.createElement(st,Se({attr:ye({},s.attr)},n),We(s.child))}function st(s){var n=t=>{var{attr:r,size:l,title:x}=s,u=Ws(s,Js),o=l||t.size||"1em",c;return t.className&&(c=t.className),s.className&&(c=(c?c+" ":"")+s.className),f.createElement("svg",Se({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,r,u,{className:c,style:ye(ye({color:s.color||t.color},t.style),s.style),height:o,width:o,xmlns:"http://www.w3.org/2000/svg"}),x&&f.createElement("title",null,x),s.children)};return qe!==void 0?f.createElement(qe.Consumer,null,t=>n(t)):n(Je)}function tt(s){return ee({tag:"svg",attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(s)}function rt(){const{theme:s}=e.useTheme(),n=f.useRef(),t=f.useRef(),[r,l]=f.useState(!1),[x,u]=f.useState(!1),[o,c]=f.useState(!1),[p,d]=f.useState(""),[j,y]=f.useState(!1),{authToken:a}=e.useSemaphorContext();e.useDashboardStore(i=>i.selectedSheetId);const m=e.useDashboardStore(i=>i.dashboard.baseQueries),h=e.useEditorStore(i=>i.card),v=e.useDashboardStore(i=>i.theme),S=e.useEditorStore(i=>i.isShowingVisual),z=e.useEditorStore(i=>i.selectedConnectionId),R=e.useEditorStore(i=>i.selectedDatabaseName),A=e.useEditorStore(i=>i.selectedDatamodelId),g=e.useEditorStore(i=>i.selectedSchemaName);e.useDashboardStore(i=>i.actions.updateFrameCard);const C=e.useEditorStore(i=>i.selectedTableName),w=e.useEditorStore(i=>i.card.sql),L=e.useEditorStore(i=>i.card.python),N=e.resolveBaseQuery(w,m),O=e.useEditorStore(i=>i.selectedConnectionId),q=e.useEditorStore(i=>i.frame),D=e.useEditorStore(i=>i.filterValues),H=e.useEditorStore(i=>i.applyFilters),{setCardCustomCfg:K,setQueryResultColumns:B,setFilterValues:G,setCardSql:F,setCardPython:Q,setQueryError:b,setPythonStdOut:E,setCardPreferences:k}=e.useEditorStore(i=>i.actions),T=e.useEditorStore(i=>i.onSave),se=e.useEditorStore(i=>i.actions.setApplyFilters),$=e.useEditorStore(i=>i.onClose),I=e.useEditorStore(i=>i.actions.setCardData),V=e.useEditorStore(i=>i.actions.setSqlGen),P=e.useEditorStore(i=>i.runSql),ne=e.useEditorStore(i=>i.actions.setRunSql),te=e.useEditorStore(i=>i.actions.setIsSqlRunning),{data:M,isLoading:U,isFetching:J,isSuccess:oe,isError:ae,error:me,status:Oe,refetch:le}=e.useQuery({queryKey:[N,L],queryFn:()=>e.postRequest("https://semaphor.cloud/api/v1/query",(a==null?void 0:a.accessToken)||"",{connection_id:O,sql:N,python:L===e.PYTHON_DEFAULT_CODE?"":L,active_filters:H?D:[]}),enabled:!1,retry:!1});f.useEffect(()=>{if(M&&(I(M.records),M.rowLimitExceeded&&e.Jt.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),E((M==null?void 0:M.output)||""),M.records.length>0)){const{dimensionKeys:i}=e.getKeys(M.records);B(i)}},[M,I,B,E]),f.useEffect(()=>{P&&(le(),ne(!1))},[P,le,ne]),f.useEffect(()=>{(U||J)&&te(!0),(ae||oe)&&te(!1),ae?(b(me.message),I([]),B([]),E("")):b("")},[U,J,M,E,ae,oe,te,I,B,b,me]);function Ne(){F(""),I([]),V({}),K(""),k({})}const je=i=>{t.current=i};function ke(){let i=w;w&&!w.includes("{{")&&(i=Hs(w),F(i));const W={...h,lastSelectedSchema:g,lastSelectedDatamodelId:A,lastSelectedDatabase:R,lastSelectedTable:C,connectionId:z,type:S?h.type:"table",sql:i,customCfg:S?h.customCfg:null},he=q.cards.map(ie=>ie.id===h.id?W:ie);T==null||T({...q,cards:he})}function we(){$==null||$()}function Ee(i){const W=getComputedStyle(document.documentElement).getPropertyValue(i);return fe(W)}function fe(i){const[W,he,ie]=i.split(" "),_=parseFloat(W),ls=parseFloat(he),cs=parseFloat(ie),xs=ls/100,Me=cs/100,re=(1-Math.abs(2*Me-1))*xs,ce=re*(1-Math.abs(_/60%2-1)),Ae=Me-re/2;let Y=0,X=0,Z=0;0<=_&&_<60?(Y=re,X=ce,Z=0):60<=_&&_<120?(Y=ce,X=re,Z=0):120<=_&&_<180?(Y=0,X=re,Z=ce):180<=_&&_<240?(Y=0,X=ce,Z=re):240<=_&&_<300?(Y=ce,X=0,Z=re):300<=_&&_<360&&(Y=re,X=0,Z=ce),Y=Math.round((Y+Ae)*255),X=Math.round((X+Ae)*255),Z=Math.round((Z+Ae)*255);const Ie=us=>{const ze=us.toString(16);return ze.length==1?"0"+ze:ze};return`#${Ie(Y)}${Ie(X)}${Ie(Z)}`}f.useEffect(()=>{const i=n.current,W=t.current;if(i){const he=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",ie=v==="system"?he:v;i.editor.defineTheme("default",{base:ie==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":ie==="light"?"#ffffff":Ee("--semaphor-background")}}),i.editor.setTheme("default")}return W&&i&&W.addCommand(i.KeyMod.Shift|i.KeyCode.Enter,function(){return console.log("Executing query..."),le(),!1}),()=>{}},[s,v,n.current]);function pe(i){n.current=i}function ge(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[x&&e.jsxRuntimeExports.jsx("div",{className:"xbg-yellow-100 relative flex w-1/3 min-w-0 grow overflow-hidden border-l p-1 text-xs",role:"editor-filter-container",children:e.jsxRuntimeExports.jsxs("div",{className:"w-[99%]",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[e.jsxRuntimeExports.jsx($s,{checked:H,onCheckedChange:()=>se(!H),text:"Apply Filters"}),e.jsxRuntimeExports.jsx(Gs,{}),D&&x&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>u(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",onChange:i=>{if(i)try{JSON.parse(i),G(JSON.parse(i))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(D,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),D&&!x&&e.jsxRuntimeExports.jsx(He,{onClick:()=>u(!0),className:e.cn("absolute bottom-4 right-6 h-3 w-3 text-foreground/50 hover:cursor-pointer hover:text-foreground",{"font-bold text-red-800":H})})]})}function Re(){return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"1",order:1,defaultSize:r?20:100,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{role:"sql-container",className:"relative flex w-[99%]",children:e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",className:"pt-3",onChange:i=>{F(i)},value:w,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",defaultValue:"SELECT * FROM table",beforeMount:pe,onMount:je})}),r&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),r&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{role:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"pt-3",theme:"default",onChange:i=>{Q(i&&i.trim()||"")},value:L||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",beforeMount:pe,onMount:je})}),e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"python"})]})]})]})}return e.jsxRuntimeExports.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxRuntimeExports.jsxs("div",{role:"sql-editor",className:"relative flex grow justify-between overflow-y-scroll",children:[Re(),ge()]}),e.jsxRuntimeExports.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{title:"Shift + Enter",disabled:U||J,onClick:()=>{le()},className:"shrink-0",size:"sm",variant:"outline",children:[U||J?e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(ks,{className:"mr-2 h-4 w-4"}),"Run"]}),ae&&e.jsxRuntimeExports.jsx(Ps,{error:me.message,setShowAIDialog:c,setTriggerAIRun:y,setUserInputforAI:d}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:Ne,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(Es,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:r,onPressedChange:i=>l(i),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(tt,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(Us,{open:o,setOpen:c,userInput:p,triggerAIRun:j,setTriggerAIRun:y,setUserInput:i=>d(i)})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{onClick:ke,size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:we,className:"w-full",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"mr-2 size-4"}),"Close"]})]})]})]})}function nt({data:s}){var u;const[n,t]=f.useState([]),l=Object.keys(s[0]).map(o=>({accessorKey:o,header:({column:c})=>{const p=c.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>c.toggleSorting(c.getIsSorted()==="asc"),children:[o,p==="asc"?e.jsxRuntimeExports.jsx(e.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):p==="desc"?e.jsxRuntimeExports.jsx(e.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),x=e.useReactTable({data:s,columns:l,getCoreRowModel:e.getCoreRowModel(),getPaginationRowModel:e.getPaginationRowModel(),onSortingChange:t,getSortedRowModel:e.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsxRuntimeExports.jsxs(e.Table$1,{children:[e.jsxRuntimeExports.jsx(e.TableHeader,{children:x.getHeaderGroups().map(o=>e.jsxRuntimeExports.jsx(e.TableRow,{children:o.headers.map(c=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 bg-muted",children:c.isPlaceholder?null:e.flexRender(c.column.columnDef.header,c.getContext())},c.id))},o.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(u=x.getRowModel().rows)!=null&&u.length?x.getRowModel().rows.map(o=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":o.getIsSelected()&&"selected",children:o.getVisibleCells().map(c=>e.jsxRuntimeExports.jsx(e.TableCell,{children:e.flexRender(c.column.columnDef.cell,c.getContext())},c.id))},o.id)):e.jsxRuntimeExports.jsx(e.TableRow,{children:e.jsxRuntimeExports.jsx(e.TableCell,{colSpan:l.length,className:"h-24 text-center",children:"No results."})})})]})}function Ye({className:s,...n}){var u;f.useState(0);const t=e.useDashboardStore(o=>o.themeStyle),r=e.useEditorStore(o=>o.card),l=e.useEditorStore(o=>o.actions.setCard);if(f.useEffect(()=>{},[r.data,r.type,r.cfg,r.customCfg,t,r.preferences]),!r.id)return null;let x;return r.data&&r.data.length>0&&(x=e.createChartConfig({data:r.data,cardType:r.type,cfg:r.cfg,customCfg:r.customCfg,preferences:r.preferences})),e.jsxRuntimeExports.jsxs(e.Card,{role:"editor-visual-card",className:e.cn("relative flex h-full flex-col rounded-none",s),...n,children:[e.jsxRuntimeExports.jsxs(e.CardHeader,{className:"py-4",children:[e.jsxRuntimeExports.jsx(e.Editable,{text:r.title,onSave:o=>l({...r,title:o}),children:e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:r.title})})},r.title),e.jsxRuntimeExports.jsx(e.Editable,{text:r.description||"",onSave:o=>l({...r,description:o}),children:e.jsxRuntimeExports.jsxs(e.CardDescription,{children:[" ",r.description]})},r.description)]}),e.jsxRuntimeExports.jsxs(e.CardContent,{className:"flex grow flex-col pb-3",children:[r.type!=="table"&&x&&e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:x},JSON.stringify(x)+JSON.stringify(r.preferences)+((u=r==null?void 0:r.preferences)==null?void 0:u.customVisualCode)),r.type==="table"&&r.data&&r.data.length>0&&e.jsxRuntimeExports.jsx(e.$57acba87d6e25586$export$ccf8d8d7bbf3c2cc,{className:"flex min-h-0 flex-1 grow basis-0",children:e.jsxRuntimeExports.jsx(e.TableVisual,{card:r,data:r==null?void 0:r.data})})]})]})}function ot(){const[s,n]=f.useState(!1),[t,r]=f.useState(""),[l,x]=f.useState(""),[u,o]=f.useState(""),[c,p]=f.useState(""),d=e.useEditorStore(R=>R.card),j=e.useEditorStore(R=>R.card.customCfg),{setCardCustomCfg:y,setCustomVisualCode:a}=e.useEditorActions();function m(R){var C,w;const A={...R,data:{...R==null?void 0:R.data,datasets:(w=(C=R==null?void 0:R.data)==null?void 0:C.datasets)==null?void 0:w.map(L=>({...L,data:[]}))}};return JSON.stringify(A,null,1)}function h(){var A,g;if(!d.data||d.data.length===0)return;const R=e.createChartConfig({data:d.data,cardType:d.type,cfg:d.cfg,preferences:d.preferences});R&&(r(JSON.stringify(R,null,1)),(A=d==null?void 0:d.preferences)!=null&&A.customVisualCode&&o((g=d==null?void 0:d.preferences)==null?void 0:g.customVisualCode),j&&x(JSON.stringify(j,null,1)))}function v(){if(u&&a(u),!!l)try{const R=JSON.parse(l);return R?(y(R),p(""),x(""),R):void 0}catch(R){console.log(R),p("Invalid JSON")}}function S(){x(""),y(null)}function z(){let R;if(j){const A=e._.cloneDeep(d.cfg),g=e._.merge(A,j);return R=m(g),R}return t?(R=m(JSON.parse(t)),R):""}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{onClick:h,className:` ${j&&"border-foreground/50 dark:border-foreground/70"}`,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.Settings,{className:"h-4 w-4"})})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{className:"",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Customize Card"}),e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:e.jsxRuntimeExports.jsx(bs,{onClick:()=>{navigator.clipboard.writeText(d.id)},className:"size-3 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{side:"right",align:"center",children:e.jsxRuntimeExports.jsx("p",{className:"text-xs",children:"Copy Card ID"})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogDescription,{children:["See the configuration options and documentation",e.jsxRuntimeExports.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex grow gap-2",children:[e.jsxRuntimeExports.jsx(Ye,{className:"w-1/2 rounded shadow-none"}),e.jsxRuntimeExports.jsxs(e.Tabs,{defaultValue:"custom-config",className:"flex w-1/2 flex-col",children:[e.jsxRuntimeExports.jsxs(e.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsxRuntimeExports.jsxs(e.TabsTrigger,{value:"custom-config",children:[j&&e.jsxRuntimeExports.jsx(e.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),j?"Custom Config":"Default Config"]}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"output",children:"Output"}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"custom-code",children:"Custom Code"})]}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"bg-red-x mt-0 grow rounded-b border border-t-0 p-2",value:"output",children:e.jsxRuntimeExports.jsx(e.Textarea,{disabled:!0,value:t,className:"h-full resize-none border-none font-mono focus-visible:ring-0 focus-visible:ring-offset-0"})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-config",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"json",value:z(),onChange:R=>x(R)})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-code",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"javascript",value:u,onChange:R=>o(R||"")})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:c}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!j,onClick:S,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:v,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>n(!1),variant:"outline",children:"Close"})]})]})]})}function Xe(s){return ee({tag:"svg",attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M926.8 397.1l-396-288a31.81 31.81 0 0 0-37.6 0l-396 288a31.99 31.99 0 0 0-11.6 35.8l151.3 466a32 32 0 0 0 30.4 22.1h489.5c13.9 0 26.1-8.9 30.4-22.1l151.3-466c4.2-13.2-.5-27.6-11.7-35.8zM838.6 417l-98.5 32-200-144.7V199.9L838.6 417zM466 567.2l-89.1 122.3-55.2-169.2L466 567.2zm-116.3-96.8L484 373.3v140.8l-134.3-43.7zM512 599.2l93.9 128.9H418.1L512 599.2zm28.1-225.9l134.2 97.1L540.1 514V373.3zM558 567.2l144.3-46.9-55.2 169.2L558 567.2zm-74-367.3v104.4L283.9 449l-98.5-32L484 199.9zM169.3 470.8l86.5 28.1 80.4 246.4-53.8 73.9-113.1-348.4zM327.1 853l50.3-69h269.3l50.3 69H327.1zm414.5-33.8l-53.8-73.9 80.4-246.4 86.5-28.1-113.1 348.4z"},child:[]}]})(s)}function Ze(s){return ee({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M137.39,24.06A16,16,0,0,0,120,40V80.67a15.86,15.86,0,0,0,13.25,15.76A32,32,0,1,1,96,129.68c-.41-8.22,1.27-15,5-20.26h0a15.86,15.86,0,0,0-1.69-20.47L71.69,60.68a16,16,0,0,0-23.63,1.1A103.6,103.6,0,0,0,55,202.05,103.24,103.24,0,0,0,128,232h1.49A104.3,104.3,0,0,0,232,129.48C232.75,75.18,191.19,28.88,137.39,24.06ZM60.32,71.94l27.61,28.19,0,.06A43.29,43.29,0,0,0,80.44,120H40.36A87.13,87.13,0,0,1,60.32,71.94ZM40.37,136h40.3A48,48,0,0,0,120,175.34v40.3A88,88,0,0,1,40.37,136Zm149.77,54.14A87.45,87.45,0,0,1,136,215.61V175.34a47.55,47.55,0,0,0,24.73-12.23A48,48,0,0,0,136,80.66L136,40c45.52,4.08,80.67,43.28,80,89.25A87.45,87.45,0,0,1,190.14,190.14Z"},child:[]}]})(s)}function es(s){return ee({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(s)}function ss(s){return ee({tag:"svg",attr:{viewBox:"0 0 24 24",strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},child:[]},{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(s)}function ts(s){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(s)}function rs(s){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M4 9h4v11H4zM4 4h4v4H4zM10 7h4v4h-4zM16 10h4v4h-4zM16 15h4v5h-4zM10 12h4v8h-4z"},child:[]}]})(s)}function ns(s){return ee({tag:"svg",attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(s)}function os(s){return ee({tag:"svg",attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M217 25v14h78V25h-78zm0 32v46h14V71h50v32h14V57h-78zm32 32v14h14V89h-14zm-64 32v46h30v-46h-30zm48 0v14h46v-14h-46zm64 0v46h30v-46h-30zm-64 32v14h46v-14h-46zm-80 32v46h62v-46h-62zm80 0v14h46v-14h-46zm64 0v46h62v-46h-62zm-64 32v14h46v-14h-46zm-112 32v46h94v-46h-94zm112 0v14h46v-14h-46zm64 0v46h94v-46h-94zm-64 32v14h46v-14h-46zM89 313v46h126v-46H89zm144 0v14h46v-14h-46zm64 0v46h126v-46H297zm-64 32v14h46v-14h-46zM57 377v46h158v-46H57zm176 0v14h46v-14h-46zm64 0v46h158v-46H297zm-64 32v14h46v-14h-46zM25 441v46h190v-46H25zm208 0v14h46v-14h-46zm64 0v46h190v-46H297zm-64 32v14h46v-14h-46z"},child:[]}]})(s)}function it(){const[s,n]=f.useState(!1),t=e.useEditorStore(c=>c.card.type),{setCardType:r,setCardPreferences:l,setChartOrientation:x}=e.useEditorStore(c=>c.actions),u=e.useEditorStore(c=>c.actions.setCardCustomCfg);function o(c){u(null),l({}),r(c),n(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(at,{className:"h-4 w-4",chartType:t})})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-50",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 place-items-center",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(De,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Le,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(rs,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ts,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ge,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ss,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ke,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ze,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Xe,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(es,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(os,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Pe,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Table,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ns,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Te,{className:"size-4"})})]})})]})}function at({chartType:s,className:n}){switch(s){case"bar":return e.jsxRuntimeExports.jsx(De,{className:n});case"line":return e.jsxRuntimeExports.jsx(Le,{className:n});case"pie":return e.jsxRuntimeExports.jsx(Ke,{className:n});case"radar":return e.jsxRuntimeExports.jsx(Xe,{className:n});case"scatter":return e.jsxRuntimeExports.jsx(Ge,{className:n});case"bubble":return e.jsxRuntimeExports.jsx(ss,{className:n});case"doughnut":return e.jsxRuntimeExports.jsx(Ze,{className:n});case"stackedBar":return e.jsxRuntimeExports.jsx(rs,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsxRuntimeExports.jsx(ts,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(es,{className:n});case"pyramid":return e.jsxRuntimeExports.jsx(os,{className:n});case"range":return e.jsxRuntimeExports.jsx(Pe,{className:n});case"kpi":return e.jsxRuntimeExports.jsx(ns,{className:n});case"text":return e.jsxRuntimeExports.jsx(Te,{className:n});default:return e.jsxRuntimeExports.jsx(e.Table,{className:n})}}function lt(){const s=e.useEditorStore(t=>t.card.refreshInterval),n=e.useEditorStore(t=>t.actions.setCardRefreshInterval);return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(ds,{className:"w-4 h-4"})})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-[200px]",children:e.jsxRuntimeExports.jsx("div",{className:"grid gap-4",children:e.jsxRuntimeExports.jsx("div",{className:"grid gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-5 items-center gap-1",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-3",htmlFor:"width",children:"Refresh Every"}),e.jsxRuntimeExports.jsx(e.Input,{value:s||"",onChange:t=>n(t.target.value),id:"width",placeholder:"30s",className:"col-span-2 h-7 focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0"})]})})})})]})}function Ve(){e.useEditorStore(o=>o.frame);const s=e.useEditorStore(o=>o.card),n=e.useEditorStore(o=>o.card.data),t=e.useEditorStore(o=>o.isShowingVisual),r=e.useEditorStore(o=>o.isSqlRunning),l=e.useEditorStore(o=>o.queryError),x=e.useEditorStore(o=>o.pythonStdOut);if(e.useEditorStore(o=>o.onSave),e.useEditorStore(o=>o.onClose),e.useEditorStore(o=>o.actions.setCardSql),e.useEditorStore(o=>o.actions.setCardType),e.useEditorStore(o=>o.actions.setSqlGen),!s)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function u(){return s.type==="kpi"?e.jsxRuntimeExports.jsx("div",{className:"flex grow items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.KPICard,{isLoading:r,card:s})})}):s.type==="text"?e.jsxRuntimeExports.jsx("div",{className:"flex grow items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.TextCard,{isLoading:r,card:s})})}):e.jsxRuntimeExports.jsx(Ye,{className:"grow border-none shadow-none"})}return e.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col pt-3",children:[r&&e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"absolute bottom-0 left-0 right-0 top-0 z-10 m-auto h-10 w-10 animate-spin text-foreground/10"}),e.jsxRuntimeExports.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[t&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsx(it,{}),s.type!=="table"&&e.jsxRuntimeExports.jsx(ot,{}),e.jsxRuntimeExports.jsx(lt,{})]}),e.jsxRuntimeExports.jsx(xt,{})]}),t?u():e.jsxRuntimeExports.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[x&&e.jsxRuntimeExports.jsx(ct,{}),s.data&&s.data.length>0&&e.jsxRuntimeExports.jsx(nt,{data:n||[]}),l&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-sm",children:l})]})]})}function ct(){const s=e.useEditorStore(t=>t.pythonStdOut);if(!s)return null;const n=s.replace(/\n/g,"<br>");return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("p",{className:"font-mono text-sm",children:"Output:"}),e.jsxRuntimeExports.jsx("div",{dangerouslySetInnerHTML:{__html:n},className:"bg-muted p-2 font-mono text-sm"}),e.jsxRuntimeExports.jsx(e.Separator,{className:"mb-2"})]})}function xt(){const s=e.useEditorStore(t=>t.isShowingVisual),n=e.useEditorStore(t=>t.actions.setIsShowingVisual);return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"visualize",children:"Chart"}),e.jsxRuntimeExports.jsx(e.Switch,{checked:s,onCheckedChange:()=>n(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function de(){const[s,n]=f.useState([]);e.useEditorStore(d=>d.card.cfg);const t=e.useEditorStore(d=>d.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:l,setCardPreferences:x}=e.useEditorStore(d=>d.actions),u=e.useEditorStore(d=>d.queryResultColumns);e.useEditorStore(d=>{var j;return(j=d.card.preferences)==null?void 0:j.filterOnClickColumnIndex}),f.useEffect(()=>{u&&n(new Array(u.length).fill(!1))},[u]);function o(d,j){var y,a;j?t!=null&&t.onClickFilter&&((y=t==null?void 0:t.onClickFilter)==null?void 0:y.length)>0?x({...t,onClickFilter:[...t.onClickFilter,{columnIndex:d,expression:""}]}):x({...t,onClickFilter:[{columnIndex:d,expression:""}]}):(x({...t,onClickFilter:(a=t==null?void 0:t.onClickFilter)==null?void 0:a.filter(m=>m.columnIndex!==d)}),n(m=>{const h=[...m];return h[d]=!1,h}))}function c(d,j){var a;const y=(a=t==null?void 0:t.onClickFilter)==null?void 0:a.map(m=>m.columnIndex===d?{...m,expression:j.target.value}:m);x({...t,onClickFilter:y})}function p(d){var j,y,a,m;if(s!=null&&s[d]||(y=(j=t==null?void 0:t.onClickFilter)==null?void 0:j.find(h=>h.columnIndex===d))!=null&&y.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(m=(a=t==null?void 0:t.onClickFilter)==null?void 0:a.find(h=>h.columnIndex===d))==null?void 0:m.expression,onChange:h=>c(d,h),type:"text",className:" h-9 w-full focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0 font-mono text-xs",placeholder:"Expression"})}return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:u==null?void 0:u.map((d,j)=>{var y,a;return e.jsxRuntimeExports.jsx("div",{className:"flex items-center justify-between space-y-2 xbg-red-100 group",children:e.jsxRuntimeExports.jsxs("div",{className:" grow",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center py-2 space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((y=t==null?void 0:t.onClickFilter)!=null&&y.find(m=>m.columnIndex===j)),onCheckedChange:m=>o(j,m)}),e.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:d}),e.jsxRuntimeExports.jsx("div",{className:"flex gap-2 items-center ",children:((a=t==null?void 0:t.onClickFilter)==null?void 0:a.find(m=>m.columnIndex===j))&&e.jsxRuntimeExports.jsx($e,{onClick:()=>{n(m=>{const h=[...m];return h[j]=!m[j],h})},className:" invisible group-hover:visible size-3 text-gray-400 cursor-pointer"})})]}),p(j)]})},d)})})}function Ce(){var u,o,c;const s=e.useEditorStore(p=>p.card.preferences),n=e.useEditorStore(p=>p.card.cfg),{setCardCfg:t,setCardPreferences:r,setChartOrientation:l}=e.useEditorStore(p=>p.actions);(u=n==null?void 0:n.options)!=null&&u.indexAxis;function x(p){l(p)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((o=s==null?void 0:s.chartOptions)==null?void 0:o.indexAxis)||((c=n==null?void 0:n.options)==null?void 0:c.indexAxis)||"x",onValueChange:x,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"x",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"y",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const xe="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function _e(s,n){var r,l,x;const t=e.getNumberAxis(s,n);return((x=(l=(r=s==null?void 0:s.chartOptions)==null?void 0:r.scales)==null?void 0:l[t])==null?void 0:x.type)||"linear"}function is(){var K,B,G,F,Q,b;const[s,n]=f.useState(!1),t=e.useEditorStore(E=>{var k;return(k=E.card)==null?void 0:k.preferences}),r=e.useEditorStore(E=>{var k;return(k=E.card)==null?void 0:k.cfg}),l=e.getNumberAxis(t,r),[x,u]=f.useState(_e(t)),[o,c]=f.useState(((G=(B=(K=t==null?void 0:t.chartOptions)==null?void 0:K.scales)==null?void 0:B[l])==null?void 0:G.min)||""),[p,d]=f.useState(((b=(Q=(F=t==null?void 0:t.chartOptions)==null?void 0:F.scales)==null?void 0:Q[l])==null?void 0:b.max)||""),[j,y]=f.useState(o||p?"custom":"auto"),[a,m]=f.useState(""),[h,v]=f.useState(0),[S,z]=f.useState(""),[R,A]=f.useState(""),[g,C]=f.useState(""),w=e.useEditorStore(E=>E.actions.setCardPreferences),L=e.useEditorStore(E=>{var k;return(k=E.card)==null?void 0:k.type}),N=["pie","doughnut","polarArea"].includes(L);f.useEffect(()=>{var E,k,T,se,$,I,V,P,ne,te,M,U,J,oe;u(_e(t)),c(((T=(k=(E=t==null?void 0:t.chartOptions)==null?void 0:E.scales)==null?void 0:k[l])==null?void 0:T.min)===0?0:""),d(((I=($=(se=t==null?void 0:t.chartOptions)==null?void 0:se.scales)==null?void 0:$[l])==null?void 0:I.max)||""),m(((te=(ne=(P=(V=t==null?void 0:t.chartOptions)==null?void 0:V.scales)==null?void 0:P[l])==null?void 0:ne.ticks)==null?void 0:te.stepSize)||""),v(((M=t==null?void 0:t.numberAxisFormat)==null?void 0:M.decimalPlaces)||0),z(((U=t==null?void 0:t.numberAxisFormat)==null?void 0:U.suffix)||""),A(((J=t==null?void 0:t.numberAxisFormat)==null?void 0:J.currency)||""),C(((oe=t==null?void 0:t.numberAxisFormat)==null?void 0:oe.locale)||"")},[s,t,l]);function O(E,k){return k===""||/^[0-9\b]+$/.test(k)?Number(k):Number(E)}function q(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsxRuntimeExports.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxRuntimeExports.jsx(e.Input,{value:R,placeholder:"USD",onChange:E=>A(E.target.value),id:"currency",className:`col-span-2 h-8 w-full ${xe}`}),e.jsxRuntimeExports.jsx(e.Input,{value:g,placeholder:"en-US",onChange:E=>C(E.target.value),id:"locale",className:`col-span-2 h-8 w-full ${xe}`})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsxRuntimeExports.jsx(e.Input,{value:h,onChange:E=>v(Number(E.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${xe}`})]})]})}function D(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"range",children:"Range"}),e.jsxRuntimeExports.jsx(e.Input,{id:"min",value:o,onChange:E=>c(k=>O(k,E.target.value)),className:`col-span-1 h-8 w-full ${xe}`}),e.jsxRuntimeExports.jsx(e.Input,{value:p,onChange:E=>d(k=>O(k,E.target.value)),id:"max",className:`col-span-1 h-8 w-full ${xe}`})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsxRuntimeExports.jsx(e.Input,{value:a,onChange:E=>m(k=>O(k,E.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${xe}`})]})]})}function H(){var T;let E={};j==="custom"&&(E={min:o,max:p,ticks:{stepSize:a}});const k={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(T=t==null?void 0:t.chartOptions)==null?void 0:T.scales,[l]:{type:x,...x==="linear"?E:{}}}},numberAxisFormat:{decimalPlaces:h,suffix:S,currency:R,locale:g}};console.log(k),w(k)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:E=>n(E),children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.SliderIcon,{className:"size-4 cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{align:"center",className:"max-w-65",children:e.jsxRuntimeExports.jsxs("div",{className:"grid gap-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsxRuntimeExports.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale",children:"Type"}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:N,value:x,onValueChange:E=>u(E),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{id:"type",children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Option"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"linear",children:"Linear"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),x=="linear"&&e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxRuntimeExports.jsxs(e.RadioGroup,{disabled:N,id:"scale-option",value:j,onValueChange:E=>y(E),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"auto",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"custom",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),j==="custom"&&x=="linear"&&D(),q(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:H,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function ut({idx:s}){var o;const n=e.useEditorStore(c=>{var p;return(p=c.card)==null?void 0:p.preferences}),t=e.useEditorStore(c=>{var p;return(p=c.card.preferences)==null?void 0:p.datasetOptions}),r=e.useEditorStore(c=>c.actions.setCardPreferences),l=(o=n==null?void 0:n.chartOptions)==null?void 0:o.indexAxis,x=t==null?void 0:t.find(c=>c.idx===s);function u(c,p){(c==="end"||c==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const d={display:c!=="none",align:c,anchor:c,clamp:!0};if(!x)r({...n,datasetOptions:[...t||[],{idx:p,datalabels:d}]});else{const j={...x};j.datalabels=d;const y=t==null?void 0:t.map(a=>a.idx===p?j:a);r({...n,datasetOptions:y})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(Ls,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-fit p-1",children:e.jsxRuntimeExports.jsxs("div",{className:"flex gap-1",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("none",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(e.X,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(Ss,{className:e.cn("h-4 w-4",{"rotate-90":l==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(vs,{className:e.cn("h-4 w-4",{"rotate-90":l==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(ys,{className:e.cn("h-4 w-4",{"rotate-90":l==="y"})})})]})})]})}function as(){const s=e.useEditorStore(c=>c.card),n=e.useEditorStore(c=>{var p,d,j;return(j=(d=(p=c==null?void 0:c.card)==null?void 0:p.preferences)==null?void 0:d.chartOptions)==null?void 0:j.indexAxis}),t=n==="y"?"Y axis":"X axis",r=n==="y"?"X axis":"Y axis",{keys:l,metricKeys:x,dimensionKeys:u}=e.getKeys(s.data||[]);let o=x;if(["stackedBar","stackedLine"].includes(s.type)){const c=e.pivotData({dataArray:s.data||[],groupKey:u[0],pivotKey:u[1],valueKey:o[0]}),{metricKeys:p}=e.getKeys(c);o=p}return l.length===0?null:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:t}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:e.jsxRuntimeExports.jsx("div",{className:"rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:e.jsxRuntimeExports.jsx("p",{children:u[0]})})})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-5",children:[e.jsxRuntimeExports.jsx(e.Label,{children:r}),e.jsxRuntimeExports.jsx(is,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:o.map((c,p)=>e.jsxRuntimeExports.jsx(dt,{col:c,idx:p},c))})]})]})}function dt({col:s,idx:n}){const t=e.useEditorStore(o=>{var c;return(c=o.card)==null?void 0:c.preferences}),r=e.useEditorStore(o=>{var c;return(c=o.card.preferences)==null?void 0:c.datasetOptions}),l=r==null?void 0:r.find(o=>o.idx===n),{setCardPreferences:x}=e.useEditorStore(o=>o.actions);function u(o){if(!l)x({...t,datasetOptions:[...r||[],{idx:n,type:o==="area"?"line":o,fill:o==="area"?"origin":""}]});else{const c={...l};c.type=o==="area"?"line":o,c.fill=o==="area"?"origin":"";const p=r==null?void 0:r.map(d=>d.idx===n?c:d);x({...t,datasetOptions:p})}}return e.jsxRuntimeExports.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:[e.jsxRuntimeExports.jsx("p",{children:s}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx(De,{onClick:()=>u("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(Le,{onClick:()=>u("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ms,{onClick:()=>u("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(e.Separator,{orientation:"vertical",className:"invisible size-4 cursor-pointer py-2 text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ut,{idx:n})]})]})}function mt({cardType:s}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis1 - number"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis2 - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#line-chart",children:"example"})," in the docs."]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(Ce,{}),e.jsxRuntimeExports.jsx(as,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(de,{})})]})]})})}function Fe(){var l,x,u;const s=e.useEditorStore(o=>o.card.cfg),n=e.useEditorStore(o=>o.actions.setCardCfg),t=e.useEditorStore(o=>o.card.type);function r(o){var d;const c={datalabels:{display:o!=="none",align:o,anchor:o,clamp:!0}},p={...s,options:{...s==null?void 0:s.options,plugins:{...(d=s==null?void 0:s.options)==null?void 0:d.plugins,...c}}};n(p),console.log(o)}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxRuntimeExports.jsx("label",{className:"font-medium",children:"Data Labels"}),!["pyramid"].includes(t)&&e.jsxRuntimeExports.jsx(is,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(u=(x=(l=s==null?void 0:s.options)==null?void 0:l.plugins)==null?void 0:x.datalabels)==null?void 0:u.anchor,onValueChange:r,defaultValue:"none",children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:"Select position"})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Data Labels"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"start",children:"Start"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"center",children:"Center"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"end",children:"End"})]})})]})]})}function pt({cardType:s}){function n(t){const r="SELECT label, [group], x-axis, y-axis, radius FROM table",l="SELECT label, [group], x-axis, y-axis FROM table";return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("div",{className:"bg-muted px-2 py-1 rounded text-xs",children:t==="bubble"?r:l}),e.jsxRuntimeExports.jsxs("ul",{className:" ml-6 list-disc [&>li]:mt-2 text-xs",children:[e.jsxRuntimeExports.jsx("li",{children:"label - category"}),e.jsxRuntimeExports.jsx("li",{children:"group - category"}),e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - category"}),t==="bubble"&&e.jsxRuntimeExports.jsx("li",{children:"radius - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:x=>x.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})}return e.jsxRuntimeExports.jsx("div",{className:"px-6 py-2 space-y-6",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:" space-y-4 font-mono text-xs ",children:n(s)})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(Fe,{})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(de,{})})]})]})})}const ht={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},jt={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Et(){const s=e.useEditorStore(n=>n.card.type);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 p-6",children:[e.jsxRuntimeExports.jsx(e.Accordion,{className:" ",type:"single",collapsible:!0,children:ft(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(Ce,{})}),e.jsxRuntimeExports.jsx("div",{children:!["kpi"].includes(s)&&e.jsxRuntimeExports.jsx(Fe,{})}),e.jsxRuntimeExports.jsx("div",{children:!["kpi"].includes(s)&&e.jsxRuntimeExports.jsx(de,{})})]})}function ft(s){if(["line","bar"].includes(s))return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsx("p",{children:"Chart Query"})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(ht,null,2)})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsxRuntimeExports.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(jt,null,2)})]})]})]});if(s==="bubble")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsxRuntimeExports.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(s==="scatter")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(s))return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:[e.jsxRuntimeExports.jsx("span",{children:s==="polarArea"?"Polar":s.charAt(0).toUpperCase()+s.slice(1)})," ","chart query"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function gt(){var c,p,d,j,y;const s=e.useEditorStore(a=>a.card.preferences),n=e.useEditorStore(a=>a.actions.setCardPreferences),t=e.useEditorStore(a=>a.actions.setNumberFormat);e.useEditorStore(a=>{var m,h;return(h=(m=a.card.preferences)==null?void 0:m.formatNumber)==null?void 0:h.decimalPlaces});const r=e.useEditorStore(a=>{var m,h;return(h=(m=a.card.preferences)==null?void 0:m.formatNumber)==null?void 0:h.locale}),l=e.useEditorStore(a=>{var m,h;return(h=(m=a.card.preferences)==null?void 0:m.formatNumber)==null?void 0:h.currency});e.useEditorStore(a=>a.actions.setFilterOnClickField);const x=e.useEditorStore(a=>{var m,h;return(h=(m=a.card.preferences)==null?void 0:m.formatNumber)==null?void 0:h.colorRanges})||[],u=e.useEditorStore(a=>a.actions.setColorRanges),o=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(a=>a.currency))];return e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((c=s==null?void 0:s.formatNumber)!=null&&c.enabled),onCheckedChange:a=>{n({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:a}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Format Number"})]}),((p=s==null?void 0:s.formatNumber)==null?void 0:p.enabled)===!0&&e.jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Locale"}),e.jsxRuntimeExports.jsxs(e.Select,{value:r||"en-US",onValueChange:a=>{var m,h,v;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((h=s==null?void 0:s.formatNumber)==null?void 0:h.currency)||"",a||"en-US",((v=s==null?void 0:s.formatNumber)==null?void 0:v.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Format"}),e.LOCALE_CURRENCY_PAIRS.map(a=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:a.locale,children:a.locale},a.locale))]})})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Currency"}),e.jsxRuntimeExports.jsxs(e.Select,{value:l||"none",onValueChange:a=>{var m,h,v;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,a==="none"?"":a,((h=s==null?void 0:s.formatNumber)==null?void 0:h.locale)||"",((v=s==null?void 0:s.formatNumber)==null?void 0:v.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),o.map(a=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:a,children:a},a))]})})]})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Decimals"}),e.jsxRuntimeExports.jsxs(e.Select,{value:((j=(d=s==null?void 0:s.formatNumber)==null?void 0:d.decimalPlaces)==null?void 0:j.toString())||"0",onValueChange:a=>{var m,h,v;return t(Number(a),((m=s==null?void 0:s.formatNumber)==null?void 0:m.currency)||"",((h=s==null?void 0:s.formatNumber)==null?void 0:h.locale)||"",((v=s==null?void 0:s.formatNumber)==null?void 0:v.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:["0","1","2","3","4"].map(a=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:a,children:a},a))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((y=s==null?void 0:s.formatNumber)==null?void 0:y.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:a=>{var m,h,v;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((h=s==null?void 0:s.formatNumber)==null?void 0:h.currency)||"",((v=s==null?void 0:s.formatNumber)==null?void 0:v.locale)||"",a.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:x,setColorRanges:u})]})]})}function Rt(){return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{type:"single",collapsible:!0,children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"font-mono",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"current - number"}),e.jsxRuntimeExports.jsx("li",{children:"previous - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#kpi",children:"example"})," in the docs."]})]})]})}),e.jsxRuntimeExports.jsx("section",{className:"",children:e.jsxRuntimeExports.jsx(gt,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}function bt(){var r;const s=e.useEditorStore(l=>l.card.preferences),{setCardPreferences:n}=e.useEditorStore(l=>l.actions);function t(l){n({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:l==="dynamic"}})}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:(r=s==null?void 0:s.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:t,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"static",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function be({cardType:s,docContent:n,suffix:t="Chart"}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} ${t}`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{children:n||e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"label - category"}),e.jsxRuntimeExports.jsx("li",{children:"measure - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[s==="range"&&e.jsxRuntimeExports.jsx(Ce,{}),s!=="text"&&e.jsxRuntimeExports.jsx(Fe,{}),s==="text"&&e.jsxRuntimeExports.jsx(bt,{})]})]}),!["range","text"].includes(s)&&e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(de,{})})]})]})})}function St(){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Stacked Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"stack by - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#stacked-chart",children:"example"})," in the docs."]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(Ce,{}),e.jsxRuntimeExports.jsx(as,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(de,{})})]})]})})}function yt({}){const s=e.useEditorStore(r=>{var l;return(l=r.card)==null?void 0:l.preferences}),n=e.useEditorStore(r=>r.actions.setCardPreferences),t=r=>{n({...s,allowDownload:r})};return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(de,{})})]})}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{onCheckedChange:t,id:"allow-download"}),e.jsxRuntimeExports.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const vt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pyramid-chart",children:"example"})," in the docs."]})]}),Ct=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#range-charts",children:"example"})," in the docs."]})]}),Nt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#text-visual",children:"example"})," in the docs."]})]});function kt(){const s=e.useEditorStore(t=>t.card.type);function n(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx(St,{});case"pyramid":return e.jsxRuntimeExports.jsx(be,{docContent:vt,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(Rt,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(mt,{cardType:t});case"range":return e.jsxRuntimeExports.jsx(be,{docContent:Ct,cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(be,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(pt,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(yt,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(be,{docContent:Nt,cardType:t,suffix:"Visual"});default:return e.jsxRuntimeExports.jsx(Et,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:n(s)})}function wt(){const s=e.useEditorStore(n=>n.isShowingVisual);return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsxRuntimeExports.jsx(e.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsxRuntimeExports.jsx(rt,{})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:s?e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"horizontal",children:[e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsx(e.ResizablePanel,{className:"flex min-w-[275px]",minSize:20,defaultSize:25,maxSize:30,children:e.jsxRuntimeExports.jsx(kt,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx(Ve,{})})]}):e.jsxRuntimeExports.jsx(Ve,{})})]})}function At({authToken:s,onSave:n,onClose:t}){const r=e.useEditorStore(u=>u.actions.setOnSave),l=e.useEditorStore(u=>u.actions.setOnClose),x=e.useDashboardStore(u=>u.actions.setAuthToken);return f.useEffect(()=>{n&&r(n),t&&l(t)},[n,r,t,l]),f.useEffect(()=>{s&&s.accessToken&&x(s)},[s,x]),e.jsxRuntimeExports.jsxs(e.EditorPanel,{className:"rounded-none",role:"editor-panel",children:[e.jsxRuntimeExports.jsx(e.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsxRuntimeExports.jsx(Ue,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(wt,{})})]})}function It(){e.useDashboardStore(u=>u.selectedCardId);const s=e.useDashboardStore(u=>u.selectedSheetId),{setIsVisualEditing:n}=e.useDashboardStore(u=>u.actions),t=e.useDashboardStore(u=>u.isVisualEditing),r=e.useDashboardStore(u=>u.actions.updateFrame);function l(u){s&&(r(s,u),n(!1))}function x(){n(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{block:t,hidden:!t}),children:e.jsxRuntimeExports.jsx(At,{onSave:l,onClose:x})})}function zt({columns:s,tableName:n}){const t=e.useEditorStore(a=>a.selectedConnectionId),r=e.useEditorStore(a=>a.selectedDatamodelId),l=e.useEditorStore(a=>a.selectedDatabaseName),x=e.useEditorStore(a=>a.selectedSchemaName),u=e.useEditorStore(a=>a.selectedTableName),o=e.useDashboardStore(a=>a.dashboard.filters)||[],c=e.useDashboardStore(a=>a.actions.addFilter),p=e.useDashboardStore(a=>a.actions.removeFilter),d=e.useDashboardStore(a=>a.actions.removeFilterValue),{modelItems:j}=ve();function y(a){var C;const m=e.fmt(a.column_name),h=e.fmt(l||""),v=e.fmt(x||""),S=e.fmt(n);let z=e.getQualifiedTableName(v,S),R=`${z}.${m}`;const A=(C=j==null?void 0:j.find(w=>w.id===r))==null?void 0:C.name;r&&r!=="none"&&(R=`d.${A}.${m}`,z=`d.${A}`),console.log("find",R,S,h);const g=o==null?void 0:o.find(w=>w.column===R&&w.table===S&&(w.database===h||w.database===l));if(g)d(g.id),p(g.id);else{if(n==="api"&&t){c({id:e.v4(),column:R,title:a.column_name,dataType:a.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:e.getDefaultFilterSql(a.data_type,z,m)});return}c({id:e.v4(),column:R,title:a.column_name,dataType:a.data_type,table:u||"",database:l||"",connectionId:t||"",operation:"in",sql:e.getDefaultFilterSql(a.data_type,z,m)})}}return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 flex-1 basis-0 flex-col overflow-scroll px-3",children:s==null?void 0:s.map(a=>{const m=o==null?void 0:o.find(h=>h.column===e.fmt(a.column_name)&&h.table===u&&h.database===l);return e.jsxRuntimeExports.jsx("div",{onClick:()=>y(a),className:e.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":m}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(Qe,{column:a}),e.jsxRuntimeExports.jsx("span",{children:a.column_name})]})},a.column_name)})})}function Dt(){e.useDashboardStore(n=>n.showFilters);const s=e.useDashboardStore(n=>n.actions.setShowFilters);return e.jsxRuntimeExports.jsxs("section",{className:"relative flex grow flex-col border-l px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-lg",children:"Filters"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>s(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{})})]}),e.jsxRuntimeExports.jsx("div",{className:"flex grow",children:e.jsxRuntimeExports.jsx(Ue,{ColumnsComponent:(n,t,r)=>e.jsxRuntimeExports.jsx(zt,{schemaName:n,tableName:t,columns:r})})})]})}function Lt(){e.useDashboardStore(t=>t.dashboard);const s=e.useDashboardStore(t=>t.showFilters),n=e.useDashboardStore(t=>t.isVisualEditing);return e.useDashboardStore(t=>t.bookmarkKey),e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("grow",{hidden:n,flex:!n}),children:[e.jsxRuntimeExports.jsx(e.DashboardTabs,{}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(Dt,{})})]})}function Tt(){const s=e.useDashboardStore(r=>r.dashboard),n=e.useDashboardStore(r=>r.actions.setDashboard),t=e.useDashboardStore(r=>r.showDashboardJSON);return e.useDashboardStore(r=>r.actions.setShowDashboardJSON),e.jsxRuntimeExports.jsx("div",{className:e.cn(" p-2",{hidden:!t}),children:e.jsxRuntimeExports.jsx(e.de,{onChange:r=>{if(r)try{JSON.parse(r),n(JSON.parse(r))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto ",value:JSON.stringify(s,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})})}function Ft({showControls:s=!1,showFooter:n=!0,...t}){return e.jsxRuntimeExports.jsxs(e.SemaphorContextProvider,{dashboardProps:t,children:[e.jsxRuntimeExports.jsx(e.Te,{}),e.jsxRuntimeExports.jsxs(e.UXProvider,{children:[e.jsxRuntimeExports.jsx(Tt,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(Bs,{}),e.jsxRuntimeExports.jsx(It,{}),e.jsxRuntimeExports.jsx(Lt,{})]})]})]})}exports.DashboardPlus=Ft;exports.SelectComponent=ue;exports.useEditorAside=ve;
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/index-4Wp9Iidj.js"),d=require("./chunks/dashboard-plus-hkbefCny.js"),I=require("react");require("react-dom");function N({card:t,footer:u,className:m,...c}){const{customCards:r}=e.useSemaphorContext(),h=I.useRef(null),{isError:p,isLoading:n,isFetching:i,cfg:x,visualKey:C,handleDatapointClick:f}=e.useDashboardCard(t),a=e.useDashboardStore(s=>s.themeStyle),l=e.useDashboardStore(s=>s.selectedSheetId),E=e.useDashboardStore(s=>s.selectedCardId),j=e.useDashboardStore(s=>s.isDashboardEditing),{setCardTitle:g,setCardDescription:D,setSelectedCardId:b}=e.useDashboardActions();function S(s){s.stopPropagation(),b(l,t.id)}function T(){if(r&&r.length>0){const s=r.find(o=>o.cardId===t.id);if(s&&s.replaceDefault){const o=s.content;if(o)return e.jsxRuntimeExports.jsx(o,{card:t})}}return t.type==="kpi"?t.data&&t.data.length>0&&e.jsxRuntimeExports.jsx(e.KPICard,{isLoading:n||i,card:t}):y}function R(){if(p)return e.jsxRuntimeExports.jsx("p",{className:"text-sm",children:"Oops! It seems like something went wrong. Please review your connection or filters."});if(t.type==="table"&&t.data&&t.data.length>0)return e.jsxRuntimeExports.jsxs(e.ScrollArea,{children:[e.jsxRuntimeExports.jsx(e.TableVisual,{card:t,data:t.data}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]});if(r&&r.length>0){const s=r.find(o=>o.cardId===t.id);if(s&&s.content){const o=s.content;return e.jsxRuntimeExports.jsx(o,{card:t})}}if(x)return e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:x,onDatapointClick:f},C)}function A(){if(r&&r.length>0){const s=r.find(o=>o.cardId===t.id);if(s&&s.footer){const o=s.footer;if(o)return e.jsxRuntimeExports.jsx(o,{card:t})}}return u||null}if(!t.id)return null;const y=e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(e.CardHeader,{className:"pb-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Editable,{text:t.title,onSave:s=>g(l,t.id,s),children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:t.title})}),t.refreshInterval&&e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{className:"pr-1",children:e.jsxRuntimeExports.jsx("div",{className:e.cn("h-2 w-2 rounded-full bg-green-500 transition-opacity",{"opacity-10":n||i})})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{side:"right",align:"center",children:e.jsxRuntimeExports.jsx("p",{className:"text-xs",children:`Realtime (${t==null?void 0:t.refreshInterval})`})})]}),!t.refreshInterval&&(n||i)&&e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"h-4 w-4 animate-spin text-muted-foreground"})]}),e.jsxRuntimeExports.jsx(e.Editable,{text:(t==null?void 0:t.description)||"",onSave:s=>D(l,t.id,s),children:e.jsxRuntimeExports.jsxs(e.CardDescription,{children:[" ",t.description]})})]}),e.jsxRuntimeExports.jsx(e.CardContent,{className:"relative flex grow flex-col overflow-auto pb-0",children:R()}),e.jsxRuntimeExports.jsx(e.CardFooter,{children:A()})]});return e.jsxRuntimeExports.jsx(e.Card,{tabIndex:-1,ref:h,role:"dashboard-card",onClick:S,className:e.cn("relative flex h-full flex-col rounded-sm",{"border-dashed border-foreground/50":E===t.id&&j},a==null?void 0:a.dashboardCard,m),...c,children:T()})}exports.BOOLEAN_DATA_TYPES=e.BOOLEAN_DATA_TYPES;exports.DATE_DATA_TYPES=e.DATE_DATA_TYPES;exports.Dashboard=e.Dashboard;exports.DashboardWC=e.DashboardWC;exports.NUMBER_DATA_TYPES=e.NUMBER_DATA_TYPES;exports.SemaphorQueryClient=e.SemaphorQueryClient;exports.TEXT_DATA_TYPES=e.TEXT_DATA_TYPES;exports.cleanCard=e.cleanCard;exports.createSqlGenConfig=e.createSqlGenConfig;exports.fmt=e.fmt;exports.getBookmarkKey=e.getBookmarkKey;exports.getColumnDataType=e.getColumnDataType;exports.getDashbaordStateWithoutData=e.getDashbaordStateWithoutData;exports.getFilterValueType=e.getFilterValueType;exports.getQualifiedTableName=e.getQualifiedTableName;exports.getSql=e.getSql;exports.isColumnInSqlGen=e.isColumnInSqlGen;exports.resolveDataType=e.resolveDataType;exports.useCard=e.useCard;exports.useDashboardActions=e.useDashboardActions;exports.useDashboardStore=e.useDashboardStore;exports.useEditorActions=e.useEditorActions;exports.useEditorStore=e.useEditorStore;exports.SelectComponent=d.SelectComponent;exports.Surfboard=d.DashboardPlus;exports.useEditorAside=d.useEditorAside;exports.DashboardCard=N;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/index-4Wp9Iidj.js"),d=require("./chunks/dashboard-plus-zrEVxZid.js"),I=require("react");require("react-dom");function N({card:t,footer:u,className:m,...c}){const{customCards:r}=e.useSemaphorContext(),h=I.useRef(null),{isError:p,isLoading:n,isFetching:i,cfg:x,visualKey:C,handleDatapointClick:f}=e.useDashboardCard(t),a=e.useDashboardStore(s=>s.themeStyle),l=e.useDashboardStore(s=>s.selectedSheetId),E=e.useDashboardStore(s=>s.selectedCardId),j=e.useDashboardStore(s=>s.isDashboardEditing),{setCardTitle:g,setCardDescription:D,setSelectedCardId:b}=e.useDashboardActions();function S(s){s.stopPropagation(),b(l,t.id)}function T(){if(r&&r.length>0){const s=r.find(o=>o.cardId===t.id);if(s&&s.replaceDefault){const o=s.content;if(o)return e.jsxRuntimeExports.jsx(o,{card:t})}}return t.type==="kpi"?t.data&&t.data.length>0&&e.jsxRuntimeExports.jsx(e.KPICard,{isLoading:n||i,card:t}):y}function R(){if(p)return e.jsxRuntimeExports.jsx("p",{className:"text-sm",children:"Oops! It seems like something went wrong. Please review your connection or filters."});if(t.type==="table"&&t.data&&t.data.length>0)return e.jsxRuntimeExports.jsxs(e.ScrollArea,{children:[e.jsxRuntimeExports.jsx(e.TableVisual,{card:t,data:t.data}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]});if(r&&r.length>0){const s=r.find(o=>o.cardId===t.id);if(s&&s.content){const o=s.content;return e.jsxRuntimeExports.jsx(o,{card:t})}}if(x)return e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:x,onDatapointClick:f},C)}function A(){if(r&&r.length>0){const s=r.find(o=>o.cardId===t.id);if(s&&s.footer){const o=s.footer;if(o)return e.jsxRuntimeExports.jsx(o,{card:t})}}return u||null}if(!t.id)return null;const y=e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(e.CardHeader,{className:"pb-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Editable,{text:t.title,onSave:s=>g(l,t.id,s),children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:t.title})}),t.refreshInterval&&e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{className:"pr-1",children:e.jsxRuntimeExports.jsx("div",{className:e.cn("h-2 w-2 rounded-full bg-green-500 transition-opacity",{"opacity-10":n||i})})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{side:"right",align:"center",children:e.jsxRuntimeExports.jsx("p",{className:"text-xs",children:`Realtime (${t==null?void 0:t.refreshInterval})`})})]}),!t.refreshInterval&&(n||i)&&e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"h-4 w-4 animate-spin text-muted-foreground"})]}),e.jsxRuntimeExports.jsx(e.Editable,{text:(t==null?void 0:t.description)||"",onSave:s=>D(l,t.id,s),children:e.jsxRuntimeExports.jsxs(e.CardDescription,{children:[" ",t.description]})})]}),e.jsxRuntimeExports.jsx(e.CardContent,{className:"relative flex grow flex-col overflow-auto pb-0",children:R()}),e.jsxRuntimeExports.jsx(e.CardFooter,{children:A()})]});return e.jsxRuntimeExports.jsx(e.Card,{tabIndex:-1,ref:h,role:"dashboard-card",onClick:S,className:e.cn("relative flex h-full flex-col rounded-sm",{"border-dashed border-foreground/50":E===t.id&&j},a==null?void 0:a.dashboardCard,m),...c,children:T()})}exports.BOOLEAN_DATA_TYPES=e.BOOLEAN_DATA_TYPES;exports.DATE_DATA_TYPES=e.DATE_DATA_TYPES;exports.Dashboard=e.Dashboard;exports.DashboardWC=e.DashboardWC;exports.NUMBER_DATA_TYPES=e.NUMBER_DATA_TYPES;exports.SemaphorQueryClient=e.SemaphorQueryClient;exports.TEXT_DATA_TYPES=e.TEXT_DATA_TYPES;exports.cleanCard=e.cleanCard;exports.createSqlGenConfig=e.createSqlGenConfig;exports.fmt=e.fmt;exports.getBookmarkKey=e.getBookmarkKey;exports.getColumnDataType=e.getColumnDataType;exports.getDashbaordStateWithoutData=e.getDashbaordStateWithoutData;exports.getFilterValueType=e.getFilterValueType;exports.getQualifiedTableName=e.getQualifiedTableName;exports.getSql=e.getSql;exports.isColumnInSqlGen=e.isColumnInSqlGen;exports.resolveDataType=e.resolveDataType;exports.useCard=e.useCard;exports.useDashboardActions=e.useDashboardActions;exports.useDashboardStore=e.useDashboardStore;exports.useEditorActions=e.useEditorActions;exports.useEditorStore=e.useEditorStore;exports.SelectComponent=d.SelectComponent;exports.Surfboard=d.DashboardPlus;exports.useEditorAside=d.useEditorAside;exports.DashboardCard=N;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { u as _, a as k, b as n, c as w, j as s, C as F, E as f, d as P, T as R, e as B, f as h, g as L, L as q, h as K, i as O, k as Y, l as G, K as V, S as z, m as H, n as J, o as M } from "./chunks/index-D_kbj8T-.js";
2
2
  import { B as se, s as te, D as ae, q as oe, N as ne, I as re, r as ie, M as le, w as de, t as ue, O as ce, y as fe, J as he, x as Ce, A as xe, v as me, z as pe, F as ge, p as je, H as De, G as be } from "./chunks/index-D_kbj8T-.js";
3
- import { S as Te, D as Ee, u as Ie } from "./chunks/dashboard-plus-TntWBpXD.js";
3
+ import { S as Te, D as Ee, u as Ie } from "./chunks/dashboard-plus-8J4cwl-H.js";
4
4
  import Q from "react";
5
5
  import "react-dom";
6
6
  function $({
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../chunks/dashboard-plus-hkbefCny.js");require("../chunks/index-4Wp9Iidj.js");require("react");require("react-dom");exports.Surfboard=r.DashboardPlus;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../chunks/dashboard-plus-zrEVxZid.js");require("../chunks/index-4Wp9Iidj.js");require("react");require("react-dom");exports.Surfboard=r.DashboardPlus;
@@ -1,4 +1,4 @@
1
- import { D as i } from "../chunks/dashboard-plus-TntWBpXD.js";
1
+ import { D as i } from "../chunks/dashboard-plus-8J4cwl-H.js";
2
2
  import "../chunks/index-D_kbj8T-.js";
3
3
  import "react";
4
4
  import "react-dom";
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "email": "support@semaphor.cloud"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "0.0.217",
8
+ "version": "0.0.218",
9
9
  "description": "Fully interactive and customizable dashboards for your apps.",
10
10
  "keywords": [
11
11
  "react",