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
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import{jsxs as n,jsx as e,Fragment as xe}from"react/jsx-runtime";import{F as Qs,P as Gs,a as Ws,b as yr,c as vr,u as Nr,d as Ke,S as Rn,e as Ln,r as Cr,E as Ys,T as Xs,A as Js,f as Zs,g as el,C as tl,G as al,W as nl,h as rl,i as sl,j as Zt}from"./slider-C4jUvJtd.js";import{Q as ll,n as Q,la as Pn,f3 as wr,eL as il,dS as rn,hM as ol,jA as Qt,dA as cl,kq as sn,jy as dl,I as ul,lb as ml,lc as hl,bq as pl,c$ as fl,b3 as gl,v as $a,k9 as xl,b_ as bl,ld as yl,le as Sr,aL as vl,fy as Nl,lf as Cl,kr as wl,fV as Sl,A as Ca,lg as Tl,lh as kl,li as El,lj as Il,jv as Fl,al as Ml,lk as Ol,ll as ln,lm as Al,r as Rl,T as Ll,ht as Tr,u as Pl,c5 as Dl,id as _l,hH as kr,dv as Vl,iv as Bl,ln as zl,ig as Kl,kW as ql,lo as $l,jK as jl,lp as Hl,lq as Ul,lr as Dn,ls as Ql,lt as Gl,ba as Xe,lu as Wl,lv as Yl,lw as Xl,lx as Jl,ly as Zl,lz as ei,lA as _n,lB as Vn,e as ti,ch as ai,e8 as ni,e6 as ri,lC as si,lD as li,lE as ii,hN as oi,bi as ci,bf as ja,bg as Er,lF as Ir,lG as on,bN as ea,l4 as di,a0 as ui,kp as mi}from"./resolve-dashboard-input-context-B5yUS9ZM.js";import{l as hi}from"./validators-U8IL8djK.js";import{D as pi,t as Fr,u as Mr}from"./matrix-operation-contract-DceN49RX.js";import"./analytics-base-schemas-DMFrDqn_.js";import{DEFAULT_RESOLVED_VALUE_FORMAT_PREFERENCES as Bn}from"../value-format-preferences/index.js";import{ct as fi,cu as gi,bZ as Or,cr as Ar,cv as xi,cw as bi,a$ as yi,I as _e,bF as vi,bG as Ni,bH as Ci,bI as wi,bJ as Si,bK as Ti,bL as ki,bM as Ei,by as ta,cx as Rr,cy as Ii,be as cn,b3 as Fi,c8 as Lr,aw as Ot,ax as At,ay as Rt,cz as Mi,cA as Oi,cB as tt,cC as Ai,cD as Ri,cE as wa,cF as Li,cG as Pi,cH as Di,cI as Pr,N as Dr,cJ as dn,cK as _i,M as Vi,cL as un,cM as Bi,cN as zi,cO as Ki,cP as aa,cQ as qi,bQ as $i,c as mn,cR as _r,cS as zn,cT as Vr,cU as ji,cV as Hi,cW as Ui,cX as Qi,cY as Gi,cZ as Wi,c_ as na,c$ as Yi,d0 as Xi,d1 as Br,d2 as zr,d3 as Ji,d4 as Zi,c4 as eo,d5 as to,d6 as Kr,d7 as ao,bP as no,bO as hn,d8 as pn,aB as qr,aD as ro,aE as Kn,aF as so,aG as lo,aH as io,ci as oo,aJ as co,aK as uo,aL as mo,aM as ho,aN as po,aO as fo,d9 as go,da as xo,b7 as bo,b8 as yo,b5 as vo,db as No,dc as Co,dd as wo,de as So,ba as To,bb as ko,df as qn,dg as $n,dh as Eo,di as Io,dj as Fo,dk as $r,bB as jr,dl as la,dm as we,dn as Se,dp as Te,bU as Mo,bV as Oo,H as Ao,aT as jn,dq as Ro,dr as ia,ds as Hr,dt as Ur,du as Qr,dv as fn,dw as Ha,dx as Lo,dy as Po,dz as Do,dA as _o,dB as Ua,dC as Vo,dD as Ze,dE as Bo,cj as oa,dF as zo,dG as Gr,dH as Ko,dI as qo,dJ as Wr,dK as $o,dL as jo,dM as Hn,dN as Ho,dO as Uo,dP as Qo,dQ as Go,dR as Wo,dS as Yo,dT as Xo,dU as Jo,dV as Zo,dW as ec,ck as tc,dX as ac,dY as nc,dZ as rc,d_ as sc,d$ as lc,u as ic,e0 as oc,aI as cc,e1 as dc,e2 as Un,e3 as uc,e4 as mc,F as hc,e5 as pc,aY as fc}from"./semaphor-ready-indicator-Cq3C2SNo.js";import{c as Me,F as E,b8 as He,cp as Yr,cq as gc,cr as xc,aK as Gt,a2 as ct,P as lt,c9 as bc,B as le,X as ca,e as it,an as Lt,ao as mt,ap as ht,ar as pt,ag as da,C as Ft,aZ as Pt,a_ as Dt,b2 as ft,a$ as Wt,b0 as _t,b3 as gt,b4 as ze,b1 as dt,b5 as Qe,b as xt,g as ua,bL as Yt,aY as nt,bX as yc,aX as Ht,ba as vc,bF as ut,cs as Nc,G as he,b9 as gn,u as be,b6 as bt,b7 as wt,ct as Cc,av as P,cu as Qa,d as Mt,ac as yt,cv as Xr,cw as xn,aw as wc,b_ as bn,$ as yn,cx as ma,cy as Jr,bQ as vn,bP as Zr,E as ha,cz as Sc,cA as Tc,cB as kc,bw as Ec,ak as es,bC as pa,bD as fa,cC as Ga,cd as ra,bE as ga,cD as Ic,cE as Fc,ax as Nn,bT as Qn,aJ as ts,cF as Mc,cG as xa,aq as as,af as ns,a4 as te,a5 as ae,a6 as ne,a7 as re,a8 as U,aa as ba,cH as Oc,cI as Gn,cJ as Ac,cK as rs,cL as ss,bc as Rc,bd as Lc,be as Pc,bf as Dc,cM as Wn,cN as _c,cO as Tt,cP as kt,cQ as Et,al as ya,bz as Ue,bH as Yn,bI as Xn,bJ as Wa,ah as Vc,cR as ls,cS as Bc,cT as zc,cU as Kc,cV as qc,cW as $c,a3 as Ya,ab as Ne,cX as jc,cY as Hc,au as jt,cZ as Uc,c_ as Qc,c$ as Gc,d0 as Wc,V as Yc,d1 as Xc,d2 as Jc,d3 as Jn,d4 as Zc,d5 as Sa,d6 as Zn,d7 as ed,d8 as td,aV as Cn,aW as Ut,d9 as Ta,da as is,db as ad,aj as os,bV as nd,dc as rd,dd as sd,bR as ld,bS as id,de as od,bB as cd,bU as dd,ck as ud,df as md,cl as hd,cn as pd,co as fd,dg as gd,dh as xd,A as bd,bY as yd}from"./appearance-provider-BBYTKSjL.js";import Xa,{useState as G,useRef as Ie,useEffect as ye,useCallback as rt,useMemo as J,useContext as wn,Suspense as vd}from"react";import{aY as Nd,aJ as Cd,aQ as wd,k as Sd}from"./pivot-result-contract-expectations-D_ane7I2.js";import"zod";import{aK as cs,aL as ds,A as Td}from"./bookmark-state-BmbBu1th.js";import"./schema-O1Y3WTGF.js";import{i as us}from"./index-DViPGDFj.js";import{f as vt,r as Nt,g as Xt,a as at,c as It,i as kd,d as Ed,e as Id,b as ms,n as Fd,h as Ja,j as Md,k as Od,l as Ad}from"./custom-visual-inputs-CUtxCe4T.js";import"./context-Cwj8Axgd.js";import{F as Rd,V as hs,u as Ld,C as Pd,a as Dd}from"./card-filter-builder-CM3SZ4kO.js";import{N as Sn,I as _d,b as Vd,Q as Bd,R as zd,U as Kd}from"./filter-reach-preview-DSH_k8AJ.js";import{H as qd,k as $d,I as jd,J as Hd,w as Ud}from"./stored-dashboard-1x0q2cNx.js";import"react-dom";import{c as Qd,b as Gd,m as Wd,K as Yd,d as Xd}from"./kpi-trend-rule-DDbguInc.js";import{e as Jd,m as Zd,d as ps,n as eu,f as fs,o as tu,b as au}from"./currency-presentation-binding-s4PlA3Wu.js";import{d as nu,e as ru,s as su,h as Tn,i as kn}from"./metric-formatting-DILSVxLq.js";import{r as lu}from"./export-file-format-B-wQNHIn.js";import{u as iu}from"./appearance-runtime-provider-De2VZS4F.js";import{r as ou,b as cu}from"./sandbox-host-WJXxpvz7.js";import{M as du,K as er,L as ka}from"./set-wWdhgHSh.js";import{b as tr}from"./raw-temporal-value-B4Md6Xfb.js";import{P as uu}from"./palette-CZJ4ZCY9.js";import{u as mu}from"./table-cell-text-DFHUGeG6.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 gs=Me("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 xs=Me("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 hu=Me("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 pu=Me("ClipboardPaste",[["path",{d:"M15 2H9a1 1 0 0 0-1 1v2c0 .6.4 1 1 1h6c.6 0 1-.4 1-1V3c0-.6-.4-1-1-1Z",key:"1pp7kr"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2M16 4h2a2 2 0 0 1 2 2v2M11 14h10",key:"2ik1ml"}],["path",{d:"m17 10 4 4-4 4",key:"vp2hj1"}]]);/**
|
|
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 fu=Me("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"}]]);/**
|
|
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 gu=Me("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"}]]);/**
|
|
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 xu=Me("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"}]]);/**
|
|
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 bu=Me("LayoutTemplate",[["rect",{width:"18",height:"7",x:"3",y:"3",rx:"1",key:"f1a2em"}],["rect",{width:"9",height:"7",x:"3",y:"14",rx:"1",key:"jqznyg"}],["rect",{width:"5",height:"7",x:"16",y:"14",rx:"1",key:"q5h2i8"}]]);/**
|
|
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 bs=Me("MessageSquareText",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}],["path",{d:"M13 8H7",key:"14i4kc"}],["path",{d:"M17 12H7",key:"16if0g"}]]);/**
|
|
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 Ea=Me("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"}]]);/**
|
|
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 Ia=Me("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"}]]);/**
|
|
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 yu=Me("PanelLeftClose",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m16 15-3-3 3-3",key:"14y99z"}]]);/**
|
|
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 vu=Me("PanelLeftOpen",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m14 9 3 3-3 3",key:"8010ee"}]]);/**
|
|
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 Za=Me("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"}]]);/**
|
|
72
|
+
* @license lucide-react v0.453.0 - ISC
|
|
73
|
+
*
|
|
74
|
+
* This source code is licensed under the ISC license.
|
|
75
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
76
|
+
*/const Nu=Me("RotateCw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]]);/**
|
|
77
|
+
* @license lucide-react v0.453.0 - ISC
|
|
78
|
+
*
|
|
79
|
+
* This source code is licensed under the ISC license.
|
|
80
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
81
|
+
*/const Cu=Me("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"}]]);/**
|
|
82
|
+
* @license lucide-react v0.453.0 - ISC
|
|
83
|
+
*
|
|
84
|
+
* This source code is licensed under the ISC license.
|
|
85
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
86
|
+
*/const wu=Me("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"}]]);/**
|
|
87
|
+
* @license lucide-react v0.453.0 - ISC
|
|
88
|
+
*
|
|
89
|
+
* This source code is licensed under the ISC license.
|
|
90
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
91
|
+
*/const Su=Me("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"}]]);/**
|
|
92
|
+
* @license lucide-react v0.453.0 - ISC
|
|
93
|
+
*
|
|
94
|
+
* This source code is licensed under the ISC license.
|
|
95
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
96
|
+
*/const Tu=Me("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"}]]);/**
|
|
97
|
+
* @license lucide-react v0.453.0 - ISC
|
|
98
|
+
*
|
|
99
|
+
* This source code is licensed under the ISC license.
|
|
100
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
101
|
+
*/const ys=Me("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 va(){var d,i;const t=E(c=>c.card),{data:a,comparisonMetadata:s}=He(t),r=(a==null?void 0:a.records)||[],{keys:l}=Yr(r,s),o=l.slice(1).filter(c=>!ll.includes(c));if(mu(t.type)){const c=t.config,x=(d=c==null?void 0:c.pivotByColumns)!=null&&d.length&&(i=c==null?void 0:c.groupByColumns)!=null&&i.length?gc(r,c.metricColumns||[]):r,u=xc({card:t,cardType:t.type,records:x,columnKeyMap:a==null?void 0:a.columnKeyMap,comparisonMetadata:s});return{transformedMetricKeys:u.valueKeys,dimensionKeys:u.axisKeys,keys:l,defaultMetricKeys:o};}return{transformedMetricKeys:o,dimensionKeys:l.slice(0,1),keys:l,defaultMetricKeys:o};}const vs="w-[308px] min-w-[308px]";function Ns({isVisible:t=!0}){return fi(),/* @__PURE__ */n("div",{"data-content":"Data Source Panel",className:Q("flex shrink-0 flex-col overflow-hidden border-r border-border bg-background",vs,!t&&"hidden"),children:[/* @__PURE__ */e("div",{className:"px-4 pt-4",children:/* @__PURE__ */e(gi,{})}),/* @__PURE__ */e("div",{className:"min-h-0 flex-1",children:/* @__PURE__ */e(Qs,{})})]});}const en=({className:t,...a})=>/* @__PURE__ */e(Ws,{className:Q("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",t),...a}),St=Gs,Cs=({withHandle:t,className:a,...s})=>/* @__PURE__ */e(yr,{className:Q("group 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(ws,{className:"top-1/2 -translate-y-1/2 group-data-[panel-group-direction=horizontal]:h-8 group-data-[panel-group-direction=horizontal]:w-[3px]"})}),ws=({className:t})=>/* @__PURE__ */e("span",{"aria-hidden":!0,className:Q("pointer-events-none absolute left-1/2 z-10 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",t)}),ku=3,tn="Self-heal",Fa={grounding:"Analyzing context",drafting:"Drafting SQL",validating:"Validating SQL",repairing:tn},Vt="Unable to generate a SQL draft right now. Try again.",Eu="Choose a data source for this card before describing a query.",Iu="Validation service unavailable. You can still replace and run.";function Bt(t,a){typeof window>"u"||window.dispatchEvent(new CustomEvent("semaphor:inline-query-writer",{detail:{event:t,...a,timestamp:Date.now()}}));}const zt={runId:0,status:"idle",prompt:"",mode:"draft",baselineSql:"",timelineSteps:[],activeStep:"",attempt:0,sql:"",validation:null,errorMessage:""};function Fu(t,a){return t===tn&&a>0?`${tn} ${a}/${ku}`:t;}async function Mu(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 Ou(t,a){const s=d=>{const i=d.trim();i&&a(JSON.parse(i));};if(!t.body){(await t.text()).split(`
|
|
102
|
+
`).forEach(s);return;}const r=t.body.getReader(),l=new TextDecoder();let o="";for(;;){const{done:d,value:i}=await r.read();if(d)break;o+=l.decode(i,{stream:!0});const c=o.split(`
|
|
103
|
+
`);o=c.pop()??"",c.forEach(s);}s(o+l.decode());}function Au({currentSql:t,selectedDatabaseName:a,selectedSchemaName:s,selectedTableName:r,onApplySql:l,autoFocus:o,onDismiss:d}){var st,Je;const{authToken:i,tokenProps:c}=Gt(),x=E(Z=>Z.card.id),u=E(Z=>{var ve;return Z.card.connectionId||((ve=Z.card.dataSource)==null?void 0:ve.connectionId)||"";}),[f,h]=G(""),[p,N]=G("draft"),[T,S]=G(!1),[b,y]=G(!1),[F,v]=G(zt),[D,K]=G(x),j=Ie(null),_=Ie(0),k=Ie(null),A=(st=c.apiServiceUrl)==null?void 0:st.replace(/\/$/,""),$=A?`${A}/v1/sql/draft`:"/v1/sql/draft";function C(){var Z;_.current+=1,(Z=k.current)==null||Z.abort(),k.current=null;}ye(()=>()=>{var Z;_.current+=1,(Z=k.current)==null||Z.abort(),k.current=null;},[x]),D!==x&&(K(x),v(Z=>({...zt,runId:Z.runId})),h(""),S(!1));const R=F.status==="running";function I(){F.status==="running"&&(C(),v(Z=>({...Z,status:"idle",activeStep:"",sql:"",validation:null})),Bt("inline_self_heal_stopped",{runId:F.runId,attemptCount:F.attempt,finalOutcome:"cancelled"}));}async function m(Z,ve,Ae){const Le=()=>_.current===Z,Pe=ge=>{Le()&&v(se=>se.runId===Z?ge(se):se);},De=ge=>Pe(se=>({...se,status:"failed",activeStep:"",errorMessage:ge}));let Ge=!1;const et=ge=>{var Ee;if(!Le()||Ge)return;if(ge.type==="stage"){const Ce=Fa[ge.stage];if(!Ce)return;const $e=ge.stage==="repairing"?ge.attempt??0:0;Pe(B=>({...B,timelineSteps:B.timelineSteps.includes(Ce)?B.timelineSteps:[...B.timelineSteps,Ce],activeStep:Ce,attempt:ge.stage==="repairing"?$e:B.attempt})),ge.stage==="repairing"&&Bt("inline_self_heal_attempt",{runId:Z,attemptCount:$e});return;}if(Ge=!0,ge.type==="error"){De(ge.message||Vt);return;}const se=((Ee=ge.sql)==null?void 0:Ee.trim())||"";if(!se){De(Vt);return;}Pe(Ce=>({...Ce,status:"done",activeStep:"",sql:se,validation:ge.validation})),ge.validation.status==="invalid"?Bt("inline_validation_failed",{runId:Z,attemptCount:ge.repairs,errorCode:ge.validation.code,finalOutcome:"validation_failed"}):Bt("inline_draft_validated",{runId:Z,attemptCount:ge.repairs,finalOutcome:ge.validation.status});};try{const ge=await fetch($,{method:"POST",headers:{Authorization:`Bearer ${i==null?void 0:i.accessToken}`,"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(ve),signal:Ae});if(!Le())return;if(!ge.ok){De(await Mu(ge,Vt));return;}await Ou(ge,et),Ge||De(Vt);}catch{De(Vt);}finally{Le()&&(k.current=null);}}const M=(t==null?void 0:t.trim())||"";function g(Z="draft"){if(R)return;const ve=f.trim();if(!ve)return;const Ae=Z==="refine"&&M?"refine":"draft",Le=Ae==="refine"?M:"";C();const Pe=_.current;if(S(!1),y(!0),!u){v({...zt,runId:Pe,status:"failed",prompt:ve,errorMessage:Eu});return;}v({...zt,runId:Pe,status:"running",prompt:ve,mode:Ae,baselineSql:Le}),Bt("inline_draft_started",{runId:Pe,attemptCount:0,finalOutcome:"drafting"});const De=new AbortController();k.current=De,m(Pe,{request:ve,mode:Ae,...(M?{currentSql:M}:{}),connectionId:u,...(a?{database:a}:{}),...(s?{schema:s}:{}),...(r?{table:r}:{})},De.signal);}const w=F.status==="done"?F.sql:"",O=F.prompt,q=F.mode,z=F.baselineSql;function L(Z){const ve=w.trim();ve&&(l(ve,Z),Z||y(!1));}const V=w.length>0,W=((Je=F.validation)==null?void 0:Je.status)==="invalid",ee=V&&O.length>0&&O===f.trim(),ie=M.length>0,Y=f.trim().length>0,H=!!d&&!Y&&!V&&!R,X=ee&&q==="draft",de=ee&&q==="refine"&&z===M,pe=p==="refine"&&!ie?"draft":p,fe=(pe==="refine"?de:X)?"Open composer preview":"Generate composer SQL",ue=f.trim().length>0||O.trim().length>0||V||F.status!=="idle"||F.timelineSteps.length>0;function ke(Z="draft"){if(R)return;if((Z==="refine"?de:X)&&!b){y(!0);return;}g(Z);}function Ve(){y(!0);}function qe(Z){I(),h(Z);}function Be(){R||(C(),h(""),N("draft"),S(!1),v({...zt,runId:_.current}));}function ce(Z){Z||I(),y(Z);}const Fe=F.timelineSteps.findIndex(Z=>Z===F.activeStep),Oe=F.activeStep===Fa.repairing?"Fixing validation issue":F.activeStep||Fa.drafting,Re=!V||!F.validation?null:F.validation.status==="valid"?{label:"Validation passed",className:"border-emerald-500/30 bg-emerald-500/10 text-emerald-700",detail:"SQL validation passed."}:F.validation.status==="invalid"?{label:"Validation failed",className:"border-destructive/40 bg-destructive/10 text-destructive",detail:F.validation.message}:{label:"Validation unavailable",className:"border-border/60 bg-muted/20 text-muted-foreground",detail:Iu};return/* @__PURE__ */n("div",{ref:j,className:"relative flex h-7 min-w-0 flex-1 items-center",children:[/* @__PURE__ */e(ct,{value:f,onChange:Z=>qe(Z.target.value),autoFocus:o,onFocus:Ve,onClick:Ve,onKeyDown:Z=>{Z.key==="Enter"?(Z.preventDefault(),ke(pe)):Z.key==="Escape"&&H&&(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",Y?"pr-[56px]":d?"pr-9":"pr-3"].join(" ")}),/* @__PURE__ */n(lt,{open:b,onOpenChange:ce,children:[/* @__PURE__ */e(bc,{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:[(Y||d)&&/* @__PURE__ */e(le,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0",onClick:Z=>{Z.preventDefault(),Y?(I(),h("")):H?d==null||d():Be();},disabled:R,"aria-label":Y?"Clear input":H?"Close":"Clear draft",title:Y?"Clear input":H?"Close":"Clear draft",children:/* @__PURE__ */e(ca,{className:"size-3.5"})}),Y&&/* @__PURE__ */e(le,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0",onClick:Z=>{if(Z.preventDefault(),R){I();return;}ke(pe);},"aria-label":R?"Stop AI generation":fe,title:R?"Stop AI generation":fe,children:R?/* @__PURE__ */e(Or,{className:"size-3 fill-current"}):/* @__PURE__ */e(Cu,{className:"size-3.5"})})]}),/* @__PURE__ */e(it,{align:"start",alignOffset:0,side:"top",sideOffset:8,className:"w-[min(92vw,var(--radix-popover-trigger-width))] max-w-[760px] p-2.5",onOpenAutoFocus:Z=>{Z.preventDefault();},onInteractOutside:Z=>{var Ae;const ve=Z.target;if(ve&&(Ae=j.current)!=null&&Ae.contains(ve)){Z.preventDefault();return;}H&&(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(le,{type:"button",variant:"ghost",className:["h-6 rounded-[4px] px-2 text-[12px]",pe==="draft"?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground"].join(" "),onClick:()=>{N("draft"),S(!1);},children:"Draft New"}),/* @__PURE__ */e(le,{type:"button",variant:"ghost",className:["h-6 rounded-[4px] px-2 text-[12px]",pe==="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:[R&&/* @__PURE__ */e(le,{variant:"ghost",size:"xs",onClick:I,children:"Stop"}),!R&&/* @__PURE__ */e(le,{variant:"ghost",size:"xs",onClick:Be,disabled:!ue,children:"Clear"})]})]}),(F.timelineSteps.length>0||Re)&&/* @__PURE__ */n("div",{className:"flex flex-wrap items-center gap-1",children:[F.timelineSteps.map((Z,ve)=>{const Ae=R&&Z===F.activeStep,Le=!Ae&&Fe>=0&&ve<Fe;return/* @__PURE__ */e("span",{className:["rounded-full border px-2 py-0.5 text-[11px]",Ae?"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:Fu(Z,F.attempt)},`${Z}-${ve}`);}),Re&&/* @__PURE__ */e(Lt,{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]",Re.className].join(" "),children:Re.label})}),/* @__PURE__ */e(pt,{side:"top",align:"start",className:"max-w-[680px] whitespace-pre-wrap break-words text-xs",children:Re.detail})]})})]}),R&&/* @__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(da,{className:"size-3.5 animate-spin"}),Oe]}),F.status==="failed"&&/* @__PURE__ */e("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive",children:F.errorMessage}),q==="refine"&&z&&/* @__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(le,{type:"button",variant:"ghost",size:"xs",onClick:()=>S(Z=>!Z),children:T?"Hide base SQL":"View base SQL"})]}),T&&/* @__PURE__ */e("div",{className:"max-h-[120px] overflow-auto rounded-[5px] border border-border/60",children:/* @__PURE__ */e(Ft,{value:z,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:[q==="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(Ft,{value:w,onValueChange:()=>{},language:"sql",readOnly:!0,embedded:!0,wrapLines:!0,dense:!0,hideLineNumbers:!0,ariaLabel:"Drafted SQL"})})]}):!R&&/* @__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(le,{variant:"secondary",size:"xs",disabled:R||!V,onClick:()=>L(!1),children:"Replace SQL"}),/* @__PURE__ */e(le,{size:"xs",disabled:R||!V||W,onClick:()=>L(!0),children:"Replace & Run"})]})]})})]})]});}function Ru({activeEditor:t,isRunning:a,sqlEditor:s,pythonEditor:r,onActiveEditorChange:l,onOpenChange:o,onRun:d}){return/* @__PURE__ */e(Pt,{open:t!==null,onOpenChange:o,children:/* @__PURE__ */e(Dt,{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:c=>l(c),className:"flex min-h-0 flex-1 flex-col",children:[/* @__PURE__ */n(Wt,{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(_t,{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(ze,{value:"sql",className:"px-0",children:"SQL"}),/* @__PURE__ */e(ze,{value:"python",className:"px-0",children:"Python"})]}),/* @__PURE__ */e(dt,{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(le,{type:"button",size:"xs",onClick:d,disabled:a,children:[a?/* @__PURE__ */e(da,{className:"h-3.5 w-3.5 animate-spin"}):/* @__PURE__ */e(Ar,{className:"h-3.5 w-3.5"}),"Run"]}),/* @__PURE__ */e(le,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>o(!1),"aria-label":"Collapse query editor",title:"Collapse editor",children:/* @__PURE__ */e(xi,{className:"h-3.5 w-3.5"})})]})]}),/* @__PURE__ */e(Qe,{value:"sql",forceMount:!0,className:"mt-0 min-h-0 flex-1 data-[state=inactive]:hidden",children:s}),/* @__PURE__ */e(Qe,{value:"python",forceMount:!0,className:"mt-0 min-h-0 flex-1 data-[state=inactive]:hidden",children:r})]})})});}function ar(t,a){return t.current.cardId!==a&&(t.current={cardId:a,snapshots:{}}),t.current;}function Lu({cardId:t,expandedEditor:a}){const s=Ie(null),r=Ie(null),l=Ie(null),o=Ie(null),d=Ie({cardId:t,snapshots:{}}),i=rt(c=>{var N,T;const x=c==="inline"?s:l,u=c==="inline"?r:o,f=(N=x.current)==null?void 0:N.captureSession(),h=(T=u.current)==null?void 0:T.captureSession(),p=ar(d,t);f&&(p.snapshots.sql=f),h&&(p.snapshots.python=h);},[t]);return ye(()=>{var p,N;const c=ar(d,t),x=a===null?s:l,u=a===null?r:o,{sql:f,python:h}=c.snapshots;f&&((p=x.current)==null||p.restoreSession(f)),h&&((N=u.current)==null||N.restoreSession(h));},[t,a]),{inlineSqlEditorRef:s,inlinePythonEditorRef:r,expandedSqlEditorRef:l,expandedPythonEditorRef:o,captureEditorSessions:i};}function Ss({openDelay:t=200,closeDelay:a=150}={}){const[s,r]=G(!1),l=Ie(null),o=Ie(null),d=Ie(!1),i=()=>{l.current&&(clearTimeout(l.current),l.current=null);},c=()=>{o.current&&(clearTimeout(o.current),o.current=null);};ye(()=>()=>{l.current&&clearTimeout(l.current),o.current&&clearTimeout(o.current);},[]);const x=f=>{f.pointerType!=="touch"&&(c(),!s&&(i(),l.current=setTimeout(()=>r(!0),t)));},u=f=>{f.pointerType!=="touch"&&(i(),c(),o.current=setTimeout(()=>r(!1),a));};return{popoverProps:{open:s,onOpenChange:r},triggerProps:{onPointerEnter:x,onPointerLeave:u,onFocus:()=>{i(),c(),d.current||r(!0);},onClick:f=>{f.preventDefault(),i(),c(),r(!0);}},contentProps:{onCloseAutoFocus:()=>{d.current=!0,queueMicrotask(()=>{d.current=!1;});},onPointerEnter:f=>{f.pointerType!=="touch"&&c();},onPointerLeave:u}};}function Pu({value:t}){const[a,s]=G(!1),r=Ie(null);ye(()=>()=>{r.current&&clearTimeout(r.current);},[]);const l=async()=>{var o;try{if(!((o=navigator.clipboard)!=null&&o.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{nt.error("Failed to copy");}};return/* @__PURE__ */n("button",{type:"button","aria-label":`Copy ${t}`,onClick:l,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(ua,{"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(Yt,{"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 Du({hint:t}){const{popoverProps:a,triggerProps:s,contentProps:r}=Ss();return/* @__PURE__ */n(lt,{...a,children:[/* @__PURE__ */e(xt,{asChild:!0,children:/* @__PURE__ */n(le,{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(Rd,{className:"h-3.5 w-3.5",strokeWidth:1.75}),/* @__PURE__ */e("span",{className:"hidden @[1550px]:inline",children:"Dashboard filters off"})]})}),/* @__PURE__ */n(it,{align:"start",collisionPadding:8,...r,onOpenAutoFocus:l=>l.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(Pu,{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 _u({activeEditor:t,showCode:a=!1,onExpand:s,trailing:r}){const l=`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(ze,{value:"sql",className:"px-0 text-[13px]",children:"SQL"}),/* @__PURE__ */e(ze,{value:"python",className:"px-0 text-[13px]",children:"Python"}),a?/* @__PURE__ */e(ze,{value:"code",className:"px-0 text-[13px]",children:"Code"}):null]}),/* @__PURE__ */n("div",{className:"ml-auto flex min-w-0 shrink-0 items-center gap-1.5",children:[r,t!=="code"?/* @__PURE__ */e(le,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:s,"aria-label":l,title:l,children:/* @__PURE__ */e(yc,{className:"h-3.5 w-3.5",strokeWidth:1.75})}):null]})]}));}function Ts({open:t,onOpenChange:a,text:s,withCode:r}){const l=async()=>{await vr(s,"Prompt copied"),a(!1);};return/* @__PURE__ */e(Pt,{open:t,onOpenChange:a,children:/* @__PURE__ */n(Dt,{className:"max-w-[720px] gap-0 p-0",children:[/* @__PURE__ */n(Wt,{className:"border-b border-border px-4 py-3",children:[/* @__PURE__ */e(_t,{className:"text-[14px]",children:"Prompt for your assistant"}),/* @__PURE__ */e(dt,{className:"text-[12px]",children:r?"The rules a visual follows, this card's fields and the code below. Paste it into Claude, ChatGPT or any assistant with the change you want, then paste the HTML it writes into the Code tab and apply it.":"The rules a visual follows and this card's fields. Paste it into Claude, ChatGPT or any assistant with what you want to see, then paste the HTML it writes here."})]}),/* @__PURE__ */e("div",{className:"p-4",children:/* @__PURE__ */e("pre",{className:"max-h-[60vh] overflow-auto whitespace-pre-wrap rounded-md border border-border bg-muted/40 p-3 font-mono text-[11px] leading-[1.5] text-foreground","aria-label":"Prompt",tabIndex:0,children:s})}),/* @__PURE__ */n(Ht,{className:"gap-2 border-t border-border px-4 py-3",children:[/* @__PURE__ */e(le,{type:"button",variant:"ghost",size:"xs",onClick:()=>a(!1),children:"Close"}),/* @__PURE__ */n(le,{type:"button",size:"xs",onClick:()=>void l(),children:[/* @__PURE__ */e(Yt,{className:"mr-1 h-3 w-3"})," Copy prompt"]})]})]})});}function ks({findings:t,manifest:a}){return t.length?/* @__PURE__ */e("ul",{className:"space-y-1","aria-label":"What to fix",children:t.map((s,r)=>/* @__PURE__ */e("li",{className:s.severity==="error"?"text-destructive":"text-muted-foreground",children:s.message},`${s.code}-${r}`))}):a?/* @__PURE__ */n("p",{className:"text-muted-foreground",children:[a.name," is ready to draw."]}):null;}function Es({check:t,onRetry:a}){if(!t)return null;const s=a&&(t.status==="error"||t.status==="done"&&t.ranRender===!1)?/* @__PURE__ */n(le,{type:"button",variant:"ghost",size:"xs",className:"-ml-2 h-6",onClick:a,children:[/* @__PURE__ */e(Nu,{className:"mr-1 h-3 w-3"})," Check again"]}):null;return/* @__PURE__ */n(xe,{children:[/* @__PURE__ */e(Vu,{check:t}),s]});}function Vu({check:t}){if(t.status==="pending")return/* @__PURE__ */e("p",{className:"text-muted-foreground",children:"Checking the visual at several sizes, light and dark…"});if(t.status==="error")return/* @__PURE__ */e("p",{className:"text-muted-foreground",children:"The visual couldn't be checked here. Saving checks it again and refuses it only if it doesn't work."});const a=t.findings??[],s=a.filter(l=>l.severity==="error"),r=a.filter(l=>l.severity==="warning");return!s.length&&!r.length?/* @__PURE__ */e("p",{className:"text-muted-foreground",children:"Checked at four sizes, light and dark: no problems."}):/* @__PURE__ */n("div",{className:"space-y-1",children:[s.length?/* @__PURE__ */e("p",{className:"text-destructive",children:"Fix this before saving; the dashboard won't save it as it is:"}):null,/* @__PURE__ */e("ul",{className:"space-y-1","aria-label":"Check results",children:[...s,...r].map((l,o)=>/* @__PURE__ */n("li",{className:l.severity==="error"?"text-destructive":"text-muted-foreground",children:[l.message,l.fix?/* @__PURE__ */e("span",{className:"block text-muted-foreground",children:l.fix}):null]},`${l.code}-${o}`))})]});}function Is(){const{card:t,html:a,loading:s,loadFailed:r,reading:l,manifest:o,check:d,recheck:i,write:c,promptText:x}=Nr(),[u,f]=G(!1),[h,p]=G();h&&(h.cardId!==t.id||h.source!==a)&&p(void 0);const N=(h==null?void 0:h.text)??a??"",T=s||r,S=!T&&N!==(a??""),b=()=>{S&&c({html:N});},y=Ie(b);y.current=b,ye(()=>vc(()=>y.current()),[]);const F=D=>{D.key==="Enter"&&(D.metaKey||D.ctrlKey)&&(D.preventDefault(),b());},v=r?/* @__PURE__ */e("p",{className:"text-destructive",children:"This visual's code can't be loaded."}):!S&&(l&&l.findings.length||d)?/* @__PURE__ */n("div",{className:"space-y-1",children:[l&&l.findings.length?/* @__PURE__ */e(ks,{findings:l.findings,manifest:o}):null,/* @__PURE__ */e(Es,{check:d,onRetry:i})]}):null;return/* @__PURE__ */n("div",{className:"flex min-h-0 flex-1 flex-col px-4 pb-4 pt-3 text-[12px]","data-testid":"custom-visual-code",children:[/* @__PURE__ */n("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden rounded-md border border-border",children:[/* @__PURE__ */n("div",{className:"flex h-9 shrink-0 items-center justify-between gap-2 border-b border-border bg-muted/40 pl-3 pr-1.5",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-2","aria-live":"polite",children:[/* @__PURE__ */e(bi,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground","aria-hidden":"true"}),/* @__PURE__ */e("span",{className:"truncate font-medium text-foreground",children:(o==null?void 0:o.name)??"Custom visual"}),/* @__PURE__ */e("span",{className:"text-muted-foreground",children:"HTML"}),S?/* @__PURE__ */n("span",{className:"flex items-center gap-1 text-muted-foreground",children:[/* @__PURE__ */e("span",{className:"h-1.5 w-1.5 rounded-full bg-amber-500","aria-hidden":"true"})," Edited"]}):null]}),/* @__PURE__ */n("div",{className:"flex shrink-0 items-center gap-0.5",children:[S?/* @__PURE__ */n(xe,{children:[/* @__PURE__ */n(le,{type:"button",variant:"ghost",size:"xs",onClick:()=>p(void 0),children:[/* @__PURE__ */e(yi,{className:"mr-1 h-3 w-3"})," Revert"]}),/* @__PURE__ */n(le,{type:"button",size:"xs",className:"mr-1",onClick:b,title:"Apply (⌘/Ctrl+Enter)",children:[/* @__PURE__ */e(ua,{className:"mr-1 h-3 w-3"})," Apply"]})]}):null,/* @__PURE__ */e(_e,{tooltip:"View prompt for an assistant",disabled:T,onClick:()=>f(!0),className:"h-7 w-7 p-0 text-muted-foreground",buttonProps:{"aria-label":"View prompt"},children:/* @__PURE__ */e(bs,{className:"h-3.5 w-3.5"})}),/* @__PURE__ */e(_e,{tooltip:"Copy code",disabled:!N,onClick:()=>void vr(N,"Code copied"),className:"h-7 w-7 p-0 text-muted-foreground",buttonProps:{"aria-label":"Copy code"},children:/* @__PURE__ */e(Yt,{className:"h-3.5 w-3.5"})})]})]}),v?/* @__PURE__ */e("div",{className:"shrink-0 border-b border-border px-3 py-2",children:v}):null,/* @__PURE__ */e(Ft,{value:N,onValueChange:D=>p(D===(a??"")?void 0:{cardId:t.id,source:a,text:D}),language:"html",embedded:!0,readOnly:T,ariaLabel:"Visual HTML",placeholder:s?"Loading the visual…":r?"":"Paste or write the visual's HTML, then apply it",onKeyDown:F,className:"min-h-0 flex-1"},t.id)]}),u?/* @__PURE__ */e(Ts,{open:!0,onOpenChange:f,text:x(N),withCode:!!N.trim()}):null]});}function Bu({value:t}){const[a,s]=G(!1),r=Ie(null);return ye(()=>()=>{r.current&&clearTimeout(r.current);},[]),/* @__PURE__ */n(le,{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 o;try{if(!((o=navigator.clipboard)!=null&&o.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{nt.error("Failed to copy");}},children:[a?/* @__PURE__ */e(ua,{className:"h-3 w-3",strokeWidth:1.75}):/* @__PURE__ */e(Yt,{className:"h-3 w-3",strokeWidth:1.75}),a?"Copied":"Copy"]});}function zu(){const{popoverProps:t,triggerProps:a,contentProps:s}=Ss();return/* @__PURE__ */n(lt,{...t,children:[/* @__PURE__ */e(xt,{asChild:!0,children:/* @__PURE__ */n(le,{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(ut,{className:"h-3.5 w-3.5",strokeWidth:1.75}),"How it works"]})}),/* @__PURE__ */n(it,{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(Bu,{value:Pn})]}),/* @__PURE__ */e("div",{className:"max-h-40 overflow-auto",children:/* @__PURE__ */e(Ft,{value:Pn,language:"python",readOnly:!0,embedded:!0,dense:!0,hideLineNumbers:!0,wrapLines:!0,ariaLabel:"Python example"})})]})]})]});}function Ku({open:t,onOpenChange:a,onConfirm:s}){return/* @__PURE__ */e(vi,{open:t,onOpenChange:a,children:/* @__PURE__ */n(Ni,{children:[/* @__PURE__ */n(Ci,{children:[/* @__PURE__ */e(wi,{children:"Clear the editor?"}),/* @__PURE__ */e(Si,{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(Ti,{children:[/* @__PURE__ */e(ki,{children:"Cancel"}),/* @__PURE__ */e(Ei,{className:Q(Nc({variant:"destructive",size:"xs"})),onClick:s,children:"Clear"})]})]})});}function qu(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:Sn};}function $u(){const{setTempQueryData:t}=he(),a=gn(),s=E(F=>F.tempQueryData),r=E(F=>F.card),l=Ke(),o=J(()=>l!==r.type?{...r,type:l}:r,[r,l]),{queryKey:d}=He(o),{setCardSql:i,setSqlGen:c,setCardPython:x,setCardCustomCfg:u,setCardPreferences:f,clearQueryConfig:h,setCardConfig:p,setCardType:N,setFrame:T,setCard:S,setActiveTabCardId:b}=he();function y(){var k,A,$,C;const F=a.getQueryData(d);s!=null&&s.queryData||t({queryKey:d,queryData:F}),a.setQueryData(d,null),a.removeQueries({queryKey:d,exact:!0}),i(""),c({}),h(),p(void 0),x(""),u(""),f({});const v=E.getState().frame,D=E.getState().card,K=vt(v,D),j=((k=K==null?void 0:K.customCardPreferences)==null?void 0:k.visualType)==="multiple"||!!((A=K==null?void 0:K.customCardPreferences)!=null&&A.dataInputCardIds)||((($=K==null?void 0:K.customCardPreferences)==null?void 0:$.minInputs)||0)>1||(((C=K==null?void 0:K.customCardPreferences)==null?void 0:C.maxInputs)||0)>1,_=qu(D,j);T({...v,cards:v.cards.map(R=>R.id===_.id?_:R)}),b(_.id),S(_),j||N(Sn);}return y;}const nr="[&_.code-editor-pre]:!pb-14 [&_.code-editor-textarea]:!pb-14";function ju(){var se,Ee,Ce,$e;const t=gn(),{tokenProps:a}=Gt(),s=((Ee=(se=a.config)==null?void 0:se.projectFeatures)==null?void 0:Ee.features.aiWritingHelpers)!==!1,[r,l]=G("sql"),[o,d]=G(!1),[i,c]=G(!1),x=$u(),[u,f]=G(!1),[h,p]=G(null),N=E(B=>B.frame),T=E(B=>B.card),S=(T==null?void 0:T.type)==="customVisual",b=r==="code"&&!S?"sql":r,{inlineSqlEditorRef:y,inlinePythonEditorRef:F,expandedSqlEditorRef:v,expandedPythonEditorRef:D,captureEditorSessions:K}=Lu({cardId:T.id,expandedEditor:h});E(B=>B.selectedConnectionId),E(B=>B.tempQueryData);const j=E(B=>B.selectedDatabaseName);E(B=>B.selectedDatamodelId);const _=E(B=>B.selectedSchemaName),k=E(B=>B.selectedTableName),A=be(B=>B.dashboard?wr(B.dashboard).length:0),$=E(B=>B.inlineFilterValuesMap[(T==null?void 0:T.id)??""]),C=J(()=>vt(N,T),[N,T]),{manifest:R}=bt(((Ce=C==null?void 0:C.customCardPreferences)==null?void 0:Ce.url)||""),I=J(()=>{var B;return(B=R==null?void 0:R.visuals)==null?void 0:B.find(me=>{var We;return me.name===((We=C==null?void 0:C.customCardPreferences)==null?void 0:We.componentName);});},[R,($e=C==null?void 0:C.customCardPreferences)==null?void 0:$e.componentName]),m=Nt(C,I),M=J(()=>Xt({frame:N,configCard:C,isMultiInputVisual:m==="multiple"}),[N,C,m]),g=J(()=>{const B=M.findIndex(me=>(me==null?void 0:me.id)===(T==null?void 0:T.id));return B<0?-1:at(T,B);},[M,T]),w=J(()=>!C||m!=="multiple"||g<0?T.type:It(T,g,I==null?void 0:I.slots)??T.type,[C,m,g,T,I==null?void 0:I.slots]),O=J(()=>w!==T.type?{...T,type:w}:T,[T,w]),q=J(()=>A===0?null:il(T==null?void 0:T.sql),[T==null?void 0:T.sql,A]),z=Ie(!0),{setCardCustomCfg:L,setQueryResultColumns:V,setCardSql:W,setTempQueryData:ee,setCardPreferences:ie,setCardType:Y,setCardPython:H,setCard:X,updateCardInFrame:de}=he();E(B=>B.onSave),E(B=>B.onClose),E(B=>B.actions.setSqlGen);const pe=E(B=>B.runSql),oe=E(B=>B.actions.setRunSql),fe=E(B=>B.actions.setIsSqlRunning),{data:ue,isLoading:ke,isFetching:Ve,isSuccess:qe,isError:Be,error:ce,errorSql:Fe,queryKey:Oe,refetch:Re,errorMessage:st}=He(O),Je=Ie(Oe);Je.current=Oe;const Z=T.type==="kpi"&&rn(T);ye(()=>{if(ue)if(ue.rowLimitExceeded&&nt.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),ue.records.length>0){const{keys:B}=Yr(ue.records),me=Z?ol(ue.records).value:void 0;V(T.type==="kpi"?me?[me]:[]:B,ue.columnKeyMap,ue.columns);}else V([]);},[T.type,ue,V,Z]),ye(()=>{(ke||Ve)&&(fe(!0),V([])),(Be||qe)&&fe(!1),Be&&V([]);},[ke,Ve,ue,Be,qe,fe,V,ce]),ye(()=>{pe&&(t.getQueryData(Oe)||Re(),oe(!1));},[pe,Re,oe,Oe,t]);const ve=Ie(Re);ve.current=Re,ye(()=>{if(z.current){z.current=!1;return;}ve.current();},[$]);function Ae(B,me){W(B),me&&oe(!0);}function Le(){Cr({queryClient:t,readQueryKey:()=>Je.current,setRunSql:oe});}function Pe(B){wt(),K("inline"),p(B);}function De(B){wt(),K("expanded"),p(B);}function Ge(B){B||(wt(),K("expanded"),p(null));}function et(B){b!=="code"&&s&&(B.metaKey||B.ctrlKey)&&!B.altKey&&!B.shiftKey&&B.key.toLowerCase()==="k"&&(B.preventDefault(),d(!0));}const ge=ke||Ve;return(/* @__PURE__ */n("section",{role:"editor-section",className:"flex grow flex-col justify-end",onKeyDown:et,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:Q("min-w-0",u&&"flex-1"),children:/* @__PURE__ */e(ta,{value:T.title,onSave:B=>X({...T,title:B}),onEditingChange:f,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(Rr,{card:T})]}),/* @__PURE__ */e(ta,{value:(T.description||"").trim(),onSave:B=>X({...T,description:B.trim()}),isEditable:!0,placeholder:"Add description",displayClassName:"text-[12px] leading-snug text-muted-foreground",inputClassName:"text-[12px] leading-snug"})]}),/* @__PURE__ */n(ft,{value:b,onValueChange:B=>{wt(),l(B);},className:"flex min-h-0 grow flex-col",children:[/* @__PURE__ */e(_u,{activeEditor:b,showCode:S,onExpand:()=>b!=="code"&&Pe(b),trailing:/* @__PURE__ */n(xe,{children:[q?/* @__PURE__ */e(Du,{hint:q}):null,b==="python"?/* @__PURE__ */e(zu,{}):null]})}),/* @__PURE__ */n("div",{className:"relative min-h-0 grow",children:[/* @__PURE__ */e(Qe,{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:h===null?/* @__PURE__ */e(Rn,{ref:y,className:nr},`inline-sql-${T.id}`):null})}),/* @__PURE__ */e(Qe,{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:h===null?/* @__PURE__ */e(Ln,{ref:F,className:nr},`inline-python-${T.id}`):null})}),S?/* @__PURE__ */e(Qe,{value:"code",className:"absolute inset-0 mt-0 flex flex-col data-[state=inactive]:hidden",children:b==="code"?/* @__PURE__ */e(Is,{}):null}):null,/* @__PURE__ */n("div",{role:"editor-controls",className:Q("pointer-events-none absolute inset-x-4 bottom-3 z-10 flex items-end justify-end gap-2",b==="code"&&"hidden"),children:[s?o?/* @__PURE__ */e("div",{className:"pointer-events-auto flex min-w-0 max-w-[560px] flex-1",children:/* @__PURE__ */e(Au,{currentSql:T==null?void 0:T.sql,selectedDatabaseName:j,selectedSchemaName:_,selectedTableName:k,onApplySql:Ae,autoFocus:!0,onDismiss:()=>d(!1)})}):/* @__PURE__ */e(le,{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(le,{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:()=>c(!0),children:"Clear"}),/* @__PURE__ */n(le,{title:"Shift + Enter",disabled:ge,onClick:Le,className:"pointer-events-auto shrink-0",size:"xs",children:[ge?/* @__PURE__ */e(da,{className:"h-3.5 w-3.5 animate-spin"}):/* @__PURE__ */e(Ar,{className:"h-3.5 w-3.5"}),"Run"]})]})]})]}),/* @__PURE__ */e(Ku,{open:i,onOpenChange:c,onConfirm:x}),/* @__PURE__ */e(Ru,{activeEditor:h,isRunning:ge,sqlEditor:/* @__PURE__ */e(Rn,{ref:v},`expanded-sql-${T.id}`),pythonEditor:/* @__PURE__ */e(Ln,{ref:D},`expanded-python-${T.id}`),onActiveEditorChange:De,onOpenChange:Ge,onRun:Le})]}));}function En(){const t=E(r=>r.actions.setCardType),{columns:a,isLoading:s}=Ii();return rt((r,l)=>{const o=t(r,{...l,catalog:a,catalogLoading:s});return o.status==="refused"?nt.info("Fields are still loading",{description:"Try switching again in a moment."}):o.status==="changed"&&o.leftOut.length&&nt.info("Some fields did not carry over to this visual",{description:o.leftOut.join(", ")}),o;},[t,a,s]);}const Ma=[{value:"table",label:"Table"},{value:"detailTable",label:"Detail"}];function Hu({className:t}){const a=E(p=>p.card),s=E(p=>p.frame),r=E(p=>p.editorContext),l=Ke(),{setCard:o,updateCardInFrame:d}=he(),i=(r==null?void 0:r.type)==="documentSection"&&!!r.lockedKind,c=(r==null?void 0:r.type)==="documentSection"?Ma.filter(p=>p.value==="table"):Ma,x=Ma.some(p=>p.value===l),u=Qt(a.config,a.type),f=kd(a,s.cards);if(!x||!u||f||i||c.length<2)return/* @__PURE__ */e("div",{"aria-hidden":"true",className:Q("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 h=p=>{if(p===l||f)return;const N=p,T=a.config??{},S=cl(l,N,T),b={...a,type:N,config:S};o(b),d(b);};return/* @__PURE__ */e("div",{role:"tablist",className:Q("flex items-center gap-5",t),children:c.map(p=>{const N=l===p.value;return/* @__PURE__ */e("button",{type:"button",role:"tab","aria-selected":N,onClick:()=>h(p.value),className:Q("-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:p.label},p.value);})});}function Fs(t){const a=E(d=>d.card),s=E(d=>d.isDevMode),{switchEditorMode:r,setRunSql:l}=he(),o=()=>{const d=t||a.sql||a.python||"";r("dev",{sqlToLoad:d}),setTimeout(()=>{l(!0);},100);};return{isDevMode:s,handleOpenInEditor:!s&&sn(a.type)?o:void 0};}function Uu(){const{authToken:t,tokenProps:a}=Gt(),{currentUser:s}=cn(),r=Fi({mutationFn:async l=>{if(!(t!=null&&t.accessToken))throw new Error("No authentication token available");const d=`${a.apiServiceUrl||""}/v1/feedback`,i={...l,user:s,tokenContext:a},c=await dl(d,t.accessToken,i,"POST");if(!c||!c.success)throw new Error((c==null?void 0:c.error)||"Failed to send feedback");return c;},onSuccess:l=>{nt.success(`Feedback sent successfully! Issue: ${l.issueNumber}`,{duration:5e3});},onError:l=>{console.error("Feedback submission error:",l),nt.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 Qu(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 Gu({code:t,language:a,wrapLongLines:s=!1,className:r,ariaLabel:l}){const o=J(()=>Cc(t,a),[t,a]);return(/* @__PURE__ */e("div",{className:Q("code-editor",r),children:/* @__PURE__ */e("pre",{"aria-label":l,className:Q("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:o===null?/* @__PURE__ */e("code",{className:"text-foreground",children:t}):/* @__PURE__ */e("code",{dangerouslySetInnerHTML:{__html:o}})})}));}function In({open:t,onOpenChange:a,feedbackData:s,onSuccess:r,showDebugInfo:l=!1}){var D,K,j,_,k,A;const[o,d]=G(""),[i,c]=G(!1),{sendFeedback:x,isLoading:u,isSuccess:f,isError:h,data:p,reset:N}=Uu(),T=f?"Feedback Sent":"Report a Query Issue",S=f?"Your feedback was sent to the support team.":"Tell us what happened. We’ll include technical details to help support investigate.",b=()=>{const $={...s,userMessage:o.trim()||void 0};x($,{onSuccess:()=>r==null?void 0:r()});},y=()=>{d(""),c(!1),N(),a(!1);},F=$=>{$||y();},v={category:s.category,error:{message:(D=s.systemState)==null?void 0:D.errorMessage,sql:(K=s.systemState)==null?void 0:K.generatedSql,errorSql:(j=s.systemState)==null?void 0:j.errorSql},cardConfig:(_=s.systemState)==null?void 0:_.cardConfig,dataSource:(k=s.systemState)==null?void 0:k.dataSource,filters:(A=s.systemState)==null?void 0:A.dashboardFilters,metadata:s.metadata};return/* @__PURE__ */e(Pt,{open:t,onOpenChange:F,children:/* @__PURE__ */n(Dt,{"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(Wt,{className:"flex h-10 flex-row items-center space-y-0 border-b border-border px-3 pr-10 text-left",children:[/* @__PURE__ */e(_t,{className:"truncate text-[13px] font-medium",children:T}),f&&/* @__PURE__ */e(dt,{className:"sr-only",children:S})]}),!f&&/* @__PURE__ */n(xe,{children:[/* @__PURE__ */n("div",{className:"min-w-0 space-y-4 px-3 py-4",children:[/* @__PURE__ */e(dt,{className:"text-[12px] leading-[1.5] text-muted-foreground",children:S}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n(P,{htmlFor:"feedback-message",className:"text-[12px] font-medium",children:["What Happened?"," ",/* @__PURE__ */e("span",{className:"font-normal text-muted-foreground",children:"(Optional)"})]}),/* @__PURE__ */e(Lr,{id:"feedback-message",name:"feedback-message",autoComplete:"off",placeholder:"Describe what you were doing when the issue occurred…",value:o,onChange:$=>d($.target.value),size:"sm",className:"min-h-[112px] resize-none",disabled:u})]}),h&&/* @__PURE__ */n("div",{role:"alert",className:"flex items-start gap-2 text-[12px] leading-[1.5] text-destructive",children:[/* @__PURE__ */e(Qa,{"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."})]}),l&&/* @__PURE__ */n(Ot,{open:i,onOpenChange:c,children:[/* @__PURE__ */n("div",{className:"flex items-center gap-1",children:[/* @__PURE__ */e(At,{asChild:!0,children:/* @__PURE__ */n(le,{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"}),i?/* @__PURE__ */e(Mt,{"aria-hidden":"true",className:"h-3.5 w-3.5"}):/* @__PURE__ */e(yt,{"aria-hidden":"true",className:"h-3.5 w-3.5"})]})}),/* @__PURE__ */e(Xr,{text:JSON.stringify(v,null,2),className:"h-8 w-8 shrink-0"})]}),/* @__PURE__ */e(Rt,{className:"mt-2 min-w-0",children:/* @__PURE__ */e(xn,{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(Gu,{code:JSON.stringify(v,null,2),language:"json",wrapLongLines:!0})})})})]})]}),/* @__PURE__ */n(Ht,{className:"gap-2 border-t border-border px-3 py-3 sm:space-x-0",children:[/* @__PURE__ */e(le,{type:"button",variant:"outline",size:"xs",onClick:y,disabled:u,children:"Cancel"}),/* @__PURE__ */e(le,{type:"button",size:"xs",onClick:b,disabled:u,"aria-busy":u,className:"min-w-[100px]",children:u?/* @__PURE__ */n(xe,{children:[/* @__PURE__ */e(da,{"aria-hidden":"true",className:"h-3.5 w-3.5 animate-spin motion-reduce:animate-none"}),"Sending…"]}):"Send Feedback"})]})]}),f&&/* @__PURE__ */n(xe,{children:[/* @__PURE__ */n("div",{role:"status","aria-live":"polite",className:"flex items-start gap-3 px-3 py-4",children:[/* @__PURE__ */e(wc,{"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:p==null?void 0:p.issueNumber}),". Our support team will review the report."]})]})]}),/* @__PURE__ */e(Ht,{className:"border-t border-border px-3 py-3",children:/* @__PURE__ */e(le,{type:"button",size:"xs",onClick:y,children:"Close"})})]})]})});}var Fn=/* @__PURE__ */(t=>(t.QUERY_GENERATION="query-generation",t))(Fn||{});function Ms(t,a){const[s,r]=G(!1),l=E(u=>u.card),o=be(u=>wr(u.dashboard)),{currentUser:d}=cn(),{tokenProps:i}=wn(bn),c=rt(()=>{r(!0);},[]),x=J(()=>{const u=typeof window<"u"?window.location.href:"",f=typeof navigator<"u"?navigator.userAgent:"",h=typeof window<"u"?`${window.innerWidth}x${window.innerHeight}`:"";return{category:Fn.QUERY_GENERATION,user:d,tokenContext:i,systemState:{cardConfig:l.config,dataSource:l.dataSource,dashboardFilters:[...o],errorMessage:t||void 0,errorSql:a||l.sql||l.python,generatedSql:a||l.sql},metadata:{url:u,userAgent:f,timestamp:(/* @__PURE__ */new Date()).toISOString(),viewport:h}};},[d,i,l,o,t,a]);return{feedbackDialogOpen:s,setFeedbackDialogOpen:r,handleSendFeedback:c,feedbackPayload:x};}const Wu="__editor_sql__",Yu="__editor_python__";function Xu(t){var s;const a=ul(t.python||"");return{sql:(s=t.sql)!=null&&s.trim()?Wu:"",python:a.trim()?Yu:""};}function Os({className:t,style:a,...s}){var Le,Pe,De,Ge,et,ge;const r=E(se=>se.card),l=yn(),d=E(se=>se.isDevMode)?!1:((Le=r.customCardPreferences)==null?void 0:Le.showCardHeader)??!0,i=((De=(Pe=r.preferences)==null?void 0:Pe.displayOptions)==null?void 0:De.showInlineFilterBar)??!0,c=E(se=>se.frame),x=E(se=>se.inlineFilterValuesMap[r.id]),u=be(se=>se.selectedSheetId),f=E(se=>se.actions.setRunSql),h=E(se=>se.actions.setCardInlineFilterValue),p=E(se=>se.actions.removeCardInlineFilterValue),N=rt(se=>h(r.id,se),[r.id,h]),T=rt(se=>p(r.id,se),[r.id,p]),S=ml(r,x,{savedFilters:i}).length>0,b=J(()=>vt(c,r),[c,r]),{manifest:y}=bt(((Ge=b==null?void 0:b.customCardPreferences)==null?void 0:Ge.url)||""),F=J(()=>{var se;return(se=y==null?void 0:y.visuals)==null?void 0:se.find(Ee=>{var Ce;return Ee.name===((Ce=b==null?void 0:b.customCardPreferences)==null?void 0:Ce.componentName);});},[y,(et=b==null?void 0:b.customCardPreferences)==null?void 0:et.componentName]),v=Nt(b,F),D=J(()=>Xt({frame:c,configCard:b,isMultiInputVisual:v==="multiple"}),[c,b,v]),K=J(()=>{const se=D.findIndex(Ee=>(Ee==null?void 0:Ee.id)===(r==null?void 0:r.id));return se<0?-1:at(r,se);},[D,r]),j=J(()=>!b||v!=="multiple"||K<0?r.type:It(r,K,F==null?void 0:F.slots)??r.type,[b,v,K,r,F==null?void 0:F.slots]),_=j??r.type,k=J(()=>_===r.type?r:{...r,type:_},[r,_]),A=k.type==="table"||k.type==="matrixTable"||k.type==="detailTable",$=J(()=>j!==r.type?{...r,type:j}:r,[r,j]),{data:C,isLoading:R,isFetching:I,errorMessage:m,errorSql:M,pagination:g}=He($),w=ma(k,C),O=!!m,{handleOpenInEditor:q}=Fs(M||r.sql||r.python),{feedbackDialogOpen:z,setFeedbackDialogOpen:L,handleSendFeedback:V,feedbackPayload:W}=Ms(m,M||r.sql||r.python),ee=J(()=>(C==null?void 0:C.records)||[],[C==null?void 0:C.records]),{setCard:ie,updateCardInFrame:Y}=he(),H=w.id,X=w.config,de=w.interactionConfig,pe=w.controls,oe=w.controlBindings,fe=w.customCfg,ue=w.preferences,ke=w.queryConfig,Ve=Xu({sql:w.sql,python:w.python}),qe=Ve.sql,Be=Ve.python,ce=C==null?void 0:C.records,Fe=J(()=>({id:H,type:_,config:X,interactionConfig:de,preferences:ue,controls:pe,controlBindings:oe,sql:qe,python:Be}),[H,_,X,de,ue,pe,oe,qe,Be]),Oe=(se,Ee)=>{var $e,B;const Ce={...r,paginationConfig:{page:se+1,pageSize:Ee}};ie(Ce),Y(Ce),r.sql&&(B=($e=r.preferences)==null?void 0:$e.tablePrefs)!=null&&B.enableDevModePagination&&f(!0);},Re=se=>{var $e,B,me,We,Ye;const Ee=_r(se,($e=r.config)==null?void 0:$e.metricColumns,(B=r.config)==null?void 0:B.groupByColumns,(me=r.config)==null?void 0:me.detailColumns),Ce={...r,config:{...(r.config||{}),sortByColumns:Ee}};ie(Ce),Y(Ce),r.sql&&(Ye=(We=r.preferences)==null?void 0:We.tablePrefs)!=null&&Ye.enableDevModePagination&&f(!0);},st=Jr(Fe,ce||void 0),Je=vn(),Z=J(()=>{var se;return!H||!ce?null:Zr({chartTheme:Je,card:Fe,data:ce,cardType:_,queryConfig:ke,customCfg:fe,preferences:ue,comparisonMetadata:(se=C==null?void 0:C.metadata)==null?void 0:se.comparisonMetadata,numericPresentation:st,resultColumns:C==null?void 0:C.columns,columnKeyMap:C==null?void 0:C.columnKeyMap});},[Fe,H,fe,ue,ke,ce,Je,C==null?void 0:C.columns,C==null?void 0:C.columnKeyMap,(ge=C==null?void 0:C.metadata)==null?void 0:ge.comparisonMetadata,_,st]);function ve(se){return/* @__PURE__ */e(ha,{FallbackComponent:mn,children:/* @__PURE__ */e(Ys,{card:se})});}function Ae(){var se,Ee;if(w.type==="matrixTable")return/* @__PURE__ */e(Vi,{card:w,frame:c,mode:"editor"});if(C!=null&&C.records&&(C==null?void 0:C.records.length)===0&&!R&&!I)return m?/* @__PURE__ */e("div",{className:"flex h-full flex-col items-start justify-start overflow-auto",children:/* @__PURE__ */e(un,{error:m,errorSql:M||r.sql||r.python,onOpenInEditor:q,onSendFeedback:V,showFeedbackButton:!0})}):/* @__PURE__ */e(Bi,{});if((R||I)&&(!(C!=null&&C.records)||C.records.length===0))return _==="table"||_==="detailTable"?/* @__PURE__ */e("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:/* @__PURE__ */e(zi,{})}):/* @__PURE__ */e("div",{className:"z-50 flex h-full items-center justify-center",children:/* @__PURE__ */e(tt,{size:"md",color:"muted","aria-label":"Loading data"})});if(!w.id)return null;if(_==="custom")return ve(r);if(_==="customVisual")return/* @__PURE__ */e(Ki,{card:w,result:{records:(C==null?void 0:C.records)??[],columns:C==null?void 0:C.columns,columnKeyMap:C==null?void 0:C.columnKeyMap,totals:C==null?void 0:C.tableTotalsByColumnId,truncated:!!(g!=null&&g.hasNextPage),comparisonMetadata:(se=C==null?void 0:C.metadata)==null?void 0:se.comparisonMetadata},isLoading:R||I,printing:!1,showReason:!0,renderFallback:()=>{var Ce;return/* @__PURE__ */e(aa,{card:qi(w),data:ee,resultColumns:C==null?void 0:C.columns,columnKeyMap:C==null?void 0:C.columnKeyMap,comparisonMetadata:(Ce=C==null?void 0:C.metadata)==null?void 0:Ce.comparisonMetadata,paginationMetadata:g,onPaginationChange:Oe,onSortChange:Re,isLoading:R||I});}});if(!["table","matrixTable","detailTable","custom","customVisual"].includes(_)&&Z)return/* @__PURE__ */e("div",{className:"relative h-full min-h-0 w-full flex-1 grow basis-0",children:R||I?/* @__PURE__ */e(xe,{}):/* @__PURE__ */e($i,{cfg:Z})});if(_==="table"||_==="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(aa,{card:w,data:ee,resultColumns:C==null?void 0:C.columns,columnKeyMap:C==null?void 0:C.columnKeyMap,totalsByColumnId:C==null?void 0:C.tableTotalsByColumnId,columnTotals:C==null?void 0:C.tableColumnTotals,comparisonMetadata:(Ee=C==null?void 0:C.metadata)==null?void 0:Ee.comparisonMetadata,paginationMetadata:g,onPaginationChange:Oe,onSortChange:Re,isLoading:R||I})});}return/* @__PURE__ */n(Mi,{role:"editor-visual-card",className:Q("relative flex h-full flex-col rounded-none bg-card text-card-foreground",t),style:{...l.cardFrameStyle,...a},...s,children:[(R||I)&&!Oi({type:_})&&(C==null?void 0:C.records)&&C.records.length>0&&/* @__PURE__ */e("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-background/50",children:/* @__PURE__ */e(tt,{size:"md",color:"muted","aria-label":"Loading data"})}),d&&/* @__PURE__ */e(Ai,{className:Q("flex flex-row items-start justify-between gap-4 px-4 pb-3 pt-3"),style:l.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(Ri,{className:Q("min-w-0",wa),children:/* @__PURE__ */e(ta,{value:r.title,onSave:se=>ie({...r,title:se}),isEditable:!0,placeholder:"Add title",displayClassName:wa,inputClassName:wa})}),/* @__PURE__ */e(Rr,{card:r}),/* @__PURE__ */e(hs,{}),/* @__PURE__ */e("div",{className:"ml-auto",children:/* @__PURE__ */e(Hu,{})})]}),/* @__PURE__ */e("div",{className:"min-w-0",children:/* @__PURE__ */e(ta,{value:(r.description||"").trim(),onSave:se=>ie({...r,description:se.trim()}),isEditable:!0,placeholder:"Add description",displayClassName:"text-[12px] leading-snug text-muted-foreground",inputClassName:"text-[12px] leading-snug"})})]})}),/* @__PURE__ */n(Li,{card:r,sheetId:u||"",inlineFilterValues:x,setInlineFilterValue:N,removeInlineFilterValue:T,children:[S&&/* @__PURE__ */e("div",{className:"px-4 pb-2",style:l.cardGutterStyle,children:/* @__PURE__ */e(Pi,{card:r,sheetId:u||"",inlineFilterValues:x,setInlineFilterValue:N,removeInlineFilterValue:T,showSavedFilters:i})}),/* @__PURE__ */n(Di,{className:Q("flex min-h-0 grow flex-col",A?O?"px-4 pb-0 pt-2":Q("p-0",dn):O?"px-4 py-0":Q("px-4",_i)),style:A&&!O?void 0:l.cardGutterStyle,children:[/* @__PURE__ */e("div",{className:"min-h-0 flex-1 grow basis-0",children:Ae()}),Pr(w)&&/* @__PURE__ */e("div",{className:Q("pt-3",A&&"px-4"),children:/* @__PURE__ */e(Dr,{card:w,mode:"editor",records:C==null?void 0:C.records})})]})]}),/* @__PURE__ */e(In,{open:z,onOpenChange:L,feedbackData:W,showDebugInfo:!0})]});}function rr(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 l={...r};return Object.keys(l).forEach(o=>{o.startsWith("semaphor")&&delete l[o];}),{...l,data:[]};})}},null,2);}const Oa=({language:t,value:a,onChange:s,readonly:r})=>/* @__PURE__ */e(Ft,{className:"h-full w-full text-xs",language:t,value:a,onValueChange:s,readOnly:r,embedded:!0}),Ju=()=>/* @__PURE__ */n(Wt,{children:[/* @__PURE__ */e("div",{className:"flex items-center gap-2",children:/* @__PURE__ */e(_t,{children:"Customize Card"})}),/* @__PURE__ */n(dt,{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."})]})]}),Zu=({customCode:t,cardCustomCfgString:a,mergedConfig:s,onConfigChange:r,onCodeChange:l})=>/* @__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(ze,{value:"final-config",className:"px-0",children:"Config"}),/* @__PURE__ */e(ze,{value:"custom-config",className:"px-0",children:"Changes"}),/* @__PURE__ */e(ze,{value:"custom-code",className:"px-0",children:"Custom Code"})]}),/* @__PURE__ */e(Qe,{value:"final-config",className:"mt-2 grow rounded border",children:/* @__PURE__ */e(Oa,{language:"json",value:s,onChange:r})}),/* @__PURE__ */e(Qe,{value:"custom-config",className:"mt-2 grow rounded border",children:/* @__PURE__ */e(Oa,{readonly:!0,language:"json",value:a,onChange:()=>{}})}),/* @__PURE__ */e(Qe,{value:"custom-code",className:"mt-2 grow rounded border",children:/* @__PURE__ */e(Oa,{language:"javascript",value:t,onChange:l})})]}),em=({error:t,hasCardCustomConfig:a,onReset:s,onApply:r,onClose:l})=>/* @__PURE__ */n(Ht,{className:"flex items-center",children:[/* @__PURE__ */e(P,{className:"mr-2 text-red-500",children:t}),/* @__PURE__ */e(le,{disabled:!a,onClick:s,variant:"outline",children:"Reset"}),/* @__PURE__ */e(le,{onClick:r,variant:"outline",children:"Apply"}),/* @__PURE__ */e(le,{onClick:l,variant:"outline",children:"Close"})]});function tm({triggerVariant:t="icon",className:a,label:s="Customize Visual"}={}){const[r,l]=G(!1),[o,d]=G(""),[i,c]=G(""),[x,u]=G(""),[f,h]=G(""),p=E(A=>A.card),N=Ke(),T=E(A=>A.card.customCfg),S=T?JSON.stringify(T,null,2):"",b=J(()=>N!==p.type?{...p,type:N}:p,[p,N]),{data:y}=He(b),F=Jr(ma(p,y),y==null?void 0:y.records),v=vn(),{setCardCustomCfg:D,setCustomVisualCode:K}=he(),j=()=>{var $,C,R;if(!(($=y==null?void 0:y.records)!=null&&$.length))return;const A=Zr({chartTheme:v,card:p,data:y.records,cardType:p.type,queryConfig:p.queryConfig,preferences:p.preferences,comparisonMetadata:(C=y==null?void 0:y.metadata)==null?void 0:C.comparisonMetadata,numericPresentation:F,resultColumns:y==null?void 0:y.columns,columnKeyMap:y==null?void 0:y.columnKeyMap});if(A){d(rr(A)),u(((R=p.preferences)==null?void 0:R.customVisualCode)||"");const I=Tc(A,T);c(rr(I));}},_=()=>{try{if(x&&K(x),i){const A=JSON.parse(i),$=qd(JSON.parse(o),A);D($),h("");}}catch{h("Invalid JSON configuration");}},k=Object.keys(T||{}).length===0;return/* @__PURE__ */n(Pt,{open:r,onOpenChange:l,children:[/* @__PURE__ */e(Sc,{asChild:!0,children:t==="menu"?/* @__PURE__ */n(le,{variant:"ghost",onClick:j,className:Q("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(zn,{className:"h-3.5 w-3.5"}),/* @__PURE__ */e("span",{children:s})]}):/* @__PURE__ */e(_e,{tooltip:"Customize Visual",onClick:j,className:Q(k?"":"text-green-600 hover:text-green-700",a),children:/* @__PURE__ */e(zn,{className:"h-4 w-4"})})}),/* @__PURE__ */n(Dt,{className:"flex h-[600px] grow flex-col overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[/* @__PURE__ */e(Ju,{}),/* @__PURE__ */n("div",{className:"flex grow gap-2",children:[/* @__PURE__ */e(ha,{FallbackComponent:mn,children:/* @__PURE__ */e(Os,{className:"w-1/2 rounded shadow-none"})}),/* @__PURE__ */e(Zu,{customCode:x,cardCustomCfgString:S,mergedConfig:i,onConfigChange:A=>c(A??""),onCodeChange:A=>u(A??"")})]}),/* @__PURE__ */e(em,{error:f,hasCardCustomConfig:!!T,onReset:()=>{c(o),D(null);},onApply:_,onClose:()=>l(!1)})]})]});}function am(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 nm(t){const a=t.trim().split(/\s+/);return a.length>1?(a[0][0]+a[1][0]).toUpperCase():t.slice(0,2).toUpperCase();}function As({chartType:t,chartName:a,isCustom:s=!1,className:r="h-6 w-6"}){if(!s&&t)return Vr(t,r);const l=ji(a);if(l)return Xa.cloneElement(l,{className:r});const o=nm(a),d=am(a);return/* @__PURE__ */e("div",{className:Q("flex items-center justify-center rounded text-white font-semibold text-xs",r),style:{backgroundColor:d},children:o});}function sr({chartType:t,chartName:a,description:s,isCustom:r=!1,pluginName:l,isSelected:o=!1,isActive:d=!1,onSelect:i,onHover:c}){return/* @__PURE__ */n("button",{type:"button",onClick:i,onMouseMove:c,"aria-pressed":o,title:l?`${a} · ${l}`:a,className:Q("flex w-full min-w-0 gap-2 rounded-[4px] px-2 text-left text-[12px] transition-colors",s?"items-start py-1.5":"h-7 items-center",d&&"bg-muted"),children:[/* @__PURE__ */e(As,{chartType:t,chartName:a,isCustom:r,className:Q("h-3.5 w-3.5 shrink-0",s&&"mt-px",r?"text-[7px]":o?"text-foreground":"text-muted-foreground")}),/* @__PURE__ */n("span",{className:"min-w-0",children:[/* @__PURE__ */e("span",{className:Q("block truncate",o?"font-medium text-foreground":"text-foreground/80"),children:a}),s?/* @__PURE__ */e("span",{className:"block text-[11px] leading-snug text-muted-foreground",children:s}):null]}),o&&/* @__PURE__ */e(ua,{className:"ml-auto h-3 w-3 shrink-0"})]});}const lr=[{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"},{id:"custom-visual",label:"Custom"}],rm=[{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"},{id:"customVisual",name:"Custom visual",group:"custom-visual",description:"A chart this list doesn't have: describe it, or start from a template"}],Aa=2;function Rs(t){return rm.filter(a=>hl(a.id,t));}function sm({selectedChart:t,onChartSelect:a,onClose:s}){var M;const[r,l]=G(""),[o,d]=G(0),i=Ie(null),{data:c=[],isLoading:x}=kc(),u=En(),{setCardPreferences:f}=E(g=>g.actions),h=E(g=>g.card),p=E(g=>g.isDevMode),N=t??h.type,T=N==="custom"?(M=h.customCardPreferences)==null?void 0:M.componentName:void 0,{setCardCustomCfg:S,setQueryConfig:b,replaceFrameCards:y,clearModeDrafts:F,initializeModeDrafts:v}=he(),D=J(()=>{const g=Rs({isDevMode:p});if(!r)return g;const w=r.toLowerCase(),O=new Set(lr.filter(q=>q.label.toLowerCase().includes(w)).map(q=>q.id));return g.filter(q=>q.name.toLowerCase().includes(w)||O.has(q.group));},[p,r]),K=J(()=>{const g=c.filter(O=>O.componentType==="chart"&&O.pluginType!=="standard");if(!r)return g;const w=r.toLowerCase();return g.filter(O=>O.name.toLowerCase().includes(w));},[c,r]),j=g=>{u(g).status!=="refused"&&(a==null||a(g),s==null||s());},_=g=>{const w=Ed(g);if(w==="multiple"&&g.slots&&g.slots.length>0){S(null),f({}),b(void 0),F();const q=Id(g.slots,g,h);y(q),q[0]&&v(q[0]),s==null||s();return;}else if(u("custom",{customVisual:{type:"component",visualType:w,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=J(()=>{const g=lr.map(w=>({key:w.id,label:w.label,entries:D.filter(O=>O.group===w.id).map(O=>({kind:"default",id:O.id,name:O.name,...(O.description?{description:O.description}:{})}))})).filter(w=>w.entries.length>0);return K.length===0?g:[...g,{key:"custom",label:"Custom charts",entries:K.map(w=>({kind:"custom",visual:w}))}];},[D,K]),A=J(()=>k.flatMap(g=>g.entries),[k]),$=Math.min(o,Math.max(A.length-1,0)),C=g=>{g.kind==="default"?j(g.id):_(g.visual);},R=g=>{var O,q;const w=Math.max(0,Math.min(g,A.length-1));d(w),(q=(O=i.current)==null?void 0:O.querySelector(`[data-index="${w}"]`))==null||q.scrollIntoView({block:"nearest"});},I=g=>{if(A.length===0)return;const w=g.key==="ArrowDown"?Aa:g.key==="ArrowUp"?-Aa:g.key==="ArrowRight"?1:g.key==="ArrowLeft"?-1:0;if(w!==0&&(Math.abs(w)===Aa||!r))g.preventDefault(),R($+w);else if(g.key==="Enter"){g.preventDefault();const O=A[$];O&&C(O);}};let m=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(Ec,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */e("input",{type:"text",placeholder:"Search charts",value:r,onChange:g=>{l(g.target.value),d(0);},onKeyDown:I,"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:i,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(w=>{const O=m++,q=O===$;if(w.kind==="default")return/* @__PURE__ */e("div",{"data-index":O,className:w.description?"col-span-2":void 0,children:/* @__PURE__ */e(sr,{chartType:w.id,chartName:w.name,description:w.description,isSelected:N===w.id,isActive:q,onSelect:()=>C(w),onHover:()=>d(O)})},w.id);const{visual:z}=w;return/* @__PURE__ */e("div",{"data-index":O,children:/* @__PURE__ */e(sr,{chartName:z.name,isCustom:!0,pluginName:z.pluginName,isSelected:T===z.name,isActive:q,onSelect:()=>C(w),onHover:()=>d(O)})},`${z.url}-${z.name}`);})})]},g.key)),x&&/* @__PURE__ */e("div",{className:"py-3 text-center text-[11px] text-muted-foreground",children:"Loading custom charts…"}),A.length===0&&!x&&/* @__PURE__ */e("div",{className:"py-8 text-center text-[11px] text-muted-foreground",children:"No charts found"})]})]});}const Ra={table:es,matrixTable:na,bar:pn,line:hn,stackedBar:no,stackedLine:ao,scatter:Kr,bubble:to,pie:eo,doughnut:Zi,kpi:Ji,treemap:zr,bullet:Br,funnel:Xi,tornado:Yi,heatmap:na,range:Wi,radar:Gi,polarArea:Qi,text:Ui,customVisual:Hi},La={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",customVisual:"Custom visual"},lm=[{id:"table"},{id:"bar"},{id:"line"},{id:"pie"},{id:"kpi"},{id:"matrixTable"}],im=6;function om({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(an,{selectedChart:t,onChartChange:a,compactMore:!0})]});}function an({selectedChart:t,onChartChange:a,compactMore:s=!1,responsiveCompact:r=!1}){const[l,o]=G(!1),d=E(p=>p.isDevMode),i=E(p=>{var N,T;return((T=(N=p.card)==null?void 0:N.customCardPreferences)==null?void 0:T.componentName)??null;}),c=J(()=>{const p=new Set(Rs({isDevMode:d}).map(T=>T.id)),N=lm.filter(T=>p.has(T.id)).map(T=>({id:T.id,label:La[T.id]??T.id,icon:Ra[T.id],isCustom:!1}));return t==="custom"&&i?N.unshift({id:i,label:i,isCustom:!0}):!N.some(T=>T.id===t)&&Ra[t]&&p.has(t)&&N.unshift({id:t,label:La[t]??t,icon:Ra[t],isCustom:!1}),N.slice(0,im);},[t,i,d]),x=p=>p.isCustom?t==="custom"&&i===p.id:t===p.id,u=p=>{p.isCustom||a(p.id);},f=c.some(x),h=f?"More":t==="custom"?i||"Custom":La[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:[c.map(p=>{const N=p.icon,T=x(p);return/* @__PURE__ */n(mt,{children:[/* @__PURE__ */e(ht,{asChild:!0,children:/* @__PURE__ */n("button",{type:"button",onClick:()=>u(p),"aria-label":p.label,"aria-pressed":!!T,className:Q("flex h-full w-7 items-center justify-center text-foreground/65 transition-colors hover:bg-muted/50 hover:text-foreground",r&&!T&&"hidden @[800px]:flex",T&&"bg-foreground/[0.08] font-medium text-foreground"),children:[N?/* @__PURE__ */e(N,{className:"h-3.5 w-3.5"}):/* @__PURE__ */e(As,{chartName:p.label,isCustom:!0,className:"h-3.5 w-3.5"}),/* @__PURE__ */e("span",{className:"sr-only",children:p.label})]})}),/* @__PURE__ */e(pt,{side:"bottom",children:p.label})]},`${p.isCustom?"custom":"default"}-${p.id}`);}),/* @__PURE__ */n(lt,{open:l,onOpenChange:o,children:[/* @__PURE__ */e(xt,{asChild:!0,children:/* @__PURE__ */n("button",{type:"button","aria-label":s?"More chart types":h,className:Q("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&&(f?"text-muted-foreground":"text-foreground")),children:[!s&&/* @__PURE__ */e("span",{className:"truncate",children:h}),/* @__PURE__ */e(Mt,{className:Q("h-3 w-3 shrink-0 text-muted-foreground transition-transform",l&&"rotate-180"),strokeWidth:1.75})]})}),/* @__PURE__ */e(it,{className:"w-[360px] overflow-hidden p-0",align:"end",onOpenAutoFocus:p=>p.preventDefault(),children:/* @__PURE__ */e(sm,{selectedChart:t,onChartSelect:p=>{a(p),o(!1);},onClose:()=>o(!1)})})]})]})});}function cm(){const t=E(c=>{var x,u;return(u=(x=c.card.preferences)==null?void 0:x.chartOptions)==null?void 0:u.indexAxis;}),a=E(c=>c.card.type),{setChartOrientation:s,setCardPreferences:r}=E(c=>c.actions),l=c=>{if(s(c),a!=="bullet")return;const x=c==="y"?"horizontal":"vertical",u=E.getState().card.preferences,f={...(u||{}),bulletConfig:{...((u==null?void 0:u.bulletConfig)||{}),orientation:x}};r(f);};function o(){const c=t??"x";return/* @__PURE__ */e(_e,{onClick:()=>{l(c==="x"?"y":"x");},tooltip:"Chart Orientation",className:"h-7 w-7 px-0",children:c==="x"?/* @__PURE__ */e(Ia,{className:"h-3.5 w-3.5"}):/* @__PURE__ */e(Ea,{className:"h-3.5 w-3.5"})});}function d(){return/* @__PURE__ */e(_e,{onClick:()=>{l(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(Ia,{className:"h-3.5 w-3.5"}):/* @__PURE__ */e(Ea,{className:"h-3.5 w-3.5"})});}function i(){const c=t??"y";return/* @__PURE__ */e(_e,{onClick:()=>{l(c==="y"?"x":"y");},tooltip:"Chart Orientation",className:"h-7 w-7 px-0",children:c==="y"?/* @__PURE__ */e(Ea,{className:"h-3.5 w-3.5"}):/* @__PURE__ */e(Ia,{className:"h-3.5 w-3.5"})});}return/* @__PURE__ */e(xe,{children:a==="funnel"?d():a==="bullet"?i():o()});}function Mn({className:t,triggerVariant:a="icon",label:s="Display options"}){var S,b,y,F,v,D,K,j,_,k;const r=E(A=>A.card),{setCardPreferences:l,updateCardInFrame:o,setCard:d}=he(),[i,c]=G(!1),x=((b=(S=r.preferences)==null?void 0:S.displayOptions)==null?void 0:b.showFilterInfo)??!0,u=((F=(y=r.preferences)==null?void 0:y.displayOptions)==null?void 0:F.showCardToolbar)??!0,f=((D=(v=r.preferences)==null?void 0:v.displayOptions)==null?void 0:D.showChrome)??!0,h=((j=(K=r.preferences)==null?void 0:K.displayOptions)==null?void 0:j.allowScroll)??!0,p=((k=(_=r.preferences)==null?void 0:_.displayOptions)==null?void 0:k.showInlineFilterBar)??!0,N=(A,$)=>{var I;const C={...r.preferences,displayOptions:{...((I=r.preferences)==null?void 0:I.displayOptions),[A]:$}};l(C);const R={...r,preferences:C};d(R),o(R);},T=[{option:"showFilterInfo",label:"Filter info",hint:"Badge",checked:x},{option:"showCardToolbar",label:"Card tools",hint:"Expand, hover actions",checked:u},{option:"showChrome",label:"Card chrome",hint:"Frame and padding",checked:f},{option:"allowScroll",label:"Allow scroll",hint:"Content scroll",checked:h},{option:"showInlineFilterBar",label:"Inline filter bar",hint:"On-card filters",checked:p}];return/* @__PURE__ */e("div",{className:Q("flex items-center",t),children:/* @__PURE__ */n(pa,{modal:!1,open:i,onOpenChange:c,children:[/* @__PURE__ */e(fa,{asChild:!0,children:a==="menu"?/* @__PURE__ */n(le,{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(Ga,{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(ra,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(ga,{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"}),T.map(A=>/* @__PURE__ */n(Ic,{checked:A.checked,onCheckedChange:$=>N(A.option,$),onSelect:$=>$.preventDefault(),className:"[&_svg]:h-3.5 [&_svg]:w-3.5",children:[/* @__PURE__ */e("span",{className:"min-w-0 flex-1 truncate",children:A.label}),/* @__PURE__ */e("span",{className:"ml-3 shrink-0 text-[11px] text-muted-foreground",children:A.hint})]},A.option))]})]})});}function On({className:t,triggerVariant:a="icon",label:s="Pinned filters"}){const[r,l]=G(!1),o=E(k=>k.card),d=E(k=>k.selectedConnectionId),{tokenProps:i}=Gt(),{setCard:c}=he(),x=be(k=>k.actions.removeCardInlineFilterValue),u=be(k=>k.actions.setCardInlineFilterValue),f=E(k=>k.actions.removeCardInlineFilterValue),h=E(k=>k.actions.setCardInlineFilterValue),p=Fc(),N=(o==null?void 0:o.inlineFilters)||[],T=Xa.useMemo(()=>o?[o]:[],[o]),{inlineCalculatedFields:S}=qr(),b=Xa.useMemo(()=>({fields:S.filter(k=>k.fieldScope==="card"),domainId:pl(o==null?void 0:o.dataSource)}),[S,o==null?void 0:o.dataSource]),y=Nn()??void 0,F=ro(Kn(io,{activationConstraint:{distance:5}}),Kn(lo,{coordinateGetter:so}));function v({active:k,over:A}){if(!A||k.id===A.id)return;const $=N.findIndex(R=>R.id===A.id);if($===-1)return;const C=Wd(N,String(k.id),$);C!==N&&c({...o,inlineFilters:[...C]});}function D(k){if(N.find(C=>fl(C,k)))return;const $=Gd({id:$a(),field:k,...gl(o??{},d)});c({...o,inlineFilters:[...N,$]});}function K(k){const A=N.filter($=>$.id!==k);c({...o,inlineFilters:A}),p?f(o.id,k):x(o.id,k);}function j(k,A){const $=N.find(m=>m.id===k),C=N.map(m=>m.id===k?{...m,...A}:m);c({...o,inlineFilters:C});const R=C.find(m=>m.id===k);if(!R||!xl($,R))return;const I=bl(R,y);I?p?h(o.id,I):u(o.id,I):p?f(o.id,k):x(o.id,k);}if(!Qd(o==null?void 0:o.type))return null;const _=a==="menu";return/* @__PURE__ */e("div",{className:Q("flex items-center gap-1",_&&"w-full",t),children:/* @__PURE__ */n(lt,{open:r,onOpenChange:l,children:[/* @__PURE__ */e(xt,{asChild:!0,children:_?/* @__PURE__ */n(le,{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(Qn,{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:Q("relative h-7 w-7 px-0",{"text-primary":N.length>0}),children:[/* @__PURE__ */e(Qn,{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(it,{align:"end",className:Q("w-80 p-0",_&&"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(oo,{cards:T,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(co,{sensors:F,collisionDetection:uo,onDragEnd:v,children:/* @__PURE__ */e(mo,{items:N.map(k=>k.id),strategy:ho,children:/* @__PURE__ */e("div",{className:"space-y-1",children:N.map(k=>/* @__PURE__ */e(dm,{filter:k,onUpdate:A=>j(k.id,A),onRemove:()=>K(k.id)},k.id))})})})]})]})})]})});}function dm({filter:t,onUpdate:a,onRemove:s}){const{attributes:r,listeners:l,setNodeRef:o,transform:d,transition:i,isDragging:c}=po({id:t.id});return/* @__PURE__ */n("div",{ref:o,style:{transform:fo.Transform.toString(d),transition:i},className:Q("flex items-center justify-between gap-1 rounded-md bg-muted px-1 py-1.5 text-sm",c&&"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,...l,children:/* @__PURE__ */e(ts,{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(Mc,{filter:t,variant:"inline",onAccept:x=>a(x),trigger:/* @__PURE__ */e(le,{variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0",title:"Configure filter",children:/* @__PURE__ */e(xa,{className:"h-3 w-3"})})}),/* @__PURE__ */e(le,{variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0 hover:bg-destructive/10 hover:text-destructive",onClick:s,children:/* @__PURE__ */e(ca,{className:"h-3 w-3"})})]})]});}const um={metric_selector:"Displayed metric",field_selector:"Group by field",aggregation_selector:"Aggregation",grain_selector:"Time grain"};function mm(t,a){return t&&typeof t=="object"&&"label"in t&&typeof t.label=="string"&&t.label.trim().length>0?t.label:a||null;}const hm={metric_selector:"config_metric_selector",field_selector:"config_field_selector",aggregation_selector:"config_aggregation",grain_selector:"config_grain"};function sa(t,a){return`${t}:${a}`;}function pm(t,a,s,r,l){const o=new Set(s.filter(i=>i.target!=="sql_param"&&i.target!=="presentation_currency").map(i=>sa(i.controlId,i.target))),d=a.map(i=>{const c=Sr({card:t,control:i,matrixSpec:r,resolveDataType:l}).map(h=>h.value),x=hm[i.type],f=[...(x&&c.includes(x)?[x]:[]),...c.filter(h=>h!==x)].find(h=>!o.has(sa(i.id,h)));return f?{controlId:i.id,target:f}:null;}).find(Boolean);return d?{controlId:d.controlId,target:d.target,mapping:{}}:null;}function fm({card:t,dashboardControls:a,bindings:s,onChange:r,availableFieldChoices:l,matrixFieldCatalog:o=[],availableMetricChoices:d,suppressTransientStaleState:i=!1,matrixSpec:c,matrixPresentation:x}){const u=J(()=>x??(c?Nd(c).presentation:void 0),[c,x]);function f(k){return!c||!u?[]:Nl(c,k,S).map(A=>({id:A.id,label:A.kind==="measure"?`${Cd(A.measure,u)} (${A.measure.aggregate})`:`${A.axis==="rows"?"Rows":"Columns"}: ${wd(A.level,u)}`}));}const h=[...a,...(t.controls||[])],[p,N]=G({}),T=Jd({sql:t.sql,controlBindings:t.controlBindings});function S(k){return c?Cl(k,c.source,o):k.dataType;}const b=yl(t,c,S),y=new Set(s.map(k=>sa(k.controlId,k.target))),F=h.some(k=>Sr({card:t,control:k,matrixSpec:c,resolveDataType:S}).some(A=>!y.has(sa(k.id,A.value)))),v=i?0:s.reduce((k,A)=>{const $=D(A.target),C=Object.values(A.mapping).filter(R=>{const I=A.target==="config_metric_selector"||A.target==="config_field_selector"?typeof R=="string"?R:R==null?void 0:R.id:typeof R=="string"?R:void 0;return typeof I=="string"&&!$.some(m=>m.value===I);}).length;return k+C;},0);function D(k){var A,$,C,R;switch(k){case"config_metric_selector":return d?d.filter(I=>!!I.target).map(I=>({value:I.target.id,label:I.target.label||I.option.label,target:I.target})):c&&u?f(k).map(I=>({value:I.id,label:I.label,target:{kind:"matrix_instance",id:I.id}})):(($=(A=t.config)==null?void 0:A.metricColumns)==null?void 0:$.map(I=>({value:I.id,label:I.label||I.id,target:I})))||[];case"config_field_selector":return l?l.filter(I=>!!I.target).map(I=>({value:I.target.id,label:I.target.label||I.option.label,target:I.target})):c&&u?f(k).map(I=>({value:I.id,label:I.label,target:{kind:"matrix_instance",id:I.id}})):((R=(C=t.config)==null?void 0:C.groupByColumns)==null?void 0:R.map(I=>({value:I.id,label:I.label||I.id,target:I})))||[];case"config_aggregation":return(b.config_aggregation||[]).map(I=>({value:I,label:I}));case"config_grain":return(b.config_grain||[]).map(I=>({value:I,label:I.charAt(0).toUpperCase()+I.slice(1)}));default:return[];}}const K=(k,A)=>{r(s.map(($,C)=>C!==k?$:A($)));},j=k=>{r(s.filter((A,$)=>$!==k));},_=()=>{const k=pm(t,h,s,c,S);k&&r([...s,k]);};if(typeof t.sql=="string"&&t.sql.trim().length>0){const k=T.map(({controlId:A,paramId:$})=>{const C=h.find(R=>R.id===A);return C?{id:A,paramId:$,label:C.label,reference:`[[param.${$}]]`}:{id:A,paramId:$,label:A,reference:`[[param.${$}]]`};});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(A=>/* @__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:A.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:A.reference}),/* @__PURE__ */e(Xr,{text:A.reference,ariaLabel:`Copy ${A.reference}`})]})]})},`${A.id}:${A.paramId}`))});}return/* @__PURE__ */n("div",{className:"space-y-4",children:[v>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(Qa,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),/* @__PURE__ */n("span",{children:[v," ",v===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,A)=>{const $=b[k.target]||[],C=h.find(V=>V.id===k.controlId),R=C?vl(C):null,I=(R==null?void 0:R.source.kind)==="manual"?R.source.options:[],m=D(k.target),M=f(k.target),g=k.matrixTargetId!==void 0&&!M.some(V=>V.id===k.matrixTargetId),w=Array.from(/* @__PURE__ */new Set([...I.map(V=>V.value),...Object.keys(k.mapping)])).map(V=>{const W=I.find(ee=>ee.value===V);return{value:V,label:(W==null?void 0:W.label)||V};}),O=`${k.controlId}-${k.target}-${A}`,q=p[O]??A===0,z=Object.keys(k.mapping).length,L=C!=null&&C.type?um[C.type]||C.type:null;return/* @__PURE__ */n(Ot,{open:q,onOpenChange:V=>N(W=>({...W,[O]:V})),className:"rounded-md border",children:[/* @__PURE__ */n("div",{className:"flex items-start justify-between gap-2 p-3",children:[/* @__PURE__ */e(At,{asChild:!0,children:/* @__PURE__ */n("button",{type:"button",className:"flex min-w-0 flex-1 items-start gap-2 text-left",children:[q?/* @__PURE__ */e(Mt,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}):/* @__PURE__ */e(yt,{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:(C==null?void 0:C.label)||"Control"}),L?/* @__PURE__ */e(as,{variant:"secondary",className:"shrink-0 text-[11px] font-normal text-muted-foreground",children:L}):null]}),/* @__PURE__ */e("div",{className:"text-xs text-muted-foreground",children:z>0?`${z} mapped`:"No mappings yet"})]})]})}),/* @__PURE__ */e(le,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>j(A),children:/* @__PURE__ */e(ns,{className:"h-4 w-4"})})]}),/* @__PURE__ */n(Rt,{className:"space-y-3 border-t px-3 pb-3 pt-2",children:[c?/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(P,{className:"text-xs",htmlFor:`matrix-target-${O}`,children:"Matrix target"}),/* @__PURE__ */n(te,{value:k.matrixTargetId??"__none__",onValueChange:V=>K(A,W=>{const{matrixTargetId:ee,...ie}=W;return V==="__none__"?ie:{...ie,matrixTargetId:V};}),children:[/* @__PURE__ */e(ae,{id:`matrix-target-${O}`,"aria-label":"Matrix target",children:/* @__PURE__ */e(ne,{placeholder:"Choose target"})}),/* @__PURE__ */n(re,{children:[/* @__PURE__ */e(U,{value:"__none__",children:M.length===1?`Automatic: ${M[0].label}`:"Choose target"}),g?/* @__PURE__ */e(U,{value:k.matrixTargetId,disabled:!0,children:"Missing target"}):null,M.map(V=>/* @__PURE__ */e(U,{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."}):M.length===0?/* @__PURE__ */e("p",{role:"alert",className:"text-xs text-muted-foreground",children:"No eligible Matrix target."}):!k.matrixTargetId&&M.length>1?/* @__PURE__ */e("p",{role:"alert",className:"text-xs text-amber-700",children:"Select a Matrix target."}):null]}):null,w.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."}):m.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(P,{className:"text-xs",children:"Map each choice"}),/* @__PURE__ */e("div",{className:"space-y-2",children:w.map(V=>{const W=k.mapping[V.value],ee=k.target==="config_metric_selector"||k.target==="config_field_selector"?typeof W=="string"?W:W==null?void 0:W.id:typeof W=="string"?W:void 0,ie=!i&&typeof ee=="string"&&!m.some(X=>X.value===ee),Y=mm(W,ee),H=ee&&ie?[...m,{value:ee,label:"Needs remap",target:W}]:m;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(P,{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(P,{className:"text-[11px] text-muted-foreground",children:"Switch to"}),/* @__PURE__ */n(te,{value:ee||"__none__",onValueChange:X=>K(A,de=>{if(de.target==="config_metric_selector"){const oe={...de.mapping};if(X==="__none__")delete oe[V.value];else{const fe=H.find(ue=>ue.value===X);fe!=null&&fe.target?oe[V.value]=fe.target:delete oe[V.value];}return{...de,mapping:oe};}if(de.target==="config_field_selector"){const oe={...de.mapping};if(X==="__none__")delete oe[V.value];else{const fe=H.find(ue=>ue.value===X);fe!=null&&fe.target?oe[V.value]=fe.target:delete oe[V.value];}return{...de,mapping:oe};}const pe={...de.mapping};return X==="__none__"?delete pe[V.value]:pe[V.value]=X,{...de,mapping:pe};}),children:[/* @__PURE__ */e(ae,{children:/* @__PURE__ */e(ne,{placeholder:"Choose what this should use"})}),/* @__PURE__ */n(re,{children:[/* @__PURE__ */e(U,{value:"__none__",children:"Not mapped"}),H.map(X=>/* @__PURE__ */e(U,{value:X.value,children:X.label},X.value))]})]}),ie?/* @__PURE__ */n("div",{className:"flex items-center gap-1.5 text-[11px] text-amber-700",children:[/* @__PURE__ */e(Qa,{className:"h-3 w-3 shrink-0"}),/* @__PURE__ */n("span",{children:["Needs remap",Y?` · Previously: ${Y}`:""]})]}):null]})]},`${k.controlId}-${k.target}-${V.value}`);})}),$.length>0&&/* @__PURE__ */n("p",{className:"text-[11px] text-muted-foreground",children:["Available choices for this card: ",$.join(", ")]})]})]})]},O);}),F?/* @__PURE__ */n(le,{type:"button",variant:"outline",size:"sm",onClick:_,children:[/* @__PURE__ */e(ba,{className:"mr-2 h-4 w-4"}),"Add another control response"]}):null]});}function gm(t,a,s){const{eligibleTargets:r}=ps(t,a,s),l=tu(t),o=new Map(l.map(i=>[i.id,i])),d=new Map(au(t,s).map(i=>[i.measureId,i.label]));return r.map(i=>{var c;return{key:fs(i),label:i.kind==="metric"?((c=o.get(i.metricId))==null?void 0:c.label)||i.metricId:i.kind==="column"?i.columnKey:d.get(i.measureId)||i.measureId,target:i};});}function xm(t){return t?t.kind==="metric"?t.metricId:t.kind==="column"?t.columnKey:t.measureId:"invalid target";}function bm({matrixCatalog:t,card:a,dashboardControls:s,resultColumnKeys:r=[],bindings:l,onChange:o}){const d=[...s,...(a.controls||[])],i=d.filter(Zd),c=J(()=>gm(a,r,t),[a,r,t]),x=J(()=>ps(a,r,t),[a,r,t]),u=eu({bindings:l,controls:d,...x}),{preferences:f,resolveBoundCurrency:h}=Oc(a,r,t),[p,N]=G(""),[T,S]=G(""),b=c.find(v=>v.key===T),y=!!(p&&b)&&!l.some(v=>v.presentationTarget&&b&&fs(v.presentationTarget)===b.key),F=v=>{if(!f)return;const D=nu({card:a,target:v,resultColumnKeys:r,valueFormatPreferences:f,boundCurrency:h(v),matrixCatalog:t});if(D)return Sd(1e3,D);};return i.length===0&&l.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."})]}),l.map((v,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:[v.controlId," →"," ",xm(v.presentationTarget),v.presentationTarget?` · ${F(v.presentationTarget)??"unavailable"}`:null]}),/* @__PURE__ */e(le,{variant:"ghost",size:"xs",onClick:()=>o(l.filter((K,j)=>j!==D)),children:/* @__PURE__ */e(ns,{className:"h-3.5 w-3.5"})})]},`${v.controlId}:${JSON.stringify(v.presentationTarget)}`)),u.length>0?/* @__PURE__ */e("div",{className:"space-y-1 text-xs text-destructive",children:u.map((v,D)=>/* @__PURE__ */n("p",{children:[v.controlId?`${v.controlId}: `:"",v.code.split("_").join(" ")]},`${v.controlId||"binding"}:${v.code}:${D}`))}):null,/* @__PURE__ */n("div",{className:"grid grid-cols-[1fr_1fr_auto] gap-2",children:[/* @__PURE__ */n(te,{value:p,onValueChange:N,children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{placeholder:"Currency control"})}),/* @__PURE__ */e(re,{children:i.map(v=>/* @__PURE__ */e(U,{value:v.id,children:v.label},v.id))})]}),/* @__PURE__ */n(te,{value:T,onValueChange:S,children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{placeholder:"Target"})}),/* @__PURE__ */e(re,{children:c.map(v=>/* @__PURE__ */e(U,{value:v.key,children:v.label},v.key))})]}),/* @__PURE__ */e(le,{variant:"outline",size:"xs",disabled:!y,onClick:()=>{b&&(o([...l,{controlId:p,target:"presentation_currency",presentationTarget:b.target}]),S(""));},children:/* @__PURE__ */e(ba,{className:"h-3.5 w-3.5"})})]})]});}const ym=[];function An({className:t,triggerVariant:a="icon",label:s="Controls"}){var O,q,z;const{handleOpenChange:r,preventPassiveDismissDuringCreate:l,resolvedOpen:o,setIsCreateFlowActive:d}=Ld({}),i=E(L=>L.card),c=E(L=>L.frame),x=E(L=>L.queryResultColumns),u=be(L=>L.dashboard),h=be(L=>L.dashboard.controls)||ym,{setCard:p,updateCardInFrame:N}=he(),[T,S]=G(null);ye(()=>{o&&!T&&i!=null&&i.id&&S(i.id);},[i==null?void 0:i.id,o,T]),ye(()=>{!o&&T!==null&&S(null);},[o,T]);const b=J(()=>T?(c==null?void 0:c.cards.find(L=>L.id===T))||((i==null?void 0:i.id)===T?i:void 0):i,[i,c==null?void 0:c.cards,T]),y=(b==null?void 0:b.type)==="matrixTable"?(O=b.config)==null?void 0:O.matrix:void 0,F=J(()=>o&&y?$d(y.spec,b==null?void 0:b.controlBindings):[],[o,y,b==null?void 0:b.controlBindings]),v=go(F),D=J(()=>v.catalog.map(L=>({...L.field,dataType:hi(L.resolvedField.dataType)})),[v.catalog]),K=(b==null?void 0:b.controls)||[],j=b?wl(u,{excludeCardId:b.id}):h.map(L=>L.id),_=((b==null?void 0:b.controlBindings)||[]).filter(Sl),k=((b==null?void 0:b.controlBindings)||[]).filter(Ca),A=xo({card:b,controls:K}),$={choices:Tl(b),targetMap:Object.fromEntries((((q=b==null?void 0:b.config)==null?void 0:q.groupByColumns)||[]).map(L=>[L.id,L]))},C={choices:kl(b),targetMap:Object.fromEntries((((z=b==null?void 0:b.config)==null?void 0:z.metricColumns)||[]).map(L=>[L.id,L]))},R=$.choices.map(L=>({option:L,target:$.targetMap[L.value]})),I=C.choices.map(L=>({option:L,target:C.targetMap[L.value]})),m=(L,V)=>{if(!b)return;const W=(V==null?void 0:V.type)==="rename"?Gn(b,{type:"rename",oldId:V.oldId,newId:V.newId}):(V==null?void 0:V.type)==="remove"?Gn(b,{type:"remove",controlId:V.controlId}):b,ee={...W,controls:L,controlBindings:El(W.controlBindings,L)};N(ee),(i==null?void 0:i.id)===ee.id&&p(ee);},M=L=>{if(!b)return;const V={...b,controlBindings:[...Il(L,(b.controlBindings||[]).filter(W=>!Ca(W))),...k]};N(V),(i==null?void 0:i.id)===V.id&&p(V);},g=L=>{if(!b)return;const V={...b,controlBindings:[...(b.controlBindings||[]).filter(W=>!Ca(W)),...L]};N(V),(i==null?void 0:i.id)===V.id&&p(V);},w=a==="menu";return/* @__PURE__ */e("div",{className:Q("flex items-center gap-1",w&&"w-full",t),children:/* @__PURE__ */n(lt,{modal:!0,open:o,onOpenChange:r,children:[/* @__PURE__ */e(xt,{asChild:!0,children:w?/* @__PURE__ */n(le,{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(ra,{className:"h-3.5 w-3.5 text-muted-foreground"}),/* @__PURE__ */e("span",{children:s}),K.length+_.length>0&&/* @__PURE__ */e("span",{className:"ml-auto text-[11px] tabular-nums text-muted-foreground",children:K.length+_.length})]}):/* @__PURE__ */n(_e,{tooltip:"Configure Controls",className:Q("relative h-7 w-7 px-0",{"text-primary":K.length>0||_.length>0}),children:[/* @__PURE__ */e(ra,{className:"h-3.5 w-3.5"}),K.length+_.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:K.length+_.length})]})}),/* @__PURE__ */n(it,{className:Q("flex max-h-[85vh] w-[560px] max-w-[95vw] flex-col",w&&"z-[60]"),align:"end",onEscapeKeyDown:l,onPointerDownOutside:l,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(Pd,{scope:"card",card:b,controls:K,reservedControlIds:j,usageByControlId:A,availableFieldChoices:R,availableMetricChoices:I,onCreateFlowActiveChange:d,onChange:(L,V,W)=>m(L,W),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(xe,{children:[/* @__PURE__ */e(fm,{card:b,dashboardControls:h,bindings:_,onChange:M,availableFieldChoices:y?void 0:R,availableMetricChoices:y?void 0:I,matrixSpec:y==null?void 0:y.spec,matrixPresentation:y==null?void 0:y.presentation,matrixFieldCatalog:D,suppressTransientStaleState:!!(y&&v.pending)}),/* @__PURE__ */e("div",{className:"border-t pt-4",children:/* @__PURE__ */e(bm,{matrixCatalog:v.catalog,card:b,dashboardControls:h,resultColumnKeys:x,bindings:k,onChange:g})})]}):null]})})]})]})});}function Ls({showOrientation:t=!0,showGridStyle:a=!0,showInlineFilters:s=!0,showControls:r=!0,showDisplayOptions:l=!0}={}){const o=E(p=>p.card),d=E(p=>{var N,T;return(T=(N=p.card)==null?void 0:N.preferences)==null?void 0:T.chartOptions;}),i=Ac(d),{setChartGrid:c}=he();function x(){const p=["xy","none","x","y"],T=(p.indexOf(i)+1)%p.length;c(p[T]);}const u=t&&["line","bar","range","stackedBar","stackedLine","horizontalBar","funnel","bullet"].includes(o.type),f=a&&!["pie","doughnut","funnel","radar","polarArea","table","detailTable","custom","kpi","text"].includes(o.type);return u||f||s||r||l?/* @__PURE__ */n("div",{"data-info":"visual-settings",className:"flex items-center gap-2",children:[u&&/* @__PURE__ */e(xe,{children:/* @__PURE__ */e(cm,{})}),f&&/* @__PURE__ */n(_e,{tooltip:"Grid Style",onClick:x,className:"h-7 w-7 px-0",children:[(i==="xy"||!i)&&/* @__PURE__ */e(na,{className:"h-3.5 w-3.5"}),i==="x"&&/* @__PURE__ */e(rs,{className:"h-3.5 w-3.5"}),i==="y"&&/* @__PURE__ */e(ss,{className:"h-3.5 w-3.5"}),i==="none"&&/* @__PURE__ */e(Or,{className:"h-3.5 w-3.5"})]}),s&&/* @__PURE__ */e(On,{}),r&&/* @__PURE__ */e(An,{}),l&&/* @__PURE__ */e(Mn,{})]}):null;}function vm({errorMessage:t,errorSql:a,onOpenInEditor:s}){const{feedbackDialogOpen:r,setFeedbackDialogOpen:l,handleSendFeedback:o,feedbackPayload:d}=Ms(t,a);return/* @__PURE__ */n(xe,{children:[/* @__PURE__ */e("div",{className:"flex h-full min-h-0 flex-col overflow-auto px-4 py-0",children:/* @__PURE__ */e(un,{error:t,errorSql:a,errorMessageClassName:"max-h-40",fillAvailableSqlHeight:!0,className:"max-h-none",onOpenInEditor:s,onSendFeedback:o,showFeedbackButton:!0})}),/* @__PURE__ */e(In,{open:r,onOpenChange:l,feedbackData:d,showDebugInfo:!0})]});}function Nm({isPreviewMode:t,onPreviewToggle:a,configCard:s}){var M,g,w,O,q;const r=E(z=>z.frame),l=E(z=>z.card),o=E(z=>z.editorContext),d=(o==null?void 0:o.type)==="documentSection",i=be(z=>{var L,V;return Ml((V=(L=z.dashboard)==null?void 0:L.sheets)==null?void 0:V.find(W=>{var ee;return(ee=W.frames)==null?void 0:ee.some(ie=>ie.id===r.id);}));}),{setFrame:c,setActiveTabCardId:x,setCard:u,updateCardInFrame:f,closeCardTab:h}=he(),{manifest:p}=bt(((M=s==null?void 0:s.customCardPreferences)==null?void 0:M.url)||""),N=(g=p==null?void 0:p.visuals)==null?void 0:g.find(z=>{var L;return z.name===((L=s==null?void 0:s.customCardPreferences)==null?void 0:L.componentName);}),S=Nt(s,N)==="multiple",b=(N==null?void 0:N.minInputs)??((w=s==null?void 0:s.customCardPreferences)==null?void 0:w.minInputs)??1,y=(N==null?void 0:N.maxInputs)??((O=s==null?void 0:s.customCardPreferences)==null?void 0:O.maxInputs),F=J(()=>Xt({frame:r,configCard:s,isMultiInputVisual:S}),[r,s,S]),v=S?F.filter(Boolean).length:r.cards.length,D=d?!1:y?v<y:!0,K=v>Math.max(b||1,1),j=!!((q=s==null?void 0:s.customCardPreferences)!=null&&q.dataInputCardIds),_=(z,L)=>{z.dataTransfer.setData("tabIndex",L.toString());},k=z=>{z.preventDefault();},A=(z,L)=>{const V=z.dataTransfer.getData("tabIndex");if(V===L.toString())return;const W=Array.from(r.cards),[ee]=W.splice(parseInt(V),1);W.splice(L,0,ee),c({...r,cards:W});};function $(z){const L=(s==null?void 0:s.id)===z;(j&&L?r.cards.length>1:K)&&h(z,{renumber:S&&!j?Md:void 0});}function C(z,L){if(!D)return;const V={...r,cards:[...r.cards,L],activeCardId:z.id};c(V),x(L.id);}function R(){if(d)return;if(S&&(s==null?void 0:s.id)===l.id){I(l);return;}const z={...l,id:$a(),title:`${l.title} Copy`,tabTitle:`${l.tabTitle||l.title} Copy`,customCardPreferences:l.customCardPreferences?{...l.customCardPreferences,slotIndex:S?Math.max(-1,...F.map((L,V)=>at(L,V)))+1:l.customCardPreferences.slotIndex}:void 0};C(l,z);}function I(z){var Y;if(d||!D)return;let L=S?"table":Sn,V="Title",W="";const ee=S?Math.max(-1,...F.map((H,X)=>at(H,X)))+1:v;if(S&&(Y=N==null?void 0:N.slots)!=null&&Y.length){const H=Ja(N.slots,ee);H&&(L=Od(H),V=H.label||`Tab ${ee+1}`,W=H.description||"");}const ie={dataSource:z.dataSource,connectionId:z.connectionId,id:$a(),title:V,tabTitle:V,description:W,preferences:{onClickFilter:[{columnIndex:0,expression:""}],...(L==="text"?{textVisualOptions:{richContent:Ol()}}:{})},type:L,sql:"",data:[],mode:"explorer",...(S&&{customCardPreferences:{slotIndex:ee}})};C(z,ie);}function m(z,L){return z.cards.length===1&&(L.displayTab===!0||L.displayTab===void 0)||z.activeCardId!==L.id&&(L.displayTab===!0||L.displayTab===void 0)?null:/* @__PURE__ */e("div",{onClick:()=>{const V=L.displayTab===void 0?!1:!L.displayTab;u({...L,displayTab:V}),f({...L,displayTab:V});},children:L.displayTab===!0||L.displayTab===void 0?/* @__PURE__ */e(Ga,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"}):/* @__PURE__ */e(Wn,{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((z,L)=>{var Y,H;const V=S?at(z,L):-1,W=S&&(Y=N==null?void 0:N.slots)!=null&&Y.length&&V>=0?Ja(N.slots,V):null,ee=W?(Array.isArray(W.expectedType)?W.expectedType[0]:W.expectedType)||"table":z.type,ie=S&&((H=N==null?void 0:N.slots)==null?void 0:H.length)&&N.slots.every(X=>typeof X.position=="number"||typeof X.position=="string"&&!X.position.includes("+"));return/* @__PURE__ */n(ze,{draggable:!S&&!d,onDragStart:S||d?void 0:X=>_(X,L),onDragOver:S||d?void 0:k,onDrop:S||d?void 0:X=>A(X,L),className:Q("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:z.id,children:[S&&W?/* @__PURE__ */e(Lt,{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:Vr(ee,"size-3.5")}),/* @__PURE__ */e("span",{children:W.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:W.label}),W.description&&/* @__PURE__ */e("p",{className:"whitespace-normal break-words text-xs text-muted-foreground",children:W.description}),/* @__PURE__ */n("div",{className:"flex items-center gap-2 pt-1",children:[W.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(W.expectedType)?W.expectedType.join(" / "):W.expectedType}),W.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(xe,{children:[m(r,z),/* @__PURE__ */e(wo,{enabled:r.activeCardId===z.id,text:z.tabTitle||z.title,onSave:X=>{u({...l,tabTitle:X}),f({...l,tabTitle:X});},children:z.tabTitle||z.title},z.id)]}),!d&&!i&&r.activeCardId===z.id&&!ie&&/* @__PURE__ */e(So,{className:"h-3 w-3 text-muted-foreground hover:text-foreground",onClick:X=>{X.stopPropagation(),R();}}),!d&&r.activeCardId===z.id&&(j&&(s==null?void 0:s.id)===z.id?r.cards.length>1:K)&&/* @__PURE__ */e(ca,{className:"h-3 w-3 text-muted-foreground hover:text-foreground",onClick:()=>$(z.id)})]},z.id);}),!d&&!i&&/* @__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:()=>I(l),disabled:!D,children:/* @__PURE__ */e(ba,{className:"h-3 w-3"})}),S&&/* @__PURE__ */n(Xs,{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(Wn,{className:"h-3 w-3"}):/* @__PURE__ */e(Ga,{className:"h-3 w-3"}),/* @__PURE__ */e("span",{children:"Preview"})]})]})});}function nn({renderCardOverride:t,alwaysRenderOverride:a=!1}={}){var De,Ge,et,ge,se,Ee,Ce,$e;const s=Rc(),r=E(B=>B.frame),l=E(B=>B.card),[o,d]=G(!1),i=J(()=>vt(r,l),[r,l]),c=E(B=>B.isSqlRunning);E(B=>B.isDevMode);const{switchCardTab:x,resetAllColumnSettings:u}=he(),f=Object.keys(((Ge=(De=l.preferences)==null?void 0:De.tablePrefs)==null?void 0:Ge.columnSettingsMap)??{}).length>0||Object.keys(((et=l.preferences)==null?void 0:et.sqlColumns)??{}).length>0,[h,p]=G({}),[N,T]=G(()=>/* @__PURE__ */new Set()),{authToken:S}=Gt(),b=Fl(S==null?void 0:S.accessToken),{compiledAppearance:y}=iu(),F=J(()=>Lc(y),[y]),{getCard:v,manifest:D,isLoading:K}=bt(((ge=i==null?void 0:i.customCardPreferences)==null?void 0:ge.url)||""),j=(se=i==null?void 0:i.customCardPreferences)==null?void 0:se.componentName,_=j?v(j):null,k=(Ee=D==null?void 0:D.visuals)==null?void 0:Ee.find(B=>B.name===j),A=Nt(i,k),$=o&&A==="multiple"&&!!i,C=J(()=>Xt({frame:r,configCard:i,isMultiInputVisual:!0}).map(me=>(me==null?void 0:me.id)===l.id?l:me),[r,i,l]),R=J(()=>ms(C),[C]),I=J(()=>{const B=C.findIndex(me=>(me==null?void 0:me.id)===l.id);return B<0?-1:at(l,B);},[C,l]),m=J(()=>!i||A!=="multiple"||I<0?l.type:It(l,I,k==null?void 0:k.slots)??l.type,[i,A,I,l,k==null?void 0:k.slots]),M=J(()=>$?{...l,connectionId:void 0,dataSource:void 0,sql:"",python:"",config:void 0,queryConfig:void 0}:m!==l.type?{...l,type:m}:l,[l,m,$]),{data:g,dataUpdatedAt:w,isLoading:O,isFetching:q,isError:z,errorMessage:L,errorSql:V,queryKey:W}=He(M),ee=ma(l,g),ie=JSON.stringify(W),{handleOpenInEditor:Y}=Fs(V||l.sql||l.python),H=l.type==="text"&&(($e=(Ce=l.preferences)==null?void 0:Ce.textVisualOptions)==null?void 0:$e.isDynamicText)===!0&&!!L,X=rt((B,me)=>{const We=Fd(me);p(Ye=>({...Ye,[B]:We}));},[]),de=rt((B,me)=>{T(We=>{const Ye=new Set(We);return me?Ye.add(B):Ye.delete(B),Ye;});},[]),pe=N.size>0,oe=J(()=>R.map((B,me)=>It(B,me,k==null?void 0:k.slots)),[R,k==null?void 0:k.slots]),fe=J(()=>bo(yo({slotOrderedCards:R,multiInputData:h,valueFormatPreferences:s})),[h,R,s]),ue=Pc(),ke=be(B=>B.dashboard),Ve=be(B=>B.dashboardInputValues),qe=be(B=>B.adHocFilterValues),Be=be(B=>{var me;return((me=B.reportContext)==null?void 0:me.calendar)??null;}),ce=be(B=>B.selectedSheetId),Fe=E(B=>B.inlineFilterValuesMap[(i==null?void 0:i.id)||""]),Oe=E(B=>B.actions.setCardInlineFilterValue),Re=E(B=>B.actions.removeCardInlineFilterValue),st=J(()=>i?vo({card:i,sheetId:ce||"",inlineFilterValues:Fe,setInlineFilterValue:B=>Oe(i.id,B),removeInlineFilterValue:B=>Re(i.id,B)}):[],[i,ce,Fe,Oe,Re]),{filterInputs:Je,filters:Z,filterValues:ve}=J(()=>i?Dc({dashboard:ke,card:i,sheetId:ce,dashboardInputValues:Ve,adHocFilterValues:qe,transientContexts:ue,calendar:Be}):{filterInputs:[],filters:[],filterValues:[]},[qe,i,Ve,Be,ke,ce,ue]);function Ae(B){x(B);}function Le(){return K?/* @__PURE__ */e("div",{className:"flex h-full items-center justify-center",children:/* @__PURE__ */e(tt,{size:"md",color:"muted","aria-label":"Loading manifest"})}):_?/* @__PURE__ */n("div",{className:"relative flex h-full flex-col pl-2 pr-4",children:[C.map((me,We)=>{if(!me)return null;const Ye=at(me,We),Us=It(me,Ye,k==null?void 0:k.slots);return/* @__PURE__ */e(To,{onLoadingStatus:de,onDataChange:X,card:me,effectiveCardType:Us},`${me.id}-${Ye}`);}),pe&&/* @__PURE__ */e("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-background/50",children:/* @__PURE__ */e(tt,{size:"md",color:"muted","aria-label":"Loading preview"})}),/* @__PURE__ */e("div",{className:Q("flex h-full min-h-0 flex-1 flex-col gap-2",pe&&"opacity-50"),children:/* @__PURE__ */e(vd,{fallback:/* @__PURE__ */e("div",{className:"flex h-full items-center justify-center",children:/* @__PURE__ */e(tt,{size:"md",color:"muted"})}),children:/* @__PURE__ */e(_,{editing:!0,...ko({configCard:i,slotOrderedCards:R,slotTypes:oe,multiInputData:h,params:b,theme:F,filterInputs:Je,filters:Z,filterValues:[...(ve||[]),...(Fe||[])],inlineFilters:st,formatTemporalBucketValue:fe})})})})]}):/* @__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 $?Le():t&&(a||!O&&!q&&!z&&!L)?t({card:l,data:g,isLoading:O,isFetching:q,isError:z}):l.type==="kpi"?O||q?/* @__PURE__ */e("div",{className:"z-50 flex h-full items-center justify-center",children:/* @__PURE__ */e(tt,{size:"md",color:"muted","aria-label":"Loading data"})}):L?/* @__PURE__ */e(vm,{errorMessage:L,errorSql:V||l.sql||l.python,onOpenInEditor:Y}):/* @__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(No,{card:ee,data:g==null?void 0:g.records,isPending:O||q,isError:z,metadata:g==null?void 0:g.metadata})}),Pr(l)&&/* @__PURE__ */e(Dr,{card:ee,mode:"editor",records:g==null?void 0:g.records})]})}):l.type==="text"?O||q?/* @__PURE__ */e("div",{className:"z-50 flex h-full items-center justify-center",children:/* @__PURE__ */e(tt,{size:"md",color:"muted","aria-label":"Loading data"})}):H?/* @__PURE__ */e("div",{className:"flex h-full min-h-0 flex-col overflow-auto px-4 py-0",children:/* @__PURE__ */e(un,{error:L,errorSql:V||l.sql||l.python,onOpenInEditor:Y,showFeedbackButton:!1})}):/* @__PURE__ */e("div",{className:"flex h-full min-h-0 flex-col px-4 py-4",children:/* @__PURE__ */e(Co,{isLoading:c,card:l,data:g==null?void 0:g.records})}):/* @__PURE__ */e(ha,{fallbackRender:B=>/* @__PURE__ */e(mn,{...B,onResetColumnSettings:f?u:void 0}),resetKeys:[ie,w,q],children:/* @__PURE__ */e(Os,{className:"grow border-none shadow-none"})});}return/* @__PURE__ */n(ft,{onValueChange:Ae,value:r.activeCardId,className:"flex min-h-0 flex-1 flex-col",children:[$?/* @__PURE__ */e("div",{className:"mt-0 min-h-0 flex-1 overflow-hidden",children:Pe()}):r.cards.map(B=>/* @__PURE__ */e(Qe,{className:"mt-0 min-h-0 flex-1 overflow-hidden focus-visible:ring-0 focus-visible:ring-offset-0",value:B.id,children:Pe()},B.id)),/* @__PURE__ */e(Nm,{isPreviewMode:$,onPreviewToggle:d,configCard:i})]});}function Ps({sql:t,debugPayloads:a,variant:s="panel",className:r}){const[l,o]=G(!1),d=s==="popover",i=E(N=>N.isDevMode),c=E(N=>N.card.type),{switchEditorMode:x,setRunSql:u}=he(),f=!d&&!i&&!!a,h=f&&l,p=()=>{x("dev",{sqlToLoad:t}),setTimeout(()=>{u(!0);},100);};return d?/* @__PURE__ */e(qn,{className:Q("overflow-hidden pt-0",r),children:/* @__PURE__ */e($n,{sql:t,label:"Executed SQL",headerClassName:"border-b border-border/60 py-2",labelClassName:"font-medium text-foreground",ariaLabel:"Executed SQL",copyAriaLabel:"Copy executed SQL",className:"min-h-0",bodyClassName:"max-h-[min(420px,calc(var(--radix-hover-card-content-available-height,100vh)-3rem))]"})}):/* @__PURE__ */n(qn,{className:Q("overflow-hidden px-3 pb-2",r),children:[/* @__PURE__ */e($n,{sql:t,framed:!0,label:/* @__PURE__ */e(Io,{note:"Built from the fields"}),ariaLabel:"Executed SQL",copyAriaLabel:"Copy SQL",headerActions:/* @__PURE__ */e(Eo,{sql:t,onOpenInEditor:!i&&sn(c)?p:void 0,inspect:f?{isOpen:l,onToggle:()=>o(N=>!N)}:void 0}),className:Q("min-h-0",h?"max-h-[40%] shrink-0":"flex-1"),bodyClassName:h?void 0:"flex-1"}),h&&a&&/* @__PURE__ */e(Fo,{payloads:a,onClose:()=>o(!1),framed:!0,className:"mt-3 flex-1"})]});}function Pa({children:t,visualAsideControl:a,mode:s="both"}){const r=gn(),l=E(oe=>oe.frame),o=E(oe=>oe.card),d=E(oe=>oe.isDevMode),i=E(oe=>oe.editorContext),c=(i==null?void 0:i.type)==="documentSection",x=be(oe=>oe.isVisualEditing),u=be(oe=>{var fe,ue;return(ue=(fe=oe.dashboard)==null?void 0:fe.exportDefaults)==null?void 0:ue.csvEncoding;}),f=E(oe=>oe.actions.setRunSql),h=Ke(),p=h==="table"||h==="detailTable"||h==="matrixTable",T=ln(h)&&!!(a!=null&&a.onOpen),S=En(),b=J(()=>h!==o.type?{...o,type:h}:o,[o,h]),{data:y,isLoading:F,isFetching:v,errorMessage:D,refetch:K,queryKey:j,pagination:_,isCurrentQueryResult:k}=He(b),A=Ie(j);A.current=j;const $=J(()=>(y==null?void 0:y.records)||[],[y==null?void 0:y.records]),{cardFilterValues:C}=_c((o==null?void 0:o.id)??""),[R,I]=G(!1),m=$r(o),[M,g]=G();ye(()=>{v||I(!1);},[v]);const w=()=>{var oe;if(m){(oe=m.refresh)==null||oe.call(m);return;}if(I(!0),d){Cr({queryClient:r,readQueryKey:()=>A.current,setRunSql:f});return;}K();},O=Array.isArray(y==null?void 0:y.records)?y.records:[],q=O.length>0;function z(){var fe;if(!q)return;const oe=JSON.stringify(O,null,2);typeof navigator>"u"||!((fe=navigator.clipboard)!=null&&fe.writeText)||navigator.clipboard.writeText(oe).catch(ue=>{console.error("Failed to copy JSON",ue);});}function L(){if(!q)return;const oe=JSON.stringify(O,null,2),fe=new Blob([oe],{type:"application/json"}),ue=URL.createObjectURL(fe),ke=document.createElement("a");ke.href=ue,ke.download=`${o.title}.json`,ke.click();}function V(){q&&Bc(zc(_d({records:O,encoding:lu({dashboardDefault:u})}),o.title||"export"));}if(!o)return/* @__PURE__ */e(xe,{children:"No Active Card"});const W=s==="both"||s==="toolbar",ee=s==="both"||s==="canvas",ie=s==="toolbar",Y=!F&&!v&&!D&&y!=null&&y.sql?/* @__PURE__ */e("div",{className:"inline-flex shrink-0 items-center text-[11px] text-muted-foreground",children:/* @__PURE__ */n(Tt,{openDelay:200,children:[/* @__PURE__ */e(kt,{asChild:!0,children:/* @__PURE__ */e("button",{type:"button",className:"cursor-pointer text-[11px] transition-colors hover:text-foreground",children:"Executed SQL"})}),/* @__PURE__ */e(Et,{align:"end",collisionPadding:16,className:"w-[500px] overflow-hidden p-0",children:/* @__PURE__ */e(Ps,{sql:y.sql,variant:"popover"})})]})}):null,H=typeof(y==null?void 0:y.output)=="string"?y.output.trim():"",X=ie&&!F&&!v&&!D&&H?/* @__PURE__ */n(Tt,{openDelay:200,children:[/* @__PURE__ */e(kt,{asChild:!0,children:/* @__PURE__ */e("button",{type:"button",className:"cursor-pointer text-[11px] transition-colors hover:text-foreground",children:"Python output"})}),/* @__PURE__ */n(Et,{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:H})]})]}):null,de=(_==null?void 0:_.totalCount)??$.length,pe=ie&&!F&&!v&&!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: ",de.toLocaleString()," ",de===1?"row":"rows"]}),Y?/* @__PURE__ */n(xe,{children:[/* @__PURE__ */e("span",{"aria-hidden":!0,className:"text-border",children:"·"}),Y]}):null,X?/* @__PURE__ */n(xe,{children:[/* @__PURE__ */e("span",{"aria-hidden":!0,className:"text-border",children:"·"}),X]}):null]}):null;return/* @__PURE__ */n("div",{className:Q("relative isolate flex flex-col",ie?"pointer-events-none w-full min-w-0":Q("h-full",!p&&"pt-2")),children:[W&&/* @__PURE__ */n("div",{className:Q("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:[!c&&/* @__PURE__ */e(an,{selectedChart:o.type,onChartChange:S,compactMore:!0,responsiveCompact:!0}),pe]}):/* @__PURE__ */e("div",{className:"flex grow items-center gap-4",children:/* @__PURE__ */e("div",{className:"flex items-center gap-3",children:!c&&/* @__PURE__ */e(an,{selectedChart:o.type,onChartChange:S,compactMore:!0})})}),/* @__PURE__ */n("div",{className:Q("flex items-center text-muted-foreground",ie?"pointer-events-auto ml-auto gap-1.5":"gap-2"),children:[t,ie?null:Y,C&&C.length>0&&/* @__PURE__ */n(Tt,{openDelay:200,children:[/* @__PURE__ */e(kt,{asChild:!0,children:/* @__PURE__ */n(le,{variant:"outline",size:"xs",className:"h-7 gap-1.5 px-2",children:[/* @__PURE__ */e(ya,{className:"h-3.5 w-3.5",strokeWidth:1.75}),/* @__PURE__ */e(as,{variant:"secondary",className:"h-4 min-w-4 rounded-[4px] px-1 text-[10px] font-medium",children:C.length})]})}),/* @__PURE__ */n(Et,{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(Ft,{value:JSON.stringify(C,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(Ls,{showInlineFilters:!1,showControls:!1,showDisplayOptions:!1})}),(a==null?void 0:a.show)&&/* @__PURE__ */n(le,{type:"button",variant:"ghost",size:"xs","aria-pressed":a.isOpen,onClick:a.onToggle,className:Q("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(xa,{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:F||v,className:"h-7 w-7 px-0",onClick:w,children:/* @__PURE__ */e(Za,{className:Q("h-3.5 w-3.5",{"animate-spin":(m==null?void 0:m.isFetching)??R})})}),/* @__PURE__ */n(pa,{modal:!1,children:[/* @__PURE__ */e(fa,{asChild:!0,children:/* @__PURE__ */e(_e,{tooltip:"More Options",className:"h-7 w-7 px-0","aria-label":"More options",children:/* @__PURE__ */e(jr,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(ga,{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(xe,{children:[/* @__PURE__ */n(Ue,{disabled:F||v,onSelect:w,children:[/* @__PURE__ */e(Za,{className:"h-3.5 w-3.5"}),"Refresh result"]}),/* @__PURE__ */e(Yn,{})]}),/* @__PURE__ */e(Xn,{children:"Export"}),m?/* @__PURE__ */n(Ue,{disabled:F||v||!m.hasDelivery,title:m.hasDelivery?void 0:"Available once the preview has loaded.",onSelect:()=>g(m.readDelivery()),className:"gap-2 text-[13px]",children:[/* @__PURE__ */e(Wa,{className:"h-3.5 w-3.5"}),"Download"]}):/* @__PURE__ */n(xe,{children:[/* @__PURE__ */n(Ue,{disabled:!q,onSelect:V,className:"gap-2 text-[13px]",children:[/* @__PURE__ */e(Wa,{className:"h-3.5 w-3.5"}),"Download CSV"]}),/* @__PURE__ */n(Ue,{disabled:!q,onSelect:L,className:"gap-2 text-[13px]",children:[/* @__PURE__ */e(gu,{className:"h-3.5 w-3.5"}),"Download JSON"]}),/* @__PURE__ */n(Ue,{disabled:!q,onSelect:z,className:"gap-2 text-[13px]",children:[/* @__PURE__ */e(Yt,{className:"h-3.5 w-3.5"}),"Copy JSON"]})]}),/* @__PURE__ */e(Yn,{}),/* @__PURE__ */e(Xn,{children:"Customize"}),!["table","detailTable","custom"].includes(o.type)&&x&&/* @__PURE__ */e(tm,{triggerVariant:"menu",className:"w-full"}),/* @__PURE__ */e(On,{triggerVariant:"menu",className:"w-full"}),/* @__PURE__ */e(An,{triggerVariant:"menu",className:"w-full"}),/* @__PURE__ */e(Mn,{triggerVariant:"menu",className:"w-full"}),T&&/* @__PURE__ */n(Ue,{onSelect:()=>{var oe;return(oe=a==null?void 0:a.onOpen)==null?void 0:oe.call(a,"style");},className:"gap-2 text-[13px]",children:[/* @__PURE__ */e(Vc,{className:"h-3.5 w-3.5"}),"Table settings"]})]})]}),M&&/* @__PURE__ */e(ls,{isOpen:!0,onClose:()=>g(void 0),card:o,frame:l,matrix:M})]})]}),ee&&/* @__PURE__ */e(nn,{})]});}function Cm({onToggleEditor:t,children:a}){return/* @__PURE__ */n("div",{className:"relative isolate shrink-0 border-t border-border bg-muted/30 @container",children:[/* @__PURE__ */e(yr,{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(ws,{className:"top-1"})}),a]});}function je({value:t,onCommit:a,type:s="text",placeholder:r,className:l}){const[o,d]=G(t),i=Ie(!1);return ye(()=>{d(t);},[t]),/* @__PURE__ */e(ct,{type:s,placeholder:r,value:o,onChange:u=>d(u.target.value),onBlur:()=>{if(i.current){i.current=!1;return;}o!==t&&a(o);},onKeyDown:u=>{if(u.key==="Enter"){u.currentTarget.blur();return;}u.key==="Escape"&&(i.current=!0,d(t),u.currentTarget.blur());},className:l});}function Jt({defaultValue:t,label:a,options:s,value:r,onValueChange:l,className:o,icon:d,showPlaceholderLabel:i=!0}){return/* @__PURE__ */n(te,{defaultValue:t,value:r,onValueChange:l,children:[/* @__PURE__ */e(ae,{className:Q("w-full focus:ring-0 focus:ring-offset-0",o),children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[d&&/* @__PURE__ */e("span",{children:d}),i&&/* @__PURE__ */e(ne,{placeholder:a})]})}),/* @__PURE__ */e(re,{children:/* @__PURE__ */n(Kc,{children:[/* @__PURE__ */e(qc,{children:a}),s.map(c=>/* @__PURE__ */e(U,{value:c.value,children:c.label},c.value))]})})]});}function wm(t,a){return Ja(t,a)||null;}function Kt(t){if(typeof t=="number")return`Tab ${t+1}`;const a=t.match(/^(\d+)-(\d+)$/);if(a){const[,r,l]=a;return`Tabs ${Number(r)+1}-${Number(l)+1}`;}const s=t.match(/^(\d+)\+$/);return s?`Tabs ${Number(s[1])+1}+`:`Tab ${t}`;}function Sm(t){return t?Array.isArray(t)?t:[t]:[];}function Da(t){var r,l;if(!t)return!1;if(t.type==="text")return!!((r=t.description)!=null&&r.trim());const a=!!((l=t.sql)!=null&&l.trim()),s=Qt(t.config);return a||s;}function Tm({slots:t,cards:a,minInputs:s}){const r=[],l=a.filter(Boolean).length;return s&&l<s&&r.push({type:"too-few-inputs",message:`This visual requires at least ${s} tab${s===1?"":"s"}.`}),!t||t.length===0||(t.forEach(o=>{if(!o.required)return;if(typeof o.position=="number"){const c=a[o.position];Da(c)||r.push({type:"missing-required",message:`${Kt(o.position)} ("${o.label}") is required but has no data configured.`});return;}const d=o.position.match(/^(\d+)-(\d+)$/);if(d){const[,c,x]=d.map(Number);for(let u=c;u<=x;u+=1){const f=a[u];if(!Da(f)){r.push({type:"missing-required",message:`${Kt(u)} ("${o.label}") is required but has no data configured.`});break;}}return;}const i=o.position.match(/^(\d+)\+$/);if(i){const c=Number(i[1]);if(a.length<=c){r.push({type:"missing-required",message:`${Kt(c)} ("${o.label}") is required but has no data configured.`});return;}for(let x=c;x<a.length;x+=1){const u=a[x];if(!Da(u)){r.push({type:"missing-required",message:`${Kt(x)} ("${o.label}") is required but has no data configured.`});break;}}}}),a.forEach((o,d)=>{if(!o)return;const i=wm(t,d);if(!i||!i.expectedType)return;const c=Sm(i.expectedType);c.length!==0&&(c.includes(o.type)||r.push({type:"wrong-type",message:`${Kt(d)} ("${i.label}") expects ${c.join(", ")}, but is configured as ${o.type}.`}));})),r;}const km={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(xe,{children:t})};function Ds(){var C,R,I;const t=E(m=>m.card.customCardPreferences),{data:a}=$c(),s=(a==null?void 0:a.plugins)||[],r=E(m=>m.card),l=E(m=>m.frame),{setCustomCardPreferences:o}=he(),d=J(()=>vt(l,r),[l,r]),i=d==null?void 0:d.customCardPreferences,{components:c,manifest:x}=bt((i==null?void 0:i.url)||(t==null?void 0:t.url)||""),u=(C=x==null?void 0:x.visuals)==null?void 0:C.find(m=>m.name===((i==null?void 0:i.componentName)||(t==null?void 0:t.componentName))),h=Nt(d||r,u)==="multiple",p=!!d&&d.id===r.id,N=(u==null?void 0:u.minInputs)??((R=d==null?void 0:d.customCardPreferences)==null?void 0:R.minInputs),T=(u==null?void 0:u.maxInputs)??((I=d==null?void 0:d.customCardPreferences)==null?void 0:I.maxInputs),S=J(()=>Xt({frame:l,configCard:d||r,isMultiInputVisual:h}),[l,d,r,h]),b=J(()=>ms(S),[S]),y=J(()=>b.map((m,M)=>{if(!m)return null;const g=at(m,M),w=It(m,g,u==null?void 0:u.slots);return{...m,type:w??m.type};}),[b,u==null?void 0:u.slots]),F=J(()=>Tm({slots:u==null?void 0:u.slots,cards:y,minInputs:N}),[u==null?void 0:u.slots,y,N]),v=J(()=>{const m=S.findIndex(M=>(M==null?void 0:M.id)===r.id);return m<0?-1:at(r,m);},[S,r]);function D(m){if(typeof m=="number")return`Tab ${m+1}`;const M=m.match(/^(\d+)-(\d+)$/);if(M){const[,w,O]=M;return`Tabs ${Number(w)+1}-${Number(O)+1}`;}const g=m.match(/^(\d+)\+$/);return g?`Tabs ${Number(g[1])+1}+`:`Tab ${m}`;}function K(m){return m?(Array.isArray(m)?m:[m]).join(", "):null;}function j(m,M,g=[],w="",O,q,z){const L=_({key:M,defaultValue:w,settingsValue:q,sourceCard:z});return m==="input"?/* @__PURE__ */e(je,{className:`h-8 w-full ${Al}`,value:String(L??""),onCommit:V=>{k({key:M,value:V,settingsField:O,settingsValue:q,sourceCard:z});}},M):m==="select"?/* @__PURE__ */e(Jt,{className:"h-8 w-full",label:"",options:g,value:String(L!==void 0?L:w??""),onValueChange:V=>{k({key:M,value:V,settingsField:O,settingsValue:q,sourceCard:z});}}):null;}function _({key:m,defaultValue:M,settingsValue:g,sourceCard:w}){const O=g==null?void 0:g[m];return O!==void 0?O:m==="title"&&(w==null?void 0:w.title)!==void 0?w.title:m==="description"&&(w==null?void 0:w.description)!==void 0?w.description:M;}function k({key:m,value:M,settingsField:g,settingsValue:w,sourceCard:O}){const q={...(w||{})},z=m==="title"&&(O==null?void 0:O.title)!==void 0,L=m==="description"&&(O==null?void 0:O.description)!==void 0;z&&M===String((O==null?void 0:O.title)??"")||L&&M===String((O==null?void 0:O.description)??"")?delete q[m]:q[m]=M,o({...(t||{}),[g]:q});}function A({settingsSchema:m,settingsField:M,settingsValue:g,sourceCard:w,headerLabel:O}){const q=Object.entries(m||{});return/* @__PURE__ */n("div",{className:"space-y-3",children:[O&&/* @__PURE__ */e(P,{children:O}),q.map(([z,L])=>{var V;return/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(P,{children:L.title}),((V=L.docs)==null?void 0:V.description)&&/* @__PURE__ */e(Lt,{delayDuration:0,children:/* @__PURE__ */n(mt,{children:[/* @__PURE__ */e(ht,{asChild:!0,children:/* @__PURE__ */e(ut,{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:L.docs.description})})]})})]}),j(L.ui,z,L.options,L.defaultValue,M,g,w)]},z);})]});}function $(){return/* @__PURE__ */n(xe,{children:[h&&/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */e(P,{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((m,M)=>/* @__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(m.position)}),/* @__PURE__ */e("span",{className:"text-muted-foreground",children:"•"}),/* @__PURE__ */e("span",{className:"font-medium",children:m.label})]}),m.description&&/* @__PURE__ */e("p",{className:"text-muted-foreground",children:m.description}),/* @__PURE__ */n("div",{className:"flex flex-wrap gap-2 text-muted-foreground",children:[K(m.expectedType)&&/* @__PURE__ */n("span",{children:["Expected: ",K(m.expectedType)]}),m.required&&/* @__PURE__ */e("span",{children:"Required"})]})]},`${m.label}-${M}`))}):/* @__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||T)&&/* @__PURE__ */n("p",{children:[N?`Min ${N} tabs`:"",N&&T?" • ":"",T?`Max ${T} tabs`:""]})]})})]}),h&&F.length>0&&/* @__PURE__ */e(Js,{className:"mt-3 border-yellow-500/40 bg-yellow-500/10 text-yellow-900 dark:text-yellow-100",children:/* @__PURE__ */e(Zs,{children:/* @__PURE__ */e("ul",{className:"list-disc space-y-1 pl-4 text-xs",children:F.map((m,M)=>/* @__PURE__ */e("li",{children:m.message},`${m.type}-${M}`))})})}),u&&!h&&u.settings&&/* @__PURE__ */e("div",{className:"space-y-3",children:/* @__PURE__ */e("div",{className:"px-2",children:A({settingsSchema:u.settings,settingsField:"settings",settingsValue:t==null?void 0:t.settings,sourceCard:r})})}),u&&h&&(u.settings||u.slotSettings)&&/* @__PURE__ */n("div",{className:"mt-4 space-y-4",children:[p&&u.settings&&/* @__PURE__ */e("div",{className:"px-2",children:A({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:A({settingsSchema:u.slotSettings,settingsField:"slotSettings",settingsValue:t==null?void 0:t.slotSettings,sourceCard:r,headerLabel:(()=>{const m=r.tabTitle||r.title,M=v>=0?v:0,g=p?"Slot 0":`Slot ${M}`;return m?`${g}: ${m} Settings`:`${g} Settings`;})()})})]})]});}return/* @__PURE__ */n(la,{type:"multiple",defaultValue:["component-settings"],className:"",children:[/* @__PURE__ */n(we,{value:"plugin-settings",children:[/* @__PURE__ */e(Se,{children:"Plugin"}),/* @__PURE__ */e(Te,{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:[(!h||p)&&/* @__PURE__ */e(Jt,{icon:/* @__PURE__ */e(xs,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Plugin",options:s,value:(i==null?void 0:i.url)||"",onValueChange:m=>o({...(t||{url:"",componentName:""}),url:m})}),h&&!p&&/* @__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&&(!h||p)&&/* @__PURE__ */e(xe,{children:c&&/* @__PURE__ */e(Jt,{icon:/* @__PURE__ */e(fu,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(c==null?void 0:c.map(m=>({value:m.name,label:m.name})))||[],value:t.componentName||"",onValueChange:m=>{var w;const M=(w=x==null?void 0:x.visuals)==null?void 0:w.find(O=>O.name===m),g=c==null?void 0:c.find(O=>O.name===m);o({...t,componentName:m,visualType:(M==null?void 0:M.visualType)||(g==null?void 0:g.type)||"single",minInputs:M==null?void 0:M.minInputs,maxInputs:M==null?void 0:M.maxInputs,pluginChartType:M==null?void 0:M.chartType});}})})]})})]}),((i==null?void 0:i.componentName)||(t==null?void 0:t.componentName))&&/* @__PURE__ */n(we,{className:"border-none",value:"component-settings",children:[/* @__PURE__ */e(Se,{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(Tt,{openDelay:0,closeDelay:100,children:[/* @__PURE__ */e(kt,{asChild:!0,onClick:m=>m.stopPropagation(),children:/* @__PURE__ */e(ut,{className:"h-3.5 w-3.5 cursor-help text-muted-foreground transition-colors hover:text-foreground"})}),/* @__PURE__ */e(Et,{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(Mo,{remarkPlugins:[Oo],components:km,children:u.docs.dataSchema})})]}),(()=>{var M;const m=(M=u.docs)==null?void 0:M.useCases;return!m||m.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:m.map((g,w)=>/* @__PURE__ */n("li",{className:"flex items-start gap-2",children:[/* @__PURE__ */e("span",{className:"mt-1 text-primary",children:"•"}),/* @__PURE__ */e("span",{children:g})]},w))})]});})()]})})]})]})}),/* @__PURE__ */e(Te,{children:$()})]})]});}const $t=[{id:"sankey",name:"Sankey",needs:"2 or more dimensions, 1 measure",html:el},{id:"calendar-heatmap",name:"Calendar heatmap",needs:"a date by day, 1 measure",html:tl},{id:"gauge",name:"Gauge",needs:"1 measure, and a target",html:al},{id:"waterfall",name:"Waterfall",needs:"1 dimension, 1 measure",html:nl},{id:"small-multiples",name:"Small multiples",needs:"2 dimensions, 1 measure",html:rl},{id:"progress-list",name:"Progress list",needs:"1 dimension, 1 measure, and a target",html:sl}];function Em(t,a){return[...t.filter(s=>s.kind===a),...t.filter(s=>s.kind!==a&&"column"in s.ref)];}const ir=t=>t.length>1?`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`:t[0]??"";function Im(t,a,s){const r=Rl(t.html,{kind:"visual"});if(!r.ok)return"";const l=r.manifest,{assigned:o,unfilled:d}=ou({card:a,result:s,manifest:l}),i=new Map(cu(a,s).map(h=>[h.key,h.label])),c=l.slots.filter(h=>{var p;return(p=o.get(h.id))==null?void 0:p.length;}).map(h=>`${ir(o.get(h.id).map(p=>i.get(p)??p))} as ${h.label}`),x=l.slots.filter(h=>d.includes(h.id)).map(h=>h.label),u=c.length?`${t.name} uses ${c.length>1?`${c.slice(0,-1).join(", ")}, and ${c[c.length-1]}`:c[0]}.`:"",f=x.length?`${c.length?"It":t.name} needs a field for ${ir(x)}.`:"";return[u,f].filter(Boolean).join(" ")||`Add fields to this card for ${t.name}.`;}function Fm({open:t,onOpenChange:a,onPick:s,card:r,result:l}){const[o,d]=G($t[0].id),i=$t.find(x=>x.id===o)??$t[0],c=J(()=>Im(i,r,l),[i,r,l]);return/* @__PURE__ */e(Pt,{open:t,onOpenChange:a,children:/* @__PURE__ */n(Dt,{className:"max-w-[640px] gap-0 p-0",children:[/* @__PURE__ */n(Wt,{className:"border-b border-border px-4 py-3",children:[/* @__PURE__ */e(_t,{className:"text-[14px]",children:"Start from a template"}),/* @__PURE__ */e(dt,{className:"text-[12px]",children:"It fills from this card's fields."})]}),/* @__PURE__ */e("div",{className:"grid grid-cols-2 gap-2 p-4 sm:grid-cols-3",role:"listbox","aria-label":"Templates",children:$t.map(x=>/* @__PURE__ */n("button",{type:"button",role:"option","aria-selected":x.id===i.id,className:Q("rounded-md border p-2 text-left transition-colors hover:bg-muted/60",x.id===i.id?"border-foreground":"border-border"),onClick:()=>d(x.id),onDoubleClick:()=>s(x),children:[/* @__PURE__ */e(Mm,{id:x.id}),/* @__PURE__ */e("div",{className:"mt-2 text-[12px] font-medium",children:x.name}),/* @__PURE__ */n("div",{className:"text-[11px] text-muted-foreground",children:["Needs ",x.needs]})]},x.id))}),/* @__PURE__ */n(Ht,{className:"items-center gap-3 border-t border-border px-4 py-3 sm:justify-between",children:[/* @__PURE__ */e("p",{className:"min-w-0 text-[11px] text-muted-foreground","data-testid":"template-fit",children:c}),/* @__PURE__ */n("div",{className:"flex shrink-0 gap-2",children:[/* @__PURE__ */e(le,{type:"button",variant:"ghost",size:"xs",onClick:()=>a(!1),children:"Cancel"}),/* @__PURE__ */n(le,{type:"button",size:"xs",onClick:()=>s(i),children:["Use ",i.name]})]})]})]})});}function Mm({id:t}){const a="h-14 w-full rounded bg-muted/60",s="fill-primary",r="fill-primary/40",l="stroke-muted-foreground/50";switch(t){case"sankey":return/* @__PURE__ */n("svg",{viewBox:"0 0 120 50",className:a,"aria-hidden":"true",children:[/* @__PURE__ */e("path",{d:"M14 10 C60 10, 60 24, 106 24 L106 30 C60 30, 60 18, 14 18 Z",className:r}),/* @__PURE__ */e("path",{d:"M14 26 C60 26, 60 34, 106 34 L106 40 C60 40, 60 34, 14 34 Z",className:"fill-primary/25"}),/* @__PURE__ */e("rect",{x:"8",y:"8",width:"6",height:"28",rx:"1",className:s}),/* @__PURE__ */e("rect",{x:"106",y:"20",width:"6",height:"22",rx:"1",className:s})]});case"calendar-heatmap":return/* @__PURE__ */e("svg",{viewBox:"0 0 120 50",className:a,"aria-hidden":"true",children:Array.from({length:4},(o,d)=>Array.from({length:12},(i,c)=>/* @__PURE__ */e("rect",{x:12+c*8,y:8+d*9,width:"6",height:"7",rx:"1",className:"fill-primary",opacity:0.15+(d*7+c*3)%5/5*0.8},`${d}-${c}`)))});case"gauge":return/* @__PURE__ */n("svg",{viewBox:"0 0 120 50",className:a,"aria-hidden":"true",children:[/* @__PURE__ */e("path",{d:"M36 42 A24 24 0 0 1 84 42",fill:"none",strokeWidth:"7",className:"stroke-muted-foreground/25"}),/* @__PURE__ */e("path",{d:"M36 42 A24 24 0 0 1 74 23",fill:"none",strokeWidth:"7",className:"stroke-primary"})]});case"waterfall":return/* @__PURE__ */n("svg",{viewBox:"0 0 120 50",className:a,"aria-hidden":"true",children:[/* @__PURE__ */e("line",{x1:"10",x2:"110",y1:"42",y2:"42",strokeWidth:"1",className:l}),/* @__PURE__ */e("rect",{x:"16",y:"20",width:"12",height:"22",className:s}),/* @__PURE__ */e("rect",{x:"36",y:"12",width:"12",height:"8",className:"fill-emerald-500/70"}),/* @__PURE__ */e("rect",{x:"56",y:"12",width:"12",height:"14",className:"fill-rose-500/70"}),/* @__PURE__ */e("rect",{x:"76",y:"18",width:"12",height:"8",className:"fill-emerald-500/70"}),/* @__PURE__ */e("rect",{x:"96",y:"18",width:"12",height:"24",className:s})]});case"small-multiples":return/* @__PURE__ */e("svg",{viewBox:"0 0 120 50",className:a,"aria-hidden":"true",children:[0,1,2].map(o=>/* @__PURE__ */n("g",{transform:`translate(${10+o*36} 8)`,children:[/* @__PURE__ */e("rect",{width:"30",height:"34",rx:"2",fill:"none",strokeWidth:"1",className:l}),[0,1,2,3].map(d=>/* @__PURE__ */e("rect",{x:4+d*6,y:34-(8+(d+o)%4*6),width:"4",height:8+(d+o)%4*6,className:r},d))]},o))});case"progress-list":return/* @__PURE__ */e("svg",{viewBox:"0 0 120 50",className:a,"aria-hidden":"true",children:[0.85,0.6,0.4].map((o,d)=>/* @__PURE__ */n("g",{transform:`translate(12 ${10+d*12})`,children:[/* @__PURE__ */e("rect",{width:"96",height:"5",rx:"2.5",className:"fill-muted-foreground/20"}),/* @__PURE__ */e("rect",{width:96*o,height:"5",rx:"2.5",className:s})]},d))});default:return/* @__PURE__ */e("div",{className:a});}}const or="__position__",Om="Build a custom visual for the card I'm editing: ";function _s(){const t=Nr(),{card:a,spec:s,loading:r,loadFailed:l,reading:o,manifest:d,result:i,fields:c,slots:x,write:u,check:f,recheck:h,promptText:p}=t,N=Ao(),[T,S]=G(!1),[b,y]=G(!1),[F,v]=G(!1),D=!!o||r||l,K=_=>{u({html:_.html}),y(!1);};return/* @__PURE__ */n("div",{className:"space-y-5 py-4 text-[12px]","data-testid":"custom-visual-panel",children:[D?/* @__PURE__ */n("section",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(Ct,{children:"Custom visual"}),/* @__PURE__ */n(le,{type:"button",variant:"ghost",size:"xs",className:"-mr-2 h-6 px-2 text-muted-foreground",onClick:()=>{t.clear(),S(!1);},children:[/* @__PURE__ */e(Ya,{className:"mr-1 h-3 w-3"})," Start over"]})]}),o?/* @__PURE__ */e(ks,{findings:o.findings,manifest:d}):null,/* @__PURE__ */e(Es,{check:f,onRetry:h}),l?/* @__PURE__ */e("p",{className:"text-destructive",children:"This visual can't be loaded."}):null,/* @__PURE__ */n("div",{className:Q("grid gap-1.5",N.available?"grid-cols-2":"grid-cols-1"),children:[N.available?/* @__PURE__ */n(le,{type:"button",variant:"outline",size:"xs",className:"min-w-0 justify-start",onClick:()=>!N.isOpen&&N.toggle(),children:[/* @__PURE__ */e(jn,{className:"mr-1 h-3 w-3 shrink-0"})," ",/* @__PURE__ */e("span",{className:"truncate",children:"Ask assistant"})]}):null,/* @__PURE__ */n(le,{type:"button",variant:"outline",size:"xs",className:"min-w-0 justify-start",onClick:()=>y(!0),children:[/* @__PURE__ */e(bu,{className:"mr-1 h-3 w-3 shrink-0"})," ",/* @__PURE__ */e("span",{className:"truncate",children:"Templates"})]})]})]}):/* @__PURE__ */n(xe,{children:[N.available?/* @__PURE__ */n("section",{className:"space-y-2",children:[/* @__PURE__ */e(Ct,{children:"Custom visual"}),/* @__PURE__ */n(le,{type:"button",variant:"outline",size:"xs",className:"w-full justify-start",onClick:()=>N.startWith(Om),children:[/* @__PURE__ */e(jn,{className:"mr-1.5 h-3 w-3"})," Describe it to the assistant"]})]}):null,/* @__PURE__ */n("section",{className:"space-y-2",children:[/* @__PURE__ */e(Ct,{children:N.available?"Or start from":"Start from"}),/* @__PURE__ */e("div",{className:"grid grid-cols-2 gap-1",children:$t.slice(0,4).map(_=>/* @__PURE__ */e(le,{type:"button",variant:"outline",size:"xs",className:"justify-start",onClick:()=>K(_),children:_.name},_.id))}),/* @__PURE__ */n(le,{type:"button",variant:"ghost",size:"xs",className:"px-1 text-muted-foreground",onClick:()=>y(!0),children:["All templates ",/* @__PURE__ */e(yt,{className:"ml-0.5 h-3 w-3"})]})]}),/* @__PURE__ */n("section",{className:"space-y-2",children:[/* @__PURE__ */e(Ct,{children:"Your own assistant"}),/* @__PURE__ */e("p",{className:"leading-[1.55] text-muted-foreground",children:"For Claude, ChatGPT or any assistant: copy the prompt, then paste the HTML it writes."}),/* @__PURE__ */n("div",{className:"flex gap-1.5",children:[/* @__PURE__ */n(le,{type:"button",variant:"outline",size:"xs",onClick:()=>v(!0),children:[/* @__PURE__ */e(bs,{className:"mr-1 h-3 w-3"})," View prompt"]}),/* @__PURE__ */n(le,{type:"button",variant:"ghost",size:"xs",onClick:()=>S(!0),children:[/* @__PURE__ */e(pu,{className:"mr-1 h-3 w-3"})," Paste code"]})]}),T?/* @__PURE__ */e(Lr,{"aria-label":"Paste visual HTML",placeholder:"Paste the HTML here",spellCheck:!1,className:"h-40 resize-y font-mono text-[11px] leading-[1.45]",onPaste:_=>{_.preventDefault();const k=_.clipboardData.getData("text/plain");k&&u({html:k});},value:"",onChange:()=>{}}):null]})]}),d&&d.slots.length?/* @__PURE__ */n("section",{className:"space-y-2",children:[/* @__PURE__ */e(Ct,{children:"Fields"}),d.slots.map(_=>{var R,I;const k=Em(c,_.kind),A=(R=s==null?void 0:s.slots)==null?void 0:R[_.id],$=A?(I=k.find(m=>Rm(m,A)))==null?void 0:I.key:void 0,C=((x==null?void 0:x.assigned.get(_.id))??[]).map(m=>{var M;return((M=c.find(g=>g.key===m))==null?void 0:M.label)??m;});return/* @__PURE__ */n("label",{className:"block space-y-1",children:[/* @__PURE__ */n("span",{className:"text-foreground",children:[_.label,_.optional?/* @__PURE__ */e("span",{className:"text-muted-foreground",children:" (optional)"}):null]}),/* @__PURE__ */n(te,{value:$??or,onValueChange:m=>{const M=k.find(g=>g.key===m);u({slots:{[_.id]:M?M.ref:null}});},children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-full","aria-label":_.label,children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */n(re,{children:[/* @__PURE__ */e(U,{value:or,children:C.length&&!$?`In order: ${C.join(", ")}`:"In order"}),k.map(m=>/* @__PURE__ */e(U,{value:m.key,children:m.label},m.key))]})]})]},_.id);})]}):null,d!=null&&d.settings&&Object.keys(d.settings).length?/* @__PURE__ */n("section",{className:"space-y-2",children:[/* @__PURE__ */e(Ct,{children:"Settings"}),Object.entries(d.settings).map(([_,k])=>{var A;return/* @__PURE__ */e(Am,{definition:k,value:(A=s==null?void 0:s.settings)==null?void 0:A[_],onChange:$=>u({settings:{[_]:$===void 0||$===k.default?null:$}})},_);})]}):null,F?/* @__PURE__ */e(Ts,{open:!0,onOpenChange:v,text:p(),withCode:!1}):null,/* @__PURE__ */e(Fm,{open:b,onOpenChange:y,onPick:K,card:a,result:i})]});}function Ct({children:t}){return/* @__PURE__ */e("div",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:t});}function Am({definition:t,value:a,onChange:s}){const r=a!==void 0&&typeof a==typeof t.default?a:t.default;if(t.type==="boolean")return/* @__PURE__ */n("label",{className:"flex items-center justify-between gap-3",children:[/* @__PURE__ */e("span",{className:"text-foreground",children:t.label}),/* @__PURE__ */e(Ne,{size:"xs",checked:!!r,onCheckedChange:l=>s(l),"aria-label":t.label})]});if(t.type==="select"||t.type==="color"){const l=t.type==="select"?t.options:[.../* @__PURE__ */new Set([...Ll,String(r)])].map(o=>({value:o,label:o}));return/* @__PURE__ */n("label",{className:"block space-y-1",children:[/* @__PURE__ */e("span",{className:"text-foreground",children:t.label}),/* @__PURE__ */n(te,{value:String(r),onValueChange:o=>s(o),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-full","aria-label":t.label,children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:l.map(o=>/* @__PURE__ */e(U,{value:o.value,children:o.label},o.value))})]})]});}return/* @__PURE__ */n("label",{className:"block space-y-1",children:[/* @__PURE__ */e("span",{className:"text-foreground",children:t.label}),/* @__PURE__ */e(ct,{size:"xs",type:t.type==="number"?"number":"text",defaultValue:String(r),...(t.type==="number"?{min:t.min,max:t.max,step:t.step}:{maxLength:t.maxLength}),onBlur:l=>{const o=l.target.value;if(t.type==="number"){const d=Number(o);o.trim()&&Number.isFinite(d)&&s(d);}else s(o);}},String(r))]});}function Rm(t,a){return a?"fieldId"in a?"fieldId"in t.ref&&t.ref.fieldId===a.fieldId:"column"in t.ref&&t.ref.column===a.column:!1;}const Lm={type:"number",minimumFractionDigits:0,maximumFractionDigits:0};function Pm(t){var a;return ru((a=t==null?void 0:t.sqlKpiValue)==null?void 0:a.format)||Lm;}function cr(t,a){const s=a?su(a):void 0,{format:r,...l}=t.sqlKpiValue??{},o=s?{...l,format:s}:l,{sqlKpiValue:d,...i}=t;return Object.keys(o).length?{...i,sqlKpiValue:o}:i;}function Dm(){var x,u;const t=E(f=>f.card),a=E(f=>f.actions.setCardPreferences),s=jc()??Bn.locale,r=Hc()??Bn.defaultCurrency,l=Ro(t)==="config",o=Pm(t.preferences),d=!!((u=(x=t.preferences)==null?void 0:x.sqlKpiValue)!=null&&u.format),i=f=>{const h=E.getState().card.preferences??{};a(cr(h,f));},c=f=>{const h=E.getState().card.preferences??{};a(cr(h,f?o:void 0));};return l?/* @__PURE__ */e(dr,{card:t}):/* @__PURE__ */n("div",{children:[/* @__PURE__ */n("div",{className:"mb-3 flex items-center gap-2",children:[/* @__PURE__ */e(jt,{id:"query-kpi-format-number",checked:d,onCheckedChange:f=>c(f===!0)}),/* @__PURE__ */e(P,{htmlFor:"query-kpi-format-number",className:"text-xs",children:"Format number"})]}),d&&/* @__PURE__ */n("div",{className:"flex flex-col gap-2",children:[/* @__PURE__ */e(ia,{formatOptions:o,onFormatOptionsChange:i,showTitle:!1,showAutoFormat:!1,reportDefaults:{currency:r,locale:s}}),/* @__PURE__ */e(Uc,{className:"my-3"})]}),/* @__PURE__ */e(dr,{card:t})]});}function dr({card:t}){const a=E(c=>c.actions.updateConditionalRules),{rules:s,onChange:r}=Hr(t.id,Tr(t),a),l=Pl(t),o=l==null?void 0:l.value,d=(l==null?void 0:l.source)==="config"?l.measure:void 0,i=o?[{value:Dl(o),label:d?d.label||d.alias||d.name:"Value"}]:[];return i.length?/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(Ur,{cardId:t.id}),/* @__PURE__ */e(Qr,{columnId:i[0].value,availableColumns:i,conditionalRules:s,onConditionalRulesChange:r,capabilities:{ruleKinds:["comparison"],automaticRanges:!1}})]}):null;}const _m={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 _m[t];}function Vm({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,l)=>/* @__PURE__ */n("tr",{className:l<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(Qc,{className:"h-3 w-3"})]})]}):null;}function Bm({chartType:t}){return Vs(t)?/* @__PURE__ */n(Tt,{openDelay:200,children:[/* @__PURE__ */e(kt,{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(Et,{className:"w-80 p-4",side:"left",align:"start",sideOffset:8,children:/* @__PURE__ */e(Vm,{chartType:t})})]}):null;}function Bs({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(Bm,{chartType:t})]});}function zm(){const t=E(l=>!Qt(l.card.config)),a=E(l=>{var o,d;return((d=(o=l.card.preferences)==null?void 0:o.sqlKpiValue)==null?void 0:d.comparisonPolarity)??pi;}),s=E(l=>l.actions.setCardPreferences),r=l=>{const o=E.getState().card;s(_l(o,{kind:"sqlKpiValue"},l).preferences??{});};return/* @__PURE__ */n("div",{className:"space-y-6 px-6 py-4",children:[/* @__PURE__ */e(Bs,{chartType:"kpi"}),/* @__PURE__ */e("section",{children:/* @__PURE__ */e(Dm,{})}),t&&/* @__PURE__ */n("section",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{htmlFor:"query-kpi-favorable-direction",className:"text-xs",children:"Favorable direction"}),/* @__PURE__ */n(te,{value:a,onValueChange:l=>r(l),children:[/* @__PURE__ */e(ae,{id:"query-kpi-favorable-direction",size:"xs",className:"w-full",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */n(re,{children:[/* @__PURE__ */e(U,{value:"higher_is_better",children:"Higher is better"}),/* @__PURE__ */e(U,{value:"lower_is_better",children:"Lower is better"}),/* @__PURE__ */e(U,{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 Km(t){return t.kind==="dashboard"?{kind:"inherit"}:t;}function zs(t,a){var s,r;return kr(t)&&((r=(s=t.config)==null?void 0:s.metricColumns)==null?void 0:r[0])===a;}function Ks(t,a){var r,l;const s=Fr({metricComparison:a.comparison,inheritGlobalComparison:(r=t.preferences)==null?void 0:r.inheritGlobalComparison,hidden:Mr((l=t.preferences)==null?void 0:l.comparisonPresentation)});return s.state==="follow"?{kind:"dashboard"}:s.state==="off"?{kind:"off"}:s.spec;}function qm({card:t,metric:a,options:s,dates:r,otherMetric:l,onChange:o}){var T,S;const{data:d}=He(t),i=d==null?void 0:d.metadata,c=(T=cs(i==null?void 0:i.comparisonMetadata,a))==null?void 0:T.output,x=Nn(),u=$m(i==null?void 0:i.dateContext,c==null?void 0:c.windowShape,x),f=(c==null?void 0:c.availability.status)==="available"&&c.comparisonWindow?Vd(c.comparisonWindow):void 0,h=zs(t,a)?{kind:"metric"}:Ks(t,a),p=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(Gc,{value:h,shape:u,dashboard:{offered:!0},target:{offered:s.comparison.target.offered,reason:p(s.comparison.target)},...(l?{otherMetric:l}:{}),shiftRefusal:p(s.comparison.shift),dates:h.kind==="shift"||h.kind==="dashboard"?f:void 0,onChange:b=>o(Km(b))}),N?/* @__PURE__ */e("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"A comparison replaces this metric's transform."}):null,h.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 $m(t,a,s){const r=(t==null?void 0:t.windows.filter(l=>!l.replaced))??[];return r.length===1?(r[0].relative?tr({kind:"relative",window:r[0].relative}):void 0)??(r[0].window?tr({kind:"resolved",window:r[0].window,calendar:s}):a):a;}function jm({card:t}){var x;const a=Nn(),s=Wc(t),r=be(u=>u.dashboard),l=be(u=>u.semanticExecutionPayload),{handleMetricComparisonChange:o}=fn(t),d=J(()=>du(t,jd(s,Hd(r,l,a)),a),[t,s,r,l,a]),i=((x=t.config)==null?void 0:x.metricColumns)??[],c=Vl("metric",i);return/* @__PURE__ */e("div",{className:"space-y-4",children:i.map((u,f)=>{const h=c[f]?Bl(t,c[f],d):void 0;if(!h||!Object.values(h.comparison).some(N=>N.offered))return null;const p=h.comparison.metric.offered?i[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(qm,{card:t,metric:u,options:h,dates:d,...(p?{otherMetric:{name:p.label||p.name}}:{}),onChange:N=>o(f,N,d)})]},u.id??f);})});}function ur({card:t}){var l;const{handleMetricComparisonPolarityChange:a}=fn(t),r=(((l=t.config)==null?void 0:l.metricColumns)??[]).map((o,d)=>({metric:o,index:d})).filter(({metric:o})=>zs(t,o)||Ks(t,o).kind!=="off");return r.length?/* @__PURE__ */e("div",{className:"space-y-2",children:r.map(({metric:o,index:d})=>/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(P,{className:"text-xs font-medium text-muted-foreground",children:r.length===1?"Higher is":`Higher is · ${o.label||o.name}`}),/* @__PURE__ */n(te,{value:ds(o),disabled:!!o.semanticComparisonPolarity,onValueChange:i=>a(d,i),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */n(re,{children:[/* @__PURE__ */e(U,{value:"higher_is_better",children:"Better"}),/* @__PURE__ */e(U,{value:"lower_is_better",children:"Worse"}),/* @__PURE__ */e(U,{value:"neutral",children:"Neither"})]})]}),o.semanticComparisonPolarity?/* @__PURE__ */e("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"Governed by this metric's semantic definition."}):null]},o.id??d))}):null;}const Hm={green:"#16a34a",red:"#dc2626",neutral:"#6b7280"};function Um(t){return t&&(Hm[t]??t);}function Qm({value:t,onChange:a,showPosition:s=!1,polarity:r,direction:l}){const o=t.colors||{},d=i=>r==="higher_is_better"?i?" (good)":" (bad)":r==="lower_is_better"?i?" (bad)":" (good)":"";return/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Shown as"}),/* @__PURE__ */e(Yc,{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:i=>a({displayMode:i})})]}),(t.displayMode||"difference")!=="difference"?/* @__PURE__ */n("div",{className:"flex items-center justify-between gap-3",children:[/* @__PURE__ */e("div",{children:/* @__PURE__ */e(P,{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:i=>{if(i.target.value===""){a({precision:void 0});return;}const c=Number(i.target.value);Number.isInteger(c)&&c>=0&&c<=6&&a({precision:c});},size:"xs",className:"w-16"})]}):null,/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{className:"text-xs font-medium text-muted-foreground",children:"Indicator"}),/* @__PURE__ */n(te,{value:t.indicatorStyle||"arrow_badge",onValueChange:i=>a({indicatorStyle:i}),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */n(re,{children:[/* @__PURE__ */e(U,{value:"arrow_badge",children:"Arrow + badge"}),/* @__PURE__ */e(U,{value:"arrow",children:"Arrow"}),/* @__PURE__ */e(U,{value:"badge",children:"Badge"}),/* @__PURE__ */e(U,{value:"none",children:"None"})]})]})]}),s&&/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{className:"text-xs",children:"Position"}),/* @__PURE__ */n(te,{value:t.position||"right",onValueChange:i=>a({position:i}),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-24",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */n(re,{children:[/* @__PURE__ */e(U,{value:"right",children:"Right"}),/* @__PURE__ */e(U,{value:"left",children:"Left"}),/* @__PURE__ */e(U,{value:"top",children:"Top"})]})]})]}),l,/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{htmlFor:"comparison-color",className:"text-xs",children:"Colors"}),/* @__PURE__ */e(Ne,{id:"comparison-color",size:"xs",checked:t.showColor!==!1,onCheckedChange:i=>a({showColor:i})})]}),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(([i,c,x])=>/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e("span",{className:"w-24 shrink-0 text-xs text-muted-foreground",children:c}),/* @__PURE__ */e(Ha,{value:Um(o[i]||x),onChange:u=>a({colors:{...o,[i]:u||x}}),defaultValue:x,ariaLabel:`${c} color`,allowEmpty:!1})]},i))}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{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(([i,c])=>{var x;return/* @__PURE__ */e(ct,{"aria-label":`${c} label`,value:((x=t.conditionalLabels)==null?void 0:x[i])||c,onChange:u=>a({conditionalLabels:{...t.conditionalLabels,[i]:u.target.value}}),size:"xs"},i);})}):/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(ct,{"aria-label":"Comparison label",value:t.labelName&&t.labelName!=="Previous"?t.labelName:"",onChange:i=>a({labelName:i.target.value}),placeholder:"The comparison's own words",size:"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(P,{htmlFor:"comparison-conditional-label",className:"text-xs",children:"Different label per direction"}),/* @__PURE__ */e(Ne,{id:"comparison-conditional-label",size:"xs",checked:t.conditionalLabel===!0,onCheckedChange:i=>a({conditionalLabel:i})})]})]})]});}function qs({cardType:t}){var f,h;const a=E(p=>p.card),{setCardPreferences:s}=he(),r=((f=a.config)==null?void 0:f.metricColumns)||[],l=((h=a.preferences)==null?void 0:h.comparisonPresentation)||{},o=p=>s(Kl(a.preferences,p)),d=Mr(l),i=kr({...a,type:t}),c=r.filter(p=>{var N;return Fr({metricComparison:p.comparison,inheritGlobalComparison:(N=a.preferences)==null?void 0:N.inheritGlobalComparison,hidden:d}).state!=="off";}),x=c.length>0||i,u=zl.includes(t);return/* @__PURE__ */n("div",{className:"space-y-4",children:[/* @__PURE__ */e(jm,{card:a}),x&&u?/* @__PURE__ */e(Qm,{value:l,onChange:o,showPosition:i,direction:/* @__PURE__ */e(ur,{card:a}),polarity:ds((i?r[0]:c[0])??r[0])}):x?/* @__PURE__ */e(ur,{card:a}):null]});}function Gm(){const t=Ke();return ql.includes(t)?/* @__PURE__ */n(we,{value:"comparison",className:"border-none",children:[/* @__PURE__ */e(Se,{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(Xc,{className:"h-3.5 w-3.5 text-foreground/60"}),/* @__PURE__ */e("span",{children:"Comparison"})]})}),/* @__PURE__ */e(Te,{className:"pb-4 pt-2",children:/* @__PURE__ */e(qs,{cardType:t})})]}):null;}const Wm={surface:"dashboard",kind:"table"};function $s({cardType:t,queryOutput:a,focusSection:s,focusRequestId:r}){var ie,Y;const l=E(H=>H.card),o=E(H=>H.queryResultColumns),d=E(H=>H.queryResultColumnKeyMap),i=E(H=>{var X;return(X=H.card)==null?void 0:X.preferences;}),c=i==null?void 0:i.tablePrefs,x=E(H=>H.actions.setCardPreferences),u=E(H=>H.queryResultColumnMeta),f=t??l.type,h=a?[...(a.keys??[])]:o,p=a?a.columnKeyMap:d,N=a?a.resultColumns:u,T=l.type===f?l:{...l,type:f},S=Lo(T,h,p,N),b=Po(T,h),y=f==="matrixTable"||Do(f),F=f==="table",v=f==="table",D=l?er(l):[],K=!!l&&er({...l,type:f}).includes("columns"),j=D.includes("columnFilters"),_=D.includes("search"),k=v||K||j,A=((ie=S[0])==null?void 0:ie.value)||"",$=$l(T),C=jl(T),[R,I]=G("style");ye(()=>{if(s==="style"){I("style");return;}if(s==="columns"&&k){I("columns");return;}s==="conditional-formatting"&&y&&I("conditional-formatting");},[k,y,r,s]);const m=l?Hl(l):!1,M=H=>{x({...i,tablePrefs:{...c,tableStyle:{...(c==null?void 0:c.tableStyle),wrapText:H}}});},{style:g}=Jc(Wm),w=(H,X)=>{x(Dn(i,{measures:{[H]:X}}));},O=H=>{x(Dn(i,{row:H}));},q=(H,X)=>{x(Ql({preferences:i},H,{hidden:!X}).preferences??{});},z=H=>{x(ka(i,"columns",H));},L=H=>{x(ka(i,"columnFilters",H));},V=H=>{x(ka(i,"search",H));},W=()=>{x(Gl({preferences:i}).preferences??{});},ee=m?/* @__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(qs,{cardType:"table"})]}):null;return/* @__PURE__ */e("div",{className:"px-4 py-3",children:/* @__PURE__ */n(ft,{value:R,onValueChange:H=>I(H),className:"space-y-4",children:[/* @__PURE__ */n(gt,{variant:"underline",children:[/* @__PURE__ */e(ze,{value:"style",children:"Appearance"}),k?/* @__PURE__ */e(ze,{value:"columns",children:"Columns"}):null,/* @__PURE__ */e(ze,{value:"conditional-formatting",disabled:!y,children:"Conditional formatting"})]}),/* @__PURE__ */n(Qe,{value:"style",className:"mt-0",children:[F?/* @__PURE__ */e(_o,{wrapText:((Y=c==null?void 0:c.tableStyle)==null?void 0:Y.wrapText)??g.cell.wrap,onWrapTextChange:M,totals:$?{enabled:C,onEnabledChange:O,measures:Ul(T),onMeasureTotalChange:w}:void 0,extraSection:ee}):ee,f==="matrixTable"&&/* @__PURE__ */e(Ua,{section:"table"})]}),/* @__PURE__ */n(Qe,{value:"columns",className:"mt-0 space-y-4",children:[K?/* @__PURE__ */n("div",{className:"flex items-start justify-between gap-3",children:[/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */e(P,{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(Ne,{id:"allow-viewer-column-customization",size:"xs",checked:(c==null?void 0:c.allowViewerColumnCustomization)!==!1,onCheckedChange:z})]}):null,j?/* @__PURE__ */n("div",{className:"flex items-start justify-between gap-3",children:[/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */e(P,{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:[f==="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(Ne,{id:"allow-viewer-column-filters",size:"xs",checked:(c==null?void 0:c.allowViewerColumnFilters)!==!1,onCheckedChange:L})]}):null,_?/* @__PURE__ */n("div",{className:"flex items-start justify-between gap-3",children:[/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */e(P,{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(Ne,{id:"allow-viewer-search",size:"xs",checked:(c==null?void 0:c.allowViewerSearch)!==!1,onCheckedChange:V})]}):null,v?/* @__PURE__ */e(Vo,{columns:b,columnVisibility:c==null?void 0:c.columnVisibility,onColumnVisibilityChange:q,onShowAllColumns:W}):null]}),/* @__PURE__ */e(Qe,{value:"conditional-formatting",className:"mt-0",children:f==="matrixTable"?/* @__PURE__ */e(Ua,{section:"conditional-formatting"}):y?A?/* @__PURE__ */e(Ym,{columnId:A,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 Ym({columnId:t,availableColumns:a}){const s=E(d=>d.card),r=E(d=>d.actions.updateConditionalRules),{rules:l,onChange:o}=Hr(s.id,Tr(s),r);return/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(Ur,{cardId:s.id}),/* @__PURE__ */e(Qr,{columnId:t,availableColumns:a,conditionalRules:l,onConditionalRulesChange:o,startRulesWithNoTrigger:!0})]});}function Xm(){var l;const t=E(o=>o.card.preferences),{setCardPreferences:a}=E(o=>o.actions),s=(l=t==null?void 0:t.textVisualOptions)!=null&&l.isDynamicText?"dynamic":"static";function r(o){a({...t,textVisualOptions:{...(t==null?void 0:t.textVisualOptions),isDynamicText:o==="dynamic"}});}return/* @__PURE__ */e(ft,{value:s,onValueChange:r,children:/* @__PURE__ */n(gt,{variant:"underline",children:[/* @__PURE__ */e(ze,{value:"static",children:"Static"}),/* @__PURE__ */e(ze,{value:"dynamic",children:"Dynamic"})]})});}function Jm(){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(Xm,{}),/* @__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 Zm({color:t,onColorChange:a,onClose:s}){const[r,l]=G(0),[o,d]=G(100),[i,c]=G(50),[x,u]=G(t);ye(()=>{const S=mr(t);if(S){const b=hr(S.r,S.g,S.b);l(b.h),d(b.s),c(b.l),u(t);}},[t]);const f=S=>{l(S),p(S,o,i);},h=S=>{const b=S.currentTarget.getBoundingClientRect(),y=Math.max(0,Math.min(1,(S.clientX-b.left)/b.width)),F=Math.max(0,Math.min(1,(S.clientY-b.top)/b.height)),v=y*100,D=(1-F)*100;d(v),c(D),p(r,v,D);},p=(S,b,y)=>{const F=th(S,b,y),v=eh(F.r,F.g,F.b);u(v);},N=S=>{if(u(S),/^#[0-9A-Fa-f]{6}$/.test(S)){const b=mr(S);if(b){const y=hr(b.r,b.g,b.b);l(y.h),d(y.s),c(y.l);}}},T=()=>{/^#[0-9A-Fa-f]{6}$/.test(x)&&(a(x),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:h,onMouseMove:S=>{S.buttons===1&&h(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:`${o}%`,top:`${100-i}%`,backgroundColor:x}})]}),/* @__PURE__ */e("div",{className:"space-y-2",children:/* @__PURE__ */e("input",{type:"range",min:"0",max:"360",value:r,onChange:S=>f(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(P,{children:"HEX"}),/* @__PURE__ */e(ct,{value:x,onChange:S=>N(S.target.value),placeholder:"#000000",size:"xs",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:x}}),/* @__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(le,{variant:"outline",onClick:s,children:"Cancel"}),/* @__PURE__ */e(le,{onClick:T,children:"OK"})]})]});}function mr(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 eh(t,a,s){return"#"+((1<<24)+(t<<16)+(a<<8)+s).toString(16).slice(1);}function hr(t,a,s){t/=255,a/=255,s/=255;const r=Math.max(t,a,s),l=Math.min(t,a,s);let o=0,d=0;const i=(r+l)/2;if(r!==l){const c=r-l;switch(d=i>0.5?c/(2-r-l):c/(r+l),r){case t:o=((a-s)/c+(a<s?6:0))/6;break;case a:o=((s-t)/c+2)/6;break;case s:o=((t-a)/c+4)/6;break;}}return{h:Math.round(o*360),s:Math.round(d*100),l:Math.round(i*100)};}function th(t,a,s){t/=360,a/=100,s/=100;let r,l,o;if(a===0)r=l=o=s;else{const d=(x,u,f)=>(f<0&&(f+=1),f>1&&(f-=1),f<0.16666666666666666?x+(u-x)*6*f:f<0.5?u:f<0.6666666666666666?x+(u-x)*(0.6666666666666666-f)*6:x),i=s<0.5?s*(1+a):s+a-s*a,c=2*s-i;r=d(c,i,t+1/3),l=d(c,i,t),o=d(c,i,t-1/3);}return{r:Math.round(r*255),g:Math.round(l*255),b:Math.round(o*255)};}const ah=["#000000","#ffffff","#6b7280","#dc2626","#ea580c","#ca8a04","#16a34a","#0891b2","#2563eb","#7c3aed","#c026d3","#e11d48","#0f172a","#f3f4f6","#fbbf24"];function nh(){var D,K,j,_,k,A,$,C,R,I;const t=E(m=>m.card),a=E(m=>{var M;return(M=m.card)==null?void 0:M.preferences;}),s=Ke(),{setCardPreferences:r,updateCardInFrame:l}=he(),o=J(()=>s!==t.type?{...t,type:s}:t,[t,s]),{data:d}=He(o),[i,c]=G({}),[x,u]=G(null),[f,h]=G(null),p=J(()=>{var w,O,q,z,L,V,W;if(!(d!=null&&d.records)||d.records.length===0)return[];const m=s==="stackedBar"||s==="stackedLine",M=s==="bar"||s==="line"||s==="horizontalBar"||s==="bullet"||s==="combo"||s==="area"||s==="stackedArea",g=((w=t==null?void 0:t.config)==null?void 0:w.pivotByColumns)&&t.config.pivotByColumns.length>0;if((m||M)&&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),Y=/* @__PURE__ */new Set();(O=t==null?void 0:t.config)!=null&&O.groupByColumns&&t.config.groupByColumns.forEach(de=>{Y.add(de.label||de.name),Y.add(de.alias||de.name);});const H=/* @__PURE__ */new Set();return(q=t==null?void 0:t.config)!=null&&q.metricColumns&&t.config.metricColumns.forEach(de=>{const pe=de.alias||de.name;H.add(pe),H.add(`${pe}_count`),H.add(`${pe}_sum`),H.add(`${pe}_avg`),H.add(`${pe}_min`),H.add(`${pe}_max`);const oe=de.entityName||de.qualifiedEntityName;oe&&(H.add(`${oe}_${pe}`),H.add(`${oe}_${pe}_count`));}),ie.filter(de=>!Y.has(de)&&!H.has(de));}}if((M||m)&&!g&&(L=(z=t==null?void 0:t.config)==null?void 0:z.metricColumns)!=null&&L.length)return t.config.metricColumns.map(ee=>ee.alias||ee.label||ee.name);if((W=(V=t==null?void 0:t.config)==null?void 0:V.groupByColumns)!=null&&W.length){const ee=t.config.groupByColumns[0],ie=ee.label||ee.name,Y=/* @__PURE__ */new Set();return d.records.forEach(H=>{const X=H[ie];X!=null&&Y.add(String(X));}),Array.from(Y);}return[];},[d,(D=t==null?void 0:t.config)==null?void 0:D.groupByColumns,(K=t==null?void 0:t.config)==null?void 0:K.pivotByColumns,(j=t==null?void 0:t.config)==null?void 0:j.metricColumns,s]),N=vn().palette;ye(()=>{const m={};p.forEach((M,g)=>{m[M]=Jn(M,g,N,a==null?void 0:a.colorConfig);}),c(m);},[p,a==null?void 0:a.colorConfig,N]);const T=(m,M)=>{var q;const g={...i,[m]:M};c(g);const w={...(a||{}),colorConfig:{...(a==null?void 0:a.colorConfig),segments:{...((q=a==null?void 0:a.colorConfig)==null?void 0:q.segments),[m]:M}}};r(w);const O={...t,preferences:w};l(O);},S=(m,M)=>{var L;const g=N[M%N.length],{[m]:w,...O}=((L=a==null?void 0:a.colorConfig)==null?void 0:L.segments)||{},q={...(a||{}),colorConfig:{segments:O}};r(q);const z={...t,preferences:q};l(z),c(V=>({...V,[m]:g}));};if(!p.length||!((t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine"?((k=(_=t==null?void 0:t.config)==null?void 0:_.groupByColumns)==null?void 0:k.length)||(($=(A=t==null?void 0:t.config)==null?void 0:A.pivotByColumns)==null?void 0:$.length):(R=(C=t==null?void 0:t.config)==null?void 0:C.groupByColumns)==null?void 0:R.length)||["table","kpi","text","custom","heatmap"].includes(s))return null;const F=()=>{const m={...(a||{}),colorConfig:{segments:{}}};r(m);const M={...t,preferences:m};l(M);const g={};p.forEach((w,O)=>{g[w]=Jn(w,O,N);}),c(g);},v=Object.keys(((I=a==null?void 0:a.colorConfig)==null?void 0:I.segments)||{}).length>0;return/* @__PURE__ */n(we,{value:"colors",className:"border-b-0",children:[/* @__PURE__ */e(Se,{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(uu,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Colors"})]})}),/* @__PURE__ */e(Te,{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:v&&/* @__PURE__ */n("button",{className:"ml-auto flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",onClick:F,children:[/* @__PURE__ */e(Ya,{className:"h-3 w-3"}),"Reset All"]})})}),/* @__PURE__ */e("div",{className:"max-h-[200px] space-y-2 overflow-y-auto pr-1",children:p.map((m,M)=>{const g=i[m]===N[M%N.length],w=!g;return/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */n(lt,{open:x===m,onOpenChange:O=>u(O?m: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:i[m]}})}),/* @__PURE__ */e(it,{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((O,q)=>/* @__PURE__ */n("button",{className:Q("relative h-5 w-5 rounded border-2 transition-all hover:scale-110",i[m]===O?"border-gray-900":"border-transparent"),style:{backgroundColor:O},onClick:()=>{T(m,O),u(null);},children:[q===M%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:O})]},`default-${q}`))})]}),/* @__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:ah.map((O,q)=>/* @__PURE__ */e("button",{className:Q("h-5 w-5 rounded border transition-all hover:scale-110",i[m]===O?"border-2 border-gray-900":O==="#ffffff"?"border border-gray-300":"border border-transparent"),style:{backgroundColor:O},onClick:()=>{T(m,O),u(null);},children:/* @__PURE__ */e("span",{className:"sr-only",children:O})},`preset-${q}`))})]}),/* @__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:()=>{h({value:m,color:i[m]}),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(m,M),u(null);},children:[/* @__PURE__ */e(Ya,{className:"h-3 w-3"}),"Reset"]})]})]})})]}),/* @__PURE__ */e("span",{className:"flex-1 truncate text-sm",children:m}),w&&/* @__PURE__ */e("span",{className:"text-xs text-muted-foreground",children:"(custom)"})]},m);})}),f&&/* @__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:()=>h(null)}),/* @__PURE__ */e("div",{className:"relative rounded-lg bg-white shadow-lg",children:/* @__PURE__ */e(Zm,{color:f.color,onColorChange:m=>{T(f.value,m),h(null);},onClose:()=>h(null)})})]})]})})]});}function _a({axis:t,label:a,type:s,config:r,onChange:l,defaultTitle:o,hidePosition:d}){var S,b,y,F,v,D,K,j,_,k,A,$,C,R;const[i,c]=G(!!(r!=null&&r.valueFormat)),x=i||!!(r!=null&&r.valueFormat),u=(I,m)=>{l({...(r??{}),[I]:m});},f=(I,m)=>{var w;const g=I==="enabled"&&m===!0&&!((w=r==null?void 0:r.name)!=null&&w.text)&&o;l(Yl(r,{[I]:m,...(g?{text:o}:{})}));},h=(I,m)=>{var M,g;l({...(r??{}),labels:{enabled:I==="enabled"?m:((M=r==null?void 0:r.labels)==null?void 0:M.enabled)??!0,rotation:I==="rotation"?m:(g=r==null?void 0:r.labels)==null?void 0:g.rotation}});},p=(I,m)=>{l(Xl(r,{[I]:m===""?null:Number(m)}));},N=t==="x"?["auto","top","bottom"]:["auto","left","right"],T=["auto","0","45","90","-45","-90"];return/* @__PURE__ */n(we,{value:`${t}-axis`,className:"border-b-0",children:[/* @__PURE__ */n("div",{className:"flex w-full items-center justify-between gap-2",children:[/* @__PURE__ */e(Se,{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(Ne,{size:"sm",checked:(r==null?void 0:r.enabled)!==!1,onCheckedChange:I=>u("enabled",I),onClick:I=>I.stopPropagation()})]}),/* @__PURE__ */n(Te,{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(jt,{id:`${t}-title-enabled`,checked:((S=r==null?void 0:r.name)==null?void 0:S.enabled)??!1,onCheckedChange:I=>f("enabled",I===!0)}),/* @__PURE__ */e(P,{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:I=>f("text",I),className:""}),/* @__PURE__ */n("div",{className:"flex items-center gap-3",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(P,{className:"text-xs text-muted-foreground",children:"Size"}),/* @__PURE__ */e("div",{className:"w-14",children:/* @__PURE__ */e(Ze,{type:"number",placeholder:"12",value:String(((F=r==null?void 0:r.name)==null?void 0:F.fontSize)||12),onSave:I=>f("fontSize",Number(I)||12),className:""})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(P,{className:"text-xs text-muted-foreground",children:"Weight"}),/* @__PURE__ */n(te,{value:((v=r==null?void 0:r.name)==null?void 0:v.fontWeight)||"normal",onValueChange:I=>f("fontWeight",I),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-20",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */n(re,{children:[/* @__PURE__ */e(U,{value:"normal",className:"text-xs",children:"Normal"}),/* @__PURE__ */e(U,{value:"bold",className:"text-xs",children:"Bold"})]})]})]})]})]})]}),!d&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(P,{className:"text-xs font-medium",children:"POSITION"}),/* @__PURE__ */n(te,{value:(r==null?void 0:r.position)||"auto",onValueChange:I=>u("position",I),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:N.map(I=>/* @__PURE__ */e(U,{value:I,className:"text-xs",children:I==="auto"?"Auto (Default)":Xe(I)},I))})]})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{className:"text-xs font-medium",children:"LABELS"}),/* @__PURE__ */e(Ne,{size:"sm",checked:((D=r==null?void 0:r.labels)==null?void 0:D.enabled)!==!1,onCheckedChange:I=>h("enabled",I)})]}),((K=r==null?void 0:r.labels)==null?void 0:K.enabled)!==!1&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(P,{className:"text-xs text-muted-foreground",children:"Rotation"}),/* @__PURE__ */n(te,{value:String(((j=r==null?void 0:r.labels)==null?void 0:j.rotation)||"auto"),onValueChange:I=>h("rotation",I==="auto"?"auto":Number(I)),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:T.map(I=>/* @__PURE__ */e(U,{value:I,className:"text-xs",children:I==="auto"?"Auto (Default)":`${I}°`},I))})]})]})]}),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(P,{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(Ne,{size:"sm",checked:x,onCheckedChange:I=>{if(c(I),!I){const{valueFormat:m,...M}=r??{};l(M);}}})]}),x&&/* @__PURE__ */e(ia,{formatOptions:Tn(r==null?void 0:r.valueFormat)||{},onFormatOptionsChange:I=>l({...r,valueFormat:kn(I)}),showTitle:!1})]}),s==="value"&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(P,{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(P,{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:((_=r==null?void 0:r.scale)==null?void 0:_.min)==="auto"||((k=r==null?void 0:r.scale)==null?void 0:k.min)===void 0?"":String(r.scale.min),onSave:I=>p("min",I),className:""})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(P,{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:((A=r==null?void 0:r.scale)==null?void 0:A.max)==="auto"||(($=r==null?void 0:r.scale)==null?void 0:$.max)===void 0?"":String(r.scale.max),onSave:I=>p("max",I),className:""})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(P,{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:((C=r==null?void 0:r.scale)==null?void 0:C.stepSize)==="auto"||((R=r==null?void 0:r.scale)==null?void 0:R.stepSize)===void 0?"":String(r.scale.stepSize),onSave:I=>p("stepSize",I),className:""})})]})]})]})]})]});}function Va(t,a,s){var o,d,i;if(t==="x"){const c=(d=(o=a==null?void 0:a.config)==null?void 0:o.groupByColumns)==null?void 0:d[0];return(c==null?void 0:c.label)||(c==null?void 0:c.name)||"";}const r=((i=a==null?void 0:a.config)==null?void 0:i.metricColumns)||[],l=(s==null?void 0:s.datasetOptions)||[];if(t==="y"){const c=r.filter((x,u)=>{const f=l.find(h=>h.idx===u);return!f||f.yAxisId!=="y2";});return c.length===1&&(c[0].label||c[0].name)||"";}if(t==="y2"){const c=r.filter((x,u)=>{const f=l.find(h=>h.idx===u);return(f==null?void 0:f.yAxisId)==="y2";});return c.length===1&&(c[0].label||c[0].name)||"";}return"";}function rh(){const t=E(c=>c.card),a=E(c=>{var x;return(x=c.card)==null?void 0:x.preferences;}),{setCardPreferences:s,updateCardInFrame:r}=he(),l=Ke();if(!t||["tornado","pyramid","kpi","treemap"].includes(l))return null;const o=Zc.getAxisInfo(l,a);if(!o.hasXAxis&&!o.hasYAxis)return null;const d=(c,x)=>{let u;c==="x"?u="xAxisConfig":c==="y"?u="yAxisConfig":u="secondaryYAxisConfig";const f=Wl(a,u,x);s(f);const h={...t,preferences:f};r(h);},i=o.hasY2Axis&&l==="combo";return/* @__PURE__ */n(we,{value:"axes",className:"border-b-0",children:[/* @__PURE__ */e(Se,{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(ra,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Axes"})]})}),/* @__PURE__ */e(Te,{className:"pt-2",children:/* @__PURE__ */n(la,{type:"single",collapsible:!0,className:"w-full",children:[o.hasXAxis&&/* @__PURE__ */e(_a,{axis:"x",label:"X-Axis",type:o.xAxisType,config:Sa(Zn(l,"x"),a==null?void 0:a.xAxisConfig),onChange:c=>d("x",c),defaultTitle:Va("x",t,a)}),o.hasYAxis&&/* @__PURE__ */e(_a,{axis:"y",label:i?"Y-Axis (Left)":"Y-Axis",type:o.yAxisType,config:Sa(Zn(l,"y"),a==null?void 0:a.yAxisConfig),onChange:c=>d("y",c),defaultTitle:Va("y",t,a)}),i&&/* @__PURE__ */e(_a,{axis:"y2",label:"Y2-Axis (Right)",type:"value",config:Sa({enabled:!0,position:"right"},a==null?void 0:a.secondaryYAxisConfig),onChange:c=>d("y2",c),defaultTitle:Va("y2",t,a),hidePosition:!0})]})})]});}function sh(){const t=E(f=>f.card),a=Ke(),s=E(f=>{var h,p,N,T;return(T=(N=(p=(h=f.card)==null?void 0:h.preferences)==null?void 0:p.chartOptions)==null?void 0:N.plugins)==null?void 0:T.legend;}),{setLegendOptions:r}=he();if(!t||!ed(a))return null;const l=td(a),o=(l==null?void 0:l.display)??!0,d=(l==null?void 0:l.position)??"top",i=(l==null?void 0:l.align)??"center",c=(f,h)=>{const p={...s,[f]:h};r(p);},x=["top","bottom","left","right"],u=["start","center","end"];return/* @__PURE__ */n(we,{value:"legend",className:"border-b-0",children:[/* @__PURE__ */e(Se,{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(Bo,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Legend"})]})}),/* @__PURE__ */e(Te,{className:"pt-2",children:/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{className:"text-xs font-medium",children:"Display"}),/* @__PURE__ */e(Ne,{size:"sm",checked:(s==null?void 0:s.display)??o,onCheckedChange:f=>c("display",f)})]}),((s==null?void 0:s.display)??o)&&/* @__PURE__ */n(xe,{children:[/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(P,{className:"text-xs font-medium",children:"Position"}),/* @__PURE__ */n(te,{value:(s==null?void 0:s.position)||d,onValueChange:f=>c("position",f),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:x.map(f=>/* @__PURE__ */e(U,{value:f,className:"text-xs",children:Xe(f)},f))})]})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(P,{className:"text-xs font-medium",children:"Alignment"}),/* @__PURE__ */n(te,{value:(s==null?void 0:s.align)||i,onValueChange:f=>c("align",f),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:u.map(f=>/* @__PURE__ */e(U,{value:f,className:"text-xs",children:Xe(f)},f))})]})]})]})]})})]});}function lh(){var R,I,m,M,g;const t=E(w=>w.card),a=Ke(),s=E(w=>{var O,q;return(q=(O=w.card)==null?void 0:O.preferences)==null?void 0:q.dataLabelsConfig;}),r=E(w=>{var O;return(O=w.card)==null?void 0:O.preferences;}),{setCardPreferences:l,updateCardInFrame:o}=he(),[d,i]=G(!!(s!=null&&s.valueFormat));if(!t||!Jl(a))return null;const c=a==="bullet"?((R=r==null?void 0:r.bulletConfig)==null?void 0:R.orientation)??(((I=r==null?void 0:r.chartOptions)==null?void 0:I.indexAxis)==="x"?"vertical":"horizontal"):void 0,x=c!=null?c==="horizontal":((m=r==null?void 0:r.chartOptions)==null?void 0:m.indexAxis)==="y",u=a==="stackedBar"||a==="stackedLine",f=a==="pie"||a==="doughnut"||a==="polarArea"||a==="funnel",h=a==="bubble"||a==="scatter",p=Zl(a,t.preferences),N=s??p,T=ei(a,t.preferences),S=(s==null?void 0:s.enabled)!==void 0?s.enabled:T,b=(w,O)=>{const z=(w==="enabled"?_n({type:a,preferences:t.preferences},{show:O}).dataLabelsConfig:void 0)??{...Vn(s,p),[w]:O};w==="enabled"&&O&&h&&!z.position&&(z.position="bottom"),w==="position"&&h&&(z.position="bottom");const L={...(t.preferences||{}),dataLabelsConfig:z};l(L);const V={...t,preferences:L};o(V);},y=(w,O)=>{const q={...Vn(s,p),font:{...((s==null?void 0:s.font)||{}),[w]:O}},z={...(t.preferences||{}),dataLabelsConfig:q};l(z);const L={...t,preferences:z};o(L);},F=()=>{const w=a;return w==="stackedBar"||w==="stackedLine"||w==="pie"||w==="doughnut"?"center":x?"right":"top";},v=a!=="treemap"&&a!=="heatmap",D=a!=="treemap",K=F();let j=[];if(v)if(h)j=["bottom"];else if(u||f)j=["center"];else{const w=x?["center","left","right"]:["center","top","bottom"];j=["auto",...(a==="bullet"?w:w.filter(q=>q!==K)),"custom"];}const _=()=>Xe(K),k=["center","start","end"],A=["center","start","end","top","bottom"],$=d||!!(N!=null&&N.valueFormat),C=w=>{const O=_n({type:a,preferences:t.preferences},{format:w??null});l(O),o({...t,preferences:O});};return/* @__PURE__ */n(we,{value:"data-labels",className:"border-b-0",children:[/* @__PURE__ */e(Se,{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(Tu,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Data Labels"})]})}),/* @__PURE__ */e(Te,{className:"pt-2",children:/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{className:"text-xs font-medium",children:"Display"}),/* @__PURE__ */e(Ne,{size:"sm",checked:S,onCheckedChange:w=>b("enabled",w)})]}),S&&/* @__PURE__ */n(xe,{children:[v&&!u&&!f&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(P,{className:"text-xs font-medium",children:"Position"}),/* @__PURE__ */n(te,{value:h?(N==null?void 0:N.position)||"bottom":(N==null?void 0:N.position)||"auto",onValueChange:w=>b("position",w),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:j.map(w=>/* @__PURE__ */e(U,{value:w,className:"text-xs",children:w==="auto"?_():w==="custom"?"Custom (Advanced)":Xe(w)},w))})]})]}),u&&/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{className:"text-xs font-medium",children:"Show Total"}),/* @__PURE__ */e(Ne,{size:"sm",checked:(s==null?void 0:s.showTotal)??!1,onCheckedChange:w=>b("showTotal",w)})]}),(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(P,{className:"text-xs text-muted-foreground w-16",children:"Anchor"}),/* @__PURE__ */n(te,{value:(N==null?void 0:N.anchor)||"center",onValueChange:w=>b("anchor",w),children:[/* @__PURE__ */e(ae,{size:"xs",className:"flex-1",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:k.map(w=>/* @__PURE__ */e(U,{value:w,className:"text-xs",children:Xe(w)},w))})]})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(P,{className:"text-xs text-muted-foreground w-16",children:"Align"}),/* @__PURE__ */n(te,{value:String((N==null?void 0:N.align)||"center"),onValueChange:w=>b("align",w),children:[/* @__PURE__ */e(ae,{size:"xs",className:"flex-1",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:A.map(w=>/* @__PURE__ */e(U,{value:w,className:"text-xs",children:Xe(w)},w))})]})]})]}),/* @__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(P,{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(Ne,{size:"sm",checked:$,onCheckedChange:w=>{i(w),w||C(void 0);}})]}),$&&/* @__PURE__ */e(ia,{formatOptions:Tn(N==null?void 0:N.valueFormat)||{},onFormatOptionsChange:w=>C(kn(w)),showTitle:!1})]}),D&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(P,{className:"text-xs font-medium",children:"Appearance"}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(P,{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(((M=N==null?void 0:N.font)==null?void 0:M.size)||12),onSave:w=>y("size",Number(w)),className:""})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(P,{className:"text-xs text-muted-foreground w-20",children:"Weight"}),/* @__PURE__ */n(te,{value:((g=N==null?void 0:N.font)==null?void 0:g.weight)||"normal",onValueChange:w=>y("weight",w),children:[/* @__PURE__ */e(ae,{size:"xs",className:"flex-1",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */n(re,{children:[/* @__PURE__ */e(U,{value:"normal",className:"text-xs",children:"Normal"}),/* @__PURE__ */e(U,{value:"bold",className:"text-xs",children:"Bold"})]})]})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(P,{className:"text-xs text-muted-foreground w-20",children:"Color"}),/* @__PURE__ */n(te,{value:(N==null?void 0:N.color)==="auto"||!(N!=null&&N.color)?"auto":"custom",onValueChange:w=>{w==="auto"&&b("color","auto");},children:[/* @__PURE__ */e(ae,{size:"xs",className:"flex-1",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */n(re,{children:[/* @__PURE__ */e(U,{value:"auto",className:"text-xs",children:"Auto (Smart Contrast)"}),/* @__PURE__ */e(U,{value:"custom",disabled:!0,className:"text-xs",children:"Custom (Coming Soon)"})]})]})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(P,{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:w=>b("rotation",Number(w)),className:""})}),/* @__PURE__ */e("span",{className:"text-xs text-muted-foreground",children:"degrees"})]})]})]})]})})]});}function ih(){var o;const t=E(d=>{var i;return(i=d.card)==null?void 0:i.type;}),a=E(d=>{var i;return(i=d.card)==null?void 0:i.preferences;}),{setCardPreferences:s}=he();if(t!=="treemap")return null;const r=((o=a==null?void 0:a.chartOptions)==null?void 0:o.treemapColorMode)??"branch",l=d=>{const i={...(a||{}),chartOptions:{...(a==null?void 0:a.chartOptions),treemapColorMode:d}};s(i);};return/* @__PURE__ */n(we,{value:"treemap-color-mode",className:"border-none",children:[/* @__PURE__ */e(Se,{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(zr,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Treemap Colors"})]})}),/* @__PURE__ */e(Te,{className:"space-y-4 border-t border-border bg-background/50 px-3 py-4 text-sm",children:/* @__PURE__ */n(Cn,{value:r,onValueChange:d=>l(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(Ut,{id:"treemap-color-branch",value:"branch"}),/* @__PURE__ */n(P,{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(Ut,{id:"treemap-color-category",value:"category"}),/* @__PURE__ */n(P,{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 oh=Object.keys(is);function ch(){const t=E(h=>h.card),a=E(h=>{var p;return(p=h.card)==null?void 0:p.preferences;}),{setCardPreferences:s}=he(),r=(t==null?void 0:t.type)==="heatmap",l=(a==null?void 0:a.heatmapConfig)||{},o=l.colorPalette??"green",d=l.legendPosition??"bottom",i=J(()=>l.colorRange&&l.colorRange[0]&&l.colorRange[1]?[l.colorRange[0],l.colorRange[1]]:[...Ta],[l.colorRange]),c=h=>{const p={...l,...h};p.colorPalette!=="custom"?delete p.colorRange:(!p.colorRange||!p.colorRange[0]||!p.colorRange[1])&&(p.colorRange=[...Ta]),s({...(a||{}),heatmapConfig:p});},x=h=>{c({colorPalette:h,colorRange:h==="custom"?l.colorRange??[...Ta]:void 0});},u=(h,p)=>{const N=[...i];N[h]=p,c({colorPalette:"custom",colorRange:N});},f=h=>{c({legendPosition:h});};return r?/* @__PURE__ */n(we,{value:"heatmap-color-config",className:"border-none",children:[/* @__PURE__ */e(Se,{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(na,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Heatmap Settings"})]})}),/* @__PURE__ */n(Te,{className:"space-y-4 border-t border-border bg-background/50 px-3 py-4 text-sm",children:[/* @__PURE__ */n(Cn,{value:o,onValueChange:h=>x(h??"blue"),className:"space-y-3",children:[oh.map(h=>{const p=is[h];return/* @__PURE__ */n("div",{className:"flex items-center gap-2 rounded-md border border-border px-3 py-2",children:[/* @__PURE__ */e(Ut,{id:`heatmap-${h}`,value:h}),/* @__PURE__ */n(P,{htmlFor:`heatmap-${h}`,className:"flex w-full flex-col gap-1 text-sm font-normal",children:[/* @__PURE__ */e("span",{className:"font-medium",children:p.label}),/* @__PURE__ */e("span",{className:"h-2 rounded-full",style:{background:`linear-gradient(90deg, ${p.start}, ${p.end})`}})]})]},h);}),/* @__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(Ut,{id:"heatmap-custom",value:"custom"}),/* @__PURE__ */e(P,{htmlFor:"heatmap-custom",className:"text-sm font-medium",children:"Custom colors"})]}),o==="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(Ha,{value:i[0],onChange:h=>u(0,h??"#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(Ha,{value:i[1],onChange:h=>u(1,h??"#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(P,{className:"text-xs font-medium",children:"Color scale position"}),/* @__PURE__ */n(te,{value:d,onValueChange:h=>f(h??"bottom"),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:["top","bottom","left","right"].map(h=>/* @__PURE__ */e(U,{value:h,className:"text-xs",children:h[0].toUpperCase()+h.slice(1)},h))})]})]})]})]}):null;}const pr=["poor","satisfactory","good"];function fr(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 dh(){var R,I;const t=E(m=>m.card.preferences),a=E(m=>m.card),s=E(m=>m.isDevMode),{setCardPreferences:r,setChartOrientation:l}=he(),o=J(()=>(t==null?void 0:t.bulletConfig)||{},[t==null?void 0:t.bulletConfig]),i=Qt(a==null?void 0:a.config)&&!s,[c,x]=G(o.showRanges??!1),[u,f]=G(o.rangesArePercentages??!1),h=o.disableAutoComparative?!1:o.comparativeMetricKey!==void 0||!i,[p,N]=G(h);ye(()=>{x(o.showRanges??!1);},[o.showRanges]),ye(()=>{f(o.rangesArePercentages??!1);},[o.rangesArePercentages]);const T=o.targetValue===void 0?"":String(o.targetValue);ye(()=>{const m=o.disableAutoComparative?!1:o.comparativeMetricKey!==void 0||!i;N(m);},[o.disableAutoComparative,o.comparativeMetricKey,i]);const S=J(()=>{var m,M;return((M=(m=a==null?void 0:a.config)==null?void 0:m.metricColumns)==null?void 0:M.map(g=>{const w=g.label||g.name||g.alias||"";return{value:w,label:w};}))||[];},[(R=a==null?void 0:a.config)==null?void 0:R.metricColumns]);ye(()=>{var L,V;if(!t||S.length===0)return;const m={};let M=!1;const g=(L=S[1])==null?void 0:L.value;!o.targetMetricKey&&g&&(m.targetMetricKey=g,M=!0);const w=(V=S[2])==null?void 0:V.value;!o.comparativeMetricKey&&!o.disableAutoComparative&&w&&(m.comparativeMetricKey=w,M=!0);const O=S.slice(3),q={...(o.rangeKeys||{})};let z=!1;if(pr.forEach((W,ee)=>{!q[W]&&O[ee]&&(q[W]=O[ee].value,z=!0);}),z&&(m.rangeKeys=q,M=!0,o.showRanges===void 0&&(m.showRanges=!0)),M){const W=fr({...o,...m});r({...t,bulletConfig:W});}},[S,o,t,r]);const b=m=>{const M=fr({...o,...m});r({...t,bulletConfig:M});},y=(m,M)=>{const g={...(o.rangeKeys||{}),[m]:M.trim()};M.trim()||delete g[m],b({rangeKeys:Object.keys(g).length>0?g:void 0});},F=(m,M)=>{const g=M===""?void 0:Number(M),w={...(o.ranges||{})};g===void 0||Number.isNaN(g)?delete w[m]:w[m]=g,b({ranges:Object.keys(w).length?w:void 0});},v=m=>{if(m===""){b({targetValue:void 0});return;}const M=Number(m);b({targetValue:Number.isNaN(M)?void 0:M});},D=(m,M)=>{const g=M.trim(),w={...(o.rangeLabels||{})};g?w[m]=g:delete w[m],b({rangeLabels:Object.keys(w).length>0?w:void 0});},K=m=>{x(m),b({showRanges:m});},j=m=>{f(m),b({rangesArePercentages:m});},_=o.orientation||(((I=t==null?void 0:t.chartOptions)==null?void 0:I.indexAxis)==="y"?"horizontal":"vertical"),k=m=>{b({orientation:m}),l(m==="horizontal"?"y":"x");},A=[{value:"__none",label:"None"},...S.map(m=>({value:m.value,label:m.label}))],$=A,C=m=>{if(N(m),!m){b({comparativeMetricKey:void 0,disableAutoComparative:!0});return;}if(!i){b({disableAutoComparative:!1});return;}if(o.comparativeMetricKey)b({disableAutoComparative:!1});else{const M=S.find(g=>g.value!==o.targetMetricKey);b({comparativeMetricKey:M==null?void 0:M.value,disableAutoComparative:!1});}};return/* @__PURE__ */n(we,{value:"bullet-config",className:"border-b-0",children:[/* @__PURE__ */e(Se,{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(Br,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Bullet Chart"})]})}),/* @__PURE__ */n(Te,{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(P,{className:"text-xs font-medium",children:"ORIENTATION"}),/* @__PURE__ */n(te,{value:_,onValueChange:m=>k(m),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */n(re,{children:[/* @__PURE__ */e(U,{value:"horizontal",className:"text-xs",children:"Horizontal"}),/* @__PURE__ */e(U,{value:"vertical",className:"text-xs",children:"Vertical"})]})]})]}),i&&/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{className:"text-xs font-medium",children:"TARGET METRIC"}),/* @__PURE__ */n(te,{value:o.targetMetricKey||"__none",onValueChange:m=>b({targetMetricKey:m==="__none"?void 0:m}),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{placeholder:"Select metric"})}),/* @__PURE__ */n(re,{children:[/* @__PURE__ */e(U,{value:"__none",className:"text-xs",children:"None"}),S.map(m=>/* @__PURE__ */e(U,{value:m.value,className:"text-xs",children:m.label},m.value))]})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{className:"text-xs font-medium",children:"COMPARATIVE METRIC"}),i?/* @__PURE__ */n(te,{value:o.comparativeMetricKey||"__none",onValueChange:m=>b({comparativeMetricKey:m==="__none"?void 0:m,disableAutoComparative:m==="__none"}),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{placeholder:"Select metric"})}),/* @__PURE__ */e(re,{children:A.map(m=>/* @__PURE__ */e(U,{value:m.value,className:"text-xs",children:m.label},m.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(Ne,{size:"sm",checked:p,onCheckedChange:m=>C(m)})]}),/* @__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(P,{className:"text-xs font-medium",children:"TARGET VALUE (FALLBACK)"}),/* @__PURE__ */e(je,{type:"number",className:"h-8 text-xs",value:T,onCommit:v,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(P,{className:"text-xs font-medium",children:"QUALITATIVE RANGES"}),/* @__PURE__ */e(Lt,{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(ut,{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(Ne,{size:"sm",checked:c,onCheckedChange:K})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2 text-xs font-medium",children:[/* @__PURE__ */e("input",{type:"checkbox",checked:u,disabled:!c,onChange:m=>j(m.target.checked),className:"h-3.5 w-3.5 accent-primary disabled:opacity-50"}),/* @__PURE__ */e("span",{children:"Use % of value"})]})]}),c&&/* @__PURE__ */e("div",{className:"space-y-3",children:pr.map(m=>{var M,g,w,O,q;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(P,{className:"text-[11px] font-medium uppercase tracking-wide",children:[m," LABEL"]}),/* @__PURE__ */e(je,{placeholder:`Display label (${m})`,value:((M=o.rangeLabels)==null?void 0:M[m])||"",onCommit:z=>D(m,z),className:"h-8 text-xs"})]}),i?/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */n(P,{className:"text-[11px] font-medium uppercase tracking-wide",children:[m," COLUMN"]}),/* @__PURE__ */n(te,{value:((g=o.rangeKeys)==null?void 0:g[m])||"__none",onValueChange:z=>{z==="__none"?y(m,""):y(m,z);},children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{placeholder:"Select column"})}),/* @__PURE__ */e(re,{children:$.map(z=>/* @__PURE__ */e(U,{value:z.value,className:"text-xs",children:z.label},z.value))})]})]}):/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */n(P,{className:"text-[11px] font-medium uppercase tracking-wide",children:[m," COLUMN KEY"]}),/* @__PURE__ */e(je,{placeholder:"Column key",value:((w=o.rangeKeys)==null?void 0:w[m])||"",onCommit:z=>y(m,z),className:"h-8 text-xs"})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */n(P,{className:"text-[11px] font-medium uppercase tracking-wide",children:[m," VALUE"]}),/* @__PURE__ */e(je,{type:"number",placeholder:u?"0.80":"Static value",value:((O=o.ranges)==null?void 0:O[m])===void 0?"":String((q=o.ranges)==null?void 0:q[m]),onCommit:z=>F(m,z),className:"h-8 text-xs"})]})]},m);})})]})]})]});}function gr(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 uh(){var D,K,j,_,k,A,$,C,R,I,m,M;const t=E(g=>g.card.preferences),a=E(g=>g.card),s=Ke(),r=E(g=>g.isDevMode),{setCardPreferences:l,updateCardInFrame:o}=he(),d=s==="bubble",i=s==="scatter",c=J(()=>(t==null?void 0:t.bubbleScatterConfig)||{},[t==null?void 0:t.bubbleScatterConfig]),u=Qt(a==null?void 0:a.config)&&!r,f=J(()=>{var g,w;return((w=(g=a==null?void 0:a.config)==null?void 0:g.metricColumns)==null?void 0:w.map(O=>{const q=O.label||O.name||O.alias||"";return{value:q,label:q};}))||[];},[(D=a==null?void 0:a.config)==null?void 0:D.metricColumns]),h=J(()=>{var g,w;return((w=(g=a==null?void 0:a.config)==null?void 0:g.groupByColumns)==null?void 0:w.map(O=>{const q=O.label||O.name||O.alias||"";return{value:q,label:q};}))||[];},[(K=a==null?void 0:a.config)==null?void 0:K.groupByColumns]),p=J(()=>c.enableGrouping!==void 0?c.enableGrouping:!r&&h.length>=2,[c.enableGrouping,r,h.length]),[N,T]=G(p);ye(()=>{T(p);},[p]);const S=g=>{const w={...(t||{}),bubbleScatterConfig:g};l(w),a&&o({...a,preferences:w});},b=g=>{l(g),a&&o({...a,preferences:g});};ye(()=>{if(!t||f.length===0)return;const g={};let w=!1;if(!c.xMetricKey&&f[0]&&(g.xMetricKey=f[0].value,w=!0),!c.yMetricKey&&f[1]&&(g.yMetricKey=f[1].value,w=!0),d&&!c.radiusMetricKey&&f[2]&&(g.radiusMetricKey=f[2].value,w=!0),!c.labelKey&&h[0]&&(g.labelKey=h[0].value,w=!0),p&&!c.groupKey&&h[1]&&(g.groupKey=h[1].value,g.enableGrouping=!0,w=!0),w){const O=gr({...c,...g});S(O);}},[f,h,c,t,l,d,p]);const y=g=>{const w=gr({...c,...g});S(w);},F=g=>{T(g),y({enableGrouping:g,groupKey:g?c.groupKey:void 0});};return!d&&!i?null:/* @__PURE__ */n(we,{value:"bubble-scatter-config",children:[/* @__PURE__ */e(Se,{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?ad:Kr,{className:"h-3.5 w-3.5 text-foreground/60"}),/* @__PURE__ */n("span",{children:[d?"Bubble":"Scatter"," Configuration"]})]})}),/* @__PURE__ */n(Te,{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(Lt,{children:/* @__PURE__ */n(mt,{children:[/* @__PURE__ */e(ht,{children:/* @__PURE__ */e(ut,{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(P,{className:"text-xs",children:"Label Column"}),u?/* @__PURE__ */n(te,{value:c.labelKey||"",onValueChange:g=>y({labelKey:g}),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{placeholder:"Select label column"})}),/* @__PURE__ */e(re,{children:h.map(g=>/* @__PURE__ */e(U,{value:g.value,children:g.label},g.value))})]}):/* @__PURE__ */e(je,{className:"h-8 text-xs",placeholder:"Column name for labels",value:c.labelKey||"",onCommit:g=>y({labelKey:g})})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{className:"text-xs",children:"Group points into series"}),/* @__PURE__ */e(Ne,{size:"sm",checked:N,onCheckedChange:F})]}),N&&/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(P,{className:"text-xs",children:"Group By"}),u?/* @__PURE__ */n(te,{value:c.groupKey||"",onValueChange:g=>y({groupKey:g}),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{placeholder:"Select group column"})}),/* @__PURE__ */e(re,{children:h.map(g=>/* @__PURE__ */e(U,{value:g.value,children:g.label},g.value))})]}):/* @__PURE__ */e(je,{className:"h-8 text-xs",placeholder:"Column name for grouping",value:c.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(P,{className:"text-xs",children:"X Axis"}),u?/* @__PURE__ */n(te,{value:c.xMetricKey||"",onValueChange:g=>y({xMetricKey:g}),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{placeholder:"Select X metric"})}),/* @__PURE__ */e(re,{children:f.map(g=>/* @__PURE__ */e(U,{value:g.value,children:g.label},g.value))})]}):/* @__PURE__ */e(je,{className:"h-8 text-xs",placeholder:"Column name for X axis",value:c.xMetricKey||"",onCommit:g=>y({xMetricKey:g})})]}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(P,{className:"text-xs",children:"Y Axis"}),u?/* @__PURE__ */n(te,{value:c.yMetricKey||"",onValueChange:g=>y({yMetricKey:g}),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{placeholder:"Select Y metric"})}),/* @__PURE__ */e(re,{children:f.map(g=>/* @__PURE__ */e(U,{value:g.value,children:g.label},g.value))})]}):/* @__PURE__ */e(je,{className:"h-8 text-xs",placeholder:"Column name for Y axis",value:c.yMetricKey||"",onCommit:g=>y({yMetricKey:g})})]}),d&&/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(P,{className:"text-xs",children:"Radius"}),u?/* @__PURE__ */n(te,{value:c.radiusMetricKey||"",onValueChange:g=>y({radiusMetricKey:g}),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{placeholder:"Select radius metric"})}),/* @__PURE__ */e(re,{children:f.map(g=>/* @__PURE__ */e(U,{value:g.value,children:g.label},g.value))})]}):/* @__PURE__ */e(je,{className:"h-8 text-xs",placeholder:"Column name for radius",value:c.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(P,{className:"text-xs",children:"Scale Mode"}),/* @__PURE__ */n(te,{value:c.radiusScale||"sqrt",onValueChange:g=>y({radiusScale:g}),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */n(re,{children:[/* @__PURE__ */e(U,{value:"sqrt",children:"Square Root (area-proportional)"}),/* @__PURE__ */e(U,{value:"linear",children:"Linear"}),/* @__PURE__ */e(U,{value:"fixed",children:"Fixed Size"})]})]})]}),c.radiusScale!=="fixed"&&/* @__PURE__ */n("div",{className:"grid grid-cols-2 gap-2",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(P,{className:"text-xs",children:"Min Radius"}),/* @__PURE__ */e(je,{className:"h-8 text-xs",type:"number",placeholder:"5",value:((j=c.minRadius)==null?void 0:j.toString())||"",onCommit:g=>y({minRadius:g?Number(g):void 0})})]}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(P,{className:"text-xs",children:"Max Radius"}),/* @__PURE__ */e(je,{className:"h-8 text-xs",type:"number",placeholder:"30",value:((_=c.maxRadius)==null?void 0:_.toString())||"",onCommit:g=>y({maxRadius:g?Number(g):void 0})})]})]}),c.radiusScale==="fixed"&&/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */n(P,{className:"text-xs",children:["Fixed Radius: ",c.fixedRadius||10]}),/* @__PURE__ */e(Zt,{value:[c.fixedRadius||10],onValueChange:([g])=>y({fixedRadius:g}),min:3,max:30,step:1,className:"py-2"})]})]}),i&&/* @__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(P,{className:"text-xs",children:["Point Size: ",c.fixedRadius||5]}),/* @__PURE__ */e(Zt,{value:[c.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(Ne,{size:"sm",checked:((A=(k=t==null?void 0:t.xAxisConfig)==null?void 0:k.name)==null?void 0:A.enabled)??!1,onCheckedChange:g=>{var q,z,L,V;const w=c.xMetricKey||"X Axis",O=c.yMetricKey||"Y Axis";b({...(t??{}),xAxisConfig:{...(t==null?void 0:t.xAxisConfig),name:{enabled:g,text:((z=(q=t==null?void 0:t.xAxisConfig)==null?void 0:q.name)==null?void 0:z.text)||w}},yAxisConfig:{...(t==null?void 0:t.yAxisConfig),name:{enabled:g,text:((V=(L=t==null?void 0:t.yAxisConfig)==null?void 0:L.name)==null?void 0:V.text)||O}}});}})]}),((C=($=t==null?void 0:t.xAxisConfig)==null?void 0:$.name)==null?void 0:C.enabled)&&/* @__PURE__ */n("div",{className:"grid grid-cols-2 gap-2",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(P,{className:"text-xs",children:"X Title"}),/* @__PURE__ */e(je,{className:"h-8 text-xs",placeholder:c.xMetricKey||"X Axis",value:((I=(R=t==null?void 0:t.xAxisConfig)==null?void 0:R.name)==null?void 0:I.text)||"",onCommit:g=>{var w;b({...(t??{}),xAxisConfig:{...(t==null?void 0:t.xAxisConfig),name:{...((w=t==null?void 0:t.xAxisConfig)==null?void 0:w.name),enabled:!0,text:g||c.xMetricKey||"X Axis"}}});}})]}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(P,{className:"text-xs",children:"Y Title"}),/* @__PURE__ */e(je,{className:"h-8 text-xs",placeholder:c.yMetricKey||"Y Axis",value:((M=(m=t==null?void 0:t.yAxisConfig)==null?void 0:m.name)==null?void 0:M.text)||"",onCommit:g=>{var w;b({...(t??{}),yAxisConfig:{...(t==null?void 0:t.yAxisConfig),name:{...((w=t==null?void 0:t.yAxisConfig)==null?void 0:w.name),enabled:!0,text:g||c.yMetricKey||"Y Axis"}}});}})]})]})]})]})]});}const mh=[{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 hh(){const t=E(h=>h.card),a=E(h=>{var p;return(p=h.card)==null?void 0:p.preferences;}),{setCardPreferences:s}=he(),r=(t==null?void 0:t.type)==="funnel",l=(a==null?void 0:a.funnelConfig)||{},o=l.percentMode??"percentOfTotal",d=l.shrinkFraction??1,i=l.labelThreshold??0,c=h=>{const p={...l,...h};s({...(a||{}),funnelConfig:p});},x=h=>{c({percentMode:h});},u=h=>{c({shrinkFraction:h[0]});},f=h=>{c({labelThreshold:h[0]});};return r?/* @__PURE__ */n(we,{value:"funnel-config",className:"border-none",children:[/* @__PURE__ */e(Se,{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(ya,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Funnel Settings"})]})}),/* @__PURE__ */n(Te,{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(P,{className:"text-xs font-medium",children:"PERCENTAGE MODE"}),/* @__PURE__ */e(Cn,{value:o,onValueChange:h=>x(h),className:"space-y-2",children:mh.map(h=>/* @__PURE__ */n("div",{className:"flex items-start gap-2 rounded-md border border-border px-3 py-2",children:[/* @__PURE__ */e(Ut,{id:`funnel-${h.value}`,value:h.value,className:"mt-0.5"}),/* @__PURE__ */n(P,{htmlFor:`funnel-${h.value}`,className:"flex flex-col gap-0.5 text-sm font-normal",children:[/* @__PURE__ */e("span",{className:"font-medium",children:h.label}),/* @__PURE__ */e("span",{className:"text-xs text-muted-foreground",children:h.description})]})]},h.value))})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(P,{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(Zt,{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(P,{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(Zt,{value:[i],onValueChange:f,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:i===0?"Showing all labels":`Hide labels below ${i}%`})]})]})]}):null;}const ph=[{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"}],fh=[{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)"}],gh=["center","start","end"],xh=["center","start","end","top","bottom"];function Na({config:t,onChange:a,isHorizontal:s=!1,showAutoFormat:r=!0,positionOptions:l,showAppearance:o=!0}){var N,T,S,b,y,F;const d=l??(s?["auto","center","left","right","custom"]:["auto","center","top","bottom","custom"]),i=r?["auto","number","currency","percent","none"]:["number","currency","percent","none"],c=(v,D)=>{const K={...t,[v]:D};a(K);},x=(v,D)=>{const K={...t,font:{...((t==null?void 0:t.font)||{}),[v]:D}};a(K);},u=(v,D)=>{const K={...t,formatOptions:{...((t==null?void 0:t.formatOptions)||{}),[v]:D}};a(K);},f=()=>s?"Right":"Top",h=t||{},p=h.format||(r?"auto":"number");return/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{className:"text-xs text-muted-foreground",children:"Position"}),/* @__PURE__ */n(te,{value:h.position||"auto",onValueChange:v=>c("position",v),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:d.map(v=>/* @__PURE__ */e(U,{value:v,className:"text-xs",children:v==="auto"?f():v==="custom"?"Custom (Advanced)":Xe(v)},v))})]})]}),h.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(P,{className:"text-xs",children:"Anchor"}),/* @__PURE__ */n(te,{value:h.anchor||"center",onValueChange:v=>c("anchor",v),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-24",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:gh.map(v=>/* @__PURE__ */e(U,{value:v,className:"text-xs",children:Xe(v)},v))})]})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{className:"text-xs",children:"Align"}),/* @__PURE__ */n(te,{value:String(h.align||"center"),onValueChange:v=>c("align",v),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-24",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:xh.map(v=>/* @__PURE__ */e(U,{value:v,className:"text-xs",children:Xe(v)},v))})]})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{className:"text-xs text-muted-foreground",children:"Format"}),/* @__PURE__ */n(te,{value:p,onValueChange:v=>c("format",v),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:i.map(v=>/* @__PURE__ */e(U,{value:v,className:"text-xs",children:v==="auto"&&r?"Auto (Use Axis)":v==="none"?"None (Raw Value)":Xe(v)},v))})]})]}),!["auto","none"].includes(p)&&/* @__PURE__ */n("div",{className:"space-y-2 rounded-md border border-border bg-background p-2",children:[["number","currency","percent"].includes(p)&&/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{className:"text-xs",children:"Decimals"}),/* @__PURE__ */e("div",{className:"w-16",children:/* @__PURE__ */e(Ze,{type:"number",placeholder:"0",value:String(((N=h.formatOptions)==null?void 0:N.decimalPlaces)??(p==="currency"?2:p==="percent"?1:0)),onSave:v=>u("decimalPlaces",Number(v)),className:""})})]}),p==="currency"&&/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{className:"text-xs",children:"Currency"}),/* @__PURE__ */n(te,{value:((T=h.formatOptions)==null?void 0:T.currency)||"USD",onValueChange:v=>u("currency",v),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-28",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:ph.map(v=>/* @__PURE__ */e(U,{value:v.value,className:"text-xs",children:v.label},v.value))})]})]}),["number","currency"].includes(p)&&/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{className:"text-xs",children:"Abbreviate (K, M, B)"}),/* @__PURE__ */e(Ne,{size:"sm",checked:((S=h.formatOptions)==null?void 0:S.useSuffix)??!1,onCheckedChange:v=>u("useSuffix",v)})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{className:"text-xs",children:"Locale"}),/* @__PURE__ */n(te,{value:((b=h.formatOptions)==null?void 0:b.locale)||"en-US",onValueChange:v=>u("locale",v),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-28",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:fh.map(v=>/* @__PURE__ */e(U,{value:v.value,className:"text-xs",children:v.label},v.value))})]})]})]}),o&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(P,{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(P,{className:"text-xs",children:"Size"}),/* @__PURE__ */e("div",{className:"w-16",children:/* @__PURE__ */e(Ze,{type:"number",placeholder:"12",value:String(((y=h.font)==null?void 0:y.size)||12),onSave:v=>x("size",Number(v)),className:""})})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{className:"text-xs",children:"Weight"}),/* @__PURE__ */n(te,{value:((F=h.font)==null?void 0:F.weight)||"normal",onValueChange:v=>x("weight",v),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-24",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */n(re,{children:[/* @__PURE__ */e(U,{value:"normal",className:"text-xs",children:"Normal"}),/* @__PURE__ */e(U,{value:"bold",className:"text-xs",children:"Bold"})]})]})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{className:"text-xs",children:"Color"}),/* @__PURE__ */n(te,{value:h.color==="auto"||!h.color?"auto":"custom",onValueChange:v=>{v==="auto"&&c("color","auto");},children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-28",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */n(re,{children:[/* @__PURE__ */e(U,{value:"auto",className:"text-xs",children:"Auto (Contrast)"}),/* @__PURE__ */e(U,{value:"custom",disabled:!0,className:"text-xs",children:"Custom"})]})]})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{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(h.rotation||0),onSave:v=>c("rotation",Number(v)),className:""})}),/* @__PURE__ */e("span",{className:"text-xs text-muted-foreground",children:"°"})]})]})]})]})]});}const bh=[{type:"bar",icon:pn,label:"Bar"},{type:"line",icon:hn,label:"Line"}],yh=[0,1,2,3,4,5,6,8,10],vh=[{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 │"}],Nh=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function Ch(){return E(a=>{var s;return(s=a.card)==null?void 0:s.type;})!=="combo"?null:/* @__PURE__ */n(we,{value:"combo-series",className:"border-b-0",children:[/* @__PURE__ */e(Se,{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(oa,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Series"})]})}),/* @__PURE__ */e(Te,{className:"pt-2",children:/* @__PURE__ */e(wh,{})})]});}function wh(){const{transformedMetricKeys:t}=va();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(Sh,{metricKey:a,idx:s},a))});}function Sh({metricKey:t,idx:a}){var b;const[s,r]=G(!1),l=E(y=>{var F;return(F=y.card)==null?void 0:F.preferences;}),o=E(y=>{var F,v;return(v=(F=y.card)==null?void 0:F.preferences)==null?void 0:v.datasetOptions;}),d=o==null?void 0:o.find(y=>y.idx===a),{setCardPreferences:i}=E(y=>y.actions),c=(d==null?void 0:d.type)||"bar",x=(d==null?void 0:d.yAxisId)||"y",u=((b=d==null?void 0:d.dataLabels)==null?void 0:b.enabled)??!1,f=c==="line"?hn:pn;function h(y){const F={idx:a,type:c,yAxisId:x,dataLabels:d==null?void 0:d.dataLabels,...y};if(!d)i({...(l||{}),datasetOptions:[...(o||[]),F]});else{const v=o==null?void 0:o.map(D=>D.idx===a?{...D,...F}:D);i({...(l||{}),datasetOptions:v});}}function p(y){h({type:y});}function N(y){h({yAxisId:y});}function T(y){h({dataLabels:{...(d==null?void 0:d.dataLabels),enabled:y}});}function S(y){h({dataLabels:y});}return/* @__PURE__ */e(Ot,{open:s,onOpenChange:r,children:/* @__PURE__ */n("div",{className:"rounded-lg border border-border bg-muted/30",children:[/* @__PURE__ */e(At,{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(yt,{className:Q("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:Q("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(f,{className:"h-3 w-3"}),c==="line"?"Line":"Bar"]}),/* @__PURE__ */e("span",{className:Q("rounded px-1.5 py-0.5 text-xs","border border-border bg-background text-muted-foreground"),children:x==="y2"?"Y2":"Y1"})]})]})}),/* @__PURE__ */e(Rt,{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(P,{className:"text-xs text-muted-foreground",children:"Chart Type"}),/* @__PURE__ */e("div",{className:"flex gap-2",children:bh.map(({type:y,icon:F,label:v})=>/* @__PURE__ */n("button",{onClick:()=>p(y),className:Q("flex items-center gap-2 rounded-md border px-3 py-1.5 text-xs transition-colors",c===y?"border-primary bg-primary/10 text-primary":"border-border bg-background text-muted-foreground hover:bg-muted"),children:[/* @__PURE__ */e(F,{className:"h-3.5 w-3.5 text-foreground/60"}),/* @__PURE__ */e("span",{children:v})]},y))})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{className:"text-xs text-muted-foreground",children:"Axis"}),/* @__PURE__ */n(te,{value:x,onValueChange:y=>N(y),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-20",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */n(re,{children:[/* @__PURE__ */e(U,{value:"y",className:"text-xs",children:"Y1 (Left)"}),/* @__PURE__ */e(U,{value:"y2",className:"text-xs",children:"Y2 (Right)"})]})]})]})]}),c==="line"&&/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */e(P,{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(P,{className:"text-xs text-muted-foreground",children:"Pattern"}),/* @__PURE__ */n(te,{value:(d==null?void 0:d.lineStyle)||"solid",onValueChange:y=>h({lineStyle:y}),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:Nh.map(({value:y,label:F})=>/* @__PURE__ */e(U,{value:y,className:"text-xs",children:F},y))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{className:"text-xs text-muted-foreground",children:"Point Size"}),/* @__PURE__ */n(te,{value:String((d==null?void 0:d.pointRadius)??3),onValueChange:y=>h({pointRadius:Number(y)}),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:yh.map(y=>/* @__PURE__ */e(U,{value:String(y),className:"text-xs",children:y===0?"None":y},y))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{className:"text-xs text-muted-foreground",children:"Point Shape"}),/* @__PURE__ */n(te,{value:(d==null?void 0:d.pointStyle)||"circle",onValueChange:y=>h({pointStyle:y}),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:vh.map(({value:y,label:F})=>/* @__PURE__ */e(U,{value:y,className:"text-xs",children:F},y))})]})]})]})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{className:"text-xs text-muted-foreground",children:"Data Labels"}),/* @__PURE__ */e(Ne,{size:"sm",checked:u,onCheckedChange:T})]}),u&&/* @__PURE__ */e("div",{className:"rounded-md border border-border bg-background p-2",children:/* @__PURE__ */e(Na,{config:d==null?void 0:d.dataLabels,onChange:S,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})});}const Ba=[{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"}],Th=[0,1,2,3,4,5,6,8,10],kh=[{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 │"}],Eh=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function Ih(t){return t==null?"origin":t===!1?"false":t;}function Fh(){const t=E(a=>{var s;return(s=a.card)==null?void 0:s.type;});return t!=="area"&&t!=="stackedArea"?null:/* @__PURE__ */n(we,{value:"area-series",className:"border-b-0",children:[/* @__PURE__ */e(Se,{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(oa,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Series"})]})}),/* @__PURE__ */e(Te,{className:"pt-2",children:/* @__PURE__ */e(Mh,{})})]});}function Mh(){const{transformedMetricKeys:t}=va();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(Oh,{metricKey:a,idx:s},a))});}function Oh({metricKey:t,idx:a}){var T;const[s,r]=G(!1),l=E(S=>{var b;return(b=S.card)==null?void 0:b.preferences;}),o=E(S=>{var b,y;return(y=(b=S.card)==null?void 0:b.preferences)==null?void 0:y.datasetOptions;}),d=o==null?void 0:o.find(S=>S.idx===a),{setCardPreferences:i}=E(S=>S.actions),c=Ih(d==null?void 0:d.fill),x=((T=d==null?void 0:d.dataLabels)==null?void 0:T.enabled)??!1,u=Ba.find(S=>S.value===c)||Ba[0];function f(S){const b={idx:a,fill:c,dataLabels:d==null?void 0:d.dataLabels,...S};if(!d)i({...(l||{}),datasetOptions:[...(o||[]),b]});else{const y=o==null?void 0:o.map(F=>F.idx===a?{...F,...b}:F);i({...(l||{}),datasetOptions:y});}}function h(S){f({fill:S==="false"?!1:S});}function p(S){f({dataLabels:{...(d==null?void 0:d.dataLabels),enabled:S}});}function N(S){f({dataLabels:S});}return/* @__PURE__ */e(Ot,{open:s,onOpenChange:r,children:/* @__PURE__ */n("div",{className:"rounded-lg border border-border bg-muted/30",children:[/* @__PURE__ */e(At,{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(yt,{className:Q("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:Q("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(zo,{className:"h-3 w-3"}),u.label.split(" ")[0]]})})]})}),/* @__PURE__ */e(Rt,{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(P,{className:"text-xs text-muted-foreground",children:"Fill Target"}),/* @__PURE__ */n(te,{value:c,onValueChange:S=>h(S),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:Ba.map(S=>/* @__PURE__ */e(U,{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(P,{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(P,{className:"text-xs text-muted-foreground",children:"Pattern"}),/* @__PURE__ */n(te,{value:(d==null?void 0:d.lineStyle)||"solid",onValueChange:S=>f({lineStyle:S}),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:Eh.map(({value:S,label:b})=>/* @__PURE__ */e(U,{value:S,className:"text-xs",children:b},S))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{className:"text-xs text-muted-foreground",children:"Point Size"}),/* @__PURE__ */n(te,{value:String((d==null?void 0:d.pointRadius)??3),onValueChange:S=>f({pointRadius:Number(S)}),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:Th.map(S=>/* @__PURE__ */e(U,{value:String(S),className:"text-xs",children:S===0?"None":S},S))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{className:"text-xs text-muted-foreground",children:"Point Shape"}),/* @__PURE__ */n(te,{value:(d==null?void 0:d.pointStyle)||"circle",onValueChange:S=>f({pointStyle:S}),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:kh.map(({value:S,label:b})=>/* @__PURE__ */e(U,{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(P,{className:"text-xs text-muted-foreground",children:"Data Labels"}),/* @__PURE__ */e(Ne,{size:"sm",checked:x,onCheckedChange:p})]}),x&&/* @__PURE__ */e("div",{className:"rounded-md border border-border bg-background p-2",children:/* @__PURE__ */e(Na,{config:d==null?void 0:d.dataLabels,onChange:N,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})});}const Ah=[0,1,2,3,4,5,6,8,10],Rh=[{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 │"}],za=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function Lh(){return E(a=>{var s;return(s=a.card)==null?void 0:s.type;})!=="line"?null:/* @__PURE__ */n(we,{value:"line-series",className:"border-b-0",children:[/* @__PURE__ */e(Se,{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(oa,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Series"})]})}),/* @__PURE__ */e(Te,{className:"pt-2",children:/* @__PURE__ */e(Ph,{})})]});}function Ph(){const{transformedMetricKeys:t}=va();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(Dh,{metricKey:a,idx:s},a))});}function Dh({metricKey:t,idx:a}){var S;const[s,r]=G(!1),l=E(b=>{var y;return(y=b.card)==null?void 0:y.preferences;}),o=E(b=>{var y,F;return(F=(y=b.card)==null?void 0:y.preferences)==null?void 0:F.datasetOptions;}),d=o==null?void 0:o.find(b=>b.idx===a),{setCardPreferences:i}=E(b=>b.actions),c=(d==null?void 0:d.lineStyle)||"solid",x=(d==null?void 0:d.pointRadius)??3,u=(d==null?void 0:d.pointStyle)||"circle",f=((S=d==null?void 0:d.dataLabels)==null?void 0:S.enabled)??!1,h=za.find(b=>b.value===c)||za[0];function p(b){const y={idx:a,lineStyle:c,pointRadius:x,pointStyle:u,dataLabels:d==null?void 0:d.dataLabels,...b};if(!d)i({...(l||{}),datasetOptions:[...(o||[]),y]});else{const F=o==null?void 0:o.map(v=>v.idx===a?{...v,...y}:v);i({...(l||{}),datasetOptions:F});}}function N(b){p({dataLabels:{...(d==null?void 0:d.dataLabels),enabled:b}});}function T(b){p({dataLabels:b});}return/* @__PURE__ */e(Ot,{open:s,onOpenChange:r,children:/* @__PURE__ */n("div",{className:"rounded-lg border border-border bg-muted/30",children:[/* @__PURE__ */e(At,{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(yt,{className:Q("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:Q("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(ys,{className:"h-3 w-3"}),h.label.split(" ")[0]]})})]})}),/* @__PURE__ */e(Rt,{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(P,{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(P,{className:"text-xs text-muted-foreground",children:"Pattern"}),/* @__PURE__ */n(te,{value:c,onValueChange:b=>p({lineStyle:b}),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:za.map(({value:b,label:y})=>/* @__PURE__ */e(U,{value:b,className:"text-xs",children:y},b))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{className:"text-xs text-muted-foreground",children:"Point Size"}),/* @__PURE__ */n(te,{value:String(x),onValueChange:b=>p({pointRadius:Number(b)}),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:Ah.map(b=>/* @__PURE__ */e(U,{value:String(b),className:"text-xs",children:b===0?"None":b},b))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{className:"text-xs text-muted-foreground",children:"Point Shape"}),/* @__PURE__ */n(te,{value:u,onValueChange:b=>p({pointStyle:b}),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:Rh.map(({value:b,label:y})=>/* @__PURE__ */e(U,{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(P,{className:"text-xs text-muted-foreground",children:"Data Labels"}),/* @__PURE__ */e(Ne,{size:"sm",checked:f,onCheckedChange:N})]}),f&&/* @__PURE__ */e("div",{className:"rounded-md border border-border bg-background p-2",children:/* @__PURE__ */e(Na,{config:d==null?void 0:d.dataLabels,onChange:T,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})});}const _h=[0,2,4,6,8,10,12,16,20];function Vh(){const t=E(a=>{var s;return(s=a.card)==null?void 0:s.type;});return!t||!["bar","horizontalBar","stackedBar"].includes(t)?null:/* @__PURE__ */n(we,{value:"bar-series",className:"border-b-0",children:[/* @__PURE__ */e(Se,{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(oa,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Series"})]})}),/* @__PURE__ */e(Te,{className:"pt-2",children:/* @__PURE__ */e(Bh,{})})]});}function Bh(){const{transformedMetricKeys:t}=va();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(zh,{metricKey:a,idx:s},a))});}function zh({metricKey:t,idx:a}){var N;const[s,r]=G(!1),l=E(T=>{var S;return(S=T.card)==null?void 0:S.type;}),o=E(T=>{var S;return(S=T.card)==null?void 0:S.preferences;}),d=E(T=>{var S,b;return(b=(S=T.card)==null?void 0:S.preferences)==null?void 0:b.datasetOptions;}),i=d==null?void 0:d.find(T=>T.idx===a),{setCardPreferences:c}=E(T=>T.actions),x=(i==null?void 0:i.borderRadius)??0,u=((N=i==null?void 0:i.dataLabels)==null?void 0:N.enabled)??!1;function f(T){const S={idx:a,borderRadius:x,dataLabels:i==null?void 0:i.dataLabels,...T};if(!i)c({...(o||{}),datasetOptions:[...(d||[]),S]});else{const b=d==null?void 0:d.map(y=>y.idx===a?{...y,...S}:y);c({...(o||{}),datasetOptions:b});}}function h(T){f({dataLabels:{...(i==null?void 0:i.dataLabels),enabled:T}});}function p(T){f({dataLabels:T});}return/* @__PURE__ */e(Ot,{open:s,onOpenChange:r,children:/* @__PURE__ */n("div",{className:"rounded-lg border border-border bg-muted/30",children:[/* @__PURE__ */e(At,{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(yt,{className:Q("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:x>0&&/* @__PURE__ */n("span",{className:Q("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"}),"r:",x]})})]})}),/* @__PURE__ */e(Rt,{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(P,{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(P,{className:"text-xs text-muted-foreground",children:"Corner Radius"}),/* @__PURE__ */n(te,{value:String(x),onValueChange:T=>f({borderRadius:Number(T)}),children:[/* @__PURE__ */e(ae,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:_h.map(T=>/* @__PURE__ */e(U,{value:String(T),className:"text-xs",children:T===0?"None":`${T}px`},T))})]})]})})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{className:"text-xs text-muted-foreground",children:"Data Labels"}),/* @__PURE__ */e(Ne,{size:"sm",checked:u,onCheckedChange:h})]}),u&&/* @__PURE__ */e("div",{className:"rounded-md border border-border bg-background p-2",children:/* @__PURE__ */e(Na,{config:i==null?void 0:i.dataLabels,onChange:p,isHorizontal:l==="horizontalBar",showAutoFormat:!0,showAppearance:!0})})]})]})})})]})});}const Kh=[0,1,2,3,4,5,6,8,10],qh=[{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 │"}],$h=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function jh(){const t=E(i=>i.card),a=E(i=>{var c;return(c=i.card)==null?void 0:c.preferences;}),s=Ke(),r=a==null?void 0:a.lineStyleConfig,{setCardPreferences:l,updateCardInFrame:o}=he();if(!t||!["line","area","stackedArea"].includes(s))return null;const d=(i,c)=>{const x={...(a||{}),lineStyleConfig:{...r,[i]:c}};l(x),o({...t,preferences:x});};return/* @__PURE__ */n(we,{value:"line-style",className:"border-b-0",children:[/* @__PURE__ */e(Se,{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(wu,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Line Style"})]})}),/* @__PURE__ */e(Te,{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(P,{className:"text-xs font-medium",children:"Line Pattern"}),/* @__PURE__ */n(te,{value:(r==null?void 0:r.lineStyle)||"solid",onValueChange:i=>d("lineStyle",i),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:$h.map(({value:i,label:c})=>/* @__PURE__ */e(U,{value:i,className:"text-xs",children:c},i))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{className:"text-xs font-medium",children:"Point Size"}),/* @__PURE__ */n(te,{value:String((r==null?void 0:r.pointRadius)??3),onValueChange:i=>d("pointRadius",Number(i)),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:Kh.map(i=>/* @__PURE__ */e(U,{value:String(i),className:"text-xs",children:i===0?"None":i},i))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{className:"text-xs font-medium",children:"Point Shape"}),/* @__PURE__ */n(te,{value:(r==null?void 0:r.pointStyle)||"circle",onValueChange:i=>d("pointStyle",i),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:qh.map(({value:i,label:c})=>/* @__PURE__ */e(U,{value:i,className:"text-xs",children:c},i))})]})]})]})})]});}const Hh=[0,2,4,6,8,10,12,16,20],Uh=[{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%"}],Qh=[{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 Gh(){const t=E(i=>i.card),a=E(i=>{var c;return(c=i.card)==null?void 0:c.preferences;}),s=Ke(),r=a==null?void 0:a.barStyleConfig,{setCardPreferences:l,updateCardInFrame:o}=he();if(!t||!["bar","horizontalBar","stackedBar"].includes(s))return null;const d=(i,c)=>{const x={...(a||{}),barStyleConfig:{...r,[i]:c}};l(x),o({...t,preferences:x});};return/* @__PURE__ */n(we,{value:"bar-style",className:"border-b-0",children:[/* @__PURE__ */e(Se,{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(os,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Bar Style"})]})}),/* @__PURE__ */e(Te,{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(P,{className:"text-xs font-medium",children:"Corner Radius"}),/* @__PURE__ */n(te,{value:String((r==null?void 0:r.borderRadius)??0),onValueChange:i=>d("borderRadius",Number(i)),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:Hh.map(i=>/* @__PURE__ */e(U,{value:String(i),className:"text-xs",children:i===0?"None":`${i}px`},i))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{className:"text-xs font-medium",children:"Bar Width"}),/* @__PURE__ */n(te,{value:String((r==null?void 0:r.barPercentage)??0.9),onValueChange:i=>d("barPercentage",Number(i)),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:Uh.map(({value:i,label:c})=>/* @__PURE__ */e(U,{value:i,className:"text-xs",children:c},i))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(P,{className:"text-xs font-medium",children:"Category Width"}),/* @__PURE__ */n(te,{value:String((r==null?void 0:r.categoryPercentage)??0.8),onValueChange:i=>d("categoryPercentage",Number(i)),children:[/* @__PURE__ */e(ae,{size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */e(re,{children:Qh.map(({value:i,label:c})=>/* @__PURE__ */e(U,{value:i,className:"text-xs",children:c},i))})]})]})]})})]});}function Wh(){const t=E(s=>{var r,l;return(l=(r=s==null?void 0:s.card)==null?void 0:r.preferences)==null?void 0:l.sortChart;}),{setSortChart:a}=he();return/* @__PURE__ */n(we,{value:"stacked-sort",children:[/* @__PURE__ */e(Se,{children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(gs,{className:"h-3.5 w-3.5 text-foreground/60"}),"Sort"]})}),/* @__PURE__ */e(Te,{className:"space-y-4 px-1",children:/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(P,{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 Yh=["kpi"],Ka=2;function ot(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 Xh(t){if(!(t!=null&&t.name)||!(t!=null&&t.dataType)||t.role==="metric")return!1;const a=ti(t.dataType);return["date","string","boolean"].includes(a);}function Jh(t){return{...t,role:"groupby"};}function Zh(){var y,F;const t=E(v=>v.card),a=E(v=>v.actions.updateCardConfig),s=Ke(),{scopedFields:r}=Gr(),l=((y=t.config)==null?void 0:y.metricColumns)||[],o=((F=t.config)==null?void 0:F.summary)||{},d=o.breakdownDimensions||[],i=d.length>0,c=Yh.includes(s),x=l.length>0,u=o.enabled===!0,f=c&&x,h=Array.from(new Map(r.filter(Xh).map(v=>[ot(v),Jh(v)])).values()),p=new Set(h.map(v=>ot(v))),N=new Set(d.map(v=>ot(v)).filter(v=>v&&p.has(v)));if(!c)return null;const T=v=>{a(t.id,{summary:{...o,...v}});},S=(v,D)=>{const K=ot(v),j=h.filter(k=>N.has(ot(k))),_=D?N.has(K)?j:[...j,v].slice(0,Ka):j.filter(k=>ot(k)!==K);T({breakdownDimensions:_,...(_.length>0?{showOnCard:!0}:{})});};return/* @__PURE__ */n(we,{value:"summary",className:"border-none",children:[/* @__PURE__ */e(Se,{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(nd,{className:"h-3.5 w-3.5 text-foreground/60"}),/* @__PURE__ */e("span",{children:"Summary"})]})}),/* @__PURE__ */n(Te,{className:"space-y-3 pb-4 pt-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{htmlFor:"summary-enabled",className:"text-xs",children:"Show summary"}),/* @__PURE__ */e(Ne,{id:"summary-enabled",size:"xs",checked:u,disabled:!f,onCheckedChange:v=>{if(!v){T({enabled:!1,showOnCard:!1,includeInDashboardSummary:!1});return;}T({enabled:!0,showOnCard:o.showOnCard??!0,includeInDashboardSummary:o.includeInDashboardSummary??!0});}})]}),/* @__PURE__ */n("div",{className:Q("space-y-3 transition-opacity",!u&&"opacity-60"),children:[!f&&/* @__PURE__ */e("p",{className:"text-[11px] text-muted-foreground",children:x?"Summary is not supported for this card type.":"Add at least one metric to enable summary."}),!i&&/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(jt,{id:"summary-show-on-card",checked:o.showOnCard===!0,disabled:!u,onCheckedChange:v=>T({showOnCard:v===!0})}),/* @__PURE__ */e(P,{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(jt,{id:"summary-include-rollup",checked:o.includeInDashboardSummary===!0,disabled:!u,onCheckedChange:v=>T({includeInDashboardSummary:v===!0})}),/* @__PURE__ */e(P,{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(P,{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,"/",Ka]})]}),h.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:h.map(v=>{const D=ot(v),K=N.has(D),j=N.size>=Ka,_=!u||!K&&j;return/* @__PURE__ */n("li",{className:"flex items-center gap-2 text-xs",children:[/* @__PURE__ */e(jt,{id:`summary-breakdown-${D}`,checked:K,disabled:_,onCheckedChange:k=>S(v,k===!0)}),/* @__PURE__ */e(P,{htmlFor:`summary-breakdown-${D}`,className:"cursor-pointer text-xs",children:v.label||v.name})]},D);})})]})]})]})]});}const ep={hour:"Hour",minute:"Minute",second:"Second",day:"Day",week:"Week",month:"Month",quarter:"Quarter",year:"Year"},qa=t=>ep[t??"day"]??"Day";function tp(){const t=E(a=>a.card);return!t||t.type!=="kpi"||rn(t)?null:/* @__PURE__ */e(ap,{card:t});}function ap({card:t}){var p,N,T,S,b;const{setCardConfig:a}=he(),{data:s}=He(t),r=s==null?void 0:s.metadata,l=ai(t.config),o=!!(r!=null&&r.dateContext&&!r.dateContext.field&&!l),d=((p=t.config)==null?void 0:p.kpiBand)==="trend",i=((N=t.config)==null?void 0:N.kpiTrendGrain)??"automatic",c=((S=(T=r==null?void 0:r.dateContext)==null?void 0:T.counted)==null?void 0:S.status)==="window"?r.dateContext.counted.window:void 0,x=((b=r==null?void 0:r.trend)==null?void 0:b.grainSource)==="automatic"?r.trend.granularity:void 0,u=y=>a(si(t,y).config),f=y=>a(li(t,y==="automatic"?null:y).config),h=o?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?l?"Trend By sets the grain. Remove it to pick one here.":i==="automatic"?"Follows the period the KPI counts: a different dashboard date changes it.":`Always by ${i}.`:"A line of the value over the period it counts.";return(/* @__PURE__ */n(we,{value:"kpi-trend",className:"border-none","data-role":"kpi-trend-settings",children:[/* @__PURE__ */e(Se,{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(ys,{className:"h-3.5 w-3.5 text-foreground/60","aria-hidden":!0}),/* @__PURE__ */e("span",{children:"Trend"})]})}),/* @__PURE__ */n(Te,{className:"space-y-3 pb-4 pt-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(P,{htmlFor:"kpi-trend",className:"text-xs",children:"Show trend"}),/* @__PURE__ */e(Ne,{id:"kpi-trend",size:"xs",checked:d,disabled:o&&!d,onCheckedChange:u})]}),d&&!o&&/* @__PURE__ */n("div",{className:"space-y-2","data-role":"kpi-trend-grain",children:[/* @__PURE__ */e(P,{htmlFor:"kpi-trend-grain",className:"text-xs",children:"Grain"}),l?/* @__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:[qa(l.granularity)," · from Trend By",/* @__PURE__ */e(rd,{className:"h-3 w-3 text-muted-foreground","aria-hidden":!0})]}):/* @__PURE__ */n(te,{value:i,onValueChange:f,children:[/* @__PURE__ */e(ae,{id:"kpi-trend-grain",size:"xs",children:/* @__PURE__ */e(ne,{})}),/* @__PURE__ */n(re,{children:[/* @__PURE__ */e(U,{value:"automatic",className:"text-xs",children:x?`Automatic · ${qa(x)}`:"Automatic"}),Yd.map(y=>{const F=c?ni(c,y)>ri:!1;return/* @__PURE__ */n(U,{value:y,className:"text-xs",disabled:F&&y!==i,children:[qa(y),F?" · too many points":""]},y);})]})]})]}),/* @__PURE__ */e("p",{className:"text-[11px] text-muted-foreground",children:h})]})]}));}const np=/* @__PURE__ */new Set(["area","bar","bubble","bullet","combo","doughnut","funnel","horizontalBar","line","pie","polarArea","radar","scatter","stackedArea","stackedBar","stackedLine","tornado"]);function rp(){const t=E(u=>u.card),a=E(u=>{var f;return(f=u.card)==null?void 0:f.preferences;}),s=Ke(),{setCardPreferences:r,updateCardInFrame:l}=he(),o=a==null?void 0:a.tooltipConfig,[d,i]=G(!!(o!=null&&o.valueFormat));if(!t||!np.has(s||""))return null;const c=d||o!=null&&o.valueFormat?"override":"inherit",x=u=>{const f={...(a||{}),tooltipConfig:u};r(f),l({...t,preferences:f});};return/* @__PURE__ */n(we,{value:"tooltip-format",className:"border-b-0",children:[/* @__PURE__ */e(Se,{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(ut,{className:"h-3.5 w-3.5 text-foreground/60"}),/* @__PURE__ */e("span",{children:"Tooltip Format"})]})}),/* @__PURE__ */n(Te,{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(P,{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(Ne,{size:"sm",checked:c==="override",onCheckedChange:u=>{if(i(u),!u){const{valueFormat:f,...h}=o??{};x(h);}}})]}),c==="override"&&/* @__PURE__ */e(ia,{formatOptions:Tn(o==null?void 0:o.valueFormat)||{},onFormatOptionsChange:u=>x({...o,valueFormat:kn(u)}),showTitle:!1})]})]});}function js({mode:t}){const a=E(s=>{var r;return(r=s.card)==null?void 0:r.type;});return us(a)?null:/* @__PURE__ */n(xe,{children:[a==="combo"&&/* @__PURE__ */e(Ch,{}),(a==="area"||a==="stackedArea")&&/* @__PURE__ */e(Fh,{}),a==="line"&&/* @__PURE__ */e(Lh,{}),(a==="bar"||a==="horizontalBar"||a==="stackedBar")&&/* @__PURE__ */e(Vh,{}),/* @__PURE__ */e(jh,{}),/* @__PURE__ */e(Gh,{}),/* @__PURE__ */e(ih,{}),t==="config"&&/* @__PURE__ */e(Gm,{}),t==="config"&&/* @__PURE__ */e(Zh,{}),t==="config"&&/* @__PURE__ */e(tp,{}),/* @__PURE__ */e(ch,{}),a==="bullet"&&/* @__PURE__ */e(dh,{}),a==="funnel"&&/* @__PURE__ */e(hh,{}),(a==="bubble"||a==="scatter")&&/* @__PURE__ */e(uh,{}),(a==="stackedBar"||a==="stackedLine")&&/* @__PURE__ */e(Wh,{}),/* @__PURE__ */e(nh,{}),/* @__PURE__ */e(rh,{}),/* @__PURE__ */e(sh,{}),/* @__PURE__ */e(lh,{}),/* @__PURE__ */e(rp,{})]});}function sp(){const t=E(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(Bs,{chartType:a}),/* @__PURE__ */e(la,{type:"single",collapsible:!0,className:"w-full px-2",children:/* @__PURE__ */e(js,{mode:"dev"})})]}):null;}function lp({focusSection:t,focusRequestId:a}){const r=E(o=>o.card).type;function l(){if(ln(r))return/* @__PURE__ */e($s,{cardType:r,focusSection:t,focusRequestId:a});switch(r){case"kpi":return/* @__PURE__ */e(zm,{});case"custom":return/* @__PURE__ */e("div",{className:"px-6 py-2",children:/* @__PURE__ */e(Ds,{})});case"text":return/* @__PURE__ */e(Jm,{});case"customVisual":return/* @__PURE__ */e("div",{className:"px-6",children:/* @__PURE__ */e(_s,{})});default:return/* @__PURE__ */e(sp,{});}}return/* @__PURE__ */n(xn,{className:"h-full w-full text-sm",children:[l(),/* @__PURE__ */e(sd,{orientation:"horizontal"})]});}const ip=32;function op(){const t=Ie(null),a=E(f=>f.isDevMode),[s,r]=G(!1),[l,o]=G({section:null,id:0}),d=!a||s,i=()=>r(f=>!f),c=f=>{f&&o(h=>({section:f,id:h.id+1})),a&&r(!0);},x=()=>{const f=t.current;f&&(f.isCollapsed()?f.expand():f.collapse());},u={show:a,isOpen:d,onToggle:i,onOpen:c};return/* @__PURE__ */n(en,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[/* @__PURE__ */e(St,{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(ju,{})})}),/* @__PURE__ */e(Cm,{onToggleEditor:x,children:/* @__PURE__ */e(Pa,{mode:"toolbar",visualAsideControl:u})}),/* @__PURE__ */e(St,{role:"visual-section",minSize:0,defaultSize:50,children:d?/* @__PURE__ */n(en,{direction:"horizontal",children:[/* @__PURE__ */e(St,{minSize:40,defaultSize:75,maxSize:100,children:/* @__PURE__ */e(Pa,{mode:"canvas",visualAsideControl:u})}),/* @__PURE__ */e(Cs,{}),/* @__PURE__ */e(St,{className:"flex",defaultSize:ip,maxSize:45,children:/* @__PURE__ */e(lp,{focusSection:l.section,focusRequestId:l.id})})]}):/* @__PURE__ */e(Pa,{mode:"canvas",visualAsideControl:u})})]});}const cp="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 xr({label:t}){const a=t.indexOf(" › ");return a<0?/* @__PURE__ */e(xe,{children:t}):/* @__PURE__ */n(xe,{children:[t.slice(0,a)," ",/* @__PURE__ */e("span",{className:"mx-1 text-muted-foreground",children:"›"})," ",t.slice(a+3)]});}function Hs({id:t,field:a,zone:s,label:r,dataType:l,nativeDataType:o,calculated:d,open:i,onOpenChange:c,onRemove:x,sortDirection:u,onSortDirectionChange:f,badge:h,children:p}){const{attributes:N,listeners:T,setNodeRef:S,isDragging:b}=Ko({id:qo(t),data:{origin:s,field:a}}),{setNodeRef:y}=Wr({id:$o(t),data:{kind:"pill",zone:s,pillId:t}}),F=rt(v=>{S(v),y(v);},[S,y]);return/* @__PURE__ */n(lt,{modal:!0,open:i,onOpenChange:c,children:[/* @__PURE__ */n("div",{ref:F,className:Q("group flex h-7 w-full items-center gap-1.5 rounded-control border bg-background px-1.5 transition-colors",i?"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,...T,"aria-label":`Drag ${r}`,className:cp,onClick:v=>v.stopPropagation(),children:/* @__PURE__ */e(ts,{className:"h-3 w-3"})}),/* @__PURE__ */e(jo,{dataType:l,nativeDataType:o,calculated:d}),p?/* @__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:v=>v.stopPropagation(),children:/* @__PURE__ */e(Hn,{className:"block truncate",children:/* @__PURE__ */e(xr,{label:r})})})}):/* @__PURE__ */e(Hn,{className:"block w-0 min-w-0 flex-1 text-[12px] text-foreground",children:/* @__PURE__ */e(xr,{label:r})}),h,f&&/* @__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:v=>{v.stopPropagation(),f(u==="asc"?"desc":"asc");},children:u==="asc"?/* @__PURE__ */e(ld,{className:"h-3 w-3"}):/* @__PURE__ */e(id,{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:v=>{v.stopPropagation(),x();},children:/* @__PURE__ */e(ca,{className:"h-3 w-3"})})]}),p&&/* @__PURE__ */n(it,{align:"start",sideOffset:6,className:"flex max-h-[480px] w-[320px] flex-col p-0",children:[/* @__PURE__ */e(Ho,{field:a,title:r,onClose:()=>c(!1)}),/* @__PURE__ */e("div",{className:"min-h-0 flex-1 space-y-3 overflow-y-auto p-3",children:p})]})]});}function dp(t){const a=Uo(t),{field:s,zone:r}=t;return/* @__PURE__ */n(xe,{children:[/* @__PURE__ */e(Hs,{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 up({field:t,zone:a,onRemove:s}){const[r,l]=G(!1);return/* @__PURE__ */e(Hs,{id:t.id,field:t,zone:a,label:ii(t),dataType:t.dataType,nativeDataType:t.nativeDataType,calculated:Qo(t),open:r,onOpenChange:l,onRemove:s,children:/* @__PURE__ */e(Ua,{fieldId:t.id})});}function mp({concept:t}){const{title:a,description:s}=hp[t];return/* @__PURE__ */n(Tt,{openDelay:150,closeDelay:50,children:[/* @__PURE__ */e(kt,{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(hu,{className:"h-3 w-3"})})}),/* @__PURE__ */n(Et,{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(pp,{highlight:t})]})]});}const hp={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 pp({highlight:t}){const a=t==="pivotBy",s=t==="groupBy",r=t==="metrics",l="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(o=>/* @__PURE__ */e("th",{className:Q("px-1.5 py-1 text-center font-normal text-muted-foreground",a&&l),children:o},o))]})}),/* @__PURE__ */e("tbody",{children:br.map((o,d)=>/* @__PURE__ */n("tr",{className:Q(d!==br.length-1&&"border-b border-border/60"),children:[/* @__PURE__ */e("td",{className:Q("px-1.5 py-1 text-left text-muted-foreground",s&&l),children:o.label}),o.values.map((i,c)=>/* @__PURE__ */e("td",{className:Q("px-1.5 py-1 text-right font-mono tabular-nums text-muted-foreground",r&&l),children:i},c))]},o.label))})]})});}const br=[{label:"Electronics",values:["2,300","1,800","3,400"]},{label:"Clothing",values:["1,300","620","480"]}],fp={groupBy:ss,pivotBy:rs,metrics:Xo,detailColumns:es,sortBy:gs};function qt({onRemoveField:t,zone:a,fields:s,label:r,placeholder:l,shouldShow:o,hasPivotColumns:d=!1}){const{setNodeRef:i}=Wr({id:Go(a),data:{kind:"shelf",zone:a,pillIds:s.map(v=>v.id)}}),c=Wo(a),{updateSortByColumn:x}=he(),u=E(v=>v.card),f=E(v=>v.card.type),h=s.length>0,p=c!==null,N=(c==null?void 0:c.kind)!=="refused",T=(c==null?void 0:c.kind)==="refused"?Yo(c.notice,r):null,S=rt((v,D)=>{var j;!((j=u.config)!=null&&j.sortByColumns)||u.config.sortByColumns.findIndex(_=>_.id===v)===-1||x(u.id,v,{direction:D});},[u,x]),b=J(()=>/* @__PURE__ */e("div",{className:"space-y-1",children:s.map((v,D)=>{const j=v.direction;return/* @__PURE__ */n("div",{className:"relative",children:[/* @__PURE__ */e(gp,{zone:a,pillId:v.id,isLast:D===s.length-1}),f==="matrixTable"?/* @__PURE__ */e(up,{field:v,zone:a,onRemove:()=>t(a,D)}):/* @__PURE__ */e(dp,{field:v,zone:a,index:D,sortDirection:j,onSortDirectionChange:_=>S(v.id,_),hasPivotColumns:d,cardType:f})]},v.id);})}),[s,a,f,d,t,S]);if(a==="sortBy"&&o===!1)return null;const y=a!=="sortBy"&&f!=="kpi",F=fp[a]||ba;return/* @__PURE__ */n("div",{ref:i,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(P,{className:"block shrink-0 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:r}),T&&/* @__PURE__ */e("span",{role:"status","data-shelf-refusal-reason":"",className:"min-w-0 truncate text-[11px] text-destructive",children:T})]}),/* @__PURE__ */e("div",{className:Q("rounded-control transition-colors",{"border border-foreground/40 bg-muted/50":p&&N,"border border-destructive/40 bg-destructive/5":p&&!N,"border border-dashed border-border/50 bg-background":!p&&!h}),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(F,{className:"h-3 w-3 shrink-0 text-muted-foreground/60"}),/* @__PURE__ */e("span",{children:l}),y&&/* @__PURE__ */e(mp,{concept:a})]}):b})]});}function gp({zone:t,pillId:a,isLast:s}){const r=Jo(t,a,s);return r?/* @__PURE__ */n("div",{"aria-hidden":!0,"data-shelf-insertion-line":r,className:Q("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 xp="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function bp({card:t,metric:a,children:s}){var x,u;const{data:r}=He(t),l=r==null?void 0:r.metadata,o=Bd(l==null?void 0:l.dateContext,a?cs(l==null?void 0:l.comparisonMetadata,a):void 0),d=r==null?void 0:r.records,i=((x=oi({renderCard:t,records:d,metadata:l}).trend)==null?void 0:x.points.length)??0,c=((u=t.config)==null?void 0:u.kpiBand)==="trend"?Xd(l==null?void 0:l.trend,i):void 0;return/* @__PURE__ */e(xe,{children:s(o,c)});}function yp({view:t,trend:a}){const s=be(l=>l.dashboard),r=zd(t,{cardTitle:l=>{var o;return s?(o=Td(s,l))==null?void 0:o.title:void 0;}});return/* @__PURE__ */e(vp,{words:r,trend:a});}function vp({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:xp,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(od,{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:Q(!s.applied&&"opacity-50"),children:[/* @__PURE__ */e("div",{className:Q("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:Q("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(cd,{className:"mt-0.5 h-3.5 w-3.5 shrink-0","aria-hidden":!0}):/* @__PURE__ */e(ut,{className:"mt-0.5 h-3.5 w-3.5 shrink-0","aria-hidden":!0}),/* @__PURE__ */e("span",{children:t.note.text})]})]})]});}const Np=[];function Cp({onRemoveField:t,onResetFields:a,groupByFields:s,pivotByFields:r,metricsFields:l,sortByFields:o,detailFields:d}){var W,ee,ie;const[i,c]=G(!1),{startOver:x,restore:u}=Zo();E(Y=>{var H;return!!((H=Y.card.customCardPreferences)!=null&&H.url);});const f=E(Y=>Y.card),h=E(Y=>Y.frame),p=vt(h,f),{manifest:N}=bt(((W=p==null?void 0:p.customCardPreferences)==null?void 0:W.url)||""),T=(ee=N==null?void 0:N.visuals)==null?void 0:ee.find(Y=>{var H;return Y.name===((H=p==null?void 0:p.customCardPreferences)==null?void 0:H.componentName);}),S=Nt(p,T)==="multiple";S&&(ie=p==null?void 0:p.customCardPreferences)!=null&&ie.url;const b=Ad(T==null?void 0:T.slots);E(Y=>Y.actions.updateCardConfig);const y=E(Y=>Y.actions.updateCard),F=be(Y=>Y.actions.updateDashboardCalculatedFields),D=be(Y=>{var H;return Y.visualEditPendingDashboardCalculatedFields??((H=Y.dashboard)==null?void 0:H.calculatedFields);})??Np,{scopedFields:K}=Gr(),{userContext:j}=cn(),_=S&&(p==null?void 0:p.id)===f.id&&b?b:f==null?void 0:f.type,k=_==="detailTable",A=s.length>0||l.length>0||d.length>0,$=!k&&(_!=="kpi"||l.length<=2),C=!k,R=!k&&_!=="kpi",I=_!=="kpi"&&_!=="matrixTable"&&A,m=k,M="Drop sort fields here",g=ec(j),w=["pie","doughnut","polar","funnel","bubble","scatter"].includes(_),O=R&&!w,q=_==="kpi"&&f.type==="kpi"&&!S&&!rn(f),z=Y=>_==="kpi"?{label:"Trend By",placeholder:Kd(Y)??"Drop trend field here"}:{label:"Rows",placeholder:"Drop dimensions here"},L=()=>_==="kpi"?{label:"Metric",placeholder:"Drop metric here"}:{label:"Metrics",placeholder:"Drop metrics here"},V=(Y,H)=>/* @__PURE__ */n("div",{className:"space-y-3 px-4 pb-6 pt-3",children:[$&&/* @__PURE__ */e(qt,{zone:"groupBy",onRemoveField:t,fields:s,label:z(Y).label,placeholder:z(Y).placeholder}),O&&/* @__PURE__ */e(qt,{zone:"pivotBy",onRemoveField:t,fields:r,label:"Pivot Columns",placeholder:"Drop pivot fields here"}),C&&/* @__PURE__ */e(qt,{zone:"metrics",onRemoveField:t,fields:l,label:L().label,placeholder:L().placeholder,hasPivotColumns:r.length>0}),m&&/* @__PURE__ */e(qt,{zone:"detailColumns",onRemoveField:t,fields:d,label:"Columns",placeholder:"Drop columns here"}),l.length>=1&&g&&/* @__PURE__ */n(le,{variant:"outline",size:"sm",onClick:()=>c(!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(rc,{className:"mr-2 h-4 w-4"}),"Create Metric"]}),Y&&/* @__PURE__ */e(yp,{view:Y,trend:H}),I&&/* @__PURE__ */e(qt,{zone:"sortBy",onRemoveField:t,fields:o,label:"Sort By",placeholder:M})]});return/* @__PURE__ */n(xe,{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(Sp,{card:f,hasFields:A,onClearFields:()=>{var fe;const Y=f,H=ci.flatMap(ue=>{var ke;return((ke=Y.config)==null?void 0:ke[ue])??[];}),X=((fe=ja(Y))==null?void 0:fe.joins)??[];a();const de=H.map(ue=>ue.label||ue.name),pe=de.length>4?`${de.slice(0,3).join(", ")} and ${de.length-3} more`:de.join(", "),oe=X.length===1?` The join to ${Er(X[0].target)} stays.`:X.length?" The joins stay.":"";nt("Cleared the fields",{description:`${pe?`Removed ${pe}.`:""}${oe}`.trim()||void 0,action:{label:"Undo",onClick:()=>u(Y)}});},onStartOver:x})]}),q?/* @__PURE__ */e(bp,{card:f,metric:l[0],children:(Y,H)=>V(Y,H)}):V(void 0),/* @__PURE__ */e(tc,{open:i,onOpenChange:c,availableFields:K,initialFieldType:"metric",allowedFieldTypes:["metric"],onSave:Y=>{if(Y.role!=="metric")return;const{nextStoredFields:H}=nc({storedFields:f.calculatedFields||[],sharedFields:D,updatedField:Y,previousScope:"card"});y(f.id,{calculatedFields:H});},onSaveToDashboard:Y=>{if(Y.role!=="metric")return;const{nextSharedFields:H}=ac({storedFields:f.calculatedFields||[],sharedFields:D,updatedField:Y,previousScope:"dashboard"});F(H);},cardId:f.id})]});}function wp(){var F,v,D;const t=E(K=>{var j;return(j=K.card)==null?void 0:j.type;}),a=t==="kpi",s=t==="customVisual",[r,l]=G(a||s),[o,d]=G(!1),i=E(K=>{var j;return!!((j=K.card.customCardPreferences)!=null&&j.url);}),c=E(K=>K.card),x=E(K=>K.frame),u=vt(x,c),{manifest:f}=bt(((F=u==null?void 0:u.customCardPreferences)==null?void 0:F.url)||""),h=(v=f==null?void 0:f.visuals)==null?void 0:v.find(K=>{var j;return K.name===((j=u==null?void 0:u.customCardPreferences)==null?void 0:j.componentName);}),N=Nt(u,h)==="multiple"&&!!((D=u==null?void 0:u.customCardPreferences)!=null&&D.url),T=!i||N,S=i||N,b=a?"KPI Settings":s?"Visual":"Chart Settings",y=T&&!us(t);return ye(()=>{(a||s)&&l(!0);},[a,s]),!y&&!S?null:/* @__PURE__ */n("div",{className:"shrink-0 border-t border-border bg-background",children:[y&&r&&/* @__PURE__ */e("div",{className:Q("overflow-y-auto border-b border-border px-4",a?"max-h-[72vh]":"max-h-[50vh]"),children:s?/* @__PURE__ */e(_s,{}):/* @__PURE__ */e(la,{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(js,{mode:"config"})})}),y&&/* @__PURE__ */n("button",{type:"button",onClick:()=>l(K=>!K),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(xa,{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:b})]}),/* @__PURE__ */e(Mt,{className:Q("h-3 w-3 text-muted-foreground transition-transform",r&&"rotate-180"),strokeWidth:1.75})]}),S&&o&&/* @__PURE__ */e("div",{className:"max-h-[40vh] overflow-y-auto border-b border-t border-border px-4",children:/* @__PURE__ */e(Ds,{})}),S&&/* @__PURE__ */n("button",{type:"button",onClick:()=>d(K=>!K),className:Q("flex w-full items-center justify-between px-4 py-2.5 text-left transition-colors hover:bg-muted/50",y&&"border-t border-border"),children:[/* @__PURE__ */n("span",{className:"inline-flex items-center gap-2",children:[/* @__PURE__ */e(xs,{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(Mt,{className:Q("h-3 w-3 text-muted-foreground transition-transform",o&&"rotate-180"),strokeWidth:1.75})]})]});}function Sp({card:t,hasFields:a,onClearFields:s,onStartOver:r}){var d,i;if(!(t.type==="matrixTable"?[]:((d=ja(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 o=Er((i=ja(t))==null?void 0:i.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(pa,{modal:!1,children:[/* @__PURE__ */e(fa,{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(Mt,{className:"h-3 w-3"})})}),/* @__PURE__ */n(ga,{align:"end",className:"w-[240px]",children:[/* @__PURE__ */n(Ue,{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(Ue,{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:o})]})]})]})]})]});}function Tp(){const t=E(i=>i.card),{autoJoinMetadata:a}=He(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 l=i=>!i||i.length===0?"No conditions":i.map(c=>{var h,p,N,T;const x=`${(h=c.source)==null?void 0:h.entityName}.${(p=c.source)==null?void 0:p.name}`,u=`${(N=c.target)==null?void 0:N.entityName}.${(T=c.target)==null?void 0:T.name}`,f=c.operator||"=";return`${x} ${f} ${u}`;}).join(" AND "),o=i=>!i.joinKeyGroups||i.joinKeyGroups.length===0?"No conditions defined":i.joinKeyGroups.length===1?l(i.joinKeyGroups[0].keys):i.joinKeyGroups.map((c,x)=>({id:x,operator:c.operator,condition:l(c.keys)})),d=/* @__PURE__ */e(Lt,{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((i,c)=>{const x=o(i),u=Array.isArray(x);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:i.source.name}),/* @__PURE__ */e(dd,{className:"size-3 text-muted-foreground"}),/* @__PURE__ */e("span",{className:"font-medium text-foreground",children:i.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:i.joinType})]}),/* @__PURE__ */e("div",{className:"mt-1 space-y-1",children:u?x.map(f=>/* @__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:f.condition}),f.operator&&/* @__PURE__ */n("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",f.operator,")"]})]},f.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:x})})})]},i.id||c);})})})]})});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(sc,{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 kp({onRemoveField:t,onResetFields:a,selectedChart:s,onChartChange:r,isVisible:l=!0,groupByFields:o,pivotByFields:d,metricsFields:i,sortByFields:c,detailFields:x}){const u=E(h=>h.editorContext),f=(u==null?void 0:u.type)==="documentSection";return/* @__PURE__ */n("div",{"data-content":"Chart Configuration Panel",className:Q("flex shrink-0 flex-col overflow-hidden border-r border-border bg-background",vs,!l&&"hidden"),children:[!f&&/* @__PURE__ */e(om,{selectedChart:s,onChartChange:r}),/* @__PURE__ */n(xn,{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(Tp,{})}),/* @__PURE__ */e(Cp,{onRemoveField:t,onResetFields:a,groupByFields:o,pivotByFields:d,metricsFields:i,sortByFields:c,detailFields:x})]}),/* @__PURE__ */e(wp,{})]});}function Ep({cardId:t,filters:a,onFiltersChange:s,onClearFilters:r,availableFields:l,source:o,isOpen:d,onOpenChange:i}){return/* @__PURE__ */n(Pt,{modal:!1,open:d,onOpenChange:i,children:[d&&/* @__PURE__ */e("div",{className:"pointer-events-none fixed inset-0 z-40 bg-zinc-950/40 backdrop-blur-sm"}),/* @__PURE__ */n(Dt,{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(ya,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */e(_t,{className:"truncate text-[13px] font-medium",children:"Card filters"}),/* @__PURE__ */e(dt,{className:"sr-only",children:"Add filters to the card to limit the data that is displayed."})]}),/* @__PURE__ */e(Dd,{filters:a,availableFields:l,source:o,onSave:u=>{s(t,u),i(!1);},onCancel:()=>i(!1),onClearAll:()=>{r(t),i(!1);}})]})]});}function Ip({activeView:t,onViewChange:a,splitViewEnabled:s,hasQueryError:r=!1}){const l=E(x=>x.card),{config:o}=wn(bn).tokenProps,d=(o==null?void 0:o.showInfoTab)!==!1&&Ir(l.type),i=!s&&on(l.type),c=[{id:"chart",label:"Visual"}];return l.type==="customVisual"&&c.push({id:"code",label:"Code"}),i&&c.push({id:"table",label:"Results"}),d&&c.push({id:"info",label:r?"Error":"Query",isError:r}),/* @__PURE__ */e(ft,{value:t,onValueChange:x=>a(x),children:/* @__PURE__ */e(gt,{variant:"underline",className:"gap-5 border-b-0",children:c.map(x=>/* @__PURE__ */e(ze,{value:x.id,className:Q("px-0 text-[13px]",x.isError&&"text-destructive hover:text-destructive focus-visible:text-destructive data-[state=active]:border-destructive data-[state=active]:text-destructive"),children:x.label},x.id))})});}const Fp=[{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 Mp(){var s,r;const t=E(l=>l.card),{updateRowLimit:a}=he();return/* @__PURE__ */n(te,{value:((r=(s=t.config)==null?void 0:s.rowLimit)==null?void 0:r.toString())||"100",onValueChange:l=>a(t.id,parseInt(l)),children:[/* @__PURE__ */n(ae,{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(ne,{})})]}),/* @__PURE__ */e(re,{align:"end",children:Fp.map(l=>/* @__PURE__ */e(U,{value:l.value,className:"text-[12px] tabular-nums",children:l.label},l.value))})]});}function Op({card:t,queryData:a,isLoading:s,isFetching:r,pagination:l,onPaginationChange:o,onSortChange:d,sortState:i,splitViewEnabled:c}){var u;const x=J(()=>(a==null?void 0:a.records)||[],[a==null?void 0:a.records]);return!c||!on(t.type)?/* @__PURE__ */e(nn,{}):/* @__PURE__ */n(en,{direction:"vertical",className:"h-full min-h-0 w-full",children:[/* @__PURE__ */e(St,{defaultSize:60,minSize:30,role:"chart-section",className:"flex flex-col",children:/* @__PURE__ */e(nn,{})}),/* @__PURE__ */e(Cs,{withHandle:!0,title:"Drag to resize."}),/* @__PURE__ */e(St,{defaultSize:40,minSize:20,role:"results-section",className:"flex flex-col",children:/* @__PURE__ */n("div",{className:Q("relative flex h-full min-h-0 max-w-full flex-1 grow basis-0",dn),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(tt,{size:"md",color:"muted","aria-label":"Loading data"})}),(a==null?void 0:a.records)&&/* @__PURE__ */e(aa,{card:t,data:x,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:l,onPaginationChange:o,isLoading:s||r,onSortChange:d,sortState:i})]})})]});}function Ap(t,a){const[s,r]=G(()=>{const l=localStorage.getItem(t);return l?JSON.parse(l):a;});return ye(()=>{localStorage.setItem(t,JSON.stringify(s));},[s,t]),[s,r];}const Rp="semaphor-split-view-enabled";function Lp(){return Ap(Rp,!0);}function Pp({error:t,showInfoTab:a}){return/* @__PURE__ */e(lc,{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 Dp({card:t,effectiveCardType:a=t.type,queryOutput:s}){return ln(a)?/* @__PURE__ */n(ud,{modal:!1,children:[/* @__PURE__ */e(md,{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(xa,{className:"h-3.5 w-3.5",strokeWidth:1.75})})}),/* @__PURE__ */n(hd,{side:"right",hideOverlay:!0,className:"flex w-[420px] flex-col gap-0 p-0 sm:max-w-[420px]",children:[/* @__PURE__ */e(pd,{className:"sr-only",children:"Table settings"}),/* @__PURE__ */e(fd,{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($s,{cardType:a,queryOutput:s,focusSection:"style"})})]})]}):null;}function _p({className:t,visible:a}){const s=be(i=>i.selectedFrameId),r=ic(i=>i.selectedVisual),l=E(i=>i.frame),d=!!!(l!=null&&l.visualId||r!=null&&r.id)&&!!s;return!a||d?null:/* @__PURE__ */e("div",{className:Q("flex",t),children:/* @__PURE__ */e(hs,{showLabel:!0,className:"h-6 w-fit px-2 py-0.5 text-[11px]"})});}function Vp({activeView:t,onViewChange:a,onFiltersClick:s,activeCard:r,sidePanels:l}){var Be;const o=E(ce=>ce.card),d=E(ce=>ce.inlineFilterValuesMap[(r==null?void 0:r.id)||""]),i=E(ce=>ce.actions.removeCardInlineFilterValue),c=be(ce=>ce.selectedSheetId),{updateCardConfig:x,setCard:u,updateCardInFrame:f}=he(),[h,p]=G(!1),[N,T]=G(!1),[S,b]=G(null),{config:y}=wn(bn).tokenProps,F=(y==null?void 0:y.showInfoTab)!==!1,v=(y==null?void 0:y.showQueryDebugTools)!==!1,[D,K]=Lp(),j=on(o.type),_=F&&Ir(o.type),k=F&&!_,A=t==="table"&&(D||!j)||t==="info"&&!_||t==="code"&&o.type!=="customVisual"?"chart":t;E(ce=>{var Fe;return!!((Fe=ce.card.customCardPreferences)!=null&&Fe.url);});const $=Ke(),{data:C,errorMessage:R,isLoading:I,isFetching:m,errorSql:M,pagination:g,refetch:w,comparisonMetadata:O,queryRequestPayload:q,resolvedPrimaryDateField:z}=He(r),L=ma(r,C),V=()=>{var Oe;const ce=be.getState(),Fe=Qu(Fn.QUERY_GENERATION,{cardConfig:o.config,dataSource:r.dataSource,dashboardFilters:Ud({dashboard:ce.dashboard,runtimeValues:{dashboardInputValues:ce.dashboardInputValues},adHocFilterValues:ce.adHocFilterValues,sheetId:c,sheetKind:"dashboard",calendar:((Oe=ce.reportContext)==null?void 0:Oe.calendar)??null}),errorMessage:R,errorSql:M,generatedSql:C==null?void 0:C.sql});b(Fe),T(!0);},W=()=>{const ce=E.getState().actions;ce.setIsDevMode(!0),ce.setCardSql(M||""),setTimeout(()=>{ce.setRunSql(!0);},100);},ee=v?{queryRequest:q,queryResponse:C}:void 0,ie=J(()=>(C==null?void 0:C.records)||[],[C==null?void 0:C.records]),Y=J(()=>!m&&ie.length>0?Object.keys(ie[0]):[],[m,ie]),H=J(()=>({keys:Y,columnKeyMap:C==null?void 0:C.columnKeyMap,resultColumns:C==null?void 0:C.columns}),[Y,C==null?void 0:C.columnKeyMap,C==null?void 0:C.columns]),X=$r(r),de=E(ce=>ce.frame),[pe,oe]=G(),fe=()=>{const ce=!D;ce&&A==="table"&&a("chart"),K(ce);},ue=(ce,Fe)=>{const Oe={...r,paginationConfig:{page:ce+1,pageSize:Fe}};u(Oe),f(Oe);},ke=ce=>{if(!o.config)return;const Fe=_r(ce,o.config.metricColumns,o.config.groupByColumns,o.config.detailColumns);x(o.id,{...o.config,sortByColumns:Fe});},Ve=J(()=>{var ce;return oc((ce=o.config)==null?void 0:ce.sortByColumns);},[(Be=o.config)==null?void 0:Be.sortByColumns]),qe=cc(ea(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:Q("flex h-11 items-center gap-3 border-b border-border px-4",l&&"pl-2"),children:[l&&/* @__PURE__ */n("div",{className:"flex items-center gap-3 self-end pb-1",children:[/* @__PURE__ */e(_e,{tooltip:l.visible?"Hide fields and configuration":"Show fields and configuration","aria-label":l.visible?"Hide fields and configuration":"Show fields and configuration","aria-pressed":!l.visible,onClick:l.onToggle,className:"h-7 w-7 shrink-0 rounded-[5px] p-0 text-muted-foreground hover:text-foreground",children:l.visible?/* @__PURE__ */e(yu,{className:"h-4 w-4",strokeWidth:1.75}):/* @__PURE__ */e(vu,{className:"h-4 w-4",strokeWidth:1.75})}),/* @__PURE__ */e("span",{"aria-hidden":!0,className:"h-4 w-px shrink-0 bg-border"})]}),/* @__PURE__ */n("div",{className:"flex items-baseline gap-3",children:[/* @__PURE__ */e("div",{className:"flex h-11 items-end gap-5",children:/* @__PURE__ */e(Ip,{activeView:A,onViewChange:a,splitViewEnabled:D,hasQueryError:!!R})}),$==="kpi"&&/* @__PURE__ */e(_p,{visible:!0,className:"self-center"}),O&&o.type!=="table"&&/* @__PURE__ */e(gd,{metadata:O})]}),/* @__PURE__ */n("div",{className:"flex grow items-center justify-end gap-1",children:[!xd($)&&/* @__PURE__ */e(Mp,{}),/* @__PURE__ */e(dc,{cardId:r.id,cardFilters:ea(r),cardFilterCount:qe,onFiltersClick:s,inlineFilters:ui(r),inlineFilterValues:di(r,d),sheetId:c||"",removeInlineFilterValue:ce=>i(r.id,ce),resolvedPrimaryDateField:z}),A==="chart"&&/* @__PURE__ */e(Dp,{card:r,effectiveCardType:$,queryOutput:H}),A==="chart"&&/* @__PURE__ */e(Ls,{showInlineFilters:!1,showControls:!1,showDisplayOptions:!1}),/* @__PURE__ */n(pa,{modal:!1,children:[/* @__PURE__ */e(fa,{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(jr,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(ga,{align:"end",className:"w-60",children:[/* @__PURE__ */n(Ue,{disabled:X?X.isFetching:I||m,onSelect:()=>{var ce;if(X){(ce=X.refresh)==null||ce.call(X);return;}wt(),w();},children:[/* @__PURE__ */e(Za,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Refresh"]}),A==="chart"&&/* @__PURE__ */n(xe,{children:[/* @__PURE__ */n(Ue,{onSelect:s,children:[/* @__PURE__ */e(ya,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Card filters",qe>0&&/* @__PURE__ */e("span",{className:"ml-auto text-[11px] tabular-nums text-muted-foreground",children:qe})]}),/* @__PURE__ */e(On,{triggerVariant:"menu",className:"w-full"}),/* @__PURE__ */e(An,{triggerVariant:"menu",className:"w-full"}),/* @__PURE__ */e(Mn,{triggerVariant:"menu",className:"w-full"}),j&&/* @__PURE__ */n(Ue,{onClick:fe,children:[D?/* @__PURE__ */e(xu,{className:"h-3.5 w-3.5 text-muted-foreground"}):/* @__PURE__ */e(Su,{className:"h-3.5 w-3.5 text-muted-foreground"}),D?"Hide results table":"Show results table"]}),X&&/* @__PURE__ */n(Ue,{disabled:X.isFetching||!X.hasDelivery,title:X.hasDelivery?void 0:"Available once the preview has loaded.",onClick:()=>oe(X.readDelivery()),children:[/* @__PURE__ */e(Wa,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Download"]})]})]})]})]})]}),/* @__PURE__ */n("div",{className:"flex min-h-0 grow flex-col",children:[A==="chart"?R?k?/* @__PURE__ */e("div",{className:"flex min-h-0 flex-1 flex-col px-1 pb-2",children:/* @__PURE__ */e(Un,{error:R,errorSql:M,onSendFeedback:V,onOpenInEditor:sn(o.type)?W:void 0})}):/* @__PURE__ */e(Pp,{error:R,showInfoTab:_}):/* @__PURE__ */e("div",{className:"flex grow flex-col",children:/* @__PURE__ */e(Op,{card:L,queryData:C,isLoading:I,isFetching:m,pagination:g,onPaginationChange:ue,onSortChange:ke,sortState:Ve,splitViewEnabled:D})}):null,A==="table"&&(C==null?void 0:C.records)&&/* @__PURE__ */n("div",{className:Q("relative flex h-full min-h-0 max-w-full flex-1 grow basis-0",dn),children:[(I||m)&&(C==null?void 0:C.records)&&/* @__PURE__ */e("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-background/50",children:/* @__PURE__ */e(tt,{size:"md",color:"muted","aria-label":"Loading data"})}),/* @__PURE__ */e(aa,{card:L,data:ie,resultColumns:C.columns,columnKeyMap:C.columnKeyMap,totalsByColumnId:C==null?void 0:C.tableTotalsByColumnId,columnTotals:C==null?void 0:C.tableColumnTotals,comparisonMetadata:O,paginationMetadata:g,onPaginationChange:ue,isLoading:I||m,onSortChange:ke,sortState:Ve})]}),A==="code"&&/* @__PURE__ */e(Is,{}),A==="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:R?/* @__PURE__ */e(Un,{error:R,errorSql:M,defaultDetailsOpen:!0,debugPayloads:ee,onSendFeedback:V,onOpenInEditor:W}):((C==null?void 0:C.sql)&&/* @__PURE__ */e(Ps,{sql:C.sql,debugPayloads:ee}))})})]}),pe&&r&&de&&/* @__PURE__ */e(ls,{isOpen:!0,onClose:()=>oe(void 0),card:r,frame:de,matrix:pe}),S&&/* @__PURE__ */e(In,{open:N,onOpenChange:T,feedbackData:S})]})});}const Bp=()=>{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 l;if((l=r.reason)!=null&&l.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 zp(){const[t,a]=G("chart"),[s,r]=G(!1),[l,o]=G(!0),d=En(),i=E(R=>R.card.type);ye(()=>Bp(),[]);const c=R=>{d(R);},x=E(R=>R.frame),u=E(R=>R.card);E(R=>R.activeTabCardId),E(R=>R.actions.getAvailableFields);const{addCard:f,removeCard:h,updateCard:p,setActiveCard:N,updateFilters:T,clearFilters:S}=he(),{scopedFields:b=[]}=qr(),y=u,{getFieldsForContainer:F,placeField:v,previewFieldPlacement:D,removeField:K,resetFields:j}=fn(y,b),_=(R,I)=>{I&&T(R,I);},k=R=>{S(R);},{filterableFields:A}=uc(u),$=R=>{if(!R)return 0;let I=R.conditions.length;return R.groups.forEach(m=>{I+=$(m);}),I;},C=$(ea(y)||null);return(/* @__PURE__ */n(mc,{activeCardId:x.activeCardId,placeField:v,previewFieldPlacement:D,children:[/* @__PURE__ */n("div",{className:"flex h-full grow",children:[/* @__PURE__ */e(Ns,{isVisible:l}),/* @__PURE__ */n("div",{className:"flex flex-1 transition-all duration-300 ease-in-out",children:[/* @__PURE__ */e(kp,{onRemoveField:K,onResetFields:j,selectedChart:i,onChartChange:c,groupByFields:F("groupBy"),pivotByFields:F("pivotBy"),metricsFields:F("metrics"),sortByFields:F("sortBy"),detailFields:F("detailColumns"),isVisible:l}),/* @__PURE__ */e(Vp,{selectedChart:i,activeView:t,onViewChange:R=>{wt(),a(R);},onFiltersClick:()=>r(!0),filterCount:C,activeCard:y,getFieldsForContainer:F,cards:x.cards,activeCardId:x.activeCardId,addCard:f,setActiveCard:N,sidePanels:{visible:l,onToggle:()=>o(R=>!R)}})]})]}),y&&/* @__PURE__ */e(Ep,{cardId:y.id,filters:ea(y)||null,onFiltersChange:_,onClearFilters:k,availableFields:A,isOpen:s,onOpenChange:r})]}));}function Kp({authToken:t,onSave:a,onClose:s}){const r=E(u=>u.isDevMode),l=yn(),{setAuthToken:o}=bd(),{setOnSave:d,setOnClose:i}=he();ye(()=>{a&&d(a),s&&i(s);},[a,d,s,i]),ye(()=>{t&&t.accessToken&&o(t);},[t,o]);function c(){return/* @__PURE__ */n(xe,{children:[/* @__PURE__ */e(Ns,{}),/* @__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(op,{})})})]});}function x(){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(zp,{})})});}return(/* @__PURE__ */e(yd,{children:/* @__PURE__ */e(ha,{FallbackComponent:hc,children:r?/* @__PURE__ */e("section",{className:"isolate flex h-full grow","data-content":"editor-panel",style:l.dashboardContainerStyle,children:c()}):/* @__PURE__ */e("section",{className:"isolate flex h-full grow","data-content":"editor-panel",style:l.dashboardContainerStyle,children:x()})})}));}function vf(){be(p=>p.selectedCardId);const t=be(p=>p.selectedSheetId),a=be(p=>p.dashboard),{setIsVisualEditing:s,setSelectedSheetId:r}=be(p=>p.actions),l=E(p=>p.editorContext),{clearEditorContext:o}=E(p=>p.actions),d=pc(),i=yn(),c=be(p=>p.isVisualEditing),x=be(p=>p.actions.updateFrame),u=fc();async function f(p){var y,F,v;if((l==null?void 0:l.type)==="documentSection"){await d.commit(p);return;}const N=t?(y=a==null?void 0:a.sheets)==null?void 0:y.some(D=>{var K;return D.id===t&&((K=D.frames)==null?void 0:K.some(j=>j.id===p.id));}):!1,T=(v=(F=a==null?void 0:a.sheets)==null?void 0:F.find(D=>{var K;return(K=D.frames)==null?void 0:K.some(j=>j.id===p.id);}))==null?void 0:v.id,S=N?t:T||null;if(!S)return;const b=mi(a,p.id);try{const D=await u(p,{previousFrame:b});x(S,p,{semanticExecutionPayload:D,origin:"editor"}),t!==S&&r(S),s(!1);}catch(D){console.error("Failed to resolve semantic metadata on save:",D),nt.error(D instanceof Error?D.message:"Failed to resolve semantic metadata for this visual");}}function h(){if((l==null?void 0:l.type)==="documentSection"){d.discard();return;}o(),s(!1);}return/* @__PURE__ */e("div",{role:"editor-container",className:Q("flex-1 grow basis-0 overflow-auto",{"max-h-0 overflow-hidden":!c}),style:i.dashboardContainerStyle,children:/* @__PURE__ */e(Kp,{onSave:f,onClose:h})});}export{vf as default};
|