react-semaphor 0.1.606 → 0.1.608
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.
- package/dist/analytics-protocol/index.js +1 -1
- package/dist/appearance-runtime/index.js +1 -1
- package/dist/assistant-context/index.js +1 -1
- package/dist/assistant-protocol/index.js +1 -1
- package/dist/brand-studio/index.js +2 -2
- package/dist/briefings/index.js +1 -1
- package/dist/chunks/add-to-dashboard-Bu3M9DpP.js +12 -0
- package/dist/chunks/appearance-provider-BBYTKSjL.js +613 -0
- package/dist/chunks/appearance-runtime-provider-De2VZS4F.js +1 -0
- package/dist/chunks/assistant-chat-x3NCrm5n.js +53 -0
- package/dist/chunks/attachment-filter-line-ClTS4GvQ.js +1 -0
- package/dist/chunks/{bookmark-impact-BW30cm5E.js → bookmark-impact-xCmo8x3V.js} +1 -1
- package/dist/chunks/bookmark-state-BmbBu1th.js +1 -0
- package/dist/chunks/{brand-CL5xDiFH.js → brand-3m_qSMyC.js} +1 -1
- package/dist/chunks/card-filter-builder-CM3SZ4kO.js +11 -0
- package/dist/chunks/check-input-C7S2sNzB.js +151 -0
- package/dist/chunks/{comparison-window-caption-tguyN24S.js → comparison-window-caption-WzGsqv4n.js} +1 -1
- package/dist/chunks/compiler-XErOfUUx.js +1 -0
- package/dist/chunks/context-Cwj8Axgd.js +2 -0
- package/dist/chunks/currency-presentation-binding-s4PlA3Wu.js +1 -0
- package/dist/chunks/custom-visual-inputs-CUtxCe4T.js +1 -0
- package/dist/chunks/custom-visual-write-CH-k-4HE.js +1 -0
- package/dist/chunks/{dashboard-Cyhj9EOl.js → dashboard-BwuurlUI.js} +1 -1
- package/dist/chunks/{dashboard-briefing-launcher-CyOFddmD.js → dashboard-briefing-launcher-CX7mCnPi.js} +5 -5
- package/dist/chunks/{dashboard-controls-DpADfhr0.js → dashboard-controls-Bwjy9G1i.js} +8 -8
- package/dist/chunks/{dashboard-json-4xMChR2q.js → dashboard-json-B9lK28i0.js} +1 -1
- package/dist/chunks/dashboard-temporal-snapshot-CcndP6CF.js +1 -0
- package/dist/chunks/edit-dashboard-visual-BF3mfrWf.js +103 -0
- package/dist/chunks/{filter-line-WwUV5JzN.js → filter-line-W-qQAjke.js} +1 -1
- package/dist/chunks/filter-reach-preview-DSH_k8AJ.js +1 -0
- package/dist/chunks/{filter-value-text-DqTHe_vu.js → filter-value-text-DQwYZHz0.js} +1 -1
- package/dist/chunks/kpi-trend-rule-DDbguInc.js +1 -0
- package/dist/chunks/{layout-grid-Dtsioq4h.js → layout-grid-Bx0jBVXj.js} +1 -1
- package/dist/chunks/matrix-analytical-definition-jn075ooo.js +1 -0
- package/dist/chunks/{matrix-member-presentation-vVAv-aqg.js → matrix-member-presentation-Chz6uGYz.js} +1 -1
- package/dist/chunks/matrix-operation-contract-DceN49RX.js +1 -0
- package/dist/chunks/metric-formatting-DILSVxLq.js +1 -0
- package/dist/chunks/{numeric-range-options-C8tr-Bls.js → numeric-range-options-Drc1EZ6H.js} +1 -1
- package/dist/chunks/{palette-565cA0nh.js → palette-CZJ4ZCY9.js} +1 -1
- package/dist/chunks/pivot-result-contract-expectations-D_ane7I2.js +1 -0
- package/dist/chunks/{pivot-result-identity-B0eWVMXg.js → pivot-result-identity-DRhVJMsF.js} +1 -1
- package/dist/chunks/{raw-temporal-value-BHQ-ldpW.js → raw-temporal-value-B4Md6Xfb.js} +1 -1
- package/dist/chunks/report-preferences-dialog-EQNoTych.js +1 -0
- package/dist/chunks/{report-runtime-context-Cd1b5pku.js → report-runtime-context-CkxgMKr6.js} +1 -1
- package/dist/chunks/resolve-dashboard-input-context-B5yUS9ZM.js +8 -0
- package/dist/chunks/sandbox-host-WJXxpvz7.js +197 -0
- package/dist/chunks/saved-dashboard-context-DQlA4Mg0.js +1 -0
- package/dist/chunks/{selection-filter-compiler-kYsRugss.js → selection-filter-compiler-BxtEEB6Z.js} +1 -1
- package/dist/chunks/semaphor-ready-indicator-Cq3C2SNo.js +622 -0
- package/dist/chunks/set-wWdhgHSh.js +1 -0
- package/dist/chunks/slider-C4jUvJtd.js +599 -0
- package/dist/chunks/stored-dashboard-1x0q2cNx.js +1 -0
- package/dist/chunks/table-cell-text-DFHUGeG6.js +1 -0
- package/dist/chunks/{table-export-sheet-xaczzWZF.js → table-export-sheet-CthBUHu4.js} +1 -1
- package/dist/chunks/{token-types-1vzMWjI-.js → token-types-BM0mpZce.js} +1 -1
- package/dist/chunks/{validators-Dg2kyF4_.js → validators-U8IL8djK.js} +1 -1
- package/dist/chunks/{variable-draft-CRbSYdB6.js → variable-draft-CwX-b6Fs.js} +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/dashboard-authoring/index.js +1 -1
- package/dist/extensions/index.js +1 -0
- package/dist/format-utils/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/report-runtime-context/index.js +1 -1
- package/dist/style.css +1 -1
- package/dist/surfboard/index.js +1 -1
- package/dist/types/components/assistant/assistant-store.d.ts +19 -0
- package/dist/types/components/assistant/use-assistant.d.ts +4 -0
- package/dist/types/components/visual/data-table/hooks/use-data-table-logic.d.ts +2 -3
- package/dist/types/components/visual/data-table/table-cell-text.d.ts +93 -0
- package/dist/types/components/visual/data-table/types/data-table.d.ts +0 -1
- package/dist/types/extensions.d.ts +2 -0
- package/dist/types/index.js +1 -1
- package/dist/types/lib/charts/types.d.ts +3 -1
- package/dist/types/lib/dashboard/semantic-dataset-references.d.ts +0 -2
- package/dist/types/lib/matrix-table/matrix-card-adapter.d.ts +12 -12
- package/dist/types/lib/matrix-table/matrix-delivery.d.ts +25 -25
- package/dist/types/lib/stores/dashboard-store.d.ts +33 -2
- package/dist/types/lib/stores/editor-store.d.ts +8 -0
- package/dist/types/lib/types/common-types.d.ts +3 -0
- package/dist/types/lib/utils/card-definition.d.ts +12 -12
- package/dist/types/lib/utils/card-type-change.d.ts +9 -0
- package/dist/types/shared/analytics-protocol/analytics-base-schemas.d.ts +6 -6
- package/dist/types/shared/analytics-protocol/execution-input-schemas.d.ts +10 -10
- package/dist/types/shared/analytics-protocol/matrix-definition-contract.d.ts +248 -248
- package/dist/types/shared/analytics-protocol/matrix-operation-contract.d.ts +10 -10
- package/dist/types/shared/analytics-protocol/matrix-operation-request.d.ts +8 -8
- package/dist/types/shared/analytics-protocol/matrix-window-contract.d.ts +2 -2
- package/dist/types/shared/assistant-protocol/context.d.ts +26 -26
- package/dist/types/shared/assistant-protocol/parts.d.ts +4 -0
- package/dist/types/shared/assistant-protocol/request.d.ts +2 -1
- package/dist/types/shared/dashboard-authoring/card-data-source/card-base.d.ts +16 -6
- package/dist/types/shared/dashboard-authoring/card-settings/custom-visual-write.d.ts +50 -0
- package/dist/types/shared/dashboard-authoring/card-settings/index.d.ts +1 -0
- package/dist/types/shared/dashboard-authoring/changes/card-query-part.d.ts +1 -0
- package/dist/types/shared/dashboard-authoring/changes/card-types.d.ts +2 -2
- package/dist/types/shared/dashboard-authoring/changes/custom-visual-change.d.ts +57 -0
- package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +61 -54
- package/dist/types/shared/dashboard-authoring/changes/diagnostics.d.ts +5 -1
- package/dist/types/shared/dashboard-authoring/changes/read-card-query.d.ts +5 -1
- package/dist/types/shared/dashboard-authoring/changes/resolve-dashboard-changes.d.ts +10 -0
- package/dist/types/shared/dashboard-authoring/conditional-formatting/schema.d.ts +60 -60
- package/dist/types/shared/dashboard-authoring/control-execution-contract.d.ts +4 -4
- package/dist/types/shared/dashboard-authoring/matrix-delivery.d.ts +48 -48
- package/dist/types/shared/dashboard-authoring/operations/operation-sentences.d.ts +8 -2
- package/dist/types/shared/dashboard-authoring/operations/operation-types.d.ts +11 -0
- package/dist/types/shared/dashboard-authoring/outline/outline-dashboard.d.ts +7 -0
- package/dist/types/shared/dashboard-authoring/table-sheet-shape.d.ts +8 -0
- package/dist/types/shared/extensions/check-audits.d.ts +30 -0
- package/dist/types/shared/extensions/check-findings.d.ts +46 -0
- package/dist/types/shared/extensions/check-input.d.ts +23 -0
- package/dist/types/shared/extensions/check-renders.d.ts +44 -0
- package/dist/types/shared/extensions/check-runner.d.ts +19 -0
- package/dist/types/shared/extensions/index.d.ts +17 -0
- package/dist/types/shared/extensions/read-document.d.ts +18 -0
- package/dist/types/shared/extensions/sandbox-host.d.ts +63 -0
- package/dist/types/shared/extensions/saved-refs.d.ts +33 -0
- package/dist/types/shared/extensions/script-policy.d.ts +11 -0
- package/dist/types/shared/extensions/types.d.ts +186 -0
- package/dist/types/shared/extensions/visual-contract.d.ts +38 -0
- package/dist/types/shared/extensions/visual-payload.d.ts +75 -0
- package/dist/types/shared/extensions/visual-theme.d.ts +21 -0
- package/dist/types/shared/format-utils/formatters/number-formatter.d.ts +13 -6
- package/dist/types/shared/format-utils/matrix-continuation.d.ts +2 -2
- package/dist/types/shared/format-utils/matrix-export-presentation.d.ts +24 -24
- package/dist/types/shared/usage-events/details.d.ts +4 -4
- package/dist/types/shared/usage-events/envelope.d.ts +2 -2
- package/dist/usage-events/index.js +1 -1
- package/package.json +7 -2
- package/dist/chunks/add-to-dashboard-CEmZUf9o.js +0 -12
- package/dist/chunks/appearance-provider-fIhJSX6y.js +0 -613
- package/dist/chunks/appearance-runtime-provider-Bx8H-moR.js +0 -1
- package/dist/chunks/assistant-chat-SBKSrrEA.js +0 -51
- package/dist/chunks/attachment-filter-line-C_zHMhGh.js +0 -1
- package/dist/chunks/bookmark-state-DScd31KT.js +0 -1
- package/dist/chunks/card-filter-builder-CzScSOQY.js +0 -11
- package/dist/chunks/context-CntvtZwC.js +0 -2
- package/dist/chunks/dashboard-temporal-snapshot-w3SMiPKj.js +0 -1
- package/dist/chunks/edit-dashboard-visual-DlvY7au4.js +0 -73
- package/dist/chunks/filter-reach-preview-DAEIyrEG.js +0 -1
- package/dist/chunks/kpi-trend-rule-N1Xkwe_u.js +0 -1
- package/dist/chunks/matrix-analytical-definition-5T-2euHZ.js +0 -1
- package/dist/chunks/matrix-operation-contract-CWvcEsQ0.js +0 -1
- package/dist/chunks/pivot-result-contract-expectations-BNWhS8mv.js +0 -1
- package/dist/chunks/report-preferences-dialog-B2ZGPS9t.js +0 -1
- package/dist/chunks/resolve-dashboard-input-context-SlAAe4GF.js +0 -8
- package/dist/chunks/saved-dashboard-context-Bc2SVDr-.js +0 -1
- package/dist/chunks/semaphor-ready-indicator-Bj-cjkz-.js +0 -612
- package/dist/chunks/set-CACXVM2A.js +0 -1
- package/dist/chunks/slider-CWze9OEM.js +0 -4
- package/dist/chunks/stored-dashboard-CcNdU-mG.js +0 -1
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import{jsxs as n,jsx as e,Fragment as be}from"react/jsx-runtime";import{F as Es,P as Fs,a as Os,b as mr,u as Ve,S as On,c as Mn,r as hr,E as Ms,T as Rs,A as As,d as Ps,e as $t}from"./slider-CWze9OEM.js";import{l3 as Ds,k as W,l4 as Rn,w as dt,eK as pr,x as ut,z as Kt,aO as tt,aP as Nt,eq as Ls,dw as Xa,hs as _s,jv as zt,F as Vs,db as Bs,jg as Ja,jb as Ks,s as zs,l5 as qs,l6 as js,l7 as $s,l8 as Us,an as Hs,cE as Qs,bk as Gs,jd as La,ke as Ws,bA as Ys,l9 as Xs,la as fr,b0 as Js,fd as Zs,lb as el,jh as tl,fB as al,fz as pa,lc as nl,ld as rl,le as sl,lf as ll,aR as ol,y as gr,aS as il,S as cl,lg as _a,lh as dl,li as ul,lj as ml,lk as Za,aT as hl,h9 as xr,c6 as pl,bH as fl,hU as gl,hn as br,d6 as xl,i8 as bl,ll as vl,hW as yl,kP as Nl,lm as Cl,jQ as wl,ln as Sl,lo as Tl,lp as An,lq as kl,lr as Il,br as Ge,ls as El,lt as Fl,lu as Ol,lv as Ml,lw as Rl,lx as Al,ly as Pn,lz as Dn,e as Pl,bU as Dl,dP as Ll,dN as _l,lA as Vl,lB as Bl,lC as Kl,ht as zl,lD as ql,af as jl,ac as Va,ad as vr,lE as yr,lF as en,aK as Ut,kZ as $l,H as Ul,jf as Hl}from"./resolve-dashboard-input-context-SlAAe4GF.js";import{a6 as Ql}from"./validators-Dg2kyF4_.js";import{D as Gl,t as Nr,u as Cr}from"./matrix-operation-contract-CWvcEsQ0.js";import"./analytics-base-schemas-DMFrDqn_.js";import{DEFAULT_RESOLVED_VALUE_FORMAT_PREFERENCES as Ln}from"../value-format-preferences/index.js";import{cq as Wl,cr as Yl,bW as wr,co as Sr,cs as Xl,bD as Jl,bE as Zl,bF as eo,bG as to,bH as ao,bI as no,bJ as ro,bK as so,bw as Ht,ct as Tr,cu as lo,bb as tn,bi as oo,c5 as io,aD as It,aE as Et,aF as Ft,cv as co,cw as uo,cx as et,cy as mo,cz as ho,cA as fa,cB as po,cC as fo,cD as go,cE as kr,L as Ir,M as xo,cF as an,cG as bo,ca as vo,cH as yo,bO as No,cI as nn,c as rn,cJ as Er,cK as _n,cL as Fr,cM as Co,cN as wo,cO as So,cP as To,cQ as ko,cR as Qt,cS as Io,cT as Eo,cU as Or,cV as Mr,cW as Fo,cX as Oo,c1 as Mo,cY as Ro,cZ as Rr,c_ as Ao,bN as Po,bM as sn,c$ as ln,aI as Ar,aK as Do,aL as Vn,aM as Lo,aN as _o,aO as Vo,cf as Bo,aQ as Ko,aR as zo,aS as qo,aT as jo,aU as $o,aV as Uo,d0 as Ho,d1 as Qo,au as Go,av as Wo,as as Yo,d2 as Xo,d3 as Jo,d4 as Zo,d5 as ei,ax as ti,ay as ai,d6 as ni,d7 as ri,d8 as si,d9 as li,da as oi,db as Pr,bz as Dr,dc as Yt,dd as Se,de as Te,df as ke,bS as ii,bT as ci,dg as di,dh as Xt,di as Lr,dj as _r,dk as Vr,dl as on,dm as Ba,dn as ui,dp as mi,dq as hi,dr as pi,ds as Ka,dt as fi,du as Ze,dv as gi,cg as Jt,dw as xi,dx as Br,dy as bi,dz as vi,dA as Kr,dB as yi,dC as Ni,dD as Bn,dE as Ci,dF as wi,dG as Si,dH as Ti,dI as ki,dJ as Ii,dK as Ei,dL as Fi,dM as Oi,dN as Mi,ch as Ri,dO as Ai,dP as Pi,dQ as Di,dR as Li,dS as _i,u as Vi,dT as Bi,aP as Ki,dU as zi,dV as Kn,dW as qi,dX as ji,F as $i,dY as Ui,b3 as Hi}from"./semaphor-ready-indicator-Bj-cjkz-.js";import{c as ze,F as T,ap as $e,co as zr,cp as Qi,cq as Gi,cr as Wi,b2 as cn,at as qt,a2 as Ct,P as st,c8 as Yi,B as ue,X as Zt,e as lt,aI as Ot,aJ as mt,aK as ht,aM as pt,ag as ea,C as _t,bh as ta,bi as aa,bm as ft,bj as dn,bk as na,bn as gt,bo as Ke,bl as Vt,bp as We,b as xt,g as un,bK as mn,bg as at,bW as Xi,bE as ct,cs as Ji,G as he,aq as hn,u as xe,an as bt,ao as ga,ct as Zi,aQ as L,cu as za,d as kt,ac as vt,cv as qr,cw as pn,bf as qa,aR as ec,bZ as fn,$ as gn,cx as ra,cy as jr,bP as xn,bO as $r,E as sa,cz as tc,cA as ac,cB as nc,bv as rc,ak as Ur,bB as la,bC as oa,cC as ja,cc as Gt,bD as ia,cD as sc,cE as lc,aS as bn,bS as zn,cF as oc,cG as ca,aL as Hr,af as Qr,a4 as ae,a5 as ne,a6 as re,a7 as se,a8 as H,aa as da,cH as ic,cI as qn,cJ as cc,cK as Gr,cL as Wr,as as dc,au as uc,av as mc,aw as hc,cM as jn,cN as pc,cO as wt,cP as St,cQ as Tt,al as ua,by as He,bG as $n,bH as Un,bI as $a,ah as fc,cR as Yr,cS as gc,cT as xc,cU as bc,cV as vc,cW as yc,cX as Nc,cY as Cc,aP as Lt,cZ as wc,c_ as Sc,c$ as Tc,d0 as kc,V as Ic,ab as we,d1 as Ec,d2 as Fc,d3 as Hn,a3 as Qn,d4 as Oc,d5 as xa,d6 as Gn,d7 as Mc,d8 as Rc,bd as vn,be as Bt,d9 as ba,da as Xr,db as Ac,aj as Jr,bU as Pc,dc as Dc,dd as Lc,bQ as _c,bR as Vc,de as Bc,bA as Kc,bT as zc,df as qc,cj as jc,dg as $c,ck as Uc,cm as Hc,cn as Qc,dh as Gc,di as Wc,cd as Yc,A as Xc,bX as Jc}from"./appearance-provider-fIhJSX6y.js";import Ua,{useState as Y,useRef as Oe,useEffect as ve,useCallback as nt,useMemo as X,useContext as yn,Suspense as Zc}from"react";import{aU as ed,aT as td,aN as ad,k as nd}from"./pivot-result-contract-expectations-BNWhS8mv.js";import"zod";import{aJ as Zr,aK as es,A as rd}from"./bookmark-state-DScd31KT.js";import"./schema-O1Y3WTGF.js";import{i as ts}from"./index-DViPGDFj.js";import"./context-CntvtZwC.js";import{F as sd,V as as,I as _e,u as ld,C as od,a as id}from"./card-filter-builder-CzScSOQY.js";import{N as Nn,a6 as cd,I as dd,a7 as ud,a8 as md,b as hd,a9 as Cn,aa as wn,Q as pd,R as fd,U as gd}from"./filter-reach-preview-DAEIyrEG.js";import{S as xd,e as bd,T as vd,N as ns,U as yd,O as rs,V as Nd,K as Cd,n as wd,W as Sd,X as Td,x as kd}from"./stored-dashboard-CcNdU-mG.js";import"react-dom";import{c as Id,b as Ed,m as Fd,K as Od,d as Md}from"./kpi-trend-rule-N1Xkwe_u.js";import{r as Rd}from"./export-file-format-B-wQNHIn.js";import{u as Ad}from"./appearance-runtime-provider-Bx8H-moR.js";import{M as Pd,K as Wn,L as va}from"./set-CACXVM2A.js";import{b as Yn}from"./raw-temporal-value-BHQ-ldpW.js";import{P as Dd}from"./palette-565cA0nh.js";/**
|
|
2
|
-
* @license lucide-react v0.453.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const ss=ze("ArrowUpDown",[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]]);/**
|
|
7
|
-
* @license lucide-react v0.453.0 - ISC
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the ISC license.
|
|
10
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const ls=ze("Blocks",[["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["path",{d:"M10 21V8a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-5a1 1 0 0 0-1-1H3",key:"1fpvtg"}]]);/**
|
|
12
|
-
* @license lucide-react v0.453.0 - ISC
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the ISC license.
|
|
15
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const Ld=ze("CircleHelp",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/**
|
|
17
|
-
* @license lucide-react v0.453.0 - ISC
|
|
18
|
-
*
|
|
19
|
-
* This source code is licensed under the ISC license.
|
|
20
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const _d=ze("Component",[["path",{d:"M15.536 11.293a1 1 0 0 0 0 1.414l2.376 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z",key:"1uwlt4"}],["path",{d:"M2.297 11.293a1 1 0 0 0 0 1.414l2.377 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414L6.088 8.916a1 1 0 0 0-1.414 0z",key:"10291m"}],["path",{d:"M8.916 17.912a1 1 0 0 0 0 1.415l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.415l-2.377-2.376a1 1 0 0 0-1.414 0z",key:"1tqoq1"}],["path",{d:"M8.916 4.674a1 1 0 0 0 0 1.414l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z",key:"1x6lto"}]]);/**
|
|
22
|
-
* @license lucide-react v0.453.0 - ISC
|
|
23
|
-
*
|
|
24
|
-
* This source code is licensed under the ISC license.
|
|
25
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
-
*/const Vd=ze("FileJson2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M4 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",key:"fq0c9t"}],["path",{d:"M8 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",key:"4gibmv"}]]);/**
|
|
27
|
-
* @license lucide-react v0.453.0 - ISC
|
|
28
|
-
*
|
|
29
|
-
* This source code is licensed under the ISC license.
|
|
30
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
-
*/const Bd=ze("Fullscreen",[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["rect",{width:"10",height:"8",x:"7",y:"8",rx:"1",key:"vys8me"}]]);/**
|
|
32
|
-
* @license lucide-react v0.453.0 - ISC
|
|
33
|
-
*
|
|
34
|
-
* This source code is licensed under the ISC license.
|
|
35
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
-
*/const ya=ze("MoveHorizontal",[["path",{d:"m18 8 4 4-4 4",key:"1ak13k"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}]]);/**
|
|
37
|
-
* @license lucide-react v0.453.0 - ISC
|
|
38
|
-
*
|
|
39
|
-
* This source code is licensed under the ISC license.
|
|
40
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
41
|
-
*/const Na=ze("MoveVertical",[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m8 18 4 4 4-4",key:"bh5tu3"}],["path",{d:"m8 6 4-4 4 4",key:"ybng9g"}]]);/**
|
|
42
|
-
* @license lucide-react v0.453.0 - ISC
|
|
43
|
-
*
|
|
44
|
-
* This source code is licensed under the ISC license.
|
|
45
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
46
|
-
*/const Ha=ze("RefreshCcw",[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]]);/**
|
|
47
|
-
* @license lucide-react v0.453.0 - ISC
|
|
48
|
-
*
|
|
49
|
-
* This source code is licensed under the ISC license.
|
|
50
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
51
|
-
*/const Kd=ze("SendHorizontal",[["path",{d:"M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z",key:"117uat"}],["path",{d:"M6 12h16",key:"s4cdu5"}]]);/**
|
|
52
|
-
* @license lucide-react v0.453.0 - ISC
|
|
53
|
-
*
|
|
54
|
-
* This source code is licensed under the ISC license.
|
|
55
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
56
|
-
*/const zd=ze("Spline",[["circle",{cx:"19",cy:"5",r:"2",key:"mhkx31"}],["circle",{cx:"5",cy:"19",r:"2",key:"v8kfzx"}],["path",{d:"M5 17A12 12 0 0 1 17 5",key:"1okkup"}]]);/**
|
|
57
|
-
* @license lucide-react v0.453.0 - ISC
|
|
58
|
-
*
|
|
59
|
-
* This source code is licensed under the ISC license.
|
|
60
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
61
|
-
*/const qd=ze("SquareSplitVertical",[["path",{d:"M5 8V5c0-1 1-2 2-2h10c1 0 2 1 2 2v3",key:"1pi83i"}],["path",{d:"M19 16v3c0 1-1 2-2 2H7c-1 0-2-1-2-2v-3",key:"ido5k7"}],["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}]]);/**
|
|
62
|
-
* @license lucide-react v0.453.0 - ISC
|
|
63
|
-
*
|
|
64
|
-
* This source code is licensed under the ISC license.
|
|
65
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
66
|
-
*/const jd=ze("Tags",[["path",{d:"m15 5 6.3 6.3a2.4 2.4 0 0 1 0 3.4L17 19",key:"1cbfv1"}],["path",{d:"M9.586 5.586A2 2 0 0 0 8.172 5H3a1 1 0 0 0-1 1v5.172a2 2 0 0 0 .586 1.414L8.29 18.29a2.426 2.426 0 0 0 3.42 0l3.58-3.58a2.426 2.426 0 0 0 0-3.42z",key:"135mg7"}],["circle",{cx:"6.5",cy:"9.5",r:".5",fill:"currentColor",key:"5pm5xn"}]]);/**
|
|
67
|
-
* @license lucide-react v0.453.0 - ISC
|
|
68
|
-
*
|
|
69
|
-
* This source code is licensed under the ISC license.
|
|
70
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
71
|
-
*/const os=ze("TrendingUp",[["polyline",{points:"22 7 13.5 15.5 8.5 10.5 2 17",key:"126l90"}],["polyline",{points:"16 7 22 7 22 13",key:"kwv8wd"}]]);function ma(){var d,l;const t=T(i=>i.card),{data:a,comparisonMetadata:s}=$e(t),r=(a==null?void 0:a.records)||[],{keys:o}=zr(r,s),c=o.slice(1).filter(i=>!Ds.includes(i));if(Qi(t.type)){const i=t.config,v=(d=i==null?void 0:i.pivotByColumns)!=null&&d.length&&(l=i==null?void 0:i.groupByColumns)!=null&&l.length?Gi(r,i.metricColumns||[]):r,u=Wi({card:t,cardType:t.type,records:v,columnKeyMap:a==null?void 0:a.columnKeyMap,comparisonMetadata:s});return{transformedMetricKeys:u.valueKeys,dimensionKeys:u.axisKeys,keys:o,defaultMetricKeys:c};}return{transformedMetricKeys:c,dimensionKeys:o.slice(0,1),keys:o,defaultMetricKeys:c};}function is({isVisible:t}){return Wl(),/* @__PURE__ */n("div",{className:W("flex shrink-0 flex-col overflow-hidden border-r border-border bg-background transition-all duration-300 ease-in-out",{"w-[290px]":t,"min-w-[290px]":t,"w-0 border-r-0":!t,"min-w-0":!t}),children:[/* @__PURE__ */e("div",{className:"px-4 pt-4",children:/* @__PURE__ */e(Yl,{})}),/* @__PURE__ */e("div",{className:"min-h-0 flex-1",children:/* @__PURE__ */e(Es,{})})]});}const Qa=({className:t,...a})=>/* @__PURE__ */e(Os,{className:W("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",t),...a}),yt=Fs,cs=({withHandle:t,className:a,...s})=>/* @__PURE__ */e(mr,{className:W("relative flex w-px items-center justify-center bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",a),...s,children:t&&/* @__PURE__ */e("div",{className:"z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border",children:/* @__PURE__ */e(cn,{className:"h-2.5 w-2.5"})})}),$d=3,Ga="Self-heal",Ca={grounding:"Analyzing context",drafting:"Drafting SQL",validating:"Validating SQL",repairing:Ga},Mt="Unable to generate a SQL draft right now. Try again.",Ud="Choose a data source for this card before describing a query.",Hd="Validation service unavailable. You can still replace and run.";function Rt(t,a){typeof window>"u"||window.dispatchEvent(new CustomEvent("semaphor:inline-query-writer",{detail:{event:t,...a,timestamp:Date.now()}}));}const At={runId:0,status:"idle",prompt:"",mode:"draft",baselineSql:"",timelineSteps:[],activeStep:"",attempt:0,sql:"",validation:null,errorMessage:""};function Qd(t,a){return t===Ga&&a>0?`${Ga} ${a}/${$d}`:t;}async function Gd(t,a){try{const s=await t.json();if(typeof(s==null?void 0:s.error)=="string"&&s.error.trim())return s.error;}catch{}return a;}async function Wd(t,a){const s=d=>{const l=d.trim();l&&a(JSON.parse(l));};if(!t.body){(await t.text()).split(`
|
|
72
|
-
`).forEach(s);return;}const r=t.body.getReader(),o=new TextDecoder();let c="";for(;;){const{done:d,value:l}=await r.read();if(d)break;c+=o.decode(l,{stream:!0});const i=c.split(`
|
|
73
|
-
`);c=i.pop()??"",i.forEach(s);}s(c+o.decode());}function Yd({currentSql:t,selectedDatabaseName:a,selectedSchemaName:s,selectedTableName:r,onApplySql:o,autoFocus:c,onDismiss:d}){var Ye,Xe;const{authToken:l,tokenProps:i}=qt(),v=T(J=>J.card.id),u=T(J=>{var ye;return J.card.connectionId||((ye=J.card.dataSource)==null?void 0:ye.connectionId)||"";}),[p,f]=Y(""),[m,N]=Y("draft"),[w,S]=Y(!1),[b,y]=Y(!1),[R,x]=Y(At),[D,B]=Y(v),$=Oe(null),j=Oe(0),k=Oe(null),O=(Ye=i.apiServiceUrl)==null?void 0:Ye.replace(/\/$/,""),A=O?`${O}/v1/sql/draft`:"/v1/sql/draft";function F(){var J;j.current+=1,(J=k.current)==null||J.abort(),k.current=null;}ve(()=>()=>{var J;j.current+=1,(J=k.current)==null||J.abort(),k.current=null;},[v]),D!==v&&(B(v),x(J=>({...At,runId:J.runId})),f(""),S(!1));const K=R.status==="running";function E(){R.status==="running"&&(F(),x(J=>({...J,status:"idle",activeStep:"",sql:"",validation:null})),Rt("inline_self_heal_stopped",{runId:R.runId,attemptCount:R.attempt,finalOutcome:"cancelled"}));}async function h(J,ye,Re){const Le=()=>j.current===J,Pe=ge=>{Le()&&x(oe=>oe.runId===J?ge(oe):oe);},De=ge=>Pe(oe=>({...oe,status:"failed",activeStep:"",errorMessage:ge}));let je=!1;const Je=ge=>{var Me;if(!Le()||je)return;if(ge.type==="stage"){const U=Ca[ge.stage];if(!U)return;const Ie=ge.stage==="repairing"?ge.attempt??0:0;Pe(Z=>({...Z,timelineSteps:Z.timelineSteps.includes(U)?Z.timelineSteps:[...Z.timelineSteps,U],activeStep:U,attempt:ge.stage==="repairing"?Ie:Z.attempt})),ge.stage==="repairing"&&Rt("inline_self_heal_attempt",{runId:J,attemptCount:Ie});return;}if(je=!0,ge.type==="error"){De(ge.message||Mt);return;}const oe=((Me=ge.sql)==null?void 0:Me.trim())||"";if(!oe){De(Mt);return;}Pe(U=>({...U,status:"done",activeStep:"",sql:oe,validation:ge.validation})),ge.validation.status==="invalid"?Rt("inline_validation_failed",{runId:J,attemptCount:ge.repairs,errorCode:ge.validation.code,finalOutcome:"validation_failed"}):Rt("inline_draft_validated",{runId:J,attemptCount:ge.repairs,finalOutcome:ge.validation.status});};try{const ge=await fetch(A,{method:"POST",headers:{Authorization:`Bearer ${l==null?void 0:l.accessToken}`,"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(ye),signal:Re});if(!Le())return;if(!ge.ok){De(await Gd(ge,Mt));return;}await Wd(ge,Je),je||De(Mt);}catch{De(Mt);}finally{Le()&&(k.current=null);}}const I=(t==null?void 0:t.trim())||"";function g(J="draft"){if(K)return;const ye=p.trim();if(!ye)return;const Re=J==="refine"&&I?"refine":"draft",Le=Re==="refine"?I:"";F();const Pe=j.current;if(S(!1),y(!0),!u){x({...At,runId:Pe,status:"failed",prompt:ye,errorMessage:Ud});return;}x({...At,runId:Pe,status:"running",prompt:ye,mode:Re,baselineSql:Le}),Rt("inline_draft_started",{runId:Pe,attemptCount:0,finalOutcome:"drafting"});const De=new AbortController();k.current=De,h(Pe,{request:ye,mode:Re,...(I?{currentSql:I}:{}),connectionId:u,...(a?{database:a}:{}),...(s?{schema:s}:{}),...(r?{table:r}:{})},De.signal);}const C=R.status==="done"?R.sql:"",M=R.prompt,z=R.mode,_=R.baselineSql;function P(J){const ye=C.trim();ye&&(o(ye,J),J||y(!1));}const V=C.length>0,G=((Xe=R.validation)==null?void 0:Xe.status)==="invalid",ee=V&&M.length>0&&M===p.trim(),ie=I.length>0,Q=p.trim().length>0,q=!!d&&!Q&&!V&&!K,te=ee&&z==="draft",ce=ee&&z==="refine"&&_===I,me=m==="refine"&&!ie?"draft":m,pe=(me==="refine"?ce:te)?"Open composer preview":"Generate composer SQL",fe=p.trim().length>0||M.trim().length>0||V||R.status!=="idle"||R.timelineSteps.length>0;function Ee(J="draft"){if(K)return;if((J==="refine"?ce:te)&&!b){y(!0);return;}g(J);}function Ae(){y(!0);}function Ue(J){E(),f(J);}function de(){K||(F(),f(""),N("draft"),S(!1),x({...At,runId:j.current}));}function Ce(J){J||E(),y(J);}const Fe=R.timelineSteps.findIndex(J=>J===R.activeStep),ot=R.activeStep===Ca.repairing?"Fixing validation issue":R.activeStep||Ca.drafting,qe=!V||!R.validation?null:R.validation.status==="valid"?{label:"Validation passed",className:"border-emerald-500/30 bg-emerald-500/10 text-emerald-700",detail:"SQL validation passed."}:R.validation.status==="invalid"?{label:"Validation failed",className:"border-destructive/40 bg-destructive/10 text-destructive",detail:R.validation.message}:{label:"Validation unavailable",className:"border-border/60 bg-muted/20 text-muted-foreground",detail:Hd};return/* @__PURE__ */n("div",{ref:$,className:"relative flex h-7 min-w-0 flex-1 items-center",children:[/* @__PURE__ */e(Ct,{value:p,onChange:J=>Ue(J.target.value),autoFocus:c,onFocus:Ae,onClick:Ae,onKeyDown:J=>{J.key==="Enter"?(J.preventDefault(),Ee(me)):J.key==="Escape"&&q&&(d==null||d());},placeholder:"Describe the query you want, or a change to this one…","aria-label":"Describe a query",className:["h-7 rounded-[5px] border border-border/60 bg-background pl-3 text-[12px] shadow-none placeholder:text-muted-foreground/70 focus-visible:border-ring focus-visible:ring-0",Q?"pr-[56px]":d?"pr-9":"pr-3"].join(" ")}),/* @__PURE__ */n(st,{open:b,onOpenChange:Ce,children:[/* @__PURE__ */e(Yi,{asChild:!0,children:/* @__PURE__ */e("div",{className:"pointer-events-none absolute inset-0"})}),/* @__PURE__ */n("div",{className:"absolute right-1 flex items-center gap-1",children:[(Q||d)&&/* @__PURE__ */e(ue,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0",onClick:J=>{J.preventDefault(),Q?(E(),f("")):q?d==null||d():de();},disabled:K,"aria-label":Q?"Clear input":q?"Close":"Clear draft",title:Q?"Clear input":q?"Close":"Clear draft",children:/* @__PURE__ */e(Zt,{className:"size-3.5"})}),Q&&/* @__PURE__ */e(ue,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0",onClick:J=>{if(J.preventDefault(),K){E();return;}Ee(me);},"aria-label":K?"Stop AI generation":pe,title:K?"Stop AI generation":pe,children:K?/* @__PURE__ */e(wr,{className:"size-3 fill-current"}):/* @__PURE__ */e(Kd,{className:"size-3.5"})})]}),/* @__PURE__ */e(lt,{align:"start",alignOffset:0,side:"top",sideOffset:8,className:"w-[min(92vw,var(--radix-popover-trigger-width))] max-w-[760px] p-2.5",onOpenAutoFocus:J=>{J.preventDefault();},onInteractOutside:J=>{var Re;const ye=J.target;if(ye&&(Re=$.current)!=null&&Re.contains(ye)){J.preventDefault();return;}q&&(d==null||d());},children:/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between gap-3",children:[/* @__PURE__ */e("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-2",children:/* @__PURE__ */n("div",{className:"inline-flex h-7 items-center rounded-[5px] border border-border/60 bg-background p-0.5",children:[/* @__PURE__ */e(ue,{type:"button",variant:"ghost",className:["h-6 rounded-[4px] px-2 text-[12px]",me==="draft"?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground"].join(" "),onClick:()=>{N("draft"),S(!1);},children:"Draft New"}),/* @__PURE__ */e(ue,{type:"button",variant:"ghost",className:["h-6 rounded-[4px] px-2 text-[12px]",me==="refine"?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground"].join(" "),onClick:()=>N("refine"),disabled:!ie,children:"Refine"})]})}),/* @__PURE__ */n("div",{className:"flex shrink-0 items-center",children:[K&&/* @__PURE__ */e(ue,{variant:"ghost",size:"xs",onClick:E,children:"Stop"}),!K&&/* @__PURE__ */e(ue,{variant:"ghost",size:"xs",onClick:de,disabled:!fe,children:"Clear"})]})]}),(R.timelineSteps.length>0||qe)&&/* @__PURE__ */n("div",{className:"flex flex-wrap items-center gap-1",children:[R.timelineSteps.map((J,ye)=>{const Re=K&&J===R.activeStep,Le=!Re&&Fe>=0&&ye<Fe;return/* @__PURE__ */e("span",{className:["rounded-full border px-2 py-0.5 text-[11px]",Re?"border-foreground/30 bg-foreground/10 text-foreground":Le?"border-border/60 bg-muted/20 text-muted-foreground":"border-border/50 bg-background text-muted-foreground/80"].join(" "),children:Qd(J,R.attempt)},`${J}-${ye}`);}),qe&&/* @__PURE__ */e(Ot,{delayDuration:150,children:/* @__PURE__ */n(mt,{children:[/* @__PURE__ */e(ht,{asChild:!0,children:/* @__PURE__ */e("span",{className:["rounded-full border px-2 py-0.5 text-[11px]",qe.className].join(" "),children:qe.label})}),/* @__PURE__ */e(pt,{side:"top",align:"start",className:"max-w-[680px] whitespace-pre-wrap break-words text-xs",children:qe.detail})]})})]}),K&&/* @__PURE__ */n("div",{className:"flex items-center gap-2 rounded-md border border-border/60 bg-muted/20 px-3 py-2 text-xs text-muted-foreground",children:[/* @__PURE__ */e(ea,{className:"size-3.5 animate-spin"}),ot]}),R.status==="failed"&&/* @__PURE__ */e("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive",children:R.errorMessage}),z==="refine"&&_&&/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between rounded-[5px] border border-border/60 bg-muted/20 px-2.5 py-1.5 text-[11px]",children:[/* @__PURE__ */e("span",{className:"text-muted-foreground",children:"Refining editor SQL"}),/* @__PURE__ */e(ue,{type:"button",variant:"ghost",size:"xs",onClick:()=>S(J=>!J),children:w?"Hide base SQL":"View base SQL"})]}),w&&/* @__PURE__ */e("div",{className:"max-h-[120px] overflow-auto rounded-[5px] border border-border/60",children:/* @__PURE__ */e(_t,{value:_,onValueChange:()=>{},language:"sql",readOnly:!0,embedded:!0,wrapLines:!0,dense:!0,hideLineNumbers:!0,ariaLabel:"Base SQL"})})]}),V?/* @__PURE__ */n("div",{className:"space-y-1",children:[z==="refine"&&/* @__PURE__ */e("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Refined SQL"}),/* @__PURE__ */e("div",{className:"max-h-[200px] overflow-auto rounded-[5px] border border-border/60",children:/* @__PURE__ */e(_t,{value:C,onValueChange:()=>{},language:"sql",readOnly:!0,embedded:!0,wrapLines:!0,dense:!0,hideLineNumbers:!0,ariaLabel:"Drafted SQL"})})]}):!K&&/* @__PURE__ */e("div",{className:"rounded-[5px] border border-dashed border-border/70 px-3 py-2 text-[11px] text-muted-foreground",children:ie?"Choose Draft New or Refine Current, then press Enter or click send.":"Describe what you want to query, then press Enter or click send to generate a SQL preview."}),/* @__PURE__ */n("div",{className:"flex flex-wrap items-center justify-end gap-1.5",children:[/* @__PURE__ */e(ue,{variant:"secondary",size:"xs",disabled:K||!V,onClick:()=>P(!1),children:"Replace SQL"}),/* @__PURE__ */e(ue,{size:"xs",disabled:K||!V||G,onClick:()=>P(!0),children:"Replace & Run"})]})]})})]})]});}function Xd({activeEditor:t,isRunning:a,sqlEditor:s,pythonEditor:r,onActiveEditorChange:o,onOpenChange:c,onRun:d}){return/* @__PURE__ */e(ta,{open:t!==null,onOpenChange:c,children:/* @__PURE__ */e(aa,{showCloseButton:!1,className:"flex h-[min(88vh,860px)] w-[min(1280px,calc(100vw-2rem))] max-w-none flex-col gap-0 overflow-hidden p-0",children:/* @__PURE__ */n(ft,{value:t??"sql",onValueChange:i=>o(i),className:"flex min-h-0 flex-1 flex-col",children:[/* @__PURE__ */n(dn,{className:"h-11 flex-row items-center justify-between space-y-0 border-b border-border/60 px-4 py-0 text-left",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-4 self-stretch",children:[/* @__PURE__ */e(na,{className:"shrink-0 text-sm",children:"Query editor"}),/* @__PURE__ */n(gt,{variant:"underline",className:"h-full items-end gap-5 self-stretch border-b-0",children:[/* @__PURE__ */e(Ke,{value:"sql",className:"px-0",children:"SQL"}),/* @__PURE__ */e(Ke,{value:"python",className:"px-0",children:"Python"})]}),/* @__PURE__ */e(Vt,{className:"sr-only",children:"Expanded SQL and Python query editor"})]}),/* @__PURE__ */n("div",{className:"flex shrink-0 items-center gap-1.5",children:[/* @__PURE__ */n(ue,{type:"button",size:"xs",onClick:d,disabled:a,children:[a?/* @__PURE__ */e(ea,{className:"h-3.5 w-3.5 animate-spin"}):/* @__PURE__ */e(Sr,{className:"h-3.5 w-3.5"}),"Run"]}),/* @__PURE__ */e(ue,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>c(!1),"aria-label":"Collapse query editor",title:"Collapse editor",children:/* @__PURE__ */e(Xl,{className:"h-3.5 w-3.5"})})]})]}),/* @__PURE__ */e(We,{value:"sql",forceMount:!0,className:"mt-0 min-h-0 flex-1 data-[state=inactive]:hidden",children:s}),/* @__PURE__ */e(We,{value:"python",forceMount:!0,className:"mt-0 min-h-0 flex-1 data-[state=inactive]:hidden",children:r})]})})});}function Xn(t,a){return t.current.cardId!==a&&(t.current={cardId:a,snapshots:{}}),t.current;}function Jd({cardId:t,expandedEditor:a}){const s=Oe(null),r=Oe(null),o=Oe(null),c=Oe(null),d=Oe({cardId:t,snapshots:{}}),l=nt(i=>{var N,w;const v=i==="inline"?s:o,u=i==="inline"?r:c,p=(N=v.current)==null?void 0:N.captureSession(),f=(w=u.current)==null?void 0:w.captureSession(),m=Xn(d,t);p&&(m.snapshots.sql=p),f&&(m.snapshots.python=f);},[t]);return ve(()=>{var m,N;const i=Xn(d,t),v=a===null?s:o,u=a===null?r:c,{sql:p,python:f}=i.snapshots;p&&((m=v.current)==null||m.restoreSession(p)),f&&((N=u.current)==null||N.restoreSession(f));},[t,a]),{inlineSqlEditorRef:s,inlinePythonEditorRef:r,expandedSqlEditorRef:o,expandedPythonEditorRef:c,captureEditorSessions:l};}function ds({openDelay:t=200,closeDelay:a=150}={}){const[s,r]=Y(!1),o=Oe(null),c=Oe(null),d=Oe(!1),l=()=>{o.current&&(clearTimeout(o.current),o.current=null);},i=()=>{c.current&&(clearTimeout(c.current),c.current=null);};ve(()=>()=>{o.current&&clearTimeout(o.current),c.current&&clearTimeout(c.current);},[]);const v=p=>{p.pointerType!=="touch"&&(i(),!s&&(l(),o.current=setTimeout(()=>r(!0),t)));},u=p=>{p.pointerType!=="touch"&&(l(),i(),c.current=setTimeout(()=>r(!1),a));};return{popoverProps:{open:s,onOpenChange:r},triggerProps:{onPointerEnter:v,onPointerLeave:u,onFocus:()=>{l(),i(),d.current||r(!0);},onClick:p=>{p.preventDefault(),l(),i(),r(!0);}},contentProps:{onCloseAutoFocus:()=>{d.current=!0,queueMicrotask(()=>{d.current=!1;});},onPointerEnter:p=>{p.pointerType!=="touch"&&i();},onPointerLeave:u}};}function Zd({value:t}){const[a,s]=Y(!1),r=Oe(null);ve(()=>()=>{r.current&&clearTimeout(r.current);},[]);const o=async()=>{var c;try{if(!((c=navigator.clipboard)!=null&&c.writeText))throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(t),s(!0),r.current&&clearTimeout(r.current),r.current=setTimeout(()=>s(!1),1200);}catch{at.error("Failed to copy");}};return/* @__PURE__ */n("button",{type:"button","aria-label":`Copy ${t}`,onClick:o,className:"group inline-flex w-full cursor-pointer items-center justify-start rounded-[3px] bg-muted/35 px-2 py-1.5 text-left font-mono text-[11px] text-foreground transition-colors hover:bg-muted/60 focus-visible:bg-muted/60 focus-visible:outline-none",children:[/* @__PURE__ */e("code",{children:t}),a?/* @__PURE__ */e(un,{"aria-hidden":"true",className:"ml-auto size-3.5 shrink-0 text-emerald-600/80 dark:text-emerald-400/80",strokeWidth:1.75}):/* @__PURE__ */e(mn,{"aria-hidden":"true",className:"ml-auto size-3.5 shrink-0 text-muted-foreground/60 transition-colors group-hover:text-muted-foreground group-focus-visible:text-muted-foreground",strokeWidth:1.75}),/* @__PURE__ */e("span",{className:"sr-only","aria-live":"polite",children:a?"Copied to clipboard":""})]});}function eu({hint:t}){const{popoverProps:a,triggerProps:s,contentProps:r}=ds();return/* @__PURE__ */n(st,{...a,children:[/* @__PURE__ */e(xt,{asChild:!0,children:/* @__PURE__ */n(ue,{type:"button",variant:"ghost",size:"xs","aria-label":"Dashboard filters off",...s,className:"h-7 w-7 shrink-0 gap-1.5 border border-amber-300/60 bg-amber-50/60 px-0 text-amber-800 hover:bg-amber-100/70 hover:text-amber-900 @[1550px]:w-auto @[1550px]:px-2 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-300 dark:hover:bg-amber-500/15 dark:hover:text-amber-200",children:[/* @__PURE__ */e(sd,{className:"h-3.5 w-3.5",strokeWidth:1.75}),/* @__PURE__ */e("span",{className:"hidden @[1550px]:inline",children:"Dashboard filters off"})]})}),/* @__PURE__ */n(lt,{align:"start",collisionPadding:8,...r,onOpenAutoFocus:o=>o.preventDefault(),className:"w-72 space-y-2.5 p-3",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e("p",{className:"text-[13px] font-medium",children:"Dashboard filters aren’t applied"}),/* @__PURE__ */e("p",{className:"text-[12px] leading-relaxed text-muted-foreground",children:t.description})]}),/* @__PURE__ */e(Zd,{value:t.helper}),/* @__PURE__ */e("a",{href:"https://docs.semaphor.cloud/docs/concepts/filters",target:"_blank",rel:"noreferrer",className:"inline-flex text-[12px] font-medium text-foreground underline-offset-4 hover:underline",children:"Learn more ↗"})]})]});}function tu({activeEditor:t,onExpand:a,trailing:s}){const r=`Expand ${t==="sql"?"SQL":"Python"} editor`;return(/* @__PURE__ */n("div",{className:"flex h-10 shrink-0 items-center gap-4 border-b border-border/60 px-4",children:[/* @__PURE__ */n(gt,{variant:"underline",className:"h-full items-end gap-5 self-stretch border-b-0",children:[/* @__PURE__ */e(Ke,{value:"sql",className:"px-0 text-[13px]",children:"SQL"}),/* @__PURE__ */e(Ke,{value:"python",className:"px-0 text-[13px]",children:"Python"})]}),/* @__PURE__ */n("div",{className:"ml-auto flex min-w-0 shrink-0 items-center gap-1.5",children:[s,/* @__PURE__ */e(ue,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:a,"aria-label":r,title:r,children:/* @__PURE__ */e(Xi,{className:"h-3.5 w-3.5",strokeWidth:1.75})})]})]}));}function au({value:t}){const[a,s]=Y(!1),r=Oe(null);return ve(()=>()=>{r.current&&clearTimeout(r.current);},[]),/* @__PURE__ */n(ue,{type:"button",variant:"ghost",size:"xs",className:"h-6 gap-1 px-1.5 text-[11px] text-muted-foreground","aria-label":"Copy example",onClick:async()=>{var c;try{if(!((c=navigator.clipboard)!=null&&c.writeText))throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(t),s(!0),r.current&&clearTimeout(r.current),r.current=setTimeout(()=>s(!1),1200);}catch{at.error("Failed to copy");}},children:[a?/* @__PURE__ */e(un,{className:"h-3 w-3",strokeWidth:1.75}):/* @__PURE__ */e(mn,{className:"h-3 w-3",strokeWidth:1.75}),a?"Copied":"Copy"]});}function nu(){const{popoverProps:t,triggerProps:a,contentProps:s}=ds();return/* @__PURE__ */n(st,{...t,children:[/* @__PURE__ */e(xt,{asChild:!0,children:/* @__PURE__ */n(ue,{type:"button",variant:"ghost",size:"xs",className:"h-7 gap-1.5 px-2 text-[12px] font-normal text-muted-foreground hover:text-foreground","aria-label":"How the Python step works",...a,children:[/* @__PURE__ */e(ct,{className:"h-3.5 w-3.5",strokeWidth:1.75}),"How it works"]})}),/* @__PURE__ */n(lt,{align:"end",collisionPadding:8,...s,onOpenAutoFocus:r=>r.preventDefault(),className:"w-[min(92vw,380px)] space-y-3 p-3",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e("p",{className:"text-[13px] font-medium",children:"Python step"}),/* @__PURE__ */e("p",{className:"text-[12px] leading-relaxed text-muted-foreground",children:"Runs after the SQL and can reshape its result. Until you add code here, only the SQL runs."})]}),/* @__PURE__ */n("dl",{className:"space-y-1.5 text-[12px] leading-relaxed",children:[/* @__PURE__ */n("div",{className:"flex gap-2",children:[/* @__PURE__ */e("dt",{children:/* @__PURE__ */e("code",{className:"rounded-[3px] bg-muted px-1 font-mono text-[11px]",children:"data"})}),/* @__PURE__ */e("dd",{className:"text-muted-foreground",children:"The SQL result, as a list of records."})]}),/* @__PURE__ */n("div",{className:"flex gap-2",children:[/* @__PURE__ */e("dt",{children:/* @__PURE__ */e("code",{className:"rounded-[3px] bg-muted px-1 font-mono text-[11px]",children:"result"})}),/* @__PURE__ */e("dd",{className:"text-muted-foreground",children:"Set it to a list of dicts to replace the result. Leave it unset to keep the SQL result as is."})]})]}),/* @__PURE__ */n("div",{className:"overflow-hidden rounded-[5px] border border-border/60",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between border-b border-border/60 bg-muted/30 px-2 py-0.5",children:[/* @__PURE__ */e("span",{className:"text-[11px] text-muted-foreground",children:"Example"}),/* @__PURE__ */e(au,{value:Rn})]}),/* @__PURE__ */e("div",{className:"max-h-40 overflow-auto",children:/* @__PURE__ */e(_t,{value:Rn,language:"python",readOnly:!0,embedded:!0,dense:!0,hideLineNumbers:!0,wrapLines:!0,ariaLabel:"Python example"})})]})]})]});}function ru({open:t,onOpenChange:a,onConfirm:s}){return/* @__PURE__ */e(Jl,{open:t,onOpenChange:a,children:/* @__PURE__ */n(Zl,{children:[/* @__PURE__ */n(eo,{children:[/* @__PURE__ */e(to,{children:"Clear the editor?"}),/* @__PURE__ */e(ao,{children:"This clears the SQL, the Python step and the chart settings in this editor. Nothing changes on the dashboard until you click Done."})]}),/* @__PURE__ */n(no,{children:[/* @__PURE__ */e(ro,{children:"Cancel"}),/* @__PURE__ */e(so,{className:W(Ji({variant:"destructive",size:"xs"})),onClick:s,children:"Clear"})]})]})});}function su(t,a){return{...t,sql:"",python:"",config:void 0,customCfg:"",preferences:{},interactionConfig:void 0,linkedInteractionTargetOverrides:void 0,customCardPreferences:a?t.customCardPreferences:void 0,type:a?t.type:Nn};}function lu(){const{setTempQueryData:t}=he(),a=hn(),s=T(R=>R.tempQueryData),r=T(R=>R.card),o=Ve(),c=X(()=>o!==r.type?{...r,type:o}:r,[r,o]),{queryKey:d}=$e(c),{setCardSql:l,setSqlGen:i,setCardPython:v,setCardCustomCfg:u,setCardPreferences:p,clearQueryConfig:f,setCardConfig:m,setCardType:N,setFrame:w,setCard:S,setActiveTabCardId:b}=he();function y(){var k,O,A,F;const R=a.getQueryData(d);s!=null&&s.queryData||t({queryKey:d,queryData:R}),a.setQueryData(d,null),a.removeQueries({queryKey:d,exact:!0}),l(""),i({}),f(),m(void 0),v(""),u(""),p({});const x=T.getState().frame,D=T.getState().card,B=dt(x,D),$=((k=B==null?void 0:B.customCardPreferences)==null?void 0:k.visualType)==="multiple"||!!((O=B==null?void 0:B.customCardPreferences)!=null&&O.dataInputCardIds)||(((A=B==null?void 0:B.customCardPreferences)==null?void 0:A.minInputs)||0)>1||(((F=B==null?void 0:B.customCardPreferences)==null?void 0:F.maxInputs)||0)>1,j=su(D,$);w({...x,cards:x.cards.map(K=>K.id===j.id?j:K)}),b(j.id),S(j),$||N(Nn);}return y;}const Jn="[&_.code-editor-pre]:!pb-14 [&_.code-editor-textarea]:!pb-14";function ou(){var Je,ge,oe,Me;const t=hn(),{tokenProps:a}=qt(),s=((ge=(Je=a.config)==null?void 0:Je.projectFeatures)==null?void 0:ge.features.aiWritingHelpers)!==!1,[r,o]=Y("sql"),[c,d]=Y(!1),[l,i]=Y(!1),v=lu(),[u,p]=Y(!1),[f,m]=Y(null),N=T(U=>U.frame),w=T(U=>U.card),{inlineSqlEditorRef:S,inlinePythonEditorRef:b,expandedSqlEditorRef:y,expandedPythonEditorRef:R,captureEditorSessions:x}=Jd({cardId:w.id,expandedEditor:f});T(U=>U.selectedConnectionId),T(U=>U.tempQueryData);const D=T(U=>U.selectedDatabaseName);T(U=>U.selectedDatamodelId);const B=T(U=>U.selectedSchemaName),$=T(U=>U.selectedTableName),j=xe(U=>U.dashboard?pr(U.dashboard).length:0),k=T(U=>U.inlineFilterValuesMap[(w==null?void 0:w.id)??""]),O=X(()=>dt(N,w),[N,w]),{manifest:A}=bt(((oe=O==null?void 0:O.customCardPreferences)==null?void 0:oe.url)||""),F=X(()=>{var U;return(U=A==null?void 0:A.visuals)==null?void 0:U.find(Ie=>{var Z;return Ie.name===((Z=O==null?void 0:O.customCardPreferences)==null?void 0:Z.componentName);});},[A,(Me=O==null?void 0:O.customCardPreferences)==null?void 0:Me.componentName]),K=ut(O,F),E=X(()=>Kt({frame:N,configCard:O,isMultiInputVisual:K==="multiple"}),[N,O,K]),h=X(()=>{const U=E.findIndex(Ie=>(Ie==null?void 0:Ie.id)===(w==null?void 0:w.id));return U<0?-1:tt(w,U);},[E,w]),I=X(()=>!O||K!=="multiple"||h<0?w.type:Nt(w,h,F==null?void 0:F.slots)??w.type,[O,K,h,w,F==null?void 0:F.slots]),g=X(()=>I!==w.type?{...w,type:I}:w,[w,I]),C=X(()=>j===0?null:Ls(w==null?void 0:w.sql),[w==null?void 0:w.sql,j]),M=Oe(!0),{setCardCustomCfg:z,setQueryResultColumns:_,setCardSql:P,setTempQueryData:V,setCardPreferences:G,setCardType:ee,setCardPython:ie,setCard:Q,updateCardInFrame:q}=he();T(U=>U.onSave),T(U=>U.onClose),T(U=>U.actions.setSqlGen);const te=T(U=>U.runSql),ce=T(U=>U.actions.setRunSql),me=T(U=>U.actions.setIsSqlRunning),{data:le,isLoading:pe,isFetching:fe,isSuccess:Ee,isError:Ae,error:Ue,errorSql:de,queryKey:Ce,refetch:Fe,errorMessage:ot}=$e(g),qe=Oe(Ce);qe.current=Ce;const Ye=w.type==="kpi"&&Xa(w);ve(()=>{if(le)if(le.rowLimitExceeded&&at.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),le.records.length>0){const{keys:U}=zr(le.records),Ie=Ye?_s(le.records).value:void 0;_(w.type==="kpi"?Ie?[Ie]:[]:U,le.columnKeyMap,le.columns);}else _([]);},[w.type,le,_,Ye]),ve(()=>{(pe||fe)&&(me(!0),_([])),(Ae||Ee)&&me(!1),Ae&&_([]);},[pe,fe,le,Ae,Ee,me,_,Ue]),ve(()=>{te&&(t.getQueryData(Ce)||Fe(),ce(!1));},[te,Fe,ce,Ce,t]);const Xe=Oe(Fe);Xe.current=Fe,ve(()=>{if(M.current){M.current=!1;return;}Xe.current();},[k]);function J(U,Ie){P(U),Ie&&ce(!0);}function ye(){hr({queryClient:t,readQueryKey:()=>qe.current,setRunSql:ce});}function Re(U){ga(),x("inline"),m(U);}function Le(U){ga(),x("expanded"),m(U);}function Pe(U){U||(ga(),x("expanded"),m(null));}function De(U){s&&(U.metaKey||U.ctrlKey)&&!U.altKey&&!U.shiftKey&&U.key.toLowerCase()==="k"&&(U.preventDefault(),d(!0));}const je=pe||fe;return(/* @__PURE__ */n("section",{role:"editor-section",className:"flex grow flex-col justify-end",onKeyDown:De,children:[/* @__PURE__ */n("div",{className:"flex shrink-0 flex-col gap-1.5 px-4 pb-1 pt-3",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e("div",{className:W("min-w-0",u&&"flex-1"),children:/* @__PURE__ */e(Ht,{value:w.title,onSave:U=>Q({...w,title:U}),onEditingChange:p,isEditable:!0,placeholder:"Add title",displayClassName:"text-[17px] font-semibold leading-tight tracking-[-0.005em]",inputClassName:"text-[17px] font-semibold leading-tight tracking-[-0.005em]"})}),/* @__PURE__ */e(Tr,{card:w})]}),/* @__PURE__ */e(Ht,{value:(w.description||"").trim(),onSave:U=>Q({...w,description:U.trim()}),isEditable:!0,placeholder:"Add description",displayClassName:"text-[12px] leading-snug text-muted-foreground",inputClassName:"text-[12px] leading-snug"})]}),/* @__PURE__ */n(ft,{value:r,onValueChange:U=>o(U),className:"flex min-h-0 grow flex-col",children:[/* @__PURE__ */e(tu,{activeEditor:r,onExpand:()=>Re(r),trailing:/* @__PURE__ */n(be,{children:[C?/* @__PURE__ */e(eu,{hint:C}):null,r==="python"?/* @__PURE__ */e(nu,{}):null]})}),/* @__PURE__ */n("div",{className:"relative min-h-0 grow",children:[/* @__PURE__ */e(We,{value:"sql",forceMount:!0,className:"absolute inset-0 mt-0 data-[state=inactive]:hidden",children:/* @__PURE__ */e("div",{id:"sql-container",className:"relative h-full w-full overflow-hidden bg-background",children:f===null?/* @__PURE__ */e(On,{ref:S,className:Jn},`inline-sql-${w.id}`):null})}),/* @__PURE__ */e(We,{value:"python",forceMount:!0,className:"absolute inset-0 mt-0 data-[state=inactive]:hidden",children:/* @__PURE__ */e("div",{id:"python-container",className:"relative h-full w-full overflow-hidden bg-background",children:f===null?/* @__PURE__ */e(Mn,{ref:b,className:Jn},`inline-python-${w.id}`):null})}),/* @__PURE__ */n("div",{role:"editor-controls",className:"pointer-events-none absolute inset-x-4 bottom-3 z-10 flex items-end justify-end gap-2",children:[s?c?/* @__PURE__ */e("div",{className:"pointer-events-auto flex min-w-0 max-w-[560px] flex-1",children:/* @__PURE__ */e(Yd,{currentSql:w==null?void 0:w.sql,selectedDatabaseName:D,selectedSchemaName:B,selectedTableName:$,onApplySql:J,autoFocus:!0,onDismiss:()=>d(!1)})}):/* @__PURE__ */e(ue,{type:"button",variant:"outline",size:"xs",className:"pointer-events-auto h-7 shrink-0 bg-background px-2.5 text-[12px] font-normal text-muted-foreground hover:text-foreground",onClick:()=>d(!0),children:"Describe a query"}):null,/* @__PURE__ */e(ue,{type:"button",variant:"outline",size:"xs",className:"pointer-events-auto h-7 shrink-0 bg-background px-2.5 text-[12px] font-normal text-muted-foreground hover:text-foreground",title:"Clear the SQL, the Python step and the chart settings",onClick:()=>i(!0),children:"Clear"}),/* @__PURE__ */n(ue,{title:"Shift + Enter",disabled:je,onClick:ye,className:"pointer-events-auto shrink-0",size:"xs",children:[je?/* @__PURE__ */e(ea,{className:"h-3.5 w-3.5 animate-spin"}):/* @__PURE__ */e(Sr,{className:"h-3.5 w-3.5"}),"Run"]})]})]})]}),/* @__PURE__ */e(ru,{open:l,onOpenChange:i,onConfirm:v}),/* @__PURE__ */e(Xd,{activeEditor:f,isRunning:je,sqlEditor:/* @__PURE__ */e(On,{ref:y},`expanded-sql-${w.id}`),pythonEditor:/* @__PURE__ */e(Mn,{ref:R},`expanded-python-${w.id}`),onActiveEditorChange:Le,onOpenChange:Pe,onRun:ye})]}));}function Sn(){const t=T(r=>r.actions.setCardType),{columns:a,isLoading:s}=lo();return nt((r,o)=>{const c=t(r,{...o,catalog:a,catalogLoading:s});return c.status==="refused"?at.info("Fields are still loading",{description:"Try switching again in a moment."}):c.status==="changed"&&c.leftOut.length&&at.info("Some fields did not carry over to this visual",{description:c.leftOut.join(", ")}),c;},[t,a,s]);}const wa=[{value:"table",label:"Table"},{value:"detailTable",label:"Detail"}];function iu({className:t}){const a=T(m=>m.card),s=T(m=>m.frame),r=T(m=>m.editorContext),o=Ve(),{setCard:c,updateCardInFrame:d}=he(),l=(r==null?void 0:r.type)==="documentSection"&&!!r.lockedKind,i=(r==null?void 0:r.type)==="documentSection"?wa.filter(m=>m.value==="table"):wa,v=wa.some(m=>m.value===o),u=zt(a.config,a.type),p=Vs(a,s.cards);if(!v||!u||p||l||i.length<2)return/* @__PURE__ */e("div",{"aria-hidden":"true",className:W("invisible flex items-center gap-5",t),children:/* @__PURE__ */e("span",{className:"-mb-px flex h-9 items-center border-b-2 border-transparent text-[12px]",children:"Placeholder"})});const f=m=>{if(m===o||p)return;const N=m,w=a.config??{},S=Bs(o,N,w),b={...a,type:N,config:S};c(b),d(b);};return/* @__PURE__ */e("div",{role:"tablist",className:W("flex items-center gap-5",t),children:i.map(m=>{const N=o===m.value;return/* @__PURE__ */e("button",{type:"button",role:"tab","aria-selected":N,onClick:()=>f(m.value),className:W("-mb-px flex h-9 items-center border-b-2 text-[12px] transition-colors",N?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:m.label},m.value);})});}function us(t){const a=T(d=>d.card),s=T(d=>d.isDevMode),{switchEditorMode:r,setRunSql:o}=he(),c=()=>{const d=t||a.sql||a.python||"";r("dev",{sqlToLoad:d}),setTimeout(()=>{o(!0);},100);};return{isDevMode:s,handleOpenInEditor:!s&&Ja(a.type)?c:void 0};}function cu(){const{authToken:t,tokenProps:a}=qt(),{currentUser:s}=tn(),r=oo({mutationFn:async o=>{if(!(t!=null&&t.accessToken))throw new Error("No authentication token available");const d=`${a.apiServiceUrl||""}/v1/feedback`,l={...o,user:s,tokenContext:a},i=await Ks(d,t.accessToken,l,"POST");if(!i||!i.success)throw new Error((i==null?void 0:i.error)||"Failed to send feedback");return i;},onSuccess:o=>{at.success(`Feedback sent successfully! Issue: ${o.issueNumber}`,{duration:5e3});},onError:o=>{console.error("Feedback submission error:",o),at.error("Failed to send feedback. Please try again later.",{duration:5e3});}});return{sendFeedback:r.mutate,sendFeedbackAsync:r.mutateAsync,isLoading:r.isPending,isSuccess:r.isSuccess,isError:r.isError,error:r.error,data:r.data,reset:r.reset};}function du(t,a,s){return{category:t,userMessage:s,systemState:a,metadata:{url:window.location.href,userAgent:navigator.userAgent,timestamp:(/* @__PURE__ */new Date()).toISOString(),viewport:`${window.innerWidth}x${window.innerHeight}`}};}function uu({code:t,language:a,wrapLongLines:s=!1,className:r,ariaLabel:o}){const c=X(()=>Zi(t,a),[t,a]);return(/* @__PURE__ */e("div",{className:W("code-editor",r),children:/* @__PURE__ */e("pre",{"aria-label":o,className:W("w-full min-w-0 max-w-full bg-transparent px-3 py-2.5 font-mono text-[12px] leading-[1.55] [font-variant-numeric:tabular-nums]",s?"overflow-x-hidden whitespace-pre-wrap break-words":"overflow-x-auto whitespace-pre"),children:c===null?/* @__PURE__ */e("code",{className:"text-foreground",children:t}):/* @__PURE__ */e("code",{dangerouslySetInnerHTML:{__html:c}})})}));}function Tn({open:t,onOpenChange:a,feedbackData:s,onSuccess:r,showDebugInfo:o=!1}){var D,B,$,j,k,O;const[c,d]=Y(""),[l,i]=Y(!1),{sendFeedback:v,isLoading:u,isSuccess:p,isError:f,data:m,reset:N}=cu(),w=p?"Feedback Sent":"Report a Query Issue",S=p?"Your feedback was sent to the support team.":"Tell us what happened. We’ll include technical details to help support investigate.",b=()=>{const A={...s,userMessage:c.trim()||void 0};v(A,{onSuccess:()=>r==null?void 0:r()});},y=()=>{d(""),i(!1),N(),a(!1);},R=A=>{A||y();},x={category:s.category,error:{message:(D=s.systemState)==null?void 0:D.errorMessage,sql:(B=s.systemState)==null?void 0:B.generatedSql,errorSql:($=s.systemState)==null?void 0:$.errorSql},cardConfig:(j=s.systemState)==null?void 0:j.cardConfig,dataSource:(k=s.systemState)==null?void 0:k.dataSource,filters:(O=s.systemState)==null?void 0:O.dashboardFilters,metadata:s.metadata};return/* @__PURE__ */e(ta,{open:t,onOpenChange:R,children:/* @__PURE__ */n(aa,{"aria-busy":u,className:"max-h-[calc(100vh-2rem)] w-[calc(100%-2rem)] max-w-[520px] gap-0 overflow-y-auto overscroll-contain rounded-card border-border/60 p-0 sm:rounded-card [&>button]:right-3 [&>button]:top-3",children:[/* @__PURE__ */n(dn,{className:"flex h-10 flex-row items-center space-y-0 border-b border-border px-3 pr-10 text-left",children:[/* @__PURE__ */e(na,{className:"truncate text-[13px] font-medium",children:w}),p&&/* @__PURE__ */e(Vt,{className:"sr-only",children:S})]}),!p&&/* @__PURE__ */n(be,{children:[/* @__PURE__ */n("div",{className:"min-w-0 space-y-4 px-3 py-4",children:[/* @__PURE__ */e(Vt,{className:"text-[12px] leading-[1.5] text-muted-foreground",children:S}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n(L,{htmlFor:"feedback-message",className:"text-[12px] font-medium",children:["What Happened?"," ",/* @__PURE__ */e("span",{className:"font-normal text-muted-foreground",children:"(Optional)"})]}),/* @__PURE__ */e(io,{id:"feedback-message",name:"feedback-message",autoComplete:"off",placeholder:"Describe what you were doing when the issue occurred…",value:c,onChange:A=>d(A.target.value),size:"sm",className:"min-h-[112px] resize-none",disabled:u})]}),f&&/* @__PURE__ */n("div",{role:"alert",className:"flex items-start gap-2 text-[12px] leading-[1.5] text-destructive",children:[/* @__PURE__ */e(za,{"aria-hidden":"true",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),/* @__PURE__ */e("p",{children:"We couldn’t send your feedback. Check your connection and try again."})]}),o&&/* @__PURE__ */n(It,{open:l,onOpenChange:i,children:[/* @__PURE__ */n("div",{className:"flex items-center gap-1",children:[/* @__PURE__ */e(Et,{asChild:!0,children:/* @__PURE__ */n(ue,{type:"button",variant:"ghost",size:"xs",className:"flex flex-1 items-center justify-between p-2 hover:bg-muted",children:[/* @__PURE__ */e("span",{className:"text-[12px] font-medium",children:"View data to be sent"}),l?/* @__PURE__ */e(kt,{"aria-hidden":"true",className:"h-3.5 w-3.5"}):/* @__PURE__ */e(vt,{"aria-hidden":"true",className:"h-3.5 w-3.5"})]})}),/* @__PURE__ */e(qr,{text:JSON.stringify(x,null,2),className:"h-8 w-8 shrink-0"})]}),/* @__PURE__ */e(Ft,{className:"mt-2 min-w-0",children:/* @__PURE__ */e(pn,{className:"h-[300px] w-full rounded-card border bg-muted/50 p-4",children:/* @__PURE__ */e("div",{className:"min-w-0 max-w-full overflow-x-hidden text-xs",children:/* @__PURE__ */e(uu,{code:JSON.stringify(x,null,2),language:"json",wrapLongLines:!0})})})})]})]}),/* @__PURE__ */n(qa,{className:"gap-2 border-t border-border px-3 py-3 sm:space-x-0",children:[/* @__PURE__ */e(ue,{type:"button",variant:"outline",size:"xs",onClick:y,disabled:u,children:"Cancel"}),/* @__PURE__ */e(ue,{type:"button",size:"xs",onClick:b,disabled:u,"aria-busy":u,className:"min-w-[100px]",children:u?/* @__PURE__ */n(be,{children:[/* @__PURE__ */e(ea,{"aria-hidden":"true",className:"h-3.5 w-3.5 animate-spin motion-reduce:animate-none"}),"Sending…"]}):"Send Feedback"})]})]}),p&&/* @__PURE__ */n(be,{children:[/* @__PURE__ */n("div",{role:"status","aria-live":"polite",className:"flex items-start gap-3 px-3 py-4",children:[/* @__PURE__ */e(ec,{"aria-hidden":"true",className:"mt-0.5 h-5 w-5 shrink-0 text-emerald-500"}),/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */e("p",{className:"text-[13px] font-medium",children:"Thanks—your feedback was sent."}),/* @__PURE__ */n("p",{className:"mt-1 text-[12px] leading-[1.5] text-muted-foreground",children:["Issue number:"," ",/* @__PURE__ */e("span",{className:"font-mono font-medium tabular-nums text-foreground",children:m==null?void 0:m.issueNumber}),". Our support team will review the report."]})]})]}),/* @__PURE__ */e(qa,{className:"border-t border-border px-3 py-3",children:/* @__PURE__ */e(ue,{type:"button",size:"xs",onClick:y,children:"Close"})})]})]})});}var kn=/* @__PURE__ */(t=>(t.QUERY_GENERATION="query-generation",t))(kn||{});function ms(t,a){const[s,r]=Y(!1),o=T(u=>u.card),c=xe(u=>pr(u.dashboard)),{currentUser:d}=tn(),{tokenProps:l}=yn(fn),i=nt(()=>{r(!0);},[]),v=X(()=>{const u=typeof window<"u"?window.location.href:"",p=typeof navigator<"u"?navigator.userAgent:"",f=typeof window<"u"?`${window.innerWidth}x${window.innerHeight}`:"";return{category:kn.QUERY_GENERATION,user:d,tokenContext:l,systemState:{cardConfig:o.config,dataSource:o.dataSource,dashboardFilters:[...c],errorMessage:t||void 0,errorSql:a||o.sql||o.python,generatedSql:a||o.sql},metadata:{url:u,userAgent:p,timestamp:(/* @__PURE__ */new Date()).toISOString(),viewport:f}};},[d,l,o,c,t,a]);return{feedbackDialogOpen:s,setFeedbackDialogOpen:r,handleSendFeedback:i,feedbackPayload:v};}const mu="__editor_sql__",hu="__editor_python__";function pu(t){var s;const a=zs(t.python||"");return{sql:(s=t.sql)!=null&&s.trim()?mu:"",python:a.trim()?hu:""};}function hs({className:t,style:a,...s}){var Le,Pe,De,je,Je,ge;const r=T(oe=>oe.card),o=gn(),d=T(oe=>oe.isDevMode)?!1:((Le=r.customCardPreferences)==null?void 0:Le.showCardHeader)??!0,l=((De=(Pe=r.preferences)==null?void 0:Pe.displayOptions)==null?void 0:De.showInlineFilterBar)??!0,i=T(oe=>oe.frame),v=T(oe=>oe.inlineFilterValuesMap[r.id]),u=xe(oe=>oe.selectedSheetId),p=T(oe=>oe.actions.setRunSql),f=T(oe=>oe.actions.setCardInlineFilterValue),m=T(oe=>oe.actions.removeCardInlineFilterValue),N=nt(oe=>f(r.id,oe),[r.id,f]),w=nt(oe=>m(r.id,oe),[r.id,m]),S=qs(r,v,{savedFilters:l}).length>0,b=X(()=>dt(i,r),[i,r]),{manifest:y}=bt(((je=b==null?void 0:b.customCardPreferences)==null?void 0:je.url)||""),R=X(()=>{var oe;return(oe=y==null?void 0:y.visuals)==null?void 0:oe.find(Me=>{var U;return Me.name===((U=b==null?void 0:b.customCardPreferences)==null?void 0:U.componentName);});},[y,(Je=b==null?void 0:b.customCardPreferences)==null?void 0:Je.componentName]),x=ut(b,R),D=X(()=>Kt({frame:i,configCard:b,isMultiInputVisual:x==="multiple"}),[i,b,x]),B=X(()=>{const oe=D.findIndex(Me=>(Me==null?void 0:Me.id)===(r==null?void 0:r.id));return oe<0?-1:tt(r,oe);},[D,r]),$=X(()=>!b||x!=="multiple"||B<0?r.type:Nt(r,B,R==null?void 0:R.slots)??r.type,[b,x,B,r,R==null?void 0:R.slots]),j=$??r.type,k=X(()=>j===r.type?r:{...r,type:j},[r,j]),O=k.type==="table"||k.type==="matrixTable"||k.type==="detailTable",A=X(()=>$!==r.type?{...r,type:$}:r,[r,$]),{data:F,isLoading:K,isFetching:E,errorMessage:h,errorSql:I,pagination:g}=$e(A),C=ra(k,F),M=!!h,{handleOpenInEditor:z}=us(I||r.sql||r.python),{feedbackDialogOpen:_,setFeedbackDialogOpen:P,handleSendFeedback:V,feedbackPayload:G}=ms(h,I||r.sql||r.python),ee=X(()=>(F==null?void 0:F.records)||[],[F==null?void 0:F.records]),{setCard:ie,updateCardInFrame:Q}=he(),q=C.id,te=C.config,ce=C.interactionConfig,me=C.controls,le=C.controlBindings,pe=C.customCfg,fe=C.preferences,Ee=C.queryConfig,Ae=pu({sql:C.sql,python:C.python}),Ue=Ae.sql,de=Ae.python,Ce=F==null?void 0:F.records,Fe=X(()=>({id:q,type:j,config:te,interactionConfig:ce,preferences:fe,controls:me,controlBindings:le,sql:Ue,python:de}),[q,j,te,ce,fe,me,le,Ue,de]),ot=(oe,Me)=>{var Ie,Z;const U={...r,paginationConfig:{page:oe+1,pageSize:Me}};ie(U),Q(U),r.sql&&(Z=(Ie=r.preferences)==null?void 0:Ie.tablePrefs)!=null&&Z.enableDevModePagination&&p(!0);},qe=oe=>{var Ie,Z,Ne,rt,Qe;const Me=Er(oe,(Ie=r.config)==null?void 0:Ie.metricColumns,(Z=r.config)==null?void 0:Z.groupByColumns,(Ne=r.config)==null?void 0:Ne.detailColumns),U={...r,config:{...(r.config||{}),sortByColumns:Me}};ie(U),Q(U),r.sql&&(Qe=(rt=r.preferences)==null?void 0:rt.tablePrefs)!=null&&Qe.enableDevModePagination&&p(!0);},Ye=jr(Fe,Ce||void 0),Xe=xn(),J=X(()=>{var oe;return!q||!Ce?null:$r({chartTheme:Xe,card:Fe,data:Ce,cardType:j,queryConfig:Ee,customCfg:pe,preferences:fe,comparisonMetadata:(oe=F==null?void 0:F.metadata)==null?void 0:oe.comparisonMetadata,numericPresentation:Ye,resultColumns:F==null?void 0:F.columns,columnKeyMap:F==null?void 0:F.columnKeyMap});},[Fe,q,pe,fe,Ee,Ce,Xe,F==null?void 0:F.columns,F==null?void 0:F.columnKeyMap,(ge=F==null?void 0:F.metadata)==null?void 0:ge.comparisonMetadata,j,Ye]);function ye(oe){return/* @__PURE__ */e(sa,{FallbackComponent:rn,children:/* @__PURE__ */e(Ms,{card:oe})});}function Re(){var oe;if(C.type==="matrixTable")return/* @__PURE__ */e(xo,{card:C,frame:i,mode:"editor"});if(F!=null&&F.records&&(F==null?void 0:F.records.length)===0&&!K&&!E)return h?/* @__PURE__ */e("div",{className:"flex h-full flex-col items-start justify-start overflow-auto",children:/* @__PURE__ */e(an,{error:h,errorSql:I||r.sql||r.python,onOpenInEditor:z,onSendFeedback:V,showFeedbackButton:!0})}):/* @__PURE__ */e(bo,{fallback:/* @__PURE__ */n("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[/* @__PURE__ */e(vo,{className:"h-8 w-8 text-muted-foreground/40"}),/* @__PURE__ */e("p",{className:"text-[12px] text-muted-foreground",children:"No results to display"})]})});if((K||E)&&(!(F!=null&&F.records)||F.records.length===0))return j==="table"||j==="detailTable"?/* @__PURE__ */e("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:/* @__PURE__ */e(yo,{})}):/* @__PURE__ */e("div",{className:"z-50 flex h-full items-center justify-center",children:/* @__PURE__ */e(et,{size:"md",color:"muted","aria-label":"Loading data"})});if(!C.id)return null;if(j==="custom")return ye(r);if(!["table","matrixTable","detailTable","custom"].includes(j)&&J)return/* @__PURE__ */e("div",{className:"relative h-full min-h-0 w-full flex-1 grow basis-0",children:K||E?/* @__PURE__ */e(be,{}):/* @__PURE__ */e(No,{cfg:J})});if(j==="table"||j==="detailTable")return/* @__PURE__ */e("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:/* @__PURE__ */e(nn,{card:C,data:ee,resultColumns:F==null?void 0:F.columns,columnKeyMap:F==null?void 0:F.columnKeyMap,totalsByColumnId:F==null?void 0:F.tableTotalsByColumnId,columnTotals:F==null?void 0:F.tableColumnTotals,comparisonMetadata:(oe=F==null?void 0:F.metadata)==null?void 0:oe.comparisonMetadata,paginationMetadata:g,onPaginationChange:ot,onSortChange:qe,isLoading:K||E})});}return/* @__PURE__ */n(co,{role:"editor-visual-card",className:W("relative flex h-full flex-col rounded-none bg-card text-card-foreground",t),style:{...o.cardFrameStyle,...a},...s,children:[(K||E)&&!uo({type:j})&&(F==null?void 0:F.records)&&F.records.length>0&&/* @__PURE__ */e("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-background/50",children:/* @__PURE__ */e(et,{size:"md",color:"muted","aria-label":"Loading data"})}),d&&/* @__PURE__ */e(mo,{className:W("flex flex-row items-start justify-between gap-4 px-4 pb-3 pt-3"),style:o.cardGutterStyle,children:/* @__PURE__ */n("div",{className:"min-w-0 flex-1 space-y-1",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(ho,{className:W("min-w-0",fa),children:/* @__PURE__ */e(Ht,{value:r.title,onSave:oe=>ie({...r,title:oe}),isEditable:!0,placeholder:"Add title",displayClassName:fa,inputClassName:fa})}),/* @__PURE__ */e(Tr,{card:r}),/* @__PURE__ */e(as,{}),/* @__PURE__ */e("div",{className:"ml-auto",children:/* @__PURE__ */e(iu,{})})]}),/* @__PURE__ */e("div",{className:"min-w-0",children:/* @__PURE__ */e(Ht,{value:(r.description||"").trim(),onSave:oe=>ie({...r,description:oe.trim()}),isEditable:!0,placeholder:"Add description",displayClassName:"text-[12px] leading-snug text-muted-foreground",inputClassName:"text-[12px] leading-snug"})})]})}),/* @__PURE__ */n(po,{card:r,sheetId:u||"",inlineFilterValues:v,setInlineFilterValue:N,removeInlineFilterValue:w,children:[S&&/* @__PURE__ */e("div",{className:"px-4 pb-2",style:o.cardGutterStyle,children:/* @__PURE__ */e(fo,{card:r,sheetId:u||"",inlineFilterValues:v,setInlineFilterValue:N,removeInlineFilterValue:w,showSavedFilters:l})}),/* @__PURE__ */n(go,{className:W("flex min-h-0 grow flex-col",O?M?"px-4 pb-0 pt-2":"p-0 [&_.data-table-scroll-container]:border-0 [&_.data-table-scroll-container]:bg-transparent":M?"px-4 py-0":"px-4"),style:O&&!M?void 0:o.cardGutterStyle,children:[/* @__PURE__ */e("div",{className:"min-h-0 flex-1 grow basis-0",children:Re()}),kr(C)&&/* @__PURE__ */e("div",{className:W("pt-3",O&&"px-4"),children:/* @__PURE__ */e(Ir,{card:C,mode:"editor",records:F==null?void 0:F.records})})]})]}),/* @__PURE__ */e(Tn,{open:_,onOpenChange:P,feedbackData:G,showDebugInfo:!0})]});}function Zn(t){var a,s;return JSON.stringify({...t,data:{...t.data,datasets:(s=(a=t.data)==null?void 0:a.datasets)==null?void 0:s.map(r=>{const o={...r};return Object.keys(o).forEach(c=>{c.startsWith("semaphor")&&delete o[c];}),{...o,data:[]};})}},null,2);}const Sa=({language:t,value:a,onChange:s,readonly:r})=>/* @__PURE__ */e(_t,{className:"h-full w-full text-xs",language:t,value:a,onValueChange:s,readOnly:r,embedded:!0}),fu=()=>/* @__PURE__ */n(dn,{children:[/* @__PURE__ */e("div",{className:"flex items-center gap-2",children:/* @__PURE__ */e(na,{children:"Customize Card"})}),/* @__PURE__ */n(Vt,{children:["See the configuration options and documentation",/* @__PURE__ */e("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),gu=({customCode:t,cardCustomCfgString:a,mergedConfig:s,onConfigChange:r,onCodeChange:o})=>/* @__PURE__ */n(ft,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[/* @__PURE__ */n(gt,{variant:"underline",className:"justify-start gap-5",children:[/* @__PURE__ */e(Ke,{value:"final-config",className:"px-0",children:"Config"}),/* @__PURE__ */e(Ke,{value:"custom-config",className:"px-0",children:"Changes"}),/* @__PURE__ */e(Ke,{value:"custom-code",className:"px-0",children:"Custom Code"})]}),/* @__PURE__ */e(We,{value:"final-config",className:"mt-2 grow rounded border",children:/* @__PURE__ */e(Sa,{language:"json",value:s,onChange:r})}),/* @__PURE__ */e(We,{value:"custom-config",className:"mt-2 grow rounded border",children:/* @__PURE__ */e(Sa,{readonly:!0,language:"json",value:a,onChange:()=>{}})}),/* @__PURE__ */e(We,{value:"custom-code",className:"mt-2 grow rounded border",children:/* @__PURE__ */e(Sa,{language:"javascript",value:t,onChange:o})})]}),xu=({error:t,hasCardCustomConfig:a,onReset:s,onApply:r,onClose:o})=>/* @__PURE__ */n(qa,{className:"flex items-center",children:[/* @__PURE__ */e(L,{className:"mr-2 text-red-500",children:t}),/* @__PURE__ */e(ue,{disabled:!a,onClick:s,variant:"outline",children:"Reset"}),/* @__PURE__ */e(ue,{onClick:r,variant:"outline",children:"Apply"}),/* @__PURE__ */e(ue,{onClick:o,variant:"outline",children:"Close"})]});function bu({triggerVariant:t="icon",className:a,label:s="Customize Visual"}={}){const[r,o]=Y(!1),[c,d]=Y(""),[l,i]=Y(""),[v,u]=Y(""),[p,f]=Y(""),m=T(O=>O.card),N=Ve(),w=T(O=>O.card.customCfg),S=w?JSON.stringify(w,null,2):"",b=X(()=>N!==m.type?{...m,type:N}:m,[m,N]),{data:y}=$e(b),R=jr(ra(m,y),y==null?void 0:y.records),x=xn(),{setCardCustomCfg:D,setCustomVisualCode:B}=he(),$=()=>{var A,F,K;if(!((A=y==null?void 0:y.records)!=null&&A.length))return;const O=$r({chartTheme:x,card:m,data:y.records,cardType:m.type,queryConfig:m.queryConfig,preferences:m.preferences,comparisonMetadata:(F=y==null?void 0:y.metadata)==null?void 0:F.comparisonMetadata,numericPresentation:R,resultColumns:y==null?void 0:y.columns,columnKeyMap:y==null?void 0:y.columnKeyMap});if(O){d(Zn(O)),u(((K=m.preferences)==null?void 0:K.customVisualCode)||"");const E=ac(O,w);i(Zn(E));}},j=()=>{try{if(v&&B(v),l){const O=JSON.parse(l),A=xd(JSON.parse(c),O);D(A),f("");}}catch{f("Invalid JSON configuration");}},k=Object.keys(w||{}).length===0;return/* @__PURE__ */n(ta,{open:r,onOpenChange:o,children:[/* @__PURE__ */e(tc,{asChild:!0,children:t==="menu"?/* @__PURE__ */n(ue,{variant:"ghost",onClick:$,className:W("h-7 w-full justify-start gap-2 px-2 text-[13px] font-normal",k?"":"text-green-600 hover:text-green-700",a),children:[/* @__PURE__ */e(_n,{className:"h-3.5 w-3.5"}),/* @__PURE__ */e("span",{children:s})]}):/* @__PURE__ */e(_e,{tooltip:"Customize Visual",onClick:$,className:W(k?"":"text-green-600 hover:text-green-700",a),children:/* @__PURE__ */e(_n,{className:"h-4 w-4"})})}),/* @__PURE__ */n(aa,{className:"flex h-[600px] grow flex-col overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[/* @__PURE__ */e(fu,{}),/* @__PURE__ */n("div",{className:"flex grow gap-2",children:[/* @__PURE__ */e(sa,{FallbackComponent:rn,children:/* @__PURE__ */e(hs,{className:"w-1/2 rounded shadow-none"})}),/* @__PURE__ */e(gu,{customCode:v,cardCustomCfgString:S,mergedConfig:l,onConfigChange:O=>i(O??""),onCodeChange:O=>u(O??"")})]}),/* @__PURE__ */e(xu,{error:p,hasCardCustomConfig:!!w,onReset:()=>{i(c),D(null);},onApply:j,onClose:()=>o(!1)})]})]});}function vu(t){let a=0;for(let r=0;r<t.length;r++)a=t.charCodeAt(r)+((a<<5)-a);return`hsl(${Math.abs(a%360)}, 65%, 45%)`;}function yu(t){const a=t.trim().split(/\s+/);return a.length>1?(a[0][0]+a[1][0]).toUpperCase():t.slice(0,2).toUpperCase();}function ps({chartType:t,chartName:a,isCustom:s=!1,className:r="h-6 w-6"}){if(!s&&t)return Fr(t,r);const o=Co(a);if(o)return Ua.cloneElement(o,{className:r});const c=yu(a),d=vu(a);return/* @__PURE__ */e("div",{className:W("flex items-center justify-center rounded text-white font-semibold text-xs",r),style:{backgroundColor:d},children:c});}function er({chartType:t,chartName:a,isCustom:s=!1,pluginName:r,isSelected:o=!1,isActive:c=!1,onSelect:d,onHover:l}){return/* @__PURE__ */n("button",{type:"button",onClick:d,onMouseMove:l,"aria-pressed":o,title:r?`${a} · ${r}`:a,className:W("flex h-7 w-full min-w-0 items-center gap-2 rounded-[4px] px-2 text-left text-[12px] transition-colors",c&&"bg-muted"),children:[/* @__PURE__ */e(ps,{chartType:t,chartName:a,isCustom:s,className:W("h-3.5 w-3.5 shrink-0",s?"text-[7px]":o?"text-foreground":"text-muted-foreground")}),/* @__PURE__ */e("span",{className:W("truncate",o?"font-medium text-foreground":"text-foreground/80"),children:a}),o&&/* @__PURE__ */e(un,{className:"ml-auto h-3 w-3 shrink-0"})]});}const tr=[{id:"tables",label:"Tables"},{id:"other",label:"Single value and text"},{id:"comparison",label:"Comparison"},{id:"trend",label:"Trend"},{id:"part",label:"Part of a whole"},{id:"relationship",label:"Relationship"}],Nu=[{id:"table",name:"Table",group:"tables"},{id:"matrixTable",name:"Matrix Table",group:"tables"},{id:"bar",name:"Bar Chart",group:"comparison"},{id:"stackedBar",name:"Stacked Bar",group:"comparison"},{id:"combo",name:"Combo Chart",group:"comparison"},{id:"bullet",name:"Bullet Chart",group:"comparison"},{id:"tornado",name:"Tornado",group:"comparison"},{id:"range",name:"Range",group:"comparison"},{id:"line",name:"Line Chart",group:"trend"},{id:"area",name:"Area Chart",group:"trend"},{id:"stackedLine",name:"Stacked Line",group:"trend"},{id:"stackedArea",name:"Stacked Area",group:"trend"},{id:"pie",name:"Pie Chart",group:"part"},{id:"doughnut",name:"Doughnut",group:"part"},{id:"treemap",name:"Treemap",group:"part"},{id:"funnel",name:"Funnel",group:"part"},{id:"polarArea",name:"Polar Area",group:"part"},{id:"scatter",name:"Scatter",group:"relationship"},{id:"bubble",name:"Bubble",group:"relationship"},{id:"heatmap",name:"Heatmap",group:"relationship"},{id:"radar",name:"Radar",group:"relationship"},{id:"kpi",name:"KPI",group:"other"},{id:"text",name:"Text",group:"other"}],Ta=2;function fs(t){return Nu.filter(a=>js(a.id,t));}function Cu({selectedChart:t,onChartSelect:a,onClose:s}){var I;const[r,o]=Y(""),[c,d]=Y(0),l=Oe(null),{data:i=[],isLoading:v}=nc(),u=Sn(),{setCardPreferences:p}=T(g=>g.actions),f=T(g=>g.card),m=T(g=>g.isDevMode),N=t??f.type,w=N==="custom"?(I=f.customCardPreferences)==null?void 0:I.componentName:void 0,{setCardCustomCfg:S,setQueryConfig:b,replaceFrameCards:y,clearModeDrafts:R,initializeModeDrafts:x}=he(),D=X(()=>{const g=fs({isDevMode:m});if(!r)return g;const C=r.toLowerCase(),M=new Set(tr.filter(z=>z.label.toLowerCase().includes(C)).map(z=>z.id));return g.filter(z=>z.name.toLowerCase().includes(C)||M.has(z.group));},[m,r]),B=X(()=>{const g=i.filter(M=>M.componentType==="chart"&&M.pluginType!=="standard");if(!r)return g;const C=r.toLowerCase();return g.filter(M=>M.name.toLowerCase().includes(C));},[i,r]),$=g=>{u(g).status!=="refused"&&(a==null||a(g),s==null||s());},j=g=>{const C=$s(g);if(C==="multiple"&&g.slots&&g.slots.length>0){S(null),p({}),b(void 0),R();const z=Us(g.slots,g,f);y(z),z[0]&&x(z[0]),s==null||s();return;}else if(u("custom",{customVisual:{type:"component",visualType:C,url:g.url,componentName:g.name,icon:g.icon,pluginChartType:g.chartType,minInputs:g.minInputs,maxInputs:g.maxInputs}}).status==="refused")return;a==null||a("custom",g),s==null||s();},k=X(()=>{const g=tr.map(C=>({key:C.id,label:C.label,entries:D.filter(M=>M.group===C.id).map(M=>({kind:"default",id:M.id,name:M.name}))})).filter(C=>C.entries.length>0);return B.length===0?g:[...g,{key:"custom",label:"Custom charts",entries:B.map(C=>({kind:"custom",visual:C}))}];},[D,B]),O=X(()=>k.flatMap(g=>g.entries),[k]),A=Math.min(c,Math.max(O.length-1,0)),F=g=>{g.kind==="default"?$(g.id):j(g.visual);},K=g=>{var M,z;const C=Math.max(0,Math.min(g,O.length-1));d(C),(z=(M=l.current)==null?void 0:M.querySelector(`[data-index="${C}"]`))==null||z.scrollIntoView({block:"nearest"});},E=g=>{if(O.length===0)return;const C=g.key==="ArrowDown"?Ta:g.key==="ArrowUp"?-Ta:g.key==="ArrowRight"?1:g.key==="ArrowLeft"?-1:0;if(C!==0&&(Math.abs(C)===Ta||!r))g.preventDefault(),K(A+C);else if(g.key==="Enter"){g.preventDefault();const M=O[A];M&&F(M);}};let h=0;return/* @__PURE__ */n("div",{className:"flex flex-col",children:[/* @__PURE__ */n("div",{className:"flex h-9 items-center gap-2 border-b border-border px-3",children:[/* @__PURE__ */e(rc,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */e("input",{type:"text",placeholder:"Search charts",value:r,onChange:g=>{o(g.target.value),d(0);},onKeyDown:E,"aria-label":"Search charts",className:"h-full w-full bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),/* @__PURE__ */n("div",{ref:l,className:"max-h-[360px] overflow-y-auto px-1.5 pb-1.5",children:[k.map(g=>/* @__PURE__ */n("section",{className:"pt-2",children:[/* @__PURE__ */e("div",{className:"px-2 pb-0.5 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:g.label}),/* @__PURE__ */e("div",{className:"grid grid-cols-2 gap-x-0.5",children:g.entries.map(C=>{const M=h++,z=M===A;if(C.kind==="default")return/* @__PURE__ */e("div",{"data-index":M,children:/* @__PURE__ */e(er,{chartType:C.id,chartName:C.name,isSelected:N===C.id,isActive:z,onSelect:()=>F(C),onHover:()=>d(M)})},C.id);const{visual:_}=C;return/* @__PURE__ */e("div",{"data-index":M,children:/* @__PURE__ */e(er,{chartName:_.name,isCustom:!0,pluginName:_.pluginName,isSelected:w===_.name,isActive:z,onSelect:()=>F(C),onHover:()=>d(M)})},`${_.url}-${_.name}`);})})]},g.key)),v&&/* @__PURE__ */e("div",{className:"py-3 text-center text-[11px] text-muted-foreground",children:"Loading custom charts…"}),O.length===0&&!v&&/* @__PURE__ */e("div",{className:"py-8 text-center text-[11px] text-muted-foreground",children:"No charts found"})]})]});}const ka={table:Ur,matrixTable:Qt,bar:ln,line:sn,stackedBar:Po,stackedLine:Ao,scatter:Rr,bubble:Ro,pie:Mo,doughnut:Oo,kpi:Fo,treemap:Mr,bullet:Or,funnel:Eo,tornado:Io,heatmap:Qt,range:ko,radar:To,polarArea:So,text:wo},Ia={table:"Table",matrixTable:"Matrix Table",bar:"Bar Chart",line:"Line Chart",stackedBar:"Stacked Bar",stackedLine:"Stacked Line",scatter:"Scatter",bubble:"Bubble",pie:"Pie Chart",doughnut:"Donut",kpi:"KPI",treemap:"Treemap",bullet:"Bullet",funnel:"Funnel",tornado:"Tornado",heatmap:"Heatmap",range:"Range",radar:"Radar",polarArea:"Polar Area",text:"Text"},wu=[{id:"table"},{id:"bar"},{id:"line"},{id:"pie"},{id:"kpi"},{id:"matrixTable"}],Su=6;function Tu({selectedChart:t,onChartChange:a}){return/* @__PURE__ */n("div",{className:"px-4 pb-3 pt-4",children:[/* @__PURE__ */e("p",{className:"pb-1.5 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Chart type"}),/* @__PURE__ */e(Wa,{selectedChart:t,onChartChange:a,compactMore:!0})]});}function Wa({selectedChart:t,onChartChange:a,compactMore:s=!1,responsiveCompact:r=!1}){const[o,c]=Y(!1),d=T(m=>m.isDevMode),l=T(m=>{var N,w;return((w=(N=m.card)==null?void 0:N.customCardPreferences)==null?void 0:w.componentName)??null;}),i=X(()=>{const m=new Set(fs({isDevMode:d}).map(w=>w.id)),N=wu.filter(w=>m.has(w.id)).map(w=>({id:w.id,label:Ia[w.id]??w.id,icon:ka[w.id],isCustom:!1}));return t==="custom"&&l?N.unshift({id:l,label:l,isCustom:!0}):!N.some(w=>w.id===t)&&ka[t]&&m.has(t)&&N.unshift({id:t,label:Ia[t]??t,icon:ka[t],isCustom:!1}),N.slice(0,Su);},[t,l,d]),v=m=>m.isCustom?t==="custom"&&l===m.id:t===m.id,u=m=>{m.isCustom||a(m.id);},p=i.some(v),f=p?"More":t==="custom"?l||"Custom":Ia[t]||"More";return/* @__PURE__ */e("div",{className:"flex items-center",children:/* @__PURE__ */n("div",{className:"inline-flex h-7 items-center overflow-hidden rounded-control border border-input bg-background",children:[i.map(m=>{const N=m.icon,w=v(m);return/* @__PURE__ */n(mt,{children:[/* @__PURE__ */e(ht,{asChild:!0,children:/* @__PURE__ */n("button",{type:"button",onClick:()=>u(m),"aria-label":m.label,"aria-pressed":!!w,className:W("flex h-full w-7 items-center justify-center text-foreground/65 transition-colors hover:bg-muted/50 hover:text-foreground",r&&!w&&"hidden @[800px]:flex",w&&"bg-foreground/[0.08] font-medium text-foreground"),children:[N?/* @__PURE__ */e(N,{className:"h-3.5 w-3.5"}):/* @__PURE__ */e(ps,{chartName:m.label,isCustom:!0,className:"h-3.5 w-3.5"}),/* @__PURE__ */e("span",{className:"sr-only",children:m.label})]})}),/* @__PURE__ */e(pt,{side:"bottom",children:m.label})]},`${m.isCustom?"custom":"default"}-${m.id}`);}),/* @__PURE__ */n(st,{open:o,onOpenChange:c,children:[/* @__PURE__ */e(xt,{asChild:!0,children:/* @__PURE__ */n("button",{type:"button","aria-label":s?"More chart types":f,className:W("inline-flex h-full items-center gap-1 border-l border-input transition-colors hover:bg-muted/50",s?"w-7 justify-center":"px-2 text-[12px]",!s&&(p?"text-muted-foreground":"text-foreground")),children:[!s&&/* @__PURE__ */e("span",{className:"truncate",children:f}),/* @__PURE__ */e(kt,{className:W("h-3 w-3 shrink-0 text-muted-foreground transition-transform",o&&"rotate-180"),strokeWidth:1.75})]})}),/* @__PURE__ */e(lt,{className:"w-[360px] overflow-hidden p-0",align:"end",onOpenAutoFocus:m=>m.preventDefault(),children:/* @__PURE__ */e(Cu,{selectedChart:t,onChartSelect:m=>{a(m),c(!1);},onClose:()=>c(!1)})})]})]})});}function ku(){const t=T(i=>{var v,u;return(u=(v=i.card.preferences)==null?void 0:v.chartOptions)==null?void 0:u.indexAxis;}),a=T(i=>i.card.type),{setChartOrientation:s,setCardPreferences:r}=T(i=>i.actions),o=i=>{if(s(i),a!=="bullet")return;const v=i==="y"?"horizontal":"vertical",u=T.getState().card.preferences,p={...(u||{}),bulletConfig:{...((u==null?void 0:u.bulletConfig)||{}),orientation:v}};r(p);};function c(){const i=t??"x";return/* @__PURE__ */e(_e,{onClick:()=>{o(i==="x"?"y":"x");},tooltip:"Chart Orientation",className:"h-7 w-7 px-0",children:i==="x"?/* @__PURE__ */e(Na,{className:"h-3.5 w-3.5"}):/* @__PURE__ */e(ya,{className:"h-3.5 w-3.5"})});}function d(){return/* @__PURE__ */e(_e,{onClick:()=>{o(t==="y"||t===void 0?"x":"y");},tooltip:"Chart Orientation",className:"h-7 w-7 px-0",children:t==="y"||t===void 0?/* @__PURE__ */e(Na,{className:"h-3.5 w-3.5"}):/* @__PURE__ */e(ya,{className:"h-3.5 w-3.5"})});}function l(){const i=t??"y";return/* @__PURE__ */e(_e,{onClick:()=>{o(i==="y"?"x":"y");},tooltip:"Chart Orientation",className:"h-7 w-7 px-0",children:i==="y"?/* @__PURE__ */e(ya,{className:"h-3.5 w-3.5"}):/* @__PURE__ */e(Na,{className:"h-3.5 w-3.5"})});}return/* @__PURE__ */e(be,{children:a==="funnel"?d():a==="bullet"?l():c()});}function In({className:t,triggerVariant:a="icon",label:s="Display options"}){var S,b,y,R,x,D,B,$,j,k;const r=T(O=>O.card),{setCardPreferences:o,updateCardInFrame:c,setCard:d}=he(),[l,i]=Y(!1),v=((b=(S=r.preferences)==null?void 0:S.displayOptions)==null?void 0:b.showFilterInfo)??!0,u=((R=(y=r.preferences)==null?void 0:y.displayOptions)==null?void 0:R.showCardToolbar)??!0,p=((D=(x=r.preferences)==null?void 0:x.displayOptions)==null?void 0:D.showChrome)??!0,f=(($=(B=r.preferences)==null?void 0:B.displayOptions)==null?void 0:$.allowScroll)??!0,m=((k=(j=r.preferences)==null?void 0:j.displayOptions)==null?void 0:k.showInlineFilterBar)??!0,N=(O,A)=>{var E;const F={...r.preferences,displayOptions:{...((E=r.preferences)==null?void 0:E.displayOptions),[O]:A}};o(F);const K={...r,preferences:F};d(K),c(K);},w=[{option:"showFilterInfo",label:"Filter info",hint:"Badge",checked:v},{option:"showCardToolbar",label:"Card tools",hint:"Expand, hover actions",checked:u},{option:"showChrome",label:"Card chrome",hint:"Frame and padding",checked:p},{option:"allowScroll",label:"Allow scroll",hint:"Content scroll",checked:f},{option:"showInlineFilterBar",label:"Inline filter bar",hint:"On-card filters",checked:m}];return/* @__PURE__ */e("div",{className:W("flex items-center",t),children:/* @__PURE__ */n(la,{modal:!1,open:l,onOpenChange:i,children:[/* @__PURE__ */e(oa,{asChild:!0,children:a==="menu"?/* @__PURE__ */n(ue,{variant:"ghost",className:"h-auto w-full justify-start gap-2 rounded-sm px-2 py-1.5 text-[13px] font-normal",children:[/* @__PURE__ */e(ja,{className:"h-3.5 w-3.5 text-muted-foreground"}),/* @__PURE__ */e("span",{children:s})]}):/* @__PURE__ */e(_e,{className:"h-7 w-7 p-0",tooltip:"Display Options",children:/* @__PURE__ */e(Gt,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(ia,{align:"end",className:"w-64",children:[/* @__PURE__ */e("p",{className:"px-2 pb-1.5 pt-1 text-[11px] text-muted-foreground",children:"Changes apply to dashboard view only"}),w.map(O=>/* @__PURE__ */n(sc,{checked:O.checked,onCheckedChange:A=>N(O.option,A),onSelect:A=>A.preventDefault(),className:"[&_svg]:h-3.5 [&_svg]:w-3.5",children:[/* @__PURE__ */e("span",{className:"min-w-0 flex-1 truncate",children:O.label}),/* @__PURE__ */e("span",{className:"ml-3 shrink-0 text-[11px] text-muted-foreground",children:O.hint})]},O.option))]})]})});}function En({className:t,triggerVariant:a="icon",label:s="Pinned filters"}){const[r,o]=Y(!1),c=T(k=>k.card),d=T(k=>k.selectedConnectionId),{tokenProps:l}=qt(),{setCard:i}=he(),v=xe(k=>k.actions.removeCardInlineFilterValue),u=xe(k=>k.actions.setCardInlineFilterValue),p=T(k=>k.actions.removeCardInlineFilterValue),f=T(k=>k.actions.setCardInlineFilterValue),m=lc(),N=(c==null?void 0:c.inlineFilters)||[],w=Ua.useMemo(()=>c?[c]:[],[c]),{inlineCalculatedFields:S}=Ar(),b=Ua.useMemo(()=>({fields:S.filter(k=>k.fieldScope==="card"),domainId:Hs(c==null?void 0:c.dataSource)}),[S,c==null?void 0:c.dataSource]),y=bn()??void 0,R=Do(Vn(Vo,{activationConstraint:{distance:5}}),Vn(_o,{coordinateGetter:Lo}));function x({active:k,over:O}){if(!O||k.id===O.id)return;const A=N.findIndex(K=>K.id===O.id);if(A===-1)return;const F=Fd(N,String(k.id),A);F!==N&&i({...c,inlineFilters:[...F]});}function D(k){if(N.find(F=>Qs(F,k)))return;const A=Ed({id:La(),field:k,...Gs(c??{},d)});i({...c,inlineFilters:[...N,A]});}function B(k){const O=N.filter(A=>A.id!==k);i({...c,inlineFilters:O}),m?p(c.id,k):v(c.id,k);}function $(k,O){const A=N.find(h=>h.id===k),F=N.map(h=>h.id===k?{...h,...O}:h);i({...c,inlineFilters:F});const K=F.find(h=>h.id===k);if(!K||!Ws(A,K))return;const E=Ys(K,y);E?m?f(c.id,E):u(c.id,E):m?p(c.id,k):v(c.id,k);}if(!Id(c==null?void 0:c.type))return null;const j=a==="menu";return/* @__PURE__ */e("div",{className:W("flex items-center gap-1",j&&"w-full",t),children:/* @__PURE__ */n(st,{open:r,onOpenChange:o,children:[/* @__PURE__ */e(xt,{asChild:!0,children:j?/* @__PURE__ */n(ue,{variant:"ghost",className:"h-auto w-full justify-start gap-2 rounded-sm px-2 py-1.5 text-[13px] font-normal",children:[/* @__PURE__ */e(zn,{className:"h-3.5 w-3.5 text-muted-foreground"}),/* @__PURE__ */e("span",{children:s}),N.length>0&&/* @__PURE__ */e("span",{className:"ml-auto text-[11px] tabular-nums text-muted-foreground",children:N.length})]}):/* @__PURE__ */n(_e,{tooltip:"Pin a filter",className:W("relative h-7 w-7 px-0",{"text-primary":N.length>0}),children:[/* @__PURE__ */e(zn,{className:"h-3.5 w-3.5"}),N.length>0&&/* @__PURE__ */e("span",{className:"absolute -right-1 -top-1 flex h-4 w-4 items-center justify-center rounded-full bg-primary text-[10px] font-medium text-primary-foreground",children:N.length})]})}),/* @__PURE__ */e(lt,{align:"end",className:W("w-80 p-0",j&&"z-[60]"),children:/* @__PURE__ */n("div",{className:"flex flex-col",children:[/* @__PURE__ */n("div",{className:"border-b px-4 py-3",children:[/* @__PURE__ */e("h4",{className:"text-sm font-medium",children:"Pinned filters"}),/* @__PURE__ */e("p",{className:"text-xs text-muted-foreground",children:"Pick a field to pin a filter on the card."})]}),/* @__PURE__ */e("div",{className:"flex h-[320px] min-h-0 flex-col overflow-hidden",children:/* @__PURE__ */e(Bo,{cards:w,context:"inline-filter",onFieldSelect:D,inlineFilters:N,cardCalculated:b})}),N.length>0&&/* @__PURE__ */n("div",{className:"border-t px-4 py-3",children:[/* @__PURE__ */e("p",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"Pinned, in the order the card shows them"}),/* @__PURE__ */e(Ko,{sensors:R,collisionDetection:zo,onDragEnd:x,children:/* @__PURE__ */e(qo,{items:N.map(k=>k.id),strategy:jo,children:/* @__PURE__ */e("div",{className:"space-y-1",children:N.map(k=>/* @__PURE__ */e(Iu,{filter:k,onUpdate:O=>$(k.id,O),onRemove:()=>B(k.id)},k.id))})})})]})]})})]})});}function Iu({filter:t,onUpdate:a,onRemove:s}){const{attributes:r,listeners:o,setNodeRef:c,transform:d,transition:l,isDragging:i}=$o({id:t.id});return/* @__PURE__ */n("div",{ref:c,style:{transform:Uo.Transform.toString(d),transition:l},className:W("flex items-center justify-between gap-1 rounded-md bg-muted px-1 py-1.5 text-sm",i&&"relative z-10 shadow-sm"),children:[/* @__PURE__ */e("button",{type:"button","aria-label":`Move ${t.title}`,className:"flex h-5 w-4 shrink-0 cursor-grab items-center justify-center text-muted-foreground hover:text-foreground active:cursor-grabbing",...r,...o,children:/* @__PURE__ */e(cn,{className:"h-3 w-3"})}),/* @__PURE__ */e("span",{className:"min-w-0 flex-1 truncate",title:t.column,children:t.title}),/* @__PURE__ */n("div",{className:"flex items-center gap-0.5",children:[/* @__PURE__ */e(oc,{filter:t,variant:"inline",onAccept:v=>a(v),trigger:/* @__PURE__ */e(ue,{variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0",title:"Configure filter",children:/* @__PURE__ */e(ca,{className:"h-3 w-3"})})}),/* @__PURE__ */e(ue,{variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0 hover:bg-destructive/10 hover:text-destructive",onClick:s,children:/* @__PURE__ */e(Zt,{className:"h-3 w-3"})})]})]});}const Eu={metric_selector:"Displayed metric",field_selector:"Group by field",aggregation_selector:"Aggregation",grain_selector:"Time grain"};function Fu(t,a){return t&&typeof t=="object"&&"label"in t&&typeof t.label=="string"&&t.label.trim().length>0?t.label:a||null;}const Ou={metric_selector:"config_metric_selector",field_selector:"config_field_selector",aggregation_selector:"config_aggregation",grain_selector:"config_grain"};function Wt(t,a){return`${t}:${a}`;}function Mu(t,a,s,r,o){const c=new Set(s.filter(l=>l.target!=="sql_param"&&l.target!=="presentation_currency").map(l=>Wt(l.controlId,l.target))),d=a.map(l=>{const i=fr({card:t,control:l,matrixSpec:r,resolveDataType:o}).map(f=>f.value),v=Ou[l.type],p=[...(v&&i.includes(v)?[v]:[]),...i.filter(f=>f!==v)].find(f=>!c.has(Wt(l.id,f)));return p?{controlId:l.id,target:p}:null;}).find(Boolean);return d?{controlId:d.controlId,target:d.target,mapping:{}}:null;}function Ru({card:t,dashboardControls:a,bindings:s,onChange:r,availableFieldChoices:o,matrixFieldCatalog:c=[],availableMetricChoices:d,suppressTransientStaleState:l=!1,matrixSpec:i,matrixPresentation:v}){const u=X(()=>v??(i?ed(i).presentation:void 0),[i,v]);function p(k){return!i||!u?[]:Zs(i,k,S).map(O=>({id:O.id,label:O.kind==="measure"?`${td(O.measure,u)} (${O.measure.aggregate})`:`${O.axis==="rows"?"Rows":"Columns"}: ${ad(O.level,u)}`}));}const f=[...a,...(t.controls||[])],[m,N]=Y({}),w=bd({sql:t.sql,controlBindings:t.controlBindings});function S(k){return i?el(k,i.source,c):k.dataType;}const b=Xs(t,i,S),y=new Set(s.map(k=>Wt(k.controlId,k.target))),R=f.some(k=>fr({card:t,control:k,matrixSpec:i,resolveDataType:S}).some(O=>!y.has(Wt(k.id,O.value)))),x=l?0:s.reduce((k,O)=>{const A=D(O.target),F=Object.values(O.mapping).filter(K=>{const E=O.target==="config_metric_selector"||O.target==="config_field_selector"?typeof K=="string"?K:K==null?void 0:K.id:typeof K=="string"?K:void 0;return typeof E=="string"&&!A.some(h=>h.value===E);}).length;return k+F;},0);function D(k){var O,A,F,K;switch(k){case"config_metric_selector":return d?d.filter(E=>!!E.target).map(E=>({value:E.target.id,label:E.target.label||E.option.label,target:E.target})):i&&u?p(k).map(E=>({value:E.id,label:E.label,target:{kind:"matrix_instance",id:E.id}})):((A=(O=t.config)==null?void 0:O.metricColumns)==null?void 0:A.map(E=>({value:E.id,label:E.label||E.id,target:E})))||[];case"config_field_selector":return o?o.filter(E=>!!E.target).map(E=>({value:E.target.id,label:E.target.label||E.option.label,target:E.target})):i&&u?p(k).map(E=>({value:E.id,label:E.label,target:{kind:"matrix_instance",id:E.id}})):((K=(F=t.config)==null?void 0:F.groupByColumns)==null?void 0:K.map(E=>({value:E.id,label:E.label||E.id,target:E})))||[];case"config_aggregation":return(b.config_aggregation||[]).map(E=>({value:E,label:E}));case"config_grain":return(b.config_grain||[]).map(E=>({value:E,label:E.charAt(0).toUpperCase()+E.slice(1)}));default:return[];}}const B=(k,O)=>{r(s.map((A,F)=>F!==k?A:O(A)));},$=k=>{r(s.filter((O,A)=>A!==k));},j=()=>{const k=Mu(t,f,s,i,S);k&&r([...s,k]);};if(typeof t.sql=="string"&&t.sql.trim().length>0){const k=w.map(({controlId:O,paramId:A})=>{const F=f.find(K=>K.id===O);return F?{id:O,paramId:A,label:F.label,reference:`[[param.${A}]]`}:{id:O,paramId:A,label:O,reference:`[[param.${A}]]`};});return/* @__PURE__ */e("div",{className:"space-y-2",children:k.length===0?/* @__PURE__ */e("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:"This card is currently using raw SQL. Reference a control directly in the SQL editor with syntax like `[[param.metric]]`."}):k.map(O=>/* @__PURE__ */e("div",{className:"rounded-md border p-3",children:/* @__PURE__ */n("div",{className:"flex items-start justify-between gap-3",children:[/* @__PURE__ */n("div",{children:[/* @__PURE__ */e("div",{className:"text-sm font-medium",children:O.label}),/* @__PURE__ */e("p",{className:"text-xs text-muted-foreground",children:"Referenced in SQL"})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2 rounded-md bg-muted/40 px-2 py-1",children:[/* @__PURE__ */e("code",{className:"text-xs",children:O.reference}),/* @__PURE__ */e(qr,{text:O.reference,ariaLabel:`Copy ${O.reference}`})]})]})},`${O.id}:${O.paramId}`))});}return/* @__PURE__ */n("div",{className:"space-y-4",children:[x>0?/* @__PURE__ */n("div",{className:"flex items-start gap-2 rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950",children:[/* @__PURE__ */e(za,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),/* @__PURE__ */n("span",{children:[x," ",x===1?"mapping needs":"mappings need"," attention before save. Replace each missing target or choose Not mapped."]})]}):null,s.length===0?/* @__PURE__ */e("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:"This card is not using any controls yet."}):s.map((k,O)=>{const A=b[k.target]||[],F=f.find(V=>V.id===k.controlId),K=F?Js(F):null,E=(K==null?void 0:K.source.kind)==="manual"?K.source.options:[],h=D(k.target),I=p(k.target),g=k.matrixTargetId!==void 0&&!I.some(V=>V.id===k.matrixTargetId),C=Array.from(/* @__PURE__ */new Set([...E.map(V=>V.value),...Object.keys(k.mapping)])).map(V=>{const G=E.find(ee=>ee.value===V);return{value:V,label:(G==null?void 0:G.label)||V};}),M=`${k.controlId}-${k.target}-${O}`,z=m[M]??O===0,_=Object.keys(k.mapping).length,P=F!=null&&F.type?Eu[F.type]||F.type:null;return/* @__PURE__ */n(It,{open:z,onOpenChange:V=>N(G=>({...G,[M]:V})),className:"rounded-md border",children:[/* @__PURE__ */n("div",{className:"flex items-start justify-between gap-2 p-3",children:[/* @__PURE__ */e(Et,{asChild:!0,children:/* @__PURE__ */n("button",{type:"button",className:"flex min-w-0 flex-1 items-start gap-2 text-left",children:[z?/* @__PURE__ */e(kt,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}):/* @__PURE__ */e(vt,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-2",children:[/* @__PURE__ */e("div",{className:"truncate text-sm font-medium",children:(F==null?void 0:F.label)||"Control"}),P?/* @__PURE__ */e(Hr,{variant:"secondary",className:"shrink-0 text-[11px] font-normal text-muted-foreground",children:P}):null]}),/* @__PURE__ */e("div",{className:"text-xs text-muted-foreground",children:_>0?`${_} mapped`:"No mappings yet"})]})]})}),/* @__PURE__ */e(ue,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>$(O),children:/* @__PURE__ */e(Qr,{className:"h-4 w-4"})})]}),/* @__PURE__ */n(Ft,{className:"space-y-3 border-t px-3 pb-3 pt-2",children:[i?/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(L,{className:"text-xs",htmlFor:`matrix-target-${M}`,children:"Matrix target"}),/* @__PURE__ */n(ae,{value:k.matrixTargetId??"__none__",onValueChange:V=>B(O,G=>{const{matrixTargetId:ee,...ie}=G;return V==="__none__"?ie:{...ie,matrixTargetId:V};}),children:[/* @__PURE__ */e(ne,{id:`matrix-target-${M}`,"aria-label":"Matrix target",children:/* @__PURE__ */e(re,{placeholder:"Choose target"})}),/* @__PURE__ */n(se,{children:[/* @__PURE__ */e(H,{value:"__none__",children:I.length===1?`Automatic: ${I[0].label}`:"Choose target"}),g?/* @__PURE__ */e(H,{value:k.matrixTargetId,disabled:!0,children:"Missing target"}):null,I.map(V=>/* @__PURE__ */e(H,{value:V.id,children:V.label},V.id))]})]}),g?/* @__PURE__ */e("p",{role:"alert",className:"text-xs text-amber-700",children:"The saved Matrix target is no longer available."}):I.length===0?/* @__PURE__ */e("p",{role:"alert",className:"text-xs text-muted-foreground",children:"No eligible Matrix target."}):!k.matrixTargetId&&I.length>1?/* @__PURE__ */e("p",{role:"alert",className:"text-xs text-amber-700",children:"Select a Matrix target."}):null]}):null,C.length===0?/* @__PURE__ */e("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:"Add choices to this control first so you can decide what each choice changes in the card."}):h.length===0?/* @__PURE__ */e("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:"No matching targets are available for this binding yet."}):/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Map each choice"}),/* @__PURE__ */e("div",{className:"space-y-2",children:C.map(V=>{const G=k.mapping[V.value],ee=k.target==="config_metric_selector"||k.target==="config_field_selector"?typeof G=="string"?G:G==null?void 0:G.id:typeof G=="string"?G:void 0,ie=!l&&typeof ee=="string"&&!h.some(te=>te.value===ee),Q=Fu(G,ee),q=ee&&ie?[...h,{value:ee,label:"Needs remap",target:G}]:h;return/* @__PURE__ */n("div",{className:"grid gap-2 rounded-md border p-2 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(L,{className:"text-[11px] text-muted-foreground",children:"Viewer picks"}),/* @__PURE__ */e("div",{className:"rounded-md bg-muted/50 px-3 py-2 text-sm",children:V.label})]}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(L,{className:"text-[11px] text-muted-foreground",children:"Switch to"}),/* @__PURE__ */n(ae,{value:ee||"__none__",onValueChange:te=>B(O,ce=>{if(ce.target==="config_metric_selector"){const le={...ce.mapping};if(te==="__none__")delete le[V.value];else{const pe=q.find(fe=>fe.value===te);pe!=null&&pe.target?le[V.value]=pe.target:delete le[V.value];}return{...ce,mapping:le};}if(ce.target==="config_field_selector"){const le={...ce.mapping};if(te==="__none__")delete le[V.value];else{const pe=q.find(fe=>fe.value===te);pe!=null&&pe.target?le[V.value]=pe.target:delete le[V.value];}return{...ce,mapping:le};}const me={...ce.mapping};return te==="__none__"?delete me[V.value]:me[V.value]=te,{...ce,mapping:me};}),children:[/* @__PURE__ */e(ne,{children:/* @__PURE__ */e(re,{placeholder:"Choose what this should use"})}),/* @__PURE__ */n(se,{children:[/* @__PURE__ */e(H,{value:"__none__",children:"Not mapped"}),q.map(te=>/* @__PURE__ */e(H,{value:te.value,children:te.label},te.value))]})]}),ie?/* @__PURE__ */n("div",{className:"flex items-center gap-1.5 text-[11px] text-amber-700",children:[/* @__PURE__ */e(za,{className:"h-3 w-3 shrink-0"}),/* @__PURE__ */n("span",{children:["Needs remap",Q?` · Previously: ${Q}`:""]})]}):null]})]},`${k.controlId}-${k.target}-${V.value}`);})}),A.length>0&&/* @__PURE__ */n("p",{className:"text-[11px] text-muted-foreground",children:["Available choices for this card: ",A.join(", ")]})]})]})]},M);}),R?/* @__PURE__ */n(ue,{type:"button",variant:"outline",size:"sm",onClick:j,children:[/* @__PURE__ */e(da,{className:"mr-2 h-4 w-4"}),"Add another control response"]}):null]});}function Au(t,a,s){const{eligibleTargets:r}=ns(t,a,s),o=Nd(t),c=new Map(o.map(l=>[l.id,l])),d=new Map(Cd(t,s).map(l=>[l.measureId,l.label]));return r.map(l=>{var i;return{key:rs(l),label:l.kind==="metric"?((i=c.get(l.metricId))==null?void 0:i.label)||l.metricId:l.kind==="column"?l.columnKey:d.get(l.measureId)||l.measureId,target:l};});}function Pu(t){return t?t.kind==="metric"?t.metricId:t.kind==="column"?t.columnKey:t.measureId:"invalid target";}function Du({matrixCatalog:t,card:a,dashboardControls:s,resultColumnKeys:r=[],bindings:o,onChange:c}){const d=[...s,...(a.controls||[])],l=d.filter(vd),i=X(()=>Au(a,r,t),[a,r,t]),v=X(()=>ns(a,r,t),[a,r,t]),u=yd({bindings:o,controls:d,...v}),{preferences:p,resolveBoundCurrency:f}=ic(a,r,t),[m,N]=Y(""),[w,S]=Y(""),b=i.find(x=>x.key===w),y=!!(m&&b)&&!o.some(x=>x.presentationTarget&&b&&rs(x.presentationTarget)===b.key),R=x=>{if(!p)return;const D=cd({card:a,target:x,resultColumnKeys:r,valueFormatPreferences:p,boundCurrency:f(x),matrixCatalog:t});if(D)return nd(1e3,D);};return l.length===0&&o.length===0?/* @__PURE__ */e("p",{className:"text-xs text-muted-foreground",children:"Add a manual enum whose options are ISO currency codes to enable presentation currency bindings."}):/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e("h5",{className:"text-xs font-medium",children:"Currency presentation"}),/* @__PURE__ */e("p",{className:"text-xs text-muted-foreground",children:"Change only the display currency for an explicit metric or column."})]}),o.map((x,D)=>/* @__PURE__ */n("div",{className:"flex items-center gap-2 rounded-control border border-border/60 px-2 py-1.5 text-xs",children:[/* @__PURE__ */n("span",{className:"min-w-0 flex-1 truncate",children:[x.controlId," →"," ",Pu(x.presentationTarget),x.presentationTarget?` · ${R(x.presentationTarget)??"unavailable"}`:null]}),/* @__PURE__ */e(ue,{variant:"ghost",size:"xs",onClick:()=>c(o.filter((B,$)=>$!==D)),children:/* @__PURE__ */e(Qr,{className:"h-3.5 w-3.5"})})]},`${x.controlId}:${JSON.stringify(x.presentationTarget)}`)),u.length>0?/* @__PURE__ */e("div",{className:"space-y-1 text-xs text-destructive",children:u.map((x,D)=>/* @__PURE__ */n("p",{children:[x.controlId?`${x.controlId}: `:"",x.code.split("_").join(" ")]},`${x.controlId||"binding"}:${x.code}:${D}`))}):null,/* @__PURE__ */n("div",{className:"grid grid-cols-[1fr_1fr_auto] gap-2",children:[/* @__PURE__ */n(ae,{value:m,onValueChange:N,children:[/* @__PURE__ */e(ne,{size:"xs",children:/* @__PURE__ */e(re,{placeholder:"Currency control"})}),/* @__PURE__ */e(se,{children:l.map(x=>/* @__PURE__ */e(H,{value:x.id,children:x.label},x.id))})]}),/* @__PURE__ */n(ae,{value:w,onValueChange:S,children:[/* @__PURE__ */e(ne,{size:"xs",children:/* @__PURE__ */e(re,{placeholder:"Target"})}),/* @__PURE__ */e(se,{children:i.map(x=>/* @__PURE__ */e(H,{value:x.key,children:x.label},x.key))})]}),/* @__PURE__ */e(ue,{variant:"outline",size:"xs",disabled:!y,onClick:()=>{b&&(c([...o,{controlId:m,target:"presentation_currency",presentationTarget:b.target}]),S(""));},children:/* @__PURE__ */e(da,{className:"h-3.5 w-3.5"})})]})]});}const Lu=[];function Fn({className:t,triggerVariant:a="icon",label:s="Controls"}){var M,z,_;const{handleOpenChange:r,preventPassiveDismissDuringCreate:o,resolvedOpen:c,setIsCreateFlowActive:d}=ld({}),l=T(P=>P.card),i=T(P=>P.frame),v=T(P=>P.queryResultColumns),u=xe(P=>P.dashboard),f=xe(P=>P.dashboard.controls)||Lu,{setCard:m,updateCardInFrame:N}=he(),[w,S]=Y(null);ve(()=>{c&&!w&&l!=null&&l.id&&S(l.id);},[l==null?void 0:l.id,c,w]),ve(()=>{!c&&w!==null&&S(null);},[c,w]);const b=X(()=>w?(i==null?void 0:i.cards.find(P=>P.id===w))||((l==null?void 0:l.id)===w?l:void 0):l,[l,i==null?void 0:i.cards,w]),y=(b==null?void 0:b.type)==="matrixTable"?(M=b.config)==null?void 0:M.matrix:void 0,R=X(()=>c&&y?wd(y.spec,b==null?void 0:b.controlBindings):[],[c,y,b==null?void 0:b.controlBindings]),x=Ho(R),D=X(()=>x.catalog.map(P=>({...P.field,dataType:Ql(P.resolvedField.dataType)})),[x.catalog]),B=(b==null?void 0:b.controls)||[],$=b?tl(u,{excludeCardId:b.id}):f.map(P=>P.id),j=((b==null?void 0:b.controlBindings)||[]).filter(al),k=((b==null?void 0:b.controlBindings)||[]).filter(pa),O=Qo({card:b,controls:B}),A={choices:nl(b),targetMap:Object.fromEntries((((z=b==null?void 0:b.config)==null?void 0:z.groupByColumns)||[]).map(P=>[P.id,P]))},F={choices:rl(b),targetMap:Object.fromEntries((((_=b==null?void 0:b.config)==null?void 0:_.metricColumns)||[]).map(P=>[P.id,P]))},K=A.choices.map(P=>({option:P,target:A.targetMap[P.value]})),E=F.choices.map(P=>({option:P,target:F.targetMap[P.value]})),h=(P,V)=>{if(!b)return;const G=(V==null?void 0:V.type)==="rename"?qn(b,{type:"rename",oldId:V.oldId,newId:V.newId}):(V==null?void 0:V.type)==="remove"?qn(b,{type:"remove",controlId:V.controlId}):b,ee={...G,controls:P,controlBindings:sl(G.controlBindings,P)};N(ee),(l==null?void 0:l.id)===ee.id&&m(ee);},I=P=>{if(!b)return;const V={...b,controlBindings:[...ll(P,(b.controlBindings||[]).filter(G=>!pa(G))),...k]};N(V),(l==null?void 0:l.id)===V.id&&m(V);},g=P=>{if(!b)return;const V={...b,controlBindings:[...(b.controlBindings||[]).filter(G=>!pa(G)),...P]};N(V),(l==null?void 0:l.id)===V.id&&m(V);},C=a==="menu";return/* @__PURE__ */e("div",{className:W("flex items-center gap-1",C&&"w-full",t),children:/* @__PURE__ */n(st,{modal:!0,open:c,onOpenChange:r,children:[/* @__PURE__ */e(xt,{asChild:!0,children:C?/* @__PURE__ */n(ue,{variant:"ghost",className:"h-auto w-full justify-start gap-2 rounded-sm px-2 py-1.5 text-[13px] font-normal",children:[/* @__PURE__ */e(Gt,{className:"h-3.5 w-3.5 text-muted-foreground"}),/* @__PURE__ */e("span",{children:s}),B.length+j.length>0&&/* @__PURE__ */e("span",{className:"ml-auto text-[11px] tabular-nums text-muted-foreground",children:B.length+j.length})]}):/* @__PURE__ */n(_e,{tooltip:"Configure Controls",className:W("relative h-7 w-7 px-0",{"text-primary":B.length>0||j.length>0}),children:[/* @__PURE__ */e(Gt,{className:"h-3.5 w-3.5"}),B.length+j.length>0&&/* @__PURE__ */e("span",{className:"absolute -right-1 -top-1 inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-primary px-1 text-[10px] font-medium text-primary-foreground",children:B.length+j.length})]})}),/* @__PURE__ */n(lt,{className:W("flex max-h-[85vh] w-[560px] max-w-[95vw] flex-col",C&&"z-[60]"),align:"end",onEscapeKeyDown:o,onPointerDownOutside:o,children:[/* @__PURE__ */n("div",{className:"space-y-1 border-b pb-4",children:[/* @__PURE__ */e("h4",{className:"text-sm font-medium",children:"Card-only controls"}),/* @__PURE__ */e("p",{className:"text-xs text-muted-foreground",children:"Add controls that belong only to this card, or decide how this card should respond to shared dashboard controls."}),b!=null&&b.sql?/* @__PURE__ */e("p",{className:"text-xs text-muted-foreground",children:"SQL cards reference controls explicitly with syntax like `[[param.wac_type]]`."}):null]}),/* @__PURE__ */e("div",{className:"flex-1 overflow-y-auto pt-5",children:/* @__PURE__ */n("div",{className:"space-y-5 pr-1",children:[/* @__PURE__ */e(od,{scope:"card",card:b,controls:B,reservedControlIds:$,usageByControlId:O,availableFieldChoices:K,availableMetricChoices:E,onCreateFlowActiveChange:d,onChange:(P,V,G)=>h(P,G),emptyMessage:"No card-scoped controls yet."}),/* @__PURE__ */n("div",{className:"space-y-1 border-t pt-4",children:[/* @__PURE__ */e("h4",{className:"text-sm font-medium",children:"How this card uses controls"}),/* @__PURE__ */e("p",{className:"text-xs text-muted-foreground",children:"Choose what each control changes in this card."})]}),b?/* @__PURE__ */n(be,{children:[/* @__PURE__ */e(Ru,{card:b,dashboardControls:f,bindings:j,onChange:I,availableFieldChoices:y?void 0:K,availableMetricChoices:y?void 0:E,matrixSpec:y==null?void 0:y.spec,matrixPresentation:y==null?void 0:y.presentation,matrixFieldCatalog:D,suppressTransientStaleState:!!(y&&x.pending)}),/* @__PURE__ */e("div",{className:"border-t pt-4",children:/* @__PURE__ */e(Du,{matrixCatalog:x.catalog,card:b,dashboardControls:f,resultColumnKeys:v,bindings:k,onChange:g})})]}):null]})})]})]})});}function gs({showOrientation:t=!0,showGridStyle:a=!0,showInlineFilters:s=!0,showControls:r=!0,showDisplayOptions:o=!0}={}){const c=T(m=>m.card),d=T(m=>{var N,w;return(w=(N=m.card)==null?void 0:N.preferences)==null?void 0:w.chartOptions;}),l=cc(d),{setChartGrid:i}=he();function v(){const m=["xy","none","x","y"],w=(m.indexOf(l)+1)%m.length;i(m[w]);}const u=t&&["line","bar","range","stackedBar","stackedLine","horizontalBar","funnel","bullet"].includes(c.type),p=a&&!["pie","doughnut","funnel","radar","polarArea","table","detailTable","custom","kpi","text"].includes(c.type);return u||p||s||r||o?/* @__PURE__ */n("div",{"data-info":"visual-settings",className:"flex items-center gap-2",children:[u&&/* @__PURE__ */e(be,{children:/* @__PURE__ */e(ku,{})}),p&&/* @__PURE__ */n(_e,{tooltip:"Grid Style",onClick:v,className:"h-7 w-7 px-0",children:[(l==="xy"||!l)&&/* @__PURE__ */e(Qt,{className:"h-3.5 w-3.5"}),l==="x"&&/* @__PURE__ */e(Gr,{className:"h-3.5 w-3.5"}),l==="y"&&/* @__PURE__ */e(Wr,{className:"h-3.5 w-3.5"}),l==="none"&&/* @__PURE__ */e(wr,{className:"h-3.5 w-3.5"})]}),s&&/* @__PURE__ */e(En,{}),r&&/* @__PURE__ */e(Fn,{}),o&&/* @__PURE__ */e(In,{})]}):null;}function _u({errorMessage:t,errorSql:a,onOpenInEditor:s}){const{feedbackDialogOpen:r,setFeedbackDialogOpen:o,handleSendFeedback:c,feedbackPayload:d}=ms(t,a);return/* @__PURE__ */n(be,{children:[/* @__PURE__ */e("div",{className:"flex h-full min-h-0 flex-col overflow-auto px-4 py-0",children:/* @__PURE__ */e(an,{error:t,errorSql:a,errorMessageClassName:"max-h-40",fillAvailableSqlHeight:!0,className:"max-h-none",onOpenInEditor:s,onSendFeedback:c,showFeedbackButton:!0})}),/* @__PURE__ */e(Tn,{open:r,onOpenChange:o,feedbackData:d,showDebugInfo:!0})]});}function Vu({isPreviewMode:t,onPreviewToggle:a,configCard:s}){var I,g,C,M,z;const r=T(_=>_.frame),o=T(_=>_.card),c=T(_=>_.editorContext),d=(c==null?void 0:c.type)==="documentSection",l=xe(_=>{var P,V;return cl((V=(P=_.dashboard)==null?void 0:P.sheets)==null?void 0:V.find(G=>{var ee;return(ee=G.frames)==null?void 0:ee.some(ie=>ie.id===r.id);}));}),{setFrame:i,setActiveTabCardId:v,setCard:u,updateCardInFrame:p,closeCardTab:f}=he(),{manifest:m}=bt(((I=s==null?void 0:s.customCardPreferences)==null?void 0:I.url)||""),N=(g=m==null?void 0:m.visuals)==null?void 0:g.find(_=>{var P;return _.name===((P=s==null?void 0:s.customCardPreferences)==null?void 0:P.componentName);}),S=ut(s,N)==="multiple",b=(N==null?void 0:N.minInputs)??((C=s==null?void 0:s.customCardPreferences)==null?void 0:C.minInputs)??1,y=(N==null?void 0:N.maxInputs)??((M=s==null?void 0:s.customCardPreferences)==null?void 0:M.maxInputs),R=X(()=>Kt({frame:r,configCard:s,isMultiInputVisual:S}),[r,s,S]),x=S?R.filter(Boolean).length:r.cards.length,D=d?!1:y?x<y:!0,B=x>Math.max(b||1,1),$=!!((z=s==null?void 0:s.customCardPreferences)!=null&&z.dataInputCardIds),j=(_,P)=>{_.dataTransfer.setData("tabIndex",P.toString());},k=_=>{_.preventDefault();},O=(_,P)=>{const V=_.dataTransfer.getData("tabIndex");if(V===P.toString())return;const G=Array.from(r.cards),[ee]=G.splice(parseInt(V),1);G.splice(P,0,ee),i({...r,cards:G});};function A(_){const P=(s==null?void 0:s.id)===_;($&&P?r.cards.length>1:B)&&f(_,{renumber:S&&!$?dl:void 0});}function F(_,P){if(!D)return;const V={...r,cards:[...r.cards,P],activeCardId:_.id};i(V),v(P.id);}function K(){if(d)return;if(S&&(s==null?void 0:s.id)===o.id){E(o);return;}const _={...o,id:La(),title:`${o.title} Copy`,tabTitle:`${o.tabTitle||o.title} Copy`,customCardPreferences:o.customCardPreferences?{...o.customCardPreferences,slotIndex:S?Math.max(-1,...R.map((P,V)=>tt(P,V)))+1:o.customCardPreferences.slotIndex}:void 0};F(o,_);}function E(_){var Q;if(d||!D)return;let P=S?"table":Nn,V="Title",G="";const ee=S?Math.max(-1,...R.map((q,te)=>tt(q,te)))+1:x;if(S&&(Q=N==null?void 0:N.slots)!=null&&Q.length){const q=_a(N.slots,ee);q&&(P=ul(q),V=q.label||`Tab ${ee+1}`,G=q.description||"");}const ie={dataSource:_.dataSource,connectionId:_.connectionId,id:La(),title:V,tabTitle:V,description:G,preferences:{onClickFilter:[{columnIndex:0,expression:""}],...(P==="text"?{textVisualOptions:{richContent:ml()}}:{})},type:P,sql:"",data:[],mode:"explorer",...(S&&{customCardPreferences:{slotIndex:ee}})};F(_,ie);}function h(_,P){return _.cards.length===1&&(P.displayTab===!0||P.displayTab===void 0)||_.activeCardId!==P.id&&(P.displayTab===!0||P.displayTab===void 0)?null:/* @__PURE__ */e("div",{onClick:()=>{const V=P.displayTab===void 0?!1:!P.displayTab;u({...P,displayTab:V}),p({...P,displayTab:V});},children:P.displayTab===!0||P.displayTab===void 0?/* @__PURE__ */e(ja,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"}):/* @__PURE__ */e(jn,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})});}return/* @__PURE__ */e(gt,{variant:"underline",className:"group flex h-9 shrink-0 items-center justify-start gap-1 overflow-x-auto rounded-none border-b-0 border-t border-border bg-background px-4",children:/* @__PURE__ */n("div",{className:"flex items-center gap-1",children:[r.cards.map((_,P)=>{var Q,q;const V=S?tt(_,P):-1,G=S&&(Q=N==null?void 0:N.slots)!=null&&Q.length&&V>=0?_a(N.slots,V):null,ee=G?(Array.isArray(G.expectedType)?G.expectedType[0]:G.expectedType)||"table":_.type,ie=S&&((q=N==null?void 0:N.slots)==null?void 0:q.length)&&N.slots.every(te=>typeof te.position=="number"||typeof te.position=="string"&&!te.position.includes("+"));return/* @__PURE__ */n(Ke,{draggable:!S&&!d,onDragStart:S||d?void 0:te=>j(te,P),onDragOver:S||d?void 0:k,onDrop:S||d?void 0:te=>O(te,P),className:W("inline-flex h-6 shrink-0 items-center gap-1.5 rounded-[5px] border px-2 text-[12px] font-normal text-muted-foreground transition-colors","mb-0 border-transparent pb-0","hover:bg-muted/40 hover:text-foreground","data-[state=active]:border-border data-[state=active]:bg-card data-[state=active]:text-foreground"),value:_.id,children:[S&&G?/* @__PURE__ */e(Ot,{delayDuration:0,children:/* @__PURE__ */n(mt,{children:[/* @__PURE__ */e(ht,{asChild:!0,children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e("span",{className:"text-muted-foreground",children:Fr(ee,"size-3.5")}),/* @__PURE__ */e("span",{children:G.label||`Tab ${V+1}`})]})}),/* @__PURE__ */e(pt,{side:"bottom",className:"w-64 p-3 text-left",children:/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e("p",{className:"text-xs font-medium",children:G.label}),G.description&&/* @__PURE__ */e("p",{className:"whitespace-normal break-words text-xs text-muted-foreground",children:G.description}),/* @__PURE__ */n("div",{className:"flex items-center gap-2 pt-1",children:[G.expectedType&&/* @__PURE__ */e("span",{className:"inline-flex items-center rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground",children:Array.isArray(G.expectedType)?G.expectedType.join(" / "):G.expectedType}),G.required&&/* @__PURE__ */e("span",{className:"inline-flex items-center rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground",children:"Required"})]})]})})]})}):/* @__PURE__ */n(be,{children:[h(r,_),/* @__PURE__ */e(Zo,{enabled:r.activeCardId===_.id,text:_.tabTitle||_.title,onSave:te=>{u({...o,tabTitle:te}),p({...o,tabTitle:te});},children:_.tabTitle||_.title},_.id)]}),!d&&!l&&r.activeCardId===_.id&&!ie&&/* @__PURE__ */e(ei,{className:"h-3 w-3 text-muted-foreground hover:text-foreground",onClick:te=>{te.stopPropagation(),K();}}),!d&&r.activeCardId===_.id&&($&&(s==null?void 0:s.id)===_.id?r.cards.length>1:B)&&/* @__PURE__ */e(Zt,{className:"h-3 w-3 text-muted-foreground hover:text-foreground",onClick:()=>A(_.id)})]},_.id);}),!d&&!l&&/* @__PURE__ */e(_e,{tooltip:"Add Card",className:"h-6 w-6 rounded-[5px] p-0 text-muted-foreground hover:bg-muted hover:text-foreground",onClick:()=>E(o),disabled:!D,children:/* @__PURE__ */e(da,{className:"h-3 w-3"})}),S&&/* @__PURE__ */n(Rs,{pressed:t,onPressedChange:a,size:"sm",className:"ml-1 h-6 gap-1 rounded-[5px] px-2 text-[11px] data-[state=on]:bg-muted data-[state=on]:text-foreground","aria-label":"Toggle preview",children:[t?/* @__PURE__ */e(jn,{className:"h-3 w-3"}):/* @__PURE__ */e(ja,{className:"h-3 w-3"}),/* @__PURE__ */e("span",{children:"Preview"})]})]})});}function Ya({renderCardOverride:t,alwaysRenderOverride:a=!1}={}){var De,je,Je,ge,oe,Me,U,Ie;const s=dc(),r=T(Z=>Z.frame),o=T(Z=>Z.card),[c,d]=Y(!1),l=X(()=>dt(r,o),[r,o]),i=T(Z=>Z.isSqlRunning);T(Z=>Z.isDevMode);const{switchCardTab:v,resetAllColumnSettings:u}=he(),p=Object.keys(((je=(De=o.preferences)==null?void 0:De.tablePrefs)==null?void 0:je.columnSettingsMap)??{}).length>0||Object.keys(((Je=o.preferences)==null?void 0:Je.sqlColumns)??{}).length>0,[f,m]=Y({}),[N,w]=Y(()=>/* @__PURE__ */new Set()),{authToken:S}=qt(),b=ol(S==null?void 0:S.accessToken),{compiledAppearance:y}=Ad(),R=X(()=>uc(y),[y]),{getCard:x,manifest:D,isLoading:B}=bt(((ge=l==null?void 0:l.customCardPreferences)==null?void 0:ge.url)||""),$=(oe=l==null?void 0:l.customCardPreferences)==null?void 0:oe.componentName,j=$?x($):null,k=(Me=D==null?void 0:D.visuals)==null?void 0:Me.find(Z=>Z.name===$),O=ut(l,k),A=c&&O==="multiple"&&!!l,F=X(()=>Kt({frame:r,configCard:l,isMultiInputVisual:!0}).map(Ne=>(Ne==null?void 0:Ne.id)===o.id?o:Ne),[r,l,o]),K=X(()=>gr(F),[F]),E=X(()=>{const Z=F.findIndex(Ne=>(Ne==null?void 0:Ne.id)===o.id);return Z<0?-1:tt(o,Z);},[F,o]),h=X(()=>!l||O!=="multiple"||E<0?o.type:Nt(o,E,k==null?void 0:k.slots)??o.type,[l,O,E,o,k==null?void 0:k.slots]),I=X(()=>A?{...o,connectionId:void 0,dataSource:void 0,sql:"",python:"",config:void 0,queryConfig:void 0}:h!==o.type?{...o,type:h}:o,[o,h,A]),{data:g,dataUpdatedAt:C,isLoading:M,isFetching:z,isError:_,errorMessage:P,errorSql:V,queryKey:G}=$e(I),ee=ra(o,g),ie=JSON.stringify(G),{handleOpenInEditor:Q}=us(V||o.sql||o.python),q=o.type==="text"&&((Ie=(U=o.preferences)==null?void 0:U.textVisualOptions)==null?void 0:Ie.isDynamicText)===!0&&!!P,te=nt((Z,Ne)=>{const rt=il(Ne);m(Qe=>({...Qe,[Z]:rt}));},[]),ce=nt((Z,Ne)=>{w(rt=>{const Qe=new Set(rt);return Ne?Qe.add(Z):Qe.delete(Z),Qe;});},[]),me=N.size>0,le=X(()=>K.map((Z,Ne)=>Nt(Z,Ne,k==null?void 0:k.slots)),[K,k==null?void 0:k.slots]),pe=X(()=>Go(Wo({slotOrderedCards:K,multiInputData:f,valueFormatPreferences:s})),[f,K,s]),fe=mc(),Ee=xe(Z=>Z.dashboard),Ae=xe(Z=>Z.dashboardInputValues),Ue=xe(Z=>Z.adHocFilterValues),de=xe(Z=>{var Ne;return((Ne=Z.reportContext)==null?void 0:Ne.calendar)??null;}),Ce=xe(Z=>Z.selectedSheetId),Fe=T(Z=>Z.inlineFilterValuesMap[(l==null?void 0:l.id)||""]),ot=T(Z=>Z.actions.setCardInlineFilterValue),qe=T(Z=>Z.actions.removeCardInlineFilterValue),Ye=X(()=>l?Yo({card:l,sheetId:Ce||"",inlineFilterValues:Fe,setInlineFilterValue:Z=>ot(l.id,Z),removeInlineFilterValue:Z=>qe(l.id,Z)}):[],[l,Ce,Fe,ot,qe]),{filterInputs:Xe,filters:J,filterValues:ye}=X(()=>l?hc({dashboard:Ee,card:l,sheetId:Ce,dashboardInputValues:Ae,adHocFilterValues:Ue,transientContexts:fe,calendar:de}):{filterInputs:[],filters:[],filterValues:[]},[Ue,l,Ae,de,Ee,Ce,fe]);function Re(Z){v(Z);}function Le(){return B?/* @__PURE__ */e("div",{className:"flex h-full items-center justify-center",children:/* @__PURE__ */e(et,{size:"md",color:"muted","aria-label":"Loading manifest"})}):j?/* @__PURE__ */n("div",{className:"relative flex h-full flex-col pl-2 pr-4",children:[F.map((Ne,rt)=>{if(!Ne)return null;const Qe=tt(Ne,rt),Is=Nt(Ne,Qe,k==null?void 0:k.slots);return/* @__PURE__ */e(ti,{onLoadingStatus:ce,onDataChange:te,card:Ne,effectiveCardType:Is},`${Ne.id}-${Qe}`);}),me&&/* @__PURE__ */e("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-background/50",children:/* @__PURE__ */e(et,{size:"md",color:"muted","aria-label":"Loading preview"})}),/* @__PURE__ */e("div",{className:W("flex h-full min-h-0 flex-1 flex-col gap-2",me&&"opacity-50"),children:/* @__PURE__ */e(Zc,{fallback:/* @__PURE__ */e("div",{className:"flex h-full items-center justify-center",children:/* @__PURE__ */e(et,{size:"md",color:"muted"})}),children:/* @__PURE__ */e(j,{editing:!0,...ai({configCard:l,slotOrderedCards:K,slotTypes:le,multiInputData:f,params:b,theme:R,filterInputs:Xe,filters:J,filterValues:[...(ye||[]),...(Fe||[])],inlineFilters:Ye,formatTemporalBucketValue:pe})})})})]}):/* @__PURE__ */e("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a component to preview the multi-input visual."});}function Pe(){return A?Le():t&&(a||!M&&!z&&!_&&!P)?t({card:o,data:g,isLoading:M,isFetching:z,isError:_}):o.type==="kpi"?M||z?/* @__PURE__ */e("div",{className:"z-50 flex h-full items-center justify-center",children:/* @__PURE__ */e(et,{size:"md",color:"muted","aria-label":"Loading data"})}):P?/* @__PURE__ */e(_u,{errorMessage:P,errorSql:V||o.sql||o.python,onOpenInEditor:Q}):/* @__PURE__ */e("div",{className:"flex h-full items-center justify-center",children:/* @__PURE__ */n("div",{className:"w-1/2 space-y-3",children:[/* @__PURE__ */e("div",{className:"flex h-44 rounded-md border border-border",children:/* @__PURE__ */e(Xo,{card:ee,data:g==null?void 0:g.records,isPending:M||z,isError:_,metadata:g==null?void 0:g.metadata})}),kr(o)&&/* @__PURE__ */e(Ir,{card:ee,mode:"editor",records:g==null?void 0:g.records})]})}):o.type==="text"?M||z?/* @__PURE__ */e("div",{className:"z-50 flex h-full items-center justify-center",children:/* @__PURE__ */e(et,{size:"md",color:"muted","aria-label":"Loading data"})}):q?/* @__PURE__ */e("div",{className:"flex h-full min-h-0 flex-col overflow-auto px-4 py-0",children:/* @__PURE__ */e(an,{error:P,errorSql:V||o.sql||o.python,onOpenInEditor:Q,showFeedbackButton:!1})}):/* @__PURE__ */e("div",{className:"flex h-full min-h-0 flex-col px-4 py-4",children:/* @__PURE__ */e(Jo,{isLoading:i,card:o,data:g==null?void 0:g.records})}):/* @__PURE__ */e(sa,{fallbackRender:Z=>/* @__PURE__ */e(rn,{...Z,onResetColumnSettings:p?u:void 0}),resetKeys:[ie,C,z],children:/* @__PURE__ */e(hs,{className:"grow border-none shadow-none"})});}return/* @__PURE__ */n(ft,{onValueChange:Re,value:r.activeCardId,className:"flex min-h-0 flex-1 flex-col",children:[A?/* @__PURE__ */e("div",{className:"mt-0 min-h-0 flex-1 overflow-hidden",children:Pe()}):r.cards.map(Z=>/* @__PURE__ */e(We,{className:"mt-0 min-h-0 flex-1 overflow-hidden focus-visible:ring-0 focus-visible:ring-offset-0",value:Z.id,children:Pe()},Z.id)),/* @__PURE__ */e(Vu,{isPreviewMode:A,onPreviewToggle:d,configCard:l})]});}function xs({sql:t,debugPayloads:a,variant:s="panel",className:r}){const[o,c]=Y(!1),d=s==="popover",l=T(N=>N.isDevMode),i=T(N=>N.card.type),{switchEditorMode:v,setRunSql:u}=he(),p=!d&&!l&&!!a,f=p&&o,m=()=>{v("dev",{sqlToLoad:t}),setTimeout(()=>{u(!0);},100);};return/* @__PURE__ */n(ni,{className:W("overflow-hidden",d&&"pt-0",r),children:[/* @__PURE__ */e(ri,{sql:t,label:d?"Executed SQL":"Governed query",headerClassName:d?"border-b border-border/60 py-2":void 0,labelClassName:d?"font-medium text-foreground":void 0,ariaLabel:"Executed SQL",copyAriaLabel:"Copy governed query",headerActions:l?void 0:/* @__PURE__ */n(be,{children:[Ja(i)&&/* @__PURE__ */e(ue,{onClick:m,variant:"outline",size:"xs",className:si,children:"Open in SQL editor"}),p&&/* @__PURE__ */e(li,{isOpen:o,onClick:()=>c(N=>!N)})]}),className:W("min-h-0",!d&&(f?"max-h-[40%] shrink-0":"flex-1")),bodyClassName:d?"max-h-[min(420px,calc(var(--radix-hover-card-content-available-height,100vh)-3rem))]":"flex-1"}),f&&a&&/* @__PURE__ */e(oi,{payloads:a,onClose:()=>c(!1),className:"mt-3 flex-1"})]});}function Ea({children:t,visualAsideControl:a,mode:s="both"}){const r=hn(),o=T(le=>le.frame),c=T(le=>le.card),d=T(le=>le.isDevMode),l=T(le=>le.editorContext),i=(l==null?void 0:l.type)==="documentSection",v=xe(le=>le.isVisualEditing),u=xe(le=>{var pe,fe;return(fe=(pe=le.dashboard)==null?void 0:pe.exportDefaults)==null?void 0:fe.csvEncoding;}),p=T(le=>le.actions.setRunSql),f=Ve(),m=f==="table"||f==="detailTable"||f==="matrixTable",w=Za(f)&&!!(a!=null&&a.onOpen),S=Sn(),b=X(()=>f!==c.type?{...c,type:f}:c,[c,f]),{data:y,isLoading:R,isFetching:x,errorMessage:D,refetch:B,queryKey:$,pagination:j,isCurrentQueryResult:k}=$e(b),O=Oe($);O.current=$;const A=X(()=>(y==null?void 0:y.records)||[],[y==null?void 0:y.records]),{cardFilterValues:F}=pc((c==null?void 0:c.id)??""),[K,E]=Y(!1),h=Pr(c),[I,g]=Y();ve(()=>{x||E(!1);},[x]);const C=()=>{var le;if(h){(le=h.refresh)==null||le.call(h);return;}if(E(!0),d){hr({queryClient:r,readQueryKey:()=>O.current,setRunSql:p});return;}B();},M=Array.isArray(y==null?void 0:y.records)?y.records:[],z=M.length>0;function _(){var pe;if(!z)return;const le=JSON.stringify(M,null,2);typeof navigator>"u"||!((pe=navigator.clipboard)!=null&&pe.writeText)||navigator.clipboard.writeText(le).catch(fe=>{console.error("Failed to copy JSON",fe);});}function P(){if(!z)return;const le=JSON.stringify(M,null,2),pe=new Blob([le],{type:"application/json"}),fe=URL.createObjectURL(pe),Ee=document.createElement("a");Ee.href=fe,Ee.download=`${c.title}.json`,Ee.click();}function V(){z&&gc(xc(dd({records:M,encoding:Rd({dashboardDefault:u})}),c.title||"export"));}if(!c)return/* @__PURE__ */e(be,{children:"No Active Card"});const G=s==="both"||s==="toolbar",ee=s==="both"||s==="canvas",ie=s==="toolbar",Q=!R&&!x&&!D&&y!=null&&y.sql?/* @__PURE__ */e("div",{className:"inline-flex shrink-0 items-center text-[11px] text-muted-foreground",children:/* @__PURE__ */n(wt,{openDelay:200,children:[/* @__PURE__ */e(St,{asChild:!0,children:/* @__PURE__ */e("button",{type:"button",className:"cursor-pointer text-[11px] transition-colors hover:text-foreground",children:"Executed SQL"})}),/* @__PURE__ */e(Tt,{align:"end",collisionPadding:16,className:"w-[500px] overflow-hidden p-0",children:/* @__PURE__ */e(xs,{sql:y.sql,variant:"popover"})})]})}):null,q=typeof(y==null?void 0:y.output)=="string"?y.output.trim():"",te=ie&&!R&&!x&&!D&&q?/* @__PURE__ */n(wt,{openDelay:200,children:[/* @__PURE__ */e(St,{asChild:!0,children:/* @__PURE__ */e("button",{type:"button",className:"cursor-pointer text-[11px] transition-colors hover:text-foreground",children:"Python output"})}),/* @__PURE__ */n(Tt,{align:"end",collisionPadding:16,className:"w-[480px] overflow-hidden p-0",children:[/* @__PURE__ */e("div",{className:"border-b border-border/60 px-3 py-2 text-[12px] font-medium",children:"Python output"}),/* @__PURE__ */e("pre",{className:"max-h-80 overflow-auto whitespace-pre-wrap break-words px-3 py-2 font-mono text-[11px] leading-relaxed text-foreground/90",children:q})]})]}):null,ce=(j==null?void 0:j.totalCount)??A.length,me=ie&&!R&&!x&&!D&&Array.isArray(y==null?void 0:y.records)?/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-1.5 whitespace-nowrap text-[11px] tabular-nums text-muted-foreground",children:[/* @__PURE__ */n("span",{children:[k?null:"Last run: ",ce.toLocaleString()," ",ce===1?"row":"rows"]}),Q?/* @__PURE__ */n(be,{children:[/* @__PURE__ */e("span",{"aria-hidden":!0,className:"text-border",children:"·"}),Q]}):null,te?/* @__PURE__ */n(be,{children:[/* @__PURE__ */e("span",{"aria-hidden":!0,className:"text-border",children:"·"}),te]}):null]}):null;return/* @__PURE__ */n("div",{className:W("relative isolate flex flex-col",ie?"pointer-events-none w-full min-w-0":W("h-full",!m&&"pt-2")),children:[G&&/* @__PURE__ */n("div",{className:W("z-10 mb-0 flex items-center",ie?"pointer-events-none relative h-10 min-w-0 gap-3 px-4":"min-h-10 gap-2 px-4"),children:[ie?/* @__PURE__ */n("div",{className:"pointer-events-auto flex min-w-0 items-center gap-3",children:[!i&&/* @__PURE__ */e(Wa,{selectedChart:c.type,onChartChange:S,compactMore:!0,responsiveCompact:!0}),me]}):/* @__PURE__ */e("div",{className:"flex grow items-center gap-4",children:/* @__PURE__ */e("div",{className:"flex items-center gap-3",children:!i&&/* @__PURE__ */e(Wa,{selectedChart:c.type,onChartChange:S,compactMore:!0})})}),/* @__PURE__ */n("div",{className:W("flex items-center text-muted-foreground",ie?"pointer-events-auto ml-auto gap-1.5":"gap-2"),children:[t,ie?null:Q,F&&F.length>0&&/* @__PURE__ */n(wt,{openDelay:200,children:[/* @__PURE__ */e(St,{asChild:!0,children:/* @__PURE__ */n(ue,{variant:"outline",size:"xs",className:"h-7 gap-1.5 px-2",children:[/* @__PURE__ */e(ua,{className:"h-3.5 w-3.5",strokeWidth:1.75}),/* @__PURE__ */e(Hr,{variant:"secondary",className:"h-4 min-w-4 rounded-[4px] px-1 text-[10px] font-medium",children:F.length})]})}),/* @__PURE__ */n(Tt,{align:"end",className:"flex max-h-[400px] w-[500px] flex-col overflow-hidden p-0",children:[/* @__PURE__ */e("div",{className:"shrink-0 border-b border-border px-3 py-2 text-[13px] font-medium",children:"Active Dashboard Filters"}),/* @__PURE__ */e("div",{className:"min-h-0 flex-1 overflow-auto",children:/* @__PURE__ */e(_t,{value:JSON.stringify(F,null,2),onValueChange:()=>{},language:"json",readOnly:!0,embedded:!0,wrapLines:!0,dense:!0,hideLineNumbers:!0,ariaLabel:"Active dashboard filters JSON"})})]})]}),/* @__PURE__ */e("div",{className:ie?"hidden @[820px]:flex":"",children:/* @__PURE__ */e(gs,{showInlineFilters:!1,showControls:!1,showDisplayOptions:!1})}),(a==null?void 0:a.show)&&/* @__PURE__ */n(ue,{type:"button",variant:"ghost",size:"xs","aria-pressed":a.isOpen,onClick:a.onToggle,className:W("h-7 shrink-0 gap-1.5 text-[12px]",ie?"w-7 px-0 @[760px]:w-auto @[760px]:px-2":"px-2",a.isOpen&&"bg-accent text-accent-foreground"),children:[/* @__PURE__ */e(ca,{className:"h-3.5 w-3.5",strokeWidth:1.75}),/* @__PURE__ */e("span",{className:ie?"hidden @[760px]:inline":"",children:"Settings"})]}),!ie&&/* @__PURE__ */e(_e,{tooltip:"Refresh",disabled:R||x,className:"h-7 w-7 px-0",onClick:C,children:/* @__PURE__ */e(Ha,{className:W("h-3.5 w-3.5",{"animate-spin":(h==null?void 0:h.isFetching)??K})})}),/* @__PURE__ */n(la,{modal:!1,children:[/* @__PURE__ */e(oa,{asChild:!0,children:/* @__PURE__ */e(_e,{tooltip:"More Options",className:"h-7 w-7 px-0","aria-label":"More options",children:/* @__PURE__ */e(Dr,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(ia,{align:"end",collisionPadding:8,className:"max-h-[var(--radix-dropdown-menu-content-available-height)] w-56 overflow-y-auto overscroll-contain",children:[ie&&/* @__PURE__ */n(be,{children:[/* @__PURE__ */n(He,{disabled:R||x,onSelect:C,children:[/* @__PURE__ */e(Ha,{className:"h-3.5 w-3.5"}),"Refresh result"]}),/* @__PURE__ */e($n,{})]}),/* @__PURE__ */e(Un,{children:"Export"}),h?/* @__PURE__ */n(He,{disabled:R||x||!h.hasDelivery,title:h.hasDelivery?void 0:"Available once the preview has loaded.",onSelect:()=>g(h.readDelivery()),className:"gap-2 text-[13px]",children:[/* @__PURE__ */e($a,{className:"h-3.5 w-3.5"}),"Download"]}):/* @__PURE__ */n(be,{children:[/* @__PURE__ */n(He,{disabled:!z,onSelect:V,className:"gap-2 text-[13px]",children:[/* @__PURE__ */e($a,{className:"h-3.5 w-3.5"}),"Download CSV"]}),/* @__PURE__ */n(He,{disabled:!z,onSelect:P,className:"gap-2 text-[13px]",children:[/* @__PURE__ */e(Vd,{className:"h-3.5 w-3.5"}),"Download JSON"]}),/* @__PURE__ */n(He,{disabled:!z,onSelect:_,className:"gap-2 text-[13px]",children:[/* @__PURE__ */e(mn,{className:"h-3.5 w-3.5"}),"Copy JSON"]})]}),/* @__PURE__ */e($n,{}),/* @__PURE__ */e(Un,{children:"Customize"}),!["table","detailTable","custom"].includes(c.type)&&v&&/* @__PURE__ */e(bu,{triggerVariant:"menu",className:"w-full"}),/* @__PURE__ */e(En,{triggerVariant:"menu",className:"w-full"}),/* @__PURE__ */e(Fn,{triggerVariant:"menu",className:"w-full"}),/* @__PURE__ */e(In,{triggerVariant:"menu",className:"w-full"}),w&&/* @__PURE__ */n(He,{onSelect:()=>{var le;return(le=a==null?void 0:a.onOpen)==null?void 0:le.call(a,"style");},className:"gap-2 text-[13px]",children:[/* @__PURE__ */e(fc,{className:"h-3.5 w-3.5"}),"Table settings"]})]})]}),I&&/* @__PURE__ */e(Yr,{isOpen:!0,onClose:()=>g(void 0),card:c,frame:o,matrix:I})]})]}),ee&&/* @__PURE__ */e(Ya,{})]});}function Bu({onToggleEditor:t,children:a}){return/* @__PURE__ */n("div",{className:"relative isolate shrink-0 border-t border-border bg-muted/30 @container",children:[/* @__PURE__ */e(mr,{title:"Drag to resize. Double-click to collapse the editor.",onDoubleClick:t,className:"group absolute inset-0 cursor-row-resize outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring",children:/* @__PURE__ */e("span",{"aria-hidden":!0,className:"pointer-events-none absolute left-1/2 top-1 h-[3px] w-8 -translate-x-1/2 rounded-[2px] bg-transparent transition-colors group-data-[resize-handle-state=drag]:bg-foreground/50 group-data-[resize-handle-state=hover]:bg-foreground/20"})}),a]});}function Be({value:t,onCommit:a,type:s="text",placeholder:r,className:o}){const[c,d]=Y(t),l=Oe(!1);return ve(()=>{d(t);},[t]),/* @__PURE__ */e(Ct,{type:s,placeholder:r,value:c,onChange:u=>d(u.target.value),onBlur:()=>{if(l.current){l.current=!1;return;}c!==t&&a(c);},onKeyDown:u=>{if(u.key==="Enter"){u.currentTarget.blur();return;}u.key==="Escape"&&(l.current=!0,d(t),u.currentTarget.blur());},className:o});}function jt({defaultValue:t,label:a,options:s,value:r,onValueChange:o,className:c,icon:d,showPlaceholderLabel:l=!0}){return/* @__PURE__ */n(ae,{defaultValue:t,value:r,onValueChange:o,children:[/* @__PURE__ */e(ne,{className:W("w-full focus:ring-0 focus:ring-offset-0",c),children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[d&&/* @__PURE__ */e("span",{children:d}),l&&/* @__PURE__ */e(re,{placeholder:a})]})}),/* @__PURE__ */e(se,{children:/* @__PURE__ */n(bc,{children:[/* @__PURE__ */e(vc,{children:a}),s.map(i=>/* @__PURE__ */e(H,{value:i.value,children:i.label},i.value))]})})]});}function Ku(t,a){return _a(t,a)||null;}function Pt(t){if(typeof t=="number")return`Tab ${t+1}`;const a=t.match(/^(\d+)-(\d+)$/);if(a){const[,r,o]=a;return`Tabs ${Number(r)+1}-${Number(o)+1}`;}const s=t.match(/^(\d+)\+$/);return s?`Tabs ${Number(s[1])+1}+`:`Tab ${t}`;}function zu(t){return t?Array.isArray(t)?t:[t]:[];}function Fa(t){var r,o;if(!t)return!1;if(t.type==="text")return!!((r=t.description)!=null&&r.trim());const a=!!((o=t.sql)!=null&&o.trim()),s=zt(t.config);return a||s;}function qu({slots:t,cards:a,minInputs:s}){const r=[],o=a.filter(Boolean).length;return s&&o<s&&r.push({type:"too-few-inputs",message:`This visual requires at least ${s} tab${s===1?"":"s"}.`}),!t||t.length===0||(t.forEach(c=>{if(!c.required)return;if(typeof c.position=="number"){const i=a[c.position];Fa(i)||r.push({type:"missing-required",message:`${Pt(c.position)} ("${c.label}") is required but has no data configured.`});return;}const d=c.position.match(/^(\d+)-(\d+)$/);if(d){const[,i,v]=d.map(Number);for(let u=i;u<=v;u+=1){const p=a[u];if(!Fa(p)){r.push({type:"missing-required",message:`${Pt(u)} ("${c.label}") is required but has no data configured.`});break;}}return;}const l=c.position.match(/^(\d+)\+$/);if(l){const i=Number(l[1]);if(a.length<=i){r.push({type:"missing-required",message:`${Pt(i)} ("${c.label}") is required but has no data configured.`});return;}for(let v=i;v<a.length;v+=1){const u=a[v];if(!Fa(u)){r.push({type:"missing-required",message:`${Pt(v)} ("${c.label}") is required but has no data configured.`});break;}}}}),a.forEach((c,d)=>{if(!c)return;const l=Ku(t,d);if(!l||!l.expectedType)return;const i=zu(l.expectedType);i.length!==0&&(i.includes(c.type)||r.push({type:"wrong-type",message:`${Pt(d)} ("${l.label}") expects ${i.join(", ")}, but is configured as ${c.type}.`}));})),r;}const ju={table:({children:t})=>/* @__PURE__ */e("table",{className:"my-3 w-full border-collapse overflow-hidden rounded-md border border-border text-sm",children:t}),thead:({children:t})=>/* @__PURE__ */e("thead",{className:"bg-muted",children:t}),th:({children:t})=>/* @__PURE__ */e("th",{className:"border border-border px-3 py-2 text-left font-medium",children:t}),td:({children:t})=>/* @__PURE__ */e("td",{className:"border border-border px-3 py-2",children:t}),code:({children:t,className:a})=>(a==null?void 0:a.includes("language-"))?/* @__PURE__ */e("pre",{className:"my-3 overflow-x-auto rounded-md bg-muted p-3 text-xs",children:/* @__PURE__ */e("code",{children:t})}):/* @__PURE__ */e("code",{className:"rounded bg-muted px-1 py-0.5 text-xs",children:t}),pre:({children:t})=>/* @__PURE__ */e(be,{children:t})};function bs(){var F,K,E;const t=T(h=>h.card.customCardPreferences),{data:a}=yc(),s=(a==null?void 0:a.plugins)||[],r=T(h=>h.card),o=T(h=>h.frame),{setCustomCardPreferences:c}=he(),d=X(()=>dt(o,r),[o,r]),l=d==null?void 0:d.customCardPreferences,{components:i,manifest:v}=bt((l==null?void 0:l.url)||(t==null?void 0:t.url)||""),u=(F=v==null?void 0:v.visuals)==null?void 0:F.find(h=>h.name===((l==null?void 0:l.componentName)||(t==null?void 0:t.componentName))),f=ut(d||r,u)==="multiple",m=!!d&&d.id===r.id,N=(u==null?void 0:u.minInputs)??((K=d==null?void 0:d.customCardPreferences)==null?void 0:K.minInputs),w=(u==null?void 0:u.maxInputs)??((E=d==null?void 0:d.customCardPreferences)==null?void 0:E.maxInputs),S=X(()=>Kt({frame:o,configCard:d||r,isMultiInputVisual:f}),[o,d,r,f]),b=X(()=>gr(S),[S]),y=X(()=>b.map((h,I)=>{if(!h)return null;const g=tt(h,I),C=Nt(h,g,u==null?void 0:u.slots);return{...h,type:C??h.type};}),[b,u==null?void 0:u.slots]),R=X(()=>qu({slots:u==null?void 0:u.slots,cards:y,minInputs:N}),[u==null?void 0:u.slots,y,N]),x=X(()=>{const h=S.findIndex(I=>(I==null?void 0:I.id)===r.id);return h<0?-1:tt(r,h);},[S,r]);function D(h){if(typeof h=="number")return`Tab ${h+1}`;const I=h.match(/^(\d+)-(\d+)$/);if(I){const[,C,M]=I;return`Tabs ${Number(C)+1}-${Number(M)+1}`;}const g=h.match(/^(\d+)\+$/);return g?`Tabs ${Number(g[1])+1}+`:`Tab ${h}`;}function B(h){return h?(Array.isArray(h)?h:[h]).join(", "):null;}function $(h,I,g=[],C="",M,z,_){const P=j({key:I,defaultValue:C,settingsValue:z,sourceCard:_});return h==="input"?/* @__PURE__ */e(Be,{className:`h-8 w-full ${hl}`,value:String(P??""),onCommit:V=>{k({key:I,value:V,settingsField:M,settingsValue:z,sourceCard:_});}},I):h==="select"?/* @__PURE__ */e(jt,{className:"h-8 w-full",label:"",options:g,value:String(P!==void 0?P:C??""),onValueChange:V=>{k({key:I,value:V,settingsField:M,settingsValue:z,sourceCard:_});}}):null;}function j({key:h,defaultValue:I,settingsValue:g,sourceCard:C}){const M=g==null?void 0:g[h];return M!==void 0?M:h==="title"&&(C==null?void 0:C.title)!==void 0?C.title:h==="description"&&(C==null?void 0:C.description)!==void 0?C.description:I;}function k({key:h,value:I,settingsField:g,settingsValue:C,sourceCard:M}){const z={...(C||{})},_=h==="title"&&(M==null?void 0:M.title)!==void 0,P=h==="description"&&(M==null?void 0:M.description)!==void 0;_&&I===String((M==null?void 0:M.title)??"")||P&&I===String((M==null?void 0:M.description)??"")?delete z[h]:z[h]=I,c({...(t||{}),[g]:z});}function O({settingsSchema:h,settingsField:I,settingsValue:g,sourceCard:C,headerLabel:M}){const z=Object.entries(h||{});return/* @__PURE__ */n("div",{className:"space-y-3",children:[M&&/* @__PURE__ */e(L,{children:M}),z.map(([_,P])=>{var V;return/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(L,{children:P.title}),((V=P.docs)==null?void 0:V.description)&&/* @__PURE__ */e(Ot,{delayDuration:0,children:/* @__PURE__ */n(mt,{children:[/* @__PURE__ */e(ht,{asChild:!0,children:/* @__PURE__ */e(ct,{className:"h-3.5 w-3.5 cursor-help text-muted-foreground"})}),/* @__PURE__ */e(pt,{side:"right",className:"max-w-xs",children:/* @__PURE__ */e("p",{className:"text-xs",children:P.docs.description})})]})})]}),$(P.ui,_,P.options,P.defaultValue,I,g,C)]},_);})]});}function A(){return/* @__PURE__ */n(be,{children:[f&&/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */e(L,{children:"Slot Guide"}),/* @__PURE__ */e("div",{className:"space-y-3 rounded-md border border-border bg-muted/40 px-3 py-2 text-xs",children:u!=null&&u.slots&&u.slots.length>0?/* @__PURE__ */e("div",{className:"space-y-3",children:u.slots.map((h,I)=>/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2 text-foreground",children:[/* @__PURE__ */e("span",{className:"font-medium",children:D(h.position)}),/* @__PURE__ */e("span",{className:"text-muted-foreground",children:"•"}),/* @__PURE__ */e("span",{className:"font-medium",children:h.label})]}),h.description&&/* @__PURE__ */e("p",{className:"text-muted-foreground",children:h.description}),/* @__PURE__ */n("div",{className:"flex flex-wrap gap-2 text-muted-foreground",children:[B(h.expectedType)&&/* @__PURE__ */n("span",{children:["Expected: ",B(h.expectedType)]}),h.required&&/* @__PURE__ */e("span",{children:"Required"})]})]},`${h.label}-${I}`))}):/* @__PURE__ */n("div",{className:"space-y-1 text-muted-foreground",children:[/* @__PURE__ */e("p",{children:"This visual renders all tabs in a flexible layout. Add as many tabs as needed."}),(N||w)&&/* @__PURE__ */n("p",{children:[N?`Min ${N} tabs`:"",N&&w?" • ":"",w?`Max ${w} tabs`:""]})]})})]}),f&&R.length>0&&/* @__PURE__ */e(As,{className:"mt-3 border-yellow-500/40 bg-yellow-500/10 text-yellow-900 dark:text-yellow-100",children:/* @__PURE__ */e(Ps,{children:/* @__PURE__ */e("ul",{className:"list-disc space-y-1 pl-4 text-xs",children:R.map((h,I)=>/* @__PURE__ */e("li",{children:h.message},`${h.type}-${I}`))})})}),u&&!f&&u.settings&&/* @__PURE__ */e("div",{className:"space-y-3",children:/* @__PURE__ */e("div",{className:"px-2",children:O({settingsSchema:u.settings,settingsField:"settings",settingsValue:t==null?void 0:t.settings,sourceCard:r})})}),u&&f&&(u.settings||u.slotSettings)&&/* @__PURE__ */n("div",{className:"mt-4 space-y-4",children:[m&&u.settings&&/* @__PURE__ */e("div",{className:"px-2",children:O({settingsSchema:u.settings,settingsField:"settings",settingsValue:t==null?void 0:t.settings,sourceCard:d||r,headerLabel:"Global Settings"})}),u.slotSettings&&/* @__PURE__ */e("div",{className:"px-2",children:O({settingsSchema:u.slotSettings,settingsField:"slotSettings",settingsValue:t==null?void 0:t.slotSettings,sourceCard:r,headerLabel:(()=>{const h=r.tabTitle||r.title,I=x>=0?x:0,g=m?"Slot 0":`Slot ${I}`;return h?`${g}: ${h} Settings`:`${g} Settings`;})()})})]})]});}return/* @__PURE__ */n(Yt,{type:"multiple",defaultValue:["component-settings"],className:"",children:[/* @__PURE__ */n(Se,{value:"plugin-settings",children:[/* @__PURE__ */e(Te,{children:"Plugin"}),/* @__PURE__ */e(ke,{children:/* @__PURE__ */n("div",{className:"space-y-4 text-sm",children:[/* @__PURE__ */e("div",{className:"space-y-2",children:/* @__PURE__ */n("div",{className:"space-y-4",children:[(!f||m)&&/* @__PURE__ */e(jt,{icon:/* @__PURE__ */e(ls,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Plugin",options:s,value:(l==null?void 0:l.url)||"",onValueChange:h=>c({...(t||{url:"",componentName:""}),url:h})}),f&&!m&&/* @__PURE__ */e("p",{className:"text-xs text-muted-foreground",children:"Switch to the config tab to change the plugin or component."})]})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&t&&(!f||m)&&/* @__PURE__ */e(be,{children:i&&/* @__PURE__ */e(jt,{icon:/* @__PURE__ */e(_d,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(i==null?void 0:i.map(h=>({value:h.name,label:h.name})))||[],value:t.componentName||"",onValueChange:h=>{var C;const I=(C=v==null?void 0:v.visuals)==null?void 0:C.find(M=>M.name===h),g=i==null?void 0:i.find(M=>M.name===h);c({...t,componentName:h,visualType:(I==null?void 0:I.visualType)||(g==null?void 0:g.type)||"single",minInputs:I==null?void 0:I.minInputs,maxInputs:I==null?void 0:I.maxInputs,pluginChartType:I==null?void 0:I.chartType});}})})]})})]}),((l==null?void 0:l.componentName)||(t==null?void 0:t.componentName))&&/* @__PURE__ */n(Se,{className:"border-none",value:"component-settings",children:[/* @__PURE__ */e(Te,{children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e("span",{children:(u==null?void 0:u.name)||"Settings"}),(u==null?void 0:u.docs)&&/* @__PURE__ */n(wt,{openDelay:0,closeDelay:100,children:[/* @__PURE__ */e(St,{asChild:!0,onClick:h=>h.stopPropagation(),children:/* @__PURE__ */e(ct,{className:"h-3.5 w-3.5 cursor-help text-muted-foreground transition-colors hover:text-foreground"})}),/* @__PURE__ */e(Tt,{side:"right",align:"start",className:"max-h-[40vh] w-[500px] overflow-y-auto text-left",children:/* @__PURE__ */n("div",{className:"space-y-4 text-left",children:[u.docs.description&&/* @__PURE__ */e("p",{className:"text-sm text-muted-foreground",children:u.docs.description}),u.docs.dataSchema&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Data Schema"}),/* @__PURE__ */e("div",{className:"prose prose-sm dark:prose-invert prose-pre:bg-muted prose-pre:text-xs max-w-none",children:/* @__PURE__ */e(ii,{remarkPlugins:[ci],components:ju,children:u.docs.dataSchema})})]}),(()=>{var I;const h=(I=u.docs)==null?void 0:I.useCases;return!h||h.length===0?null:/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Use Cases"}),/* @__PURE__ */e("ul",{className:"space-y-1 text-sm",children:h.map((g,C)=>/* @__PURE__ */n("li",{className:"flex items-start gap-2",children:[/* @__PURE__ */e("span",{className:"mt-1 text-primary",children:"•"}),/* @__PURE__ */e("span",{children:g})]},C))})]});})()]})})]})]})}),/* @__PURE__ */e(ke,{children:A()})]})]});}const $u={type:"number",minimumFractionDigits:0,maximumFractionDigits:0};function Uu(t){var a;return ud((a=t==null?void 0:t.sqlKpiValue)==null?void 0:a.format)||$u;}function ar(t,a){const s=a?md(a):void 0,{format:r,...o}=t.sqlKpiValue??{},c=s?{...o,format:s}:o,{sqlKpiValue:d,...l}=t;return Object.keys(c).length?{...l,sqlKpiValue:c}:l;}function Hu(){var v,u;const t=T(p=>p.card),a=T(p=>p.actions.setCardPreferences),s=Nc()??Ln.locale,r=Cc()??Ln.defaultCurrency,o=di(t)==="config",c=Uu(t.preferences),d=!!((u=(v=t.preferences)==null?void 0:v.sqlKpiValue)!=null&&u.format),l=p=>{const f=T.getState().card.preferences??{};a(ar(f,p));},i=p=>{const f=T.getState().card.preferences??{};a(ar(f,p?c:void 0));};return o?/* @__PURE__ */e(nr,{card:t}):/* @__PURE__ */n("div",{children:[/* @__PURE__ */n("div",{className:"mb-3 flex items-center gap-2",children:[/* @__PURE__ */e(Lt,{id:"query-kpi-format-number",checked:d,onCheckedChange:p=>i(p===!0)}),/* @__PURE__ */e(L,{htmlFor:"query-kpi-format-number",className:"text-xs",children:"Format number"})]}),d&&/* @__PURE__ */n("div",{className:"flex flex-col gap-2",children:[/* @__PURE__ */e(Xt,{formatOptions:c,onFormatOptionsChange:l,showTitle:!1,showAutoFormat:!1,reportDefaults:{currency:r,locale:s}}),/* @__PURE__ */e(wc,{className:"my-3"})]}),/* @__PURE__ */e(nr,{card:t})]});}function nr({card:t}){const a=T(i=>i.actions.updateConditionalRules),{rules:s,onChange:r}=Lr(t.id,xr(t),a),o=pl(t),c=o==null?void 0:o.value,d=(o==null?void 0:o.source)==="config"?o.measure:void 0,l=c?[{value:fl(c),label:d?d.label||d.alias||d.name:"Value"}]:[];return l.length?/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(_r,{cardId:t.id}),/* @__PURE__ */e(Vr,{columnId:l[0].value,availableColumns:l,conditionalRules:s,onConditionalRulesChange:r,capabilities:{ruleKinds:["comparison"],automaticRanges:!1}})]}):null;}const Qu={combo:{label:"Combo Chart",query:"SELECT x-axis, metric-1, metric-2, ... FROM table",fields:[{name:"x-axis",type:"category",description:"dimension"},{name:"metric-1, metric-2",type:"number",description:"can be bar, line, or area"}],description:"Combo charts allow mixing bar and line series with optional dual Y-axis for metrics with different scales.",docsUrl:"https://docs.semaphor.cloud/docs/charts/combo"},area:{label:"Area Chart",query:"SELECT x-axis, y-axis-1, y-axis-2, ... FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., date, city"},{name:"Y-axis",type:"number",description:"e.g., sales, population"}],description:"Area charts display quantitative data with filled areas under the line.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bar-line-area"},stackedArea:{label:"Stacked Area Chart",query:"SELECT x-axis, y-axis-1, y-axis-2, ... FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., date, city"},{name:"Y-axis",type:"number",description:"e.g., sales, population"}],description:"Stacked area charts show how multiple series contribute to a total over time.",docsUrl:"https://docs.semaphor.cloud/docs/charts/stacked"},bar:{label:"Bar Chart",query:"SELECT x-axis, y-axis-1, y-axis-2, ... FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., city, product"},{name:"Y-axis",type:"number",description:"e.g., sales, count"}],description:"Bar charts compare values across categories using horizontal or vertical bars.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bar-line-area"},line:{label:"Line Chart",query:"SELECT x-axis, y-axis-1, y-axis-2, ... FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., date, month"},{name:"Y-axis",type:"number",description:"e.g., revenue, count"}],description:"Line charts show trends over time or continuous data.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bar-line-area"},stackedBar:{label:"Stacked Bar Chart",query:"SELECT x-axis, stack-by, y-axis FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., month"},{name:"Stack-by",type:"category",description:"e.g., product type"},{name:"Y-axis",type:"number",description:"e.g., sales"}],description:"Stacked bar charts show how parts contribute to a whole across categories.",docsUrl:"https://docs.semaphor.cloud/docs/charts/stacked"},stackedLine:{label:"Stacked Line Chart",query:"SELECT x-axis, stack-by, y-axis FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., date"},{name:"Stack-by",type:"category",description:"e.g., region"},{name:"Y-axis",type:"number",description:"e.g., revenue"}],description:"Stacked line charts show cumulative trends over time.",docsUrl:"https://docs.semaphor.cloud/docs/charts/stacked"},pie:{label:"Pie Chart",query:"SELECT label, measure FROM table",fields:[{name:"Label",type:"category",description:"e.g., product, region"},{name:"Measure",type:"number",description:"e.g., sales, count"}],description:"Pie charts show proportions of a whole.",docsUrl:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar"},doughnut:{label:"Doughnut Chart",query:"SELECT label, measure FROM table",fields:[{name:"Label",type:"category",description:"e.g., product, region"},{name:"Measure",type:"number",description:"e.g., sales, count"}],description:"Doughnut charts show proportions with a hollow center.",docsUrl:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar"},polarArea:{label:"Polar Area Chart",query:"SELECT label, measure FROM table",fields:[{name:"Label",type:"category",description:"e.g., skill, metric"},{name:"Measure",type:"number",description:"e.g., score, value"}],description:"Polar area charts compare values using sectors of equal angle but varying radius.",docsUrl:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar"},radar:{label:"Radar Chart",query:"SELECT label, measure FROM table",fields:[{name:"Label",type:"category",description:"e.g., attribute, skill"},{name:"Measure",type:"number",description:"e.g., score, rating"}],description:"Radar charts display multivariate data on axes starting from the same point.",docsUrl:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar"},funnel:{label:"Funnel Chart",query:"SELECT label, measure FROM table",fields:[{name:"Label",type:"category",description:"e.g., stage name"},{name:"Measure",type:"number",description:"e.g., count, value"}],description:"Funnel charts visualize progressive reduction of data through stages.",docsUrl:"https://docs.semaphor.cloud/docs/charts/funnel"},bubble:{label:"Bubble Chart",query:"SELECT label, [group], x-axis, y-axis, radius FROM table",fields:[{name:"Label",type:"category",description:"e.g., city"},{name:"Group",type:"category",description:"e.g., region",optional:!0},{name:"X-axis",type:"number",description:"e.g., population"},{name:"Y-axis",type:"number",description:"e.g., income"},{name:"Radius",type:"number",description:"e.g., area"}],description:"Bubble charts display three dimensions of data using position and size.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bubble"},scatter:{label:"Scatter Chart",query:"SELECT label, [group], x-axis, y-axis FROM table",fields:[{name:"Label",type:"category",description:"e.g., item name"},{name:"Group",type:"category",description:"e.g., type",optional:!0},{name:"X-axis",type:"number",description:"e.g., price"},{name:"Y-axis",type:"number",description:"e.g., quantity"}],description:"Scatter charts show relationships between two numeric variables.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bubble"},tornado:{label:"Tornado Chart",query:"SELECT dimension, cohort, metric FROM table",fields:[{name:"Dimension",type:"category",description:"e.g., age group"},{name:"Cohort",type:"category",description:"e.g., gender"},{name:"Metric",type:"number",description:"e.g., population"}],description:"Tornado charts compare two groups across categories using back-to-back bars.",docsUrl:"https://docs.semaphor.cloud/docs/charts/tornado"},pyramid:{label:"Pyramid Chart",query:"SELECT dimension, cohort, metric FROM table",fields:[{name:"Dimension",type:"category",description:"e.g., age group"},{name:"Cohort",type:"category",description:"e.g., gender"},{name:"Metric",type:"number",description:"e.g., population"}],description:"Population pyramids show age and gender distribution.",docsUrl:"https://docs.semaphor.cloud/docs/charts/tornado"},range:{label:"Range Chart",query:"SELECT y-axis, label, range-from, range-to, range-value FROM table",fields:[{name:"Y-axis",type:"category",description:"e.g., category"},{name:"Label",type:"category",description:"e.g., range name"},{name:"Range-from",type:"number",description:"start value"},{name:"Range-to",type:"number",description:"end value"},{name:"Range-value",type:"number",description:"e.g., midpoint"}],description:"Range charts display data ranges with start and end values.",docsUrl:"https://docs.semaphor.cloud/docs/charts/range"},heatmap:{label:"Heatmap",query:"SELECT x-axis, y-axis, value FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., day"},{name:"Y-axis",type:"category",description:"e.g., hour"},{name:"Value",type:"number",description:"e.g., count, intensity"}],description:"Heatmaps visualize data density using color intensity.",docsUrl:"https://docs.semaphor.cloud/docs/charts/heatmap"},bullet:{label:"Bullet Chart",query:"SELECT label, actual, target, [ranges] FROM table",fields:[{name:"Label",type:"category",description:"e.g., metric name"},{name:"Actual",type:"number",description:"current value"},{name:"Target",type:"number",description:"goal value"},{name:"Ranges",type:"number",description:"threshold values",optional:!0}],description:"Bullet charts compare actual performance against targets.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bullet"},text:{label:"Text Visual",query:"SELECT text FROM table LIMIT 1",fields:[{name:"Text",type:"string",description:"content to display"}],description:"Text visuals display dynamic text content from your data.",docsUrl:"https://docs.semaphor.cloud/docs/charts/text"},kpi:{label:"KPI",query:"SELECT current, previous FROM table",fields:[{name:"Current",type:"number",description:"current value"},{name:"Previous",type:"number",description:"comparison value"}],description:"KPI visuals display key performance indicators with comparison values.",docsUrl:"https://docs.semaphor.cloud/docs/charts/kpi"},table:{label:"Table",query:"SELECT column1, column2, ... FROM table",fields:[{name:"Columns",type:"category",description:"any data columns"}],description:"Tables display data in rows and columns.",docsUrl:"https://docs.semaphor.cloud/docs/charts/table"},detailTable:{label:"Detail Table",query:"SELECT column1, column2, ... FROM table ORDER BY column1 DESC",fields:[{name:"Columns",type:"category",description:"columns to display (no aggregation)"}],description:"Detail tables display raw records without aggregation. Ideal for event logs, transaction history, and audit trails.",docsUrl:"https://docs.semaphor.cloud/docs/charts/detail-table"}};function vs(t){return Qu[t];}function Gu({chartType:t,showDocsLink:a=!0}){const s=vs(t);return s?/* @__PURE__ */n("div",{className:"space-y-4",children:[/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e("h4",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Query Format"}),/* @__PURE__ */e("code",{className:"block rounded-md bg-muted/50 px-3 py-2 font-mono text-xs text-foreground",children:s.query})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e("h4",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Fields"}),/* @__PURE__ */e("div",{className:"rounded-md border",children:/* @__PURE__ */n("table",{className:"w-full text-xs",children:[/* @__PURE__ */e("thead",{children:/* @__PURE__ */n("tr",{className:"border-b bg-muted/50",children:[/* @__PURE__ */e("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Field"}),/* @__PURE__ */e("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Type"}),/* @__PURE__ */e("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Description"})]})}),/* @__PURE__ */e("tbody",{children:s.fields.map((r,o)=>/* @__PURE__ */n("tr",{className:o<s.fields.length-1?"border-b":"",children:[/* @__PURE__ */n("td",{className:"px-2.5 py-1.5 font-medium text-foreground",children:[r.name,r.optional&&/* @__PURE__ */e("span",{className:"ml-1 text-muted-foreground",children:"?"})]}),/* @__PURE__ */e("td",{className:"px-2.5 py-1.5 font-mono text-muted-foreground",children:r.type}),/* @__PURE__ */e("td",{className:"px-2.5 py-1.5 text-muted-foreground",children:r.description||"—"})]},r.name))})]})})]}),/* @__PURE__ */e("p",{className:"text-xs leading-relaxed text-muted-foreground",children:s.description}),a&&s.docsUrl&&/* @__PURE__ */n("a",{href:s.docsUrl,target:"_blank",rel:"noopener noreferrer",onClick:r=>r.stopPropagation(),className:"inline-flex items-center gap-1.5 text-xs font-medium text-primary hover:underline",children:["View documentation",/* @__PURE__ */e(Sc,{className:"h-3 w-3"})]})]}):null;}function Wu({chartType:t}){return vs(t)?/* @__PURE__ */n(wt,{openDelay:200,children:[/* @__PURE__ */e(St,{asChild:!0,children:/* @__PURE__ */e("button",{type:"button",className:"rounded bg-muted px-2 py-0.5 font-mono text-[10px] font-semibold uppercase tracking-wider text-muted-foreground transition-colors hover:bg-muted/80 hover:text-foreground",children:"SQL"})}),/* @__PURE__ */e(Tt,{className:"w-80 p-4",side:"left",align:"start",sideOffset:8,children:/* @__PURE__ */e(Gu,{chartType:t})})]}):null;}function ys({chartType:t,suffix:a="Configuration"}){return/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e("h3",{className:"text-xs font-medium",children:a}),/* @__PURE__ */e(Wu,{chartType:t})]});}function Yu(){const t=T(o=>!zt(o.card.config)),a=T(o=>{var c,d;return((d=(c=o.card.preferences)==null?void 0:c.sqlKpiValue)==null?void 0:d.comparisonPolarity)??Gl;}),s=T(o=>o.actions.setCardPreferences),r=o=>{const c=T.getState().card;s(gl(c,{kind:"sqlKpiValue"},o).preferences??{});};return/* @__PURE__ */n("div",{className:"space-y-6 px-6 py-4",children:[/* @__PURE__ */e(ys,{chartType:"kpi"}),/* @__PURE__ */e("section",{children:/* @__PURE__ */e(Hu,{})}),t&&/* @__PURE__ */n("section",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{htmlFor:"query-kpi-favorable-direction",className:"text-xs",children:"Favorable direction"}),/* @__PURE__ */n(ae,{value:a,onValueChange:o=>r(o),children:[/* @__PURE__ */e(ne,{id:"query-kpi-favorable-direction",className:"h-8 w-full text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */n(se,{children:[/* @__PURE__ */e(H,{value:"higher_is_better",children:"Higher is better"}),/* @__PURE__ */e(H,{value:"lower_is_better",children:"Lower is better"}),/* @__PURE__ */e(H,{value:"neutral",children:"Neutral"})]})]}),/* @__PURE__ */e("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"Applies when the query returns current and comparison values."})]})]});}function Xu(t){return t.kind==="dashboard"?{kind:"inherit"}:t;}function Ns(t,a){var s,r;return br(t)&&((r=(s=t.config)==null?void 0:s.metricColumns)==null?void 0:r[0])===a;}function Cs(t,a){var r,o;const s=Nr({metricComparison:a.comparison,inheritGlobalComparison:(r=t.preferences)==null?void 0:r.inheritGlobalComparison,hidden:Cr((o=t.preferences)==null?void 0:o.comparisonPresentation)});return s.state==="follow"?{kind:"dashboard"}:s.state==="off"?{kind:"off"}:s.spec;}function Ju({card:t,metric:a,options:s,dates:r,otherMetric:o,onChange:c}){var w,S;const{data:d}=$e(t),l=d==null?void 0:d.metadata,i=(w=Zr(l==null?void 0:l.comparisonMetadata,a))==null?void 0:w.output,v=bn(),u=Zu(l==null?void 0:l.dateContext,i==null?void 0:i.windowShape,v),p=(i==null?void 0:i.availability.status)==="available"&&i.comparisonWindow?hd(i.comparisonWindow):void 0,f=Ns(t,a)?{kind:"metric"}:Cs(t,a),m=b=>b.offered?void 0:b.reason,N=Object.values(s.comparison).some(b=>b.offered&&b.replaces==="transform");return/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(Tc,{value:f,shape:u,dashboard:{offered:!0},target:{offered:s.comparison.target.offered,reason:m(s.comparison.target)},...(o?{otherMetric:o}:{}),shiftRefusal:m(s.comparison.shift),dates:f.kind==="shift"||f.kind==="dashboard"?p:void 0,onChange:b=>c(Xu(b))}),N?/* @__PURE__ */e("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"A comparison replaces this metric's transform."}):null,f.kind==="shift"&&r.dateWindow==="none"?/* @__PURE__ */n("p",{className:"text-[11px] leading-4 text-muted-foreground",children:["Shows only while a date range applies to ",((S=r.comparisonDate)==null?void 0:S.label)??"its date","; none does yet."]}):null]});}function Zu(t,a,s){const r=(t==null?void 0:t.windows.filter(o=>!o.replaced))??[];return r.length===1?(r[0].relative?Yn({kind:"relative",window:r[0].relative}):void 0)??(r[0].window?Yn({kind:"resolved",window:r[0].window,calendar:s}):a):a;}function em({card:t}){var v;const a=bn(),s=kc(t),r=xe(u=>u.dashboard),o=xe(u=>u.semanticExecutionPayload),{handleMetricComparisonChange:c}=on(t),d=X(()=>Pd(t,Sd(s,Td(r,o,a)),a),[t,s,r,o,a]),l=((v=t.config)==null?void 0:v.metricColumns)??[],i=xl("metric",l);return/* @__PURE__ */e("div",{className:"space-y-4",children:l.map((u,p)=>{const f=i[p]?bl(t,i[p],d):void 0;if(!f||!Object.values(f.comparison).some(N=>N.offered))return null;const m=f.comparison.metric.offered?l[1]:void 0;return/* @__PURE__ */n("div",{className:"space-y-2","data-role":"measure-comparison",children:[/* @__PURE__ */e("div",{className:"text-[12px] font-medium",children:u.label||u.name}),/* @__PURE__ */e(Ju,{card:t,metric:u,options:f,dates:d,...(m?{otherMetric:{name:m.label||m.name}}:{}),onChange:N=>c(p,N,d)})]},u.id??p);})});}function rr({card:t}){var o;const{handleMetricComparisonPolarityChange:a}=on(t),r=(((o=t.config)==null?void 0:o.metricColumns)??[]).map((c,d)=>({metric:c,index:d})).filter(({metric:c})=>Ns(t,c)||Cs(t,c).kind!=="off");return r.length?/* @__PURE__ */e("div",{className:"space-y-2",children:r.map(({metric:c,index:d})=>/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium text-muted-foreground",children:r.length===1?"Higher is":`Higher is · ${c.label||c.name}`}),/* @__PURE__ */n(ae,{value:es(c),disabled:!!c.semanticComparisonPolarity,onValueChange:l=>a(d,l),children:[/* @__PURE__ */e(ne,{size:"xs",className:"w-full",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */n(se,{children:[/* @__PURE__ */e(H,{value:"higher_is_better",children:"Better"}),/* @__PURE__ */e(H,{value:"lower_is_better",children:"Worse"}),/* @__PURE__ */e(H,{value:"neutral",children:"Neither"})]})]}),c.semanticComparisonPolarity?/* @__PURE__ */e("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"Governed by this metric's semantic definition."}):null]},c.id??d))}):null;}const tm={green:"#16a34a",red:"#dc2626",neutral:"#6b7280"};function am(t){return t&&(tm[t]??t);}function nm({value:t,onChange:a,showPosition:s=!1,polarity:r,direction:o}){const c=t.colors||{},d=l=>r==="higher_is_better"?l?" (good)":" (bad)":r==="lower_is_better"?l?" (bad)":" (good)":"";return/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Shown as"}),/* @__PURE__ */e(Ic,{fill:!0,label:"Shown as",value:t.displayMode||"difference",options:[{value:"percent_change",label:"Change %"},{value:"difference",label:"Change"},{value:"both",label:"Both"},{value:"ratio",label:"Ratio",title:"Current ÷ comparison"}],onChange:l=>a({displayMode:l})})]}),(t.displayMode||"difference")!=="difference"?/* @__PURE__ */n("div",{className:"flex items-center justify-between gap-3",children:[/* @__PURE__ */e("div",{children:/* @__PURE__ */e(L,{htmlFor:"comparison-precision",className:"text-xs",children:"Decimals"})}),/* @__PURE__ */e(Ct,{id:"comparison-precision",type:"number",min:0,max:6,step:1,value:t.precision??"",placeholder:"Auto",onChange:l=>{if(l.target.value===""){a({precision:void 0});return;}const i=Number(l.target.value);Number.isInteger(i)&&i>=0&&i<=6&&a({precision:i});},size:"xs",className:"w-16"})]}):null,/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium text-muted-foreground",children:"Indicator"}),/* @__PURE__ */n(ae,{value:t.indicatorStyle||"arrow_badge",onValueChange:l=>a({indicatorStyle:l}),children:[/* @__PURE__ */e(ne,{className:"h-7 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */n(se,{children:[/* @__PURE__ */e(H,{value:"arrow_badge",children:"Arrow + badge"}),/* @__PURE__ */e(H,{value:"arrow",children:"Arrow"}),/* @__PURE__ */e(H,{value:"badge",children:"Badge"}),/* @__PURE__ */e(H,{value:"none",children:"None"})]})]})]}),s&&/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Position"}),/* @__PURE__ */n(ae,{value:t.position||"right",onValueChange:l=>a({position:l}),children:[/* @__PURE__ */e(ne,{className:"h-7 w-24 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */n(se,{children:[/* @__PURE__ */e(H,{value:"right",children:"Right"}),/* @__PURE__ */e(H,{value:"left",children:"Left"}),/* @__PURE__ */e(H,{value:"top",children:"Top"})]})]})]}),o,/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{htmlFor:"comparison-color",className:"text-xs",children:"Colors"}),/* @__PURE__ */e(we,{id:"comparison-color",size:"xs",checked:t.showColor!==!1,onCheckedChange:l=>a({showColor:l})})]}),t.showColor!==!1&&/* @__PURE__ */e("div",{className:"space-y-1.5",children:[["increase",`Up${d(!0)}`,"#16a34a"],["decrease",`Down${d(!1)}`,"#dc2626"],["neutral","No change","#6b7280"]].map(([l,i,v])=>/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e("span",{className:"w-24 shrink-0 text-xs text-muted-foreground",children:i}),/* @__PURE__ */e(Ba,{value:am(c[l]||v),onChange:u=>a({colors:{...c,[l]:u||v}}),defaultValue:v,ariaLabel:`${i} color`,allowEmpty:!1})]},l))}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),t.conditionalLabel?/* @__PURE__ */e("div",{className:"space-y-1.5",children:[["increase","Increase"],["decrease","Decrease"],["neutral","No change"]].map(([l,i])=>{var v;return/* @__PURE__ */e(Ct,{"aria-label":`${i} label`,value:((v=t.conditionalLabels)==null?void 0:v[l])||i,onChange:u=>a({conditionalLabels:{...t.conditionalLabels,[l]:u.target.value}}),className:"h-7 text-xs"},l);})}):/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(Ct,{"aria-label":"Comparison label",value:t.labelName&&t.labelName!=="Previous"?t.labelName:"",onChange:l=>a({labelName:l.target.value}),placeholder:"The comparison's own words",className:"h-7 text-xs"}),/* @__PURE__ */e("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"Empty: the comparison's own words, which follow the Date filter."})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between pt-1",children:[/* @__PURE__ */e(L,{htmlFor:"comparison-conditional-label",className:"text-xs",children:"Different label per direction"}),/* @__PURE__ */e(we,{id:"comparison-conditional-label",size:"xs",checked:t.conditionalLabel===!0,onCheckedChange:l=>a({conditionalLabel:l})})]})]})]});}function ws({cardType:t}){var p,f;const a=T(m=>m.card),{setCardPreferences:s}=he(),r=((p=a.config)==null?void 0:p.metricColumns)||[],o=((f=a.preferences)==null?void 0:f.comparisonPresentation)||{},c=m=>s(yl(a.preferences,m)),d=Cr(o),l=br({...a,type:t}),i=r.filter(m=>{var N;return Nr({metricComparison:m.comparison,inheritGlobalComparison:(N=a.preferences)==null?void 0:N.inheritGlobalComparison,hidden:d}).state!=="off";}),v=i.length>0||l,u=vl.includes(t);return/* @__PURE__ */n("div",{className:"space-y-4",children:[/* @__PURE__ */e(em,{card:a}),v&&u?/* @__PURE__ */e(nm,{value:o,onChange:c,showPosition:l,direction:/* @__PURE__ */e(rr,{card:a}),polarity:es((l?r[0]:i[0])??r[0])}):v?/* @__PURE__ */e(rr,{card:a}):null]});}function rm(){const t=Ve();return Nl.includes(t)?/* @__PURE__ */n(Se,{value:"comparison",className:"border-none",children:[/* @__PURE__ */e(Te,{className:"flex items-center gap-2 py-2 text-[12px] hover:no-underline [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Ec,{className:"h-3.5 w-3.5 text-foreground/60"}),/* @__PURE__ */e("span",{children:"Comparison"})]})}),/* @__PURE__ */e(ke,{className:"pb-4 pt-2",children:/* @__PURE__ */e(ws,{cardType:t})})]}):null;}const sm={surface:"dashboard",kind:"table"};function Ss({cardType:t,queryOutput:a,focusSection:s,focusRequestId:r}){var ie,Q;const o=T(q=>q.card),c=T(q=>q.queryResultColumns),d=T(q=>q.queryResultColumnKeyMap),l=T(q=>{var te;return(te=q.card)==null?void 0:te.preferences;}),i=l==null?void 0:l.tablePrefs,v=T(q=>q.actions.setCardPreferences),u=T(q=>q.queryResultColumnMeta),p=t??o.type,f=a?[...(a.keys??[])]:c,m=a?a.columnKeyMap:d,N=a?a.resultColumns:u,w=o.type===p?o:{...o,type:p},S=ui(w,f,m,N),b=mi(w,f),y=p==="matrixTable"||hi(p),R=p==="table",x=p==="table",D=o?Wn(o):[],B=!!o&&Wn({...o,type:p}).includes("columns"),$=D.includes("columnFilters"),j=D.includes("search"),k=x||B||$,O=((ie=S[0])==null?void 0:ie.value)||"",A=Cl(w),F=wl(w),[K,E]=Y("style");ve(()=>{if(s==="style"){E("style");return;}if(s==="columns"&&k){E("columns");return;}s==="conditional-formatting"&&y&&E("conditional-formatting");},[k,y,r,s]);const h=o?Sl(o):!1,I=q=>{v({...l,tablePrefs:{...i,tableStyle:{...(i==null?void 0:i.tableStyle),wrapText:q}}});},{style:g}=Fc(sm),C=(q,te)=>{v(An(l,{measures:{[q]:te}}));},M=q=>{v(An(l,{row:q}));},z=(q,te)=>{v(kl({preferences:l},q,{hidden:!te}).preferences??{});},_=q=>{v(va(l,"columns",q));},P=q=>{v(va(l,"columnFilters",q));},V=q=>{v(va(l,"search",q));},G=()=>{v(Il({preferences:l}).preferences??{});},ee=h?/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e("div",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Comparison"}),/* @__PURE__ */e(ws,{cardType:"table"})]}):null;return/* @__PURE__ */e("div",{className:"px-4 py-3",children:/* @__PURE__ */n(ft,{value:K,onValueChange:q=>E(q),className:"space-y-4",children:[/* @__PURE__ */n(gt,{variant:"underline",children:[/* @__PURE__ */e(Ke,{value:"style",children:"Appearance"}),k?/* @__PURE__ */e(Ke,{value:"columns",children:"Columns"}):null,/* @__PURE__ */e(Ke,{value:"conditional-formatting",disabled:!y,children:"Conditional formatting"})]}),/* @__PURE__ */n(We,{value:"style",className:"mt-0",children:[R?/* @__PURE__ */e(pi,{wrapText:((Q=i==null?void 0:i.tableStyle)==null?void 0:Q.wrapText)??g.cell.wrap,onWrapTextChange:I,totals:A?{enabled:F,onEnabledChange:M,measures:Tl(w),onMeasureTotalChange:C}:void 0,extraSection:ee}):ee,p==="matrixTable"&&/* @__PURE__ */e(Ka,{section:"table"})]}),/* @__PURE__ */n(We,{value:"columns",className:"mt-0 space-y-4",children:[B?/* @__PURE__ */n("div",{className:"flex items-start justify-between gap-3",children:[/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */e(L,{htmlFor:"allow-viewer-column-customization",className:"text-xs",children:"Let viewers customize columns"}),/* @__PURE__ */e("p",{className:"mt-0.5 text-[12px] leading-5 text-muted-foreground",children:"Viewers can hide, reorder and rename columns for themselves, and their changes are remembered. Sorting works either way. Their changes never affect anyone else."})]}),/* @__PURE__ */e(we,{id:"allow-viewer-column-customization",size:"xs",checked:(i==null?void 0:i.allowViewerColumnCustomization)!==!1,onCheckedChange:_})]}):null,$?/* @__PURE__ */n("div",{className:"flex items-start justify-between gap-3",children:[/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */e(L,{htmlFor:"allow-viewer-column-filters",className:"text-xs",children:"Let viewers filter columns"}),/* @__PURE__ */n("p",{className:"mt-0.5 text-[12px] leading-5 text-muted-foreground",children:[p==="matrixTable"?"Viewers can filter any row or column level from its menu, for this card only.":"Viewers can filter any column from its header, for this card only."," ","Their filters never affect anyone else, and a saved view keeps them."]})]}),/* @__PURE__ */e(we,{id:"allow-viewer-column-filters",size:"xs",checked:(i==null?void 0:i.allowViewerColumnFilters)!==!1,onCheckedChange:P})]}):null,j?/* @__PURE__ */n("div",{className:"flex items-start justify-between gap-3",children:[/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */e(L,{htmlFor:"allow-viewer-search",className:"text-xs",children:"Let viewers search"}),/* @__PURE__ */e("p",{className:"mt-0.5 text-[12px] leading-5 text-muted-foreground",children:"Viewers can search the table's text columns, for this card only and for their visit."})]}),/* @__PURE__ */e(we,{id:"allow-viewer-search",size:"xs",checked:(i==null?void 0:i.allowViewerSearch)!==!1,onCheckedChange:V})]}):null,x?/* @__PURE__ */e(fi,{columns:b,columnVisibility:i==null?void 0:i.columnVisibility,onColumnVisibilityChange:z,onShowAllColumns:G}):null]}),/* @__PURE__ */e(We,{value:"conditional-formatting",className:"mt-0",children:p==="matrixTable"?/* @__PURE__ */e(Ka,{section:"conditional-formatting"}):y?O?/* @__PURE__ */e(lm,{columnId:O,availableColumns:S}):/* @__PURE__ */e("p",{className:"py-6 text-center text-[12px] text-muted-foreground",children:"Run the query to configure conditional formatting."}):/* @__PURE__ */e("p",{className:"py-6 text-center text-[12px] text-muted-foreground",children:"Conditional formatting is available for table and detail table cards."})})]})});}function lm({columnId:t,availableColumns:a}){const s=T(d=>d.card),r=T(d=>d.actions.updateConditionalRules),{rules:o,onChange:c}=Lr(s.id,xr(s),r);return/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(_r,{cardId:s.id}),/* @__PURE__ */e(Vr,{columnId:t,availableColumns:a,conditionalRules:o,onConditionalRulesChange:c,startRulesWithNoTrigger:!0})]});}function om(){var o;const t=T(c=>c.card.preferences),{setCardPreferences:a}=T(c=>c.actions),s=(o=t==null?void 0:t.textVisualOptions)!=null&&o.isDynamicText?"dynamic":"static";function r(c){a({...t,textVisualOptions:{...(t==null?void 0:t.textVisualOptions),isDynamicText:c==="dynamic"}});}return/* @__PURE__ */e(ft,{value:s,onValueChange:r,children:/* @__PURE__ */n(gt,{variant:"underline",children:[/* @__PURE__ */e(Ke,{value:"static",children:"Static"}),/* @__PURE__ */e(Ke,{value:"dynamic",children:"Dynamic"})]})});}function im(){return/* @__PURE__ */n("div",{className:"space-y-2 px-6 py-4",children:[/* @__PURE__ */e("div",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Text mode"}),/* @__PURE__ */e(om,{}),/* @__PURE__ */e("p",{className:"pt-1 text-[12px] leading-[1.55] text-muted-foreground",children:"Static text is authored inline. Dynamic text reads from the first cell of the card's query."})]});}function cm({color:t,onColorChange:a,onClose:s}){const[r,o]=Y(0),[c,d]=Y(100),[l,i]=Y(50),[v,u]=Y(t);ve(()=>{const S=sr(t);if(S){const b=lr(S.r,S.g,S.b);o(b.h),d(b.s),i(b.l),u(t);}},[t]);const p=S=>{o(S),m(S,c,l);},f=S=>{const b=S.currentTarget.getBoundingClientRect(),y=Math.max(0,Math.min(1,(S.clientX-b.left)/b.width)),R=Math.max(0,Math.min(1,(S.clientY-b.top)/b.height)),x=y*100,D=(1-R)*100;d(x),i(D),m(r,x,D);},m=(S,b,y)=>{const R=um(S,b,y),x=dm(R.r,R.g,R.b);u(x);},N=S=>{if(u(S),/^#[0-9A-Fa-f]{6}$/.test(S)){const b=sr(S);if(b){const y=lr(b.r,b.g,b.b);o(y.h),d(y.s),i(y.l);}}},w=()=>{/^#[0-9A-Fa-f]{6}$/.test(v)&&(a(v),s());};return/* @__PURE__ */n("div",{className:"p-4 space-y-4 w-[320px]",children:[/* @__PURE__ */n("div",{className:"relative h-[200px] rounded cursor-crosshair",style:{background:`hsl(${r}, 100%, 50%)`},onClick:f,onMouseMove:S=>{S.buttons===1&&f(S);},children:[/* @__PURE__ */e("div",{className:"absolute inset-0 rounded",style:{background:"linear-gradient(to right, white, transparent)"}}),/* @__PURE__ */e("div",{className:"absolute inset-0 rounded",style:{background:"linear-gradient(to bottom, transparent, black)"}}),/* @__PURE__ */e("div",{className:"absolute w-4 h-4 -ml-2 -mt-2 rounded-full border-2 border-white shadow-md",style:{left:`${c}%`,top:`${100-l}%`,backgroundColor:v}})]}),/* @__PURE__ */e("div",{className:"space-y-2",children:/* @__PURE__ */e("input",{type:"range",min:"0",max:"360",value:r,onChange:S=>p(Number(S.target.value)),className:"w-full h-4 rounded-lg appearance-none cursor-pointer",style:{background:"linear-gradient(to right, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000)"}})}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(L,{children:"HEX"}),/* @__PURE__ */e(Ct,{value:v,onChange:S=>N(S.target.value),placeholder:"#000000",className:"font-mono"})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-4",children:[/* @__PURE__ */n("div",{className:"text-center",children:[/* @__PURE__ */e("div",{className:"w-12 h-12 rounded-full border shadow-sm",style:{backgroundColor:t}}),/* @__PURE__ */e("span",{className:"text-xs text-muted-foreground mt-1",children:"CURRENT"})]}),/* @__PURE__ */n("div",{className:"text-center",children:[/* @__PURE__ */e("div",{className:"w-12 h-12 rounded-full border shadow-sm",style:{backgroundColor:v}}),/* @__PURE__ */e("span",{className:"text-xs text-muted-foreground mt-1",children:"NEW"})]})]}),/* @__PURE__ */n("div",{className:"flex gap-2 justify-end",children:[/* @__PURE__ */e(ue,{variant:"outline",onClick:s,children:"Cancel"}),/* @__PURE__ */e(ue,{onClick:w,children:"OK"})]})]});}function sr(t){const a=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return a?{r:parseInt(a[1],16),g:parseInt(a[2],16),b:parseInt(a[3],16)}:null;}function dm(t,a,s){return"#"+((1<<24)+(t<<16)+(a<<8)+s).toString(16).slice(1);}function lr(t,a,s){t/=255,a/=255,s/=255;const r=Math.max(t,a,s),o=Math.min(t,a,s);let c=0,d=0;const l=(r+o)/2;if(r!==o){const i=r-o;switch(d=l>0.5?i/(2-r-o):i/(r+o),r){case t:c=((a-s)/i+(a<s?6:0))/6;break;case a:c=((s-t)/i+2)/6;break;case s:c=((t-a)/i+4)/6;break;}}return{h:Math.round(c*360),s:Math.round(d*100),l:Math.round(l*100)};}function um(t,a,s){t/=360,a/=100,s/=100;let r,o,c;if(a===0)r=o=c=s;else{const d=(v,u,p)=>(p<0&&(p+=1),p>1&&(p-=1),p<0.16666666666666666?v+(u-v)*6*p:p<0.5?u:p<0.6666666666666666?v+(u-v)*(0.6666666666666666-p)*6:v),l=s<0.5?s*(1+a):s+a-s*a,i=2*s-l;r=d(i,l,t+1/3),o=d(i,l,t),c=d(i,l,t-1/3);}return{r:Math.round(r*255),g:Math.round(o*255),b:Math.round(c*255)};}const mm=["#000000","#ffffff","#6b7280","#dc2626","#ea580c","#ca8a04","#16a34a","#0891b2","#2563eb","#7c3aed","#c026d3","#e11d48","#0f172a","#f3f4f6","#fbbf24"];function hm(){var D,B,$,j,k,O,A,F,K,E;const t=T(h=>h.card),a=T(h=>{var I;return(I=h.card)==null?void 0:I.preferences;}),s=Ve(),{setCardPreferences:r,updateCardInFrame:o}=he(),c=X(()=>s!==t.type?{...t,type:s}:t,[t,s]),{data:d}=$e(c),[l,i]=Y({}),[v,u]=Y(null),[p,f]=Y(null),m=X(()=>{var C,M,z,_,P,V,G;if(!(d!=null&&d.records)||d.records.length===0)return[];const h=s==="stackedBar"||s==="stackedLine",I=s==="bar"||s==="line"||s==="horizontalBar"||s==="bullet"||s==="combo"||s==="area"||s==="stackedArea",g=((C=t==null?void 0:t.config)==null?void 0:C.pivotByColumns)&&t.config.pivotByColumns.length>0;if((h||I)&&g){if(d.pivotSchema&&Array.isArray(d.pivotSchema)){const ee=/* @__PURE__ */new Set();return d.pivotSchema.forEach(ie=>{ie.alias&&ee.add(ie.alias);}),Array.from(ee);}if(d.records.length>0){const ee=d.records[0],ie=Object.keys(ee),Q=/* @__PURE__ */new Set();(M=t==null?void 0:t.config)!=null&&M.groupByColumns&&t.config.groupByColumns.forEach(ce=>{Q.add(ce.label||ce.name),Q.add(ce.alias||ce.name);});const q=/* @__PURE__ */new Set();return(z=t==null?void 0:t.config)!=null&&z.metricColumns&&t.config.metricColumns.forEach(ce=>{const me=ce.alias||ce.name;q.add(me),q.add(`${me}_count`),q.add(`${me}_sum`),q.add(`${me}_avg`),q.add(`${me}_min`),q.add(`${me}_max`);const le=ce.entityName||ce.qualifiedEntityName;le&&(q.add(`${le}_${me}`),q.add(`${le}_${me}_count`));}),ie.filter(ce=>!Q.has(ce)&&!q.has(ce));}}if((I||h)&&!g&&(P=(_=t==null?void 0:t.config)==null?void 0:_.metricColumns)!=null&&P.length)return t.config.metricColumns.map(ee=>ee.alias||ee.label||ee.name);if((G=(V=t==null?void 0:t.config)==null?void 0:V.groupByColumns)!=null&&G.length){const ee=t.config.groupByColumns[0],ie=ee.label||ee.name,Q=/* @__PURE__ */new Set();return d.records.forEach(q=>{const te=q[ie];te!=null&&Q.add(String(te));}),Array.from(Q);}return[];},[d,(D=t==null?void 0:t.config)==null?void 0:D.groupByColumns,(B=t==null?void 0:t.config)==null?void 0:B.pivotByColumns,($=t==null?void 0:t.config)==null?void 0:$.metricColumns,s]),N=xn().palette;ve(()=>{const h={};m.forEach((I,g)=>{h[I]=Hn(I,g,N,a==null?void 0:a.colorConfig);}),i(h);},[m,a==null?void 0:a.colorConfig,N]);const w=(h,I)=>{var z;const g={...l,[h]:I};i(g);const C={...(a||{}),colorConfig:{...(a==null?void 0:a.colorConfig),segments:{...((z=a==null?void 0:a.colorConfig)==null?void 0:z.segments),[h]:I}}};r(C);const M={...t,preferences:C};o(M);},S=(h,I)=>{var P;const g=N[I%N.length],{[h]:C,...M}=((P=a==null?void 0:a.colorConfig)==null?void 0:P.segments)||{},z={...(a||{}),colorConfig:{segments:M}};r(z);const _={...t,preferences:z};o(_),i(V=>({...V,[h]:g}));};if(!m.length||!((t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine"?((k=(j=t==null?void 0:t.config)==null?void 0:j.groupByColumns)==null?void 0:k.length)||((A=(O=t==null?void 0:t.config)==null?void 0:O.pivotByColumns)==null?void 0:A.length):(K=(F=t==null?void 0:t.config)==null?void 0:F.groupByColumns)==null?void 0:K.length)||["table","kpi","text","custom","heatmap"].includes(s))return null;const R=()=>{const h={...(a||{}),colorConfig:{segments:{}}};r(h);const I={...t,preferences:h};o(I);const g={};m.forEach((C,M)=>{g[C]=Hn(C,M,N);}),i(g);},x=Object.keys(((E=a==null?void 0:a.colorConfig)==null?void 0:E.segments)||{}).length>0;return/* @__PURE__ */n(Se,{value:"colors",className:"border-b-0",children:[/* @__PURE__ */e(Te,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Dd,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Colors"})]})}),/* @__PURE__ */e(ke,{className:"",children:/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */e("div",{className:"space-y-2",children:/* @__PURE__ */e("div",{className:"flex items-center justify-between",children:x&&/* @__PURE__ */n("button",{className:"ml-auto flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",onClick:R,children:[/* @__PURE__ */e(Qn,{className:"h-3 w-3"}),"Reset All"]})})}),/* @__PURE__ */e("div",{className:"max-h-[200px] space-y-2 overflow-y-auto pr-1",children:m.map((h,I)=>{const g=l[h]===N[I%N.length],C=!g;return/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */n(st,{open:v===h,onOpenChange:M=>u(M?h:null),children:[/* @__PURE__ */e(xt,{asChild:!0,children:/* @__PURE__ */e("button",{className:"h-5 w-5 shrink-0 rounded border border-input shadow-sm transition-colors hover:border-gray-400 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",style:{backgroundColor:l[h]}})}),/* @__PURE__ */e(lt,{align:"start",className:"w-auto p-3",children:/* @__PURE__ */n("div",{className:"space-y-2.5",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e("p",{className:"text-xs font-medium text-muted-foreground",children:"Theme Colors"}),/* @__PURE__ */e("div",{className:"grid grid-cols-5 gap-1.5",children:N.slice(0,10).map((M,z)=>/* @__PURE__ */n("button",{className:W("relative h-5 w-5 rounded border-2 transition-all hover:scale-110",l[h]===M?"border-gray-900":"border-transparent"),style:{backgroundColor:M},onClick:()=>{w(h,M),u(null);},children:[z===I%N.length&&/* @__PURE__ */e("div",{className:"absolute inset-0 flex items-center justify-center",children:/* @__PURE__ */e("div",{className:"rounded-full bg-white/90 px-0.5 text-[8px] font-bold text-gray-900 shadow-sm",children:"D"})}),/* @__PURE__ */e("span",{className:"sr-only",children:M})]},`default-${z}`))})]}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e("p",{className:"text-xs font-medium text-muted-foreground",children:"Popular Colors"}),/* @__PURE__ */e("div",{className:"grid grid-cols-5 gap-1.5",children:mm.map((M,z)=>/* @__PURE__ */e("button",{className:W("h-5 w-5 rounded border transition-all hover:scale-110",l[h]===M?"border-2 border-gray-900":M==="#ffffff"?"border border-gray-300":"border border-transparent"),style:{backgroundColor:M},onClick:()=>{w(h,M),u(null);},children:/* @__PURE__ */e("span",{className:"sr-only",children:M})},`preset-${z}`))})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between gap-2 pt-1",children:[/* @__PURE__ */e("button",{className:"text-sm font-medium text-blue-600 hover:text-blue-700",onClick:()=>{f({value:h,color:l[h]}),u(null);},children:"Custom color"}),!g&&/* @__PURE__ */n("button",{className:"flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",onClick:()=>{S(h,I),u(null);},children:[/* @__PURE__ */e(Qn,{className:"h-3 w-3"}),"Reset"]})]})]})})]}),/* @__PURE__ */e("span",{className:"flex-1 truncate text-sm",children:h}),C&&/* @__PURE__ */e("span",{className:"text-xs text-muted-foreground",children:"(custom)"})]},h);})}),p&&/* @__PURE__ */n("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[/* @__PURE__ */e("div",{className:"absolute inset-0 bg-black/50",onClick:()=>f(null)}),/* @__PURE__ */e("div",{className:"relative rounded-lg bg-white shadow-lg",children:/* @__PURE__ */e(cm,{color:p.color,onColorChange:h=>{w(p.value,h),f(null);},onClose:()=>f(null)})})]})]})})]});}function Oa({axis:t,label:a,type:s,config:r,onChange:o,defaultTitle:c,hidePosition:d}){var S,b,y,R,x,D,B,$,j,k,O,A,F,K;const[l,i]=Y(!!(r!=null&&r.valueFormat)),v=l||!!(r!=null&&r.valueFormat),u=(E,h)=>{o({...(r??{}),[E]:h});},p=(E,h)=>{var C;const g=E==="enabled"&&h===!0&&!((C=r==null?void 0:r.name)!=null&&C.text)&&c;o(Fl(r,{[E]:h,...(g?{text:c}:{})}));},f=(E,h)=>{var I,g;o({...(r??{}),labels:{enabled:E==="enabled"?h:((I=r==null?void 0:r.labels)==null?void 0:I.enabled)??!0,rotation:E==="rotation"?h:(g=r==null?void 0:r.labels)==null?void 0:g.rotation}});},m=(E,h)=>{o(Ol(r,{[E]:h===""?null:Number(h)}));},N=t==="x"?["auto","top","bottom"]:["auto","left","right"],w=["auto","0","45","90","-45","-90"];return/* @__PURE__ */n(Se,{value:`${t}-axis`,className:"border-b-0",children:[/* @__PURE__ */n("div",{className:"flex w-full items-center justify-between gap-2",children:[/* @__PURE__ */e(Te,{className:"flex grow items-center justify-between gap-3 py-2 text-[12px] font-medium hover:no-underline",children:/* @__PURE__ */e("div",{className:"flex grow items-center justify-between gap-2",children:/* @__PURE__ */e("span",{children:a})})}),/* @__PURE__ */e(we,{size:"sm",checked:(r==null?void 0:r.enabled)!==!1,onCheckedChange:E=>u("enabled",E),onClick:E=>E.stopPropagation()})]}),/* @__PURE__ */n(ke,{className:"space-y-4 pt-2",children:[/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Lt,{id:`${t}-title-enabled`,checked:((S=r==null?void 0:r.name)==null?void 0:S.enabled)??!1,onCheckedChange:E=>p("enabled",E===!0)}),/* @__PURE__ */e(L,{htmlFor:`${t}-title-enabled`,className:"text-xs font-medium cursor-pointer",children:"TITLE"})]}),((b=r==null?void 0:r.name)==null?void 0:b.enabled)&&/* @__PURE__ */n("div",{className:"space-y-2 pl-6",children:[/* @__PURE__ */e(Ze,{placeholder:`${a} title`,value:((y=r==null?void 0:r.name)==null?void 0:y.text)||"",onSave:E=>p("text",E),className:""}),/* @__PURE__ */n("div",{className:"flex items-center gap-3",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Size"}),/* @__PURE__ */e("div",{className:"w-14",children:/* @__PURE__ */e(Ze,{type:"number",placeholder:"12",value:String(((R=r==null?void 0:r.name)==null?void 0:R.fontSize)||12),onSave:E=>p("fontSize",Number(E)||12),className:""})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Weight"}),/* @__PURE__ */n(ae,{value:((x=r==null?void 0:r.name)==null?void 0:x.fontWeight)||"normal",onValueChange:E=>p("fontWeight",E),children:[/* @__PURE__ */e(ne,{className:"h-7 w-20 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */n(se,{children:[/* @__PURE__ */e(H,{value:"normal",className:"text-xs",children:"Normal"}),/* @__PURE__ */e(H,{value:"bold",className:"text-xs",children:"Bold"})]})]})]})]})]})]}),!d&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"POSITION"}),/* @__PURE__ */n(ae,{value:(r==null?void 0:r.position)||"auto",onValueChange:E=>u("position",E),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:N.map(E=>/* @__PURE__ */e(H,{value:E,className:"text-xs",children:E==="auto"?"Auto (Default)":Ge(E)},E))})]})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"LABELS"}),/* @__PURE__ */e(we,{size:"sm",checked:((D=r==null?void 0:r.labels)==null?void 0:D.enabled)!==!1,onCheckedChange:E=>f("enabled",E)})]}),((B=r==null?void 0:r.labels)==null?void 0:B.enabled)!==!1&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Rotation"}),/* @__PURE__ */n(ae,{value:String((($=r==null?void 0:r.labels)==null?void 0:$.rotation)||"auto"),onValueChange:E=>f("rotation",E==="auto"?"auto":Number(E)),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:w.map(E=>/* @__PURE__ */e(H,{value:E,className:"text-xs",children:E==="auto"?"Auto (Default)":`${E}°`},E))})]})]})]}),s==="value"&&/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"FORMAT"}),/* @__PURE__ */e("div",{className:"text-xs text-muted-foreground",children:"Inherit from the bound metric by default."})]}),/* @__PURE__ */e(we,{size:"sm",checked:v,onCheckedChange:E=>{if(i(E),!E){const{valueFormat:h,...I}=r??{};o(I);}}})]}),v&&/* @__PURE__ */e(Xt,{formatOptions:Cn(r==null?void 0:r.valueFormat)||{},onFormatOptionsChange:E=>o({...r,valueFormat:wn(E)}),showTitle:!1})]}),s==="value"&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"SCALE"}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(L,{className:"w-8 text-xs text-muted-foreground",children:"Min"}),/* @__PURE__ */e("div",{className:"flex-1",children:/* @__PURE__ */e(Ze,{type:"number",placeholder:"auto",value:((j=r==null?void 0:r.scale)==null?void 0:j.min)==="auto"||((k=r==null?void 0:r.scale)==null?void 0:k.min)===void 0?"":String(r.scale.min),onSave:E=>m("min",E),className:""})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(L,{className:"w-8 text-xs text-muted-foreground",children:"Max"}),/* @__PURE__ */e("div",{className:"flex-1",children:/* @__PURE__ */e(Ze,{type:"number",placeholder:"auto",value:((O=r==null?void 0:r.scale)==null?void 0:O.max)==="auto"||((A=r==null?void 0:r.scale)==null?void 0:A.max)===void 0?"":String(r.scale.max),onSave:E=>m("max",E),className:""})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(L,{className:"w-8 text-xs text-muted-foreground",children:"Step"}),/* @__PURE__ */e("div",{className:"flex-1",children:/* @__PURE__ */e(Ze,{type:"number",placeholder:"auto",value:((F=r==null?void 0:r.scale)==null?void 0:F.stepSize)==="auto"||((K=r==null?void 0:r.scale)==null?void 0:K.stepSize)===void 0?"":String(r.scale.stepSize),onSave:E=>m("stepSize",E),className:""})})]})]})]})]})]});}function Ma(t,a,s){var c,d,l;if(t==="x"){const i=(d=(c=a==null?void 0:a.config)==null?void 0:c.groupByColumns)==null?void 0:d[0];return(i==null?void 0:i.label)||(i==null?void 0:i.name)||"";}const r=((l=a==null?void 0:a.config)==null?void 0:l.metricColumns)||[],o=(s==null?void 0:s.datasetOptions)||[];if(t==="y"){const i=r.filter((v,u)=>{const p=o.find(f=>f.idx===u);return!p||p.yAxisId!=="y2";});return i.length===1&&(i[0].label||i[0].name)||"";}if(t==="y2"){const i=r.filter((v,u)=>{const p=o.find(f=>f.idx===u);return(p==null?void 0:p.yAxisId)==="y2";});return i.length===1&&(i[0].label||i[0].name)||"";}return"";}function pm(){const t=T(i=>i.card),a=T(i=>{var v;return(v=i.card)==null?void 0:v.preferences;}),{setCardPreferences:s,updateCardInFrame:r}=he(),o=Ve();if(!t||["tornado","pyramid","kpi","treemap"].includes(o))return null;const c=Oc.getAxisInfo(o,a);if(!c.hasXAxis&&!c.hasYAxis)return null;const d=(i,v)=>{let u;i==="x"?u="xAxisConfig":i==="y"?u="yAxisConfig":u="secondaryYAxisConfig";const p=El(a,u,v);s(p);const f={...t,preferences:p};r(f);},l=c.hasY2Axis&&o==="combo";return/* @__PURE__ */n(Se,{value:"axes",className:"border-b-0",children:[/* @__PURE__ */e(Te,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Gt,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Axes"})]})}),/* @__PURE__ */e(ke,{className:"pt-2",children:/* @__PURE__ */n(Yt,{type:"single",collapsible:!0,className:"w-full",children:[c.hasXAxis&&/* @__PURE__ */e(Oa,{axis:"x",label:"X-Axis",type:c.xAxisType,config:xa(Gn(o,"x"),a==null?void 0:a.xAxisConfig),onChange:i=>d("x",i),defaultTitle:Ma("x",t,a)}),c.hasYAxis&&/* @__PURE__ */e(Oa,{axis:"y",label:l?"Y-Axis (Left)":"Y-Axis",type:c.yAxisType,config:xa(Gn(o,"y"),a==null?void 0:a.yAxisConfig),onChange:i=>d("y",i),defaultTitle:Ma("y",t,a)}),l&&/* @__PURE__ */e(Oa,{axis:"y2",label:"Y2-Axis (Right)",type:"value",config:xa({enabled:!0,position:"right"},a==null?void 0:a.secondaryYAxisConfig),onChange:i=>d("y2",i),defaultTitle:Ma("y2",t,a),hidePosition:!0})]})})]});}function fm(){const t=T(p=>p.card),a=Ve(),s=T(p=>{var f,m,N,w;return(w=(N=(m=(f=p.card)==null?void 0:f.preferences)==null?void 0:m.chartOptions)==null?void 0:N.plugins)==null?void 0:w.legend;}),{setLegendOptions:r}=he();if(!t||!Mc(a))return null;const o=Rc(a),c=(o==null?void 0:o.display)??!0,d=(o==null?void 0:o.position)??"top",l=(o==null?void 0:o.align)??"center",i=(p,f)=>{const m={...s,[p]:f};r(m);},v=["top","bottom","left","right"],u=["start","center","end"];return/* @__PURE__ */n(Se,{value:"legend",className:"border-b-0",children:[/* @__PURE__ */e(Te,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(gi,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Legend"})]})}),/* @__PURE__ */e(ke,{className:"pt-2",children:/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Display"}),/* @__PURE__ */e(we,{size:"sm",checked:(s==null?void 0:s.display)??c,onCheckedChange:p=>i("display",p)})]}),((s==null?void 0:s.display)??c)&&/* @__PURE__ */n(be,{children:[/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Position"}),/* @__PURE__ */n(ae,{value:(s==null?void 0:s.position)||d,onValueChange:p=>i("position",p),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:v.map(p=>/* @__PURE__ */e(H,{value:p,className:"text-xs",children:Ge(p)},p))})]})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Alignment"}),/* @__PURE__ */n(ae,{value:(s==null?void 0:s.align)||l,onValueChange:p=>i("align",p),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:u.map(p=>/* @__PURE__ */e(H,{value:p,className:"text-xs",children:Ge(p)},p))})]})]})]})]})})]});}function gm(){var K,E,h,I,g;const t=T(C=>C.card),a=Ve(),s=T(C=>{var M,z;return(z=(M=C.card)==null?void 0:M.preferences)==null?void 0:z.dataLabelsConfig;}),r=T(C=>{var M;return(M=C.card)==null?void 0:M.preferences;}),{setCardPreferences:o,updateCardInFrame:c}=he(),[d,l]=Y(!!(s!=null&&s.valueFormat));if(!t||!Ml(a))return null;const i=a==="bullet"?((K=r==null?void 0:r.bulletConfig)==null?void 0:K.orientation)??(((E=r==null?void 0:r.chartOptions)==null?void 0:E.indexAxis)==="x"?"vertical":"horizontal"):void 0,v=i!=null?i==="horizontal":((h=r==null?void 0:r.chartOptions)==null?void 0:h.indexAxis)==="y",u=a==="stackedBar"||a==="stackedLine",p=a==="pie"||a==="doughnut"||a==="polarArea"||a==="funnel",f=a==="bubble"||a==="scatter",m=Rl(a,t.preferences),N=s??m,w=Al(a,t.preferences),S=(s==null?void 0:s.enabled)!==void 0?s.enabled:w,b=(C,M)=>{const _=(C==="enabled"?Pn({type:a,preferences:t.preferences},{show:M}).dataLabelsConfig:void 0)??{...Dn(s,m),[C]:M};C==="enabled"&&M&&f&&!_.position&&(_.position="bottom"),C==="position"&&f&&(_.position="bottom");const P={...(t.preferences||{}),dataLabelsConfig:_};o(P);const V={...t,preferences:P};c(V);},y=(C,M)=>{const z={...Dn(s,m),font:{...((s==null?void 0:s.font)||{}),[C]:M}},_={...(t.preferences||{}),dataLabelsConfig:z};o(_);const P={...t,preferences:_};c(P);},R=()=>{const C=a;return C==="stackedBar"||C==="stackedLine"||C==="pie"||C==="doughnut"?"center":v?"right":"top";},x=a!=="treemap"&&a!=="heatmap",D=a!=="treemap",B=R();let $=[];if(x)if(f)$=["bottom"];else if(u||p)$=["center"];else{const C=v?["center","left","right"]:["center","top","bottom"];$=["auto",...(a==="bullet"?C:C.filter(z=>z!==B)),"custom"];}const j=()=>Ge(B),k=["center","start","end"],O=["center","start","end","top","bottom"],A=d||!!(N!=null&&N.valueFormat),F=C=>{const M=Pn({type:a,preferences:t.preferences},{format:C??null});o(M),c({...t,preferences:M});};return/* @__PURE__ */n(Se,{value:"data-labels",className:"border-b-0",children:[/* @__PURE__ */e(Te,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(jd,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Data Labels"})]})}),/* @__PURE__ */e(ke,{className:"pt-2",children:/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Display"}),/* @__PURE__ */e(we,{size:"sm",checked:S,onCheckedChange:C=>b("enabled",C)})]}),S&&/* @__PURE__ */n(be,{children:[x&&!u&&!p&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Position"}),/* @__PURE__ */n(ae,{value:f?(N==null?void 0:N.position)||"bottom":(N==null?void 0:N.position)||"auto",onValueChange:C=>b("position",C),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:$.map(C=>/* @__PURE__ */e(H,{value:C,className:"text-xs",children:C==="auto"?j():C==="custom"?"Custom (Advanced)":Ge(C)},C))})]})]}),u&&/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Show Total"}),/* @__PURE__ */e(we,{size:"sm",checked:(s==null?void 0:s.showTotal)??!1,onCheckedChange:C=>b("showTotal",C)})]}),(N==null?void 0:N.position)==="custom"&&/* @__PURE__ */n("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground w-16",children:"Anchor"}),/* @__PURE__ */n(ae,{value:(N==null?void 0:N.anchor)||"center",onValueChange:C=>b("anchor",C),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs flex-1",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:k.map(C=>/* @__PURE__ */e(H,{value:C,className:"text-xs",children:Ge(C)},C))})]})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground w-16",children:"Align"}),/* @__PURE__ */n(ae,{value:String((N==null?void 0:N.align)||"center"),onValueChange:C=>b("align",C),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs flex-1",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:O.map(C=>/* @__PURE__ */e(H,{value:C,className:"text-xs",children:Ge(C)},C))})]})]})]}),/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Format"}),/* @__PURE__ */e("div",{className:"text-xs text-muted-foreground",children:"Keep this off to inherit from the bound metric."})]}),/* @__PURE__ */e(we,{size:"sm",checked:A,onCheckedChange:C=>{l(C),C||F(void 0);}})]}),A&&/* @__PURE__ */e(Xt,{formatOptions:Cn(N==null?void 0:N.valueFormat)||{},onFormatOptionsChange:C=>F(wn(C)),showTitle:!1})]}),D&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Appearance"}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground w-20",children:"Size"}),/* @__PURE__ */e("div",{className:"flex-1",children:/* @__PURE__ */e(Ze,{type:"number",placeholder:"12",value:String(((I=N==null?void 0:N.font)==null?void 0:I.size)||12),onSave:C=>y("size",Number(C)),className:""})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground w-20",children:"Weight"}),/* @__PURE__ */n(ae,{value:((g=N==null?void 0:N.font)==null?void 0:g.weight)||"normal",onValueChange:C=>y("weight",C),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs flex-1",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */n(se,{children:[/* @__PURE__ */e(H,{value:"normal",className:"text-xs",children:"Normal"}),/* @__PURE__ */e(H,{value:"bold",className:"text-xs",children:"Bold"})]})]})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground w-20",children:"Color"}),/* @__PURE__ */n(ae,{value:(N==null?void 0:N.color)==="auto"||!(N!=null&&N.color)?"auto":"custom",onValueChange:C=>{C==="auto"&&b("color","auto");},children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs flex-1",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */n(se,{children:[/* @__PURE__ */e(H,{value:"auto",className:"text-xs",children:"Auto (Smart Contrast)"}),/* @__PURE__ */e(H,{value:"custom",disabled:!0,className:"text-xs",children:"Custom (Coming Soon)"})]})]})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground w-20",children:"Rotation"}),/* @__PURE__ */e("div",{className:"flex-1",children:/* @__PURE__ */e(Ze,{type:"number",placeholder:"0",value:String((N==null?void 0:N.rotation)||0),onSave:C=>b("rotation",Number(C)),className:""})}),/* @__PURE__ */e("span",{className:"text-xs text-muted-foreground",children:"degrees"})]})]})]})]})})]});}function xm(){var c;const t=T(d=>{var l;return(l=d.card)==null?void 0:l.type;}),a=T(d=>{var l;return(l=d.card)==null?void 0:l.preferences;}),{setCardPreferences:s}=he();if(t!=="treemap")return null;const r=((c=a==null?void 0:a.chartOptions)==null?void 0:c.treemapColorMode)??"branch",o=d=>{const l={...(a||{}),chartOptions:{...(a==null?void 0:a.chartOptions),treemapColorMode:d}};s(l);};return/* @__PURE__ */n(Se,{value:"treemap-color-mode",className:"border-none",children:[/* @__PURE__ */e(Te,{className:"flex w-full items-center gap-2 py-3 text-[12px] font-medium hover:no-underline",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Mr,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Treemap Colors"})]})}),/* @__PURE__ */e(ke,{className:"space-y-4 border-t border-border bg-background/50 px-3 py-4 text-sm",children:/* @__PURE__ */n(vn,{value:r,onValueChange:d=>o(d??"branch"),className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"flex items-start gap-2 rounded-md border border-border px-3 py-2",children:[/* @__PURE__ */e(Bt,{id:"treemap-color-branch",value:"branch"}),/* @__PURE__ */n(L,{htmlFor:"treemap-color-branch",className:"flex flex-col text-sm font-normal leading-tight",children:[/* @__PURE__ */e("span",{className:"font-medium",children:"Shade by value (default)"}),/* @__PURE__ */e("span",{className:"text-xs text-muted-foreground",children:"Keeps parent hue and adjusts lightness based on the node's share within the branch."})]})]}),/* @__PURE__ */n("div",{className:"flex items-start gap-2 rounded-md border border-border px-3 py-2",children:[/* @__PURE__ */e(Bt,{id:"treemap-color-category",value:"category"}),/* @__PURE__ */n(L,{htmlFor:"treemap-color-category",className:"flex flex-col text-sm font-normal leading-tight",children:[/* @__PURE__ */e("span",{className:"font-medium",children:"Single color per category"}),/* @__PURE__ */e("span",{className:"text-xs text-muted-foreground",children:"Applies the top-level color to all descendants without lightening/darkening."})]})]})]})})]});}const bm=Object.keys(Xr);function vm(){const t=T(f=>f.card),a=T(f=>{var m;return(m=f.card)==null?void 0:m.preferences;}),{setCardPreferences:s}=he(),r=(t==null?void 0:t.type)==="heatmap",o=(a==null?void 0:a.heatmapConfig)||{},c=o.colorPalette??"green",d=o.legendPosition??"bottom",l=X(()=>o.colorRange&&o.colorRange[0]&&o.colorRange[1]?[o.colorRange[0],o.colorRange[1]]:[...ba],[o.colorRange]),i=f=>{const m={...o,...f};m.colorPalette!=="custom"?delete m.colorRange:(!m.colorRange||!m.colorRange[0]||!m.colorRange[1])&&(m.colorRange=[...ba]),s({...(a||{}),heatmapConfig:m});},v=f=>{i({colorPalette:f,colorRange:f==="custom"?o.colorRange??[...ba]:void 0});},u=(f,m)=>{const N=[...l];N[f]=m,i({colorPalette:"custom",colorRange:N});},p=f=>{i({legendPosition:f});};return r?/* @__PURE__ */n(Se,{value:"heatmap-color-config",className:"border-none",children:[/* @__PURE__ */e(Te,{className:"flex w-full items-center gap-2 py-3 text-[12px] font-medium hover:no-underline",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Qt,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Heatmap Settings"})]})}),/* @__PURE__ */n(ke,{className:"space-y-4 border-t border-border bg-background/50 px-3 py-4 text-sm",children:[/* @__PURE__ */n(vn,{value:c,onValueChange:f=>v(f??"blue"),className:"space-y-3",children:[bm.map(f=>{const m=Xr[f];return/* @__PURE__ */n("div",{className:"flex items-center gap-2 rounded-md border border-border px-3 py-2",children:[/* @__PURE__ */e(Bt,{id:`heatmap-${f}`,value:f}),/* @__PURE__ */n(L,{htmlFor:`heatmap-${f}`,className:"flex w-full flex-col gap-1 text-sm font-normal",children:[/* @__PURE__ */e("span",{className:"font-medium",children:m.label}),/* @__PURE__ */e("span",{className:"h-2 rounded-full",style:{background:`linear-gradient(90deg, ${m.start}, ${m.end})`}})]})]},f);}),/* @__PURE__ */n("div",{className:"flex flex-col gap-2 rounded-md border border-border px-3 py-2",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Bt,{id:"heatmap-custom",value:"custom"}),/* @__PURE__ */e(L,{htmlFor:"heatmap-custom",className:"text-sm font-medium",children:"Custom colors"})]}),c==="custom"&&/* @__PURE__ */n("div",{className:"flex flex-col gap-2 pl-6",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Ba,{value:l[0],onChange:f=>u(0,f??"#000000"),ariaLabel:"Start color",allowEmpty:!1}),/* @__PURE__ */e("span",{className:"text-[11px] text-muted-foreground",children:"Start color"})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Ba,{value:l[1],onChange:f=>u(1,f??"#000000"),ariaLabel:"End color",allowEmpty:!1}),/* @__PURE__ */e("span",{className:"text-[11px] text-muted-foreground",children:"End color"})]})]})]})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Color scale position"}),/* @__PURE__ */n(ae,{value:d,onValueChange:f=>p(f??"bottom"),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:["top","bottom","left","right"].map(f=>/* @__PURE__ */e(H,{value:f,className:"text-xs",children:f[0].toUpperCase()+f.slice(1)},f))})]})]})]})]}):null;}const or=["poor","satisfactory","good"];function ir(t){if(!t)return;const a={...t};return a.targetMetricKey||delete a.targetMetricKey,a.comparativeMetricKey||delete a.comparativeMetricKey,!a.targetValue&&a.targetValue!==0&&delete a.targetValue,(!a.rangeKeys||Object.keys(a.rangeKeys).length===0)&&delete a.rangeKeys,(!a.ranges||Object.keys(a.ranges).length===0)&&delete a.ranges,(!a.rangeLabels||Object.keys(a.rangeLabels).length===0)&&delete a.rangeLabels,a;}function ym(){var K,E;const t=T(h=>h.card.preferences),a=T(h=>h.card),s=T(h=>h.isDevMode),{setCardPreferences:r,setChartOrientation:o}=he(),c=X(()=>(t==null?void 0:t.bulletConfig)||{},[t==null?void 0:t.bulletConfig]),l=zt(a==null?void 0:a.config)&&!s,[i,v]=Y(c.showRanges??!1),[u,p]=Y(c.rangesArePercentages??!1),f=c.disableAutoComparative?!1:c.comparativeMetricKey!==void 0||!l,[m,N]=Y(f);ve(()=>{v(c.showRanges??!1);},[c.showRanges]),ve(()=>{p(c.rangesArePercentages??!1);},[c.rangesArePercentages]);const w=c.targetValue===void 0?"":String(c.targetValue);ve(()=>{const h=c.disableAutoComparative?!1:c.comparativeMetricKey!==void 0||!l;N(h);},[c.disableAutoComparative,c.comparativeMetricKey,l]);const S=X(()=>{var h,I;return((I=(h=a==null?void 0:a.config)==null?void 0:h.metricColumns)==null?void 0:I.map(g=>{const C=g.label||g.name||g.alias||"";return{value:C,label:C};}))||[];},[(K=a==null?void 0:a.config)==null?void 0:K.metricColumns]);ve(()=>{var P,V;if(!t||S.length===0)return;const h={};let I=!1;const g=(P=S[1])==null?void 0:P.value;!c.targetMetricKey&&g&&(h.targetMetricKey=g,I=!0);const C=(V=S[2])==null?void 0:V.value;!c.comparativeMetricKey&&!c.disableAutoComparative&&C&&(h.comparativeMetricKey=C,I=!0);const M=S.slice(3),z={...(c.rangeKeys||{})};let _=!1;if(or.forEach((G,ee)=>{!z[G]&&M[ee]&&(z[G]=M[ee].value,_=!0);}),_&&(h.rangeKeys=z,I=!0,c.showRanges===void 0&&(h.showRanges=!0)),I){const G=ir({...c,...h});r({...t,bulletConfig:G});}},[S,c,t,r]);const b=h=>{const I=ir({...c,...h});r({...t,bulletConfig:I});},y=(h,I)=>{const g={...(c.rangeKeys||{}),[h]:I.trim()};I.trim()||delete g[h],b({rangeKeys:Object.keys(g).length>0?g:void 0});},R=(h,I)=>{const g=I===""?void 0:Number(I),C={...(c.ranges||{})};g===void 0||Number.isNaN(g)?delete C[h]:C[h]=g,b({ranges:Object.keys(C).length?C:void 0});},x=h=>{if(h===""){b({targetValue:void 0});return;}const I=Number(h);b({targetValue:Number.isNaN(I)?void 0:I});},D=(h,I)=>{const g=I.trim(),C={...(c.rangeLabels||{})};g?C[h]=g:delete C[h],b({rangeLabels:Object.keys(C).length>0?C:void 0});},B=h=>{v(h),b({showRanges:h});},$=h=>{p(h),b({rangesArePercentages:h});},j=c.orientation||(((E=t==null?void 0:t.chartOptions)==null?void 0:E.indexAxis)==="y"?"horizontal":"vertical"),k=h=>{b({orientation:h}),o(h==="horizontal"?"y":"x");},O=[{value:"__none",label:"None"},...S.map(h=>({value:h.value,label:h.label}))],A=O,F=h=>{if(N(h),!h){b({comparativeMetricKey:void 0,disableAutoComparative:!0});return;}if(!l){b({disableAutoComparative:!1});return;}if(c.comparativeMetricKey)b({disableAutoComparative:!1});else{const I=S.find(g=>g.value!==c.targetMetricKey);b({comparativeMetricKey:I==null?void 0:I.value,disableAutoComparative:!1});}};return/* @__PURE__ */n(Se,{value:"bullet-config",className:"border-b-0",children:[/* @__PURE__ */e(Te,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Or,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Bullet Chart"})]})}),/* @__PURE__ */n(ke,{className:"space-y-6 border-t border-border/50 py-4",children:[/* @__PURE__ */n("section",{className:"space-y-4",children:[/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"ORIENTATION"}),/* @__PURE__ */n(ae,{value:j,onValueChange:h=>k(h),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */n(se,{children:[/* @__PURE__ */e(H,{value:"horizontal",className:"text-xs",children:"Horizontal"}),/* @__PURE__ */e(H,{value:"vertical",className:"text-xs",children:"Vertical"})]})]})]}),l&&/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"TARGET METRIC"}),/* @__PURE__ */n(ae,{value:c.targetMetricKey||"__none",onValueChange:h=>b({targetMetricKey:h==="__none"?void 0:h}),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{placeholder:"Select metric"})}),/* @__PURE__ */n(se,{children:[/* @__PURE__ */e(H,{value:"__none",className:"text-xs",children:"None"}),S.map(h=>/* @__PURE__ */e(H,{value:h.value,className:"text-xs",children:h.label},h.value))]})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"COMPARATIVE METRIC"}),l?/* @__PURE__ */n(ae,{value:c.comparativeMetricKey||"__none",onValueChange:h=>b({comparativeMetricKey:h==="__none"?void 0:h,disableAutoComparative:h==="__none"}),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{placeholder:"Select metric"})}),/* @__PURE__ */e(se,{children:O.map(h=>/* @__PURE__ */e(H,{value:h.value,className:"text-xs",children:h.label},h.value))})]}):/* @__PURE__ */n("div",{className:"space-y-2 rounded-md border border-border/50 p-3 text-xs",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between font-medium",children:[/* @__PURE__ */e("span",{children:"Show comparative"}),/* @__PURE__ */e(we,{size:"sm",checked:m,onCheckedChange:h=>F(h)})]}),/* @__PURE__ */e("p",{className:"text-[11px] text-muted-foreground",children:"Comparative values are auto-detected from the third metric in your results."})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"TARGET VALUE (FALLBACK)"}),/* @__PURE__ */e(Be,{type:"number",className:"h-8 text-xs",value:w,onCommit:x,placeholder:"Optional numeric fallback"})]})]}),/* @__PURE__ */n("section",{className:"space-y-4 rounded-md border border-border/60 p-3",children:[/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between gap-2",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"QUALITATIVE RANGES"}),/* @__PURE__ */e(Ot,{children:/* @__PURE__ */n(mt,{delayDuration:200,children:[/* @__PURE__ */e(ht,{asChild:!0,children:/* @__PURE__ */e("button",{type:"button",className:"text-muted-foreground transition-colors hover:text-foreground",children:/* @__PURE__ */e(ct,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */e(pt,{side:"top",children:"Use columns or static values for Poor / Average / Good."})]})})]}),/* @__PURE__ */e("div",{className:"flex items-center gap-2 text-xs font-medium",children:/* @__PURE__ */e(we,{size:"sm",checked:i,onCheckedChange:B})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2 text-xs font-medium",children:[/* @__PURE__ */e("input",{type:"checkbox",checked:u,disabled:!i,onChange:h=>$(h.target.checked),className:"h-3.5 w-3.5 accent-primary disabled:opacity-50"}),/* @__PURE__ */e("span",{children:"Use % of value"})]})]}),i&&/* @__PURE__ */e("div",{className:"space-y-3",children:or.map(h=>{var I,g,C,M,z;return/* @__PURE__ */n("div",{className:"space-y-2 rounded-md border border-border/60 bg-muted/40 p-3",children:[/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */n(L,{className:"text-[11px] font-medium uppercase tracking-wide",children:[h," LABEL"]}),/* @__PURE__ */e(Be,{placeholder:`Display label (${h})`,value:((I=c.rangeLabels)==null?void 0:I[h])||"",onCommit:_=>D(h,_),className:"h-8 text-xs"})]}),l?/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */n(L,{className:"text-[11px] font-medium uppercase tracking-wide",children:[h," COLUMN"]}),/* @__PURE__ */n(ae,{value:((g=c.rangeKeys)==null?void 0:g[h])||"__none",onValueChange:_=>{_==="__none"?y(h,""):y(h,_);},children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{placeholder:"Select column"})}),/* @__PURE__ */e(se,{children:A.map(_=>/* @__PURE__ */e(H,{value:_.value,className:"text-xs",children:_.label},_.value))})]})]}):/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */n(L,{className:"text-[11px] font-medium uppercase tracking-wide",children:[h," COLUMN KEY"]}),/* @__PURE__ */e(Be,{placeholder:"Column key",value:((C=c.rangeKeys)==null?void 0:C[h])||"",onCommit:_=>y(h,_),className:"h-8 text-xs"})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */n(L,{className:"text-[11px] font-medium uppercase tracking-wide",children:[h," VALUE"]}),/* @__PURE__ */e(Be,{type:"number",placeholder:u?"0.80":"Static value",value:((M=c.ranges)==null?void 0:M[h])===void 0?"":String((z=c.ranges)==null?void 0:z[h]),onCommit:_=>R(h,_),className:"h-8 text-xs"})]})]},h);})})]})]})]});}function cr(t){if(!t)return;const a={...t};if(a.xMetricKey||delete a.xMetricKey,a.yMetricKey||delete a.yMetricKey,a.radiusMetricKey||delete a.radiusMetricKey,a.labelKey||delete a.labelKey,a.groupKey||delete a.groupKey,a.enableGrouping===void 0&&delete a.enableGrouping,a.radiusScale||delete a.radiusScale,a.fixedRadius===void 0&&delete a.fixedRadius,a.minRadius===void 0&&delete a.minRadius,a.maxRadius===void 0&&delete a.maxRadius,Object.keys(a).length!==0)return a;}function Nm(){var D,B,$,j,k,O,A,F,K,E,h,I;const t=T(g=>g.card.preferences),a=T(g=>g.card),s=Ve(),r=T(g=>g.isDevMode),{setCardPreferences:o,updateCardInFrame:c}=he(),d=s==="bubble",l=s==="scatter",i=X(()=>(t==null?void 0:t.bubbleScatterConfig)||{},[t==null?void 0:t.bubbleScatterConfig]),u=zt(a==null?void 0:a.config)&&!r,p=X(()=>{var g,C;return((C=(g=a==null?void 0:a.config)==null?void 0:g.metricColumns)==null?void 0:C.map(M=>{const z=M.label||M.name||M.alias||"";return{value:z,label:z};}))||[];},[(D=a==null?void 0:a.config)==null?void 0:D.metricColumns]),f=X(()=>{var g,C;return((C=(g=a==null?void 0:a.config)==null?void 0:g.groupByColumns)==null?void 0:C.map(M=>{const z=M.label||M.name||M.alias||"";return{value:z,label:z};}))||[];},[(B=a==null?void 0:a.config)==null?void 0:B.groupByColumns]),m=X(()=>i.enableGrouping!==void 0?i.enableGrouping:!r&&f.length>=2,[i.enableGrouping,r,f.length]),[N,w]=Y(m);ve(()=>{w(m);},[m]);const S=g=>{const C={...(t||{}),bubbleScatterConfig:g};o(C),a&&c({...a,preferences:C});},b=g=>{o(g),a&&c({...a,preferences:g});};ve(()=>{if(!t||p.length===0)return;const g={};let C=!1;if(!i.xMetricKey&&p[0]&&(g.xMetricKey=p[0].value,C=!0),!i.yMetricKey&&p[1]&&(g.yMetricKey=p[1].value,C=!0),d&&!i.radiusMetricKey&&p[2]&&(g.radiusMetricKey=p[2].value,C=!0),!i.labelKey&&f[0]&&(g.labelKey=f[0].value,C=!0),m&&!i.groupKey&&f[1]&&(g.groupKey=f[1].value,g.enableGrouping=!0,C=!0),C){const M=cr({...i,...g});S(M);}},[p,f,i,t,o,d,m]);const y=g=>{const C=cr({...i,...g});S(C);},R=g=>{w(g),y({enableGrouping:g,groupKey:g?i.groupKey:void 0});};return!d&&!l?null:/* @__PURE__ */n(Se,{value:"bubble-scatter-config",children:[/* @__PURE__ */e(Te,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(d?Ac:Rr,{className:"h-3.5 w-3.5 text-foreground/60"}),/* @__PURE__ */n("span",{children:[d?"Bubble":"Scatter"," Configuration"]})]})}),/* @__PURE__ */n(ke,{className:"space-y-4 px-1 pb-4",children:[/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-1 text-xs font-medium text-muted-foreground",children:["Dimensions",/* @__PURE__ */e(Ot,{children:/* @__PURE__ */n(mt,{children:[/* @__PURE__ */e(ht,{children:/* @__PURE__ */e(ct,{className:"h-3 w-3"})}),/* @__PURE__ */e(pt,{side:"right",className:"max-w-xs",children:/* @__PURE__ */e("p",{children:"Label identifies each point. Group creates separate series in the legend."})})]})})]}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Label Column"}),u?/* @__PURE__ */n(ae,{value:i.labelKey||"",onValueChange:g=>y({labelKey:g}),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{placeholder:"Select label column"})}),/* @__PURE__ */e(se,{children:f.map(g=>/* @__PURE__ */e(H,{value:g.value,children:g.label},g.value))})]}):/* @__PURE__ */e(Be,{className:"h-8 text-xs",placeholder:"Column name for labels",value:i.labelKey||"",onCommit:g=>y({labelKey:g})})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Group points into series"}),/* @__PURE__ */e(we,{size:"sm",checked:N,onCheckedChange:R})]}),N&&/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Group By"}),u?/* @__PURE__ */n(ae,{value:i.groupKey||"",onValueChange:g=>y({groupKey:g}),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{placeholder:"Select group column"})}),/* @__PURE__ */e(se,{children:f.map(g=>/* @__PURE__ */e(H,{value:g.value,children:g.label},g.value))})]}):/* @__PURE__ */e(Be,{className:"h-8 text-xs",placeholder:"Column name for grouping",value:i.groupKey||"",onCommit:g=>y({groupKey:g})})]})]}),/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */e("div",{className:"text-xs font-medium text-muted-foreground",children:"Metrics"}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"X Axis"}),u?/* @__PURE__ */n(ae,{value:i.xMetricKey||"",onValueChange:g=>y({xMetricKey:g}),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{placeholder:"Select X metric"})}),/* @__PURE__ */e(se,{children:p.map(g=>/* @__PURE__ */e(H,{value:g.value,children:g.label},g.value))})]}):/* @__PURE__ */e(Be,{className:"h-8 text-xs",placeholder:"Column name for X axis",value:i.xMetricKey||"",onCommit:g=>y({xMetricKey:g})})]}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Y Axis"}),u?/* @__PURE__ */n(ae,{value:i.yMetricKey||"",onValueChange:g=>y({yMetricKey:g}),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{placeholder:"Select Y metric"})}),/* @__PURE__ */e(se,{children:p.map(g=>/* @__PURE__ */e(H,{value:g.value,children:g.label},g.value))})]}):/* @__PURE__ */e(Be,{className:"h-8 text-xs",placeholder:"Column name for Y axis",value:i.yMetricKey||"",onCommit:g=>y({yMetricKey:g})})]}),d&&/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Radius"}),u?/* @__PURE__ */n(ae,{value:i.radiusMetricKey||"",onValueChange:g=>y({radiusMetricKey:g}),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{placeholder:"Select radius metric"})}),/* @__PURE__ */e(se,{children:p.map(g=>/* @__PURE__ */e(H,{value:g.value,children:g.label},g.value))})]}):/* @__PURE__ */e(Be,{className:"h-8 text-xs",placeholder:"Column name for radius",value:i.radiusMetricKey||"",onCommit:g=>y({radiusMetricKey:g})})]})]}),d&&/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */e("div",{className:"text-xs font-medium text-muted-foreground",children:"Radius Settings"}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Scale Mode"}),/* @__PURE__ */n(ae,{value:i.radiusScale||"sqrt",onValueChange:g=>y({radiusScale:g}),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */n(se,{children:[/* @__PURE__ */e(H,{value:"sqrt",children:"Square Root (area-proportional)"}),/* @__PURE__ */e(H,{value:"linear",children:"Linear"}),/* @__PURE__ */e(H,{value:"fixed",children:"Fixed Size"})]})]})]}),i.radiusScale!=="fixed"&&/* @__PURE__ */n("div",{className:"grid grid-cols-2 gap-2",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Min Radius"}),/* @__PURE__ */e(Be,{className:"h-8 text-xs",type:"number",placeholder:"5",value:(($=i.minRadius)==null?void 0:$.toString())||"",onCommit:g=>y({minRadius:g?Number(g):void 0})})]}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Max Radius"}),/* @__PURE__ */e(Be,{className:"h-8 text-xs",type:"number",placeholder:"30",value:((j=i.maxRadius)==null?void 0:j.toString())||"",onCommit:g=>y({maxRadius:g?Number(g):void 0})})]})]}),i.radiusScale==="fixed"&&/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */n(L,{className:"text-xs",children:["Fixed Radius: ",i.fixedRadius||10]}),/* @__PURE__ */e($t,{value:[i.fixedRadius||10],onValueChange:([g])=>y({fixedRadius:g}),min:3,max:30,step:1,className:"py-2"})]})]}),l&&/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */e("div",{className:"text-xs font-medium text-muted-foreground",children:"Point Settings"}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */n(L,{className:"text-xs",children:["Point Size: ",i.fixedRadius||5]}),/* @__PURE__ */e($t,{value:[i.fixedRadius||5],onValueChange:([g])=>y({fixedRadius:g}),min:2,max:15,step:1,className:"py-2"})]})]}),/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e("span",{className:"text-xs font-medium text-muted-foreground",children:"Axis Titles"}),/* @__PURE__ */e(we,{size:"sm",checked:((O=(k=t==null?void 0:t.xAxisConfig)==null?void 0:k.name)==null?void 0:O.enabled)??!1,onCheckedChange:g=>{var z,_,P,V;const C=i.xMetricKey||"X Axis",M=i.yMetricKey||"Y Axis";b({...(t??{}),xAxisConfig:{...(t==null?void 0:t.xAxisConfig),name:{enabled:g,text:((_=(z=t==null?void 0:t.xAxisConfig)==null?void 0:z.name)==null?void 0:_.text)||C}},yAxisConfig:{...(t==null?void 0:t.yAxisConfig),name:{enabled:g,text:((V=(P=t==null?void 0:t.yAxisConfig)==null?void 0:P.name)==null?void 0:V.text)||M}}});}})]}),((F=(A=t==null?void 0:t.xAxisConfig)==null?void 0:A.name)==null?void 0:F.enabled)&&/* @__PURE__ */n("div",{className:"grid grid-cols-2 gap-2",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"X Title"}),/* @__PURE__ */e(Be,{className:"h-8 text-xs",placeholder:i.xMetricKey||"X Axis",value:((E=(K=t==null?void 0:t.xAxisConfig)==null?void 0:K.name)==null?void 0:E.text)||"",onCommit:g=>{var C;b({...(t??{}),xAxisConfig:{...(t==null?void 0:t.xAxisConfig),name:{...((C=t==null?void 0:t.xAxisConfig)==null?void 0:C.name),enabled:!0,text:g||i.xMetricKey||"X Axis"}}});}})]}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Y Title"}),/* @__PURE__ */e(Be,{className:"h-8 text-xs",placeholder:i.yMetricKey||"Y Axis",value:((I=(h=t==null?void 0:t.yAxisConfig)==null?void 0:h.name)==null?void 0:I.text)||"",onCommit:g=>{var C;b({...(t??{}),yAxisConfig:{...(t==null?void 0:t.yAxisConfig),name:{...((C=t==null?void 0:t.yAxisConfig)==null?void 0:C.name),enabled:!0,text:g||i.yMetricKey||"Y Axis"}}});}})]})]})]})]})]});}const Cm=[{value:"percentOfTotal",label:"% of Total",description:"Each stage shows percentage of the sum of all values"},{value:"percentOfFirst",label:"% of Stage 1",description:"First stage = 100%, others relative to first stage"}];function wm(){const t=T(f=>f.card),a=T(f=>{var m;return(m=f.card)==null?void 0:m.preferences;}),{setCardPreferences:s}=he(),r=(t==null?void 0:t.type)==="funnel",o=(a==null?void 0:a.funnelConfig)||{},c=o.percentMode??"percentOfTotal",d=o.shrinkFraction??1,l=o.labelThreshold??0,i=f=>{const m={...o,...f};s({...(a||{}),funnelConfig:m});},v=f=>{i({percentMode:f});},u=f=>{i({shrinkFraction:f[0]});},p=f=>{i({labelThreshold:f[0]});};return r?/* @__PURE__ */n(Se,{value:"funnel-config",className:"border-none",children:[/* @__PURE__ */e(Te,{className:"flex w-full items-center gap-2 py-3 text-[12px] font-medium hover:no-underline",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(ua,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Funnel Settings"})]})}),/* @__PURE__ */n(ke,{className:"space-y-4 border-t border-border bg-background/50 px-3 py-4 text-sm",children:[/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"PERCENTAGE MODE"}),/* @__PURE__ */e(vn,{value:c,onValueChange:f=>v(f),className:"space-y-2",children:Cm.map(f=>/* @__PURE__ */n("div",{className:"flex items-start gap-2 rounded-md border border-border px-3 py-2",children:[/* @__PURE__ */e(Bt,{id:`funnel-${f.value}`,value:f.value,className:"mt-0.5"}),/* @__PURE__ */n(L,{htmlFor:`funnel-${f.value}`,className:"flex flex-col gap-0.5 text-sm font-normal",children:[/* @__PURE__ */e("span",{className:"font-medium",children:f.label}),/* @__PURE__ */e("span",{className:"text-xs text-muted-foreground",children:f.description})]})]},f.value))})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"SEGMENT SHRINK"}),/* @__PURE__ */n("div",{className:"flex items-center gap-3 pt-1",children:[/* @__PURE__ */e("span",{className:"whitespace-nowrap text-xs text-muted-foreground",children:"Same Width"}),/* @__PURE__ */e($t,{value:[d],onValueChange:u,min:0,max:1,step:0.1,className:"flex-1"}),/* @__PURE__ */e("span",{className:"whitespace-nowrap text-xs text-muted-foreground",children:"Full Shrink"})]}),/* @__PURE__ */n("p",{className:"text-center text-xs text-muted-foreground",children:["Current: ",Math.round(d*100),"%"]})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"LABEL VISIBILITY THRESHOLD"}),/* @__PURE__ */n("div",{className:"flex items-center gap-3 pt-1",children:[/* @__PURE__ */e("span",{className:"whitespace-nowrap text-xs text-muted-foreground",children:"Show All"}),/* @__PURE__ */e($t,{value:[l],onValueChange:p,min:0,max:25,step:1,className:"flex-1"}),/* @__PURE__ */e("span",{className:"whitespace-nowrap text-xs text-muted-foreground",children:"Hide Small"})]}),/* @__PURE__ */e("p",{className:"text-center text-xs text-muted-foreground",children:l===0?"Showing all labels":`Hide labels below ${l}%`})]})]})]}):null;}const Sm=[{value:"USD",label:"USD - US Dollar"},{value:"EUR",label:"EUR - Euro"},{value:"GBP",label:"GBP - British Pound"},{value:"JPY",label:"JPY - Japanese Yen"},{value:"CNY",label:"CNY - Chinese Yuan"},{value:"INR",label:"INR - Indian Rupee"},{value:"CAD",label:"CAD - Canadian Dollar"},{value:"AUD",label:"AUD - Australian Dollar"}],Tm=[{value:"en-US",label:"English (US)"},{value:"en-GB",label:"English (UK)"},{value:"de-DE",label:"German"},{value:"fr-FR",label:"French"},{value:"es-ES",label:"Spanish"},{value:"it-IT",label:"Italian"},{value:"pt-BR",label:"Portuguese (Brazil)"},{value:"zh-CN",label:"Chinese (Simplified)"}],km=["center","start","end"],Im=["center","start","end","top","bottom"];function ha({config:t,onChange:a,isHorizontal:s=!1,showAutoFormat:r=!0,positionOptions:o,showAppearance:c=!0}){var N,w,S,b,y,R;const d=o??(s?["auto","center","left","right","custom"]:["auto","center","top","bottom","custom"]),l=r?["auto","number","currency","percent","none"]:["number","currency","percent","none"],i=(x,D)=>{const B={...t,[x]:D};a(B);},v=(x,D)=>{const B={...t,font:{...((t==null?void 0:t.font)||{}),[x]:D}};a(B);},u=(x,D)=>{const B={...t,formatOptions:{...((t==null?void 0:t.formatOptions)||{}),[x]:D}};a(B);},p=()=>s?"Right":"Top",f=t||{},m=f.format||(r?"auto":"number");return/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Position"}),/* @__PURE__ */n(ae,{value:f.position||"auto",onValueChange:x=>i("position",x),children:[/* @__PURE__ */e(ne,{className:"h-7 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:d.map(x=>/* @__PURE__ */e(H,{value:x,className:"text-xs",children:x==="auto"?p():x==="custom"?"Custom (Advanced)":Ge(x)},x))})]})]}),f.position==="custom"&&/* @__PURE__ */n("div",{className:"space-y-2 rounded-md border border-border bg-background p-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Anchor"}),/* @__PURE__ */n(ae,{value:f.anchor||"center",onValueChange:x=>i("anchor",x),children:[/* @__PURE__ */e(ne,{className:"h-7 w-24 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:km.map(x=>/* @__PURE__ */e(H,{value:x,className:"text-xs",children:Ge(x)},x))})]})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Align"}),/* @__PURE__ */n(ae,{value:String(f.align||"center"),onValueChange:x=>i("align",x),children:[/* @__PURE__ */e(ne,{className:"h-7 w-24 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:Im.map(x=>/* @__PURE__ */e(H,{value:x,className:"text-xs",children:Ge(x)},x))})]})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Format"}),/* @__PURE__ */n(ae,{value:m,onValueChange:x=>i("format",x),children:[/* @__PURE__ */e(ne,{className:"h-7 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:l.map(x=>/* @__PURE__ */e(H,{value:x,className:"text-xs",children:x==="auto"&&r?"Auto (Use Axis)":x==="none"?"None (Raw Value)":Ge(x)},x))})]})]}),!["auto","none"].includes(m)&&/* @__PURE__ */n("div",{className:"space-y-2 rounded-md border border-border bg-background p-2",children:[["number","currency","percent"].includes(m)&&/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Decimals"}),/* @__PURE__ */e("div",{className:"w-16",children:/* @__PURE__ */e(Ze,{type:"number",placeholder:"0",value:String(((N=f.formatOptions)==null?void 0:N.decimalPlaces)??(m==="currency"?2:m==="percent"?1:0)),onSave:x=>u("decimalPlaces",Number(x)),className:""})})]}),m==="currency"&&/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Currency"}),/* @__PURE__ */n(ae,{value:((w=f.formatOptions)==null?void 0:w.currency)||"USD",onValueChange:x=>u("currency",x),children:[/* @__PURE__ */e(ne,{className:"h-7 w-28 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:Sm.map(x=>/* @__PURE__ */e(H,{value:x.value,className:"text-xs",children:x.label},x.value))})]})]}),["number","currency"].includes(m)&&/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Abbreviate (K, M, B)"}),/* @__PURE__ */e(we,{size:"sm",checked:((S=f.formatOptions)==null?void 0:S.useSuffix)??!1,onCheckedChange:x=>u("useSuffix",x)})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Locale"}),/* @__PURE__ */n(ae,{value:((b=f.formatOptions)==null?void 0:b.locale)||"en-US",onValueChange:x=>u("locale",x),children:[/* @__PURE__ */e(ne,{className:"h-7 w-28 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:Tm.map(x=>/* @__PURE__ */e(H,{value:x.value,className:"text-xs",children:x.label},x.value))})]})]})]}),c&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Appearance"}),/* @__PURE__ */n("div",{className:"space-y-2 rounded-md border border-border bg-background p-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Size"}),/* @__PURE__ */e("div",{className:"w-16",children:/* @__PURE__ */e(Ze,{type:"number",placeholder:"12",value:String(((y=f.font)==null?void 0:y.size)||12),onSave:x=>v("size",Number(x)),className:""})})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Weight"}),/* @__PURE__ */n(ae,{value:((R=f.font)==null?void 0:R.weight)||"normal",onValueChange:x=>v("weight",x),children:[/* @__PURE__ */e(ne,{className:"h-7 w-24 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */n(se,{children:[/* @__PURE__ */e(H,{value:"normal",className:"text-xs",children:"Normal"}),/* @__PURE__ */e(H,{value:"bold",className:"text-xs",children:"Bold"})]})]})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Color"}),/* @__PURE__ */n(ae,{value:f.color==="auto"||!f.color?"auto":"custom",onValueChange:x=>{x==="auto"&&i("color","auto");},children:[/* @__PURE__ */e(ne,{className:"h-7 w-28 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */n(se,{children:[/* @__PURE__ */e(H,{value:"auto",className:"text-xs",children:"Auto (Contrast)"}),/* @__PURE__ */e(H,{value:"custom",disabled:!0,className:"text-xs",children:"Custom"})]})]})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs",children:"Rotation"}),/* @__PURE__ */n("div",{className:"flex items-center gap-1",children:[/* @__PURE__ */e("div",{className:"w-12",children:/* @__PURE__ */e(Ze,{type:"number",placeholder:"0",value:String(f.rotation||0),onSave:x=>i("rotation",Number(x)),className:""})}),/* @__PURE__ */e("span",{className:"text-xs text-muted-foreground",children:"°"})]})]})]})]})]});}const Em=[{type:"bar",icon:ln,label:"Bar"},{type:"line",icon:sn,label:"Line"}],Fm=[0,1,2,3,4,5,6,8,10],Om=[{value:"circle",label:"Circle ●"},{value:"rect",label:"Square ■"},{value:"rectRounded",label:"Rounded ▢"},{value:"rectRot",label:"Diamond ◆"},{value:"triangle",label:"Triangle ▲"},{value:"cross",label:"Cross +"},{value:"crossRot",label:"X ×"},{value:"star",label:"Star ★"},{value:"dash",label:"Dash —"},{value:"line",label:"Line │"}],Mm=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function Rm(){return T(a=>{var s;return(s=a.card)==null?void 0:s.type;})!=="combo"?null:/* @__PURE__ */n(Se,{value:"combo-series",className:"border-b-0",children:[/* @__PURE__ */e(Te,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Jt,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Series"})]})}),/* @__PURE__ */e(ke,{className:"pt-2",children:/* @__PURE__ */e(Am,{})})]});}function Am(){const{transformedMetricKeys:t}=ma();return t.length===0?/* @__PURE__ */e("div",{className:"rounded-lg border border-dashed border-border p-4 text-center text-xs text-muted-foreground",children:"Add metrics to configure series"}):/* @__PURE__ */e("div",{className:"space-y-3",children:t.map((a,s)=>/* @__PURE__ */e(Pm,{metricKey:a,idx:s},a))});}function Pm({metricKey:t,idx:a}){var b;const[s,r]=Y(!1),o=T(y=>{var R;return(R=y.card)==null?void 0:R.preferences;}),c=T(y=>{var R,x;return(x=(R=y.card)==null?void 0:R.preferences)==null?void 0:x.datasetOptions;}),d=c==null?void 0:c.find(y=>y.idx===a),{setCardPreferences:l}=T(y=>y.actions),i=(d==null?void 0:d.type)||"bar",v=(d==null?void 0:d.yAxisId)||"y",u=((b=d==null?void 0:d.dataLabels)==null?void 0:b.enabled)??!1,p=i==="line"?sn:ln;function f(y){const R={idx:a,type:i,yAxisId:v,dataLabels:d==null?void 0:d.dataLabels,...y};if(!d)l({...(o||{}),datasetOptions:[...(c||[]),R]});else{const x=c==null?void 0:c.map(D=>D.idx===a?{...D,...R}:D);l({...(o||{}),datasetOptions:x});}}function m(y){f({type:y});}function N(y){f({yAxisId:y});}function w(y){f({dataLabels:{...(d==null?void 0:d.dataLabels),enabled:y}});}function S(y){f({dataLabels:y});}return/* @__PURE__ */e(It,{open:s,onOpenChange:r,children:/* @__PURE__ */n("div",{className:"rounded-lg border border-border bg-muted/30",children:[/* @__PURE__ */e(Et,{asChild:!0,children:/* @__PURE__ */n("button",{className:"flex w-full items-center justify-between gap-3 overflow-hidden px-3 py-2 text-left hover:bg-muted/50",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[/* @__PURE__ */e(vt,{className:W("h-4 w-4 shrink-0 text-muted-foreground transition-transform",s&&"rotate-90")}),/* @__PURE__ */e("span",{className:"max-w-[100px] truncate text-xs font-medium",title:t,children:t})]}),/* @__PURE__ */n("div",{className:"flex shrink-0 items-center gap-1.5",children:[/* @__PURE__ */n("span",{className:W("flex items-center gap-1 rounded px-1.5 py-0.5 text-xs","border border-border bg-background text-muted-foreground"),children:[/* @__PURE__ */e(p,{className:"h-3 w-3"}),i==="line"?"Line":"Bar"]}),/* @__PURE__ */e("span",{className:W("rounded px-1.5 py-0.5 text-xs","border border-border bg-background text-muted-foreground"),children:v==="y2"?"Y2":"Y1"})]})]})}),/* @__PURE__ */e(Ft,{children:/* @__PURE__ */e("div",{className:"border-t border-border",children:/* @__PURE__ */n("div",{className:"space-y-4 p-3",children:[/* @__PURE__ */n("div",{className:"flex items-end gap-4",children:[/* @__PURE__ */n("div",{className:"flex-1 space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Chart Type"}),/* @__PURE__ */e("div",{className:"flex gap-2",children:Em.map(({type:y,icon:R,label:x})=>/* @__PURE__ */n("button",{onClick:()=>m(y),className:W("flex items-center gap-2 rounded-md border px-3 py-1.5 text-xs transition-colors",i===y?"border-primary bg-primary/10 text-primary":"border-border bg-background text-muted-foreground hover:bg-muted"),children:[/* @__PURE__ */e(R,{className:"h-3.5 w-3.5 text-foreground/60"}),/* @__PURE__ */e("span",{children:x})]},y))})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Axis"}),/* @__PURE__ */n(ae,{value:v,onValueChange:y=>N(y),children:[/* @__PURE__ */e(ne,{className:"h-8 w-20 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */n(se,{children:[/* @__PURE__ */e(H,{value:"y",className:"text-xs",children:"Y1 (Left)"}),/* @__PURE__ */e(H,{value:"y2",className:"text-xs",children:"Y2 (Right)"})]})]})]})]}),i==="line"&&/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Line Style"}),/* @__PURE__ */n("div",{className:"grid grid-cols-3 gap-3",children:[/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Pattern"}),/* @__PURE__ */n(ae,{value:(d==null?void 0:d.lineStyle)||"solid",onValueChange:y=>f({lineStyle:y}),children:[/* @__PURE__ */e(ne,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:Mm.map(({value:y,label:R})=>/* @__PURE__ */e(H,{value:y,className:"text-xs",children:R},y))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Point Size"}),/* @__PURE__ */n(ae,{value:String((d==null?void 0:d.pointRadius)??3),onValueChange:y=>f({pointRadius:Number(y)}),children:[/* @__PURE__ */e(ne,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:Fm.map(y=>/* @__PURE__ */e(H,{value:String(y),className:"text-xs",children:y===0?"None":y},y))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Point Shape"}),/* @__PURE__ */n(ae,{value:(d==null?void 0:d.pointStyle)||"circle",onValueChange:y=>f({pointStyle:y}),children:[/* @__PURE__ */e(ne,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:Om.map(({value:y,label:R})=>/* @__PURE__ */e(H,{value:y,className:"text-xs",children:R},y))})]})]})]})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Data Labels"}),/* @__PURE__ */e(we,{size:"sm",checked:u,onCheckedChange:w})]}),u&&/* @__PURE__ */e("div",{className:"rounded-md border border-border bg-background p-2",children:/* @__PURE__ */e(ha,{config:d==null?void 0:d.dataLabels,onChange:S,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})});}const Ra=[{value:"origin",label:"Origin (X-axis)",description:"Fill to the X-axis (y=0)"},{value:"start",label:"Start (Top)",description:"Fill to the top of chart area"},{value:"end",label:"End (Bottom)",description:"Fill to the bottom of chart area"},{value:"-1",label:"Previous Series",description:"Fill to the series below"},{value:"+1",label:"Next Series",description:"Fill to the series above"},{value:"false",label:"No Fill (Line)",description:"Show as line without fill"}],Dm=[0,1,2,3,4,5,6,8,10],Lm=[{value:"circle",label:"Circle ●"},{value:"rect",label:"Square ■"},{value:"rectRounded",label:"Rounded ▢"},{value:"rectRot",label:"Diamond ◆"},{value:"triangle",label:"Triangle ▲"},{value:"cross",label:"Cross +"},{value:"crossRot",label:"X ×"},{value:"star",label:"Star ★"},{value:"dash",label:"Dash —"},{value:"line",label:"Line │"}],_m=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function Vm(t){return t==null?"origin":t===!1?"false":t;}function Bm(){const t=T(a=>{var s;return(s=a.card)==null?void 0:s.type;});return t!=="area"&&t!=="stackedArea"?null:/* @__PURE__ */n(Se,{value:"area-series",className:"border-b-0",children:[/* @__PURE__ */e(Te,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Jt,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Series"})]})}),/* @__PURE__ */e(ke,{className:"pt-2",children:/* @__PURE__ */e(Km,{})})]});}function Km(){const{transformedMetricKeys:t}=ma();return t.length===0?/* @__PURE__ */e("div",{className:"rounded-lg border border-dashed border-border p-4 text-center text-xs text-muted-foreground",children:"Add metrics to configure series"}):/* @__PURE__ */e("div",{className:"space-y-3",children:t.map((a,s)=>/* @__PURE__ */e(zm,{metricKey:a,idx:s},a))});}function zm({metricKey:t,idx:a}){var w;const[s,r]=Y(!1),o=T(S=>{var b;return(b=S.card)==null?void 0:b.preferences;}),c=T(S=>{var b,y;return(y=(b=S.card)==null?void 0:b.preferences)==null?void 0:y.datasetOptions;}),d=c==null?void 0:c.find(S=>S.idx===a),{setCardPreferences:l}=T(S=>S.actions),i=Vm(d==null?void 0:d.fill),v=((w=d==null?void 0:d.dataLabels)==null?void 0:w.enabled)??!1,u=Ra.find(S=>S.value===i)||Ra[0];function p(S){const b={idx:a,fill:i,dataLabels:d==null?void 0:d.dataLabels,...S};if(!d)l({...(o||{}),datasetOptions:[...(c||[]),b]});else{const y=c==null?void 0:c.map(R=>R.idx===a?{...R,...b}:R);l({...(o||{}),datasetOptions:y});}}function f(S){p({fill:S==="false"?!1:S});}function m(S){p({dataLabels:{...(d==null?void 0:d.dataLabels),enabled:S}});}function N(S){p({dataLabels:S});}return/* @__PURE__ */e(It,{open:s,onOpenChange:r,children:/* @__PURE__ */n("div",{className:"rounded-lg border border-border bg-muted/30",children:[/* @__PURE__ */e(Et,{asChild:!0,children:/* @__PURE__ */n("button",{className:"flex w-full items-center justify-between gap-3 overflow-hidden px-3 py-2 text-left hover:bg-muted/50",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[/* @__PURE__ */e(vt,{className:W("h-4 w-4 shrink-0 text-muted-foreground transition-transform",s&&"rotate-90")}),/* @__PURE__ */e("span",{className:"max-w-[100px] truncate text-xs font-medium",title:t,children:t})]}),/* @__PURE__ */e("div",{className:"flex shrink-0 items-center gap-1.5",children:/* @__PURE__ */n("span",{className:W("flex items-center gap-1 rounded px-1.5 py-0.5 text-xs","border border-border bg-background text-muted-foreground"),children:[/* @__PURE__ */e(xi,{className:"h-3 w-3"}),u.label.split(" ")[0]]})})]})}),/* @__PURE__ */e(Ft,{children:/* @__PURE__ */e("div",{className:"border-t border-border",children:/* @__PURE__ */n("div",{className:"space-y-4 p-3",children:[/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Fill Target"}),/* @__PURE__ */n(ae,{value:i,onValueChange:S=>f(S),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:Ra.map(S=>/* @__PURE__ */e(H,{value:S.value,className:"text-xs",children:/* @__PURE__ */e("div",{className:"flex flex-col",children:/* @__PURE__ */e("span",{children:S.label})})},S.value))})]})]}),/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Line Style"}),/* @__PURE__ */n("div",{className:"grid grid-cols-3 gap-3",children:[/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Pattern"}),/* @__PURE__ */n(ae,{value:(d==null?void 0:d.lineStyle)||"solid",onValueChange:S=>p({lineStyle:S}),children:[/* @__PURE__ */e(ne,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:_m.map(({value:S,label:b})=>/* @__PURE__ */e(H,{value:S,className:"text-xs",children:b},S))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Point Size"}),/* @__PURE__ */n(ae,{value:String((d==null?void 0:d.pointRadius)??3),onValueChange:S=>p({pointRadius:Number(S)}),children:[/* @__PURE__ */e(ne,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:Dm.map(S=>/* @__PURE__ */e(H,{value:String(S),className:"text-xs",children:S===0?"None":S},S))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Point Shape"}),/* @__PURE__ */n(ae,{value:(d==null?void 0:d.pointStyle)||"circle",onValueChange:S=>p({pointStyle:S}),children:[/* @__PURE__ */e(ne,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:Lm.map(({value:S,label:b})=>/* @__PURE__ */e(H,{value:S,className:"text-xs",children:b},S))})]})]})]})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Data Labels"}),/* @__PURE__ */e(we,{size:"sm",checked:v,onCheckedChange:m})]}),v&&/* @__PURE__ */e("div",{className:"rounded-md border border-border bg-background p-2",children:/* @__PURE__ */e(ha,{config:d==null?void 0:d.dataLabels,onChange:N,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})});}const qm=[0,1,2,3,4,5,6,8,10],jm=[{value:"circle",label:"Circle ●"},{value:"rect",label:"Square ■"},{value:"rectRounded",label:"Rounded ▢"},{value:"rectRot",label:"Diamond ◆"},{value:"triangle",label:"Triangle ▲"},{value:"cross",label:"Cross +"},{value:"crossRot",label:"X ×"},{value:"star",label:"Star ★"},{value:"dash",label:"Dash —"},{value:"line",label:"Line │"}],Aa=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function $m(){return T(a=>{var s;return(s=a.card)==null?void 0:s.type;})!=="line"?null:/* @__PURE__ */n(Se,{value:"line-series",className:"border-b-0",children:[/* @__PURE__ */e(Te,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Jt,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Series"})]})}),/* @__PURE__ */e(ke,{className:"pt-2",children:/* @__PURE__ */e(Um,{})})]});}function Um(){const{transformedMetricKeys:t}=ma();return t.length===0?/* @__PURE__ */e("div",{className:"rounded-lg border border-dashed border-border p-4 text-center text-xs text-muted-foreground",children:"Add metrics to configure series"}):/* @__PURE__ */e("div",{className:"space-y-3",children:t.map((a,s)=>/* @__PURE__ */e(Hm,{metricKey:a,idx:s},a))});}function Hm({metricKey:t,idx:a}){var S;const[s,r]=Y(!1),o=T(b=>{var y;return(y=b.card)==null?void 0:y.preferences;}),c=T(b=>{var y,R;return(R=(y=b.card)==null?void 0:y.preferences)==null?void 0:R.datasetOptions;}),d=c==null?void 0:c.find(b=>b.idx===a),{setCardPreferences:l}=T(b=>b.actions),i=(d==null?void 0:d.lineStyle)||"solid",v=(d==null?void 0:d.pointRadius)??3,u=(d==null?void 0:d.pointStyle)||"circle",p=((S=d==null?void 0:d.dataLabels)==null?void 0:S.enabled)??!1,f=Aa.find(b=>b.value===i)||Aa[0];function m(b){const y={idx:a,lineStyle:i,pointRadius:v,pointStyle:u,dataLabels:d==null?void 0:d.dataLabels,...b};if(!d)l({...(o||{}),datasetOptions:[...(c||[]),y]});else{const R=c==null?void 0:c.map(x=>x.idx===a?{...x,...y}:x);l({...(o||{}),datasetOptions:R});}}function N(b){m({dataLabels:{...(d==null?void 0:d.dataLabels),enabled:b}});}function w(b){m({dataLabels:b});}return/* @__PURE__ */e(It,{open:s,onOpenChange:r,children:/* @__PURE__ */n("div",{className:"rounded-lg border border-border bg-muted/30",children:[/* @__PURE__ */e(Et,{asChild:!0,children:/* @__PURE__ */n("button",{className:"flex w-full items-center justify-between gap-3 overflow-hidden px-3 py-2 text-left hover:bg-muted/50",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[/* @__PURE__ */e(vt,{className:W("h-4 w-4 shrink-0 text-muted-foreground transition-transform",s&&"rotate-90")}),/* @__PURE__ */e("span",{className:"max-w-[100px] truncate text-xs font-medium",title:t,children:t})]}),/* @__PURE__ */e("div",{className:"flex shrink-0 items-center gap-1.5",children:/* @__PURE__ */n("span",{className:W("flex items-center gap-1 rounded px-1.5 py-0.5 text-xs","border border-border bg-background text-muted-foreground"),children:[/* @__PURE__ */e(os,{className:"h-3 w-3"}),f.label.split(" ")[0]]})})]})}),/* @__PURE__ */e(Ft,{children:/* @__PURE__ */e("div",{className:"border-t border-border",children:/* @__PURE__ */n("div",{className:"space-y-4 p-3",children:[/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Line Style"}),/* @__PURE__ */n("div",{className:"grid grid-cols-3 gap-3",children:[/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Pattern"}),/* @__PURE__ */n(ae,{value:i,onValueChange:b=>m({lineStyle:b}),children:[/* @__PURE__ */e(ne,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:Aa.map(({value:b,label:y})=>/* @__PURE__ */e(H,{value:b,className:"text-xs",children:y},b))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Point Size"}),/* @__PURE__ */n(ae,{value:String(v),onValueChange:b=>m({pointRadius:Number(b)}),children:[/* @__PURE__ */e(ne,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:qm.map(b=>/* @__PURE__ */e(H,{value:String(b),className:"text-xs",children:b===0?"None":b},b))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Point Shape"}),/* @__PURE__ */n(ae,{value:u,onValueChange:b=>m({pointStyle:b}),children:[/* @__PURE__ */e(ne,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:jm.map(({value:b,label:y})=>/* @__PURE__ */e(H,{value:b,className:"text-xs",children:y},b))})]})]})]})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Data Labels"}),/* @__PURE__ */e(we,{size:"sm",checked:p,onCheckedChange:N})]}),p&&/* @__PURE__ */e("div",{className:"rounded-md border border-border bg-background p-2",children:/* @__PURE__ */e(ha,{config:d==null?void 0:d.dataLabels,onChange:w,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})});}const Qm=[0,2,4,6,8,10,12,16,20];function Gm(){const t=T(a=>{var s;return(s=a.card)==null?void 0:s.type;});return!t||!["bar","horizontalBar","stackedBar"].includes(t)?null:/* @__PURE__ */n(Se,{value:"bar-series",className:"border-b-0",children:[/* @__PURE__ */e(Te,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Jt,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Series"})]})}),/* @__PURE__ */e(ke,{className:"pt-2",children:/* @__PURE__ */e(Wm,{})})]});}function Wm(){const{transformedMetricKeys:t}=ma();return t.length===0?/* @__PURE__ */e("div",{className:"rounded-lg border border-dashed border-border p-4 text-center text-xs text-muted-foreground",children:"Add metrics to configure series"}):/* @__PURE__ */e("div",{className:"space-y-3",children:t.map((a,s)=>/* @__PURE__ */e(Ym,{metricKey:a,idx:s},a))});}function Ym({metricKey:t,idx:a}){var N;const[s,r]=Y(!1),o=T(w=>{var S;return(S=w.card)==null?void 0:S.type;}),c=T(w=>{var S;return(S=w.card)==null?void 0:S.preferences;}),d=T(w=>{var S,b;return(b=(S=w.card)==null?void 0:S.preferences)==null?void 0:b.datasetOptions;}),l=d==null?void 0:d.find(w=>w.idx===a),{setCardPreferences:i}=T(w=>w.actions),v=(l==null?void 0:l.borderRadius)??0,u=((N=l==null?void 0:l.dataLabels)==null?void 0:N.enabled)??!1;function p(w){const S={idx:a,borderRadius:v,dataLabels:l==null?void 0:l.dataLabels,...w};if(!l)i({...(c||{}),datasetOptions:[...(d||[]),S]});else{const b=d==null?void 0:d.map(y=>y.idx===a?{...y,...S}:y);i({...(c||{}),datasetOptions:b});}}function f(w){p({dataLabels:{...(l==null?void 0:l.dataLabels),enabled:w}});}function m(w){p({dataLabels:w});}return/* @__PURE__ */e(It,{open:s,onOpenChange:r,children:/* @__PURE__ */n("div",{className:"rounded-lg border border-border bg-muted/30",children:[/* @__PURE__ */e(Et,{asChild:!0,children:/* @__PURE__ */n("button",{className:"flex w-full items-center justify-between gap-3 overflow-hidden px-3 py-2 text-left hover:bg-muted/50",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[/* @__PURE__ */e(vt,{className:W("h-4 w-4 shrink-0 text-muted-foreground transition-transform",s&&"rotate-90")}),/* @__PURE__ */e("span",{className:"max-w-[100px] truncate text-xs font-medium",title:t,children:t})]}),/* @__PURE__ */e("div",{className:"flex shrink-0 items-center gap-1.5",children:v>0&&/* @__PURE__ */n("span",{className:W("flex items-center gap-1 rounded px-1.5 py-0.5 text-xs","border border-border bg-background text-muted-foreground"),children:[/* @__PURE__ */e(Jr,{className:"h-3 w-3"}),"r:",v]})})]})}),/* @__PURE__ */e(Ft,{children:/* @__PURE__ */e("div",{className:"border-t border-border",children:/* @__PURE__ */n("div",{className:"space-y-4 p-3",children:[/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Bar Style"}),/* @__PURE__ */e("div",{className:"space-y-3",children:/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Corner Radius"}),/* @__PURE__ */n(ae,{value:String(v),onValueChange:w=>p({borderRadius:Number(w)}),children:[/* @__PURE__ */e(ne,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:Qm.map(w=>/* @__PURE__ */e(H,{value:String(w),className:"text-xs",children:w===0?"None":`${w}px`},w))})]})]})})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-xs text-muted-foreground",children:"Data Labels"}),/* @__PURE__ */e(we,{size:"sm",checked:u,onCheckedChange:f})]}),u&&/* @__PURE__ */e("div",{className:"rounded-md border border-border bg-background p-2",children:/* @__PURE__ */e(ha,{config:l==null?void 0:l.dataLabels,onChange:m,isHorizontal:o==="horizontalBar",showAutoFormat:!0,showAppearance:!0})})]})]})})})]})});}const Xm=[0,1,2,3,4,5,6,8,10],Jm=[{value:"circle",label:"Circle ●"},{value:"rect",label:"Square ■"},{value:"rectRounded",label:"Rounded ▢"},{value:"rectRot",label:"Diamond ◆"},{value:"triangle",label:"Triangle ▲"},{value:"cross",label:"Cross +"},{value:"crossRot",label:"X ×"},{value:"star",label:"Star ★"},{value:"dash",label:"Dash —"},{value:"line",label:"Line │"}],Zm=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function eh(){const t=T(l=>l.card),a=T(l=>{var i;return(i=l.card)==null?void 0:i.preferences;}),s=Ve(),r=a==null?void 0:a.lineStyleConfig,{setCardPreferences:o,updateCardInFrame:c}=he();if(!t||!["line","area","stackedArea"].includes(s))return null;const d=(l,i)=>{const v={...(a||{}),lineStyleConfig:{...r,[l]:i}};o(v),c({...t,preferences:v});};return/* @__PURE__ */n(Se,{value:"line-style",className:"border-b-0",children:[/* @__PURE__ */e(Te,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(zd,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Line Style"})]})}),/* @__PURE__ */e(ke,{className:"pt-2",children:/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */e("p",{className:"text-xs text-muted-foreground",children:"Default styles for all series. Override per-series in the Series section."}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Line Pattern"}),/* @__PURE__ */n(ae,{value:(r==null?void 0:r.lineStyle)||"solid",onValueChange:l=>d("lineStyle",l),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:Zm.map(({value:l,label:i})=>/* @__PURE__ */e(H,{value:l,className:"text-xs",children:i},l))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Point Size"}),/* @__PURE__ */n(ae,{value:String((r==null?void 0:r.pointRadius)??3),onValueChange:l=>d("pointRadius",Number(l)),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:Xm.map(l=>/* @__PURE__ */e(H,{value:String(l),className:"text-xs",children:l===0?"None":l},l))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Point Shape"}),/* @__PURE__ */n(ae,{value:(r==null?void 0:r.pointStyle)||"circle",onValueChange:l=>d("pointStyle",l),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:Jm.map(({value:l,label:i})=>/* @__PURE__ */e(H,{value:l,className:"text-xs",children:i},l))})]})]})]})})]});}const th=[0,2,4,6,8,10,12,16,20],ah=[{value:"0.5",label:"50%"},{value:"0.6",label:"60%"},{value:"0.7",label:"70%"},{value:"0.8",label:"80%"},{value:"0.9",label:"90%"},{value:"1",label:"100%"}],nh=[{value:"0.5",label:"50%"},{value:"0.6",label:"60%"},{value:"0.7",label:"70%"},{value:"0.8",label:"80%"},{value:"0.9",label:"90%"},{value:"1",label:"100%"}];function rh(){const t=T(l=>l.card),a=T(l=>{var i;return(i=l.card)==null?void 0:i.preferences;}),s=Ve(),r=a==null?void 0:a.barStyleConfig,{setCardPreferences:o,updateCardInFrame:c}=he();if(!t||!["bar","horizontalBar","stackedBar"].includes(s))return null;const d=(l,i)=>{const v={...(a||{}),barStyleConfig:{...r,[l]:i}};o(v),c({...t,preferences:v});};return/* @__PURE__ */n(Se,{value:"bar-style",className:"border-b-0",children:[/* @__PURE__ */e(Te,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Jr,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Bar Style"})]})}),/* @__PURE__ */e(ke,{className:"pt-2",children:/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */e("p",{className:"text-xs text-muted-foreground",children:"Default styles for all bars. Override per-series in the Series section."}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Corner Radius"}),/* @__PURE__ */n(ae,{value:String((r==null?void 0:r.borderRadius)??0),onValueChange:l=>d("borderRadius",Number(l)),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:th.map(l=>/* @__PURE__ */e(H,{value:String(l),className:"text-xs",children:l===0?"None":`${l}px`},l))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Bar Width"}),/* @__PURE__ */n(ae,{value:String((r==null?void 0:r.barPercentage)??0.9),onValueChange:l=>d("barPercentage",Number(l)),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:ah.map(({value:l,label:i})=>/* @__PURE__ */e(H,{value:l,className:"text-xs",children:i},l))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium",children:"Category Width"}),/* @__PURE__ */n(ae,{value:String((r==null?void 0:r.categoryPercentage)??0.8),onValueChange:l=>d("categoryPercentage",Number(l)),children:[/* @__PURE__ */e(ne,{className:"h-8 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */e(se,{children:nh.map(({value:l,label:i})=>/* @__PURE__ */e(H,{value:l,className:"text-xs",children:i},l))})]})]})]})})]});}function sh(){const t=T(s=>{var r,o;return(o=(r=s==null?void 0:s.card)==null?void 0:r.preferences)==null?void 0:o.sortChart;}),{setSortChart:a}=he();return/* @__PURE__ */n(Se,{value:"stacked-sort",children:[/* @__PURE__ */e(Te,{children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(ss,{className:"h-3.5 w-3.5 text-foreground/60"}),"Sort"]})}),/* @__PURE__ */e(ke,{className:"space-y-4 px-1",children:/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(L,{children:"Sort Order"}),/* @__PURE__ */e(jt,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"Ascending",value:"asc"},{label:"Descending",value:"desc"}],value:t||"none",onValueChange:s=>{a(s);}})]})})]});}const lh=["kpi"],Pa=2;function it(t){return typeof t=="string"?t.trim().toLowerCase():((t==null?void 0:t.id)||(t==null?void 0:t.qualifiedFieldName)||(t==null?void 0:t.name)||(t==null?void 0:t.label)||"").trim().toLowerCase();}function oh(t){if(!(t!=null&&t.name)||!(t!=null&&t.dataType)||t.role==="metric")return!1;const a=Pl(t.dataType);return["date","string","boolean"].includes(a);}function ih(t){return{...t,role:"groupby"};}function ch(){var y,R;const t=T(x=>x.card),a=T(x=>x.actions.updateCardConfig),s=Ve(),{scopedFields:r}=Br(),o=((y=t.config)==null?void 0:y.metricColumns)||[],c=((R=t.config)==null?void 0:R.summary)||{},d=c.breakdownDimensions||[],l=d.length>0,i=lh.includes(s),v=o.length>0,u=c.enabled===!0,p=i&&v,f=Array.from(new Map(r.filter(oh).map(x=>[it(x),ih(x)])).values()),m=new Set(f.map(x=>it(x))),N=new Set(d.map(x=>it(x)).filter(x=>x&&m.has(x)));if(!i)return null;const w=x=>{a(t.id,{summary:{...c,...x}});},S=(x,D)=>{const B=it(x),$=f.filter(k=>N.has(it(k))),j=D?N.has(B)?$:[...$,x].slice(0,Pa):$.filter(k=>it(k)!==B);w({breakdownDimensions:j,...(j.length>0?{showOnCard:!0}:{})});};return/* @__PURE__ */n(Se,{value:"summary",className:"border-none",children:[/* @__PURE__ */e(Te,{className:"flex items-center gap-2 py-2 text-[12px] hover:no-underline [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground",children:/* @__PURE__ */n("div",{className:"flex flex-1 items-center gap-2",children:[/* @__PURE__ */e(Pc,{className:"h-3.5 w-3.5 text-foreground/60"}),/* @__PURE__ */e("span",{children:"Summary"})]})}),/* @__PURE__ */n(ke,{className:"space-y-3 pb-4 pt-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{htmlFor:"summary-enabled",className:"text-xs",children:"Show summary"}),/* @__PURE__ */e(we,{id:"summary-enabled",size:"xs",checked:u,disabled:!p,onCheckedChange:x=>{if(!x){w({enabled:!1,showOnCard:!1,includeInDashboardSummary:!1});return;}w({enabled:!0,showOnCard:c.showOnCard??!0,includeInDashboardSummary:c.includeInDashboardSummary??!0});}})]}),/* @__PURE__ */n("div",{className:W("space-y-3 transition-opacity",!u&&"opacity-60"),children:[!p&&/* @__PURE__ */e("p",{className:"text-[11px] text-muted-foreground",children:v?"Summary is not supported for this card type.":"Add at least one metric to enable summary."}),!l&&/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Lt,{id:"summary-show-on-card",checked:c.showOnCard===!0,disabled:!u,onCheckedChange:x=>w({showOnCard:x===!0})}),/* @__PURE__ */e(L,{htmlFor:"summary-show-on-card",className:"cursor-pointer text-xs",children:"Show summary on card"})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Lt,{id:"summary-include-rollup",checked:c.includeInDashboardSummary===!0,disabled:!u,onCheckedChange:x=>w({includeInDashboardSummary:x===!0})}),/* @__PURE__ */e(L,{htmlFor:"summary-include-rollup",className:"cursor-pointer text-xs",children:"Include in dashboard summary"})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Breakdown Dimensions"}),/* @__PURE__ */n("span",{className:"text-[11px] tabular-nums text-muted-foreground",children:[d.length,"/",Pa]})]}),f.length===0?/* @__PURE__ */e("p",{className:"text-[11px] text-muted-foreground",children:"No dimension fields available for breakdown."}):/* @__PURE__ */e("ul",{className:"max-h-40 space-y-1 overflow-y-auto",children:f.map(x=>{const D=it(x),B=N.has(D),$=N.size>=Pa,j=!u||!B&&$;return/* @__PURE__ */n("li",{className:"flex items-center gap-2 text-xs",children:[/* @__PURE__ */e(Lt,{id:`summary-breakdown-${D}`,checked:B,disabled:j,onCheckedChange:k=>S(x,k===!0)}),/* @__PURE__ */e(L,{htmlFor:`summary-breakdown-${D}`,className:"cursor-pointer text-xs",children:x.label||x.name})]},D);})})]})]})]})]});}const dh={hour:"Hour",minute:"Minute",second:"Second",day:"Day",week:"Week",month:"Month",quarter:"Quarter",year:"Year"},Da=t=>dh[t??"day"]??"Day";function uh(){const t=T(a=>a.card);return!t||t.type!=="kpi"||Xa(t)?null:/* @__PURE__ */e(mh,{card:t});}function mh({card:t}){var m,N,w,S,b;const{setCardConfig:a}=he(),{data:s}=$e(t),r=s==null?void 0:s.metadata,o=Dl(t.config),c=!!(r!=null&&r.dateContext&&!r.dateContext.field&&!o),d=((m=t.config)==null?void 0:m.kpiBand)==="trend",l=((N=t.config)==null?void 0:N.kpiTrendGrain)??"automatic",i=((S=(w=r==null?void 0:r.dateContext)==null?void 0:w.counted)==null?void 0:S.status)==="window"?r.dateContext.counted.window:void 0,v=((b=r==null?void 0:r.trend)==null?void 0:b.grainSource)==="automatic"?r.trend.granularity:void 0,u=y=>a(Vl(t,y).config),p=y=>a(Bl(t,y==="automatic"?null:y).config),f=c?d?"This KPI counts on no date, so the trend can't show. Turn it off, or drop a date on Trend By.":"This KPI counts on no date. Drop a date on Trend By to show a trend.":d?o?"Trend By sets the grain. Remove it to pick one here.":l==="automatic"?"Follows the period the KPI counts: a different dashboard date changes it.":`Always by ${l}.`:"A line of the value over the period it counts.";return(/* @__PURE__ */n(Se,{value:"kpi-trend",className:"border-none","data-role":"kpi-trend-settings",children:[/* @__PURE__ */e(Te,{className:"flex items-center gap-2 py-2 text-[12px] hover:no-underline [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground",children:/* @__PURE__ */n("div",{className:"flex flex-1 items-center gap-2",children:[/* @__PURE__ */e(os,{className:"h-3.5 w-3.5 text-foreground/60","aria-hidden":!0}),/* @__PURE__ */e("span",{children:"Trend"})]})}),/* @__PURE__ */n(ke,{className:"space-y-3 pb-4 pt-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(L,{htmlFor:"kpi-trend",className:"text-xs",children:"Show trend"}),/* @__PURE__ */e(we,{id:"kpi-trend",size:"xs",checked:d,disabled:c&&!d,onCheckedChange:u})]}),d&&!c&&/* @__PURE__ */n("div",{className:"space-y-2","data-role":"kpi-trend-grain",children:[/* @__PURE__ */e(L,{htmlFor:"kpi-trend-grain",className:"text-xs",children:"Grain"}),o?/* @__PURE__ */n("div",{className:"flex h-8 items-center justify-between rounded-control border border-border bg-muted/30 px-2.5 text-xs text-foreground/80",children:[Da(o.granularity)," · from Trend By",/* @__PURE__ */e(Dc,{className:"h-3 w-3 text-muted-foreground","aria-hidden":!0})]}):/* @__PURE__ */n(ae,{value:l,onValueChange:p,children:[/* @__PURE__ */e(ne,{id:"kpi-trend-grain",className:"h-8 text-xs",children:/* @__PURE__ */e(re,{})}),/* @__PURE__ */n(se,{children:[/* @__PURE__ */e(H,{value:"automatic",className:"text-xs",children:v?`Automatic · ${Da(v)}`:"Automatic"}),Od.map(y=>{const R=i?Ll(i,y)>_l:!1;return/* @__PURE__ */n(H,{value:y,className:"text-xs",disabled:R&&y!==l,children:[Da(y),R?" · too many points":""]},y);})]})]})]}),/* @__PURE__ */e("p",{className:"text-[11px] text-muted-foreground",children:f})]})]}));}const hh=/* @__PURE__ */new Set(["area","bar","bubble","bullet","combo","doughnut","funnel","horizontalBar","line","pie","polarArea","radar","scatter","stackedArea","stackedBar","stackedLine","tornado"]);function ph(){const t=T(u=>u.card),a=T(u=>{var p;return(p=u.card)==null?void 0:p.preferences;}),s=Ve(),{setCardPreferences:r,updateCardInFrame:o}=he(),c=a==null?void 0:a.tooltipConfig,[d,l]=Y(!!(c!=null&&c.valueFormat));if(!t||!hh.has(s||""))return null;const i=d||c!=null&&c.valueFormat?"override":"inherit",v=u=>{const p={...(a||{}),tooltipConfig:u};r(p),o({...t,preferences:p});};return/* @__PURE__ */n(Se,{value:"tooltip-format",className:"border-b-0",children:[/* @__PURE__ */e(Te,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(ct,{className:"h-3.5 w-3.5 text-foreground/60"}),/* @__PURE__ */e("span",{children:"Tooltip Format"})]})}),/* @__PURE__ */n(ke,{className:"space-y-4 pt-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(L,{className:"text-xs font-medium text-muted-foreground",children:"Override metric format"}),/* @__PURE__ */e("div",{className:"text-xs text-muted-foreground",children:"Keep this off to inherit from each metric."})]}),/* @__PURE__ */e(we,{size:"sm",checked:i==="override",onCheckedChange:u=>{if(l(u),!u){const{valueFormat:p,...f}=c??{};v(f);}}})]}),i==="override"&&/* @__PURE__ */e(Xt,{formatOptions:Cn(c==null?void 0:c.valueFormat)||{},onFormatOptionsChange:u=>v({...c,valueFormat:wn(u)}),showTitle:!1})]})]});}function Ts({mode:t}){const a=T(s=>{var r;return(r=s.card)==null?void 0:r.type;});return ts(a)?null:/* @__PURE__ */n(be,{children:[a==="combo"&&/* @__PURE__ */e(Rm,{}),(a==="area"||a==="stackedArea")&&/* @__PURE__ */e(Bm,{}),a==="line"&&/* @__PURE__ */e($m,{}),(a==="bar"||a==="horizontalBar"||a==="stackedBar")&&/* @__PURE__ */e(Gm,{}),/* @__PURE__ */e(eh,{}),/* @__PURE__ */e(rh,{}),/* @__PURE__ */e(xm,{}),t==="config"&&/* @__PURE__ */e(rm,{}),t==="config"&&/* @__PURE__ */e(ch,{}),t==="config"&&/* @__PURE__ */e(uh,{}),/* @__PURE__ */e(vm,{}),a==="bullet"&&/* @__PURE__ */e(ym,{}),a==="funnel"&&/* @__PURE__ */e(wm,{}),(a==="bubble"||a==="scatter")&&/* @__PURE__ */e(Nm,{}),(a==="stackedBar"||a==="stackedLine")&&/* @__PURE__ */e(sh,{}),/* @__PURE__ */e(hm,{}),/* @__PURE__ */e(pm,{}),/* @__PURE__ */e(fm,{}),/* @__PURE__ */e(gm,{}),/* @__PURE__ */e(ph,{})]});}function fh(){const t=T(s=>s.card),a=t==null?void 0:t.type;return a?/* @__PURE__ */n("div",{className:"space-y-4 px-6 py-4",children:[/* @__PURE__ */e(ys,{chartType:a}),/* @__PURE__ */e(Yt,{type:"single",collapsible:!0,className:"w-full px-2",children:/* @__PURE__ */e(Ts,{mode:"dev"})})]}):null;}function gh({focusSection:t,focusRequestId:a}){const r=T(c=>c.card).type;function o(){if(Za(r))return/* @__PURE__ */e(Ss,{cardType:r,focusSection:t,focusRequestId:a});switch(r){case"kpi":return/* @__PURE__ */e(Yu,{});case"custom":return/* @__PURE__ */e("div",{className:"px-6 py-2",children:/* @__PURE__ */e(bs,{})});case"text":return/* @__PURE__ */e(im,{});default:return/* @__PURE__ */e(fh,{});}}return/* @__PURE__ */n(pn,{className:"h-full w-full text-sm",children:[o(),/* @__PURE__ */e(Lc,{orientation:"horizontal"})]});}const xh=32;function bh(){const t=Oe(null),a=T(p=>p.isDevMode),[s,r]=Y(!1),[o,c]=Y({section:null,id:0}),d=!a||s,l=()=>r(p=>!p),i=p=>{p&&c(f=>({section:p,id:f.id+1})),a&&r(!0);},v=()=>{const p=t.current;p&&(p.isCollapsed()?p.expand():p.collapse());},u={show:a,isOpen:d,onToggle:l,onOpen:i};return/* @__PURE__ */n(Qa,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[/* @__PURE__ */e(yt,{ref:t,role:"query-section",className:"flex",minSize:20,defaultSize:50,collapsible:!0,collapsedSize:0,children:/* @__PURE__ */e("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:/* @__PURE__ */e(ou,{})})}),/* @__PURE__ */e(Bu,{onToggleEditor:v,children:/* @__PURE__ */e(Ea,{mode:"toolbar",visualAsideControl:u})}),/* @__PURE__ */e(yt,{role:"visual-section",minSize:0,defaultSize:50,children:d?/* @__PURE__ */n(Qa,{direction:"horizontal",children:[/* @__PURE__ */e(yt,{minSize:40,defaultSize:75,maxSize:100,children:/* @__PURE__ */e(Ea,{mode:"canvas",visualAsideControl:u})}),/* @__PURE__ */e(cs,{}),/* @__PURE__ */e(yt,{className:"flex",defaultSize:xh,maxSize:45,children:/* @__PURE__ */e(gh,{focusSection:o.section,focusRequestId:o.id})})]}):/* @__PURE__ */e(Ea,{mode:"canvas",visualAsideControl:u})})]});}const vh="inline-flex w-3 shrink-0 cursor-grab items-center text-muted-foreground/40 transition-colors duration-150 group-hover:text-muted-foreground group-focus-within:text-muted-foreground hover:!text-foreground active:cursor-grabbing";function dr({label:t}){const a=t.indexOf(" › ");return a<0?/* @__PURE__ */e(be,{children:t}):/* @__PURE__ */n(be,{children:[t.slice(0,a)," ",/* @__PURE__ */e("span",{className:"mx-1 text-muted-foreground",children:"›"})," ",t.slice(a+3)]});}function ks({id:t,field:a,zone:s,label:r,dataType:o,nativeDataType:c,calculated:d,open:l,onOpenChange:i,onRemove:v,sortDirection:u,onSortDirectionChange:p,badge:f,children:m}){const{attributes:N,listeners:w,setNodeRef:S,isDragging:b}=bi({id:vi(t),data:{origin:s,field:a}}),{setNodeRef:y}=Kr({id:yi(t),data:{kind:"pill",zone:s,pillId:t}}),R=nt(x=>{S(x),y(x);},[S,y]);return/* @__PURE__ */n(st,{modal:!0,open:l,onOpenChange:i,children:[/* @__PURE__ */n("div",{ref:R,className:W("group flex h-7 w-full items-center gap-1.5 rounded-control border bg-background px-1.5 transition-colors",l?"border-foreground/30 bg-muted/40":"border-border hover:bg-muted/40",b&&"z-50 scale-95 opacity-50"),children:[/* @__PURE__ */e("button",{type:"button",...N,...w,"aria-label":`Drag ${r}`,className:vh,onClick:x=>x.stopPropagation(),children:/* @__PURE__ */e(cn,{className:"h-3 w-3"})}),/* @__PURE__ */e(Ni,{dataType:o,nativeDataType:c,calculated:d}),m?/* @__PURE__ */e(xt,{asChild:!0,children:/* @__PURE__ */e("button",{type:"button","aria-label":`${r} settings`,className:"block w-0 min-w-0 flex-1 truncate text-left text-[12px] text-foreground hover:underline data-[state=open]:underline",onClick:x=>x.stopPropagation(),children:/* @__PURE__ */e(Bn,{className:"block truncate",children:/* @__PURE__ */e(dr,{label:r})})})}):/* @__PURE__ */e(Bn,{className:"block w-0 min-w-0 flex-1 text-[12px] text-foreground",children:/* @__PURE__ */e(dr,{label:r})}),f,p&&/* @__PURE__ */e("button",{type:"button","aria-label":u==="asc"?"Switch to descending":"Switch to ascending",className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-muted hover:text-foreground",onClick:x=>{x.stopPropagation(),p(u==="asc"?"desc":"asc");},children:u==="asc"?/* @__PURE__ */e(_c,{className:"h-3 w-3"}):/* @__PURE__ */e(Vc,{className:"h-3 w-3"})}),/* @__PURE__ */e("button",{type:"button","aria-label":"Remove",className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-[3px] text-muted-foreground opacity-0 hover:bg-muted hover:text-foreground group-focus-within:opacity-100 group-hover:opacity-100 [@media(hover:none)]:opacity-100",onClick:x=>{x.stopPropagation(),v();},children:/* @__PURE__ */e(Zt,{className:"h-3 w-3"})})]}),m&&/* @__PURE__ */n(lt,{align:"start",sideOffset:6,className:"flex max-h-[480px] w-[320px] flex-col p-0",children:[/* @__PURE__ */e(Ci,{field:a,title:r,onClose:()=>i(!1)}),/* @__PURE__ */e("div",{className:"min-h-0 flex-1 space-y-3 overflow-y-auto p-3",children:m})]})]});}function yh(t){const a=wi(t),{field:s,zone:r}=t;return/* @__PURE__ */n(be,{children:[/* @__PURE__ */e(ks,{id:s.id,field:s,zone:r,label:a.label,dataType:a.dataType,nativeDataType:a.nativeDataType,calculated:a.calculated,open:a.open,onOpenChange:a.setOpen,onRemove:a.remove,sortDirection:a.sortDirection,onSortDirectionChange:a.onSortDirectionChange,badge:a.badge,children:a.settings}),a.dialogs]});}function Nh({field:t,zone:a,onRemove:s}){const[r,o]=Y(!1);return/* @__PURE__ */e(ks,{id:t.id,field:t,zone:a,label:Kl(t),dataType:t.dataType,nativeDataType:t.nativeDataType,calculated:Si(t),open:r,onOpenChange:o,onRemove:s,children:/* @__PURE__ */e(Ka,{fieldId:t.id})});}function Ch({concept:t}){const{title:a,description:s}=wh[t];return/* @__PURE__ */n(wt,{openDelay:150,closeDelay:50,children:[/* @__PURE__ */e(St,{asChild:!0,children:/* @__PURE__ */e("button",{type:"button","aria-label":`What does ${a} mean?`,className:"inline-flex h-3 w-3 shrink-0 items-center justify-center text-muted-foreground/70 transition-colors hover:text-foreground",children:/* @__PURE__ */e(Ld,{className:"h-3 w-3"})})}),/* @__PURE__ */n(Tt,{side:"right",align:"start",sideOffset:8,className:"w-[260px] space-y-2 rounded-control border border-border bg-popover p-3 shadow-[0_4px_16px_rgba(0,0,0,0.08)]",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e("p",{className:"text-[12px] font-semibold text-foreground",children:a}),/* @__PURE__ */e("p",{className:"text-[11px] leading-[1.45] text-muted-foreground",children:s})]}),t!=="detailColumns"&&/* @__PURE__ */e(Sh,{highlight:t})]})]});}const wh={groupBy:{title:"Rows",description:"Each unique value becomes a row. Use for the dimensions you want stacked vertically."},pivotBy:{title:"Pivot Columns",description:"Each unique value spreads across as a column, splitting your metrics horizontally."},metrics:{title:"Metrics",description:"The aggregated numbers (sum, count, avg…) that fill the cells of your chart or table."},detailColumns:{title:"Columns",description:"Raw column values with no aggregation — the underlying detail rows from the database."}};function Sh({highlight:t}){const a=t==="pivotBy",s=t==="groupBy",r=t==="metrics",o="bg-foreground/[0.06] font-medium text-foreground dark:bg-foreground/[0.12]";return/* @__PURE__ */e("div",{className:"overflow-hidden rounded-control border border-border",children:/* @__PURE__ */n("table",{className:"w-full text-[10px]",children:[/* @__PURE__ */e("thead",{children:/* @__PURE__ */n("tr",{className:"border-b border-border bg-muted/40",children:[/* @__PURE__ */e("th",{className:"px-1.5 py-1 text-left font-normal text-muted-foreground"}),["North","South","East"].map(c=>/* @__PURE__ */e("th",{className:W("px-1.5 py-1 text-center font-normal text-muted-foreground",a&&o),children:c},c))]})}),/* @__PURE__ */e("tbody",{children:ur.map((c,d)=>/* @__PURE__ */n("tr",{className:W(d!==ur.length-1&&"border-b border-border/60"),children:[/* @__PURE__ */e("td",{className:W("px-1.5 py-1 text-left text-muted-foreground",s&&o),children:c.label}),c.values.map((l,i)=>/* @__PURE__ */e("td",{className:W("px-1.5 py-1 text-right font-mono tabular-nums text-muted-foreground",r&&o),children:l},i))]},c.label))})]})});}const ur=[{label:"Electronics",values:["2,300","1,800","3,400"]},{label:"Clothing",values:["1,300","620","480"]}],Th={groupBy:Wr,pivotBy:Gr,metrics:Ei,detailColumns:Ur,sortBy:ss};function Dt({onRemoveField:t,zone:a,fields:s,label:r,placeholder:o,shouldShow:c,hasPivotColumns:d=!1}){const{setNodeRef:l}=Kr({id:Ti(a),data:{kind:"shelf",zone:a,pillIds:s.map(x=>x.id)}}),i=ki(a),{updateSortByColumn:v}=he(),u=T(x=>x.card),p=T(x=>x.card.type),f=s.length>0,m=i!==null,N=(i==null?void 0:i.kind)!=="refused",w=(i==null?void 0:i.kind)==="refused"?Ii(i.notice,r):null,S=nt((x,D)=>{var $;!(($=u.config)!=null&&$.sortByColumns)||u.config.sortByColumns.findIndex(j=>j.id===x)===-1||v(u.id,x,{direction:D});},[u,v]),b=X(()=>/* @__PURE__ */e("div",{className:"space-y-1",children:s.map((x,D)=>{const $=x.direction;return/* @__PURE__ */n("div",{className:"relative",children:[/* @__PURE__ */e(kh,{zone:a,pillId:x.id,isLast:D===s.length-1}),p==="matrixTable"?/* @__PURE__ */e(Nh,{field:x,zone:a,onRemove:()=>t(a,D)}):/* @__PURE__ */e(yh,{field:x,zone:a,index:D,sortDirection:$,onSortDirectionChange:j=>S(x.id,j),hasPivotColumns:d,cardType:p})]},x.id);})}),[s,a,p,d,t,S]);if(a==="sortBy"&&c===!1)return null;const y=a!=="sortBy"&&p!=="kpi",R=Th[a]||da;return/* @__PURE__ */n("div",{ref:l,className:"w-full",role:"group","aria-label":r,children:[/* @__PURE__ */n("div",{className:"mb-1 flex min-w-0 items-center justify-between gap-2",children:[/* @__PURE__ */e(L,{className:"block shrink-0 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:r}),w&&/* @__PURE__ */e("span",{role:"status","data-shelf-refusal-reason":"",className:"min-w-0 truncate text-[11px] text-destructive",children:w})]}),/* @__PURE__ */e("div",{className:W("rounded-control transition-colors",{"border border-foreground/40 bg-muted/50":m&&N,"border border-destructive/40 bg-destructive/5":m&&!N,"border border-dashed border-border/50 bg-background":!m&&!f}),children:s.length===0?/* @__PURE__ */n("div",{className:"flex h-9 items-center justify-center gap-1.5 text-[11px] text-muted-foreground/80",children:[/* @__PURE__ */e(R,{className:"h-3 w-3 shrink-0 text-muted-foreground/60"}),/* @__PURE__ */e("span",{children:o}),y&&/* @__PURE__ */e(Ch,{concept:a})]}):b})]});}function kh({zone:t,pillId:a,isLast:s}){const r=Fi(t,a,s);return r?/* @__PURE__ */n("div",{"aria-hidden":!0,"data-shelf-insertion-line":r,className:W("pointer-events-none absolute inset-x-0 z-10 flex h-1.5 items-center",r==="top"?"-top-[5px]":"-bottom-[5px]"),children:[/* @__PURE__ */e("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full border-[1.5px] border-foreground bg-background"}),/* @__PURE__ */e("span",{className:"h-0.5 flex-1 bg-foreground"})]}):null;}const Ih="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Eh({card:t,metric:a,children:s}){var v,u;const{data:r}=$e(t),o=r==null?void 0:r.metadata,c=pd(o==null?void 0:o.dateContext,a?Zr(o==null?void 0:o.comparisonMetadata,a):void 0),d=r==null?void 0:r.records,l=((v=zl({renderCard:t,records:d,metadata:o}).trend)==null?void 0:v.points.length)??0,i=((u=t.config)==null?void 0:u.kpiBand)==="trend"?Md(o==null?void 0:o.trend,l):void 0;return/* @__PURE__ */e(be,{children:s(c,i)});}function Fh({view:t,trend:a}){const s=xe(o=>o.dashboard),r=fd(t,{cardTitle:o=>{var c;return s?(c=rd(s,o))==null?void 0:c.title:void 0;}});return/* @__PURE__ */e(Oh,{words:r,trend:a});}function Oh({words:t,trend:a}){return/* @__PURE__ */n("div",{className:"space-y-1.5 pt-1","data-role":"kpi-date-section",children:[/* @__PURE__ */e("div",{className:Ih,children:"Date"}),/* @__PURE__ */n("div",{className:"rounded-control border border-border bg-muted/20 text-[12px]",children:[/* @__PURE__ */n("div",{className:"flex items-start gap-2 border-b border-border/70 px-2.5 py-2",children:[/* @__PURE__ */e(Bc,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground","aria-hidden":!0}),t.field?/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */e("div",{className:"truncate font-medium",children:t.field.name}),/* @__PURE__ */e("div",{className:"text-[11px] text-muted-foreground",children:t.field.from})]}):/* @__PURE__ */e("div",{className:"text-muted-foreground",children:"No date"})]}),t.windows.length>0&&/* @__PURE__ */e("div",{className:"space-y-2 border-b border-border/70 px-2.5 py-2",children:t.windows.map(s=>/* @__PURE__ */n("div",{className:W(!s.applied&&"opacity-50"),children:[/* @__PURE__ */e("div",{className:W("leading-tight",!s.applied&&"line-through"),children:s.text}),/* @__PURE__ */e("div",{className:"text-[11px] leading-tight text-muted-foreground",children:s.from})]},`${s.text}|${s.from}`))}),/* @__PURE__ */n("div",{className:"space-y-2 px-2.5 py-2",children:[/* @__PURE__ */n("div",{children:[/* @__PURE__ */e("div",{className:"text-[11px] leading-tight text-muted-foreground",children:"Counts"}),/* @__PURE__ */e("div",{className:"font-medium leading-tight",children:t.counts})]}),t.compared&&/* @__PURE__ */n("div",{children:[/* @__PURE__ */e("div",{className:"text-[11px] leading-tight text-muted-foreground",children:"Compared with"}),/* @__PURE__ */e("div",{className:"leading-tight",children:t.compared})]}),a&&/* @__PURE__ */n("div",{"data-role":"kpi-trend-row",children:[/* @__PURE__ */e("div",{className:"text-[11px] leading-tight text-muted-foreground",children:"Trend"}),/* @__PURE__ */e("div",{className:"leading-tight",children:a.head}),/* @__PURE__ */e("div",{className:"text-[11px] leading-tight text-muted-foreground",children:a.detail})]})]}),t.note&&/* @__PURE__ */n("div",{"data-role":"kpi-date-note",className:W("flex gap-1.5 border-t px-2.5 py-2 text-[11.5px] leading-snug",t.note.tone==="warn"?"border-amber-200 bg-amber-50 text-amber-900 dark:border-amber-900/50 dark:bg-amber-950/30 dark:text-amber-200":"border-border/70 text-muted-foreground"),children:[t.note.tone==="warn"?/* @__PURE__ */e(Kc,{className:"mt-0.5 h-3.5 w-3.5 shrink-0","aria-hidden":!0}):/* @__PURE__ */e(ct,{className:"mt-0.5 h-3.5 w-3.5 shrink-0","aria-hidden":!0}),/* @__PURE__ */e("span",{children:t.note.text})]})]})]});}const Mh=[];function Rh({onRemoveField:t,onResetFields:a,groupByFields:s,pivotByFields:r,metricsFields:o,sortByFields:c,detailFields:d}){var G,ee,ie;const[l,i]=Y(!1),{startOver:v,restore:u}=Oi();T(Q=>{var q;return!!((q=Q.card.customCardPreferences)!=null&&q.url);});const p=T(Q=>Q.card),f=T(Q=>Q.frame),m=dt(f,p),{manifest:N}=bt(((G=m==null?void 0:m.customCardPreferences)==null?void 0:G.url)||""),w=(ee=N==null?void 0:N.visuals)==null?void 0:ee.find(Q=>{var q;return Q.name===((q=m==null?void 0:m.customCardPreferences)==null?void 0:q.componentName);}),S=ut(m,w)==="multiple";S&&(ie=m==null?void 0:m.customCardPreferences)!=null&&ie.url;const b=ql(w==null?void 0:w.slots);T(Q=>Q.actions.updateCardConfig);const y=T(Q=>Q.actions.updateCard),R=xe(Q=>Q.actions.updateDashboardCalculatedFields),D=xe(Q=>{var q;return Q.visualEditPendingDashboardCalculatedFields??((q=Q.dashboard)==null?void 0:q.calculatedFields);})??Mh,{scopedFields:B}=Br(),{userContext:$}=tn(),j=S&&(m==null?void 0:m.id)===p.id&&b?b:p==null?void 0:p.type,k=j==="detailTable",O=s.length>0||o.length>0||d.length>0,A=!k&&(j!=="kpi"||o.length<=2),F=!k,K=!k&&j!=="kpi",E=j!=="kpi"&&j!=="matrixTable"&&O,h=k,I="Drop sort fields here",g=Mi($),C=["pie","doughnut","polar","funnel","bubble","scatter"].includes(j),M=K&&!C,z=j==="kpi"&&p.type==="kpi"&&!S&&!Xa(p),_=Q=>j==="kpi"?{label:"Trend By",placeholder:gd(Q)??"Drop trend field here"}:{label:"Rows",placeholder:"Drop dimensions here"},P=()=>j==="kpi"?{label:"Metric",placeholder:"Drop metric here"}:{label:"Metrics",placeholder:"Drop metrics here"},V=(Q,q)=>/* @__PURE__ */n("div",{className:"space-y-3 px-4 pb-6 pt-3",children:[A&&/* @__PURE__ */e(Dt,{zone:"groupBy",onRemoveField:t,fields:s,label:_(Q).label,placeholder:_(Q).placeholder}),M&&/* @__PURE__ */e(Dt,{zone:"pivotBy",onRemoveField:t,fields:r,label:"Pivot Columns",placeholder:"Drop pivot fields here"}),F&&/* @__PURE__ */e(Dt,{zone:"metrics",onRemoveField:t,fields:o,label:P().label,placeholder:P().placeholder,hasPivotColumns:r.length>0}),h&&/* @__PURE__ */e(Dt,{zone:"detailColumns",onRemoveField:t,fields:d,label:"Columns",placeholder:"Drop columns here"}),o.length>=1&&g&&/* @__PURE__ */n(ue,{variant:"outline",size:"sm",onClick:()=>i(!0),className:"mt-1.5 w-full justify-start border-border/60 border-dashed bg-background text-xs text-foreground/70 hover:bg-muted/40 hover:text-foreground",children:[/* @__PURE__ */e(Di,{className:"mr-2 h-4 w-4"}),"Create Metric"]}),Q&&/* @__PURE__ */e(Fh,{view:Q,trend:q}),E&&/* @__PURE__ */e(Dt,{zone:"sortBy",onRemoveField:t,fields:c,label:"Sort By",placeholder:I})]});return/* @__PURE__ */n(be,{children:[/* @__PURE__ */n("div",{"data-shelf-scroll-header":"",className:"sticky top-0 z-10 flex items-center justify-between bg-background px-4 py-2",children:[/* @__PURE__ */e("span",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-foreground/70",children:"Fields"}),/* @__PURE__ */e(Ph,{card:p,hasFields:O,onClearFields:()=>{var pe;const Q=p,q=jl.flatMap(fe=>{var Ee;return((Ee=Q.config)==null?void 0:Ee[fe])??[];}),te=((pe=Va(Q))==null?void 0:pe.joins)??[];a();const ce=q.map(fe=>fe.label||fe.name),me=ce.length>4?`${ce.slice(0,3).join(", ")} and ${ce.length-3} more`:ce.join(", "),le=te.length===1?` The join to ${vr(te[0].target)} stays.`:te.length?" The joins stay.":"";at("Cleared the fields",{description:`${me?`Removed ${me}.`:""}${le}`.trim()||void 0,action:{label:"Undo",onClick:()=>u(Q)}});},onStartOver:v})]}),z?/* @__PURE__ */e(Eh,{card:p,metric:o[0],children:(Q,q)=>V(Q,q)}):V(void 0),/* @__PURE__ */e(Ri,{open:l,onOpenChange:i,availableFields:B,initialFieldType:"metric",allowedFieldTypes:["metric"],onSave:Q=>{if(Q.role!=="metric")return;const{nextStoredFields:q}=Pi({storedFields:p.calculatedFields||[],sharedFields:D,updatedField:Q,previousScope:"card"});y(p.id,{calculatedFields:q});},onSaveToDashboard:Q=>{if(Q.role!=="metric")return;const{nextSharedFields:q}=Ai({storedFields:p.calculatedFields||[],sharedFields:D,updatedField:Q,previousScope:"dashboard"});R(q);},cardId:p.id})]});}function Ah(){var y,R,x;const t=T(D=>{var B;return(B=D.card)==null?void 0:B.type;}),a=t==="kpi",[s,r]=Y(a),[o,c]=Y(!1),d=T(D=>{var B;return!!((B=D.card.customCardPreferences)!=null&&B.url);}),l=T(D=>D.card),i=T(D=>D.frame),v=dt(i,l),{manifest:u}=bt(((y=v==null?void 0:v.customCardPreferences)==null?void 0:y.url)||""),p=(R=u==null?void 0:u.visuals)==null?void 0:R.find(D=>{var B;return D.name===((B=v==null?void 0:v.customCardPreferences)==null?void 0:B.componentName);}),m=ut(v,p)==="multiple"&&!!((x=v==null?void 0:v.customCardPreferences)!=null&&x.url),N=!d||m,w=d||m,S=a?"KPI Settings":"Chart Settings",b=N&&!ts(t);return ve(()=>{a&&r(!0);},[a]),!b&&!w?null:/* @__PURE__ */n("div",{className:"shrink-0 border-t border-border bg-background",children:[b&&s&&/* @__PURE__ */e("div",{className:W("overflow-y-auto border-b border-border px-4",a?"max-h-[72vh]":"max-h-[50vh]"),children:/* @__PURE__ */e(Yt,{type:"single",collapsible:!0,className:"w-full divide-y divide-border/60 [&_h3]:sticky [&_h3]:top-0 [&_h3]:z-10 [&_h3]:bg-background",children:/* @__PURE__ */e(Ts,{mode:"config"})})}),b&&/* @__PURE__ */n("button",{type:"button",onClick:()=>r(D=>!D),className:"flex w-full items-center justify-between px-4 py-2.5 text-left transition-colors hover:bg-muted/50",children:[/* @__PURE__ */n("span",{className:"inline-flex items-center gap-2",children:[/* @__PURE__ */e(ca,{className:"h-3.5 w-3.5 text-muted-foreground"}),/* @__PURE__ */e("span",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-foreground/70",children:S})]}),/* @__PURE__ */e(kt,{className:W("h-3 w-3 text-muted-foreground transition-transform",s&&"rotate-180"),strokeWidth:1.75})]}),w&&o&&/* @__PURE__ */e("div",{className:"max-h-[40vh] overflow-y-auto border-b border-t border-border px-4",children:/* @__PURE__ */e(bs,{})}),w&&/* @__PURE__ */n("button",{type:"button",onClick:()=>c(D=>!D),className:W("flex w-full items-center justify-between px-4 py-2.5 text-left transition-colors hover:bg-muted/50",b&&"border-t border-border"),children:[/* @__PURE__ */n("span",{className:"inline-flex items-center gap-2",children:[/* @__PURE__ */e(ls,{className:"h-3.5 w-3.5 text-muted-foreground"}),/* @__PURE__ */e("span",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-foreground/70",children:"Component settings"})]}),/* @__PURE__ */e(kt,{className:W("h-3 w-3 text-muted-foreground transition-transform",o&&"rotate-180"),strokeWidth:1.75})]})]});}function Ph({card:t,hasFields:a,onClearFields:s,onStartOver:r}){var d,l;if(!(t.type==="matrixTable"?[]:((d=Va(t))==null?void 0:d.joins)??[]).length)return a?/* @__PURE__ */e("button",{type:"button",onClick:s,className:"text-[11px] text-muted-foreground transition-colors hover:text-foreground",children:"Clear fields"}):null;const c=vr((l=Va(t))==null?void 0:l.baseEntity);return/* @__PURE__ */n("div",{className:"flex items-center",children:[/* @__PURE__ */e("button",{type:"button",onClick:s,disabled:!a,className:"rounded-l-control px-1 text-[11px] text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-40",children:"Clear fields"}),/* @__PURE__ */n(la,{modal:!1,children:[/* @__PURE__ */e(oa,{asChild:!0,children:/* @__PURE__ */e("button",{type:"button","aria-label":"More ways to clear",className:"rounded-r-control px-0.5 text-muted-foreground transition-colors hover:text-foreground",children:/* @__PURE__ */e(kt,{className:"h-3 w-3"})})}),/* @__PURE__ */n(ia,{align:"end",className:"w-[240px]",children:[/* @__PURE__ */n(He,{disabled:!a,onClick:s,className:"flex flex-col items-start gap-0",children:[/* @__PURE__ */e("span",{className:"text-[12.5px]",children:"Clear fields"}),/* @__PURE__ */e("span",{className:"text-[11px] text-muted-foreground",children:"Empty the shelves; joins stay"})]}),/* @__PURE__ */n(He,{onClick:r,className:"flex flex-col items-start gap-0",children:[/* @__PURE__ */e("span",{className:"text-[12.5px]",children:"Start over"}),/* @__PURE__ */n("span",{className:"text-[11px] text-muted-foreground",children:["Clear fields and joins; keep ",/* @__PURE__ */e("span",{className:"font-mono",children:c})]})]})]})]})]});}function Dh(){const t=T(l=>l.card),{autoJoinMetadata:a}=$e(t);if(!(a!=null&&a.autoResolved))return null;const{resolvedJoinPlan:s}=a,r=(s==null?void 0:s.joins)||[];if(r.length===0)return null;const o=l=>!l||l.length===0?"No conditions":l.map(i=>{var f,m,N,w;const v=`${(f=i.source)==null?void 0:f.entityName}.${(m=i.source)==null?void 0:m.name}`,u=`${(N=i.target)==null?void 0:N.entityName}.${(w=i.target)==null?void 0:w.name}`,p=i.operator||"=";return`${v} ${p} ${u}`;}).join(" AND "),c=l=>!l.joinKeyGroups||l.joinKeyGroups.length===0?"No conditions defined":l.joinKeyGroups.length===1?o(l.joinKeyGroups[0].keys):l.joinKeyGroups.map((i,v)=>({id:v,operator:i.operator,condition:o(i.keys)})),d=/* @__PURE__ */e(Ot,{children:/* @__PURE__ */n(mt,{children:[/* @__PURE__ */e(ht,{asChild:!0,children:/* @__PURE__ */e("button",{type:"button",className:"shrink-0 cursor-help rounded-control px-1 font-mono text-[10px] tabular-nums text-muted-foreground/70 transition-colors hover:bg-muted hover:text-foreground","aria-label":`${r.length} resolved ${r.length===1?"join":"joins"}`,children:r.length})}),/* @__PURE__ */e(pt,{side:"bottom",align:"start",className:"max-w-md border border-border bg-popover p-2 text-popover-foreground shadow-[0_4px_16px_rgba(0,0,0,0.08)]",children:/* @__PURE__ */e("div",{className:"space-y-2",children:r.map((l,i)=>{const v=c(l),u=Array.isArray(v);return/* @__PURE__ */n("div",{className:"rounded-md border border-border bg-background p-2 text-foreground",children:[/* @__PURE__ */n("div",{className:"mb-1 flex items-center justify-between gap-2",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2 text-xs",children:[/* @__PURE__ */e("span",{className:"font-medium text-foreground",children:l.source.name}),/* @__PURE__ */e(zc,{className:"size-3 text-muted-foreground"}),/* @__PURE__ */e("span",{className:"font-medium text-foreground",children:l.target.name})]}),/* @__PURE__ */e("span",{className:"shrink-0 rounded-[3px] border border-border px-1 font-mono text-[10px] uppercase tracking-[0.06em] text-muted-foreground",children:l.joinType})]}),/* @__PURE__ */e("div",{className:"mt-1 space-y-1",children:u?v.map(p=>/* @__PURE__ */n("div",{className:"rounded bg-muted/30 px-2 py-1",children:[/* @__PURE__ */e("code",{className:"block break-all text-xs text-muted-foreground",children:p.condition}),p.operator&&/* @__PURE__ */n("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",p.operator,")"]})]},p.id)):/* @__PURE__ */e("div",{className:"rounded bg-muted/30 px-2 py-1",children:/* @__PURE__ */e("code",{className:"block break-all text-xs text-muted-foreground",children:v})})})]},l.id||i);})})})]})});return/* @__PURE__ */n("div",{className:"flex h-7 w-full items-center gap-2 rounded-control border border-input bg-background px-2 text-left transition-colors hover:bg-muted",children:[/* @__PURE__ */e(Li,{className:"h-3 w-3 shrink-0 text-muted-foreground",strokeWidth:1.75}),/* @__PURE__ */e("span",{className:"min-w-0 flex-1 truncate text-[13px] text-foreground",children:"Resolved joins"}),d]});}function Lh({onRemoveField:t,onResetFields:a,selectedChart:s,onChartChange:r,isVisible:o=!0,onToggleVisibility:c,groupByFields:d,pivotByFields:l,metricsFields:i,sortByFields:v,detailFields:u}){const p=T(m=>m.editorContext),f=(p==null?void 0:p.type)==="documentSection";return o?/* @__PURE__ */n("div",{"data-content":"Chart Configuration Panel",className:"flex w-[325px] min-w-[325px] shrink-0 flex-col overflow-hidden border-r border-border bg-background transition-all duration-300 ease-in-out",children:[!f&&/* @__PURE__ */n("div",{className:"flex items-start",children:[/* @__PURE__ */e("div",{className:"min-w-0 flex-1",children:/* @__PURE__ */e(Tu,{selectedChart:s,onChartChange:r})}),c&&/* @__PURE__ */e("div",{className:"px-2 pt-4",children:/* @__PURE__ */e(_e,{tooltip:"Hide chart configuration","aria-label":"Hide chart configuration",onClick:c,className:"h-7 w-7 rounded-[5px] p-0 text-muted-foreground hover:text-foreground",children:/* @__PURE__ */e(qc,{className:"h-4 w-4",strokeWidth:1.75})})})]}),/* @__PURE__ */n(pn,{className:"min-h-0 w-full flex-1 basis-0 border-t border-border [&>[data-radix-scroll-area-viewport]]:overscroll-none [&>[data-radix-scroll-area-viewport]>div]:!block [&>[data-radix-scroll-area-viewport]>div]:w-full",children:[/* @__PURE__ */e("div",{className:"px-4 pt-4 empty:hidden",children:/* @__PURE__ */e(Dh,{})}),/* @__PURE__ */e(Rh,{onRemoveField:t,onResetFields:a,groupByFields:d,pivotByFields:l,metricsFields:i,sortByFields:v,detailFields:u})]}),/* @__PURE__ */e(Ah,{})]}):/* @__PURE__ */e("div",{"data-content":"Chart Configuration Panel (collapsed)",className:"flex w-9 shrink-0 flex-col items-center border-r border-border bg-background transition-all duration-300 ease-in-out",children:c&&/* @__PURE__ */e(_e,{tooltip:"Show chart configuration","aria-label":"Show chart configuration",onClick:c,className:"mt-3 h-7 w-7 rounded-[5px] p-0 text-muted-foreground hover:text-foreground",children:/* @__PURE__ */e(vt,{className:"h-4 w-4",strokeWidth:1.75})})});}function _h({cardId:t,filters:a,onFiltersChange:s,onClearFilters:r,availableFields:o,source:c,isOpen:d,onOpenChange:l}){return/* @__PURE__ */n(ta,{modal:!1,open:d,onOpenChange:l,children:[d&&/* @__PURE__ */e("div",{className:"pointer-events-none fixed inset-0 z-40 bg-zinc-950/40 backdrop-blur-sm"}),/* @__PURE__ */n(aa,{className:"flex max-h-[80vh] w-[min(880px,92vw)] max-w-none flex-col gap-0 overflow-hidden p-0 [&>button:last-child]:top-3",onInteractOutside:u=>{u.preventDefault();},children:[/* @__PURE__ */n("div",{className:"flex h-10 shrink-0 items-center gap-2 border-b border-border pl-3 pr-10",children:[/* @__PURE__ */e(ua,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */e(na,{className:"truncate text-[13px] font-medium",children:"Card filters"}),/* @__PURE__ */e(Vt,{className:"sr-only",children:"Add filters to the card to limit the data that is displayed."})]}),/* @__PURE__ */e(id,{filters:a,availableFields:o,source:c,onSave:u=>{s(t,u),l(!1);},onCancel:()=>l(!1),onClearAll:()=>{r(t),l(!1);}})]})]});}function Vh({activeView:t,onViewChange:a,splitViewEnabled:s,hasQueryError:r=!1}){const o=T(v=>v.card),{config:c}=yn(fn).tokenProps,d=(c==null?void 0:c.showInfoTab)!==!1&&yr(o.type),l=!s&&en(o.type),i=[{id:"chart",label:"Visual"}];return l&&i.push({id:"table",label:"Results"}),d&&i.push({id:"info",label:r?"Error":"Info",isError:r}),/* @__PURE__ */e(ft,{value:t,onValueChange:v=>a(v),children:/* @__PURE__ */e(gt,{variant:"underline",className:"gap-5 border-b-0",children:i.map(v=>/* @__PURE__ */e(Ke,{value:v.id,className:W("px-0 text-[13px]",v.isError&&"text-destructive hover:text-destructive focus-visible:text-destructive data-[state=active]:border-destructive data-[state=active]:text-destructive"),children:v.label},v.id))})});}const Bh=[{value:"10",label:"10"},{value:"20",label:"20"},{value:"50",label:"50"},{value:"100",label:"100"},{value:"200",label:"200"},{value:"500",label:"500"},{value:"1000",label:"1,000"}];function Kh(){var s,r;const t=T(o=>o.card),{updateRowLimit:a}=he();return/* @__PURE__ */n(ae,{value:((r=(s=t.config)==null?void 0:s.rowLimit)==null?void 0:r.toString())||"100",onValueChange:o=>a(t.id,parseInt(o)),children:[/* @__PURE__ */n(ne,{size:"xs","aria-label":"Row limit",className:"h-6 w-auto gap-1 rounded-control border-transparent bg-transparent px-1.5 py-0 text-[11px] text-muted-foreground shadow-none transition-colors hover:bg-accent hover:text-accent-foreground [&>svg]:h-3 [&>svg]:w-3",children:[/* @__PURE__ */e("span",{children:"Limit"}),/* @__PURE__ */e("span",{className:"font-medium tabular-nums text-foreground",children:/* @__PURE__ */e(re,{})})]}),/* @__PURE__ */e(se,{align:"end",children:Bh.map(o=>/* @__PURE__ */e(H,{value:o.value,className:"text-[12px] tabular-nums",children:o.label},o.value))})]});}function zh({card:t,queryData:a,isLoading:s,isFetching:r,pagination:o,onPaginationChange:c,onSortChange:d,sortState:l,splitViewEnabled:i}){var u;const v=X(()=>(a==null?void 0:a.records)||[],[a==null?void 0:a.records]);return!i||!en(t.type)?/* @__PURE__ */e(Ya,{}):/* @__PURE__ */n(Qa,{direction:"vertical",className:"h-full min-h-0 w-full",children:[/* @__PURE__ */e(yt,{defaultSize:60,minSize:30,role:"chart-section",className:"flex flex-col pb-3",children:/* @__PURE__ */e(Ya,{})}),/* @__PURE__ */e(cs,{withHandle:!0}),/* @__PURE__ */e(yt,{defaultSize:40,minSize:20,role:"results-section",className:"flex flex-col",children:/* @__PURE__ */n("div",{className:"relative flex h-full min-h-0 max-w-full flex-1 grow basis-0 py-4 pl-2 pr-4",children:[(s||r)&&(a==null?void 0:a.records)&&/* @__PURE__ */e("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-background/50",children:/* @__PURE__ */e(et,{size:"md",color:"muted","aria-label":"Loading data"})}),(a==null?void 0:a.records)&&/* @__PURE__ */e(nn,{card:t,data:v,resultColumns:a==null?void 0:a.columns,columnKeyMap:a==null?void 0:a.columnKeyMap,totalsByColumnId:a==null?void 0:a.tableTotalsByColumnId,columnTotals:a==null?void 0:a.tableColumnTotals,comparisonMetadata:(u=a==null?void 0:a.metadata)==null?void 0:u.comparisonMetadata,paginationMetadata:o,onPaginationChange:c,isLoading:s||r,onSortChange:d,sortState:l})]})})]});}function qh(t,a){const[s,r]=Y(()=>{const o=localStorage.getItem(t);return o?JSON.parse(o):a;});return ve(()=>{localStorage.setItem(t,JSON.stringify(s));},[s,t]),[s,r];}const jh="semaphor-split-view-enabled";function $h(){return qh(jh,!0);}function Uh({error:t,showInfoTab:a}){return/* @__PURE__ */e(_i,{className:"mx-4 mt-3",hint:a?"The Error tab has the query and its payload.":"Contact your administrator for help resolving this issue.",detail:a?t:void 0});}function Hh({card:t,effectiveCardType:a=t.type,queryOutput:s}){return Za(a)?/* @__PURE__ */n(jc,{modal:!1,children:[/* @__PURE__ */e($c,{asChild:!0,children:/* @__PURE__ */e(_e,{tooltip:"Table settings",className:"h-7 w-7 rounded-[5px] p-0",buttonProps:{type:"button","aria-label":"Table settings"},children:/* @__PURE__ */e(ca,{className:"h-3.5 w-3.5",strokeWidth:1.75})})}),/* @__PURE__ */n(Uc,{side:"right",hideOverlay:!0,className:"flex w-[420px] flex-col gap-0 p-0 sm:max-w-[420px]",children:[/* @__PURE__ */e(Hc,{className:"sr-only",children:"Table settings"}),/* @__PURE__ */e(Qc,{className:"sr-only",children:"Configure table presentation and conditional formatting."}),/* @__PURE__ */n("div",{className:"border-b px-4 py-3",children:[/* @__PURE__ */e("div",{className:"text-[13px] font-semibold text-foreground",children:"Table settings"}),/* @__PURE__ */e("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:"Settings apply to this table and document exports that reuse it."})]}),/* @__PURE__ */e("div",{className:"min-h-0 flex-1 overflow-auto",children:/* @__PURE__ */e(Ss,{cardType:a,queryOutput:s,focusSection:"style"})})]})]}):null;}function Qh({className:t,visible:a}){const s=xe(l=>l.selectedFrameId),r=Vi(l=>l.selectedVisual),o=T(l=>l.frame),d=!!!(o!=null&&o.visualId||r!=null&&r.id)&&!!s;return!a||d?null:/* @__PURE__ */e("div",{className:W("flex",t),children:/* @__PURE__ */e(as,{showLabel:!0,className:"h-6 w-fit px-2 py-0.5 text-[11px]"})});}function Gh({activeView:t,onViewChange:a,onFiltersClick:s,activeCard:r}){var Ue;const o=T(de=>de.card),c=T(de=>de.inlineFilterValuesMap[(r==null?void 0:r.id)||""]),d=T(de=>de.actions.removeCardInlineFilterValue),l=xe(de=>de.selectedSheetId),{updateCardConfig:i,setCard:v,updateCardInFrame:u}=he(),[p,f]=Y(!1),[m,N]=Y(!1),[w,S]=Y(null),{config:b}=yn(fn).tokenProps,y=(b==null?void 0:b.showInfoTab)!==!1,R=(b==null?void 0:b.showQueryDebugTools)!==!1,[x,D]=$h(),B=en(o.type),$=y&&yr(o.type),j=y&&!$,k=t==="table"&&(x||!B)||t==="info"&&!$?"chart":t;T(de=>{var Ce;return!!((Ce=de.card.customCardPreferences)!=null&&Ce.url);});const O=Ve(),{data:A,errorMessage:F,isLoading:K,isFetching:E,errorSql:h,pagination:I,refetch:g,comparisonMetadata:C,queryRequestPayload:M,resolvedPrimaryDateField:z}=$e(r),_=ra(r,A),P=()=>{var Fe;const de=xe.getState(),Ce=du(kn.QUERY_GENERATION,{cardConfig:o.config,dataSource:r.dataSource,dashboardFilters:kd({dashboard:de.dashboard,runtimeValues:{dashboardInputValues:de.dashboardInputValues},adHocFilterValues:de.adHocFilterValues,sheetId:l,sheetKind:"dashboard",calendar:((Fe=de.reportContext)==null?void 0:Fe.calendar)??null}),errorMessage:F,errorSql:h,generatedSql:A==null?void 0:A.sql});S(Ce),N(!0);},V=()=>{const de=T.getState().actions;de.setIsDevMode(!0),de.setCardSql(h||""),setTimeout(()=>{de.setRunSql(!0);},100);},G=R?{queryRequest:M,queryResponse:A}:void 0,ee=X(()=>(A==null?void 0:A.records)||[],[A==null?void 0:A.records]),ie=X(()=>!E&&ee.length>0?Object.keys(ee[0]):[],[E,ee]),Q=X(()=>({keys:ie,columnKeyMap:A==null?void 0:A.columnKeyMap,resultColumns:A==null?void 0:A.columns}),[ie,A==null?void 0:A.columnKeyMap,A==null?void 0:A.columns]),q=Pr(r),te=T(de=>de.frame),[ce,me]=Y(),le=()=>{const de=!x;de&&k==="table"&&a("chart"),D(de);},pe=(de,Ce)=>{const Fe={...r,paginationConfig:{page:de+1,pageSize:Ce}};v(Fe),u(Fe);},fe=de=>{if(!o.config)return;const Ce=Er(de,o.config.metricColumns,o.config.groupByColumns,o.config.detailColumns);i(o.id,{...o.config,sortByColumns:Ce});},Ee=X(()=>{var de;return Bi((de=o.config)==null?void 0:de.sortByColumns);},[(Ue=o.config)==null?void 0:Ue.sortByColumns]),Ae=Ki(Ut(r)||null);return/* @__PURE__ */e("div",{className:"relative flex w-0 grow flex-col",children:/* @__PURE__ */n("div",{className:"group/visualization relative flex h-full max-w-full grow flex-col",children:[/* @__PURE__ */n("div",{className:"flex h-11 items-center gap-3 border-b border-border px-4",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-3",children:[/* @__PURE__ */e("div",{className:"flex h-11 items-end gap-5 self-stretch",children:/* @__PURE__ */e(Vh,{activeView:k,onViewChange:a,splitViewEnabled:x,hasQueryError:!!F})}),O==="kpi"&&/* @__PURE__ */e(Qh,{visible:!0,className:"self-center"}),C&&o.type!=="table"&&/* @__PURE__ */e(Gc,{metadata:C})]}),/* @__PURE__ */n("div",{className:"flex grow items-center justify-end gap-1",children:[!Wc(O)&&/* @__PURE__ */e(Kh,{}),/* @__PURE__ */e(zi,{cardId:r.id,cardFilters:Ut(r),cardFilterCount:Ae,onFiltersClick:s,inlineFilters:Ul(r),inlineFilterValues:$l(r,c),sheetId:l||"",removeInlineFilterValue:de=>d(r.id,de),resolvedPrimaryDateField:z}),k==="chart"&&/* @__PURE__ */e(Hh,{card:r,effectiveCardType:O,queryOutput:Q}),k==="chart"&&/* @__PURE__ */e(gs,{showInlineFilters:!1,showControls:!1,showDisplayOptions:!1}),/* @__PURE__ */n(la,{modal:!1,children:[/* @__PURE__ */e(oa,{asChild:!0,children:/* @__PURE__ */e(_e,{tooltip:"More Options",className:"h-7 w-7 rounded-[5px] p-0","aria-label":"More options",children:/* @__PURE__ */e(Dr,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(ia,{align:"end",className:"w-60",children:[/* @__PURE__ */n(He,{disabled:q?q.isFetching:K||E,onSelect:()=>{var de;if(q){(de=q.refresh)==null||de.call(q);return;}g();},children:[/* @__PURE__ */e(Ha,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Refresh"]}),k==="chart"&&/* @__PURE__ */n(be,{children:[/* @__PURE__ */n(He,{onSelect:s,children:[/* @__PURE__ */e(ua,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Card filters",Ae>0&&/* @__PURE__ */e("span",{className:"ml-auto text-[11px] tabular-nums text-muted-foreground",children:Ae})]}),/* @__PURE__ */e(En,{triggerVariant:"menu",className:"w-full"}),/* @__PURE__ */e(Fn,{triggerVariant:"menu",className:"w-full"}),/* @__PURE__ */e(In,{triggerVariant:"menu",className:"w-full"}),B&&/* @__PURE__ */n(He,{onClick:le,children:[x?/* @__PURE__ */e(Bd,{className:"h-3.5 w-3.5 text-muted-foreground"}):/* @__PURE__ */e(qd,{className:"h-3.5 w-3.5 text-muted-foreground"}),x?"Hide results table":"Show results table"]}),q&&/* @__PURE__ */n(He,{disabled:q.isFetching||!q.hasDelivery,title:q.hasDelivery?void 0:"Available once the preview has loaded.",onClick:()=>me(q.readDelivery()),children:[/* @__PURE__ */e($a,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Download"]})]})]})]})]})]}),/* @__PURE__ */n("div",{className:"flex min-h-0 grow flex-col",children:[k==="chart"?F?j?/* @__PURE__ */e("div",{className:"flex min-h-0 flex-1 flex-col px-1 pb-2",children:/* @__PURE__ */e(Kn,{error:F,errorSql:h,onSendFeedback:P,onOpenInEditor:Ja(o.type)?V:void 0})}):/* @__PURE__ */e(Uh,{error:F,showInfoTab:$}):/* @__PURE__ */e("div",{className:"flex grow flex-col",children:/* @__PURE__ */e(zh,{card:_,queryData:A,isLoading:K,isFetching:E,pagination:I,onPaginationChange:pe,onSortChange:fe,sortState:Ee,splitViewEnabled:x})}):null,k==="table"&&(A==null?void 0:A.records)&&/* @__PURE__ */n("div",{className:"relative flex h-full min-h-0 max-w-full flex-1 grow basis-0 px-4 py-4",children:[(K||E)&&(A==null?void 0:A.records)&&/* @__PURE__ */e("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-background/50",children:/* @__PURE__ */e(et,{size:"md",color:"muted","aria-label":"Loading data"})}),/* @__PURE__ */e(nn,{card:_,data:ee,resultColumns:A.columns,columnKeyMap:A.columnKeyMap,totalsByColumnId:A==null?void 0:A.tableTotalsByColumnId,columnTotals:A==null?void 0:A.tableColumnTotals,comparisonMetadata:C,paginationMetadata:I,onPaginationChange:pe,isLoading:K||E,onSortChange:fe,sortState:Ee})]}),k==="info"&&$&&/* @__PURE__ */e("div",{className:"flex min-h-0 flex-1 flex-col pb-2",children:/* @__PURE__ */e("div",{className:"flex min-h-0 flex-1 flex-col rounded-md bg-background px-1",children:F?/* @__PURE__ */e(Kn,{error:F,errorSql:h,defaultDetailsOpen:!0,debugPayloads:G,onSendFeedback:P,onOpenInEditor:V}):((A==null?void 0:A.sql)&&/* @__PURE__ */e(xs,{sql:A.sql,debugPayloads:G}))})})]}),ce&&r&&te&&/* @__PURE__ */e(Yr,{isOpen:!0,onClose:()=>me(void 0),card:r,frame:te,matrix:ce}),w&&/* @__PURE__ */e(Tn,{open:m,onOpenChange:N,feedbackData:w})]})});}const Wh=()=>{const t=console.error;console.error=(...r)=>{r.length>0&&typeof r[0]=="string"&&r[0].includes("ResizeObserver loop completed with undelivered notifications")||t.apply(console,r);};const a=r=>{if(r.message&&(r.message.includes("ResizeObserver loop completed with undelivered notifications")||r.message.includes("ResizeObserver loop limit exceeded")))return r.preventDefault(),r.stopPropagation(),!1;},s=r=>{var o;if((o=r.reason)!=null&&o.message&&(r.reason.message.includes("ResizeObserver loop completed with undelivered notifications")||r.reason.message.includes("ResizeObserver loop limit exceeded")))return r.preventDefault(),!1;};return window.addEventListener("error",a,!0),window.addEventListener("unhandledrejection",s,!0),()=>{console.error=t,window.removeEventListener("error",a,!0),window.removeEventListener("unhandledrejection",s,!0);};};function Yh(){const[t,a]=Y("chart"),[s,r]=Y(!1),[o,c]=Y(!0),[d,l]=Y(!0),i=xe(I=>I.isVisualEditing),v=Sn(),u=T(I=>I.card.type);ve(()=>Wh(),[]);const p=I=>{v(I);},f=T(I=>I.frame),m=T(I=>I.card);T(I=>I.activeTabCardId),T(I=>I.actions.getAvailableFields);const{addCard:N,removeCard:w,updateCard:S,setActiveCard:b,updateFilters:y,clearFilters:R}=he(),{scopedFields:x=[]}=Ar(),D=m,{getFieldsForContainer:B,placeField:$,previewFieldPlacement:j,removeField:k,resetFields:O}=on(D,x),A=(I,g)=>{g&&y(I,g);},F=I=>{R(I);},{filterableFields:K}=qi(m),E=I=>{if(!I)return 0;let g=I.conditions.length;return I.groups.forEach(C=>{g+=E(C);}),g;},h=E(Ut(D)||null);return(/* @__PURE__ */n(ji,{activeCardId:f.activeCardId,placeField:$,previewFieldPlacement:j,children:[/* @__PURE__ */n("div",{className:"flex h-full grow",children:[/* @__PURE__ */e(is,{isVisible:o,onToggleVisibility:()=>c(!o)}),/* @__PURE__ */n("div",{className:"flex flex-1 transition-all duration-300 ease-in-out",children:[/* @__PURE__ */e(Lh,{onRemoveField:k,onResetFields:O,selectedChart:u,onChartChange:p,groupByFields:B("groupBy"),pivotByFields:B("pivotBy"),metricsFields:B("metrics"),sortByFields:B("sortBy"),detailFields:B("detailColumns"),isVisible:d,onToggleVisibility:()=>l(!d)}),/* @__PURE__ */e(Gh,{selectedChart:u,activeView:t,onViewChange:a,onFiltersClick:()=>r(!0),filterCount:h,activeCard:D,getFieldsForContainer:B,cards:f.cards,activeCardId:f.activeCardId,addCard:N,setActiveCard:b})]}),!o&&i&&/* @__PURE__ */e("div",{className:"fixed left-6 top-[105px] z-50",children:/* @__PURE__ */e(ue,{size:"sm",variant:"outline",className:"h-10 w-10 rounded-full border-border bg-background p-0 shadow-lg hover:bg-muted",onClick:()=>c(!0),title:"Show Data Source Panel",children:/* @__PURE__ */e(Yc,{className:"h-4 w-4"})})})]}),D&&/* @__PURE__ */e(_h,{cardId:D.id,filters:Ut(D)||null,onFiltersChange:A,onClearFilters:F,availableFields:K,isOpen:s,onOpenChange:r})]}));}function Xh({authToken:t,onSave:a,onClose:s}){const r=T(u=>u.isDevMode),o=gn(),{setAuthToken:c}=Xc(),{setOnSave:d,setOnClose:l}=he();ve(()=>{a&&d(a),s&&l(s);},[a,d,s,l]),ve(()=>{t&&t.accessToken&&c(t);},[t,c]);function i(){return/* @__PURE__ */n(be,{children:[/* @__PURE__ */e(is,{isVisible:!0,onToggleVisibility:()=>{}}),/* @__PURE__ */e("div",{className:"relative flex grow",children:/* @__PURE__ */e("div",{"data-content":"editor-main",className:"min-w-[510px] flex-1 basis-0 overflow-hidden",children:/* @__PURE__ */e(bh,{})})})]});}function v(){return/* @__PURE__ */e("div",{className:"relative flex h-full grow",children:/* @__PURE__ */e("div",{"data-content":"explorer",className:"min-w-[510px] flex-1 basis-0 overflow-hidden",children:/* @__PURE__ */e(Yh,{})})});}return(/* @__PURE__ */e(Jc,{children:/* @__PURE__ */e(sa,{FallbackComponent:$i,children:r?/* @__PURE__ */e("section",{className:"isolate flex h-full grow","data-content":"editor-panel",style:o.dashboardContainerStyle,children:i()}):/* @__PURE__ */e("section",{className:"isolate flex h-full grow","data-content":"editor-panel",style:o.dashboardContainerStyle,children:v()})})}));}function Sp(){xe(m=>m.selectedCardId);const t=xe(m=>m.selectedSheetId),a=xe(m=>m.dashboard),{setIsVisualEditing:s,setSelectedSheetId:r}=xe(m=>m.actions),o=T(m=>m.editorContext),{clearEditorContext:c}=T(m=>m.actions),d=Ui(),l=gn(),i=xe(m=>m.isVisualEditing),v=xe(m=>m.actions.updateFrame),u=Hi();async function p(m){var y,R,x;if((o==null?void 0:o.type)==="documentSection"){await d.commit(m);return;}const N=t?(y=a==null?void 0:a.sheets)==null?void 0:y.some(D=>{var B;return D.id===t&&((B=D.frames)==null?void 0:B.some($=>$.id===m.id));}):!1,w=(x=(R=a==null?void 0:a.sheets)==null?void 0:R.find(D=>{var B;return(B=D.frames)==null?void 0:B.some($=>$.id===m.id);}))==null?void 0:x.id,S=N?t:w||null;if(!S)return;const b=Hl(a,m.id);try{const D=await u(m,{previousFrame:b});v(S,m,{semanticExecutionPayload:D,origin:"editor"}),t!==S&&r(S),s(!1);}catch(D){console.error("Failed to resolve semantic metadata on save:",D),at.error(D instanceof Error?D.message:"Failed to resolve semantic metadata for this visual");}}function f(){if((o==null?void 0:o.type)==="documentSection"){d.discard();return;}c(),s(!1);}return/* @__PURE__ */e("div",{role:"editor-container",className:W("flex-1 grow basis-0 overflow-auto",{"max-h-0 overflow-hidden":!i}),style:l.dashboardContainerStyle,children:/* @__PURE__ */e(Xh,{onSave:p,onClose:f})});}export{Sp as default};
|