react-semaphor 0.1.604 → 0.1.605
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/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 +3 -8
- package/dist/briefings/index.js +1 -1
- package/dist/chunks/{add-to-dashboard-DeHEBEqG.js → add-to-dashboard-CEmZUf9o.js} +1 -1
- package/dist/chunks/{analytics-base-schemas-BREc5WGv.js → analytics-base-schemas-DMFrDqn_.js} +1 -1
- package/dist/chunks/appearance-provider-CfoAVQuG.js +608 -0
- package/dist/chunks/appearance-runtime-provider-Bx8H-moR.js +1 -0
- package/dist/chunks/{assistant-chat-CjYrwVDa.js → assistant-chat-DgUaCE9k.js} +19 -24
- package/dist/chunks/attachment-filter-line-C_zHMhGh.js +1 -0
- package/dist/chunks/{bookmark-impact-C89zBLq3.js → bookmark-impact-BAtemeyK.js} +1 -1
- package/dist/chunks/bookmark-state-DScd31KT.js +1 -0
- package/dist/chunks/brand-C9APUFaP.js +1 -0
- package/dist/chunks/card-filter-builder-ClWrXB7P.js +11 -0
- package/dist/chunks/comparison-window-caption-tguyN24S.js +1 -0
- package/dist/chunks/{context-ALdccLHw.js → context-CntvtZwC.js} +1 -1
- package/dist/chunks/dashboard-ChIcbVTx.js +1 -0
- package/dist/chunks/dashboard-briefing-launcher-CwMlhkxV.js +42 -0
- package/dist/chunks/dashboard-controls-UCSAFCGA.js +42 -0
- package/dist/chunks/dashboard-json-B120hYDa.js +1 -0
- package/dist/chunks/dashboard-temporal-snapshot-BFJKbp_6.js +1 -0
- package/dist/chunks/edit-dashboard-visual-DvHp03h_.js +73 -0
- package/dist/chunks/filter-line-WwUV5JzN.js +1 -0
- package/dist/chunks/filter-reach-preview-C5M5_hf_.js +1 -0
- package/dist/chunks/filter-value-text-DqTHe_vu.js +1 -0
- package/dist/chunks/{index-BE1DfxNs.js → index-bkP6SnYu.js} +1 -1
- package/dist/chunks/kpi-trend-rule-B87LNzcz.js +1 -0
- package/dist/chunks/{layout-grid-BWtlgw0T.js → layout-grid-CFzqJ7GC.js} +1 -1
- package/dist/chunks/matrix-analytical-definition-5T-2euHZ.js +1 -0
- package/dist/chunks/matrix-member-presentation-vVAv-aqg.js +1 -0
- package/dist/chunks/matrix-operation-contract-CWvcEsQ0.js +1 -0
- package/dist/chunks/numeric-range-options-C8tr-Bls.js +1 -0
- package/dist/chunks/{palette-BzC-CGOc.js → palette-NvEIuXHN.js} +1 -1
- package/dist/chunks/pivot-result-contract-expectations-BNWhS8mv.js +1 -0
- package/dist/chunks/pivot-result-identity-B0eWVMXg.js +1 -0
- package/dist/chunks/{raw-temporal-value-DeyEhL0S.js → raw-temporal-value-BHQ-ldpW.js} +1 -1
- package/dist/chunks/report-preferences-dialog-Bseb2Rlg.js +1 -0
- package/dist/chunks/{report-runtime-context-BWzIHCKK.js → report-runtime-context-Cd1b5pku.js} +1 -1
- package/dist/chunks/resolve-dashboard-input-context-BDY7KwRe.js +8 -0
- package/dist/chunks/resolver-CjsW8Rz0.js +1 -0
- package/dist/chunks/saved-dashboard-context-C3lWc4Dx.js +1 -0
- package/dist/chunks/schema-O1Y3WTGF.js +4 -0
- package/dist/chunks/{selection-filter-compiler-CCoCD25M.js → selection-filter-compiler-kYsRugss.js} +1 -1
- package/dist/chunks/semaphor-ready-indicator-BQarSo6S.js +612 -0
- package/dist/chunks/set-6mOnfQeH.js +1 -0
- package/dist/chunks/slider-BPnHdMGq.js +4 -0
- package/dist/chunks/stored-dashboard-DfrxDLhR.js +1 -0
- package/dist/chunks/{table-export-sheet-rC5pKmXg.js → table-export-sheet-xaczzWZF.js} +1 -1
- package/dist/chunks/{token-types-Bj9iMy0w.js → token-types-1vzMWjI-.js} +1 -1
- package/dist/chunks/{validators-CqV3Yka1.js → validators-Dg2kyF4_.js} +1 -1
- package/dist/chunks/{variable-draft-DJrfUyhv.js → variable-draft-B4_xqr4Y.js} +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/dashboard-authoring/index.js +1 -1
- 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/brand-studio/brand-studio-draft.d.ts +45 -13
- package/dist/types/brand-studio/brand-studio-editor.d.ts +13 -2
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/components/visual/data-table/hooks/use-data-table-logic.d.ts +17 -6
- package/dist/types/components/visual/data-table/types/data-table.d.ts +52 -42
- package/dist/types/index.js +1 -1
- package/dist/types/lib/appearance/aliases.d.ts +3 -0
- package/dist/types/lib/appearance/index.d.ts +1 -0
- package/dist/types/lib/appearance/table-density.d.ts +18 -0
- package/dist/types/lib/appearance/types.d.ts +39 -1
- package/dist/types/lib/dashboard-viewer/column-header-actions.d.ts +100 -0
- package/dist/types/lib/dashboard-viewer/table-view-edit.d.ts +0 -27
- package/dist/types/lib/dashboard-viewer/table-view.d.ts +26 -2
- package/dist/types/lib/dashboard-viewer/use-table-view.d.ts +2 -0
- package/dist/types/lib/hooks/use-add-new-frame.d.ts +7 -0
- package/dist/types/lib/hooks/use-dashboard-card.d.ts +4 -0
- package/dist/types/lib/interactions/get-click-context-from-chartjs.d.ts +8 -0
- package/dist/types/lib/stores/dashboard-store.d.ts +14 -2
- package/dist/types/lib/stores/explorer-actions.d.ts +0 -4
- package/dist/types/lib/types/common-types.d.ts +1 -2
- package/dist/types/lib/utils/card-config-utils.d.ts +13 -0
- package/dist/types/lib/utils/field-placement.d.ts +17 -0
- package/dist/types/shared/analytics-protocol/analytics-refusal.d.ts +21 -1
- package/dist/types/shared/analytics-protocol/field-provenance.d.ts +7 -4
- package/dist/types/shared/dashboard-authoring/card-data-source/filter-field-folders.d.ts +48 -0
- package/dist/types/shared/dashboard-authoring/card-settings/card-display-write.d.ts +2 -8
- package/dist/types/shared/dashboard-authoring/card-settings/card-kinds.d.ts +1 -1
- package/dist/types/shared/dashboard-authoring/card-settings/column-display-values.d.ts +5 -0
- package/dist/types/shared/dashboard-authoring/card-settings/column-display.d.ts +52 -0
- package/dist/types/shared/dashboard-authoring/card-settings/index.d.ts +1 -0
- package/dist/types/shared/dashboard-authoring/card-settings/inputs.d.ts +9 -0
- package/dist/types/shared/dashboard-authoring/card-settings/resolved.d.ts +4 -0
- package/dist/types/shared/dashboard-authoring/card-settings/table-viewer-switches.d.ts +15 -0
- package/dist/types/shared/dashboard-authoring/card-settings/views.d.ts +5 -0
- package/dist/types/shared/dashboard-authoring/changes/card-query-part.d.ts +6 -0
- package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +132 -3
- package/dist/types/shared/dashboard-authoring/changes/diagnostics.d.ts +3 -1
- package/dist/types/shared/dashboard-authoring/conditional-formatting/schema.d.ts +10 -10
- package/dist/types/shared/dashboard-authoring/conditional-formatting/store.d.ts +10 -1
- package/dist/types/shared/dashboard-authoring/field-aggregations.d.ts +9 -2
- package/dist/types/shared/dashboard-authoring/field-folders/field-folders.d.ts +8 -7
- package/dist/types/shared/dashboard-authoring/index.d.ts +1 -0
- package/dist/types/shared/dashboard-authoring/operations/card-operations.d.ts +2 -0
- package/dist/types/shared/dashboard-authoring/operations/operation-types.d.ts +7 -2
- package/dist/types/shared/dashboard-authoring/outline/outline-dashboard.d.ts +6 -2
- package/dist/types/shared/dashboard-authoring/sheet-kinds.d.ts +36 -0
- package/dist/types/shared/dashboard-authoring/table-sheet-shape.d.ts +140 -0
- package/dist/types/shared/dashboard-viewer/table-column-move.d.ts +15 -0
- package/dist/types/shared/dashboard-viewer/table-settings.d.ts +8 -2
- package/dist/types/shared/format-utils/types/format-types.d.ts +1 -1
- package/dist/usage-events/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunks/appearance-context-BqBZrijL.js +0 -1
- package/dist/chunks/appearance-runtime-provider-DmbCrOOG.js +0 -1
- package/dist/chunks/bookmark-state-69YYnRql.js +0 -1
- package/dist/chunks/brand-DCaZyRt6.js +0 -1
- package/dist/chunks/card-filter-builder-CTp6RAz1.js +0 -17
- package/dist/chunks/comparison-window-caption-C312mn3s.js +0 -1
- package/dist/chunks/dashboard-BX28ld6s.js +0 -1
- package/dist/chunks/dashboard-briefing-launcher-qo7GH4EO.js +0 -37
- package/dist/chunks/dashboard-controls-DhRjB7MA.js +0 -42
- package/dist/chunks/dashboard-json-9cHzhSjC.js +0 -1
- package/dist/chunks/dates-D-KP8G-z.js +0 -1
- package/dist/chunks/edit-DEAK0UZo.js +0 -1
- package/dist/chunks/edit-dashboard-visual-Duq_QkB_.js +0 -93
- package/dist/chunks/filter-line-CwQrqORc.js +0 -1
- package/dist/chunks/filter-reach-preview-gixPFlZj.js +0 -1
- package/dist/chunks/filter-value-text-B3tXakhd.js +0 -1
- package/dist/chunks/index-B-VF1ogs.js +0 -1
- package/dist/chunks/matrix-analytical-definition-CtFqWyCK.js +0 -1
- package/dist/chunks/matrix-member-presentation-Q0MCJ-YK.js +0 -1
- package/dist/chunks/matrix-operation-contract-D1RC1bfi.js +0 -1
- package/dist/chunks/metric-comparison-DEZYXROZ.js +0 -1
- package/dist/chunks/paintbrush-BjS3SbrH.js +0 -6
- package/dist/chunks/pickers-DuBrUht0.js +0 -1
- package/dist/chunks/pivot-result-contract-expectations-DTQAgr4n.js +0 -1
- package/dist/chunks/pivot-result-identity-DTNCB--h.js +0 -1
- package/dist/chunks/report-preferences-dialog-B_gUmCzG.js +0 -1
- package/dist/chunks/resolve-dashboard-input-context-B-TtRqxu.js +0 -8
- package/dist/chunks/resolver-AN9ChBfZ.js +0 -1
- package/dist/chunks/save-DdFUZcbi.js +0 -6
- package/dist/chunks/saved-dashboard-context-BAJ5tWiq.js +0 -1
- package/dist/chunks/schema-MC0cQSAb.js +0 -4
- package/dist/chunks/semaphor-ready-indicator-DzjorP3t.js +0 -999
- package/dist/chunks/set-DuJfGkbY.js +0 -1
- package/dist/chunks/shelf-drop-preview-context-BlLJ5RsT.js +0 -6
- package/dist/chunks/stored-dashboard-Ctcpkllg.js +0 -1
- package/dist/chunks/style-sheet-parts-BRGt9O05.js +0 -178
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import{jsxs as n,Fragment as me,jsx as e}from"react/jsx-runtime";import{u as sl,a as lr,b as Bi,F as Vi,P as Ki,c as $i,d as ll,e as Ze,S as us,f as ms,r as ol,E as qi,T as zi,A as $a,g as Pe,h as Re,i as Oe,j as ji,k as Ui,l as qa,m as Ia,n as Hi,o as Gi,s as il,p as cl,q as Qi,t as Yi,v as Wi,w as Ji,x as Xi}from"./shelf-drop-preview-context-BlLJ5RsT.js";import{c as H}from"./pickers-DuBrUht0.js";import{a6 as dl,N as Zi,w as hs,m as Fa}from"./validators-CqV3Yka1.js";import"./matrix-operation-contract-D1RC1bfi.js";import{z as ec}from"./analytics-base-schemas-BREc5WGv.js";import{DEFAULT_RESOLVED_VALUE_FORMAT_PREFERENCES as Xt}from"../value-format-preferences/index.js";import Ma,{useRef as Ae,useCallback as Je,useState as U,useMemo as Z,useEffect as Ne,useId as da,useContext as or,Suspense as tc}from"react";import{am as D,an as xe,fc as ac,bo as Qe,b1 as It,fd as nc,fe as rc,ff as sc,fg as lc,fh as oc,bE as za,fi as ul,fj as ic,i as cc,j as dc,k as uc,m as Kn,fk as $n,fl as ml,eZ as mc,dD as hl,fm as hc,n as pc,dt as fc,de as ir,eg as pl,bp as ha,bq as pa,br as ja,bs as fa,bt as ua,f5 as fl,fn as gc,cf as cr,ee as xc,ch as bc,ci as vc,cj as yc,ck as Nc,cl as Cc,cm as wc,cn as Sc,co as Tc,dm as nt,u as ye,dI as Kt,fo as gl,c1 as Aa,fp as xl,dJ as hn,dg as kc,fq as Pa,ct as dr,bV as bl,bx as Ua,bF as Dc,cv as Ec,fr as qn,cL as $t,cM as qt,bQ as zt,cN as jt,bn as zn,cQ as Ic,ez as ur,fs as mr,ft as Ha,fu as vl,d$ as hr,d_ as yl,fv as Fc,fw as Mc,dC as Ct,fx as Ac,fy as Pc,fz as Rc,fA as Oc,fB as Lc,fC as Nl,a4 as Cl,M as _c,fD as Bc,eP as Vc,fE as Kc,e5 as $c,fF as pr,E as Ga,e as fr,fG as wl,fH as qc,fI as ps,fJ as zc,fK as Sl,fL as jc,fM as Uc,bJ as Tl,fN as Hc,fO as Gc,fP as Qc,fQ as Yc,fR as Ra,fS as Wc,fT as Jc,fU as kl,fV as Dl,fW as Xc,fX as Zc,ev as ed,fY as td,fZ as El,f_ as ad,e2 as nd,e1 as Qa,f$ as Ya,c3 as Wa,c4 as Ja,c5 as Xa,g0 as rd,g1 as sd,cR as gr,bi as Za,d2 as Il,d3 as jn,e7 as fs,eW as ld,d8 as Fl,d9 as od,da as id,db as cd,d4 as dd,d5 as ud,d6 as Ml,dc as md,dd as hd,g2 as pd,g3 as en,cE as Al,bI as Pl,bK as ga,g4 as fd,g5 as gd,g6 as xd,g7 as gs,g8 as bd,g9 as Rl,ga as Ol,dL as Ll,dM as vd,dR as yd,dS as Nd,dN as Cd,dO as wd,dP as Sd,gb as Td,gc as kd,gd as Dd,ge as Ed,gf as xs,dU as Id,dV as Fd,gg as Md,gh as _l,gi as Qt,gj as Yt,gk as Wt,eU as Zt,c8 as Bl,bS as ot,ca as bs,cb as vs,cc as Un,gl as Vl,gm as Ad,gn as Pd,go as Rd,ec as Od,ed as Ld,gp as Kl,gq as $l,gr as _d,cG as _t,gs as xr,gt as br,gu as Bd,gv as ql,gw as zl,gx as Vd,gy as Kd,gz as $d,gA as jl,gB as Hn,gC as qd,gD as zd,gE as jd,gF as Ud,gG as Hd,gH as Gd,gI as Qd,gJ as Ot,gK as ra,gL as ys,gM as Yd,gN as pn,gO as Ns,gP as Wd,gQ as Jd,bj as vr,bk as ma,gR as fn,gS as Ul,gT as Xd,gU as Zd,gV as eu,gW as tu,eY as tn,gX as Hl,gY as Gl,eb as au,gZ as nu,g_ as ru,g$ as su,h0 as lu,h1 as Ql,h2 as ou,h3 as iu,h4 as Yl,e3 as cu,e4 as du,dl as uu,e6 as mu,bU as hu,h5 as pu,h6 as fu,h7 as gu,cp as xu,h8 as bu,h9 as vu,ha as yu,cZ as Nu,hb as Cu,dH as wu,hc as yr,e8 as Su,hd as Tu,he as ku,hf as Du,cs as Eu,hg as Iu,hh as Fu,dW as Mu,hi as Cs,f7 as Au,hj as Pu,f8 as Ru,fa as Ou,fb as Lu,o as _u,hk as Bu,d7 as Vu,hl as Ku,hm as $u,hn as qu,ho as zu,hp as ju,hq as Uu,ak as Hu,eh as Gu,F as Qu,hr as Yu,bc as Wu}from"./semaphor-ready-indicator-DzjorP3t.js";import{c as je,e as bt,f as Tt,F as Et,h as vt,q as Nr,j as Ft,x as _e,$ as Ju,B as ie,X as it,t as xt,u as ht,v as pt,w as ft,L as xa,C as Bt,T as Mt,k as At,l as Ye,n as mt,I as Vt,af as Xu,ag as Zu,s as A,m as Cr,i as Oa,y as ee,z as te,A as ae,D as ne,E as K,ah as Gn,ai as Wl,d as De,r as em,S as Qn,R as ws,p as Jl,a9 as tm}from"./style-sheet-parts-BRGt9O05.js";import{bL as Ss,gt as Ts,gF as am,gu as ks,iP as Xl,gx as nm,gq as rm,q as sm,l4 as Ds,aa as Ut,dr as Zl,ab as Ht,ad as ba,j5 as St,j6 as Jt,d6 as lm,ce as wr,gf as om,jq as va,E as im,bV as cm,jd as Sr,i0 as eo,F as dm,l5 as um,l6 as mm,l7 as hm,l8 as pm,bm as fm,iE as gm,iX as Dt,k7 as xm,al as bm,l9 as vm,la as to,ij as ym,dW as Nm,lb as ao,je as Cm,ej as wm,eh as gn,lc as Sm,ld as Tm,le as km,lf as Dm,j8 as Em,ac as no,j9 as Im,lg as Yn,lh as Fm,li as Mm,lj as Am,lk as Tr,i9 as Pm,f_ as kr,aU as Rm,as as Wn,gK as Om,jx as Lm,cI as ro,bZ as _m,h as so,ll as Bm,bY as Vm,c6 as Km,lm as $m,ln as qm,ga as lo,bQ as oo,h0 as io,lo as zm,gM as jm,kQ as Um,aJ as Es,lp as Hm,jL as Gm,lq as Qm,lr as Ym,ls as Is,lt as Wm,gP as Jm,gQ as Xm,lu as Zm,lv as eh,iJ as ut,lw as th,lx as ah,ly as nh,lz as rh,lA as sh,lB as lh,lC as Fs,lD as Ms,lE as oh,e as co,aF as ih,cz as ch,cx as dh,lF as uh,lG as mh,hw as hh,lH as ph,lI as fh,lJ as gh,lK as xh,i1 as ka,fO as bh,fR as vh,aT as yh,fN as xn,fM as Nh,fP as Ch,fL as wh,hu as As,iT as Sh,bS as Th,lL as kh,j4 as Dh,lM as Eh,lN as Ps,h5 as Ih,au as Fh,jB as Mh,gw as Ah,lO as uo,iY as Ph,gg as Rh,lP as Oh,C as Lh,k as Jn,m as mo,lQ as ho,lR as Dr,z as La,k_ as _h,H as Bh,jc as Vh}from"./resolve-dashboard-input-context-B-TtRqxu.js";import"zod";import{aU as Kh,aT as an,aO as Er,k as $h,X as qh,aK as po}from"./pivot-result-contract-expectations-DTQAgr4n.js";import{aJ as fo,aK as go,A as zh}from"./bookmark-state-69YYnRql.js";import"./schema-MC0cQSAb.js";import{i as xo}from"./index-DViPGDFj.js";import"./context-ALdccLHw.js";import{F as jh,V as bo,I as Xe,u as Uh,a as Hh,c as vo,C as yo,b as Gh}from"./card-filter-builder-CTp6RAz1.js";import{N as Ir,ah as Qh,B as Yh,ai as No,aj as Co,d as Wh,ak as Fr,al as Mr,P as Jh,Q as Xh,S as Zh}from"./filter-reach-preview-gixPFlZj.js";import{T as ep,e as tp,U as ap,O as wo,V as np,P as So,W as rp,M as sp,n as lp,X as op,Y as To,Z as ko,y as ip}from"./stored-dashboard-Ctcpkllg.js";import"react-dom";import{c as cp,b as dp,m as up,r as Do,K as mp,d as hp}from"./dates-D-KP8G-z.js";import{r as pp}from"./export-file-format-B-wQNHIn.js";import{u as fp}from"./appearance-context-BqBZrijL.js";import{P as gp}from"./paintbrush-BjS3SbrH.js";import{D as xp,f as Eo,g as Io}from"./metric-comparison-DEZYXROZ.js";import{b as Rs}from"./raw-temporal-value-DeyEhL0S.js";import{P as bp}from"./palette-BzC-CGOc.js";import"./attribution-BEFSsbNn.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 Fo=je("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 Mo=je("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 vp=je("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 yp=je("Component",[["path",{d:"M15.536 11.293a1 1 0 0 0 0 1.414l2.376 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z",key:"1uwlt4"}],["path",{d:"M2.297 11.293a1 1 0 0 0 0 1.414l2.377 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414L6.088 8.916a1 1 0 0 0-1.414 0z",key:"10291m"}],["path",{d:"M8.916 17.912a1 1 0 0 0 0 1.415l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.415l-2.377-2.376a1 1 0 0 0-1.414 0z",key:"1tqoq1"}],["path",{d:"M8.916 4.674a1 1 0 0 0 0 1.414l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z",key:"1x6lto"}]]);/**
|
|
22
|
-
* @license lucide-react v0.453.0 - ISC
|
|
23
|
-
*
|
|
24
|
-
* This source code is licensed under the ISC license.
|
|
25
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
-
*/const Np=je("FileJson2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M4 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",key:"fq0c9t"}],["path",{d:"M8 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",key:"4gibmv"}]]);/**
|
|
27
|
-
* @license lucide-react v0.453.0 - ISC
|
|
28
|
-
*
|
|
29
|
-
* This source code is licensed under the ISC license.
|
|
30
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
-
*/const Cp=je("Fullscreen",[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["rect",{width:"10",height:"8",x:"7",y:"8",rx:"1",key:"vys8me"}]]);/**
|
|
32
|
-
* @license lucide-react v0.453.0 - ISC
|
|
33
|
-
*
|
|
34
|
-
* This source code is licensed under the ISC license.
|
|
35
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
-
*/const wp=je("ListEnd",[["path",{d:"M16 12H3",key:"1a2rj7"}],["path",{d:"M16 6H3",key:"1wxfjs"}],["path",{d:"M10 18H3",key:"13769t"}],["path",{d:"M21 6v10a2 2 0 0 1-2 2h-5",key:"ilrcs8"}],["path",{d:"m16 16-2 2 2 2",key:"kkc6pm"}]]);/**
|
|
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 Sp=je("ListStart",[["path",{d:"M16 12H3",key:"1a2rj7"}],["path",{d:"M16 18H3",key:"12xzn7"}],["path",{d:"M10 6H3",key:"lf8lx7"}],["path",{d:"M21 18V8a2 2 0 0 0-2-2h-5",key:"1hghli"}],["path",{d:"m16 8-2-2 2-2",key:"160uvd"}]]);/**
|
|
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 Tp=je("ListX",[["path",{d:"M11 12H3",key:"51ecnj"}],["path",{d:"M16 6H3",key:"1wxfjs"}],["path",{d:"M16 18H3",key:"12xzn7"}],["path",{d:"m19 10-4 4",key:"1tz659"}],["path",{d:"m15 10 4 4",key:"1n7nei"}]]);/**
|
|
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 bn=je("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 vn=je("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 Xn=je("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"}]]);/**
|
|
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 kp=je("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"}]]);/**
|
|
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 Dp=je("Sigma",[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]]);/**
|
|
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 Ep=je("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"}]]);/**
|
|
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 Ip=je("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"}]]);/**
|
|
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 Fp=je("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"}]]);/**
|
|
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 Ao=je("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"}]]),yn=t=>"label"in t&&t.label||t.name;function Os(t,a){const s=a.type==="dataset";return{...(t??{}),connectionId:a.connectionId||(t==null?void 0:t.connectionId)||"",connectionType:a.connectionType||(t==null?void 0:t.connectionType)||"",mode:s?"semanticDomain":"database",semanticDomainId:s?a.domainId:void 0,selectedEntities:[a]};}function Ls(t,a,s){const r=t.map(o=>{const c=sm(o)[0],d=o.label||o.name;return c&&c!==a?`${s(c)} › ${d}`:d;});return[...new Set(r)].join(", ");}function Mp(){const t=D(h=>h.card),{updateCard:a,setDataSource:s}=xe(),{restore:r}=sl(),{base:o}=lr(t),c=o==null?void 0:o.name,d=ac(),l=Bi(),i=Ae(null);return Je(async h=>{var M;i.current=h;const u=()=>D.getState().card,m=u(),p=Ss(m,c);if(Ts(p,h))return;const f=Os(m.dataSource,h);if(m.type==="matrixTable"){s(f);return;}if(!p||am(m).length===0){const I=ks({card:m,base:p??h,nextBase:h,dataSource:f,columns:[],reaches:()=>!1,entityOf:()=>{}});a(m.id,{dataSource:I.card.dataSource,config:I.card.config,inlineFilters:I.card.inlineFilters}),I.removedJoins&&Qe(`Switched to ${yn(h)}`,{description:"Removed the card’s joins.",action:{label:"Undo",onClick:()=>r(m)}});return;}const w=h.type==="dataset",C=w?h.domainId:void 0;let y,b;try{[y,b]=await Promise.all([d(h,f.connectionId,C),C?l(C):Promise.resolve(null)]);}catch{i.current===h&&Qe.error(`Couldn’t read the fields of ${yn(h)}.`);return;}if(i.current!==h)return;const v=u();if(v.id!==m.id)return;const N=Ss(v,c)??p;if(Ts(N,h))return;const g=w&&C===Xl(v.dataSource),F=new Set(g?(((M=b==null?void 0:b.reach)==null?void 0:M[h.name])??[]).filter(I=>!I.needsSetup).map(I=>I.dataset):[]),O=I=>b==null?void 0:b.datasets.find(q=>q.name===I),V=ks({card:v,base:N,nextBase:h,dataSource:Os(v.dataSource,h),columns:y,reaches:I=>F.has(I),entityOf:I=>{const q=O(I);return q?rm(h,q):void 0;}});a(v.id,{dataSource:V.card.dataSource,config:V.card.config,inlineFilters:V.card.inlineFilters});const $=I=>{var q;return((q=O(I))==null?void 0:q.label)||I;},E=yn(h),T=[V.kept.length?`Kept ${Ls(V.kept,N.name,$)}.`:"",V.removed.length?`Removed ${Ls(V.removed,N.name,$)}: not in ${E}.`:"",V.removedJoins?"Removed the card’s joins.":"",nm(V.calculations)].filter(Boolean).join(" ");Qe(`Switched to ${E}`,{description:T||"Nothing on the card changed.",action:{label:"Undo",onClick:()=>r(v)}});},[c,s,a,d,l,r]);}const Da=t=>`${t.type}:${t.connectionId??""}:${t.domainId??""}:${t.schema??""}:${t.name}`,Ap=t=>((t==null?void 0:t.description)??"").trim()||void 0;function Po({entity:t,className:a}){const s=t&&t.type!=="dataset"?Nr:hl;return/* @__PURE__ */e(s,{className:H("h-3 w-3 shrink-0 text-muted-foreground",a),strokeWidth:1.75,"aria-hidden":!0});}const Ar=t=>"label"in t&&t.label||t.name||"Dataset",Ro=(t,a)=>!a||`${Ar(t)} ${t.name} ${t.description??""}`.toLowerCase().includes(a);function Zn({entity:t,picked:a,hint:s,onPick:r}){return/* @__PURE__ */n(pc,{value:Da(t),onSelect:r,"data-picked":a||void 0,className:H("flex h-7 items-center gap-2 rounded-none px-3 py-0",a&&"bg-muted"),children:[/* @__PURE__ */e(Po,{entity:t}),/* @__PURE__ */e("span",{className:H("min-w-0 flex-1 truncate text-[13px] text-foreground",t.type!=="dataset"&&"font-mono text-[12px]"),children:Ar(t)}),s&&/* @__PURE__ */e("span",{className:"max-w-[40%] shrink-0 truncate text-[11px] text-muted-foreground",children:s}),/* @__PURE__ */e("span",{className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:a&&/* @__PURE__ */e(Ft,{className:"h-3.5 w-3.5","aria-label":"Current"})})]});}const er="p-0 [&_[cmdk-group-heading]]:px-3 [&_[cmdk-group-heading]]:pb-1 [&_[cmdk-group-heading]]:pt-2.5 [&_[cmdk-group-heading]]:text-[10px] [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-[0.08em] [&_[cmdk-group-heading]]:text-muted-foreground";function Pp({domain:t,query:a,base:s,onPick:r}){const{datasets:o,isPending:c}=hc(t.id),d=Z(()=>o.map(ul).filter(l=>Ro(l,a)),[o,a]);return!c&&d.length===0?null:/* @__PURE__ */e(Kn,{heading:t.label,className:er,children:c&&d.length===0?/* @__PURE__ */e("p",{className:"px-8 py-1 text-[11px] text-muted-foreground",children:"Loading…"}):d.map(l=>/* @__PURE__ */e(Zn,{entity:l,picked:!!(s&&$n(s,l)),onPick:()=>r(l)},l.name))});}function Rp(){const[t,a]=U(!1),[s,r]=U(!1),[o,c]=U(""),d=D(x=>x.card),{tokenProps:l}=It(),{base:i}=lr(d),{semanticDomains:h}=nc(),u=rc(),m=Mp(),p=sc(l.config,l.semanticDomainAccess),f=o.trim().toLowerCase(),w=Z(()=>new Map(h.map(x=>[x.id,x.label||x.name])),[h]),C=Z(()=>lc(h,p.semanticDomainAccess).map(x=>({id:x.id,label:x.label||x.name})),[h,p.semanticDomainAccess]),{offersDirect:y,semanticDomainAccess:b}=p,v=Z(()=>{const x=R=>R.type==="dataset"?oc(b.mode,R.domainId??"",b.domainIds??[]):y;return u.filter(R=>(R.type==="dataset"||R.type==="table"||R.type==="view")&&x(R)&&Ro(R,f));},[u,f,y,b]),N=Z(()=>new Set(C.map(x=>x.id)),[C]),g=v.filter(x=>x.type!=="dataset"),F=v.filter(x=>x.type==="dataset"&&!N.has(x.domainId??"")),[O,V]=U(""),$=za(),E=Z(()=>{if(!O)return;const x=C.flatMap(R=>{var S;return(((S=$.getQueryData(["datasets",R.id]))==null?void 0:S.datasets)??[]).map(ul);});return[...v,...x].find(R=>Da(R)===O);},[O,C,v,$]),T=Ap(E),M=x=>ic(x,w)??[x.database,x.schema].filter(Boolean).join(" · "),I=x=>{a(!1),c(""),m(x);},q=i?Ar(i):"Choose dataset",P=i?M(i):"";return/* @__PURE__ */n(me,{children:[/* @__PURE__ */n(bt,{open:t,onOpenChange:x=>{a(x),x||c("");},children:[/* @__PURE__ */e(Tt,{asChild:!0,children:/* @__PURE__ */n("button",{type:"button","aria-label":i?`Card data: ${q}`:"Card data: choose dataset",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 focus:outline-none focus-visible:border-ring",children:[/* @__PURE__ */e(Po,{entity:i}),/* @__PURE__ */e("span",{className:H("min-w-0 truncate text-[13px] text-foreground",i&&i.type!=="dataset"&&"font-mono text-[12px]"),children:q}),P&&/* @__PURE__ */e("span",{className:"min-w-0 flex-1 truncate text-[11px] text-muted-foreground",children:P}),/* @__PURE__ */e(Et,{className:H("ml-auto h-3 w-3 shrink-0 text-muted-foreground transition-transform",t&&"rotate-180")})]})}),/* @__PURE__ */n(vt,{align:"start",sideOffset:4,className:"w-[320px] overflow-hidden rounded-control border border-border bg-popover p-0 shadow-[0_4px_16px_rgba(0,0,0,0.08)]",children:[/* @__PURE__ */n(cc,{shouldFilter:!1,value:O,onValueChange:V,className:"rounded-none",children:[/* @__PURE__ */e(dc,{autoFocus:!0,value:o,onValueChange:c,placeholder:"Search datasets and tables","aria-label":"Search datasets and tables",className:"h-9 text-[12px]"}),/* @__PURE__ */n(uc,{"aria-label":"Datasets and tables",className:"max-h-[340px] pb-1",children:[t&&C.map(x=>/* @__PURE__ */e(Pp,{domain:x,query:f,base:i,onPick:I},x.id)),F.length>0&&/* @__PURE__ */e(Kn,{heading:"On this dashboard",className:er,children:F.map(x=>/* @__PURE__ */e(Zn,{entity:x,hint:M(x),picked:!!(i&&$n(i,x)),onPick:()=>I(x)},Da(x)))}),g.length>0&&/* @__PURE__ */e(Kn,{heading:"Tables on this dashboard",className:er,children:g.map(x=>/* @__PURE__ */e(Zn,{entity:x,hint:M(x),picked:!!(i&&$n(i,x)),onPick:()=>I(x)},Da(x)))})]})]}),T&&/* @__PURE__ */e("div",{className:"border-t border-border/60 px-3 py-2",children:/* @__PURE__ */e("p",{title:T,className:"line-clamp-2 text-[11px] leading-[1.45] text-muted-foreground",children:T})}),/* @__PURE__ */e("div",{className:"border-t border-border/60",children:/* @__PURE__ */n("button",{type:"button",onClick:()=>{a(!1),r(!0);},className:"flex h-8 w-full items-center gap-1.5 px-3 text-left text-[12px] text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground",children:[/* @__PURE__ */e(ml,{className:"h-3 w-3","aria-hidden":!0}),"Browse all data"]})})]})]}),/* @__PURE__ */e(mc,{open:s,onOpenChange:r,dataSource:d.dataSource??{connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},incomingSelectedEntities:i?[i]:[],onPick:x=>void m(x)})]});}function Op(){const t=D(d=>d.card.dataSource),{setSelectedConnectionId:a,setSelectedDatabaseName:s,setSelectedSchemaName:r,setSelectedTableName:o,setSelectedDatamodelId:c}=xe();Ne(()=>{var f;if(!t)return;const{tableName:d,schemaName:l,databaseName:i,connectionId:h}=fc(t),u=(f=t.selectedEntities)==null?void 0:f[0],p=(u==null?void 0:u.type)==="model"&&"id"in u?u.id:"";a(h||""),s(i||""),r(l||""),o(d||""),c(p);},[t,a,s,r,o,c]);}function Oo({isVisible:t}){return Op(),/* @__PURE__ */n("div",{className:H("flex shrink-0 flex-col overflow-hidden border-r border-border bg-background transition-all duration-300 ease-in-out",{"w-[290px]":t,"min-w-[290px]":t,"w-0 border-r-0":!t,"min-w-0":!t}),children:[/* @__PURE__ */e("div",{className:"px-4 pt-4",children:/* @__PURE__ */e(Rp,{})}),/* @__PURE__ */e("div",{className:"min-h-0 flex-1",children:/* @__PURE__ */e(Vi,{})})]});}const tr=({className:t,...a})=>/* @__PURE__ */e($i,{className:H("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",t),...a}),Gt=Ki,Lo=({withHandle:t,className:a,...s})=>/* @__PURE__ */e(ll,{className:H("relative flex w-px items-center justify-center bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",a),...s,children:t&&/* @__PURE__ */e("div",{className:"z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border",children:/* @__PURE__ */e(ir,{className:"h-2.5 w-2.5"})})}),Lp=3,ar="Self-heal",Nn={grounding:"Analyzing context",drafting:"Drafting SQL",validating:"Validating SQL",repairing:ar},sa="Unable to generate a SQL draft right now. Try again.",_p="Choose a data source for this card before describing a query.",Bp="Validation service unavailable. You can still replace and run.";function la(t,a){typeof window>"u"||window.dispatchEvent(new CustomEvent("semaphor:inline-query-writer",{detail:{event:t,...a,timestamp:Date.now()}}));}const oa={runId:0,status:"idle",prompt:"",mode:"draft",baselineSql:"",timelineSteps:[],activeStep:"",attempt:0,sql:"",validation:null,errorMessage:""};function Vp(t,a){return t===ar&&a>0?`${ar} ${a}/${Lp}`:t;}async function Kp(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 $p(t,a){const s=d=>{const l=d.trim();l&&a(JSON.parse(l));};if(!t.body){(await t.text()).split(`
|
|
92
|
-
`).forEach(s);return;}const r=t.body.getReader(),o=new TextDecoder();let c="";for(;;){const{done:d,value:l}=await r.read();if(d)break;c+=o.decode(l,{stream:!0});const i=c.split(`
|
|
93
|
-
`);c=i.pop()??"",i.forEach(s);}s(c+o.decode());}function qp({currentSql:t,selectedDatabaseName:a,selectedSchemaName:s,selectedTableName:r,onApplySql:o,autoFocus:c,onDismiss:d}){var He,st;const{authToken:l,tokenProps:i}=It(),h=D(le=>le.card.id),u=D(le=>{var Se;return le.card.connectionId||((Se=le.card.dataSource)==null?void 0:Se.connectionId)||"";}),[m,p]=U(""),[f,w]=U("draft"),[C,y]=U(!1),[b,v]=U(!1),[N,g]=U(oa),[F,O]=U(h),V=Ae(null),$=Ae(0),E=Ae(null),T=(He=i.apiServiceUrl)==null?void 0:He.replace(/\/$/,""),M=T?`${T}/v1/sql/draft`:"/v1/sql/draft";function I(){var le;$.current+=1,(le=E.current)==null||le.abort(),E.current=null;}Ne(()=>()=>{var le;$.current+=1,(le=E.current)==null||le.abort(),E.current=null;},[h]),F!==h&&(O(h),g(le=>({...oa,runId:le.runId})),p(""),y(!1));const q=N.status==="running";function P(){N.status==="running"&&(I(),g(le=>({...le,status:"idle",activeStep:"",sql:"",validation:null})),la("inline_self_heal_stopped",{runId:N.runId,attemptCount:N.attempt,finalOutcome:"cancelled"}));}async function x(le,Se,Ke){const Ge=()=>$.current===le,$e=ve=>{Ge()&&g(de=>de.runId===le?ve(de):de);},qe=ve=>$e(de=>({...de,status:"failed",activeStep:"",errorMessage:ve}));let We=!1;const ke=ve=>{var Be;if(!Ge()||We)return;if(ve.type==="stage"){const W=Nn[ve.stage];if(!W)return;const Fe=ve.stage==="repairing"?ve.attempt??0:0;$e(oe=>({...oe,timelineSteps:oe.timelineSteps.includes(W)?oe.timelineSteps:[...oe.timelineSteps,W],activeStep:W,attempt:ve.stage==="repairing"?Fe:oe.attempt})),ve.stage==="repairing"&&la("inline_self_heal_attempt",{runId:le,attemptCount:Fe});return;}if(We=!0,ve.type==="error"){qe(ve.message||sa);return;}const de=((Be=ve.sql)==null?void 0:Be.trim())||"";if(!de){qe(sa);return;}$e(W=>({...W,status:"done",activeStep:"",sql:de,validation:ve.validation})),ve.validation.status==="invalid"?la("inline_validation_failed",{runId:le,attemptCount:ve.repairs,errorCode:ve.validation.code,finalOutcome:"validation_failed"}):la("inline_draft_validated",{runId:le,attemptCount:ve.repairs,finalOutcome:ve.validation.status});};try{const ve=await fetch(M,{method:"POST",headers:{Authorization:`Bearer ${l==null?void 0:l.accessToken}`,"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(Se),signal:Ke});if(!Ge())return;if(!ve.ok){qe(await Kp(ve,sa));return;}await $p(ve,ke),We||qe(sa);}catch{qe(sa);}finally{Ge()&&(E.current=null);}}const R=(t==null?void 0:t.trim())||"";function S(le="draft"){if(q)return;const Se=m.trim();if(!Se)return;const Ke=le==="refine"&&R?"refine":"draft",Ge=Ke==="refine"?R:"";I();const $e=$.current;if(y(!1),v(!0),!u){g({...oa,runId:$e,status:"failed",prompt:Se,errorMessage:_p});return;}g({...oa,runId:$e,status:"running",prompt:Se,mode:Ke,baselineSql:Ge}),la("inline_draft_started",{runId:$e,attemptCount:0,finalOutcome:"drafting"});const qe=new AbortController();E.current=qe,x($e,{request:Se,mode:Ke,...(R?{currentSql:R}:{}),connectionId:u,...(a?{database:a}:{}),...(s?{schema:s}:{}),...(r?{table:r}:{})},qe.signal);}const k=N.status==="done"?N.sql:"",L=N.prompt,_=N.mode,z=N.baselineSql;function j(le){const Se=k.trim();Se&&(o(Se,le),le||v(!1));}const B=k.length>0,G=((st=N.validation)==null?void 0:st.status)==="invalid",ce=B&&L.length>0&&L===m.trim(),ue=R.length>0,X=m.trim().length>0,Y=!!d&&!X&&!B&&!q,fe=ce&&_==="draft",he=ce&&_==="refine"&&z===R,re=f==="refine"&&!ue?"draft":f,ge=(re==="refine"?he:fe)?"Open composer preview":"Generate composer SQL",be=m.trim().length>0||L.trim().length>0||B||N.status!=="idle"||N.timelineSteps.length>0;function Ie(le="draft"){if(q)return;if((le==="refine"?he:fe)&&!b){v(!0);return;}S(le);}function Ve(){v(!0);}function et(le){P(),p(le);}function pe(){q||(I(),p(""),w("draft"),y(!1),g({...oa,runId:$.current}));}function we(le){le||P(),v(le);}const Ee=N.timelineSteps.findIndex(le=>le===N.activeStep),rt=N.activeStep===Nn.repairing?"Fixing validation issue":N.activeStep||Nn.drafting,Ue=!B||!N.validation?null:N.validation.status==="valid"?{label:"Validation passed",className:"border-emerald-500/30 bg-emerald-500/10 text-emerald-700",detail:"SQL validation passed."}:N.validation.status==="invalid"?{label:"Validation failed",className:"border-destructive/40 bg-destructive/10 text-destructive",detail:N.validation.message}:{label:"Validation unavailable",className:"border-border/60 bg-muted/20 text-muted-foreground",detail:Bp};return/* @__PURE__ */n("div",{ref:V,className:"relative flex h-7 min-w-0 flex-1 items-center",children:[/* @__PURE__ */e(_e,{value:m,onChange:le=>et(le.target.value),autoFocus:c,onFocus:Ve,onClick:Ve,onKeyDown:le=>{le.key==="Enter"?(le.preventDefault(),Ie(re)):le.key==="Escape"&&Y&&(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",X?"pr-[56px]":d?"pr-9":"pr-3"].join(" ")}),/* @__PURE__ */n(bt,{open:b,onOpenChange:we,children:[/* @__PURE__ */e(Ju,{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:[(X||d)&&/* @__PURE__ */e(ie,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0",onClick:le=>{le.preventDefault(),X?(P(),p("")):Y?d==null||d():pe();},disabled:q,"aria-label":X?"Clear input":Y?"Close":"Clear draft",title:X?"Clear input":Y?"Close":"Clear draft",children:/* @__PURE__ */e(it,{className:"size-3.5"})}),X&&/* @__PURE__ */e(ie,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0",onClick:le=>{if(le.preventDefault(),q){P();return;}Ie(re);},"aria-label":q?"Stop AI generation":ge,title:q?"Stop AI generation":ge,children:q?/* @__PURE__ */e(pl,{className:"size-3 fill-current"}):/* @__PURE__ */e(kp,{className:"size-3.5"})})]}),/* @__PURE__ */e(vt,{align:"start",alignOffset:0,side:"top",sideOffset:8,className:"w-[min(92vw,var(--radix-popover-trigger-width))] max-w-[760px] p-2.5",onOpenAutoFocus:le=>{le.preventDefault();},onInteractOutside:le=>{var Ke;const Se=le.target;if(Se&&(Ke=V.current)!=null&&Ke.contains(Se)){le.preventDefault();return;}Y&&(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(ie,{type:"button",variant:"ghost",className:["h-6 rounded-[4px] px-2 text-[12px]",re==="draft"?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground"].join(" "),onClick:()=>{w("draft"),y(!1);},children:"Draft New"}),/* @__PURE__ */e(ie,{type:"button",variant:"ghost",className:["h-6 rounded-[4px] px-2 text-[12px]",re==="refine"?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground"].join(" "),onClick:()=>w("refine"),disabled:!ue,children:"Refine"})]})}),/* @__PURE__ */n("div",{className:"flex shrink-0 items-center",children:[q&&/* @__PURE__ */e(ie,{variant:"ghost",size:"xs",onClick:P,children:"Stop"}),!q&&/* @__PURE__ */e(ie,{variant:"ghost",size:"xs",onClick:pe,disabled:!be,children:"Clear"})]})]}),(N.timelineSteps.length>0||Ue)&&/* @__PURE__ */n("div",{className:"flex flex-wrap items-center gap-1",children:[N.timelineSteps.map((le,Se)=>{const Ke=q&&le===N.activeStep,Ge=!Ke&&Ee>=0&&Se<Ee;return/* @__PURE__ */e("span",{className:["rounded-full border px-2 py-0.5 text-[11px]",Ke?"border-foreground/30 bg-foreground/10 text-foreground":Ge?"border-border/60 bg-muted/20 text-muted-foreground":"border-border/50 bg-background text-muted-foreground/80"].join(" "),children:Vp(le,N.attempt)},`${le}-${Se}`);}),Ue&&/* @__PURE__ */e(xt,{delayDuration:150,children:/* @__PURE__ */n(ht,{children:[/* @__PURE__ */e(pt,{asChild:!0,children:/* @__PURE__ */e("span",{className:["rounded-full border px-2 py-0.5 text-[11px]",Ue.className].join(" "),children:Ue.label})}),/* @__PURE__ */e(ft,{side:"top",align:"start",className:"max-w-[680px] whitespace-pre-wrap break-words text-xs",children:Ue.detail})]})})]}),q&&/* @__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(xa,{className:"size-3.5 animate-spin"}),rt]}),N.status==="failed"&&/* @__PURE__ */e("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive",children:N.errorMessage}),_==="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(ie,{type:"button",variant:"ghost",size:"xs",onClick:()=>y(le=>!le),children:C?"Hide base SQL":"View base SQL"})]}),C&&/* @__PURE__ */e("div",{className:"max-h-[120px] overflow-auto rounded-[5px] border border-border/60",children:/* @__PURE__ */e(Bt,{value:z,onValueChange:()=>{},language:"sql",readOnly:!0,embedded:!0,wrapLines:!0,dense:!0,hideLineNumbers:!0,ariaLabel:"Base SQL"})})]}),B?/* @__PURE__ */n("div",{className:"space-y-1",children:[_==="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(Bt,{value:k,onValueChange:()=>{},language:"sql",readOnly:!0,embedded:!0,wrapLines:!0,dense:!0,hideLineNumbers:!0,ariaLabel:"Drafted SQL"})})]}):!q&&/* @__PURE__ */e("div",{className:"rounded-[5px] border border-dashed border-border/70 px-3 py-2 text-[11px] text-muted-foreground",children:ue?"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(ie,{variant:"secondary",size:"xs",disabled:q||!B,onClick:()=>j(!1),children:"Replace SQL"}),/* @__PURE__ */e(ie,{size:"xs",disabled:q||!B||G,onClick:()=>j(!0),children:"Replace & Run"})]})]})})]})]});}function zp({activeEditor:t,isRunning:a,sqlEditor:s,pythonEditor:r,onActiveEditorChange:o,onOpenChange:c,onRun:d}){return/* @__PURE__ */e(ha,{open:t!==null,onOpenChange:c,children:/* @__PURE__ */e(pa,{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(Mt,{value:t??"sql",onValueChange:i=>o(i),className:"flex min-h-0 flex-1 flex-col",children:[/* @__PURE__ */n(ja,{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(fa,{className:"shrink-0 text-sm",children:"Query editor"}),/* @__PURE__ */n(At,{variant:"underline",className:"h-full items-end gap-5 self-stretch border-b-0",children:[/* @__PURE__ */e(Ye,{value:"sql",className:"px-0",children:"SQL"}),/* @__PURE__ */e(Ye,{value:"python",className:"px-0",children:"Python"})]}),/* @__PURE__ */e(ua,{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(ie,{type:"button",size:"xs",onClick:d,disabled:a,children:[a?/* @__PURE__ */e(xa,{className:"h-3.5 w-3.5 animate-spin"}):/* @__PURE__ */e(fl,{className:"h-3.5 w-3.5"}),"Run"]}),/* @__PURE__ */e(ie,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>c(!1),"aria-label":"Collapse query editor",title:"Collapse editor",children:/* @__PURE__ */e(gc,{className:"h-3.5 w-3.5"})})]})]}),/* @__PURE__ */e(mt,{value:"sql",forceMount:!0,className:"mt-0 min-h-0 flex-1 data-[state=inactive]:hidden",children:s}),/* @__PURE__ */e(mt,{value:"python",forceMount:!0,className:"mt-0 min-h-0 flex-1 data-[state=inactive]:hidden",children:r})]})})});}function _s(t,a){return t.current.cardId!==a&&(t.current={cardId:a,snapshots:{}}),t.current;}function jp({cardId:t,expandedEditor:a}){const s=Ae(null),r=Ae(null),o=Ae(null),c=Ae(null),d=Ae({cardId:t,snapshots:{}}),l=Je(i=>{var w,C;const h=i==="inline"?s:o,u=i==="inline"?r:c,m=(w=h.current)==null?void 0:w.captureSession(),p=(C=u.current)==null?void 0:C.captureSession(),f=_s(d,t);m&&(f.snapshots.sql=m),p&&(f.snapshots.python=p);},[t]);return Ne(()=>{var f,w;const i=_s(d,t),h=a===null?s:o,u=a===null?r:c,{sql:m,python:p}=i.snapshots;m&&((f=h.current)==null||f.restoreSession(m)),p&&((w=u.current)==null||w.restoreSession(p));},[t,a]),{inlineSqlEditorRef:s,inlinePythonEditorRef:r,expandedSqlEditorRef:o,expandedPythonEditorRef:c,captureEditorSessions:l};}function _o({openDelay:t=200,closeDelay:a=150}={}){const[s,r]=U(!1),o=Ae(null),c=Ae(null),d=Ae(!1),l=()=>{o.current&&(clearTimeout(o.current),o.current=null);},i=()=>{c.current&&(clearTimeout(c.current),c.current=null);};Ne(()=>()=>{o.current&&clearTimeout(o.current),c.current&&clearTimeout(c.current);},[]);const h=m=>{m.pointerType!=="touch"&&(i(),!s&&(l(),o.current=setTimeout(()=>r(!0),t)));},u=m=>{m.pointerType!=="touch"&&(l(),i(),c.current=setTimeout(()=>r(!1),a));};return{popoverProps:{open:s,onOpenChange:r},triggerProps:{onPointerEnter:h,onPointerLeave:u,onFocus:()=>{l(),i(),d.current||r(!0);},onClick:m=>{m.preventDefault(),l(),i(),r(!0);}},contentProps:{onCloseAutoFocus:()=>{d.current=!0,queueMicrotask(()=>{d.current=!1;});},onPointerEnter:m=>{m.pointerType!=="touch"&&i();},onPointerLeave:u}};}function Up({value:t}){const[a,s]=U(!1),r=Ae(null);Ne(()=>()=>{r.current&&clearTimeout(r.current);},[]);const o=async()=>{var c;try{if(!((c=navigator.clipboard)!=null&&c.writeText))throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(t),s(!0),r.current&&clearTimeout(r.current),r.current=setTimeout(()=>s(!1),1200);}catch{Qe.error("Failed to copy");}};return/* @__PURE__ */n("button",{type:"button","aria-label":`Copy ${t}`,onClick:o,className:"group inline-flex w-full cursor-pointer items-center justify-start rounded-[3px] bg-muted/35 px-2 py-1.5 text-left font-mono text-[11px] text-foreground transition-colors hover:bg-muted/60 focus-visible:bg-muted/60 focus-visible:outline-none",children:[/* @__PURE__ */e("code",{children:t}),a?/* @__PURE__ */e(Ft,{"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(cr,{"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 Hp({hint:t}){const{popoverProps:a,triggerProps:s,contentProps:r}=_o();return/* @__PURE__ */n(bt,{...a,children:[/* @__PURE__ */e(Tt,{asChild:!0,children:/* @__PURE__ */n(ie,{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(jh,{className:"h-3.5 w-3.5",strokeWidth:1.75}),/* @__PURE__ */e("span",{className:"hidden @[1550px]:inline",children:"Dashboard filters off"})]})}),/* @__PURE__ */n(vt,{align:"start",collisionPadding:8,...r,onOpenAutoFocus:o=>o.preventDefault(),className:"w-72 space-y-2.5 p-3",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e("p",{className:"text-[13px] font-medium",children:"Dashboard filters aren’t applied"}),/* @__PURE__ */e("p",{className:"text-[12px] leading-relaxed text-muted-foreground",children:t.description})]}),/* @__PURE__ */e(Up,{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 Gp({activeEditor:t,onExpand:a,trailing:s}){const r=`Expand ${t==="sql"?"SQL":"Python"} editor`;return(/* @__PURE__ */n("div",{className:"flex h-10 shrink-0 items-center gap-4 border-b border-border/60 px-4",children:[/* @__PURE__ */n(At,{variant:"underline",className:"h-full items-end gap-5 self-stretch border-b-0",children:[/* @__PURE__ */e(Ye,{value:"sql",className:"px-0 text-[13px]",children:"SQL"}),/* @__PURE__ */e(Ye,{value:"python",className:"px-0 text-[13px]",children:"Python"})]}),/* @__PURE__ */n("div",{className:"ml-auto flex min-w-0 shrink-0 items-center gap-1.5",children:[s,/* @__PURE__ */e(ie,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:a,"aria-label":r,title:r,children:/* @__PURE__ */e(xc,{className:"h-3.5 w-3.5",strokeWidth:1.75})})]})]}));}function Qp({value:t}){const[a,s]=U(!1),r=Ae(null);return Ne(()=>()=>{r.current&&clearTimeout(r.current);},[]),/* @__PURE__ */n(ie,{type:"button",variant:"ghost",size:"xs",className:"h-6 gap-1 px-1.5 text-[11px] text-muted-foreground","aria-label":"Copy example",onClick:async()=>{var c;try{if(!((c=navigator.clipboard)!=null&&c.writeText))throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(t),s(!0),r.current&&clearTimeout(r.current),r.current=setTimeout(()=>s(!1),1200);}catch{Qe.error("Failed to copy");}},children:[a?/* @__PURE__ */e(Ft,{className:"h-3 w-3",strokeWidth:1.75}):/* @__PURE__ */e(cr,{className:"h-3 w-3",strokeWidth:1.75}),a?"Copied":"Copy"]});}function Yp(){const{popoverProps:t,triggerProps:a,contentProps:s}=_o();return/* @__PURE__ */n(bt,{...t,children:[/* @__PURE__ */e(Tt,{asChild:!0,children:/* @__PURE__ */n(ie,{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(Vt,{className:"h-3.5 w-3.5",strokeWidth:1.75}),"How it works"]})}),/* @__PURE__ */n(vt,{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(Qp,{value:Ds})]}),/* @__PURE__ */e("div",{className:"max-h-40 overflow-auto",children:/* @__PURE__ */e(Bt,{value:Ds,language:"python",readOnly:!0,embedded:!0,dense:!0,hideLineNumbers:!0,wrapLines:!0,ariaLabel:"Python example"})})]})]})]});}function Wp({open:t,onOpenChange:a,onConfirm:s}){return/* @__PURE__ */e(bc,{open:t,onOpenChange:a,children:/* @__PURE__ */n(vc,{children:[/* @__PURE__ */n(yc,{children:[/* @__PURE__ */e(Nc,{children:"Clear the editor?"}),/* @__PURE__ */e(Cc,{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(wc,{children:[/* @__PURE__ */e(Sc,{children:"Cancel"}),/* @__PURE__ */e(Tc,{className:H(Xu({variant:"destructive",size:"xs"})),onClick:s,children:"Clear"})]})]})});}function Jp(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:Ir};}function Xp(){const{setTempQueryData:t}=xe(),a=za(),s=D(N=>N.tempQueryData),r=D(N=>N.card),o=Ze(),c=Z(()=>o!==r.type?{...r,type:o}:r,[r,o]),{queryKey:d}=nt(c),{setCardSql:l,setSqlGen:i,setCardPython:h,setCardCustomCfg:u,setCardPreferences:m,clearQueryConfig:p,setCardConfig:f,setCardType:w,setFrame:C,setCard:y,setActiveTabCardId:b}=xe();function v(){var E,T,M,I;const N=a.getQueryData(d);s!=null&&s.queryData||t({queryKey:d,queryData:N}),a.setQueryData(d,null),a.removeQueries({queryKey:d,exact:!0}),l(""),i({}),p(),f(void 0),h(""),u(""),m({});const g=D.getState().frame,F=D.getState().card,O=Ut(g,F),V=((E=O==null?void 0:O.customCardPreferences)==null?void 0:E.visualType)==="multiple"||!!((T=O==null?void 0:O.customCardPreferences)!=null&&T.dataInputCardIds)||(((M=O==null?void 0:O.customCardPreferences)==null?void 0:M.minInputs)||0)>1||(((I=O==null?void 0:O.customCardPreferences)==null?void 0:I.maxInputs)||0)>1,$=Jp(F,V);C({...g,cards:g.cards.map(q=>q.id===$.id?$:q)}),b($.id),y($),V||w(Ir);}return v;}const Bs="[&_.code-editor-pre]:!pb-14 [&_.code-editor-textarea]:!pb-14";function Zp(){var ke,ve,de,Be;const t=za(),{tokenProps:a}=It(),s=((ve=(ke=a.config)==null?void 0:ke.projectFeatures)==null?void 0:ve.features.aiWritingHelpers)!==!1,[r,o]=U("sql"),[c,d]=U(!1),[l,i]=U(!1),h=Xp(),[u,m]=U(!1),[p,f]=U(null),w=D(W=>W.frame),C=D(W=>W.card),{inlineSqlEditorRef:y,inlinePythonEditorRef:b,expandedSqlEditorRef:v,expandedPythonEditorRef:N,captureEditorSessions:g}=jp({cardId:C.id,expandedEditor:p});D(W=>W.selectedConnectionId),D(W=>W.tempQueryData);const F=D(W=>W.selectedDatabaseName);D(W=>W.selectedDatamodelId);const O=D(W=>W.selectedSchemaName),V=D(W=>W.selectedTableName),$=ye(W=>W.dashboard?Zl(W.dashboard).length:0),E=D(W=>W.inlineFilterValuesMap[(C==null?void 0:C.id)??""]),T=Z(()=>Ut(w,C),[w,C]),{manifest:M}=Kt(((de=T==null?void 0:T.customCardPreferences)==null?void 0:de.url)||""),I=Z(()=>{var W;return(W=M==null?void 0:M.visuals)==null?void 0:W.find(Fe=>{var oe;return Fe.name===((oe=T==null?void 0:T.customCardPreferences)==null?void 0:oe.componentName);});},[M,(Be=T==null?void 0:T.customCardPreferences)==null?void 0:Be.componentName]),q=Ht(T,I),P=Z(()=>ba({frame:w,configCard:T,isMultiInputVisual:q==="multiple"}),[w,T,q]),x=Z(()=>{const W=P.findIndex(Fe=>(Fe==null?void 0:Fe.id)===(C==null?void 0:C.id));return W<0?-1:St(C,W);},[P,C]),R=Z(()=>!T||q!=="multiple"||x<0?C.type:Jt(C,x,I==null?void 0:I.slots)??C.type,[T,q,x,C,I==null?void 0:I.slots]),S=Z(()=>R!==C.type?{...C,type:R}:C,[C,R]),k=Z(()=>$===0?null:lm(C==null?void 0:C.sql),[C==null?void 0:C.sql,$]),L=Ae(!0),{setCardCustomCfg:_,setQueryResultColumns:z,setCardSql:j,setTempQueryData:B,setCardPreferences:G,setCardType:ce,setCardPython:ue,setCard:X,updateCardInFrame:Y}=xe();D(W=>W.onSave),D(W=>W.onClose),D(W=>W.actions.setSqlGen);const fe=D(W=>W.runSql),he=D(W=>W.actions.setRunSql),re=D(W=>W.actions.setIsSqlRunning),{data:se,isLoading:ge,isFetching:be,isSuccess:Ie,isError:Ve,error:et,errorSql:pe,queryKey:we,refetch:Ee,errorMessage:rt}=nt(S),Ue=Ae(we);Ue.current=we;const He=C.type==="kpi"&&wr(C);Ne(()=>{if(se)if(se.rowLimitExceeded&&Qe.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),se.records.length>0){const{keys:W}=gl(se.records),Fe=He?om(se.records).value:void 0;z(C.type==="kpi"?Fe?[Fe]:[]:W,se.columnKeyMap,se.columns);}else z([]);},[C.type,se,z,He]),Ne(()=>{(ge||be)&&(re(!0),z([])),(Ve||Ie)&&re(!1),Ve&&z([]);},[ge,be,se,Ve,Ie,re,z,et]),Ne(()=>{fe&&(t.getQueryData(we)||Ee(),he(!1));},[fe,Ee,he,we,t]);const st=Ae(Ee);st.current=Ee,Ne(()=>{if(L.current){L.current=!1;return;}st.current();},[E]);function le(W,Fe){j(W),Fe&&he(!0);}function Se(){ol({queryClient:t,readQueryKey:()=>Ue.current,setRunSql:he});}function Ke(W){hn(),g("inline"),f(W);}function Ge(W){hn(),g("expanded"),f(W);}function $e(W){W||(hn(),g("expanded"),f(null));}function qe(W){s&&(W.metaKey||W.ctrlKey)&&!W.altKey&&!W.shiftKey&&W.key.toLowerCase()==="k"&&(W.preventDefault(),d(!0));}const We=ge||be;return(/* @__PURE__ */n("section",{role:"editor-section",className:"flex grow flex-col justify-end",onKeyDown:qe,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:H("min-w-0",u&&"flex-1"),children:/* @__PURE__ */e(Aa,{value:C.title,onSave:W=>X({...C,title:W}),onEditingChange:m,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(xl,{card:C})]}),/* @__PURE__ */e(Aa,{value:(C.description||"").trim(),onSave:W=>X({...C,description:W.trim()}),isEditable:!0,placeholder:"Add description",displayClassName:"text-[12px] leading-snug text-muted-foreground",inputClassName:"text-[12px] leading-snug"})]}),/* @__PURE__ */n(Mt,{value:r,onValueChange:W=>o(W),className:"flex min-h-0 grow flex-col",children:[/* @__PURE__ */e(Gp,{activeEditor:r,onExpand:()=>Ke(r),trailing:/* @__PURE__ */n(me,{children:[k?/* @__PURE__ */e(Hp,{hint:k}):null,r==="python"?/* @__PURE__ */e(Yp,{}):null]})}),/* @__PURE__ */n("div",{className:"relative min-h-0 grow",children:[/* @__PURE__ */e(mt,{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:p===null?/* @__PURE__ */e(us,{ref:y,className:Bs},`inline-sql-${C.id}`):null})}),/* @__PURE__ */e(mt,{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:p===null?/* @__PURE__ */e(ms,{ref:b,className:Bs},`inline-python-${C.id}`):null})}),/* @__PURE__ */n("div",{role:"editor-controls",className:"pointer-events-none absolute inset-x-4 bottom-3 z-10 flex items-end justify-end gap-2",children:[s?c?/* @__PURE__ */e("div",{className:"pointer-events-auto flex min-w-0 max-w-[560px] flex-1",children:/* @__PURE__ */e(qp,{currentSql:C==null?void 0:C.sql,selectedDatabaseName:F,selectedSchemaName:O,selectedTableName:V,onApplySql:le,autoFocus:!0,onDismiss:()=>d(!1)})}):/* @__PURE__ */e(ie,{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(ie,{type:"button",variant:"outline",size:"xs",className:"pointer-events-auto h-7 shrink-0 bg-background px-2.5 text-[12px] font-normal text-muted-foreground hover:text-foreground",title:"Clear the SQL, the Python step and the chart settings",onClick:()=>i(!0),children:"Clear"}),/* @__PURE__ */n(ie,{title:"Shift + Enter",disabled:We,onClick:Se,className:"pointer-events-auto shrink-0",size:"xs",children:[We?/* @__PURE__ */e(xa,{className:"h-3.5 w-3.5 animate-spin"}):/* @__PURE__ */e(fl,{className:"h-3.5 w-3.5"}),"Run"]})]})]})]}),/* @__PURE__ */e(Wp,{open:l,onOpenChange:i,onConfirm:h}),/* @__PURE__ */e(zp,{activeEditor:p,isRunning:We,sqlEditor:/* @__PURE__ */e(us,{ref:v},`expanded-sql-${C.id}`),pythonEditor:/* @__PURE__ */e(ms,{ref:N},`expanded-python-${C.id}`),onActiveEditorChange:Ge,onOpenChange:$e,onRun:Se})]}));}function Pr(){const t=D(r=>r.actions.setCardType),{columns:a,isLoading:s}=kc();return Je((r,o)=>{const c=t(r,{...o,catalog:a,catalogLoading:s});return c.status==="refused"?Qe.info("Fields are still loading",{description:"Try switching again in a moment."}):c.status==="changed"&&c.leftOut.length&&Qe.info("Some fields did not carry over to this visual",{description:c.leftOut.join(", ")}),c;},[t,a,s]);}const Cn=[{value:"table",label:"Table"},{value:"detailTable",label:"Detail"}];function ef({className:t}){const a=D(f=>f.card),s=D(f=>f.frame),r=D(f=>f.editorContext),o=Ze(),{setCard:c,updateCardInFrame:d}=xe(),l=(r==null?void 0:r.type)==="documentSection"&&!!r.lockedKind,i=(r==null?void 0:r.type)==="documentSection"?Cn.filter(f=>f.value==="table"):Cn,h=Cn.some(f=>f.value===o),u=va(a.config,a.type),m=im(a,s.cards);if(!h||!u||m||l||i.length<2)return/* @__PURE__ */e("div",{"aria-hidden":"true",className:H("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 p=f=>{if(f===o||m)return;const w=f,C=a.config??{},y=cm(o,w,C),b={...a,type:w,config:y};c(b),d(b);};return/* @__PURE__ */e("div",{role:"tablist",className:H("flex items-center gap-5",t),children:i.map(f=>{const w=o===f.value;return/* @__PURE__ */e("button",{type:"button",role:"tab","aria-selected":w,onClick:()=>p(f.value),className:H("-mb-px flex h-9 items-center border-b-2 text-[12px] transition-colors",w?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:f.label},f.value);})});}const tf={async writeTextToClipboard(t){return typeof navigator>"u"||!navigator.clipboard?!1:(await navigator.clipboard.writeText(t),!0);}},_a="h-6 gap-1 px-2 text-[11px] [&_svg]:h-3 [&_svg]:w-3";function Bo({children:t,className:a}){return/* @__PURE__ */e("div",{className:H("flex max-h-full min-h-0 flex-1 flex-col pt-3",a),children:t});}function Vo({children:t,className:a}){return/* @__PURE__ */e("div",{className:H("flex min-h-7 shrink-0 flex-wrap items-center justify-between gap-x-3 gap-y-1 px-3",a),children:t});}function Ko({children:t,className:a}){return/* @__PURE__ */e("div",{className:H("ml-auto flex min-w-0 flex-wrap items-center justify-end gap-1.5",a),children:t});}const Ta=50,af={request:"Query request",response:"Query response"};function Vs(t){try{return JSON.stringify(t,null,2);}catch(a){return console.error("Unable to stringify debug payload",a),null;}}function nf(t){if(!t||typeof t!="object")return{value:t};const a=t.records;return!Array.isArray(a)||a.length<=Ta?{value:t}:{value:{...t,records:a.slice(0,Ta),previewMeta:{truncatedRecords:!0,displayedRecords:Ta,totalRecords:a.length}},truncationMessage:`First ${Ta} of ${a.length} records. Copy includes all.`};}function $o({isOpen:t,onClick:a}){return/* @__PURE__ */n(ie,{onClick:a,variant:"outline",size:"xs",className:H(_a,t&&"bg-accent"),"aria-pressed":t,children:[/* @__PURE__ */e(Pa,{}),"Inspect payload"]});}function qo({payloads:t,onClose:a,className:s}){const r=t.queryResponse!==void 0,[o,c]=U("request"),d=o==="response"&&!r?"request":o,l=af[d],i=d==="request"?t.queryRequest:t.queryResponse,h=Z(()=>{if(i===void 0)return null;const m=d==="response"?nf(i):{value:i},p=Vs(m.value);return p?{json:p,truncationMessage:m.truncationMessage}:null;},[i,d]),u=async()=>{const m=i===void 0?null:Vs(i);if(!m)return Qe.error(`No ${l.toLowerCase()} available`),!1;try{return(await tf.writeTextToClipboard(m))?(Qe.success(`${l} copied`),!0):(Qe.error("Clipboard is not available"),!1);}catch(p){return console.error("Failed to copy debug payload",p),Qe.error(`Unable to copy ${l.toLowerCase()}`),!1;}};return/* @__PURE__ */n("section",{"aria-label":"Payload",className:H("flex min-h-0 flex-col",s),children:[/* @__PURE__ */n(Vo,{className:"items-end border-b border-border/60",children:[/* @__PURE__ */e(Mt,{value:d,onValueChange:m=>c(m),children:/* @__PURE__ */n(At,{variant:"underline","aria-label":"Payload",className:"gap-5 border-b-0",children:[/* @__PURE__ */e(Ye,{value:"request",className:"px-0 pb-2 text-[13px]",children:"Request"}),/* @__PURE__ */e(Ye,{value:"response",disabled:!r,className:"px-0 pb-2 text-[13px]",children:"Response"})]})}),/* @__PURE__ */n(Ko,{className:"gap-1 pb-1.5",children:[(h==null?void 0:h.truncationMessage)&&/* @__PURE__ */e("span",{className:"mr-1 text-[11px] text-muted-foreground",children:h.truncationMessage}),/* @__PURE__ */e(dr,{text:h==null?void 0:h.json,disabled:!h,className:"h-6 w-6 rounded-control px-0 text-muted-foreground",ariaLabel:`Copy ${l.toLowerCase()}`,onCopy:u}),/* @__PURE__ */e(ie,{variant:"ghost",size:"xs",className:"h-6 w-6 px-0 text-muted-foreground","aria-label":"Close payload",onClick:a,children:/* @__PURE__ */e(it,{className:"h-3.5 w-3.5"})})]})]}),/* @__PURE__ */e("div",{className:"mt-1 min-h-[120px] flex-1 overflow-auto px-1 py-1",children:h?/* @__PURE__ */e(Bt,{value:h.json,language:"json",readOnly:!0,embedded:!0,wrapLines:!0,dense:!0,hideLineNumbers:!0,ariaLabel:`${l} JSON`}):/* @__PURE__ */n("p",{className:"px-3 py-2 text-[12px] text-muted-foreground",children:["No ",l.toLowerCase()," available."]})})]});}const rf=1200;function sf(t){var r;const a=t.target;if(a instanceof HTMLInputElement||a instanceof HTMLTextAreaElement)return a.selectionStart!==a.selectionEnd;const s=(r=t.currentTarget.ownerDocument.defaultView)==null?void 0:r.getSelection();return!!(s&&!s.isCollapsed);}function zo({text:t,children:a,className:s,as:r="button",disabled:o,onClick:c,onCopy:d,...l}){const[i,h]=U(!1),u=Ae(void 0);Ne(()=>()=>{u.current&&clearTimeout(u.current);},[]);const m=()=>{u.current&&(clearTimeout(u.current),u.current=void 0),h(!1);},p=()=>{u.current&&clearTimeout(u.current),h(!0),u.current=setTimeout(()=>{h(!1),u.current=void 0;},rf);},f=async()=>{try{let b=!1;d?b=await d():typeof t=="string"&&navigator.clipboard&&(await navigator.clipboard.writeText(t),b=!0),b&&p();}catch(b){console.error("Failed to copy text",b);}},w=b=>{c==null||c(b),!(b.defaultPrevented||sf(b))&&f();},C=H("group/copy-on-click relative block w-full cursor-pointer rounded-control text-left transition-[background-color,box-shadow] duration-150","hover:bg-muted/30 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring motion-reduce:transition-none",o&&"cursor-default opacity-60",s),y=r==="div"?/* @__PURE__ */e("div",{...l,"aria-disabled":o||void 0,className:C,onClick:o?void 0:w,onBlur:m,onMouseLeave:m,children:a}):/* @__PURE__ */e("button",{type:"button",className:C,disabled:o,onClick:w,onBlur:m,onMouseLeave:m,...l,children:a});return/* @__PURE__ */e(xt,{delayDuration:0,children:/* @__PURE__ */n(ht,{open:i,onOpenChange:b=>{b||m();},children:[/* @__PURE__ */e(pt,{asChild:!0,children:y}),/* @__PURE__ */e(ft,{side:"top",children:"Copied!"})]})});}const lf="This visual couldn't load its data.";function jo({title:t=lf,hint:a,detail:s,defaultDetailsOpen:r=!1,detailClassName:o,actions:c,className:d}){const l=da(),[i,h]=U(r);return/* @__PURE__ */n("div",{role:"alert","aria-labelledby":l,className:H("flex shrink-0 flex-wrap items-center gap-x-2 gap-y-1 rounded-control bg-[hsl(38_92%_50%/0.1)] px-2.5 py-1.5 text-[12px] text-foreground",d),children:[/* @__PURE__ */e(bl,{"aria-hidden":"true",className:"h-3.5 w-3.5 shrink-0 text-[hsl(32_95%_44%)]"}),/* @__PURE__ */n("span",{id:l,className:"min-w-0 flex-1",children:[t,a?` ${a}`:""]}),c?/* @__PURE__ */e("span",{className:"ml-auto flex shrink-0 flex-wrap items-center gap-1.5",children:c}):null,s?/* @__PURE__ */n("details",{open:i,onToggle:u=>h(u.currentTarget.open),className:"basis-full text-[11px] text-muted-foreground",children:[/* @__PURE__ */e("summary",{className:"w-fit cursor-pointer list-none underline underline-offset-2 hover:text-foreground [&::-webkit-details-marker]:hidden",children:"Details"}),i?/* @__PURE__ */e(zo,{text:s,"aria-label":"Copy error message",title:"Copy error message",className:H("mt-1 max-h-60 overflow-auto",o),children:/* @__PURE__ */e("span",{className:"block whitespace-pre-wrap break-words text-left font-mono text-[11px] leading-[1.55]",children:s})}):null]}):null]});}const of=()=>{};function Uo({sql:t,label:a,ariaLabel:s,copyAriaLabel:r,headerActions:o,trailingHeaderActions:c,className:d,headerClassName:l,labelClassName:i,bodyClassName:h}){return/* @__PURE__ */n("div",{className:H("flex min-h-0 flex-col overflow-hidden",d),children:[/* @__PURE__ */n(Vo,{className:l,children:[/* @__PURE__ */e("span",{className:H("text-[12px] text-muted-foreground",i),children:a}),/* @__PURE__ */n(Ko,{children:[o,c]})]}),/* @__PURE__ */e("div",{className:H("min-h-[80px] overflow-auto px-1 py-1",h),children:/* @__PURE__ */e(zo,{as:"div",text:t,title:r,className:"min-h-[80px] [&_pre]:!cursor-pointer [&_textarea]:!cursor-pointer",children:/* @__PURE__ */e(Bt,{value:t,onValueChange:of,language:"sql",readOnly:!0,embedded:!0,wrapLines:!0,dense:!0,hideLineNumbers:!0,ariaLabel:s})})})]});}function Ho({error:t,errorSql:a,errorTitle:s,errorHint:r,defaultDetailsOpen:o=!1,errorMessageClassName:c,fillAvailableSqlHeight:d=!1,onOpenInEditor:l,onSendFeedback:i,showFeedbackButton:h=!0,debugPayloads:u,className:m,embedded:p=!1}){const[f,w]=U(!1),C=p?"px-3":"px-0",y=!!(l&&a),b=!!u,v=b&&f,N=d&&!v,g=!!(h&&i),F=y||b?/* @__PURE__ */n(me,{children:[l&&a?/* @__PURE__ */e(ie,{variant:"outline",size:"xs",className:_a,onClick:l,children:"Open in SQL editor"}):null,b?/* @__PURE__ */e($o,{isOpen:f,onClick:()=>w(V=>!V)}):null]}):null,O=g?/* @__PURE__ */e(ie,{type:"button",variant:"ghost",size:"xs",className:H(_a,"text-muted-foreground"),onClick:i,children:"Report issue"}):null;return/* @__PURE__ */n(Bo,{className:H("w-full",m),children:[/* @__PURE__ */e(jo,{title:s,hint:r,detail:t,defaultDetailsOpen:o,detailClassName:c,className:p?"mx-3":void 0,actions:F||O?/* @__PURE__ */n(me,{children:[F,O]}):void 0}),a?/* @__PURE__ */e(Uo,{sql:a,label:"Failed query",ariaLabel:"Failed SQL query",copyAriaLabel:"Copy failed query",headerClassName:C,className:H("mt-1",N&&"min-h-7 flex-1"),bodyClassName:H("max-h-80",N&&"min-h-0 max-h-none flex-1")}):null,v&&u?/* @__PURE__ */e(qo,{payloads:u,onClose:()=>w(!1),className:"mt-3 flex-1"}):null]});}function Rr({className:t,...a}){return/* @__PURE__ */e(Ho,{...a,className:H("!pt-0",t)});}function Ks(t){const{className:a,...s}=t;return/* @__PURE__ */e(Ho,{...s,embedded:!0,className:H("overflow-auto",a)});}function Go(t){const a=D(d=>d.card),s=D(d=>d.isDevMode),{switchEditorMode:r,setRunSql:o}=xe(),c=()=>{const d=t||a.sql||a.python||"";r("dev",{sqlToLoad:d}),setTimeout(()=>{o(!0);},100);};return{isDevMode:s,handleOpenInEditor:!s&&Sr(a.type)?c:void 0};}function cf(){const{authToken:t,tokenProps:a}=It(),{currentUser:s}=Ua(),r=Dc({mutationFn:async o=>{if(!(t!=null&&t.accessToken))throw new Error("No authentication token available");const d=`${a.apiServiceUrl||""}/v1/feedback`,l={...o,user:s,tokenContext:a},i=await eo(d,t.accessToken,l,"POST");if(!i||!i.success)throw new Error((i==null?void 0:i.error)||"Failed to send feedback");return i;},onSuccess:o=>{Qe.success(`Feedback sent successfully! Issue: ${o.issueNumber}`,{duration:5e3});},onError:o=>{console.error("Feedback submission error:",o),Qe.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 df(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 uf({code:t,language:a,wrapLongLines:s=!1,className:r,ariaLabel:o}){const c=Z(()=>Zu(t,a),[t,a]);return(/* @__PURE__ */e("div",{className:H("code-editor",r),children:/* @__PURE__ */e("pre",{"aria-label":o,className:H("w-full min-w-0 max-w-full bg-transparent px-3 py-2.5 font-mono text-[12px] leading-[1.55] [font-variant-numeric:tabular-nums]",s?"overflow-x-hidden whitespace-pre-wrap break-words":"overflow-x-auto whitespace-pre"),children:c===null?/* @__PURE__ */e("code",{className:"text-foreground",children:t}):/* @__PURE__ */e("code",{dangerouslySetInnerHTML:{__html:c}})})}));}function Or({open:t,onOpenChange:a,feedbackData:s,onSuccess:r,showDebugInfo:o=!1}){var F,O,V,$,E,T;const[c,d]=U(""),[l,i]=U(!1),{sendFeedback:h,isLoading:u,isSuccess:m,isError:p,data:f,reset:w}=cf(),C=m?"Feedback Sent":"Report a Query Issue",y=m?"Your feedback was sent to the support team.":"Tell us what happened. We’ll include technical details to help support investigate.",b=()=>{const M={...s,userMessage:c.trim()||void 0};h(M,{onSuccess:()=>r==null?void 0:r()});},v=()=>{d(""),i(!1),w(),a(!1);},N=M=>{M||v();},g={category:s.category,error:{message:(F=s.systemState)==null?void 0:F.errorMessage,sql:(O=s.systemState)==null?void 0:O.generatedSql,errorSql:(V=s.systemState)==null?void 0:V.errorSql},cardConfig:($=s.systemState)==null?void 0:$.cardConfig,dataSource:(E=s.systemState)==null?void 0:E.dataSource,filters:(T=s.systemState)==null?void 0:T.dashboardFilters,metadata:s.metadata};return/* @__PURE__ */e(ha,{open:t,onOpenChange:N,children:/* @__PURE__ */n(pa,{"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(ja,{className:"flex h-10 flex-row items-center space-y-0 border-b border-border px-3 pr-10 text-left",children:[/* @__PURE__ */e(fa,{className:"truncate text-[13px] font-medium",children:C}),m&&/* @__PURE__ */e(ua,{className:"sr-only",children:y})]}),!m&&/* @__PURE__ */n(me,{children:[/* @__PURE__ */n("div",{className:"min-w-0 space-y-4 px-3 py-4",children:[/* @__PURE__ */e(ua,{className:"text-[12px] leading-[1.5] text-muted-foreground",children:y}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n(A,{htmlFor:"feedback-message",className:"text-[12px] font-medium",children:["What Happened?"," ",/* @__PURE__ */e("span",{className:"font-normal text-muted-foreground",children:"(Optional)"})]}),/* @__PURE__ */e(Ec,{id:"feedback-message",name:"feedback-message",autoComplete:"off",placeholder:"Describe what you were doing when the issue occurred…",value:c,onChange:M=>d(M.target.value),size:"sm",className:"min-h-[112px] resize-none",disabled:u})]}),p&&/* @__PURE__ */n("div",{role:"alert",className:"flex items-start gap-2 text-[12px] leading-[1.5] text-destructive",children:[/* @__PURE__ */e(qn,{"aria-hidden":"true",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),/* @__PURE__ */e("p",{children:"We couldn’t send your feedback. Check your connection and try again."})]}),o&&/* @__PURE__ */n($t,{open:l,onOpenChange:i,children:[/* @__PURE__ */n("div",{className:"flex items-center gap-1",children:[/* @__PURE__ */e(qt,{asChild:!0,children:/* @__PURE__ */n(ie,{type:"button",variant:"ghost",size:"xs",className:"flex flex-1 items-center justify-between p-2 hover:bg-muted",children:[/* @__PURE__ */e("span",{className:"text-[12px] font-medium",children:"View data to be sent"}),l?/* @__PURE__ */e(Et,{"aria-hidden":"true",className:"h-3.5 w-3.5"}):/* @__PURE__ */e(zt,{"aria-hidden":"true",className:"h-3.5 w-3.5"})]})}),/* @__PURE__ */e(dr,{text:JSON.stringify(g,null,2),className:"h-8 w-8 shrink-0"})]}),/* @__PURE__ */e(jt,{className:"mt-2 min-w-0",children:/* @__PURE__ */e(Cr,{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(uf,{code:JSON.stringify(g,null,2),language:"json",wrapLongLines:!0})})})})]})]}),/* @__PURE__ */n(zn,{className:"gap-2 border-t border-border px-3 py-3 sm:space-x-0",children:[/* @__PURE__ */e(ie,{type:"button",variant:"outline",size:"xs",onClick:v,disabled:u,children:"Cancel"}),/* @__PURE__ */e(ie,{type:"button",size:"xs",onClick:b,disabled:u,"aria-busy":u,className:"min-w-[100px]",children:u?/* @__PURE__ */n(me,{children:[/* @__PURE__ */e(xa,{"aria-hidden":"true",className:"h-3.5 w-3.5 animate-spin motion-reduce:animate-none"}),"Sending…"]}):"Send Feedback"})]})]}),m&&/* @__PURE__ */n(me,{children:[/* @__PURE__ */n("div",{role:"status","aria-live":"polite",className:"flex items-start gap-3 px-3 py-4",children:[/* @__PURE__ */e(Ic,{"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:f==null?void 0:f.issueNumber}),". Our support team will review the report."]})]})]}),/* @__PURE__ */e(zn,{className:"border-t border-border px-3 py-3",children:/* @__PURE__ */e(ie,{type:"button",size:"xs",onClick:v,children:"Close"})})]})]})});}var Lr=/* @__PURE__ */(t=>(t.QUERY_GENERATION="query-generation",t))(Lr||{});function Qo(t,a){const[s,r]=U(!1),o=D(u=>u.card),c=ye(u=>Zl(u.dashboard)),{currentUser:d}=Ua(),{tokenProps:l}=or(ur),i=Je(()=>{r(!0);},[]),h=Z(()=>{const u=typeof window<"u"?window.location.href:"",m=typeof navigator<"u"?navigator.userAgent:"",p=typeof window<"u"?`${window.innerWidth}x${window.innerHeight}`:"";return{category:Lr.QUERY_GENERATION,user:d,tokenContext:l,systemState:{cardConfig:o.config,dataSource:o.dataSource,dashboardFilters:[...c],errorMessage:t||void 0,errorSql:a||o.sql||o.python,generatedSql:a||o.sql},metadata:{url:u,userAgent:m,timestamp:(/* @__PURE__ */new Date()).toISOString(),viewport:p}};},[d,l,o,c,t,a]);return{feedbackDialogOpen:s,setFeedbackDialogOpen:r,handleSendFeedback:i,feedbackPayload:h};}const mf="__editor_sql__",hf="__editor_python__";function pf(t){var s;const a=dm(t.python||"");return{sql:(s=t.sql)!=null&&s.trim()?mf:"",python:a.trim()?hf:""};}function Yo({className:t,style:a,...s}){var Ge,$e,qe,We,ke,ve;const r=D(de=>de.card),o=mr(),d=D(de=>de.isDevMode)?!1:((Ge=r.customCardPreferences)==null?void 0:Ge.showCardHeader)??!0,l=((qe=($e=r.preferences)==null?void 0:$e.displayOptions)==null?void 0:qe.showInlineFilterBar)??!0,i=D(de=>de.frame),h=D(de=>de.inlineFilterValuesMap[r.id]),u=ye(de=>de.selectedSheetId),m=D(de=>de.actions.setRunSql),p=D(de=>de.actions.setCardInlineFilterValue),f=D(de=>de.actions.removeCardInlineFilterValue),w=Je(de=>p(r.id,de),[r.id,p]),C=Je(de=>f(r.id,de),[r.id,f]),y=um(r,h,{savedFilters:l}).length>0,b=Z(()=>Ut(i,r),[i,r]),{manifest:v}=Kt(((We=b==null?void 0:b.customCardPreferences)==null?void 0:We.url)||""),N=Z(()=>{var de;return(de=v==null?void 0:v.visuals)==null?void 0:de.find(Be=>{var W;return Be.name===((W=b==null?void 0:b.customCardPreferences)==null?void 0:W.componentName);});},[v,(ke=b==null?void 0:b.customCardPreferences)==null?void 0:ke.componentName]),g=Ht(b,N),F=Z(()=>ba({frame:i,configCard:b,isMultiInputVisual:g==="multiple"}),[i,b,g]),O=Z(()=>{const de=F.findIndex(Be=>(Be==null?void 0:Be.id)===(r==null?void 0:r.id));return de<0?-1:St(r,de);},[F,r]),V=Z(()=>!b||g!=="multiple"||O<0?r.type:Jt(r,O,N==null?void 0:N.slots)??r.type,[b,g,O,r,N==null?void 0:N.slots]),$=V??r.type,E=Z(()=>$===r.type?r:{...r,type:$},[r,$]),T=E.type==="table"||E.type==="matrixTable"||E.type==="detailTable",M=Z(()=>V!==r.type?{...r,type:V}:r,[r,V]),{data:I,isLoading:q,isFetching:P,errorMessage:x,errorSql:R,pagination:S}=nt(M),k=Ha(E,I),L=!!x,{handleOpenInEditor:_}=Go(R||r.sql||r.python),{feedbackDialogOpen:z,setFeedbackDialogOpen:j,handleSendFeedback:B,feedbackPayload:G}=Qo(x,R||r.sql||r.python),ce=Z(()=>(I==null?void 0:I.records)||[],[I==null?void 0:I.records]),{setCard:ue,updateCardInFrame:X}=xe(),Y=k.id,fe=k.config,he=k.interactionConfig,re=k.controls,se=k.controlBindings,ge=k.customCfg,be=k.preferences,Ie=k.queryConfig,Ve=pf({sql:k.sql,python:k.python}),et=Ve.sql,pe=Ve.python,we=I==null?void 0:I.records,Ee=Z(()=>({id:Y,type:$,config:fe,interactionConfig:he,preferences:be,controls:re,controlBindings:se,sql:et,python:pe}),[Y,$,fe,he,be,re,se,et,pe]),rt=(de,Be)=>{var Fe,oe;const W={...r,paginationConfig:{page:de+1,pageSize:Be}};ue(W),X(W),r.sql&&(oe=(Fe=r.preferences)==null?void 0:Fe.tablePrefs)!=null&&oe.enableDevModePagination&&m(!0);},Ue=de=>{var Fe,oe,Ce,ct,tt;const Be=wl(de,(Fe=r.config)==null?void 0:Fe.metricColumns,(oe=r.config)==null?void 0:oe.groupByColumns,(Ce=r.config)==null?void 0:Ce.detailColumns),W={...r,config:{...(r.config||{}),sortByColumns:Be}};ue(W),X(W),r.sql&&(tt=(ct=r.preferences)==null?void 0:ct.tablePrefs)!=null&&tt.enableDevModePagination&&m(!0);},He=vl(Ee,we||void 0),st=hr(),le=Z(()=>{var de;return!Y||!we?null:yl({chartTheme:st,card:Ee,data:we,cardType:$,queryConfig:Ie,customCfg:ge,preferences:be,comparisonMetadata:(de=I==null?void 0:I.metadata)==null?void 0:de.comparisonMetadata,numericPresentation:He,resultColumns:I==null?void 0:I.columns,columnKeyMap:I==null?void 0:I.columnKeyMap});},[Ee,Y,ge,be,Ie,we,st,I==null?void 0:I.columns,I==null?void 0:I.columnKeyMap,(ve=I==null?void 0:I.metadata)==null?void 0:ve.comparisonMetadata,$,He]);function Se(de){return/* @__PURE__ */e(Ga,{FallbackComponent:fr,children:/* @__PURE__ */e(qi,{card:de})});}function Ke(){var de;if(k.type==="matrixTable")return/* @__PURE__ */e(_c,{card:k,frame:i,mode:"editor"});if(I!=null&&I.records&&(I==null?void 0:I.records.length)===0&&!q&&!P)return x?/* @__PURE__ */e("div",{className:"flex h-full flex-col items-start justify-start overflow-auto",children:/* @__PURE__ */e(Rr,{error:x,errorSql:R||r.sql||r.python,onOpenInEditor:_,onSendFeedback:B,showFeedbackButton:!0})}):/* @__PURE__ */e(Bc,{fallback:/* @__PURE__ */n("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[/* @__PURE__ */e(Vc,{className:"h-8 w-8 text-muted-foreground/40"}),/* @__PURE__ */e("p",{className:"text-[12px] text-muted-foreground",children:"No results to display"})]})});if((q||P)&&(!(I!=null&&I.records)||I.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(Kc,{})}):/* @__PURE__ */e("div",{className:"z-50 flex h-full items-center justify-center",children:/* @__PURE__ */e(Ct,{size:"md",color:"muted","aria-label":"Loading data"})});if(!k.id)return null;if($==="custom")return Se(r);if(!["table","matrixTable","detailTable","custom"].includes($)&&le)return/* @__PURE__ */e("div",{className:"relative h-full min-h-0 w-full flex-1 grow basis-0",children:q||P?/* @__PURE__ */e(me,{}):/* @__PURE__ */e($c,{cfg:le})});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(pr,{card:k,data:ce,resultColumns:I==null?void 0:I.columns,columnKeyMap:I==null?void 0:I.columnKeyMap,totalsByColumnId:I==null?void 0:I.tableTotalsByColumnId,columnTotals:I==null?void 0:I.tableColumnTotals,comparisonMetadata:(de=I==null?void 0:I.metadata)==null?void 0:de.comparisonMetadata,paginationMetadata:S,onPaginationChange:rt,onSortChange:Ue,isLoading:q||P})});}return/* @__PURE__ */n(Fc,{role:"editor-visual-card",className:H("relative flex h-full flex-col rounded-none bg-card text-card-foreground",t),style:{...o.cardFrameStyle,...a},...s,children:[(q||P)&&!Mc({type:$})&&(I==null?void 0:I.records)&&I.records.length>0&&/* @__PURE__ */e("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-background/50",children:/* @__PURE__ */e(Ct,{size:"md",color:"muted","aria-label":"Loading data"})}),d&&/* @__PURE__ */e(Ac,{className:H("flex flex-row items-start justify-between gap-4 px-4 pb-3 pt-3"),style:o.cardGutterStyle,children:/* @__PURE__ */n("div",{className:"min-w-0 flex-1 space-y-1",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Pc,{className:"min-w-0 text-[17px] font-semibold leading-tight tracking-[-0.005em]",children:/* @__PURE__ */e(Aa,{value:r.title,onSave:de=>ue({...r,title:de}),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(xl,{card:r}),/* @__PURE__ */e(bo,{}),/* @__PURE__ */e("div",{className:"ml-auto",children:/* @__PURE__ */e(ef,{})})]}),/* @__PURE__ */e("div",{className:"min-w-0",children:/* @__PURE__ */e(Aa,{value:(r.description||"").trim(),onSave:de=>ue({...r,description:de.trim()}),isEditable:!0,placeholder:"Add description",displayClassName:"text-[12px] leading-snug text-muted-foreground",inputClassName:"text-[12px] leading-snug"})})]})}),/* @__PURE__ */n(Rc,{card:r,sheetId:u||"",inlineFilterValues:h,setInlineFilterValue:w,removeInlineFilterValue:C,children:[y&&/* @__PURE__ */e("div",{className:"px-4 pb-2",style:o.cardGutterStyle,children:/* @__PURE__ */e(Oc,{card:r,sheetId:u||"",inlineFilterValues:h,setInlineFilterValue:w,removeInlineFilterValue:C,showSavedFilters:l})}),/* @__PURE__ */n(Lc,{className:H("flex min-h-0 grow flex-col",T?L?"px-4 pb-0 pt-2":"p-0 [&_.data-table-scroll-container]:border-0 [&_.data-table-scroll-container]:bg-transparent":L?"px-4 py-0":"px-4"),style:T&&!L?void 0:o.cardGutterStyle,children:[/* @__PURE__ */e("div",{className:"min-h-0 flex-1 grow basis-0",children:Ke()}),Nl(k)&&/* @__PURE__ */e("div",{className:H("pt-3",T&&"px-4"),children:/* @__PURE__ */e(Cl,{card:k,mode:"editor",records:I==null?void 0:I.records})})]})]}),/* @__PURE__ */e(Or,{open:z,onOpenChange:j,feedbackData:G,showDebugInfo:!0})]});}function $s(t){var a,s;return JSON.stringify({...t,data:{...t.data,datasets:(s=(a=t.data)==null?void 0:a.datasets)==null?void 0:s.map(r=>{const o={...r};return Object.keys(o).forEach(c=>{c.startsWith("semaphor")&&delete o[c];}),{...o,data:[]};})}},null,2);}const wn=({language:t,value:a,onChange:s,readonly:r})=>/* @__PURE__ */e(Bt,{className:"h-full w-full text-xs",language:t,value:a,onValueChange:s,readOnly:r,embedded:!0}),ff=()=>/* @__PURE__ */n(ja,{children:[/* @__PURE__ */e("div",{className:"flex items-center gap-2",children:/* @__PURE__ */e(fa,{children:"Customize Card"})}),/* @__PURE__ */n(ua,{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."})]})]}),gf=({customCode:t,cardCustomCfgString:a,mergedConfig:s,onConfigChange:r,onCodeChange:o})=>/* @__PURE__ */n(Mt,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[/* @__PURE__ */n(At,{variant:"underline",className:"justify-start gap-5",children:[/* @__PURE__ */e(Ye,{value:"final-config",className:"px-0",children:"Config"}),/* @__PURE__ */e(Ye,{value:"custom-config",className:"px-0",children:"Changes"}),/* @__PURE__ */e(Ye,{value:"custom-code",className:"px-0",children:"Custom Code"})]}),/* @__PURE__ */e(mt,{value:"final-config",className:"mt-2 grow rounded border",children:/* @__PURE__ */e(wn,{language:"json",value:s,onChange:r})}),/* @__PURE__ */e(mt,{value:"custom-config",className:"mt-2 grow rounded border",children:/* @__PURE__ */e(wn,{readonly:!0,language:"json",value:a,onChange:()=>{}})}),/* @__PURE__ */e(mt,{value:"custom-code",className:"mt-2 grow rounded border",children:/* @__PURE__ */e(wn,{language:"javascript",value:t,onChange:o})})]}),xf=({error:t,hasCardCustomConfig:a,onReset:s,onApply:r,onClose:o})=>/* @__PURE__ */n(zn,{className:"flex items-center",children:[/* @__PURE__ */e(A,{className:"mr-2 text-red-500",children:t}),/* @__PURE__ */e(ie,{disabled:!a,onClick:s,variant:"outline",children:"Reset"}),/* @__PURE__ */e(ie,{onClick:r,variant:"outline",children:"Apply"}),/* @__PURE__ */e(ie,{onClick:o,variant:"outline",children:"Close"})]});function bf({triggerVariant:t="icon",className:a,label:s="Customize Visual"}={}){const[r,o]=U(!1),[c,d]=U(""),[l,i]=U(""),[h,u]=U(""),[m,p]=U(""),f=D(T=>T.card),w=Ze(),C=D(T=>T.card.customCfg),y=C?JSON.stringify(C,null,2):"",b=Z(()=>w!==f.type?{...f,type:w}:f,[f,w]),{data:v}=nt(b),N=vl(Ha(f,v),v==null?void 0:v.records),g=hr(),{setCardCustomCfg:F,setCustomVisualCode:O}=xe(),V=()=>{var M,I,q;if(!((M=v==null?void 0:v.records)!=null&&M.length))return;const T=yl({chartTheme:g,card:f,data:v.records,cardType:f.type,queryConfig:f.queryConfig,preferences:f.preferences,comparisonMetadata:(I=v==null?void 0:v.metadata)==null?void 0:I.comparisonMetadata,numericPresentation:N,resultColumns:v==null?void 0:v.columns,columnKeyMap:v==null?void 0:v.columnKeyMap});if(T){d($s(T)),u(((q=f.preferences)==null?void 0:q.customVisualCode)||"");const P=zc(T,C);i($s(P));}},$=()=>{try{if(h&&O(h),l){const T=JSON.parse(l),M=ep(JSON.parse(c),T);F(M),p("");}}catch{p("Invalid JSON configuration");}},E=Object.keys(C||{}).length===0;return/* @__PURE__ */n(ha,{open:r,onOpenChange:o,children:[/* @__PURE__ */e(qc,{asChild:!0,children:t==="menu"?/* @__PURE__ */n(ie,{variant:"ghost",onClick:V,className:H("h-7 w-full justify-start gap-2 px-2 text-[13px] font-normal",E?"":"text-green-600 hover:text-green-700",a),children:[/* @__PURE__ */e(ps,{className:"h-3.5 w-3.5"}),/* @__PURE__ */e("span",{children:s})]}):/* @__PURE__ */e(Xe,{tooltip:"Customize Visual",onClick:V,className:H(E?"":"text-green-600 hover:text-green-700",a),children:/* @__PURE__ */e(ps,{className:"h-4 w-4"})})}),/* @__PURE__ */n(pa,{className:"flex h-[600px] grow flex-col overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[/* @__PURE__ */e(ff,{}),/* @__PURE__ */n("div",{className:"flex grow gap-2",children:[/* @__PURE__ */e(Ga,{FallbackComponent:fr,children:/* @__PURE__ */e(Yo,{className:"w-1/2 rounded shadow-none"})}),/* @__PURE__ */e(gf,{customCode:h,cardCustomCfgString:y,mergedConfig:l,onConfigChange:T=>i(T??""),onCodeChange:T=>u(T??"")})]}),/* @__PURE__ */e(xf,{error:m,hasCardCustomConfig:!!C,onReset:()=>{i(c),F(null);},onApply:$,onClose:()=>o(!1)})]})]});}function vf(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 yf(t){const a=t.trim().split(/\s+/);return a.length>1?(a[0][0]+a[1][0]).toUpperCase():t.slice(0,2).toUpperCase();}function Wo({chartType:t,chartName:a,isCustom:s=!1,className:r="h-6 w-6"}){if(!s&&t)return Sl(t,r);const o=jc(a);if(o)return Ma.cloneElement(o,{className:r});const c=yf(a),d=vf(a);return/* @__PURE__ */e("div",{className:H("flex items-center justify-center rounded text-white font-semibold text-xs",r),style:{backgroundColor:d},children:c});}function qs({chartType:t,chartName:a,isCustom:s=!1,pluginName:r,isSelected:o=!1,isActive:c=!1,onSelect:d,onHover:l}){return/* @__PURE__ */n("button",{type:"button",onClick:d,onMouseMove:l,"aria-pressed":o,title:r?`${a} · ${r}`:a,className:H("flex h-7 w-full min-w-0 items-center gap-2 rounded-[4px] px-2 text-left text-[12px] transition-colors",c&&"bg-muted"),children:[/* @__PURE__ */e(Wo,{chartType:t,chartName:a,isCustom:s,className:H("h-3.5 w-3.5 shrink-0",s?"text-[7px]":o?"text-foreground":"text-muted-foreground")}),/* @__PURE__ */e("span",{className:H("truncate",o?"font-medium text-foreground":"text-foreground/80"),children:a}),o&&/* @__PURE__ */e(Ft,{className:"ml-auto h-3 w-3 shrink-0"})]});}const zs=[{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"}],Nf=[{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"}],Sn=2;function Jo(t){return Nf.filter(a=>mm(a.id,t));}function Cf({selectedChart:t,onChartSelect:a,onClose:s}){var R;const[r,o]=U(""),[c,d]=U(0),l=Ae(null),{data:i=[],isLoading:h}=Uc(),u=Pr(),{setCardPreferences:m}=D(S=>S.actions),p=D(S=>S.card),f=D(S=>S.isDevMode),w=t??p.type,C=w==="custom"?(R=p.customCardPreferences)==null?void 0:R.componentName:void 0,{setCardCustomCfg:y,setQueryConfig:b,replaceFrameCards:v,clearModeDrafts:N,initializeModeDrafts:g}=xe(),F=Z(()=>{const S=Jo({isDevMode:f});if(!r)return S;const k=r.toLowerCase(),L=new Set(zs.filter(_=>_.label.toLowerCase().includes(k)).map(_=>_.id));return S.filter(_=>_.name.toLowerCase().includes(k)||L.has(_.group));},[f,r]),O=Z(()=>{const S=i.filter(L=>L.componentType==="chart"&&L.pluginType!=="standard");if(!r)return S;const k=r.toLowerCase();return S.filter(L=>L.name.toLowerCase().includes(k));},[i,r]),V=S=>{u(S).status!=="refused"&&(a==null||a(S),s==null||s());},$=S=>{const k=hm(S);if(k==="multiple"&&S.slots&&S.slots.length>0){y(null),m({}),b(void 0),N();const _=pm(S.slots,S,p);v(_),_[0]&&g(_[0]),s==null||s();return;}else if(u("custom",{customVisual:{type:"component",visualType:k,url:S.url,componentName:S.name,icon:S.icon,pluginChartType:S.chartType,minInputs:S.minInputs,maxInputs:S.maxInputs}}).status==="refused")return;a==null||a("custom",S),s==null||s();},E=Z(()=>{const S=zs.map(k=>({key:k.id,label:k.label,entries:F.filter(L=>L.group===k.id).map(L=>({kind:"default",id:L.id,name:L.name}))})).filter(k=>k.entries.length>0);return O.length===0?S:[...S,{key:"custom",label:"Custom charts",entries:O.map(k=>({kind:"custom",visual:k}))}];},[F,O]),T=Z(()=>E.flatMap(S=>S.entries),[E]),M=Math.min(c,Math.max(T.length-1,0)),I=S=>{S.kind==="default"?V(S.id):$(S.visual);},q=S=>{var L,_;const k=Math.max(0,Math.min(S,T.length-1));d(k),(_=(L=l.current)==null?void 0:L.querySelector(`[data-index="${k}"]`))==null||_.scrollIntoView({block:"nearest"});},P=S=>{if(T.length===0)return;const k=S.key==="ArrowDown"?Sn:S.key==="ArrowUp"?-Sn:S.key==="ArrowRight"?1:S.key==="ArrowLeft"?-1:0;if(k!==0&&(Math.abs(k)===Sn||!r))S.preventDefault(),q(M+k);else if(S.key==="Enter"){S.preventDefault();const L=T[M];L&&I(L);}};let x=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(Tl,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */e("input",{type:"text",placeholder:"Search charts",value:r,onChange:S=>{o(S.target.value),d(0);},onKeyDown:P,"aria-label":"Search charts",className:"h-full w-full bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),/* @__PURE__ */n("div",{ref:l,className:"max-h-[360px] overflow-y-auto px-1.5 pb-1.5",children:[E.map(S=>/* @__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:S.label}),/* @__PURE__ */e("div",{className:"grid grid-cols-2 gap-x-0.5",children:S.entries.map(k=>{const L=x++,_=L===M;if(k.kind==="default")return/* @__PURE__ */e("div",{"data-index":L,children:/* @__PURE__ */e(qs,{chartType:k.id,chartName:k.name,isSelected:w===k.id,isActive:_,onSelect:()=>I(k),onHover:()=>d(L)})},k.id);const{visual:z}=k;return/* @__PURE__ */e("div",{"data-index":L,children:/* @__PURE__ */e(qs,{chartName:z.name,isCustom:!0,pluginName:z.pluginName,isSelected:C===z.name,isActive:_,onSelect:()=>I(k),onHover:()=>d(L)})},`${z.url}-${z.name}`);})})]},S.key)),h&&/* @__PURE__ */e("div",{className:"py-3 text-center text-[11px] text-muted-foreground",children:"Loading custom charts…"}),T.length===0&&!h&&/* @__PURE__ */e("div",{className:"py-8 text-center text-[11px] text-muted-foreground",children:"No charts found"})]})]});}const Tn={table:Nr,matrixTable:Ra,bar:Ya,line:Qa,stackedBar:nd,stackedLine:ad,scatter:El,bubble:td,pie:ed,doughnut:Zc,kpi:Xc,treemap:Dl,bullet:kl,funnel:Jc,tornado:Wc,heatmap:Ra,range:Yc,radar:Qc,polarArea:Gc,text:Hc},kn={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"},wf=[{id:"table"},{id:"bar"},{id:"line"},{id:"pie"},{id:"kpi"},{id:"matrixTable"}],Sf=6;function Tf({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(nr,{selectedChart:t,onChartChange:a,compactMore:!0})]});}function nr({selectedChart:t,onChartChange:a,compactMore:s=!1,responsiveCompact:r=!1}){const[o,c]=U(!1),d=D(f=>f.isDevMode),l=D(f=>{var w,C;return((C=(w=f.card)==null?void 0:w.customCardPreferences)==null?void 0:C.componentName)??null;}),i=Z(()=>{const f=new Set(Jo({isDevMode:d}).map(C=>C.id)),w=wf.filter(C=>f.has(C.id)).map(C=>({id:C.id,label:kn[C.id]??C.id,icon:Tn[C.id],isCustom:!1}));return t==="custom"&&l?w.unshift({id:l,label:l,isCustom:!0}):!w.some(C=>C.id===t)&&Tn[t]&&f.has(t)&&w.unshift({id:t,label:kn[t]??t,icon:Tn[t],isCustom:!1}),w.slice(0,Sf);},[t,l,d]),h=f=>f.isCustom?t==="custom"&&l===f.id:t===f.id,u=f=>{f.isCustom||a(f.id);},m=i.some(h),p=m?"More":t==="custom"?l||"Custom":kn[t]||"More";return/* @__PURE__ */e("div",{className:"flex items-center",children:/* @__PURE__ */n("div",{className:"inline-flex h-7 items-center overflow-hidden rounded-control border border-input bg-background",children:[i.map(f=>{const w=f.icon,C=h(f);return/* @__PURE__ */n(ht,{children:[/* @__PURE__ */e(pt,{asChild:!0,children:/* @__PURE__ */n("button",{type:"button",onClick:()=>u(f),"aria-label":f.label,"aria-pressed":!!C,className:H("flex h-full w-7 items-center justify-center text-foreground/65 transition-colors hover:bg-muted/50 hover:text-foreground",r&&!C&&"hidden @[800px]:flex",C&&"bg-foreground/[0.08] font-medium text-foreground"),children:[w?/* @__PURE__ */e(w,{className:"h-3.5 w-3.5"}):/* @__PURE__ */e(Wo,{chartName:f.label,isCustom:!0,className:"h-3.5 w-3.5"}),/* @__PURE__ */e("span",{className:"sr-only",children:f.label})]})}),/* @__PURE__ */e(ft,{side:"bottom",children:f.label})]},`${f.isCustom?"custom":"default"}-${f.id}`);}),/* @__PURE__ */n(bt,{open:o,onOpenChange:c,children:[/* @__PURE__ */e(Tt,{asChild:!0,children:/* @__PURE__ */n("button",{type:"button","aria-label":s?"More chart types":p,className:H("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&&(m?"text-muted-foreground":"text-foreground")),children:[!s&&/* @__PURE__ */e("span",{className:"truncate",children:p}),/* @__PURE__ */e(Et,{className:H("h-3 w-3 shrink-0 text-muted-foreground transition-transform",o&&"rotate-180"),strokeWidth:1.75})]})}),/* @__PURE__ */e(vt,{className:"w-[360px] overflow-hidden p-0",align:"end",onOpenAutoFocus:f=>f.preventDefault(),children:/* @__PURE__ */e(Cf,{selectedChart:t,onChartSelect:f=>{a(f),c(!1);},onClose:()=>c(!1)})})]})]})});}function kf(){const t=D(i=>{var h,u;return(u=(h=i.card.preferences)==null?void 0:h.chartOptions)==null?void 0:u.indexAxis;}),a=D(i=>i.card.type),{setChartOrientation:s,setCardPreferences:r}=D(i=>i.actions),o=i=>{if(s(i),a!=="bullet")return;const h=i==="y"?"horizontal":"vertical",u=D.getState().card.preferences,m={...(u||{}),bulletConfig:{...((u==null?void 0:u.bulletConfig)||{}),orientation:h}};r(m);};function c(){const i=t??"x";return/* @__PURE__ */e(Xe,{onClick:()=>{o(i==="x"?"y":"x");},tooltip:"Chart Orientation",className:"h-7 w-7 px-0",children:i==="x"?/* @__PURE__ */e(vn,{className:"h-3.5 w-3.5"}):/* @__PURE__ */e(bn,{className:"h-3.5 w-3.5"})});}function d(){return/* @__PURE__ */e(Xe,{onClick:()=>{o(t==="y"||t===void 0?"x":"y");},tooltip:"Chart Orientation",className:"h-7 w-7 px-0",children:t==="y"||t===void 0?/* @__PURE__ */e(vn,{className:"h-3.5 w-3.5"}):/* @__PURE__ */e(bn,{className:"h-3.5 w-3.5"})});}function l(){const i=t??"y";return/* @__PURE__ */e(Xe,{onClick:()=>{o(i==="y"?"x":"y");},tooltip:"Chart Orientation",className:"h-7 w-7 px-0",children:i==="y"?/* @__PURE__ */e(bn,{className:"h-3.5 w-3.5"}):/* @__PURE__ */e(vn,{className:"h-3.5 w-3.5"})});}return/* @__PURE__ */e(me,{children:a==="funnel"?d():a==="bullet"?l():c()});}function _r({className:t,triggerVariant:a="icon",label:s="Display options"}){var y,b,v,N,g,F,O,V,$,E;const r=D(T=>T.card),{setCardPreferences:o,updateCardInFrame:c,setCard:d}=xe(),[l,i]=U(!1),h=((b=(y=r.preferences)==null?void 0:y.displayOptions)==null?void 0:b.showFilterInfo)??!0,u=((N=(v=r.preferences)==null?void 0:v.displayOptions)==null?void 0:N.showCardToolbar)??!0,m=((F=(g=r.preferences)==null?void 0:g.displayOptions)==null?void 0:F.showChrome)??!0,p=((V=(O=r.preferences)==null?void 0:O.displayOptions)==null?void 0:V.allowScroll)??!0,f=((E=($=r.preferences)==null?void 0:$.displayOptions)==null?void 0:E.showInlineFilterBar)??!0,w=(T,M)=>{var P;const I={...r.preferences,displayOptions:{...((P=r.preferences)==null?void 0:P.displayOptions),[T]:M}};o(I);const q={...r,preferences:I};d(q),c(q);},C=[{option:"showFilterInfo",label:"Filter info",hint:"Badge",checked:h},{option:"showCardToolbar",label:"Card tools",hint:"Expand, hover actions",checked:u},{option:"showChrome",label:"Card chrome",hint:"Frame and padding",checked:m},{option:"allowScroll",label:"Allow scroll",hint:"Content scroll",checked:p},{option:"showInlineFilterBar",label:"Inline filter bar",hint:"On-card filters",checked:f}];return/* @__PURE__ */e("div",{className:H("flex items-center",t),children:/* @__PURE__ */n(Wa,{modal:!1,open:l,onOpenChange:i,children:[/* @__PURE__ */e(Ja,{asChild:!0,children:a==="menu"?/* @__PURE__ */n(ie,{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(Pa,{className:"h-3.5 w-3.5 text-muted-foreground"}),/* @__PURE__ */e("span",{children:s})]}):/* @__PURE__ */e(Xe,{className:"h-7 w-7 p-0",tooltip:"Display Options",children:/* @__PURE__ */e(Oa,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(Xa,{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"}),C.map(T=>/* @__PURE__ */n(rd,{checked:T.checked,onCheckedChange:M=>w(T.option,M),onSelect:M=>M.preventDefault(),className:"[&_svg]:h-3.5 [&_svg]:w-3.5",children:[/* @__PURE__ */e("span",{className:"min-w-0 flex-1 truncate",children:T.label}),/* @__PURE__ */e("span",{className:"ml-3 shrink-0 text-[11px] text-muted-foreground",children:T.hint})]},T.option))]})]})});}function Br({className:t,triggerVariant:a="icon",label:s="Pinned filters"}){const[r,o]=U(!1),c=D(E=>E.card),d=D(E=>E.selectedConnectionId),{tokenProps:l}=It(),{setCard:i}=xe(),h=ye(E=>E.actions.removeCardInlineFilterValue),u=ye(E=>E.actions.setCardInlineFilterValue),m=D(E=>E.actions.removeCardInlineFilterValue),p=D(E=>E.actions.setCardInlineFilterValue),f=sd(),w=(c==null?void 0:c.inlineFilters)||[],C=Ma.useMemo(()=>c?[c]:[],[c]),{inlineCalculatedFields:y}=gr(),b=Ma.useMemo(()=>({fields:y.filter(E=>E.fieldScope==="card"),domainId:Xl(c==null?void 0:c.dataSource)}),[y,c==null?void 0:c.dataSource]),v=Za()??void 0,N=Il(jn(Ml,{activationConstraint:{distance:5}}),jn(ud,{coordinateGetter:dd}));function g({active:E,over:T}){if(!T||E.id===T.id)return;const M=w.findIndex(q=>q.id===T.id);if(M===-1)return;const I=up(w,String(E.id),M);I!==w&&i({...c,inlineFilters:[...I]});}function F(E){if(w.find(I=>fm(I,E)))return;const M=dp({id:Dt(),field:E,...gm(c??{},d)});i({...c,inlineFilters:[...w,M]});}function O(E){const T=w.filter(M=>M.id!==E);i({...c,inlineFilters:T}),f?m(c.id,E):h(c.id,E);}function V(E,T){const M=w.find(x=>x.id===E),I=w.map(x=>x.id===E?{...x,...T}:x);i({...c,inlineFilters:I});const q=I.find(x=>x.id===E);if(!q||!xm(M,q))return;const P=bm(q,v);P?f?p(c.id,P):u(c.id,P):f?m(c.id,E):h(c.id,E);}if(!cp(c==null?void 0:c.type))return null;const $=a==="menu";return/* @__PURE__ */e("div",{className:H("flex items-center gap-1",$&&"w-full",t),children:/* @__PURE__ */n(bt,{open:r,onOpenChange:o,children:[/* @__PURE__ */e(Tt,{asChild:!0,children:$?/* @__PURE__ */n(ie,{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(fs,{className:"h-3.5 w-3.5 text-muted-foreground"}),/* @__PURE__ */e("span",{children:s}),w.length>0&&/* @__PURE__ */e("span",{className:"ml-auto text-[11px] tabular-nums text-muted-foreground",children:w.length})]}):/* @__PURE__ */n(Xe,{tooltip:"Pin a filter",className:H("relative h-7 w-7 px-0",{"text-primary":w.length>0}),children:[/* @__PURE__ */e(fs,{className:"h-3.5 w-3.5"}),w.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:w.length})]})}),/* @__PURE__ */e(vt,{align:"end",className:H("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(ld,{cards:C,context:"inline-filter",onFieldSelect:F,inlineFilters:w,cardCalculated:b})}),w.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(Fl,{sensors:N,collisionDetection:od,onDragEnd:g,children:/* @__PURE__ */e(id,{items:w.map(E=>E.id),strategy:cd,children:/* @__PURE__ */e("div",{className:"space-y-1",children:w.map(E=>/* @__PURE__ */e(Df,{filter:E,onUpdate:T=>V(E.id,T),onRemove:()=>O(E.id)},E.id))})})})]})]})})]})});}function Df({filter:t,onUpdate:a,onRemove:s}){const{attributes:r,listeners:o,setNodeRef:c,transform:d,transition:l,isDragging:i}=md({id:t.id});return/* @__PURE__ */n("div",{ref:c,style:{transform:hd.Transform.toString(d),transition:l},className:H("flex items-center justify-between gap-1 rounded-md bg-muted px-1 py-1.5 text-sm",i&&"relative z-10 shadow-sm"),children:[/* @__PURE__ */e("button",{type:"button","aria-label":`Move ${t.title}`,className:"flex h-5 w-4 shrink-0 cursor-grab items-center justify-center text-muted-foreground hover:text-foreground active:cursor-grabbing",...r,...o,children:/* @__PURE__ */e(ir,{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(pd,{filter:t,variant:"inline",onAccept:h=>a(h),trigger:/* @__PURE__ */e(ie,{variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0",title:"Configure filter",children:/* @__PURE__ */e(en,{className:"h-3 w-3"})})}),/* @__PURE__ */e(ie,{variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0 hover:bg-destructive/10 hover:text-destructive",onClick:s,children:/* @__PURE__ */e(it,{className:"h-3 w-3"})})]})]});}const Ef={metric_selector:"Displayed metric",field_selector:"Group by field",aggregation_selector:"Aggregation",grain_selector:"Time grain"};function If(t,a){return t&&typeof t=="object"&&"label"in t&&typeof t.label=="string"&&t.label.trim().length>0?t.label:a||null;}const Ff={metric_selector:"config_metric_selector",field_selector:"config_field_selector",aggregation_selector:"config_aggregation",grain_selector:"config_grain"};function Ba(t,a){return`${t}:${a}`;}function Mf(t,a,s,r,o){const c=new Set(s.filter(l=>l.target!=="sql_param"&&l.target!=="presentation_currency").map(l=>Ba(l.controlId,l.target))),d=a.map(l=>{const i=to({card:t,control:l,matrixSpec:r,resolveDataType:o}).map(p=>p.value),h=Ff[l.type],m=[...(h&&i.includes(h)?[h]:[]),...i.filter(p=>p!==h)].find(p=>!c.has(Ba(l.id,p)));return m?{controlId:l.id,target:m}:null;}).find(Boolean);return d?{controlId:d.controlId,target:d.target,mapping:{}}:null;}function Af({card:t,dashboardControls:a,bindings:s,onChange:r,availableFieldChoices:o,matrixFieldCatalog:c=[],availableMetricChoices:d,suppressTransientStaleState:l=!1,matrixSpec:i,matrixPresentation:h}){const u=Z(()=>h??(i?Kh(i).presentation:void 0),[i,h]);function m(E){return!i||!u?[]:Nm(i,E,y).map(T=>({id:T.id,label:T.kind==="measure"?`${an(T.measure,u)} (${T.measure.aggregate})`:`${T.axis==="rows"?"Rows":"Columns"}: ${Er(T.level,u)}`}));}const p=[...a,...(t.controls||[])],[f,w]=U({}),C=tp({sql:t.sql,controlBindings:t.controlBindings});function y(E){return i?ao(E,i.source,c):E.dataType;}const b=vm(t,i,y),v=new Set(s.map(E=>Ba(E.controlId,E.target))),N=p.some(E=>to({card:t,control:E,matrixSpec:i,resolveDataType:y}).some(T=>!v.has(Ba(E.id,T.value)))),g=l?0:s.reduce((E,T)=>{const M=F(T.target),I=Object.values(T.mapping).filter(q=>{const P=T.target==="config_metric_selector"||T.target==="config_field_selector"?typeof q=="string"?q:q==null?void 0:q.id:typeof q=="string"?q:void 0;return typeof P=="string"&&!M.some(x=>x.value===P);}).length;return E+I;},0);function F(E){var T,M,I,q;switch(E){case"config_metric_selector":return d?d.filter(P=>!!P.target).map(P=>({value:P.target.id,label:P.target.label||P.option.label,target:P.target})):i&&u?m(E).map(P=>({value:P.id,label:P.label,target:{kind:"matrix_instance",id:P.id}})):((M=(T=t.config)==null?void 0:T.metricColumns)==null?void 0:M.map(P=>({value:P.id,label:P.label||P.id,target:P})))||[];case"config_field_selector":return o?o.filter(P=>!!P.target).map(P=>({value:P.target.id,label:P.target.label||P.option.label,target:P.target})):i&&u?m(E).map(P=>({value:P.id,label:P.label,target:{kind:"matrix_instance",id:P.id}})):((q=(I=t.config)==null?void 0:I.groupByColumns)==null?void 0:q.map(P=>({value:P.id,label:P.label||P.id,target:P})))||[];case"config_aggregation":return(b.config_aggregation||[]).map(P=>({value:P,label:P}));case"config_grain":return(b.config_grain||[]).map(P=>({value:P,label:P.charAt(0).toUpperCase()+P.slice(1)}));default:return[];}}const O=(E,T)=>{r(s.map((M,I)=>I!==E?M:T(M)));},V=E=>{r(s.filter((T,M)=>M!==E));},$=()=>{const E=Mf(t,p,s,i,y);E&&r([...s,E]);};if(typeof t.sql=="string"&&t.sql.trim().length>0){const E=C.map(({controlId:T,paramId:M})=>{const I=p.find(q=>q.id===T);return I?{id:T,paramId:M,label:I.label,reference:`[[param.${M}]]`}:{id:T,paramId:M,label:T,reference:`[[param.${M}]]`};});return/* @__PURE__ */e("div",{className:"space-y-2",children:E.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]]`."}):E.map(T=>/* @__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:T.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:T.reference}),/* @__PURE__ */e(dr,{text:T.reference,ariaLabel:`Copy ${T.reference}`})]})]})},`${T.id}:${T.paramId}`))});}return/* @__PURE__ */n("div",{className:"space-y-4",children:[g>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(qn,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),/* @__PURE__ */n("span",{children:[g," ",g===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((E,T)=>{const M=b[E.target]||[],I=p.find(B=>B.id===E.controlId),q=I?ym(I):null,P=(q==null?void 0:q.source.kind)==="manual"?q.source.options:[],x=F(E.target),R=m(E.target),S=E.matrixTargetId!==void 0&&!R.some(B=>B.id===E.matrixTargetId),k=Array.from(/* @__PURE__ */new Set([...P.map(B=>B.value),...Object.keys(E.mapping)])).map(B=>{const G=P.find(ce=>ce.value===B);return{value:B,label:(G==null?void 0:G.label)||B};}),L=`${E.controlId}-${E.target}-${T}`,_=f[L]??T===0,z=Object.keys(E.mapping).length,j=I!=null&&I.type?Ef[I.type]||I.type:null;return/* @__PURE__ */n($t,{open:_,onOpenChange:B=>w(G=>({...G,[L]:B})),className:"rounded-md border",children:[/* @__PURE__ */n("div",{className:"flex items-start justify-between gap-2 p-3",children:[/* @__PURE__ */e(qt,{asChild:!0,children:/* @__PURE__ */n("button",{type:"button",className:"flex min-w-0 flex-1 items-start gap-2 text-left",children:[_?/* @__PURE__ */e(Et,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}):/* @__PURE__ */e(zt,{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:(I==null?void 0:I.label)||"Control"}),j?/* @__PURE__ */e(Al,{variant:"secondary",className:"shrink-0 text-[11px] font-normal text-muted-foreground",children:j}):null]}),/* @__PURE__ */e("div",{className:"text-xs text-muted-foreground",children:z>0?`${z} mapped`:"No mappings yet"})]})]})}),/* @__PURE__ */e(ie,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>V(T),children:/* @__PURE__ */e(Pl,{className:"h-4 w-4"})})]}),/* @__PURE__ */n(jt,{className:"space-y-3 border-t px-3 pb-3 pt-2",children:[i?/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs",htmlFor:`matrix-target-${L}`,children:"Matrix target"}),/* @__PURE__ */n(ee,{value:E.matrixTargetId??"__none__",onValueChange:B=>O(T,G=>{const{matrixTargetId:ce,...ue}=G;return B==="__none__"?ue:{...ue,matrixTargetId:B};}),children:[/* @__PURE__ */e(te,{id:`matrix-target-${L}`,"aria-label":"Matrix target",children:/* @__PURE__ */e(ae,{placeholder:"Choose target"})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"__none__",children:R.length===1?`Automatic: ${R[0].label}`:"Choose target"}),S?/* @__PURE__ */e(K,{value:E.matrixTargetId,disabled:!0,children:"Missing target"}):null,R.map(B=>/* @__PURE__ */e(K,{value:B.id,children:B.label},B.id))]})]}),S?/* @__PURE__ */e("p",{role:"alert",className:"text-xs text-amber-700",children:"The saved Matrix target is no longer available."}):R.length===0?/* @__PURE__ */e("p",{role:"alert",className:"text-xs text-muted-foreground",children:"No eligible Matrix target."}):!E.matrixTargetId&&R.length>1?/* @__PURE__ */e("p",{role:"alert",className:"text-xs text-amber-700",children:"Select a Matrix target."}):null]}):null,k.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."}):x.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(A,{className:"text-xs",children:"Map each choice"}),/* @__PURE__ */e("div",{className:"space-y-2",children:k.map(B=>{const G=E.mapping[B.value],ce=E.target==="config_metric_selector"||E.target==="config_field_selector"?typeof G=="string"?G:G==null?void 0:G.id:typeof G=="string"?G:void 0,ue=!l&&typeof ce=="string"&&!x.some(fe=>fe.value===ce),X=If(G,ce),Y=ce&&ue?[...x,{value:ce,label:"Needs remap",target:G}]:x;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(A,{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:B.label})]}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-[11px] text-muted-foreground",children:"Switch to"}),/* @__PURE__ */n(ee,{value:ce||"__none__",onValueChange:fe=>O(T,he=>{if(he.target==="config_metric_selector"){const se={...he.mapping};if(fe==="__none__")delete se[B.value];else{const ge=Y.find(be=>be.value===fe);ge!=null&&ge.target?se[B.value]=ge.target:delete se[B.value];}return{...he,mapping:se};}if(he.target==="config_field_selector"){const se={...he.mapping};if(fe==="__none__")delete se[B.value];else{const ge=Y.find(be=>be.value===fe);ge!=null&&ge.target?se[B.value]=ge.target:delete se[B.value];}return{...he,mapping:se};}const re={...he.mapping};return fe==="__none__"?delete re[B.value]:re[B.value]=fe,{...he,mapping:re};}),children:[/* @__PURE__ */e(te,{children:/* @__PURE__ */e(ae,{placeholder:"Choose what this should use"})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"__none__",children:"Not mapped"}),Y.map(fe=>/* @__PURE__ */e(K,{value:fe.value,children:fe.label},fe.value))]})]}),ue?/* @__PURE__ */n("div",{className:"flex items-center gap-1.5 text-[11px] text-amber-700",children:[/* @__PURE__ */e(qn,{className:"h-3 w-3 shrink-0"}),/* @__PURE__ */n("span",{children:["Needs remap",X?` · Previously: ${X}`:""]})]}):null]})]},`${E.controlId}-${E.target}-${B.value}`);})}),M.length>0&&/* @__PURE__ */n("p",{className:"text-[11px] text-muted-foreground",children:["Available choices for this card: ",M.join(", ")]})]})]})]},L);}),N?/* @__PURE__ */n(ie,{type:"button",variant:"outline",size:"sm",onClick:$,children:[/* @__PURE__ */e(ga,{className:"mr-2 h-4 w-4"}),"Add another control response"]}):null]});}function Pf(t,a,s){const{eligibleTargets:r}=wo(t,a,s),o=rp(t),c=new Map(o.map(l=>[l.id,l])),d=new Map(sp(t,s).map(l=>[l.measureId,l.label]));return r.map(l=>{var i;return{key:So(l),label:l.kind==="metric"?((i=c.get(l.metricId))==null?void 0:i.label)||l.metricId:l.kind==="column"?l.columnKey:d.get(l.measureId)||l.measureId,target:l};});}function Rf(t){return t?t.kind==="metric"?t.metricId:t.kind==="column"?t.columnKey:t.measureId:"invalid target";}function Of({matrixCatalog:t,card:a,dashboardControls:s,resultColumnKeys:r=[],bindings:o,onChange:c}){const d=[...s,...(a.controls||[])],l=d.filter(ap),i=Z(()=>Pf(a,r,t),[a,r,t]),h=Z(()=>wo(a,r,t),[a,r,t]),u=np({bindings:o,controls:d,...h}),{preferences:m,resolveBoundCurrency:p}=fd(a,r,t),[f,w]=U(""),[C,y]=U(""),b=i.find(g=>g.key===C),v=!!(f&&b)&&!o.some(g=>g.presentationTarget&&b&&So(g.presentationTarget)===b.key),N=g=>{if(!m)return;const F=Qh({card:a,target:g,resultColumnKeys:r,valueFormatPreferences:m,boundCurrency:p(g),matrixCatalog:t});if(F)return $h(1e3,F);};return l.length===0&&o.length===0?/* @__PURE__ */e("p",{className:"text-xs text-muted-foreground",children:"Add a manual enum whose options are ISO currency codes to enable presentation currency bindings."}):/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e("h5",{className:"text-xs font-medium",children:"Currency presentation"}),/* @__PURE__ */e("p",{className:"text-xs text-muted-foreground",children:"Change only the display currency for an explicit metric or column."})]}),o.map((g,F)=>/* @__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:[g.controlId," →"," ",Rf(g.presentationTarget),g.presentationTarget?` · ${N(g.presentationTarget)??"unavailable"}`:null]}),/* @__PURE__ */e(ie,{variant:"ghost",size:"xs",onClick:()=>c(o.filter((O,V)=>V!==F)),children:/* @__PURE__ */e(Pl,{className:"h-3.5 w-3.5"})})]},`${g.controlId}:${JSON.stringify(g.presentationTarget)}`)),u.length>0?/* @__PURE__ */e("div",{className:"space-y-1 text-xs text-destructive",children:u.map((g,F)=>/* @__PURE__ */n("p",{children:[g.controlId?`${g.controlId}: `:"",g.code.split("_").join(" ")]},`${g.controlId||"binding"}:${g.code}:${F}`))}):null,/* @__PURE__ */n("div",{className:"grid grid-cols-[1fr_1fr_auto] gap-2",children:[/* @__PURE__ */n(ee,{value:f,onValueChange:w,children:[/* @__PURE__ */e(te,{size:"xs",children:/* @__PURE__ */e(ae,{placeholder:"Currency control"})}),/* @__PURE__ */e(ne,{children:l.map(g=>/* @__PURE__ */e(K,{value:g.id,children:g.label},g.id))})]}),/* @__PURE__ */n(ee,{value:C,onValueChange:y,children:[/* @__PURE__ */e(te,{size:"xs",children:/* @__PURE__ */e(ae,{placeholder:"Target"})}),/* @__PURE__ */e(ne,{children:i.map(g=>/* @__PURE__ */e(K,{value:g.key,children:g.label},g.key))})]}),/* @__PURE__ */e(ie,{variant:"outline",size:"xs",disabled:!v,onClick:()=>{b&&(c([...o,{controlId:f,target:"presentation_currency",presentationTarget:b.target}]),y(""));},children:/* @__PURE__ */e(ga,{className:"h-3.5 w-3.5"})})]})]});}const Lf=[];function Vr({className:t,triggerVariant:a="icon",label:s="Controls"}){var L,_,z;const{handleOpenChange:r,preventPassiveDismissDuringCreate:o,resolvedOpen:c,setIsCreateFlowActive:d}=Uh({}),l=D(j=>j.card),i=D(j=>j.frame),h=D(j=>j.queryResultColumns),u=ye(j=>j.dashboard),p=ye(j=>j.dashboard.controls)||Lf,{setCard:f,updateCardInFrame:w}=xe(),[C,y]=U(null);Ne(()=>{c&&!C&&l!=null&&l.id&&y(l.id);},[l==null?void 0:l.id,c,C]),Ne(()=>{!c&&C!==null&&y(null);},[c,C]);const b=Z(()=>C?(i==null?void 0:i.cards.find(j=>j.id===C))||((l==null?void 0:l.id)===C?l:void 0):l,[l,i==null?void 0:i.cards,C]),v=(b==null?void 0:b.type)==="matrixTable"?(L=b.config)==null?void 0:L.matrix:void 0,N=Z(()=>c&&v?lp(v.spec,b==null?void 0:b.controlBindings):[],[c,v,b==null?void 0:b.controlBindings]),g=gd(N),F=Z(()=>g.catalog.map(j=>({...j.field,dataType:dl(j.resolvedField.dataType)})),[g.catalog]),O=(b==null?void 0:b.controls)||[],V=b?Cm(u,{excludeCardId:b.id}):p.map(j=>j.id),$=((b==null?void 0:b.controlBindings)||[]).filter(wm),E=((b==null?void 0:b.controlBindings)||[]).filter(gn),T=xd({card:b,controls:O}),M={choices:Sm(b),targetMap:Object.fromEntries((((_=b==null?void 0:b.config)==null?void 0:_.groupByColumns)||[]).map(j=>[j.id,j]))},I={choices:Tm(b),targetMap:Object.fromEntries((((z=b==null?void 0:b.config)==null?void 0:z.metricColumns)||[]).map(j=>[j.id,j]))},q=M.choices.map(j=>({option:j,target:M.targetMap[j.value]})),P=I.choices.map(j=>({option:j,target:I.targetMap[j.value]})),x=(j,B)=>{if(!b)return;const G=(B==null?void 0:B.type)==="rename"?gs(b,{type:"rename",oldId:B.oldId,newId:B.newId}):(B==null?void 0:B.type)==="remove"?gs(b,{type:"remove",controlId:B.controlId}):b,ce={...G,controls:j,controlBindings:km(G.controlBindings,j)};w(ce),(l==null?void 0:l.id)===ce.id&&f(ce);},R=j=>{if(!b)return;const B={...b,controlBindings:[...Dm(j,(b.controlBindings||[]).filter(G=>!gn(G))),...E]};w(B),(l==null?void 0:l.id)===B.id&&f(B);},S=j=>{if(!b)return;const B={...b,controlBindings:[...(b.controlBindings||[]).filter(G=>!gn(G)),...j]};w(B),(l==null?void 0:l.id)===B.id&&f(B);},k=a==="menu";return/* @__PURE__ */e("div",{className:H("flex items-center gap-1",k&&"w-full",t),children:/* @__PURE__ */n(bt,{modal:!0,open:c,onOpenChange:r,children:[/* @__PURE__ */e(Tt,{asChild:!0,children:k?/* @__PURE__ */n(ie,{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(Oa,{className:"h-3.5 w-3.5 text-muted-foreground"}),/* @__PURE__ */e("span",{children:s}),O.length+$.length>0&&/* @__PURE__ */e("span",{className:"ml-auto text-[11px] tabular-nums text-muted-foreground",children:O.length+$.length})]}):/* @__PURE__ */n(Xe,{tooltip:"Configure Controls",className:H("relative h-7 w-7 px-0",{"text-primary":O.length>0||$.length>0}),children:[/* @__PURE__ */e(Oa,{className:"h-3.5 w-3.5"}),O.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:O.length+$.length})]})}),/* @__PURE__ */n(vt,{className:H("flex max-h-[85vh] w-[560px] max-w-[95vw] flex-col",k&&"z-[60]"),align:"end",onEscapeKeyDown:o,onPointerDownOutside:o,children:[/* @__PURE__ */n("div",{className:"space-y-1 border-b pb-4",children:[/* @__PURE__ */e("h4",{className:"text-sm font-medium",children:"Card-only controls"}),/* @__PURE__ */e("p",{className:"text-xs text-muted-foreground",children:"Add controls that belong only to this card, or decide how this card should respond to shared dashboard controls."}),b!=null&&b.sql?/* @__PURE__ */e("p",{className:"text-xs text-muted-foreground",children:"SQL cards reference controls explicitly with syntax like `[[param.wac_type]]`."}):null]}),/* @__PURE__ */e("div",{className:"flex-1 overflow-y-auto pt-5",children:/* @__PURE__ */n("div",{className:"space-y-5 pr-1",children:[/* @__PURE__ */e(Hh,{scope:"card",card:b,controls:O,reservedControlIds:V,usageByControlId:T,availableFieldChoices:q,availableMetricChoices:P,onCreateFlowActiveChange:d,onChange:(j,B,G)=>x(j,G),emptyMessage:"No card-scoped controls yet."}),/* @__PURE__ */n("div",{className:"space-y-1 border-t pt-4",children:[/* @__PURE__ */e("h4",{className:"text-sm font-medium",children:"How this card uses controls"}),/* @__PURE__ */e("p",{className:"text-xs text-muted-foreground",children:"Choose what each control changes in this card."})]}),b?/* @__PURE__ */n(me,{children:[/* @__PURE__ */e(Af,{card:b,dashboardControls:p,bindings:$,onChange:R,availableFieldChoices:v?void 0:q,availableMetricChoices:v?void 0:P,matrixSpec:v==null?void 0:v.spec,matrixPresentation:v==null?void 0:v.presentation,matrixFieldCatalog:F,suppressTransientStaleState:!!(v&&g.pending)}),/* @__PURE__ */e("div",{className:"border-t pt-4",children:/* @__PURE__ */e(Of,{matrixCatalog:g.catalog,card:b,dashboardControls:p,resultColumnKeys:h,bindings:E,onChange:S})})]}):null]})})]})]})});}function Xo({showOrientation:t=!0,showGridStyle:a=!0,showInlineFilters:s=!0,showControls:r=!0,showDisplayOptions:o=!0}={}){const c=D(f=>f.card),d=D(f=>{var w,C;return(C=(w=f.card)==null?void 0:w.preferences)==null?void 0:C.chartOptions;}),l=bd(d),{setChartGrid:i}=xe();function h(){const f=["xy","none","x","y"],C=(f.indexOf(l)+1)%f.length;i(f[C]);}const u=t&&["line","bar","range","stackedBar","stackedLine","horizontalBar","funnel","bullet"].includes(c.type),m=a&&!["pie","doughnut","funnel","radar","polarArea","table","detailTable","custom","kpi","text"].includes(c.type);return u||m||s||r||o?/* @__PURE__ */n("div",{"data-info":"visual-settings",className:"flex items-center gap-2",children:[u&&/* @__PURE__ */e(me,{children:/* @__PURE__ */e(kf,{})}),m&&/* @__PURE__ */n(Xe,{tooltip:"Grid Style",onClick:h,className:"h-7 w-7 px-0",children:[(l==="xy"||!l)&&/* @__PURE__ */e(Ra,{className:"h-3.5 w-3.5"}),l==="x"&&/* @__PURE__ */e(Rl,{className:"h-3.5 w-3.5"}),l==="y"&&/* @__PURE__ */e(Ol,{className:"h-3.5 w-3.5"}),l==="none"&&/* @__PURE__ */e(pl,{className:"h-3.5 w-3.5"})]}),s&&/* @__PURE__ */e(Br,{}),r&&/* @__PURE__ */e(Vr,{}),o&&/* @__PURE__ */e(_r,{})]}):null;}function _f({errorMessage:t,errorSql:a,onOpenInEditor:s}){const{feedbackDialogOpen:r,setFeedbackDialogOpen:o,handleSendFeedback:c,feedbackPayload:d}=Qo(t,a);return/* @__PURE__ */n(me,{children:[/* @__PURE__ */e("div",{className:"flex h-full min-h-0 flex-col overflow-auto px-4 py-0",children:/* @__PURE__ */e(Rr,{error:t,errorSql:a,errorMessageClassName:"max-h-40",fillAvailableSqlHeight:!0,className:"max-h-none",onOpenInEditor:s,onSendFeedback:c,showFeedbackButton:!0})}),/* @__PURE__ */e(Or,{open:r,onOpenChange:o,feedbackData:d,showDebugInfo:!0})]});}function Bf({isPreviewMode:t,onPreviewToggle:a,configCard:s}){var x,R,S,k,L;const r=D(_=>_.frame),o=D(_=>_.card),c=D(_=>_.editorContext),d=(c==null?void 0:c.type)==="documentSection",{setFrame:l,setActiveTabCardId:i,setCard:h,updateCardInFrame:u,closeCardTab:m}=xe(),{manifest:p}=Kt(((x=s==null?void 0:s.customCardPreferences)==null?void 0:x.url)||""),f=(R=p==null?void 0:p.visuals)==null?void 0:R.find(_=>{var z;return _.name===((z=s==null?void 0:s.customCardPreferences)==null?void 0:z.componentName);}),C=Ht(s,f)==="multiple",y=(f==null?void 0:f.minInputs)??((S=s==null?void 0:s.customCardPreferences)==null?void 0:S.minInputs)??1,b=(f==null?void 0:f.maxInputs)??((k=s==null?void 0:s.customCardPreferences)==null?void 0:k.maxInputs),v=Z(()=>ba({frame:r,configCard:s,isMultiInputVisual:C}),[r,s,C]),N=C?v.filter(Boolean).length:r.cards.length,g=d?!1:b?N<b:!0,F=N>Math.max(y||1,1),O=!!((L=s==null?void 0:s.customCardPreferences)!=null&&L.dataInputCardIds),V=(_,z)=>{_.dataTransfer.setData("tabIndex",z.toString());},$=_=>{_.preventDefault();},E=(_,z)=>{const j=_.dataTransfer.getData("tabIndex");if(j===z.toString())return;const B=Array.from(r.cards),[G]=B.splice(parseInt(j),1);B.splice(z,0,G),l({...r,cards:B});};function T(_){const z=(s==null?void 0:s.id)===_;(O&&z?r.cards.length>1:F)&&m(_,{renumber:C&&!O?Fm:void 0});}function M(_,z){if(!g)return;const j={...r,cards:[...r.cards,z],activeCardId:_.id};l(j),i(z.id);}function I(){if(d)return;if(C&&(s==null?void 0:s.id)===o.id){q(o);return;}const _={...o,id:Dt(),title:`${o.title} Copy`,tabTitle:`${o.tabTitle||o.title} Copy`,customCardPreferences:o.customCardPreferences?{...o.customCardPreferences,slotIndex:C?Math.max(-1,...v.map((z,j)=>St(z,j)))+1:o.customCardPreferences.slotIndex}:void 0};M(o,_);}function q(_){var ue;if(d||!g)return;let z=C?"table":Ir,j="Title",B="";const G=C?Math.max(-1,...v.map((X,Y)=>St(X,Y)))+1:N;if(C&&(ue=f==null?void 0:f.slots)!=null&&ue.length){const X=Yn(f.slots,G);X&&(z=Mm(X),j=X.label||`Tab ${G+1}`,B=X.description||"");}const ce={dataSource:_.dataSource,connectionId:_.connectionId,id:Dt(),title:j,tabTitle:j,description:B,preferences:{onClickFilter:[{columnIndex:0,expression:""}],...(z==="text"?{textVisualOptions:{richContent:Am()}}:{})},type:z,sql:"",data:[],mode:"explorer",...(C&&{customCardPreferences:{slotIndex:G}})};M(_,ce);}function P(_,z){return _.cards.length===1&&(z.displayTab===!0||z.displayTab===void 0)||_.activeCardId!==z.id&&(z.displayTab===!0||z.displayTab===void 0)?null:/* @__PURE__ */e("div",{onClick:()=>{const j=z.displayTab===void 0?!1:!z.displayTab;h({...z,displayTab:j}),u({...z,displayTab:j});},children:z.displayTab===!0||z.displayTab===void 0?/* @__PURE__ */e(Pa,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"}):/* @__PURE__ */e(xs,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})});}return/* @__PURE__ */e(At,{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)=>{var ue,X;const j=C?St(_,z):-1,B=C&&(ue=f==null?void 0:f.slots)!=null&&ue.length&&j>=0?Yn(f.slots,j):null,G=B?(Array.isArray(B.expectedType)?B.expectedType[0]:B.expectedType)||"table":_.type,ce=C&&((X=f==null?void 0:f.slots)==null?void 0:X.length)&&f.slots.every(Y=>typeof Y.position=="number"||typeof Y.position=="string"&&!Y.position.includes("+"));return/* @__PURE__ */n(Ye,{draggable:!C&&!d,onDragStart:C||d?void 0:Y=>V(Y,z),onDragOver:C||d?void 0:$,onDrop:C||d?void 0:Y=>E(Y,z),className:H("inline-flex h-6 shrink-0 items-center gap-1.5 rounded-[5px] border px-2 text-[12px] font-normal text-muted-foreground transition-colors","mb-0 border-transparent pb-0","hover:bg-muted/40 hover:text-foreground","data-[state=active]:border-border data-[state=active]:bg-card data-[state=active]:text-foreground"),value:_.id,children:[C&&B?/* @__PURE__ */e(xt,{delayDuration:0,children:/* @__PURE__ */n(ht,{children:[/* @__PURE__ */e(pt,{asChild:!0,children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e("span",{className:"text-muted-foreground",children:Sl(G,"size-3.5")}),/* @__PURE__ */e("span",{children:B.label||`Tab ${j+1}`})]})}),/* @__PURE__ */e(ft,{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:B.label}),B.description&&/* @__PURE__ */e("p",{className:"whitespace-normal break-words text-xs text-muted-foreground",children:B.description}),/* @__PURE__ */n("div",{className:"flex items-center gap-2 pt-1",children:[B.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(B.expectedType)?B.expectedType.join(" / "):B.expectedType}),B.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(me,{children:[P(r,_),/* @__PURE__ */e(Dd,{enabled:r.activeCardId===_.id,text:_.tabTitle||_.title,onSave:Y=>{h({...o,tabTitle:Y}),u({...o,tabTitle:Y});},children:_.tabTitle||_.title},_.id)]}),!d&&r.activeCardId===_.id&&!ce&&/* @__PURE__ */e(Ed,{className:"h-3 w-3 text-muted-foreground hover:text-foreground",onClick:Y=>{Y.stopPropagation(),I();}}),!d&&r.activeCardId===_.id&&(O&&(s==null?void 0:s.id)===_.id?r.cards.length>1:F)&&/* @__PURE__ */e(it,{className:"h-3 w-3 text-muted-foreground hover:text-foreground",onClick:()=>T(_.id)})]},_.id);}),!d&&/* @__PURE__ */e(Xe,{tooltip:"Add Card",className:"h-6 w-6 rounded-[5px] p-0 text-muted-foreground hover:bg-muted hover:text-foreground",onClick:()=>q(o),disabled:!g,children:/* @__PURE__ */e(ga,{className:"h-3 w-3"})}),C&&/* @__PURE__ */n(zi,{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(xs,{className:"h-3 w-3"}):/* @__PURE__ */e(Pa,{className:"h-3 w-3"}),/* @__PURE__ */e("span",{children:"Preview"})]})]})});}function rr({renderCardOverride:t,alwaysRenderOverride:a=!1}={}){var qe,We,ke,ve,de,Be,W,Fe;const s=Ll(),r=D(oe=>oe.frame),o=D(oe=>oe.card),[c,d]=U(!1),l=Z(()=>Ut(r,o),[r,o]),i=D(oe=>oe.isSqlRunning);D(oe=>oe.isDevMode);const{switchCardTab:h,resetAllColumnSettings:u}=xe(),m=Object.keys(((We=(qe=o.preferences)==null?void 0:qe.tablePrefs)==null?void 0:We.columnSettingsMap)??{}).length>0||Object.keys(((ke=o.preferences)==null?void 0:ke.sqlColumns)??{}).length>0,[p,f]=U({}),[w,C]=U(()=>/* @__PURE__ */new Set()),{authToken:y}=It(),b=Em(y==null?void 0:y.accessToken),{compiledAppearance:v}=fp(),N=Z(()=>vd(v),[v]),{getCard:g,manifest:F,isLoading:O}=Kt(((ve=l==null?void 0:l.customCardPreferences)==null?void 0:ve.url)||""),V=(de=l==null?void 0:l.customCardPreferences)==null?void 0:de.componentName,$=V?g(V):null,E=(Be=F==null?void 0:F.visuals)==null?void 0:Be.find(oe=>oe.name===V),T=Ht(l,E),M=c&&T==="multiple"&&!!l,I=Z(()=>ba({frame:r,configCard:l,isMultiInputVisual:!0}).map(Ce=>(Ce==null?void 0:Ce.id)===o.id?o:Ce),[r,l,o]),q=Z(()=>no(I),[I]),P=Z(()=>{const oe=I.findIndex(Ce=>(Ce==null?void 0:Ce.id)===o.id);return oe<0?-1:St(o,oe);},[I,o]),x=Z(()=>!l||T!=="multiple"||P<0?o.type:Jt(o,P,E==null?void 0:E.slots)??o.type,[l,T,P,o,E==null?void 0:E.slots]),R=Z(()=>M?{...o,connectionId:void 0,dataSource:void 0,sql:"",python:"",config:void 0,queryConfig:void 0}:x!==o.type?{...o,type:x}:o,[o,x,M]),{data:S,dataUpdatedAt:k,isLoading:L,isFetching:_,isError:z,errorMessage:j,errorSql:B,queryKey:G}=nt(R),ce=Ha(o,S),ue=JSON.stringify(G),{handleOpenInEditor:X}=Go(B||o.sql||o.python),Y=o.type==="text"&&((Fe=(W=o.preferences)==null?void 0:W.textVisualOptions)==null?void 0:Fe.isDynamicText)===!0&&!!j,fe=Je((oe,Ce)=>{const ct=Im(Ce);f(tt=>({...tt,[oe]:ct}));},[]),he=Je((oe,Ce)=>{C(ct=>{const tt=new Set(ct);return Ce?tt.add(oe):tt.delete(oe),tt;});},[]),re=w.size>0,se=Z(()=>q.map((oe,Ce)=>Jt(oe,Ce,E==null?void 0:E.slots)),[q,E==null?void 0:E.slots]),ge=Z(()=>yd(Nd({slotOrderedCards:q,multiInputData:p,valueFormatPreferences:s})),[p,q,s]),be=Cd(),Ie=ye(oe=>oe.dashboard),Ve=ye(oe=>oe.dashboardInputValues),et=ye(oe=>oe.adHocFilterValues),pe=ye(oe=>{var Ce;return((Ce=oe.reportContext)==null?void 0:Ce.calendar)??null;}),we=ye(oe=>oe.selectedSheetId),Ee=D(oe=>oe.inlineFilterValuesMap[(l==null?void 0:l.id)||""]),rt=D(oe=>oe.actions.setCardInlineFilterValue),Ue=D(oe=>oe.actions.removeCardInlineFilterValue),He=Z(()=>l?wd({card:l,sheetId:we||"",inlineFilterValues:Ee,setInlineFilterValue:oe=>rt(l.id,oe),removeInlineFilterValue:oe=>Ue(l.id,oe)}):[],[l,we,Ee,rt,Ue]),{filterInputs:st,filters:le,filterValues:Se}=Z(()=>l?Sd({dashboard:Ie,card:l,sheetId:we,dashboardInputValues:Ve,adHocFilterValues:et,transientContexts:be,calendar:pe}):{filterInputs:[],filters:[],filterValues:[]},[et,l,Ve,pe,Ie,we,be]);function Ke(oe){h(oe);}function Ge(){return O?/* @__PURE__ */e("div",{className:"flex h-full items-center justify-center",children:/* @__PURE__ */e(Ct,{size:"md",color:"muted","aria-label":"Loading manifest"})}):$?/* @__PURE__ */n("div",{className:"relative flex h-full flex-col pl-2 pr-4",children:[I.map((Ce,ct)=>{if(!Ce)return null;const tt=St(Ce,ct),Na=Jt(Ce,tt,E==null?void 0:E.slots);return/* @__PURE__ */e(Id,{onLoadingStatus:he,onDataChange:fe,card:Ce,effectiveCardType:Na},`${Ce.id}-${tt}`);}),re&&/* @__PURE__ */e("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-background/50",children:/* @__PURE__ */e(Ct,{size:"md",color:"muted","aria-label":"Loading preview"})}),/* @__PURE__ */e("div",{className:H("flex h-full min-h-0 flex-1 flex-col gap-2",re&&"opacity-50"),children:/* @__PURE__ */e(tc,{fallback:/* @__PURE__ */e("div",{className:"flex h-full items-center justify-center",children:/* @__PURE__ */e(Ct,{size:"md",color:"muted"})}),children:/* @__PURE__ */e($,{editing:!0,...Fd({configCard:l,slotOrderedCards:q,slotTypes:se,multiInputData:p,params:b,theme:N,filterInputs:st,filters:le,filterValues:[...(Se||[]),...(Ee||[])],inlineFilters:He,formatTemporalBucketValue:ge})})})})]}):/* @__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 $e(){return M?Ge():t&&(a||!L&&!_&&!z&&!j)?t({card:o,data:S,isLoading:L,isFetching:_,isError:z}):o.type==="kpi"?L||_?/* @__PURE__ */e("div",{className:"z-50 flex h-full items-center justify-center",children:/* @__PURE__ */e(Ct,{size:"md",color:"muted","aria-label":"Loading data"})}):j?/* @__PURE__ */e(_f,{errorMessage:j,errorSql:B||o.sql||o.python,onOpenInEditor:X}):/* @__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(Td,{card:ce,data:S==null?void 0:S.records,isPending:L||_,isError:z,metadata:S==null?void 0:S.metadata})}),Nl(o)&&/* @__PURE__ */e(Cl,{card:ce,mode:"editor",records:S==null?void 0:S.records})]})}):o.type==="text"?L||_?/* @__PURE__ */e("div",{className:"z-50 flex h-full items-center justify-center",children:/* @__PURE__ */e(Ct,{size:"md",color:"muted","aria-label":"Loading data"})}):Y?/* @__PURE__ */e("div",{className:"flex h-full min-h-0 flex-col overflow-auto px-4 py-0",children:/* @__PURE__ */e(Rr,{error:j,errorSql:B||o.sql||o.python,onOpenInEditor:X,showFeedbackButton:!1})}):/* @__PURE__ */e("div",{className:"flex h-full min-h-0 flex-col px-4 py-4",children:/* @__PURE__ */e(kd,{isLoading:i,card:o,data:S==null?void 0:S.records})}):/* @__PURE__ */e(Ga,{fallbackRender:oe=>/* @__PURE__ */e(fr,{...oe,onResetColumnSettings:m?u:void 0}),resetKeys:[ue,k,_],children:/* @__PURE__ */e(Yo,{className:"grow border-none shadow-none"})});}return/* @__PURE__ */n(Mt,{onValueChange:Ke,value:r.activeCardId,className:"flex min-h-0 flex-1 flex-col",children:[M?/* @__PURE__ */e("div",{className:"mt-0 min-h-0 flex-1 overflow-hidden",children:$e()}):r.cards.map(oe=>/* @__PURE__ */e(mt,{className:"mt-0 min-h-0 flex-1 overflow-hidden focus-visible:ring-0 focus-visible:ring-offset-0",value:oe.id,children:$e()},oe.id)),/* @__PURE__ */e(Bf,{isPreviewMode:M,onPreviewToggle:d,configCard:l})]});}function Zo({sql:t,debugPayloads:a,variant:s="panel",className:r}){const[o,c]=U(!1),d=s==="popover",l=D(w=>w.isDevMode),i=D(w=>w.card.type),{switchEditorMode:h,setRunSql:u}=xe(),m=!d&&!l&&!!a,p=m&&o,f=()=>{h("dev",{sqlToLoad:t}),setTimeout(()=>{u(!0);},100);};return/* @__PURE__ */n(Bo,{className:H("overflow-hidden",d&&"pt-0",r),children:[/* @__PURE__ */e(Uo,{sql:t,label:d?"Executed SQL":"Governed query",headerClassName:d?"border-b border-border/60 py-2":void 0,labelClassName:d?"font-medium text-foreground":void 0,ariaLabel:"Executed SQL",copyAriaLabel:"Copy governed query",headerActions:l?void 0:/* @__PURE__ */n(me,{children:[Sr(i)&&/* @__PURE__ */e(ie,{onClick:f,variant:"outline",size:"xs",className:_a,children:"Open in SQL editor"}),m&&/* @__PURE__ */e($o,{isOpen:o,onClick:()=>c(w=>!w)})]}),className:H("min-h-0",!d&&(p?"max-h-[40%] shrink-0":"flex-1")),bodyClassName:d?"max-h-[min(420px,calc(var(--radix-hover-card-content-available-height,100vh)-3rem))]":"flex-1"}),p&&a&&/* @__PURE__ */e(qo,{payloads:a,onClose:()=>c(!1),className:"mt-3 flex-1"})]});}function Dn({children:t,visualAsideControl:a,mode:s="both"}){const r=za(),o=D(se=>se.frame),c=D(se=>se.card),d=D(se=>se.isDevMode),l=D(se=>se.editorContext),i=(l==null?void 0:l.type)==="documentSection",h=ye(se=>se.isVisualEditing),u=ye(se=>{var ge,be;return(be=(ge=se.dashboard)==null?void 0:ge.exportDefaults)==null?void 0:be.csvEncoding;}),m=D(se=>se.actions.setRunSql),p=Ze(),f=p==="table"||p==="detailTable"||p==="matrixTable",C=Tr(p)&&!!(a!=null&&a.onOpen),y=Pr(),b=Z(()=>p!==c.type?{...c,type:p}:c,[c,p]),{data:v,isLoading:N,isFetching:g,errorMessage:F,refetch:O,queryKey:V,pagination:$,isCurrentQueryResult:E}=nt(b),T=Ae(V);T.current=V;const M=Z(()=>(v==null?void 0:v.records)||[],[v==null?void 0:v.records]),{cardFilterValues:I}=Md((c==null?void 0:c.id)??""),[q,P]=U(!1),x=_l(c),[R,S]=U();Ne(()=>{g||P(!1);},[g]);const k=()=>{var se;if(x){(se=x.refresh)==null||se.call(x);return;}if(P(!0),d){ol({queryClient:r,readQueryKey:()=>T.current,setRunSql:m});return;}O();},L=Array.isArray(v==null?void 0:v.records)?v.records:[],_=L.length>0;function z(){var ge;if(!_)return;const se=JSON.stringify(L,null,2);typeof navigator>"u"||!((ge=navigator.clipboard)!=null&&ge.writeText)||navigator.clipboard.writeText(se).catch(be=>{console.error("Failed to copy JSON",be);});}function j(){if(!_)return;const se=JSON.stringify(L,null,2),ge=new Blob([se],{type:"application/json"}),be=URL.createObjectURL(ge),Ie=document.createElement("a");Ie.href=be,Ie.download=`${c.title}.json`,Ie.click();}function B(){_&&Ad(Pd(Yh({records:L,encoding:pp({dashboardDefault:u})}),c.title||"export"));}if(!c)return/* @__PURE__ */e(me,{children:"No Active Card"});const G=s==="both"||s==="toolbar",ce=s==="both"||s==="canvas",ue=s==="toolbar",X=!N&&!g&&!F&&v!=null&&v.sql?/* @__PURE__ */e("div",{className:"inline-flex shrink-0 items-center text-[11px] text-muted-foreground",children:/* @__PURE__ */n(Qt,{openDelay:200,children:[/* @__PURE__ */e(Yt,{asChild:!0,children:/* @__PURE__ */e("button",{type:"button",className:"cursor-pointer text-[11px] transition-colors hover:text-foreground",children:"Executed SQL"})}),/* @__PURE__ */e(Wt,{align:"end",collisionPadding:16,className:"w-[500px] overflow-hidden p-0",children:/* @__PURE__ */e(Zo,{sql:v.sql,variant:"popover"})})]})}):null,Y=typeof(v==null?void 0:v.output)=="string"?v.output.trim():"",fe=ue&&!N&&!g&&!F&&Y?/* @__PURE__ */n(Qt,{openDelay:200,children:[/* @__PURE__ */e(Yt,{asChild:!0,children:/* @__PURE__ */e("button",{type:"button",className:"cursor-pointer text-[11px] transition-colors hover:text-foreground",children:"Python output"})}),/* @__PURE__ */n(Wt,{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:Y})]})]}):null,he=($==null?void 0:$.totalCount)??M.length,re=ue&&!N&&!g&&!F&&Array.isArray(v==null?void 0:v.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:[E?null:"Last run: ",he.toLocaleString()," ",he===1?"row":"rows"]}),X?/* @__PURE__ */n(me,{children:[/* @__PURE__ */e("span",{"aria-hidden":!0,className:"text-border",children:"·"}),X]}):null,fe?/* @__PURE__ */n(me,{children:[/* @__PURE__ */e("span",{"aria-hidden":!0,className:"text-border",children:"·"}),fe]}):null]}):null;return/* @__PURE__ */n("div",{className:H("relative isolate flex flex-col",ue?"pointer-events-none w-full min-w-0":H("h-full",!f&&"pt-2")),children:[G&&/* @__PURE__ */n("div",{className:H("z-10 mb-0 flex items-center",ue?"pointer-events-none relative h-10 min-w-0 gap-3 px-4":"min-h-10 gap-2 px-4"),children:[ue?/* @__PURE__ */n("div",{className:"pointer-events-auto flex min-w-0 items-center gap-3",children:[!i&&/* @__PURE__ */e(nr,{selectedChart:c.type,onChartChange:y,compactMore:!0,responsiveCompact:!0}),re]}):/* @__PURE__ */e("div",{className:"flex grow items-center gap-4",children:/* @__PURE__ */e("div",{className:"flex items-center gap-3",children:!i&&/* @__PURE__ */e(nr,{selectedChart:c.type,onChartChange:y,compactMore:!0})})}),/* @__PURE__ */n("div",{className:H("flex items-center text-muted-foreground",ue?"pointer-events-auto ml-auto gap-1.5":"gap-2"),children:[t,ue?null:X,I&&I.length>0&&/* @__PURE__ */n(Qt,{openDelay:200,children:[/* @__PURE__ */e(Yt,{asChild:!0,children:/* @__PURE__ */n(ie,{variant:"outline",size:"xs",className:"h-7 gap-1.5 px-2",children:[/* @__PURE__ */e(Zt,{className:"h-3.5 w-3.5",strokeWidth:1.75}),/* @__PURE__ */e(Al,{variant:"secondary",className:"h-4 min-w-4 rounded-[4px] px-1 text-[10px] font-medium",children:I.length})]})}),/* @__PURE__ */n(Wt,{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(Bt,{value:JSON.stringify(I,null,2),onValueChange:()=>{},language:"json",readOnly:!0,embedded:!0,wrapLines:!0,dense:!0,hideLineNumbers:!0,ariaLabel:"Active dashboard filters JSON"})})]})]}),/* @__PURE__ */e("div",{className:ue?"hidden @[820px]:flex":"",children:/* @__PURE__ */e(Xo,{showInlineFilters:!1,showControls:!1,showDisplayOptions:!1})}),(a==null?void 0:a.show)&&/* @__PURE__ */n(ie,{type:"button",variant:"ghost",size:"xs","aria-pressed":a.isOpen,onClick:a.onToggle,className:H("h-7 shrink-0 gap-1.5 text-[12px]",ue?"w-7 px-0 @[760px]:w-auto @[760px]:px-2":"px-2",a.isOpen&&"bg-accent text-accent-foreground"),children:[/* @__PURE__ */e(en,{className:"h-3.5 w-3.5",strokeWidth:1.75}),/* @__PURE__ */e("span",{className:ue?"hidden @[760px]:inline":"",children:"Settings"})]}),!ue&&/* @__PURE__ */e(Xe,{tooltip:"Refresh",disabled:N||g,className:"h-7 w-7 px-0",onClick:k,children:/* @__PURE__ */e(Xn,{className:H("h-3.5 w-3.5",{"animate-spin":(x==null?void 0:x.isFetching)??q})})}),/* @__PURE__ */n(Wa,{modal:!1,children:[/* @__PURE__ */e(Ja,{asChild:!0,children:/* @__PURE__ */e(Xe,{tooltip:"More Options",className:"h-7 w-7 px-0","aria-label":"More options",children:/* @__PURE__ */e(Bl,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(Xa,{align:"end",collisionPadding:8,className:"max-h-[var(--radix-dropdown-menu-content-available-height)] w-56 overflow-y-auto overscroll-contain",children:[ue&&/* @__PURE__ */n(me,{children:[/* @__PURE__ */n(ot,{disabled:N||g,onSelect:k,children:[/* @__PURE__ */e(Xn,{className:"h-3.5 w-3.5"}),"Refresh result"]}),/* @__PURE__ */e(bs,{})]}),/* @__PURE__ */e(vs,{children:"Export"}),x?/* @__PURE__ */n(ot,{disabled:N||g||!x.hasDelivery,title:x.hasDelivery?void 0:"Available once the preview has loaded.",onSelect:()=>S(x.readDelivery()),className:"gap-2 text-[13px]",children:[/* @__PURE__ */e(Un,{className:"h-3.5 w-3.5"}),"Download"]}):/* @__PURE__ */n(me,{children:[/* @__PURE__ */n(ot,{disabled:!_,onSelect:B,className:"gap-2 text-[13px]",children:[/* @__PURE__ */e(Un,{className:"h-3.5 w-3.5"}),"Download CSV"]}),/* @__PURE__ */n(ot,{disabled:!_,onSelect:j,className:"gap-2 text-[13px]",children:[/* @__PURE__ */e(Np,{className:"h-3.5 w-3.5"}),"Download JSON"]}),/* @__PURE__ */n(ot,{disabled:!_,onSelect:z,className:"gap-2 text-[13px]",children:[/* @__PURE__ */e(cr,{className:"h-3.5 w-3.5"}),"Copy JSON"]})]}),/* @__PURE__ */e(bs,{}),/* @__PURE__ */e(vs,{children:"Customize"}),!["table","detailTable","custom"].includes(c.type)&&h&&/* @__PURE__ */e(bf,{triggerVariant:"menu",className:"w-full"}),/* @__PURE__ */e(Br,{triggerVariant:"menu",className:"w-full"}),/* @__PURE__ */e(Vr,{triggerVariant:"menu",className:"w-full"}),/* @__PURE__ */e(_r,{triggerVariant:"menu",className:"w-full"}),C&&/* @__PURE__ */n(ot,{onSelect:()=>{var se;return(se=a==null?void 0:a.onOpen)==null?void 0:se.call(a,"style");},className:"gap-2 text-[13px]",children:[/* @__PURE__ */e(gp,{className:"h-3.5 w-3.5"}),"Table settings"]})]})]}),R&&/* @__PURE__ */e(Vl,{isOpen:!0,onClose:()=>S(void 0),card:c,frame:o,matrix:R})]})]}),ce&&/* @__PURE__ */e(rr,{})]});}function Vf({onToggleEditor:t,children:a}){return/* @__PURE__ */n("div",{className:"relative isolate shrink-0 border-t border-border bg-muted/30 @container",children:[/* @__PURE__ */e(ll,{title:"Drag to resize. Double-click to collapse the editor.",onDoubleClick:t,className:"group absolute inset-0 cursor-row-resize outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring",children:/* @__PURE__ */e("span",{"aria-hidden":!0,className:"pointer-events-none absolute left-1/2 top-1 h-[3px] w-8 -translate-x-1/2 rounded-[2px] bg-transparent transition-colors group-data-[resize-handle-state=drag]:bg-foreground/50 group-data-[resize-handle-state=hover]:bg-foreground/20"})}),a]});}function at({value:t,onCommit:a,type:s="text",placeholder:r,className:o}){const[c,d]=U(t),l=Ae(!1);return Ne(()=>{d(t);},[t]),/* @__PURE__ */e(_e,{type:s,placeholder:r,value:c,onChange:u=>d(u.target.value),onBlur:()=>{if(l.current){l.current=!1;return;}c!==t&&a(c);},onKeyDown:u=>{if(u.key==="Enter"){u.currentTarget.blur();return;}u.key==="Escape"&&(l.current=!0,d(t),u.currentTarget.blur());},className:o});}function Ea({defaultValue:t,label:a,options:s,value:r,onValueChange:o,className:c,icon:d,showPlaceholderLabel:l=!0}){return/* @__PURE__ */n(ee,{defaultValue:t,value:r,onValueChange:o,children:[/* @__PURE__ */e(te,{className:H("w-full focus:ring-0 focus:ring-offset-0",c),children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[d&&/* @__PURE__ */e("span",{children:d}),l&&/* @__PURE__ */e(ae,{placeholder:a})]})}),/* @__PURE__ */e(ne,{children:/* @__PURE__ */n(Gn,{children:[/* @__PURE__ */e(Wl,{children:a}),s.map(i=>/* @__PURE__ */e(K,{value:i.value,children:i.label},i.value))]})})]});}function Kf(t,a){return Yn(t,a)||null;}function ia(t){if(typeof t=="number")return`Tab ${t+1}`;const a=t.match(/^(\d+)-(\d+)$/);if(a){const[,r,o]=a;return`Tabs ${Number(r)+1}-${Number(o)+1}`;}const s=t.match(/^(\d+)\+$/);return s?`Tabs ${Number(s[1])+1}+`:`Tab ${t}`;}function $f(t){return t?Array.isArray(t)?t:[t]:[];}function En(t){var r,o;if(!t)return!1;if(t.type==="text")return!!((r=t.description)!=null&&r.trim());const a=!!((o=t.sql)!=null&&o.trim()),s=va(t.config);return a||s;}function qf({slots:t,cards:a,minInputs:s}){const r=[],o=a.filter(Boolean).length;return s&&o<s&&r.push({type:"too-few-inputs",message:`This visual requires at least ${s} tab${s===1?"":"s"}.`}),!t||t.length===0||(t.forEach(c=>{if(!c.required)return;if(typeof c.position=="number"){const i=a[c.position];En(i)||r.push({type:"missing-required",message:`${ia(c.position)} ("${c.label}") is required but has no data configured.`});return;}const d=c.position.match(/^(\d+)-(\d+)$/);if(d){const[,i,h]=d.map(Number);for(let u=i;u<=h;u+=1){const m=a[u];if(!En(m)){r.push({type:"missing-required",message:`${ia(u)} ("${c.label}") is required but has no data configured.`});break;}}return;}const l=c.position.match(/^(\d+)\+$/);if(l){const i=Number(l[1]);if(a.length<=i){r.push({type:"missing-required",message:`${ia(i)} ("${c.label}") is required but has no data configured.`});return;}for(let h=i;h<a.length;h+=1){const u=a[h];if(!En(u)){r.push({type:"missing-required",message:`${ia(h)} ("${c.label}") is required but has no data configured.`});break;}}}}),a.forEach((c,d)=>{if(!c)return;const l=Kf(t,d);if(!l||!l.expectedType)return;const i=$f(l.expectedType);i.length!==0&&(i.includes(c.type)||r.push({type:"wrong-type",message:`${ia(d)} ("${l.label}") expects ${i.join(", ")}, but is configured as ${c.type}.`}));})),r;}const zf={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(me,{children:t})};function ei(){var I,q,P;const t=D(x=>x.card.customCardPreferences),{data:a}=Rd(),s=(a==null?void 0:a.plugins)||[],r=D(x=>x.card),o=D(x=>x.frame),{setCustomCardPreferences:c}=xe(),d=Z(()=>Ut(o,r),[o,r]),l=d==null?void 0:d.customCardPreferences,{components:i,manifest:h}=Kt((l==null?void 0:l.url)||(t==null?void 0:t.url)||""),u=(I=h==null?void 0:h.visuals)==null?void 0:I.find(x=>x.name===((l==null?void 0:l.componentName)||(t==null?void 0:t.componentName))),p=Ht(d||r,u)==="multiple",f=!!d&&d.id===r.id,w=(u==null?void 0:u.minInputs)??((q=d==null?void 0:d.customCardPreferences)==null?void 0:q.minInputs),C=(u==null?void 0:u.maxInputs)??((P=d==null?void 0:d.customCardPreferences)==null?void 0:P.maxInputs),y=Z(()=>ba({frame:o,configCard:d||r,isMultiInputVisual:p}),[o,d,r,p]),b=Z(()=>no(y),[y]),v=Z(()=>b.map((x,R)=>{if(!x)return null;const S=St(x,R),k=Jt(x,S,u==null?void 0:u.slots);return{...x,type:k??x.type};}),[b,u==null?void 0:u.slots]),N=Z(()=>qf({slots:u==null?void 0:u.slots,cards:v,minInputs:w}),[u==null?void 0:u.slots,v,w]),g=Z(()=>{const x=y.findIndex(R=>(R==null?void 0:R.id)===r.id);return x<0?-1:St(r,x);},[y,r]);function F(x){if(typeof x=="number")return`Tab ${x+1}`;const R=x.match(/^(\d+)-(\d+)$/);if(R){const[,k,L]=R;return`Tabs ${Number(k)+1}-${Number(L)+1}`;}const S=x.match(/^(\d+)\+$/);return S?`Tabs ${Number(S[1])+1}+`:`Tab ${x}`;}function O(x){return x?(Array.isArray(x)?x:[x]).join(", "):null;}function V(x,R,S=[],k="",L,_,z){const j=$({key:R,defaultValue:k,settingsValue:_,sourceCard:z});return x==="input"?/* @__PURE__ */e(at,{className:`h-8 w-full ${Pm}`,value:String(j??""),onCommit:B=>{E({key:R,value:B,settingsField:L,settingsValue:_,sourceCard:z});}},R):x==="select"?/* @__PURE__ */e(Ea,{className:"h-8 w-full",label:"",options:S,value:String(j!==void 0?j:k??""),onValueChange:B=>{E({key:R,value:B,settingsField:L,settingsValue:_,sourceCard:z});}}):null;}function $({key:x,defaultValue:R,settingsValue:S,sourceCard:k}){const L=S==null?void 0:S[x];return L!==void 0?L:x==="title"&&(k==null?void 0:k.title)!==void 0?k.title:x==="description"&&(k==null?void 0:k.description)!==void 0?k.description:R;}function E({key:x,value:R,settingsField:S,settingsValue:k,sourceCard:L}){const _={...(k||{})},z=x==="title"&&(L==null?void 0:L.title)!==void 0,j=x==="description"&&(L==null?void 0:L.description)!==void 0;z&&R===String((L==null?void 0:L.title)??"")||j&&R===String((L==null?void 0:L.description)??"")?delete _[x]:_[x]=R,c({...(t||{}),[S]:_});}function T({settingsSchema:x,settingsField:R,settingsValue:S,sourceCard:k,headerLabel:L}){const _=Object.entries(x||{});return/* @__PURE__ */n("div",{className:"space-y-3",children:[L&&/* @__PURE__ */e(A,{children:L}),_.map(([z,j])=>{var B;return/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{children:j.title}),((B=j.docs)==null?void 0:B.description)&&/* @__PURE__ */e(xt,{delayDuration:0,children:/* @__PURE__ */n(ht,{children:[/* @__PURE__ */e(pt,{asChild:!0,children:/* @__PURE__ */e(Vt,{className:"h-3.5 w-3.5 cursor-help text-muted-foreground"})}),/* @__PURE__ */e(ft,{side:"right",className:"max-w-xs",children:/* @__PURE__ */e("p",{className:"text-xs",children:j.docs.description})})]})})]}),V(j.ui,z,j.options,j.defaultValue,R,S,k)]},z);})]});}function M(){return/* @__PURE__ */n(me,{children:[p&&/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */e(A,{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((x,R)=>/* @__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:F(x.position)}),/* @__PURE__ */e("span",{className:"text-muted-foreground",children:"•"}),/* @__PURE__ */e("span",{className:"font-medium",children:x.label})]}),x.description&&/* @__PURE__ */e("p",{className:"text-muted-foreground",children:x.description}),/* @__PURE__ */n("div",{className:"flex flex-wrap gap-2 text-muted-foreground",children:[O(x.expectedType)&&/* @__PURE__ */n("span",{children:["Expected: ",O(x.expectedType)]}),x.required&&/* @__PURE__ */e("span",{children:"Required"})]})]},`${x.label}-${R}`))}):/* @__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."}),(w||C)&&/* @__PURE__ */n("p",{children:[w?`Min ${w} tabs`:"",w&&C?" • ":"",C?`Max ${C} tabs`:""]})]})})]}),p&&N.length>0&&/* @__PURE__ */e(ji,{className:"mt-3 border-yellow-500/40 bg-yellow-500/10 text-yellow-900 dark:text-yellow-100",children:/* @__PURE__ */e(Ui,{children:/* @__PURE__ */e("ul",{className:"list-disc space-y-1 pl-4 text-xs",children:N.map((x,R)=>/* @__PURE__ */e("li",{children:x.message},`${x.type}-${R}`))})})}),u&&!p&&u.settings&&/* @__PURE__ */e("div",{className:"space-y-3",children:/* @__PURE__ */e("div",{className:"px-2",children:T({settingsSchema:u.settings,settingsField:"settings",settingsValue:t==null?void 0:t.settings,sourceCard:r})})}),u&&p&&(u.settings||u.slotSettings)&&/* @__PURE__ */n("div",{className:"mt-4 space-y-4",children:[f&&u.settings&&/* @__PURE__ */e("div",{className:"px-2",children:T({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:T({settingsSchema:u.slotSettings,settingsField:"slotSettings",settingsValue:t==null?void 0:t.slotSettings,sourceCard:r,headerLabel:(()=>{const x=r.tabTitle||r.title,R=g>=0?g:0,S=f?"Slot 0":`Slot ${R}`;return x?`${S}: ${x} Settings`:`${S} Settings`;})()})})]})]});}return/* @__PURE__ */n($a,{type:"multiple",defaultValue:["component-settings"],className:"",children:[/* @__PURE__ */n(Pe,{value:"plugin-settings",children:[/* @__PURE__ */e(Re,{children:"Plugin"}),/* @__PURE__ */e(Oe,{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:[(!p||f)&&/* @__PURE__ */e(Ea,{icon:/* @__PURE__ */e(Mo,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Plugin",options:s,value:(l==null?void 0:l.url)||"",onValueChange:x=>c({...(t||{url:"",componentName:""}),url:x})}),p&&!f&&/* @__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&&(!p||f)&&/* @__PURE__ */e(me,{children:i&&/* @__PURE__ */e(Ea,{icon:/* @__PURE__ */e(yp,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(i==null?void 0:i.map(x=>({value:x.name,label:x.name})))||[],value:t.componentName||"",onValueChange:x=>{var k;const R=(k=h==null?void 0:h.visuals)==null?void 0:k.find(L=>L.name===x),S=i==null?void 0:i.find(L=>L.name===x);c({...t,componentName:x,visualType:(R==null?void 0:R.visualType)||(S==null?void 0:S.type)||"single",minInputs:R==null?void 0:R.minInputs,maxInputs:R==null?void 0:R.maxInputs,pluginChartType:R==null?void 0:R.chartType});}})})]})})]}),((l==null?void 0:l.componentName)||(t==null?void 0:t.componentName))&&/* @__PURE__ */n(Pe,{className:"border-none",value:"component-settings",children:[/* @__PURE__ */e(Re,{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(Qt,{openDelay:0,closeDelay:100,children:[/* @__PURE__ */e(Yt,{asChild:!0,onClick:x=>x.stopPropagation(),children:/* @__PURE__ */e(Vt,{className:"h-3.5 w-3.5 cursor-help text-muted-foreground transition-colors hover:text-foreground"})}),/* @__PURE__ */e(Wt,{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(Od,{remarkPlugins:[Ld],components:zf,children:u.docs.dataSchema})})]}),(()=>{var R;const x=(R=u.docs)==null?void 0:R.useCases;return!x||x.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:x.map((S,k)=>/* @__PURE__ */n("li",{className:"flex items-start gap-2",children:[/* @__PURE__ */e("span",{className:"mt-1 text-primary",children:"•"}),/* @__PURE__ */e("span",{children:S})]},k))})]});})()]})})]})]})}),/* @__PURE__ */e(Oe,{children:M()})]})]});}function Va(t){return t==="currency"?2:t==="percent"?1:t==="scientific"?2:0;}function ti(t,a,s){if(!a||a==="auto")return{type:"auto"};if(a==="duration")return{type:"duration",multiplyBy:void 0,percentValueMode:void 0,durationInputUnit:t.durationInputUnit||"second",durationDisplayStyle:t.durationDisplayStyle||"compact",durationLargestUnit:t.durationLargestUnit||"day",durationSmallestUnit:t.durationSmallestUnit||"second",durationMaxUnits:t.durationMaxUnits};const r={...t,type:a,multiplyBy:a==="percent"||a===t.type?t.multiplyBy:void 0,percentValueMode:a==="percent"?t.percentValueMode:void 0,durationInputUnit:void 0,durationDisplayStyle:void 0,durationLargestUnit:void 0,durationSmallestUnit:void 0,durationMaxUnits:void 0};return a&&["number","currency","percent","scientific"].includes(a)&&t.decimalPlaces===void 0&&t.minimumFractionDigits===void 0&&t.maximumFractionDigits===void 0&&!(a==="currency"&&s!=null&&s.preserveSparseCurrency)?ai(r,Va(a)):r;}function jf(t,a){return{...t,decimalPlaces:void 0,minimumFractionDigits:a,maximumFractionDigits:a};}function js(t){const a=t.decimalPlaces;return{...t,currency:void 0,decimalPlaces:void 0,minimumFractionDigits:t.minimumFractionDigits??a,maximumFractionDigits:t.maximumFractionDigits??a};}function Uf(t,a){const s=t.type||"auto";return s==="auto"?t:s==="duration"?{type:"duration",prefix:t.prefix,suffix:t.suffix,negativeInParentheses:t.negativeInParentheses,durationInputUnit:t.durationInputUnit||"second",durationDisplayStyle:t.durationDisplayStyle||"compact",durationLargestUnit:t.durationLargestUnit||"day",durationSmallestUnit:t.durationSmallestUnit||"second",durationMaxUnits:t.durationMaxUnits}:ti(t,s,a);}function ai(t,a){return{...t,decimalPlaces:a,minimumFractionDigits:a,maximumFractionDigits:a};}const In="__report_default__",Hf=["auto","number","currency","percent","scientific","date","duration"];function ni(t,a){return Hf.filter(s=>s!=="auto"&&(!t||t.includes(s)||s===a));}const Us=[{value:"USD",label:"USD - US Dollar"},{value:"EUR",label:"EUR - Euro"},{value:"JPY",label:"JPY - Japanese Yen"},{value:"GBP",label:"GBP - British Pound"},{value:"CNY",label:"CNY - Chinese Yuan"},{value:"CHF",label:"CHF - Swiss Franc"},{value:"CAD",label:"CAD - Canadian Dollar"},{value:"AUD",label:"AUD - Australian Dollar"},{value:"HKD",label:"HKD - Hong Kong Dollar"},{value:"SGD",label:"SGD - Singapore Dollar"},{value:"NZD",label:"NZD - New Zealand Dollar"},{value:"SEK",label:"SEK - Swedish Krona"},{value:"NOK",label:"NOK - Norwegian Krone"},{value:"DKK",label:"DKK - Danish Krone"},{value:"KRW",label:"KRW - South Korean Won"},{value:"INR",label:"INR - Indian Rupee"},{value:"RUB",label:"RUB - Russian Ruble"},{value:"BRL",label:"BRL - Brazilian Real"},{value:"MXN",label:"MXN - Mexican Peso"},{value:"TRY",label:"TRY - Turkish Lira"},{value:"ZAR",label:"ZAR - South African Rand"},{value:"SAR",label:"SAR - Saudi Riyal"},{value:"AED",label:"AED - UAE Dirham"},{value:"ARS",label:"ARS - Argentine Peso"},{value:"CLP",label:"CLP - Chilean Peso"},{value:"COP",label:"COP - Colombian Peso"},{value:"THB",label:"THB - Thai Baht"},{value:"IDR",label:"IDR - Indonesian Rupiah"},{value:"MYR",label:"MYR - Malaysian Ringgit"},{value:"PHP",label:"PHP - Philippine Peso"},{value:"PLN",label:"PLN - Polish Zloty"},{value:"NGN",label:"NGN - Nigerian Naira"},{value:"KES",label:"KES - Kenyan Shilling"},{value:"GHS",label:"GHS - Ghanaian Cedi"},{value:"ZMW",label:"ZMW - Zambian Kwacha"},{value:"ZWL",label:"ZWL - Zimbabwean Dollar"},{value:"EGP",label:"EGP - Egyptian Pound"},{value:"MAD",label:"MAD - Moroccan Dirham"},{value:"UAH",label:"UAH - Ukrainian Hryvnia"},{value:"HUF",label:"HUF - Hungarian Forint"},{value:"CZK",label:"CZK - Czech Koruna"},{value:"RON",label:"RON - Romanian Leu"},{value:"PKR",label:"PKR - Pakistani Rupee"},{value:"BDT",label:"BDT - Bangladeshi Taka"},{value:"VND",label:"VND - Vietnamese Dong"},{value:"TWD",label:"TWD - New Taiwan Dollar"},{value:"ILS",label:"ILS - Israeli New Shekel"}],Fn=[{value:"millisecond",label:"Milliseconds"},{value:"second",label:"Seconds"},{value:"minute",label:"Minutes"},{value:"hour",label:"Hours"},{value:"day",label:"Days"}],Gf=[{value:"compact",label:"Compact (6min 32s)"},{value:"digital",label:"Digital (6:32)"},{value:"long",label:"Long (6 minutes 32 seconds)"}],Qf=t=>t.charAt(0).toUpperCase()+t.slice(1);function Yf(t,a){try{return qh(t,a).maximumFractionDigits??Va("currency");}catch{return Va("currency");}}function ya({formatOptions:t={},onFormatOptionsChange:a,showTitle:s=!0,title:r="NUMBER FORMAT",maxDecimalPlaces:o=10,reportDefaults:c,showAutoFormat:d=!0,drawnTypes:l}){var E;const i=t.type||"auto",h=Uf(t,{preserveSparseCurrency:!!c}),u=T=>{T.stopPropagation();},m=(T,M)=>{a({...h,[T]:M});},p=h.decimalPlaces??h.maximumFractionDigits??h.minimumFractionDigits,f=t.currency??(c==null?void 0:c.currency)??"USD",w=t.locale??(c==null?void 0:c.locale)??"en-US",C=i==="currency"?Yf(w,f):void 0,y=p??C??Va(i),b=i==="currency"&&h.decimalPlaces===void 0&&h.minimumFractionDigits===void 0&&h.maximumFractionDigits===void 0,[v,N]=U(()=>String(y)),[g,F]=U(()=>h.multiplyBy!==void 0?String(h.multiplyBy):""),O=T=>{const M=ti(t,T,{preserveSparseCurrency:!!c});a(c&&T==="currency"&&t.type!=="currency"?js(M):M);},V=T=>c&&i==="currency"?jf(h,T):ai(h,T),$=((E=Us.find(T=>T.value===(c==null?void 0:c.currency)))==null?void 0:E.label)??(c==null?void 0:c.currency);return Ne(()=>{N(String(y));},[y]),Ne(()=>{F(h.multiplyBy!==void 0?String(h.multiplyBy):"");},[h.multiplyBy]),/* @__PURE__ */n(me,{children:[/* @__PURE__ */n("div",{className:"space-y-2",children:[s&&/* @__PURE__ */e(A,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:r}),/* @__PURE__ */n(ee,{value:i,onValueChange:T=>O(T),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",onClick:u,onPointerDown:u,onKeyDown:u,children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:[...(d?["auto"]:[]),...ni(l,i)].map(T=>/* @__PURE__ */e(K,{value:T,className:"text-xs",children:T==="auto"?"Auto (Default)":Qf(T)},T))})]})]}),i!=="auto"&&/* @__PURE__ */n("div",{className:"space-y-2 border-l-2 border-muted pl-4",children:[["number","currency","percent","scientific"].includes(i)&&/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"w-20 text-xs text-muted-foreground",children:"Decimals"}),/* @__PURE__ */n("div",{className:"flex-1",children:[/* @__PURE__ */e(_e,{type:"text",inputMode:"numeric",min:"0",max:o,placeholder:"0",value:v,onClick:u,onPointerDown:u,onKeyDown:u,onChange:T=>{const M=T.target.value.replace(/[^\d]/g,"");N(M),M!==""&&a(V(Math.max(0,Math.min(o,parseInt(M,10)))));},onBlur:()=>{if(v!=="")return;const T=y;N(String(T)),a(V(T));},className:"h-8 text-xs"}),b&&/* @__PURE__ */e("p",{className:"mt-1 text-[10px] text-muted-foreground",children:"Currency default"})]})]}),i==="currency"&&/* @__PURE__ */e("div",{className:"space-y-1",children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"w-20 text-xs text-muted-foreground",children:"Currency"}),/* @__PURE__ */n(ee,{value:t.currency||(c?In:"USD"),onValueChange:T=>{if(T===In){a(js(h));return;}m("currency",T);},children:[/* @__PURE__ */e(te,{className:"h-8 flex-1 text-xs",onClick:u,onPointerDown:u,onKeyDown:u,children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */n(ne,{children:[c&&/* @__PURE__ */n(K,{value:In,className:"text-xs",children:["Report default — ",$]}),Us.map(T=>/* @__PURE__ */e(K,{value:T.value,className:"text-xs",children:T.label},T.value))]})]})]})}),["number","currency"].includes(i)&&/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Abbreviate (K, M, B)"}),/* @__PURE__ */e(De,{size:"sm",checked:t.useSuffix??!1,onClick:T=>T.stopPropagation(),onCheckedChange:T=>m("useSuffix",T)})]}),i==="number"&&/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"w-20 text-xs text-muted-foreground",children:"Prefix"}),/* @__PURE__ */e("div",{className:"flex-1",children:/* @__PURE__ */e(_e,{placeholder:"e.g., $",value:t.prefix||"",onClick:u,onPointerDown:u,onKeyDown:u,onChange:T=>m("prefix",T.target.value),className:"h-8 text-xs"})})]}),i==="number"&&/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"w-20 text-xs text-muted-foreground",children:"Suffix"}),/* @__PURE__ */e("div",{className:"flex-1",children:/* @__PURE__ */e(_e,{placeholder:"e.g., units",value:t.suffix||"",onClick:u,onPointerDown:u,onKeyDown:u,onChange:T=>m("suffix",T.target.value),className:"h-8 text-xs"})})]}),["number","currency"].includes(i)&&/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Negative in ()"}),/* @__PURE__ */e(De,{size:"sm",checked:t.negativeInParentheses??!1,onClick:T=>T.stopPropagation(),onCheckedChange:T=>m("negativeInParentheses",T)})]}),i==="percent"&&/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"w-20 text-xs text-muted-foreground",children:"Multiply By"}),/* @__PURE__ */e("div",{className:"flex-1",children:/* @__PURE__ */e(_e,{type:"text",inputMode:"decimal",placeholder:"100",value:g,onClick:u,onPointerDown:u,onKeyDown:u,onChange:T=>{const M=T.target.value.replace(/[^0-9.]/g,"");F(M),m("multiplyBy",M?parseFloat(M):void 0);},className:"h-8 text-xs"})})]}),i==="date"&&/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"w-20 text-xs text-muted-foreground",children:"Format"}),/* @__PURE__ */e("div",{className:"flex-1",children:/* @__PURE__ */e(_e,{type:"text",placeholder:"MM/DD/YYYY",value:t.dateFormat||"",onClick:u,onPointerDown:u,onKeyDown:u,onChange:T=>m("dateFormat",T.target.value),className:"h-8 text-xs"})})]}),i==="duration"&&/* @__PURE__ */n(me,{children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"w-20 text-xs text-muted-foreground",children:"Value Is"}),/* @__PURE__ */n(ee,{value:t.durationInputUnit||"second",onValueChange:T=>m("durationInputUnit",T),children:[/* @__PURE__ */e(te,{className:"h-8 flex-1 text-xs",onClick:u,onPointerDown:u,onKeyDown:u,children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:Fn.map(T=>/* @__PURE__ */e(K,{value:T.value,className:"text-xs",children:T.label},T.value))})]})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"w-20 text-xs text-muted-foreground",children:"Display"}),/* @__PURE__ */n(ee,{value:t.durationDisplayStyle||"compact",onValueChange:T=>m("durationDisplayStyle",T),children:[/* @__PURE__ */e(te,{className:"h-8 flex-1 text-xs",onClick:u,onPointerDown:u,onKeyDown:u,children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:Gf.map(T=>/* @__PURE__ */e(K,{value:T.value,className:"text-xs",children:T.label},T.value))})]})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"w-20 text-xs text-muted-foreground",children:"Smallest"}),/* @__PURE__ */n(ee,{value:t.durationSmallestUnit||"second",onValueChange:T=>m("durationSmallestUnit",T),children:[/* @__PURE__ */e(te,{className:"h-8 flex-1 text-xs",onClick:u,onPointerDown:u,onKeyDown:u,children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:Fn.map(T=>/* @__PURE__ */e(K,{value:T.value,className:"text-xs",children:T.label},T.value))})]})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"w-20 text-xs text-muted-foreground",children:"Largest"}),/* @__PURE__ */n(ee,{value:t.durationLargestUnit||"day",onValueChange:T=>m("durationLargestUnit",T),children:[/* @__PURE__ */e(te,{className:"h-8 flex-1 text-xs",onClick:u,onPointerDown:u,onKeyDown:u,children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:Fn.map(T=>/* @__PURE__ */e(K,{value:T.value,className:"text-xs",children:T.label},T.value))})]})]})]})]})]});}function Kr({cardId:t}){const a=D(r=>r.droppedConditionalRules);if(!a||a.cardId!==t||!a.rules.length)return null;const s=a.rules.map(r=>r.name||"An unnamed rule");return/* @__PURE__ */n("p",{role:"status",className:"text-xs text-muted-foreground",children:["Removed ",a.rules.length===1?"a rule":`${a.rules.length} rules`," whose column left the card: ",s.join(", "),"."]});}const Wf={type:"number",minimumFractionDigits:0,maximumFractionDigits:0};function Jf(t){var a;return No((a=t==null?void 0:t.sqlKpiValue)==null?void 0:a.format)||Wf;}function Hs(t,a){const s=a?Co(a):void 0,{format:r,...o}=t.sqlKpiValue??{},c=s?{...o,format:s}:o,{sqlKpiValue:d,...l}=t;return Object.keys(c).length?{...l,sqlKpiValue:c}:l;}function Xf(){var h,u;const t=D(m=>m.card),a=D(m=>m.actions.setCardPreferences),s=Kl()??Xt.locale,r=$l()??Xt.defaultCurrency,o=_d(t)==="config",c=Jf(t.preferences),d=!!((u=(h=t.preferences)==null?void 0:h.sqlKpiValue)!=null&&u.format),l=m=>{const p=D.getState().card.preferences??{};a(Hs(p,m));},i=m=>{const p=D.getState().card.preferences??{};a(Hs(p,m?c:void 0));};return o?/* @__PURE__ */e(Gs,{card:t}):/* @__PURE__ */n("div",{children:[/* @__PURE__ */n("div",{className:"mb-3 flex items-center gap-2",children:[/* @__PURE__ */e(_t,{id:"query-kpi-format-number",checked:d,onCheckedChange:m=>i(m===!0)}),/* @__PURE__ */e(A,{htmlFor:"query-kpi-format-number",className:"text-xs",children:"Format number"})]}),d&&/* @__PURE__ */n("div",{className:"flex flex-col gap-2",children:[/* @__PURE__ */e(ya,{formatOptions:c,onFormatOptionsChange:l,showTitle:!1,showAutoFormat:!1,reportDefaults:{currency:r,locale:s}}),/* @__PURE__ */e(em,{className:"my-3"})]}),/* @__PURE__ */e(Gs,{card:t})]});}function Gs({card:t}){const a=D(i=>i.actions.updateConditionalRules),{rules:s,onChange:r}=xr(t.id,kr(t),a),o=Rm(t),c=o==null?void 0:o.value,d=(o==null?void 0:o.source)==="config"?o.measure:void 0,l=c?[{value:Wn(c),label:d?d.label||d.alias||d.name:"Value"}]:[];return l.length?/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(Kr,{cardId:t.id}),/* @__PURE__ */e(br,{columnId:l[0].value,availableColumns:l,conditionalRules:s,onConditionalRulesChange:r,capabilities:{ruleKinds:["comparison"],automaticRanges:!1}})]}):null;}const Zf={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 ri(t){return Zf[t];}function eg({chartType:t,showDocsLink:a=!0}){const s=ri(t);return s?/* @__PURE__ */n("div",{className:"space-y-4",children:[/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e("h4",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Query Format"}),/* @__PURE__ */e("code",{className:"block rounded-md bg-muted/50 px-3 py-2 font-mono text-xs text-foreground",children:s.query})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e("h4",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Fields"}),/* @__PURE__ */e("div",{className:"rounded-md border",children:/* @__PURE__ */n("table",{className:"w-full text-xs",children:[/* @__PURE__ */e("thead",{children:/* @__PURE__ */n("tr",{className:"border-b bg-muted/50",children:[/* @__PURE__ */e("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Field"}),/* @__PURE__ */e("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Type"}),/* @__PURE__ */e("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Description"})]})}),/* @__PURE__ */e("tbody",{children:s.fields.map((r,o)=>/* @__PURE__ */n("tr",{className:o<s.fields.length-1?"border-b":"",children:[/* @__PURE__ */n("td",{className:"px-2.5 py-1.5 font-medium text-foreground",children:[r.name,r.optional&&/* @__PURE__ */e("span",{className:"ml-1 text-muted-foreground",children:"?"})]}),/* @__PURE__ */e("td",{className:"px-2.5 py-1.5 font-mono text-muted-foreground",children:r.type}),/* @__PURE__ */e("td",{className:"px-2.5 py-1.5 text-muted-foreground",children:r.description||"—"})]},r.name))})]})})]}),/* @__PURE__ */e("p",{className:"text-xs leading-relaxed text-muted-foreground",children:s.description}),a&&s.docsUrl&&/* @__PURE__ */n("a",{href:s.docsUrl,target:"_blank",rel:"noopener noreferrer",onClick:r=>r.stopPropagation(),className:"inline-flex items-center gap-1.5 text-xs font-medium text-primary hover:underline",children:["View documentation",/* @__PURE__ */e(Bd,{className:"h-3 w-3"})]})]}):null;}function tg({chartType:t}){return ri(t)?/* @__PURE__ */n(Qt,{openDelay:200,children:[/* @__PURE__ */e(Yt,{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(Wt,{className:"w-80 p-4",side:"left",align:"start",sideOffset:8,children:/* @__PURE__ */e(eg,{chartType:t})})]}):null;}function si({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(tg,{chartType:t})]});}function ag(){const t=D(o=>!va(o.card.config)),a=D(o=>{var c,d;return((d=(c=o.card.preferences)==null?void 0:c.sqlKpiValue)==null?void 0:d.comparisonPolarity)??xp;}),s=D(o=>o.actions.setCardPreferences),r=o=>{const c=D.getState().card;s(Om(c,{kind:"sqlKpiValue"},o).preferences??{});};return/* @__PURE__ */n("div",{className:"space-y-6 px-6 py-4",children:[/* @__PURE__ */e(si,{chartType:"kpi"}),/* @__PURE__ */e("section",{children:/* @__PURE__ */e(Xf,{})}),t&&/* @__PURE__ */n("section",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{htmlFor:"query-kpi-favorable-direction",className:"text-xs",children:"Favorable direction"}),/* @__PURE__ */n(ee,{value:a,onValueChange:o=>r(o),children:[/* @__PURE__ */e(te,{id:"query-kpi-favorable-direction",className:"h-8 w-full text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"higher_is_better",children:"Higher is better"}),/* @__PURE__ */e(K,{value:"lower_is_better",children:"Lower is better"}),/* @__PURE__ */e(K,{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 ze({label:t,value:a,options:s,onChange:r,disabled:o}){const c=da();return/* @__PURE__ */n("div",{className:"min-w-0 space-y-1",children:[/* @__PURE__ */e(A,{htmlFor:c,className:"text-xs",children:t}),/* @__PURE__ */n(ee,{value:a,onValueChange:r,disabled:o,children:[/* @__PURE__ */e(te,{id:c,"aria-label":t,className:"h-8 min-w-0 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:s.map(d=>/* @__PURE__ */e(K,{value:d.value,className:"text-xs",children:d.label},d.value))})]})]});}function wt({label:t,value:a,onChange:s,type:r="text",min:o,max:c,placeholder:d,hint:l}){const i=da(),h=da();return/* @__PURE__ */n("div",{className:"min-w-0 space-y-1",children:[/* @__PURE__ */e(A,{htmlFor:i,className:"text-xs",children:t}),/* @__PURE__ */e(_e,{id:i,className:"h-8 text-xs",type:r,min:o,max:c,value:a,placeholder:d,"aria-describedby":l?h:void 0,onChange:u=>s(u.target.value)}),l?/* @__PURE__ */e("p",{id:h,className:"text-[11px] text-muted-foreground",children:l}):null]});}function Ka({label:t,checked:a,onChange:s}){const r=da();return/* @__PURE__ */n("div",{className:"flex min-w-0 items-center justify-between gap-2 py-1",children:[/* @__PURE__ */e(A,{className:"text-xs",htmlFor:r,children:t}),/* @__PURE__ */e(De,{id:r,size:"xs",checked:a,onCheckedChange:s})]});}function ng({label:t,disabled:a,onClick:s,children:r}){return/* @__PURE__ */e(ie,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0","aria-label":t,title:t,disabled:a,onClick:s,children:r});}function Qs({label:t,value:a,onChange:s,role:r="subtotal"}){return/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(Ka,{label:t,checked:a.visible,onChange:o=>s({...a,visible:o})}),/* @__PURE__ */e(ze,{label:`${t} position`,value:a.position,options:[{value:"before",label:"Before"},{value:"after",label:"After"}],onChange:o=>s({...a,position:o})}),/* @__PURE__ */e(wt,{label:`${t} label`,value:a.label??"",placeholder:r==="subtotal"?"{member} Total":"Grand Total",hint:r==="subtotal"?`Use ${Zi} for the group's name.`:void 0,onChange:o=>s({...a,label:o||void 0})})]});}function li({value:t,onChange:a,cardType:s,showTitle:r=!0,title:o="NUMBER FORMAT",origin:c,drawnTypes:d}){const l=Lm(s),i=Kl(),h=$l(),u=!!(c&&!c.custom&&c.modelFormat),m=u?c==null?void 0:c.modelFormat:t,p=No(m)||{};if(!ni(d,p.type).length)return null;const w=/* @__PURE__ */e(ya,{formatOptions:p,onFormatOptionsChange:C=>a(Co(C)),showTitle:r,title:o,drawnTypes:d,reportDefaults:l?{currency:h??Xt.defaultCurrency,locale:i??Xt.locale}:void 0});return!(c!=null&&c.custom)&&!u?w:/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */n("div",{className:"flex h-6 items-center justify-between text-xs text-muted-foreground",children:[/* @__PURE__ */e("span",{children:c!=null&&c.custom?"Custom":"Follows the model"}),(c==null?void 0:c.custom)&&/* @__PURE__ */e(ie,{variant:"ghost",size:"xs",onClick:()=>a(void 0),children:"Reset"})]}),w]});}function Ys({field:t,...a}){var c,d;const s=D(l=>l.card),r=(d=(c=nt(s).data)==null?void 0:c.modelFormats)==null?void 0:d[t.id],o=t.formatOrigin==="override";return/* @__PURE__ */e(li,{...a,value:t.format,origin:o||r?{custom:o,modelFormat:r}:void 0});}function oi(t,a,s){const r=(s==null?void 0:s.length)&&s.every((o,c)=>{var d;return((d=t[c])==null?void 0:d.id)===o.levelId&&o.member.kind==="value";});return new Map([...(a!=null&&a.length?[[Fa(a),a]]:[]),...(r?[[Fa(s),s]]:[])]);}const rg=[{value:">",label:"Greater than"},{value:">=",label:"At least"},{value:"<",label:"Less than"},{value:"<=",label:"At most"},{value:"=",label:"Equal to"},{value:"!=",label:"Not equal to"},{value:"between",label:"Between"},{value:"not between",label:"Not between"}],sg=t=>t==="between"||t==="not between";function lg({value:t,onChange:a}){const s=Array.isArray(t),[r,o]=U(()=>s?t.map(String):[String(t)]),c=r.map(i=>i.trim()!==""&&Number.isFinite(Number(i))?Number(i):void 0),d=s&&c[0]!==void 0&&c[1]!==void 0&&c[0]>c[1],l=(i,h)=>{const u=r.map((p,f)=>f===i?h:p);o(u);const m=u.map(p=>p.trim()!==""&&Number.isFinite(Number(p))?Number(p):void 0);m.some(p=>p===void 0)||(s?m[0]<=m[1]&&a([m[0],m[1]]):a(m[0]));};return s?/* @__PURE__ */n(me,{children:[/* @__PURE__ */e(wt,{label:"From",type:"number",value:r[0],onChange:i=>l(0,i)}),/* @__PURE__ */e(wt,{label:"To",type:"number",value:r[1],hint:d?"To must be at least From.":void 0,onChange:i=>l(1,i)})]}):/* @__PURE__ */e(wt,{label:"Value",type:"number",value:r[0],hint:"Keeps members whose value passes. Totals include kept members only.",onChange:i=>l(0,i)});}function og({axis:t,level:a,value:s,change:r,scopeSelection:o}){var C;const c=s.spec.sorts.find(y=>y.axis===t&&y.levelId===a.id&&y.scope.kind==="level"),d=s.spec.rankings.find(y=>y.axis===t&&y.levelId===a.id),l=(C=s.spec.measureFilters)==null?void 0:C.find(y=>y.axis===t&&y.levelId===a.id),i=t==="rows"?"columns":"rows",h=oi(s.spec[i],d==null?void 0:d.oppositePath,i==="rows"?o==null?void 0:o.rowPath:o==null?void 0:o.columnPath),u=s.spec.measures.map(y=>({value:y.id,label:an(y,s.presentation)})),m=y=>{const b=s.spec.sorts.filter(v=>!(v.axis===t&&v.levelId===a.id&&v.scope.kind==="level"));r({kind:"sorts",sorts:y?[...b,{axis:t,levelId:a.id,scope:{kind:"level"},target:{kind:"member"},direction:"asc",nulls:"last",...c,...y}]:b});},p=y=>{if(y&&!s.spec.measures.length)return;const b=s.spec.rankings.filter(v=>!(v.axis===t&&v.levelId===a.id));r({kind:"rankings",rankings:y?[...b,{id:Dt(),axis:t,levelId:a.id,direction:"top",count:10,measureId:s.spec.measures[0].id,oppositePath:[],others:!1,...d,...y}]:b});},f=y=>{if(y&&!s.spec.measures.length)return;const b=(s.spec.measureFilters??[]).filter(v=>!(v.axis===t&&v.levelId===a.id));r({kind:"measureFilters",measureFilters:y?[...b,{id:Dt(),axis:t,levelId:a.id,measureId:s.spec.measures[0].id,operator:">",value:0,...l,...y}]:b});},w=l&&Array.isArray(l.value)?l.value:void 0;return/* @__PURE__ */n("div",{className:"space-y-2 border-t pt-2",children:[/* @__PURE__ */e(ze,{label:"Sort by",value:c?c.target.kind==="member"?"member":c.target.measureId:"default",options:[{value:"default",label:"Default"},{value:"member",label:"Member"},...u],onChange:y=>m(y==="default"?void 0:{target:y==="member"?{kind:"member"}:{kind:"measure",measureId:y,oppositePath:[]}})}),c&&/* @__PURE__ */n(me,{children:[/* @__PURE__ */e(ze,{label:"Sort direction",value:c.direction,options:[{value:"asc",label:"Ascending"},{value:"desc",label:"Descending"}],onChange:y=>m({direction:y})}),/* @__PURE__ */e(ze,{label:"Null order",value:c.nulls,options:[{value:"first",label:"First"},{value:"last",label:"Last"}],onChange:y=>m({nulls:y})})]}),/* @__PURE__ */e(ze,{label:"Ranking",disabled:!s.spec.measures.length,value:(d==null?void 0:d.direction)??"none",options:[{value:"none",label:"None"},{value:"top",label:"Top"},{value:"bottom",label:"Bottom"}],onChange:y=>p(y==="none"?void 0:{direction:y})}),d&&/* @__PURE__ */n(me,{children:[/* @__PURE__ */e(wt,{label:"Ranking count",type:"number",min:1,value:d.count,onChange:y=>{y&&Number.isSafeInteger(Number(y))&&Number(y)>0&&p({count:Number(y)});}}),/* @__PURE__ */e(ze,{label:"Rank by measure",value:d.measureId,options:u,onChange:y=>p({measureId:y})}),/* @__PURE__ */e(Ka,{label:"Include Others",checked:d.others,onChange:y=>p({others:y})}),/* @__PURE__ */e(ze,{label:"Ranking context",value:d.oppositePath.length?Fa(d.oppositePath):"total",options:[{value:"total",label:"Grand total"},...[...h].map(([y,b])=>({value:y,label:b.map((v,N)=>po(b.slice(0,N+1))).join(" / ")}))],onChange:y=>p({oppositePath:y==="total"?[]:[...h.get(y)]})})]}),/* @__PURE__ */e(ze,{label:"Measure filter",disabled:!s.spec.measures.length,value:(l==null?void 0:l.measureId)??"none",options:[{value:"none",label:"None"},...u],onChange:y=>f(y==="none"?void 0:{measureId:y})}),l&&/* @__PURE__ */n(me,{children:[/* @__PURE__ */e(ze,{label:"Condition",value:l.operator,options:rg,onChange:y=>{const b=y,v=w?w[0]:l.value;f({operator:b,value:sg(b)?w??[v,v]:v});}}),/* @__PURE__ */e(lg,{value:l.value,onChange:y=>f({value:y})},`${l.id}:${w?"range":"value"}`)]})]});}function ig(t,a){var r;return(r=Km({type:"matrixTable",config:{matrix:t},preferences:{conditionalFormatting:{version:1,rules:a}}})[0])==null?void 0:r.message;}function cg({cardId:t,value:a,scopeSelection:s,conditionalRules:r,onConditionalRulesChange:o}){const c=xr(t,r,o,m=>ig(a,m)),d=c.rules,l=m=>c.onChange(m(d)),i=d.find(m=>!Vd(m)),h=i?`${i.name||"the new rule"} is incomplete`:c.issue??"",u=a.spec.measures[0];return u?/* @__PURE__ */n("div",{className:"min-w-0 space-y-2",children:[h&&/* @__PURE__ */n("p",{className:"text-xs text-muted-foreground",children:["Not applied yet: ",h]}),/* @__PURE__ */e(br,{columnId:Wn({kind:"matrixMeasure",measureId:u.id}),availableColumns:a.spec.measures.map(m=>({value:Wn({kind:"matrixMeasure",measureId:m.id}),label:an(m,a.presentation)})),conditionalRules:d,onConditionalRulesChange:c.onChange,capabilities:{ruleKinds:["comparison","colorScale","dataBar"],automaticRanges:!1,separateApplyTargets:!0,targetScope:{defaultRowRoles:["member"]}}}),d.map((m,p)=>{var v;const f=m.target.matrix,w=(f==null?void 0:f.axis)==="columns"?"rows":"columns",C=w==="rows"?s==null?void 0:s.rowPath:s==null?void 0:s.columnPath,y=oi(a.spec[w],f==null?void 0:f.oppositePath,C),b=N=>l(g=>g.map(F=>F.id===m.id?{...F,target:{...F.target,matrix:N}}:F));return/* @__PURE__ */n("fieldset",{className:"min-w-0 space-y-2 border-t pt-2",children:[/* @__PURE__ */n("legend",{className:"text-xs font-medium",children:[m.name||`Rule ${p+1}`," scope"]}),/* @__PURE__ */e(ze,{label:"Cell role",value:((v=m.target.rowRoles)==null?void 0:v.length)===1?m.target.rowRoles[0]:"all",options:[{value:"all",label:"All roles"},{value:"member",label:"Detail"},{value:"subtotal",label:"Subtotal"},{value:"grand_total",label:"Grand total"},{value:"others",label:"Others"}],onChange:N=>l(g=>g.map(F=>{if(F.id!==m.id)return F;const{tableParts:O,includeTotals:V,includeSubtotals:$,...E}=F.target;return{...F,target:{...E,rowRoles:N==="all"?void 0:[N]}};}))}),/* @__PURE__ */e(ze,{label:"Rule axis",value:(f==null?void 0:f.axis)??"all",options:[{value:"all",label:"All cells"},{value:"rows",label:"Rows"},{value:"columns",label:"Columns"}],onChange:N=>b(N==="all"?void 0:{axis:N})}),f&&/* @__PURE__ */n(me,{children:[/* @__PURE__ */e(ze,{label:"Rule level",value:f.levelId??"all",options:[{value:"all",label:"All levels"},...a.spec[f.axis].map(N=>({value:N.id,label:Er(N,a.presentation)}))],onChange:N=>b({...f,levelId:N==="all"?void 0:N})}),/* @__PURE__ */e(ze,{label:"Opposite members",value:f.oppositePath===void 0?"all":f.oppositePath.length?Fa(f.oppositePath):"total",options:[{value:"all",label:"All members"},{value:"total",label:"Grand total"},...[...y].map(([N,g])=>({value:N,label:g.map((F,O)=>po(g.slice(0,O+1))).join(" / ")}))],onChange:N=>b({...f,oppositePath:N==="all"?void 0:N==="total"?[]:[...y.get(N)]})})]})]},m.id);})]}):/* @__PURE__ */e("p",{role:"status",className:"text-xs text-muted-foreground",children:"No metrics available"});}function dg({cardId:t,section:a,value:s,availableFields:r,bindings:o,scopeSelection:c,modelFormats:d,conditionalRules:l,onConditionalRulesChange:i,onChange:h}){const[u,m]=U([]),[p,f]=U(""),w=N=>ao(N,s.spec.source,r),C=N=>{try{const g=Vm(s,N,o,w,!0);f(""),m(g.notices),h(g.config,g.notices,g.removedBindings,g.bindings);}catch(g){f(g instanceof Error?g.message:"Invalid Matrix settings.");}},y=N=>C({kind:"presentation",presentation:{...s.presentation,...N}}),b=(N,g,F)=>{const O={...s.presentation[N]};if(F===void 0)delete O[g];else{const V=ec.safeParse(F);if(!V.success){f(V.error.message);return;}O[g]=V.data;}y({[N]:O});},v=(N,g)=>{const F=s.presentation[g][N],O=d==null?void 0:d[g][N],$=Bm({type:"matrixTable",config:{matrix:s}},g==="levelFormats"?{kind:"matrixLevel",levelId:N}:{kind:"matrixMeasure",measureId:N});return/* @__PURE__ */e(li,{cardType:"matrixTable",value:F,onChange:E=>b(g,N,E),origin:F||O?{custom:F!==void 0,modelFormat:O}:void 0,drawnTypes:$});};return/* @__PURE__ */n("aside",{"aria-label":"Matrix authoring",className:"min-w-0 text-foreground",children:[p&&/* @__PURE__ */e("p",{role:"alert",className:"break-words p-3 text-xs text-destructive",children:p}),u.length>0&&/* @__PURE__ */n("div",{role:"status",className:"border-b p-3 text-xs",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e("strong",{children:"Updated references"}),/* @__PURE__ */e(ng,{label:"Dismiss cleanup notices",onClick:()=>m([]),children:/* @__PURE__ */e(it,{className:"size-3.5"})})]}),/* @__PURE__ */e("ul",{className:"space-y-1",children:u.map((N,g)=>/* @__PURE__ */e("li",{children:N.message},`${N.kind}-${N.id}-${g}`))})]}),a.kind!=="conditional-formatting"&&["rows","columns"].filter(N=>a.kind!=="field"||s.spec[N].some(g=>g.id===a.id)).map(N=>/* @__PURE__ */n("section",{"aria-label":a.kind==="field"?`Field ${a.id}`:N==="rows"?"Rows":"Columns",className:(a==null?void 0:a.kind)==="field"?"space-y-2":"space-y-2 border-b p-3",children:[(a==null?void 0:a.kind)!=="field"&&/* @__PURE__ */e("h2",{className:"text-xs font-semibold",children:N==="rows"?"Rows":"Columns"}),s.spec[N].filter(g=>a.kind==="field"&&g.id===a.id).map(g=>{const F=Er(g,s.presentation),O=M=>C({kind:"structure",[N]:s.spec[N].map(I=>I.id===g.id?M:I)}),V=w(g.field),$=V==="date"||V==="datetime",E=s.presentation.levelFormats[g.id],T=(E==null?void 0:E.type)==="temporal_bucket"?E:ro;return/* @__PURE__ */n("div",{className:(a==null?void 0:a.kind)==="field"?"min-w-0":"min-w-0 border-b pb-2",children:[/* @__PURE__ */e("div",{className:"flex min-w-0 items-center justify-between gap-1",children:/* @__PURE__ */e("span",{className:"truncate text-xs font-medium",title:F,children:F})}),/* @__PURE__ */n("details",{open:(a==null?void 0:a.kind)==="field"?!0:void 0,children:[/* @__PURE__ */n("summary",{className:`cursor-pointer py-1 text-xs text-muted-foreground ${(a==null?void 0:a.kind)==="field"?"hidden":""}`,children:[F," settings"]}),/* @__PURE__ */n("div",{className:(a==null?void 0:a.kind)==="field"?"space-y-2 pt-2":"space-y-2 py-2",children:[/* @__PURE__ */e(wt,{label:"Level label",value:s.presentation.levelLabels[g.id]??"",onChange:M=>{const I={...s.presentation.levelLabels};M?I[g.id]=M:delete I[g.id],y({levelLabels:I});}}),/* @__PURE__ */e(ze,{label:"Axis",value:N,options:[{value:"rows",label:"Rows"},{value:"columns",label:"Columns"}],onChange:M=>{M!==N&&C(_m(s.spec,g.id,M));}}),$&&/* @__PURE__ */e(ze,{label:"Time grain",value:g.grain??"none",options:[{value:"none",label:"No grouping"},...ql(V).map(M=>({value:M,label:M}))],onChange:M=>O({...g,grain:M==="none"?void 0:M})}),g.grain?/* @__PURE__ */e(zl,{grain:g.grain,format:T,onChange:M=>b("levelFormats",g.id,M.presentation.mode==="auto"?void 0:M)},`${g.id}:${g.grain}`):v(g.id,"levelFormats"),/* @__PURE__ */e(Qs,{label:"Subtotal",value:s.presentation.totals[N].levels[g.id],onChange:M=>y({totals:{...s.presentation.totals,[N]:{...s.presentation.totals[N],levels:{...s.presentation.totals[N].levels,[g.id]:M}}}})}),/* @__PURE__ */e(og,{axis:N,level:g,value:s,change:C,scopeSelection:c})]})]})]},g.id);}),(a==null?void 0:a.kind)!=="field"&&/* @__PURE__ */n("details",{children:[/* @__PURE__ */n("summary",{className:"cursor-pointer py-1 text-xs text-muted-foreground",children:[N==="rows"?"Row":"Column"," totals and expansion"]}),/* @__PURE__ */n("div",{className:"space-y-2 py-2",children:[/* @__PURE__ */e(Ka,{label:"Skip subtotals that repeat one row",checked:s.presentation.totals[N].skipRedundant===!0,onChange:g=>{const{skipRedundant:F,...O}=s.presentation.totals[N];y({totals:{...s.presentation.totals,[N]:g?{...O,skipRedundant:!0}:O}});}}),/* @__PURE__ */e(Qs,{label:"Grand total",role:"grand_total",value:s.presentation.totals[N].grand,onChange:g=>y({totals:{...s.presentation.totals,[N]:{...s.presentation.totals[N],grand:g}}})}),/* @__PURE__ */e(ze,{label:"Default expanded levels",value:String(Math.min(s.defaultView[N].depth,Math.max(0,s.spec[N].length-1))),options:Array.from({length:Math.max(1,s.spec[N].length)},(g,F)=>({value:String(F),label:F===0?"Collapsed":String(F)})),onChange:g=>C({kind:"defaults",defaultView:{...s.defaultView,[N]:{...s.defaultView[N],depth:Number(g)}}})})]})]})]},N)),a.kind==="field"&&s.spec.measures.some(N=>N.id===a.id)&&/* @__PURE__ */e("section",{"aria-label":"Values",className:"space-y-2",children:s.spec.measures.filter(N=>N.id===a.id).map(N=>{const g=an(N,s.presentation);return/* @__PURE__ */n("div",{className:(a==null?void 0:a.kind)==="field"?"min-w-0":"min-w-0 border-b pb-2",children:[/* @__PURE__ */e("div",{className:"flex min-w-0 items-center justify-between gap-1",children:/* @__PURE__ */n("span",{className:"truncate text-xs font-medium",title:g,children:[g,N.kind==="aggregate"?` (${N.aggregate})`:""]})}),/* @__PURE__ */n("details",{open:(a==null?void 0:a.kind)==="field"?!0:void 0,children:[/* @__PURE__ */n("summary",{className:`cursor-pointer py-1 text-xs text-muted-foreground ${(a==null?void 0:a.kind)==="field"?"hidden":""}`,children:[g," settings"]}),/* @__PURE__ */n("div",{className:(a==null?void 0:a.kind)==="field"?"space-y-2 pt-2":"space-y-2 py-2",children:[/* @__PURE__ */e(wt,{label:"Measure label",value:s.presentation.measureLabels[N.id]??"",onChange:F=>{const O={...s.presentation.measureLabels};F?O[N.id]=F:delete O[N.id],y({measureLabels:O});}}),N.kind==="aggregate"&&/* @__PURE__ */e(ze,{label:"Aggregation",value:N.aggregate,options:so(w(N.field)).filter(F=>hs.safeParse(F.value).success).map(({value:F})=>({value:F,label:F})),onChange:F=>C({kind:"structure",measures:s.spec.measures.map(O=>O.id===N.id?{...N,aggregate:hs.parse(F)}:O)})}),v(N.id,"measureFormats")]})]})]},N.id);})}),a.kind==="table"&&/* @__PURE__ */n("section",{"aria-label":"Presentation",className:"space-y-2 border-b p-3",children:[/* @__PURE__ */e("h2",{className:"text-xs font-semibold",children:"Presentation"}),/* @__PURE__ */e(ze,{label:"Row layout",value:s.presentation.layout.kind,options:[{value:"compact",label:"Compact"},{value:"tabular",label:"Tabular"}],onChange:N=>y({layout:N==="compact"?{kind:"compact"}:{kind:"tabular",repeatLabels:!1}})}),s.presentation.layout.kind==="tabular"&&/* @__PURE__ */e(Ka,{label:"Repeat row labels",checked:s.presentation.layout.repeatLabels,onChange:N=>y({layout:{kind:"tabular",repeatLabels:N}})}),/* @__PURE__ */e(wt,{label:"Empty cell text",value:s.presentation.absence.emptyText,onChange:N=>y({absence:{...s.presentation.absence,emptyText:N}})}),/* @__PURE__ */e(wt,{label:"Null cell text",value:s.presentation.absence.nullText,onChange:N=>y({absence:{...s.presentation.absence,nullText:N}})})]}),a.kind==="conditional-formatting"&&/* @__PURE__ */n("section",{"aria-label":"Conditional formatting",className:"min-w-0 space-y-2 p-3",children:[/* @__PURE__ */e("h2",{className:"text-xs font-semibold",children:"Conditional formatting"}),/* @__PURE__ */e(cg,{cardId:t??"",value:s,scopeSelection:c,conditionalRules:l??[],onConditionalRulesChange:N=>i==null?void 0:i(N)})]})]});}function sr({fieldId:t,section:a="table"}){const s=D(i=>i.card),r=D(i=>i.actions.updateCard),o=D(i=>i.actions.updateConditionalRules),c=D(i=>i.matrixSelection),d=Kd(s),l=$m(s);return l.status==="invalid"?/* @__PURE__ */e("div",{role:"alert",className:"p-3 text-xs text-destructive",children:"Invalid Matrix configuration. Repair or reset the card definition."}):l.status==="absent"?/* @__PURE__ */e("div",{className:"p-3 text-xs text-muted-foreground",children:"No fields selected"}):/* @__PURE__ */n(me,{children:[a==="conditional-formatting"&&!t&&/* @__PURE__ */e("div",{className:"px-3 pt-3",children:/* @__PURE__ */e(Kr,{cardId:s.id})}),/* @__PURE__ */e(dg,{cardId:s.id,value:l.config,section:t?{kind:"field",id:t}:{kind:a},scopeSelection:(c==null?void 0:c.cardId)===s.id?c.coordinate:void 0,bindings:s.controlBindings,modelFormats:op(l.config.spec,d.catalog),conditionalRules:kr(s),onConditionalRulesChange:o,availableFields:d.catalog.map(i=>({...i.field,dataType:dl(i.resolvedField.dataType)})),onChange:(i,h,u,m)=>{const p=qm(s,{config:i,notices:h,bindings:m});r(s.id,p.card);}})]});}function ug(t){return t.kind==="dashboard"?{kind:"inherit"}:t;}function ii(t,a){var s,r;return lo(t)&&((r=(s=t.config)==null?void 0:s.metricColumns)==null?void 0:r[0])===a;}function ci(t,a){var r,o;const s=Eo({metricComparison:a.comparison,inheritGlobalComparison:(r=t.preferences)==null?void 0:r.inheritGlobalComparison,hidden:Io((o=t.preferences)==null?void 0:o.comparisonPresentation)});return s.state==="follow"?{kind:"dashboard"}:s.state==="off"?{kind:"off"}:s.spec;}function mg({card:t,metric:a,options:s,dates:r,otherMetric:o,onChange:c}){var C,y;const{data:d}=nt(t),l=d==null?void 0:d.metadata,i=(C=fo(l==null?void 0:l.comparisonMetadata,a))==null?void 0:C.output,h=Za(),u=hg(l==null?void 0:l.dateContext,i==null?void 0:i.windowShape,h),m=(i==null?void 0:i.availability.status)==="available"&&i.comparisonWindow?Wh(i.comparisonWindow):void 0,p=ii(t,a)?{kind:"metric"}:ci(t,a),f=b=>b.offered?void 0:b.reason,w=Object.values(s.comparison).some(b=>b.offered&&b.replaces==="transform");return/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e($d,{value:p,shape:u,dashboard:{offered:!0},target:{offered:s.comparison.target.offered,reason:f(s.comparison.target)},...(o?{otherMetric:o}:{}),shiftRefusal:f(s.comparison.shift),dates:p.kind==="shift"||p.kind==="dashboard"?m:void 0,onChange:b=>c(ug(b))}),w?/* @__PURE__ */e("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"A comparison replaces this metric's transform."}):null,p.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 ",((y=r.comparisonDate)==null?void 0:y.label)??"its date","; none does yet."]}):null]});}function hg(t,a,s){const r=(t==null?void 0:t.windows.filter(o=>!o.replaced))??[];return r.length===1?(r[0].relative?Rs({kind:"relative",window:r[0].relative}):void 0)??(r[0].window?Rs({kind:"resolved",window:r[0].window,calendar:s}):a):a;}function pg({card:t}){var h;const a=Za(),s=jl(t),r=ye(u=>u.dashboard),o=ye(u=>u.semanticExecutionPayload),{handleMetricComparisonChange:c}=qa(t),d=Z(()=>Do(t,To(s,ko(r,o,a)),a),[t,s,r,o,a]),l=((h=t.config)==null?void 0:h.metricColumns)??[],i=oo("metric",l);return/* @__PURE__ */e("div",{className:"space-y-4",children:l.map((u,m)=>{const p=i[m]?io(t,i[m],d):void 0;if(!p||!Object.values(p.comparison).some(w=>w.offered))return null;const f=p.comparison.metric.offered?l[1]:void 0;return/* @__PURE__ */n("div",{className:"space-y-2","data-role":"measure-comparison",children:[/* @__PURE__ */e("div",{className:"text-[12px] font-medium",children:u.label||u.name}),/* @__PURE__ */e(mg,{card:t,metric:u,options:p,dates:d,...(f?{otherMetric:{name:f.label||f.name}}:{}),onChange:w=>c(m,w,d)})]},u.id??m);})});}function Ws({card:t}){var o;const{handleMetricComparisonPolarityChange:a}=qa(t),r=(((o=t.config)==null?void 0:o.metricColumns)??[]).map((c,d)=>({metric:c,index:d})).filter(({metric:c})=>ii(t,c)||ci(t,c).kind!=="off");return r.length?/* @__PURE__ */e("div",{className:"space-y-2",children:r.map(({metric:c,index:d})=>/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:r.length===1?"Higher is":`Higher is · ${c.label||c.name}`}),/* @__PURE__ */n(ee,{value:go(c),disabled:!!c.semanticComparisonPolarity,onValueChange:l=>a(d,l),children:[/* @__PURE__ */e(te,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"higher_is_better",children:"Better"}),/* @__PURE__ */e(K,{value:"lower_is_better",children:"Worse"}),/* @__PURE__ */e(K,{value:"neutral",children:"Neither"})]})]}),c.semanticComparisonPolarity?/* @__PURE__ */e("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"Governed by this metric's semantic definition."}):null]},c.id??d))}):null;}const fg={green:"#16a34a",red:"#dc2626",neutral:"#6b7280"};function gg(t){return t&&(fg[t]??t);}function xg({value:t,onChange:a,showPosition:s=!1,polarity:r,direction:o}){const c=t.colors||{},d=l=>r==="higher_is_better"?l?" (good)":" (bad)":r==="lower_is_better"?l?" (bad)":" (good)":"";return/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Shown as"}),/* @__PURE__ */e(Qn,{fill:!0,label:"Shown as",value:t.displayMode||"difference",options:[{value:"percent_change",label:"Change %"},{value:"difference",label:"Change"},{value:"both",label:"Both"},{value:"ratio",label:"Ratio",title:"Current ÷ comparison"}],onChange:l=>a({displayMode:l})})]}),(t.displayMode||"difference")!=="difference"?/* @__PURE__ */n("div",{className:"flex items-center justify-between gap-3",children:[/* @__PURE__ */e("div",{children:/* @__PURE__ */e(A,{htmlFor:"comparison-precision",className:"text-xs",children:"Decimals"})}),/* @__PURE__ */e(_e,{id:"comparison-precision",type:"number",min:0,max:6,step:1,value:t.precision??"",placeholder:"Auto",onChange:l=>{if(l.target.value===""){a({precision:void 0});return;}const i=Number(l.target.value);Number.isInteger(i)&&i>=0&&i<=6&&a({precision:i});},size:"xs",className:"w-16"})]}):null,/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Indicator"}),/* @__PURE__ */n(ee,{value:t.indicatorStyle||"arrow_badge",onValueChange:l=>a({indicatorStyle:l}),children:[/* @__PURE__ */e(te,{className:"h-7 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"arrow_badge",children:"Arrow + badge"}),/* @__PURE__ */e(K,{value:"arrow",children:"Arrow"}),/* @__PURE__ */e(K,{value:"badge",children:"Badge"}),/* @__PURE__ */e(K,{value:"none",children:"None"})]})]})]}),s&&/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs",children:"Position"}),/* @__PURE__ */n(ee,{value:t.position||"right",onValueChange:l=>a({position:l}),children:[/* @__PURE__ */e(te,{className:"h-7 w-24 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"right",children:"Right"}),/* @__PURE__ */e(K,{value:"left",children:"Left"}),/* @__PURE__ */e(K,{value:"top",children:"Top"})]})]})]}),o,/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{htmlFor:"comparison-color",className:"text-xs",children:"Colors"}),/* @__PURE__ */e(De,{id:"comparison-color",size:"xs",checked:t.showColor!==!1,onCheckedChange:l=>a({showColor:l})})]}),t.showColor!==!1&&/* @__PURE__ */e("div",{className:"space-y-1.5",children:[["increase",`Up${d(!0)}`,"#16a34a"],["decrease",`Down${d(!1)}`,"#dc2626"],["neutral","No change","#6b7280"]].map(([l,i,h])=>/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e("span",{className:"w-24 shrink-0 text-xs text-muted-foreground",children:i}),/* @__PURE__ */e(Hn,{value:gg(c[l]||h),onChange:u=>a({colors:{...c,[l]:u||h}}),defaultValue:h,ariaLabel:`${i} color`,allowEmpty:!1})]},l))}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),t.conditionalLabel?/* @__PURE__ */e("div",{className:"space-y-1.5",children:[["increase","Increase"],["decrease","Decrease"],["neutral","No change"]].map(([l,i])=>{var h;return/* @__PURE__ */e(_e,{"aria-label":`${i} label`,value:((h=t.conditionalLabels)==null?void 0:h[l])||i,onChange:u=>a({conditionalLabels:{...t.conditionalLabels,[l]:u.target.value}}),className:"h-7 text-xs"},l);})}):/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(_e,{"aria-label":"Comparison label",value:t.labelName&&t.labelName!=="Previous"?t.labelName:"",onChange:l=>a({labelName:l.target.value}),placeholder:"The comparison's own words",className:"h-7 text-xs"}),/* @__PURE__ */e("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"Empty: the comparison's own words, which follow the Date filter."})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between pt-1",children:[/* @__PURE__ */e(A,{htmlFor:"comparison-conditional-label",className:"text-xs",children:"Different label per direction"}),/* @__PURE__ */e(De,{id:"comparison-conditional-label",size:"xs",checked:t.conditionalLabel===!0,onCheckedChange:l=>a({conditionalLabel:l})})]})]})]});}function di({cardType:t}){var m,p;const a=D(f=>f.card),{setCardPreferences:s}=xe(),r=((m=a.config)==null?void 0:m.metricColumns)||[],o=((p=a.preferences)==null?void 0:p.comparisonPresentation)||{},c=f=>s(jm(a.preferences,f)),d=Io(o),l=lo({...a,type:t}),i=r.filter(f=>{var w;return Eo({metricComparison:f.comparison,inheritGlobalComparison:(w=a.preferences)==null?void 0:w.inheritGlobalComparison,hidden:d}).state!=="off";}),h=i.length>0||l,u=zm.includes(t);return/* @__PURE__ */n("div",{className:"space-y-4",children:[/* @__PURE__ */e(pg,{card:a}),h&&u?/* @__PURE__ */e(xg,{value:o,onChange:c,showPosition:l,direction:/* @__PURE__ */e(Ws,{card:a}),polarity:go((l?r[0]:i[0])??r[0])}):h?/* @__PURE__ */e(Ws,{card:a}):null]});}function bg(){const t=Ze();return Um.includes(t)?/* @__PURE__ */n(Pe,{value:"comparison",className:"border-none",children:[/* @__PURE__ */e(Re,{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(qd,{className:"h-3.5 w-3.5 text-foreground/60"}),/* @__PURE__ */e("span",{children:"Comparison"})]})}),/* @__PURE__ */e(Oe,{className:"pb-4 pt-2",children:/* @__PURE__ */e(di,{cardType:t})})]}):null;}function ui({cardType:t,queryOutput:a,focusSection:s,focusRequestId:r}){var Y,fe,he;const o=D(re=>re.card),c=D(re=>re.queryResultColumns),d=D(re=>re.queryResultColumnKeyMap),l=D(re=>{var se;return(se=re.card)==null?void 0:se.preferences;}),i=l==null?void 0:l.tablePrefs,h=D(re=>re.actions.setCardPreferences),u=D(re=>re.queryResultColumnMeta),m=t??o.type,p=a?[...(a.keys??[])]:c,f=a?a.columnKeyMap:d,w=a?a.resultColumns:u,C=o.type===m?o:{...o,type:m},y=zd(C,p,f,w),b=jd(C,p),v=m==="matrixTable"||Hd(m),N=m==="table",g=m==="table",F=m==="table"||m==="detailTable",O=!!(o&&(Y=Es(o))!=null&&Y.settings.has("columnFilters")),V=!!(o&&(fe=Es(o))!=null&&fe.settings.has("tableSearch")),$=g||F||O,E=((he=y[0])==null?void 0:he.value)||"",T=Ud(i),M=Hm(C),I=Gm(C),[q,P]=U("style");Ne(()=>{if(s==="style"){P("style");return;}if(s==="columns"&&$){P("columns");return;}s==="conditional-formatting"&&v&&P("conditional-formatting");},[$,v,r,s]);const x=o?Qm(o):!1,R=re=>{h({...l,tablePrefs:{...i,density:re}});},S=re=>{h({...l,tablePrefs:{...i,tableStyle:{...(i==null?void 0:i.tableStyle),...re}}});},k=re=>{var se;S({totals:{...((se=i==null?void 0:i.tableStyle)==null?void 0:se.totals),...re}});},L=(re,se)=>{h(Is(l,{measures:{[re]:se}}));},_=re=>{h(Is(l,{row:re}));},z=(re,se)=>{h(Wm({preferences:l},re,{hidden:!se}).preferences??{});},j=re=>{const{allowViewerColumnCustomization:se,...ge}=i??{};h({...l,tablePrefs:re?ge:{...ge,allowViewerColumnCustomization:!1}});},B=re=>{h(Jm(l,re));},G=re=>{h(Xm(l,re));},ce=()=>{h(Zm({preferences:l}).preferences??{});},ue=()=>{var re;h({...l,tablePrefs:{...i,density:ra.density,tableStyle:{headerStyle:ra.headerStyle,headerWrapText:ra.headerWrapText,stripedRows:ra.stripedRows,wrapText:ra.wrapText,totals:{enabled:M?I:Ot.enabled,backgroundColor:Ot.backgroundColor,textColor:Ot.textColor,fontWeight:Ot.fontWeight,borderTop:Ot.borderTop,borderTopStyle:Ot.borderTopStyle,borderTopColor:Ot.borderTopColor,...eh((re=i==null?void 0:i.tableStyle)==null?void 0:re.totals)}}}});},X=x?/* @__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(di,{cardType:"table"})]}):null;return/* @__PURE__ */e("div",{className:"px-4 py-3",children:/* @__PURE__ */n(Mt,{value:q,onValueChange:re=>P(re),className:"space-y-4",children:[/* @__PURE__ */n(At,{variant:"underline",children:[/* @__PURE__ */e(Ye,{value:"style",children:"Appearance"}),$?/* @__PURE__ */e(Ye,{value:"columns",children:"Columns"}):null,/* @__PURE__ */e(Ye,{value:"conditional-formatting",disabled:!v,children:"Conditional formatting"})]}),/* @__PURE__ */n(mt,{value:"style",className:"mt-0",children:[/* @__PURE__ */e(Gd,{style:T,onDensityChange:R,onStyleChange:S,showFullStyle:N,showBorderStyle:!1,totals:N&&M?{enabled:I,onEnabledChange:_,onStyleChange:k,measures:Ym(C),onMeasureTotalChange:L}:void 0,extraSection:X,onReset:N?ue:void 0}),m==="matrixTable"&&/* @__PURE__ */e(sr,{section:"table"})]}),/* @__PURE__ */n(mt,{value:"columns",className:"mt-0 space-y-4",children:[F?/* @__PURE__ */n("div",{className:"flex items-start justify-between gap-3",children:[/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */e(A,{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(De,{id:"allow-viewer-column-customization",size:"xs",checked:(i==null?void 0:i.allowViewerColumnCustomization)!==!1,onCheckedChange:j})]}):null,O?/* @__PURE__ */n("div",{className:"flex items-start justify-between gap-3",children:[/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */e(A,{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:[m==="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(De,{id:"allow-viewer-column-filters",size:"xs",checked:(i==null?void 0:i.allowViewerColumnFilters)!==!1,onCheckedChange:B})]}):null,V?/* @__PURE__ */n("div",{className:"flex items-start justify-between gap-3",children:[/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */e(A,{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(De,{id:"allow-viewer-search",size:"xs",checked:(i==null?void 0:i.allowViewerSearch)!==!1,onCheckedChange:G})]}):null,g?/* @__PURE__ */e(Qd,{columns:b,columnVisibility:i==null?void 0:i.columnVisibility,onColumnVisibilityChange:z,onShowAllColumns:ce}):null]}),/* @__PURE__ */e(mt,{value:"conditional-formatting",className:"mt-0",children:m==="matrixTable"?/* @__PURE__ */e(sr,{section:"conditional-formatting"}):v?E?/* @__PURE__ */e(vg,{columnId:E,availableColumns:y}):/* @__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 vg({columnId:t,availableColumns:a}){const s=D(d=>d.card),r=D(d=>d.actions.updateConditionalRules),{rules:o,onChange:c}=xr(s.id,kr(s),r);return/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(Kr,{cardId:s.id}),/* @__PURE__ */e(br,{columnId:t,availableColumns:a,conditionalRules:o,onConditionalRulesChange:c,startRulesWithNoTrigger:!0})]});}function yg(){var o;const t=D(c=>c.card.preferences),{setCardPreferences:a}=D(c=>c.actions),s=(o=t==null?void 0:t.textVisualOptions)!=null&&o.isDynamicText?"dynamic":"static";function r(c){a({...t,textVisualOptions:{...(t==null?void 0:t.textVisualOptions),isDynamicText:c==="dynamic"}});}return/* @__PURE__ */e(Mt,{value:s,onValueChange:r,children:/* @__PURE__ */n(At,{variant:"underline",children:[/* @__PURE__ */e(Ye,{value:"static",children:"Static"}),/* @__PURE__ */e(Ye,{value:"dynamic",children:"Dynamic"})]})});}function Ng(){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(yg,{}),/* @__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 Cg({color:t,onColorChange:a,onClose:s}){const[r,o]=U(0),[c,d]=U(100),[l,i]=U(50),[h,u]=U(t);Ne(()=>{const y=Js(t);if(y){const b=Xs(y.r,y.g,y.b);o(b.h),d(b.s),i(b.l),u(t);}},[t]);const m=y=>{o(y),f(y,c,l);},p=y=>{const b=y.currentTarget.getBoundingClientRect(),v=Math.max(0,Math.min(1,(y.clientX-b.left)/b.width)),N=Math.max(0,Math.min(1,(y.clientY-b.top)/b.height)),g=v*100,F=(1-N)*100;d(g),i(F),f(r,g,F);},f=(y,b,v)=>{const N=Sg(y,b,v),g=wg(N.r,N.g,N.b);u(g);},w=y=>{if(u(y),/^#[0-9A-Fa-f]{6}$/.test(y)){const b=Js(y);if(b){const v=Xs(b.r,b.g,b.b);o(v.h),d(v.s),i(v.l);}}},C=()=>{/^#[0-9A-Fa-f]{6}$/.test(h)&&(a(h),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:p,onMouseMove:y=>{y.buttons===1&&p(y);},children:[/* @__PURE__ */e("div",{className:"absolute inset-0 rounded",style:{background:"linear-gradient(to right, white, transparent)"}}),/* @__PURE__ */e("div",{className:"absolute inset-0 rounded",style:{background:"linear-gradient(to bottom, transparent, black)"}}),/* @__PURE__ */e("div",{className:"absolute w-4 h-4 -ml-2 -mt-2 rounded-full border-2 border-white shadow-md",style:{left:`${c}%`,top:`${100-l}%`,backgroundColor:h}})]}),/* @__PURE__ */e("div",{className:"space-y-2",children:/* @__PURE__ */e("input",{type:"range",min:"0",max:"360",value:r,onChange:y=>m(Number(y.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(A,{children:"HEX"}),/* @__PURE__ */e(_e,{value:h,onChange:y=>w(y.target.value),placeholder:"#000000",className:"font-mono"})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-4",children:[/* @__PURE__ */n("div",{className:"text-center",children:[/* @__PURE__ */e("div",{className:"w-12 h-12 rounded-full border shadow-sm",style:{backgroundColor:t}}),/* @__PURE__ */e("span",{className:"text-xs text-muted-foreground mt-1",children:"CURRENT"})]}),/* @__PURE__ */n("div",{className:"text-center",children:[/* @__PURE__ */e("div",{className:"w-12 h-12 rounded-full border shadow-sm",style:{backgroundColor:h}}),/* @__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(ie,{variant:"outline",onClick:s,children:"Cancel"}),/* @__PURE__ */e(ie,{onClick:C,children:"OK"})]})]});}function Js(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 wg(t,a,s){return"#"+((1<<24)+(t<<16)+(a<<8)+s).toString(16).slice(1);}function Xs(t,a,s){t/=255,a/=255,s/=255;const r=Math.max(t,a,s),o=Math.min(t,a,s);let c=0,d=0;const l=(r+o)/2;if(r!==o){const i=r-o;switch(d=l>0.5?i/(2-r-o):i/(r+o),r){case t:c=((a-s)/i+(a<s?6:0))/6;break;case a:c=((s-t)/i+2)/6;break;case s:c=((t-a)/i+4)/6;break;}}return{h:Math.round(c*360),s:Math.round(d*100),l:Math.round(l*100)};}function Sg(t,a,s){t/=360,a/=100,s/=100;let r,o,c;if(a===0)r=o=c=s;else{const d=(h,u,m)=>(m<0&&(m+=1),m>1&&(m-=1),m<0.16666666666666666?h+(u-h)*6*m:m<0.5?u:m<0.6666666666666666?h+(u-h)*(0.6666666666666666-m)*6:h),l=s<0.5?s*(1+a):s+a-s*a,i=2*s-l;r=d(i,l,t+1/3),o=d(i,l,t),c=d(i,l,t-1/3);}return{r:Math.round(r*255),g:Math.round(o*255),b:Math.round(c*255)};}const Tg=["#000000","#ffffff","#6b7280","#dc2626","#ea580c","#ca8a04","#16a34a","#0891b2","#2563eb","#7c3aed","#c026d3","#e11d48","#0f172a","#f3f4f6","#fbbf24"];function kg(){var F,O,V,$,E,T,M,I,q,P;const t=D(x=>x.card),a=D(x=>{var R;return(R=x.card)==null?void 0:R.preferences;}),s=Ze(),{setCardPreferences:r,updateCardInFrame:o}=xe(),c=Z(()=>s!==t.type?{...t,type:s}:t,[t,s]),{data:d}=nt(c),[l,i]=U({}),[h,u]=U(null),[m,p]=U(null),f=Z(()=>{var k,L,_,z,j,B,G;if(!(d!=null&&d.records)||d.records.length===0)return[];const x=s==="stackedBar"||s==="stackedLine",R=s==="bar"||s==="line"||s==="horizontalBar"||s==="bullet"||s==="combo"||s==="area"||s==="stackedArea",S=((k=t==null?void 0:t.config)==null?void 0:k.pivotByColumns)&&t.config.pivotByColumns.length>0;if((x||R)&&S){if(d.pivotSchema&&Array.isArray(d.pivotSchema)){const ce=/* @__PURE__ */new Set();return d.pivotSchema.forEach(ue=>{ue.alias&&ce.add(ue.alias);}),Array.from(ce);}if(d.records.length>0){const ce=d.records[0],ue=Object.keys(ce),X=/* @__PURE__ */new Set();(L=t==null?void 0:t.config)!=null&&L.groupByColumns&&t.config.groupByColumns.forEach(he=>{X.add(he.label||he.name),X.add(he.alias||he.name);});const Y=/* @__PURE__ */new Set();return(_=t==null?void 0:t.config)!=null&&_.metricColumns&&t.config.metricColumns.forEach(he=>{const re=he.alias||he.name;Y.add(re),Y.add(`${re}_count`),Y.add(`${re}_sum`),Y.add(`${re}_avg`),Y.add(`${re}_min`),Y.add(`${re}_max`);const se=he.entityName||he.qualifiedEntityName;se&&(Y.add(`${se}_${re}`),Y.add(`${se}_${re}_count`));}),ue.filter(he=>!X.has(he)&&!Y.has(he));}}if((R||x)&&!S&&(j=(z=t==null?void 0:t.config)==null?void 0:z.metricColumns)!=null&&j.length)return t.config.metricColumns.map(ce=>ce.alias||ce.label||ce.name);if((G=(B=t==null?void 0:t.config)==null?void 0:B.groupByColumns)!=null&&G.length){const ce=t.config.groupByColumns[0],ue=ce.label||ce.name,X=/* @__PURE__ */new Set();return d.records.forEach(Y=>{const fe=Y[ue];fe!=null&&X.add(String(fe));}),Array.from(X);}return[];},[d,(F=t==null?void 0:t.config)==null?void 0:F.groupByColumns,(O=t==null?void 0:t.config)==null?void 0:O.pivotByColumns,(V=t==null?void 0:t.config)==null?void 0:V.metricColumns,s]),w=hr().palette;Ne(()=>{const x={};f.forEach((R,S)=>{x[R]=ys(R,S,w,a==null?void 0:a.colorConfig);}),i(x);},[f,a==null?void 0:a.colorConfig,w]);const C=(x,R)=>{var _;const S={...l,[x]:R};i(S);const k={...(a||{}),colorConfig:{...(a==null?void 0:a.colorConfig),segments:{...((_=a==null?void 0:a.colorConfig)==null?void 0:_.segments),[x]:R}}};r(k);const L={...t,preferences:k};o(L);},y=(x,R)=>{var j;const S=w[R%w.length],{[x]:k,...L}=((j=a==null?void 0:a.colorConfig)==null?void 0:j.segments)||{},_={...(a||{}),colorConfig:{segments:L}};r(_);const z={...t,preferences:_};o(z),i(B=>({...B,[x]:S}));};if(!f.length||!((t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine"?((E=($=t==null?void 0:t.config)==null?void 0:$.groupByColumns)==null?void 0:E.length)||((M=(T=t==null?void 0:t.config)==null?void 0:T.pivotByColumns)==null?void 0:M.length):(q=(I=t==null?void 0:t.config)==null?void 0:I.groupByColumns)==null?void 0:q.length)||["table","kpi","text","custom","heatmap"].includes(s))return null;const N=()=>{const x={...(a||{}),colorConfig:{segments:{}}};r(x);const R={...t,preferences:x};o(R);const S={};f.forEach((k,L)=>{S[k]=ys(k,L,w);}),i(S);},g=Object.keys(((P=a==null?void 0:a.colorConfig)==null?void 0:P.segments)||{}).length>0;return/* @__PURE__ */n(Pe,{value:"colors",className:"border-b-0",children:[/* @__PURE__ */e(Re,{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(bp,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Colors"})]})}),/* @__PURE__ */e(Oe,{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:g&&/* @__PURE__ */n("button",{className:"ml-auto flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",onClick:N,children:[/* @__PURE__ */e(ws,{className:"h-3 w-3"}),"Reset All"]})})}),/* @__PURE__ */e("div",{className:"max-h-[200px] space-y-2 overflow-y-auto pr-1",children:f.map((x,R)=>{const S=l[x]===w[R%w.length],k=!S;return/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */n(bt,{open:h===x,onOpenChange:L=>u(L?x:null),children:[/* @__PURE__ */e(Tt,{asChild:!0,children:/* @__PURE__ */e("button",{className:"h-5 w-5 shrink-0 rounded border border-input shadow-sm transition-colors hover:border-gray-400 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",style:{backgroundColor:l[x]}})}),/* @__PURE__ */e(vt,{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:w.slice(0,10).map((L,_)=>/* @__PURE__ */n("button",{className:H("relative h-5 w-5 rounded border-2 transition-all hover:scale-110",l[x]===L?"border-gray-900":"border-transparent"),style:{backgroundColor:L},onClick:()=>{C(x,L),u(null);},children:[_===R%w.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:L})]},`default-${_}`))})]}),/* @__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:Tg.map((L,_)=>/* @__PURE__ */e("button",{className:H("h-5 w-5 rounded border transition-all hover:scale-110",l[x]===L?"border-2 border-gray-900":L==="#ffffff"?"border border-gray-300":"border border-transparent"),style:{backgroundColor:L},onClick:()=>{C(x,L),u(null);},children:/* @__PURE__ */e("span",{className:"sr-only",children:L})},`preset-${_}`))})]}),/* @__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:()=>{p({value:x,color:l[x]}),u(null);},children:"Custom color"}),!S&&/* @__PURE__ */n("button",{className:"flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",onClick:()=>{y(x,R),u(null);},children:[/* @__PURE__ */e(ws,{className:"h-3 w-3"}),"Reset"]})]})]})})]}),/* @__PURE__ */e("span",{className:"flex-1 truncate text-sm",children:x}),k&&/* @__PURE__ */e("span",{className:"text-xs text-muted-foreground",children:"(custom)"})]},x);})}),m&&/* @__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:()=>p(null)}),/* @__PURE__ */e("div",{className:"relative rounded-lg bg-white shadow-lg",children:/* @__PURE__ */e(Cg,{color:m.color,onColorChange:x=>{C(m.value,x),p(null);},onClose:()=>p(null)})})]})]})})]});}function dt({value:t,onSave:a,placeholder:s="",type:r="text",className:o=""}){const[c,d]=U(t??""),[l,i]=U(!1);Ma.useEffect(()=>{d(t??"");},[t]);const h=()=>{a(c),i(!1);},u=()=>{d(t??""),i(!1);};return/* @__PURE__ */n("div",{className:`flex items-center gap-2 ${o}`,children:[/* @__PURE__ */e(_e,{placeholder:s,type:r,value:l?c:t??"",onChange:m=>{d(m.target.value),i(!0);},onFocus:()=>i(!0),onClick:m=>m.stopPropagation(),size:"xs",onPointerDown:m=>m.stopPropagation(),onKeyDown:m=>{m.stopPropagation(),m.key==="Enter"&&l&&c!==t?h():m.key==="Escape"&&u();},"aria-label":s||"Edit field"}),l&&c!==t&&/* @__PURE__ */n(me,{children:[/* @__PURE__ */e(ie,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm edit",onClick:h,children:/* @__PURE__ */e(Ft,{className:"h-4 w-4 text-green-600"})}),/* @__PURE__ */e(ie,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel edit",onClick:u,children:/* @__PURE__ */e(it,{className:"h-4 w-4 text-muted-foreground"})})]})]});}function Mn({axis:t,label:a,type:s,config:r,onChange:o,defaultTitle:c,hidePosition:d}){var y,b,v,N,g,F,O,V,$,E,T,M,I,q;const[l,i]=U(!!(r!=null&&r.valueFormat)),h=l||!!(r!=null&&r.valueFormat),u=(P,x)=>{o({...(r??{}),[P]:x});},m=(P,x)=>{var k;const S=P==="enabled"&&x===!0&&!((k=r==null?void 0:r.name)!=null&&k.text)&&c;o(ah(r,{[P]:x,...(S?{text:c}:{})}));},p=(P,x)=>{var R,S;o({...(r??{}),labels:{enabled:P==="enabled"?x:((R=r==null?void 0:r.labels)==null?void 0:R.enabled)??!0,rotation:P==="rotation"?x:(S=r==null?void 0:r.labels)==null?void 0:S.rotation}});},f=(P,x)=>{o(nh(r,{[P]:x===""?null:Number(x)}));},w=t==="x"?["auto","top","bottom"]:["auto","left","right"],C=["auto","0","45","90","-45","-90"];return/* @__PURE__ */n(Pe,{value:`${t}-axis`,className:"border-b-0",children:[/* @__PURE__ */n("div",{className:"flex w-full items-center justify-between gap-2",children:[/* @__PURE__ */e(Re,{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(De,{size:"sm",checked:(r==null?void 0:r.enabled)!==!1,onCheckedChange:P=>u("enabled",P),onClick:P=>P.stopPropagation()})]}),/* @__PURE__ */n(Oe,{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(_t,{id:`${t}-title-enabled`,checked:((y=r==null?void 0:r.name)==null?void 0:y.enabled)??!1,onCheckedChange:P=>m("enabled",P===!0)}),/* @__PURE__ */e(A,{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(dt,{placeholder:`${a} title`,value:((v=r==null?void 0:r.name)==null?void 0:v.text)||"",onSave:P=>m("text",P),className:""}),/* @__PURE__ */n("div",{className:"flex items-center gap-3",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Size"}),/* @__PURE__ */e("div",{className:"w-14",children:/* @__PURE__ */e(dt,{type:"number",placeholder:"12",value:String(((N=r==null?void 0:r.name)==null?void 0:N.fontSize)||12),onSave:P=>m("fontSize",Number(P)||12),className:""})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Weight"}),/* @__PURE__ */n(ee,{value:((g=r==null?void 0:r.name)==null?void 0:g.fontWeight)||"normal",onValueChange:P=>m("fontWeight",P),children:[/* @__PURE__ */e(te,{className:"h-7 w-20 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"normal",className:"text-xs",children:"Normal"}),/* @__PURE__ */e(K,{value:"bold",className:"text-xs",children:"Bold"})]})]})]})]})]})]}),!d&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium",children:"POSITION"}),/* @__PURE__ */n(ee,{value:(r==null?void 0:r.position)||"auto",onValueChange:P=>u("position",P),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:w.map(P=>/* @__PURE__ */e(K,{value:P,className:"text-xs",children:P==="auto"?"Auto (Default)":ut(P)},P))})]})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium",children:"LABELS"}),/* @__PURE__ */e(De,{size:"sm",checked:((F=r==null?void 0:r.labels)==null?void 0:F.enabled)!==!1,onCheckedChange:P=>p("enabled",P)})]}),((O=r==null?void 0:r.labels)==null?void 0:O.enabled)!==!1&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Rotation"}),/* @__PURE__ */n(ee,{value:String(((V=r==null?void 0:r.labels)==null?void 0:V.rotation)||"auto"),onValueChange:P=>p("rotation",P==="auto"?"auto":Number(P)),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:C.map(P=>/* @__PURE__ */e(K,{value:P,className:"text-xs",children:P==="auto"?"Auto (Default)":`${P}°`},P))})]})]})]}),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(A,{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(De,{size:"sm",checked:h,onCheckedChange:P=>{if(i(P),!P){const{valueFormat:x,...R}=r??{};o(R);}}})]}),h&&/* @__PURE__ */e(ya,{formatOptions:Fr(r==null?void 0:r.valueFormat)||{},onFormatOptionsChange:P=>o({...r,valueFormat:Mr(P)}),showTitle:!1})]}),s==="value"&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(A,{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(A,{className:"w-8 text-xs text-muted-foreground",children:"Min"}),/* @__PURE__ */e("div",{className:"flex-1",children:/* @__PURE__ */e(dt,{type:"number",placeholder:"auto",value:(($=r==null?void 0:r.scale)==null?void 0:$.min)==="auto"||((E=r==null?void 0:r.scale)==null?void 0:E.min)===void 0?"":String(r.scale.min),onSave:P=>f("min",P),className:""})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"w-8 text-xs text-muted-foreground",children:"Max"}),/* @__PURE__ */e("div",{className:"flex-1",children:/* @__PURE__ */e(dt,{type:"number",placeholder:"auto",value:((T=r==null?void 0:r.scale)==null?void 0:T.max)==="auto"||((M=r==null?void 0:r.scale)==null?void 0:M.max)===void 0?"":String(r.scale.max),onSave:P=>f("max",P),className:""})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"w-8 text-xs text-muted-foreground",children:"Step"}),/* @__PURE__ */e("div",{className:"flex-1",children:/* @__PURE__ */e(dt,{type:"number",placeholder:"auto",value:((I=r==null?void 0:r.scale)==null?void 0:I.stepSize)==="auto"||((q=r==null?void 0:r.scale)==null?void 0:q.stepSize)===void 0?"":String(r.scale.stepSize),onSave:P=>f("stepSize",P),className:""})})]})]})]})]})]});}function An(t,a,s){var c,d,l;if(t==="x"){const i=(d=(c=a==null?void 0:a.config)==null?void 0:c.groupByColumns)==null?void 0:d[0];return(i==null?void 0:i.label)||(i==null?void 0:i.name)||"";}const r=((l=a==null?void 0:a.config)==null?void 0:l.metricColumns)||[],o=(s==null?void 0:s.datasetOptions)||[];if(t==="y"){const i=r.filter((h,u)=>{const m=o.find(p=>p.idx===u);return!m||m.yAxisId!=="y2";});return i.length===1&&(i[0].label||i[0].name)||"";}if(t==="y2"){const i=r.filter((h,u)=>{const m=o.find(p=>p.idx===u);return(m==null?void 0:m.yAxisId)==="y2";});return i.length===1&&(i[0].label||i[0].name)||"";}return"";}function Dg(){const t=D(i=>i.card),a=D(i=>{var h;return(h=i.card)==null?void 0:h.preferences;}),{setCardPreferences:s,updateCardInFrame:r}=xe(),o=Ze();if(!t||["tornado","pyramid","kpi","treemap"].includes(o))return null;const c=Yd.getAxisInfo(o,a);if(!c.hasXAxis&&!c.hasYAxis)return null;const d=(i,h)=>{let u;i==="x"?u="xAxisConfig":i==="y"?u="yAxisConfig":u="secondaryYAxisConfig";const m=th(a,u,h);s(m);const p={...t,preferences:m};r(p);},l=c.hasY2Axis&&o==="combo";return/* @__PURE__ */n(Pe,{value:"axes",className:"border-b-0",children:[/* @__PURE__ */e(Re,{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:"Axes"})]})}),/* @__PURE__ */e(Oe,{className:"pt-2",children:/* @__PURE__ */n($a,{type:"single",collapsible:!0,className:"w-full",children:[c.hasXAxis&&/* @__PURE__ */e(Mn,{axis:"x",label:"X-Axis",type:c.xAxisType,config:pn(Ns(o,"x"),a==null?void 0:a.xAxisConfig),onChange:i=>d("x",i),defaultTitle:An("x",t,a)}),c.hasYAxis&&/* @__PURE__ */e(Mn,{axis:"y",label:l?"Y-Axis (Left)":"Y-Axis",type:c.yAxisType,config:pn(Ns(o,"y"),a==null?void 0:a.yAxisConfig),onChange:i=>d("y",i),defaultTitle:An("y",t,a)}),l&&/* @__PURE__ */e(Mn,{axis:"y2",label:"Y2-Axis (Right)",type:"value",config:pn({enabled:!0,position:"right"},a==null?void 0:a.secondaryYAxisConfig),onChange:i=>d("y2",i),defaultTitle:An("y2",t,a),hidePosition:!0})]})})]});}function Eg(){const t=D(m=>m.card),a=Ze(),s=D(m=>{var p,f,w,C;return(C=(w=(f=(p=m.card)==null?void 0:p.preferences)==null?void 0:f.chartOptions)==null?void 0:w.plugins)==null?void 0:C.legend;}),{setLegendOptions:r}=xe();if(!t||!Wd(a))return null;const o=Jd(a),c=(o==null?void 0:o.display)??!0,d=(o==null?void 0:o.position)??"top",l=(o==null?void 0:o.align)??"center",i=(m,p)=>{const f={...s,[m]:p};r(f);},h=["top","bottom","left","right"],u=["start","center","end"];return/* @__PURE__ */n(Pe,{value:"legend",className:"border-b-0",children:[/* @__PURE__ */e(Re,{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(ml,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Legend"})]})}),/* @__PURE__ */e(Oe,{className:"pt-2",children:/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium",children:"Display"}),/* @__PURE__ */e(De,{size:"sm",checked:(s==null?void 0:s.display)??c,onCheckedChange:m=>i("display",m)})]}),((s==null?void 0:s.display)??c)&&/* @__PURE__ */n(me,{children:[/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium",children:"Position"}),/* @__PURE__ */n(ee,{value:(s==null?void 0:s.position)||d,onValueChange:m=>i("position",m),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:h.map(m=>/* @__PURE__ */e(K,{value:m,className:"text-xs",children:ut(m)},m))})]})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium",children:"Alignment"}),/* @__PURE__ */n(ee,{value:(s==null?void 0:s.align)||l,onValueChange:m=>i("align",m),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:u.map(m=>/* @__PURE__ */e(K,{value:m,className:"text-xs",children:ut(m)},m))})]})]})]})]})})]});}function Ig(){var q,P,x,R,S;const t=D(k=>k.card),a=Ze(),s=D(k=>{var L,_;return(_=(L=k.card)==null?void 0:L.preferences)==null?void 0:_.dataLabelsConfig;}),r=D(k=>{var L;return(L=k.card)==null?void 0:L.preferences;}),{setCardPreferences:o,updateCardInFrame:c}=xe(),[d,l]=U(!!(s!=null&&s.valueFormat));if(!t||!rh(a))return null;const i=a==="bullet"?((q=r==null?void 0:r.bulletConfig)==null?void 0:q.orientation)??(((P=r==null?void 0:r.chartOptions)==null?void 0:P.indexAxis)==="x"?"vertical":"horizontal"):void 0,h=i!=null?i==="horizontal":((x=r==null?void 0:r.chartOptions)==null?void 0:x.indexAxis)==="y",u=a==="stackedBar"||a==="stackedLine",m=a==="pie"||a==="doughnut"||a==="polarArea"||a==="funnel",p=a==="bubble"||a==="scatter",f=sh(a,t.preferences),w=s??f,C=lh(a,t.preferences),y=(s==null?void 0:s.enabled)!==void 0?s.enabled:C,b=(k,L)=>{const z=(k==="enabled"?Fs({type:a,preferences:t.preferences},{show:L}).dataLabelsConfig:void 0)??{...Ms(s,f),[k]:L};k==="enabled"&&L&&p&&!z.position&&(z.position="bottom"),k==="position"&&p&&(z.position="bottom");const j={...(t.preferences||{}),dataLabelsConfig:z};o(j);const B={...t,preferences:j};c(B);},v=(k,L)=>{const _={...Ms(s,f),font:{...((s==null?void 0:s.font)||{}),[k]:L}},z={...(t.preferences||{}),dataLabelsConfig:_};o(z);const j={...t,preferences:z};c(j);},N=()=>{const k=a;return k==="stackedBar"||k==="stackedLine"||k==="pie"||k==="doughnut"?"center":h?"right":"top";},g=a!=="treemap"&&a!=="heatmap",F=a!=="treemap",O=N();let V=[];if(g)if(p)V=["bottom"];else if(u||m)V=["center"];else{const k=h?["center","left","right"]:["center","top","bottom"];V=["auto",...(a==="bullet"?k:k.filter(_=>_!==O)),"custom"];}const $=()=>ut(O),E=["center","start","end"],T=["center","start","end","top","bottom"],M=d||!!(w!=null&&w.valueFormat),I=k=>{const L=Fs({type:a,preferences:t.preferences},{format:k??null});o(L),c({...t,preferences:L});};return/* @__PURE__ */n(Pe,{value:"data-labels",className:"border-b-0",children:[/* @__PURE__ */e(Re,{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(Fp,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Data Labels"})]})}),/* @__PURE__ */e(Oe,{className:"pt-2",children:/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium",children:"Display"}),/* @__PURE__ */e(De,{size:"sm",checked:y,onCheckedChange:k=>b("enabled",k)})]}),y&&/* @__PURE__ */n(me,{children:[g&&!u&&!m&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium",children:"Position"}),/* @__PURE__ */n(ee,{value:p?(w==null?void 0:w.position)||"bottom":(w==null?void 0:w.position)||"auto",onValueChange:k=>b("position",k),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:V.map(k=>/* @__PURE__ */e(K,{value:k,className:"text-xs",children:k==="auto"?$():k==="custom"?"Custom (Advanced)":ut(k)},k))})]})]}),u&&/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium",children:"Show Total"}),/* @__PURE__ */e(De,{size:"sm",checked:(s==null?void 0:s.showTotal)??!1,onCheckedChange:k=>b("showTotal",k)})]}),(w==null?void 0:w.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(A,{className:"text-xs text-muted-foreground w-16",children:"Anchor"}),/* @__PURE__ */n(ee,{value:(w==null?void 0:w.anchor)||"center",onValueChange:k=>b("anchor",k),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs flex-1",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:E.map(k=>/* @__PURE__ */e(K,{value:k,className:"text-xs",children:ut(k)},k))})]})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground w-16",children:"Align"}),/* @__PURE__ */n(ee,{value:String((w==null?void 0:w.align)||"center"),onValueChange:k=>b("align",k),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs flex-1",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:T.map(k=>/* @__PURE__ */e(K,{value:k,className:"text-xs",children:ut(k)},k))})]})]})]}),/* @__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(A,{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(De,{size:"sm",checked:M,onCheckedChange:k=>{l(k),k||I(void 0);}})]}),M&&/* @__PURE__ */e(ya,{formatOptions:Fr(w==null?void 0:w.valueFormat)||{},onFormatOptionsChange:k=>I(Mr(k)),showTitle:!1})]}),F&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium",children:"Appearance"}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground w-20",children:"Size"}),/* @__PURE__ */e("div",{className:"flex-1",children:/* @__PURE__ */e(dt,{type:"number",placeholder:"12",value:String(((R=w==null?void 0:w.font)==null?void 0:R.size)||12),onSave:k=>v("size",Number(k)),className:""})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground w-20",children:"Weight"}),/* @__PURE__ */n(ee,{value:((S=w==null?void 0:w.font)==null?void 0:S.weight)||"normal",onValueChange:k=>v("weight",k),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs flex-1",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"normal",className:"text-xs",children:"Normal"}),/* @__PURE__ */e(K,{value:"bold",className:"text-xs",children:"Bold"})]})]})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground w-20",children:"Color"}),/* @__PURE__ */n(ee,{value:(w==null?void 0:w.color)==="auto"||!(w!=null&&w.color)?"auto":"custom",onValueChange:k=>{k==="auto"&&b("color","auto");},children:[/* @__PURE__ */e(te,{className:"h-8 text-xs flex-1",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"auto",className:"text-xs",children:"Auto (Smart Contrast)"}),/* @__PURE__ */e(K,{value:"custom",disabled:!0,className:"text-xs",children:"Custom (Coming Soon)"})]})]})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground w-20",children:"Rotation"}),/* @__PURE__ */e("div",{className:"flex-1",children:/* @__PURE__ */e(dt,{type:"number",placeholder:"0",value:String((w==null?void 0:w.rotation)||0),onSave:k=>b("rotation",Number(k)),className:""})}),/* @__PURE__ */e("span",{className:"text-xs text-muted-foreground",children:"degrees"})]})]})]})]})})]});}function Fg(){var c;const t=D(d=>{var l;return(l=d.card)==null?void 0:l.type;}),a=D(d=>{var l;return(l=d.card)==null?void 0:l.preferences;}),{setCardPreferences:s}=xe();if(t!=="treemap")return null;const r=((c=a==null?void 0:a.chartOptions)==null?void 0:c.treemapColorMode)??"branch",o=d=>{const l={...(a||{}),chartOptions:{...(a==null?void 0:a.chartOptions),treemapColorMode:d}};s(l);};return/* @__PURE__ */n(Pe,{value:"treemap-color-mode",className:"border-none",children:[/* @__PURE__ */e(Re,{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(Dl,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Treemap Colors"})]})}),/* @__PURE__ */e(Oe,{className:"space-y-4 border-t border-border bg-background/50 px-3 py-4 text-sm",children:/* @__PURE__ */n(vr,{value:r,onValueChange:d=>o(d??"branch"),className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"flex items-start gap-2 rounded-md border border-border px-3 py-2",children:[/* @__PURE__ */e(ma,{id:"treemap-color-branch",value:"branch"}),/* @__PURE__ */n(A,{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(ma,{id:"treemap-color-category",value:"category"}),/* @__PURE__ */n(A,{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 Mg=Object.keys(Ul);function Ag(){const t=D(p=>p.card),a=D(p=>{var f;return(f=p.card)==null?void 0:f.preferences;}),{setCardPreferences:s}=xe(),r=(t==null?void 0:t.type)==="heatmap",o=(a==null?void 0:a.heatmapConfig)||{},c=o.colorPalette??"green",d=o.legendPosition??"bottom",l=Z(()=>o.colorRange&&o.colorRange[0]&&o.colorRange[1]?[o.colorRange[0],o.colorRange[1]]:[...fn],[o.colorRange]),i=p=>{const f={...o,...p};f.colorPalette!=="custom"?delete f.colorRange:(!f.colorRange||!f.colorRange[0]||!f.colorRange[1])&&(f.colorRange=[...fn]),s({...(a||{}),heatmapConfig:f});},h=p=>{i({colorPalette:p,colorRange:p==="custom"?o.colorRange??[...fn]:void 0});},u=(p,f)=>{const w=[...l];w[p]=f,i({colorPalette:"custom",colorRange:w});},m=p=>{i({legendPosition:p});};return r?/* @__PURE__ */n(Pe,{value:"heatmap-color-config",className:"border-none",children:[/* @__PURE__ */e(Re,{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(Ra,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Heatmap Settings"})]})}),/* @__PURE__ */n(Oe,{className:"space-y-4 border-t border-border bg-background/50 px-3 py-4 text-sm",children:[/* @__PURE__ */n(vr,{value:c,onValueChange:p=>h(p??"blue"),className:"space-y-3",children:[Mg.map(p=>{const f=Ul[p];return/* @__PURE__ */n("div",{className:"flex items-center gap-2 rounded-md border border-border px-3 py-2",children:[/* @__PURE__ */e(ma,{id:`heatmap-${p}`,value:p}),/* @__PURE__ */n(A,{htmlFor:`heatmap-${p}`,className:"flex w-full flex-col gap-1 text-sm font-normal",children:[/* @__PURE__ */e("span",{className:"font-medium",children:f.label}),/* @__PURE__ */e("span",{className:"h-2 rounded-full",style:{background:`linear-gradient(90deg, ${f.start}, ${f.end})`}})]})]},p);}),/* @__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(ma,{id:"heatmap-custom",value:"custom"}),/* @__PURE__ */e(A,{htmlFor:"heatmap-custom",className:"text-sm font-medium",children:"Custom colors"})]}),c==="custom"&&/* @__PURE__ */n("div",{className:"flex flex-col gap-2 pl-6",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Hn,{value:l[0],onChange:p=>u(0,p??"#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(Hn,{value:l[1],onChange:p=>u(1,p??"#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(A,{className:"text-xs font-medium",children:"Color scale position"}),/* @__PURE__ */n(ee,{value:d,onValueChange:p=>m(p??"bottom"),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:["top","bottom","left","right"].map(p=>/* @__PURE__ */e(K,{value:p,className:"text-xs",children:p[0].toUpperCase()+p.slice(1)},p))})]})]})]})]}):null;}const Zs=["poor","satisfactory","good"];function el(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 Pg(){var q,P;const t=D(x=>x.card.preferences),a=D(x=>x.card),s=D(x=>x.isDevMode),{setCardPreferences:r,setChartOrientation:o}=xe(),c=Z(()=>(t==null?void 0:t.bulletConfig)||{},[t==null?void 0:t.bulletConfig]),l=va(a==null?void 0:a.config)&&!s,[i,h]=U(c.showRanges??!1),[u,m]=U(c.rangesArePercentages??!1),p=c.disableAutoComparative?!1:c.comparativeMetricKey!==void 0||!l,[f,w]=U(p);Ne(()=>{h(c.showRanges??!1);},[c.showRanges]),Ne(()=>{m(c.rangesArePercentages??!1);},[c.rangesArePercentages]);const C=c.targetValue===void 0?"":String(c.targetValue);Ne(()=>{const x=c.disableAutoComparative?!1:c.comparativeMetricKey!==void 0||!l;w(x);},[c.disableAutoComparative,c.comparativeMetricKey,l]);const y=Z(()=>{var x,R;return((R=(x=a==null?void 0:a.config)==null?void 0:x.metricColumns)==null?void 0:R.map(S=>{const k=S.label||S.name||S.alias||"";return{value:k,label:k};}))||[];},[(q=a==null?void 0:a.config)==null?void 0:q.metricColumns]);Ne(()=>{var j,B;if(!t||y.length===0)return;const x={};let R=!1;const S=(j=y[1])==null?void 0:j.value;!c.targetMetricKey&&S&&(x.targetMetricKey=S,R=!0);const k=(B=y[2])==null?void 0:B.value;!c.comparativeMetricKey&&!c.disableAutoComparative&&k&&(x.comparativeMetricKey=k,R=!0);const L=y.slice(3),_={...(c.rangeKeys||{})};let z=!1;if(Zs.forEach((G,ce)=>{!_[G]&&L[ce]&&(_[G]=L[ce].value,z=!0);}),z&&(x.rangeKeys=_,R=!0,c.showRanges===void 0&&(x.showRanges=!0)),R){const G=el({...c,...x});r({...t,bulletConfig:G});}},[y,c,t,r]);const b=x=>{const R=el({...c,...x});r({...t,bulletConfig:R});},v=(x,R)=>{const S={...(c.rangeKeys||{}),[x]:R.trim()};R.trim()||delete S[x],b({rangeKeys:Object.keys(S).length>0?S:void 0});},N=(x,R)=>{const S=R===""?void 0:Number(R),k={...(c.ranges||{})};S===void 0||Number.isNaN(S)?delete k[x]:k[x]=S,b({ranges:Object.keys(k).length?k:void 0});},g=x=>{if(x===""){b({targetValue:void 0});return;}const R=Number(x);b({targetValue:Number.isNaN(R)?void 0:R});},F=(x,R)=>{const S=R.trim(),k={...(c.rangeLabels||{})};S?k[x]=S:delete k[x],b({rangeLabels:Object.keys(k).length>0?k:void 0});},O=x=>{h(x),b({showRanges:x});},V=x=>{m(x),b({rangesArePercentages:x});},$=c.orientation||(((P=t==null?void 0:t.chartOptions)==null?void 0:P.indexAxis)==="y"?"horizontal":"vertical"),E=x=>{b({orientation:x}),o(x==="horizontal"?"y":"x");},T=[{value:"__none",label:"None"},...y.map(x=>({value:x.value,label:x.label}))],M=T,I=x=>{if(w(x),!x){b({comparativeMetricKey:void 0,disableAutoComparative:!0});return;}if(!l){b({disableAutoComparative:!1});return;}if(c.comparativeMetricKey)b({disableAutoComparative:!1});else{const R=y.find(S=>S.value!==c.targetMetricKey);b({comparativeMetricKey:R==null?void 0:R.value,disableAutoComparative:!1});}};return/* @__PURE__ */n(Pe,{value:"bullet-config",className:"border-b-0",children:[/* @__PURE__ */e(Re,{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(kl,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Bullet Chart"})]})}),/* @__PURE__ */n(Oe,{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(A,{className:"text-xs font-medium",children:"ORIENTATION"}),/* @__PURE__ */n(ee,{value:$,onValueChange:x=>E(x),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"horizontal",className:"text-xs",children:"Horizontal"}),/* @__PURE__ */e(K,{value:"vertical",className:"text-xs",children:"Vertical"})]})]})]}),l&&/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium",children:"TARGET METRIC"}),/* @__PURE__ */n(ee,{value:c.targetMetricKey||"__none",onValueChange:x=>b({targetMetricKey:x==="__none"?void 0:x}),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{placeholder:"Select metric"})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"__none",className:"text-xs",children:"None"}),y.map(x=>/* @__PURE__ */e(K,{value:x.value,className:"text-xs",children:x.label},x.value))]})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium",children:"COMPARATIVE METRIC"}),l?/* @__PURE__ */n(ee,{value:c.comparativeMetricKey||"__none",onValueChange:x=>b({comparativeMetricKey:x==="__none"?void 0:x,disableAutoComparative:x==="__none"}),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{placeholder:"Select metric"})}),/* @__PURE__ */e(ne,{children:T.map(x=>/* @__PURE__ */e(K,{value:x.value,className:"text-xs",children:x.label},x.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(De,{size:"sm",checked:f,onCheckedChange:x=>I(x)})]}),/* @__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(A,{className:"text-xs font-medium",children:"TARGET VALUE (FALLBACK)"}),/* @__PURE__ */e(at,{type:"number",className:"h-8 text-xs",value:C,onCommit:g,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(A,{className:"text-xs font-medium",children:"QUALITATIVE RANGES"}),/* @__PURE__ */e(xt,{children:/* @__PURE__ */n(ht,{delayDuration:200,children:[/* @__PURE__ */e(pt,{asChild:!0,children:/* @__PURE__ */e("button",{type:"button",className:"text-muted-foreground transition-colors hover:text-foreground",children:/* @__PURE__ */e(Vt,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */e(ft,{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(De,{size:"sm",checked:i,onCheckedChange:O})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-2 text-xs font-medium",children:[/* @__PURE__ */e("input",{type:"checkbox",checked:u,disabled:!i,onChange:x=>V(x.target.checked),className:"h-3.5 w-3.5 accent-primary disabled:opacity-50"}),/* @__PURE__ */e("span",{children:"Use % of value"})]})]}),i&&/* @__PURE__ */e("div",{className:"space-y-3",children:Zs.map(x=>{var R,S,k,L,_;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(A,{className:"text-[11px] font-medium uppercase tracking-wide",children:[x," LABEL"]}),/* @__PURE__ */e(at,{placeholder:`Display label (${x})`,value:((R=c.rangeLabels)==null?void 0:R[x])||"",onCommit:z=>F(x,z),className:"h-8 text-xs"})]}),l?/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */n(A,{className:"text-[11px] font-medium uppercase tracking-wide",children:[x," COLUMN"]}),/* @__PURE__ */n(ee,{value:((S=c.rangeKeys)==null?void 0:S[x])||"__none",onValueChange:z=>{z==="__none"?v(x,""):v(x,z);},children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{placeholder:"Select column"})}),/* @__PURE__ */e(ne,{children:M.map(z=>/* @__PURE__ */e(K,{value:z.value,className:"text-xs",children:z.label},z.value))})]})]}):/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */n(A,{className:"text-[11px] font-medium uppercase tracking-wide",children:[x," COLUMN KEY"]}),/* @__PURE__ */e(at,{placeholder:"Column key",value:((k=c.rangeKeys)==null?void 0:k[x])||"",onCommit:z=>v(x,z),className:"h-8 text-xs"})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */n(A,{className:"text-[11px] font-medium uppercase tracking-wide",children:[x," VALUE"]}),/* @__PURE__ */e(at,{type:"number",placeholder:u?"0.80":"Static value",value:((L=c.ranges)==null?void 0:L[x])===void 0?"":String((_=c.ranges)==null?void 0:_[x]),onCommit:z=>N(x,z),className:"h-8 text-xs"})]})]},x);})})]})]})]});}function tl(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 Rg(){var F,O,V,$,E,T,M,I,q,P,x,R;const t=D(S=>S.card.preferences),a=D(S=>S.card),s=Ze(),r=D(S=>S.isDevMode),{setCardPreferences:o,updateCardInFrame:c}=xe(),d=s==="bubble",l=s==="scatter",i=Z(()=>(t==null?void 0:t.bubbleScatterConfig)||{},[t==null?void 0:t.bubbleScatterConfig]),u=va(a==null?void 0:a.config)&&!r,m=Z(()=>{var S,k;return((k=(S=a==null?void 0:a.config)==null?void 0:S.metricColumns)==null?void 0:k.map(L=>{const _=L.label||L.name||L.alias||"";return{value:_,label:_};}))||[];},[(F=a==null?void 0:a.config)==null?void 0:F.metricColumns]),p=Z(()=>{var S,k;return((k=(S=a==null?void 0:a.config)==null?void 0:S.groupByColumns)==null?void 0:k.map(L=>{const _=L.label||L.name||L.alias||"";return{value:_,label:_};}))||[];},[(O=a==null?void 0:a.config)==null?void 0:O.groupByColumns]),f=Z(()=>i.enableGrouping!==void 0?i.enableGrouping:!r&&p.length>=2,[i.enableGrouping,r,p.length]),[w,C]=U(f);Ne(()=>{C(f);},[f]);const y=S=>{const k={...(t||{}),bubbleScatterConfig:S};o(k),a&&c({...a,preferences:k});},b=S=>{o(S),a&&c({...a,preferences:S});};Ne(()=>{if(!t||m.length===0)return;const S={};let k=!1;if(!i.xMetricKey&&m[0]&&(S.xMetricKey=m[0].value,k=!0),!i.yMetricKey&&m[1]&&(S.yMetricKey=m[1].value,k=!0),d&&!i.radiusMetricKey&&m[2]&&(S.radiusMetricKey=m[2].value,k=!0),!i.labelKey&&p[0]&&(S.labelKey=p[0].value,k=!0),f&&!i.groupKey&&p[1]&&(S.groupKey=p[1].value,S.enableGrouping=!0,k=!0),k){const L=tl({...i,...S});y(L);}},[m,p,i,t,o,d,f]);const v=S=>{const k=tl({...i,...S});y(k);},N=S=>{C(S),v({enableGrouping:S,groupKey:S?i.groupKey:void 0});};return!d&&!l?null:/* @__PURE__ */n(Pe,{value:"bubble-scatter-config",children:[/* @__PURE__ */e(Re,{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?Xd:El,{className:"h-3.5 w-3.5 text-foreground/60"}),/* @__PURE__ */n("span",{children:[d?"Bubble":"Scatter"," Configuration"]})]})}),/* @__PURE__ */n(Oe,{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(xt,{children:/* @__PURE__ */n(ht,{children:[/* @__PURE__ */e(pt,{children:/* @__PURE__ */e(Vt,{className:"h-3 w-3"})}),/* @__PURE__ */e(ft,{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(A,{className:"text-xs",children:"Label Column"}),u?/* @__PURE__ */n(ee,{value:i.labelKey||"",onValueChange:S=>v({labelKey:S}),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{placeholder:"Select label column"})}),/* @__PURE__ */e(ne,{children:p.map(S=>/* @__PURE__ */e(K,{value:S.value,children:S.label},S.value))})]}):/* @__PURE__ */e(at,{className:"h-8 text-xs",placeholder:"Column name for labels",value:i.labelKey||"",onCommit:S=>v({labelKey:S})})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs",children:"Group points into series"}),/* @__PURE__ */e(De,{size:"sm",checked:w,onCheckedChange:N})]}),w&&/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs",children:"Group By"}),u?/* @__PURE__ */n(ee,{value:i.groupKey||"",onValueChange:S=>v({groupKey:S}),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{placeholder:"Select group column"})}),/* @__PURE__ */e(ne,{children:p.map(S=>/* @__PURE__ */e(K,{value:S.value,children:S.label},S.value))})]}):/* @__PURE__ */e(at,{className:"h-8 text-xs",placeholder:"Column name for grouping",value:i.groupKey||"",onCommit:S=>v({groupKey:S})})]})]}),/* @__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(A,{className:"text-xs",children:"X Axis"}),u?/* @__PURE__ */n(ee,{value:i.xMetricKey||"",onValueChange:S=>v({xMetricKey:S}),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{placeholder:"Select X metric"})}),/* @__PURE__ */e(ne,{children:m.map(S=>/* @__PURE__ */e(K,{value:S.value,children:S.label},S.value))})]}):/* @__PURE__ */e(at,{className:"h-8 text-xs",placeholder:"Column name for X axis",value:i.xMetricKey||"",onCommit:S=>v({xMetricKey:S})})]}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs",children:"Y Axis"}),u?/* @__PURE__ */n(ee,{value:i.yMetricKey||"",onValueChange:S=>v({yMetricKey:S}),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{placeholder:"Select Y metric"})}),/* @__PURE__ */e(ne,{children:m.map(S=>/* @__PURE__ */e(K,{value:S.value,children:S.label},S.value))})]}):/* @__PURE__ */e(at,{className:"h-8 text-xs",placeholder:"Column name for Y axis",value:i.yMetricKey||"",onCommit:S=>v({yMetricKey:S})})]}),d&&/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs",children:"Radius"}),u?/* @__PURE__ */n(ee,{value:i.radiusMetricKey||"",onValueChange:S=>v({radiusMetricKey:S}),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{placeholder:"Select radius metric"})}),/* @__PURE__ */e(ne,{children:m.map(S=>/* @__PURE__ */e(K,{value:S.value,children:S.label},S.value))})]}):/* @__PURE__ */e(at,{className:"h-8 text-xs",placeholder:"Column name for radius",value:i.radiusMetricKey||"",onCommit:S=>v({radiusMetricKey:S})})]})]}),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(A,{className:"text-xs",children:"Scale Mode"}),/* @__PURE__ */n(ee,{value:i.radiusScale||"sqrt",onValueChange:S=>v({radiusScale:S}),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"sqrt",children:"Square Root (area-proportional)"}),/* @__PURE__ */e(K,{value:"linear",children:"Linear"}),/* @__PURE__ */e(K,{value:"fixed",children:"Fixed Size"})]})]})]}),i.radiusScale!=="fixed"&&/* @__PURE__ */n("div",{className:"grid grid-cols-2 gap-2",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs",children:"Min Radius"}),/* @__PURE__ */e(at,{className:"h-8 text-xs",type:"number",placeholder:"5",value:((V=i.minRadius)==null?void 0:V.toString())||"",onCommit:S=>v({minRadius:S?Number(S):void 0})})]}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs",children:"Max Radius"}),/* @__PURE__ */e(at,{className:"h-8 text-xs",type:"number",placeholder:"30",value:(($=i.maxRadius)==null?void 0:$.toString())||"",onCommit:S=>v({maxRadius:S?Number(S):void 0})})]})]}),i.radiusScale==="fixed"&&/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */n(A,{className:"text-xs",children:["Fixed Radius: ",i.fixedRadius||10]}),/* @__PURE__ */e(Ia,{value:[i.fixedRadius||10],onValueChange:([S])=>v({fixedRadius:S}),min:3,max:30,step:1,className:"py-2"})]})]}),l&&/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */e("div",{className:"text-xs font-medium text-muted-foreground",children:"Point Settings"}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */n(A,{className:"text-xs",children:["Point Size: ",i.fixedRadius||5]}),/* @__PURE__ */e(Ia,{value:[i.fixedRadius||5],onValueChange:([S])=>v({fixedRadius:S}),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(De,{size:"sm",checked:((T=(E=t==null?void 0:t.xAxisConfig)==null?void 0:E.name)==null?void 0:T.enabled)??!1,onCheckedChange:S=>{var _,z,j,B;const k=i.xMetricKey||"X Axis",L=i.yMetricKey||"Y Axis";b({...(t??{}),xAxisConfig:{...(t==null?void 0:t.xAxisConfig),name:{enabled:S,text:((z=(_=t==null?void 0:t.xAxisConfig)==null?void 0:_.name)==null?void 0:z.text)||k}},yAxisConfig:{...(t==null?void 0:t.yAxisConfig),name:{enabled:S,text:((B=(j=t==null?void 0:t.yAxisConfig)==null?void 0:j.name)==null?void 0:B.text)||L}}});}})]}),((I=(M=t==null?void 0:t.xAxisConfig)==null?void 0:M.name)==null?void 0:I.enabled)&&/* @__PURE__ */n("div",{className:"grid grid-cols-2 gap-2",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs",children:"X Title"}),/* @__PURE__ */e(at,{className:"h-8 text-xs",placeholder:i.xMetricKey||"X Axis",value:((P=(q=t==null?void 0:t.xAxisConfig)==null?void 0:q.name)==null?void 0:P.text)||"",onCommit:S=>{var k;b({...(t??{}),xAxisConfig:{...(t==null?void 0:t.xAxisConfig),name:{...((k=t==null?void 0:t.xAxisConfig)==null?void 0:k.name),enabled:!0,text:S||i.xMetricKey||"X Axis"}}});}})]}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs",children:"Y Title"}),/* @__PURE__ */e(at,{className:"h-8 text-xs",placeholder:i.yMetricKey||"Y Axis",value:((R=(x=t==null?void 0:t.yAxisConfig)==null?void 0:x.name)==null?void 0:R.text)||"",onCommit:S=>{var k;b({...(t??{}),yAxisConfig:{...(t==null?void 0:t.yAxisConfig),name:{...((k=t==null?void 0:t.yAxisConfig)==null?void 0:k.name),enabled:!0,text:S||i.yMetricKey||"Y Axis"}}});}})]})]})]})]})]});}const Og=[{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 Lg(){const t=D(p=>p.card),a=D(p=>{var f;return(f=p.card)==null?void 0:f.preferences;}),{setCardPreferences:s}=xe(),r=(t==null?void 0:t.type)==="funnel",o=(a==null?void 0:a.funnelConfig)||{},c=o.percentMode??"percentOfTotal",d=o.shrinkFraction??1,l=o.labelThreshold??0,i=p=>{const f={...o,...p};s({...(a||{}),funnelConfig:f});},h=p=>{i({percentMode:p});},u=p=>{i({shrinkFraction:p[0]});},m=p=>{i({labelThreshold:p[0]});};return r?/* @__PURE__ */n(Pe,{value:"funnel-config",className:"border-none",children:[/* @__PURE__ */e(Re,{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(Zt,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Funnel Settings"})]})}),/* @__PURE__ */n(Oe,{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(A,{className:"text-xs font-medium",children:"PERCENTAGE MODE"}),/* @__PURE__ */e(vr,{value:c,onValueChange:p=>h(p),className:"space-y-2",children:Og.map(p=>/* @__PURE__ */n("div",{className:"flex items-start gap-2 rounded-md border border-border px-3 py-2",children:[/* @__PURE__ */e(ma,{id:`funnel-${p.value}`,value:p.value,className:"mt-0.5"}),/* @__PURE__ */n(A,{htmlFor:`funnel-${p.value}`,className:"flex flex-col gap-0.5 text-sm font-normal",children:[/* @__PURE__ */e("span",{className:"font-medium",children:p.label}),/* @__PURE__ */e("span",{className:"text-xs text-muted-foreground",children:p.description})]})]},p.value))})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(A,{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(Ia,{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(A,{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(Ia,{value:[l],onValueChange:m,min:0,max:25,step:1,className:"flex-1"}),/* @__PURE__ */e("span",{className:"whitespace-nowrap text-xs text-muted-foreground",children:"Hide Small"})]}),/* @__PURE__ */e("p",{className:"text-center text-xs text-muted-foreground",children:l===0?"Showing all labels":`Hide labels below ${l}%`})]})]})]}):null;}function nn(){var d,l;const t=D(i=>i.card),{data:a,comparisonMetadata:s}=nt(t),r=(a==null?void 0:a.records)||[],{keys:o}=gl(r,s),c=o.slice(1).filter(i=>!oh.includes(i));if(Zd(t.type)){const i=t.config,h=(d=i==null?void 0:i.pivotByColumns)!=null&&d.length&&(l=i==null?void 0:i.groupByColumns)!=null&&l.length?eu(r,i.metricColumns||[]):r,u=tu({card:t,cardType:t.type,records:h,columnKeyMap:a==null?void 0:a.columnKeyMap,comparisonMetadata:s});return{transformedMetricKeys:u.valueKeys,dimensionKeys:u.axisKeys,keys:o,defaultMetricKeys:c};}return{transformedMetricKeys:c,dimensionKeys:o.slice(0,1),keys:o,defaultMetricKeys:c};}const _g=[{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"}],Bg=[{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)"}],Vg=["center","start","end"],Kg=["center","start","end","top","bottom"];function rn({config:t,onChange:a,isHorizontal:s=!1,showAutoFormat:r=!0,positionOptions:o,showAppearance:c=!0}){var w,C,y,b,v,N;const d=o??(s?["auto","center","left","right","custom"]:["auto","center","top","bottom","custom"]),l=r?["auto","number","currency","percent","none"]:["number","currency","percent","none"],i=(g,F)=>{const O={...t,[g]:F};a(O);},h=(g,F)=>{const O={...t,font:{...((t==null?void 0:t.font)||{}),[g]:F}};a(O);},u=(g,F)=>{const O={...t,formatOptions:{...((t==null?void 0:t.formatOptions)||{}),[g]:F}};a(O);},m=()=>s?"Right":"Top",p=t||{},f=p.format||(r?"auto":"number");return/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Position"}),/* @__PURE__ */n(ee,{value:p.position||"auto",onValueChange:g=>i("position",g),children:[/* @__PURE__ */e(te,{className:"h-7 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:d.map(g=>/* @__PURE__ */e(K,{value:g,className:"text-xs",children:g==="auto"?m():g==="custom"?"Custom (Advanced)":ut(g)},g))})]})]}),p.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(A,{className:"text-xs",children:"Anchor"}),/* @__PURE__ */n(ee,{value:p.anchor||"center",onValueChange:g=>i("anchor",g),children:[/* @__PURE__ */e(te,{className:"h-7 w-24 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:Vg.map(g=>/* @__PURE__ */e(K,{value:g,className:"text-xs",children:ut(g)},g))})]})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs",children:"Align"}),/* @__PURE__ */n(ee,{value:String(p.align||"center"),onValueChange:g=>i("align",g),children:[/* @__PURE__ */e(te,{className:"h-7 w-24 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:Kg.map(g=>/* @__PURE__ */e(K,{value:g,className:"text-xs",children:ut(g)},g))})]})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Format"}),/* @__PURE__ */n(ee,{value:f,onValueChange:g=>i("format",g),children:[/* @__PURE__ */e(te,{className:"h-7 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:l.map(g=>/* @__PURE__ */e(K,{value:g,className:"text-xs",children:g==="auto"&&r?"Auto (Use Axis)":g==="none"?"None (Raw Value)":ut(g)},g))})]})]}),!["auto","none"].includes(f)&&/* @__PURE__ */n("div",{className:"space-y-2 rounded-md border border-border bg-background p-2",children:[["number","currency","percent"].includes(f)&&/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs",children:"Decimals"}),/* @__PURE__ */e("div",{className:"w-16",children:/* @__PURE__ */e(dt,{type:"number",placeholder:"0",value:String(((w=p.formatOptions)==null?void 0:w.decimalPlaces)??(f==="currency"?2:f==="percent"?1:0)),onSave:g=>u("decimalPlaces",Number(g)),className:""})})]}),f==="currency"&&/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs",children:"Currency"}),/* @__PURE__ */n(ee,{value:((C=p.formatOptions)==null?void 0:C.currency)||"USD",onValueChange:g=>u("currency",g),children:[/* @__PURE__ */e(te,{className:"h-7 w-28 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:_g.map(g=>/* @__PURE__ */e(K,{value:g.value,className:"text-xs",children:g.label},g.value))})]})]}),["number","currency"].includes(f)&&/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs",children:"Abbreviate (K, M, B)"}),/* @__PURE__ */e(De,{size:"sm",checked:((y=p.formatOptions)==null?void 0:y.useSuffix)??!1,onCheckedChange:g=>u("useSuffix",g)})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs",children:"Locale"}),/* @__PURE__ */n(ee,{value:((b=p.formatOptions)==null?void 0:b.locale)||"en-US",onValueChange:g=>u("locale",g),children:[/* @__PURE__ */e(te,{className:"h-7 w-28 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:Bg.map(g=>/* @__PURE__ */e(K,{value:g.value,className:"text-xs",children:g.label},g.value))})]})]})]}),c&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(A,{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(A,{className:"text-xs",children:"Size"}),/* @__PURE__ */e("div",{className:"w-16",children:/* @__PURE__ */e(dt,{type:"number",placeholder:"12",value:String(((v=p.font)==null?void 0:v.size)||12),onSave:g=>h("size",Number(g)),className:""})})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs",children:"Weight"}),/* @__PURE__ */n(ee,{value:((N=p.font)==null?void 0:N.weight)||"normal",onValueChange:g=>h("weight",g),children:[/* @__PURE__ */e(te,{className:"h-7 w-24 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"normal",className:"text-xs",children:"Normal"}),/* @__PURE__ */e(K,{value:"bold",className:"text-xs",children:"Bold"})]})]})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs",children:"Color"}),/* @__PURE__ */n(ee,{value:p.color==="auto"||!p.color?"auto":"custom",onValueChange:g=>{g==="auto"&&i("color","auto");},children:[/* @__PURE__ */e(te,{className:"h-7 w-28 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"auto",className:"text-xs",children:"Auto (Contrast)"}),/* @__PURE__ */e(K,{value:"custom",disabled:!0,className:"text-xs",children:"Custom"})]})]})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs",children:"Rotation"}),/* @__PURE__ */n("div",{className:"flex items-center gap-1",children:[/* @__PURE__ */e("div",{className:"w-12",children:/* @__PURE__ */e(dt,{type:"number",placeholder:"0",value:String(p.rotation||0),onSave:g=>i("rotation",Number(g)),className:""})}),/* @__PURE__ */e("span",{className:"text-xs text-muted-foreground",children:"°"})]})]})]})]})]});}const $g=[{type:"bar",icon:Ya,label:"Bar"},{type:"line",icon:Qa,label:"Line"}],qg=[0,1,2,3,4,5,6,8,10],zg=[{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 │"}],jg=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function Ug(){return D(a=>{var s;return(s=a.card)==null?void 0:s.type;})!=="combo"?null:/* @__PURE__ */n(Pe,{value:"combo-series",className:"border-b-0",children:[/* @__PURE__ */e(Re,{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(tn,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Series"})]})}),/* @__PURE__ */e(Oe,{className:"pt-2",children:/* @__PURE__ */e(Hg,{})})]});}function Hg(){const{transformedMetricKeys:t}=nn();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(Gg,{metricKey:a,idx:s},a))});}function Gg({metricKey:t,idx:a}){var b;const[s,r]=U(!1),o=D(v=>{var N;return(N=v.card)==null?void 0:N.preferences;}),c=D(v=>{var N,g;return(g=(N=v.card)==null?void 0:N.preferences)==null?void 0:g.datasetOptions;}),d=c==null?void 0:c.find(v=>v.idx===a),{setCardPreferences:l}=D(v=>v.actions),i=(d==null?void 0:d.type)||"bar",h=(d==null?void 0:d.yAxisId)||"y",u=((b=d==null?void 0:d.dataLabels)==null?void 0:b.enabled)??!1,m=i==="line"?Qa:Ya;function p(v){const N={idx:a,type:i,yAxisId:h,dataLabels:d==null?void 0:d.dataLabels,...v};if(!d)l({...(o||{}),datasetOptions:[...(c||[]),N]});else{const g=c==null?void 0:c.map(F=>F.idx===a?{...F,...N}:F);l({...(o||{}),datasetOptions:g});}}function f(v){p({type:v});}function w(v){p({yAxisId:v});}function C(v){p({dataLabels:{...(d==null?void 0:d.dataLabels),enabled:v}});}function y(v){p({dataLabels:v});}return/* @__PURE__ */e($t,{open:s,onOpenChange:r,children:/* @__PURE__ */n("div",{className:"rounded-lg border border-border bg-muted/30",children:[/* @__PURE__ */e(qt,{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(zt,{className:H("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:H("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(m,{className:"h-3 w-3"}),i==="line"?"Line":"Bar"]}),/* @__PURE__ */e("span",{className:H("rounded px-1.5 py-0.5 text-xs","border border-border bg-background text-muted-foreground"),children:h==="y2"?"Y2":"Y1"})]})]})}),/* @__PURE__ */e(jt,{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(A,{className:"text-xs text-muted-foreground",children:"Chart Type"}),/* @__PURE__ */e("div",{className:"flex gap-2",children:$g.map(({type:v,icon:N,label:g})=>/* @__PURE__ */n("button",{onClick:()=>f(v),className:H("flex items-center gap-2 rounded-md border px-3 py-1.5 text-xs transition-colors",i===v?"border-primary bg-primary/10 text-primary":"border-border bg-background text-muted-foreground hover:bg-muted"),children:[/* @__PURE__ */e(N,{className:"h-3.5 w-3.5 text-foreground/60"}),/* @__PURE__ */e("span",{children:g})]},v))})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Axis"}),/* @__PURE__ */n(ee,{value:h,onValueChange:v=>w(v),children:[/* @__PURE__ */e(te,{className:"h-8 w-20 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"y",className:"text-xs",children:"Y1 (Left)"}),/* @__PURE__ */e(K,{value:"y2",className:"text-xs",children:"Y2 (Right)"})]})]})]})]}),i==="line"&&/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */e(A,{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(A,{className:"text-xs text-muted-foreground",children:"Pattern"}),/* @__PURE__ */n(ee,{value:(d==null?void 0:d.lineStyle)||"solid",onValueChange:v=>p({lineStyle:v}),children:[/* @__PURE__ */e(te,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:jg.map(({value:v,label:N})=>/* @__PURE__ */e(K,{value:v,className:"text-xs",children:N},v))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Point Size"}),/* @__PURE__ */n(ee,{value:String((d==null?void 0:d.pointRadius)??3),onValueChange:v=>p({pointRadius:Number(v)}),children:[/* @__PURE__ */e(te,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:qg.map(v=>/* @__PURE__ */e(K,{value:String(v),className:"text-xs",children:v===0?"None":v},v))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Point Shape"}),/* @__PURE__ */n(ee,{value:(d==null?void 0:d.pointStyle)||"circle",onValueChange:v=>p({pointStyle:v}),children:[/* @__PURE__ */e(te,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:zg.map(({value:v,label:N})=>/* @__PURE__ */e(K,{value:v,className:"text-xs",children:N},v))})]})]})]})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Data Labels"}),/* @__PURE__ */e(De,{size:"sm",checked:u,onCheckedChange:C})]}),u&&/* @__PURE__ */e("div",{className:"rounded-md border border-border bg-background p-2",children:/* @__PURE__ */e(rn,{config:d==null?void 0:d.dataLabels,onChange:y,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})});}const Pn=[{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"}],Qg=[0,1,2,3,4,5,6,8,10],Yg=[{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 │"}],Wg=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function Jg(t){return t==null?"origin":t===!1?"false":t;}function Xg(){const t=D(a=>{var s;return(s=a.card)==null?void 0:s.type;});return t!=="area"&&t!=="stackedArea"?null:/* @__PURE__ */n(Pe,{value:"area-series",className:"border-b-0",children:[/* @__PURE__ */e(Re,{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(tn,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Series"})]})}),/* @__PURE__ */e(Oe,{className:"pt-2",children:/* @__PURE__ */e(Zg,{})})]});}function Zg(){const{transformedMetricKeys:t}=nn();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(ex,{metricKey:a,idx:s},a))});}function ex({metricKey:t,idx:a}){var C;const[s,r]=U(!1),o=D(y=>{var b;return(b=y.card)==null?void 0:b.preferences;}),c=D(y=>{var b,v;return(v=(b=y.card)==null?void 0:b.preferences)==null?void 0:v.datasetOptions;}),d=c==null?void 0:c.find(y=>y.idx===a),{setCardPreferences:l}=D(y=>y.actions),i=Jg(d==null?void 0:d.fill),h=((C=d==null?void 0:d.dataLabels)==null?void 0:C.enabled)??!1,u=Pn.find(y=>y.value===i)||Pn[0];function m(y){const b={idx:a,fill:i,dataLabels:d==null?void 0:d.dataLabels,...y};if(!d)l({...(o||{}),datasetOptions:[...(c||[]),b]});else{const v=c==null?void 0:c.map(N=>N.idx===a?{...N,...b}:N);l({...(o||{}),datasetOptions:v});}}function p(y){m({fill:y==="false"?!1:y});}function f(y){m({dataLabels:{...(d==null?void 0:d.dataLabels),enabled:y}});}function w(y){m({dataLabels:y});}return/* @__PURE__ */e($t,{open:s,onOpenChange:r,children:/* @__PURE__ */n("div",{className:"rounded-lg border border-border bg-muted/30",children:[/* @__PURE__ */e(qt,{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(zt,{className:H("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:H("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(Hl,{className:"h-3 w-3"}),u.label.split(" ")[0]]})})]})}),/* @__PURE__ */e(jt,{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(A,{className:"text-xs text-muted-foreground",children:"Fill Target"}),/* @__PURE__ */n(ee,{value:i,onValueChange:y=>p(y),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:Pn.map(y=>/* @__PURE__ */e(K,{value:y.value,className:"text-xs",children:/* @__PURE__ */e("div",{className:"flex flex-col",children:/* @__PURE__ */e("span",{children:y.label})})},y.value))})]})]}),/* @__PURE__ */n("div",{className:"space-y-3",children:[/* @__PURE__ */e(A,{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(A,{className:"text-xs text-muted-foreground",children:"Pattern"}),/* @__PURE__ */n(ee,{value:(d==null?void 0:d.lineStyle)||"solid",onValueChange:y=>m({lineStyle:y}),children:[/* @__PURE__ */e(te,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:Wg.map(({value:y,label:b})=>/* @__PURE__ */e(K,{value:y,className:"text-xs",children:b},y))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Point Size"}),/* @__PURE__ */n(ee,{value:String((d==null?void 0:d.pointRadius)??3),onValueChange:y=>m({pointRadius:Number(y)}),children:[/* @__PURE__ */e(te,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:Qg.map(y=>/* @__PURE__ */e(K,{value:String(y),className:"text-xs",children:y===0?"None":y},y))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Point Shape"}),/* @__PURE__ */n(ee,{value:(d==null?void 0:d.pointStyle)||"circle",onValueChange:y=>m({pointStyle:y}),children:[/* @__PURE__ */e(te,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:Yg.map(({value:y,label:b})=>/* @__PURE__ */e(K,{value:y,className:"text-xs",children:b},y))})]})]})]})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Data Labels"}),/* @__PURE__ */e(De,{size:"sm",checked:h,onCheckedChange:f})]}),h&&/* @__PURE__ */e("div",{className:"rounded-md border border-border bg-background p-2",children:/* @__PURE__ */e(rn,{config:d==null?void 0:d.dataLabels,onChange:w,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})});}const tx=[0,1,2,3,4,5,6,8,10],ax=[{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 │"}],Rn=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function nx(){return D(a=>{var s;return(s=a.card)==null?void 0:s.type;})!=="line"?null:/* @__PURE__ */n(Pe,{value:"line-series",className:"border-b-0",children:[/* @__PURE__ */e(Re,{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(tn,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Series"})]})}),/* @__PURE__ */e(Oe,{className:"pt-2",children:/* @__PURE__ */e(rx,{})})]});}function rx(){const{transformedMetricKeys:t}=nn();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(sx,{metricKey:a,idx:s},a))});}function sx({metricKey:t,idx:a}){var y;const[s,r]=U(!1),o=D(b=>{var v;return(v=b.card)==null?void 0:v.preferences;}),c=D(b=>{var v,N;return(N=(v=b.card)==null?void 0:v.preferences)==null?void 0:N.datasetOptions;}),d=c==null?void 0:c.find(b=>b.idx===a),{setCardPreferences:l}=D(b=>b.actions),i=(d==null?void 0:d.lineStyle)||"solid",h=(d==null?void 0:d.pointRadius)??3,u=(d==null?void 0:d.pointStyle)||"circle",m=((y=d==null?void 0:d.dataLabels)==null?void 0:y.enabled)??!1,p=Rn.find(b=>b.value===i)||Rn[0];function f(b){const v={idx:a,lineStyle:i,pointRadius:h,pointStyle:u,dataLabels:d==null?void 0:d.dataLabels,...b};if(!d)l({...(o||{}),datasetOptions:[...(c||[]),v]});else{const N=c==null?void 0:c.map(g=>g.idx===a?{...g,...v}:g);l({...(o||{}),datasetOptions:N});}}function w(b){f({dataLabels:{...(d==null?void 0:d.dataLabels),enabled:b}});}function C(b){f({dataLabels:b});}return/* @__PURE__ */e($t,{open:s,onOpenChange:r,children:/* @__PURE__ */n("div",{className:"rounded-lg border border-border bg-muted/30",children:[/* @__PURE__ */e(qt,{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(zt,{className:H("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:H("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(Ao,{className:"h-3 w-3"}),p.label.split(" ")[0]]})})]})}),/* @__PURE__ */e(jt,{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(A,{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(A,{className:"text-xs text-muted-foreground",children:"Pattern"}),/* @__PURE__ */n(ee,{value:i,onValueChange:b=>f({lineStyle:b}),children:[/* @__PURE__ */e(te,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:Rn.map(({value:b,label:v})=>/* @__PURE__ */e(K,{value:b,className:"text-xs",children:v},b))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Point Size"}),/* @__PURE__ */n(ee,{value:String(h),onValueChange:b=>f({pointRadius:Number(b)}),children:[/* @__PURE__ */e(te,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:tx.map(b=>/* @__PURE__ */e(K,{value:String(b),className:"text-xs",children:b===0?"None":b},b))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Point Shape"}),/* @__PURE__ */n(ee,{value:u,onValueChange:b=>f({pointStyle:b}),children:[/* @__PURE__ */e(te,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:ax.map(({value:b,label:v})=>/* @__PURE__ */e(K,{value:b,className:"text-xs",children:v},b))})]})]})]})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Data Labels"}),/* @__PURE__ */e(De,{size:"sm",checked:m,onCheckedChange:w})]}),m&&/* @__PURE__ */e("div",{className:"rounded-md border border-border bg-background p-2",children:/* @__PURE__ */e(rn,{config:d==null?void 0:d.dataLabels,onChange:C,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})});}const lx=[0,2,4,6,8,10,12,16,20];function ox(){const t=D(a=>{var s;return(s=a.card)==null?void 0:s.type;});return!t||!["bar","horizontalBar","stackedBar"].includes(t)?null:/* @__PURE__ */n(Pe,{value:"bar-series",className:"border-b-0",children:[/* @__PURE__ */e(Re,{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(tn,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Series"})]})}),/* @__PURE__ */e(Oe,{className:"pt-2",children:/* @__PURE__ */e(ix,{})})]});}function ix(){const{transformedMetricKeys:t}=nn();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(cx,{metricKey:a,idx:s},a))});}function cx({metricKey:t,idx:a}){var w;const[s,r]=U(!1),o=D(C=>{var y;return(y=C.card)==null?void 0:y.type;}),c=D(C=>{var y;return(y=C.card)==null?void 0:y.preferences;}),d=D(C=>{var y,b;return(b=(y=C.card)==null?void 0:y.preferences)==null?void 0:b.datasetOptions;}),l=d==null?void 0:d.find(C=>C.idx===a),{setCardPreferences:i}=D(C=>C.actions),h=(l==null?void 0:l.borderRadius)??0,u=((w=l==null?void 0:l.dataLabels)==null?void 0:w.enabled)??!1;function m(C){const y={idx:a,borderRadius:h,dataLabels:l==null?void 0:l.dataLabels,...C};if(!l)i({...(c||{}),datasetOptions:[...(d||[]),y]});else{const b=d==null?void 0:d.map(v=>v.idx===a?{...v,...y}:v);i({...(c||{}),datasetOptions:b});}}function p(C){m({dataLabels:{...(l==null?void 0:l.dataLabels),enabled:C}});}function f(C){m({dataLabels:C});}return/* @__PURE__ */e($t,{open:s,onOpenChange:r,children:/* @__PURE__ */n("div",{className:"rounded-lg border border-border bg-muted/30",children:[/* @__PURE__ */e(qt,{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(zt,{className:H("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:h>0&&/* @__PURE__ */n("span",{className:H("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(Jl,{className:"h-3 w-3"}),"r:",h]})})]})}),/* @__PURE__ */e(jt,{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(A,{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(A,{className:"text-xs text-muted-foreground",children:"Corner Radius"}),/* @__PURE__ */n(ee,{value:String(h),onValueChange:C=>m({borderRadius:Number(C)}),children:[/* @__PURE__ */e(te,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:lx.map(C=>/* @__PURE__ */e(K,{value:String(C),className:"text-xs",children:C===0?"None":`${C}px`},C))})]})]})})]}),/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{className:"text-xs text-muted-foreground",children:"Data Labels"}),/* @__PURE__ */e(De,{size:"sm",checked:u,onCheckedChange:p})]}),u&&/* @__PURE__ */e("div",{className:"rounded-md border border-border bg-background p-2",children:/* @__PURE__ */e(rn,{config:l==null?void 0:l.dataLabels,onChange:f,isHorizontal:o==="horizontalBar",showAutoFormat:!0,showAppearance:!0})})]})]})})})]})});}const dx=[0,1,2,3,4,5,6,8,10],ux=[{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 │"}],mx=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function hx(){const t=D(l=>l.card),a=D(l=>{var i;return(i=l.card)==null?void 0:i.preferences;}),s=Ze(),r=a==null?void 0:a.lineStyleConfig,{setCardPreferences:o,updateCardInFrame:c}=xe();if(!t||!["line","area","stackedArea"].includes(s))return null;const d=(l,i)=>{const h={...(a||{}),lineStyleConfig:{...r,[l]:i}};o(h),c({...t,preferences:h});};return/* @__PURE__ */n(Pe,{value:"line-style",className:"border-b-0",children:[/* @__PURE__ */e(Re,{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(Ep,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Line Style"})]})}),/* @__PURE__ */e(Oe,{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(A,{className:"text-xs font-medium",children:"Line Pattern"}),/* @__PURE__ */n(ee,{value:(r==null?void 0:r.lineStyle)||"solid",onValueChange:l=>d("lineStyle",l),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:mx.map(({value:l,label:i})=>/* @__PURE__ */e(K,{value:l,className:"text-xs",children:i},l))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium",children:"Point Size"}),/* @__PURE__ */n(ee,{value:String((r==null?void 0:r.pointRadius)??3),onValueChange:l=>d("pointRadius",Number(l)),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:dx.map(l=>/* @__PURE__ */e(K,{value:String(l),className:"text-xs",children:l===0?"None":l},l))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium",children:"Point Shape"}),/* @__PURE__ */n(ee,{value:(r==null?void 0:r.pointStyle)||"circle",onValueChange:l=>d("pointStyle",l),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:ux.map(({value:l,label:i})=>/* @__PURE__ */e(K,{value:l,className:"text-xs",children:i},l))})]})]})]})})]});}const px=[0,2,4,6,8,10,12,16,20],fx=[{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%"}],gx=[{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 xx(){const t=D(l=>l.card),a=D(l=>{var i;return(i=l.card)==null?void 0:i.preferences;}),s=Ze(),r=a==null?void 0:a.barStyleConfig,{setCardPreferences:o,updateCardInFrame:c}=xe();if(!t||!["bar","horizontalBar","stackedBar"].includes(s))return null;const d=(l,i)=>{const h={...(a||{}),barStyleConfig:{...r,[l]:i}};o(h),c({...t,preferences:h});};return/* @__PURE__ */n(Pe,{value:"bar-style",className:"border-b-0",children:[/* @__PURE__ */e(Re,{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(Jl,{className:"h-4 w-4 text-muted-foreground"}),/* @__PURE__ */e("span",{children:"Bar Style"})]})}),/* @__PURE__ */e(Oe,{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(A,{className:"text-xs font-medium",children:"Corner Radius"}),/* @__PURE__ */n(ee,{value:String((r==null?void 0:r.borderRadius)??0),onValueChange:l=>d("borderRadius",Number(l)),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:px.map(l=>/* @__PURE__ */e(K,{value:String(l),className:"text-xs",children:l===0?"None":`${l}px`},l))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium",children:"Bar Width"}),/* @__PURE__ */n(ee,{value:String((r==null?void 0:r.barPercentage)??0.9),onValueChange:l=>d("barPercentage",Number(l)),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:fx.map(({value:l,label:i})=>/* @__PURE__ */e(K,{value:l,className:"text-xs",children:i},l))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium",children:"Category Width"}),/* @__PURE__ */n(ee,{value:String((r==null?void 0:r.categoryPercentage)??0.8),onValueChange:l=>d("categoryPercentage",Number(l)),children:[/* @__PURE__ */e(te,{className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */e(ne,{children:gx.map(({value:l,label:i})=>/* @__PURE__ */e(K,{value:l,className:"text-xs",children:i},l))})]})]})]})})]});}function bx(){const t=D(s=>{var r,o;return(o=(r=s==null?void 0:s.card)==null?void 0:r.preferences)==null?void 0:o.sortChart;}),{setSortChart:a}=xe();return/* @__PURE__ */n(Pe,{value:"stacked-sort",children:[/* @__PURE__ */e(Re,{children:/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(Fo,{className:"h-3.5 w-3.5 text-foreground/60"}),"Sort"]})}),/* @__PURE__ */e(Oe,{className:"space-y-4 px-1",children:/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(A,{children:"Sort Order"}),/* @__PURE__ */e(Ea,{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 vx=["kpi"],On=2;function Lt(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 yx(t){if(!(t!=null&&t.name)||!(t!=null&&t.dataType)||t.role==="metric")return!1;const a=co(t.dataType);return["date","string","boolean"].includes(a);}function Nx(t){return{...t,role:"groupby"};}function Cx(){var v,N;const t=D(g=>g.card),a=D(g=>g.actions.updateCardConfig),s=Ze(),{scopedFields:r}=Gl(),o=((v=t.config)==null?void 0:v.metricColumns)||[],c=((N=t.config)==null?void 0:N.summary)||{},d=c.breakdownDimensions||[],l=d.length>0,i=vx.includes(s),h=o.length>0,u=c.enabled===!0,m=i&&h,p=Array.from(new Map(r.filter(yx).map(g=>[Lt(g),Nx(g)])).values()),f=new Set(p.map(g=>Lt(g))),w=new Set(d.map(g=>Lt(g)).filter(g=>g&&f.has(g)));if(!i)return null;const C=g=>{a(t.id,{summary:{...c,...g}});},y=(g,F)=>{const O=Lt(g),V=p.filter(E=>w.has(Lt(E))),$=F?w.has(O)?V:[...V,g].slice(0,On):V.filter(E=>Lt(E)!==O);C({breakdownDimensions:$,...($.length>0?{showOnCard:!0}:{})});};return/* @__PURE__ */n(Pe,{value:"summary",className:"border-none",children:[/* @__PURE__ */e(Re,{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(au,{className:"h-3.5 w-3.5 text-foreground/60"}),/* @__PURE__ */e("span",{children:"Summary"})]})}),/* @__PURE__ */n(Oe,{className:"space-y-3 pb-4 pt-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{htmlFor:"summary-enabled",className:"text-xs",children:"Show summary"}),/* @__PURE__ */e(De,{id:"summary-enabled",size:"xs",checked:u,disabled:!m,onCheckedChange:g=>{if(!g){C({enabled:!1,showOnCard:!1,includeInDashboardSummary:!1});return;}C({enabled:!0,showOnCard:c.showOnCard??!0,includeInDashboardSummary:c.includeInDashboardSummary??!0});}})]}),/* @__PURE__ */n("div",{className:H("space-y-3 transition-opacity",!u&&"opacity-60"),children:[!m&&/* @__PURE__ */e("p",{className:"text-[11px] text-muted-foreground",children:h?"Summary is not supported for this card type.":"Add at least one metric to enable summary."}),!l&&/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(_t,{id:"summary-show-on-card",checked:c.showOnCard===!0,disabled:!u,onCheckedChange:g=>C({showOnCard:g===!0})}),/* @__PURE__ */e(A,{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(_t,{id:"summary-include-rollup",checked:c.includeInDashboardSummary===!0,disabled:!u,onCheckedChange:g=>C({includeInDashboardSummary:g===!0})}),/* @__PURE__ */e(A,{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(A,{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,"/",On]})]}),p.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:p.map(g=>{const F=Lt(g),O=w.has(F),V=w.size>=On,$=!u||!O&&V;return/* @__PURE__ */n("li",{className:"flex items-center gap-2 text-xs",children:[/* @__PURE__ */e(_t,{id:`summary-breakdown-${F}`,checked:O,disabled:$,onCheckedChange:E=>y(g,E===!0)}),/* @__PURE__ */e(A,{htmlFor:`summary-breakdown-${F}`,className:"cursor-pointer text-xs",children:g.label||g.name})]},F);})})]})]})]})]});}const wx={hour:"Hour",minute:"Minute",second:"Second",day:"Day",week:"Week",month:"Month",quarter:"Quarter",year:"Year"},Ln=t=>wx[t??"day"]??"Day";function Sx(){const t=D(a=>a.card);return!t||t.type!=="kpi"||wr(t)?null:/* @__PURE__ */e(Tx,{card:t});}function Tx({card:t}){var f,w,C,y,b;const{setCardConfig:a}=xe(),{data:s}=nt(t),r=s==null?void 0:s.metadata,o=ih(t.config),c=!!(r!=null&&r.dateContext&&!r.dateContext.field&&!o),d=((f=t.config)==null?void 0:f.kpiBand)==="trend",l=((w=t.config)==null?void 0:w.kpiTrendGrain)??"automatic",i=((y=(C=r==null?void 0:r.dateContext)==null?void 0:C.counted)==null?void 0:y.status)==="window"?r.dateContext.counted.window:void 0,h=((b=r==null?void 0:r.trend)==null?void 0:b.grainSource)==="automatic"?r.trend.granularity:void 0,u=v=>a(uh(t,v).config),m=v=>a(mh(t,v==="automatic"?null:v).config),p=c?d?"This KPI counts on no date, so the trend can't show. Turn it off, or drop a date on Trend By.":"This KPI counts on no date. Drop a date on Trend By to show a trend.":d?o?"Trend By sets the grain. Remove it to pick one here.":l==="automatic"?"Follows the period the KPI counts: a different dashboard date changes it.":`Always by ${l}.`:"A line of the value over the period it counts.";return(/* @__PURE__ */n(Pe,{value:"kpi-trend",className:"border-none","data-role":"kpi-trend-settings",children:[/* @__PURE__ */e(Re,{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(Ao,{className:"h-3.5 w-3.5 text-foreground/60","aria-hidden":!0}),/* @__PURE__ */e("span",{children:"Trend"})]})}),/* @__PURE__ */n(Oe,{className:"space-y-3 pb-4 pt-2",children:[/* @__PURE__ */n("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */e(A,{htmlFor:"kpi-trend",className:"text-xs",children:"Show trend"}),/* @__PURE__ */e(De,{id:"kpi-trend",size:"xs",checked:d,disabled:c&&!d,onCheckedChange:u})]}),d&&!c&&/* @__PURE__ */n("div",{className:"space-y-2","data-role":"kpi-trend-grain",children:[/* @__PURE__ */e(A,{htmlFor:"kpi-trend-grain",className:"text-xs",children:"Grain"}),o?/* @__PURE__ */n("div",{className:"flex h-8 items-center justify-between rounded-control border border-border bg-muted/30 px-2.5 text-xs text-foreground/80",children:[Ln(o.granularity)," · from Trend By",/* @__PURE__ */e(nu,{className:"h-3 w-3 text-muted-foreground","aria-hidden":!0})]}):/* @__PURE__ */n(ee,{value:l,onValueChange:m,children:[/* @__PURE__ */e(te,{id:"kpi-trend-grain",className:"h-8 text-xs",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"automatic",className:"text-xs",children:h?`Automatic · ${Ln(h)}`:"Automatic"}),mp.map(v=>{const N=i?ch(i,v)>dh:!1;return/* @__PURE__ */n(K,{value:v,className:"text-xs",disabled:N&&v!==l,children:[Ln(v),N?" · too many points":""]},v);})]})]})]}),/* @__PURE__ */e("p",{className:"text-[11px] text-muted-foreground",children:p})]})]}));}const kx=/* @__PURE__ */new Set(["area","bar","bubble","bullet","combo","doughnut","funnel","horizontalBar","line","pie","polarArea","radar","scatter","stackedArea","stackedBar","stackedLine","tornado"]);function Dx(){const t=D(u=>u.card),a=D(u=>{var m;return(m=u.card)==null?void 0:m.preferences;}),s=Ze(),{setCardPreferences:r,updateCardInFrame:o}=xe(),c=a==null?void 0:a.tooltipConfig,[d,l]=U(!!(c!=null&&c.valueFormat));if(!t||!kx.has(s||""))return null;const i=d||c!=null&&c.valueFormat?"override":"inherit",h=u=>{const m={...(a||{}),tooltipConfig:u};r(m),o({...t,preferences:m});};return/* @__PURE__ */n(Pe,{value:"tooltip-format",className:"border-b-0",children:[/* @__PURE__ */e(Re,{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(Vt,{className:"h-3.5 w-3.5 text-foreground/60"}),/* @__PURE__ */e("span",{children:"Tooltip Format"})]})}),/* @__PURE__ */n(Oe,{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(A,{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(De,{size:"sm",checked:i==="override",onCheckedChange:u=>{if(l(u),!u){const{valueFormat:m,...p}=c??{};h(p);}}})]}),i==="override"&&/* @__PURE__ */e(ya,{formatOptions:Fr(c==null?void 0:c.valueFormat)||{},onFormatOptionsChange:u=>h({...c,valueFormat:Mr(u)}),showTitle:!1})]})]});}function mi({mode:t}){const a=D(s=>{var r;return(r=s.card)==null?void 0:r.type;});return xo(a)?null:/* @__PURE__ */n(me,{children:[a==="combo"&&/* @__PURE__ */e(Ug,{}),(a==="area"||a==="stackedArea")&&/* @__PURE__ */e(Xg,{}),a==="line"&&/* @__PURE__ */e(nx,{}),(a==="bar"||a==="horizontalBar"||a==="stackedBar")&&/* @__PURE__ */e(ox,{}),/* @__PURE__ */e(hx,{}),/* @__PURE__ */e(xx,{}),/* @__PURE__ */e(Fg,{}),t==="config"&&/* @__PURE__ */e(bg,{}),t==="config"&&/* @__PURE__ */e(Cx,{}),t==="config"&&/* @__PURE__ */e(Sx,{}),/* @__PURE__ */e(Ag,{}),a==="bullet"&&/* @__PURE__ */e(Pg,{}),a==="funnel"&&/* @__PURE__ */e(Lg,{}),(a==="bubble"||a==="scatter")&&/* @__PURE__ */e(Rg,{}),(a==="stackedBar"||a==="stackedLine")&&/* @__PURE__ */e(bx,{}),/* @__PURE__ */e(kg,{}),/* @__PURE__ */e(Dg,{}),/* @__PURE__ */e(Eg,{}),/* @__PURE__ */e(Ig,{}),/* @__PURE__ */e(Dx,{})]});}function Ex(){const t=D(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(si,{chartType:a}),/* @__PURE__ */e($a,{type:"single",collapsible:!0,className:"w-full px-2",children:/* @__PURE__ */e(mi,{mode:"dev"})})]}):null;}function Ix({focusSection:t,focusRequestId:a}){const r=D(c=>c.card).type;function o(){if(Tr(r))return/* @__PURE__ */e(ui,{cardType:r,focusSection:t,focusRequestId:a});switch(r){case"kpi":return/* @__PURE__ */e(ag,{});case"custom":return/* @__PURE__ */e("div",{className:"px-6 py-2",children:/* @__PURE__ */e(ei,{})});case"text":return/* @__PURE__ */e(Ng,{});default:return/* @__PURE__ */e(Ex,{});}}return/* @__PURE__ */n(Cr,{className:"h-full w-full text-sm",children:[o(),/* @__PURE__ */e(tm,{orientation:"horizontal"})]});}const Fx=32;function Mx(){const t=Ae(null),a=D(m=>m.isDevMode),[s,r]=U(!1),[o,c]=U({section:null,id:0}),d=!a||s,l=()=>r(m=>!m),i=m=>{m&&c(p=>({section:m,id:p.id+1})),a&&r(!0);},h=()=>{const m=t.current;m&&(m.isCollapsed()?m.expand():m.collapse());},u={show:a,isOpen:d,onToggle:l,onOpen:i};return/* @__PURE__ */n(tr,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[/* @__PURE__ */e(Gt,{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(Zp,{})})}),/* @__PURE__ */e(Vf,{onToggleEditor:h,children:/* @__PURE__ */e(Dn,{mode:"toolbar",visualAsideControl:u})}),/* @__PURE__ */e(Gt,{role:"visual-section",minSize:0,defaultSize:50,children:d?/* @__PURE__ */n(tr,{direction:"horizontal",children:[/* @__PURE__ */e(Gt,{minSize:40,defaultSize:75,maxSize:100,children:/* @__PURE__ */e(Dn,{mode:"canvas",visualAsideControl:u})}),/* @__PURE__ */e(Lo,{}),/* @__PURE__ */e(Gt,{className:"flex",defaultSize:Fx,maxSize:45,children:/* @__PURE__ */e(Ix,{focusSection:o.section,focusRequestId:o.id})})]}):/* @__PURE__ */e(Dn,{mode:"canvas",visualAsideControl:u})})]});}function $r({children:t,className:a,delayDuration:s}){return/* @__PURE__ */e(xt,{children:/* @__PURE__ */n(ht,{delayDuration:s,children:[/* @__PURE__ */e(pt,{asChild:!0,children:/* @__PURE__ */e("span",{className:H("overflow-hidden text-ellipsis whitespace-nowrap",a),children:t})}),/* @__PURE__ */e(ft,{children:t})]})});}function Ax({field:t,title:a}){const s=hh(t),r=s?ru(t.fieldScope):"Column",o=s?Rx(t):Ox(t);return/* @__PURE__ */n("div",{className:"shrink-0 space-y-0.5 border-b border-border px-3 py-2",onPointerDown:c=>c.stopPropagation(),children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-center justify-between gap-2",children:[/* @__PURE__ */e("span",{className:"min-w-0 truncate text-sm font-medium text-foreground",title:a,children:a}),/* @__PURE__ */e("span",{className:H("shrink-0 whitespace-nowrap rounded-[4px] px-1.5 py-px text-[11px]",s?"bg-primary/10 text-primary":"bg-muted text-muted-foreground"),children:r})]}),o&&s&&/* @__PURE__ */e(Px,{formula:o}),o&&!s&&/* @__PURE__ */e("div",{className:"truncate text-xs text-muted-foreground",title:o,children:o})]});}function Px({formula:t}){const[a,s]=U(!1);return/* @__PURE__ */e("button",{type:"button","aria-expanded":a,title:a?void 0:t,onClick:()=>s(r=>!r),className:H("block w-full cursor-pointer whitespace-pre-wrap text-left font-mono text-xs text-muted-foreground [overflow-wrap:anywhere] hover:text-foreground",a?"max-h-32 overflow-y-auto":"line-clamp-2"),children:t});}function Rx(t){const a=ph(t);return a?`= ${a}`:t.calculatedFormula&&t.calculatedFormula.operation!=="custom"?`= ${fh(t.calculatedFormula)}`:null;}function Ox(t){return t.name?t.entityName?`${t.entityName} · ${t.name}`:t.name:null;}function Lx({label:t}){const a=t.indexOf(" › ");return a<0?/* @__PURE__ */e(me,{children:t}):/* @__PURE__ */n(me,{children:[t.slice(0,a)," ",/* @__PURE__ */e("span",{className:"mx-1 text-muted-foreground",children:"›"})," ",t.slice(a+3)]});}function hi({id:t,field:a,zone:s,label:r,dataType:o,nativeDataType:c,calculated:d,open:l,onOpenChange:i,onRemove:h,sortDirection:u,onSortDirectionChange:m,badge:p,children:f}){const{attributes:w,listeners:C,setNodeRef:y,isDragging:b}=su({id:lu(t),data:{origin:s,field:a}}),{setNodeRef:v}=Ql({id:ou(t),data:{kind:"pill",zone:s,pillId:t}}),N=Je(g=>{y(g),v(g);},[y,v]);return/* @__PURE__ */n(bt,{modal:!0,open:l,onOpenChange:i,children:[/* @__PURE__ */n("div",{ref:N,className:H("group flex h-7 w-full items-center gap-1.5 rounded-control border bg-background px-1.5 transition-colors",l?"border-foreground/30 bg-muted/40":"border-border hover:bg-muted/40",b&&"z-50 scale-95 opacity-50"),children:[/* @__PURE__ */e("button",{type:"button",...w,...C,"aria-label":`Drag ${r}`,className:iu,onClick:g=>g.stopPropagation(),children:/* @__PURE__ */e(ir,{className:"h-3 w-3"})}),/* @__PURE__ */e(Yl,{dataType:o,nativeDataType:c,calculated:d}),/* @__PURE__ */e($r,{className:"block w-0 min-w-0 flex-1 text-[12px] text-foreground",children:/* @__PURE__ */e(Lx,{label:r})}),p,m&&/* @__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:g=>{g.stopPropagation(),m(u==="asc"?"desc":"asc");},children:u==="asc"?/* @__PURE__ */e(cu,{className:"h-3 w-3"}):/* @__PURE__ */e(du,{className:"h-3 w-3"})}),f&&/* @__PURE__ */e(Tt,{asChild:!0,children:/* @__PURE__ */e("button",{type:"button","aria-label":"Field configuration",className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-muted hover:text-foreground data-[state=open]:bg-muted",onClick:g=>g.stopPropagation(),children:/* @__PURE__ */e(uu,{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:g=>{g.stopPropagation(),h();},children:/* @__PURE__ */e(it,{className:"h-3 w-3"})})]}),f&&/* @__PURE__ */n(vt,{align:"start",sideOffset:6,className:"flex max-h-[480px] w-[320px] flex-col p-0",children:[/* @__PURE__ */e(Ax,{field:a,title:r}),/* @__PURE__ */e("div",{className:"min-h-0 flex-1 space-y-3 overflow-y-auto p-3",children:f})]})]});}function _x({aliasTemplate:t,onAliasTemplateChange:a}){var i;const[s,r]=U(t),[o,c]=U(!1),d=(i=D(h=>{var u;return(u=h.card.config)==null?void 0:u.pivotByColumns;}))==null?void 0:i[0],l=d?`e.g. Min Sales in {{${d.name}}}`:"e.g. Min Sales in {{region}}";return/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-gray-600",children:"Pivot Alias Template"}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(_e,{placeholder:l,value:o?s:t,onChange:h=>{r(h.target.value),c(!0);},onFocus:()=>c(!0),onPointerDown:h=>h.stopPropagation(),className:"h-8 text-xs",onKeyDown:h=>{h.key==="Enter"&&o&&s!==t?(a(s),c(!1)):h.key==="Escape"&&(r(t),c(!1));},"aria-label":"Edit alias template"}),o&&s!==t&&/* @__PURE__ */n(me,{children:[/* @__PURE__ */e(ie,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm alias template",onClick:()=>{a(s),c(!1);},children:/* @__PURE__ */e(Ft,{className:"h-4 w-4 text-green-600"})}),/* @__PURE__ */e(ie,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel alias template edit",onClick:()=>{r(t),c(!1);},children:/* @__PURE__ */e(it,{className:"h-4 w-4 text-gray-400"})})]})]})]});}function Bx({valueAliases:t,onValueAliasesChange:a}){const[s,r]=U(null),[o,c]=U(""),[d,l]=U(""),i=()=>{a({...t,"":""});},h=m=>{const p={...t};delete p[m],a(p);},u=m=>{const p={...t};delete p[m],p[o]=d,a(p),r(null);};return/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Pivot Value Aliases"}),/* @__PURE__ */n("div",{className:"space-y-2",children:[Object.entries(t).map(([m,p],f)=>/* @__PURE__ */e("div",{className:"flex items-center gap-2",children:s===m?/* @__PURE__ */n(me,{children:[/* @__PURE__ */e(_e,{placeholder:"Value key",value:o,onChange:w=>c(w.target.value),className:"h-8 w-24 text-xs",onPointerDown:w=>w.stopPropagation(),onKeyDown:w=>{w.key==="Enter"?u(m):w.key==="Escape"&&r(null);},"aria-label":"Edit value alias key"}),/* @__PURE__ */e(_e,{placeholder:"Alias label",value:d,onChange:w=>l(w.target.value),className:"h-8 w-24 text-xs",onPointerDown:w=>w.stopPropagation(),onKeyDown:w=>{w.key==="Enter"?u(m):w.key==="Escape"&&r(null);},"aria-label":"Edit value alias label"}),/* @__PURE__ */e(ie,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm value alias edit",onClick:()=>u(m),children:/* @__PURE__ */e(Ft,{className:"h-4 w-4 text-green-600"})}),/* @__PURE__ */e(ie,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel value alias edit",onClick:()=>r(null),children:/* @__PURE__ */e(it,{className:"h-4 w-4 text-muted-foreground"})})]}):/* @__PURE__ */n(me,{children:[/* @__PURE__ */e(_e,{placeholder:"Value key",value:m,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(m),c(m),l(p);},"aria-label":"Edit value alias key"}),/* @__PURE__ */e(_e,{placeholder:"Alias label",value:p,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(m),c(m),l(p);},"aria-label":"Edit value alias label"}),/* @__PURE__ */e(ie,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>h(m),"aria-label":"Remove value alias",children:/* @__PURE__ */e(it,{className:"h-3 w-3"})})]})},m+f)),/* @__PURE__ */n(ie,{variant:"outline",size:"sm",className:"mt-1 h-8 text-xs",onClick:i,children:[/* @__PURE__ */e(ga,{className:"mr-1 h-3 w-3"})," Add Value Alias"]})]})]});}function Vx({idx:t}){var l;const a=D(i=>{var h;return(h=i.card)==null?void 0:h.preferences;}),s=D(i=>{var h;return(h=i.card.preferences)==null?void 0:h.datasetOptions;}),r=D(i=>i.actions.setCardPreferences),o=(l=a==null?void 0:a.chartOptions)==null?void 0:l.indexAxis,c=s==null?void 0:s.find(i=>i.idx===t);function d(i,h){(i==="end"||i==="start")&&gh(xh());const u={display:i!=="none",align:i,anchor:i,clamp:!0};if(!c)r({...a,datasetOptions:[...(s||[]),{idx:h,datalabels:u}]});else{const m={...c};m.datalabels=u;const p=s==null?void 0:s.map(f=>f.idx===h?m:f);r({...a,datasetOptions:p});}}return/* @__PURE__ */n(bt,{children:[/* @__PURE__ */e(Tt,{children:/* @__PURE__ */e(mu,{className:"size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground"})}),/* @__PURE__ */e(vt,{className:"w-fit px-2 py-1",children:/* @__PURE__ */n("div",{className:"flex gap-1",children:[/* @__PURE__ */e("button",{onClick:()=>d("none",t),className:"h-7 p-1 text-xs font-normal",children:/* @__PURE__ */e(it,{className:"size-3.5"})}),/* @__PURE__ */e("button",{onClick:()=>d("start",t),className:"h-7 p-1 text-xs font-normal",children:/* @__PURE__ */e(wp,{className:H("h-4 w-4",{"rotate-90":o==="y"})})}),/* @__PURE__ */e("button",{onClick:()=>d("center",t),className:"h-7 p-1 text-xs font-normal",children:/* @__PURE__ */e(Tp,{className:H("h-4 w-4",{"rotate-90":o==="y"})})}),/* @__PURE__ */e("button",{onClick:()=>d("end",t),className:"h-7 p-1 text-xs font-normal",children:/* @__PURE__ */e(Sp,{className:H("h-4 w-4",{"rotate-90":o==="y"})})})]})})]});}function Kx(t,a=30){return t.length>a?t.slice(0,a)+"...":t;}function $x({col:t,idx:a,className:s,iconClassName:r,children:o}){const c=D(u=>{var m;return(m=u.card)==null?void 0:m.preferences;}),d=D(u=>{var m,p;return(p=(m=u.card)==null?void 0:m.preferences)==null?void 0:p.datasetOptions;}),l=d==null?void 0:d.find(u=>u.idx===a),{setCardPreferences:i}=D(u=>u.actions);function h(u){if(!l)i({...c,datasetOptions:[...(d||[]),{idx:a,type:u==="area"?"line":u,fill:u==="area"?"origin":""}]});else{const m={...l};m.type=u==="area"?"line":u,m.fill=u==="area"?"origin":"";const p=d==null?void 0:d.map(f=>f.idx===a?m:f);i({...c,datasetOptions:p});}}return/* @__PURE__ */n("div",{className:H("group flex items-center justify-between gap-2 rounded-md",s),children:[o||/* @__PURE__ */e($r,{className:"max-w-[100px]",title:t,children:Kx(t)}),/* @__PURE__ */n("div",{className:"flex gap-2",children:[/* @__PURE__ */e(Ya,{onClick:()=>h("bar"),className:H("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),/* @__PURE__ */e(Qa,{onClick:()=>h("line"),className:H("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),/* @__PURE__ */e(Hl,{onClick:()=>h("area"),className:H("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),/* @__PURE__ */e(Vx,{idx:a})]})]});}function qx(){const t=D(l=>l.card.type),a=D(l=>l.isDevMode),s=D(l=>l.card.preferences),{setCardPreferences:r}=D(l=>l.actions);function o(l){var u;const i={datalabels:{display:l!=="none",align:l,anchor:l,clamp:!0}},h={...s,chartOptions:{...(s==null?void 0:s.chartOptions),plugins:{...((u=s==null?void 0:s.chartOptions)==null?void 0:u.plugins),...i}}};r(h);}function c(){var l,i,h;return/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e("label",{className:"font-medium",children:"Data Labels"}),/* @__PURE__ */n(ee,{value:((h=(i=(l=s==null?void 0:s.chartOptions)==null?void 0:l.plugins)==null?void 0:i.datalabels)==null?void 0:h.anchor)||"none",onValueChange:o,defaultValue:"none",children:[/* @__PURE__ */e(te,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:/* @__PURE__ */e(ae,{placeholder:"Select position"})}),/* @__PURE__ */e(ne,{children:/* @__PURE__ */n(Gn,{children:[/* @__PURE__ */e(Wl,{children:"Data Labels"}),/* @__PURE__ */e(K,{value:"none",children:"None"}),!["pyramid","funnel"].includes(t)&&/* @__PURE__ */e(K,{value:"start",children:"Start"}),/* @__PURE__ */e(K,{value:"center",children:"Center"}),!["pyramid","funnel"].includes(t)&&/* @__PURE__ */e(K,{value:"end",children:"End"})]})})]})]});}function d(){var l,i,h;return/* @__PURE__ */e("div",{children:/* @__PURE__ */n(ee,{value:((h=(i=(l=s==null?void 0:s.chartOptions)==null?void 0:l.plugins)==null?void 0:i.datalabels)==null?void 0:h.anchor)||"none",onValueChange:o,defaultValue:"none",children:[/* @__PURE__ */e(te,{className:"h-8 w-full text-xs",children:/* @__PURE__ */e(ae,{placeholder:"Select position"})}),/* @__PURE__ */e(ne,{children:/* @__PURE__ */n(Gn,{children:[/* @__PURE__ */e(K,{className:"text-xs",value:"none",children:"None"}),!["pyramid","funnel"].includes(t)&&/* @__PURE__ */e(K,{className:"text-xs",value:"start",children:"Start"}),/* @__PURE__ */e(K,{className:"text-xs",value:"center",children:"Center"}),!["pyramid","funnel"].includes(t)&&/* @__PURE__ */e(K,{className:"text-xs",value:"end",children:"End"})]})})]})});}return/* @__PURE__ */e(me,{children:a?c():d()});}function zx({column:t}){const a=D(i=>i.card.type),s=D(i=>{var h,u;return(u=(h=i.card)==null?void 0:h.config)==null?void 0:u.metricColumns;}),r=(s==null?void 0:s.map(i=>i.label))||[],o=r==null?void 0:r.find(i=>i===t.label||i===t.name),c=o?r.indexOf(o):-1;function d(){return/* @__PURE__ */e("div",{className:"pr-1",children:o&&/* @__PURE__ */e($x,{idx:c,col:o,children:/* @__PURE__ */e("div",{className:"w-[130px] text-xs text-muted-foreground",children:"Display Series As"})})});}function l(){return/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Data Labels"}),/* @__PURE__ */e(qx,{})]});}return/* @__PURE__ */n("div",{className:"space-y-1",children:[["stackedBar","stackedLine","bar","line"].includes(a)&&d(),["pie","doughnut"].includes(a)&&l()]});}function jx({field:t,searchQuery:a="",limit:s=500}){const{authToken:r,tokenProps:o}=It(),c=ye(u=>{var m;return((m=u.reportContext)==null?void 0:m.calendar)??null;}),d=D(u=>u.card),l=d==null?void 0:d.dataSource,i=["attribute-values",t.entityName,t.name,a,s,c],h=hu({queryKey:i,queryFn:async()=>{if(!(l!=null&&l.connectionId))return console.warn("No connection ID available for attribute values query"),[];try{const u={groupByColumns:[{...t,role:"groupby"}],metricColumns:[],filters:a?{id:"search-filter",logicalOperator:"AND",negate:!1,conditions:[{id:"search-condition",field:t,operator:"contains",value:a}],groups:[]}:void 0,rowLimit:s},m={connection_id:l.connectionId,cardConfig:u,cardDataSource:l,cache_config:pu({card:d}),calendarContext:c};console.log("requestBody",m);const p=await eo(`${o.apiServiceUrl}/v1/query`,(r==null?void 0:r.accessToken)||"",fu(m,gu()));if(p!=null&&p.error)return console.error("Error fetching attribute values:",p.error),[];const f=t.name;return((p==null?void 0:p.records)||[]).map(C=>{const y=C[f]||C[t.alias||f]||C[t.label];return{id:y||"",value:y||"",label:String(y||"(empty)")};});}catch(u){return console.error("Error fetching attribute values:",u),[];}},enabled:!!t&&!!(l!=null&&l.connectionId)&&!!c,staleTime:5*60*1e3,gcTime:10*60*1e3});return{values:h.data||[],isLoading:h.isLoading,isFetching:h.isFetching,isError:h.isError,error:h.error,refetch:h.refetch};}const Ux=/* @__PURE__ */new Set();function Hx({open:t,onOpenChange:a,availableFields:s,existingFilters:r,editingCondition:o,onSave:c}){const d=!!o,[l,i]=U(d?"values":"fields"),[h,u]=U(""),[m,p]=U({id:(o==null?void 0:o.id)||Dt(),field:(o==null?void 0:o.field)||null,selectedValues:o?Array.isArray(o.value)?o.value:[o.value]:[]}),f=s.filter(N=>{var F;return d?!1:!((F=r==null?void 0:r.conditions)==null?void 0:F.some(O=>O.field.id===N.id));}),w=N=>{p({...m,field:N}),i("values");},C=()=>{if(m.field&&m.selectedValues.length>0){const N={id:m.id,field:m.field,operator:"in",value:m.selectedValues};let g;if(d){const F=((r==null?void 0:r.conditions)||[]).map(O=>O.id===o.id?N:O);g={...r,conditions:F};}else{const F=(r==null?void 0:r.conditions)||[];g={id:(r==null?void 0:r.id)||Dt(),logicalOperator:"AND",negate:!1,conditions:[...F,N],groups:[]};}c(g),a(!1);}},y=()=>{if(!d||!o)return;const N=((r==null?void 0:r.conditions)||[]).filter(g=>g.id!==o.id);if(N.length>0){const g={...r,conditions:N};c(g);}else c(void 0);a(!1);},b=N=>{p({...m,selectedValues:N});},v=()=>{d&&o?(p({id:o.id,field:o.field,selectedValues:Array.isArray(o.value)?o.value:[o.value]}),i("values")):(p({id:Dt(),field:null,selectedValues:[]}),i("fields")),u("");};return Ne(()=>{t&&v();},[t,d,o]),/* @__PURE__ */e(ha,{open:t,onOpenChange:a,children:/* @__PURE__ */n(pa,{className:"max-w-2xl",children:[/* @__PURE__ */e(ja,{children:/* @__PURE__ */e(fa,{children:d?`Edit Filter: ${m.field?ka(m.field):""}`:l==="fields"?"Select Field to Filter":`Select Values for ${m.field?ka(m.field):""}`})}),/* @__PURE__ */n("div",{className:"space-y-4",children:[!d&&(r==null?void 0:r.conditions)&&r.conditions.length>0&&l==="fields"&&/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Current Filters:"}),/* @__PURE__ */e("div",{className:"flex flex-wrap gap-2",children:r.conditions.map(N=>/* @__PURE__ */n("div",{className:"flex items-center gap-1 px-2 py-1 bg-muted rounded-md text-xs",children:[/* @__PURE__ */n("span",{className:"font-medium",children:[ka(N.field),":"]}),/* @__PURE__ */e("span",{className:"text-muted-foreground",children:Array.isArray(N.value)?`${N.value.length} values`:String(N.value)})]},N.id))})]}),l==="fields"&&!d?/* @__PURE__ */e("div",{className:"flex flex-col",children:/* @__PURE__ */e(xu,{fields:f,selectedIds:Ux,onSelect:w,query:h,onQueryChange:u,density:"compact",listLabel:"Filterable fields",listClassName:"max-h-[400px]",autoFocusSearch:!0,emptyMessage:h?`No fields found matching "${h}"`:s.length>0?"All available fields are already filtered":void 0})}):/* @__PURE__ */e(Gx,{field:m.field,selectedValues:m.selectedValues,onValuesChange:b,onBack:d?void 0:()=>i("fields")}),/* @__PURE__ */n("div",{className:"flex justify-between pt-4 border-t",children:[/* @__PURE__ */e("div",{children:d?/* @__PURE__ */e(ie,{variant:"destructive",onClick:y,children:"Delete Filter"}):/* @__PURE__ */e(ie,{variant:"outline",onClick:v,children:"Reset"})}),/* @__PURE__ */n("div",{className:"flex gap-2",children:[/* @__PURE__ */e(ie,{variant:"outline",onClick:()=>a(!1),children:"Cancel"}),/* @__PURE__ */e(ie,{onClick:C,disabled:!m.field||m.selectedValues.length===0,children:"Apply"})]})]})]})]})});}function Gx({field:t,selectedValues:a,onValuesChange:s,onBack:r}){const[o,c]=U(""),{values:d,isLoading:l,isFetching:i}=jx({field:t,searchQuery:o,limit:500}),h=o?d.filter(p=>String(p.value).toLowerCase().includes(o.toLowerCase())):d,u=p=>{const f=a.includes(p);s(f?a.filter(w=>w!==p):[...a,p]);},m=()=>{a.length===h.length&&h.length>0?s([]):s(h.map(p=>p.value));};return/* @__PURE__ */n("div",{className:"space-y-4",children:[r&&/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */e(ie,{variant:"ghost",size:"sm",onClick:r,children:"← Back"}),/* @__PURE__ */n(A,{className:"text-sm font-medium",children:["Select values for ",ka(t)]})]}),/* @__PURE__ */n("div",{className:"relative",children:[/* @__PURE__ */e(Tl,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),/* @__PURE__ */e(_e,{placeholder:"Search values...",value:o,onChange:p=>c(p.target.value),className:"pl-10"})]}),l||i?/* @__PURE__ */e("div",{className:"flex items-center justify-center py-8",children:/* @__PURE__ */e(xa,{className:"h-6 w-6 animate-spin"})}):/* @__PURE__ */n("div",{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2 pb-2 border-b",children:[/* @__PURE__ */e(_t,{checked:a.length===h.length&&h.length>0,onCheckedChange:m}),/* @__PURE__ */n(A,{className:"text-sm",children:["Select All (",h.length,")"]})]}),/* @__PURE__ */e("div",{className:"max-h-[300px] overflow-y-auto space-y-1",children:h.map(p=>/* @__PURE__ */n("div",{className:"flex items-center gap-2 p-2 hover:bg-muted/50 rounded cursor-pointer",onClick:()=>u(p.value),children:[/* @__PURE__ */e(_t,{checked:a.includes(p.value),onCheckedChange:()=>u(p.value)}),/* @__PURE__ */e($r,{className:"text-sm",children:p.label})]},p.id))})]})]});}const _n="auto",Bn=vu;function Qx({format:t,column:a,dateOnly:s,connectionType:r,automaticPreview:o,onChange:c}){const d=bh(t),l=vh(r),[i,h]=U(d.kind==="custom"?d.pattern:null),u=d.kind==="automatic",m=l?"12h":"24h",p=d.kind==="display"?d.display.show==="date"?{...d.display,clock:m}:d.display:{show:s?"date":"datetime",dateStyle:Nh,clock:m,seconds:!1},f=s?"date":p.show,w=v=>c(xn(v)),C=v=>{var N;return(v==null?void 0:v.type)==="date"?(N=yh(a,v,r))==null?void 0:N.message:void 0;},y=C(t);if(i!==null){const v=d.kind==="custom"?d.dialect:void 0,N=d.kind==="custom"?d.pattern:d.kind==="display"?xn(p).pattern??"":"";return/* @__PURE__ */e(bu,{initial:i,saved:N,placeholder:"MMM d, yyyy h:mm a",hint:"YYYY MMM MM DD · HH mm ss, or yyyy MMM dd · h hh H HH · mm ss · a (AM/PM)",read:g=>Ch(g,v),problemOf:C,onSave:g=>{JSON.stringify(g)!==JSON.stringify(t)&&c(g);},back:{label:"Use Show and Clock instead",onClick:()=>{h(null),d.kind==="custom"&&w(p);}}});}const b=u?_n:d.kind==="preset"?void 0:p.dateStyle;return/* @__PURE__ */n(me,{children:[!s&&/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:Bn,children:"Show"}),/* @__PURE__ */e(Qn,{label:"Show",value:f,onChange:v=>{v!==f&&w({...p,show:v});},options:[{value:"date",label:"Date"},{value:"time",label:"Time"},{value:"datetime",label:"Date and time"}]})]}),f!=="time"&&/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:Bn,children:"Date format"}),/* @__PURE__ */n(ee,{value:b,onValueChange:v=>{v===_n?c(void 0):w({...p,show:f,dateStyle:v});},children:[/* @__PURE__ */e(te,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ae,{placeholder:d.kind==="preset"?`Saved style (${d.preset})`:"Select date format..."})}),/* @__PURE__ */n(ne,{children:[(f==="datetime"||s)&&/* @__PURE__ */e(K,{className:"text-xs",value:_n,children:`Automatic (${o})`}),wh.map(v=>/* @__PURE__ */e(K,{className:"text-xs",value:v.id,children:v.label},v.id))]})]})]}),f!=="date"&&!u&&/* @__PURE__ */n(me,{children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:Bn,children:"Clock"}),/* @__PURE__ */e(Qn,{label:"Clock",value:p.clock,onChange:v=>w({...p,show:f,clock:v}),options:[{value:"12h",label:"12-hour · 12:20 PM",disabled:!l&&p.clock!=="12h",title:l?void 0:"12-hour times aren't available for this data source yet"},{value:"24h",label:"24-hour · 12:20"}]})]}),/* @__PURE__ */n("label",{className:"flex items-center justify-between text-xs text-muted-foreground",children:["Show seconds",/* @__PURE__ */e(De,{size:"xs",checked:p.seconds,onCheckedChange:v=>w({...p,show:f,seconds:v})})]})]}),y&&/* @__PURE__ */e("p",{className:"text-[12px] leading-4 text-amber-700 dark:text-amber-400",children:y}),/* @__PURE__ */e("button",{type:"button",onClick:()=>{h(d.kind==="custom"?d.pattern:d.kind==="display"?xn(p).pattern??"":"");},className:"text-left text-[12px] text-muted-foreground underline underline-offset-2 hover:text-foreground",children:"Custom pattern…"})]});}function Yx(t,a){return t==="pivotBy"&&a==="table";}const al=[],Vn={running_total:"Running Total",moving_average:"Moving Average",difference_from_previous:"Difference from previous",percent_of_total:"Percent of Total"};function Wx({field:t,zone:a,index:s,sortDirection:r,onSortDirectionChange:o,hasPivotColumns:c=!1,cardType:d}){var ss,ls,os,is,cs,ds;const l=D(J=>J.card),i=lr(l).baseName,h=Hi(l),u=ye(J=>J.actions.updateDashboardCalculatedFields),p=ye(J=>{var Q;return J.visualEditPendingDashboardCalculatedFields??((Q=J.dashboard)==null?void 0:Q.calculatedFields);})??al,{scopedFields:f,valuePickFilterableFields:w,isLoading:C,hasError:y,refetch:b}=gr(),{userContext:v}=Ua(),{tokenProps:N}=It(),g=vo(v),F=Za(),O=Ll()??Xt,V=yu()??Xt,$=Nu(),{updateLabel:E,handleAggregationChange:T,handleDetailDateFormatChange:M,handleDimensionFormatChange:I,handleTemporalBucketFormatChange:q,handleGranularityChange:P,handleAliasTemplateChange:x,handlePivotMemberOrderChange:R,handleValueAliasesChange:S,handleMetricFormatChange:k,removeField:L,handleMetricWindowTransformChange:_,handleMetricWindowOrderByChange:z,handleMetricWindowDirectionChange:j,handleMetricWindowPartitionToggle:B,handleMetricMovingAverageWindowSizeChange:G,handleMetricMovingAverageMinPeriodsChange:ce,handleMetricPreviousPeriodDeltaModeChange:ue,handleMetricPercentOfTotalScopeChange:X,handleMetricPercentOfTotalOutputChange:Y}=qa(l),[fe,he]=U(!1),[re,se]=U(()=>{var J;return!!((J=t.parameters)!=null&&J.windowTransform);}),[ge,be]=U(!1),[Ie,Ve]=U(!1),[et,pe]=U(null),we=Z(()=>{const J=As(t.id),Q=f.find(Te=>{if(t.qualifiedFieldName&&Te.qualifiedFieldName&&Te.qualifiedFieldName===t.qualifiedFieldName||t.qualifiedEntityName&&Te.qualifiedEntityName&&Te.qualifiedEntityName===t.qualifiedEntityName&&Te.name===t.name)return!0;const Le=As(Te.id);return!!(J&&Le&&J===Le);});return{dataType:(Q==null?void 0:Q.dataType)||t.dataType,resolvedFromScopedField:!!Q};},[t.dataType,t.id,t.name,t.qualifiedEntityName,t.qualifiedFieldName,f]),Ee=ql(we.dataType),rt=Z(()=>Sh({fieldId:t.id,dataType:t.dataType,granularity:t.granularity,format:t.format,semanticTemporalPresentation:t.semanticTemporalPresentation}),[t.dataType,t.format,t.id,t.granularity,t.semanticTemporalPresentation]),Ue=a==="groupBy"?rt.ok&&Ee.includes(rt.granularity)?rt.granularity:void 0:Ee.includes(t.granularity)?t.granularity:"day",He=a==="groupBy"?Th({cardType:(l==null?void 0:l.type)??"",configBacked:!0,shelf:"groupBy",dataType:we.dataType}):void 0,st=(He==null?void 0:He.ok)===!0,le=He&&!He.ok&&He.reason==="card_type"&&(l==null?void 0:l.type)!=="kpi"?"Not on this chart type":void 0,Se=st&&t.grainMode==="automatic",Ke=rt.ok?rt.selection:{format:ro},[Ge,$e]=U(t.aliasTemplate||""),[qe,We]=U(t.valueAliases||{}),[ke,ve]=U((ss=t.parameters)==null?void 0:ss.filters),de=J=>{a==="groupBy"&&P(s,J);},Be=J=>{$e(J),a==="metrics"&&x(s,J);},W=J=>{a==="pivotBy"&&R(s,J);},Fe=J=>{We(J),a==="metrics"&&S(s,J);},oe=J=>{E(a,s,J);},Ce=kh(t);Cu(t);const ct=Dh(t),tt=t.role==="metric"&&ct,Na=ct&&(Ce==="user_calculated"||Ce==="inline_expression"&&t.fieldScope!=="domain"),Pt=Na?wu({field:t,dashboardFields:p}):void 0,qr=Na&&(Pt==null?void 0:Pt.scope)==="dashboard",ea=Ce==="domain_calculated"||t.fieldScope==="domain",zr=ea?Gi(t,f):void 0,ta=ea?"domain":qr?"dashboard":"card",sn=ea?zr||t:qr&&Pt!=null&&Pt.matchedField?Pt.matchedField:t,pi=ea?zr?"effective":C?"loading":y?"unavailable":"unverified":void 0,jr=J=>{var Q;if(ve(J),a==="metrics"){const Te={...t,parameters:{...t.parameters,filters:J}},Le=[...(((Q=l.config)==null?void 0:Q.metricColumns)||[])];Le[s]=Te,D.getState().actions.updateCardConfig(l.id,{metricColumns:Le});}be(!1);},fi=()=>{L(a,s);},ln=co(we.dataType||t.dataType),Ur=ln==="date",Hr=d==="kpi",on=a==="detailColumns",Gr=(ls=l.config)==null?void 0:ls.metricColumns,Qr=(os=l.config)==null?void 0:os.groupByColumns,Yr=jl(l),Wr=ye(J=>J.dashboard),Jr=ye(J=>J.semanticExecutionPayload),Ca=t.nativeDataType||t.dataType,gi=Z(()=>a==="detailColumns"?Eh({format:void 0,valueKind:Ps(Ca)?"date":"wall_datetime",preferences:V,calendarTimezone:$||"UTC"}):void 0,[Ca,$,V,a]),Xr=Z(()=>Do(l,To(Yr,ko(Wr,Jr,F)),F),[l,Yr,Wr,Jr,F]),cn=Z(()=>{if(a!=="metrics")return;const J=oo("metric",Gr??[])[s];return J?io(l,J,Xr):void 0;},[l,Xr,s,Gr,a]),wa=t,dn=(is=wa.parameters)==null?void 0:is.windowTransform,aa=!!dn,lt=Z(()=>dn&&a==="metrics"?Ih(l,wa.id,J=>({name:J.name,datasetName:Fh(J)})):void 0,[l,wa.id,dn,a]),Me=lt==null?void 0:lt.transform,yt=(Me==null?void 0:Me.kind)??null,gt=cn==null?void 0:cn.transform,un=gt?Object.values(gt.kinds).filter(J=>J.offered):[],mn=gt&&!un.length?Object.values(gt.kinds).find(J=>!J.offered):void 0,xi=un.some(J=>J.offered&&J.replaces==="comparison"),Zr=Qr||[],na=(lt==null?void 0:lt.order)??"",bi=(lt==null?void 0:lt.direction)??"asc",Sa=yt!==null&&yt!=="percent_of_total",es=Zr.findIndex(J=>J.id===na),vi=Sa&&es>=0&&((cs=gt==null?void 0:gt.groupings[es])==null?void 0:cs.isDate)===!1,yi=new Set((lt==null?void 0:lt.resetBy)??[]),ts=(Qr||[]).filter(J=>J.id&&(!Sa||J.id!==na)),as=(Me==null?void 0:Me.kind)==="moving_average"?Me.window??7:7,Ni=(Me==null?void 0:Me.kind)==="moving_average"?Me.minPeriods??1:1,Ci=(Me==null?void 0:Me.kind)==="difference_from_previous"?Me.mode??"difference":"difference",ns=(Me==null?void 0:Me.kind)==="percent_of_total"?Me.scope??"grand_total":"grand_total",wi=(Me==null?void 0:Me.kind)==="percent_of_total"?Me.output??"percent":"percent";Ne(()=>{aa&&se(!0);},[aa]);const Si=a!=="pivotBy"&&a!=="sortBy",Ti=Yx(a,d),ki=t.memberOrder??"auto",Di=Ur&&a==="groupBy",Ei=!Hr&&Ur&&(a==="groupBy"||on),Ii=a==="metrics",Fi=!Hr&&ln==="number"&&(a==="groupBy"||on)&&Mh(d),Mi=()=>Si?/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Label"}),/* @__PURE__ */e(dt,{value:t.label??"",onSave:oe,placeholder:"Display label...",type:"text"})]}):null,Ai=()=>a!=="sortBy"?null:/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Order"}),/* @__PURE__ */n(ee,{value:r||"asc",onValueChange:J=>o(J),children:[/* @__PURE__ */e(te,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{className:"text-xs",value:"asc",children:"Ascending"}),/* @__PURE__ */e(K,{className:"text-xs",value:"desc",children:"Descending"})]})]})]}),Pi=()=>Ti?/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Pivot column order"}),/* @__PURE__ */n(ee,{value:ki,onValueChange:J=>W(J),children:[/* @__PURE__ */e(te,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ae,{})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{className:"text-xs",value:"auto",children:"Auto"}),/* @__PURE__ */e(K,{className:"text-xs",value:"asc",children:"Ascending"}),/* @__PURE__ */e(K,{className:"text-xs",value:"desc",children:"Descending"})]})]})]}):null,rs=()=>Di?/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Granularity"}),/* @__PURE__ */n(ee,{value:Se?"automatic":Ue,onValueChange:de,children:[/* @__PURE__ */e(te,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ae,{placeholder:"Select granularity..."})}),/* @__PURE__ */n(ne,{children:[st&&/* @__PURE__ */e(K,{className:"text-xs",value:"automatic",children:"Automatic"}),le&&/* @__PURE__ */n(K,{className:"text-xs",value:"automatic",disabled:!0,children:["Automatic · ",le]}),Ee.map(J=>/* @__PURE__ */e(K,{className:"text-xs",value:J,children:Ph(J)},J))]})]}),Se&&/* @__PURE__ */e("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"Follows the date range: by day for a week, by week for a quarter, by month for a year."})]}):null,Ri=()=>{var J;return Ei?a==="detailColumns"?/* @__PURE__ */e(Qx,{format:t.format,column:t,dateOnly:Ps(Ca),connectionType:(J=l.dataSource)==null?void 0:J.connectionType,automaticPreview:gi??"",onChange:Q=>M(s,Q)},t.id):/* @__PURE__ */n(me,{children:[rs(),/* @__PURE__ */e(zl,{grain:Ue,format:Ke.format,preferences:O,onChange:Q=>q(s,Q)},`${t.id}:${Ue??"none"}`)]}):null;},Oi=()=>Fi?/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Number Format"}),/* @__PURE__ */e(Ys,{field:t,onChange:J=>I(on?"detailColumns":"groupBy",s,J),cardType:d,showTitle:!1})]}):null,Li=()=>{if(!Ii)return null;const J=tt;return/* @__PURE__ */n(me,{children:[J&&g&&!ea&&/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Formula"}),/* @__PURE__ */n(ie,{variant:"outline",size:"sm",className:"h-8 w-full justify-start text-xs",onClick:()=>Ve(!0),children:[/* @__PURE__ */e(Su,{className:"mr-2 h-3 w-3"}),"Edit Formula"]})]}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Aggregation"}),/* @__PURE__ */n(ee,{value:t.aggregate,onValueChange:Q=>{T(s,Q);},disabled:J,children:[/* @__PURE__ */e(te,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ae,{placeholder:"Select function..."})}),/* @__PURE__ */e(ne,{children:so(t.dataType).map(Q=>/* @__PURE__ */e(K,{className:"text-xs",value:Q.value,children:Q.label},Q.value))})]})]}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Number Format"}),/* @__PURE__ */e(Ys,{field:wa,onChange:Q=>k(s,Q),cardType:d,showTitle:!1})]}),/* @__PURE__ */e($t,{open:re,onOpenChange:se,children:/* @__PURE__ */n("div",{className:"space-y-2 rounded-md border border-border/60 bg-muted/20 p-2.5",children:[/* @__PURE__ */e(qt,{asChild:!0,children:/* @__PURE__ */n("button",{type:"button",className:"flex w-full items-center justify-between rounded-sm px-0.5 py-0.5 text-left",children:[/* @__PURE__ */e("div",{className:"text-xs font-medium text-foreground",children:"Metric Transform"}),/* @__PURE__ */n("div",{className:"flex items-center text-[11px] text-muted-foreground",children:[!re&&/* @__PURE__ */e("span",{className:"mr-2",children:yt?Vn[yt]:"None"}),/* @__PURE__ */e(Et,{className:H("h-3 w-3 transition-transform",re?"rotate-180":"")})]})]})}),/* @__PURE__ */n(jt,{className:"space-y-2",children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Transform"}),/* @__PURE__ */n(ee,{value:yt??"none",onValueChange:Q=>_(s,Q),disabled:!un.length&&!aa,children:[/* @__PURE__ */e(te,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ae,{placeholder:"Select transform..."})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"none",children:"None"}),Object.keys(Vn).map(Q=>{const Te=gt==null?void 0:gt.kinds[Q];return/* @__PURE__ */e(K,{value:Q,disabled:Te?!Te.offered:!1,title:Te&&!Te.offered?Te.reason:void 0,children:Vn[Q]},Q);})]})]}),mn&&!mn.offered&&!aa&&/* @__PURE__ */e("div",{className:"text-xs text-muted-foreground",children:mn.reason}),xi&&/* @__PURE__ */e("div",{className:"text-xs text-muted-foreground",children:"A table calculation replaces this metric's comparison."})]}),aa&&/* @__PURE__ */n(me,{children:[Sa&&/* @__PURE__ */n(me,{children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Order By"}),/* @__PURE__ */n(ee,{value:na,onValueChange:Q=>z(s,Q),children:[/* @__PURE__ */e(te,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ae,{placeholder:"Select order field..."})}),/* @__PURE__ */e(ne,{children:Zr.filter(Q=>!!Q.id).map(Q=>/* @__PURE__ */e(K,{value:Q.id,className:"text-xs",children:Q.label||Q.name},Q.id))})]}),!na&&/* @__PURE__ */e("div",{className:"text-xs text-amber-700",children:"No date trend detected. Select an order field."}),vi&&/* @__PURE__ */e("div",{className:"text-xs text-amber-700",children:"No date trend detected. The transform will follow the selected order field."})]}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Direction"}),/* @__PURE__ */n(ee,{value:bi,onValueChange:Q=>j(s,Q),disabled:!na,children:[/* @__PURE__ */e(te,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ae,{placeholder:"Select direction..."})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{className:"text-xs",value:"asc",children:"Ascending"}),/* @__PURE__ */e(K,{className:"text-xs",value:"desc",children:"Descending"})]})]})]})]}),yt==="moving_average"&&/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Window Size"}),/* @__PURE__ */e(_e,{type:"number",min:1,size:"xs",value:as,onChange:Q=>G(s,Number(Q.target.value))}),/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Min Periods"}),/* @__PURE__ */e(_e,{type:"number",min:1,max:as,size:"xs",value:Ni,onChange:Q=>ce(s,Number(Q.target.value))})]}),yt==="difference_from_previous"&&/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Output"}),/* @__PURE__ */n(ee,{value:Ci,onValueChange:Q=>ue(s,Q),children:[/* @__PURE__ */e(te,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ae,{placeholder:"Select output..."})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"difference",children:"Difference"}),/* @__PURE__ */e(K,{value:"percent_change",children:"Percent change"})]})]})]}),yt==="percent_of_total"&&/* @__PURE__ */n(me,{children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Scope"}),/* @__PURE__ */n(ee,{value:ns,onValueChange:Q=>X(s,Q),children:[/* @__PURE__ */e(te,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ae,{placeholder:"Select scope..."})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"grand_total",children:"Grand Total"}),/* @__PURE__ */e(K,{value:"partition_total",children:"Partition Total"})]})]})]}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Output"}),/* @__PURE__ */n(ee,{value:wi,onValueChange:Q=>Y(s,Q),children:[/* @__PURE__ */e(te,{size:"xs",className:"w-full",children:/* @__PURE__ */e(ae,{placeholder:"Select output..."})}),/* @__PURE__ */n(ne,{children:[/* @__PURE__ */e(K,{value:"percent",children:"Percent"}),/* @__PURE__ */e(K,{value:"fraction",children:"Fraction"})]})]})]})]}),(Sa||yt==="percent_of_total"&&ns==="partition_total")&&ts.length>0&&/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Reset By"}),/* @__PURE__ */e("div",{className:"space-y-1",children:ts.map(Q=>{const Te=!!Q.id&&yi.has(Q.id);return/* @__PURE__ */n("button",{type:"button",onClick:()=>Q.id&&B(s,Q.id),className:H("flex h-7 w-full items-center justify-between rounded border px-2 text-xs",Te?"border-primary bg-primary/5 text-primary":"border-border text-muted-foreground"),children:[/* @__PURE__ */e("span",{children:Q.label||Q.name}),Te?/* @__PURE__ */e(Ft,{className:"h-3 w-3"}):null]},Q.id);})})]})]})]})]})}),/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */e(A,{className:"text-xs font-medium text-muted-foreground",children:"Attribute Filters"}),(ke==null?void 0:ke.conditions)&&ke.conditions.length>0&&/* @__PURE__ */e("div",{className:"mb-2 space-y-1",children:ke.conditions.map(Q=>/* @__PURE__ */n("div",{className:"flex cursor-pointer items-center gap-2 rounded bg-muted/50 p-2 text-xs transition-colors hover:bg-muted/70",onClick:()=>{pe(Q),be(!0);},children:[/* @__PURE__ */n("span",{className:"font-medium",children:[Q.field.label,":"]}),/* @__PURE__ */e(xt,{children:/* @__PURE__ */n(ht,{children:[/* @__PURE__ */e(pt,{asChild:!0,children:/* @__PURE__ */e("span",{className:"cursor-help text-muted-foreground",children:Array.isArray(Q.value)?Q.value.length===1?String(Q.value[0]):Q.value.length<=2?Q.value.join(", "):`${Q.value.slice(0,2).join(", ")} +${Q.value.length-2}`:String(Q.value)})}),Array.isArray(Q.value)&&Q.value.length>1&&/* @__PURE__ */e(ft,{side:"top",className:"max-w-[300px]",children:/* @__PURE__ */n("div",{className:"text-xs",children:[/* @__PURE__ */n("div",{className:"mb-1 font-medium",children:["Selected values (",Q.value.length,"):"]}),/* @__PURE__ */e("div",{className:"max-h-[200px] overflow-y-auto",children:Q.value.map((Te,Le)=>/* @__PURE__ */e("div",{children:String(Te)},Le))})]})})]})}),/* @__PURE__ */e(ie,{variant:"ghost",size:"sm",className:"ml-auto h-4 w-4 p-0",onClick:Te=>{var kt;Te.stopPropagation();const Le=ke.conditions.filter(Nt=>Nt.id!==Q.id);if(Le.length>0){const Nt={...ke,conditions:Le};jr(Nt);}else if(ve(void 0),a==="metrics"){const Nt={...t,parameters:{...t.parameters,filters:void 0}},Rt=[...(((kt=l.config)==null?void 0:kt.metricColumns)||[])];Rt[s]=Nt,D.getState().actions.updateCardConfig(l.id,{metricColumns:Rt});}},children:/* @__PURE__ */e(it,{className:"h-3 w-3"})})]},Q.id))}),/* @__PURE__ */n(ie,{variant:"outline",size:"sm",className:"h-8 w-full justify-start text-xs",onClick:()=>{pe(null),be(!0);},children:[/* @__PURE__ */e(Zt,{className:"mr-2 h-3 w-3"}),"Add attribute filter"]})]}),/* @__PURE__ */e(zx,{column:t}),c&&/* @__PURE__ */n(me,{children:[/* @__PURE__ */e(_x,{aliasTemplate:Ge,onAliasTemplateChange:Be}),/* @__PURE__ */e(Bx,{valueAliases:qe,onValueAliasesChange:Fe})]})]});};ke!=null&&ke.conditions&&ke.conditions.length>0;const _i=a!=="sortBy";return/* @__PURE__ */n(me,{children:[/* @__PURE__ */e(hi,{id:t.id,field:t,zone:a,label:Ah(t,uo(t),i,h),dataType:ln,nativeDataType:Ca,calculated:yr(t),open:fe,onOpenChange:he,onRemove:fi,sortDirection:r,onSortDirectionChange:a==="sortBy"?o:void 0,badge:/* @__PURE__ */e(me,{children:a==="metrics"&&((ds=ke==null?void 0:ke.conditions)==null?void 0:ds.length)&&!fe&&/* @__PURE__ */e(xt,{children:/* @__PURE__ */n(ht,{children:[/* @__PURE__ */e(pt,{asChild:!0,children:/* @__PURE__ */n("div",{className:"flex shrink-0 items-center gap-1 rounded-[3px] bg-primary/10 px-1 text-[10px] tabular-nums text-primary/90",children:[/* @__PURE__ */e(Zt,{className:"h-2.5 w-2.5"}),/* @__PURE__ */e("span",{children:ke.conditions.length})]})}),/* @__PURE__ */e(ft,{side:"top",children:/* @__PURE__ */e("div",{className:"text-xs",children:ke.conditions.map(J=>/* @__PURE__ */n("div",{children:[J.field.label,":"," ",Array.isArray(J.value)?`${J.value.length} values`:String(J.value)]},J.id))})})]})})}),children:_i&&/* @__PURE__ */n(me,{children:[Ai(),Pi(),Mi(),d==="kpi"&&rs(),Ri(),Oi(),Li()]})}),ge&&/* @__PURE__ */e(Hx,{open:ge,onOpenChange:J=>{be(J),J||pe(null);},availableFields:w,existingFilters:ke,editingCondition:et,onSave:J=>{var Q;if(J)jr(J);else if(ve(void 0),a==="metrics"){const Te={...t,parameters:{...t.parameters,filters:void 0}},Le=[...(((Q=l.config)==null?void 0:Q.metricColumns)||[])];Le[s]=Te,D.getState().actions.updateCardConfig(l.id,{metricColumns:Le});}pe(null);}}),Ie&&a==="metrics"&&tt&&/* @__PURE__ */e(yo,{open:Ie,onOpenChange:Ve,availableFields:f,existingField:sn,existingFieldScope:ta,domainDefinitionStatus:pi,initialFieldType:"metric",allowedFieldTypes:["metric"],onSave:J=>{if(J.role!=="metric")return;const{card:Q,actions:Te}=D.getState(),Le=ta==="dashboard"?p:al,{cardConfigPatch:kt,nextStoredFields:Nt,nextSharedFields:Rt}=cl({cardConfig:Q.config,storedFields:Q.calculatedFields||[],sharedFields:Le,updatedField:J,editingField:sn,previousScope:ta});Object.keys(kt).length&&Te.updateCardConfig(l.id,kt),Te.updateCard(l.id,{calculatedFields:Nt}),ta==="dashboard"&&Rt!==Le&&u(Rt);},onSaveToDashboard:J=>{if(J.role!=="metric")return;const{card:Q,actions:Te}=D.getState(),Le=t,{cardConfigPatch:kt,nextStoredFields:Nt,nextSharedFields:Rt}=il({cardConfig:Q.config,storedFields:Q.calculatedFields||[],sharedFields:p,updatedField:{...J,id:Le.id,aliasTemplate:Le.aliasTemplate,valueAliases:Le.valueAliases,parameters:Le.parameters},editingField:sn,previousScope:ta});u(Rt),Object.keys(kt).length&&Te.updateCardConfig(l.id,kt),Te.updateCard(l.id,{calculatedFields:Nt});},cardId:l.id})]});}function Jx({field:t,zone:a,onRemove:s}){const[r,o]=U(!1);return/* @__PURE__ */e(hi,{id:t.id,field:t,zone:a,label:uo(t),dataType:t.dataType,nativeDataType:t.nativeDataType,calculated:yr(t),open:r,onOpenChange:o,onRemove:s,children:/* @__PURE__ */e(sr,{fieldId:t.id})});}function Xx({concept:t}){const{title:a,description:s}=Zx[t];return/* @__PURE__ */n(Qt,{openDelay:150,closeDelay:50,children:[/* @__PURE__ */e(Yt,{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(vp,{className:"h-3 w-3"})})}),/* @__PURE__ */n(Wt,{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(eb,{highlight:t})]})]});}const Zx={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 eb({highlight:t}){const a=t==="pivotBy",s=t==="groupBy",r=t==="metrics",o="bg-foreground/[0.06] font-medium text-foreground dark:bg-foreground/[0.12]";return/* @__PURE__ */e("div",{className:"overflow-hidden rounded-control border border-border",children:/* @__PURE__ */n("table",{className:"w-full text-[10px]",children:[/* @__PURE__ */e("thead",{children:/* @__PURE__ */n("tr",{className:"border-b border-border bg-muted/40",children:[/* @__PURE__ */e("th",{className:"px-1.5 py-1 text-left font-normal text-muted-foreground"}),["North","South","East"].map(c=>/* @__PURE__ */e("th",{className:H("px-1.5 py-1 text-center font-normal text-muted-foreground",a&&o),children:c},c))]})}),/* @__PURE__ */e("tbody",{children:nl.map((c,d)=>/* @__PURE__ */n("tr",{className:H(d!==nl.length-1&&"border-b border-border/60"),children:[/* @__PURE__ */e("td",{className:H("px-1.5 py-1 text-left text-muted-foreground",s&&o),children:c.label}),c.values.map((l,i)=>/* @__PURE__ */e("td",{className:H("px-1.5 py-1 text-right font-mono tabular-nums text-muted-foreground",r&&o),children:l},i))]},c.label))})]})});}const nl=[{label:"Electronics",values:["2,300","1,800","3,400"]},{label:"Clothing",values:["1,300","620","480"]}],tb={groupBy:Ol,pivotBy:Rl,metrics:Dp,detailColumns:Nr,sortBy:Fo};function ca({onRemoveField:t,zone:a,fields:s,label:r,placeholder:o,shouldShow:c,hasPivotColumns:d=!1}){const{setNodeRef:l}=Ql({id:Tu(a),data:{kind:"shelf",zone:a,pillIds:s.map(g=>g.id)}}),i=Qi(a),{updateSortByColumn:h}=xe(),u=D(g=>g.card),m=D(g=>g.card.type),p=s.length>0,f=i!==null,w=(i==null?void 0:i.kind)!=="refused",C=(i==null?void 0:i.kind)==="refused"?Yi(i.notice,r):null,y=Je((g,F)=>{var V;!((V=u.config)!=null&&V.sortByColumns)||u.config.sortByColumns.findIndex($=>$.id===g)===-1||h(u.id,g,{direction:F});},[u,h]),b=Z(()=>/* @__PURE__ */e("div",{className:"space-y-1",children:s.map((g,F)=>{const V=g.direction;return/* @__PURE__ */n("div",{className:"relative",children:[/* @__PURE__ */e(ab,{zone:a,pillId:g.id,isLast:F===s.length-1}),m==="matrixTable"?/* @__PURE__ */e(Jx,{field:g,zone:a,onRemove:()=>t(a,F)}):/* @__PURE__ */e(Wx,{field:g,zone:a,index:F,sortDirection:V,onSortDirectionChange:$=>y(g.id,$),hasPivotColumns:d,cardType:m})]},g.id);})}),[s,a,m,d,t,y]);if(a==="sortBy"&&c===!1)return null;const v=a!=="sortBy"&&m!=="kpi",N=tb[a]||ga;return/* @__PURE__ */n("div",{ref:l,className:"w-full",role:"group","aria-label":r,children:[/* @__PURE__ */n("div",{className:"mb-1 flex min-w-0 items-center justify-between gap-2",children:[/* @__PURE__ */e(A,{className:"block shrink-0 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:r}),C&&/* @__PURE__ */e("span",{role:"status","data-shelf-refusal-reason":"",className:"min-w-0 truncate text-[11px] text-destructive",children:C})]}),/* @__PURE__ */e("div",{className:H("rounded-control transition-colors",{"border border-foreground/40 bg-muted/50":f&&w,"border border-destructive/40 bg-destructive/5":f&&!w,"border border-dashed border-border/50 bg-background":!f&&!p}),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(N,{className:"h-3 w-3 shrink-0 text-muted-foreground/60"}),/* @__PURE__ */e("span",{children:o}),v&&/* @__PURE__ */e(Xx,{concept:a})]}):b})]});}function ab({zone:t,pillId:a,isLast:s}){const r=Wi(t,a,s);return r?/* @__PURE__ */n("div",{"aria-hidden":!0,"data-shelf-insertion-line":r,className:H("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 nb="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function rb({card:t,metric:a,children:s}){var h,u;const{data:r}=nt(t),o=r==null?void 0:r.metadata,c=Jh(o==null?void 0:o.dateContext,a?fo(o==null?void 0:o.comparisonMetadata,a):void 0),d=r==null?void 0:r.records,l=((h=Rh({renderCard:t,records:d,metadata:o}).trend)==null?void 0:h.points.length)??0,i=((u=t.config)==null?void 0:u.kpiBand)==="trend"?hp(o==null?void 0:o.trend,l):void 0;return/* @__PURE__ */e(me,{children:s(c,i)});}function sb({view:t,trend:a}){const s=ye(o=>o.dashboard),r=Xh(t,{cardTitle:o=>{var c;return s?(c=zh(s,o))==null?void 0:c.title:void 0;}});return/* @__PURE__ */e(lb,{words:r,trend:a});}function lb({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:nb,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(ku,{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:H(!s.applied&&"opacity-50"),children:[/* @__PURE__ */e("div",{className:H("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:H("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(bl,{className:"mt-0.5 h-3.5 w-3.5 shrink-0","aria-hidden":!0}):/* @__PURE__ */e(Vt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0","aria-hidden":!0}),/* @__PURE__ */e("span",{children:t.note.text})]})]})]});}const ob=[];function ib({onRemoveField:t,onResetFields:a,groupByFields:s,pivotByFields:r,metricsFields:o,sortByFields:c,detailFields:d}){var G,ce,ue;const[l,i]=U(!1),{startOver:h,restore:u}=sl();D(X=>{var Y;return!!((Y=X.card.customCardPreferences)!=null&&Y.url);});const m=D(X=>X.card),p=D(X=>X.frame),f=Ut(p,m),{manifest:w}=Kt(((G=f==null?void 0:f.customCardPreferences)==null?void 0:G.url)||""),C=(ce=w==null?void 0:w.visuals)==null?void 0:ce.find(X=>{var Y;return X.name===((Y=f==null?void 0:f.customCardPreferences)==null?void 0:Y.componentName);}),y=Ht(f,C)==="multiple";y&&(ue=f==null?void 0:f.customCardPreferences)!=null&&ue.url;const b=Oh(C==null?void 0:C.slots);D(X=>X.actions.updateCardConfig);const v=D(X=>X.actions.updateCard),N=ye(X=>X.actions.updateDashboardCalculatedFields),F=ye(X=>{var Y;return X.visualEditPendingDashboardCalculatedFields??((Y=X.dashboard)==null?void 0:Y.calculatedFields);})??ob,{scopedFields:O}=Gl(),{userContext:V}=Ua(),$=y&&(f==null?void 0:f.id)===m.id&&b?b:m==null?void 0:m.type,E=$==="detailTable",T=s.length>0||o.length>0||d.length>0,M=!E&&($!=="kpi"||o.length<=2),I=!E,q=!E&&$!=="kpi",P=$!=="kpi"&&$!=="matrixTable"&&T,x=E,R="Drop sort fields here",S=vo(V),k=["pie","doughnut","polar","funnel","bubble","scatter"].includes($),L=q&&!k,_=$==="kpi"&&m.type==="kpi"&&!y&&!wr(m),z=X=>$==="kpi"?{label:"Trend By",placeholder:Zh(X)??"Drop trend field here"}:{label:"Rows",placeholder:"Drop dimensions here"},j=()=>$==="kpi"?{label:"Metric",placeholder:"Drop metric here"}:{label:"Metrics",placeholder:"Drop metrics here"},B=(X,Y)=>/* @__PURE__ */n("div",{className:"space-y-3 px-4 pb-6 pt-3",children:[M&&/* @__PURE__ */e(ca,{zone:"groupBy",onRemoveField:t,fields:s,label:z(X).label,placeholder:z(X).placeholder}),L&&/* @__PURE__ */e(ca,{zone:"pivotBy",onRemoveField:t,fields:r,label:"Pivot Columns",placeholder:"Drop pivot fields here"}),I&&/* @__PURE__ */e(ca,{zone:"metrics",onRemoveField:t,fields:o,label:j().label,placeholder:j().placeholder,hasPivotColumns:r.length>0}),x&&/* @__PURE__ */e(ca,{zone:"detailColumns",onRemoveField:t,fields:d,label:"Columns",placeholder:"Drop columns here"}),o.length>=1&&S&&/* @__PURE__ */n(ie,{variant:"outline",size:"sm",onClick:()=>i(!0),className:"mt-1.5 w-full justify-start border-border/60 border-dashed bg-background text-xs text-foreground/70 hover:bg-muted/40 hover:text-foreground",children:[/* @__PURE__ */e(Du,{className:"mr-2 h-4 w-4"}),"Create Metric"]}),X&&/* @__PURE__ */e(sb,{view:X,trend:Y}),P&&/* @__PURE__ */e(ca,{zone:"sortBy",onRemoveField:t,fields:c,label:"Sort By",placeholder:R})]});return/* @__PURE__ */n(me,{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(db,{card:m,hasFields:T,onClearFields:()=>{var ge;const X=m,Y=Lh.flatMap(be=>{var Ie;return((Ie=X.config)==null?void 0:Ie[be])??[];}),fe=((ge=Jn(X))==null?void 0:ge.joins)??[];a();const he=Y.map(be=>be.label||be.name),re=he.length>4?`${he.slice(0,3).join(", ")} and ${he.length-3} more`:he.join(", "),se=fe.length===1?` The join to ${mo(fe[0].target)} stays.`:fe.length?" The joins stay.":"";Qe("Cleared the fields",{description:`${re?`Removed ${re}.`:""}${se}`.trim()||void 0,action:{label:"Undo",onClick:()=>u(X)}});},onStartOver:h})]}),_?/* @__PURE__ */e(rb,{card:m,metric:o[0],children:(X,Y)=>B(X,Y)}):B(void 0),/* @__PURE__ */e(yo,{open:l,onOpenChange:i,availableFields:O,initialFieldType:"metric",allowedFieldTypes:["metric"],onSave:X=>{if(X.role!=="metric")return;const{nextStoredFields:Y}=cl({storedFields:m.calculatedFields||[],sharedFields:F,updatedField:X,previousScope:"card"});v(m.id,{calculatedFields:Y});},onSaveToDashboard:X=>{if(X.role!=="metric")return;const{nextSharedFields:Y}=il({storedFields:m.calculatedFields||[],sharedFields:F,updatedField:X,previousScope:"dashboard"});N(Y);},cardId:m.id})]});}function cb(){var v,N,g;const t=D(F=>{var O;return(O=F.card)==null?void 0:O.type;}),a=t==="kpi",[s,r]=U(a),[o,c]=U(!1),d=D(F=>{var O;return!!((O=F.card.customCardPreferences)!=null&&O.url);}),l=D(F=>F.card),i=D(F=>F.frame),h=Ut(i,l),{manifest:u}=Kt(((v=h==null?void 0:h.customCardPreferences)==null?void 0:v.url)||""),m=(N=u==null?void 0:u.visuals)==null?void 0:N.find(F=>{var O;return F.name===((O=h==null?void 0:h.customCardPreferences)==null?void 0:O.componentName);}),f=Ht(h,m)==="multiple"&&!!((g=h==null?void 0:h.customCardPreferences)!=null&&g.url),w=!d||f,C=d||f,y=a?"KPI Settings":"Chart Settings",b=w&&!xo(t);return Ne(()=>{a&&r(!0);},[a]),!b&&!C?null:/* @__PURE__ */n("div",{className:"shrink-0 border-t border-border bg-background",children:[b&&s&&/* @__PURE__ */e("div",{className:H("overflow-y-auto border-b border-border px-4",a?"max-h-[72vh]":"max-h-[50vh]"),children:/* @__PURE__ */e($a,{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(mi,{mode:"config"})})}),b&&/* @__PURE__ */n("button",{type:"button",onClick:()=>r(F=>!F),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(en,{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:y})]}),/* @__PURE__ */e(Et,{className:H("h-3 w-3 text-muted-foreground transition-transform",s&&"rotate-180"),strokeWidth:1.75})]}),C&&o&&/* @__PURE__ */e("div",{className:"max-h-[40vh] overflow-y-auto border-b border-t border-border px-4",children:/* @__PURE__ */e(ei,{})}),C&&/* @__PURE__ */n("button",{type:"button",onClick:()=>c(F=>!F),className:H("flex w-full items-center justify-between px-4 py-2.5 text-left transition-colors hover:bg-muted/50",b&&"border-t border-border"),children:[/* @__PURE__ */n("span",{className:"inline-flex items-center gap-2",children:[/* @__PURE__ */e(Mo,{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(Et,{className:H("h-3 w-3 text-muted-foreground transition-transform",o&&"rotate-180"),strokeWidth:1.75})]})]});}function db({card:t,hasFields:a,onClearFields:s,onStartOver:r}){var d,l;if(!(t.type==="matrixTable"?[]:((d=Jn(t))==null?void 0:d.joins)??[]).length)return a?/* @__PURE__ */e("button",{type:"button",onClick:s,className:"text-[11px] text-muted-foreground transition-colors hover:text-foreground",children:"Clear fields"}):null;const c=mo((l=Jn(t))==null?void 0:l.baseEntity);return/* @__PURE__ */n("div",{className:"flex items-center",children:[/* @__PURE__ */e("button",{type:"button",onClick:s,disabled:!a,className:"rounded-l-control px-1 text-[11px] text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-40",children:"Clear fields"}),/* @__PURE__ */n(Wa,{modal:!1,children:[/* @__PURE__ */e(Ja,{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(Et,{className:"h-3 w-3"})})}),/* @__PURE__ */n(Xa,{align:"end",className:"w-[240px]",children:[/* @__PURE__ */n(ot,{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(ot,{onClick:r,className:"flex flex-col items-start gap-0",children:[/* @__PURE__ */e("span",{className:"text-[12.5px]",children:"Start over"}),/* @__PURE__ */n("span",{className:"text-[11px] text-muted-foreground",children:["Clear fields and joins; keep ",/* @__PURE__ */e("span",{className:"font-mono",children:c})]})]})]})]})]});}function ub(){const t=D(l=>l.card),{autoJoinMetadata:a}=nt(t);if(!(a!=null&&a.autoResolved))return null;const{resolvedJoinPlan:s}=a,r=(s==null?void 0:s.joins)||[];if(r.length===0)return null;const o=l=>!l||l.length===0?"No conditions":l.map(i=>{var p,f,w,C;const h=`${(p=i.source)==null?void 0:p.entityName}.${(f=i.source)==null?void 0:f.name}`,u=`${(w=i.target)==null?void 0:w.entityName}.${(C=i.target)==null?void 0:C.name}`,m=i.operator||"=";return`${h} ${m} ${u}`;}).join(" AND "),c=l=>!l.joinKeyGroups||l.joinKeyGroups.length===0?"No conditions defined":l.joinKeyGroups.length===1?o(l.joinKeyGroups[0].keys):l.joinKeyGroups.map((i,h)=>({id:h,operator:i.operator,condition:o(i.keys)})),d=/* @__PURE__ */e(xt,{children:/* @__PURE__ */n(ht,{children:[/* @__PURE__ */e(pt,{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(ft,{side:"bottom",align:"start",className:"max-w-md border border-border bg-popover p-2 text-popover-foreground shadow-[0_4px_16px_rgba(0,0,0,0.08)]",children:/* @__PURE__ */e("div",{className:"space-y-2",children:r.map((l,i)=>{const h=c(l),u=Array.isArray(h);return/* @__PURE__ */n("div",{className:"rounded-md border border-border bg-background p-2 text-foreground",children:[/* @__PURE__ */n("div",{className:"mb-1 flex items-center justify-between gap-2",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2 text-xs",children:[/* @__PURE__ */e("span",{className:"font-medium text-foreground",children:l.source.name}),/* @__PURE__ */e(Eu,{className:"size-3 text-muted-foreground"}),/* @__PURE__ */e("span",{className:"font-medium text-foreground",children:l.target.name})]}),/* @__PURE__ */e("span",{className:"shrink-0 rounded-[3px] border border-border px-1 font-mono text-[10px] uppercase tracking-[0.06em] text-muted-foreground",children:l.joinType})]}),/* @__PURE__ */e("div",{className:"mt-1 space-y-1",children:u?h.map(m=>/* @__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:m.condition}),m.operator&&/* @__PURE__ */n("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",m.operator,")"]})]},m.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:h})})})]},l.id||i);})})})]})});return/* @__PURE__ */n("div",{className:"flex h-7 w-full items-center gap-2 rounded-control border border-input bg-background px-2 text-left transition-colors hover:bg-muted",children:[/* @__PURE__ */e(Iu,{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 mb({onRemoveField:t,onResetFields:a,selectedChart:s,onChartChange:r,isVisible:o=!0,onToggleVisibility:c,groupByFields:d,pivotByFields:l,metricsFields:i,sortByFields:h,detailFields:u}){const m=D(f=>f.editorContext),p=(m==null?void 0:m.type)==="documentSection";return o?/* @__PURE__ */n("div",{"data-content":"Chart Configuration Panel",className:"flex w-[325px] min-w-[325px] shrink-0 flex-col overflow-hidden border-r border-border bg-background transition-all duration-300 ease-in-out",children:[!p&&/* @__PURE__ */n("div",{className:"flex items-start",children:[/* @__PURE__ */e("div",{className:"min-w-0 flex-1",children:/* @__PURE__ */e(Tf,{selectedChart:s,onChartChange:r})}),c&&/* @__PURE__ */e("div",{className:"px-2 pt-4",children:/* @__PURE__ */e(Xe,{tooltip:"Hide chart configuration","aria-label":"Hide chart configuration",onClick:c,className:"h-7 w-7 rounded-[5px] p-0 text-muted-foreground hover:text-foreground",children:/* @__PURE__ */e(Fu,{className:"h-4 w-4",strokeWidth:1.75})})})]}),/* @__PURE__ */n(Cr,{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(ub,{})}),/* @__PURE__ */e(ib,{onRemoveField:t,onResetFields:a,groupByFields:d,pivotByFields:l,metricsFields:i,sortByFields:h,detailFields:u})]}),/* @__PURE__ */e(cb,{})]}):/* @__PURE__ */e("div",{"data-content":"Chart Configuration Panel (collapsed)",className:"flex w-9 shrink-0 flex-col items-center border-r border-border bg-background transition-all duration-300 ease-in-out",children:c&&/* @__PURE__ */e(Xe,{tooltip:"Show chart configuration","aria-label":"Show chart configuration",onClick:c,className:"mt-3 h-7 w-7 rounded-[5px] p-0 text-muted-foreground hover:text-foreground",children:/* @__PURE__ */e(zt,{className:"h-4 w-4",strokeWidth:1.75})})});}function hb({cardId:t,filters:a,onFiltersChange:s,onClearFilters:r,availableFields:o,source:c,isOpen:d,onOpenChange:l}){return/* @__PURE__ */n(ha,{modal:!1,open:d,onOpenChange:l,children:[d&&/* @__PURE__ */e("div",{className:"pointer-events-none fixed inset-0 z-40 bg-zinc-950/40 backdrop-blur-sm"}),/* @__PURE__ */n(pa,{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(Zt,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */e(fa,{className:"truncate text-[13px] font-medium",children:"Card filters"}),/* @__PURE__ */e(ua,{className:"sr-only",children:"Add filters to the card to limit the data that is displayed."})]}),/* @__PURE__ */e(Gh,{filters:a,availableFields:o,source:c,onSave:u=>{s(t,u),l(!1);},onCancel:()=>l(!1),onClearAll:()=>{r(t),l(!1);}})]})]});}const rl=t=>t.active.data.current??null;function pb({activeCardId:t,placeField:a,previewFieldPlacement:s}){const[r]=U(Mu),o=Ae(null),c=Je(()=>{o.current=null,r.set(null);},[r]),d=Je(u=>{c();},[c]),l=Je(u=>{var f;const m=rl(u),p=Cs(u.collisions);if(!m||!p){r.set(null);return;}((f=o.current)==null?void 0:f.zone)!==p.zone&&(o.current={zone:p.zone,outcome:s({field:m.field,from:m.origin,to:p.zone,beforeId:p.beforeId})}),r.set({slot:p,outcome:o.current.outcome});},[r,s]),i=Je(u=>{const m=rl(u),p=Cs(u.collisions);c(),!(!m||!p||!t)&&a({field:m.field,from:m.origin,to:p.zone,beforeId:p.beforeId});},[t,a,c]),h=Je(()=>{c();},[c]);return{dropStore:r,handleDragStart:d,handleDragMove:l,handleDragOver:l,handleDragEnd:i,handleDragCancel:h};}function fb({activeView:t,onViewChange:a,splitViewEnabled:s,hasQueryError:r=!1}){const o=D(h=>h.card),{config:c}=or(ur).tokenProps,d=(c==null?void 0:c.showInfoTab)!==!1&&ho(o.type),l=!s&&Dr(o.type),i=[{id:"chart",label:"Visual"}];return l&&i.push({id:"table",label:"Results"}),d&&i.push({id:"info",label:r?"Error":"Info",isError:r}),/* @__PURE__ */e(Mt,{value:t,onValueChange:h=>a(h),children:/* @__PURE__ */e(At,{variant:"underline",className:"gap-5 border-b-0",children:i.map(h=>/* @__PURE__ */e(Ye,{value:h.id,className:H("px-0 text-[13px]",h.isError&&"text-destructive hover:text-destructive focus-visible:text-destructive data-[state=active]:border-destructive data-[state=active]:text-destructive"),children:h.label},h.id))})});}const gb=[{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 xb(){var s,r;const t=D(o=>o.card),{updateRowLimit:a}=xe();return/* @__PURE__ */n(ee,{value:((r=(s=t.config)==null?void 0:s.rowLimit)==null?void 0:r.toString())||"100",onValueChange:o=>a(t.id,parseInt(o)),children:[/* @__PURE__ */n(te,{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(ae,{})})]}),/* @__PURE__ */e(ne,{align:"end",children:gb.map(o=>/* @__PURE__ */e(K,{value:o.value,className:"text-[12px] tabular-nums",children:o.label},o.value))})]});}function bb({card:t,queryData:a,isLoading:s,isFetching:r,pagination:o,onPaginationChange:c,onSortChange:d,sortState:l,splitViewEnabled:i}){var u;const h=Z(()=>(a==null?void 0:a.records)||[],[a==null?void 0:a.records]);return!i||!Dr(t.type)?/* @__PURE__ */e(rr,{}):/* @__PURE__ */n(tr,{direction:"vertical",className:"h-full min-h-0 w-full",children:[/* @__PURE__ */e(Gt,{defaultSize:60,minSize:30,role:"chart-section",className:"flex flex-col pb-3",children:/* @__PURE__ */e(rr,{})}),/* @__PURE__ */e(Lo,{withHandle:!0}),/* @__PURE__ */e(Gt,{defaultSize:40,minSize:20,role:"results-section",className:"flex flex-col",children:/* @__PURE__ */n("div",{className:"relative flex h-full min-h-0 max-w-full flex-1 grow basis-0 py-4 pl-2 pr-4",children:[(s||r)&&(a==null?void 0:a.records)&&/* @__PURE__ */e("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-background/50",children:/* @__PURE__ */e(Ct,{size:"md",color:"muted","aria-label":"Loading data"})}),(a==null?void 0:a.records)&&/* @__PURE__ */e(pr,{card:t,data:h,resultColumns:a==null?void 0:a.columns,columnKeyMap:a==null?void 0:a.columnKeyMap,totalsByColumnId:a==null?void 0:a.tableTotalsByColumnId,columnTotals:a==null?void 0:a.tableColumnTotals,comparisonMetadata:(u=a==null?void 0:a.metadata)==null?void 0:u.comparisonMetadata,paginationMetadata:o,onPaginationChange:c,isLoading:s||r,onSortChange:d,sortState:l})]})})]});}function vb(t,a){const[s,r]=U(()=>{const o=localStorage.getItem(t);return o?JSON.parse(o):a;});return Ne(()=>{localStorage.setItem(t,JSON.stringify(s));},[s,t]),[s,r];}const yb="semaphor-split-view-enabled";function Nb(){return vb(yb,!0);}function Cb({error:t,showInfoTab:a}){return/* @__PURE__ */e(jo,{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 wb({card:t,effectiveCardType:a=t.type,queryOutput:s}){return Tr(a)?/* @__PURE__ */n(Au,{modal:!1,children:[/* @__PURE__ */e(Pu,{asChild:!0,children:/* @__PURE__ */e(Xe,{tooltip:"Table settings",className:"h-7 w-7 rounded-[5px] p-0",buttonProps:{type:"button","aria-label":"Table settings"},children:/* @__PURE__ */e(en,{className:"h-3.5 w-3.5",strokeWidth:1.75})})}),/* @__PURE__ */n(Ru,{side:"right",hideOverlay:!0,className:"flex w-[420px] flex-col gap-0 p-0 sm:max-w-[420px]",children:[/* @__PURE__ */e(Ou,{className:"sr-only",children:"Table settings"}),/* @__PURE__ */e(Lu,{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(ui,{cardType:a,queryOutput:s,focusSection:"style"})})]})]}):null;}function Sb({className:t,visible:a}){const s=ye(l=>l.selectedFrameId),r=_u(l=>l.selectedVisual),o=D(l=>l.frame),d=!!!(o!=null&&o.visualId||r!=null&&r.id)&&!!s;return!a||d?null:/* @__PURE__ */e("div",{className:H("flex",t),children:/* @__PURE__ */e(bo,{showLabel:!0,className:"h-6 w-fit px-2 py-0.5 text-[11px]"})});}function Tb({activeView:t,onViewChange:a,onFiltersClick:s,activeCard:r}){var et;const o=D(pe=>pe.card),c=D(pe=>pe.inlineFilterValuesMap[(r==null?void 0:r.id)||""]),d=D(pe=>pe.actions.removeCardInlineFilterValue),l=ye(pe=>pe.selectedSheetId),{updateCardConfig:i,setCard:h,updateCardInFrame:u}=xe(),[m,p]=U(!1),[f,w]=U(!1),[C,y]=U(null),{config:b}=or(ur).tokenProps,v=(b==null?void 0:b.showInfoTab)!==!1,N=(b==null?void 0:b.showQueryDebugTools)!==!1,[g,F]=Nb(),O=Dr(o.type),V=v&&ho(o.type),$=v&&!V,E=t==="table"&&(g||!O)||t==="info"&&!V?"chart":t;D(pe=>{var we;return!!((we=pe.card.customCardPreferences)!=null&&we.url);});const T=Ze(),{data:M,errorMessage:I,isLoading:q,isFetching:P,errorSql:x,pagination:R,refetch:S,comparisonMetadata:k,queryRequestPayload:L,resolvedPrimaryDateField:_}=nt(r),z=Ha(r,M),j=()=>{var Ee;const pe=ye.getState(),we=df(Lr.QUERY_GENERATION,{cardConfig:o.config,dataSource:r.dataSource,dashboardFilters:ip({dashboard:pe.dashboard,runtimeValues:{dashboardInputValues:pe.dashboardInputValues},adHocFilterValues:pe.adHocFilterValues,sheetId:l,sheetKind:"dashboard",calendar:((Ee=pe.reportContext)==null?void 0:Ee.calendar)??null}),errorMessage:I,errorSql:x,generatedSql:M==null?void 0:M.sql});y(we),w(!0);},B=()=>{const pe=D.getState().actions;pe.setIsDevMode(!0),pe.setCardSql(x||""),setTimeout(()=>{pe.setRunSql(!0);},100);},G=N?{queryRequest:L,queryResponse:M}:void 0,ce=Z(()=>(M==null?void 0:M.records)||[],[M==null?void 0:M.records]),ue=Z(()=>!P&&ce.length>0?Object.keys(ce[0]):[],[P,ce]),X=Z(()=>({keys:ue,columnKeyMap:M==null?void 0:M.columnKeyMap,resultColumns:M==null?void 0:M.columns}),[ue,M==null?void 0:M.columnKeyMap,M==null?void 0:M.columns]),Y=_l(r),fe=D(pe=>pe.frame),[he,re]=U(),se=()=>{const pe=!g;pe&&E==="table"&&a("chart"),F(pe);},ge=(pe,we)=>{const Ee={...r,paginationConfig:{page:pe+1,pageSize:we}};h(Ee),u(Ee);},be=pe=>{if(!o.config)return;const we=wl(pe,o.config.metricColumns,o.config.groupByColumns,o.config.detailColumns);i(o.id,{...o.config,sortByColumns:we});},Ie=Z(()=>{var pe;return Bu((pe=o.config)==null?void 0:pe.sortByColumns);},[(et=o.config)==null?void 0:et.sortByColumns]),Ve=Vu(La(r)||null);return/* @__PURE__ */e("div",{className:"relative flex w-0 grow flex-col",children:/* @__PURE__ */n("div",{className:"group/visualization relative flex h-full max-w-full grow flex-col",children:[/* @__PURE__ */n("div",{className:"flex h-11 items-center gap-3 border-b border-border px-4",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-3",children:[/* @__PURE__ */e("div",{className:"flex h-11 items-end gap-5 self-stretch",children:/* @__PURE__ */e(fb,{activeView:E,onViewChange:a,splitViewEnabled:g,hasQueryError:!!I})}),T==="kpi"&&/* @__PURE__ */e(Sb,{visible:!0,className:"self-center"}),k&&o.type!=="table"&&/* @__PURE__ */e(Ku,{metadata:k})]}),/* @__PURE__ */n("div",{className:"flex grow items-center justify-end gap-1",children:[!$u(T)&&/* @__PURE__ */e(xb,{}),/* @__PURE__ */e(qu,{cardId:r.id,cardFilters:La(r),cardFilterCount:Ve,onFiltersClick:s,inlineFilters:Bh(r),inlineFilterValues:_h(r,c),sheetId:l||"",removeInlineFilterValue:pe=>d(r.id,pe),resolvedPrimaryDateField:_}),E==="chart"&&/* @__PURE__ */e(wb,{card:r,effectiveCardType:T,queryOutput:X}),E==="chart"&&/* @__PURE__ */e(Xo,{showInlineFilters:!1,showControls:!1,showDisplayOptions:!1}),/* @__PURE__ */n(Wa,{modal:!1,children:[/* @__PURE__ */e(Ja,{asChild:!0,children:/* @__PURE__ */e(Xe,{tooltip:"More Options",className:"h-7 w-7 rounded-[5px] p-0","aria-label":"More options",children:/* @__PURE__ */e(Bl,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(Xa,{align:"end",className:"w-60",children:[/* @__PURE__ */n(ot,{disabled:Y?Y.isFetching:q||P,onSelect:()=>{var pe;if(Y){(pe=Y.refresh)==null||pe.call(Y);return;}S();},children:[/* @__PURE__ */e(Xn,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Refresh"]}),E==="chart"&&/* @__PURE__ */n(me,{children:[/* @__PURE__ */n(ot,{onSelect:s,children:[/* @__PURE__ */e(Zt,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Card filters",Ve>0&&/* @__PURE__ */e("span",{className:"ml-auto text-[11px] tabular-nums text-muted-foreground",children:Ve})]}),/* @__PURE__ */e(Br,{triggerVariant:"menu",className:"w-full"}),/* @__PURE__ */e(Vr,{triggerVariant:"menu",className:"w-full"}),/* @__PURE__ */e(_r,{triggerVariant:"menu",className:"w-full"}),O&&/* @__PURE__ */n(ot,{onClick:se,children:[g?/* @__PURE__ */e(Cp,{className:"h-3.5 w-3.5 text-muted-foreground"}):/* @__PURE__ */e(Ip,{className:"h-3.5 w-3.5 text-muted-foreground"}),g?"Hide results table":"Show results table"]}),Y&&/* @__PURE__ */n(ot,{disabled:Y.isFetching||!Y.hasDelivery,title:Y.hasDelivery?void 0:"Available once the preview has loaded.",onClick:()=>re(Y.readDelivery()),children:[/* @__PURE__ */e(Un,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Download"]})]})]})]})]})]}),/* @__PURE__ */n("div",{className:"flex min-h-0 grow flex-col",children:[E==="chart"?I?$?/* @__PURE__ */e("div",{className:"flex min-h-0 flex-1 flex-col px-1 pb-2",children:/* @__PURE__ */e(Ks,{error:I,errorSql:x,onSendFeedback:j,onOpenInEditor:Sr(o.type)?B:void 0})}):/* @__PURE__ */e(Cb,{error:I,showInfoTab:V}):/* @__PURE__ */e("div",{className:"flex grow flex-col",children:/* @__PURE__ */e(bb,{card:z,queryData:M,isLoading:q,isFetching:P,pagination:R,onPaginationChange:ge,onSortChange:be,sortState:Ie,splitViewEnabled:g})}):null,E==="table"&&(M==null?void 0:M.records)&&/* @__PURE__ */n("div",{className:"relative flex h-full min-h-0 max-w-full flex-1 grow basis-0 px-4 py-4",children:[(q||P)&&(M==null?void 0:M.records)&&/* @__PURE__ */e("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-background/50",children:/* @__PURE__ */e(Ct,{size:"md",color:"muted","aria-label":"Loading data"})}),/* @__PURE__ */e(pr,{card:z,data:ce,resultColumns:M.columns,columnKeyMap:M.columnKeyMap,totalsByColumnId:M==null?void 0:M.tableTotalsByColumnId,columnTotals:M==null?void 0:M.tableColumnTotals,comparisonMetadata:k,paginationMetadata:R,onPaginationChange:ge,isLoading:q||P,onSortChange:be,sortState:Ie})]}),E==="info"&&V&&/* @__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:I?/* @__PURE__ */e(Ks,{error:I,errorSql:x,defaultDetailsOpen:!0,debugPayloads:G,onSendFeedback:j,onOpenInEditor:B}):((M==null?void 0:M.sql)&&/* @__PURE__ */e(Zo,{sql:M.sql,debugPayloads:G}))})})]}),he&&r&&fe&&/* @__PURE__ */e(Vl,{isOpen:!0,onClose:()=>re(void 0),card:r,frame:fe,matrix:he}),C&&/* @__PURE__ */e(Or,{open:f,onOpenChange:w,feedbackData:C})]})});}function kb({activeField:t}){const[a,s]=U(!0);if(Ne(()=>{t&&s(!0);},[t]),!t)return null;const r=yr(t);return/* @__PURE__ */n("div",{className:`flex h-7 max-w-[300px] items-center gap-2 rounded-[5px] border border-border bg-popover px-3 text-[13px] text-foreground/90 shadow-[0_4px_12px_rgba(0,0,0,0.08)] transition-all duration-150 ${a?"scale-100 opacity-100":"scale-95 opacity-0"}`,children:[/* @__PURE__ */e(Yl,{dataType:t.dataType,nativeDataType:t.nativeDataType,calculated:r}),/* @__PURE__ */e("span",{className:"overflow-hidden text-ellipsis whitespace-nowrap",children:t.label||t.name})]});}function Db(){const{active:t}=zu(),a=t==null?void 0:t.data.current;return/* @__PURE__ */e(kb,{activeField:(a==null?void 0:a.field)??null});}const Eb=()=>{const t=console.error;console.error=(...r)=>{r.length>0&&typeof r[0]=="string"&&r[0].includes("ResizeObserver loop completed with undelivered notifications")||t.apply(console,r);};const a=r=>{if(r.message&&(r.message.includes("ResizeObserver loop completed with undelivered notifications")||r.message.includes("ResizeObserver loop limit exceeded")))return r.preventDefault(),r.stopPropagation(),!1;},s=r=>{var o;if((o=r.reason)!=null&&o.message&&(r.reason.message.includes("ResizeObserver loop completed with undelivered notifications")||r.reason.message.includes("ResizeObserver loop limit exceeded")))return r.preventDefault(),!1;};return window.addEventListener("error",a,!0),window.addEventListener("unhandledrejection",s,!0),()=>{console.error=t,window.removeEventListener("error",a,!0),window.removeEventListener("unhandledrejection",s,!0);};};function Ib(){const[t,a]=U("chart"),[s,r]=U(!1),[o,c]=U(!0),[d,l]=U(!0),i=ye(G=>G.isVisualEditing),h=Pr(),u=D(G=>G.card.type);Ne(()=>Eb(),[]);const m=G=>{h(G);},p=D(G=>G.frame),f=D(G=>G.card);D(G=>G.activeTabCardId),D(G=>G.actions.getAvailableFields);const{addCard:w,removeCard:C,updateCard:y,setActiveCard:b,updateFilters:v,clearFilters:N}=xe(),{scopedFields:g=[]}=gr(),F=Il(jn(Ml,{activationConstraint:{distance:8}})),O=f,{getFieldsForContainer:V,placeField:$,previewFieldPlacement:E,removeField:T,resetFields:M}=qa(O,g),{dropStore:I,handleDragStart:q,handleDragMove:P,handleDragOver:x,handleDragEnd:R,handleDragCancel:S}=pb({activeCardId:p.activeCardId,placeField:$,previewFieldPlacement:E}),k=Z(()=>ju(),[]),L=(G,ce)=>{ce&&v(G,ce);},_=G=>{N(G);},{filterableFields:z}=Ji(f),j=G=>{if(!G)return 0;let ce=G.conditions.length;return G.groups.forEach(ue=>{ce+=j(ue);}),ce;},B=j(La(O)||null);return/* @__PURE__ */n(Fl,{sensors:F,collisionDetection:k,onDragStart:q,onDragMove:P,onDragOver:x,onDragEnd:R,onDragCancel:S,children:[/* @__PURE__ */n(Xi.Provider,{value:I,children:[/* @__PURE__ */n("div",{className:"flex h-full grow",children:[/* @__PURE__ */e(Oo,{isVisible:o,onToggleVisibility:()=>c(!o)}),/* @__PURE__ */n("div",{className:"flex flex-1 transition-all duration-300 ease-in-out",children:[/* @__PURE__ */e(mb,{onRemoveField:T,onResetFields:M,selectedChart:u,onChartChange:m,groupByFields:V("groupBy"),pivotByFields:V("pivotBy"),metricsFields:V("metrics"),sortByFields:V("sortBy"),detailFields:V("detailColumns"),isVisible:d,onToggleVisibility:()=>l(!d)}),/* @__PURE__ */e(Tb,{selectedChart:u,activeView:t,onViewChange:a,onFiltersClick:()=>r(!0),filterCount:B,activeCard:O,getFieldsForContainer:V,cards:p.cards,activeCardId:p.activeCardId,addCard:w,setActiveCard:b})]}),!o&&i&&/* @__PURE__ */e("div",{className:"fixed left-6 top-[105px] z-50",children:/* @__PURE__ */e(ie,{size:"sm",variant:"outline",className:"h-10 w-10 rounded-full border-border bg-background p-0 shadow-lg hover:bg-muted",onClick:()=>c(!0),title:"Show Data Source Panel",children:/* @__PURE__ */e(hl,{className:"h-4 w-4"})})})]}),O&&/* @__PURE__ */e(hb,{cardId:O.id,filters:La(O)||null,onFiltersChange:L,onClearFilters:_,availableFields:z,isOpen:s,onOpenChange:r})]}),/* @__PURE__ */e(Uu,{dropAnimation:null,children:/* @__PURE__ */e(Db,{})})]});}function Fb({authToken:t,onSave:a,onClose:s}){const r=D(u=>u.isDevMode),o=mr(),{setAuthToken:c}=Hu(),{setOnSave:d,setOnClose:l}=xe();Ne(()=>{a&&d(a),s&&l(s);},[a,d,s,l]),Ne(()=>{t&&t.accessToken&&c(t);},[t,c]);function i(){return/* @__PURE__ */n(me,{children:[/* @__PURE__ */e(Oo,{isVisible:!0,onToggleVisibility:()=>{}}),/* @__PURE__ */e("div",{className:"relative flex grow",children:/* @__PURE__ */e("div",{"data-content":"editor-main",className:"min-w-[510px] flex-1 basis-0 overflow-hidden",children:/* @__PURE__ */e(Mx,{})})})]});}function h(){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(Ib,{})})});}return(/* @__PURE__ */e(Gu,{children:/* @__PURE__ */e(Ga,{FallbackComponent:Qu,children:r?/* @__PURE__ */e("section",{className:"isolate flex h-full grow","data-content":"editor-panel",style:o.dashboardContainerStyle,children:i()}):/* @__PURE__ */e("section",{className:"isolate flex h-full grow","data-content":"editor-panel",style:o.dashboardContainerStyle,children:h()})})}));}function lv(){ye(f=>f.selectedCardId);const t=ye(f=>f.selectedSheetId),a=ye(f=>f.dashboard),{setIsVisualEditing:s,setSelectedSheetId:r}=ye(f=>f.actions),o=D(f=>f.editorContext),{clearEditorContext:c}=D(f=>f.actions),d=Yu(),l=mr(),i=ye(f=>f.isVisualEditing),h=ye(f=>f.actions.updateFrame),u=Wu();async function m(f){var v,N,g;if((o==null?void 0:o.type)==="documentSection"){await d.commit(f);return;}const w=t?(v=a==null?void 0:a.sheets)==null?void 0:v.some(F=>{var O;return F.id===t&&((O=F.frames)==null?void 0:O.some(V=>V.id===f.id));}):!1,C=(g=(N=a==null?void 0:a.sheets)==null?void 0:N.find(F=>{var O;return(O=F.frames)==null?void 0:O.some(V=>V.id===f.id);}))==null?void 0:g.id,y=w?t:C||null;if(!y)return;const b=Vh(a,f.id);try{const F=await u(f,{previousFrame:b});h(y,f,{semanticExecutionPayload:F}),t!==y&&r(y),s(!1);}catch(F){console.error("Failed to resolve semantic metadata on save:",F),Qe.error(F instanceof Error?F.message:"Failed to resolve semantic metadata for this visual");}}function p(){if((o==null?void 0:o.type)==="documentSection"){d.discard();return;}c(),s(!1);}return/* @__PURE__ */e("div",{role:"editor-container",className:H("flex-1 grow basis-0 overflow-auto",{"max-h-0 overflow-hidden":!i}),style:l.dashboardContainerStyle,children:/* @__PURE__ */e(Fb,{onSave:m,onClose:p})});}export{lv as default};
|