react-semaphor 0.1.607 → 0.1.609

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/analytics-protocol/index.js +1 -1
  2. package/dist/assistant-context/index.js +1 -1
  3. package/dist/brand-studio/index.js +1 -1
  4. package/dist/briefings/index.js +1 -1
  5. package/dist/chunks/{appearance-provider-C4lPZcaN.js → appearance-provider-BW022_Qu.js} +106 -106
  6. package/dist/chunks/{assistant-chat-B7Fngg8U.js → assistant-chat-DAmFZEnD.js} +8 -8
  7. package/dist/chunks/attachment-filter-line-ClTS4GvQ.js +1 -0
  8. package/dist/chunks/{bookmark-impact-DjrrJomS.js → bookmark-impact-BEVaXjug.js} +1 -1
  9. package/dist/chunks/{bookmark-state-x9hJS83D.js → bookmark-state-DnkzIsyw.js} +1 -1
  10. package/dist/chunks/{brand-DgFcvKJI.js → brand-BjC1mPjw.js} +1 -1
  11. package/dist/chunks/card-filter-builder-BGIVEHmJ.js +11 -0
  12. package/dist/chunks/{visual-contract-DQPKg5QW.js → check-input-qgwboKei.js} +13 -5
  13. package/dist/chunks/{comparison-window-caption-zUZDe4tL.js → comparison-window-caption-WzGsqv4n.js} +1 -1
  14. package/dist/chunks/{currency-presentation-binding-w9WDUk3b.js → currency-presentation-binding-ClrH_6Tq.js} +1 -1
  15. package/dist/chunks/{custom-visual-inputs-D8U98aBz.js → custom-visual-inputs-CoAs_73N.js} +1 -1
  16. package/dist/chunks/custom-visual-write-BWApKrHe.js +1 -0
  17. package/dist/chunks/{dashboard-BEd6i29E.js → dashboard-DbBgEesz.js} +1 -1
  18. package/dist/chunks/{dashboard-briefing-launcher-DMDYM9IA.js → dashboard-briefing-launcher-DadG4ES9.js} +14 -9
  19. package/dist/chunks/{dashboard-controls-5B2vCIjJ.js → dashboard-controls-CyQg_GC1.js} +3 -3
  20. package/dist/chunks/{dashboard-json-C6r30x-5.js → dashboard-json-ZSAQQkcR.js} +1 -1
  21. package/dist/chunks/{dashboard-temporal-snapshot-Wki-YACw.js → dashboard-temporal-snapshot-BSTfqT29.js} +1 -1
  22. package/dist/chunks/edit-dashboard-visual-DIF1fllI.js +103 -0
  23. package/dist/chunks/{filter-line-COFQaF4_.js → filter-line-W-qQAjke.js} +1 -1
  24. package/dist/chunks/{filter-reach-preview-BWRGfSmb.js → filter-reach-preview-CfbwaLf4.js} +1 -1
  25. package/dist/chunks/filter-value-text-DQwYZHz0.js +1 -0
  26. package/dist/chunks/kpi-trend-rule-B4ebKzNj.js +1 -0
  27. package/dist/chunks/{layout-grid-DahW4ClC.js → layout-grid-Cs350bW-.js} +1 -1
  28. package/dist/chunks/{matrix-analytical-definition-Bd-dXB8q.js → matrix-analytical-definition-jn075ooo.js} +1 -1
  29. package/dist/chunks/{matrix-member-presentation-CfvxPV-i.js → matrix-member-presentation-Chz6uGYz.js} +1 -1
  30. package/dist/chunks/{matrix-operation-contract-Cw7U53Ao.js → matrix-operation-contract-DceN49RX.js} +1 -1
  31. package/dist/chunks/{metric-formatting-QDqXfQGY.js → metric-formatting-toJrRqu4.js} +1 -1
  32. package/dist/chunks/{numeric-range-options-s6i_nDXg.js → numeric-range-options-Drc1EZ6H.js} +1 -1
  33. package/dist/chunks/{palette-CYvJHSqP.js → palette-DpLPXjUd.js} +1 -1
  34. package/dist/chunks/{pivot-result-contract-expectations-BX5gLcze.js → pivot-result-contract-expectations-D_ane7I2.js} +1 -1
  35. package/dist/chunks/{pivot-result-identity-DOISzHU4.js → pivot-result-identity-DRhVJMsF.js} +1 -1
  36. package/dist/chunks/{raw-temporal-value-Cssny3RJ.js → raw-temporal-value-B4Md6Xfb.js} +1 -1
  37. package/dist/chunks/{report-preferences-dialog-BNpB9byP.js → report-preferences-dialog-DEfUYExu.js} +1 -1
  38. package/dist/chunks/{report-runtime-context-B8HuY0bu.js → report-runtime-context-CkxgMKr6.js} +1 -1
  39. package/dist/chunks/resolve-dashboard-input-context-Dm4PD8Gx.js +8 -0
  40. package/dist/chunks/{sandbox-host-Drf58_oU.js → sandbox-host-BqcLSoTV.js} +1 -1
  41. package/dist/chunks/{saved-dashboard-context-dbdbQ5bB.js → saved-dashboard-context-GjEJuDjj.js} +1 -1
  42. package/dist/chunks/{selection-filter-compiler-DK8KkS9g.js → selection-filter-compiler-BxtEEB6Z.js} +1 -1
  43. package/dist/chunks/semaphor-ready-indicator-BViyPq5k.js +622 -0
  44. package/dist/chunks/set-q-2M4nis.js +1 -0
  45. package/dist/chunks/slider-C2nbml5r.js +599 -0
  46. package/dist/chunks/{stored-dashboard-DmgJQcyZ.js → stored-dashboard-CTwrNvBy.js} +1 -1
  47. package/dist/chunks/{table-cell-text-2x6r_oHO.js → table-cell-text-DJe6I1G3.js} +1 -1
  48. package/dist/chunks/{table-export-sheet-CWqKiQu4.js → table-export-sheet-CthBUHu4.js} +1 -1
  49. package/dist/chunks/{token-types-BSyWn2pb.js → token-types-BM0mpZce.js} +1 -1
  50. package/dist/chunks/{validators-BPGmPz8-.js → validators-U8IL8djK.js} +1 -1
  51. package/dist/chunks/variable-draft-DAVLIY3l.js +1 -0
  52. package/dist/dashboard/index.js +1 -1
  53. package/dist/dashboard-authoring/index.js +1 -1
  54. package/dist/extensions/index.js +1 -1
  55. package/dist/format-utils/index.js +1 -1
  56. package/dist/index.js +1 -1
  57. package/dist/report-runtime-context/index.js +1 -1
  58. package/dist/style.css +1 -1
  59. package/dist/surfboard/index.js +1 -1
  60. package/dist/types/index.js +1 -1
  61. package/dist/types/lib/dashboard-viewer/table-view.d.ts +6 -1
  62. package/dist/types/lib/types/explorer-types.d.ts +12 -0
  63. package/dist/types/shared/dashboard-authoring/card-settings/custom-visual-write.d.ts +6 -0
  64. package/dist/types/shared/dashboard-authoring/card-sort-comparison.d.ts +13 -0
  65. package/dist/types/shared/dashboard-authoring/changes/card-query-part.d.ts +1 -0
  66. package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +12 -0
  67. package/dist/types/shared/dashboard-authoring/index.d.ts +1 -0
  68. package/dist/types/shared/dashboard-authoring/table-sheet-shape.d.ts +8 -0
  69. package/dist/types/shared/dashboard-authoring/variable-draft.d.ts +1 -0
  70. package/dist/types/shared/dashboard-viewer/table-settings.d.ts +8 -0
  71. package/dist/types/shared/extensions/visual-contract.d.ts +3 -1
  72. package/dist/types/shared/usage-events/envelope.d.ts +2 -2
  73. package/package.json +1 -1
  74. package/dist/chunks/attachment-filter-line-wJRB0GSP.js +0 -1
  75. package/dist/chunks/card-filter-builder-CvxygmsE.js +0 -16
  76. package/dist/chunks/check-input-7DVPUuco.js +0 -1
  77. package/dist/chunks/edit-dashboard-visual-F2w7v4iB.js +0 -83
  78. package/dist/chunks/filter-value-text-BSAMEgve.js +0 -1
  79. package/dist/chunks/kpi-trend-rule-BcnKbY7d.js +0 -1
  80. package/dist/chunks/resolve-dashboard-input-context-B-0tONJg.js +0 -8
  81. package/dist/chunks/semaphor-ready-indicator-BSFsqsBJ.js +0 -617
  82. package/dist/chunks/set-oJDaJdtI.js +0 -1
  83. package/dist/chunks/slider-DAvAdfMC.js +0 -599
  84. package/dist/chunks/variable-draft-DGA22H2g.js +0 -1
@@ -1,37 +1,42 @@
1
- import{jsx as t,jsxs as n,Fragment as R}from"react/jsx-runtime";import aa,{useState as F,useEffect as Ye,useMemo as K,useCallback as oe,useLayoutEffect as Mt,useRef as Ze,useContext as Ea}from"react";import{c as De,a0 as rt,aZ as Te,a_ as Le,b0 as Ve,B as I,X as Ue,av as Re,a2 as be,ag as se,ak as vt,bv as na,aa as xe,af as Je,g as yt,au as Nt,aY as U,aj as Ia,bB as $e,bC as je,bV as ra,bD as qe,by as ee,bK as Ta,bG as et,bw as La,u as C,F as le,G as sa,b9 as Ct,A as Ae,a$ as wt,b1 as st,aX as Va,d as kt,at as Ba,bZ as _a,aM as Pa,aK as it,b_ as ia,b$ as Oa,c0 as za,c1 as Ne,c2 as Ra,R as oa,c3 as Ma,c4 as Ua,T as $a,c5 as ja,c6 as ge,c7 as qa,p as St,P as Ee,c8 as la,e as Ie,b as tt,c9 as Wa,ca as ct,cb as Ut,cc as da,al as ca,cd as Ka,am as xt,ce as ua,cf as Qa,a4 as Ce,a5 as we,a6 as ke,a7 as Se,a8 as fe,cg as Ga,ch as Ha,bb as Ya,ax as Xa,bA as ha,ci as Za,cj as Ja,ck as en,cl as tn,cm as an,cn as nn}from"./appearance-provider-C4lPZcaN.js";import{bZ as ma,b_ as Be,bp as rn,b$ as sn,c0 as on,bB as pa,m as ln,R as dn,c1 as cn,bD as Dt,bE as At,bF as Ft,bG as Et,bH as It,bI as Tt,bJ as Lt,bK as fa,c2 as un,bM as hn,by as ut,c3 as mn,c4 as Vt,c5 as ga,aX as ot,c6 as ba,c7 as pn,aY as fn,u as gn,E as bn,y as xa,G as xn,p as vn,c8 as yn,c9 as Nn,ca as Cn,cb as wn,cc as kn,cd as Sn,ce as Dn,cf as An,cg as Fn,bQ as Bt,ch as $t,ci as En,cj as In,ck as Tn,cl as Ln,cm as Vn,cn as Ge,co as Bn,cp as _n,cq as Pn,A as On,ap as zn,aq as Rn,a5 as Mn,a4 as Un,a3 as $n,a2 as jn,$ as qn,Z as Wn,an as Kn}from"./semaphor-ready-indicator-BSFsqsBJ.js";import{L as Me}from"./layout-grid-DahW4ClC.js";import{m as G,kq as at,v as ht,kr as Qn,ak as va,ks as Gn,a6 as Hn,k1 as Yn,kt as Xn,ku as Zn,f7 as Jn,kv as er,a5 as _t,a2 as tr,kw as ar,kx as nr,ky as rr,kz as sr,e as Pt,c_ as ir,bW as or,eN as lr,kA as dr,kB as cr,eY as ur,kC as hr,kD as jt,kE as mr}from"./resolve-dashboard-input-context-B-0tONJg.js";import{U as pr}from"./validators-BPGmPz8-.js";import"./matrix-operation-contract-Cw7U53Ao.js";import"./analytics-base-schemas-DMFrDqn_.js";import"../value-format-preferences/index.js";import{s as He}from"./normalize-dashboard-for-dirty-check-ILKfqgL3.js";import{V as fr,L as gr,C as br,u as ya,a as Na,F as xr,b as vr}from"./card-filter-builder-CvxygmsE.js";import{createPortal as yr}from"react-dom";import{bb as qt,aD as Nr}from"./pivot-result-contract-expectations-BX5gLcze.js";import{D as Cr,au as wr,K as kr,af as nt,Z as Sr}from"./bookmark-state-x9hJS83D.js";import{p as Dr}from"./dashboard-temporal-snapshot-Wki-YACw.js";import{y as Ar,i as Fr}from"./set-oJDaJdtI.js";import"zod";import"./schema-O1Y3WTGF.js";import"./index-DViPGDFj.js";import"./context-Cwj8Axgd.js";import{v as Er}from"./filter-reach-preview-BWRGfSmb.js";import{a as Wt,d as Kt,c as Ir,i as Tr,b as Lr,e as Vr,v as Qt,f as Gt,g as Br}from"./variable-draft-DGA22H2g.js";import{getBriefingPresentation as pe,describeBriefingSchedule as _r,getBriefingCreationIntents as Pr}from"../briefings/index.js";/**
1
+ import{jsx as t,jsxs as n,Fragment as R}from"react/jsx-runtime";import aa,{useState as F,useEffect as Ye,useMemo as K,useCallback as oe,useLayoutEffect as Mt,useRef as Ze,useContext as Ea}from"react";import{c as Ce,a0 as rt,aZ as Te,a_ as Le,b0 as Ve,B as I,X as Ue,av as Re,a2 as be,ag as se,ak as vt,bw as na,aa as xe,af as Je,g as yt,au as Nt,aY as U,aj as Ia,bC as $e,bD as je,bW as ra,bE as qe,bz as ee,bL as Ta,bH as et,bx as La,u as C,F as le,G as sa,b9 as Ct,A as Ae,a$ as wt,b1 as st,aX as Va,d as kt,at as Ba,b_ as _a,aM as Oa,aK as it,b$ as ia,c0 as Pa,c1 as za,c2 as Ne,c3 as Ra,R as oa,c4 as Ma,c5 as Ua,T as $a,c6 as ja,c7 as ge,c8 as qa,p as St,P as Ee,c9 as la,e as Ie,b as tt,ca as Wa,cb as ct,cc as Ut,cd as da,al as ca,ce as Ka,am as xt,cf as ua,cg as Qa,a4 as we,a5 as ke,a6 as Se,a7 as De,a8 as fe,ch as Ga,ci as Ha,bc as Ya,ax as Xa,bB as ha,cj as Za,ck as Ja,cl as en,cm as tn,cn as an,co as nn}from"./appearance-provider-BW022_Qu.js";import{b$ as ma,c0 as Be,br as rn,c1 as sn,c2 as on,bD as pa,m as ln,R as dn,c3 as cn,bF as Dt,bG as At,bH as Ft,bI as Et,bJ as It,bK as Tt,bL as Lt,bM as fa,c4 as un,bO as hn,bA as ut,c5 as mn,c6 as Vt,c7 as ga,aY as ot,c8 as ba,c9 as pn,aZ as fn,u as gn,E as bn,y as xa,G as xn,p as vn,ca as yn,cb as Nn,cc as Cn,cd as wn,ce as kn,cf as Sn,cg as Dn,ch as An,ci as Fn,bS as Bt,cj as $t,ck as En,cl as In,cm as Tn,cn as Ln,co as Vn,cp as Ge,cq as Bn,cr as _n,cs as On,A as Pn,aq as zn,ar as Rn,a6 as Mn,a5 as Un,a4 as $n,a3 as jn,a0 as qn,_ as Wn,ao as Kn}from"./semaphor-ready-indicator-BViyPq5k.js";import{L as Me}from"./layout-grid-Cs350bW-.js";import{n as G,kq as at,v as ht,kr as Qn,ak as va,ks as Gn,a6 as Hn,k1 as Yn,kt as Xn,ku as Zn,f5 as Jn,kv as er,a5 as _t,a2 as tr,kw as ar,kx as nr,ky as rr,kz as sr,e as Ot,cY as ir,bV as or,eL as lr,kA as dr,kB as cr,eW as ur,kC as hr,kD as jt,kE as mr}from"./resolve-dashboard-input-context-Dm4PD8Gx.js";import{U as pr}from"./validators-U8IL8djK.js";import"./matrix-operation-contract-DceN49RX.js";import"./analytics-base-schemas-DMFrDqn_.js";import"../value-format-preferences/index.js";import{s as He}from"./normalize-dashboard-for-dirty-check-ILKfqgL3.js";import{V as fr,L as gr,u as ya,C as Na,F as br,a as xr}from"./card-filter-builder-BGIVEHmJ.js";import{createPortal as vr}from"react-dom";import{bb as qt,aD as yr}from"./pivot-result-contract-expectations-D_ane7I2.js";import{F as Nr,av as Cr,L as wr,ag as nt,_ as kr}from"./bookmark-state-DnkzIsyw.js";import{p as Sr}from"./dashboard-temporal-snapshot-BSTfqT29.js";import{A as Dr,j as Ar}from"./set-q-2M4nis.js";import"zod";import"./schema-O1Y3WTGF.js";import"./index-DViPGDFj.js";import"./context-Cwj8Axgd.js";import{v as Fr}from"./filter-reach-preview-CfbwaLf4.js";import{a as Wt,d as Kt,c as Er,i as Ir,b as Tr,e as Lr,v as Qt,f as Gt,g as Vr}from"./variable-draft-DAVLIY3l.js";import{getBriefingPresentation as pe,describeBriefingSchedule as Br,getBriefingCreationIntents as _r}from"../briefings/index.js";/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const Or=De("ArrowUpRight",[["path",{d:"M7 7h10v10",key:"1tivn9"}],["path",{d:"M7 17 17 7",key:"1vkiza"}]]);/**
6
+ */const Or=Ce("ArrowUpRight",[["path",{d:"M7 7h10v10",key:"1tivn9"}],["path",{d:"M7 17 17 7",key:"1vkiza"}]]);/**
7
7
  * @license lucide-react v0.453.0 - ISC
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const Ht=De("Bell",[["path",{d:"M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9",key:"1qo2s2"}],["path",{d:"M10.3 21a1.94 1.94 0 0 0 3.4 0",key:"qgo35s"}]]);/**
11
+ */const Ht=Ce("Bell",[["path",{d:"M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9",key:"1qo2s2"}],["path",{d:"M10.3 21a1.94 1.94 0 0 0 3.4 0",key:"qgo35s"}]]);/**
12
12
  * @license lucide-react v0.453.0 - ISC
13
13
  *
14
14
  * This source code is licensed under the ISC license.
15
15
  * See the LICENSE file in the root directory of this source tree.
16
- */const Yt=De("MonitorSmartphone",[["path",{d:"M18 8V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h8",key:"10dyio"}],["path",{d:"M10 19v-3.96 3.15",key:"1irgej"}],["path",{d:"M7 19h5",key:"qswx4l"}],["rect",{width:"6",height:"10",x:"16",y:"12",rx:"2",key:"1egngj"}]]);/**
16
+ */const Pr=Ce("CodeXml",[["path",{d:"m18 16 4-4-4-4",key:"1inbqp"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}],["path",{d:"m14.5 4-5 16",key:"e7oirm"}]]);/**
17
17
  * @license lucide-react v0.453.0 - ISC
18
18
  *
19
19
  * This source code is licensed under the ISC license.
20
20
  * See the LICENSE file in the root directory of this source tree.
21
- */const zr=De("MousePointer2",[["path",{d:"M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z",key:"edeuup"}]]);/**
21
+ */const Yt=Ce("MonitorSmartphone",[["path",{d:"M18 8V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h8",key:"10dyio"}],["path",{d:"M10 19v-3.96 3.15",key:"1irgej"}],["path",{d:"M7 19h5",key:"qswx4l"}],["rect",{width:"6",height:"10",x:"16",y:"12",rx:"2",key:"1egngj"}]]);/**
22
22
  * @license lucide-react v0.453.0 - ISC
23
23
  *
24
24
  * This source code is licensed under the ISC license.
25
25
  * See the LICENSE file in the root directory of this source tree.
26
- */const Rr=De("Newspaper",[["path",{d:"M4 22h16a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H8a2 2 0 0 0-2 2v16a2 2 0 0 1-2 2Zm0 0a2 2 0 0 1-2-2v-9c0-1.1.9-2 2-2h2",key:"7pis2x"}],["path",{d:"M18 14h-8",key:"sponae"}],["path",{d:"M15 18h-5",key:"95g1m2"}],["path",{d:"M10 6h8v4h-8V6Z",key:"smlsk5"}]]);/**
26
+ */const zr=Ce("MousePointer2",[["path",{d:"M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z",key:"edeuup"}]]);/**
27
27
  * @license lucide-react v0.453.0 - ISC
28
28
  *
29
29
  * This source code is licensed under the ISC license.
30
30
  * See the LICENSE file in the root directory of this source tree.
31
- */const Ca=De("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);/**
31
+ */const Rr=Ce("Newspaper",[["path",{d:"M4 22h16a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H8a2 2 0 0 0-2 2v16a2 2 0 0 1-2 2Zm0 0a2 2 0 0 1-2-2v-9c0-1.1.9-2 2-2h2",key:"7pis2x"}],["path",{d:"M18 14h-8",key:"sponae"}],["path",{d:"M15 18h-5",key:"95g1m2"}],["path",{d:"M10 6h8v4h-8V6Z",key:"smlsk5"}]]);/**
32
32
  * @license lucide-react v0.453.0 - ISC
33
33
  *
34
34
  * This source code is licensed under the ISC license.
35
35
  * See the LICENSE file in the root directory of this source tree.
36
- */const Mr=De("Terminal",[["polyline",{points:"4 17 10 11 4 5",key:"akl6gq"}],["line",{x1:"12",x2:"20",y1:"19",y2:"19",key:"q2wloq"}]]);function Ur(){return/* @__PURE__ */t("div",{className:"space-y-1.5 py-1",children:[...Array(5)].map((e,a)=>/* @__PURE__ */n("div",{className:"flex animate-pulse items-start gap-3 rounded-xl border border-transparent px-2.5 py-2.5",children:[/* @__PURE__ */t("div",{className:"mt-0.5 h-4 w-4 flex-shrink-0 rounded bg-muted/60"}),/* @__PURE__ */n("div",{className:"flex-1 space-y-1.5",children:[/* @__PURE__ */t("div",{className:"h-4 w-3/5 rounded bg-muted/60"}),/* @__PURE__ */t("div",{className:"h-3 w-4/5 rounded bg-muted/40"})]})]},a))});}function $r({open:e,onOpenChange:a,onSubmit:s,isCreating:r}){const d=rt("interactive"),[o,i]=F(""),[h,u]=F("");Ye(()=>{e||(i(""),u(""));},[e]);const l=()=>{o.trim()&&s({title:o,description:h});},c=p=>{a(p);};return/* @__PURE__ */t(Te,{open:e,onOpenChange:c,children:/* @__PURE__ */n(Le,{showCloseButton:!1,className:"flex max-w-lg grid-cols-none flex-col gap-0 overflow-hidden rounded-card border-border/60 p-0 shadow-lg sm:rounded-card",style:d.dialogStyle,children:[/* @__PURE__ */n("div",{className:"flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-2",children:[/* @__PURE__ */t(Me,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */n("div",{className:"flex min-w-0 items-baseline gap-2",children:[/* @__PURE__ */t(Ve,{className:"truncate text-[13px] font-medium leading-none tracking-normal",children:"New library visual"}),/* @__PURE__ */t("span",{className:"shrink-0 text-[10px] font-medium uppercase leading-none tracking-[0.08em] text-muted-foreground",children:"Visual"})]})]}),/* @__PURE__ */t(I,{size:"xs",variant:"ghost",className:"w-7 px-0 text-muted-foreground hover:text-foreground",onClick:()=>c(!1),"aria-label":"Close",disabled:r,children:/* @__PURE__ */t(Ue,{className:"h-3.5 w-3.5"})})]}),/* @__PURE__ */n("div",{className:"space-y-3 px-4 py-3",children:[/* @__PURE__ */t("p",{className:"text-[12px] text-muted-foreground",children:"Create a saved visual that can be reused across dashboards."}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */t(Re,{htmlFor:"visual-title",className:"text-[12px]",children:"Name"}),/* @__PURE__ */t(be,{id:"visual-title",size:"sm",placeholder:"Untitled visual",value:o,onChange:p=>i(p.target.value),disabled:r,onKeyDown:p=>{p.key==="Enter"&&!p.shiftKey&&(p.preventDefault(),l());}})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */t(Re,{htmlFor:"visual-description",className:"text-[12px]",children:"Description"}),/* @__PURE__ */t(be,{id:"visual-description",size:"sm",placeholder:"Optional",value:h,onChange:p=>u(p.target.value),disabled:r})]})]}),/* @__PURE__ */n("div",{className:"flex shrink-0 justify-end gap-2 border-t border-border/60 px-4 py-2.5",children:[/* @__PURE__ */t(I,{size:"xs",variant:"outline",onClick:()=>c(!1),disabled:r,children:"Cancel"}),/* @__PURE__ */t(I,{size:"xs",onClick:l,disabled:!o.trim()||r,children:r?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin"}),"Creating..."]}):"Create library visual"})]})]})});}function wa(e){return e?new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Unknown";}function ka(e,a){var r;const s=(r=e.ownership.createdBy)==null?void 0:r.type;return s==="tenant"||s==="organization"&&a;}function Ot(e,a){var s,r;return ka(e,a)?((s=e.ownership.createdBy)==null?void 0:s.name)||((r=e.createdByTenantUserRel)==null?void 0:r.name)||e.lastModifiedBy||"Unknown":"Organization";}function jr(e,a){return Ot(e,a).split(/\s+/).filter(Boolean).slice(0,2).map(r=>r.charAt(0).toUpperCase()).join("")||"?";}function qr(e){const a=(e||"").toLowerCase();return a.includes("table")?vt:a.includes("pie")||a.includes("donut")?un:a.includes("line")?hn:a.includes("bar")?Ia:Me;}function Wr({visual:e}){const a=e.ownership.status==="public"?"Public":e.ownership.status==="shared"||e.ownership.sharedCount>0?"Shared":"Private";return/* @__PURE__ */t("span",{className:"inline-flex items-center rounded-[4px] border border-border/60 px-1.5 py-px text-[11px] text-muted-foreground",children:a});}function Fi({open:e,onOpenChange:a}){const s=rt("interactive"),[r,d]=F(""),[o,i]=F(/* @__PURE__ */new Set()),[h,u]=F(!1),[l,c]=F(null),[p,m]=F(null),[g,f]=F(!1),[N,w]=F(null),[T,L]=F(null),B=()=>{i(/* @__PURE__ */new Set()),c(null),m(null),f(!1),w(null);},D=()=>{a(!1),B();},{selectVisual:O}=ma(),{handleAddLibraryVisual:k,handleEditLibraryVisual:v}=Be(),{isConsoleMode:b}=rn(),{resources:_,isLoading:A,isError:H,createResource:V,updateResource:M,deleteResourceAsync:X,duplicateResource:Y,isCreating:he,isDeleting:te}=sn(void 0,y=>{u(!1),y&&(O(y),v(y),D());}),{startUpdating:me,stopUpdating:E,isUpdating:ne}=on(),Q=_,z=K(()=>{const y=r.trim().toLowerCase();return y?Q.filter(j=>{var Z,ue,ye;return((Z=j.title)==null?void 0:Z.toLowerCase().includes(y))||((ue=j.description)==null?void 0:ue.toLowerCase().includes(y))||((ye=j.kind)==null?void 0:ye.toLowerCase().includes(y));}):Q;},[r,Q]),J=K(()=>Q.filter(y=>o.has(y.id)),[o,Q]),de=J.filter(y=>y.permissions.canDelete),ce=J.filter(y=>y.permissions.canShare),ve=z.length>0&&z.every(y=>o.has(y.id)),x=z.some(y=>o.has(y.id)),P=y=>{const j=new Set(o);y(j),i(j);},$=y=>{P(j=>{j.has(y)?j.delete(y):j.add(y);});},W=()=>{i(y=>{const j=new Set(y);return ve?z.forEach(Z=>j.delete(Z.id)):z.forEach(Z=>j.add(Z.id)),j;});},re=async y=>{(await k(y)).success&&D();},_e=async()=>{const y=J;if(y.length===0)return;let j=!1;for(const Z of y)if(!(await k(Z)).success){j=!0;break;}j||D();},lt=y=>{v(y),D();},Fe=y=>{L(y),Y(y,{onSettled:()=>L(null)});},We=()=>{if(de.length===0){U.error("Select a visual you can delete");return;}w(null),f(!0);},dt=async()=>{const y=N?[N]:de;try{for(const j of y)await X(j.id);i(j=>{const Z=new Set(j);return y.forEach(ue=>Z.delete(ue.id)),Z;}),f(!1),w(null);}catch{}},Pe=()=>{if(J.length!==1){U.error("Select one visual to share");return;}const[y]=J;if(!y.permissions.canShare){U.error("You do not have permission to share this visual");return;}c(y);},Oe=({title:y,description:j})=>{if(!p)return;const Z={};if(y!==p.title&&(Z.title=y),(p.description||"")!==j&&(Z.description=j),Object.keys(Z).length===0){m(null);return;}const ue=Object.keys(Z),ye=ue.length===1?ue[0]:void 0;me(p.id,ye),M({resourceId:p.id,data:Z},{onSuccess:()=>{E(p.id,ye),m(null);},onError:()=>{E(p.id,ye);}});},ie=y=>{a(y),y||B();},ze=N?1:de.length;return/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(Te,{open:e,onOpenChange:ie,children:/* @__PURE__ */n(Le,{showCloseButton:!1,className:"flex max-h-[80vh] w-[min(72rem,calc(100vw-2rem))] max-w-none grid-cols-none flex-col gap-0 overflow-hidden rounded-card border-border/60 p-0 shadow-lg sm:rounded-card",style:s.dialogStyle,children:[/* @__PURE__ */n("div",{className:"flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-2",children:[/* @__PURE__ */t(vt,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */n("div",{className:"flex min-w-0 items-baseline gap-2",children:[/* @__PURE__ */t(Ve,{className:"truncate text-[13px] font-medium leading-none tracking-normal",children:"Visuals library"}),/* @__PURE__ */t("span",{className:"shrink-0 text-[10px] font-medium uppercase leading-none tracking-[0.08em] text-muted-foreground",children:"Add to dashboard"})]})]}),/* @__PURE__ */t(I,{size:"xs",variant:"ghost",className:"w-7 px-0 text-muted-foreground hover:text-foreground",onClick:()=>ie(!1),"aria-label":"Close visuals library",children:"×"})]}),/* @__PURE__ */n("div",{className:"flex shrink-0 items-center gap-2 border-b border-border/60 px-3 py-2",children:[/* @__PURE__ */n("div",{className:"relative min-w-[12rem] flex-1 md:max-w-md",children:[/* @__PURE__ */t(na,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),/* @__PURE__ */t("input",{autoFocus:!0,value:r,onChange:y=>d(y.target.value),placeholder:"Search visuals...",className:"h-7 w-full rounded-control border border-input bg-background pl-7 pr-2 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-ring focus:outline-none","aria-label":"Search visuals"})]}),/* @__PURE__ */n(I,{size:"xs",variant:"outline",className:"ml-auto",onClick:()=>u(!0),children:[/* @__PURE__ */t(xe,{className:"h-3.5 w-3.5"}),"New library visual"]})]}),/* @__PURE__ */t("div",{className:"min-h-0 flex-1 overflow-auto",children:A?/* @__PURE__ */t("div",{className:"p-3",children:/* @__PURE__ */t(Ur,{})}):H?/* @__PURE__ */t("div",{className:"flex flex-col items-center gap-2 px-4 py-12 text-center",children:/* @__PURE__ */t("p",{className:"text-[13px] text-destructive",children:"Failed to load visuals"})}):z.length===0?/* @__PURE__ */n("div",{className:"flex flex-col items-center gap-2 px-4 py-12 text-center",children:[/* @__PURE__ */t(Me,{className:"h-5 w-5 text-muted-foreground/60"}),/* @__PURE__ */t("p",{className:"text-[13px] font-medium",children:r?"No visuals found":"No visuals yet"}),/* @__PURE__ */t("p",{className:"text-[12px] text-muted-foreground",children:r?"Try a different search.":"Create a saved visual to add it here."})]}):/* @__PURE__ */t(Kr,{visuals:z,selectedIds:o,allFilteredSelected:ve,someFilteredSelected:x,onSelectAll:W,onToggleSelection:$,onAddVisual:re,onOpenVisual:lt,onEditDetails:m,onShareVisual:c,onDeleteVisual:y=>{w(y),f(!0);},onDuplicateVisual:Fe,duplicatingId:T,isDeleting:te,isConsoleMode:b})}),/* @__PURE__ */n("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border/60 px-3 py-2",children:[/* @__PURE__ */t("div",{className:"flex min-w-0 items-center gap-1.5",children:o.size>0&&/* @__PURE__ */n(R,{children:[/* @__PURE__ */n("span",{className:"text-[12px] text-muted-foreground",children:[/* @__PURE__ */t("span",{className:"font-medium tabular-nums text-foreground",children:o.size})," ","selected"]}),/* @__PURE__ */t(I,{size:"xs",variant:"ghost",onClick:()=>i(/* @__PURE__ */new Set()),children:"Clear"}),/* @__PURE__ */n(I,{size:"xs",variant:"outline",onClick:Pe,disabled:J.length!==1||ce.length!==1,children:[/* @__PURE__ */t(pa,{className:"h-3.5 w-3.5"}),"Share"]}),/* @__PURE__ */n(I,{size:"xs",variant:"outline",className:"text-destructive hover:text-destructive",onClick:We,disabled:de.length===0,children:[/* @__PURE__ */t(Je,{className:"h-3.5 w-3.5"}),"Delete ",de.length||o.size]})]})}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */t(I,{size:"xs",variant:"outline",onClick:()=>ie(!1),children:"Close"}),/* @__PURE__ */n(I,{size:"xs",onClick:_e,disabled:o.size===0,children:[/* @__PURE__ */t(yt,{className:"h-3.5 w-3.5"}),o.size===0?"Add to dashboard":`Add ${o.size} visual${o.size===1?"":"s"}`]})]})]})]})}),/* @__PURE__ */t($r,{open:h,onOpenChange:u,onSubmit:V,isCreating:he}),l&&/* @__PURE__ */t(ln,{resource:l,resourceType:dn.VISUAL,onClose:()=>c(null)}),p&&/* @__PURE__ */t(cn,{open:!!p,resourceLabel:"Visual",initialTitle:p.title||"",initialDescription:p.description||"",onClose:()=>m(null),onSave:Oe,isSaving:ne(p.id)}),/* @__PURE__ */t(Dt,{open:g,onOpenChange:y=>{!y&&te||(f(y),y||w(null));},children:/* @__PURE__ */n(At,{children:[/* @__PURE__ */n(Ft,{children:[/* @__PURE__ */n(Et,{children:["Delete ",ze," visual",ze===1?"":"s","?"]}),/* @__PURE__ */t(It,{children:"This cannot be undone. Visuals already added to dashboards may need to be removed from those dashboards separately."})]}),/* @__PURE__ */n(Tt,{children:[/* @__PURE__ */t(Lt,{disabled:te,children:"Cancel"}),/* @__PURE__ */n(fa,{onClick:y=>{y.preventDefault(),dt();},disabled:te||ze===0,children:[te?/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin"}):/* @__PURE__ */t(Je,{className:"h-3.5 w-3.5"}),te?"Deleting...":"Delete"]})]})]})})]});}function Kr({visuals:e,selectedIds:a,allFilteredSelected:s,someFilteredSelected:r,onSelectAll:d,onToggleSelection:o,onAddVisual:i,onOpenVisual:h,onEditDetails:u,onShareVisual:l,onDeleteVisual:c,onDuplicateVisual:p,duplicatingId:m,isDeleting:g,isConsoleMode:f}){return/* @__PURE__ */n("div",{className:"min-w-[48rem]",children:[/* @__PURE__ */n("div",{className:"grid h-9 grid-cols-[2.5rem_minmax(14rem,1.8fr)_minmax(10rem,1fr)_8rem_7rem_5rem_5.5rem] items-center border-b border-border/60 px-3 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:[/* @__PURE__ */t(Nt,{checked:s?!0:r?"indeterminate":!1,onCheckedChange:d,"aria-label":"Select all visuals"}),/* @__PURE__ */t("span",{children:"Name"}),/* @__PURE__ */t("span",{children:"Created by"}),/* @__PURE__ */t("span",{children:"Updated"}),/* @__PURE__ */t("span",{children:"Visibility"}),/* @__PURE__ */t("span",{className:"text-right",children:"Shared"}),/* @__PURE__ */t("span",{className:"text-right",children:"Actions"})]}),e.map(N=>/* @__PURE__ */t(Qr,{visual:N,selected:a.has(N.id),onToggleSelection:o,onAddVisual:i,onOpenVisual:h,onEditDetails:u,onShareVisual:l,onDeleteVisual:c,onDuplicateVisual:p,duplicatingId:m,isDeleting:g,isConsoleMode:f},N.id))]});}function Qr({visual:e,selected:a,onToggleSelection:s,onAddVisual:r,onOpenVisual:d,onEditDetails:o,onShareVisual:i,onDeleteVisual:h,onDuplicateVisual:u,duplicatingId:l,isDeleting:c,isConsoleMode:p}){var f;const m=qr(e.kind),g=()=>{r(e);};return/* @__PURE__ */n("div",{className:G("group grid min-h-12 grid-cols-[2.5rem_minmax(14rem,1.8fr)_minmax(10rem,1fr)_8rem_7rem_5rem_5.5rem] items-center border-b border-border/50 px-3 text-[13px] hover:bg-muted/50",a&&"bg-muted/70"),children:[/* @__PURE__ */t("div",{children:/* @__PURE__ */t(Nt,{checked:a,onCheckedChange:()=>s(e.id),"aria-label":`Select ${e.title||"visual"}`})}),/* @__PURE__ */n("button",{type:"button",className:"flex min-w-0 items-center gap-2 rounded-[4px] text-left outline-none focus-visible:ring-1 focus-visible:ring-ring",onClick:g,"aria-label":`Add ${e.title||"visual"} to dashboard`,children:[/* @__PURE__ */t(m,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */t("div",{className:"truncate font-medium text-foreground",title:e.title||"Untitled Visual",children:e.title||"Untitled Visual"}),((f=e.description)==null?void 0:f.trim())&&/* @__PURE__ */t("div",{className:"truncate text-[11px] text-muted-foreground",title:e.description,children:e.description})]})]}),/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-2",children:[/* @__PURE__ */t("div",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-muted text-[9px] font-medium text-muted-foreground",children:jr(e,p)}),/* @__PURE__ */t("span",{className:"truncate text-muted-foreground",children:Ot(e,p)})]}),/* @__PURE__ */t("span",{className:"text-muted-foreground",children:wa(e.updatedAt)}),/* @__PURE__ */t(Wr,{visual:e}),/* @__PURE__ */t("span",{className:"text-right tabular-nums text-muted-foreground",children:e.ownership.sharedCount>0?e.ownership.sharedCount:"—"}),/* @__PURE__ */t(Gr,{visual:e,onOpenVisual:d,onEditDetails:o,onShareVisual:i,onDeleteVisual:h,onDuplicateVisual:u,duplicatingId:l,isDeleting:c,isConsoleMode:p})]});}function Gr({visual:e,onOpenVisual:a,onEditDetails:s,onShareVisual:r,onDeleteVisual:d,onDuplicateVisual:o,duplicatingId:i,isDeleting:h,isConsoleMode:u}){return/* @__PURE__ */n("div",{className:"flex items-center justify-end gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",onClick:l=>l.stopPropagation(),children:[/* @__PURE__ */t(I,{size:"xs",variant:"ghost",className:"w-7 px-0",onClick:()=>a(e),"aria-label":"Edit visual",children:/* @__PURE__ */t(ut,{className:"h-3.5 w-3.5"})}),/* @__PURE__ */n($e,{modal:!1,children:[/* @__PURE__ */t(je,{asChild:!0,children:/* @__PURE__ */t(I,{size:"xs",variant:"ghost",className:"w-7 px-0","aria-label":"More actions",children:/* @__PURE__ */t(ra,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(qe,{align:"end",className:"z-[60] w-44 rounded-[6px] border-border/60 p-1 shadow-sm",children:[/* @__PURE__ */n(ee,{onClick:()=>a(e),children:[/* @__PURE__ */t(ut,{className:"h-3.5 w-3.5"}),"Edit visual"]}),/* @__PURE__ */n(ee,{onClick:()=>o(e.id),disabled:i===e.id,children:[i===e.id?/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin"}):/* @__PURE__ */t(Ta,{className:"h-3.5 w-3.5"}),i===e.id?"Duplicating...":"Duplicate"]}),e.permissions.canEdit&&/* @__PURE__ */n(ee,{onClick:()=>s(e),children:[/* @__PURE__ */t(ut,{className:"h-3.5 w-3.5"}),"Edit details"]}),e.permissions.canShare&&/* @__PURE__ */n(ee,{onClick:()=>r(e),children:[/* @__PURE__ */t(pa,{className:"h-3.5 w-3.5"}),"Share"]}),e.permissions.canDelete&&/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(et,{}),/* @__PURE__ */n(ee,{className:"text-destructive focus:bg-destructive/10 focus:text-destructive",onClick:()=>d(e),disabled:h,children:[/* @__PURE__ */t(Je,{className:"h-3.5 w-3.5"}),h?"Deleting...":"Delete"]})]}),/* @__PURE__ */t(et,{}),/* @__PURE__ */n("div",{className:"space-y-1 px-2 py-1.5 text-[11px] text-muted-foreground",children:[ka(e,u)&&/* @__PURE__ */n("div",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */t(mn,{className:"h-3 w-3"}),/* @__PURE__ */t("span",{className:"truncate",children:Ot(e,u)})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */t(La,{className:"h-3 w-3"}),/* @__PURE__ */t("span",{children:wa(e.updatedAt)})]})]})]})]})]});}function Ei(e,a,s=!1){const r=C(c=>c.dashboard),d=C(c=>c.isDashboardEditing),o=C(c=>c.isVisualEditing),i=C(c=>c.onDashboardLifecycleEvent),h=oe(()=>{const{dashboard:c,isVisualEditing:p}=C.getState();return a||!e||!c||c.id!==e.id?!1:p?!0:He(c)!==He(e);},[e,a]);Mt(()=>(C.setState({checkUnsavedDashboardChanges:h}),()=>{C.getState().checkUnsavedDashboardChanges===h&&C.setState({checkUnsavedDashboardChanges:null});}),[h]);const u=K(()=>!s||a||!r||d&&(!e||r.id!==e.id)?null:{dashboardId:r.id,dirty:d&&e?o||He(r)!==He(e):!1},[d,o,a,s,e,r]),l=Ze(null);return Mt(()=>{if(!i||!u){l.current=null;return;}const c=l.current;(c==null?void 0:c.callback)===i&&c.dashboardId===u.dashboardId&&c.dirty===u.dirty||(l.current={callback:i,dashboardId:u.dashboardId,dirty:u.dirty},i({type:"dashboard:dirty-state",dashboardId:u.dashboardId,payload:{dirty:u.dirty}}));},[u,i]),h;}function zt(e){var a;for(const s of e.cards)if(s.type==="matrixTable"&&!pr.safeParse((a=s.config)==null?void 0:a.matrix).success)return U.error("Matrix requires at least one row field, one metric, and valid settings."),!1;return!0;}function mt({className:e,variant:a="outline"}){const s=le(o=>o.onSave),{getUpdatedFrame:r}=Be();function d(){const o=r();zt(o)&&(s==null||s(o));}return/* @__PURE__ */n(I,{onClick:d,className:e,size:"xs",variant:a,children:[/* @__PURE__ */t(yt,{className:"h-3.5 w-3.5"}),"Done"]});}function Hr({className:e,variant:a="default"}){const s=Ct(),[r,d]=F(!1),{setIsVisualEditing:o}=Ae(),{getUpdatedFrame:i}=Be(),h=Vt(),u=le(p=>p.frame),l=ga();return/* @__PURE__ */t(I,{onClick:()=>{const p=i();if(!zt(p))return;const m=(u==null?void 0:u.visualId)||(h==null?void 0:h.id);if(!m){U.error("No visual to save");return;}d(!0),l.mutate({visualId:m,data:{frameObject:p}},{onSuccess:()=>{d(!1),U.success("Visual updated successfully"),s.invalidateQueries({queryKey:["resource-by-id","visual",m],exact:!0});},onError:()=>{d(!1),U.error("Failed to update visual");}});},className:e,size:"xs",variant:a,children:r?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin"}),"Saving"]}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(Ca,{className:"h-3.5 w-3.5"}),"Save to Library"]})});}function Yr({className:e}){const a=Ct(),[s,r]=F(!1),d=Vt(),o=le(f=>f.frame),i=C(f=>f.selectedSheetId),h=C(f=>f.dashboard),{updateFrame:u,setIsVisualEditing:l}=Ae(),{getUpdatedFrame:c}=Be(),p=ga(),m=ot();return/* @__PURE__ */t(I,{onClick:async()=>{if(!i){U.error("No sheet selected");return;}const f=(o==null?void 0:o.visualId)||(d==null?void 0:d.id);if(!f){U.error("No visual to update");return;}r(!0);try{const N=c();if(!zt(N)){r(!1);return;}const w={...N,visualId:f},T=at(h,w.id),L=await m(w,{previousFrame:T});await p.mutateAsync({visualId:f,data:{frameObject:N}}),u(i,w,{semanticExecutionPayload:L,origin:"editor"}),a.invalidateQueries({queryKey:["visuals"]}),a.invalidateQueries({queryKey:["visual",f]}),U.success("Saved to library and applied locally"),setTimeout(()=>{l(!1);},300);}catch(N){console.error("Failed to save and apply:",N),U.error(N instanceof Error?N.message:"Failed to save and apply changes");}finally{r(!1);}},className:e,size:"xs",variant:"default",disabled:s,children:s?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin"}),"Saving..."]}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(Ca,{className:"h-3.5 w-3.5"}),"Save & Apply"]})});}function pt({className:e}){const{setTempQueryData:a,setSqlGen:s}=sa(),r=Ct(),d=le(h=>h.tempQueryData),o=le(h=>h.onClose);function i(){if(d){const{queryKey:h,queryData:u}=d;h&&u&&r.setQueryData(h,u);}s({}),o==null||o();}return/* @__PURE__ */n(I,{onClick:i,className:e,size:"xs",variant:"outline",children:[/* @__PURE__ */t(Ue,{className:"h-3.5 w-3.5"}),"Close"]});}function Xr({open:e,onOpenChange:a,isLibraryVisual:s,currentVisualName:r,isSaving:d=!1,destinationMode:o="both",onConfirm:i}){const[h,u]=F(s&&r?`Copy of ${r}`:r||""),[l,c]=F("");aa.useEffect(()=>{e&&(u(s&&r?`Copy of ${r}`:r||""),c(""));},[e,s,r]);const p=!!h.trim(),m=o==="local"?{saveToLibrary:!1,saveToCurrentDashboard:!0,badgeType:"local",description:"Creates a local copy on the current dashboard.",actionLabel:"Add to Dashboard (Local)"}:o==="library"?{saveToLibrary:!0,saveToCurrentDashboard:!1,badgeType:"library",description:"Creates a reusable visual in Visual Library.",actionLabel:"Save as Library Visual"}:{saveToLibrary:!0,saveToCurrentDashboard:!0,badgeType:"linked",description:"Creates a new library visual and adds a linked copy to this dashboard.",actionLabel:"Save Copy as Linked Visual"},g=()=>{!p||d||i({name:h.trim(),description:l.trim()||void 0,saveToLibrary:m.saveToLibrary,saveToCurrentDashboard:m.saveToCurrentDashboard});};return/* @__PURE__ */t(Te,{open:e,onOpenChange:a,children:/* @__PURE__ */n(Le,{className:"sm:max-w-[500px]",children:[/* @__PURE__ */n(wt,{children:[/* @__PURE__ */n(Ve,{className:"flex items-center gap-2",children:[/* @__PURE__ */t("span",{children:"Save Visual As"}),m.badgeType!=="local"&&/* @__PURE__ */t(fr,{type:m.badgeType,showLabel:!0,className:"px-2 py-0.5"})]}),/* @__PURE__ */t(st,{children:m.description})]}),/* @__PURE__ */n("div",{className:"grid gap-4 py-4",children:[/* @__PURE__ */n("div",{className:"grid gap-2",children:[/* @__PURE__ */t(Re,{htmlFor:"name",children:"Name"}),/* @__PURE__ */t(be,{id:"name",value:h,onChange:f=>u(f.target.value),placeholder:"Enter visual name",disabled:d})]}),/* @__PURE__ */n("div",{className:"grid gap-2",children:[/* @__PURE__ */t(Re,{htmlFor:"description",children:"Description (optional)"}),/* @__PURE__ */t(ba,{id:"description",value:l,onChange:f=>c(f.target.value),placeholder:"Enter visual description",rows:3,disabled:d})]})]}),/* @__PURE__ */n(Va,{children:[/* @__PURE__ */t(I,{variant:"outline",onClick:()=>a(!1),disabled:d,children:"Cancel"}),/* @__PURE__ */n(I,{onClick:g,disabled:!p||d,children:[d&&/* @__PURE__ */t(se,{className:"mr-2 h-4 w-4 animate-spin"}),m.actionLabel]})]})]})});}function Zr(){const[e,a]=F(!1),[s,r]=F(!1),[d,o]=F(null),[i,h]=F(null),u=le(v=>v.frame),l=le(v=>v.card),c=Vt(),p=C(v=>v.selectedSheetId),m=C(v=>v.dashboard),{getUpdatedFrame:g}=Be(),{selectVisual:f}=ma(),{addFrame:N,checkAddFrame:w,setIsVisualEditing:T}=Ae(),L=ot(),B=!!(u!=null&&u.visualId),D=(()=>{var v,b;return((v=u==null?void 0:u.cards)==null?void 0:v.length)===1&&(b=u.cards[0])!=null&&b.title?u.cards[0].title:c!=null&&c.title?c.title:(l==null?void 0:l.title)||"Untitled Visual";})(),O=pn(v=>{v!=null&&v.id&&(f(v),s&&d&&i&&p&&(async()=>{try{const b={...d,id:ht(),visualId:v.id};N(p,b,{semanticExecutionPayload:i,withEditorFieldChanges:!0}),r(!1),o(null),h(null),T(!1);}catch(b){console.error("Failed to promote semantic metadata for saved visual:",b),U.error(b instanceof Error?b.message:"Failed to prepare semantic metadata for the saved visual");}})(),a(!1));});return{saveAsDialogOpen:e,setSaveAsDialogOpen:a,handleSaveAs:async v=>{if(!p){U.error("No sheet selected");return;}const b=g(),A=b.cards.length===1?{...b,cards:b.cards.map(H=>({...H,title:v.name}))}:b;if(v.saveToLibrary){let H=null;if(v.saveToCurrentDashboard)try{H=await L(A,{previousFrame:at(m,A.id)});}catch(M){console.error("Failed to prepare semantic metadata before saving visual:",M),U.error(M instanceof Error?M.message:"Failed to prepare semantic metadata for the saved visual");return;}if(v.saveToCurrentDashboard){const M=w(p,{...A,id:ht()},{withEditorFieldChanges:!0});if(!M.ok){U.error(M.reason);return;}}r(v.saveToCurrentDashboard),o(A),h(H);const V={title:v.name,description:v.description,frameObject:A,isPrivate:!1};O.mutate(V);}else if(v.saveToCurrentDashboard){const H={...A,id:ht(),visualId:void 0};try{const V=await L(A,{previousFrame:at(m,A.id)});N(p,H,{semanticExecutionPayload:V,withEditorFieldChanges:!0}),U.success("Visual saved to dashboard"),a(!1),T(!1);}catch(V){console.error("Failed to save visual to dashboard:",V),U.error(V instanceof Error?V.message:"Failed to prepare semantic metadata for the visual");}}},isLibraryVisual:B,currentVisualName:D,isSaving:O.isPending};}function Ii(e={}){const{isInspectionMode:a}=fn(),s=le(V=>V.frame),r=le(V=>V.editorContext),d=gn(V=>V.selectedVisual),o=C(V=>V.selectedFrameId),i=C(V=>V.selectedSheetId),h=C(V=>V.dashboard),{setIsVisualEditing:u,updateFrame:l}=Ae(),[c,p]=F(!1),[m,g]=F("both"),f=ot(),N=(r==null?void 0:r.type)==="documentSection",w=!!(s!=null&&s.visualId||d!=null&&d.id),T=!!(s!=null&&s.visualId&&o),L=w&&!T,{saveAsDialogOpen:B,setSaveAsDialogOpen:D,handleSaveAs:O,isLibraryVisual:k,currentVisualName:v,isSaving:b}=Zr(),{getUpdatedFrame:_}=Be();if(a)return/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(mt,{className:"rounded-control",variant:"default"}),/* @__PURE__ */t(pt,{})]});if(N)return/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(mt,{className:"rounded-control",variant:"default"}),/* @__PURE__ */t(pt,{})]});const A=async()=>{if(!i){U.error("No sheet selected");return;}if(c)return;p(!0);const M={..._(),visualId:void 0},X=at(h,M.id);try{const Y=await f(M,{previousFrame:X});l(i,M,{semanticExecutionPayload:Y,origin:"editor"});}catch(Y){console.error("Failed to apply local semantic metadata:",Y),p(!1),U.error(Y instanceof Error?Y.message:"Failed to prepare semantic metadata for this visual");return;}setTimeout(()=>{p(!1),U.success("Changes applied. Visual is now local to this dashboard"),u(!1);},300);},H=V=>{g(V),D(!0);};return/* @__PURE__ */n(R,{children:[/* @__PURE__ */n("div",{className:"inline-flex items-center overflow-hidden rounded-control",children:[!w&&/* @__PURE__ */t(mt,{className:"!rounded-none",variant:"default"}),w&&L&&/* @__PURE__ */t(Hr,{className:"!rounded-none",variant:"default"}),w&&T&&/* @__PURE__ */t(Yr,{className:"!rounded-none"}),/* @__PURE__ */n($e,{modal:!1,children:[/* @__PURE__ */t(je,{asChild:!0,children:/* @__PURE__ */t(I,{variant:"default",size:"xs",className:"w-7 !rounded-none border-l border-primary-foreground/20 px-0","aria-label":"Open visual save options",disabled:b||c,children:/* @__PURE__ */t(kt,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(qe,{align:"end",className:"min-w-[220px] rounded-control border border-border/60 p-1 shadow-sm",children:[T&&/* @__PURE__ */n(R,{children:[/* @__PURE__ */n(ee,{onClick:A,disabled:c,children:[/* @__PURE__ */t(yt,{className:"h-3.5 w-3.5"}),c?"Applying...":"Apply Locally"]}),/* @__PURE__ */t(et,{})]}),/* @__PURE__ */n(ee,{onClick:()=>H("local"),disabled:b,children:[/* @__PURE__ */t(xe,{className:"h-3.5 w-3.5"}),"Add to Dashboard (Local)"]}),/* @__PURE__ */n(ee,{onClick:()=>H("library"),disabled:b,children:[/* @__PURE__ */t(gr,{className:"h-3.5 w-3.5"}),"Save as Library Visual"]}),/* @__PURE__ */n(ee,{onClick:()=>H("both"),disabled:b,children:[/* @__PURE__ */t(Ba,{className:"h-3.5 w-3.5"}),"Save Copy as Linked Visual"]})]})]})]}),/* @__PURE__ */t(pt,{}),/* @__PURE__ */t(Xr,{open:B,onOpenChange:V=>{b||D(V);},isLibraryVisual:k,currentVisualName:v,isSaving:b,destinationMode:m,onConfirm:O})]});}function Ti({className:e}){const a=le(c=>c.isDevMode),s=le(c=>c.card.type),r=C(c=>c.isVisualEditing),{setIsDevMode:d}=sa(),{config:o}=Ea(_a).tokenProps,i=(o==null?void 0:o.showAdvancedMode)!==!1;if(!r||!i||!Qn(s))return null;const h=a?zr:br,u=a?"Visual editor":"SQL editor",l=a?"Switch to visual editor":"Switch to SQL editor";return/* @__PURE__ */n("button",{type:"button","aria-label":l,title:l,onClick:()=>d(!a),className:G("inline-flex h-7 items-center gap-1.5 rounded-control border border-input bg-background px-2 text-[12px] font-medium text-foreground transition-colors hover:bg-muted/40 focus-visible:border-ring focus-visible:outline-none",e),children:[/* @__PURE__ */t(h,{className:"h-3 w-3 text-muted-foreground"}),u]});}function Li(){const e=bn()==="sm",a=C(u=>u.isDashboardEditing),s=C(u=>u.isVisualEditing),r=C(u=>{var c;const l=((c=u.dashboard)==null?void 0:c.sheets)??[];return l.find(p=>p.id===u.selectedSheetId)??l[0];}),d=C(u=>u.actions.arrangeSheet),o=C(u=>u.actions.undoArrange);if(!a||s||!r||!va(r))return null;const i=!(r.frames??[]).length,h=u=>{const l=d(r.id,{keepOrder:u});if(!l.ok){U.error(l.reason==="not_a_grid"?"This sheet has no grid to arrange.":"The dashboard can't be arranged right now.");return;}U("Arranged",{duration:1e4,description:u?"Sizes and gaps fixed on every screen size, in your order.":"KPIs on top, charts in pairs, tables full width, on every screen size.",action:{label:"Undo",onClick:()=>{const c=o();!c.ok&&c.reason==="changed_since"&&U.info("The dashboard changed after Arrange, so it can't be undone from here.");}}});};return/* @__PURE__ */n("div",{className:"inline-flex h-7 items-stretch overflow-hidden rounded-control border border-input bg-background",children:[/* @__PURE__ */n(I,{variant:"ghost",size:"xs",disabled:i,title:i?"This sheet has no cards to arrange":"Lay out the cards by kind on every screen size",onClick:()=>h(!1),"aria-label":e?"Arrange":void 0,className:`h-full rounded-none border-0 shadow-none hover:bg-accent${e?" w-7 px-0":""}`,children:[/* @__PURE__ */t(Me,{className:"h-3.5 w-3.5"}),!e&&"Arrange"]}),/* @__PURE__ */n($e,{modal:!1,children:[/* @__PURE__ */t(je,{asChild:!0,children:/* @__PURE__ */t(I,{variant:"ghost",size:"xs",disabled:i,className:"h-full w-7 rounded-none border-0 border-l border-border/60 px-0 shadow-none hover:bg-accent","aria-label":"Open arrange options",children:/* @__PURE__ */t(kt,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */t(qe,{align:"end",className:"z-[60] w-48 rounded-[6px] border-border/60 p-1 shadow-sm",children:/* @__PURE__ */n(ee,{onClick:()=>h(!0),children:[/* @__PURE__ */t(Me,{className:"h-3.5 w-3.5"}),"Keep my order"]})})]})]});}function Vi(){const e=C(d=>d.screenSizesOpen),a=C(d=>{var h,u;const o=((h=d.dashboard)==null?void 0:h.sheets)??[],i=o.find(l=>l.id===d.selectedSheetId)??o[0];return!!i&&va(i)&&!!((u=i.frames)!=null&&u.length);}),s=C(d=>d.actions.setScreenSizesOpen),r=xa("screen-sizes","lg",a?{label:"Screen sizes",icon:/* @__PURE__ */t(Yt,{className:"h-3.5 w-3.5","aria-hidden":!0}),checked:e,order:40,onSelect:()=>s(!e)}:void 0);return!a||r.collapsed?null:/* @__PURE__ */t(I,{type:"button",size:"xs",variant:e?"secondary":"ghost","aria-pressed":e,"aria-label":"Screen sizes",title:"Screen sizes",onClick:()=>s(!e),className:"w-7 px-0",children:/* @__PURE__ */t(Yt,{className:"h-3.5 w-3.5","aria-hidden":!0})});}function Bi({dashboardId:e}){const{openDashboardId:a,access:s,printMode:r,serverIsFavorite:d,fetchedAt:o}=C(Pa(u=>{var l;return{openDashboardId:(l=u.dashboard)==null?void 0:l.id,access:u.viewer.access,printMode:u.viewer.printMode,serverIsFavorite:u.viewer.isFavorite,fetchedAt:u.viewer.fetchedAt};})),i=xn(),h=i.isFavorite(e,d,o);return a!==e||r||s==="session-only"?null:/* @__PURE__ */t(vn,{variant:"toolbar",isFavorite:h,readOnly:s==="read-only",pending:i.isPending(e),onToggle:()=>void i.setFavorite({dashboardId:e,isFavorite:!h})});}function _i(e){var u;const{authToken:a,tokenProps:s}=it(),{data:r}=yn(),{mutate:d,isPending:o}=Nn(),i=!!e&&((u=r==null?void 0:r.preference)==null?void 0:u.defaultDashboardId)===e,h=!r||o;return{available:!!e&&!!(a!=null&&a.accessToken)&&!!(s!=null&&s.apiServiceUrl),isDefault:i,disabled:h,toggle:()=>{!e||h||d({dashboardId:i?null:e});}};}function Pi({open:e,onOpenChange:a,onSave:s,onDiscard:r,isSaving:d,title:o="Unsaved changes",description:i="You have unsaved changes to this dashboard. What would you like to do?",cancelLabel:h="Cancel",discardLabel:u="Discard changes",saveLabel:l="Save"}){return/* @__PURE__ */t(Dt,{open:e,onOpenChange:p=>{!p&&d||a(p);},children:/* @__PURE__ */n(At,{children:[/* @__PURE__ */n(Ft,{children:[/* @__PURE__ */t(Et,{children:o}),/* @__PURE__ */t(It,{children:i})]}),/* @__PURE__ */n(Tt,{children:[/* @__PURE__ */t(I,{type:"button",size:"xs",onClick:r,disabled:d,variant:"outline",className:"mr-auto text-destructive hover:border-destructive/40 hover:bg-destructive/10 hover:text-destructive focus-visible:bg-destructive/10 focus-visible:text-destructive",children:u}),s?/* @__PURE__ */t(Lt,{disabled:d,children:h}):/* @__PURE__ */t(Cn,{asChild:!0,children:/* @__PURE__ */t(I,{type:"button",size:"xs",children:h})}),s&&/* @__PURE__ */t(I,{type:"button",size:"xs",onClick:s,disabled:d,children:d?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(se,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Saving..."]}):l})]})]})});}async function Oi(e){var o,i;const a=(i=(o=C.getState())==null?void 0:o.authToken)==null?void 0:i.accessToken;if(!a)return;const s=`${e}/v1/invalidate-token`,r=await fetch(s,{method:"POST",headers:{Authorization:`Bearer ${a}`}});if(!r.ok)throw new Error("Failed to invalidate token");const d=await r.json();return console.log("invalidateToken",d),d;}function Jr(e){var s;const a=e.item;return a.kind==="export"?{title:a.title,status:a.status,startedAt:a.startedAt,finishedAt:a.finishedAt,running:ja(a.stage),finishedDetail:[a.totalRows!==null?`${a.totalRows.toLocaleString("en-US")} rows`:null,a.fileSize?$a(a.fileSize):null].filter(r=>!!r),failure:((s=a.failure)==null?void 0:s.kind)==="export"?a.failure.message:a.status==="failed"?Ne.failedFallback:null,note:null}:{title:a.title,status:a.status,startedAt:a.startedAt,finishedAt:a.finishedAt,running:{text:a.stageLabel??Ne.inProgress},finishedDetail:[],failure:null,note:a.omittedAttachmentCount>0?ge.attachmentsLeftOut(a.omittedAttachmentCount):null};}function Xt({row:e,now:a,api:s}){const[r,d]=F("idle"),o=za(e,s),i=async()=>{if(!o)return;d("working");const h=await qa(s,e,o);d(h==="done"?"idle":h);};return/* @__PURE__ */t(Sa,{shown:Jr(e),now:a,longRunningHint:e.item.kind==="export",action:o?{label:ia[o],run:()=>void i()}:null,working:r==="working",problem:r==="denied"||r==="blocked"?r:null});}function es({work:e,now:a}){const s=e.stage==="preparing"?e.cancel:null;return/* @__PURE__ */t(Sa,{shown:{title:e.title,status:"running",startedAt:e.startedAt,finishedAt:null,running:Oa(e),finishedDetail:[],failure:null,note:null},now:a,longRunningHint:!1,action:s?{label:ia.cancel,run:s}:null,working:!1,problem:null});}function Sa({shown:e,now:a,longRunningHint:s,action:r,working:d,problem:o}){const i=e.status==="ready"?"bg-emerald-500":e.status==="failed"?"bg-destructive":e.status==="cancelled"?"bg-muted-foreground/40":"animate-pulse bg-muted-foreground/60",h=e.status==="ready"?Ne.ready:e.status==="failed"?Ne.failed:e.status==="cancelled"?Ne.cancelled:Ne.inProgress,u=Date.parse(e.startedAt),l=qt(Date.parse(e.finishedAt??e.startedAt),a,{addSuffix:!0}),c=e.status==="running"&&s&&a-u>=Ra,p=/* @__PURE__ */t("span",{className:"text-muted-foreground/50",children:"·"});return/* @__PURE__ */n("div",{className:"group flex items-start gap-2.5 px-3 py-2 transition-colors hover:bg-muted/40 focus-within:bg-muted/40",children:[/* @__PURE__ */t("span",{className:"flex h-5 shrink-0 items-center","aria-hidden":"true",children:/* @__PURE__ */t("span",{className:`h-1.5 w-1.5 rounded-full ${i}`})}),/* @__PURE__ */t("span",{className:"sr-only",children:h}),/* @__PURE__ */n("div",{className:"min-w-0 flex-1",children:[/* @__PURE__ */n("div",{className:"flex h-5 items-center gap-2",children:[/* @__PURE__ */t("span",{className:"min-w-0 flex-1 truncate text-[13px] font-medium leading-5",children:e.title}),r&&d&&/* @__PURE__ */t("span",{role:"status",className:"inline-flex shrink-0 items-center gap-1.5 text-[12px] text-muted-foreground",children:/* @__PURE__ */t(oa,{className:"h-3 w-3 animate-spin",strokeWidth:1.75})}),r&&!d&&/* @__PURE__ */t("button",{type:"button",onClick:r.run,className:"shrink-0 text-[12px] font-medium text-foreground/80 underline-offset-2 hover:text-foreground hover:underline focus-visible:underline focus-visible:outline-none",children:r.label})]}),e.status==="running"&&e.running&&/* @__PURE__ */n("div",{className:"text-[12px] leading-4 text-muted-foreground",children:[/* @__PURE__ */t("span",{className:"tabular-nums",children:e.running.text}),e.running.detail&&/* @__PURE__ */n(R,{children:[" ",p," ",/* @__PURE__ */t("span",{className:"tabular-nums",children:e.running.detail})]})," ",p," ",/* @__PURE__ */t("span",{children:Ne.started(qt(u,a))}),e.running.percent!==void 0&&/* @__PURE__ */t(Ma,{value:e.running.percent,className:"mt-1.5 h-1"}),c&&/* @__PURE__ */t("div",{className:"mt-1",children:Ne.longRunning})]}),e.status!=="running"&&/* @__PURE__ */n("div",{className:"flex items-center gap-1.5 text-[12px] leading-4 text-muted-foreground",children:[e.status==="ready"&&e.finishedDetail.length>0?/* @__PURE__ */n("span",{className:"hidden group-hover:contents group-focus-within:contents",children:[e.finishedDetail.map((m,g)=>/* @__PURE__ */n(aa.Fragment,{children:[g>0&&p,/* @__PURE__ */t("span",{children:m})]},g)),p]}):e.status!=="ready"?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t("span",{children:h}),p]}):null,/* @__PURE__ */t("span",{children:l})]}),e.note&&/* @__PURE__ */t("div",{className:"text-[12px] leading-4 text-muted-foreground",children:e.note}),e.status==="failed"&&e.failure&&/* @__PURE__ */t("div",{className:"mt-1 whitespace-pre-wrap break-words text-[12px] leading-4 text-destructive",children:e.failure}),o&&/* @__PURE__ */t(Ua,{problem:o,className:"mt-1"})]})]});}function zi({variant:e}){const{snapshot:a,markSeen:s}=St(),r=a.runningCount>0?a.runningCount>9?"9+":String(a.runningCount):a.hasUnseenFinished?"":null,d=xa("activity","md",{label:ge.title,icon:/* @__PURE__ */t(Ht,{className:"h-3.5 w-3.5"}),hint:r||(r===""?"New":void 0),order:30,onOpen:s});return d.collapsed?/* @__PURE__ */n(Ee,{open:d.popoverOpen,onOpenChange:o=>{d.setPopoverOpen(o),o&&s();},children:[d.anchorSlot&&yr(/* @__PURE__ */t(la,{asChild:!0,children:/* @__PURE__ */t("span",{className:"absolute right-0 top-0 h-7 w-px"})}),d.anchorSlot),/* @__PURE__ */t(Ie,{className:"w-80 p-0",align:"end",sideOffset:8,onFocusOutside:o=>o.preventDefault(),children:/* @__PURE__ */t(Zt,{})})]}):/* @__PURE__ */n(Ee,{onOpenChange:o=>{o&&s();},children:[/* @__PURE__ */t(tt,{asChild:!0,children:/* @__PURE__ */n(I,{variant:e??"ghost",size:"xs",className:"relative w-7 px-0","aria-label":ge.title,title:ge.title,children:[/* @__PURE__ */t(Ht,{className:"h-3.5 w-3.5"}),r!==null&&/* @__PURE__ */t("span",{className:`absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${r?"-right-0.5 -top-0.5 h-3.5 min-w-3.5 px-0.5 text-[9px] font-semibold":"right-1 top-1 h-1.5 w-1.5"}`,children:r})]})}),/* @__PURE__ */t(Ie,{className:"w-80 p-0",align:"end",sideOffset:8,children:/* @__PURE__ */t(Zt,{})})]});}function Zt(){const e=St(),a=Wa(),{rows:s,browserRows:r,activeTruncated:d}=e.snapshot,o=s.some(l=>ct(l.item.status)),i=[...s.filter(l=>!ct(l.item.status)).map(l=>({startedAt:l.item.startedAt,row:l})),...r.map(l=>({startedAt:l.startedAt,work:l}))].sort((l,c)=>c.startedAt.localeCompare(l.startedAt)),h=s.filter(l=>ct(l.item.status)),u=s.length+r.length;return u===0?/* @__PURE__ */n("div",{className:"flex flex-col items-center gap-1.5 px-6 py-8 text-center",children:[/* @__PURE__ */t("span",{className:"flex h-8 w-8 items-center justify-center rounded-[6px] border border-border text-muted-foreground",children:/* @__PURE__ */t(wn,{className:"h-3.5 w-3.5",strokeWidth:1.75})}),/* @__PURE__ */t("p",{className:"text-[13px] font-medium",children:ge.title}),/* @__PURE__ */t("p",{className:"text-[12px] text-muted-foreground",children:ge.empty})]}):/* @__PURE__ */n("div",{className:"flex flex-col",children:[/* @__PURE__ */n("div",{className:"flex h-8 items-center gap-2 border-b border-border px-3",children:[/* @__PURE__ */t("span",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:ge.title}),/* @__PURE__ */t("span",{className:"text-[10px] tabular-nums text-muted-foreground/70",children:u}),/* @__PURE__ */n("div",{className:"ml-auto flex items-center gap-0.5",children:[o&&/* @__PURE__ */t(I,{variant:"ghost",size:"xs",className:"h-6 px-1.5 text-[12px] text-muted-foreground hover:text-foreground",onClick:e.clearFinished,children:ge.clear}),/* @__PURE__ */t(I,{variant:"ghost",size:"xs",className:"h-6 w-6 px-0 text-muted-foreground hover:text-foreground",onClick:e.refresh,title:"Refresh status","aria-label":"Refresh status",children:/* @__PURE__ */t(oa,{strokeWidth:1.75,className:"h-3.5 w-3.5"})})]})]}),d&&/* @__PURE__ */t("p",{className:"border-b border-border px-3 py-2 text-[12px] leading-4 text-muted-foreground",children:ge.truncated}),/* @__PURE__ */t("div",{className:"max-h-[320px] overflow-y-auto",children:/* @__PURE__ */n("div",{className:"divide-y divide-border/70",children:[i.map(l=>"work"in l?/* @__PURE__ */t(es,{work:l.work,now:a},l.work.id):/* @__PURE__ */t(Xt,{row:l.row,now:a,api:e},Ut(l.row))),h.map(l=>/* @__PURE__ */t(Xt,{row:l,now:a,api:e},Ut(l)))]})})]});}function ts(e){if(e)return{renamed:e.type==="rename"?{oldId:e.oldId,newId:e.newId}:void 0,removedControlId:e.type==="remove"?e.controlId:void 0,cardBindingsById:e.type==="add"||e.type==="update"?e.cardBindingsById:void 0,affectedBindingControlIds:e.type==="add"||e.type==="update"?e.affectedBindingControlIds:void 0};}function as({open:e,onOpenChange:a,trigger:s,showTrigger:r=!0,initialMode:d="manage"}){const o=d==="create",{forceClose:i,handleOpenChange:h,isCreateFlowActive:u,preventPassiveDismissDuringCreate:l,resolvedOpen:c,setIsCreateFlowActive:p}=ya({open:e,onOpenChange:a,initialCreateFlowActive:d==="create",dismissMode:r?"passive":"explicit-only"}),m=C(b=>b.dashboard),{setDashboardControlsModel:g}=Ae(),{participants:f}=kn(Cr(m)),N=Array.from(new Map(f.flatMap(b=>b.fieldChoices.map(_=>{var A;return[_.value,{option:_,target:(A=b.fieldTargetMap)==null?void 0:A[_.value]}];}))).values()),w=Array.from(new Map(f.flatMap(b=>b.metricChoices.map(_=>{var A;return[_.value,{option:_,target:(A=b.metricTargetMap)==null?void 0:A[_.value]}];}))).values()),T=Gn({...(m||{}),controls:[]}),L=Sn(m),B=(b,_,A)=>{g(b,_,ts(A));},D=oe(()=>{if(o){i();return;}p(!1);},[o,i,p]),O=/* @__PURE__ */t(Na,{scope:"dashboard",controls:m.controls||[],reservedControlIds:T,defaultValues:m.defaultControlValues||{},usageByControlId:Dn(m),availableFieldChoices:N,availableMetricChoices:w,structuralParticipants:f,structuralParticipantIdsByControlId:L,initialCreateFlow:d==="create",onCreateFlowActiveChange:p,onCreateFlowComplete:D,onChange:B,emptyMessage:"No dashboard controls yet."}),k=u?"Add dashboard control":"Dashboard Controls",v=/* @__PURE__ */n(R,{children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */t("h4",{className:"text-sm font-medium",children:"Dashboard Controls"}),/* @__PURE__ */t("p",{className:"text-xs text-muted-foreground",children:"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),O]});return r?/* @__PURE__ */n(Ee,{open:c,onOpenChange:h,children:[/* @__PURE__ */t(tt,{asChild:!0,children:s||/* @__PURE__ */n(I,{variant:"outline",className:"h-7 px-2",size:"sm",children:[/* @__PURE__ */t(da,{className:"mr-2 h-4 w-4"}),"Controls"]})}),/* @__PURE__ */t(Ie,{className:"w-[620px] max-w-[95vw] space-y-4",align:"end",onEscapeKeyDown:l,onPointerDownOutside:l,children:v})]}):/* @__PURE__ */t(Te,{open:c,onOpenChange:h,children:/* @__PURE__ */n(Le,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:l,onPointerDownOutside:l,children:[/* @__PURE__ */n(wt,{className:u?"space-y-0":void 0,children:[/* @__PURE__ */t(Ve,{className:"text-[15px]",children:k}),/* @__PURE__ */t(st,{className:u?"sr-only":"text-[13px]",children:u?"Configure and add a shared dashboard control.":"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),/* @__PURE__ */t("div",{className:"min-h-0 overflow-y-auto pr-1",children:O})]})});}const ns=["enum","multi_enum","text","number","boolean","date"];function rs({open:e,onOpenChange:a,initialMode:s="manage"}){var v;const r=s==="create",{forceClose:d,handleOpenChange:o,isCreateFlowActive:i,preventPassiveDismissDuringCreate:h,resolvedOpen:u,setIsCreateFlowActive:l}=ya({open:e,onOpenChange:a,initialCreateFlowActive:s==="create",dismissMode:"explicit-only"}),c=C(b=>b.dashboard),p=C(b=>b.selectedSheetId),{setDashboardInputs:m}=Ae(),g=(v=c.sheets)==null?void 0:v.find(b=>b.id===p),f=(g==null?void 0:g.kind)==="document"&&!!g.document,N=K(()=>f&&g!=null&&g.document?Hn(c,g.id):[],[c,f,g==null?void 0:g.document,g==null?void 0:g.id]),w=K(()=>N.filter(b=>b.kind==="control"),[N]),T=K(()=>w.map(b=>b.control),[w]),L=K(()=>is(T),[T]),B=K(()=>[...ss(c),...(c.variables??[]).map(b=>b.name)],[c]),D=oe(()=>{if(r){d();return;}l(!1);},[r,d,l]),O=oe((b,_,A)=>{!f||!(g!=null&&g.document)||m(ls({dashboard:c,documentSheetId:g.id,currentDocumentInputs:N,nextControls:b,nextDefaultValues:_,change:A}));},[c,N,f,g,m]);return!f||!(g!=null&&g.document)?null:/* @__PURE__ */t(Te,{open:u,onOpenChange:o,children:/* @__PURE__ */n(Le,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:h,onPointerDownOutside:h,children:[/* @__PURE__ */n(wt,{className:i?"space-y-0":void 0,children:[/* @__PURE__ */t(Ve,{className:"text-[15px]",children:i?"Add document control":"Document Controls"}),/* @__PURE__ */t(st,{className:i?"sr-only":"text-[13px]",children:i?"Configure and add a document-local control input.":"Add document-local control inputs. They are stored on this document sheet and are not dashboard controls."})]}),/* @__PURE__ */t("div",{className:"min-h-0 overflow-y-auto pr-1",children:/* @__PURE__ */t(Na,{scope:"dashboard",controls:T,reservedControlIds:B,defaultValues:L,usageByControlId:{},availableFieldChoices:[],availableMetricChoices:[],structuralParticipants:[],structuralParticipantIdsByControlId:{},allowedControlTypes:ns,initialCreateFlow:s==="create",onCreateFlowActiveChange:l,onCreateFlowComplete:D,onChange:O,emptyMessage:"No document controls yet."})})]})});}function ss(e){return(e.controls||[]).map(a=>a.id);}function is(e){const a={};for(const s of e)s.defaultValue!==void 0&&(a[s.id]=s.defaultValue);return a;}function os(e,a){return a?Object.prototype.hasOwnProperty.call(a,e.id)?{...e,defaultValue:a[e.id]}:e.defaultValue===void 0?e:{...e,defaultValue:void 0}:e.defaultValue===void 0?e:{...e,defaultValue:void 0};}function ls({dashboard:e,documentSheetId:a,currentDocumentInputs:s,nextControls:r,nextDefaultValues:d,change:o}){const i=new Map(r.map(g=>[g.id,os(g,d)])),h=(o==null?void 0:o.type)==="rename"?{oldId:o.oldId,newId:o.newId}:null,u=/* @__PURE__ */new Set(),l=[];for(const g of s){if(g.kind!=="control"){l.push(g);continue;}const f=i.get(g.control.id)||((h==null?void 0:h.oldId)===g.control.id?i.get(h.newId):void 0);if(!f)continue;u.add(f.id);const N=Yn(e,{name:f.id},{exclude:{source:"input",inputId:g.id},alsoTaken:l}),w=f.id===N?f:{...f,id:N};l.push({...g,label:w.label,variableName:N,requiredAtExecution:w.requiredAtExecution,control:w});}for(const g of i.values())u.has(g.id)||l.push(Xn({control:g,dashboard:e,alsoTaken:l,sheetId:a}));const c=new Set(s.map(g=>g.id));return[...(Array.isArray(e.inputs)?e.inputs:[]).filter(g=>!c.has(g.id)),...l];}function ds({showFilters:e,onShowFiltersChange:a,pickerContent:s,settingsContent:r,size:d="default",className:o,primaryButtonClassName:i,secondaryButtonClassName:h,pickerContentClassName:u,settingsContentClassName:l}){const c=d==="toolbar",[p,m]=F(!1),g=rt("interactive");return/* @__PURE__ */n("div",{className:G("relative inline-flex items-stretch overflow-hidden rounded-control border border-input bg-background",c?"h-8":"h-7",o),children:[/* @__PURE__ */n(Ee,{open:e,onOpenChange:a,children:[/* @__PURE__ */t(tt,{asChild:!0,children:/* @__PURE__ */n(I,{variant:"ghost",size:"xs",className:G("h-full rounded-none border-0 bg-transparent pl-2.5 pr-2 shadow-none hover:bg-accent/50 data-[state=open]:bg-accent/60",i),children:[e?/* @__PURE__ */t(xr,{className:"h-3.5 w-3.5"}):/* @__PURE__ */t(ca,{className:"h-3.5 w-3.5"}),"Filter"]})}),/* @__PURE__ */t(Ie,{align:"end",sideOffset:6,className:G("w-auto rounded-card border border-border/60 p-0 shadow-[0_10px_28px_rgba(0,0,0,0.14)] dark:shadow-[0_10px_28px_rgba(0,0,0,0.5)]",u),style:g.contentStyle,children:s})]}),/* @__PURE__ */n(Ee,{open:p,onOpenChange:m,children:[/* @__PURE__ */t(tt,{asChild:!0,children:/* @__PURE__ */t(I,{variant:"ghost",size:"xs",className:G("h-full w-7 rounded-none border-0 border-l border-border/60 bg-transparent px-0 shadow-none hover:bg-accent/50 data-[state=open]:bg-accent/60",h),"aria-label":"Filter and control actions",children:/* @__PURE__ */t(kt,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */t(Ie,{align:"end",sideOffset:6,className:G("w-auto rounded-card border border-border/60 p-0 shadow-[0_10px_28px_rgba(0,0,0,0.14)] dark:shadow-[0_10px_28px_rgba(0,0,0,0.5)]",l),style:g.contentStyle,children:r(()=>m(!1))})]})]});}function cs(){const e=C(l=>l.dashboard),a=C(l=>l.semanticExecutionPayload),s=C(l=>l.actions.addFilterInput),r=C(l=>l.selectedSheetId),d=K(()=>{var c,p;const l=((c=e==null?void 0:e.sheets)==null?void 0:c.find(m=>m.id===r))??((p=e==null?void 0:e.sheets)==null?void 0:p[0]);return((l==null?void 0:l.frames)??[]).map(m=>Dr(m)).filter(m=>!!m);},[e,r]),o=Ar(d).length>0,i=K(()=>Zn(e,a),[e,a]),u=!Jn(e)&&i.hasEligibleCards;return/* @__PURE__ */n("div",{className:"flex h-[520px] w-[400px] flex-col",children:[u&&/* @__PURE__ */t("div",{className:"border-b border-border/60 p-2",children:/* @__PURE__ */n("button",{type:"button",onClick:()=>s(er(),{kind:"allSheets",sheetKinds:["dashboard"]}),title:`Applies to ${i.eligibleCardCount} of ${i.totalCardCount} date-aware cards`,className:"flex w-full items-start gap-2 rounded-control px-2 py-1.5 text-left outline-none transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-border",children:[/* @__PURE__ */t(An,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */n("span",{className:"flex min-w-0 flex-col",children:[/* @__PURE__ */t("span",{className:"text-[12px] font-medium text-foreground",children:"Add global date filter"}),/* @__PURE__ */t("span",{className:"text-[11px] leading-[1.4] text-muted-foreground",children:"One date range across all date-aware cards."})]})]})}),!o&&/* @__PURE__ */n("div",{className:"flex flex-1 flex-col items-center justify-center px-6 py-8 text-center",children:[/* @__PURE__ */t(Ka,{className:"mb-3 h-10 w-10 text-muted-foreground/50"}),/* @__PURE__ */t("h3",{className:"mb-1 text-[13px] font-medium text-foreground",children:"No fields configured"}),/* @__PURE__ */t("p",{className:"text-[11px] text-muted-foreground",children:"Add a card with data to this sheet to filter it."})]}),o&&/* @__PURE__ */t("div",{className:"flex flex-1 overflow-hidden",children:/* @__PURE__ */t(Fn,{cards:d,context:"filter"})})]});}function us({onAddFilter:e,onAddControl:a,onManageControls:s,onDismiss:r}){const d=C(h=>h.dashboard.filterLayout),{setFilterLayout:o}=Ae(),i=(d==null?void 0:d.toolbarWrap)??!1;return/* @__PURE__ */n("div",{className:"w-[300px]",children:[/* @__PURE__ */n("div",{className:"p-1",children:[/* @__PURE__ */t(ft,{icon:ca,label:"Add filter",onClick:()=>{e(),r();}}),/* @__PURE__ */t(ft,{icon:da,label:"Add control",onClick:()=>{a(),r();}}),/* @__PURE__ */t(ft,{icon:Bt,label:"Manage controls",onClick:()=>{s(),r();}})]}),/* @__PURE__ */t("div",{className:"border-t border-border/60"}),/* @__PURE__ */n("div",{className:"space-y-1 p-2",children:[/* @__PURE__ */t("p",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Display"}),/* @__PURE__ */t(hs,{id:"filter-display-wrap",label:"Wrap to multiple lines",checked:i,onCheckedChange:h=>o({toolbarWrap:h===!0})})]})]});}function ft({icon:e,label:a,onClick:s}){return/* @__PURE__ */n("button",{type:"button",onClick:s,className:"flex w-full items-center gap-2 rounded-control px-2 py-1.5 text-left text-[13px] text-foreground outline-none transition-colors hover:bg-muted/40 focus-visible:bg-muted/40",children:[/* @__PURE__ */t(e,{className:"h-3.5 w-3.5 text-muted-foreground"}),a]});}function hs({id:e,label:a,checked:s,onCheckedChange:r}){return/* @__PURE__ */n("div",{className:"flex items-center gap-2 rounded-control px-1 py-1 transition-colors hover:bg-muted/40 focus-within:bg-muted/40",children:[/* @__PURE__ */t(Nt,{id:e,checked:s,onCheckedChange:r}),/* @__PURE__ */t(Re,{htmlFor:e,className:"cursor-pointer text-[12px] font-normal leading-[1.3]",children:a})]});}function Ri({size:e,className:a,primaryButtonClassName:s,secondaryButtonClassName:r,pickerContentClassName:d,settingsContentClassName:o}){var O;const[i,h]=F(null),u=C(k=>k.dashboard),l=C(k=>k.selectedSheetId),c=C(k=>k.showFilters),p=C(k=>k.actions),{setDocumentPanelTarget:m,setShowFilters:g}=p,f=(O=u.sheets)==null?void 0:O.find(k=>k.id===l),N=_t(f),w=oe(k=>{window.setTimeout(()=>{h(k);},0);},[]),T=oe(k=>{if(N&&l){k&&m(l,{kind:"document",group:"inputs"});return;}g(k);},[N,l,m,g]),L=oe(()=>{T(!0);},[T]),B=oe(()=>{w("create");},[w]),D=oe(()=>{w("manage");},[w]);return/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(ds,{showFilters:N?!1:c,onShowFiltersChange:T,pickerContent:/* @__PURE__ */t(cs,{}),settingsContent:k=>/* @__PURE__ */t(us,{onAddFilter:L,onAddControl:B,onManageControls:D,onDismiss:k}),size:e,className:a,primaryButtonClassName:s,secondaryButtonClassName:r,pickerContentClassName:d,settingsContentClassName:o}),i?N?/* @__PURE__ */t(rs,{open:!0,onOpenChange:k=>{k||h(null);},initialMode:i}):/* @__PURE__ */t(as,{open:!0,onOpenChange:k=>{k||h(null);},showTrigger:!1,initialMode:i}):null]});}function ms(e,a){return(e.variables??[]).map(s=>{const r=wr(e,s.id);return{variable:s,question:Er(s),places:r,usedHere:!!a&&r.some(d=>d.sheetId===a)};});}function ps(e,a){const s=a?e.places.filter(d=>d.sheetId===a).length:0,r=e.places.length-s;return e.places.length?s&&r?`Used here · ${r} elsewhere`:s?"Used here":`Used in ${r} ${r===1?"place":"places"}`:"Not used yet";}function fs({dashboard:e,sheetId:a,sheetTitle:s,onOpen:r,onNew:d}){const[o,i]=F(""),h=K(()=>ms(e,a),[e,a]),u=o.trim().toLowerCase(),l=h.filter(m=>!u||m.variable.name.toLowerCase().includes(u)||(m.variable.label??"").toLowerCase().includes(u)||m.question.toLowerCase().includes(u)),c=l.filter(m=>m.usedHere),p=l.filter(m=>!m.usedHere);return/* @__PURE__ */n("div",{className:"w-[380px] max-w-[calc(100vw-24px)] overflow-hidden","data-testid":"variables-list",children:[/* @__PURE__ */n("div",{className:"flex h-11 items-center justify-between gap-2 border-b border-border/60 px-3",children:[/* @__PURE__ */n("span",{className:"flex items-center gap-2",children:[/* @__PURE__ */t(xt,{className:"h-3.5 w-3.5 text-muted-foreground","aria-hidden":!0}),/* @__PURE__ */t("span",{className:"text-[13px] font-medium",children:"Data variables"}),h.length?/* @__PURE__ */t("span",{className:"rounded-full bg-muted px-2 py-0.5 text-[10px] font-medium tabular-nums text-muted-foreground",children:h.length}):null]}),h.length?/* @__PURE__ */n(I,{size:"xs",className:"gap-1",onClick:d,children:[/* @__PURE__ */t(xe,{className:"h-3.5 w-3.5","aria-hidden":!0})," New variable"]}):null]}),h.length?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t("div",{className:"px-3 py-2",children:/* @__PURE__ */n("div",{className:"flex h-7 items-center gap-1.5 rounded-control border border-border px-2 text-[12px] text-muted-foreground",children:[/* @__PURE__ */t(na,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}),/* @__PURE__ */t("input",{value:o,onChange:m=>i(m.target.value),placeholder:"Search variables","aria-label":"Search variables",className:"w-full bg-transparent text-foreground outline-none placeholder:text-muted-foreground"})]})}),/* @__PURE__ */n("div",{className:"max-h-[360px] overflow-y-auto",children:[c.length?/* @__PURE__ */t(Jt,{children:s?`On ${s}`:"On this tab"}):null,c.map(m=>/* @__PURE__ */t(ea,{row:m,sheetId:a,onOpen:r},m.variable.id)),p.length?/* @__PURE__ */t(Jt,{children:c.length?"Elsewhere on this dashboard":"On this dashboard"}):null,p.map(m=>/* @__PURE__ */t(ea,{row:m,sheetId:a,onOpen:r,muted:!!c.length},m.variable.id)),l.length?null:/* @__PURE__ */t("p",{className:"px-4 py-6 text-center text-[12px] text-muted-foreground",children:"No variable matches."})]})]}):/* @__PURE__ */n("div",{className:"px-6 py-8 text-center",children:[/* @__PURE__ */t("span",{className:"mx-auto flex h-8 w-8 items-center justify-center rounded-full bg-muted",children:/* @__PURE__ */t(xt,{className:"h-4 w-4 text-muted-foreground","aria-hidden":!0})}),/* @__PURE__ */t("p",{className:"mt-3 text-[13px] font-medium",children:"No variables yet"}),/* @__PURE__ */t("p",{className:"mx-auto mt-1 max-w-[280px] text-[12px] leading-[1.5] text-muted-foreground",children:"A variable shows a value from your data in any text: a name or address in a header, the latest date in a footer."}),/* @__PURE__ */n(I,{size:"xs",className:"mt-4 gap-1",onClick:d,children:[/* @__PURE__ */t(xe,{className:"h-3.5 w-3.5","aria-hidden":!0})," New variable"]})]})]});}function Jt({children:e}){return/* @__PURE__ */t("p",{className:"border-y border-border/60 bg-muted/40 px-4 py-1 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground first:border-t-0",children:e});}function ea({row:e,sheetId:a,onOpen:s,muted:r}){return/* @__PURE__ */n("button",{type:"button",onClick:()=>s(e.variable.id),className:"grid w-full grid-cols-[minmax(0,1fr)_132px] items-center gap-3 border-t border-border/60 px-4 py-2 text-left first:border-t-0 hover:bg-muted/50",children:[/* @__PURE__ */n("span",{className:"min-w-0",children:[/* @__PURE__ */t("span",{className:G("block truncate text-[12px] font-medium text-foreground",!e.variable.label&&"font-mono"),children:e.variable.label||e.variable.name}),/* @__PURE__ */t("span",{className:"mt-0.5 block truncate text-[11px] text-muted-foreground",children:e.question})]}),/* @__PURE__ */t("span",{className:G("truncate text-right text-[11px]",r?"text-muted-foreground/70":"text-muted-foreground"),children:ps(e,a)})]});}function Mi(){const e=C(s=>{var r;return((r=s.dashboard.variables)==null?void 0:r.length)??0;}),a=C(s=>s.actions.setVariablesListOpen);return{label:"Data variables",count:e,open:()=>a(!0)};}function Ui(){var u;const e=C(l=>l.variablesListOpen),a=C(l=>l.actions.setVariablesListOpen),s=C(l=>l.dashboard),r=C(l=>l.selectedSheetId),d=C(l=>l.actions.openVariableEditor),o=rt("interactive"),i=(u=s.sheets)==null?void 0:u.find(l=>l.id===r),h=l=>{a(!1),d(l);};return/* @__PURE__ */n(Ee,{open:e,onOpenChange:a,children:[/* @__PURE__ */t(la,{asChild:!0,children:/* @__PURE__ */t("span",{"aria-hidden":!0,className:"pointer-events-none inline-block h-7 w-0 self-center"})}),/* @__PURE__ */t(Ie,{align:"end",sideOffset:6,collisionPadding:12,onFocusOutside:l=>l.preventDefault(),className:"z-50 w-auto rounded-card border border-border/60 p-0 shadow-[0_10px_28px_rgba(0,0,0,0.14)] dark:shadow-[0_10px_28px_rgba(0,0,0,0.5)]",style:o.contentStyle,children:/* @__PURE__ */t(fs,{dashboard:s,sheetId:r??void 0,sheetTitle:i==null?void 0:i.title,onOpen:l=>h({kind:"edit",variableId:l}),onNew:()=>h({kind:"new"})})})]});}function gs(e,a){const s=tr(e);return new Set((e.sheets??[]).map(d=>{const o={sheetId:d.id,cardId:a,sheetKind:_t(d)?"document":"dashboard"};return s.filter(i=>kr(i,o)).map(i=>i.runtimeScope==="shared"?i.id:`${i.id}@${d.id}`).join(`
37
- `);})).size>1;}const bs=[];function gt(e){return Object.fromEntries(Object.entries(e).filter(([,a])=>a!=null));}function xs(e){const a=e==null?void 0:e.type;return a==="dataset"||a==="model"||nr.includes(a);}function vs(e,a){return Fr(e.map((s,r)=>{var d,o;return{target:s,columns:(d=a[r])==null?void 0:d.columns,calculatedFields:(o=a[r])==null?void 0:o.calculatedFields};})).columns;}function ys(e){const{tokenProps:a}=it(),s=C(m=>m.authToken),{connections:r}=ua(),d=e==null?void 0:e.connectionId,o=r.find(m=>m.id===d),i=K(()=>((e==null?void 0:e.selectedEntities)??[]).filter(xs),[e==null?void 0:e.selectedEntities]),h=m=>{var f;if(!(s!=null&&s.accessToken))return!1;if(m.type==="dataset"){const N=m;return!!(N.domainId&&N.name);}if(m.type==="model")return!!(d&&m.id);const g=((f=o==null?void 0:o.capabilities)==null?void 0:f.path)||[];return!(!d||!m.name||g.includes("database")&&!m.database||g.includes("schema")&&!m.schema);},u=oe(m=>{var f,N;const g=vs(i,m.map(w=>w.data));return{fields:g.length?g:bs,isLoading:m.some(w=>w.isLoading),error:(N=(f=m.find(w=>w.error))==null?void 0:f.error)==null?void 0:N.message};},[i]),{fields:l,isLoading:c,error:p}=Qa({queries:i.map(m=>({queryKey:["columns",d,m,(e==null?void 0:e.semanticDomainId)??null],queryFn:()=>ar(`${a.apiServiceUrl}/v1/columns`,(s==null?void 0:s.accessToken)||"",m.type==="model"?gt({connection_id:d,datamodel_id:m.id,database_name:"",schema_name:"",table_name:""}):m.type==="dataset"?gt({connection_id:m.connectionId??d,domain_id:m.domainId,dataset_name:m.name,database_name:m.database,schema_name:m.schema,table_name:m.table}):gt({connection_id:d,datamodel_id:"",database_name:m.database,schema_name:m.schema,table_name:m.name})),enabled:h(m),staleTime:6e4})),combine:u});return{fields:l,isLoading:c,error:p};}function Ns(e){var s;const a=((s=e.comparison)==null?void 0:s.mode)==="explicit"?e.comparison.spec:void 0;return a&&a.kind!=="target"?{mode:"period",spec:a}:{mode:"off"};}function Cs(e){return e.mode==="period"?ir(e.spec):void 0;}const Rt="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",ws={connectionId:"",connectionType:"",mode:"semanticDomain",selectedEntities:[]};function ae({label:e,hint:a,aside:s,children:r,className:d}){return/* @__PURE__ */n("div",{className:d,children:[/* @__PURE__ */n("div",{className:"mb-1 flex min-h-5 items-center justify-between gap-2",children:[/* @__PURE__ */t("p",{className:Rt,children:e}),s]}),r,a?/* @__PURE__ */t("p",{className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:a}):null]});}function bt({muted:e,onClick:a,children:s,ariaLabel:r}){return/* @__PURE__ */t("button",{type:"button",onClick:a,"aria-label":r,className:G("flex h-7 w-full items-center gap-1.5 rounded-control border border-input bg-background px-2 text-left text-[12px] hover:bg-muted/50",e?"text-muted-foreground":"text-foreground"),children:s});}function ks(e){var s;const a=(s=e==null?void 0:e.selectedEntities)==null?void 0:s[0];if(a)return a.label||a.name;}function Ss(e){const a=Pt(e);return a==="date"?"date":a==="string"?"text":a==="number"?"number":a==="boolean"?"yes/no":a;}const ta="__new_calculated_field__";function Ds({draft:e,onChange:a,handle:s,onCalculatedFieldOpenChange:r}){var Y,he,te,me,E,ne,Q,z,J,de,ce,ve;const{tokenProps:d}=it(),o=((Y=d.config)==null?void 0:Y.showAdvancedMode)!==!1,i=((he=d.config)==null?void 0:he.showDirectSource)!==!1,{connections:h}=ua(),[u,l]=F(!1),[c,p]=F(!1),[m,g]=F(!1),f=x=>{p(x),r==null||r(x);},{fields:N,isLoading:w,error:T}=ys(e.mode==="data"?e.dataSource:void 0),L=[...(e.calculatedFields??[]),...N],B=x=>x&&(L.find(P=>P.id===x.id)??L.find(P=>sr(P,x,"entity"))),D=[...L,...[e.field,e.sortField].filter(x=>!!x&&!B(x)&&!L.some(P=>P.id===x.id))],O=((te=B(e.field))==null?void 0:te.id)??((me=e.field)==null?void 0:me.id)??"",k=((E=B(e.sortField??e.field))==null?void 0:E.id)??((ne=e.sortField??e.field)==null?void 0:ne.id)??"",v=x=>a({...e,...x}),b=ks(e.dataSource),_=((Q=e.dataSource)==null?void 0:Q.mode)==="database"?vt:$t,A="mt-1 inline-flex items-center gap-1 text-[11px] font-medium text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",H={connectionId:((z=e.dataSource)==null?void 0:z.connectionId)||e.connectionId,dataSource:e.dataSource,config:e.conditions?{filters:e.conditions}:{},cardType:"text"},V=Wt(e.field),M=(J=V.find(x=>x.value===e.get))==null?void 0:J.hint,X=x=>{if(x===ta){f(!0);return;}const P=D.find(W=>W.id===x);if(!P)return;const $=Wt(P).some(W=>W.value===e.get)&&e.field!==void 0;v({field:P,get:$?e.get:Kt(P)});};return c?/* @__PURE__ */t(En,{inline:!0,open:!0,onOpenChange:f,availableFields:D,cardId:e.id,source:H,onSave:x=>{const P={...x,fieldScope:x.fieldScope??"card"};v({calculatedFields:[...(e.calculatedFields??[]).filter($=>$.id!==P.id),P],field:P,get:Kt(P)}),f(!1);}}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(ae,{label:"Name",aside:/* @__PURE__ */t(Fs,{value:e.name,placeholder:s,editing:m,onEditing:g,onChange:x=>v({name:x})}),hint:m?"The key: what you type after {{, and what links and agents use. Letters, digits and underscores.":void 0,children:/* @__PURE__ */t(be,{size:"xs",value:e.label??"",onChange:x=>v({label:x.target.value}),placeholder:((de=e.field)==null?void 0:de.label)||"Latest order date","aria-label":"Variable name"})}),e.mode==="sql"?/* @__PURE__ */n(R,{children:[/* @__PURE__ */n(ae,{label:"Connection",children:[/* @__PURE__ */n(Ce,{value:e.connectionId??"",onValueChange:x=>v({connectionId:x}),children:[/* @__PURE__ */t(we,{size:"xs","aria-label":"Connection",children:/* @__PURE__ */t(ke,{placeholder:"Choose a connection"})}),/* @__PURE__ */t(Se,{children:h.map(x=>/* @__PURE__ */t(fe,{value:x.id,children:x.name},x.id))})]}),/* @__PURE__ */n("button",{type:"button",onClick:()=>v({mode:"data"}),className:A,children:[/* @__PURE__ */t($t,{className:"h-3 w-3","aria-hidden":!0})," Use a dataset or table instead"]})]}),/* @__PURE__ */t(ae,{label:"SQL",hint:/* @__PURE__ */t(R,{children:"One row. Each column is a part; the first shows by default. Filters reach it where the SQL names them, as a SQL card's do."}),children:/* @__PURE__ */t(ba,{size:"xs",value:e.sql,onChange:x=>v({sql:x.target.value}),placeholder:"select max(order_date) as latest_order_date from orders",className:"min-h-[96px] font-mono","aria-label":"SQL"})}),/* @__PURE__ */t(ae,{label:"Get",children:/* @__PURE__ */n(Ce,{value:e.get==="first"?"first":"only",onValueChange:x=>v({get:x}),children:[/* @__PURE__ */t(we,{size:"xs","aria-label":"Get",children:/* @__PURE__ */t(ke,{})}),/* @__PURE__ */n(Se,{children:[/* @__PURE__ */t(fe,{value:"only",children:"The only row"}),/* @__PURE__ */t(fe,{value:"first",children:"The first row"})]})]})})]}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */n(ae,{label:"Source",children:[/* @__PURE__ */t(bt,{muted:!b,onClick:()=>l(!0),ariaLabel:"Source",children:b?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(_,{className:"h-3.5 w-3.5 text-muted-foreground","aria-hidden":!0})," ",b]}):i?"Choose a dataset or table":"Choose a dataset"}),o?/* @__PURE__ */n("button",{type:"button",onClick:()=>{var x;return v({mode:"sql",connectionId:((x=e.dataSource)==null?void 0:x.connectionId)||e.connectionId});},className:A,children:[/* @__PURE__ */t(Mr,{className:"h-3 w-3","aria-hidden":!0})," Write SQL instead"]}):null]}),/* @__PURE__ */t(In,{open:u,onOpenChange:l,dataSource:e.dataSource??ws,incomingSelectedEntities:((ce=e.dataSource)==null?void 0:ce.selectedEntities)??[],onDataSourceChange:x=>{var $;const P=JSON.stringify(x.selectedEntities)===JSON.stringify(($=e.dataSource)==null?void 0:$.selectedEntities);v(P?{dataSource:x}:{dataSource:x,field:void 0,sortField:void 0,conditions:null,calculatedFields:void 0});}}),/* @__PURE__ */n("div",{className:"grid grid-cols-2 gap-3",children:[/* @__PURE__ */t(ae,{label:"Field",children:b?/* @__PURE__ */n(Ce,{value:O,onValueChange:X,disabled:w&&!D.length,children:[/* @__PURE__ */t(we,{size:"xs","aria-label":"Field",children:/* @__PURE__ */t(ke,{placeholder:w?"Loading fields…":T?"Fields unavailable":"Choose a field"})}),/* @__PURE__ */n(Se,{children:[D.map(x=>/* @__PURE__ */t(fe,{value:x.id,children:/* @__PURE__ */n("span",{className:"flex items-center gap-2",children:[/* @__PURE__ */t("span",{children:x.label||x.name}),/* @__PURE__ */t("span",{className:"text-muted-foreground",children:Ss(x.dataType)})]})},x.id)),/* @__PURE__ */t(Ga,{}),/* @__PURE__ */t(fe,{value:ta,children:/* @__PURE__ */n("span",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */t(xe,{className:"h-3 w-3","aria-hidden":!0})," New calculated field…"]})})]})]}):/* @__PURE__ */t(bt,{muted:!0,children:"Choose a source first"})}),/* @__PURE__ */t(ae,{label:"Get",children:/* @__PURE__ */n(Ce,{value:e.get,onValueChange:x=>v({get:x}),disabled:!e.field,children:[/* @__PURE__ */t(we,{size:"xs","aria-label":"Get",children:/* @__PURE__ */t(ke,{})}),/* @__PURE__ */t(Se,{children:V.map(x=>/* @__PURE__ */t(fe,{value:x.value,children:x.label},x.value))})]})}),e.field&&M?/* @__PURE__ */t("p",{className:"col-span-2 -mt-1.5 text-[11px] leading-4 text-muted-foreground",children:M}):null,T?/* @__PURE__ */t("p",{className:"col-span-2 -mt-1.5 text-[11px] leading-4 text-destructive",children:T}):null,Ir(e)?/* @__PURE__ */t(ae,{label:"Compare with",className:"col-span-2",children:/* @__PURE__ */t(Ha,{controlLabel:"Variable",selection:Ns(e),onChange:x=>v({comparison:Cs(x)})})}):null,e.field&&!Tr(e.get)&&e.get!=="only"?/* @__PURE__ */n("div",{className:G("col-span-2 grid gap-3",e.get==="list"?"grid-cols-3":"grid-cols-2"),children:[/* @__PURE__ */t(ae,{label:"Order by",children:/* @__PURE__ */n(Ce,{value:`${k}|${e.sortDirection}`,onValueChange:x=>{const P=x.lastIndexOf("|"),$=x.slice(0,P),W=x.slice(P+1);v({sortField:D.find(re=>re.id===$),sortDirection:W});},children:[/* @__PURE__ */t(we,{size:"xs","aria-label":"Order by",children:/* @__PURE__ */t(ke,{})}),/* @__PURE__ */t(Se,{children:D.flatMap(x=>["asc","desc"].map(P=>/* @__PURE__ */n(fe,{value:`${x.id}|${P}`,children:[x.label||x.name,", ",As(x,P)]},`${x.id}|${P}`)))})]})}),e.get==="list"?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(ae,{label:"Show up to",children:/* @__PURE__ */t(be,{size:"xs",type:"number",min:1,max:nt,value:e.listLimit??"",placeholder:"10",onChange:x=>{const P=Number.parseInt(x.target.value,10);v({listLimit:Number.isFinite(P)&&P>0?Math.min(P,nt):void 0});},"aria-label":"Show up to"})}),/* @__PURE__ */t(ae,{label:"Separator",children:/* @__PURE__ */t(be,{size:"xs",value:e.listSeparator??", ",maxLength:rr,onChange:x=>v({listSeparator:x.target.value}),className:"font-mono","aria-label":"Separator"})})]}):null]}):null]}),/* @__PURE__ */t(ae,{label:"Filters",children:b?/* @__PURE__ */t(vr,{filters:e.conditions??null,availableFields:D,source:H,onChange:x=>v({conditions:x})},JSON.stringify(((ve=e.dataSource)==null?void 0:ve.selectedEntities)??null)):/* @__PURE__ */t(bt,{muted:!0,children:"Choose a source first"})})]})]});}function As(e,a){const s=Pt(e.dataType);return s==="date"?a==="asc"?"earliest first":"latest first":s==="number"?a==="asc"?"lowest first":"highest first":a==="asc"?"A to Z":"Z to A";}function Fs({value:e,placeholder:a,editing:s,onEditing:r,onChange:d}){return s?/* @__PURE__ */t(be,{size:"xs",autoFocus:!0,value:e,placeholder:a,onChange:o=>d(o.target.value),onBlur:()=>r(!1),onKeyDown:o=>{(o.key==="Enter"||o.key==="Escape")&&(o.preventDefault(),o.stopPropagation(),r(!1));},className:"h-6 w-44 font-mono text-[11px]","aria-label":"Key"}):/* @__PURE__ */n("button",{type:"button",onClick:()=>r(!0),"aria-label":"Edit key",title:"The key: what you type after {{, and what links and agents use",className:"inline-flex h-5 items-center gap-1 rounded-[4px] px-1 font-mono text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:[`{{${e.trim()||a}}}`,/* @__PURE__ */t(Bt,{className:"h-3 w-3","aria-hidden":!0})]});}const Es=[{id:"data",label:"Data"},{id:"filters",label:"Dashboard filters"},{id:"display",label:"Display"}];function Is(e){const{name:a,label:s,presentation:r,emptyText:d,...o}=e;return JSON.stringify(o);}function Ts({variable:e,onClose:a,onHoldEscape:s}){var te,me;const r=C(E=>E.dashboard),d=C(E=>E.selectedSheetId),o=C(E=>E.actions.saveVariableChange),[i,h]=F(()=>e?Lr(e):Vr()),[u,l]=F("data"),[c,p]=F(!1),m=E=>{p(E),s==null||s(E);},[g,f]=F([]),[N,w]=F(null),T=!e,L=Is(i),B=K(()=>Qt({...JSON.parse(L),name:""},r),[L,r]),{name:D,label:O,presentation:k,emptyText:v}=i,b=K(()=>({...B,name:Gt(r,{id:B.id,name:D,field:i.field,mode:i.mode,label:O}),...(O!=null&&O.trim()?{label:O.trim()}:{}),...(k?{presentation:k}:{}),...(v!=null&&v.trim()?{emptyText:v}:{})}),[B,r,D,O,k,v,i.field,i.mode]),_=K(()=>({...r,variables:[...(r.variables??[]).filter(E=>E.id!==b.id),b]}),[r,b]),A=Br(i),H=ot(),V=C(E=>E.actions.mergeSemanticExecutionPayload),[M,X]=F(!1),Y=async()=>{const E=Qt(i,r);X(!0);let ne;try{const z=ur(r,e?{kind:"update",id:e.id,patch:E}:{kind:"add",variable:E});if(!z.ok){X(!1),f(z.issues);return;}const[J]=z.queryFrames;ne=J?await H(J,e?{previousFrame:hr(r,e)}:void 0):{domainsById:{}};}catch(z){X(!1),f([{code:"queryMissing",message:z instanceof Error&&z.message?z.message:"The data source's details could not be loaded.",fix:"Try again, or choose the source again."}]);return;}const Q=o(T?{kind:"add",variable:E}:{kind:"update",id:E.id,patch:Ls(E)});if(X(!1),!Q.ok){f(Q.issues);return;}V(ne),a();},he=E=>{if(!e)return;const ne=o({kind:"remove",id:e.id,confirmed:E});if(!ne.ok){const Q=ne.issues.find(z=>z.code==="inUse");if(Q&&!E){w(Q);return;}f(ne.issues);return;}a();};return/* @__PURE__ */n("div",{className:"flex h-[600px] max-h-[85vh] w-[600px] max-w-[calc(100vw-24px)] flex-col overflow-hidden","data-testid":"variable-editor",children:[/* @__PURE__ */n("div",{className:"flex min-h-12 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3 py-1.5",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-start gap-2",children:[/* @__PURE__ */t(xt,{className:"mt-1 h-3.5 w-3.5 shrink-0 text-muted-foreground","aria-hidden":!0}),/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */n("p",{className:"flex items-center gap-2",children:[/* @__PURE__ */t("span",{className:"truncate text-[13px] font-medium text-foreground",children:T?"New variable":e.label||e.name}),/* @__PURE__ */t("span",{className:Rt,children:"Variable from data"})]}),/* @__PURE__ */t("p",{className:"mt-0.5 truncate text-[10px] leading-3 text-muted-foreground/70",children:"Available on every tab and Document of this dashboard"})]})]}),/* @__PURE__ */t("button",{type:"button",onClick:a,"aria-label":"Close",className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-control text-muted-foreground hover:bg-muted hover:text-foreground",children:/* @__PURE__ */t(Ue,{className:"h-3.5 w-3.5","aria-hidden":!0})})]}),c?null:/* @__PURE__ */t("nav",{role:"tablist","aria-label":"Variable settings sections",className:"flex h-9 shrink-0 items-stretch gap-4 border-b border-border/60 px-4",children:Es.map(E=>/* @__PURE__ */n("button",{role:"tab","aria-selected":u===E.id,onClick:()=>l(E.id),className:G("relative -mb-px inline-flex items-center text-[13px] transition-colors focus-visible:outline-none",u===E.id?"font-medium text-foreground":"text-muted-foreground hover:text-foreground"),children:[E.label,u===E.id?/* @__PURE__ */t("span",{className:"absolute inset-x-0 -bottom-px h-[2px] bg-foreground"}):null]},E.id))}),/* @__PURE__ */n("div",{className:G("min-h-0 flex-1 overflow-y-auto",u==="filters"||c?"":"space-y-4 px-4 py-4"),children:[u==="data"?/* @__PURE__ */t(Ds,{draft:i,onChange:h,handle:Gt(r,i),onCalculatedFieldOpenChange:m}):null,u==="filters"?/* @__PURE__ */t(Vs,{draft:i,draftDashboard:_}):null,u==="display"?/* @__PURE__ */t(Ps,{draft:i,onChange:h}):null]}),c?null:/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(Os,{draft:i,draftVariable:b,draftDashboard:_,blocker:A,selectedSheetId:d??void 0}),g.length?/* @__PURE__ */t("div",{className:"shrink-0 border-t border-border/60 bg-destructive/5 px-4 py-2 text-[11px] leading-4 text-destructive",role:"alert",children:g.map(E=>/* @__PURE__ */n("p",{children:[E.message," ",E.fix]},`${E.code}:${E.path??""}`))}):null,N?/* @__PURE__ */n("div",{className:"shrink-0 border-t border-border/60 bg-amber-500/10 px-4 py-2 text-[11px] leading-4 text-amber-800 dark:text-amber-300",role:"alertdialog",children:[/* @__PURE__ */n("p",{children:[N.message," Used in ",((te=N.places)==null?void 0:te.length)??0," ",((me=N.places)==null?void 0:me.length)===1?"place":"places",". Its chips then read as missing."]}),/* @__PURE__ */n("div",{className:"mt-1.5 flex gap-1.5",children:[/* @__PURE__ */t(I,{variant:"outline",size:"xs",className:"h-6 px-2 text-[11px]",onClick:()=>w(null),children:"Keep it"}),/* @__PURE__ */t(I,{size:"xs",className:"h-6 px-2 text-[11px]",onClick:()=>he(!0),children:"Remove anyway"})]})]}):null,/* @__PURE__ */n("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border/60 px-4 py-2.5",children:[T?/* @__PURE__ */t("span",{}):/* @__PURE__ */t(I,{variant:"outline",size:"xs",className:"text-destructive hover:border-destructive/40 hover:bg-destructive/10 hover:text-destructive",onClick:()=>he(!1),children:"Delete"}),/* @__PURE__ */n("span",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */t(I,{variant:"outline",size:"xs",onClick:a,children:"Cancel"}),/* @__PURE__ */t(I,{size:"xs",disabled:!!A||M,title:A,onClick:()=>void Y(),children:T?"Create":"Done"})]})]})]})]});}function Ls(e){const{id:a,...s}=e;return{...s,label:s.label,presentation:s.presentation,emptyText:s.emptyText};}function Vs({draft:e,draftDashboard:a}){const s=K(()=>or(a),[a]),r=s.inputs.filter(o=>s.reachedVariables({inputId:o.input.id}).some(i=>i.variableId===e.id)),d=e.mode==="sql"&&lr(e.sql);return r.length?/* @__PURE__ */n("div",{className:"divide-y divide-border/60",children:[/* @__PURE__ */t("p",{className:"px-4 py-2 text-[11px] leading-4 text-muted-foreground",children:"How each filter applies here. Change a mapping on the filter's Cards tab, under Variables."}),r.map(o=>{var u;const i=(u=o.input.application)==null?void 0:u.cards.find(l=>l.cardId===e.id),h=d?"Subscribes in SQL":e.mode==="sql"?"Not named in the SQL":(i==null?void 0:i.kind)==="excluded"?"Don't apply":(i==null?void 0:i.kind)==="bound"?`${i.target.kind==="field"?"Field":"Path"} · ${i.target.field.name}`:"Auto";return/* @__PURE__ */n("div",{className:"flex items-center justify-between gap-3 px-4 py-2 text-[12px]",children:[/* @__PURE__ */n("span",{className:"min-w-0",children:[/* @__PURE__ */t("span",{className:"block truncate font-medium text-foreground",children:o.input.label||o.input.filter.title}),/* @__PURE__ */t("span",{className:"block truncate text-[11px] text-muted-foreground",children:Bs(o.input.scope)})]}),/* @__PURE__ */t("span",{className:G("shrink-0 text-[11px]",h==="Don't apply"||h==="Not named in the SQL"?"text-muted-foreground":"text-foreground"),children:h})]},o.input.id);})]}):/* @__PURE__ */t("p",{className:"px-4 py-6 text-center text-[12px] text-muted-foreground",children:"No filter reaches this variable. A filter on the tabs or Documents where it is used reaches it; a variable used nowhere yet follows every tab's filters."});}function Bs(e){switch(e.kind){case"allSheets":return"On every tab";case"sheets":return"On chosen tabs";case"cards":return"On chosen cards and variables";default:return e.kind;}}const _s=[{value:"auto",label:"Automatic"},{value:"short",label:"Short"},{value:"medium",label:"Medium"},{value:"long",label:"Long"},{value:"pattern",label:"Custom pattern…"}];function Ps({draft:e,onChange:a}){var h,u;const s=e.mode==="sql"?"unknown":Pt((h=e.field)==null?void 0:h.dataType),r=(u=e.presentation)==null?void 0:u.temporal,d=r?r.mode==="style"?r.dateStyle:r.mode==="pattern"?"pattern":"auto":"auto",o=(r==null?void 0:r.mode)==="pattern"?Nr(r.pattern):null,i=l=>a({...e,presentation:l&&Object.keys(l).length?l:void 0});return/* @__PURE__ */n(R,{children:[s==="date"||s==="unknown"?/* @__PURE__ */n(ae,{label:"Dates read as",hint:"A chip can change this for itself.",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */n(Ce,{value:d,onValueChange:l=>i({...e.presentation,temporal:l==="auto"?void 0:l==="pattern"?{mode:"pattern",dialect:"semaphor_tokens",pattern:(r==null?void 0:r.mode)==="pattern"?r.pattern:"MMM D, YYYY"}:{mode:"style",dateStyle:l}}),children:[/* @__PURE__ */t(we,{size:"xs",className:"w-44","aria-label":"Date style",children:/* @__PURE__ */t(ke,{})}),/* @__PURE__ */t(Se,{children:_s.map(l=>/* @__PURE__ */t(fe,{value:l.value,children:l.label},l.value))})]}),(r==null?void 0:r.mode)==="pattern"?/* @__PURE__ */t(be,{size:"xs",value:r.pattern,onChange:l=>i({...e.presentation,temporal:{mode:"pattern",dialect:"semaphor_tokens",pattern:l.target.value}}),className:"w-40 font-mono","aria-label":"Date pattern"}):null]}),o?/* @__PURE__ */t("p",{className:"mt-1 text-[11px] text-destructive",children:o}):null]}):null,s==="number"||s==="unknown"?/* @__PURE__ */t(ae,{label:"Numbers read as",hint:"A chip can change any of these for itself.",children:/* @__PURE__ */t(Tn,{value:e.presentation,onChange:i})}):null,/* @__PURE__ */t(ae,{label:"When there’s no value",hint:"Readers see this when nothing matches or more than one does. Leave it empty to show nothing.",children:/* @__PURE__ */t(be,{size:"xs",value:e.emptyText??"",maxLength:dr,onChange:l=>a({...e,emptyText:l.target.value||void 0}),placeholder:"Show nothing",className:"w-72","aria-label":"Empty text"})})]});}function Os({draft:e,draftVariable:a,draftDashboard:s,blocker:r,selectedSheetId:d}){var v;const o=s.sheets??[],i=K(()=>gs(s,a.id),[s,a.id]),[h,u]=F(void 0),l=(i?h:void 0)??d??((v=o[0])==null?void 0:v.id),c=o.find(b=>b.id===l),p=C(b=>l?b.documentSectionRuntimeBySheetId[l]:void 0),m=!!(c&&_t(c)),g=K(()=>l?m?p?{kind:"document",sheetId:l,runtime:p}:void 0:{kind:"sheet",sheetId:l}:void 0,[m,p,l]),f=K(()=>r||!g?[]:[a],[r,a,g]),w=Ln({dashboard:s,place:g??{kind:"sheet",sheetId:l??""},purpose:"preview",variables:f}).byId.get(a.id),T=Ya(),L=Xa(),B=K(()=>cr({preferences:T,calendar:L}),[L,T]);let D,O="",k=null;if(r)D=/* @__PURE__ */t("span",{className:"text-muted-foreground",children:e.mode==="sql"?"Write the SQL to see a value.":"Choose a source and a field to see a value."});else if(!g)D=/* @__PURE__ */t("span",{className:"text-muted-foreground",children:"Open this Document to preview here."});else if(!w||w.status==="loading")D=/* @__PURE__ */t("span",{className:"text-muted-foreground",children:"Loading…"});else{const b=zs(a,w,B);if(D=b.body,O=b.meta,b.unavailable){const _=(c==null?void 0:c.title)||"this tab";k=/* @__PURE__ */n("p",{className:"mt-1.5 flex gap-1.5 text-[11px] leading-4 text-amber-700 dark:text-amber-400",children:[/* @__PURE__ */t(ha,{className:"mt-px h-3 w-3 shrink-0","aria-hidden":!0}),/* @__PURE__ */n("span",{children:["No change on ",_,". ",Za(b.unavailable,"variable")]})]});}}return/* @__PURE__ */n("div",{className:"shrink-0 border-t border-border/60 bg-muted/30 px-4 py-2.5","data-testid":"variable-preview",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-3",children:[/* @__PURE__ */t("span",{className:Rt,children:i?"Preview on":"Preview"}),i?/* @__PURE__ */n(Ce,{value:l??"",onValueChange:u,disabled:!!r,children:[/* @__PURE__ */t(we,{size:"xs",className:"h-6 w-auto gap-1.5 px-2 text-[12px]","aria-label":"Preview place",children:/* @__PURE__ */t(ke,{})}),/* @__PURE__ */t(Se,{children:o.map(b=>/* @__PURE__ */t(fe,{value:b.id,children:b.title||b.id},b.id))})]}):null,/* @__PURE__ */t("div",{className:"min-w-0 flex-1 truncate text-right text-[13px]",children:D})]}),O?/* @__PURE__ */t("p",{className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:O}):null,k]});}function zs(e,a,s){const r=c=>/* @__PURE__ */t("span",{className:"font-medium text-foreground",children:c}),d=c=>/* @__PURE__ */n("span",{className:"inline-flex items-center gap-1.5 text-[12px] text-amber-700 dark:text-amber-400",children:[/* @__PURE__ */t(ha,{className:"h-3.5 w-3.5","aria-hidden":!0})," ",c]}),o=c=>c===void 0?"":c==="beyondCap"?`more than ${nt} match`:`${c} ${c===1?"match":"matches"}`,i="filterReach"in a?a.filterReach:[],h=i.filter(c=>c.status==="applied").length,u=i.length-h,l=i.length?` · ${h} ${h===1?"filter":"filters"} applied${u?`, ${u} skipped`:""}`:"";switch(a.status){case"answered":{const c=Sr(e,Object.keys(a.parts))[0],p=c?a.parts[c]:void 0,m=p&&jt(p,e.presentation,s)||"(empty)",g=`${o(a.matched)}${l}`.replace(/^ · /,""),f=mr(e,a,s);return f&&typeof f=="object"&&"unavailable"in f?{body:r(m),meta:g,unavailable:f.unavailable}:f==="noPrevious"?{body:r(m),meta:`${g} · Nothing in the period before to compare with.`.replace(/^ · /,"")}:f?{body:/* @__PURE__ */n(R,{children:[r(f.value),/* @__PURE__ */n("span",{className:"text-muted-foreground",children:[" · was ",f.previous," · "]}),r(f.change)]}),meta:g}:{body:r(m),meta:g};}case"listed":{const c=a.items.map(m=>jt(m,e.presentation,s)),p=a.more==="beyondCap"?" and more":a.more?` and ${a.more} more`:"";return{body:r(`${c.join(e.get.kind==="list"?e.get.separator??", ":", ")}${p}`),meta:`${o(a.matched)}${l}`};}case"none":return a.why==="moreThanOne"?{body:d(`More than one matches${a.matched!==void 0?` (${a.matched==="beyondCap"?`${nt}+`:a.matched})`:""}. Readers see nothing.`),meta:"Keep a selection on a filter, add a condition, or choose First or List."}:{body:/* @__PURE__ */t("span",{className:"text-muted-foreground",children:"No rows match."}),meta:l.slice(3)};case"held":return{body:/* @__PURE__ */n("span",{className:"text-muted-foreground",children:["Waiting for ",a.missingRequired.join(", "),"."]}),meta:"A required filter has no value here."};case"broken":return{body:d("The query no longer compiles against its mapping."),meta:""};case"failed":return{body:d("The query failed."),meta:a.message};default:return{body:null,meta:""};}}function $i(){const e=C(i=>i.variableEditor),a=C(i=>i.dashboard.variables),s=C(i=>i.actions.closeVariableEditor),r=Ze(!1),d=(e==null?void 0:e.kind)==="edit"?a==null?void 0:a.find(i=>i.id===e.variableId):void 0;return!(e&&(e.kind==="new"||d))?null:/* @__PURE__ */n(Te,{modal:!1,open:!0,onOpenChange:i=>!i&&s(),children:[/* @__PURE__ */t("div",{className:"pointer-events-none fixed inset-0 z-40 bg-zinc-950/40 backdrop-blur-sm"}),/* @__PURE__ */n(Le,{className:"w-auto max-w-none gap-0 overflow-hidden p-0 [&>button:last-child]:hidden",onInteractOutside:i=>i.preventDefault(),onEscapeKeyDown:i=>{r.current?i.preventDefault():s();},children:[/* @__PURE__ */t(Ve,{className:"sr-only",children:"Variable from data"}),/* @__PURE__ */t(st,{className:"sr-only",children:"Define a value from your data to show in text."}),/* @__PURE__ */t(Ts,{variable:d,onClose:s,onHoldEscape:i=>{r.current=i;}},(e==null?void 0:e.kind)==="edit"?e.variableId:"new")]})]});}function Rs({disabled:e,briefingCount:a,className:s,onClick:r}){const d=typeof a=="number"&&a>0;return/* @__PURE__ */n(I,{type:"button",size:"xs",variant:"outline",disabled:e,className:G("gap-1.5",s),onClick:r,"aria-label":"Reports & briefings",children:[/* @__PURE__ */t(Rr,{className:"h-3.5 w-3.5"}),"Reports & briefings",d?/* @__PURE__ */t("span",{className:"ml-0.5 rounded-control bg-muted px-1 text-[10px] tabular-nums text-foreground/70",children:a}):null]});}const Ms="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",Da="inline-flex h-7 items-center gap-1.5 rounded-control px-2 text-[12px] text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-50",Xe="inline-flex h-7 items-center gap-1.5 rounded-control bg-primary px-3 text-[12px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50";function Us(e){return e==="dashboard"?"This dashboard":"Project";}function $s(e){if(!e)return"Never";const a=new Date(e);if(Number.isNaN(a.getTime()))return"Unknown";const s=Date.now()-a.getTime(),r=Math.round(s/6e4);if(r<1)return"now";if(r<60)return`${r}m ago`;const d=Math.round(r/60);if(d<24)return`${d}h ago`;const o=Math.round(d/24);if(o<7)return`${o}d ago`;const i=Math.round(o/7);return i<5?`${i}w ago`:`${Math.round(o/30)}mo ago`;}function js(e){return e.scheduleExpr?_r(e.scheduleExpr,e.timezone||"UTC")??"Invalid schedule":"On demand";}function qs(e){if(e.lastRunStatus){const a=e.lastRunStatus.toString().toUpperCase();return a==="SUCCESS"?"Last run completed.":a==="FAILED"?"Last run failed.":`Last run ${e.lastRunStatus.toString().toLowerCase()}`;}return null;}function Aa(e){return e.hasActiveRun?"Running":e.lastRunStatus?`Last run ${e.lastRunStatus.toString().toLowerCase()}`:"Idle";}function Ws(e){return e.source.type==="dashboard"?"This dashboard":"Project";}function Ks({activeView:e,onChange:a}){return/* @__PURE__ */t("div",{className:"flex shrink-0 items-center gap-1 rounded-control bg-muted p-0.5",role:"tablist","aria-label":"Briefing source view",children:["dashboard","project"].map(s=>{const r=e===s;return/* @__PURE__ */t("button",{type:"button",role:"tab","aria-selected":r,onClick:()=>a(s),className:G("h-6 rounded-[3px] px-2 text-[11px] transition-colors",r?"bg-background font-medium text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:Us(s)},s);})});}function Qs({briefings:e,dashboardLabel:a,sourceView:s,error:r,loading:d,onSourceViewChange:o,onClose:i,onEdit:h,onNew:u,canCreate:l,canCreateScheduledReport:c,analyticalBriefingsEnabled:p,onRunNow:m,onTogglePause:g,onDelete:f,selectingId:N,busyId:w,manageBriefingsHref:T,contentKind:L,hideHeader:B=!1}){const D=e.length,O=e.filter(A=>A.status==="ACTIVE").length,k=L==="reports"?D===1?"report":"reports":L==="briefings"?D===1?"briefing":"briefings":D===1?"item":"items",v=e.find(A=>A.hasActiveRun)??null,b=L??"reports & briefings",_=s==="dashboard"?a:`Project ${b}`;return/* @__PURE__ */n("section",{"aria-label":`Dashboard ${b.replace("&","and")}`,className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:[B?null:/* @__PURE__ */n("header",{className:"flex items-start justify-between gap-3 border-b border-border px-4 py-3",children:[/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */t("div",{className:Ms,children:b}),/* @__PURE__ */t("h2",{className:"mt-0.5 truncate text-[14px] font-semibold leading-5",children:_})]}),/* @__PURE__ */t("button",{type:"button",onClick:i,className:"rounded-control p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":`Close ${b.replace("&","and")} panel`,children:/* @__PURE__ */t(Ue,{className:"h-3.5 w-3.5"})})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between gap-3 border-b border-border px-4 py-2",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-3",children:[/* @__PURE__ */t(Ks,{activeView:s,onChange:o}),/* @__PURE__ */t("div",{className:"flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:d&&D===0?/* @__PURE__ */n("span",{children:["Loading ",b,"…"]}):D===0?/* @__PURE__ */n("span",{children:["No ",b," yet"]}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */n("span",{className:"font-medium text-foreground/80",children:[D," ",k]}),/* @__PURE__ */t("span",{className:"text-border",children:"·"}),/* @__PURE__ */n("span",{children:[O," active"]})]})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-1.5",children:[d?/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}):null,D>0&&l?p&&c?/* @__PURE__ */n($e,{children:[/* @__PURE__ */t(je,{asChild:!0,children:/* @__PURE__ */n("button",{className:Xe,children:[/* @__PURE__ */t(xe,{className:"h-3 w-3"})," New"]})}),/* @__PURE__ */n(qe,{align:"end",children:[/* @__PURE__ */t(ee,{onClick:()=>u("scheduled_report"),children:"Schedule a report"}),/* @__PURE__ */t(ee,{onClick:()=>u("analytical_briefing"),children:"Create analytical briefing"})]})]}):c?/* @__PURE__ */n("button",{onClick:()=>u("scheduled_report"),className:Xe,children:[/* @__PURE__ */t(xe,{className:"h-3 w-3"})," Schedule report"]}):p?/* @__PURE__ */n("button",{onClick:()=>u("analytical_briefing"),className:Xe,children:[/* @__PURE__ */t(xe,{className:"h-3 w-3"})," New briefing"]}):null:null]})]}),v?/* @__PURE__ */n("div",{className:"flex items-center gap-2 border-b border-border bg-muted/60 px-4 py-2 text-[12px]",children:[/* @__PURE__ */t(se,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}),/* @__PURE__ */t("span",{className:"font-medium text-foreground",children:v.name}),/* @__PURE__ */t("span",{className:"text-border",children:"·"}),/* @__PURE__ */t("span",{className:"truncate text-muted-foreground",children:Aa(v)})]}):null,/* @__PURE__ */n("div",{className:"flex-1 overflow-y-auto",children:[r?/* @__PURE__ */t("div",{className:"m-4 rounded-card border border-destructive/30 bg-destructive/10 px-3 py-2 text-[12px] text-destructive",children:r}):null,!d&&e.length===0&&!r?/* @__PURE__ */t(Gs,{onNew:u,canCreate:l,canCreateScheduledReport:c,analyticalBriefingsEnabled:p,contentKind:L}):null,e.map(A=>/* @__PURE__ */t(Ys,{briefing:A,isOpening:N===A.id,isBusy:w===A.id,onOpen:()=>h(A.id),onRunNow:()=>m(A),onTogglePause:()=>g(A),onDelete:()=>f(A)},A.id))]}),T?/* @__PURE__ */t("div",{className:"border-t border-border px-4 py-2.5",children:/* @__PURE__ */n("a",{href:T,className:G(Da,"h-6 px-1 text-[11px]"),children:["Manage all reports & briefings",/* @__PURE__ */t(Or,{className:"h-3 w-3"})]})}):null]});}function Gs({onNew:e,canCreate:a,canCreateScheduledReport:s,analyticalBriefingsEnabled:r,contentKind:d}){const o=d==="reports"?{title:"No reports yet",description:"Schedule an emailed dashboard or visual report to see it here."}:d==="briefings"?{title:"No briefings yet",description:"Create an analytical briefing to monitor this dashboard and brief your team."}:null;return/* @__PURE__ */n("div",{className:"flex h-full flex-col items-center justify-center px-8 py-12 text-center",children:[/* @__PURE__ */t(Hs,{className:"mb-5 h-[88px] w-[112px] text-border"}),/* @__PURE__ */t("div",{className:"text-[13px] font-medium text-foreground",children:(o==null?void 0:o.title)??"Have an analyst brief your team"}),/* @__PURE__ */t("p",{className:"mt-1.5 max-w-[320px] text-[12px] leading-5 text-muted-foreground",children:(o==null?void 0:o.description)??"Describe what to watch. An analyst digs into this dashboard and the data behind it, then briefs your team on the cadence you choose."}),a?/* @__PURE__ */n("div",{className:"mt-4 flex flex-wrap justify-center gap-2",children:[s?/* @__PURE__ */n("button",{onClick:()=>e("scheduled_report"),className:Xe,children:[/* @__PURE__ */t(xe,{className:"h-3 w-3"})," Schedule a report"]}):null,r?/* @__PURE__ */t("button",{onClick:()=>e("analytical_briefing"),className:Da,children:"Create analytical briefing"}):null]}):null]});}function Hs({className:e}){return/* @__PURE__ */n("svg",{viewBox:"0 0 112 88",fill:"none",xmlns:"http://www.w3.org/2000/svg",role:"presentation","aria-hidden":"true",className:e,children:[/* @__PURE__ */t("rect",{x:"22",y:"6",width:"60",height:"72",rx:"3",stroke:"currentColor",strokeWidth:"1.25"}),/* @__PURE__ */t("line",{x1:"30",y1:"16",x2:"64",y2:"16",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),/* @__PURE__ */t("line",{x1:"30",y1:"21",x2:"52",y2:"21",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round",opacity:"0.5"}),/* @__PURE__ */t("circle",{cx:"31",cy:"32",r:"1",fill:"currentColor",opacity:"0.6"}),/* @__PURE__ */t("line",{x1:"35",y1:"32",x2:"72",y2:"32",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),/* @__PURE__ */t("circle",{cx:"31",cy:"38",r:"1",fill:"currentColor",opacity:"0.6"}),/* @__PURE__ */t("line",{x1:"35",y1:"38",x2:"68",y2:"38",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),/* @__PURE__ */t("circle",{cx:"31",cy:"44",r:"1",fill:"currentColor",opacity:"0.6"}),/* @__PURE__ */t("line",{x1:"35",y1:"44",x2:"74",y2:"44",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),/* @__PURE__ */t("rect",{x:"30",y:"64",width:"5",height:"8",rx:"0.5",fill:"currentColor",opacity:"0.55"}),/* @__PURE__ */t("rect",{x:"38",y:"60",width:"5",height:"12",rx:"0.5",fill:"currentColor",opacity:"0.7"}),/* @__PURE__ */t("rect",{x:"46",y:"56",width:"5",height:"16",rx:"0.5",fill:"currentColor",opacity:"0.85"}),/* @__PURE__ */t("rect",{x:"54",y:"62",width:"5",height:"10",rx:"0.5",fill:"currentColor",opacity:"0.6"}),/* @__PURE__ */t("rect",{x:"62",y:"58",width:"5",height:"14",rx:"0.5",fill:"currentColor",opacity:"0.75"}),/* @__PURE__ */t("circle",{cx:"86",cy:"62",r:"10",className:"fill-background",stroke:"currentColor",strokeWidth:"1.25"}),/* @__PURE__ */t("line",{x1:"93.5",y1:"69.5",x2:"100",y2:"76",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]});}function Ys({briefing:e,isOpening:a,isBusy:s,onOpen:r,onRunNow:d,onTogglePause:o,onDelete:i}){const h=e.status==="PAUSED",u=e.hasActiveRun,l=qs(e),c=$s(e.lastRunAt),p=e.lastRunStatus,m=pe(e),g=p==="SUCCESS"?Ge.success.dot:p==="FAILED"?Ge.danger.dot:p?Ge.warning.dot:Ge.neutral.dot;return/* @__PURE__ */n("div",{className:G("group relative border-b border-border/60 px-4 py-3 transition-colors hover:bg-muted/60",h&&"opacity-70"),children:[/* @__PURE__ */n("div",{role:"button",tabIndex:0,onClick:r,onKeyDown:f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),r());},className:"cursor-pointer pr-8",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-2",children:[/* @__PURE__ */t("span",{className:"truncate text-[13px] font-medium text-foreground",children:e.name}),h?/* @__PURE__ */t("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:"· Paused"}):null]}),/* @__PURE__ */n("div",{className:"mt-1 flex flex-wrap items-center gap-x-1.5 text-[11px] text-muted-foreground",children:[/* @__PURE__ */t("span",{children:m.typeLabel}),/* @__PURE__ */t("span",{className:"text-border",children:"·"}),/* @__PURE__ */t("span",{children:Ws(e)}),/* @__PURE__ */t("span",{className:"text-border",children:"·"}),/* @__PURE__ */t(Vn,{className:"h-3 w-3"}),/* @__PURE__ */t("span",{className:"truncate",children:js(e)}),e.lastRunAt?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t("span",{className:"text-border",children:"·"}),/* @__PURE__ */n("span",{children:["Last run ",c]})]}):null]}),l||u?/* @__PURE__ */n("div",{className:"mt-1.5 flex items-center gap-1.5 text-[12px] leading-[1.5] text-foreground/80",children:[u?/* @__PURE__ */t(se,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground/70"}):/* @__PURE__ */t("span",{className:G("inline-block h-1.5 w-1.5 shrink-0 rounded-full",g)}),/* @__PURE__ */t("span",{className:"truncate",children:u?Aa(e):l})]}):null]}),/* @__PURE__ */t("div",{className:"absolute right-3 top-3",children:s?/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground/70"}):a?/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground/70"}):/* @__PURE__ */n($e,{children:[/* @__PURE__ */t(je,{asChild:!0,children:/* @__PURE__ */t("button",{type:"button",onClick:f=>f.stopPropagation(),className:"inline-flex h-6 w-6 items-center justify-center rounded-control text-muted-foreground/70 opacity-60 hover:bg-muted hover:text-foreground/80 focus-visible:opacity-100 group-hover:opacity-100","aria-label":`${m.noun==="report"?"Report":"Briefing"} actions`,children:/* @__PURE__ */t(ra,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(qe,{align:"end",className:"w-44",children:[/* @__PURE__ */n(ee,{onClick:r,children:[/* @__PURE__ */t(Bt,{className:"h-3.5 w-3.5"}),"Edit ",m.noun]}),/* @__PURE__ */n(ee,{onClick:f=>{f.preventDefault(),d();},children:[/* @__PURE__ */t(Bn,{className:"h-3.5 w-3.5"}),"Run now"]}),e.scheduleExpr?/* @__PURE__ */t(ee,{onClick:f=>{f.preventDefault(),o();},children:h?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(_n,{className:"h-3.5 w-3.5"}),"Resume"]}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(Pn,{className:"h-3.5 w-3.5"}),"Pause"]})}):null,/* @__PURE__ */t(et,{}),/* @__PURE__ */n(ee,{onClick:f=>{f.preventDefault(),i();},className:"text-destructive focus:bg-destructive/10 focus:text-destructive",children:[/* @__PURE__ */t(Je,{className:"h-3.5 w-3.5"}),"Delete ",m.noun]})]})]})})]});}function Xs(e){return(e==null?void 0:e.trim())||"This dashboard";}function Zs(e){return e==="This dashboard"?"Watch this dashboard":`Watch ${e}`;}function Js(e,a,s){return a!=="dashboard"?e:e.filter(r=>r.source.type==="dashboard"&&r.source.dashboardId===s);}async function ei(e){const s=[];let r=1,d=0,o=Number.POSITIVE_INFINITY;for(;d<o;){const i=await e.apiClient.listBriefings(e.apiServiceUrl,e.token,{scope:"organization",page:r,pageSize:100});if(s.push(...i.briefings),d+=i.briefings.length,o=i.total,i.briefings.length===0||d>=o)break;r+=1;}return s;}const ti={listBriefings:Wn,getBriefing:qn,pauseBriefing:jn,resumeBriefing:$n,deleteBriefing:Un,runBriefingNow:Mn};function ji(e){return/* @__PURE__ */t(On,{authToken:e.token?{accessToken:e.token}:void 0,children:/* @__PURE__ */t(zn,{children:/* @__PURE__ */t(ai,{...e})})});}function ai({dashboardId:e,dashboardTitle:a,apiServiceUrl:s,token:r,disabled:d,className:o,manageBriefingsHref:i,open:h,onOpenChange:u,hideTrigger:l=!1,workflowIntent:c,openRun:p,client:m}){const{authToken:g,tokenProps:f}=it(),N=Rn(),w=!c||N.canCreate&&(c==="scheduled_report"||N.analyticalBriefingsEnabled),[T,L]=F(!1),B=h??T,D=S=>{h===void 0&&L(S),u==null||u(S);},[O,k]=F(c?"author":"list"),[v,b]=F(c??"analytical_briefing"),[_,A]=F("dashboard"),[H,V]=F([]),[M,X]=F(null),Y=c&&!w&&!M?"list":O,[he,te]=F(!1),[me,E]=F(null),[ne,Q]=F(null),[z,J]=F(null),[de,ce]=F(null),ve=Ze(null),x=Ze(B);Ye(()=>{const S=B&&!x.current;x.current=B,!(!S||!c)&&(X(null),A("dashboard"),b(c),k("author"),ce(null));},[B,c]);const P=St(),$=s??(f==null?void 0:f.apiServiceUrl),W=r??(g==null?void 0:g.accessToken),re=K(()=>({...ti,...m}),[m]),[_e,lt]=F(null);Ye(()=>{if(!p||!$||!W)return;let S=!0;return re.getBriefing($,W,p.briefingId).then(({briefing:q})=>{S&&(X(q),lt(p),k("author"));},q=>{S&&U.error(q instanceof Error?q.message:"Could not open the run.");}),()=>{S=!1;};},[p,$,W,re]);const Fe=Xs(a),We=K(()=>{const S=Js(H,_,e);if(!c)return S;const q=c==="scheduled_report"?"report":"briefing";return S.filter(Ke=>pe(Ke).noun===q);},[e,H,_,c]),dt=K(()=>_==="dashboard"?{source:{type:"dashboard",dashboardId:e},label:Fe,detail:Zs(Fe)}:{source:{type:"project"},label:"This project",detail:"Use any data in this project."},[e,Fe,_]),Pe=!!($&&W),Oe=Pr({canCreate:N.canCreate,analyticalBriefingsEnabled:N.analyticalBriefingsEnabled,scheduledReportAvailable:_==="dashboard"}),ie=oe(async()=>{if(!(!$||!W)){te(!0),ce(null);try{V(await ei({apiClient:re,apiServiceUrl:$,token:W}));}catch(S){ce(S instanceof Error?S.message:"Could not load briefings.");}finally{te(!1);}}},[re,$,W]);Ye(()=>{!B||Y!=="list"||!Pe||ie();},[Pe,Y,ie,B]);const ze=()=>{X(null),A("dashboard"),k("list"),D(!0);},y=S=>{X(null),b(S),k("author");},j=async S=>{if(!(!$||!W)){E(S),ce(null);try{const q=await re.getBriefing($,W,S);X(q.briefing),k("author");}catch(q){ce(q instanceof Error?q.message:"Could not open briefing.");}finally{E(null);}}},Z=async S=>{if(!(!$||!W)){Q(S.id);try{const q=await re.runBriefingNow($,W,S.id,{requestId:ni()});P.track({kind:"briefing",id:q.run.id,title:S.name,briefingId:S.id}),ie();}catch(q){U.error(q instanceof Error?q.message:"Could not start the run.");}finally{Q(null);}}},ue=async S=>{if(!$||!W)return;const{noun:q}=pe(S),Ke=q==="report"?"Report":"Briefing";Q(S.id);try{const Qe=S.status==="PAUSED"?await re.resumeBriefing($,W,S.id):await re.pauseBriefing($,W,S.id);U.success(Qe.briefing.status==="PAUSED"?`${Ke} paused`:`${Ke} resumed`),ie();}catch(Qe){U.error(Qe instanceof Error?Qe.message:`Could not update the ${q} status.`);}finally{Q(null);}},ye=async()=>{if(!z||!$||!W)return;const S=z;Q(S.id);try{await re.deleteBriefing($,W,S.id);const{noun:q}=pe(S);U.success(`${q==="report"?"Report":"Briefing"} deleted`),J(null),ie();}catch(q){U.error(q instanceof Error?q.message:"Could not delete the briefing.");}finally{Q(null);}},Fa=We.length;return N.surfaceVisible?/* @__PURE__ */n(Ja,{open:B,onOpenChange:D,children:[l?null:/* @__PURE__ */t(Rs,{disabled:d||!Pe,briefingCount:Fa,className:o,onClick:ze}),/* @__PURE__ */n(en,{ref:ve,side:"right",hideClose:!0,className:"flex h-full w-full flex-col overflow-hidden p-0 outline-none sm:max-w-[560px]",onOpenAutoFocus:S=>{var q;S.preventDefault(),(q=ve.current)==null||q.focus({preventScroll:!0});},children:[/* @__PURE__ */n(tn,{className:"sr-only",children:[/* @__PURE__ */t(an,{children:"Reports & briefings"}),/* @__PURE__ */t(nn,{children:"Manage reports and briefings for this dashboard."})]}),c?/* @__PURE__ */n("div",{className:"flex shrink-0 items-start justify-between gap-3 border-b border-border pl-4 pr-3 pt-2",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-5",role:"tablist","aria-label":c==="scheduled_report"?"Email report workflow":"Analytical briefing workflow",children:[/* @__PURE__ */t("button",{type:"button",role:"tab","aria-selected":Y==="author",disabled:!w,className:G("-mb-px border-b-2 px-0.5 pb-2 text-[12px] transition-colors",Y==="author"?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground",!w&&"cursor-not-allowed opacity-50"),onClick:()=>{w&&(X(null),b(c),A("dashboard"),k("author"));},children:M?`Edit ${pe(M).noun}`:c==="scheduled_report"?"Schedule report":"Create briefing"}),/* @__PURE__ */t("button",{type:"button",role:"tab","aria-selected":Y==="list",className:G("-mb-px border-b-2 px-0.5 pb-2 text-[12px] transition-colors",Y==="list"?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),onClick:()=>k("list"),children:c==="scheduled_report"?"Manage reports":"Manage briefings"})]}),/* @__PURE__ */t("button",{type:"button",onClick:()=>D(!1),className:"rounded-control p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":c==="scheduled_report"?"Close email report workflow":"Close analytical briefing workflow",children:/* @__PURE__ */t(Ue,{className:"h-3.5 w-3.5"})})]}):null,Y==="list"?/* @__PURE__ */t(Qs,{briefings:We,dashboardLabel:Fe,sourceView:_,error:de,loading:he,onSourceViewChange:A,onClose:()=>D(!1),onEdit:S=>{j(S);},onNew:y,canCreate:!c&&Oe.length>0,canCreateScheduledReport:Oe.includes("scheduled_report"),analyticalBriefingsEnabled:Oe.includes("analytical_briefing"),onRunNow:S=>{Z(S);},onTogglePause:S=>{ue(S);},onDelete:S=>J(S),selectingId:me,busyId:ne,manageBriefingsHref:i,contentKind:c==="scheduled_report"?"reports":c==="analytical_briefing"?"briefings":void 0,hideHeader:!!c}):/* @__PURE__ */t(Kn,{apiServiceUrl:$,token:W,briefing:M,initialRunId:_e&&(M==null?void 0:M.id)===_e.briefingId?_e.runId:void 0,intent:v,sourceContext:M?void 0:dt,title:M?`Edit ${pe(M).noun}`:v==="scheduled_report"?"Schedule report":"Create analytical briefing",hideHeader:!!c,className:"h-full min-h-0 max-w-none border-0 shadow-none",onBack:c?void 0:()=>k("list"),onCancel:()=>D(!1),onDeleted:()=>{const S=M?pe(M).noun:"briefing";U.success(`${S==="report"?"Report":"Briefing"} deleted`),X(null),k("list"),ie();},onRunStarted:()=>{},onSaved:S=>{X(S),ie();},onMinimizeRun:()=>{D(!1);}})]}),/* @__PURE__ */t(Dt,{open:!!z,onOpenChange:S=>{S||J(null);},children:/* @__PURE__ */n(At,{children:[/* @__PURE__ */n(Ft,{children:[/* @__PURE__ */n(Et,{children:["Delete"," ",z?pe(z).noun:"briefing","?"]}),/* @__PURE__ */n(It,{children:["This permanently deletes ",/* @__PURE__ */t("strong",{children:z==null?void 0:z.name}),". Recipients will stop receiving it."]})]}),/* @__PURE__ */n(Tt,{children:[/* @__PURE__ */t(Lt,{children:"Cancel"}),/* @__PURE__ */n(fa,{className:"bg-destructive/90 hover:bg-destructive",onClick:ye,children:["Delete"," ",z?pe(z).noun:"briefing"]})]})]})})]}):null;}function ni(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`briefing-run-now-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;}export{Ti as A,Bi as D,Vi as S,Pi as U,Fi as V,Rs as W,Ii as a,Li as b,_i as c,zi as d,as as e,rs as f,ds as g,Ri as h,Oi as i,Ui as j,Mi as k,$i as l,ji as m,Ca as n,Ei as u};
36
+ */const Ca=Ce("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);/**
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 Mr=Ce("Terminal",[["polyline",{points:"4 17 10 11 4 5",key:"akl6gq"}],["line",{x1:"12",x2:"20",y1:"19",y2:"19",key:"q2wloq"}]]);function Ur(){return/* @__PURE__ */t("div",{className:"space-y-1.5 py-1",children:[...Array(5)].map((e,a)=>/* @__PURE__ */n("div",{className:"flex animate-pulse items-start gap-3 rounded-xl border border-transparent px-2.5 py-2.5",children:[/* @__PURE__ */t("div",{className:"mt-0.5 h-4 w-4 flex-shrink-0 rounded bg-muted/60"}),/* @__PURE__ */n("div",{className:"flex-1 space-y-1.5",children:[/* @__PURE__ */t("div",{className:"h-4 w-3/5 rounded bg-muted/60"}),/* @__PURE__ */t("div",{className:"h-3 w-4/5 rounded bg-muted/40"})]})]},a))});}function $r({open:e,onOpenChange:a,onSubmit:s,isCreating:r}){const d=rt("interactive"),[o,i]=F(""),[h,u]=F("");Ye(()=>{e||(i(""),u(""));},[e]);const l=()=>{o.trim()&&s({title:o,description:h});},c=p=>{a(p);};return/* @__PURE__ */t(Te,{open:e,onOpenChange:c,children:/* @__PURE__ */n(Le,{showCloseButton:!1,className:"flex max-w-lg grid-cols-none flex-col gap-0 overflow-hidden rounded-card border-border/60 p-0 shadow-lg sm:rounded-card",style:d.dialogStyle,children:[/* @__PURE__ */n("div",{className:"flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-2",children:[/* @__PURE__ */t(Me,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */n("div",{className:"flex min-w-0 items-baseline gap-2",children:[/* @__PURE__ */t(Ve,{className:"truncate text-[13px] font-medium leading-none tracking-normal",children:"New library visual"}),/* @__PURE__ */t("span",{className:"shrink-0 text-[10px] font-medium uppercase leading-none tracking-[0.08em] text-muted-foreground",children:"Visual"})]})]}),/* @__PURE__ */t(I,{size:"xs",variant:"ghost",className:"w-7 px-0 text-muted-foreground hover:text-foreground",onClick:()=>c(!1),"aria-label":"Close",disabled:r,children:/* @__PURE__ */t(Ue,{className:"h-3.5 w-3.5"})})]}),/* @__PURE__ */n("div",{className:"space-y-3 px-4 py-3",children:[/* @__PURE__ */t("p",{className:"text-[12px] text-muted-foreground",children:"Create a saved visual that can be reused across dashboards."}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */t(Re,{htmlFor:"visual-title",className:"text-[12px]",children:"Name"}),/* @__PURE__ */t(be,{id:"visual-title",size:"sm",placeholder:"Untitled visual",value:o,onChange:p=>i(p.target.value),disabled:r,onKeyDown:p=>{p.key==="Enter"&&!p.shiftKey&&(p.preventDefault(),l());}})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */t(Re,{htmlFor:"visual-description",className:"text-[12px]",children:"Description"}),/* @__PURE__ */t(be,{id:"visual-description",size:"sm",placeholder:"Optional",value:h,onChange:p=>u(p.target.value),disabled:r})]})]}),/* @__PURE__ */n("div",{className:"flex shrink-0 justify-end gap-2 border-t border-border/60 px-4 py-2.5",children:[/* @__PURE__ */t(I,{size:"xs",variant:"outline",onClick:()=>c(!1),disabled:r,children:"Cancel"}),/* @__PURE__ */t(I,{size:"xs",onClick:l,disabled:!o.trim()||r,children:r?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin"}),"Creating..."]}):"Create library visual"})]})]})});}function wa(e){return e?new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Unknown";}function ka(e,a){var r;const s=(r=e.ownership.createdBy)==null?void 0:r.type;return s==="tenant"||s==="organization"&&a;}function Pt(e,a){var s,r;return ka(e,a)?((s=e.ownership.createdBy)==null?void 0:s.name)||((r=e.createdByTenantUserRel)==null?void 0:r.name)||e.lastModifiedBy||"Unknown":"Organization";}function jr(e,a){return Pt(e,a).split(/\s+/).filter(Boolean).slice(0,2).map(r=>r.charAt(0).toUpperCase()).join("")||"?";}function qr(e){const a=(e||"").toLowerCase();return a.includes("table")?vt:a.includes("pie")||a.includes("donut")?un:a.includes("line")?hn:a.includes("bar")?Ia:Me;}function Wr({visual:e}){const a=e.ownership.status==="public"?"Public":e.ownership.status==="shared"||e.ownership.sharedCount>0?"Shared":"Private";return/* @__PURE__ */t("span",{className:"inline-flex items-center rounded-[4px] border border-border/60 px-1.5 py-px text-[11px] text-muted-foreground",children:a});}function Fi({open:e,onOpenChange:a}){const s=rt("interactive"),[r,d]=F(""),[o,i]=F(/* @__PURE__ */new Set()),[h,u]=F(!1),[l,c]=F(null),[p,m]=F(null),[g,f]=F(!1),[N,w]=F(null),[T,L]=F(null),B=()=>{i(/* @__PURE__ */new Set()),c(null),m(null),f(!1),w(null);},D=()=>{a(!1),B();},{selectVisual:P}=ma(),{handleAddLibraryVisual:k,handleEditLibraryVisual:v}=Be(),{isConsoleMode:b}=rn(),{resources:_,isLoading:A,isError:H,createResource:V,updateResource:M,deleteResourceAsync:X,duplicateResource:Y,isCreating:he,isDeleting:te}=sn(void 0,y=>{u(!1),y&&(P(y),v(y),D());}),{startUpdating:me,stopUpdating:E,isUpdating:ne}=on(),Q=_,z=K(()=>{const y=r.trim().toLowerCase();return y?Q.filter(j=>{var Z,ue,ye;return((Z=j.title)==null?void 0:Z.toLowerCase().includes(y))||((ue=j.description)==null?void 0:ue.toLowerCase().includes(y))||((ye=j.kind)==null?void 0:ye.toLowerCase().includes(y));}):Q;},[r,Q]),J=K(()=>Q.filter(y=>o.has(y.id)),[o,Q]),de=J.filter(y=>y.permissions.canDelete),ce=J.filter(y=>y.permissions.canShare),ve=z.length>0&&z.every(y=>o.has(y.id)),x=z.some(y=>o.has(y.id)),O=y=>{const j=new Set(o);y(j),i(j);},$=y=>{O(j=>{j.has(y)?j.delete(y):j.add(y);});},W=()=>{i(y=>{const j=new Set(y);return ve?z.forEach(Z=>j.delete(Z.id)):z.forEach(Z=>j.add(Z.id)),j;});},re=async y=>{(await k(y)).success&&D();},_e=async()=>{const y=J;if(y.length===0)return;let j=!1;for(const Z of y)if(!(await k(Z)).success){j=!0;break;}j||D();},lt=y=>{v(y),D();},Fe=y=>{L(y),Y(y,{onSettled:()=>L(null)});},We=()=>{if(de.length===0){U.error("Select a visual you can delete");return;}w(null),f(!0);},dt=async()=>{const y=N?[N]:de;try{for(const j of y)await X(j.id);i(j=>{const Z=new Set(j);return y.forEach(ue=>Z.delete(ue.id)),Z;}),f(!1),w(null);}catch{}},Oe=()=>{if(J.length!==1){U.error("Select one visual to share");return;}const[y]=J;if(!y.permissions.canShare){U.error("You do not have permission to share this visual");return;}c(y);},Pe=({title:y,description:j})=>{if(!p)return;const Z={};if(y!==p.title&&(Z.title=y),(p.description||"")!==j&&(Z.description=j),Object.keys(Z).length===0){m(null);return;}const ue=Object.keys(Z),ye=ue.length===1?ue[0]:void 0;me(p.id,ye),M({resourceId:p.id,data:Z},{onSuccess:()=>{E(p.id,ye),m(null);},onError:()=>{E(p.id,ye);}});},ie=y=>{a(y),y||B();},ze=N?1:de.length;return/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(Te,{open:e,onOpenChange:ie,children:/* @__PURE__ */n(Le,{showCloseButton:!1,className:"flex max-h-[80vh] w-[min(72rem,calc(100vw-2rem))] max-w-none grid-cols-none flex-col gap-0 overflow-hidden rounded-card border-border/60 p-0 shadow-lg sm:rounded-card",style:s.dialogStyle,children:[/* @__PURE__ */n("div",{className:"flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-2",children:[/* @__PURE__ */t(vt,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */n("div",{className:"flex min-w-0 items-baseline gap-2",children:[/* @__PURE__ */t(Ve,{className:"truncate text-[13px] font-medium leading-none tracking-normal",children:"Visuals library"}),/* @__PURE__ */t("span",{className:"shrink-0 text-[10px] font-medium uppercase leading-none tracking-[0.08em] text-muted-foreground",children:"Add to dashboard"})]})]}),/* @__PURE__ */t(I,{size:"xs",variant:"ghost",className:"w-7 px-0 text-muted-foreground hover:text-foreground",onClick:()=>ie(!1),"aria-label":"Close visuals library",children:"×"})]}),/* @__PURE__ */n("div",{className:"flex shrink-0 items-center gap-2 border-b border-border/60 px-3 py-2",children:[/* @__PURE__ */n("div",{className:"relative min-w-[12rem] flex-1 md:max-w-md",children:[/* @__PURE__ */t(na,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),/* @__PURE__ */t("input",{autoFocus:!0,value:r,onChange:y=>d(y.target.value),placeholder:"Search visuals...",className:"h-7 w-full rounded-control border border-input bg-background pl-7 pr-2 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-ring focus:outline-none","aria-label":"Search visuals"})]}),/* @__PURE__ */n(I,{size:"xs",variant:"outline",className:"ml-auto",onClick:()=>u(!0),children:[/* @__PURE__ */t(xe,{className:"h-3.5 w-3.5"}),"New library visual"]})]}),/* @__PURE__ */t("div",{className:"min-h-0 flex-1 overflow-auto",children:A?/* @__PURE__ */t("div",{className:"p-3",children:/* @__PURE__ */t(Ur,{})}):H?/* @__PURE__ */t("div",{className:"flex flex-col items-center gap-2 px-4 py-12 text-center",children:/* @__PURE__ */t("p",{className:"text-[13px] text-destructive",children:"Failed to load visuals"})}):z.length===0?/* @__PURE__ */n("div",{className:"flex flex-col items-center gap-2 px-4 py-12 text-center",children:[/* @__PURE__ */t(Me,{className:"h-5 w-5 text-muted-foreground/60"}),/* @__PURE__ */t("p",{className:"text-[13px] font-medium",children:r?"No visuals found":"No visuals yet"}),/* @__PURE__ */t("p",{className:"text-[12px] text-muted-foreground",children:r?"Try a different search.":"Create a saved visual to add it here."})]}):/* @__PURE__ */t(Kr,{visuals:z,selectedIds:o,allFilteredSelected:ve,someFilteredSelected:x,onSelectAll:W,onToggleSelection:$,onAddVisual:re,onOpenVisual:lt,onEditDetails:m,onShareVisual:c,onDeleteVisual:y=>{w(y),f(!0);},onDuplicateVisual:Fe,duplicatingId:T,isDeleting:te,isConsoleMode:b})}),/* @__PURE__ */n("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border/60 px-3 py-2",children:[/* @__PURE__ */t("div",{className:"flex min-w-0 items-center gap-1.5",children:o.size>0&&/* @__PURE__ */n(R,{children:[/* @__PURE__ */n("span",{className:"text-[12px] text-muted-foreground",children:[/* @__PURE__ */t("span",{className:"font-medium tabular-nums text-foreground",children:o.size})," ","selected"]}),/* @__PURE__ */t(I,{size:"xs",variant:"ghost",onClick:()=>i(/* @__PURE__ */new Set()),children:"Clear"}),/* @__PURE__ */n(I,{size:"xs",variant:"outline",onClick:Oe,disabled:J.length!==1||ce.length!==1,children:[/* @__PURE__ */t(pa,{className:"h-3.5 w-3.5"}),"Share"]}),/* @__PURE__ */n(I,{size:"xs",variant:"outline",className:"text-destructive hover:text-destructive",onClick:We,disabled:de.length===0,children:[/* @__PURE__ */t(Je,{className:"h-3.5 w-3.5"}),"Delete ",de.length||o.size]})]})}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */t(I,{size:"xs",variant:"outline",onClick:()=>ie(!1),children:"Close"}),/* @__PURE__ */n(I,{size:"xs",onClick:_e,disabled:o.size===0,children:[/* @__PURE__ */t(yt,{className:"h-3.5 w-3.5"}),o.size===0?"Add to dashboard":`Add ${o.size} visual${o.size===1?"":"s"}`]})]})]})]})}),/* @__PURE__ */t($r,{open:h,onOpenChange:u,onSubmit:V,isCreating:he}),l&&/* @__PURE__ */t(ln,{resource:l,resourceType:dn.VISUAL,onClose:()=>c(null)}),p&&/* @__PURE__ */t(cn,{open:!!p,resourceLabel:"Visual",initialTitle:p.title||"",initialDescription:p.description||"",onClose:()=>m(null),onSave:Pe,isSaving:ne(p.id)}),/* @__PURE__ */t(Dt,{open:g,onOpenChange:y=>{!y&&te||(f(y),y||w(null));},children:/* @__PURE__ */n(At,{children:[/* @__PURE__ */n(Ft,{children:[/* @__PURE__ */n(Et,{children:["Delete ",ze," visual",ze===1?"":"s","?"]}),/* @__PURE__ */t(It,{children:"This cannot be undone. Visuals already added to dashboards may need to be removed from those dashboards separately."})]}),/* @__PURE__ */n(Tt,{children:[/* @__PURE__ */t(Lt,{disabled:te,children:"Cancel"}),/* @__PURE__ */n(fa,{onClick:y=>{y.preventDefault(),dt();},disabled:te||ze===0,children:[te?/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin"}):/* @__PURE__ */t(Je,{className:"h-3.5 w-3.5"}),te?"Deleting...":"Delete"]})]})]})})]});}function Kr({visuals:e,selectedIds:a,allFilteredSelected:s,someFilteredSelected:r,onSelectAll:d,onToggleSelection:o,onAddVisual:i,onOpenVisual:h,onEditDetails:u,onShareVisual:l,onDeleteVisual:c,onDuplicateVisual:p,duplicatingId:m,isDeleting:g,isConsoleMode:f}){return/* @__PURE__ */n("div",{className:"min-w-[48rem]",children:[/* @__PURE__ */n("div",{className:"grid h-9 grid-cols-[2.5rem_minmax(14rem,1.8fr)_minmax(10rem,1fr)_8rem_7rem_5rem_5.5rem] items-center border-b border-border/60 px-3 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:[/* @__PURE__ */t(Nt,{checked:s?!0:r?"indeterminate":!1,onCheckedChange:d,"aria-label":"Select all visuals"}),/* @__PURE__ */t("span",{children:"Name"}),/* @__PURE__ */t("span",{children:"Created by"}),/* @__PURE__ */t("span",{children:"Updated"}),/* @__PURE__ */t("span",{children:"Visibility"}),/* @__PURE__ */t("span",{className:"text-right",children:"Shared"}),/* @__PURE__ */t("span",{className:"text-right",children:"Actions"})]}),e.map(N=>/* @__PURE__ */t(Qr,{visual:N,selected:a.has(N.id),onToggleSelection:o,onAddVisual:i,onOpenVisual:h,onEditDetails:u,onShareVisual:l,onDeleteVisual:c,onDuplicateVisual:p,duplicatingId:m,isDeleting:g,isConsoleMode:f},N.id))]});}function Qr({visual:e,selected:a,onToggleSelection:s,onAddVisual:r,onOpenVisual:d,onEditDetails:o,onShareVisual:i,onDeleteVisual:h,onDuplicateVisual:u,duplicatingId:l,isDeleting:c,isConsoleMode:p}){var f;const m=qr(e.kind),g=()=>{r(e);};return/* @__PURE__ */n("div",{className:G("group grid min-h-12 grid-cols-[2.5rem_minmax(14rem,1.8fr)_minmax(10rem,1fr)_8rem_7rem_5rem_5.5rem] items-center border-b border-border/50 px-3 text-[13px] hover:bg-muted/50",a&&"bg-muted/70"),children:[/* @__PURE__ */t("div",{children:/* @__PURE__ */t(Nt,{checked:a,onCheckedChange:()=>s(e.id),"aria-label":`Select ${e.title||"visual"}`})}),/* @__PURE__ */n("button",{type:"button",className:"flex min-w-0 items-center gap-2 rounded-[4px] text-left outline-none focus-visible:ring-1 focus-visible:ring-ring",onClick:g,"aria-label":`Add ${e.title||"visual"} to dashboard`,children:[/* @__PURE__ */t(m,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */t("div",{className:"truncate font-medium text-foreground",title:e.title||"Untitled Visual",children:e.title||"Untitled Visual"}),((f=e.description)==null?void 0:f.trim())&&/* @__PURE__ */t("div",{className:"truncate text-[11px] text-muted-foreground",title:e.description,children:e.description})]})]}),/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-2",children:[/* @__PURE__ */t("div",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-muted text-[9px] font-medium text-muted-foreground",children:jr(e,p)}),/* @__PURE__ */t("span",{className:"truncate text-muted-foreground",children:Pt(e,p)})]}),/* @__PURE__ */t("span",{className:"text-muted-foreground",children:wa(e.updatedAt)}),/* @__PURE__ */t(Wr,{visual:e}),/* @__PURE__ */t("span",{className:"text-right tabular-nums text-muted-foreground",children:e.ownership.sharedCount>0?e.ownership.sharedCount:"—"}),/* @__PURE__ */t(Gr,{visual:e,onOpenVisual:d,onEditDetails:o,onShareVisual:i,onDeleteVisual:h,onDuplicateVisual:u,duplicatingId:l,isDeleting:c,isConsoleMode:p})]});}function Gr({visual:e,onOpenVisual:a,onEditDetails:s,onShareVisual:r,onDeleteVisual:d,onDuplicateVisual:o,duplicatingId:i,isDeleting:h,isConsoleMode:u}){return/* @__PURE__ */n("div",{className:"flex items-center justify-end gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",onClick:l=>l.stopPropagation(),children:[/* @__PURE__ */t(I,{size:"xs",variant:"ghost",className:"w-7 px-0",onClick:()=>a(e),"aria-label":"Edit visual",children:/* @__PURE__ */t(ut,{className:"h-3.5 w-3.5"})}),/* @__PURE__ */n($e,{modal:!1,children:[/* @__PURE__ */t(je,{asChild:!0,children:/* @__PURE__ */t(I,{size:"xs",variant:"ghost",className:"w-7 px-0","aria-label":"More actions",children:/* @__PURE__ */t(ra,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(qe,{align:"end",className:"z-[60] w-44 rounded-[6px] border-border/60 p-1 shadow-sm",children:[/* @__PURE__ */n(ee,{onClick:()=>a(e),children:[/* @__PURE__ */t(ut,{className:"h-3.5 w-3.5"}),"Edit visual"]}),/* @__PURE__ */n(ee,{onClick:()=>o(e.id),disabled:i===e.id,children:[i===e.id?/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin"}):/* @__PURE__ */t(Ta,{className:"h-3.5 w-3.5"}),i===e.id?"Duplicating...":"Duplicate"]}),e.permissions.canEdit&&/* @__PURE__ */n(ee,{onClick:()=>s(e),children:[/* @__PURE__ */t(ut,{className:"h-3.5 w-3.5"}),"Edit details"]}),e.permissions.canShare&&/* @__PURE__ */n(ee,{onClick:()=>r(e),children:[/* @__PURE__ */t(pa,{className:"h-3.5 w-3.5"}),"Share"]}),e.permissions.canDelete&&/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(et,{}),/* @__PURE__ */n(ee,{className:"text-destructive focus:bg-destructive/10 focus:text-destructive",onClick:()=>d(e),disabled:h,children:[/* @__PURE__ */t(Je,{className:"h-3.5 w-3.5"}),h?"Deleting...":"Delete"]})]}),/* @__PURE__ */t(et,{}),/* @__PURE__ */n("div",{className:"space-y-1 px-2 py-1.5 text-[11px] text-muted-foreground",children:[ka(e,u)&&/* @__PURE__ */n("div",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */t(mn,{className:"h-3 w-3"}),/* @__PURE__ */t("span",{className:"truncate",children:Pt(e,u)})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */t(La,{className:"h-3 w-3"}),/* @__PURE__ */t("span",{children:wa(e.updatedAt)})]})]})]})]})]});}function Ei(e,a,s=!1){const r=C(c=>c.dashboard),d=C(c=>c.isDashboardEditing),o=C(c=>c.isVisualEditing),i=C(c=>c.onDashboardLifecycleEvent),h=oe(()=>{const{dashboard:c,isVisualEditing:p}=C.getState();return a||!e||!c||c.id!==e.id?!1:p?!0:He(c)!==He(e);},[e,a]);Mt(()=>(C.setState({checkUnsavedDashboardChanges:h}),()=>{C.getState().checkUnsavedDashboardChanges===h&&C.setState({checkUnsavedDashboardChanges:null});}),[h]);const u=K(()=>!s||a||!r||d&&(!e||r.id!==e.id)?null:{dashboardId:r.id,dirty:d&&e?o||He(r)!==He(e):!1},[d,o,a,s,e,r]),l=Ze(null);return Mt(()=>{if(!i||!u){l.current=null;return;}const c=l.current;(c==null?void 0:c.callback)===i&&c.dashboardId===u.dashboardId&&c.dirty===u.dirty||(l.current={callback:i,dashboardId:u.dashboardId,dirty:u.dirty},i({type:"dashboard:dirty-state",dashboardId:u.dashboardId,payload:{dirty:u.dirty}}));},[u,i]),h;}function zt(e){var a;for(const s of e.cards)if(s.type==="matrixTable"&&!pr.safeParse((a=s.config)==null?void 0:a.matrix).success)return U.error("Matrix requires at least one row field, one metric, and valid settings."),!1;return!0;}function mt({className:e,variant:a="outline"}){const s=le(o=>o.onSave),{getUpdatedFrame:r}=Be();function d(){const o=r();zt(o)&&(s==null||s(o));}return/* @__PURE__ */n(I,{onClick:d,className:e,size:"xs",variant:a,children:[/* @__PURE__ */t(yt,{className:"h-3.5 w-3.5"}),"Done"]});}function Hr({className:e,variant:a="default"}){const s=Ct(),[r,d]=F(!1),{setIsVisualEditing:o}=Ae(),{getUpdatedFrame:i}=Be(),h=Vt(),u=le(p=>p.frame),l=ga();return/* @__PURE__ */t(I,{onClick:()=>{const p=i();if(!zt(p))return;const m=(u==null?void 0:u.visualId)||(h==null?void 0:h.id);if(!m){U.error("No visual to save");return;}d(!0),l.mutate({visualId:m,data:{frameObject:p}},{onSuccess:()=>{d(!1),U.success("Visual updated successfully"),s.invalidateQueries({queryKey:["resource-by-id","visual",m],exact:!0});},onError:()=>{d(!1),U.error("Failed to update visual");}});},className:e,size:"xs",variant:a,children:r?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin"}),"Saving"]}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(Ca,{className:"h-3.5 w-3.5"}),"Save to Library"]})});}function Yr({className:e}){const a=Ct(),[s,r]=F(!1),d=Vt(),o=le(f=>f.frame),i=C(f=>f.selectedSheetId),h=C(f=>f.dashboard),{updateFrame:u,setIsVisualEditing:l}=Ae(),{getUpdatedFrame:c}=Be(),p=ga(),m=ot();return/* @__PURE__ */t(I,{onClick:async()=>{if(!i){U.error("No sheet selected");return;}const f=(o==null?void 0:o.visualId)||(d==null?void 0:d.id);if(!f){U.error("No visual to update");return;}r(!0);try{const N=c();if(!zt(N)){r(!1);return;}const w={...N,visualId:f},T=at(h,w.id),L=await m(w,{previousFrame:T});await p.mutateAsync({visualId:f,data:{frameObject:N}}),u(i,w,{semanticExecutionPayload:L,origin:"editor"}),a.invalidateQueries({queryKey:["visuals"]}),a.invalidateQueries({queryKey:["visual",f]}),U.success("Saved to library and applied locally"),setTimeout(()=>{l(!1);},300);}catch(N){console.error("Failed to save and apply:",N),U.error(N instanceof Error?N.message:"Failed to save and apply changes");}finally{r(!1);}},className:e,size:"xs",variant:"default",disabled:s,children:s?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin"}),"Saving..."]}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(Ca,{className:"h-3.5 w-3.5"}),"Save & Apply"]})});}function pt({className:e}){const{setTempQueryData:a,setSqlGen:s}=sa(),r=Ct(),d=le(h=>h.tempQueryData),o=le(h=>h.onClose);function i(){if(d){const{queryKey:h,queryData:u}=d;h&&u&&r.setQueryData(h,u);}s({}),o==null||o();}return/* @__PURE__ */n(I,{onClick:i,className:e,size:"xs",variant:"outline",children:[/* @__PURE__ */t(Ue,{className:"h-3.5 w-3.5"}),"Close"]});}function Xr({open:e,onOpenChange:a,isLibraryVisual:s,currentVisualName:r,isSaving:d=!1,destinationMode:o="both",onConfirm:i}){const[h,u]=F(s&&r?`Copy of ${r}`:r||""),[l,c]=F("");aa.useEffect(()=>{e&&(u(s&&r?`Copy of ${r}`:r||""),c(""));},[e,s,r]);const p=!!h.trim(),m=o==="local"?{saveToLibrary:!1,saveToCurrentDashboard:!0,badgeType:"local",description:"Creates a local copy on the current dashboard.",actionLabel:"Add to Dashboard (Local)"}:o==="library"?{saveToLibrary:!0,saveToCurrentDashboard:!1,badgeType:"library",description:"Creates a reusable visual in Visual Library.",actionLabel:"Save as Library Visual"}:{saveToLibrary:!0,saveToCurrentDashboard:!0,badgeType:"linked",description:"Creates a new library visual and adds a linked copy to this dashboard.",actionLabel:"Save Copy as Linked Visual"},g=()=>{!p||d||i({name:h.trim(),description:l.trim()||void 0,saveToLibrary:m.saveToLibrary,saveToCurrentDashboard:m.saveToCurrentDashboard});};return/* @__PURE__ */t(Te,{open:e,onOpenChange:a,children:/* @__PURE__ */n(Le,{className:"sm:max-w-[500px]",children:[/* @__PURE__ */n(wt,{children:[/* @__PURE__ */n(Ve,{className:"flex items-center gap-2",children:[/* @__PURE__ */t("span",{children:"Save Visual As"}),m.badgeType!=="local"&&/* @__PURE__ */t(fr,{type:m.badgeType,showLabel:!0,className:"px-2 py-0.5"})]}),/* @__PURE__ */t(st,{children:m.description})]}),/* @__PURE__ */n("div",{className:"grid gap-4 py-4",children:[/* @__PURE__ */n("div",{className:"grid gap-2",children:[/* @__PURE__ */t(Re,{htmlFor:"name",children:"Name"}),/* @__PURE__ */t(be,{id:"name",value:h,onChange:f=>u(f.target.value),placeholder:"Enter visual name",disabled:d})]}),/* @__PURE__ */n("div",{className:"grid gap-2",children:[/* @__PURE__ */t(Re,{htmlFor:"description",children:"Description (optional)"}),/* @__PURE__ */t(ba,{id:"description",value:l,onChange:f=>c(f.target.value),placeholder:"Enter visual description",rows:3,disabled:d})]})]}),/* @__PURE__ */n(Va,{children:[/* @__PURE__ */t(I,{variant:"outline",onClick:()=>a(!1),disabled:d,children:"Cancel"}),/* @__PURE__ */n(I,{onClick:g,disabled:!p||d,children:[d&&/* @__PURE__ */t(se,{className:"mr-2 h-4 w-4 animate-spin"}),m.actionLabel]})]})]})});}function Zr(){const[e,a]=F(!1),[s,r]=F(!1),[d,o]=F(null),[i,h]=F(null),u=le(v=>v.frame),l=le(v=>v.card),c=Vt(),p=C(v=>v.selectedSheetId),m=C(v=>v.dashboard),{getUpdatedFrame:g}=Be(),{selectVisual:f}=ma(),{addFrame:N,checkAddFrame:w,setIsVisualEditing:T}=Ae(),L=ot(),B=!!(u!=null&&u.visualId),D=(()=>{var v,b;return((v=u==null?void 0:u.cards)==null?void 0:v.length)===1&&(b=u.cards[0])!=null&&b.title?u.cards[0].title:c!=null&&c.title?c.title:(l==null?void 0:l.title)||"Untitled Visual";})(),P=pn(v=>{v!=null&&v.id&&(f(v),s&&d&&i&&p&&(async()=>{try{const b={...d,id:ht(),visualId:v.id};N(p,b,{semanticExecutionPayload:i,withEditorFieldChanges:!0}),r(!1),o(null),h(null),T(!1);}catch(b){console.error("Failed to promote semantic metadata for saved visual:",b),U.error(b instanceof Error?b.message:"Failed to prepare semantic metadata for the saved visual");}})(),a(!1));});return{saveAsDialogOpen:e,setSaveAsDialogOpen:a,handleSaveAs:async v=>{if(!p){U.error("No sheet selected");return;}const b=g(),A=b.cards.length===1?{...b,cards:b.cards.map(H=>({...H,title:v.name}))}:b;if(v.saveToLibrary){let H=null;if(v.saveToCurrentDashboard)try{H=await L(A,{previousFrame:at(m,A.id)});}catch(M){console.error("Failed to prepare semantic metadata before saving visual:",M),U.error(M instanceof Error?M.message:"Failed to prepare semantic metadata for the saved visual");return;}if(v.saveToCurrentDashboard){const M=w(p,{...A,id:ht()},{withEditorFieldChanges:!0});if(!M.ok){U.error(M.reason);return;}}r(v.saveToCurrentDashboard),o(A),h(H);const V={title:v.name,description:v.description,frameObject:A,isPrivate:!1};P.mutate(V);}else if(v.saveToCurrentDashboard){const H={...A,id:ht(),visualId:void 0};try{const V=await L(A,{previousFrame:at(m,A.id)});N(p,H,{semanticExecutionPayload:V,withEditorFieldChanges:!0}),U.success("Visual saved to dashboard"),a(!1),T(!1);}catch(V){console.error("Failed to save visual to dashboard:",V),U.error(V instanceof Error?V.message:"Failed to prepare semantic metadata for the visual");}}},isLibraryVisual:B,currentVisualName:D,isSaving:P.isPending};}function Ii(e={}){const{isInspectionMode:a}=fn(),s=le(V=>V.frame),r=le(V=>V.editorContext),d=gn(V=>V.selectedVisual),o=C(V=>V.selectedFrameId),i=C(V=>V.selectedSheetId),h=C(V=>V.dashboard),{setIsVisualEditing:u,updateFrame:l}=Ae(),[c,p]=F(!1),[m,g]=F("both"),f=ot(),N=(r==null?void 0:r.type)==="documentSection",w=!!(s!=null&&s.visualId||d!=null&&d.id),T=!!(s!=null&&s.visualId&&o),L=w&&!T,{saveAsDialogOpen:B,setSaveAsDialogOpen:D,handleSaveAs:P,isLibraryVisual:k,currentVisualName:v,isSaving:b}=Zr(),{getUpdatedFrame:_}=Be();if(a)return/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(mt,{className:"rounded-control",variant:"default"}),/* @__PURE__ */t(pt,{})]});if(N)return/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(mt,{className:"rounded-control",variant:"default"}),/* @__PURE__ */t(pt,{})]});const A=async()=>{if(!i){U.error("No sheet selected");return;}if(c)return;p(!0);const M={..._(),visualId:void 0},X=at(h,M.id);try{const Y=await f(M,{previousFrame:X});l(i,M,{semanticExecutionPayload:Y,origin:"editor"});}catch(Y){console.error("Failed to apply local semantic metadata:",Y),p(!1),U.error(Y instanceof Error?Y.message:"Failed to prepare semantic metadata for this visual");return;}setTimeout(()=>{p(!1),U.success("Changes applied. Visual is now local to this dashboard"),u(!1);},300);},H=V=>{g(V),D(!0);};return/* @__PURE__ */n(R,{children:[/* @__PURE__ */n("div",{className:"inline-flex items-center overflow-hidden rounded-control",children:[!w&&/* @__PURE__ */t(mt,{className:"!rounded-none",variant:"default"}),w&&L&&/* @__PURE__ */t(Hr,{className:"!rounded-none",variant:"default"}),w&&T&&/* @__PURE__ */t(Yr,{className:"!rounded-none"}),/* @__PURE__ */n($e,{modal:!1,children:[/* @__PURE__ */t(je,{asChild:!0,children:/* @__PURE__ */t(I,{variant:"default",size:"xs",className:"w-7 !rounded-none border-l border-primary-foreground/20 px-0","aria-label":"Open visual save options",disabled:b||c,children:/* @__PURE__ */t(kt,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(qe,{align:"end",className:"min-w-[220px] rounded-control border border-border/60 p-1 shadow-sm",children:[T&&/* @__PURE__ */n(R,{children:[/* @__PURE__ */n(ee,{onClick:A,disabled:c,children:[/* @__PURE__ */t(yt,{className:"h-3.5 w-3.5"}),c?"Applying...":"Apply Locally"]}),/* @__PURE__ */t(et,{})]}),/* @__PURE__ */n(ee,{onClick:()=>H("local"),disabled:b,children:[/* @__PURE__ */t(xe,{className:"h-3.5 w-3.5"}),"Add to Dashboard (Local)"]}),/* @__PURE__ */n(ee,{onClick:()=>H("library"),disabled:b,children:[/* @__PURE__ */t(gr,{className:"h-3.5 w-3.5"}),"Save as Library Visual"]}),/* @__PURE__ */n(ee,{onClick:()=>H("both"),disabled:b,children:[/* @__PURE__ */t(Ba,{className:"h-3.5 w-3.5"}),"Save Copy as Linked Visual"]})]})]})]}),/* @__PURE__ */t(pt,{}),/* @__PURE__ */t(Xr,{open:B,onOpenChange:V=>{b||D(V);},isLibraryVisual:k,currentVisualName:v,isSaving:b,destinationMode:m,onConfirm:P})]});}function Ti({className:e}){const a=le(c=>c.isDevMode),s=le(c=>c.card.type),r=C(c=>c.isVisualEditing),{setIsDevMode:d}=sa(),{config:o}=Ea(_a).tokenProps,i=(o==null?void 0:o.showAdvancedMode)!==!1;if(!r||!i||!Qn(s))return null;const h=a?zr:Pr,u=a?"Visual editor":"SQL editor",l=a?"Switch to visual editor":"Switch to SQL editor";return/* @__PURE__ */n("button",{type:"button","aria-label":l,title:l,onClick:()=>d(!a),className:G("inline-flex h-7 items-center gap-1.5 rounded-control border border-input bg-background px-2 text-[12px] font-medium text-foreground transition-colors hover:bg-muted/40 focus-visible:border-ring focus-visible:outline-none",e),children:[/* @__PURE__ */t(h,{className:"h-3 w-3 text-muted-foreground"}),u]});}function Li(){const e=bn()==="sm",a=C(u=>u.isDashboardEditing),s=C(u=>u.isVisualEditing),r=C(u=>{var c;const l=((c=u.dashboard)==null?void 0:c.sheets)??[];return l.find(p=>p.id===u.selectedSheetId)??l[0];}),d=C(u=>u.actions.arrangeSheet),o=C(u=>u.actions.undoArrange);if(!a||s||!r||!va(r))return null;const i=!(r.frames??[]).length,h=u=>{const l=d(r.id,{keepOrder:u});if(!l.ok){U.error(l.reason==="not_a_grid"?"This sheet has no grid to arrange.":"The dashboard can't be arranged right now.");return;}U("Arranged",{duration:1e4,description:u?"Sizes and gaps fixed on every screen size, in your order.":"KPIs on top, charts in pairs, tables full width, on every screen size.",action:{label:"Undo",onClick:()=>{const c=o();!c.ok&&c.reason==="changed_since"&&U.info("The dashboard changed after Arrange, so it can't be undone from here.");}}});};return/* @__PURE__ */n("div",{className:"inline-flex h-7 items-stretch overflow-hidden rounded-control border border-input bg-background",children:[/* @__PURE__ */n(I,{variant:"ghost",size:"xs",disabled:i,title:i?"This sheet has no cards to arrange":"Lay out the cards by kind on every screen size",onClick:()=>h(!1),"aria-label":e?"Arrange":void 0,className:`h-full rounded-none border-0 shadow-none hover:bg-accent${e?" w-7 px-0":""}`,children:[/* @__PURE__ */t(Me,{className:"h-3.5 w-3.5"}),!e&&"Arrange"]}),/* @__PURE__ */n($e,{modal:!1,children:[/* @__PURE__ */t(je,{asChild:!0,children:/* @__PURE__ */t(I,{variant:"ghost",size:"xs",disabled:i,className:"h-full w-7 rounded-none border-0 border-l border-border/60 px-0 shadow-none hover:bg-accent","aria-label":"Open arrange options",children:/* @__PURE__ */t(kt,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */t(qe,{align:"end",className:"z-[60] w-48 rounded-[6px] border-border/60 p-1 shadow-sm",children:/* @__PURE__ */n(ee,{onClick:()=>h(!0),children:[/* @__PURE__ */t(Me,{className:"h-3.5 w-3.5"}),"Keep my order"]})})]})]});}function Vi(){const e=C(d=>d.screenSizesOpen),a=C(d=>{var h,u;const o=((h=d.dashboard)==null?void 0:h.sheets)??[],i=o.find(l=>l.id===d.selectedSheetId)??o[0];return!!i&&va(i)&&!!((u=i.frames)!=null&&u.length);}),s=C(d=>d.actions.setScreenSizesOpen),r=xa("screen-sizes","lg",a?{label:"Screen sizes",icon:/* @__PURE__ */t(Yt,{className:"h-3.5 w-3.5","aria-hidden":!0}),checked:e,order:40,onSelect:()=>s(!e)}:void 0);return!a||r.collapsed?null:/* @__PURE__ */t(I,{type:"button",size:"xs",variant:e?"secondary":"ghost","aria-pressed":e,"aria-label":"Screen sizes",title:"Screen sizes",onClick:()=>s(!e),className:"w-7 px-0",children:/* @__PURE__ */t(Yt,{className:"h-3.5 w-3.5","aria-hidden":!0})});}function Bi({dashboardId:e}){const{openDashboardId:a,access:s,printMode:r,serverIsFavorite:d,fetchedAt:o}=C(Oa(u=>{var l;return{openDashboardId:(l=u.dashboard)==null?void 0:l.id,access:u.viewer.access,printMode:u.viewer.printMode,serverIsFavorite:u.viewer.isFavorite,fetchedAt:u.viewer.fetchedAt};})),i=xn(),h=i.isFavorite(e,d,o);return a!==e||r||s==="session-only"?null:/* @__PURE__ */t(vn,{variant:"toolbar",isFavorite:h,readOnly:s==="read-only",pending:i.isPending(e),onToggle:()=>void i.setFavorite({dashboardId:e,isFavorite:!h})});}function _i(e){var u;const{authToken:a,tokenProps:s}=it(),{data:r}=yn(),{mutate:d,isPending:o}=Nn(),i=!!e&&((u=r==null?void 0:r.preference)==null?void 0:u.defaultDashboardId)===e,h=!r||o;return{available:!!e&&!!(a!=null&&a.accessToken)&&!!(s!=null&&s.apiServiceUrl),isDefault:i,disabled:h,toggle:()=>{!e||h||d({dashboardId:i?null:e});}};}function Oi({open:e,onOpenChange:a,onSave:s,onDiscard:r,isSaving:d,title:o="Unsaved changes",description:i="You have unsaved changes to this dashboard. What would you like to do?",cancelLabel:h="Cancel",discardLabel:u="Discard changes",saveLabel:l="Save"}){return/* @__PURE__ */t(Dt,{open:e,onOpenChange:p=>{!p&&d||a(p);},children:/* @__PURE__ */n(At,{children:[/* @__PURE__ */n(Ft,{children:[/* @__PURE__ */t(Et,{children:o}),/* @__PURE__ */t(It,{children:i})]}),/* @__PURE__ */n(Tt,{children:[/* @__PURE__ */t(I,{type:"button",size:"xs",onClick:r,disabled:d,variant:"outline",className:"mr-auto text-destructive hover:border-destructive/40 hover:bg-destructive/10 hover:text-destructive focus-visible:bg-destructive/10 focus-visible:text-destructive",children:u}),s?/* @__PURE__ */t(Lt,{disabled:d,children:h}):/* @__PURE__ */t(Cn,{asChild:!0,children:/* @__PURE__ */t(I,{type:"button",size:"xs",children:h})}),s&&/* @__PURE__ */t(I,{type:"button",size:"xs",onClick:s,disabled:d,children:d?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(se,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Saving..."]}):l})]})]})});}async function Pi(e){var o,i;const a=(i=(o=C.getState())==null?void 0:o.authToken)==null?void 0:i.accessToken;if(!a)return;const s=`${e}/v1/invalidate-token`,r=await fetch(s,{method:"POST",headers:{Authorization:`Bearer ${a}`}});if(!r.ok)throw new Error("Failed to invalidate token");const d=await r.json();return console.log("invalidateToken",d),d;}function Jr(e){var s;const a=e.item;return a.kind==="export"?{title:a.title,status:a.status,startedAt:a.startedAt,finishedAt:a.finishedAt,running:ja(a.stage),finishedDetail:[a.totalRows!==null?`${a.totalRows.toLocaleString("en-US")} rows`:null,a.fileSize?$a(a.fileSize):null].filter(r=>!!r),failure:((s=a.failure)==null?void 0:s.kind)==="export"?a.failure.message:a.status==="failed"?Ne.failedFallback:null,note:null}:{title:a.title,status:a.status,startedAt:a.startedAt,finishedAt:a.finishedAt,running:{text:a.stageLabel??Ne.inProgress},finishedDetail:[],failure:null,note:a.omittedAttachmentCount>0?ge.attachmentsLeftOut(a.omittedAttachmentCount):null};}function Xt({row:e,now:a,api:s}){const[r,d]=F("idle"),o=za(e,s),i=async()=>{if(!o)return;d("working");const h=await qa(s,e,o);d(h==="done"?"idle":h);};return/* @__PURE__ */t(Sa,{shown:Jr(e),now:a,longRunningHint:e.item.kind==="export",action:o?{label:ia[o],run:()=>void i()}:null,working:r==="working",problem:r==="denied"||r==="blocked"?r:null});}function es({work:e,now:a}){const s=e.stage==="preparing"?e.cancel:null;return/* @__PURE__ */t(Sa,{shown:{title:e.title,status:"running",startedAt:e.startedAt,finishedAt:null,running:Pa(e),finishedDetail:[],failure:null,note:null},now:a,longRunningHint:!1,action:s?{label:ia.cancel,run:s}:null,working:!1,problem:null});}function Sa({shown:e,now:a,longRunningHint:s,action:r,working:d,problem:o}){const i=e.status==="ready"?"bg-emerald-500":e.status==="failed"?"bg-destructive":e.status==="cancelled"?"bg-muted-foreground/40":"animate-pulse bg-muted-foreground/60",h=e.status==="ready"?Ne.ready:e.status==="failed"?Ne.failed:e.status==="cancelled"?Ne.cancelled:Ne.inProgress,u=Date.parse(e.startedAt),l=qt(Date.parse(e.finishedAt??e.startedAt),a,{addSuffix:!0}),c=e.status==="running"&&s&&a-u>=Ra,p=/* @__PURE__ */t("span",{className:"text-muted-foreground/50",children:"·"});return/* @__PURE__ */n("div",{className:"group flex items-start gap-2.5 px-3 py-2 transition-colors hover:bg-muted/40 focus-within:bg-muted/40",children:[/* @__PURE__ */t("span",{className:"flex h-5 shrink-0 items-center","aria-hidden":"true",children:/* @__PURE__ */t("span",{className:`h-1.5 w-1.5 rounded-full ${i}`})}),/* @__PURE__ */t("span",{className:"sr-only",children:h}),/* @__PURE__ */n("div",{className:"min-w-0 flex-1",children:[/* @__PURE__ */n("div",{className:"flex h-5 items-center gap-2",children:[/* @__PURE__ */t("span",{className:"min-w-0 flex-1 truncate text-[13px] font-medium leading-5",children:e.title}),r&&d&&/* @__PURE__ */t("span",{role:"status",className:"inline-flex shrink-0 items-center gap-1.5 text-[12px] text-muted-foreground",children:/* @__PURE__ */t(oa,{className:"h-3 w-3 animate-spin",strokeWidth:1.75})}),r&&!d&&/* @__PURE__ */t("button",{type:"button",onClick:r.run,className:"shrink-0 text-[12px] font-medium text-foreground/80 underline-offset-2 hover:text-foreground hover:underline focus-visible:underline focus-visible:outline-none",children:r.label})]}),e.status==="running"&&e.running&&/* @__PURE__ */n("div",{className:"text-[12px] leading-4 text-muted-foreground",children:[/* @__PURE__ */t("span",{className:"tabular-nums",children:e.running.text}),e.running.detail&&/* @__PURE__ */n(R,{children:[" ",p," ",/* @__PURE__ */t("span",{className:"tabular-nums",children:e.running.detail})]})," ",p," ",/* @__PURE__ */t("span",{children:Ne.started(qt(u,a))}),e.running.percent!==void 0&&/* @__PURE__ */t(Ma,{value:e.running.percent,className:"mt-1.5 h-1"}),c&&/* @__PURE__ */t("div",{className:"mt-1",children:Ne.longRunning})]}),e.status!=="running"&&/* @__PURE__ */n("div",{className:"flex items-center gap-1.5 text-[12px] leading-4 text-muted-foreground",children:[e.status==="ready"&&e.finishedDetail.length>0?/* @__PURE__ */n("span",{className:"hidden group-hover:contents group-focus-within:contents",children:[e.finishedDetail.map((m,g)=>/* @__PURE__ */n(aa.Fragment,{children:[g>0&&p,/* @__PURE__ */t("span",{children:m})]},g)),p]}):e.status!=="ready"?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t("span",{children:h}),p]}):null,/* @__PURE__ */t("span",{children:l})]}),e.note&&/* @__PURE__ */t("div",{className:"text-[12px] leading-4 text-muted-foreground",children:e.note}),e.status==="failed"&&e.failure&&/* @__PURE__ */t("div",{className:"mt-1 whitespace-pre-wrap break-words text-[12px] leading-4 text-destructive",children:e.failure}),o&&/* @__PURE__ */t(Ua,{problem:o,className:"mt-1"})]})]});}function zi({variant:e}){const{snapshot:a,markSeen:s}=St(),r=a.runningCount>0?a.runningCount>9?"9+":String(a.runningCount):a.hasUnseenFinished?"":null,d=xa("activity","md",{label:ge.title,icon:/* @__PURE__ */t(Ht,{className:"h-3.5 w-3.5"}),hint:r||(r===""?"New":void 0),order:30,onOpen:s});return d.collapsed?/* @__PURE__ */n(Ee,{open:d.popoverOpen,onOpenChange:o=>{d.setPopoverOpen(o),o&&s();},children:[d.anchorSlot&&vr(/* @__PURE__ */t(la,{asChild:!0,children:/* @__PURE__ */t("span",{className:"absolute right-0 top-0 h-7 w-px"})}),d.anchorSlot),/* @__PURE__ */t(Ie,{className:"w-80 p-0",align:"end",sideOffset:8,onFocusOutside:o=>o.preventDefault(),children:/* @__PURE__ */t(Zt,{})})]}):/* @__PURE__ */n(Ee,{onOpenChange:o=>{o&&s();},children:[/* @__PURE__ */t(tt,{asChild:!0,children:/* @__PURE__ */n(I,{variant:e??"ghost",size:"xs",className:"relative w-7 px-0","aria-label":ge.title,title:ge.title,children:[/* @__PURE__ */t(Ht,{className:"h-3.5 w-3.5"}),r!==null&&/* @__PURE__ */t("span",{className:`absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${r?"-right-0.5 -top-0.5 h-3.5 min-w-3.5 px-0.5 text-[9px] font-semibold":"right-1 top-1 h-1.5 w-1.5"}`,children:r})]})}),/* @__PURE__ */t(Ie,{className:"w-80 p-0",align:"end",sideOffset:8,children:/* @__PURE__ */t(Zt,{})})]});}function Zt(){const e=St(),a=Wa(),{rows:s,browserRows:r,activeTruncated:d}=e.snapshot,o=s.some(l=>ct(l.item.status)),i=[...s.filter(l=>!ct(l.item.status)).map(l=>({startedAt:l.item.startedAt,row:l})),...r.map(l=>({startedAt:l.startedAt,work:l}))].sort((l,c)=>c.startedAt.localeCompare(l.startedAt)),h=s.filter(l=>ct(l.item.status)),u=s.length+r.length;return u===0?/* @__PURE__ */n("div",{className:"flex flex-col items-center gap-1.5 px-6 py-8 text-center",children:[/* @__PURE__ */t("span",{className:"flex h-8 w-8 items-center justify-center rounded-[6px] border border-border text-muted-foreground",children:/* @__PURE__ */t(wn,{className:"h-3.5 w-3.5",strokeWidth:1.75})}),/* @__PURE__ */t("p",{className:"text-[13px] font-medium",children:ge.title}),/* @__PURE__ */t("p",{className:"text-[12px] text-muted-foreground",children:ge.empty})]}):/* @__PURE__ */n("div",{className:"flex flex-col",children:[/* @__PURE__ */n("div",{className:"flex h-8 items-center gap-2 border-b border-border px-3",children:[/* @__PURE__ */t("span",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:ge.title}),/* @__PURE__ */t("span",{className:"text-[10px] tabular-nums text-muted-foreground/70",children:u}),/* @__PURE__ */n("div",{className:"ml-auto flex items-center gap-0.5",children:[o&&/* @__PURE__ */t(I,{variant:"ghost",size:"xs",className:"h-6 px-1.5 text-[12px] text-muted-foreground hover:text-foreground",onClick:e.clearFinished,children:ge.clear}),/* @__PURE__ */t(I,{variant:"ghost",size:"xs",className:"h-6 w-6 px-0 text-muted-foreground hover:text-foreground",onClick:e.refresh,title:"Refresh status","aria-label":"Refresh status",children:/* @__PURE__ */t(oa,{strokeWidth:1.75,className:"h-3.5 w-3.5"})})]})]}),d&&/* @__PURE__ */t("p",{className:"border-b border-border px-3 py-2 text-[12px] leading-4 text-muted-foreground",children:ge.truncated}),/* @__PURE__ */t("div",{className:"max-h-[320px] overflow-y-auto",children:/* @__PURE__ */n("div",{className:"divide-y divide-border/70",children:[i.map(l=>"work"in l?/* @__PURE__ */t(es,{work:l.work,now:a},l.work.id):/* @__PURE__ */t(Xt,{row:l.row,now:a,api:e},Ut(l.row))),h.map(l=>/* @__PURE__ */t(Xt,{row:l,now:a,api:e},Ut(l)))]})})]});}function ts(e){if(e)return{renamed:e.type==="rename"?{oldId:e.oldId,newId:e.newId}:void 0,removedControlId:e.type==="remove"?e.controlId:void 0,cardBindingsById:e.type==="add"||e.type==="update"?e.cardBindingsById:void 0,affectedBindingControlIds:e.type==="add"||e.type==="update"?e.affectedBindingControlIds:void 0};}function as({open:e,onOpenChange:a,trigger:s,showTrigger:r=!0,initialMode:d="manage"}){const o=d==="create",{forceClose:i,handleOpenChange:h,isCreateFlowActive:u,preventPassiveDismissDuringCreate:l,resolvedOpen:c,setIsCreateFlowActive:p}=ya({open:e,onOpenChange:a,initialCreateFlowActive:d==="create",dismissMode:r?"passive":"explicit-only"}),m=C(b=>b.dashboard),{setDashboardControlsModel:g}=Ae(),{participants:f}=kn(Nr(m)),N=Array.from(new Map(f.flatMap(b=>b.fieldChoices.map(_=>{var A;return[_.value,{option:_,target:(A=b.fieldTargetMap)==null?void 0:A[_.value]}];}))).values()),w=Array.from(new Map(f.flatMap(b=>b.metricChoices.map(_=>{var A;return[_.value,{option:_,target:(A=b.metricTargetMap)==null?void 0:A[_.value]}];}))).values()),T=Gn({...(m||{}),controls:[]}),L=Sn(m),B=(b,_,A)=>{g(b,_,ts(A));},D=oe(()=>{if(o){i();return;}p(!1);},[o,i,p]),P=/* @__PURE__ */t(Na,{scope:"dashboard",controls:m.controls||[],reservedControlIds:T,defaultValues:m.defaultControlValues||{},usageByControlId:Dn(m),availableFieldChoices:N,availableMetricChoices:w,structuralParticipants:f,structuralParticipantIdsByControlId:L,initialCreateFlow:d==="create",onCreateFlowActiveChange:p,onCreateFlowComplete:D,onChange:B,emptyMessage:"No dashboard controls yet."}),k=u?"Add dashboard control":"Dashboard Controls",v=/* @__PURE__ */n(R,{children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */t("h4",{className:"text-sm font-medium",children:"Dashboard Controls"}),/* @__PURE__ */t("p",{className:"text-xs text-muted-foreground",children:"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),P]});return r?/* @__PURE__ */n(Ee,{open:c,onOpenChange:h,children:[/* @__PURE__ */t(tt,{asChild:!0,children:s||/* @__PURE__ */n(I,{variant:"outline",className:"h-7 px-2",size:"sm",children:[/* @__PURE__ */t(da,{className:"mr-2 h-4 w-4"}),"Controls"]})}),/* @__PURE__ */t(Ie,{className:"w-[620px] max-w-[95vw] space-y-4",align:"end",onEscapeKeyDown:l,onPointerDownOutside:l,children:v})]}):/* @__PURE__ */t(Te,{open:c,onOpenChange:h,children:/* @__PURE__ */n(Le,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:l,onPointerDownOutside:l,children:[/* @__PURE__ */n(wt,{className:u?"space-y-0":void 0,children:[/* @__PURE__ */t(Ve,{className:"text-[15px]",children:k}),/* @__PURE__ */t(st,{className:u?"sr-only":"text-[13px]",children:u?"Configure and add a shared dashboard control.":"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),/* @__PURE__ */t("div",{className:"min-h-0 overflow-y-auto pr-1",children:P})]})});}const ns=["enum","multi_enum","text","number","boolean","date"];function rs({open:e,onOpenChange:a,initialMode:s="manage"}){var v;const r=s==="create",{forceClose:d,handleOpenChange:o,isCreateFlowActive:i,preventPassiveDismissDuringCreate:h,resolvedOpen:u,setIsCreateFlowActive:l}=ya({open:e,onOpenChange:a,initialCreateFlowActive:s==="create",dismissMode:"explicit-only"}),c=C(b=>b.dashboard),p=C(b=>b.selectedSheetId),{setDashboardInputs:m}=Ae(),g=(v=c.sheets)==null?void 0:v.find(b=>b.id===p),f=(g==null?void 0:g.kind)==="document"&&!!g.document,N=K(()=>f&&g!=null&&g.document?Hn(c,g.id):[],[c,f,g==null?void 0:g.document,g==null?void 0:g.id]),w=K(()=>N.filter(b=>b.kind==="control"),[N]),T=K(()=>w.map(b=>b.control),[w]),L=K(()=>is(T),[T]),B=K(()=>[...ss(c),...(c.variables??[]).map(b=>b.name)],[c]),D=oe(()=>{if(r){d();return;}l(!1);},[r,d,l]),P=oe((b,_,A)=>{!f||!(g!=null&&g.document)||m(ls({dashboard:c,documentSheetId:g.id,currentDocumentInputs:N,nextControls:b,nextDefaultValues:_,change:A}));},[c,N,f,g,m]);return!f||!(g!=null&&g.document)?null:/* @__PURE__ */t(Te,{open:u,onOpenChange:o,children:/* @__PURE__ */n(Le,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:h,onPointerDownOutside:h,children:[/* @__PURE__ */n(wt,{className:i?"space-y-0":void 0,children:[/* @__PURE__ */t(Ve,{className:"text-[15px]",children:i?"Add document control":"Document Controls"}),/* @__PURE__ */t(st,{className:i?"sr-only":"text-[13px]",children:i?"Configure and add a document-local control input.":"Add document-local control inputs. They are stored on this document sheet and are not dashboard controls."})]}),/* @__PURE__ */t("div",{className:"min-h-0 overflow-y-auto pr-1",children:/* @__PURE__ */t(Na,{scope:"dashboard",controls:T,reservedControlIds:B,defaultValues:L,usageByControlId:{},availableFieldChoices:[],availableMetricChoices:[],structuralParticipants:[],structuralParticipantIdsByControlId:{},allowedControlTypes:ns,initialCreateFlow:s==="create",onCreateFlowActiveChange:l,onCreateFlowComplete:D,onChange:P,emptyMessage:"No document controls yet."})})]})});}function ss(e){return(e.controls||[]).map(a=>a.id);}function is(e){const a={};for(const s of e)s.defaultValue!==void 0&&(a[s.id]=s.defaultValue);return a;}function os(e,a){return a?Object.prototype.hasOwnProperty.call(a,e.id)?{...e,defaultValue:a[e.id]}:e.defaultValue===void 0?e:{...e,defaultValue:void 0}:e.defaultValue===void 0?e:{...e,defaultValue:void 0};}function ls({dashboard:e,documentSheetId:a,currentDocumentInputs:s,nextControls:r,nextDefaultValues:d,change:o}){const i=new Map(r.map(g=>[g.id,os(g,d)])),h=(o==null?void 0:o.type)==="rename"?{oldId:o.oldId,newId:o.newId}:null,u=/* @__PURE__ */new Set(),l=[];for(const g of s){if(g.kind!=="control"){l.push(g);continue;}const f=i.get(g.control.id)||((h==null?void 0:h.oldId)===g.control.id?i.get(h.newId):void 0);if(!f)continue;u.add(f.id);const N=Yn(e,{name:f.id},{exclude:{source:"input",inputId:g.id},alsoTaken:l}),w=f.id===N?f:{...f,id:N};l.push({...g,label:w.label,variableName:N,requiredAtExecution:w.requiredAtExecution,control:w});}for(const g of i.values())u.has(g.id)||l.push(Xn({control:g,dashboard:e,alsoTaken:l,sheetId:a}));const c=new Set(s.map(g=>g.id));return[...(Array.isArray(e.inputs)?e.inputs:[]).filter(g=>!c.has(g.id)),...l];}function ds({showFilters:e,onShowFiltersChange:a,pickerContent:s,settingsContent:r,size:d="default",className:o,primaryButtonClassName:i,secondaryButtonClassName:h,pickerContentClassName:u,settingsContentClassName:l}){const c=d==="toolbar",[p,m]=F(!1),g=rt("interactive");return/* @__PURE__ */n("div",{className:G("relative inline-flex items-stretch overflow-hidden rounded-control border border-input bg-background",c?"h-8":"h-7",o),children:[/* @__PURE__ */n(Ee,{open:e,onOpenChange:a,children:[/* @__PURE__ */t(tt,{asChild:!0,children:/* @__PURE__ */n(I,{variant:"ghost",size:"xs",className:G("h-full rounded-none border-0 bg-transparent pl-2.5 pr-2 shadow-none hover:bg-accent/50 data-[state=open]:bg-accent/60",i),children:[e?/* @__PURE__ */t(br,{className:"h-3.5 w-3.5"}):/* @__PURE__ */t(ca,{className:"h-3.5 w-3.5"}),"Filter"]})}),/* @__PURE__ */t(Ie,{align:"end",sideOffset:6,className:G("w-auto rounded-card border border-border/60 p-0 shadow-[0_10px_28px_rgba(0,0,0,0.14)] dark:shadow-[0_10px_28px_rgba(0,0,0,0.5)]",u),style:g.contentStyle,children:s})]}),/* @__PURE__ */n(Ee,{open:p,onOpenChange:m,children:[/* @__PURE__ */t(tt,{asChild:!0,children:/* @__PURE__ */t(I,{variant:"ghost",size:"xs",className:G("h-full w-7 rounded-none border-0 border-l border-border/60 bg-transparent px-0 shadow-none hover:bg-accent/50 data-[state=open]:bg-accent/60",h),"aria-label":"Filter and control actions",children:/* @__PURE__ */t(kt,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */t(Ie,{align:"end",sideOffset:6,className:G("w-auto rounded-card border border-border/60 p-0 shadow-[0_10px_28px_rgba(0,0,0,0.14)] dark:shadow-[0_10px_28px_rgba(0,0,0,0.5)]",l),style:g.contentStyle,children:r(()=>m(!1))})]})]});}function cs(){const e=C(l=>l.dashboard),a=C(l=>l.semanticExecutionPayload),s=C(l=>l.actions.addFilterInput),r=C(l=>l.selectedSheetId),d=K(()=>{var c,p;const l=((c=e==null?void 0:e.sheets)==null?void 0:c.find(m=>m.id===r))??((p=e==null?void 0:e.sheets)==null?void 0:p[0]);return((l==null?void 0:l.frames)??[]).map(m=>Sr(m)).filter(m=>!!m);},[e,r]),o=Dr(d).length>0,i=K(()=>Zn(e,a),[e,a]),u=!Jn(e)&&i.hasEligibleCards;return/* @__PURE__ */n("div",{className:"flex h-[520px] w-[400px] flex-col",children:[u&&/* @__PURE__ */t("div",{className:"border-b border-border/60 p-2",children:/* @__PURE__ */n("button",{type:"button",onClick:()=>s(er(),{kind:"allSheets",sheetKinds:["dashboard"]}),title:`Applies to ${i.eligibleCardCount} of ${i.totalCardCount} date-aware cards`,className:"flex w-full items-start gap-2 rounded-control px-2 py-1.5 text-left outline-none transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-border",children:[/* @__PURE__ */t(An,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */n("span",{className:"flex min-w-0 flex-col",children:[/* @__PURE__ */t("span",{className:"text-[12px] font-medium text-foreground",children:"Add global date filter"}),/* @__PURE__ */t("span",{className:"text-[11px] leading-[1.4] text-muted-foreground",children:"One date range across all date-aware cards."})]})]})}),!o&&/* @__PURE__ */n("div",{className:"flex flex-1 flex-col items-center justify-center px-6 py-8 text-center",children:[/* @__PURE__ */t(Ka,{className:"mb-3 h-10 w-10 text-muted-foreground/50"}),/* @__PURE__ */t("h3",{className:"mb-1 text-[13px] font-medium text-foreground",children:"No fields configured"}),/* @__PURE__ */t("p",{className:"text-[11px] text-muted-foreground",children:"Add a card with data to this sheet to filter it."})]}),o&&/* @__PURE__ */t("div",{className:"flex flex-1 overflow-hidden",children:/* @__PURE__ */t(Fn,{cards:d,context:"filter"})})]});}function us({onAddFilter:e,onAddControl:a,onManageControls:s,onDismiss:r}){const d=C(h=>h.dashboard.filterLayout),{setFilterLayout:o}=Ae(),i=(d==null?void 0:d.toolbarWrap)??!1;return/* @__PURE__ */n("div",{className:"w-[300px]",children:[/* @__PURE__ */n("div",{className:"p-1",children:[/* @__PURE__ */t(ft,{icon:ca,label:"Add filter",onClick:()=>{e(),r();}}),/* @__PURE__ */t(ft,{icon:da,label:"Add control",onClick:()=>{a(),r();}}),/* @__PURE__ */t(ft,{icon:Bt,label:"Manage controls",onClick:()=>{s(),r();}})]}),/* @__PURE__ */t("div",{className:"border-t border-border/60"}),/* @__PURE__ */n("div",{className:"space-y-1 p-2",children:[/* @__PURE__ */t("p",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Display"}),/* @__PURE__ */t(hs,{id:"filter-display-wrap",label:"Wrap to multiple lines",checked:i,onCheckedChange:h=>o({toolbarWrap:h===!0})})]})]});}function ft({icon:e,label:a,onClick:s}){return/* @__PURE__ */n("button",{type:"button",onClick:s,className:"flex w-full items-center gap-2 rounded-control px-2 py-1.5 text-left text-[13px] text-foreground outline-none transition-colors hover:bg-muted/40 focus-visible:bg-muted/40",children:[/* @__PURE__ */t(e,{className:"h-3.5 w-3.5 text-muted-foreground"}),a]});}function hs({id:e,label:a,checked:s,onCheckedChange:r}){return/* @__PURE__ */n("div",{className:"flex items-center gap-2 rounded-control px-1 py-1 transition-colors hover:bg-muted/40 focus-within:bg-muted/40",children:[/* @__PURE__ */t(Nt,{id:e,checked:s,onCheckedChange:r}),/* @__PURE__ */t(Re,{htmlFor:e,className:"cursor-pointer text-[12px] font-normal leading-[1.3]",children:a})]});}function Ri({size:e,className:a,primaryButtonClassName:s,secondaryButtonClassName:r,pickerContentClassName:d,settingsContentClassName:o}){var P;const[i,h]=F(null),u=C(k=>k.dashboard),l=C(k=>k.selectedSheetId),c=C(k=>k.showFilters),p=C(k=>k.actions),{setDocumentPanelTarget:m,setShowFilters:g}=p,f=(P=u.sheets)==null?void 0:P.find(k=>k.id===l),N=_t(f),w=oe(k=>{window.setTimeout(()=>{h(k);},0);},[]),T=oe(k=>{if(N&&l){k&&m(l,{kind:"document",group:"inputs"});return;}g(k);},[N,l,m,g]),L=oe(()=>{T(!0);},[T]),B=oe(()=>{w("create");},[w]),D=oe(()=>{w("manage");},[w]);return/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(ds,{showFilters:N?!1:c,onShowFiltersChange:T,pickerContent:/* @__PURE__ */t(cs,{}),settingsContent:k=>/* @__PURE__ */t(us,{onAddFilter:L,onAddControl:B,onManageControls:D,onDismiss:k}),size:e,className:a,primaryButtonClassName:s,secondaryButtonClassName:r,pickerContentClassName:d,settingsContentClassName:o}),i?N?/* @__PURE__ */t(rs,{open:!0,onOpenChange:k=>{k||h(null);},initialMode:i}):/* @__PURE__ */t(as,{open:!0,onOpenChange:k=>{k||h(null);},showTrigger:!1,initialMode:i}):null]});}function ms(e,a){return(e.variables??[]).map(s=>{const r=Cr(e,s.id);return{variable:s,question:Fr(s),places:r,usedHere:!!a&&r.some(d=>d.sheetId===a)};});}function ps(e,a){const s=a?e.places.filter(d=>d.sheetId===a).length:0,r=e.places.length-s;return e.places.length?s&&r?`Used here · ${r} elsewhere`:s?"Used here":`Used in ${r} ${r===1?"place":"places"}`:"Not used yet";}function fs({dashboard:e,sheetId:a,sheetTitle:s,onOpen:r,onNew:d}){const[o,i]=F(""),h=K(()=>ms(e,a),[e,a]),u=o.trim().toLowerCase(),l=h.filter(m=>!u||m.variable.name.toLowerCase().includes(u)||(m.variable.label??"").toLowerCase().includes(u)||m.question.toLowerCase().includes(u)),c=l.filter(m=>m.usedHere),p=l.filter(m=>!m.usedHere);return/* @__PURE__ */n("div",{className:"w-[380px] max-w-[calc(100vw-24px)] overflow-hidden","data-testid":"variables-list",children:[/* @__PURE__ */n("div",{className:"flex h-11 items-center justify-between gap-2 border-b border-border/60 px-3",children:[/* @__PURE__ */n("span",{className:"flex items-center gap-2",children:[/* @__PURE__ */t(xt,{className:"h-3.5 w-3.5 text-muted-foreground","aria-hidden":!0}),/* @__PURE__ */t("span",{className:"text-[13px] font-medium",children:"Data variables"}),h.length?/* @__PURE__ */t("span",{className:"rounded-full bg-muted px-2 py-0.5 text-[10px] font-medium tabular-nums text-muted-foreground",children:h.length}):null]}),h.length?/* @__PURE__ */n(I,{size:"xs",className:"gap-1",onClick:d,children:[/* @__PURE__ */t(xe,{className:"h-3.5 w-3.5","aria-hidden":!0})," New variable"]}):null]}),h.length?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t("div",{className:"px-3 py-2",children:/* @__PURE__ */n("div",{className:"flex h-7 items-center gap-1.5 rounded-control border border-border px-2 text-[12px] text-muted-foreground",children:[/* @__PURE__ */t(na,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}),/* @__PURE__ */t("input",{value:o,onChange:m=>i(m.target.value),placeholder:"Search variables","aria-label":"Search variables",className:"w-full bg-transparent text-foreground outline-none placeholder:text-muted-foreground"})]})}),/* @__PURE__ */n("div",{className:"max-h-[360px] overflow-y-auto",children:[c.length?/* @__PURE__ */t(Jt,{children:s?`On ${s}`:"On this tab"}):null,c.map(m=>/* @__PURE__ */t(ea,{row:m,sheetId:a,onOpen:r},m.variable.id)),p.length?/* @__PURE__ */t(Jt,{children:c.length?"Elsewhere on this dashboard":"On this dashboard"}):null,p.map(m=>/* @__PURE__ */t(ea,{row:m,sheetId:a,onOpen:r,muted:!!c.length},m.variable.id)),l.length?null:/* @__PURE__ */t("p",{className:"px-4 py-6 text-center text-[12px] text-muted-foreground",children:"No variable matches."})]})]}):/* @__PURE__ */n("div",{className:"px-6 py-8 text-center",children:[/* @__PURE__ */t("span",{className:"mx-auto flex h-8 w-8 items-center justify-center rounded-full bg-muted",children:/* @__PURE__ */t(xt,{className:"h-4 w-4 text-muted-foreground","aria-hidden":!0})}),/* @__PURE__ */t("p",{className:"mt-3 text-[13px] font-medium",children:"No variables yet"}),/* @__PURE__ */t("p",{className:"mx-auto mt-1 max-w-[280px] text-[12px] leading-[1.5] text-muted-foreground",children:"A variable shows a value from your data in any text: a name or address in a header, the latest date in a footer."}),/* @__PURE__ */n(I,{size:"xs",className:"mt-4 gap-1",onClick:d,children:[/* @__PURE__ */t(xe,{className:"h-3.5 w-3.5","aria-hidden":!0})," New variable"]})]})]});}function Jt({children:e}){return/* @__PURE__ */t("p",{className:"border-y border-border/60 bg-muted/40 px-4 py-1 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground first:border-t-0",children:e});}function ea({row:e,sheetId:a,onOpen:s,muted:r}){return/* @__PURE__ */n("button",{type:"button",onClick:()=>s(e.variable.id),className:"grid w-full grid-cols-[minmax(0,1fr)_132px] items-center gap-3 border-t border-border/60 px-4 py-2 text-left first:border-t-0 hover:bg-muted/50",children:[/* @__PURE__ */n("span",{className:"min-w-0",children:[/* @__PURE__ */t("span",{className:G("block truncate text-[12px] font-medium text-foreground",!e.variable.label&&"font-mono"),children:e.variable.label||e.variable.name}),/* @__PURE__ */t("span",{className:"mt-0.5 block truncate text-[11px] text-muted-foreground",children:e.question})]}),/* @__PURE__ */t("span",{className:G("truncate text-right text-[11px]",r?"text-muted-foreground/70":"text-muted-foreground"),children:ps(e,a)})]});}function Mi(){const e=C(s=>{var r;return((r=s.dashboard.variables)==null?void 0:r.length)??0;}),a=C(s=>s.actions.setVariablesListOpen);return{label:"Data variables",count:e,open:()=>a(!0)};}function Ui(){var u;const e=C(l=>l.variablesListOpen),a=C(l=>l.actions.setVariablesListOpen),s=C(l=>l.dashboard),r=C(l=>l.selectedSheetId),d=C(l=>l.actions.openVariableEditor),o=rt("interactive"),i=(u=s.sheets)==null?void 0:u.find(l=>l.id===r),h=l=>{a(!1),d(l);};return/* @__PURE__ */n(Ee,{open:e,onOpenChange:a,children:[/* @__PURE__ */t(la,{asChild:!0,children:/* @__PURE__ */t("span",{"aria-hidden":!0,className:"pointer-events-none inline-block h-7 w-0 self-center"})}),/* @__PURE__ */t(Ie,{align:"end",sideOffset:6,collisionPadding:12,onFocusOutside:l=>l.preventDefault(),className:"z-50 w-auto rounded-card border border-border/60 p-0 shadow-[0_10px_28px_rgba(0,0,0,0.14)] dark:shadow-[0_10px_28px_rgba(0,0,0,0.5)]",style:o.contentStyle,children:/* @__PURE__ */t(fs,{dashboard:s,sheetId:r??void 0,sheetTitle:i==null?void 0:i.title,onOpen:l=>h({kind:"edit",variableId:l}),onNew:()=>h({kind:"new"})})})]});}function gs(e,a){const s=tr(e);return new Set((e.sheets??[]).map(d=>{const o={sheetId:d.id,cardId:a,sheetKind:_t(d)?"document":"dashboard"};return s.filter(i=>wr(i,o)).map(i=>i.runtimeScope==="shared"?i.id:`${i.id}@${d.id}`).join(`
42
+ `);})).size>1;}const bs=[];function gt(e){return Object.fromEntries(Object.entries(e).filter(([,a])=>a!=null));}function xs(e){const a=e==null?void 0:e.type;return a==="dataset"||a==="model"||nr.includes(a);}function vs(e,a){return Ar(e.map((s,r)=>{var d,o;return{target:s,columns:(d=a[r])==null?void 0:d.columns,calculatedFields:(o=a[r])==null?void 0:o.calculatedFields};})).columns;}function ys(e){const{tokenProps:a}=it(),s=C(m=>m.authToken),{connections:r}=ua(),d=e==null?void 0:e.connectionId,o=r.find(m=>m.id===d),i=K(()=>((e==null?void 0:e.selectedEntities)??[]).filter(xs),[e==null?void 0:e.selectedEntities]),h=m=>{var f;if(!(s!=null&&s.accessToken))return!1;if(m.type==="dataset"){const N=m;return!!(N.domainId&&N.name);}if(m.type==="model")return!!(d&&m.id);const g=((f=o==null?void 0:o.capabilities)==null?void 0:f.path)||[];return!(!d||!m.name||g.includes("database")&&!m.database||g.includes("schema")&&!m.schema);},u=oe(m=>{var f,N;const g=vs(i,m.map(w=>w.data));return{fields:g.length?g:bs,isLoading:m.some(w=>w.isLoading),error:(N=(f=m.find(w=>w.error))==null?void 0:f.error)==null?void 0:N.message};},[i]),{fields:l,isLoading:c,error:p}=Qa({queries:i.map(m=>({queryKey:["columns",d,m,(e==null?void 0:e.semanticDomainId)??null],queryFn:()=>ar(`${a.apiServiceUrl}/v1/columns`,(s==null?void 0:s.accessToken)||"",m.type==="model"?gt({connection_id:d,datamodel_id:m.id,database_name:"",schema_name:"",table_name:""}):m.type==="dataset"?gt({connection_id:m.connectionId??d,domain_id:m.domainId,dataset_name:m.name,database_name:m.database,schema_name:m.schema,table_name:m.table}):gt({connection_id:d,datamodel_id:"",database_name:m.database,schema_name:m.schema,table_name:m.name})),enabled:h(m),staleTime:6e4})),combine:u});return{fields:l,isLoading:c,error:p};}function Ns(e){var s;const a=((s=e.comparison)==null?void 0:s.mode)==="explicit"?e.comparison.spec:void 0;return a&&a.kind!=="target"?{mode:"period",spec:a}:{mode:"off"};}function Cs(e){return e.mode==="period"?ir(e.spec):void 0;}const Rt="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",ws={connectionId:"",connectionType:"",mode:"semanticDomain",selectedEntities:[]};function ae({label:e,hint:a,aside:s,children:r,className:d}){return/* @__PURE__ */n("div",{className:d,children:[/* @__PURE__ */n("div",{className:"mb-1 flex min-h-5 items-center justify-between gap-2",children:[/* @__PURE__ */t("p",{className:Rt,children:e}),s]}),r,a?/* @__PURE__ */t("p",{className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:a}):null]});}function bt({muted:e,onClick:a,children:s,ariaLabel:r}){return/* @__PURE__ */t("button",{type:"button",onClick:a,"aria-label":r,className:G("flex h-7 w-full items-center gap-1.5 rounded-control border border-input bg-background px-2 text-left text-[12px] hover:bg-muted/50",e?"text-muted-foreground":"text-foreground"),children:s});}function ks(e){var s;const a=(s=e==null?void 0:e.selectedEntities)==null?void 0:s[0];if(a)return a.label||a.name;}function Ss(e){const a=Ot(e);return a==="date"?"date":a==="string"?"text":a==="number"?"number":a==="boolean"?"yes/no":a;}const ta="__new_calculated_field__";function Ds({draft:e,onChange:a,handle:s,onCalculatedFieldOpenChange:r}){var Y,he,te,me,E,ne,Q,z,J,de,ce,ve;const{tokenProps:d}=it(),o=((Y=d.config)==null?void 0:Y.showAdvancedMode)!==!1,i=((he=d.config)==null?void 0:he.showDirectSource)!==!1,{connections:h}=ua(),[u,l]=F(!1),[c,p]=F(!1),[m,g]=F(!1),f=x=>{p(x),r==null||r(x);},{fields:N,isLoading:w,error:T}=ys(e.mode==="data"?e.dataSource:void 0),L=[...(e.calculatedFields??[]),...N],B=x=>x&&(L.find(O=>O.id===x.id)??L.find(O=>sr(O,x,"entity"))),D=[...L,...[e.field,e.sortField].filter(x=>!!x&&!B(x)&&!L.some(O=>O.id===x.id))],P=((te=B(e.field))==null?void 0:te.id)??((me=e.field)==null?void 0:me.id)??"",k=((E=B(e.sortField??e.field))==null?void 0:E.id)??((ne=e.sortField??e.field)==null?void 0:ne.id)??"",v=x=>a({...e,...x}),b=ks(e.dataSource),_=((Q=e.dataSource)==null?void 0:Q.mode)==="database"?vt:$t,A="mt-1 inline-flex items-center gap-1 text-[11px] font-medium text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",H={connectionId:((z=e.dataSource)==null?void 0:z.connectionId)||e.connectionId,dataSource:e.dataSource,config:e.conditions?{filters:e.conditions}:{},cardType:"text"},V=Wt(e.field),M=(J=V.find(x=>x.value===e.get))==null?void 0:J.hint,X=x=>{if(x===ta){f(!0);return;}const O=D.find(W=>W.id===x);if(!O)return;const $=Wt(O).some(W=>W.value===e.get)&&e.field!==void 0;v({field:O,get:$?e.get:Kt(O)});};return c?/* @__PURE__ */t(En,{inline:!0,open:!0,onOpenChange:f,availableFields:D,cardId:e.id,source:H,onSave:x=>{const O={...x,fieldScope:x.fieldScope??"card"};v({calculatedFields:[...(e.calculatedFields??[]).filter($=>$.id!==O.id),O],field:O,get:Kt(O)}),f(!1);}}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(ae,{label:"Name",aside:/* @__PURE__ */t(Fs,{value:e.name,placeholder:s,editing:m,onEditing:g,onChange:x=>v({name:x})}),hint:m?"The key: what you type after {{, and what links and agents use. Letters, digits and underscores.":void 0,children:/* @__PURE__ */t(be,{size:"xs",value:e.label??"",onChange:x=>v({label:x.target.value}),placeholder:((de=e.field)==null?void 0:de.label)||"Latest order date","aria-label":"Variable name"})}),e.mode==="sql"?/* @__PURE__ */n(R,{children:[/* @__PURE__ */n(ae,{label:"Connection",children:[/* @__PURE__ */n(we,{value:e.connectionId??"",onValueChange:x=>v({connectionId:x}),children:[/* @__PURE__ */t(ke,{size:"xs","aria-label":"Connection",children:/* @__PURE__ */t(Se,{placeholder:"Choose a connection"})}),/* @__PURE__ */t(De,{children:h.map(x=>/* @__PURE__ */t(fe,{value:x.id,children:x.name},x.id))})]}),/* @__PURE__ */n("button",{type:"button",onClick:()=>v({mode:"data"}),className:A,children:[/* @__PURE__ */t($t,{className:"h-3 w-3","aria-hidden":!0})," Use a dataset or table instead"]})]}),/* @__PURE__ */t(ae,{label:"SQL",hint:/* @__PURE__ */t(R,{children:"One row. Each column is a part; the first shows by default. Filters reach it where the SQL names them, as a SQL card's do."}),children:/* @__PURE__ */t(ba,{size:"xs",value:e.sql,onChange:x=>v({sql:x.target.value}),placeholder:"select max(order_date) as latest_order_date from orders",className:"min-h-[96px] font-mono","aria-label":"SQL"})}),/* @__PURE__ */t(ae,{label:"Get",children:/* @__PURE__ */n(we,{value:e.get==="first"?"first":"only",onValueChange:x=>v({get:x}),children:[/* @__PURE__ */t(ke,{size:"xs","aria-label":"Get",children:/* @__PURE__ */t(Se,{})}),/* @__PURE__ */n(De,{children:[/* @__PURE__ */t(fe,{value:"only",children:"The only row"}),/* @__PURE__ */t(fe,{value:"first",children:"The first row"})]})]})})]}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */n(ae,{label:"Source",children:[/* @__PURE__ */t(bt,{muted:!b,onClick:()=>l(!0),ariaLabel:"Source",children:b?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(_,{className:"h-3.5 w-3.5 text-muted-foreground","aria-hidden":!0})," ",b]}):i?"Choose a dataset or table":"Choose a dataset"}),o?/* @__PURE__ */n("button",{type:"button",onClick:()=>{var x;return v({mode:"sql",connectionId:((x=e.dataSource)==null?void 0:x.connectionId)||e.connectionId});},className:A,children:[/* @__PURE__ */t(Mr,{className:"h-3 w-3","aria-hidden":!0})," Write SQL instead"]}):null]}),/* @__PURE__ */t(In,{open:u,onOpenChange:l,dataSource:e.dataSource??ws,incomingSelectedEntities:((ce=e.dataSource)==null?void 0:ce.selectedEntities)??[],onDataSourceChange:x=>{var $;const O=JSON.stringify(x.selectedEntities)===JSON.stringify(($=e.dataSource)==null?void 0:$.selectedEntities);v(O?{dataSource:x}:{dataSource:x,field:void 0,sortField:void 0,conditions:null,calculatedFields:void 0});}}),/* @__PURE__ */n("div",{className:"grid grid-cols-2 gap-3",children:[/* @__PURE__ */t(ae,{label:"Field",children:b?/* @__PURE__ */n(we,{value:P,onValueChange:X,disabled:w&&!D.length,children:[/* @__PURE__ */t(ke,{size:"xs","aria-label":"Field",children:/* @__PURE__ */t(Se,{placeholder:w?"Loading fields…":T?"Fields unavailable":"Choose a field"})}),/* @__PURE__ */n(De,{children:[D.map(x=>/* @__PURE__ */t(fe,{value:x.id,children:/* @__PURE__ */n("span",{className:"flex items-center gap-2",children:[/* @__PURE__ */t("span",{children:x.label||x.name}),/* @__PURE__ */t("span",{className:"text-muted-foreground",children:Ss(x.dataType)})]})},x.id)),/* @__PURE__ */t(Ga,{}),/* @__PURE__ */t(fe,{value:ta,children:/* @__PURE__ */n("span",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */t(xe,{className:"h-3 w-3","aria-hidden":!0})," New calculated field…"]})})]})]}):/* @__PURE__ */t(bt,{muted:!0,children:"Choose a source first"})}),/* @__PURE__ */t(ae,{label:"Get",children:/* @__PURE__ */n(we,{value:e.get,onValueChange:x=>v({get:x}),disabled:!e.field,children:[/* @__PURE__ */t(ke,{size:"xs","aria-label":"Get",children:/* @__PURE__ */t(Se,{})}),/* @__PURE__ */t(De,{children:V.map(x=>/* @__PURE__ */t(fe,{value:x.value,children:x.label},x.value))})]})}),e.field&&M?/* @__PURE__ */t("p",{className:"col-span-2 -mt-1.5 text-[11px] leading-4 text-muted-foreground",children:M}):null,T?/* @__PURE__ */t("p",{className:"col-span-2 -mt-1.5 text-[11px] leading-4 text-destructive",children:T}):null,Er(e)?/* @__PURE__ */t(ae,{label:"Compare with",className:"col-span-2",children:/* @__PURE__ */t(Ha,{controlLabel:"Variable",selection:Ns(e),onChange:x=>v({comparison:Cs(x)})})}):null,e.field&&!Ir(e.get)&&e.get!=="only"?/* @__PURE__ */n("div",{className:G("col-span-2 grid gap-3",e.get==="list"?"grid-cols-3":"grid-cols-2"),children:[/* @__PURE__ */t(ae,{label:"Order by",children:/* @__PURE__ */n(we,{value:`${k}|${e.sortDirection}`,onValueChange:x=>{const O=x.lastIndexOf("|"),$=x.slice(0,O),W=x.slice(O+1);v({sortField:D.find(re=>re.id===$),sortDirection:W});},children:[/* @__PURE__ */t(ke,{size:"xs","aria-label":"Order by",children:/* @__PURE__ */t(Se,{})}),/* @__PURE__ */t(De,{children:D.flatMap(x=>["asc","desc"].map(O=>/* @__PURE__ */n(fe,{value:`${x.id}|${O}`,children:[x.label||x.name,", ",As(x,O)]},`${x.id}|${O}`)))})]})}),e.get==="list"?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(ae,{label:"Show up to",children:/* @__PURE__ */t(be,{size:"xs",type:"number",min:1,max:nt,value:e.listLimit??"",placeholder:"10",onChange:x=>{const O=Number.parseInt(x.target.value,10);v({listLimit:Number.isFinite(O)&&O>0?Math.min(O,nt):void 0});},"aria-label":"Show up to"})}),/* @__PURE__ */t(ae,{label:"Separator",children:/* @__PURE__ */t(be,{size:"xs",value:e.listSeparator??", ",maxLength:rr,onChange:x=>v({listSeparator:x.target.value}),className:"font-mono","aria-label":"Separator"})})]}):null]}):null]}),/* @__PURE__ */t(ae,{label:"Filters",children:b?/* @__PURE__ */t(xr,{filters:e.conditions??null,availableFields:D,source:H,onChange:x=>v({conditions:x})},JSON.stringify(((ve=e.dataSource)==null?void 0:ve.selectedEntities)??null)):/* @__PURE__ */t(bt,{muted:!0,children:"Choose a source first"})})]})]});}function As(e,a){const s=Ot(e.dataType);return s==="date"?a==="asc"?"earliest first":"latest first":s==="number"?a==="asc"?"lowest first":"highest first":a==="asc"?"A to Z":"Z to A";}function Fs({value:e,placeholder:a,editing:s,onEditing:r,onChange:d}){return s?/* @__PURE__ */t(be,{size:"xs",autoFocus:!0,value:e,placeholder:a,onChange:o=>d(o.target.value),onBlur:()=>r(!1),onKeyDown:o=>{(o.key==="Enter"||o.key==="Escape")&&(o.preventDefault(),o.stopPropagation(),r(!1));},className:"h-6 w-44 font-mono text-[11px]","aria-label":"Key"}):/* @__PURE__ */n("button",{type:"button",onClick:()=>r(!0),"aria-label":"Edit key",title:"The key: what you type after {{, and what links and agents use",className:"inline-flex h-5 items-center gap-1 rounded-[4px] px-1 font-mono text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:[`{{${e.trim()||a}}}`,/* @__PURE__ */t(Bt,{className:"h-3 w-3","aria-hidden":!0})]});}const Es=[{id:"data",label:"Data"},{id:"filters",label:"Dashboard filters"},{id:"display",label:"Display"}];function Is(e){const{name:a,label:s,presentation:r,emptyText:d,...o}=e;return JSON.stringify(o);}function Ts({variable:e,onClose:a,onHoldEscape:s}){var te,me;const r=C(E=>E.dashboard),d=C(E=>E.selectedSheetId),o=C(E=>E.actions.saveVariableChange),[i,h]=F(()=>e?Tr(e):Lr()),[u,l]=F("data"),[c,p]=F(!1),m=E=>{p(E),s==null||s(E);},[g,f]=F([]),[N,w]=F(null),T=!e,L=Is(i),B=K(()=>Qt({...JSON.parse(L),name:""},r),[L,r]),{name:D,label:P,presentation:k,emptyText:v}=i,b=K(()=>({...B,name:Gt(r,{id:B.id,name:D,field:i.field,mode:i.mode,label:P}),...(P!=null&&P.trim()?{label:P.trim()}:{}),...(k?{presentation:k}:{}),...(v!=null&&v.trim()?{emptyText:v}:{})}),[B,r,D,P,k,v,i.field,i.mode]),_=K(()=>({...r,variables:[...(r.variables??[]).filter(E=>E.id!==b.id),b]}),[r,b]),A=Vr(i),H=ot(),V=C(E=>E.actions.mergeSemanticExecutionPayload),[M,X]=F(!1),Y=async()=>{const E=Qt(i,r);X(!0);let ne;try{const z=ur(r,e?{kind:"update",id:e.id,patch:E}:{kind:"add",variable:E});if(!z.ok){X(!1),f(z.issues);return;}const[J]=z.queryFrames;ne=J?await H(J,e?{previousFrame:hr(r,e)}:void 0):{domainsById:{}};}catch(z){X(!1),f([{code:"queryMissing",message:z instanceof Error&&z.message?z.message:"The data source's details could not be loaded.",fix:"Try again, or choose the source again."}]);return;}const Q=o(T?{kind:"add",variable:E}:{kind:"update",id:E.id,patch:Ls(E)});if(X(!1),!Q.ok){f(Q.issues);return;}V(ne),a();},he=E=>{if(!e)return;const ne=o({kind:"remove",id:e.id,confirmed:E});if(!ne.ok){const Q=ne.issues.find(z=>z.code==="inUse");if(Q&&!E){w(Q);return;}f(ne.issues);return;}a();};return/* @__PURE__ */n("div",{className:"flex h-[600px] max-h-[85vh] w-[600px] max-w-[calc(100vw-24px)] flex-col overflow-hidden","data-testid":"variable-editor",children:[/* @__PURE__ */n("div",{className:"flex min-h-12 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3 py-1.5",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-start gap-2",children:[/* @__PURE__ */t(xt,{className:"mt-1 h-3.5 w-3.5 shrink-0 text-muted-foreground","aria-hidden":!0}),/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */n("p",{className:"flex items-center gap-2",children:[/* @__PURE__ */t("span",{className:"truncate text-[13px] font-medium text-foreground",children:T?"New variable":e.label||e.name}),/* @__PURE__ */t("span",{className:Rt,children:"Variable from data"})]}),/* @__PURE__ */t("p",{className:"mt-0.5 truncate text-[10px] leading-3 text-muted-foreground/70",children:"Available on every tab and Document of this dashboard"})]})]}),/* @__PURE__ */t("button",{type:"button",onClick:a,"aria-label":"Close",className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-control text-muted-foreground hover:bg-muted hover:text-foreground",children:/* @__PURE__ */t(Ue,{className:"h-3.5 w-3.5","aria-hidden":!0})})]}),c?null:/* @__PURE__ */t("nav",{role:"tablist","aria-label":"Variable settings sections",className:"flex h-9 shrink-0 items-stretch gap-4 border-b border-border/60 px-4",children:Es.map(E=>/* @__PURE__ */n("button",{role:"tab","aria-selected":u===E.id,onClick:()=>l(E.id),className:G("relative -mb-px inline-flex items-center text-[13px] transition-colors focus-visible:outline-none",u===E.id?"font-medium text-foreground":"text-muted-foreground hover:text-foreground"),children:[E.label,u===E.id?/* @__PURE__ */t("span",{className:"absolute inset-x-0 -bottom-px h-[2px] bg-foreground"}):null]},E.id))}),/* @__PURE__ */n("div",{className:G("min-h-0 flex-1 overflow-y-auto",u==="filters"||c?"":"space-y-4 px-4 py-4"),children:[u==="data"?/* @__PURE__ */t(Ds,{draft:i,onChange:h,handle:Gt(r,i),onCalculatedFieldOpenChange:m}):null,u==="filters"?/* @__PURE__ */t(Vs,{draft:i,draftDashboard:_}):null,u==="display"?/* @__PURE__ */t(Os,{draft:i,onChange:h}):null]}),c?null:/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(Ps,{draft:i,draftVariable:b,draftDashboard:_,blocker:A,selectedSheetId:d??void 0}),g.length?/* @__PURE__ */t("div",{className:"shrink-0 border-t border-border/60 bg-destructive/5 px-4 py-2 text-[11px] leading-4 text-destructive",role:"alert",children:g.map(E=>/* @__PURE__ */n("p",{children:[E.message," ",E.fix]},`${E.code}:${E.path??""}`))}):null,N?/* @__PURE__ */n("div",{className:"shrink-0 border-t border-border/60 bg-amber-500/10 px-4 py-2 text-[11px] leading-4 text-amber-800 dark:text-amber-300",role:"alertdialog",children:[/* @__PURE__ */n("p",{children:[N.message," Used in ",((te=N.places)==null?void 0:te.length)??0," ",((me=N.places)==null?void 0:me.length)===1?"place":"places",". Its chips then read as missing."]}),/* @__PURE__ */n("div",{className:"mt-1.5 flex gap-1.5",children:[/* @__PURE__ */t(I,{variant:"outline",size:"xs",className:"h-6 px-2 text-[11px]",onClick:()=>w(null),children:"Keep it"}),/* @__PURE__ */t(I,{size:"xs",className:"h-6 px-2 text-[11px]",onClick:()=>he(!0),children:"Remove anyway"})]})]}):null,/* @__PURE__ */n("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border/60 px-4 py-2.5",children:[T?/* @__PURE__ */t("span",{}):/* @__PURE__ */t(I,{variant:"outline",size:"xs",className:"text-destructive hover:border-destructive/40 hover:bg-destructive/10 hover:text-destructive",onClick:()=>he(!1),children:"Delete"}),/* @__PURE__ */n("span",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */t(I,{variant:"outline",size:"xs",onClick:a,children:"Cancel"}),/* @__PURE__ */t(I,{size:"xs",disabled:!!A||M,title:A,onClick:()=>void Y(),children:T?"Create":"Done"})]})]})]})]});}function Ls(e){const{id:a,...s}=e;return{...s,label:s.label,presentation:s.presentation,emptyText:s.emptyText};}function Vs({draft:e,draftDashboard:a}){const s=K(()=>or(a),[a]),r=s.inputs.filter(o=>s.reachedVariables({inputId:o.input.id}).some(i=>i.variableId===e.id)),d=e.mode==="sql"&&lr(e.sql);return r.length?/* @__PURE__ */n("div",{className:"divide-y divide-border/60",children:[/* @__PURE__ */t("p",{className:"px-4 py-2 text-[11px] leading-4 text-muted-foreground",children:"How each filter applies here. Change a mapping on the filter's Cards tab, under Variables."}),r.map(o=>{var u;const i=(u=o.input.application)==null?void 0:u.cards.find(l=>l.cardId===e.id),h=d?"Subscribes in SQL":e.mode==="sql"?"Not named in the SQL":(i==null?void 0:i.kind)==="excluded"?"Don't apply":(i==null?void 0:i.kind)==="bound"?`${i.target.kind==="field"?"Field":"Path"} · ${i.target.field.name}`:"Auto";return/* @__PURE__ */n("div",{className:"flex items-center justify-between gap-3 px-4 py-2 text-[12px]",children:[/* @__PURE__ */n("span",{className:"min-w-0",children:[/* @__PURE__ */t("span",{className:"block truncate font-medium text-foreground",children:o.input.label||o.input.filter.title}),/* @__PURE__ */t("span",{className:"block truncate text-[11px] text-muted-foreground",children:Bs(o.input.scope)})]}),/* @__PURE__ */t("span",{className:G("shrink-0 text-[11px]",h==="Don't apply"||h==="Not named in the SQL"?"text-muted-foreground":"text-foreground"),children:h})]},o.input.id);})]}):/* @__PURE__ */t("p",{className:"px-4 py-6 text-center text-[12px] text-muted-foreground",children:"No filter reaches this variable. A filter on the tabs or Documents where it is used reaches it; a variable used nowhere yet follows every tab's filters."});}function Bs(e){switch(e.kind){case"allSheets":return"On every tab";case"sheets":return"On chosen tabs";case"cards":return"On chosen cards and variables";default:return e.kind;}}const _s=[{value:"auto",label:"Automatic"},{value:"short",label:"Short"},{value:"medium",label:"Medium"},{value:"long",label:"Long"},{value:"pattern",label:"Custom pattern…"}];function Os({draft:e,onChange:a}){var h,u;const s=e.mode==="sql"?"unknown":Ot((h=e.field)==null?void 0:h.dataType),r=(u=e.presentation)==null?void 0:u.temporal,d=r?r.mode==="style"?r.dateStyle:r.mode==="pattern"?"pattern":"auto":"auto",o=(r==null?void 0:r.mode)==="pattern"?yr(r.pattern):null,i=l=>a({...e,presentation:l&&Object.keys(l).length?l:void 0});return/* @__PURE__ */n(R,{children:[s==="date"||s==="unknown"?/* @__PURE__ */n(ae,{label:"Dates read as",hint:"A chip can change this for itself.",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */n(we,{value:d,onValueChange:l=>i({...e.presentation,temporal:l==="auto"?void 0:l==="pattern"?{mode:"pattern",dialect:"semaphor_tokens",pattern:(r==null?void 0:r.mode)==="pattern"?r.pattern:"MMM D, YYYY"}:{mode:"style",dateStyle:l}}),children:[/* @__PURE__ */t(ke,{size:"xs",className:"w-44","aria-label":"Date style",children:/* @__PURE__ */t(Se,{})}),/* @__PURE__ */t(De,{children:_s.map(l=>/* @__PURE__ */t(fe,{value:l.value,children:l.label},l.value))})]}),(r==null?void 0:r.mode)==="pattern"?/* @__PURE__ */t(be,{size:"xs",value:r.pattern,onChange:l=>i({...e.presentation,temporal:{mode:"pattern",dialect:"semaphor_tokens",pattern:l.target.value}}),className:"w-40 font-mono","aria-label":"Date pattern"}):null]}),o?/* @__PURE__ */t("p",{className:"mt-1 text-[11px] text-destructive",children:o}):null]}):null,s==="number"||s==="unknown"?/* @__PURE__ */t(ae,{label:"Numbers read as",hint:"A chip can change any of these for itself.",children:/* @__PURE__ */t(Tn,{value:e.presentation,onChange:i})}):null,/* @__PURE__ */t(ae,{label:"When there’s no value",hint:"Readers see this when nothing matches or more than one does. Leave it empty to show nothing.",children:/* @__PURE__ */t(be,{size:"xs",value:e.emptyText??"",maxLength:dr,onChange:l=>a({...e,emptyText:l.target.value||void 0}),placeholder:"Show nothing",className:"w-72","aria-label":"Empty text"})})]});}function Ps({draft:e,draftVariable:a,draftDashboard:s,blocker:r,selectedSheetId:d}){var v;const o=s.sheets??[],i=K(()=>gs(s,a.id),[s,a.id]),[h,u]=F(void 0),l=(i?h:void 0)??d??((v=o[0])==null?void 0:v.id),c=o.find(b=>b.id===l),p=C(b=>l?b.documentSectionRuntimeBySheetId[l]:void 0),m=!!(c&&_t(c)),g=K(()=>l?m?p?{kind:"document",sheetId:l,runtime:p}:void 0:{kind:"sheet",sheetId:l}:void 0,[m,p,l]),f=K(()=>r||!g?[]:[a],[r,a,g]),w=Ln({dashboard:s,place:g??{kind:"sheet",sheetId:l??""},purpose:"preview",variables:f}).byId.get(a.id),T=Ya(),L=Xa(),B=K(()=>cr({preferences:T,calendar:L}),[L,T]);let D,P="",k=null;if(r)D=/* @__PURE__ */t("span",{className:"text-muted-foreground",children:e.mode==="sql"?"Write the SQL to see a value.":"Choose a source and a field to see a value."});else if(!g)D=/* @__PURE__ */t("span",{className:"text-muted-foreground",children:"Open this Document to preview here."});else if(!w||w.status==="loading")D=/* @__PURE__ */t("span",{className:"text-muted-foreground",children:"Loading…"});else{const b=zs(a,w,B);if(D=b.body,P=b.meta,b.unavailable){const _=(c==null?void 0:c.title)||"this tab";k=/* @__PURE__ */n("p",{className:"mt-1.5 flex gap-1.5 text-[11px] leading-4 text-amber-700 dark:text-amber-400",children:[/* @__PURE__ */t(ha,{className:"mt-px h-3 w-3 shrink-0","aria-hidden":!0}),/* @__PURE__ */n("span",{children:["No change on ",_,". ",Za(b.unavailable,"variable")]})]});}}return/* @__PURE__ */n("div",{className:"shrink-0 border-t border-border/60 bg-muted/30 px-4 py-2.5","data-testid":"variable-preview",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-3",children:[/* @__PURE__ */t("span",{className:Rt,children:i?"Preview on":"Preview"}),i?/* @__PURE__ */n(we,{value:l??"",onValueChange:u,disabled:!!r,children:[/* @__PURE__ */t(ke,{size:"xs",className:"h-6 w-auto gap-1.5 px-2 text-[12px]","aria-label":"Preview place",children:/* @__PURE__ */t(Se,{})}),/* @__PURE__ */t(De,{children:o.map(b=>/* @__PURE__ */t(fe,{value:b.id,children:b.title||b.id},b.id))})]}):null,/* @__PURE__ */t("div",{className:"min-w-0 flex-1 truncate text-right text-[13px]",children:D})]}),P?/* @__PURE__ */t("p",{className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:P}):null,k]});}function zs(e,a,s){const r=c=>/* @__PURE__ */t("span",{className:"font-medium text-foreground",children:c}),d=c=>/* @__PURE__ */n("span",{className:"inline-flex items-center gap-1.5 text-[12px] text-amber-700 dark:text-amber-400",children:[/* @__PURE__ */t(ha,{className:"h-3.5 w-3.5","aria-hidden":!0})," ",c]}),o=c=>c===void 0?"":c==="beyondCap"?`more than ${nt} match`:`${c} ${c===1?"match":"matches"}`,i="filterReach"in a?a.filterReach:[],h=i.filter(c=>c.status==="applied").length,u=i.length-h,l=i.length?` · ${h} ${h===1?"filter":"filters"} applied${u?`, ${u} skipped`:""}`:"";switch(a.status){case"answered":{const c=kr(e,Object.keys(a.parts))[0],p=c?a.parts[c]:void 0,m=p&&jt(p,e.presentation,s)||"(empty)",g=`${o(a.matched)}${l}`.replace(/^ · /,""),f=mr(e,a,s);return f&&typeof f=="object"&&"unavailable"in f?{body:r(m),meta:g,unavailable:f.unavailable}:f==="noPrevious"?{body:r(m),meta:`${g} · Nothing in the period before to compare with.`.replace(/^ · /,"")}:f?{body:/* @__PURE__ */n(R,{children:[r(f.value),/* @__PURE__ */n("span",{className:"text-muted-foreground",children:[" · was ",f.previous," · "]}),r(f.change)]}),meta:g}:{body:r(m),meta:g};}case"listed":{const c=a.items.map(m=>jt(m,e.presentation,s)),p=a.more==="beyondCap"?" and more":a.more?` and ${a.more} more`:"";return{body:r(`${c.join(e.get.kind==="list"?e.get.separator??", ":", ")}${p}`),meta:`${o(a.matched)}${l}`};}case"none":return a.why==="moreThanOne"?{body:d(`More than one matches${a.matched!==void 0?` (${a.matched==="beyondCap"?`${nt}+`:a.matched})`:""}. Readers see nothing.`),meta:"Keep a selection on a filter, add a condition, or choose First or List."}:{body:/* @__PURE__ */t("span",{className:"text-muted-foreground",children:"No rows match."}),meta:l.slice(3)};case"held":return{body:/* @__PURE__ */n("span",{className:"text-muted-foreground",children:["Waiting for ",a.missingRequired.join(", "),"."]}),meta:"A required filter has no value here."};case"broken":return{body:d("The query no longer compiles against its mapping."),meta:""};case"failed":return{body:d("The query failed."),meta:a.message};default:return{body:null,meta:""};}}function $i(){const e=C(i=>i.variableEditor),a=C(i=>i.dashboard.variables),s=C(i=>i.actions.closeVariableEditor),r=Ze(!1),d=(e==null?void 0:e.kind)==="edit"?a==null?void 0:a.find(i=>i.id===e.variableId):void 0;return!(e&&(e.kind==="new"||d))?null:/* @__PURE__ */n(Te,{modal:!1,open:!0,onOpenChange:i=>!i&&s(),children:[/* @__PURE__ */t("div",{className:"pointer-events-none fixed inset-0 z-40 bg-zinc-950/40 backdrop-blur-sm"}),/* @__PURE__ */n(Le,{className:"w-auto max-w-none gap-0 overflow-hidden p-0 [&>button:last-child]:hidden",onInteractOutside:i=>i.preventDefault(),onEscapeKeyDown:i=>{r.current?i.preventDefault():s();},children:[/* @__PURE__ */t(Ve,{className:"sr-only",children:"Variable from data"}),/* @__PURE__ */t(st,{className:"sr-only",children:"Define a value from your data to show in text."}),/* @__PURE__ */t(Ts,{variable:d,onClose:s,onHoldEscape:i=>{r.current=i;}},(e==null?void 0:e.kind)==="edit"?e.variableId:"new")]})]});}function Rs({disabled:e,briefingCount:a,className:s,onClick:r}){const d=typeof a=="number"&&a>0;return/* @__PURE__ */n(I,{type:"button",size:"xs",variant:"outline",disabled:e,className:G("gap-1.5",s),onClick:r,"aria-label":"Reports & briefings",children:[/* @__PURE__ */t(Rr,{className:"h-3.5 w-3.5"}),"Reports & briefings",d?/* @__PURE__ */t("span",{className:"ml-0.5 rounded-control bg-muted px-1 text-[10px] tabular-nums text-foreground/70",children:a}):null]});}const Ms="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",Da="inline-flex h-7 items-center gap-1.5 rounded-control px-2 text-[12px] text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-50",Xe="inline-flex h-7 items-center gap-1.5 rounded-control bg-primary px-3 text-[12px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50";function Us(e){return e==="dashboard"?"This dashboard":"Project";}function $s(e){if(!e)return"Never";const a=new Date(e);if(Number.isNaN(a.getTime()))return"Unknown";const s=Date.now()-a.getTime(),r=Math.round(s/6e4);if(r<1)return"now";if(r<60)return`${r}m ago`;const d=Math.round(r/60);if(d<24)return`${d}h ago`;const o=Math.round(d/24);if(o<7)return`${o}d ago`;const i=Math.round(o/7);return i<5?`${i}w ago`:`${Math.round(o/30)}mo ago`;}function js(e){return e.scheduleExpr?Br(e.scheduleExpr,e.timezone||"UTC")??"Invalid schedule":"On demand";}function qs(e){if(e.lastRunStatus){const a=e.lastRunStatus.toString().toUpperCase();return a==="SUCCESS"?"Last run completed.":a==="FAILED"?"Last run failed.":`Last run ${e.lastRunStatus.toString().toLowerCase()}`;}return null;}function Aa(e){return e.hasActiveRun?"Running":e.lastRunStatus?`Last run ${e.lastRunStatus.toString().toLowerCase()}`:"Idle";}function Ws(e){return e.source.type==="dashboard"?"This dashboard":"Project";}function Ks({activeView:e,onChange:a}){return/* @__PURE__ */t("div",{className:"flex shrink-0 items-center gap-1 rounded-control bg-muted p-0.5",role:"tablist","aria-label":"Briefing source view",children:["dashboard","project"].map(s=>{const r=e===s;return/* @__PURE__ */t("button",{type:"button",role:"tab","aria-selected":r,onClick:()=>a(s),className:G("h-6 rounded-[3px] px-2 text-[11px] transition-colors",r?"bg-background font-medium text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:Us(s)},s);})});}function Qs({briefings:e,dashboardLabel:a,sourceView:s,error:r,loading:d,onSourceViewChange:o,onClose:i,onEdit:h,onNew:u,canCreate:l,canCreateScheduledReport:c,analyticalBriefingsEnabled:p,onRunNow:m,onTogglePause:g,onDelete:f,selectingId:N,busyId:w,manageBriefingsHref:T,contentKind:L,hideHeader:B=!1}){const D=e.length,P=e.filter(A=>A.status==="ACTIVE").length,k=L==="reports"?D===1?"report":"reports":L==="briefings"?D===1?"briefing":"briefings":D===1?"item":"items",v=e.find(A=>A.hasActiveRun)??null,b=L??"reports & briefings",_=s==="dashboard"?a:`Project ${b}`;return/* @__PURE__ */n("section",{"aria-label":`Dashboard ${b.replace("&","and")}`,className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:[B?null:/* @__PURE__ */n("header",{className:"flex items-start justify-between gap-3 border-b border-border px-4 py-3",children:[/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */t("div",{className:Ms,children:b}),/* @__PURE__ */t("h2",{className:"mt-0.5 truncate text-[14px] font-semibold leading-5",children:_})]}),/* @__PURE__ */t("button",{type:"button",onClick:i,className:"rounded-control p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":`Close ${b.replace("&","and")} panel`,children:/* @__PURE__ */t(Ue,{className:"h-3.5 w-3.5"})})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between gap-3 border-b border-border px-4 py-2",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-3",children:[/* @__PURE__ */t(Ks,{activeView:s,onChange:o}),/* @__PURE__ */t("div",{className:"flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:d&&D===0?/* @__PURE__ */n("span",{children:["Loading ",b,"…"]}):D===0?/* @__PURE__ */n("span",{children:["No ",b," yet"]}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */n("span",{className:"font-medium text-foreground/80",children:[D," ",k]}),/* @__PURE__ */t("span",{className:"text-border",children:"·"}),/* @__PURE__ */n("span",{children:[P," active"]})]})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-1.5",children:[d?/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}):null,D>0&&l?p&&c?/* @__PURE__ */n($e,{children:[/* @__PURE__ */t(je,{asChild:!0,children:/* @__PURE__ */n("button",{className:Xe,children:[/* @__PURE__ */t(xe,{className:"h-3 w-3"})," New"]})}),/* @__PURE__ */n(qe,{align:"end",children:[/* @__PURE__ */t(ee,{onClick:()=>u("scheduled_report"),children:"Schedule a report"}),/* @__PURE__ */t(ee,{onClick:()=>u("analytical_briefing"),children:"Create analytical briefing"})]})]}):c?/* @__PURE__ */n("button",{onClick:()=>u("scheduled_report"),className:Xe,children:[/* @__PURE__ */t(xe,{className:"h-3 w-3"})," Schedule report"]}):p?/* @__PURE__ */n("button",{onClick:()=>u("analytical_briefing"),className:Xe,children:[/* @__PURE__ */t(xe,{className:"h-3 w-3"})," New briefing"]}):null:null]})]}),v?/* @__PURE__ */n("div",{className:"flex items-center gap-2 border-b border-border bg-muted/60 px-4 py-2 text-[12px]",children:[/* @__PURE__ */t(se,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}),/* @__PURE__ */t("span",{className:"font-medium text-foreground",children:v.name}),/* @__PURE__ */t("span",{className:"text-border",children:"·"}),/* @__PURE__ */t("span",{className:"truncate text-muted-foreground",children:Aa(v)})]}):null,/* @__PURE__ */n("div",{className:"flex-1 overflow-y-auto",children:[r?/* @__PURE__ */t("div",{className:"m-4 rounded-card border border-destructive/30 bg-destructive/10 px-3 py-2 text-[12px] text-destructive",children:r}):null,!d&&e.length===0&&!r?/* @__PURE__ */t(Gs,{onNew:u,canCreate:l,canCreateScheduledReport:c,analyticalBriefingsEnabled:p,contentKind:L}):null,e.map(A=>/* @__PURE__ */t(Ys,{briefing:A,isOpening:N===A.id,isBusy:w===A.id,onOpen:()=>h(A.id),onRunNow:()=>m(A),onTogglePause:()=>g(A),onDelete:()=>f(A)},A.id))]}),T?/* @__PURE__ */t("div",{className:"border-t border-border px-4 py-2.5",children:/* @__PURE__ */n("a",{href:T,className:G(Da,"h-6 px-1 text-[11px]"),children:["Manage all reports & briefings",/* @__PURE__ */t(Or,{className:"h-3 w-3"})]})}):null]});}function Gs({onNew:e,canCreate:a,canCreateScheduledReport:s,analyticalBriefingsEnabled:r,contentKind:d}){const o=d==="reports"?{title:"No reports yet",description:"Schedule an emailed dashboard or visual report to see it here."}:d==="briefings"?{title:"No briefings yet",description:"Create an analytical briefing to monitor this dashboard and brief your team."}:null;return/* @__PURE__ */n("div",{className:"flex h-full flex-col items-center justify-center px-8 py-12 text-center",children:[/* @__PURE__ */t(Hs,{className:"mb-5 h-[88px] w-[112px] text-border"}),/* @__PURE__ */t("div",{className:"text-[13px] font-medium text-foreground",children:(o==null?void 0:o.title)??"Have an analyst brief your team"}),/* @__PURE__ */t("p",{className:"mt-1.5 max-w-[320px] text-[12px] leading-5 text-muted-foreground",children:(o==null?void 0:o.description)??"Describe what to watch. An analyst digs into this dashboard and the data behind it, then briefs your team on the cadence you choose."}),a?/* @__PURE__ */n("div",{className:"mt-4 flex flex-wrap justify-center gap-2",children:[s?/* @__PURE__ */n("button",{onClick:()=>e("scheduled_report"),className:Xe,children:[/* @__PURE__ */t(xe,{className:"h-3 w-3"})," Schedule a report"]}):null,r?/* @__PURE__ */t("button",{onClick:()=>e("analytical_briefing"),className:Da,children:"Create analytical briefing"}):null]}):null]});}function Hs({className:e}){return/* @__PURE__ */n("svg",{viewBox:"0 0 112 88",fill:"none",xmlns:"http://www.w3.org/2000/svg",role:"presentation","aria-hidden":"true",className:e,children:[/* @__PURE__ */t("rect",{x:"22",y:"6",width:"60",height:"72",rx:"3",stroke:"currentColor",strokeWidth:"1.25"}),/* @__PURE__ */t("line",{x1:"30",y1:"16",x2:"64",y2:"16",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),/* @__PURE__ */t("line",{x1:"30",y1:"21",x2:"52",y2:"21",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round",opacity:"0.5"}),/* @__PURE__ */t("circle",{cx:"31",cy:"32",r:"1",fill:"currentColor",opacity:"0.6"}),/* @__PURE__ */t("line",{x1:"35",y1:"32",x2:"72",y2:"32",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),/* @__PURE__ */t("circle",{cx:"31",cy:"38",r:"1",fill:"currentColor",opacity:"0.6"}),/* @__PURE__ */t("line",{x1:"35",y1:"38",x2:"68",y2:"38",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),/* @__PURE__ */t("circle",{cx:"31",cy:"44",r:"1",fill:"currentColor",opacity:"0.6"}),/* @__PURE__ */t("line",{x1:"35",y1:"44",x2:"74",y2:"44",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),/* @__PURE__ */t("rect",{x:"30",y:"64",width:"5",height:"8",rx:"0.5",fill:"currentColor",opacity:"0.55"}),/* @__PURE__ */t("rect",{x:"38",y:"60",width:"5",height:"12",rx:"0.5",fill:"currentColor",opacity:"0.7"}),/* @__PURE__ */t("rect",{x:"46",y:"56",width:"5",height:"16",rx:"0.5",fill:"currentColor",opacity:"0.85"}),/* @__PURE__ */t("rect",{x:"54",y:"62",width:"5",height:"10",rx:"0.5",fill:"currentColor",opacity:"0.6"}),/* @__PURE__ */t("rect",{x:"62",y:"58",width:"5",height:"14",rx:"0.5",fill:"currentColor",opacity:"0.75"}),/* @__PURE__ */t("circle",{cx:"86",cy:"62",r:"10",className:"fill-background",stroke:"currentColor",strokeWidth:"1.25"}),/* @__PURE__ */t("line",{x1:"93.5",y1:"69.5",x2:"100",y2:"76",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]});}function Ys({briefing:e,isOpening:a,isBusy:s,onOpen:r,onRunNow:d,onTogglePause:o,onDelete:i}){const h=e.status==="PAUSED",u=e.hasActiveRun,l=qs(e),c=$s(e.lastRunAt),p=e.lastRunStatus,m=pe(e),g=p==="SUCCESS"?Ge.success.dot:p==="FAILED"?Ge.danger.dot:p?Ge.warning.dot:Ge.neutral.dot;return/* @__PURE__ */n("div",{className:G("group relative border-b border-border/60 px-4 py-3 transition-colors hover:bg-muted/60",h&&"opacity-70"),children:[/* @__PURE__ */n("div",{role:"button",tabIndex:0,onClick:r,onKeyDown:f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),r());},className:"cursor-pointer pr-8",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-2",children:[/* @__PURE__ */t("span",{className:"truncate text-[13px] font-medium text-foreground",children:e.name}),h?/* @__PURE__ */t("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:"· Paused"}):null]}),/* @__PURE__ */n("div",{className:"mt-1 flex flex-wrap items-center gap-x-1.5 text-[11px] text-muted-foreground",children:[/* @__PURE__ */t("span",{children:m.typeLabel}),/* @__PURE__ */t("span",{className:"text-border",children:"·"}),/* @__PURE__ */t("span",{children:Ws(e)}),/* @__PURE__ */t("span",{className:"text-border",children:"·"}),/* @__PURE__ */t(Vn,{className:"h-3 w-3"}),/* @__PURE__ */t("span",{className:"truncate",children:js(e)}),e.lastRunAt?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t("span",{className:"text-border",children:"·"}),/* @__PURE__ */n("span",{children:["Last run ",c]})]}):null]}),l||u?/* @__PURE__ */n("div",{className:"mt-1.5 flex items-center gap-1.5 text-[12px] leading-[1.5] text-foreground/80",children:[u?/* @__PURE__ */t(se,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground/70"}):/* @__PURE__ */t("span",{className:G("inline-block h-1.5 w-1.5 shrink-0 rounded-full",g)}),/* @__PURE__ */t("span",{className:"truncate",children:u?Aa(e):l})]}):null]}),/* @__PURE__ */t("div",{className:"absolute right-3 top-3",children:s?/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground/70"}):a?/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground/70"}):/* @__PURE__ */n($e,{children:[/* @__PURE__ */t(je,{asChild:!0,children:/* @__PURE__ */t("button",{type:"button",onClick:f=>f.stopPropagation(),className:"inline-flex h-6 w-6 items-center justify-center rounded-control text-muted-foreground/70 opacity-60 hover:bg-muted hover:text-foreground/80 focus-visible:opacity-100 group-hover:opacity-100","aria-label":`${m.noun==="report"?"Report":"Briefing"} actions`,children:/* @__PURE__ */t(ra,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(qe,{align:"end",className:"w-44",children:[/* @__PURE__ */n(ee,{onClick:r,children:[/* @__PURE__ */t(Bt,{className:"h-3.5 w-3.5"}),"Edit ",m.noun]}),/* @__PURE__ */n(ee,{onClick:f=>{f.preventDefault(),d();},children:[/* @__PURE__ */t(Bn,{className:"h-3.5 w-3.5"}),"Run now"]}),e.scheduleExpr?/* @__PURE__ */t(ee,{onClick:f=>{f.preventDefault(),o();},children:h?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(_n,{className:"h-3.5 w-3.5"}),"Resume"]}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(On,{className:"h-3.5 w-3.5"}),"Pause"]})}):null,/* @__PURE__ */t(et,{}),/* @__PURE__ */n(ee,{onClick:f=>{f.preventDefault(),i();},className:"text-destructive focus:bg-destructive/10 focus:text-destructive",children:[/* @__PURE__ */t(Je,{className:"h-3.5 w-3.5"}),"Delete ",m.noun]})]})]})})]});}function Xs(e){return(e==null?void 0:e.trim())||"This dashboard";}function Zs(e){return e==="This dashboard"?"Watch this dashboard":`Watch ${e}`;}function Js(e,a,s){return a!=="dashboard"?e:e.filter(r=>r.source.type==="dashboard"&&r.source.dashboardId===s);}async function ei(e){const s=[];let r=1,d=0,o=Number.POSITIVE_INFINITY;for(;d<o;){const i=await e.apiClient.listBriefings(e.apiServiceUrl,e.token,{scope:"organization",page:r,pageSize:100});if(s.push(...i.briefings),d+=i.briefings.length,o=i.total,i.briefings.length===0||d>=o)break;r+=1;}return s;}const ti={listBriefings:Wn,getBriefing:qn,pauseBriefing:jn,resumeBriefing:$n,deleteBriefing:Un,runBriefingNow:Mn};function ji(e){return/* @__PURE__ */t(Pn,{authToken:e.token?{accessToken:e.token}:void 0,children:/* @__PURE__ */t(zn,{children:/* @__PURE__ */t(ai,{...e})})});}function ai({dashboardId:e,dashboardTitle:a,apiServiceUrl:s,token:r,disabled:d,className:o,manageBriefingsHref:i,open:h,onOpenChange:u,hideTrigger:l=!1,workflowIntent:c,openRun:p,client:m}){const{authToken:g,tokenProps:f}=it(),N=Rn(),w=!c||N.canCreate&&(c==="scheduled_report"||N.analyticalBriefingsEnabled),[T,L]=F(!1),B=h??T,D=S=>{h===void 0&&L(S),u==null||u(S);},[P,k]=F(c?"author":"list"),[v,b]=F(c??"analytical_briefing"),[_,A]=F("dashboard"),[H,V]=F([]),[M,X]=F(null),Y=c&&!w&&!M?"list":P,[he,te]=F(!1),[me,E]=F(null),[ne,Q]=F(null),[z,J]=F(null),[de,ce]=F(null),ve=Ze(null),x=Ze(B);Ye(()=>{const S=B&&!x.current;x.current=B,!(!S||!c)&&(X(null),A("dashboard"),b(c),k("author"),ce(null));},[B,c]);const O=St(),$=s??(f==null?void 0:f.apiServiceUrl),W=r??(g==null?void 0:g.accessToken),re=K(()=>({...ti,...m}),[m]),[_e,lt]=F(null);Ye(()=>{if(!p||!$||!W)return;let S=!0;return re.getBriefing($,W,p.briefingId).then(({briefing:q})=>{S&&(X(q),lt(p),k("author"));},q=>{S&&U.error(q instanceof Error?q.message:"Could not open the run.");}),()=>{S=!1;};},[p,$,W,re]);const Fe=Xs(a),We=K(()=>{const S=Js(H,_,e);if(!c)return S;const q=c==="scheduled_report"?"report":"briefing";return S.filter(Ke=>pe(Ke).noun===q);},[e,H,_,c]),dt=K(()=>_==="dashboard"?{source:{type:"dashboard",dashboardId:e},label:Fe,detail:Zs(Fe)}:{source:{type:"project"},label:"This project",detail:"Use any data in this project."},[e,Fe,_]),Oe=!!($&&W),Pe=_r({canCreate:N.canCreate,analyticalBriefingsEnabled:N.analyticalBriefingsEnabled,scheduledReportAvailable:_==="dashboard"}),ie=oe(async()=>{if(!(!$||!W)){te(!0),ce(null);try{V(await ei({apiClient:re,apiServiceUrl:$,token:W}));}catch(S){ce(S instanceof Error?S.message:"Could not load briefings.");}finally{te(!1);}}},[re,$,W]);Ye(()=>{!B||Y!=="list"||!Oe||ie();},[Oe,Y,ie,B]);const ze=()=>{X(null),A("dashboard"),k("list"),D(!0);},y=S=>{X(null),b(S),k("author");},j=async S=>{if(!(!$||!W)){E(S),ce(null);try{const q=await re.getBriefing($,W,S);X(q.briefing),k("author");}catch(q){ce(q instanceof Error?q.message:"Could not open briefing.");}finally{E(null);}}},Z=async S=>{if(!(!$||!W)){Q(S.id);try{const q=await re.runBriefingNow($,W,S.id,{requestId:ni()});O.track({kind:"briefing",id:q.run.id,title:S.name,briefingId:S.id}),ie();}catch(q){U.error(q instanceof Error?q.message:"Could not start the run.");}finally{Q(null);}}},ue=async S=>{if(!$||!W)return;const{noun:q}=pe(S),Ke=q==="report"?"Report":"Briefing";Q(S.id);try{const Qe=S.status==="PAUSED"?await re.resumeBriefing($,W,S.id):await re.pauseBriefing($,W,S.id);U.success(Qe.briefing.status==="PAUSED"?`${Ke} paused`:`${Ke} resumed`),ie();}catch(Qe){U.error(Qe instanceof Error?Qe.message:`Could not update the ${q} status.`);}finally{Q(null);}},ye=async()=>{if(!z||!$||!W)return;const S=z;Q(S.id);try{await re.deleteBriefing($,W,S.id);const{noun:q}=pe(S);U.success(`${q==="report"?"Report":"Briefing"} deleted`),J(null),ie();}catch(q){U.error(q instanceof Error?q.message:"Could not delete the briefing.");}finally{Q(null);}},Fa=We.length;return N.surfaceVisible?/* @__PURE__ */n(Ja,{open:B,onOpenChange:D,children:[l?null:/* @__PURE__ */t(Rs,{disabled:d||!Oe,briefingCount:Fa,className:o,onClick:ze}),/* @__PURE__ */n(en,{ref:ve,side:"right",hideClose:!0,className:"flex h-full w-full flex-col overflow-hidden p-0 outline-none sm:max-w-[560px]",onOpenAutoFocus:S=>{var q;S.preventDefault(),(q=ve.current)==null||q.focus({preventScroll:!0});},children:[/* @__PURE__ */n(tn,{className:"sr-only",children:[/* @__PURE__ */t(an,{children:"Reports & briefings"}),/* @__PURE__ */t(nn,{children:"Manage reports and briefings for this dashboard."})]}),c?/* @__PURE__ */n("div",{className:"flex shrink-0 items-start justify-between gap-3 border-b border-border pl-4 pr-3 pt-2",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-5",role:"tablist","aria-label":c==="scheduled_report"?"Email report workflow":"Analytical briefing workflow",children:[/* @__PURE__ */t("button",{type:"button",role:"tab","aria-selected":Y==="author",disabled:!w,className:G("-mb-px border-b-2 px-0.5 pb-2 text-[12px] transition-colors",Y==="author"?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground",!w&&"cursor-not-allowed opacity-50"),onClick:()=>{w&&(X(null),b(c),A("dashboard"),k("author"));},children:M?`Edit ${pe(M).noun}`:c==="scheduled_report"?"Schedule report":"Create briefing"}),/* @__PURE__ */t("button",{type:"button",role:"tab","aria-selected":Y==="list",className:G("-mb-px border-b-2 px-0.5 pb-2 text-[12px] transition-colors",Y==="list"?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),onClick:()=>k("list"),children:c==="scheduled_report"?"Manage reports":"Manage briefings"})]}),/* @__PURE__ */t("button",{type:"button",onClick:()=>D(!1),className:"rounded-control p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":c==="scheduled_report"?"Close email report workflow":"Close analytical briefing workflow",children:/* @__PURE__ */t(Ue,{className:"h-3.5 w-3.5"})})]}):null,Y==="list"?/* @__PURE__ */t(Qs,{briefings:We,dashboardLabel:Fe,sourceView:_,error:de,loading:he,onSourceViewChange:A,onClose:()=>D(!1),onEdit:S=>{j(S);},onNew:y,canCreate:!c&&Pe.length>0,canCreateScheduledReport:Pe.includes("scheduled_report"),analyticalBriefingsEnabled:Pe.includes("analytical_briefing"),onRunNow:S=>{Z(S);},onTogglePause:S=>{ue(S);},onDelete:S=>J(S),selectingId:me,busyId:ne,manageBriefingsHref:i,contentKind:c==="scheduled_report"?"reports":c==="analytical_briefing"?"briefings":void 0,hideHeader:!!c}):/* @__PURE__ */t(Kn,{apiServiceUrl:$,token:W,briefing:M,initialRunId:_e&&(M==null?void 0:M.id)===_e.briefingId?_e.runId:void 0,intent:v,sourceContext:M?void 0:dt,title:M?`Edit ${pe(M).noun}`:v==="scheduled_report"?"Schedule report":"Create analytical briefing",hideHeader:!!c,className:"h-full min-h-0 max-w-none border-0 shadow-none",onBack:c?void 0:()=>k("list"),onCancel:()=>D(!1),onDeleted:()=>{const S=M?pe(M).noun:"briefing";U.success(`${S==="report"?"Report":"Briefing"} deleted`),X(null),k("list"),ie();},onRunStarted:()=>{},onSaved:S=>{X(S),ie();},onMinimizeRun:()=>{D(!1);}})]}),/* @__PURE__ */t(Dt,{open:!!z,onOpenChange:S=>{S||J(null);},children:/* @__PURE__ */n(At,{children:[/* @__PURE__ */n(Ft,{children:[/* @__PURE__ */n(Et,{children:["Delete"," ",z?pe(z).noun:"briefing","?"]}),/* @__PURE__ */n(It,{children:["This permanently deletes ",/* @__PURE__ */t("strong",{children:z==null?void 0:z.name}),". Recipients will stop receiving it."]})]}),/* @__PURE__ */n(Tt,{children:[/* @__PURE__ */t(Lt,{children:"Cancel"}),/* @__PURE__ */n(fa,{className:"bg-destructive/90 hover:bg-destructive",onClick:ye,children:["Delete"," ",z?pe(z).noun:"briefing"]})]})]})})]}):null;}function ni(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`briefing-run-now-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;}export{Ti as A,Bi as D,Vi as S,Oi as U,Fi as V,Rs as W,Ii as a,Li as b,_i as c,zi as d,as as e,rs as f,ds as g,Ri as h,Pi as i,Ui as j,Mi as k,$i as l,ji as m,Ca as n,Ei as u};