react-semaphor 0.1.610 → 0.1.611

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 (108) hide show
  1. package/dist/.gate-build-input +1 -0
  2. package/dist/analytics-protocol/index.js +1 -1
  3. package/dist/assistant-context/index.js +1 -1
  4. package/dist/brand-studio/index.js +2 -2
  5. package/dist/briefings/index.js +1 -1
  6. package/dist/chunks/appearance-provider-nxBjHmOo.js +708 -0
  7. package/dist/chunks/{assistant-chat-BqdXuU42.js → assistant-chat-DGaSGyx_.js} +13 -13
  8. package/dist/chunks/{attachment-filter-line-ClTS4GvQ.js → attachment-filter-line-CVkfzZF9.js} +1 -1
  9. package/dist/chunks/{bookmark-impact-BAYpeKb-.js → bookmark-impact-DnhE262D.js} +1 -1
  10. package/dist/chunks/{bookmark-state-B3lDH0E_.js → bookmark-state-CrJDZi3y.js} +1 -1
  11. package/dist/chunks/{brand-9AazkIHH.js → brand-BjIkbHgw.js} +1 -1
  12. package/dist/chunks/{card-filter-builder-CpSD-8yA.js → card-filter-builder-9xCSYFNv.js} +2 -2
  13. package/dist/chunks/{check-input-D36evEN2.js → check-input-DmKJoLY-.js} +1 -1
  14. package/dist/chunks/{comparison-window-caption-WzGsqv4n.js → comparison-window-caption-DImvKgCt.js} +1 -1
  15. package/dist/chunks/currency-presentation-binding-DCHJ2sRD.js +1 -0
  16. package/dist/chunks/{custom-visual-inputs-obG5lDlW.js → custom-visual-inputs-C2BRX8l_.js} +1 -1
  17. package/dist/chunks/{custom-visual-write-fOcTV3dl.js → custom-visual-write-CYA-Y9YF.js} +1 -1
  18. package/dist/chunks/{dashboard-BVYXrYaU.js → dashboard-DEsWObFS.js} +1 -1
  19. package/dist/chunks/{dashboard-briefing-launcher-CVjONGRj.js → dashboard-briefing-launcher-PzvxJm1T.js} +7 -7
  20. package/dist/chunks/{dashboard-controls-Cca_ra4d.js → dashboard-controls-DPVMjbpG.js} +2 -2
  21. package/dist/chunks/{dashboard-json-CUHyo-if.js → dashboard-json-CWJ6drfv.js} +1 -1
  22. package/dist/chunks/{dashboard-temporal-snapshot-DyRl61Yv.js → dashboard-temporal-snapshot-C2y8qWoK.js} +1 -1
  23. package/dist/chunks/dates-ByeRG2Tz.js +1 -0
  24. package/dist/chunks/edit-dashboard-visual-BxwhXWe2.js +103 -0
  25. package/dist/chunks/{filter-line-W-qQAjke.js → filter-line-BpaHAj8x.js} +1 -1
  26. package/dist/chunks/filter-reach-preview-C9WDhZaV.js +1 -0
  27. package/dist/chunks/{filter-value-text-DQwYZHz0.js → filter-value-text-vD4CXg9H.js} +1 -1
  28. package/dist/chunks/{kpi-trend-rule-DSVBCJDV.js → kpi-trend-rule-H3cLKxwe.js} +1 -1
  29. package/dist/chunks/matrix-analytical-definition-B6Auo_Up.js +1 -0
  30. package/dist/chunks/{matrix-member-presentation-Chz6uGYz.js → matrix-member-presentation-B6wzUGA9.js} +1 -1
  31. package/dist/chunks/matrix-operation-contract-1dtkh4UB.js +1 -0
  32. package/dist/chunks/{metric-formatting-BhmZiuD8.js → metric-formatting-BF1b9EEC.js} +1 -1
  33. package/dist/chunks/numeric-range-options-B_EcRH8C.js +1 -0
  34. package/dist/chunks/{palette-Bg_6xero.js → palette-DLYro9VS.js} +1 -1
  35. package/dist/chunks/pivot-result-contract-expectations-Bl55bAD9.js +1 -0
  36. package/dist/chunks/{pivot-result-identity-DRhVJMsF.js → pivot-result-identity-CAP9xTVF.js} +1 -1
  37. package/dist/chunks/{raw-temporal-value-B4Md6Xfb.js → raw-temporal-value-DqmEQqi9.js} +1 -1
  38. package/dist/chunks/report-preferences-dialog-CV0NMmo0.js +1 -0
  39. package/dist/chunks/report-runtime-context-DUyoI64N.js +1 -0
  40. package/dist/chunks/resolve-dashboard-input-context-D3lfJtPf.js +8 -0
  41. package/dist/chunks/{sandbox-host-BnadJPB9.js → sandbox-host-DTsb-07w.js} +1 -1
  42. package/dist/chunks/saved-dashboard-context-pT-jLe_M.js +1 -0
  43. package/dist/chunks/{selection-filter-compiler-BxtEEB6Z.js → selection-filter-compiler-D2O1G8aM.js} +1 -1
  44. package/dist/chunks/semaphor-ready-indicator-X4VBj9J1.js +542 -0
  45. package/dist/chunks/{slider-DD5nxK4N.js → slider-BuDy7URL.js} +1 -1
  46. package/dist/chunks/stored-dashboard-CtbTHA6d.js +1 -0
  47. package/dist/chunks/table-cell-text-CcdZI7W5.js +1 -0
  48. package/dist/chunks/{table-export-sheet-CthBUHu4.js → table-export-sheet-CR05ORx7.js} +1 -1
  49. package/dist/chunks/{token-types-BM0mpZce.js → token-types-DapH4m_I.js} +1 -1
  50. package/dist/chunks/validators-D6oX9c_4.js +1 -0
  51. package/dist/chunks/{variable-draft-C8xXjy0M.js → variable-draft-BugdJvFc.js} +1 -1
  52. package/dist/chunks/work-days-BbCJDTJK.js +1 -0
  53. package/dist/dashboard/index.js +1 -1
  54. package/dist/dashboard-authoring/index.js +1 -1
  55. package/dist/extensions/index.js +1 -1
  56. package/dist/format-utils/index.js +1 -1
  57. package/dist/index.js +1 -1
  58. package/dist/report-runtime-context/index.js +1 -1
  59. package/dist/style.css +1 -1
  60. package/dist/surfboard/index.js +1 -1
  61. package/dist/types/components/surfboard/index.d.ts +1 -0
  62. package/dist/types/components/surfboard/preferences/work-day-toggles.d.ts +16 -0
  63. package/dist/types/components/ui-custom/date-range-presets.d.ts +4 -1
  64. package/dist/types/index.js +1 -1
  65. package/dist/types/lib/stores/dashboard-store.d.ts +2 -0
  66. package/dist/types/shared/analytics-protocol/comparison-choices.d.ts +7 -0
  67. package/dist/types/shared/analytics-protocol/comparison-placement.d.ts +2 -0
  68. package/dist/types/shared/analytics-protocol/relative-date/index.d.ts +1 -1
  69. package/dist/types/shared/analytics-protocol/relative-date/presets.d.ts +1 -1
  70. package/dist/types/shared/analytics-protocol/relative-date/resolve.d.ts +4 -2
  71. package/dist/types/shared/analytics-protocol/relative-date/schemas.d.ts +7 -0
  72. package/dist/types/shared/analytics-protocol/relative-date/traits.d.ts +2 -1
  73. package/dist/types/shared/analytics-protocol/relative-date/window.d.ts +9 -1
  74. package/dist/types/shared/dashboard-authoring/card-data-source/data-source-selection.d.ts +11 -0
  75. package/dist/types/shared/dashboard-authoring/card-data-source/index.d.ts +1 -0
  76. package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +16 -0
  77. package/dist/types/shared/dashboard-authoring/filter-model/filter-values.d.ts +10 -0
  78. package/dist/types/shared/dashboard-authoring/frame-cards.d.ts +29 -0
  79. package/dist/types/shared/dashboard-authoring/operations/card-operations.d.ts +13 -10
  80. package/dist/types/shared/dashboard-authoring/operations/operation-sentences.d.ts +18 -0
  81. package/dist/types/shared/dashboard-authoring/operations/operation-types.d.ts +16 -1
  82. package/dist/types/shared/dashboard-authoring/outline/outline-dashboard.d.ts +12 -1
  83. package/dist/types/shared/dashboard-authoring/table-sheet-shape.d.ts +53 -3
  84. package/dist/types/shared/dashboard-viewer/table-column-move.d.ts +7 -0
  85. package/dist/types/shared/extensions/saved-refs.d.ts +1 -15
  86. package/dist/types/shared/report-runtime-context/index.d.ts +1 -0
  87. package/dist/types/shared/report-runtime-context/report-runtime-context.d.ts +22 -1
  88. package/dist/types/shared/report-runtime-context/work-days.d.ts +31 -0
  89. package/dist/types/shared/temporal/calendar-periods.d.ts +1 -1
  90. package/package.json +1 -1
  91. package/dist/chunks/appearance-provider-CxsEFvNA.js +0 -703
  92. package/dist/chunks/currency-presentation-binding-CUh82q48.js +0 -1
  93. package/dist/chunks/dates-Cym78NYg.js +0 -1
  94. package/dist/chunks/edit-dashboard-visual-DRLguKmV.js +0 -103
  95. package/dist/chunks/filter-reach-preview-IFwTq7Hh.js +0 -1
  96. package/dist/chunks/layout-grid-Ctnv2-au.js +0 -6
  97. package/dist/chunks/matrix-analytical-definition-jn075ooo.js +0 -1
  98. package/dist/chunks/matrix-operation-contract-DceN49RX.js +0 -1
  99. package/dist/chunks/numeric-range-options-Drc1EZ6H.js +0 -1
  100. package/dist/chunks/pivot-result-contract-expectations-D_ane7I2.js +0 -1
  101. package/dist/chunks/report-preferences-dialog-DQNwImoN.js +0 -1
  102. package/dist/chunks/report-runtime-context-CkxgMKr6.js +0 -1
  103. package/dist/chunks/resolve-dashboard-input-context-Djm2WgEF.js +0 -8
  104. package/dist/chunks/saved-dashboard-context-EwdvXIE6.js +0 -1
  105. package/dist/chunks/semaphor-ready-indicator-BJR23T8j.js +0 -532
  106. package/dist/chunks/stored-dashboard--6xPxYpX.js +0 -1
  107. package/dist/chunks/table-cell-text-C5J5E_Am.js +0 -1
  108. package/dist/chunks/validators-U8IL8djK.js +0 -1
@@ -1,4 +1,4 @@
1
- import{c as pt,u as Bt,N as pe,av as Ut,aw as Wt,ax as Kt,ay as Qt,az as Yt,aA as Ht,aB as Xt,B,aC as Jt,d as ge,ak as Xe,an as mt,aD as ae,aa as be,ac as le,ad as ie,ae as oe,af as de,ag as ee,ai as Ve,aE as Zt,aF as Pt,aG as er,aH as ft,aI as Je,aJ as tr,aK as rr,aL as ce,P as ht,b as gt,X as bt,e as xt,aM as vt,aN as ar,aO as nr,aP as sr,aQ as lr,aR as ir,aS as _e,aT as se,aU as Re,aV as ze,ao as or,aj as dr,aW as xe,aX as ve,aY as yt,aZ as Nt,a_ as cr}from"./appearance-provider-CxsEFvNA.js";import{jsx as e,jsxs as c,Fragment as me}from"react/jsx-runtime";import{n as U,b1 as ur,b2 as fe,b3 as Ze,b4 as Pe,b5 as Oe,b6 as Ae,b7 as pr,b8 as mr,b9 as et,ba as fr,bb as hr,bc as he,bd as gr,be as tt,bf as Ct,bg as wt,bh as St,bi as kt,bj as br,bk as xr,bl as rt,bm as vr,bn as at,bo as yr,bp as Nr,bq as Cr,br as wr,bs as Ee,e as ye,bt as nt,bu as Sr,bv as $e,bw as kr,bx as Dr,by as Tr,bz as Lr,bA as Or}from"./resolve-dashboard-input-context-Djm2WgEF.js";import{k as Dt,r as Ar,aE as Tt,aF as Lt}from"./validators-U8IL8djK.js";import{a as Ot}from"./matrix-operation-contract-DceN49RX.js";import"./analytics-base-schemas-DMFrDqn_.js";import"../value-format-preferences/index.js";import{u as Er,ak as st,al as $r,am as At,an as Et,ao as Ir,ap as Fr,aq as Vr,ar as _r,as as Rr,at as lt,au as Ge,av as zr,aw as Ne,ax as Ce,ay as $t}from"./semaphor-ready-indicator-BJR23T8j.js";import*as we from"react";import{useMemo as P,useState as te,useRef as Ie,useCallback as Z,useEffect as Me,Fragment as Gr}from"react";import{r as Mr,m as qr}from"./raw-temporal-value-B4Md6Xfb.js";/**
1
+ import{c as pt,u as Bt,N as pe,aw as Ut,ax as Wt,ay as Kt,az as Qt,aA as Yt,aB as Ht,aC as Xt,B,aD as Jt,d as ge,ak as Xe,an as mt,aE as ae,aa as be,ac as le,ad as ie,ae as oe,af as de,ag as ee,ai as Ve,aF as Zt,aG as Pt,aH as er,aI as ft,aJ as Je,aK as tr,aL as rr,aM as ce,P as ht,b as gt,X as bt,e as xt,aN as vt,aO as ar,aP as nr,aQ as sr,aR as lr,aS as ir,aT as _e,aU as se,aV as Re,aW as ze,ao as or,aj as dr,aX as xe,aY as ve,aZ as yt,a_ as Nt,a$ as cr}from"./appearance-provider-nxBjHmOo.js";import{jsx as e,jsxs as c,Fragment as me}from"react/jsx-runtime";import{n as U,b6 as ur,b7 as fe,b8 as Ze,b9 as Pe,ba as Oe,bb as Ae,bc as pr,bd as mr,be as et,bf as fr,bg as hr,bh as he,bi as gr,bj as tt,bk as Ct,bl as wt,bm as St,bn as kt,bo as br,bp as xr,bq as rt,br as vr,bs as at,bt as yr,bu as Nr,bv as Cr,bw as wr,bx as Ee,e as ye,by as nt,bz as Sr,bA as $e,bB as kr,bC as Dr,bD as Tr,bE as Lr,bF as Or}from"./resolve-dashboard-input-context-D3lfJtPf.js";import{k as Dt,r as Ar,aE as Tt,aF as Lt}from"./validators-D6oX9c_4.js";import{a as Ot}from"./matrix-operation-contract-1dtkh4UB.js";import"./analytics-base-schemas-DMFrDqn_.js";import"../value-format-preferences/index.js";import{u as Er,ak as st,al as $r,am as At,an as Et,ao as Fr,ap as Ir,aq as Vr,ar as _r,as as Rr,at as lt,au as Ge,av as zr,aw as Ne,ax as Ce,ay as $t}from"./semaphor-ready-indicator-X4VBj9J1.js";import*as we from"react";import{useMemo as P,useState as te,useRef as Fe,useCallback as Z,useEffect as Me,Fragment as Gr}from"react";import{r as Mr,m as qr}from"./raw-temporal-value-DqmEQqi9.js";/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -8,4 +8,4 @@ import{c as pt,u as Bt,N as pe,av as Ut,aw as Wt,ax as Kt,ay as Qt,az as Yt,aA a
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 jr=pt("Library",[["path",{d:"m16 6 4 14",key:"ji33uf"}],["path",{d:"M12 6v14",key:"1n7gus"}],["path",{d:"M8 8v12",key:"1gg7y9"}],["path",{d:"M4 4v16",key:"6qkkli"}]]);function va({type:t,isLinked:a,className:s,showLabel:i=!1,showLocal:$=!1}){const h=Bt(O=>O.selectedFrameId),k=Er(O=>O.selectedVisual),b=pe(O=>O.frame);let m;if(t)m=t;else if(a!==void 0)m=a?"linked":"library";else if(!!!(b!=null&&b.visualId||k!=null&&k.id)&&h)m="local";else if(k&&!h)m="library";else if(b!=null&&b.visualId&&h)m="linked";else if(k!=null&&k.id&&h)m="library";else return null;if(m==="local"&&!$)return null;const x={local:"border-slate-200/70 bg-slate-50/80 text-slate-700 shadow-sm hover:bg-slate-100/80 dark:border-slate-700 dark:bg-slate-900/70 dark:text-slate-200 dark:hover:bg-slate-800/80",linked:"border-purple-200/70 bg-gradient-to-r from-purple-50/50 to-purple-100/30 text-purple-900 shadow-sm hover:from-purple-100/60 hover:to-purple-100/50 hover:shadow-md dark:border-purple-800/50 dark:from-purple-950/40 dark:to-purple-900/30 dark:text-purple-100 dark:hover:from-purple-950/60 dark:hover:to-purple-900/50",library:"border-blue-200/70 bg-gradient-to-r from-blue-50/50 to-blue-100/30 text-blue-900 shadow-sm hover:from-blue-100/60 hover:to-blue-100/50 hover:shadow-md dark:border-blue-800/50 dark:from-blue-950/40 dark:to-blue-900/30 dark:text-blue-100 dark:hover:from-blue-950/60 dark:hover:to-blue-900/50"},L={local:"Local to this dashboard: Changes made here only affect this dashboard copy.",linked:"Linked to library: Changes made here update the library visual and all linked instances.",library:"Library visual: Share and reuse this visual across multiple dashboards."},N={local:"border-slate-200 bg-slate-50 text-slate-900 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100",linked:"border-purple-200 bg-purple-50 text-purple-900 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-100",library:"border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-100"},I={local:"fill-slate-50 dark:fill-slate-900",linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},S={local:/* @__PURE__ */e("span",{className:"h-2 w-2 rounded-full bg-current/70"}),linked:/* @__PURE__ */e(Xt,{className:"h-3.5 w-3.5"}),library:/* @__PURE__ */e(jr,{className:"h-3.5 w-3.5"})},y={local:"Local",linked:"Linked",library:"Library"};return/* @__PURE__ */e(Ut,{children:/* @__PURE__ */c(Wt,{delayDuration:300,children:[/* @__PURE__ */e(Kt,{asChild:!0,children:/* @__PURE__ */c(Qt,{variant:"outline",className:U("cursor-help select-none transition-all",x[m],s),children:[S[m],i&&/* @__PURE__ */e("span",{className:"ml-1 text-xs font-medium leading-none",children:y[m]})]})}),/* @__PURE__ */c(Yt,{side:"bottom",className:U("max-w-xs",N[m]),children:[/* @__PURE__ */e(Ht,{className:I[m]}),/* @__PURE__ */e("p",{children:L[m]})]})]})});}function It(t){const{control:a,onChange:s}=t;return/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(ae,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),/* @__PURE__ */e(be,{size:"xs",value:a.label,placeholder:"Control label",onChange:i=>s(i.target.value)})]});}function Br(t){const{currentStep:a,labels:s}=t;return/* @__PURE__ */e("div",{className:"sticky top-0 z-10 -mx-1 border-b border-border/60 bg-background/95 px-1 pb-2.5 pt-1 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:/* @__PURE__ */e("div",{className:"flex flex-wrap items-center gap-2 sm:gap-2.5",children:s.map((i,$)=>{const h=$+1,k=h===a,b=h<a;return/* @__PURE__ */c(Gr,{children:[/* @__PURE__ */c("div",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */e("span",{className:U("flex h-5 w-5 items-center justify-center rounded-full border text-[10px] font-medium tabular-nums",k?"border-foreground bg-foreground text-background":b?"border-foreground/30 bg-foreground/10 text-foreground":"border-border/60 bg-background text-muted-foreground"),children:h}),/* @__PURE__ */e("span",{className:U("text-[12px]",k?"font-medium text-foreground":"text-muted-foreground"),children:i})]}),$<s.length-1?/* @__PURE__ */e("span",{className:"h-px w-4 bg-border/60 sm:w-6","aria-hidden":"true"}):null]},i);})})});}function Se(t){const{secondary:a,tertiary:s,primary:i}=t;return/* @__PURE__ */c("div",{className:"sticky bottom-0 z-10 -mx-1 flex justify-end gap-2 border-t bg-background/95 px-1 pb-1 pt-3 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:[a,s,i]});}function Ur(t){const{control:a,scope:s,detail:i}=t;return/* @__PURE__ */c("div",{className:"flex items-start gap-2.5 rounded-control border border-border/60 bg-muted/30 px-3 py-2.5",children:[/* @__PURE__ */e(Zt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground"}),/* @__PURE__ */c("div",{className:"min-w-0 space-y-0.5",children:[/* @__PURE__ */e("div",{className:"text-[13px] font-medium text-foreground",children:a.label}),/* @__PURE__ */c("div",{className:"text-[12px] text-muted-foreground",children:[Ct(a.type).label," ·"," ",St(a)," ·"," ",wt(s,a.placement)]}),i?/* @__PURE__ */e("div",{className:"text-[12px] text-muted-foreground",children:i}):null]})]});}function it(t){const{control:a,defaultValue:s,availableFieldChoices:i,availableMetricChoices:$,previewControlDefinitions:h,previewControlValues:k,onControlChange:b,onLabelChange:m,onDefaultValueChange:x,onBack:L,onNext:N,nextDisabled:I}=t;return/* @__PURE__ */c("div",{className:"space-y-3",children:[/* @__PURE__ */e(It,{control:a,onChange:m}),/* @__PURE__ */e(At,{control:a,availableFieldChoices:i,availableMetricChoices:$,previewControlDefinitions:h,previewControlValues:k,controlLifecycle:"create",onChange:b}),/* @__PURE__ */e(Et,{control:a,value:s,onChange:x,allowNoDefault:!0,allowCardDefault:!0,hint:"This is the value viewers will see first.",previewControlDefinitions:h,previewControlValues:k}),/* @__PURE__ */e(Se,{secondary:/* @__PURE__ */e(B,{type:"button",variant:"outline",size:"xs",onClick:L,children:"Back"}),primary:/* @__PURE__ */e(B,{type:"button",size:"xs",onClick:N,disabled:I,children:"Next"})})]});}const Wr=/* @__PURE__ */new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]);function ot(t){const{text:a,ariaLabel:s}=t,[i,$]=te(!1);return/* @__PURE__ */c("button",{type:"button","aria-label":s,onClick:async()=>{try{await navigator.clipboard.writeText(a),$(!0),setTimeout(()=>$(!1),1200);}catch(h){console.error("Failed to copy",h);}},className:"group flex w-full items-center justify-between gap-2 rounded-control bg-muted/40 px-2 py-1 text-left transition-colors hover:bg-muted/60 focus-visible:bg-muted/60 focus-visible:outline-none",children:[/* @__PURE__ */e("code",{className:"min-w-0 truncate font-mono text-[12px] text-foreground",children:a}),/* @__PURE__ */e("span",{className:"shrink-0 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:i?"Copied":"Click to copy"})]});}function dt(t){const{control:a,scope:s,createdReference:i,explorerContent:$,sqlDescription:h,summaryDetail:k,onBack:b,onCancel:m,onDone:x}=t,L=Wr.has(a.type),N=i.match(/\[\[param\.(.+?)\]\]/),I=N?`{{ param('${N[1]}') }}`:"";return/* @__PURE__ */c("div",{className:"space-y-4",children:[/* @__PURE__ */e(Ur,{control:a,scope:s,detail:k}),/* @__PURE__ */c("div",{className:"space-y-2",children:[/* @__PURE__ */e("p",{className:"text-[13px] font-medium text-foreground",children:"How cards use this control"}),/* @__PURE__ */c("div",{className:"divide-y divide-border/60 overflow-hidden rounded-control border border-border/60",children:[L?/* @__PURE__ */c("div",{className:"space-y-1 px-3 py-2.5",children:[/* @__PURE__ */e("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Explorer cards"}),/* @__PURE__ */e("div",{className:"text-[12px] text-muted-foreground",children:$})]}):null,/* @__PURE__ */c("div",{className:"space-y-1.5 px-3 py-2.5",children:[/* @__PURE__ */e("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"SQL cards"}),/* @__PURE__ */e(ot,{text:i,ariaLabel:"Copy SQL control reference"}),I?/* @__PURE__ */e(ot,{text:I,ariaLabel:"Copy Jinja control reference"}):null,/* @__PURE__ */c("p",{className:"text-[12px] text-muted-foreground",children:[h," ",/* @__PURE__ */e("a",{href:"https://docs.semaphor.cloud/docs/concepts/template-expressions",target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:"Template expressions docs"}),"."]})]})]})]}),/* @__PURE__ */e(Se,{secondary:/* @__PURE__ */e(B,{type:"button",variant:"outline",size:"xs",onClick:b,children:"Back"}),tertiary:/* @__PURE__ */e(B,{type:"button",variant:"outline",size:"xs",onClick:m,children:"Cancel"}),primary:/* @__PURE__ */e(B,{type:"button",size:"xs",onClick:x,children:"Done"})})]});}function Kr(t){const a=fe(t.scope,t.existingControls,t.reservedIds),s=t.type===a.type?{...a,label:Ee[t.type]}:{...kt({controls:[{...a,label:Ee[t.type]}],controlId:a.id,nextType:t.type}).controls[0],label:Ee[t.type]};return{step:2,control:s,defaultValue:he(s,void 0)};}function ya({scope:t,controls:a,reservedControlIds:s,defaultValues:i,onChange:$,emptyMessage:h,initialCreateFlow:k=!1,usageByControlId:b,availableFieldChoices:m,availableMetricChoices:x,structuralParticipants:L,structuralParticipantIdsByControlId:N,card:I,allowedControlTypes:S,onCreateFlowActiveChange:y,onCreateFlowComplete:O}){const z=P(()=>new Set(s||[]),[s]),F=br(t),X=ur(t),[D,T]=te(null),[Q,H]=te(null),[n,g]=te(()=>k?{step:1,control:fe(t,a,Array.from(z))}:null),C=Ie({}),f=Ie(void 0),d=Ie(k),l=P(()=>{const r=Ze({scope:t,card:I});if(!S)return r;const u=new Set(S);return r.filter(o=>u.has(o.value));},[S,I,t]),V=Z(r=>{const u=Ze({scope:t,card:I,includeType:S?void 0:r});if(!S)return u;const o=new Set(S);return u.filter(v=>o.has(v.value));},[S,I,t]),p=Z(r=>t==="dashboard"&&(r==="field_selector"||r==="metric_selector"),[t]),K=P(()=>n?Pe(L||[],n.control.type):[],[n,L]),A=P(()=>{if(!n)return{fields:m||[],metrics:x||[]};if(!p(n.control.type))return{fields:m||[],metrics:x||[]};const r=n.selectedCardIds||[],u=Oe({controlType:n.control.type,participants:L||[],selectedCardIds:r});return{fields:n.control.type==="field_selector"?u.choices.map(o=>({option:o,target:u.fieldTargetMap[o.value]})):[],metrics:n.control.type==="metric_selector"?u.choices.map(o=>({option:o,target:u.metricTargetMap[o.value]})):[]};},[m,x,n,p,L]);Me(()=>{y==null||y(!!n);},[n,y]),Me(()=>{const r=k&&!d.current;d.current=k,r&&(g({step:1,control:fe(t,a,Array.from(z))}),H(null),T(null));},[a,k,z,t]);const R=r=>{if(!p(r.type))return{fields:m||[],metrics:x||[]};const u=(N==null?void 0:N[r.id])||[];if(u.length===0)return{fields:m||[],metrics:x||[]};const o=Oe({controlType:r.type,participants:L||[],selectedCardIds:u});return{fields:r.type==="field_selector"?o.choices.map(v=>({option:v,target:o.fieldTargetMap[v.value]})):[],metrics:r.type==="metric_selector"?o.choices.map(v=>({option:v,target:o.metricTargetMap[v.value]})):[]};},q=r=>{if(!p(r.control.type))return{nextControl:r.control,cardBindingsById:void 0};const u=(N==null?void 0:N[r.control.id])||[],o=Oe({controlType:r.control.type,participants:L||[],selectedCardIds:r.nextSelectedCardIds}),v=Cr({control:r.control,choices:o.choices}),E=Object.fromEntries(u.filter(_=>!r.nextSelectedCardIds.includes(_)).map(_=>[_,void 0]));return r.nextSelectedCardIds.length>0&&v.source.kind==="manual"&&v.source.options.length>0&&Object.assign(E,at({control:v,participants:L||[],selectedCardIds:r.nextSelectedCardIds,matrixTargetIds:r.matrixTargetIds})),{nextControl:v,cardBindingsById:E};},j=Z((r,u=i,o={type:"update"})=>{const v=r.map(E=>(Ae({control:E,defaultValues:u}),pr(E)));$(v,u,o);},[i,$]),Y=(r,u)=>{const o=a.find(M=>M.id===r);let v=a.map(M=>M.id!==r?M:u(M));const E=v.find(M=>M.id===r);let _,w;if(E&&(!o||yr({control:o},{control:E}))&&t==="dashboard"&&(E.type==="field_selector"||E.type==="metric_selector")){const M=(N==null?void 0:N[E.id])||[],ne=q({control:E,nextSelectedCardIds:M});v=v.map(re=>re.id===r?ne.nextControl:re),_=ne.cardBindingsById,w=[E.id];}else if(o&&(!E||!Nr(E.type))&&t==="dashboard"&&(o.type==="field_selector"||o.type==="metric_selector")){const M=(N==null?void 0:N[o.id])||[];_=Object.fromEntries(M.map(ne=>[ne,void 0])),w=[o.id];}const G=v.find(M=>M.id===r);let W=i;if(o&&G){const M=Ae({control:o,defaultValues:i});o.source.kind==="manual"&&G.source.kind==="sql_query"&&(C.current[r]=M);const ne=M===void 0&&o.source.kind==="sql_query"&&G.source.kind==="manual"?C.current[r]:M,re=rt({previousControl:o,nextControl:G,currentDefaultValue:ne});G.source.kind==="manual"&&(C.current[r]=re),i&&(W={...i},re===void 0?delete W[r]:W[r]=re),v=v.map(He=>He.id===r?{...G,defaultValue:re}:He);}j(v,W,{type:"update",cardBindingsById:_,affectedBindingControlIds:w});},J=(r,u)=>{if(!u.trim())return;const o=wr(u);if(o===r||z.has(o)||a.some(_=>_.id===o&&_.id!==r))return;const v=a.map(_=>_.id===r?{..._,id:o}:_);if(!i){j(v,void 0,{type:"rename",oldId:r,newId:o});return;}const E={...i};Object.prototype.hasOwnProperty.call(E,r)&&(E[o]=E[r],delete E[r]),j(v,E,{type:"rename",oldId:r,newId:o});},Mt=r=>{const u=a.filter(v=>v.id!==r);if(!i){j(u,void 0,{type:"remove",controlId:r});return;}const o={...i};delete o[r],j(u,o,{type:"remove",controlId:r});},qt=Z(()=>{f.current=void 0,g({step:1,control:fe(t,a,Array.from(z))}),H(null),T(null);},[a,z,t]),ue=r=>{g(u=>u&&(()=>{const o=r(u.control);u.control.source.kind==="manual"&&o.source.kind==="sql_query"&&(f.current=u.defaultValue);const v=u.defaultValue===void 0&&u.control.source.kind==="sql_query"&&o.source.kind==="manual"?f.current:u.defaultValue,E=rt({previousControl:u.control,nextControl:o,currentDefaultValue:v});return o.source.kind==="manual"&&(f.current=E),{...u,control:o,defaultValue:E};})());},Ue=r=>{g(u=>u&&(u.control.source.kind==="manual"&&(f.current=r),{...u,defaultValue:r}));},ke=(()=>{if(!n)return!1;if(n.step===2&&p(n.control.type))return(n.selectedCardIds||[]).length>0&&mr({participants:L||[],selectedCardIds:n.selectedCardIds||[],control:n.control,selected:n.matrixTargetIds});if(n.step!==2&&n.step!==3||!n.control.label.trim())return!1;const u=n.control.source.kind==="sql_query"?n.control:et(n.control);if(u.source.kind==="manual"&&(fr(u)&&u.source.options.length===0||u.source.options.some(v=>v.label.trim().length===0||v.value.trim().length===0)))return!1;if(u.source.kind==="sql_query"){const{connectionId:o,sql:v,valueColumn:E}=u.source;return o.trim().length>0&&v.trim().length>0&&E.trim().length>0;}return hr(he(u,n.defaultValue));})(),We=()=>{var _;if(!n)return;const r=et(n.control),u=vr({label:r.label,fallbackId:r.id,existingControls:a,reservedIds:Array.from(z)}),o={...r,id:u},v=t==="dashboard"&&(o.type==="field_selector"||o.type==="metric_selector")&&(_=n.selectedCardIds)!=null&&_.length?at({control:o,participants:L||[],selectedCardIds:n.selectedCardIds,matrixTargetIds:n.matrixTargetIds}):void 0,E=he(o,n.defaultValue);g({step:t==="dashboard"&&(o.type==="field_selector"||o.type==="metric_selector")?4:3,control:o,defaultValue:E,createdControlId:u,selectedCardIds:n.selectedCardIds,matrixTargetIds:n.matrixTargetIds,cardBindingsById:v});},De=Z(()=>{g(null);},[]),Ke=Z(()=>{if(!(n!=null&&n.createdControlId)){g(null);return;}const r=n.control,u=n.createdControlId,o=he(r,n.defaultValue);if(i){const v={...i};o===void 0?delete v[u]:v[u]=o,j([...a,{...r,defaultValue:o}],v,{type:"add",cardBindingsById:n.cardBindingsById});}else j([...a,{...r,defaultValue:o}],void 0,{type:"add",cardBindingsById:n.cardBindingsById});H(u),g(null),O==null||O();},[a,n,i,j,O]),jt=n?p(n.control.type)?["Choose type","Select cards","Configure","Finish"]:["Choose type","Configure","Finish"]:[],Qe=n!=null&&n.createdControlId?`[[param.${n.createdControlId}]]`:n?`[[param.${gr(n.control.label)||n.control.id}]]`:"",Te=tt({controls:a,defaultValues:i}),Le=n?[...a,n.control]:a,Ye=n?tt({controls:Le,defaultValues:i,overrides:[{controlId:n.control.id,value:n.defaultValue}]}):Te;return/* @__PURE__ */c("div",{className:"space-y-4",children:[n?/* @__PURE__ */c("div",{className:"space-y-4 pb-1",children:[/* @__PURE__ */e(Br,{currentStep:n.step,labels:jt}),n.step===1&&(()=>{const r=/* @__PURE__ */new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]),u=/* @__PURE__ */new Set(["date","text"]),o=l.filter(_=>!r.has(_.value)&&!u.has(_.value)),v=l.filter(_=>r.has(_.value)),E=_=>/* @__PURE__ */c("button",{type:"button",className:"rounded-control border border-border/60 bg-background px-3 py-2.5 text-left transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:outline-none",onClick:()=>g(Kr({scope:t,existingControls:a,reservedIds:Array.from(z),type:_.value})),children:[/* @__PURE__ */e("div",{className:"text-[13px] font-medium text-foreground",children:_.label}),/* @__PURE__ */e("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:_.description})]},_.value);return/* @__PURE__ */c("div",{className:"space-y-4",children:[t==="card"&&(I==null?void 0:I.sql)==null?/* @__PURE__ */e("p",{className:"text-[12px] text-muted-foreground",children:"Explorer cards support displayed metric, group by field, aggregation, and time grain controls here."}):null,o.length>0&&/* @__PURE__ */c("div",{className:"space-y-1.5",children:[/* @__PURE__ */e("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Input controls"}),/* @__PURE__ */e("div",{className:"grid gap-1.5 sm:grid-cols-2",children:o.map(E)})]}),v.length>0&&/* @__PURE__ */c("div",{className:"space-y-1.5",children:[/* @__PURE__ */e("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Data-driven controls"}),/* @__PURE__ */e("div",{className:"grid gap-1.5 sm:grid-cols-2",children:v.map(E)})]}),/* @__PURE__ */e(Se,{secondary:/* @__PURE__ */e(B,{type:"button",variant:"outline",size:"xs",onClick:De,children:"Back to controls"})})]});})(),n.step===2&&p(n.control.type)&&/* @__PURE__ */c("div",{className:"space-y-3",children:[/* @__PURE__ */c("div",{className:"space-y-3",children:[/* @__PURE__ */e(It,{control:n.control,onChange:r=>ue(u=>({...u,label:r}))}),/* @__PURE__ */e("p",{className:"text-[12px] text-muted-foreground",children:"Choose which cards should respond to this shared control."})]}),K.length===0?/* @__PURE__ */e("div",{className:"rounded-control border border-border/60 bg-muted/30 px-3 py-2.5 text-[12px] text-muted-foreground",children:"No eligible cards are available yet. Add compatible metrics or group-by fields to cards first."}):/* @__PURE__ */e("div",{className:"space-y-1 rounded-control border border-border/60 bg-background p-2",children:K.map(r=>{const u=(n.selectedCardIds||[]).includes(r.cardId);return/* @__PURE__ */c("label",{className:"flex items-start gap-2 rounded-control px-1.5 py-1 text-[13px] hover:bg-muted/40",children:[/* @__PURE__ */e(Jt,{checked:u,onCheckedChange:o=>g(v=>v&&{...v,selectedCardIds:o===!0?[...(v.selectedCardIds||[]),r.cardId]:(v.selectedCardIds||[]).filter(E=>E!==r.cardId)})}),/* @__PURE__ */c("div",{className:"min-w-0",children:[/* @__PURE__ */e("div",{className:"font-medium text-foreground",children:r.title}),/* @__PURE__ */e("div",{className:"text-[12px] text-muted-foreground",children:n.control.type==="field_selector"?`${r.fieldChoices.length} compatible group-by fields`:`${r.metricChoices.length} compatible metrics`})]})]},r.cardId);})}),/* @__PURE__ */e(st,{participants:K,selectedCardIds:n.selectedCardIds||[],control:n.control,selected:n.matrixTargetIds,onChange:(r,u)=>g(o=>o&&{...o,matrixTargetIds:{...o.matrixTargetIds,[r]:u}})}),/* @__PURE__ */e(Se,{secondary:/* @__PURE__ */e(B,{type:"button",variant:"outline",size:"xs",onClick:()=>g(r=>r&&{...r,step:1,selectedCardIds:[]}),children:"Back"}),primary:/* @__PURE__ */e(B,{type:"button",size:"xs",onClick:()=>g(r=>r&&{...r,step:3}),disabled:!ke,children:"Next"})})]}),n.step===2&&!p(n.control.type)&&/* @__PURE__ */e(it,{control:n.control,defaultValue:n.defaultValue,availableFieldChoices:A.fields,availableMetricChoices:A.metrics,previewControlDefinitions:Le,previewControlValues:Ye,onControlChange:r=>ue(()=>r),onLabelChange:r=>ue(u=>({...u,label:r})),onDefaultValueChange:Ue,onBack:()=>g(r=>r&&{...r,step:1}),onNext:We,nextDisabled:!ke}),n.step===3&&p(n.control.type)&&/* @__PURE__ */e(it,{control:n.control,defaultValue:n.defaultValue,availableFieldChoices:A.fields,availableMetricChoices:A.metrics,previewControlDefinitions:Le,previewControlValues:Ye,onControlChange:r=>ue(()=>r),onLabelChange:r=>ue(u=>({...u,label:r})),onDefaultValueChange:Ue,onBack:()=>g(r=>r&&{...r,step:2}),onNext:We,nextDisabled:!ke}),n.step===3&&!p(n.control.type)&&/* @__PURE__ */e(dt,{control:n.control,scope:t,createdReference:Qe,explorerContent:/* @__PURE__ */c(me,{children:["Open the card and use"," ",/* @__PURE__ */e("span",{className:"font-medium text-foreground",children:"Settings → Controls"})," ","to choose what this control changes."]}),sqlDescription:"Reference this control directly in the SQL editor.",onBack:()=>g(r=>r&&{...r,step:2}),onCancel:De,onDone:Ke}),n.step===4&&p(n.control.type)&&/* @__PURE__ */e(dt,{control:n.control,scope:t,createdReference:Qe,summaryDetail:/* @__PURE__ */c(me,{children:["Used by ",(n.selectedCardIds||[]).length," selected card",(n.selectedCardIds||[]).length===1?"":"s"]}),explorerContent:/* @__PURE__ */e(me,{children:"Selected cards have been set up to respond to this control automatically."}),sqlDescription:"SQL cards can still reference this control directly in the SQL editor.",onBack:()=>g(r=>r&&{...r,step:3}),onCancel:De,onDone:Ke})]}):null,!n&&a.length===0?/* @__PURE__ */e("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:h}):null,!n&&a.map(r=>{const u=R(r),o=b==null?void 0:b[r.id],v=Ae({control:r,defaultValues:i}),E=Q===r.id,_="inline-flex shrink-0 items-center rounded-[4px] border border-border/60 bg-muted/40 px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground";return/* @__PURE__ */c("div",{className:"rounded-control border border-border/60",children:[/* @__PURE__ */c("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[/* @__PURE__ */c("button",{type:"button",className:"flex min-w-0 flex-1 items-start gap-2 rounded-control text-left focus:outline-none focus-visible:bg-muted/40",onClick:()=>H(w=>w===r.id?null:r.id),children:[E?/* @__PURE__ */e(ge,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):/* @__PURE__ */e(Xe,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */c("div",{className:"min-w-0",children:[/* @__PURE__ */c("div",{className:"flex flex-wrap items-center gap-1.5",children:[/* @__PURE__ */e("span",{className:"truncate text-[13px] font-medium text-foreground",children:r.label||"Untitled control"}),/* @__PURE__ */e("span",{className:_,children:Ct(r.type).label}),/* @__PURE__ */e("span",{className:_,children:wt(t,r.placement)})]}),/* @__PURE__ */c("div",{className:"mt-0.5 text-[12px] text-muted-foreground",children:[St(r),o!=null&&o.status?` · ${o.status}`:""]})]})]}),/* @__PURE__ */e(B,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground",onClick:()=>Mt(r.id),"aria-label":`Remove ${r.label}`,children:/* @__PURE__ */e(mt,{className:"h-3.5 w-3.5"})})]}),E&&/* @__PURE__ */c("div",{className:"space-y-4 border-t border-border/60 px-3 py-3",children:[/* @__PURE__ */c("div",{className:"grid gap-3 md:grid-cols-3",children:[/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(ae,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),/* @__PURE__ */e(be,{size:"xs",value:r.label,placeholder:"Control label",onChange:w=>Y(r.id,G=>({...G,label:w.target.value}))})]}),/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(ae,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Type"}),/* @__PURE__ */c(le,{value:r.type,onValueChange:w=>{const G=kt({controls:a,controlId:r.id,nextType:w,defaultValues:i});j(G.controls,G.defaultValues);},children:[/* @__PURE__ */e(ie,{size:"xs",children:/* @__PURE__ */e(oe,{})}),/* @__PURE__ */e(de,{children:V(r.type).map(w=>/* @__PURE__ */e(ee,{value:w.value,children:w.label},w.value))})]})]}),/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(ae,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Show in"}),/* @__PURE__ */c(le,{value:r.placement||X,onValueChange:w=>Y(r.id,G=>({...G,placement:w})),children:[/* @__PURE__ */e(ie,{size:"xs",children:/* @__PURE__ */e(oe,{})}),/* @__PURE__ */e(de,{children:F.map(w=>/* @__PURE__ */e(ee,{value:w.value,children:w.label},w.value))})]})]})]}),p(r.type)?/* @__PURE__ */c(me,{children:[/* @__PURE__ */e($r,{type:r.type,participants:Pe(L||[],r.type).map(w=>({cardId:w.cardId,title:w.title,choiceCount:r.type==="field_selector"?w.fieldChoices.length:w.metricChoices.length})),selectedCardIds:(N==null?void 0:N[r.id])||[],onChange:w=>{const G=q({control:r,nextSelectedCardIds:w}),W=a.map(M=>M.id===r.id?G.nextControl:M);j(W,i,{type:"update",cardBindingsById:G.cardBindingsById});}}),/* @__PURE__ */e(st,{participants:L||[],selectedCardIds:(N==null?void 0:N[r.id])||[],control:r,onChange:(w,G)=>{const W=q({control:r,nextSelectedCardIds:(N==null?void 0:N[r.id])||[],matrixTargetIds:{[w]:G}});j(a.map(M=>M.id===r.id?W.nextControl:M),i,{type:"update",cardBindingsById:W.cardBindingsById});}})]}):null,/* @__PURE__ */e(At,{control:r,availableFieldChoices:u.fields,availableMetricChoices:u.metrics,previewControlDefinitions:a,previewControlValues:Te,controlLifecycle:"edit",onChange:w=>Y(r.id,()=>w)}),r.initialValueStrategy==="saved_default"&&/* @__PURE__ */e(Et,{control:r,value:v,allowNoDefault:!0,allowCardDefault:!0,previewControlDefinitions:a,previewControlValues:Te,onChange:w=>{const G=a.map(W=>W.id===r.id?{...W,defaultValue:w}:W);if(r.source.kind==="manual"&&(C.current[r.id]=w),i){const W={...i};w===void 0?delete W[r.id]:W[r.id]=w,j(G,W);return;}j(G,void 0);}}),/* @__PURE__ */c(Ir,{open:D===r.id,onOpenChange:w=>T(w?r.id:null),children:[/* @__PURE__ */e(Fr,{asChild:!0,children:/* @__PURE__ */c(B,{type:"button",variant:"ghost",size:"xs",className:"-ml-2 gap-1 text-muted-foreground hover:text-foreground",children:[D===r.id?/* @__PURE__ */e(ge,{className:"h-3.5 w-3.5"}):/* @__PURE__ */e(Xe,{className:"h-3.5 w-3.5"}),"Advanced"]})}),/* @__PURE__ */c(Vr,{className:"space-y-3 pt-2",children:[/* @__PURE__ */c("div",{className:"grid gap-3 md:grid-cols-2",children:[/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(ae,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Variable name"}),/* @__PURE__ */e(_r,{controlId:r.id,onCommit:w=>J(r.id,w)},r.id)]}),/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(ae,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Initial value"}),/* @__PURE__ */c(le,{value:r.initialValueStrategy,onValueChange:w=>Y(r.id,G=>({...G,initialValueStrategy:w})),children:[/* @__PURE__ */e(ie,{size:"xs",children:/* @__PURE__ */e(oe,{})}),/* @__PURE__ */e(de,{children:xr.map(w=>/* @__PURE__ */e(ee,{value:w.value,children:w.label},w.value))})]})]})]}),/* @__PURE__ */e(Rr,{control:r,onChange:w=>Y(r.id,()=>w)})]})]})]})]},r.id);}),!n&&/* @__PURE__ */c(B,{type:"button",variant:"outline",size:"xs",onClick:qt,children:[/* @__PURE__ */e(Ve,{className:"h-3.5 w-3.5"}),"Add control"]})]});}function Na(t){const{open:a,onOpenChange:s,initialCreateFlowActive:i=!1,dismissMode:$="passive"}=t,h=a!==void 0,[k,b]=te(!1),[m,x]=te(i),L=h?a:k,N=Z(y=>{!y&&m&&$==="passive"||(h||b(y),y||x(!1),s==null||s(y));},[h,m,$,s]),I=Z(()=>{h||b(!1),x(!1),s==null||s(!1);},[h,s]);Me(()=>{L||x(!1);},[L]);const S=Z(y=>{m&&y.preventDefault();},[m]);return{forceClose:I,handleOpenChange:N,isCreateFlowActive:m,preventPassiveDismissDuringCreate:S,resolvedOpen:L,setIsCreateFlowActive:x};}function Ft(t){const{relativeMeta:a,latestValue:s,...i}=t;return i;}function qe(t,a){const s=Ft(t);return a.relativeMeta?{...s,value:a.value,relativeMeta:a.relativeMeta}:{...s,value:a.value};}function Qr(t,a){const s=a==="in"||a==="not in"||a==="between"||a==="not between"?[]:a==="isNull"||a==="isNotNull"?null:"";return qe({...t,operator:a},{value:s});}function Yr(t,a){const s=ye(a.dataType)==="date";return qe({...t,field:a,operator:s?"between":"="},{value:""});}function Hr({initialFilters:t,availableFields:a,onChange:s}={}){const[i,$]=te(t||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]}),h=g=>{$(g),s==null||s(g);};pe(g=>g.card.dataSource);const{filterableFields:k,isLoading:b}=Pt(),m=a||k||[],x={id:"default",qualifiedFieldName:"default",name:"default",dataType:"string",label:"Default",entityId:"default",entityName:"Default",entityType:"table"},L=g=>{const C=f=>{if(f.id===g){const d=m[0]||x,l=ye(d.dataType)==="date";return{...f,conditions:[...f.conditions,{id:`condition-${Date.now()}`,field:d,operator:l?"between":"=",value:l?[]:""}]};}return{...f,groups:f.groups.map(C)};};h(C(i));},N=g=>{const C=f=>{if(f.id===g){const d=m[0]||x,l=ye(d.dataType)==="date";return{...f,groups:[...f.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:d,operator:l?"between":"=",value:l?[]:""}],groups:[]}]};}return{...f,groups:f.groups.map(C)};};h(C(i));},I=(g,C)=>{const f=d=>d.id===g?{...d,conditions:d.conditions.filter(l=>l.id!==C)}:{...d,groups:d.groups.map(f)};h(f(i));},S=(g,C)=>{const f=d=>d.id===g?{...d,groups:d.groups.filter(l=>l.id!==C)}:{...d,groups:d.groups.map(f)};h(f(i));},y=(g,C,f)=>{const d=l=>l.id===g?{...l,conditions:l.conditions.map(V=>V.id===C?f(V):V)}:{...l,groups:l.groups.map(d)};h(d(i));},O=(g,C,f)=>y(g,C,d=>({...("value"in f||"operator"in f||"field"in f?Ft(d):d),...f})),z=(g,C,f)=>y(g,C,()=>f),F=er(),X=(g,C)=>{const f=d=>d.id===g?{...d,logicalOperator:C}:{...d,groups:d.groups.map(f)};h(f(i));},D=(g,C)=>{const f=d=>d.id===g?{...d,negate:C}:{...d,groups:d.groups.map(f)};h(f(i));},T=(g,C,f)=>{const d=l=>l.id===g?{...l,conditions:lt(l.conditions,C,f)}:{...l,groups:l.groups.map(d)};h(d(i));},Q=(g,C,f)=>{const d=l=>l.id===g?{...l,groups:lt(l.groups,C,f)}:{...l,groups:l.groups.map(d)};h(d(i));},H=g=>{if(!g||g.conditions.length===0&&g.groups.length===0)return"-- No filters defined";const C=d=>{let l="";typeof d.field=="object"?l=d.field.entityName?`${d.field.entityName}.${d.field.name}`:d.field.name:l=String(d.field);const V=d.operator;let p=d.value;if(d.latestValue&&V==="=")return`${l} = ${ft} /* the latest value each time the card runs */`;const K=Dt(d.relativeMeta);if(K&&Ar(V)&&Tt(V,K)){const A=Mr(V,K),{label:R,range:q}=Je(K,{tz:(F==null?void 0:F.tz)??"UTC",weekStart:(F==null?void 0:F.weekStart)??1,anchor:(F==null?void 0:F.anchor)??"now"}),j=A?qr(A):R;if(q){const[Y]=Lt(V,[q.start,q.end]);return`${l} ${V} '${Y.toISOString()}' /* ${j}: the date updates each time the card runs */`;}return`${l} ${V} ${j} /* the date follows your calendar each time the card runs */`;}if(K&&(V==="between"||V==="not between")){const A=V==="between"?"BETWEEN":"NOT BETWEEN",{label:R,range:q}=Je(K,{tz:(F==null?void 0:F.tz)??"UTC",weekStart:(F==null?void 0:F.weekStart)??1,anchor:(F==null?void 0:F.anchor)??"now"});return q?`${l} ${A} '${q.start.toISOString()}' AND '${q.end.toISOString()}' /* ${R}: dates update each time the card runs */`:Ot(K).dataAnchored?`${l} ${A} ${R} /* dates count back from the latest data each time the card runs */`:`${l} ${A} ${R} /* dates follow your calendar each time the card runs */`;}if(d.field.dataType==="string"&&!["in","not in"].includes(d.operator))typeof p=="string"?p=`'${p}'`:Array.isArray(p)&&(p=`'${p.join(", ")}'`);else if(d.field.dataType==="date"||d.field.dataType==="datetime"||d.field.dataType==="timestamp"){if(d.operator==="between"&&Array.isArray(p)&&p.length===2){const A=p[0]?`'${p[0]}'`:"NULL",R=p[1]?`'${p[1]}'`:"NULL";return`${l} BETWEEN ${A} AND ${R}`;}else if((d.operator==="in"||d.operator==="not in")&&Array.isArray(p)){const A=p.map(R=>R?`'${R}'`:"NULL").join(", ");return`${l} ${V} (${A})`;}else typeof p=="string"||p instanceof Date?p=`'${p}'`:Array.isArray(p)&&p.length>0&&(p=`'${p[0]}'`);}else if(["in","not in"].includes(d.operator)){let A=[];Array.isArray(p)?A=p.map(R=>typeof R=="string"?`'${R}'`:String(R)):typeof p=="string"?A=p.split(",").map(R=>{const q=R.trim();return d.field.dataType==="string"?`'${q}'`:q;}):typeof p=="number"&&(A=[String(p)]),p=`(${A.join(", ")})`;}switch(V){case"contains":return typeof p=="string"?`${l} LIKE '%${p.replace(/'/g,"")}'`:`${l} LIKE '%${String(p)}'`;case"startsWith":return typeof p=="string"?`${l} LIKE '${p.replace(/'/g,"")}%'`:`${l} LIKE '${String(p)}%'`;case"endsWith":return typeof p=="string"?`${l} LIKE '%${p.replace(/'/g,"")}'`:`${l} LIKE '%${String(p)}'`;case"isNull":return`${l} IS NULL`;case"isNotNull":return`${l} IS NOT NULL`;default:return`${l} ${V} ${p}`;}},f=d=>{const l=d.conditions.map(C),V=d.groups.map(R=>f(R)),p=[...l,...V].filter(Boolean);if(p.length===0)return"";const K=p.join(` ${d.logicalOperator} `),A=p.length>1?`(${K})`:K;return d.negate?`NOT ${A}`:A;};return f(g);},n=i.conditions.length>0||i.groups.length>0;return{currentFilters:i,setCurrentFilters:h,availableFields:m,isLoading:b,addCondition:L,addGroup:N,removeCondition:I,removeGroup:S,updateConditionFields:O,replaceCondition:z,updateGroupOperator:X,updateGroupNegate:D,reorderConditions:T,reorderGroups:Q,generateSQLPreview:H,hasAnyFilters:n};}function Vt(t,a){const s=pe(x=>x.card.dataSource),i=pe(x=>x.card.connectionId),$=pe(x=>x.selectedConnectionId),{dataSource:h,connectionId:k}=a?nt(a):nt({dataSource:s,connectionId:i},$),b=P(()=>({id:`card-filter-option:${t.id}`,...Sr(t,{dataSource:h,connectionId:k})}),[k,h,t]),m=P(()=>tr({filter:b}),[b]);return rr(b,{inputContext:m,currentSelectionPolicy:"exclude"});}function Xr({field:t,source:a,selected:s,onChange:i,placeholder:$="Select values…",className:h}){const[k,b]=we.useState(!1),m=Vt(t,a),x=we.useMemo(()=>new Set(s.map(S=>ce(S))),[s]),L=S=>{var y,O;return((O=(y=m.allRecords.find(z=>ce(z.value)===ce(S)))==null?void 0:y.label)==null?void 0:O.toString())??S;},N=S=>{i(s.filter(y=>y!==S));},I=S=>{b(S),!S&&m.query&&m.setQuery("");};return/* @__PURE__ */e("div",{className:U("w-full",h),children:/* @__PURE__ */c(ht,{open:k,onOpenChange:I,modal:!0,children:[/* @__PURE__ */e(gt,{asChild:!0,children:/* @__PURE__ */c(B,{variant:"outline",size:"xs",role:"combobox","aria-expanded":k,className:"h-auto min-h-7 w-full justify-between gap-1.5 px-2 py-0.5 font-normal",children:[/* @__PURE__ */e("div",{className:"flex min-w-0 flex-1 flex-wrap gap-1",children:s.length>0?s.map(S=>{const y=L(S);return(/* @__PURE__ */c("span",{className:"inline-flex max-w-full items-center gap-1 rounded-[4px] border border-border/70 bg-muted/40 px-1.5 py-0.5 text-[11px] leading-[14px] text-foreground",children:[/* @__PURE__ */e("span",{className:"truncate",children:y}),/* @__PURE__ */e("span",{role:"button",tabIndex:0,"aria-label":`Remove ${y}`,className:"shrink-0 rounded-[2px] text-muted-foreground outline-none hover:text-foreground focus-visible:ring-1 focus-visible:ring-ring",onKeyDown:O=>{O.key==="Enter"&&N(S);},onMouseDown:O=>{O.preventDefault(),O.stopPropagation();},onClick:O=>{O.stopPropagation(),N(S);},children:/* @__PURE__ */e(bt,{className:"h-3 w-3"})})]},S));}):/* @__PURE__ */e("span",{className:"truncate text-muted-foreground",children:$})}),/* @__PURE__ */e(ge,{className:"h-3.5 w-3.5 shrink-0 opacity-50"})]})}),/* @__PURE__ */e(xt,{className:"w-[var(--radix-popover-trigger-width)] min-w-[240px] rounded-control p-1.5",align:"start",onOpenAutoFocus:S=>{var y,O;S.preventDefault(),(O=(y=S.currentTarget)==null?void 0:y.querySelector('input[type="text"]'))==null||O.focus();},children:/* @__PURE__ */e(vt,{records:m.displayRecords,selectedIdentities:x,onToggle:S=>{const y=String(S.value);s.includes(y)?N(y):i([...s,y]);},browse:m,searchPlaceholder:`Search ${(t.label||t.name).toLowerCase()}`,listLabel:t.label||t.name,density:"compact"})})]})});}function Jr({field:t,source:a,value:s,onChange:i,placeholder:$="Select value…",className:h}){var I,S;const[k,b]=we.useState(!1),m=Vt(t,a),x=we.useMemo(()=>new Set(s?[ce(s)]:[]),[s]),L=s?((S=(I=m.allRecords.find(y=>ce(y.value)===ce(s)))==null?void 0:I.label)==null?void 0:S.toString())??s:"",N=y=>{b(y),!y&&m.query&&m.setQuery("");};return/* @__PURE__ */c(ht,{open:k,onOpenChange:N,modal:!0,children:[/* @__PURE__ */e(gt,{asChild:!0,children:/* @__PURE__ */c(B,{variant:"outline",size:"xs",role:"combobox","aria-expanded":k,className:U("min-w-0 flex-1 justify-between gap-1.5 px-2 font-normal",h),children:[/* @__PURE__ */e("span",{className:U("truncate",!s&&"text-muted-foreground"),children:s?L:$}),/* @__PURE__ */e(ge,{className:"h-3.5 w-3.5 shrink-0 opacity-50"})]})}),/* @__PURE__ */e(xt,{className:"w-[var(--radix-popover-trigger-width)] min-w-[240px] rounded-control p-1.5",align:"start",onOpenAutoFocus:y=>{var O,z;y.preventDefault(),(z=(O=y.currentTarget)==null?void 0:O.querySelector('input[type="text"]'))==null||z.focus();},children:/* @__PURE__ */e(vt,{records:m.displayRecords,selectedIdentities:x,onToggle:y=>{i(String(y.value)),N(!1);},selectionMode:"single",browse:m,searchPlaceholder:`Search ${(t.label||t.name).toLowerCase()}`,listLabel:t.label||t.name,density:"compact"})})]});}function Zr({value:t,operator:a,relativeMeta:s,latestValue:i,field:$,onChange:h,className:k}){const b=ar(),m=nr(),x=a==="between"||a==="not between",L=Tt(a),N=L?s:void 0,I=P(()=>{if(!x||!s)return;const D=m(s);return{...D,tooltip:D.dates?void 0:Ot(s).dataAnchored?sr:lr};},[x,s,m]),S=P(()=>{if(x){if(I){const{range:D}=I;return D?{from:D.start,to:D.end}:void 0;}if(t&&Array.isArray(t)&&t.length===2){const D=$e(t[0],b,"start"),T=$e(t[1],b,"end");if(D&&T)return{from:D,to:T};}}},[t,x,I,b]),y=P(()=>{if(!t||x||i)return;const D=Array.isArray(t)?t[0]:t;return $e(D,b,"start");},[t,x,i,b]),O=D=>a==="<="||a===">"?Tr(D,b):Lr(D,b);return/* @__PURE__ */e(ir,{value:x?S:void 0,selectionMode:x?"range":"single",singleValue:x?void 0:y,singleValueLabel:!x&&i?ft:void 0,onChange:D=>{if(D!=null&&D.from&&D.to){h({value:[D.from.toISOString(),D.to.toISOString()]});return;}h({value:[]});},onSingleChange:D=>{if(!D){h({value:""});return;}const T=O(D),Q=Dr(T,a,{timezone:b});h({value:typeof Q=="string"?Q:Q.toISOString()});},onRelativeSelect:L?(D,T)=>{if(!D.from||!D.to){h({value:x?[]:""});return;}const Q=Lt(a,[D.from.toISOString(),D.to.toISOString()]);h({value:Q.length===1?Q[0]:Q,relativeMeta:T});}:void 0,relativeValue:N,comparisonValue:!x&&L?a:void 0,relativePoints:!x&&L?{operator:a}:"none",relativeSummary:I,supplementalFooter:L?/* @__PURE__ */e("p",{className:"border-t border-border px-3 py-2 text-[11px] text-muted-foreground",children:"Presets and Relative update each time the card runs. Static dates stay fixed."}):void 0,timezone:b,enableTimePrecision:kr($),staticTimeInputs:!1,showRelativeTab:L,className:U("min-w-0",k),buttonClassName:"h-7 text-[12px] [&>span]:text-[12px]",placeholder:"Select date…"});}const Pr=t=>t.conditions.length>0||t.groups.length>0,je=["contains","startsWith","endsWith","like","not like"],ea=["=","!=",">",">=","<","<=",...je,"in","not in","isNull","isNotNull"],ta=["=","!=",...je,"in","not in","isNull","isNotNull"],ra=["=","!=",">",">=","<","<=","in","not in","isNull","isNotNull"],aa=["=","!=","isNull","isNotNull"],na=["between","=","!=","<","<=",">",">=","isNull","isNotNull"],sa={"=":"Equals","!=":"Not equals",">":"Greater than",">=":"Greater than or equal","<":"Less than","<=":"Less than or equal",contains:"Contains",startsWith:"Starts with",endsWith:"Ends with",like:"Like","not like":"Not like",in:"In","not in":"Not in",between:"Between",isNull:"Is null",isNotNull:"Is not null","not between":"Not between"};function Fe(t){return sa[t]||Or(t);}function la(t){switch(t){case"string":return ta;case"number":return ra;case"boolean":return aa;case"date":return na;default:return ea;}}const _t="w-[68px] shrink-0",ct="group-data-[inline]/filters:w-auto group-data-[inline]/filters:min-w-0 group-data-[inline]/filters:flex-1 group-data-[inline]/filters:shrink",Be="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Rt({value:t,onValueChange:a,"aria-label":s}){return/* @__PURE__ */c(le,{value:t,onValueChange:i=>a(i),children:[/* @__PURE__ */e(ie,{size:"xs","aria-label":s,className:U(_t,"font-medium"),children:/* @__PURE__ */e(oe,{})}),/* @__PURE__ */c(de,{className:"min-w-[var(--radix-select-trigger-width)]",children:[/* @__PURE__ */e(ee,{value:"AND",className:"text-[12px] font-medium",children:"AND"}),/* @__PURE__ */e(ee,{value:"OR",className:"text-[12px] font-medium",children:"OR"})]})]});}function zt({condition:t,index:a,groupId:s,groupLogicalOperator:i,onRemoveCondition:$,onUpdateGroupOperator:h,availableFields:k,source:b,updateConditionFields:m,replaceCondition:x}){const{attributes:L,listeners:N,setNodeRef:I,transform:S,transition:y,isDragging:O}=$t({id:t.id}),z={transform:yt.Transform.toString(S),transition:y},F=ye(t.field.dataType),X=t.operator==="isNull"||t.operator==="isNotNull",D=t.operator==="in"||t.operator==="not in";return/* @__PURE__ */c("div",{ref:I,style:z,className:U("flex items-center gap-2 rounded-control px-1.5 py-1 transition-colors hover:bg-muted/40",O&&"z-50 opacity-50"),children:[/* @__PURE__ */e("button",{type:"button",...L,...N,"aria-label":"Drag to reorder condition",className:"flex h-7 w-5 shrink-0 cursor-grab items-center justify-center rounded-control text-muted-foreground/60 hover:text-foreground focus-visible:outline-none active:cursor-grabbing",children:/* @__PURE__ */e(Nt,{className:"h-3.5 w-3.5"})}),a>0?/* @__PURE__ */e(Rt,{value:i,onValueChange:T=>h(s,T),"aria-label":"Logical operator"}):/* @__PURE__ */e("span",{className:U(_t,"text-center",Be),children:"Where"}),/* @__PURE__ */e(cr,{value:t.field,onValueChange:T=>{x(s,t.id,Yr(t,T));},availableFields:k,placeholder:"Select field",className:U("w-60 shrink-0",ct)}),/* @__PURE__ */c(le,{value:t.operator,onValueChange:T=>x(s,t.id,Qr(t,T)),children:[/* @__PURE__ */e(ie,{size:"xs","aria-label":"Operator",className:U("w-40 shrink-0",ct),children:/* @__PURE__ */e(oe,{children:t.operator?Fe(t.operator):""})}),/* @__PURE__ */e(de,{children:la(F).map(T=>/* @__PURE__ */e(ee,{value:T,children:Fe(T)},T))})]}),X?/* @__PURE__ */e("div",{className:"min-w-0 flex-1"}):F==="string"?D?/* @__PURE__ */e(Xr,{field:t.field,source:b,selected:Array.isArray(t.value)&&t.value.every(T=>typeof T=="string")?t.value:[],onChange:T=>m(s,t.id,{value:T}),placeholder:"Select values…",className:"min-w-0 flex-1"}):je.includes(t.operator)?/* @__PURE__ */e(be,{size:"xs",value:typeof t.value=="string"?t.value:"",onChange:T=>m(s,t.id,{value:T.target.value}),className:"min-w-0 flex-1",placeholder:`${Fe(t.operator)}…`}):/* @__PURE__ */e(Jr,{field:t.field,source:b,value:typeof t.value=="string"?t.value:"",onChange:T=>m(s,t.id,{value:T}),placeholder:"Select value…",className:"min-w-0 flex-1"}):F==="boolean"?/* @__PURE__ */c(le,{value:typeof t.value=="boolean"?String(t.value):"",onValueChange:T=>m(s,t.id,{value:T==="true"}),children:[/* @__PURE__ */e(ie,{size:"xs",className:"min-w-0 flex-1",children:/* @__PURE__ */e(oe,{placeholder:"Select value…"})}),/* @__PURE__ */c(de,{children:[/* @__PURE__ */e(ee,{value:"true",children:"True"}),/* @__PURE__ */e(ee,{value:"false",children:"False"})]})]}):F==="date"?/* @__PURE__ */e(Zr,{value:t.value,operator:t.operator,relativeMeta:Dt(t.relativeMeta),latestValue:t.latestValue===!0,field:t.field,onChange:T=>x(s,t.id,qe(t,T)),className:"min-w-0 flex-1"}):/* @__PURE__ */e(be,{size:"xs",value:typeof t.value=="string"||typeof t.value=="number"?t.value:"",onChange:T=>m(s,t.id,{value:T.target.value}),className:"min-w-0 flex-1",placeholder:D?"value1, value2, value3":"Value"}),/* @__PURE__ */e(B,{variant:"ghost",size:"xs","aria-label":"Remove condition",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground hover:text-foreground",onClick:()=>$(s,t.id),children:/* @__PURE__ */e(bt,{className:"h-3.5 w-3.5"})})]});}const ut="group-data-[inline]/filters:h-auto group-data-[inline]/filters:gap-1 group-data-[inline]/filters:border-0 group-data-[inline]/filters:bg-transparent group-data-[inline]/filters:px-0 group-data-[inline]/filters:py-0.5 group-data-[inline]/filters:text-[11px] group-data-[inline]/filters:font-medium group-data-[inline]/filters:text-muted-foreground group-data-[inline]/filters:shadow-none group-data-[inline]/filters:underline-offset-2 group-data-[inline]/filters:hover:bg-transparent group-data-[inline]/filters:hover:text-foreground group-data-[inline]/filters:hover:underline";function Gt({onAddCondition:t,onAddGroup:a}){return/* @__PURE__ */c("div",{className:"mt-2 flex items-center gap-1.5 group-data-[inline]/filters:mt-1 group-data-[inline]/filters:gap-3",children:[/* @__PURE__ */c(B,{type:"button",size:"xs",variant:"outline",className:U("gap-1.5",ut),onClick:t,children:[/* @__PURE__ */e(Ve,{className:"h-3 w-3"}),"Add condition"]}),a&&/* @__PURE__ */c(B,{type:"button",size:"xs",variant:"ghost",className:U("gap-1.5 text-muted-foreground hover:text-foreground",ut),onClick:a,children:[/* @__PURE__ */e(Ve,{className:"h-3 w-3"}),"Add group"]})]});}function ia({group:t,depth:a,parentGroupId:s,onUpdateGroupOperator:i,onUpdateGroupNegate:$,onRemoveGroup:h,onRemoveCondition:k,onReorderConditions:b,onReorderGroups:m,onAddCondition:x,onAddGroup:L,availableFields:N,source:I,renderFilterGroup:S,updateConditionFields:y,replaceCondition:O}){const{attributes:z,listeners:F,setNodeRef:X,transform:D,transition:T,isDragging:Q}=$t({id:t.id}),H={transform:yt.Transform.toString(D),transition:T},n=C=>{const{active:f,over:d}=C;if(d&&f.id!==d.id){const l=t.conditions.findIndex(p=>p.id===f.id),V=t.conditions.findIndex(p=>p.id===d.id);l!==-1&&V!==-1&&b(t.id,l,V);}},g=C=>{const{active:f,over:d}=C;if(d&&f.id!==d.id&&s){const l=t.groups.findIndex(p=>p.id===f.id),V=t.groups.findIndex(p=>p.id===d.id);l!==-1&&V!==-1&&m(s,l,V);}};return/* @__PURE__ */c("div",{ref:X,style:H,className:U(a>0&&"mt-2 overflow-hidden rounded-[6px] border border-border/60",Q&&"z-50 opacity-50"),children:[a>0&&/* @__PURE__ */c("div",{className:"flex items-center justify-between gap-2 border-b border-border/60 bg-muted/40 px-2 py-1",children:[/* @__PURE__ */c("div",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */e("button",{type:"button",...z,...F,"aria-label":"Drag to reorder group",className:"flex h-7 w-5 shrink-0 cursor-grab items-center justify-center rounded-control text-muted-foreground/60 hover:text-foreground focus-visible:outline-none active:cursor-grabbing",children:/* @__PURE__ */e(Nt,{className:"h-3.5 w-3.5"})}),/* @__PURE__ */e(B,{type:"button",variant:t.negate?"default":"outline",size:"xs","aria-pressed":t.negate,className:"px-2",onClick:()=>$(t.id,!t.negate),children:"NOT"}),/* @__PURE__ */e(Rt,{value:t.logicalOperator,onValueChange:C=>i(t.id,C),"aria-label":"Group logical operator"}),/* @__PURE__ */e("span",{className:Be,children:"Group"})]}),/* @__PURE__ */e(B,{type:"button",variant:"ghost",size:"xs","aria-label":"Remove group",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:()=>s&&h(s,t.id),children:/* @__PURE__ */e(mt,{className:"h-3.5 w-3.5"})})]}),/* @__PURE__ */c("div",{className:U(a>0&&"p-2"),children:[/* @__PURE__ */e(xe,{sensors:_e(se(ze),se(Re,{coordinateGetter:Ge})),collisionDetection:ve,onDragEnd:n,children:/* @__PURE__ */e(Ne,{items:t.conditions.map(C=>C.id),strategy:Ce,children:/* @__PURE__ */e("div",{className:"space-y-0.5",children:t.conditions.map((C,f)=>/* @__PURE__ */e(zt,{condition:C,index:f,groupId:t.id,groupLogicalOperator:t.logicalOperator,onRemoveCondition:k,onUpdateGroupOperator:i,availableFields:N,source:I,updateConditionFields:y,replaceCondition:O},C.id))})})}),/* @__PURE__ */e(xe,{sensors:_e(se(ze),se(Re,{coordinateGetter:Ge})),collisionDetection:ve,onDragEnd:g,children:/* @__PURE__ */e(Ne,{items:t.groups.map(C=>C.id),strategy:Ce,children:t.groups.map(C=>S(C,a+1,t.id))})}),t.conditions.length===0&&t.groups.length===0&&/* @__PURE__ */e("p",{className:"rounded-control border border-dashed border-border/60 px-3 py-2 text-center text-[11.5px] text-muted-foreground",children:"No conditions in this group."}),/* @__PURE__ */e(Gt,{onAddCondition:()=>x(t.id),onAddGroup:()=>L(t.id)})]})]});}function Ca({filters:t,availableFields:a,source:s,onSave:i,onClearAll:$,onCancel:h,onChange:k}){const b=k!==void 0,{currentFilters:m,availableFields:x,isLoading:L,addCondition:N,addGroup:I,removeCondition:S,removeGroup:y,updateConditionFields:O,replaceCondition:z,updateGroupOperator:F,updateGroupNegate:X,reorderConditions:D,reorderGroups:T,generateSQLPreview:Q,hasAnyFilters:H}=Hr({initialFilters:t,availableFields:a,...(k?{onChange:l=>k(Pr(l)?l:null)}:{})}),n=_e(se(ze),se(Re,{coordinateGetter:Ge})),[g,C]=te(!1),f=(l,V=0,p)=>{if(V===0){const K=l.conditions.length===0&&l.groups.length===0;return/* @__PURE__ */c("div",{children:[/* @__PURE__ */e(xe,{sensors:n,collisionDetection:ve,onDragEnd:A=>{const{active:R,over:q}=A;if(q&&R.id!==q.id){const j=l.conditions.findIndex(J=>J.id===R.id),Y=l.conditions.findIndex(J=>J.id===q.id);j!==-1&&Y!==-1&&D(l.id,j,Y);}},children:/* @__PURE__ */e(Ne,{items:l.conditions.map(A=>A.id),strategy:Ce,children:/* @__PURE__ */e("div",{className:"space-y-0.5",children:l.conditions.map((A,R)=>/* @__PURE__ */e(zt,{condition:A,index:R,groupId:l.id,groupLogicalOperator:l.logicalOperator,onRemoveCondition:S,onUpdateGroupOperator:F,availableFields:x,source:s,updateConditionFields:O,replaceCondition:z},A.id))})})}),/* @__PURE__ */e(xe,{sensors:n,collisionDetection:ve,onDragEnd:A=>{const{active:R,over:q}=A;if(q&&R.id!==q.id){const j=l.groups.findIndex(J=>J.id===R.id),Y=l.groups.findIndex(J=>J.id===q.id);j!==-1&&Y!==-1&&T(l.id,j,Y);}},children:/* @__PURE__ */e(Ne,{items:l.groups.map(A=>A.id),strategy:Ce,children:l.groups.map(A=>f(A,V+1,l.id))})}),K&&!b&&/* @__PURE__ */e("p",{className:"rounded-control border border-dashed border-border/60 px-3 py-2 text-center text-[11.5px] text-muted-foreground",children:"No filters yet. Add a condition to limit the rows this card shows."}),/* @__PURE__ */e(Gt,{onAddCondition:()=>N(l.id),onAddGroup:(b?l.conditions.length+l.groups.length>=2:g)?()=>I(l.id):void 0})]},l.id);}return/* @__PURE__ */e(ia,{group:l,depth:V,parentGroupId:p,onUpdateGroupOperator:F,onUpdateGroupNegate:X,onRemoveGroup:y,onRemoveCondition:S,onReorderConditions:D,onReorderGroups:T,onAddCondition:N,onAddGroup:I,availableFields:x,source:s,renderFilterGroup:f,updateConditionFields:O,replaceCondition:z},l.id);},d=zr(t);return/* @__PURE__ */c("div",{className:U("group/filters",b?"flex flex-col":"flex min-h-0 flex-1 flex-col"),"data-inline":b||void 0,children:[/* @__PURE__ */c("div",{className:b?"":"min-h-0 flex-1 overflow-y-auto px-3 py-3",children:[L?/* @__PURE__ */c("div",{className:"flex items-center justify-center gap-2 py-6 text-[12px] text-muted-foreground",children:[/* @__PURE__ */e(or,{className:"h-3.5 w-3.5 animate-spin"}),"Loading columns…"]}):f(m),!b&&/* @__PURE__ */c("div",{className:"mt-3 flex items-center gap-2 border-t border-border/60 pt-3",children:[/* @__PURE__ */e(dr,{size:"xs",id:"advanced-mode",checked:g,onCheckedChange:l=>C(l)}),/* @__PURE__ */e(ae,{htmlFor:"advanced-mode",className:"text-[12px] font-normal leading-none text-foreground",children:"Advanced mode"}),/* @__PURE__ */e("span",{className:"text-[11px] text-muted-foreground",children:"Nest conditions in groups"})]}),H&&!b&&/* @__PURE__ */c("div",{className:"mt-3 border-t border-border/60 pt-3",children:[/* @__PURE__ */e("div",{className:U("mb-1.5",Be),children:"Where clause"}),/* @__PURE__ */e("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words rounded-[6px] border border-border bg-muted/40 px-3 py-2 font-mono text-[12px] leading-[1.55] text-foreground",children:Q(m)})]})]}),b?null:/* @__PURE__ */c("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border px-3 py-2.5",children:[/* @__PURE__ */e("div",{children:d>0&&/* @__PURE__ */e(B,{size:"xs",variant:"ghost",className:"text-muted-foreground hover:text-foreground",onClick:()=>$==null?void 0:$(),children:"Clear all"})}),/* @__PURE__ */c("div",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */e(B,{size:"xs",variant:"ghost",onClick:()=>h==null?void 0:h(),children:"Cancel"}),/* @__PURE__ */e(B,{size:"xs",onClick:()=>i==null?void 0:i(H?m:null),children:"Apply filters"})]})]})]});}export{ya as C,xa as F,jr as L,va as V,Ca as a,Na as u};
11
+ */const jr=pt("Library",[["path",{d:"m16 6 4 14",key:"ji33uf"}],["path",{d:"M12 6v14",key:"1n7gus"}],["path",{d:"M8 8v12",key:"1gg7y9"}],["path",{d:"M4 4v16",key:"6qkkli"}]]);function va({type:t,isLinked:a,className:s,showLabel:i=!1,showLocal:F=!1}){const h=Bt(A=>A.selectedFrameId),k=Er(A=>A.selectedVisual),b=pe(A=>A.frame);let m;if(t)m=t;else if(a!==void 0)m=a?"linked":"library";else if(!!!(b!=null&&b.visualId||k!=null&&k.id)&&h)m="local";else if(k&&!h)m="library";else if(b!=null&&b.visualId&&h)m="linked";else if(k!=null&&k.id&&h)m="library";else return null;if(m==="local"&&!F)return null;const x={local:"border-slate-200/70 bg-slate-50/80 text-slate-700 shadow-sm hover:bg-slate-100/80 dark:border-slate-700 dark:bg-slate-900/70 dark:text-slate-200 dark:hover:bg-slate-800/80",linked:"border-purple-200/70 bg-gradient-to-r from-purple-50/50 to-purple-100/30 text-purple-900 shadow-sm hover:from-purple-100/60 hover:to-purple-100/50 hover:shadow-md dark:border-purple-800/50 dark:from-purple-950/40 dark:to-purple-900/30 dark:text-purple-100 dark:hover:from-purple-950/60 dark:hover:to-purple-900/50",library:"border-blue-200/70 bg-gradient-to-r from-blue-50/50 to-blue-100/30 text-blue-900 shadow-sm hover:from-blue-100/60 hover:to-blue-100/50 hover:shadow-md dark:border-blue-800/50 dark:from-blue-950/40 dark:to-blue-900/30 dark:text-blue-100 dark:hover:from-blue-950/60 dark:hover:to-blue-900/50"},L={local:"Local to this dashboard: Changes made here only affect this dashboard copy.",linked:"Linked to library: Changes made here update the library visual and all linked instances.",library:"Library visual: Share and reuse this visual across multiple dashboards."},N={local:"border-slate-200 bg-slate-50 text-slate-900 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100",linked:"border-purple-200 bg-purple-50 text-purple-900 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-100",library:"border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-100"},I={local:"fill-slate-50 dark:fill-slate-900",linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},S={local:/* @__PURE__ */e("span",{className:"h-2 w-2 rounded-full bg-current/70"}),linked:/* @__PURE__ */e(Xt,{className:"h-3.5 w-3.5"}),library:/* @__PURE__ */e(jr,{className:"h-3.5 w-3.5"})},y={local:"Local",linked:"Linked",library:"Library"};return/* @__PURE__ */e(Ut,{children:/* @__PURE__ */c(Wt,{delayDuration:300,children:[/* @__PURE__ */e(Kt,{asChild:!0,children:/* @__PURE__ */c(Qt,{variant:"outline",className:U("cursor-help select-none transition-all",x[m],s),children:[S[m],i&&/* @__PURE__ */e("span",{className:"ml-1 text-xs font-medium leading-none",children:y[m]})]})}),/* @__PURE__ */c(Yt,{side:"bottom",className:U("max-w-xs",N[m]),children:[/* @__PURE__ */e(Ht,{className:I[m]}),/* @__PURE__ */e("p",{children:L[m]})]})]})});}function Ft(t){const{control:a,onChange:s}=t;return/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(ae,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),/* @__PURE__ */e(be,{size:"xs",value:a.label,placeholder:"Control label",onChange:i=>s(i.target.value)})]});}function Br(t){const{currentStep:a,labels:s}=t;return/* @__PURE__ */e("div",{className:"sticky top-0 z-10 -mx-1 border-b border-border/60 bg-background/95 px-1 pb-2.5 pt-1 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:/* @__PURE__ */e("div",{className:"flex flex-wrap items-center gap-2 sm:gap-2.5",children:s.map((i,F)=>{const h=F+1,k=h===a,b=h<a;return/* @__PURE__ */c(Gr,{children:[/* @__PURE__ */c("div",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */e("span",{className:U("flex h-5 w-5 items-center justify-center rounded-full border text-[10px] font-medium tabular-nums",k?"border-foreground bg-foreground text-background":b?"border-foreground/30 bg-foreground/10 text-foreground":"border-border/60 bg-background text-muted-foreground"),children:h}),/* @__PURE__ */e("span",{className:U("text-[12px]",k?"font-medium text-foreground":"text-muted-foreground"),children:i})]}),F<s.length-1?/* @__PURE__ */e("span",{className:"h-px w-4 bg-border/60 sm:w-6","aria-hidden":"true"}):null]},i);})})});}function Se(t){const{secondary:a,tertiary:s,primary:i}=t;return/* @__PURE__ */c("div",{className:"sticky bottom-0 z-10 -mx-1 flex justify-end gap-2 border-t bg-background/95 px-1 pb-1 pt-3 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:[a,s,i]});}function Ur(t){const{control:a,scope:s,detail:i}=t;return/* @__PURE__ */c("div",{className:"flex items-start gap-2.5 rounded-control border border-border/60 bg-muted/30 px-3 py-2.5",children:[/* @__PURE__ */e(Zt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground"}),/* @__PURE__ */c("div",{className:"min-w-0 space-y-0.5",children:[/* @__PURE__ */e("div",{className:"text-[13px] font-medium text-foreground",children:a.label}),/* @__PURE__ */c("div",{className:"text-[12px] text-muted-foreground",children:[Ct(a.type).label," ·"," ",St(a)," ·"," ",wt(s,a.placement)]}),i?/* @__PURE__ */e("div",{className:"text-[12px] text-muted-foreground",children:i}):null]})]});}function it(t){const{control:a,defaultValue:s,availableFieldChoices:i,availableMetricChoices:F,previewControlDefinitions:h,previewControlValues:k,onControlChange:b,onLabelChange:m,onDefaultValueChange:x,onBack:L,onNext:N,nextDisabled:I}=t;return/* @__PURE__ */c("div",{className:"space-y-3",children:[/* @__PURE__ */e(Ft,{control:a,onChange:m}),/* @__PURE__ */e(At,{control:a,availableFieldChoices:i,availableMetricChoices:F,previewControlDefinitions:h,previewControlValues:k,controlLifecycle:"create",onChange:b}),/* @__PURE__ */e(Et,{control:a,value:s,onChange:x,allowNoDefault:!0,allowCardDefault:!0,hint:"This is the value viewers will see first.",previewControlDefinitions:h,previewControlValues:k}),/* @__PURE__ */e(Se,{secondary:/* @__PURE__ */e(B,{type:"button",variant:"outline",size:"xs",onClick:L,children:"Back"}),primary:/* @__PURE__ */e(B,{type:"button",size:"xs",onClick:N,disabled:I,children:"Next"})})]});}const Wr=/* @__PURE__ */new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]);function ot(t){const{text:a,ariaLabel:s}=t,[i,F]=te(!1);return/* @__PURE__ */c("button",{type:"button","aria-label":s,onClick:async()=>{try{await navigator.clipboard.writeText(a),F(!0),setTimeout(()=>F(!1),1200);}catch(h){console.error("Failed to copy",h);}},className:"group flex w-full items-center justify-between gap-2 rounded-control bg-muted/40 px-2 py-1 text-left transition-colors hover:bg-muted/60 focus-visible:bg-muted/60 focus-visible:outline-none",children:[/* @__PURE__ */e("code",{className:"min-w-0 truncate font-mono text-[12px] text-foreground",children:a}),/* @__PURE__ */e("span",{className:"shrink-0 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:i?"Copied":"Click to copy"})]});}function dt(t){const{control:a,scope:s,createdReference:i,explorerContent:F,sqlDescription:h,summaryDetail:k,onBack:b,onCancel:m,onDone:x}=t,L=Wr.has(a.type),N=i.match(/\[\[param\.(.+?)\]\]/),I=N?`{{ param('${N[1]}') }}`:"";return/* @__PURE__ */c("div",{className:"space-y-4",children:[/* @__PURE__ */e(Ur,{control:a,scope:s,detail:k}),/* @__PURE__ */c("div",{className:"space-y-2",children:[/* @__PURE__ */e("p",{className:"text-[13px] font-medium text-foreground",children:"How cards use this control"}),/* @__PURE__ */c("div",{className:"divide-y divide-border/60 overflow-hidden rounded-control border border-border/60",children:[L?/* @__PURE__ */c("div",{className:"space-y-1 px-3 py-2.5",children:[/* @__PURE__ */e("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Explorer cards"}),/* @__PURE__ */e("div",{className:"text-[12px] text-muted-foreground",children:F})]}):null,/* @__PURE__ */c("div",{className:"space-y-1.5 px-3 py-2.5",children:[/* @__PURE__ */e("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"SQL cards"}),/* @__PURE__ */e(ot,{text:i,ariaLabel:"Copy SQL control reference"}),I?/* @__PURE__ */e(ot,{text:I,ariaLabel:"Copy Jinja control reference"}):null,/* @__PURE__ */c("p",{className:"text-[12px] text-muted-foreground",children:[h," ",/* @__PURE__ */e("a",{href:"https://docs.semaphor.cloud/docs/concepts/template-expressions",target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:"Template expressions docs"}),"."]})]})]})]}),/* @__PURE__ */e(Se,{secondary:/* @__PURE__ */e(B,{type:"button",variant:"outline",size:"xs",onClick:b,children:"Back"}),tertiary:/* @__PURE__ */e(B,{type:"button",variant:"outline",size:"xs",onClick:m,children:"Cancel"}),primary:/* @__PURE__ */e(B,{type:"button",size:"xs",onClick:x,children:"Done"})})]});}function Kr(t){const a=fe(t.scope,t.existingControls,t.reservedIds),s=t.type===a.type?{...a,label:Ee[t.type]}:{...kt({controls:[{...a,label:Ee[t.type]}],controlId:a.id,nextType:t.type}).controls[0],label:Ee[t.type]};return{step:2,control:s,defaultValue:he(s,void 0)};}function ya({scope:t,controls:a,reservedControlIds:s,defaultValues:i,onChange:F,emptyMessage:h,initialCreateFlow:k=!1,usageByControlId:b,availableFieldChoices:m,availableMetricChoices:x,structuralParticipants:L,structuralParticipantIdsByControlId:N,card:I,allowedControlTypes:S,onCreateFlowActiveChange:y,onCreateFlowComplete:A}){const z=P(()=>new Set(s||[]),[s]),O=br(t),X=ur(t),[D,T]=te(null),[Q,H]=te(null),[n,g]=te(()=>k?{step:1,control:fe(t,a,Array.from(z))}:null),C=Fe({}),f=Fe(void 0),d=Fe(k),l=P(()=>{const r=Ze({scope:t,card:I});if(!S)return r;const u=new Set(S);return r.filter(o=>u.has(o.value));},[S,I,t]),V=Z(r=>{const u=Ze({scope:t,card:I,includeType:S?void 0:r});if(!S)return u;const o=new Set(S);return u.filter(v=>o.has(v.value));},[S,I,t]),p=Z(r=>t==="dashboard"&&(r==="field_selector"||r==="metric_selector"),[t]),K=P(()=>n?Pe(L||[],n.control.type):[],[n,L]),E=P(()=>{if(!n)return{fields:m||[],metrics:x||[]};if(!p(n.control.type))return{fields:m||[],metrics:x||[]};const r=n.selectedCardIds||[],u=Oe({controlType:n.control.type,participants:L||[],selectedCardIds:r});return{fields:n.control.type==="field_selector"?u.choices.map(o=>({option:o,target:u.fieldTargetMap[o.value]})):[],metrics:n.control.type==="metric_selector"?u.choices.map(o=>({option:o,target:u.metricTargetMap[o.value]})):[]};},[m,x,n,p,L]);Me(()=>{y==null||y(!!n);},[n,y]),Me(()=>{const r=k&&!d.current;d.current=k,r&&(g({step:1,control:fe(t,a,Array.from(z))}),H(null),T(null));},[a,k,z,t]);const R=r=>{if(!p(r.type))return{fields:m||[],metrics:x||[]};const u=(N==null?void 0:N[r.id])||[];if(u.length===0)return{fields:m||[],metrics:x||[]};const o=Oe({controlType:r.type,participants:L||[],selectedCardIds:u});return{fields:r.type==="field_selector"?o.choices.map(v=>({option:v,target:o.fieldTargetMap[v.value]})):[],metrics:r.type==="metric_selector"?o.choices.map(v=>({option:v,target:o.metricTargetMap[v.value]})):[]};},q=r=>{if(!p(r.control.type))return{nextControl:r.control,cardBindingsById:void 0};const u=(N==null?void 0:N[r.control.id])||[],o=Oe({controlType:r.control.type,participants:L||[],selectedCardIds:r.nextSelectedCardIds}),v=Cr({control:r.control,choices:o.choices}),$=Object.fromEntries(u.filter(_=>!r.nextSelectedCardIds.includes(_)).map(_=>[_,void 0]));return r.nextSelectedCardIds.length>0&&v.source.kind==="manual"&&v.source.options.length>0&&Object.assign($,at({control:v,participants:L||[],selectedCardIds:r.nextSelectedCardIds,matrixTargetIds:r.matrixTargetIds})),{nextControl:v,cardBindingsById:$};},j=Z((r,u=i,o={type:"update"})=>{const v=r.map($=>(Ae({control:$,defaultValues:u}),pr($)));F(v,u,o);},[i,F]),Y=(r,u)=>{const o=a.find(M=>M.id===r);let v=a.map(M=>M.id!==r?M:u(M));const $=v.find(M=>M.id===r);let _,w;if($&&(!o||yr({control:o},{control:$}))&&t==="dashboard"&&($.type==="field_selector"||$.type==="metric_selector")){const M=(N==null?void 0:N[$.id])||[],ne=q({control:$,nextSelectedCardIds:M});v=v.map(re=>re.id===r?ne.nextControl:re),_=ne.cardBindingsById,w=[$.id];}else if(o&&(!$||!Nr($.type))&&t==="dashboard"&&(o.type==="field_selector"||o.type==="metric_selector")){const M=(N==null?void 0:N[o.id])||[];_=Object.fromEntries(M.map(ne=>[ne,void 0])),w=[o.id];}const G=v.find(M=>M.id===r);let W=i;if(o&&G){const M=Ae({control:o,defaultValues:i});o.source.kind==="manual"&&G.source.kind==="sql_query"&&(C.current[r]=M);const ne=M===void 0&&o.source.kind==="sql_query"&&G.source.kind==="manual"?C.current[r]:M,re=rt({previousControl:o,nextControl:G,currentDefaultValue:ne});G.source.kind==="manual"&&(C.current[r]=re),i&&(W={...i},re===void 0?delete W[r]:W[r]=re),v=v.map(He=>He.id===r?{...G,defaultValue:re}:He);}j(v,W,{type:"update",cardBindingsById:_,affectedBindingControlIds:w});},J=(r,u)=>{if(!u.trim())return;const o=wr(u);if(o===r||z.has(o)||a.some(_=>_.id===o&&_.id!==r))return;const v=a.map(_=>_.id===r?{..._,id:o}:_);if(!i){j(v,void 0,{type:"rename",oldId:r,newId:o});return;}const $={...i};Object.prototype.hasOwnProperty.call($,r)&&($[o]=$[r],delete $[r]),j(v,$,{type:"rename",oldId:r,newId:o});},Mt=r=>{const u=a.filter(v=>v.id!==r);if(!i){j(u,void 0,{type:"remove",controlId:r});return;}const o={...i};delete o[r],j(u,o,{type:"remove",controlId:r});},qt=Z(()=>{f.current=void 0,g({step:1,control:fe(t,a,Array.from(z))}),H(null),T(null);},[a,z,t]),ue=r=>{g(u=>u&&(()=>{const o=r(u.control);u.control.source.kind==="manual"&&o.source.kind==="sql_query"&&(f.current=u.defaultValue);const v=u.defaultValue===void 0&&u.control.source.kind==="sql_query"&&o.source.kind==="manual"?f.current:u.defaultValue,$=rt({previousControl:u.control,nextControl:o,currentDefaultValue:v});return o.source.kind==="manual"&&(f.current=$),{...u,control:o,defaultValue:$};})());},Ue=r=>{g(u=>u&&(u.control.source.kind==="manual"&&(f.current=r),{...u,defaultValue:r}));},ke=(()=>{if(!n)return!1;if(n.step===2&&p(n.control.type))return(n.selectedCardIds||[]).length>0&&mr({participants:L||[],selectedCardIds:n.selectedCardIds||[],control:n.control,selected:n.matrixTargetIds});if(n.step!==2&&n.step!==3||!n.control.label.trim())return!1;const u=n.control.source.kind==="sql_query"?n.control:et(n.control);if(u.source.kind==="manual"&&(fr(u)&&u.source.options.length===0||u.source.options.some(v=>v.label.trim().length===0||v.value.trim().length===0)))return!1;if(u.source.kind==="sql_query"){const{connectionId:o,sql:v,valueColumn:$}=u.source;return o.trim().length>0&&v.trim().length>0&&$.trim().length>0;}return hr(he(u,n.defaultValue));})(),We=()=>{var _;if(!n)return;const r=et(n.control),u=vr({label:r.label,fallbackId:r.id,existingControls:a,reservedIds:Array.from(z)}),o={...r,id:u},v=t==="dashboard"&&(o.type==="field_selector"||o.type==="metric_selector")&&(_=n.selectedCardIds)!=null&&_.length?at({control:o,participants:L||[],selectedCardIds:n.selectedCardIds,matrixTargetIds:n.matrixTargetIds}):void 0,$=he(o,n.defaultValue);g({step:t==="dashboard"&&(o.type==="field_selector"||o.type==="metric_selector")?4:3,control:o,defaultValue:$,createdControlId:u,selectedCardIds:n.selectedCardIds,matrixTargetIds:n.matrixTargetIds,cardBindingsById:v});},De=Z(()=>{g(null);},[]),Ke=Z(()=>{if(!(n!=null&&n.createdControlId)){g(null);return;}const r=n.control,u=n.createdControlId,o=he(r,n.defaultValue);if(i){const v={...i};o===void 0?delete v[u]:v[u]=o,j([...a,{...r,defaultValue:o}],v,{type:"add",cardBindingsById:n.cardBindingsById});}else j([...a,{...r,defaultValue:o}],void 0,{type:"add",cardBindingsById:n.cardBindingsById});H(u),g(null),A==null||A();},[a,n,i,j,A]),jt=n?p(n.control.type)?["Choose type","Select cards","Configure","Finish"]:["Choose type","Configure","Finish"]:[],Qe=n!=null&&n.createdControlId?`[[param.${n.createdControlId}]]`:n?`[[param.${gr(n.control.label)||n.control.id}]]`:"",Te=tt({controls:a,defaultValues:i}),Le=n?[...a,n.control]:a,Ye=n?tt({controls:Le,defaultValues:i,overrides:[{controlId:n.control.id,value:n.defaultValue}]}):Te;return/* @__PURE__ */c("div",{className:"space-y-4",children:[n?/* @__PURE__ */c("div",{className:"space-y-4 pb-1",children:[/* @__PURE__ */e(Br,{currentStep:n.step,labels:jt}),n.step===1&&(()=>{const r=/* @__PURE__ */new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]),u=/* @__PURE__ */new Set(["date","text"]),o=l.filter(_=>!r.has(_.value)&&!u.has(_.value)),v=l.filter(_=>r.has(_.value)),$=_=>/* @__PURE__ */c("button",{type:"button",className:"rounded-control border border-border/60 bg-background px-3 py-2.5 text-left transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:outline-none",onClick:()=>g(Kr({scope:t,existingControls:a,reservedIds:Array.from(z),type:_.value})),children:[/* @__PURE__ */e("div",{className:"text-[13px] font-medium text-foreground",children:_.label}),/* @__PURE__ */e("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:_.description})]},_.value);return/* @__PURE__ */c("div",{className:"space-y-4",children:[t==="card"&&(I==null?void 0:I.sql)==null?/* @__PURE__ */e("p",{className:"text-[12px] text-muted-foreground",children:"Explorer cards support displayed metric, group by field, aggregation, and time grain controls here."}):null,o.length>0&&/* @__PURE__ */c("div",{className:"space-y-1.5",children:[/* @__PURE__ */e("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Input controls"}),/* @__PURE__ */e("div",{className:"grid gap-1.5 sm:grid-cols-2",children:o.map($)})]}),v.length>0&&/* @__PURE__ */c("div",{className:"space-y-1.5",children:[/* @__PURE__ */e("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Data-driven controls"}),/* @__PURE__ */e("div",{className:"grid gap-1.5 sm:grid-cols-2",children:v.map($)})]}),/* @__PURE__ */e(Se,{secondary:/* @__PURE__ */e(B,{type:"button",variant:"outline",size:"xs",onClick:De,children:"Back to controls"})})]});})(),n.step===2&&p(n.control.type)&&/* @__PURE__ */c("div",{className:"space-y-3",children:[/* @__PURE__ */c("div",{className:"space-y-3",children:[/* @__PURE__ */e(Ft,{control:n.control,onChange:r=>ue(u=>({...u,label:r}))}),/* @__PURE__ */e("p",{className:"text-[12px] text-muted-foreground",children:"Choose which cards should respond to this shared control."})]}),K.length===0?/* @__PURE__ */e("div",{className:"rounded-control border border-border/60 bg-muted/30 px-3 py-2.5 text-[12px] text-muted-foreground",children:"No eligible cards are available yet. Add compatible metrics or group-by fields to cards first."}):/* @__PURE__ */e("div",{className:"space-y-1 rounded-control border border-border/60 bg-background p-2",children:K.map(r=>{const u=(n.selectedCardIds||[]).includes(r.cardId);return/* @__PURE__ */c("label",{className:"flex items-start gap-2 rounded-control px-1.5 py-1 text-[13px] hover:bg-muted/40",children:[/* @__PURE__ */e(Jt,{checked:u,onCheckedChange:o=>g(v=>v&&{...v,selectedCardIds:o===!0?[...(v.selectedCardIds||[]),r.cardId]:(v.selectedCardIds||[]).filter($=>$!==r.cardId)})}),/* @__PURE__ */c("div",{className:"min-w-0",children:[/* @__PURE__ */e("div",{className:"font-medium text-foreground",children:r.title}),/* @__PURE__ */e("div",{className:"text-[12px] text-muted-foreground",children:n.control.type==="field_selector"?`${r.fieldChoices.length} compatible group-by fields`:`${r.metricChoices.length} compatible metrics`})]})]},r.cardId);})}),/* @__PURE__ */e(st,{participants:K,selectedCardIds:n.selectedCardIds||[],control:n.control,selected:n.matrixTargetIds,onChange:(r,u)=>g(o=>o&&{...o,matrixTargetIds:{...o.matrixTargetIds,[r]:u}})}),/* @__PURE__ */e(Se,{secondary:/* @__PURE__ */e(B,{type:"button",variant:"outline",size:"xs",onClick:()=>g(r=>r&&{...r,step:1,selectedCardIds:[]}),children:"Back"}),primary:/* @__PURE__ */e(B,{type:"button",size:"xs",onClick:()=>g(r=>r&&{...r,step:3}),disabled:!ke,children:"Next"})})]}),n.step===2&&!p(n.control.type)&&/* @__PURE__ */e(it,{control:n.control,defaultValue:n.defaultValue,availableFieldChoices:E.fields,availableMetricChoices:E.metrics,previewControlDefinitions:Le,previewControlValues:Ye,onControlChange:r=>ue(()=>r),onLabelChange:r=>ue(u=>({...u,label:r})),onDefaultValueChange:Ue,onBack:()=>g(r=>r&&{...r,step:1}),onNext:We,nextDisabled:!ke}),n.step===3&&p(n.control.type)&&/* @__PURE__ */e(it,{control:n.control,defaultValue:n.defaultValue,availableFieldChoices:E.fields,availableMetricChoices:E.metrics,previewControlDefinitions:Le,previewControlValues:Ye,onControlChange:r=>ue(()=>r),onLabelChange:r=>ue(u=>({...u,label:r})),onDefaultValueChange:Ue,onBack:()=>g(r=>r&&{...r,step:2}),onNext:We,nextDisabled:!ke}),n.step===3&&!p(n.control.type)&&/* @__PURE__ */e(dt,{control:n.control,scope:t,createdReference:Qe,explorerContent:/* @__PURE__ */c(me,{children:["Open the card and use"," ",/* @__PURE__ */e("span",{className:"font-medium text-foreground",children:"Settings → Controls"})," ","to choose what this control changes."]}),sqlDescription:"Reference this control directly in the SQL editor.",onBack:()=>g(r=>r&&{...r,step:2}),onCancel:De,onDone:Ke}),n.step===4&&p(n.control.type)&&/* @__PURE__ */e(dt,{control:n.control,scope:t,createdReference:Qe,summaryDetail:/* @__PURE__ */c(me,{children:["Used by ",(n.selectedCardIds||[]).length," selected card",(n.selectedCardIds||[]).length===1?"":"s"]}),explorerContent:/* @__PURE__ */e(me,{children:"Selected cards have been set up to respond to this control automatically."}),sqlDescription:"SQL cards can still reference this control directly in the SQL editor.",onBack:()=>g(r=>r&&{...r,step:3}),onCancel:De,onDone:Ke})]}):null,!n&&a.length===0?/* @__PURE__ */e("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:h}):null,!n&&a.map(r=>{const u=R(r),o=b==null?void 0:b[r.id],v=Ae({control:r,defaultValues:i}),$=Q===r.id,_="inline-flex shrink-0 items-center rounded-[4px] border border-border/60 bg-muted/40 px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground";return/* @__PURE__ */c("div",{className:"rounded-control border border-border/60",children:[/* @__PURE__ */c("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[/* @__PURE__ */c("button",{type:"button",className:"flex min-w-0 flex-1 items-start gap-2 rounded-control text-left focus:outline-none focus-visible:bg-muted/40",onClick:()=>H(w=>w===r.id?null:r.id),children:[$?/* @__PURE__ */e(ge,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):/* @__PURE__ */e(Xe,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */c("div",{className:"min-w-0",children:[/* @__PURE__ */c("div",{className:"flex flex-wrap items-center gap-1.5",children:[/* @__PURE__ */e("span",{className:"truncate text-[13px] font-medium text-foreground",children:r.label||"Untitled control"}),/* @__PURE__ */e("span",{className:_,children:Ct(r.type).label}),/* @__PURE__ */e("span",{className:_,children:wt(t,r.placement)})]}),/* @__PURE__ */c("div",{className:"mt-0.5 text-[12px] text-muted-foreground",children:[St(r),o!=null&&o.status?` · ${o.status}`:""]})]})]}),/* @__PURE__ */e(B,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground",onClick:()=>Mt(r.id),"aria-label":`Remove ${r.label}`,children:/* @__PURE__ */e(mt,{className:"h-3.5 w-3.5"})})]}),$&&/* @__PURE__ */c("div",{className:"space-y-4 border-t border-border/60 px-3 py-3",children:[/* @__PURE__ */c("div",{className:"grid gap-3 md:grid-cols-3",children:[/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(ae,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),/* @__PURE__ */e(be,{size:"xs",value:r.label,placeholder:"Control label",onChange:w=>Y(r.id,G=>({...G,label:w.target.value}))})]}),/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(ae,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Type"}),/* @__PURE__ */c(le,{value:r.type,onValueChange:w=>{const G=kt({controls:a,controlId:r.id,nextType:w,defaultValues:i});j(G.controls,G.defaultValues);},children:[/* @__PURE__ */e(ie,{size:"xs",children:/* @__PURE__ */e(oe,{})}),/* @__PURE__ */e(de,{children:V(r.type).map(w=>/* @__PURE__ */e(ee,{value:w.value,children:w.label},w.value))})]})]}),/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(ae,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Show in"}),/* @__PURE__ */c(le,{value:r.placement||X,onValueChange:w=>Y(r.id,G=>({...G,placement:w})),children:[/* @__PURE__ */e(ie,{size:"xs",children:/* @__PURE__ */e(oe,{})}),/* @__PURE__ */e(de,{children:O.map(w=>/* @__PURE__ */e(ee,{value:w.value,children:w.label},w.value))})]})]})]}),p(r.type)?/* @__PURE__ */c(me,{children:[/* @__PURE__ */e($r,{type:r.type,participants:Pe(L||[],r.type).map(w=>({cardId:w.cardId,title:w.title,choiceCount:r.type==="field_selector"?w.fieldChoices.length:w.metricChoices.length})),selectedCardIds:(N==null?void 0:N[r.id])||[],onChange:w=>{const G=q({control:r,nextSelectedCardIds:w}),W=a.map(M=>M.id===r.id?G.nextControl:M);j(W,i,{type:"update",cardBindingsById:G.cardBindingsById});}}),/* @__PURE__ */e(st,{participants:L||[],selectedCardIds:(N==null?void 0:N[r.id])||[],control:r,onChange:(w,G)=>{const W=q({control:r,nextSelectedCardIds:(N==null?void 0:N[r.id])||[],matrixTargetIds:{[w]:G}});j(a.map(M=>M.id===r.id?W.nextControl:M),i,{type:"update",cardBindingsById:W.cardBindingsById});}})]}):null,/* @__PURE__ */e(At,{control:r,availableFieldChoices:u.fields,availableMetricChoices:u.metrics,previewControlDefinitions:a,previewControlValues:Te,controlLifecycle:"edit",onChange:w=>Y(r.id,()=>w)}),r.initialValueStrategy==="saved_default"&&/* @__PURE__ */e(Et,{control:r,value:v,allowNoDefault:!0,allowCardDefault:!0,previewControlDefinitions:a,previewControlValues:Te,onChange:w=>{const G=a.map(W=>W.id===r.id?{...W,defaultValue:w}:W);if(r.source.kind==="manual"&&(C.current[r.id]=w),i){const W={...i};w===void 0?delete W[r.id]:W[r.id]=w,j(G,W);return;}j(G,void 0);}}),/* @__PURE__ */c(Fr,{open:D===r.id,onOpenChange:w=>T(w?r.id:null),children:[/* @__PURE__ */e(Ir,{asChild:!0,children:/* @__PURE__ */c(B,{type:"button",variant:"ghost",size:"xs",className:"-ml-2 gap-1 text-muted-foreground hover:text-foreground",children:[D===r.id?/* @__PURE__ */e(ge,{className:"h-3.5 w-3.5"}):/* @__PURE__ */e(Xe,{className:"h-3.5 w-3.5"}),"Advanced"]})}),/* @__PURE__ */c(Vr,{className:"space-y-3 pt-2",children:[/* @__PURE__ */c("div",{className:"grid gap-3 md:grid-cols-2",children:[/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(ae,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Variable name"}),/* @__PURE__ */e(_r,{controlId:r.id,onCommit:w=>J(r.id,w)},r.id)]}),/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(ae,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Initial value"}),/* @__PURE__ */c(le,{value:r.initialValueStrategy,onValueChange:w=>Y(r.id,G=>({...G,initialValueStrategy:w})),children:[/* @__PURE__ */e(ie,{size:"xs",children:/* @__PURE__ */e(oe,{})}),/* @__PURE__ */e(de,{children:xr.map(w=>/* @__PURE__ */e(ee,{value:w.value,children:w.label},w.value))})]})]})]}),/* @__PURE__ */e(Rr,{control:r,onChange:w=>Y(r.id,()=>w)})]})]})]})]},r.id);}),!n&&/* @__PURE__ */c(B,{type:"button",variant:"outline",size:"xs",onClick:qt,children:[/* @__PURE__ */e(Ve,{className:"h-3.5 w-3.5"}),"Add control"]})]});}function Na(t){const{open:a,onOpenChange:s,initialCreateFlowActive:i=!1,dismissMode:F="passive"}=t,h=a!==void 0,[k,b]=te(!1),[m,x]=te(i),L=h?a:k,N=Z(y=>{!y&&m&&F==="passive"||(h||b(y),y||x(!1),s==null||s(y));},[h,m,F,s]),I=Z(()=>{h||b(!1),x(!1),s==null||s(!1);},[h,s]);Me(()=>{L||x(!1);},[L]);const S=Z(y=>{m&&y.preventDefault();},[m]);return{forceClose:I,handleOpenChange:N,isCreateFlowActive:m,preventPassiveDismissDuringCreate:S,resolvedOpen:L,setIsCreateFlowActive:x};}function It(t){const{relativeMeta:a,latestValue:s,...i}=t;return i;}function qe(t,a){const s=It(t);return a.relativeMeta?{...s,value:a.value,relativeMeta:a.relativeMeta}:{...s,value:a.value};}function Qr(t,a){const s=a==="in"||a==="not in"||a==="between"||a==="not between"?[]:a==="isNull"||a==="isNotNull"?null:"";return qe({...t,operator:a},{value:s});}function Yr(t,a){const s=ye(a.dataType)==="date";return qe({...t,field:a,operator:s?"between":"="},{value:""});}function Hr({initialFilters:t,availableFields:a,onChange:s}={}){const[i,F]=te(t||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]}),h=g=>{F(g),s==null||s(g);};pe(g=>g.card.dataSource);const{filterableFields:k,isLoading:b}=Pt(),m=a||k||[],x={id:"default",qualifiedFieldName:"default",name:"default",dataType:"string",label:"Default",entityId:"default",entityName:"Default",entityType:"table"},L=g=>{const C=f=>{if(f.id===g){const d=m[0]||x,l=ye(d.dataType)==="date";return{...f,conditions:[...f.conditions,{id:`condition-${Date.now()}`,field:d,operator:l?"between":"=",value:l?[]:""}]};}return{...f,groups:f.groups.map(C)};};h(C(i));},N=g=>{const C=f=>{if(f.id===g){const d=m[0]||x,l=ye(d.dataType)==="date";return{...f,groups:[...f.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:d,operator:l?"between":"=",value:l?[]:""}],groups:[]}]};}return{...f,groups:f.groups.map(C)};};h(C(i));},I=(g,C)=>{const f=d=>d.id===g?{...d,conditions:d.conditions.filter(l=>l.id!==C)}:{...d,groups:d.groups.map(f)};h(f(i));},S=(g,C)=>{const f=d=>d.id===g?{...d,groups:d.groups.filter(l=>l.id!==C)}:{...d,groups:d.groups.map(f)};h(f(i));},y=(g,C,f)=>{const d=l=>l.id===g?{...l,conditions:l.conditions.map(V=>V.id===C?f(V):V)}:{...l,groups:l.groups.map(d)};h(d(i));},A=(g,C,f)=>y(g,C,d=>({...("value"in f||"operator"in f||"field"in f?It(d):d),...f})),z=(g,C,f)=>y(g,C,()=>f),O=er(),X=(g,C)=>{const f=d=>d.id===g?{...d,logicalOperator:C}:{...d,groups:d.groups.map(f)};h(f(i));},D=(g,C)=>{const f=d=>d.id===g?{...d,negate:C}:{...d,groups:d.groups.map(f)};h(f(i));},T=(g,C,f)=>{const d=l=>l.id===g?{...l,conditions:lt(l.conditions,C,f)}:{...l,groups:l.groups.map(d)};h(d(i));},Q=(g,C,f)=>{const d=l=>l.id===g?{...l,groups:lt(l.groups,C,f)}:{...l,groups:l.groups.map(d)};h(d(i));},H=g=>{if(!g||g.conditions.length===0&&g.groups.length===0)return"-- No filters defined";const C=d=>{let l="";typeof d.field=="object"?l=d.field.entityName?`${d.field.entityName}.${d.field.name}`:d.field.name:l=String(d.field);const V=d.operator;let p=d.value;if(d.latestValue&&V==="=")return`${l} = ${ft} /* the latest value each time the card runs */`;const K=Dt(d.relativeMeta);if(K&&Ar(V)&&Tt(V,K)){const E=Mr(V,K),{label:R,range:q}=Je(K,{tz:(O==null?void 0:O.tz)??"UTC",weekStart:(O==null?void 0:O.weekStart)??1,anchor:(O==null?void 0:O.anchor)??"now",...(O!=null&&O.workDays?{workDays:O.workDays}:{})}),j=E?qr(E):R;if(q){const[Y]=Lt(V,[q.start,q.end]);return`${l} ${V} '${Y.toISOString()}' /* ${j}: the date updates each time the card runs */`;}return`${l} ${V} ${j} /* the date follows your calendar each time the card runs */`;}if(K&&(V==="between"||V==="not between")){const E=V==="between"?"BETWEEN":"NOT BETWEEN",{label:R,range:q}=Je(K,{tz:(O==null?void 0:O.tz)??"UTC",weekStart:(O==null?void 0:O.weekStart)??1,anchor:(O==null?void 0:O.anchor)??"now",...(O!=null&&O.workDays?{workDays:O.workDays}:{})});return q?`${l} ${E} '${q.start.toISOString()}' AND '${q.end.toISOString()}' /* ${R}: dates update each time the card runs */`:Ot(K).dataAnchored?`${l} ${E} ${R} /* dates count back from the latest data each time the card runs */`:`${l} ${E} ${R} /* dates follow your calendar each time the card runs */`;}if(d.field.dataType==="string"&&!["in","not in"].includes(d.operator))typeof p=="string"?p=`'${p}'`:Array.isArray(p)&&(p=`'${p.join(", ")}'`);else if(d.field.dataType==="date"||d.field.dataType==="datetime"||d.field.dataType==="timestamp"){if(d.operator==="between"&&Array.isArray(p)&&p.length===2){const E=p[0]?`'${p[0]}'`:"NULL",R=p[1]?`'${p[1]}'`:"NULL";return`${l} BETWEEN ${E} AND ${R}`;}else if((d.operator==="in"||d.operator==="not in")&&Array.isArray(p)){const E=p.map(R=>R?`'${R}'`:"NULL").join(", ");return`${l} ${V} (${E})`;}else typeof p=="string"||p instanceof Date?p=`'${p}'`:Array.isArray(p)&&p.length>0&&(p=`'${p[0]}'`);}else if(["in","not in"].includes(d.operator)){let E=[];Array.isArray(p)?E=p.map(R=>typeof R=="string"?`'${R}'`:String(R)):typeof p=="string"?E=p.split(",").map(R=>{const q=R.trim();return d.field.dataType==="string"?`'${q}'`:q;}):typeof p=="number"&&(E=[String(p)]),p=`(${E.join(", ")})`;}switch(V){case"contains":return typeof p=="string"?`${l} LIKE '%${p.replace(/'/g,"")}'`:`${l} LIKE '%${String(p)}'`;case"startsWith":return typeof p=="string"?`${l} LIKE '${p.replace(/'/g,"")}%'`:`${l} LIKE '${String(p)}%'`;case"endsWith":return typeof p=="string"?`${l} LIKE '%${p.replace(/'/g,"")}'`:`${l} LIKE '%${String(p)}'`;case"isNull":return`${l} IS NULL`;case"isNotNull":return`${l} IS NOT NULL`;default:return`${l} ${V} ${p}`;}},f=d=>{const l=d.conditions.map(C),V=d.groups.map(R=>f(R)),p=[...l,...V].filter(Boolean);if(p.length===0)return"";const K=p.join(` ${d.logicalOperator} `),E=p.length>1?`(${K})`:K;return d.negate?`NOT ${E}`:E;};return f(g);},n=i.conditions.length>0||i.groups.length>0;return{currentFilters:i,setCurrentFilters:h,availableFields:m,isLoading:b,addCondition:L,addGroup:N,removeCondition:I,removeGroup:S,updateConditionFields:A,replaceCondition:z,updateGroupOperator:X,updateGroupNegate:D,reorderConditions:T,reorderGroups:Q,generateSQLPreview:H,hasAnyFilters:n};}function Vt(t,a){const s=pe(x=>x.card.dataSource),i=pe(x=>x.card.connectionId),F=pe(x=>x.selectedConnectionId),{dataSource:h,connectionId:k}=a?nt(a):nt({dataSource:s,connectionId:i},F),b=P(()=>({id:`card-filter-option:${t.id}`,...Sr(t,{dataSource:h,connectionId:k})}),[k,h,t]),m=P(()=>tr({filter:b}),[b]);return rr(b,{inputContext:m,currentSelectionPolicy:"exclude"});}function Xr({field:t,source:a,selected:s,onChange:i,placeholder:F="Select values…",className:h}){const[k,b]=we.useState(!1),m=Vt(t,a),x=we.useMemo(()=>new Set(s.map(S=>ce(S))),[s]),L=S=>{var y,A;return((A=(y=m.allRecords.find(z=>ce(z.value)===ce(S)))==null?void 0:y.label)==null?void 0:A.toString())??S;},N=S=>{i(s.filter(y=>y!==S));},I=S=>{b(S),!S&&m.query&&m.setQuery("");};return/* @__PURE__ */e("div",{className:U("w-full",h),children:/* @__PURE__ */c(ht,{open:k,onOpenChange:I,modal:!0,children:[/* @__PURE__ */e(gt,{asChild:!0,children:/* @__PURE__ */c(B,{variant:"outline",size:"xs",role:"combobox","aria-expanded":k,className:"h-auto min-h-7 w-full justify-between gap-1.5 px-2 py-0.5 font-normal",children:[/* @__PURE__ */e("div",{className:"flex min-w-0 flex-1 flex-wrap gap-1",children:s.length>0?s.map(S=>{const y=L(S);return(/* @__PURE__ */c("span",{className:"inline-flex max-w-full items-center gap-1 rounded-[4px] border border-border/70 bg-muted/40 px-1.5 py-0.5 text-[11px] leading-[14px] text-foreground",children:[/* @__PURE__ */e("span",{className:"truncate",children:y}),/* @__PURE__ */e("span",{role:"button",tabIndex:0,"aria-label":`Remove ${y}`,className:"shrink-0 rounded-[2px] text-muted-foreground outline-none hover:text-foreground focus-visible:ring-1 focus-visible:ring-ring",onKeyDown:A=>{A.key==="Enter"&&N(S);},onMouseDown:A=>{A.preventDefault(),A.stopPropagation();},onClick:A=>{A.stopPropagation(),N(S);},children:/* @__PURE__ */e(bt,{className:"h-3 w-3"})})]},S));}):/* @__PURE__ */e("span",{className:"truncate text-muted-foreground",children:F})}),/* @__PURE__ */e(ge,{className:"h-3.5 w-3.5 shrink-0 opacity-50"})]})}),/* @__PURE__ */e(xt,{className:"w-[var(--radix-popover-trigger-width)] min-w-[240px] rounded-control p-1.5",align:"start",onOpenAutoFocus:S=>{var y,A;S.preventDefault(),(A=(y=S.currentTarget)==null?void 0:y.querySelector('input[type="text"]'))==null||A.focus();},children:/* @__PURE__ */e(vt,{records:m.displayRecords,selectedIdentities:x,onToggle:S=>{const y=String(S.value);s.includes(y)?N(y):i([...s,y]);},browse:m,searchPlaceholder:`Search ${(t.label||t.name).toLowerCase()}`,listLabel:t.label||t.name,density:"compact"})})]})});}function Jr({field:t,source:a,value:s,onChange:i,placeholder:F="Select value…",className:h}){var I,S;const[k,b]=we.useState(!1),m=Vt(t,a),x=we.useMemo(()=>new Set(s?[ce(s)]:[]),[s]),L=s?((S=(I=m.allRecords.find(y=>ce(y.value)===ce(s)))==null?void 0:I.label)==null?void 0:S.toString())??s:"",N=y=>{b(y),!y&&m.query&&m.setQuery("");};return/* @__PURE__ */c(ht,{open:k,onOpenChange:N,modal:!0,children:[/* @__PURE__ */e(gt,{asChild:!0,children:/* @__PURE__ */c(B,{variant:"outline",size:"xs",role:"combobox","aria-expanded":k,className:U("min-w-0 flex-1 justify-between gap-1.5 px-2 font-normal",h),children:[/* @__PURE__ */e("span",{className:U("truncate",!s&&"text-muted-foreground"),children:s?L:F}),/* @__PURE__ */e(ge,{className:"h-3.5 w-3.5 shrink-0 opacity-50"})]})}),/* @__PURE__ */e(xt,{className:"w-[var(--radix-popover-trigger-width)] min-w-[240px] rounded-control p-1.5",align:"start",onOpenAutoFocus:y=>{var A,z;y.preventDefault(),(z=(A=y.currentTarget)==null?void 0:A.querySelector('input[type="text"]'))==null||z.focus();},children:/* @__PURE__ */e(vt,{records:m.displayRecords,selectedIdentities:x,onToggle:y=>{i(String(y.value)),N(!1);},selectionMode:"single",browse:m,searchPlaceholder:`Search ${(t.label||t.name).toLowerCase()}`,listLabel:t.label||t.name,density:"compact"})})]});}function Zr({value:t,operator:a,relativeMeta:s,latestValue:i,field:F,onChange:h,className:k}){const b=ar(),m=nr(),x=a==="between"||a==="not between",L=Tt(a),N=L?s:void 0,I=P(()=>{if(!x||!s)return;const D=m(s);return{...D,tooltip:D.dates?void 0:Ot(s).dataAnchored?sr:lr};},[x,s,m]),S=P(()=>{if(x){if(I){const{range:D}=I;return D?{from:D.start,to:D.end}:void 0;}if(t&&Array.isArray(t)&&t.length===2){const D=$e(t[0],b,"start"),T=$e(t[1],b,"end");if(D&&T)return{from:D,to:T};}}},[t,x,I,b]),y=P(()=>{if(!t||x||i)return;const D=Array.isArray(t)?t[0]:t;return $e(D,b,"start");},[t,x,i,b]),A=D=>a==="<="||a===">"?Tr(D,b):Lr(D,b);return/* @__PURE__ */e(ir,{value:x?S:void 0,selectionMode:x?"range":"single",singleValue:x?void 0:y,singleValueLabel:!x&&i?ft:void 0,onChange:D=>{if(D!=null&&D.from&&D.to){h({value:[D.from.toISOString(),D.to.toISOString()]});return;}h({value:[]});},onSingleChange:D=>{if(!D){h({value:""});return;}const T=A(D),Q=Dr(T,a,{timezone:b});h({value:typeof Q=="string"?Q:Q.toISOString()});},onRelativeSelect:L?(D,T)=>{if(!D.from||!D.to){h({value:x?[]:""});return;}const Q=Lt(a,[D.from.toISOString(),D.to.toISOString()]);h({value:Q.length===1?Q[0]:Q,relativeMeta:T});}:void 0,relativeValue:N,comparisonValue:!x&&L?a:void 0,relativePoints:!x&&L?{operator:a}:"none",relativeSummary:I,supplementalFooter:L?/* @__PURE__ */e("p",{className:"border-t border-border px-3 py-2 text-[11px] text-muted-foreground",children:"Presets and Relative update each time the card runs. Static dates stay fixed."}):void 0,timezone:b,enableTimePrecision:kr(F),staticTimeInputs:!1,showRelativeTab:L,className:U("min-w-0",k),buttonClassName:"h-7 text-[12px] [&>span]:text-[12px]",placeholder:"Select date…"});}const Pr=t=>t.conditions.length>0||t.groups.length>0,je=["contains","startsWith","endsWith","like","not like"],ea=["=","!=",">",">=","<","<=",...je,"in","not in","isNull","isNotNull"],ta=["=","!=",...je,"in","not in","isNull","isNotNull"],ra=["=","!=",">",">=","<","<=","in","not in","isNull","isNotNull"],aa=["=","!=","isNull","isNotNull"],na=["between","=","!=","<","<=",">",">=","isNull","isNotNull"],sa={"=":"Equals","!=":"Not equals",">":"Greater than",">=":"Greater than or equal","<":"Less than","<=":"Less than or equal",contains:"Contains",startsWith:"Starts with",endsWith:"Ends with",like:"Like","not like":"Not like",in:"In","not in":"Not in",between:"Between",isNull:"Is null",isNotNull:"Is not null","not between":"Not between"};function Ie(t){return sa[t]||Or(t);}function la(t){switch(t){case"string":return ta;case"number":return ra;case"boolean":return aa;case"date":return na;default:return ea;}}const _t="w-[68px] shrink-0",ct="group-data-[inline]/filters:w-auto group-data-[inline]/filters:min-w-0 group-data-[inline]/filters:flex-1 group-data-[inline]/filters:shrink",Be="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Rt({value:t,onValueChange:a,"aria-label":s}){return/* @__PURE__ */c(le,{value:t,onValueChange:i=>a(i),children:[/* @__PURE__ */e(ie,{size:"xs","aria-label":s,className:U(_t,"font-medium"),children:/* @__PURE__ */e(oe,{})}),/* @__PURE__ */c(de,{className:"min-w-[var(--radix-select-trigger-width)]",children:[/* @__PURE__ */e(ee,{value:"AND",className:"text-[12px] font-medium",children:"AND"}),/* @__PURE__ */e(ee,{value:"OR",className:"text-[12px] font-medium",children:"OR"})]})]});}function zt({condition:t,index:a,groupId:s,groupLogicalOperator:i,onRemoveCondition:F,onUpdateGroupOperator:h,availableFields:k,source:b,updateConditionFields:m,replaceCondition:x}){const{attributes:L,listeners:N,setNodeRef:I,transform:S,transition:y,isDragging:A}=$t({id:t.id}),z={transform:yt.Transform.toString(S),transition:y},O=ye(t.field.dataType),X=t.operator==="isNull"||t.operator==="isNotNull",D=t.operator==="in"||t.operator==="not in";return/* @__PURE__ */c("div",{ref:I,style:z,className:U("flex items-center gap-2 rounded-control px-1.5 py-1 transition-colors hover:bg-muted/40",A&&"z-50 opacity-50"),children:[/* @__PURE__ */e("button",{type:"button",...L,...N,"aria-label":"Drag to reorder condition",className:"flex h-7 w-5 shrink-0 cursor-grab items-center justify-center rounded-control text-muted-foreground/60 hover:text-foreground focus-visible:outline-none active:cursor-grabbing",children:/* @__PURE__ */e(Nt,{className:"h-3.5 w-3.5"})}),a>0?/* @__PURE__ */e(Rt,{value:i,onValueChange:T=>h(s,T),"aria-label":"Logical operator"}):/* @__PURE__ */e("span",{className:U(_t,"text-center",Be),children:"Where"}),/* @__PURE__ */e(cr,{value:t.field,onValueChange:T=>{x(s,t.id,Yr(t,T));},availableFields:k,placeholder:"Select field",className:U("w-60 shrink-0",ct)}),/* @__PURE__ */c(le,{value:t.operator,onValueChange:T=>x(s,t.id,Qr(t,T)),children:[/* @__PURE__ */e(ie,{size:"xs","aria-label":"Operator",className:U("w-40 shrink-0",ct),children:/* @__PURE__ */e(oe,{children:t.operator?Ie(t.operator):""})}),/* @__PURE__ */e(de,{children:la(O).map(T=>/* @__PURE__ */e(ee,{value:T,children:Ie(T)},T))})]}),X?/* @__PURE__ */e("div",{className:"min-w-0 flex-1"}):O==="string"?D?/* @__PURE__ */e(Xr,{field:t.field,source:b,selected:Array.isArray(t.value)&&t.value.every(T=>typeof T=="string")?t.value:[],onChange:T=>m(s,t.id,{value:T}),placeholder:"Select values…",className:"min-w-0 flex-1"}):je.includes(t.operator)?/* @__PURE__ */e(be,{size:"xs",value:typeof t.value=="string"?t.value:"",onChange:T=>m(s,t.id,{value:T.target.value}),className:"min-w-0 flex-1",placeholder:`${Ie(t.operator)}…`}):/* @__PURE__ */e(Jr,{field:t.field,source:b,value:typeof t.value=="string"?t.value:"",onChange:T=>m(s,t.id,{value:T}),placeholder:"Select value…",className:"min-w-0 flex-1"}):O==="boolean"?/* @__PURE__ */c(le,{value:typeof t.value=="boolean"?String(t.value):"",onValueChange:T=>m(s,t.id,{value:T==="true"}),children:[/* @__PURE__ */e(ie,{size:"xs",className:"min-w-0 flex-1",children:/* @__PURE__ */e(oe,{placeholder:"Select value…"})}),/* @__PURE__ */c(de,{children:[/* @__PURE__ */e(ee,{value:"true",children:"True"}),/* @__PURE__ */e(ee,{value:"false",children:"False"})]})]}):O==="date"?/* @__PURE__ */e(Zr,{value:t.value,operator:t.operator,relativeMeta:Dt(t.relativeMeta),latestValue:t.latestValue===!0,field:t.field,onChange:T=>x(s,t.id,qe(t,T)),className:"min-w-0 flex-1"}):/* @__PURE__ */e(be,{size:"xs",value:typeof t.value=="string"||typeof t.value=="number"?t.value:"",onChange:T=>m(s,t.id,{value:T.target.value}),className:"min-w-0 flex-1",placeholder:D?"value1, value2, value3":"Value"}),/* @__PURE__ */e(B,{variant:"ghost",size:"xs","aria-label":"Remove condition",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground hover:text-foreground",onClick:()=>F(s,t.id),children:/* @__PURE__ */e(bt,{className:"h-3.5 w-3.5"})})]});}const ut="group-data-[inline]/filters:h-auto group-data-[inline]/filters:gap-1 group-data-[inline]/filters:border-0 group-data-[inline]/filters:bg-transparent group-data-[inline]/filters:px-0 group-data-[inline]/filters:py-0.5 group-data-[inline]/filters:text-[11px] group-data-[inline]/filters:font-medium group-data-[inline]/filters:text-muted-foreground group-data-[inline]/filters:shadow-none group-data-[inline]/filters:underline-offset-2 group-data-[inline]/filters:hover:bg-transparent group-data-[inline]/filters:hover:text-foreground group-data-[inline]/filters:hover:underline";function Gt({onAddCondition:t,onAddGroup:a}){return/* @__PURE__ */c("div",{className:"mt-2 flex items-center gap-1.5 group-data-[inline]/filters:mt-1 group-data-[inline]/filters:gap-3",children:[/* @__PURE__ */c(B,{type:"button",size:"xs",variant:"outline",className:U("gap-1.5",ut),onClick:t,children:[/* @__PURE__ */e(Ve,{className:"h-3 w-3"}),"Add condition"]}),a&&/* @__PURE__ */c(B,{type:"button",size:"xs",variant:"ghost",className:U("gap-1.5 text-muted-foreground hover:text-foreground",ut),onClick:a,children:[/* @__PURE__ */e(Ve,{className:"h-3 w-3"}),"Add group"]})]});}function ia({group:t,depth:a,parentGroupId:s,onUpdateGroupOperator:i,onUpdateGroupNegate:F,onRemoveGroup:h,onRemoveCondition:k,onReorderConditions:b,onReorderGroups:m,onAddCondition:x,onAddGroup:L,availableFields:N,source:I,renderFilterGroup:S,updateConditionFields:y,replaceCondition:A}){const{attributes:z,listeners:O,setNodeRef:X,transform:D,transition:T,isDragging:Q}=$t({id:t.id}),H={transform:yt.Transform.toString(D),transition:T},n=C=>{const{active:f,over:d}=C;if(d&&f.id!==d.id){const l=t.conditions.findIndex(p=>p.id===f.id),V=t.conditions.findIndex(p=>p.id===d.id);l!==-1&&V!==-1&&b(t.id,l,V);}},g=C=>{const{active:f,over:d}=C;if(d&&f.id!==d.id&&s){const l=t.groups.findIndex(p=>p.id===f.id),V=t.groups.findIndex(p=>p.id===d.id);l!==-1&&V!==-1&&m(s,l,V);}};return/* @__PURE__ */c("div",{ref:X,style:H,className:U(a>0&&"mt-2 overflow-hidden rounded-[6px] border border-border/60",Q&&"z-50 opacity-50"),children:[a>0&&/* @__PURE__ */c("div",{className:"flex items-center justify-between gap-2 border-b border-border/60 bg-muted/40 px-2 py-1",children:[/* @__PURE__ */c("div",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */e("button",{type:"button",...z,...O,"aria-label":"Drag to reorder group",className:"flex h-7 w-5 shrink-0 cursor-grab items-center justify-center rounded-control text-muted-foreground/60 hover:text-foreground focus-visible:outline-none active:cursor-grabbing",children:/* @__PURE__ */e(Nt,{className:"h-3.5 w-3.5"})}),/* @__PURE__ */e(B,{type:"button",variant:t.negate?"default":"outline",size:"xs","aria-pressed":t.negate,className:"px-2",onClick:()=>F(t.id,!t.negate),children:"NOT"}),/* @__PURE__ */e(Rt,{value:t.logicalOperator,onValueChange:C=>i(t.id,C),"aria-label":"Group logical operator"}),/* @__PURE__ */e("span",{className:Be,children:"Group"})]}),/* @__PURE__ */e(B,{type:"button",variant:"ghost",size:"xs","aria-label":"Remove group",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:()=>s&&h(s,t.id),children:/* @__PURE__ */e(mt,{className:"h-3.5 w-3.5"})})]}),/* @__PURE__ */c("div",{className:U(a>0&&"p-2"),children:[/* @__PURE__ */e(xe,{sensors:_e(se(ze),se(Re,{coordinateGetter:Ge})),collisionDetection:ve,onDragEnd:n,children:/* @__PURE__ */e(Ne,{items:t.conditions.map(C=>C.id),strategy:Ce,children:/* @__PURE__ */e("div",{className:"space-y-0.5",children:t.conditions.map((C,f)=>/* @__PURE__ */e(zt,{condition:C,index:f,groupId:t.id,groupLogicalOperator:t.logicalOperator,onRemoveCondition:k,onUpdateGroupOperator:i,availableFields:N,source:I,updateConditionFields:y,replaceCondition:A},C.id))})})}),/* @__PURE__ */e(xe,{sensors:_e(se(ze),se(Re,{coordinateGetter:Ge})),collisionDetection:ve,onDragEnd:g,children:/* @__PURE__ */e(Ne,{items:t.groups.map(C=>C.id),strategy:Ce,children:t.groups.map(C=>S(C,a+1,t.id))})}),t.conditions.length===0&&t.groups.length===0&&/* @__PURE__ */e("p",{className:"rounded-control border border-dashed border-border/60 px-3 py-2 text-center text-[11.5px] text-muted-foreground",children:"No conditions in this group."}),/* @__PURE__ */e(Gt,{onAddCondition:()=>x(t.id),onAddGroup:()=>L(t.id)})]})]});}function Ca({filters:t,availableFields:a,source:s,onSave:i,onClearAll:F,onCancel:h,onChange:k}){const b=k!==void 0,{currentFilters:m,availableFields:x,isLoading:L,addCondition:N,addGroup:I,removeCondition:S,removeGroup:y,updateConditionFields:A,replaceCondition:z,updateGroupOperator:O,updateGroupNegate:X,reorderConditions:D,reorderGroups:T,generateSQLPreview:Q,hasAnyFilters:H}=Hr({initialFilters:t,availableFields:a,...(k?{onChange:l=>k(Pr(l)?l:null)}:{})}),n=_e(se(ze),se(Re,{coordinateGetter:Ge})),[g,C]=te(!1),f=(l,V=0,p)=>{if(V===0){const K=l.conditions.length===0&&l.groups.length===0;return/* @__PURE__ */c("div",{children:[/* @__PURE__ */e(xe,{sensors:n,collisionDetection:ve,onDragEnd:E=>{const{active:R,over:q}=E;if(q&&R.id!==q.id){const j=l.conditions.findIndex(J=>J.id===R.id),Y=l.conditions.findIndex(J=>J.id===q.id);j!==-1&&Y!==-1&&D(l.id,j,Y);}},children:/* @__PURE__ */e(Ne,{items:l.conditions.map(E=>E.id),strategy:Ce,children:/* @__PURE__ */e("div",{className:"space-y-0.5",children:l.conditions.map((E,R)=>/* @__PURE__ */e(zt,{condition:E,index:R,groupId:l.id,groupLogicalOperator:l.logicalOperator,onRemoveCondition:S,onUpdateGroupOperator:O,availableFields:x,source:s,updateConditionFields:A,replaceCondition:z},E.id))})})}),/* @__PURE__ */e(xe,{sensors:n,collisionDetection:ve,onDragEnd:E=>{const{active:R,over:q}=E;if(q&&R.id!==q.id){const j=l.groups.findIndex(J=>J.id===R.id),Y=l.groups.findIndex(J=>J.id===q.id);j!==-1&&Y!==-1&&T(l.id,j,Y);}},children:/* @__PURE__ */e(Ne,{items:l.groups.map(E=>E.id),strategy:Ce,children:l.groups.map(E=>f(E,V+1,l.id))})}),K&&!b&&/* @__PURE__ */e("p",{className:"rounded-control border border-dashed border-border/60 px-3 py-2 text-center text-[11.5px] text-muted-foreground",children:"No filters yet. Add a condition to limit the rows this card shows."}),/* @__PURE__ */e(Gt,{onAddCondition:()=>N(l.id),onAddGroup:(b?l.conditions.length+l.groups.length>=2:g)?()=>I(l.id):void 0})]},l.id);}return/* @__PURE__ */e(ia,{group:l,depth:V,parentGroupId:p,onUpdateGroupOperator:O,onUpdateGroupNegate:X,onRemoveGroup:y,onRemoveCondition:S,onReorderConditions:D,onReorderGroups:T,onAddCondition:N,onAddGroup:I,availableFields:x,source:s,renderFilterGroup:f,updateConditionFields:A,replaceCondition:z},l.id);},d=zr(t);return/* @__PURE__ */c("div",{className:U("group/filters",b?"flex flex-col":"flex min-h-0 flex-1 flex-col"),"data-inline":b||void 0,children:[/* @__PURE__ */c("div",{className:b?"":"min-h-0 flex-1 overflow-y-auto px-3 py-3",children:[L?/* @__PURE__ */c("div",{className:"flex items-center justify-center gap-2 py-6 text-[12px] text-muted-foreground",children:[/* @__PURE__ */e(or,{className:"h-3.5 w-3.5 animate-spin"}),"Loading columns…"]}):f(m),!b&&/* @__PURE__ */c("div",{className:"mt-3 flex items-center gap-2 border-t border-border/60 pt-3",children:[/* @__PURE__ */e(dr,{size:"xs",id:"advanced-mode",checked:g,onCheckedChange:l=>C(l)}),/* @__PURE__ */e(ae,{htmlFor:"advanced-mode",className:"text-[12px] font-normal leading-none text-foreground",children:"Advanced mode"}),/* @__PURE__ */e("span",{className:"text-[11px] text-muted-foreground",children:"Nest conditions in groups"})]}),H&&!b&&/* @__PURE__ */c("div",{className:"mt-3 border-t border-border/60 pt-3",children:[/* @__PURE__ */e("div",{className:U("mb-1.5",Be),children:"Where clause"}),/* @__PURE__ */e("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words rounded-[6px] border border-border bg-muted/40 px-3 py-2 font-mono text-[12px] leading-[1.55] text-foreground",children:Q(m)})]})]}),b?null:/* @__PURE__ */c("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border px-3 py-2.5",children:[/* @__PURE__ */e("div",{children:d>0&&/* @__PURE__ */e(B,{size:"xs",variant:"ghost",className:"text-muted-foreground hover:text-foreground",onClick:()=>F==null?void 0:F(),children:"Clear all"})}),/* @__PURE__ */c("div",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */e(B,{size:"xs",variant:"ghost",onClick:()=>h==null?void 0:h(),children:"Cancel"}),/* @__PURE__ */e(B,{size:"xs",onClick:()=>i==null?void 0:i(H?m:null),children:"Apply filters"})]})]})]});}export{ya as C,xa as F,jr as L,va as V,Ca as a,Na as u};
@@ -1,4 +1,4 @@
1
- import{l as f}from"./validators-U8IL8djK.js";import{p}from"./resolve-dashboard-input-context-Djm2WgEF.js";function w(e){var a;const r=e!=null&&e.fields.length?`
1
+ import{l as f}from"./validators-D6oX9c_4.js";import{p}from"./resolve-dashboard-input-context-D3lfJtPf.js";function w(e){var a;const r=e!=null&&e.fields.length?`
2
2
  ## Your card's fields
3
3
 
4
4
  The card this visual draws has these fields, in order. Dimension slots take its dimensions in order, measure slots its measures; the author can reassign them.
@@ -1 +1 @@
1
- import{aR as x,i as M,k as m,n as S,an as w,ap as _,aS as c,aT as f}from"./pivot-result-contract-expectations-D_ane7I2.js";import{readPdfCapacityFacts as A,PDF_SAFETY_LIMIT_EXCEEDED as P,PDF_CAPACITY as l,PDF_NUMBER_COLUMN_TOO_WIDE as p,getUtf8ByteLength as I,FAST_PDF_POLICY as U,isPdfCapacityRefusalCode as L}from"../pdf-export-policy/index.js";import{w as R}from"./raw-temporal-value-B4Md6Xfb.js";function N(t,e,r){const a={...e,locale:e.locale??r};if(a.type==="number")return m(t,a);const{prefix:n,suffix:o,...s}=a;return`${n??""}${m(t,{...s,negativeStyle:a.type==="currency"?a.negativeStyle:"minus"})}${o??""}`;}function D(t,e,r){return t===null?{value:t,text:null}:!e||!M(e)&&e.type!=="duration"?{value:t,text:m(t,{type:"number",locale:r})}:e.type==="duration"?{value:t,text:S(t,{inputUnit:e.inputUnit,outputStyle:e.outputStyle,largestUnit:e.largestUnit,smallestUnit:e.smallestUnit,maxUnits:e.maxUnits,prefix:e.prefix,suffix:e.suffix,negativeInParentheses:e.negativeStyle==="parentheses"})}:{value:t,text:N(t,e,r)};}function F(t,e,r,a){return t===null?{value:t,text:null}:a==="percent"?{value:t,text:m(t,{type:"percent",locale:r,minimumFractionDigits:e,maximumFractionDigits:e,percentValueMode:"fraction"})}:{value:t,text:m(t,{type:"number",locale:r,minimumFractionDigits:e,maximumFractionDigits:e,suffix:"×"})};}function C(t,e){if(t===void 0)return e;if(!Number.isInteger(t)||t<0||t>6)throw new RangeError("Comparison precision must be an integer from 0 to 6.");return t;}function Y(t,e){const r={mode:e.displayMode,current:D(t.currentValue,e.metricFormat,e.locale),comparison:D(t.comparisonValue,e.metricFormat,e.locale)};return(e.displayMode==="difference"||e.displayMode==="both")&&(r.difference=D(t.delta,x(e.metricFormat),e.locale)),(e.displayMode==="percent_change"||e.displayMode==="both")&&(r.percentChange=F(t.percentChange,C(e.precision,1),e.locale,"percent")),e.displayMode==="ratio"&&(r.ratio=F(t.ratio,C(e.precision,2),e.locale,"ratio")),r;}const i=t=>t.toLocaleString("en-US"),h=t=>`${i(Math.ceil(t/1048576))} MB`,$="export the data as CSV or Excel";function H(t){const e=A(t.facts),r=t.dataExport?`Add a filter to narrow it, or ${$}.`:"Add a filter to narrow it, then export again.";switch(t.code){case"PDF_ROW_LIMIT_EXCEEDED":{const a=t.subject??"This table",n=e.rowLimit??l.maxTableRows;return e.rowCount!==void 0?`${a} has ${i(e.rowCount)} rows. A PDF holds up to ${i(n)} rows per table. ${r}`:`${a} has more than ${i(n)} rows, the most a PDF holds per table. ${r}`;}case"PDF_PAGE_LIMIT_EXCEEDED":{const a=t.subject??"This PDF",n=e.pageLimit??l.maxPages;return e.pageCount!==void 0?`${a} is ${i(e.pageCount)} pages. A PDF holds up to ${i(n)}. ${r}`:`${a} is longer than ${i(n)} pages, the most a PDF holds. ${r}`;}case"PDF_SIZE_LIMIT_EXCEEDED":{const a=t.subject??"This PDF",n=e.byteLimit??l.maxFileBytes;return e.bytes!==void 0?`${a} is ${h(e.bytes)}. A PDF file holds up to ${h(n)}. ${r}`:`${a} is larger than ${h(n)}, the most a PDF file holds. ${r}`;}case"PDF_CAPTURE_TOO_TALL":return`${t.subject??"This dashboard"} is too long to print as one PDF. Print one sheet or fewer cards${t.dataExport?`, or ${$}`:""}.`;case p:return`A number in this table is too wide for its column in a PDF. Use landscape or fewer columns${t.dataExport?`, or ${$}`:""}.`;case P:return`This PDF is over what a PDF holds: ${i(l.maxTableRows)} rows per table, ${i(l.maxPages)} pages and ${h(l.maxFileBytes)}. ${r}`;}}class O extends Error{constructor(e,r=P){super(e),this.code=r;}}function j(t){return L(t)||t===P||t===p;}function T(t){if(!t||typeof t!="object")return;const{error:e,message:r,detail:a}=t;for(const n of[e,r,a])if(typeof n=="string"&&n.trim())return n.trim();}async function k(t){const e=`PDF request failed: ${t.status} ${t.statusText}`.trim(),r=t.headers.get("content-type")||"";try{if(r.includes("application/json")){const n=await t.json(),o=typeof n.code=="string"?n.code:typeof n.errorCode=="string"?n.errorCode:void 0;return{message:T(n)||e,code:o};}const a=await t.text();if(!a.trim())return{message:e};try{const n=JSON.parse(a),o=typeof n.code=="string"?n.code:typeof n.errorCode=="string"?n.errorCode:void 0;return{message:T(n)||a.trim(),code:o};}catch{return{message:a.trim()};}}catch{return{message:e};}}async function W(t){if(!t.token)throw new Error("Missing auth token for PDF export");if(I(t.serializedPayload)>U.maxRequestBytes)throw new Error("Fast-path PDF request exceeds the structured body limit");const e=await(t.fetchImpl??fetch)(t.url,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t.token}`},body:t.serializedPayload,signal:t.signal});if(!e.ok){const a=await k(e);throw j(a.code)?new O(a.message,a.code):new Error(a.message);}const r=await e.json();if(r!=null&&r.error)throw new Error(r.error);if(typeof(r==null?void 0:r.url)!="string"||!r.url.trim())throw new Error("Fast-path PDF response missing download URL");return r;}function J(t,e,r){const a=e.from>t.start?e.from:t.start,n=e.to&&e.to<t.end?e.to:t.end,s=a<=r&&n>r?"running":a>t.start?"start":n<t.end?"end":void 0;return{start:a,end:n,...(s?{partial:s}:{})};}function K(t,e,r){switch(e){case"running":return`${t} (so far)`;case"start":return r?`${t} (from ${r.start})`:`${t} (partial)`;case"end":return r?`${t} (to ${r.end})`:`${t} (partial)`;default:return t;}}function Q(t,e,r){const a=Date.parse(t.startInclusive),n=Date.parse(t.endExclusive);if(!Number.isFinite(a)||!Number.isFinite(n))return;if(e.granularity==="hour"||e.granularity==="minute"||e.granularity==="second"){const y=u=>{try{return new Intl.DateTimeFormat((r==null?void 0:r.locale)??"en-US",{timeStyle:(r==null?void 0:r.dateTime.timeStyle)??"short",timeZone:e.calendar.tz}).format(new Date(u));}catch{return new Date(u).toISOString();}};return{start:y(a),end:y(n)};}const o={kind:"temporal_bucket",granularity:"day",calendar:e.calendar};let s;try{s=w({metadata:o,locale:(r==null?void 0:r.locale)??"en-US",...(r?{styles:{dateStyle:r.dateStyle,dateTime:r.dateTime}}:{})});}catch{s=void 0;}const d=y=>{const u=R(new Date(y),e.calendar.tz),g=`${String(u.year).padStart(4,"0")}-${String(u.month).padStart(2,"0")}-${String(u.day).padStart(2,"0")}`;try{return s?_({value:g,metadata:o,format:s.format}):g;}catch{return g;}};return{start:d(a),end:d(n-1)};}const B=/* @__PURE__ */new Set(["day","week","month","quarter","year"]);function v(t,e){try{const r=f(t),a=c(r,e,"yyyy-MM-dd");if(c(r,e,"HH:mm:ss.SSS")!=="00:00:00.000")return{date:a,time:c(r,e,"h:mm a")};const[n,o,s]=a.split("-").map(Number),d=new Date(Date.UTC(n,o-1,s));return d.setUTCDate(d.getUTCDate()-1),{date:c(d,"UTC","yyyy-MM-dd")};}catch{return;}}function b(t,e,r){const a=v(t.end,e);if(a)return{start:c(f(t.start),e,r?"MMM d":"MMM d, yyyy"),endDate:c(f(`${a.date}T00:00:00Z`),"UTC","MMM d, yyyy"),...(a.time?{endTime:a.time}:{})};}function E(t){return!!(t&&B.has(t));}function z(t,e,r,a=!1){if(E(r))try{const o=b(t,e,!1);if(o&&o.start===o.endDate)return o.endTime?`${o.endDate} until ${o.endTime}`:o.endDate;}catch{}const n=V(t,e,r,a);return`${n.start} – ${n.end}`;}function V(t,e,r,a=!1){try{if(E(r)){const n=b(t,e,a);if(n)return{start:n.start,end:n.endTime?`${n.endDate}, ${n.endTime}`:n.endDate};}if(r==="second"||r==="minute"||r==="hour"){const n=a?"MMM d, h:mm a":"MMM d, yyyy, h:mm a";return{start:c(f(t.start),e,n),end:`before ${c(f(t.end),e,n)}`};}}catch{}return{start:t.start,end:`before ${t.end}`};}export{O as P,Y as a,W as b,J as c,K as d,Q as e,z as f,V as g,j as i,H as p,k as r};
1
+ import{aR as x,i as M,k as m,n as S,an as w,ap as _,aS as c,aT as f}from"./pivot-result-contract-expectations-Bl55bAD9.js";import{readPdfCapacityFacts as A,PDF_SAFETY_LIMIT_EXCEEDED as P,PDF_CAPACITY as l,PDF_NUMBER_COLUMN_TOO_WIDE as p,getUtf8ByteLength as I,FAST_PDF_POLICY as U,isPdfCapacityRefusalCode as L}from"../pdf-export-policy/index.js";import{w as R}from"./raw-temporal-value-DqmEQqi9.js";function N(t,e,r){const a={...e,locale:e.locale??r};if(a.type==="number")return m(t,a);const{prefix:n,suffix:o,...s}=a;return`${n??""}${m(t,{...s,negativeStyle:a.type==="currency"?a.negativeStyle:"minus"})}${o??""}`;}function D(t,e,r){return t===null?{value:t,text:null}:!e||!M(e)&&e.type!=="duration"?{value:t,text:m(t,{type:"number",locale:r})}:e.type==="duration"?{value:t,text:S(t,{inputUnit:e.inputUnit,outputStyle:e.outputStyle,largestUnit:e.largestUnit,smallestUnit:e.smallestUnit,maxUnits:e.maxUnits,prefix:e.prefix,suffix:e.suffix,negativeInParentheses:e.negativeStyle==="parentheses"})}:{value:t,text:N(t,e,r)};}function F(t,e,r,a){return t===null?{value:t,text:null}:a==="percent"?{value:t,text:m(t,{type:"percent",locale:r,minimumFractionDigits:e,maximumFractionDigits:e,percentValueMode:"fraction"})}:{value:t,text:m(t,{type:"number",locale:r,minimumFractionDigits:e,maximumFractionDigits:e,suffix:"×"})};}function C(t,e){if(t===void 0)return e;if(!Number.isInteger(t)||t<0||t>6)throw new RangeError("Comparison precision must be an integer from 0 to 6.");return t;}function Y(t,e){const r={mode:e.displayMode,current:D(t.currentValue,e.metricFormat,e.locale),comparison:D(t.comparisonValue,e.metricFormat,e.locale)};return(e.displayMode==="difference"||e.displayMode==="both")&&(r.difference=D(t.delta,x(e.metricFormat),e.locale)),(e.displayMode==="percent_change"||e.displayMode==="both")&&(r.percentChange=F(t.percentChange,C(e.precision,1),e.locale,"percent")),e.displayMode==="ratio"&&(r.ratio=F(t.ratio,C(e.precision,2),e.locale,"ratio")),r;}const i=t=>t.toLocaleString("en-US"),h=t=>`${i(Math.ceil(t/1048576))} MB`,$="export the data as CSV or Excel";function H(t){const e=A(t.facts),r=t.dataExport?`Add a filter to narrow it, or ${$}.`:"Add a filter to narrow it, then export again.";switch(t.code){case"PDF_ROW_LIMIT_EXCEEDED":{const a=t.subject??"This table",n=e.rowLimit??l.maxTableRows;return e.rowCount!==void 0?`${a} has ${i(e.rowCount)} rows. A PDF holds up to ${i(n)} rows per table. ${r}`:`${a} has more than ${i(n)} rows, the most a PDF holds per table. ${r}`;}case"PDF_PAGE_LIMIT_EXCEEDED":{const a=t.subject??"This PDF",n=e.pageLimit??l.maxPages;return e.pageCount!==void 0?`${a} is ${i(e.pageCount)} pages. A PDF holds up to ${i(n)}. ${r}`:`${a} is longer than ${i(n)} pages, the most a PDF holds. ${r}`;}case"PDF_SIZE_LIMIT_EXCEEDED":{const a=t.subject??"This PDF",n=e.byteLimit??l.maxFileBytes;return e.bytes!==void 0?`${a} is ${h(e.bytes)}. A PDF file holds up to ${h(n)}. ${r}`:`${a} is larger than ${h(n)}, the most a PDF file holds. ${r}`;}case"PDF_CAPTURE_TOO_TALL":return`${t.subject??"This dashboard"} is too long to print as one PDF. Print one sheet or fewer cards${t.dataExport?`, or ${$}`:""}.`;case p:return`A number in this table is too wide for its column in a PDF. Use landscape or fewer columns${t.dataExport?`, or ${$}`:""}.`;case P:return`This PDF is over what a PDF holds: ${i(l.maxTableRows)} rows per table, ${i(l.maxPages)} pages and ${h(l.maxFileBytes)}. ${r}`;}}class O extends Error{constructor(e,r=P){super(e),this.code=r;}}function j(t){return L(t)||t===P||t===p;}function T(t){if(!t||typeof t!="object")return;const{error:e,message:r,detail:a}=t;for(const n of[e,r,a])if(typeof n=="string"&&n.trim())return n.trim();}async function k(t){const e=`PDF request failed: ${t.status} ${t.statusText}`.trim(),r=t.headers.get("content-type")||"";try{if(r.includes("application/json")){const n=await t.json(),o=typeof n.code=="string"?n.code:typeof n.errorCode=="string"?n.errorCode:void 0;return{message:T(n)||e,code:o};}const a=await t.text();if(!a.trim())return{message:e};try{const n=JSON.parse(a),o=typeof n.code=="string"?n.code:typeof n.errorCode=="string"?n.errorCode:void 0;return{message:T(n)||a.trim(),code:o};}catch{return{message:a.trim()};}}catch{return{message:e};}}async function W(t){if(!t.token)throw new Error("Missing auth token for PDF export");if(I(t.serializedPayload)>U.maxRequestBytes)throw new Error("Fast-path PDF request exceeds the structured body limit");const e=await(t.fetchImpl??fetch)(t.url,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t.token}`},body:t.serializedPayload,signal:t.signal});if(!e.ok){const a=await k(e);throw j(a.code)?new O(a.message,a.code):new Error(a.message);}const r=await e.json();if(r!=null&&r.error)throw new Error(r.error);if(typeof(r==null?void 0:r.url)!="string"||!r.url.trim())throw new Error("Fast-path PDF response missing download URL");return r;}function J(t,e,r){const a=e.from>t.start?e.from:t.start,n=e.to&&e.to<t.end?e.to:t.end,s=a<=r&&n>r?"running":a>t.start?"start":n<t.end?"end":void 0;return{start:a,end:n,...(s?{partial:s}:{})};}function K(t,e,r){switch(e){case"running":return`${t} (so far)`;case"start":return r?`${t} (from ${r.start})`:`${t} (partial)`;case"end":return r?`${t} (to ${r.end})`:`${t} (partial)`;default:return t;}}function Q(t,e,r){const a=Date.parse(t.startInclusive),n=Date.parse(t.endExclusive);if(!Number.isFinite(a)||!Number.isFinite(n))return;if(e.granularity==="hour"||e.granularity==="minute"||e.granularity==="second"){const y=u=>{try{return new Intl.DateTimeFormat((r==null?void 0:r.locale)??"en-US",{timeStyle:(r==null?void 0:r.dateTime.timeStyle)??"short",timeZone:e.calendar.tz}).format(new Date(u));}catch{return new Date(u).toISOString();}};return{start:y(a),end:y(n)};}const o={kind:"temporal_bucket",granularity:"day",calendar:e.calendar};let s;try{s=w({metadata:o,locale:(r==null?void 0:r.locale)??"en-US",...(r?{styles:{dateStyle:r.dateStyle,dateTime:r.dateTime}}:{})});}catch{s=void 0;}const d=y=>{const u=R(new Date(y),e.calendar.tz),g=`${String(u.year).padStart(4,"0")}-${String(u.month).padStart(2,"0")}-${String(u.day).padStart(2,"0")}`;try{return s?_({value:g,metadata:o,format:s.format}):g;}catch{return g;}};return{start:d(a),end:d(n-1)};}const B=/* @__PURE__ */new Set(["day","week","month","quarter","year"]);function v(t,e){try{const r=f(t),a=c(r,e,"yyyy-MM-dd");if(c(r,e,"HH:mm:ss.SSS")!=="00:00:00.000")return{date:a,time:c(r,e,"h:mm a")};const[n,o,s]=a.split("-").map(Number),d=new Date(Date.UTC(n,o-1,s));return d.setUTCDate(d.getUTCDate()-1),{date:c(d,"UTC","yyyy-MM-dd")};}catch{return;}}function b(t,e,r){const a=v(t.end,e);if(a)return{start:c(f(t.start),e,r?"MMM d":"MMM d, yyyy"),endDate:c(f(`${a.date}T00:00:00Z`),"UTC","MMM d, yyyy"),...(a.time?{endTime:a.time}:{})};}function E(t){return!!(t&&B.has(t));}function z(t,e,r,a=!1){if(E(r))try{const o=b(t,e,!1);if(o&&o.start===o.endDate)return o.endTime?`${o.endDate} until ${o.endTime}`:o.endDate;}catch{}const n=V(t,e,r,a);return`${n.start} – ${n.end}`;}function V(t,e,r,a=!1){try{if(E(r)){const n=b(t,e,a);if(n)return{start:n.start,end:n.endTime?`${n.endDate}, ${n.endTime}`:n.endDate};}if(r==="second"||r==="minute"||r==="hour"){const n=a?"MMM d, h:mm a":"MMM d, yyyy, h:mm a";return{start:c(f(t.start),e,n),end:`before ${c(f(t.end),e,n)}`};}}catch{}return{start:t.start,end:`before ${t.end}`};}export{O as P,Y as a,W as b,J as c,K as d,Q as e,z as f,V as g,j as i,H as p,k as r};
@@ -0,0 +1 @@
1
+ import{q as L,s as B,t as E,u as Q,w as h,x as $,y as w,z as J,A as X}from"./resolve-dashboard-input-context-D3lfJtPf.js";import{canonicalizeSupportedCurrencyCode as S}from"../value-format-preferences/index.js";import{F as G}from"./bookmark-state-CrJDZi3y.js";import{l as v}from"./validators-D6oX9c_4.js";import"./matrix-operation-contract-1dtkh4UB.js";import"./analytics-base-schemas-DMFrDqn_.js";import{b as g,r as H,aI as U,i as W,aJ as Y}from"./pivot-result-contract-expectations-Bl55bAD9.js";function C(e){return(e==null?void 0:e.type)==="number"||(e==null?void 0:e.type)==="currency";}function Z(e){return(e==null?void 0:e.type)==="number";}function ee(e){var t;if(!Z(e))return!1;const n=(t=e==null?void 0:e.numberFormat)==null?void 0:t.style;return n===void 0||n==="decimal"||n==="currency";}function ne(e,n){const t=n==null?void 0:n.type;if(t&&t!=="none"&&t!=="number")return{currencyBindable:!1};const r=t==="number"?n!=null&&n.numberFormat?E(n.numberFormat,{preserveOmittedProperties:!0}):{type:"number"}:void 0,i=g(e.format,{preserveOmittedProperties:!0}),s=v(e.dataType)==="number"?{type:"number"}:void 0,a=(n==null?void 0:n.inheritMetricFormat)===!1||!!(n!=null&&n.numberFormat)&&(n==null?void 0:n.inheritMetricFormat)!==!0?r:i||s||r;return{authoredFormat:a,currencyBindable:C(a)};}function re(e,n){const t=g(n.format,{preserveOmittedProperties:!0}),r=v(n.dataType)==="number"?{type:"number"}:void 0,i=t||r;return{authoredFormat:i,source:t?"semantic":r?"inferred":void 0,currencyBindable:C(i)};}function I(e,n={}){var u,l,d;const t=n.column??((u=L(e))==null?void 0:u.value);if((t==null?void 0:t.kind)==="sqlKpiValue"){const m=n.resultColumnKey?{kind:"column",columnKey:n.resultColumnKey}:void 0,f=g(H({card:e,column:{kind:"sqlKpiValue"},surface:"kpiValue"}).format,{preserveOmittedProperties:!0});return{target:m,authoredFormat:f,...(f?{source:"stored"}:{}),currencyBindable:!!m&&C(f)};}const r=t?(d=(l=e.config)==null?void 0:l.metricColumns)==null?void 0:d.find(m=>m.id===t.fieldId):void 0,i=r!=null&&r.id?{kind:"metric",metricId:r.id}:void 0,s=g(r==null?void 0:r.format,{preserveOmittedProperties:!0}),o=v(r==null?void 0:r.dataType)==="number"?{type:"number"}:void 0,a=s||o;return{target:i,authoredFormat:a,...(s?{source:"stored"}:o?{source:"inferred"}:{}),currencyBindable:B(e.type)&&!!i&&C(a)};}function _(e,n,t){var i;const r=t(e,n);return((i=e.derivedField)==null?void 0:i.format)??(r==null?void 0:r.format)??(r==null?void 0:r.resolvedField.format);}function q(e,n,t){return e.kind==="calculated"?e.definition.format:_(e.field,n,t);}function be(e,n){const t=h(n),r=(i,s)=>Object.fromEntries(i.flatMap(o=>{const a=s(o);return a?[[o.id,a]]:[];}));return{measureFormats:r(e.measures,i=>q(i,e.source,t)),levelFormats:r([...e.rows,...e.columns],i=>_(i.field,e.source,t))};}function N(e,n=[]){const t=Q(e);if(t.status!=="ready")return[];const{spec:r,presentation:i}=t.config,s=h(n);return r.measures.map(o=>{var y;const a=o.kind==="aggregate"?s(o.field,r.source):void 0,u=U(i.measureFormats[o.id],q(o,r.source,s)),l=o.kind==="calculated"?o.definition.dataType:["MIN","MAX"].includes(o.aggregate)?((y=o.field.derivedField)==null?void 0:y.dataType)??(a==null?void 0:a.resolvedField.dataType)??o.field.dataType:"number",d=v(l)==="number",m=o.kind==="calculated"||!!(a||o.field.derivedField||o.field.name==="*"),f=u&&W(u)?u:!u&&d&&m?{type:"number"}:void 0;return{measureId:o.id,label:Y(o,i),canonical:f};});}function te(e){var n,t;return e.type==="detailTable"?((n=e.config)==null?void 0:n.detailColumns)||[]:((t=e.config)==null?void 0:t.metricColumns)||[];}function ie(e){return new Set(G(e).flatMap(n=>(n.controlBindings||[]).filter($).map(t=>t.controlId)));}function oe(e,n){const t=[n.id,n.alias,n.label,n.name,n.qualifiedFieldName].filter(s=>!!s);for(const s of t)if(e[s])return e[s];const r=new Set(t.map(s=>s.trim().toLowerCase())),i=Object.entries(e).find(([s])=>r.has(s.trim().toLowerCase()));return i==null?void 0:i[1];}function K(e){return[...new Map(e.map(n=>[p(n),n])).values()];}function ae(e,n=[],t){var M;const r=!!((M=e.sql)!=null&&M.trim()),i=B(e.type),s=r&&i&&e.type!=="kpi"&&e.type!=="matrixTable",o=te(e),a=J(e),u=!r&&e.type==="kpi"?o.map(c=>I(e,{column:{kind:"field",fieldId:c.id}})):[],l=!r&&e.type==="matrixTable"?N(e,t):[],d=(r?[]:o).map(c=>({kind:"metric",metricId:c.id})),m=l.map(c=>({kind:"matrix_measure",measureId:c.measureId})),f=l.filter(c=>{var k,x;return((k=c.canonical)==null?void 0:k.type)==="number"||((x=c.canonical)==null?void 0:x.type)==="currency";}).map(c=>({kind:"matrix_measure",measureId:c.measureId})),y=e.type==="matrixTable"?[]:e.type==="kpi"?u.filter(c=>c.currencyBindable).flatMap(c=>c.target?[c.target]:[]):(r||!i?[]:o).filter(c=>(X(e.type)?ne(c,oe(a,c)):re(e,c)).currencyBindable).map(c=>({kind:"metric",metricId:c.id})),b=[...new Set(n)],D=(s?b:[]).map(c=>({kind:"column",columnKey:c})),z=(s?b:[]).filter(c=>ee(a[c])).map(c=>({kind:"column",columnKey:c})),T=(r&&e.type==="kpi"?b.slice(0,1):[]).map(c=>({kind:"column",columnKey:c})),F=r&&e.type==="kpi"?I(e,{resultColumnKey:b[0]}):void 0,R=i&&F!=null&&F.currencyBindable?T:[];return{knownTargets:K([...(e.type==="matrixTable"?m:d),...D,...T]),eligibleTargets:K([...y,...f,...z,...R])};}function ge(e,n){const t=I(e,{resultColumnKey:n});return t.currencyBindable?t.target:void 0;}function Ce(e){var n;return(n=e.card.sql)!=null&&n.trim()?{kind:"column",columnKey:e.columnKey}:e.metricId?{kind:"metric",metricId:e.metricId}:void 0;}function p(e){return e.kind==="metric"?`metric:${e.metricId}`:e.kind==="column"?`column:${e.columnKey}`:`matrix_measure:${e.measureId}`;}function ce(e){if(!e||typeof e!="object"||Array.isArray(e))return;const n=e;if(n.kind==="metric"&&typeof n.metricId=="string"&&n.metricId.trim())return{kind:"metric",metricId:n.metricId};if(n.kind==="column"&&typeof n.columnKey=="string"&&n.columnKey.trim())return{kind:"column",columnKey:n.columnKey};if(n.kind==="matrix_measure"&&typeof n.measureId=="string"&&n.measureId.trim())return{kind:"matrix_measure",measureId:n.measureId};}function P(e){const n=S(e);return typeof e=="string"&&e===n?n:void 0;}function O(e){if(e.type!=="enum"||e.source.kind!=="manual")return{diagnostic:"invalid_control_type"};const n=e.source.options.map(t=>P(t.value));if(n.length===0||n.some(t=>!t))return{diagnostic:"invalid_currency_option"};if(e.requiredAtExecution){const t=e.initialValueStrategy==="saved_default"?P(e.defaultValue):void 0;if(!t||!n.includes(t))return{diagnostic:"invalid_control_default"};}return{control:e,currencies:n};}function ve(e){return"control"in O(e);}function A(e){const n=ie(e.dashboard);if(n.size===0)return{definitions:e.definitions||[],values:e.values||{}};const t=new Set([...n].filter(r=>!e.referencedControlIds.has(r)));return{definitions:(e.definitions||[]).filter(r=>!t.has(r.id)),values:Object.fromEntries(Object.entries(e.values||{}).filter(([r])=>!t.has(r)))};}function Fe(e){return A({...e,referencedControlIds:new Set(w({sql:e.filterSql,controlBindings:[]}))});}function ke(e){var n;return A({...e,referencedControlIds:new Set(w({sql:(n=e.source)==null?void 0:n.sql,controlBindings:[]}))});}function j(e){return{knownKeys:new Set(e.knownTargets.map(p)),eligibleKeys:new Set(e.eligibleTargets.map(p)),controlsById:new Map((e.controls||[]).map(n=>[n.id,n]))};}function V(e,n){if(!e||typeof e!="object"||e.target!=="presentation_currency")return{};const t=e,r=typeof t.controlId=="string"&&t.controlId.trim()?t.controlId:void 0;if(!r)return{diagnostic:{code:"invalid_binding_shape"}};const i=ce(t.presentationTarget);if(!i)return{diagnostic:{code:"missing_target",controlId:r}};const s=p(i);if(!n.knownKeys.has(s))return{diagnostic:{code:"stale_target",controlId:r}};if(!n.eligibleKeys.has(s))return{diagnostic:{code:"inapplicable_target",controlId:r}};const o=n.controlsById.get(r);if(!o)return{diagnostic:{code:"missing_control",controlId:r}};const a=O(o);return"diagnostic"in a?{diagnostic:{code:a.diagnostic,controlId:r}}:{binding:{controlId:r,presentationTarget:i,control:a.control,currencies:a.currencies}};}function Ie(e){const n=j(e);return(e.bindings||[]).flatMap(t=>{const r=V(t,n);return"diagnostic"in r?[r.diagnostic]:[];});}function se(e){var i;const n=[],t=p(e.target),r=j(e);for(const s of e.bindings||[]){const o=V(s,r);if("diagnostic"in o){n.push(o.diagnostic);continue;}const a=o.binding;if(!a||p(a.presentationTarget)!==t)continue;const l=S((i=e.values)==null?void 0:i[a.control.id]);if(!(!l||!a.currencies.includes(l)))return{currency:l,diagnostics:n};}return{diagnostics:n};}function Te(e,n,t,r){const i={...e,config:{...e.config,matrix:n}},s=ae(i,[],r),o=N(i,r),a={...n.presentation.measureFormats};for(const u of o){const l={kind:"matrix_measure",measureId:u.measureId},{currency:d}=se({...t,...s,bindings:e.controlBindings,target:l});if(!d||!u.canonical)continue;const{locale:m,...f}=u.canonical;a[u.measureId]={...f,type:"currency",currency:d};}return{...n.presentation,measureFormats:a};}export{ne as a,N as b,I as c,ie as d,Te as e,ae as f,Ce as g,Z as h,p as i,se as j,ve as k,Ie as l,te as m,Fe as n,ge as o,ke as p,be as q,re as r};
@@ -1 +1 @@
1
- import{v as F}from"./resolve-dashboard-input-context-Djm2WgEF.js";function h(e){if(!(e!=null&&e.expectedType))return"table";const r=Array.isArray(e.expectedType)?e.expectedType[0]:e.expectedType;return M(r)?r:"table";}const E=["bar","horizontalBar","line","area","stackedArea","combo","pie","doughnut","radar","polarArea","bubble","scatter","stackedBar","stackedLine","table","detailTable","kpi","pyramid","tornado","range","text","funnel","bullet","heatmap","treemap","custom"];function M(e){return E.includes(e);}function x(e){const r=e.position;if(typeof r=="number")return r;if(typeof r=="string"){const t=r.match(/\d+/);if(t){const n=Number(t[0]);if(!Number.isNaN(n))return n;}}return Number.POSITIVE_INFINITY;}function m(e){if(typeof e=="number")return{kind:"number",start:e,end:e};if(typeof e=="string"){const r=e.match(/^(\d+)$/);if(r){const s=Number(r[1]);return{kind:"number",start:s,end:s};}const t=e.match(/^(\d+)-(\d+)$/);if(t){const s=Number(t[1]),d=Number(t[2]);return{kind:"range",start:s,end:d};}const n=e.match(/^(\d+)\+$/);if(n)return{kind:"dynamic",start:Number(n[1]),end:Number.POSITIVE_INFINITY};}return null;}function k(e){return!e||e.length===0?void 0:[...e].sort((t,n)=>x(t)-x(n))[0];}function N(e,r){if(!e||e.length===0)return;const t=[],n=[],s=[];e.forEach(i=>{const u=m(i.position);u&&(u.kind==="number"?t.push(i):u.kind==="range"?n.push(i):u.kind==="dynamic"&&s.push(i));});const d=t.find(i=>{const u=m(i.position);return(u==null?void 0:u.kind)==="number"&&u.start===r;});if(d)return d;const p=n.sort((i,u)=>x(i)-x(u)).find(i=>{const u=m(i.position);return(u==null?void 0:u.kind)==="range"&&r>=u.start&&r<=u.end;});if(p)return p;const a=s.map(i=>({slot:i,parsed:m(i.position)})).filter(i=>{var u;return((u=i.parsed)==null?void 0:u.kind)==="dynamic";}).sort((i,u)=>{var o,f;return(((o=i.parsed)==null?void 0:o.start)??0)-(((f=u.parsed)==null?void 0:f.start)??0);}).filter(i=>{var u;return r>=(((u=i.parsed)==null?void 0:u.start)??0);}).sort((i,u)=>{var o,f;return(((o=u.parsed)==null?void 0:o.start)??0)-(((f=i.parsed)==null?void 0:f.start)??0);})[0];return a==null?void 0:a.slot;}function A(e,r){const t=N(e,r);if(t)return h(t);}function V(e,r){var n;const t=(n=e==null?void 0:e.customCardPreferences)==null?void 0:n.slotIndex;return typeof t=="number"?t:r;}function S(e,r){var t;if(!((t=e==null?void 0:e.customCardPreferences)!=null&&t.url))return!1;if(e.type==="custom"||e.customCardPreferences.visualType==="multiple"||e.customCardPreferences.dataInputCardIds||(e.customCardPreferences.minInputs||0)>1||(e.customCardPreferences.maxInputs||0)>1)return!0;if(r&&r.length>1){const n=r.filter(s=>{var d;return typeof((d=s.customCardPreferences)==null?void 0:d.slotIndex)=="number";});if(n.length>1&&n.some(s=>s.id!==e.id))return!0;}return!1;}function O(e){const r=[];let t=-1;e.forEach((n,s)=>{const d=V(n,s);d>t&&(t=d),r[d]=n??null;});for(let n=0;n<=t;n+=1)n in r||(r[n]=null);return r;}function $(e){return e.map((r,t)=>!r.customCardPreferences||r.customCardPreferences.slotIndex===t?r:{...r,customCardPreferences:{...r.customCardPreferences,slotIndex:t}});}function v(e){const r=k(e);if(r)return h(r);}function R(e,r,t){if(!e)return;const n=A(t,r);return e.type==="custom"&&n?n:e.type;}function Y(e,r,t){var T;const n={dataSource:t.dataSource,connectionId:t.connectionId},s={type:"component",visualType:"multiple",url:r.url,componentName:r.name,icon:r.icon,pluginChartType:r.chartType,minInputs:r.minInputs,maxInputs:r.maxInputs},d=r.minInputs||1,p=e.map(c=>({slot:c,parsed:m(c.position)})).filter(c=>c.parsed!==null).reduce((c,l)=>{const g=l.parsed.end;return Number.isFinite(g)?Math.max(c,g):c;},-1),b=Math.max(d,p+1),a=k(e),i=a?x(a):0;let u=!1;const o=[];for(let c=0;c<b;c+=1){const l=N(e,c),g=h(l),I=!u&&c===i,P=c,C={...n,id:F(),title:(I?a==null?void 0:a.label:l==null?void 0:l.label)||`Tab ${c+1}`,tabTitle:(I?a==null?void 0:a.label:l==null?void 0:l.label)||`Tab ${c+1}`,description:(I?a==null?void 0:a.description:l==null?void 0:l.description)||"",type:g,sql:"",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},...(I&&{customCardPreferences:{...s,slotIndex:P}}),...(!I&&{customCardPreferences:{slotIndex:P}})};I&&(u=!0),o.push(C);}if(!u&&o.length>0){const c=((T=o[0].customCardPreferences)==null?void 0:T.slotIndex)??0;o[0]={...o[0],type:o[0].type,customCardPreferences:{...s,slotIndex:c}};}const f=o.findIndex(c=>{var l;return!!((l=c.customCardPreferences)!=null&&l.url);});if(f>0){const[c]=o.splice(f,1);o.unshift(c);}return o;}function _({frame:e,configCard:r,isMultiInputVisual:t}){var s;if(!t||!r)return e.cards;const n=(s=r.customCardPreferences)==null?void 0:s.dataInputCardIds;return n?Object.keys(n).sort((d,y)=>Number(d)-Number(y)).map(d=>{var p;const y=(p=n[d])==null?void 0:p.cardId;return e.cards.find(b=>b.id===y)||null;}):e.cards;}function j(e,r){return r&&S(r,e.cards)?r:e.cards.find(t=>S(t,e.cards))||null;}function q(e,r){var s,d;if(!e)return null;const t=r==null?void 0:r.visualType;if(t)return t;if(r!=null&&r.slots&&r.slots.length>0||((r==null?void 0:r.minInputs)||0)>1||((r==null?void 0:r.maxInputs)||0)>1||((r==null?void 0:r.dataInputs)||[]).length>1)return"multiple";const n=(s=e.customCardPreferences)==null?void 0:s.visualType;return n||((d=e.customCardPreferences)!=null&&d.dataInputCardIds?"multiple":null);}function w(e){return e.visualType==="multiple"||e.slots&&e.slots.length>0||(e.minInputs||0)>1||(e.maxInputs||0)>1||(e.dataInputs||[]).length>1?"multiple":"single";}function z(e){return Array.isArray(e)?{records:e}:e;}export{V as a,O as b,R as c,w as d,Y as e,j as f,_ as g,N as h,S as i,$ as j,h as k,v as l,z as n,q as r};
1
+ import{v as F}from"./resolve-dashboard-input-context-D3lfJtPf.js";function h(e){if(!(e!=null&&e.expectedType))return"table";const r=Array.isArray(e.expectedType)?e.expectedType[0]:e.expectedType;return M(r)?r:"table";}const E=["bar","horizontalBar","line","area","stackedArea","combo","pie","doughnut","radar","polarArea","bubble","scatter","stackedBar","stackedLine","table","detailTable","kpi","pyramid","tornado","range","text","funnel","bullet","heatmap","treemap","custom"];function M(e){return E.includes(e);}function x(e){const r=e.position;if(typeof r=="number")return r;if(typeof r=="string"){const t=r.match(/\d+/);if(t){const n=Number(t[0]);if(!Number.isNaN(n))return n;}}return Number.POSITIVE_INFINITY;}function m(e){if(typeof e=="number")return{kind:"number",start:e,end:e};if(typeof e=="string"){const r=e.match(/^(\d+)$/);if(r){const s=Number(r[1]);return{kind:"number",start:s,end:s};}const t=e.match(/^(\d+)-(\d+)$/);if(t){const s=Number(t[1]),d=Number(t[2]);return{kind:"range",start:s,end:d};}const n=e.match(/^(\d+)\+$/);if(n)return{kind:"dynamic",start:Number(n[1]),end:Number.POSITIVE_INFINITY};}return null;}function k(e){return!e||e.length===0?void 0:[...e].sort((t,n)=>x(t)-x(n))[0];}function N(e,r){if(!e||e.length===0)return;const t=[],n=[],s=[];e.forEach(i=>{const u=m(i.position);u&&(u.kind==="number"?t.push(i):u.kind==="range"?n.push(i):u.kind==="dynamic"&&s.push(i));});const d=t.find(i=>{const u=m(i.position);return(u==null?void 0:u.kind)==="number"&&u.start===r;});if(d)return d;const p=n.sort((i,u)=>x(i)-x(u)).find(i=>{const u=m(i.position);return(u==null?void 0:u.kind)==="range"&&r>=u.start&&r<=u.end;});if(p)return p;const a=s.map(i=>({slot:i,parsed:m(i.position)})).filter(i=>{var u;return((u=i.parsed)==null?void 0:u.kind)==="dynamic";}).sort((i,u)=>{var o,f;return(((o=i.parsed)==null?void 0:o.start)??0)-(((f=u.parsed)==null?void 0:f.start)??0);}).filter(i=>{var u;return r>=(((u=i.parsed)==null?void 0:u.start)??0);}).sort((i,u)=>{var o,f;return(((o=u.parsed)==null?void 0:o.start)??0)-(((f=i.parsed)==null?void 0:f.start)??0);})[0];return a==null?void 0:a.slot;}function A(e,r){const t=N(e,r);if(t)return h(t);}function V(e,r){var n;const t=(n=e==null?void 0:e.customCardPreferences)==null?void 0:n.slotIndex;return typeof t=="number"?t:r;}function S(e,r){var t;if(!((t=e==null?void 0:e.customCardPreferences)!=null&&t.url))return!1;if(e.type==="custom"||e.customCardPreferences.visualType==="multiple"||e.customCardPreferences.dataInputCardIds||(e.customCardPreferences.minInputs||0)>1||(e.customCardPreferences.maxInputs||0)>1)return!0;if(r&&r.length>1){const n=r.filter(s=>{var d;return typeof((d=s.customCardPreferences)==null?void 0:d.slotIndex)=="number";});if(n.length>1&&n.some(s=>s.id!==e.id))return!0;}return!1;}function O(e){const r=[];let t=-1;e.forEach((n,s)=>{const d=V(n,s);d>t&&(t=d),r[d]=n??null;});for(let n=0;n<=t;n+=1)n in r||(r[n]=null);return r;}function $(e){return e.map((r,t)=>!r.customCardPreferences||r.customCardPreferences.slotIndex===t?r:{...r,customCardPreferences:{...r.customCardPreferences,slotIndex:t}});}function v(e){const r=k(e);if(r)return h(r);}function R(e,r,t){if(!e)return;const n=A(t,r);return e.type==="custom"&&n?n:e.type;}function Y(e,r,t){var T;const n={dataSource:t.dataSource,connectionId:t.connectionId},s={type:"component",visualType:"multiple",url:r.url,componentName:r.name,icon:r.icon,pluginChartType:r.chartType,minInputs:r.minInputs,maxInputs:r.maxInputs},d=r.minInputs||1,p=e.map(c=>({slot:c,parsed:m(c.position)})).filter(c=>c.parsed!==null).reduce((c,l)=>{const g=l.parsed.end;return Number.isFinite(g)?Math.max(c,g):c;},-1),b=Math.max(d,p+1),a=k(e),i=a?x(a):0;let u=!1;const o=[];for(let c=0;c<b;c+=1){const l=N(e,c),g=h(l),I=!u&&c===i,P=c,C={...n,id:F(),title:(I?a==null?void 0:a.label:l==null?void 0:l.label)||`Tab ${c+1}`,tabTitle:(I?a==null?void 0:a.label:l==null?void 0:l.label)||`Tab ${c+1}`,description:(I?a==null?void 0:a.description:l==null?void 0:l.description)||"",type:g,sql:"",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},...(I&&{customCardPreferences:{...s,slotIndex:P}}),...(!I&&{customCardPreferences:{slotIndex:P}})};I&&(u=!0),o.push(C);}if(!u&&o.length>0){const c=((T=o[0].customCardPreferences)==null?void 0:T.slotIndex)??0;o[0]={...o[0],type:o[0].type,customCardPreferences:{...s,slotIndex:c}};}const f=o.findIndex(c=>{var l;return!!((l=c.customCardPreferences)!=null&&l.url);});if(f>0){const[c]=o.splice(f,1);o.unshift(c);}return o;}function _({frame:e,configCard:r,isMultiInputVisual:t}){var s;if(!t||!r)return e.cards;const n=(s=r.customCardPreferences)==null?void 0:s.dataInputCardIds;return n?Object.keys(n).sort((d,y)=>Number(d)-Number(y)).map(d=>{var p;const y=(p=n[d])==null?void 0:p.cardId;return e.cards.find(b=>b.id===y)||null;}):e.cards;}function j(e,r){return r&&S(r,e.cards)?r:e.cards.find(t=>S(t,e.cards))||null;}function q(e,r){var s,d;if(!e)return null;const t=r==null?void 0:r.visualType;if(t)return t;if(r!=null&&r.slots&&r.slots.length>0||((r==null?void 0:r.minInputs)||0)>1||((r==null?void 0:r.maxInputs)||0)>1||((r==null?void 0:r.dataInputs)||[]).length>1)return"multiple";const n=(s=e.customCardPreferences)==null?void 0:s.visualType;return n||((d=e.customCardPreferences)!=null&&d.dataInputCardIds?"multiple":null);}function w(e){return e.visualType==="multiple"||e.slots&&e.slots.length>0||(e.minInputs||0)>1||(e.maxInputs||0)>1||(e.dataInputs||[]).length>1?"multiple":"single";}function z(e){return Array.isArray(e)?{records:e}:e;}export{V as a,O as b,R as c,w as d,Y as e,j as f,_ as g,N as h,S as i,$ as j,h as k,v as l,z as n,q as r};
@@ -1 +1 @@
1
- import{r as j,k as x,m as $}from"./resolve-dashboard-input-context-Djm2WgEF.js";function I(s,t,n={}){var u,m,g;if(t.clear){if(t.html!==void 0||t.slots||t.settings)return d("Start over takes the visual off the card; send its new code as a separate change.","customVisual","Send clear alone.");if(!s.customVisual&&s.type==="customVisual")return{ok:!0,card:s,manifest:void 0};const{customVisual:l,...a}=s;return{ok:!0,card:{...a,type:"customVisual"},manifest:void 0};}const i=s.customVisual??{};let e=i,r=n.manifest;if(t.html!==void 0){const l=j(t.html,{kind:"visual"});if(!l.ok&&!n.keepUnreadable){const a=l.findings.filter(o=>o.severity==="error");return{ok:!1,problem:{code:"invalid_change",message:a.map(o=>o.message).join(" ")||"The visual is invalid.",path:"html",fix:((u=a.find(o=>o.fix))==null?void 0:u.fix)??"Fix the HTML against the contract (semaphor_get_extension_contract) and send it again.",details:{reason:"custom_visual_invalid",findings:l.findings}}};}if(r=l.ok?l.manifest:void 0,t.html!==((m=i.draft)==null?void 0:m.html)){const{version:a,draft:o,...f}=e;e={...f,draft:{html:t.html}};}r&&(e=O(e,r));}if((t.slots&&Object.keys(t.slots).length||t.settings&&Object.keys(t.settings).length)&&!r)return d("This visual's slots and settings can't be read, so they can't be changed.","customVisual","Send the visual's html with the change, or change it in the editor.");if(t.slots){for(const a of Object.keys(t.slots))if(!r.slots.some(o=>o.id===a))return d(`This visual has no slot "${a}"; it has ${p(r.slots.map(o=>o.id))}.`,`slots.${a}`,"Name one of its slots.",r.slots.map(o=>o.id));const l=k(e.slots,t.slots,_);l!==e.slots&&(e=h(e,"slots",l));}if(t.settings){const l={};for(const[o,f]of Object.entries(t.settings)){const c=(g=r.settings)==null?void 0:g[o];if(!c){const v=Object.keys(r.settings??{});return d(v.length?`This visual has no setting "${o}"; it has ${p(v)}.`:`This visual has no settings, so "${o}" can't be set.`,`settings.${o}`,"Name one of its settings.",v);}if(f===null||f===c.default){l[o]=null;continue;}const b=y(c,f);if(b)return d(`"${c.label}" ${b}.`,`settings.${o}`,"Send a value the setting takes.",V(c));l[o]=f;}const a=k(e.settings,l,(o,f)=>o===f);a!==e.settings&&(e=h(e,"settings",a));}return e===i&&s.type==="customVisual"?{ok:!0,card:s,manifest:r}:{ok:!0,card:{...s,type:"customVisual",customVisual:e},manifest:r};}function d(s,t,n,i){return{ok:!1,problem:{code:"invalid_change",message:s,path:t,fix:n,...(i!=null&&i.length?{allowed:i}:{})}};}function O(s,t){let n=s;if(s.slots){const i=Object.fromEntries(Object.entries(s.slots).filter(([e])=>t.slots.some(r=>r.id===e)));Object.keys(i).length!==Object.keys(s.slots).length&&(n=h(n,"slots",i));}if(s.settings){const i=Object.fromEntries(Object.entries(s.settings).filter(([e,r])=>{var m;const u=(m=t.settings)==null?void 0:m[e];return u&&r!==u.default&&!y(u,r);}));Object.keys(i).length!==Object.keys(s.settings).length&&(n=h(n,"settings",i));}return n;}function y(s,t){switch(s.type){case"boolean":return typeof t=="boolean"?void 0:"is on or off (true or false)";case"number":return typeof t!="number"||!Number.isFinite(t)?"takes a number":s.min!==void 0&&t<s.min?`is at least ${s.min}`:s.max!==void 0&&t>s.max?`is at most ${s.max}`:void 0;case"string":return typeof t!="string"?"takes text":s.maxLength!==void 0&&t.length>s.maxLength?`takes at most ${s.maxLength} characters`:void 0;case"select":return typeof t=="string"&&s.options.some(n=>n.value===t)?void 0:`is one of ${p(s.options.map(n=>n.value))}`;case"color":return typeof t=="string"&&(x(t)||$(t))?void 0:"takes a theme colour (palette-1 to palette-8, primary, positive…) or a hex colour";}}function V(s){if(s.type==="select")return s.options.map(t=>t.value);if(s.type==="boolean")return["true","false"];}function p(s){const t=s.map(n=>`"${n}"`);return t.length<=1?t[0]??"none":`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`;}function k(s,t,n){let i=s;for(const[e,r]of Object.entries(t)){const u=i==null?void 0:i[e];if(r===null){if(u===void 0)continue;const{[e]:m,...g}=i;i=g;}else(u===void 0||!n(u,r))&&(i={...i,[e]:r});}return i;}function h(s,t,n){const{[t]:i,...e}=s;return n&&Object.keys(n).length?{...e,[t]:n}:e;}function _(s,t){return"fieldId"in s?"fieldId"in t&&s.fieldId===t.fieldId:"column"in t&&s.column===t.column;}export{I as w};
1
+ import{r as j,k as x,m as $}from"./resolve-dashboard-input-context-D3lfJtPf.js";function I(s,t,n={}){var u,m,g;if(t.clear){if(t.html!==void 0||t.slots||t.settings)return d("Start over takes the visual off the card; send its new code as a separate change.","customVisual","Send clear alone.");if(!s.customVisual&&s.type==="customVisual")return{ok:!0,card:s,manifest:void 0};const{customVisual:l,...a}=s;return{ok:!0,card:{...a,type:"customVisual"},manifest:void 0};}const i=s.customVisual??{};let e=i,r=n.manifest;if(t.html!==void 0){const l=j(t.html,{kind:"visual"});if(!l.ok&&!n.keepUnreadable){const a=l.findings.filter(o=>o.severity==="error");return{ok:!1,problem:{code:"invalid_change",message:a.map(o=>o.message).join(" ")||"The visual is invalid.",path:"html",fix:((u=a.find(o=>o.fix))==null?void 0:u.fix)??"Fix the HTML against the contract (semaphor_get_extension_contract) and send it again.",details:{reason:"custom_visual_invalid",findings:l.findings}}};}if(r=l.ok?l.manifest:void 0,t.html!==((m=i.draft)==null?void 0:m.html)){const{version:a,draft:o,...f}=e;e={...f,draft:{html:t.html}};}r&&(e=O(e,r));}if((t.slots&&Object.keys(t.slots).length||t.settings&&Object.keys(t.settings).length)&&!r)return d("This visual's slots and settings can't be read, so they can't be changed.","customVisual","Send the visual's html with the change, or change it in the editor.");if(t.slots){for(const a of Object.keys(t.slots))if(!r.slots.some(o=>o.id===a))return d(`This visual has no slot "${a}"; it has ${p(r.slots.map(o=>o.id))}.`,`slots.${a}`,"Name one of its slots.",r.slots.map(o=>o.id));const l=k(e.slots,t.slots,_);l!==e.slots&&(e=h(e,"slots",l));}if(t.settings){const l={};for(const[o,f]of Object.entries(t.settings)){const c=(g=r.settings)==null?void 0:g[o];if(!c){const v=Object.keys(r.settings??{});return d(v.length?`This visual has no setting "${o}"; it has ${p(v)}.`:`This visual has no settings, so "${o}" can't be set.`,`settings.${o}`,"Name one of its settings.",v);}if(f===null||f===c.default){l[o]=null;continue;}const b=y(c,f);if(b)return d(`"${c.label}" ${b}.`,`settings.${o}`,"Send a value the setting takes.",V(c));l[o]=f;}const a=k(e.settings,l,(o,f)=>o===f);a!==e.settings&&(e=h(e,"settings",a));}return e===i&&s.type==="customVisual"?{ok:!0,card:s,manifest:r}:{ok:!0,card:{...s,type:"customVisual",customVisual:e},manifest:r};}function d(s,t,n,i){return{ok:!1,problem:{code:"invalid_change",message:s,path:t,fix:n,...(i!=null&&i.length?{allowed:i}:{})}};}function O(s,t){let n=s;if(s.slots){const i=Object.fromEntries(Object.entries(s.slots).filter(([e])=>t.slots.some(r=>r.id===e)));Object.keys(i).length!==Object.keys(s.slots).length&&(n=h(n,"slots",i));}if(s.settings){const i=Object.fromEntries(Object.entries(s.settings).filter(([e,r])=>{var m;const u=(m=t.settings)==null?void 0:m[e];return u&&r!==u.default&&!y(u,r);}));Object.keys(i).length!==Object.keys(s.settings).length&&(n=h(n,"settings",i));}return n;}function y(s,t){switch(s.type){case"boolean":return typeof t=="boolean"?void 0:"is on or off (true or false)";case"number":return typeof t!="number"||!Number.isFinite(t)?"takes a number":s.min!==void 0&&t<s.min?`is at least ${s.min}`:s.max!==void 0&&t>s.max?`is at most ${s.max}`:void 0;case"string":return typeof t!="string"?"takes text":s.maxLength!==void 0&&t.length>s.maxLength?`takes at most ${s.maxLength} characters`:void 0;case"select":return typeof t=="string"&&s.options.some(n=>n.value===t)?void 0:`is one of ${p(s.options.map(n=>n.value))}`;case"color":return typeof t=="string"&&(x(t)||$(t))?void 0:"takes a theme colour (palette-1 to palette-8, primary, positive…) or a hex colour";}}function V(s){if(s.type==="select")return s.options.map(t=>t.value);if(s.type==="boolean")return["true","false"];}function p(s){const t=s.map(n=>`"${n}"`);return t.length<=1?t[0]??"none":`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`;}function k(s,t,n){let i=s;for(const[e,r]of Object.entries(t)){const u=i==null?void 0:i[e];if(r===null){if(u===void 0)continue;const{[e]:m,...g}=i;i=g;}else(u===void 0||!n(u,r))&&(i={...i,[e]:r});}return i;}function h(s,t,n){const{[t]:i,...e}=s;return n&&Object.keys(n).length?{...e,[t]:n}:e;}function _(s,t){return"fieldId"in s?"fieldId"in t&&s.fieldId===t.fieldId:"column"in t&&s.column===t.column;}export{I as w};
@@ -1 +1 @@
1
- import{jsx as a,jsxs as n}from"react/jsx-runtime";import{F as o,B as i,S as d,U as s,D as c,A as l,C as t,a as h}from"./semaphor-ready-indicator-BJR23T8j.js";import{E as f,S as m}from"./appearance-provider-CxsEFvNA.js";function x(e){if(typeof window>"u")return null;const{preferences:r}=e;return/* @__PURE__ */a(f,{FallbackComponent:o,children:/* @__PURE__ */a(m,{dashboardProps:e,children:/* @__PURE__ */n(i,{children:[/* @__PURE__ */a(d,{componentType:"dashboard",componentId:e.id}),/* @__PURE__ */a(s,{appearance:e.appearance,children:/* @__PURE__ */a(c,{preferences:r,children:/* @__PURE__ */a(l,{children:/* @__PURE__ */a("main",{className:"flex h-full flex-col",children:/* @__PURE__ */a(t,{...e,type:"dashboard",children:/* @__PURE__ */a(h,{})})})})})})]})})});}export{x as D};
1
+ import{jsx as a,jsxs as n}from"react/jsx-runtime";import{F as o,B as i,S as d,U as s,D as c,A as l,C as t,a as h}from"./semaphor-ready-indicator-X4VBj9J1.js";import{E as f,S as m}from"./appearance-provider-nxBjHmOo.js";function x(e){if(typeof window>"u")return null;const{preferences:r}=e;return/* @__PURE__ */a(f,{FallbackComponent:o,children:/* @__PURE__ */a(m,{dashboardProps:e,children:/* @__PURE__ */n(i,{children:[/* @__PURE__ */a(d,{componentType:"dashboard",componentId:e.id}),/* @__PURE__ */a(s,{appearance:e.appearance,children:/* @__PURE__ */a(c,{preferences:r,children:/* @__PURE__ */a(l,{children:/* @__PURE__ */a("main",{className:"flex h-full flex-col",children:/* @__PURE__ */a(t,{...e,type:"dashboard",children:/* @__PURE__ */a(h,{})})})})})})]})})});}export{x as D};