react-semaphor 0.1.609 → 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.
- package/dist/.gate-build-input +1 -0
- package/dist/analytics-protocol/index.js +1 -1
- package/dist/assistant-context/index.js +1 -1
- package/dist/brand-studio/index.js +2 -2
- package/dist/briefings/index.js +1 -1
- package/dist/chunks/appearance-provider-nxBjHmOo.js +708 -0
- package/dist/chunks/{assistant-chat-DAmFZEnD.js → assistant-chat-DGaSGyx_.js} +13 -13
- package/dist/chunks/{attachment-filter-line-ClTS4GvQ.js → attachment-filter-line-CVkfzZF9.js} +1 -1
- package/dist/chunks/{bookmark-impact-BEVaXjug.js → bookmark-impact-DnhE262D.js} +1 -1
- package/dist/chunks/{bookmark-state-DnkzIsyw.js → bookmark-state-CrJDZi3y.js} +1 -1
- package/dist/chunks/{brand-BjC1mPjw.js → brand-BjIkbHgw.js} +1 -1
- package/dist/chunks/card-filter-builder-9xCSYFNv.js +11 -0
- package/dist/chunks/{check-input-qgwboKei.js → check-input-DmKJoLY-.js} +1 -1
- package/dist/chunks/{comparison-window-caption-WzGsqv4n.js → comparison-window-caption-DImvKgCt.js} +1 -1
- package/dist/chunks/currency-presentation-binding-DCHJ2sRD.js +1 -0
- package/dist/chunks/{custom-visual-inputs-CoAs_73N.js → custom-visual-inputs-C2BRX8l_.js} +1 -1
- package/dist/chunks/{custom-visual-write-BWApKrHe.js → custom-visual-write-CYA-Y9YF.js} +1 -1
- package/dist/chunks/{dashboard-DbBgEesz.js → dashboard-DEsWObFS.js} +1 -1
- package/dist/chunks/dashboard-briefing-launcher-PzvxJm1T.js +42 -0
- package/dist/chunks/{dashboard-controls-CyQg_GC1.js → dashboard-controls-DPVMjbpG.js} +5 -5
- package/dist/chunks/{dashboard-json-ZSAQQkcR.js → dashboard-json-CWJ6drfv.js} +1 -1
- package/dist/chunks/{dashboard-temporal-snapshot-BSTfqT29.js → dashboard-temporal-snapshot-C2y8qWoK.js} +1 -1
- package/dist/chunks/dates-ByeRG2Tz.js +1 -0
- package/dist/chunks/edit-dashboard-visual-BxwhXWe2.js +103 -0
- package/dist/chunks/{filter-line-W-qQAjke.js → filter-line-BpaHAj8x.js} +1 -1
- package/dist/chunks/filter-reach-preview-C9WDhZaV.js +1 -0
- package/dist/chunks/{filter-value-text-DQwYZHz0.js → filter-value-text-vD4CXg9H.js} +1 -1
- package/dist/chunks/{kpi-trend-rule-B4ebKzNj.js → kpi-trend-rule-H3cLKxwe.js} +1 -1
- package/dist/chunks/matrix-analytical-definition-B6Auo_Up.js +1 -0
- package/dist/chunks/{matrix-member-presentation-Chz6uGYz.js → matrix-member-presentation-B6wzUGA9.js} +1 -1
- package/dist/chunks/matrix-operation-contract-1dtkh4UB.js +1 -0
- package/dist/chunks/{metric-formatting-toJrRqu4.js → metric-formatting-BF1b9EEC.js} +1 -1
- package/dist/chunks/numeric-range-options-B_EcRH8C.js +1 -0
- package/dist/chunks/{palette-DpLPXjUd.js → palette-DLYro9VS.js} +1 -1
- package/dist/chunks/pivot-result-contract-expectations-Bl55bAD9.js +1 -0
- package/dist/chunks/{pivot-result-identity-DRhVJMsF.js → pivot-result-identity-CAP9xTVF.js} +1 -1
- package/dist/chunks/{raw-temporal-value-B4Md6Xfb.js → raw-temporal-value-DqmEQqi9.js} +1 -1
- package/dist/chunks/report-preferences-dialog-CV0NMmo0.js +1 -0
- package/dist/chunks/report-runtime-context-DUyoI64N.js +1 -0
- package/dist/chunks/resolve-dashboard-input-context-D3lfJtPf.js +8 -0
- package/dist/chunks/{sandbox-host-BqcLSoTV.js → sandbox-host-DTsb-07w.js} +1 -1
- package/dist/chunks/saved-dashboard-context-pT-jLe_M.js +1 -0
- package/dist/chunks/{selection-filter-compiler-BxtEEB6Z.js → selection-filter-compiler-D2O1G8aM.js} +1 -1
- package/dist/chunks/semaphor-ready-indicator-X4VBj9J1.js +542 -0
- package/dist/chunks/{slider-C2nbml5r.js → slider-BuDy7URL.js} +5 -5
- package/dist/chunks/stored-dashboard-CtbTHA6d.js +1 -0
- package/dist/chunks/table-cell-text-CcdZI7W5.js +1 -0
- package/dist/chunks/{table-export-sheet-CthBUHu4.js → table-export-sheet-CR05ORx7.js} +1 -1
- package/dist/chunks/{token-types-BM0mpZce.js → token-types-DapH4m_I.js} +1 -1
- package/dist/chunks/validators-D6oX9c_4.js +1 -0
- package/dist/chunks/{variable-draft-DAVLIY3l.js → variable-draft-BugdJvFc.js} +1 -1
- package/dist/chunks/work-days-BbCJDTJK.js +1 -0
- package/dist/dashboard/index.js +1 -1
- package/dist/dashboard-authoring/index.js +1 -1
- package/dist/extensions/index.js +1 -1
- package/dist/format-utils/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/report-runtime-context/index.js +1 -1
- package/dist/style.css +1 -1
- package/dist/surfboard/index.js +1 -1
- package/dist/types/briefings/index.d.ts +1 -1
- package/dist/types/briefings/run-failures.d.ts +67 -0
- package/dist/types/components/surfboard/index.d.ts +1 -0
- package/dist/types/components/surfboard/preferences/work-day-toggles.d.ts +16 -0
- package/dist/types/components/ui-custom/date-range-presets.d.ts +4 -1
- package/dist/types/components/visual/data-table/column-display/link-fields.d.ts +29 -0
- package/dist/types/components/visual/data-table/types/data-table.d.ts +6 -1
- package/dist/types/index.js +1 -1
- package/dist/types/lib/stores/dashboard-store.d.ts +2 -0
- package/dist/types/lib/types/briefing-types.d.ts +4 -0
- package/dist/types/shared/analytics-protocol/comparison-choices.d.ts +7 -0
- package/dist/types/shared/analytics-protocol/comparison-placement.d.ts +2 -0
- package/dist/types/shared/analytics-protocol/relative-date/index.d.ts +1 -1
- package/dist/types/shared/analytics-protocol/relative-date/presets.d.ts +1 -1
- package/dist/types/shared/analytics-protocol/relative-date/resolve.d.ts +4 -2
- package/dist/types/shared/analytics-protocol/relative-date/schemas.d.ts +7 -0
- package/dist/types/shared/analytics-protocol/relative-date/traits.d.ts +2 -1
- package/dist/types/shared/analytics-protocol/relative-date/window.d.ts +9 -1
- package/dist/types/shared/dashboard-authoring/card-data-source/data-source-selection.d.ts +11 -0
- package/dist/types/shared/dashboard-authoring/card-data-source/index.d.ts +1 -0
- package/dist/types/shared/dashboard-authoring/card-settings/column-display.d.ts +0 -2
- package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +16 -0
- package/dist/types/shared/dashboard-authoring/filter-model/filter-values.d.ts +10 -0
- package/dist/types/shared/dashboard-authoring/frame-cards.d.ts +29 -0
- package/dist/types/shared/dashboard-authoring/operations/card-operations.d.ts +13 -10
- package/dist/types/shared/dashboard-authoring/operations/operation-sentences.d.ts +18 -0
- package/dist/types/shared/dashboard-authoring/operations/operation-types.d.ts +16 -1
- package/dist/types/shared/dashboard-authoring/outline/outline-dashboard.d.ts +12 -1
- package/dist/types/shared/dashboard-authoring/sheet-kinds.d.ts +7 -0
- package/dist/types/shared/dashboard-authoring/table-sheet-shape.d.ts +53 -3
- package/dist/types/shared/dashboard-viewer/table-column-move.d.ts +7 -0
- package/dist/types/shared/extensions/saved-refs.d.ts +1 -15
- package/dist/types/shared/report-runtime-context/index.d.ts +1 -0
- package/dist/types/shared/report-runtime-context/report-runtime-context.d.ts +22 -1
- package/dist/types/shared/report-runtime-context/work-days.d.ts +31 -0
- package/dist/types/shared/temporal/calendar-periods.d.ts +1 -1
- package/dist/types/shared/usage-events/details.d.ts +2 -2
- package/package.json +7 -5
- package/dist/chunks/appearance-provider-BW022_Qu.js +0 -613
- package/dist/chunks/card-filter-builder-BGIVEHmJ.js +0 -11
- package/dist/chunks/currency-presentation-binding-ClrH_6Tq.js +0 -1
- package/dist/chunks/dashboard-briefing-launcher-DadG4ES9.js +0 -42
- package/dist/chunks/edit-dashboard-visual-DIF1fllI.js +0 -103
- package/dist/chunks/filter-reach-preview-CfbwaLf4.js +0 -1
- package/dist/chunks/layout-grid-Cs350bW-.js +0 -6
- package/dist/chunks/matrix-analytical-definition-jn075ooo.js +0 -1
- package/dist/chunks/matrix-operation-contract-DceN49RX.js +0 -1
- package/dist/chunks/numeric-range-options-Drc1EZ6H.js +0 -1
- package/dist/chunks/pivot-result-contract-expectations-D_ane7I2.js +0 -1
- package/dist/chunks/report-preferences-dialog-DEfUYExu.js +0 -1
- package/dist/chunks/report-runtime-context-CkxgMKr6.js +0 -1
- package/dist/chunks/resolve-dashboard-input-context-Dm4PD8Gx.js +0 -8
- package/dist/chunks/saved-dashboard-context-GjEJuDjj.js +0 -1
- package/dist/chunks/semaphor-ready-indicator-BViyPq5k.js +0 -622
- package/dist/chunks/set-q-2M4nis.js +0 -1
- package/dist/chunks/stored-dashboard-CTwrNvBy.js +0 -1
- package/dist/chunks/table-cell-text-DJe6I1G3.js +0 -1
- package/dist/chunks/validators-U8IL8djK.js +0 -1
- package/dist/types/briefings/run-outcomes.d.ts +0 -6
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import{c as pt,u as Bt,F as pe,an as Ut,ao as Wt,ap as Kt,aq as Qt,ar as Ht,as as Yt,at as Xt,B,au as Jt,d as ge,ac as Xe,af as mt,av as re,a2 as be,a4 as le,a5 as ie,a6 as oe,a7 as de,a8 as ee,aa as Ve,aw as Pt,ax as Zt,ay as ft,az as Je,aA as ea,aB as ta,aC as ce,P as ht,b as gt,X as bt,e as xt,aD as vt,aE as aa,aF as ra,aG as na,aH as sa,aI as la,ag as ia,ab as oa,aJ as yt}from"./appearance-provider-BW022_Qu.js";import{jsx as e,jsxs as c,Fragment as me}from"react/jsx-runtime";import{n as U,aD as da,aE as fe,aF as Pe,aG as Ze,aH as Oe,aI as Ae,aJ as ca,aK as ua,aL as et,aM as pa,aN as ma,aO as he,aP as fa,aQ as tt,aR as Nt,aS as Ct,aT as wt,aU as St,aV as ha,aW as ga,aX as at,aY as ba,aZ as rt,a_ as xa,a$ as va,b0 as ya,b1 as Na,b2 as Ee,e as xe,b3 as nt,b4 as Ca,b5 as Fe,b6 as wa,b7 as Sa,b8 as ka,b9 as Da,ba as Ta}from"./resolve-dashboard-input-context-Dm4PD8Gx.js";import{k as kt,r as La,aE as Dt,aF as Tt}from"./validators-U8IL8djK.js";import{a as Lt}from"./matrix-operation-contract-DceN49RX.js";import"./analytics-base-schemas-DMFrDqn_.js";import"../value-format-preferences/index.js";import{u as Oa,as as st,at as Aa,au as Ot,av as At,aw as Ea,ax as Fa,ay as Ia,az as $a,aA as Va,aB as _a,aC as lt,aD as _e,aE as se,aF as Re,aG as ze,aH as Ge,aI as Ra,aJ as ve,aK as ye,aL as Ne,aM as Ce,aN as Et,aO as Ft,aP as za}from"./semaphor-ready-indicator-BViyPq5k.js";import*as we from"react";import{useMemo as Z,useState as te,useRef as Ie,useCallback as P,useEffect as Me,Fragment as Ga}from"react";import{r as Ma,m as qa}from"./raw-temporal-value-B4Md6Xfb.js";/**
|
|
2
|
-
* @license lucide-react v0.453.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const xr=pt("FilterX",[["path",{d:"M13.013 3H2l8 9.46V19l4 2v-8.54l.9-1.055",key:"1fi1da"}],["path",{d:"m22 3-5 5",key:"12jva0"}],["path",{d:"m17 3 5 5",key:"k36vhe"}]]);/**
|
|
7
|
-
* @license lucide-react v0.453.0 - ISC
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the ISC license.
|
|
10
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const ja=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 vr({type:t,isLinked:r,className:s,showLabel:i=!1,showLocal:F=!1}){const h=Bt(O=>O.selectedFrameId),k=Oa(O=>O.selectedVisual),b=pe(O=>O.frame);let m;if(t)m=t;else if(r!==void 0)m=r?"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(ja,{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(Ht,{side:"bottom",className:U("max-w-xs",N[m]),children:[/* @__PURE__ */e(Yt,{className:I[m]}),/* @__PURE__ */e("p",{children:L[m]})]})]})});}function It(t){const{control:r,onChange:s}=t;return/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(re,{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:i=>s(i.target.value)})]});}function Ba(t){const{currentStep:r,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===r,b=h<r;return/* @__PURE__ */c(Ga,{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:r,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:[r,s,i]});}function Ua(t){const{control:r,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(Pt,{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:r.label}),/* @__PURE__ */c("div",{className:"text-[12px] text-muted-foreground",children:[Nt(r.type).label," ·"," ",wt(r)," ·"," ",Ct(s,r.placement)]}),i?/* @__PURE__ */e("div",{className:"text-[12px] text-muted-foreground",children:i}):null]})]});}function it(t){const{control:r,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(It,{control:r,onChange:m}),/* @__PURE__ */e(Ot,{control:r,availableFieldChoices:i,availableMetricChoices:F,previewControlDefinitions:h,previewControlValues:k,controlLifecycle:"create",onChange:b}),/* @__PURE__ */e(At,{control:r,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 Wa=/* @__PURE__ */new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]);function ot(t){const{text:r,ariaLabel:s}=t,[i,F]=te(!1);return/* @__PURE__ */c("button",{type:"button","aria-label":s,onClick:async()=>{try{await navigator.clipboard.writeText(r),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:r}),/* @__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:r,scope:s,createdReference:i,explorerContent:F,sqlDescription:h,summaryDetail:k,onBack:b,onCancel:m,onDone:x}=t,L=Wa.has(r.type),N=i.match(/\[\[param\.(.+?)\]\]/),I=N?`{{ param('${N[1]}') }}`:"";return/* @__PURE__ */c("div",{className:"space-y-4",children:[/* @__PURE__ */e(Ua,{control:r,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 Ka(t){const r=fe(t.scope,t.existingControls,t.reservedIds),s=t.type===r.type?{...r,label:Ee[t.type]}:{...St({controls:[{...r,label:Ee[t.type]}],controlId:r.id,nextType:t.type}).controls[0],label:Ee[t.type]};return{step:2,control:s,defaultValue:he(s,void 0)};}function yr({scope:t,controls:r,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:O}){const z=Z(()=>new Set(s||[]),[s]),$=ha(t),X=da(t),[D,T]=te(null),[Q,Y]=te(null),[n,g]=te(()=>k?{step:1,control:fe(t,r,Array.from(z))}:null),C=Ie({}),f=Ie(void 0),d=Ie(k),l=Z(()=>{const a=Pe({scope:t,card:I});if(!S)return a;const u=new Set(S);return a.filter(o=>u.has(o.value));},[S,I,t]),V=P(a=>{const u=Pe({scope:t,card:I,includeType:S?void 0:a});if(!S)return u;const o=new Set(S);return u.filter(v=>o.has(v.value));},[S,I,t]),p=P(a=>t==="dashboard"&&(a==="field_selector"||a==="metric_selector"),[t]),K=Z(()=>n?Ze(L||[],n.control.type):[],[n,L]),A=Z(()=>{if(!n)return{fields:m||[],metrics:x||[]};if(!p(n.control.type))return{fields:m||[],metrics:x||[]};const a=n.selectedCardIds||[],u=Oe({controlType:n.control.type,participants:L||[],selectedCardIds:a});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 a=k&&!d.current;d.current=k,a&&(g({step:1,control:fe(t,r,Array.from(z))}),Y(null),T(null));},[r,k,z,t]);const R=a=>{if(!p(a.type))return{fields:m||[],metrics:x||[]};const u=(N==null?void 0:N[a.id])||[];if(u.length===0)return{fields:m||[],metrics:x||[]};const o=Oe({controlType:a.type,participants:L||[],selectedCardIds:u});return{fields:a.type==="field_selector"?o.choices.map(v=>({option:v,target:o.fieldTargetMap[v.value]})):[],metrics:a.type==="metric_selector"?o.choices.map(v=>({option:v,target:o.metricTargetMap[v.value]})):[]};},q=a=>{if(!p(a.control.type))return{nextControl:a.control,cardBindingsById:void 0};const u=(N==null?void 0:N[a.control.id])||[],o=Oe({controlType:a.control.type,participants:L||[],selectedCardIds:a.nextSelectedCardIds}),v=ya({control:a.control,choices:o.choices}),E=Object.fromEntries(u.filter(_=>!a.nextSelectedCardIds.includes(_)).map(_=>[_,void 0]));return a.nextSelectedCardIds.length>0&&v.source.kind==="manual"&&v.source.options.length>0&&Object.assign(E,rt({control:v,participants:L||[],selectedCardIds:a.nextSelectedCardIds,matrixTargetIds:a.matrixTargetIds})),{nextControl:v,cardBindingsById:E};},j=P((a,u=i,o={type:"update"})=>{const v=a.map(E=>(Ae({control:E,defaultValues:u}),ca(E)));F(v,u,o);},[i,F]),H=(a,u)=>{const o=r.find(M=>M.id===a);let v=r.map(M=>M.id!==a?M:u(M));const E=v.find(M=>M.id===a);let _,w;if(E&&(!o||xa({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(ae=>ae.id===a?ne.nextControl:ae),_=ne.cardBindingsById,w=[E.id];}else if(o&&(!E||!va(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===a);let W=i;if(o&&G){const M=Ae({control:o,defaultValues:i});o.source.kind==="manual"&&G.source.kind==="sql_query"&&(C.current[a]=M);const ne=M===void 0&&o.source.kind==="sql_query"&&G.source.kind==="manual"?C.current[a]:M,ae=at({previousControl:o,nextControl:G,currentDefaultValue:ne});G.source.kind==="manual"&&(C.current[a]=ae),i&&(W={...i},ae===void 0?delete W[a]:W[a]=ae),v=v.map(Ye=>Ye.id===a?{...G,defaultValue:ae}:Ye);}j(v,W,{type:"update",cardBindingsById:_,affectedBindingControlIds:w});},J=(a,u)=>{if(!u.trim())return;const o=Na(u);if(o===a||z.has(o)||r.some(_=>_.id===o&&_.id!==a))return;const v=r.map(_=>_.id===a?{..._,id:o}:_);if(!i){j(v,void 0,{type:"rename",oldId:a,newId:o});return;}const E={...i};Object.prototype.hasOwnProperty.call(E,a)&&(E[o]=E[a],delete E[a]),j(v,E,{type:"rename",oldId:a,newId:o});},Mt=a=>{const u=r.filter(v=>v.id!==a);if(!i){j(u,void 0,{type:"remove",controlId:a});return;}const o={...i};delete o[a],j(u,o,{type:"remove",controlId:a});},qt=P(()=>{f.current=void 0,g({step:1,control:fe(t,r,Array.from(z))}),Y(null),T(null);},[r,z,t]),ue=a=>{g(u=>u&&(()=>{const o=a(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=at({previousControl:u.control,nextControl:o,currentDefaultValue:v});return o.source.kind==="manual"&&(f.current=E),{...u,control:o,defaultValue:E};})());},Ue=a=>{g(u=>u&&(u.control.source.kind==="manual"&&(f.current=a),{...u,defaultValue:a}));},ke=(()=>{if(!n)return!1;if(n.step===2&&p(n.control.type))return(n.selectedCardIds||[]).length>0&&ua({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"&&(pa(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 ma(he(u,n.defaultValue));})(),We=()=>{var _;if(!n)return;const a=et(n.control),u=ba({label:a.label,fallbackId:a.id,existingControls:r,reservedIds:Array.from(z)}),o={...a,id:u},v=t==="dashboard"&&(o.type==="field_selector"||o.type==="metric_selector")&&(_=n.selectedCardIds)!=null&&_.length?rt({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=P(()=>{g(null);},[]),Ke=P(()=>{if(!(n!=null&&n.createdControlId)){g(null);return;}const a=n.control,u=n.createdControlId,o=he(a,n.defaultValue);if(i){const v={...i};o===void 0?delete v[u]:v[u]=o,j([...r,{...a,defaultValue:o}],v,{type:"add",cardBindingsById:n.cardBindingsById});}else j([...r,{...a,defaultValue:o}],void 0,{type:"add",cardBindingsById:n.cardBindingsById});Y(u),g(null),O==null||O();},[r,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.${fa(n.control.label)||n.control.id}]]`:"",Te=tt({controls:r,defaultValues:i}),Le=n?[...r,n.control]:r,He=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(Ba,{currentStep:n.step,labels:jt}),n.step===1&&(()=>{const a=/* @__PURE__ */new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]),u=/* @__PURE__ */new Set(["date","text"]),o=l.filter(_=>!a.has(_.value)&&!u.has(_.value)),v=l.filter(_=>a.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(Ka({scope:t,existingControls:r,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:a=>ue(u=>({...u,label:a}))}),/* @__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(a=>{const u=(n.selectedCardIds||[]).includes(a.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||[]),a.cardId]:(v.selectedCardIds||[]).filter(E=>E!==a.cardId)})}),/* @__PURE__ */c("div",{className:"min-w-0",children:[/* @__PURE__ */e("div",{className:"font-medium text-foreground",children:a.title}),/* @__PURE__ */e("div",{className:"text-[12px] text-muted-foreground",children:n.control.type==="field_selector"?`${a.fieldChoices.length} compatible group-by fields`:`${a.metricChoices.length} compatible metrics`})]})]},a.cardId);})}),/* @__PURE__ */e(st,{participants:K,selectedCardIds:n.selectedCardIds||[],control:n.control,selected:n.matrixTargetIds,onChange:(a,u)=>g(o=>o&&{...o,matrixTargetIds:{...o.matrixTargetIds,[a]:u}})}),/* @__PURE__ */e(Se,{secondary:/* @__PURE__ */e(B,{type:"button",variant:"outline",size:"xs",onClick:()=>g(a=>a&&{...a,step:1,selectedCardIds:[]}),children:"Back"}),primary:/* @__PURE__ */e(B,{type:"button",size:"xs",onClick:()=>g(a=>a&&{...a,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:He,onControlChange:a=>ue(()=>a),onLabelChange:a=>ue(u=>({...u,label:a})),onDefaultValueChange:Ue,onBack:()=>g(a=>a&&{...a,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:He,onControlChange:a=>ue(()=>a),onLabelChange:a=>ue(u=>({...u,label:a})),onDefaultValueChange:Ue,onBack:()=>g(a=>a&&{...a,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(a=>a&&{...a,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(a=>a&&{...a,step:3}),onCancel:De,onDone:Ke})]}):null,!n&&r.length===0?/* @__PURE__ */e("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:h}):null,!n&&r.map(a=>{const u=R(a),o=b==null?void 0:b[a.id],v=Ae({control:a,defaultValues:i}),E=Q===a.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:()=>Y(w=>w===a.id?null:a.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:a.label||"Untitled control"}),/* @__PURE__ */e("span",{className:_,children:Nt(a.type).label}),/* @__PURE__ */e("span",{className:_,children:Ct(t,a.placement)})]}),/* @__PURE__ */c("div",{className:"mt-0.5 text-[12px] text-muted-foreground",children:[wt(a),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(a.id),"aria-label":`Remove ${a.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(re,{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:w=>H(a.id,G=>({...G,label:w.target.value}))})]}),/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(re,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Type"}),/* @__PURE__ */c(le,{value:a.type,onValueChange:w=>{const G=St({controls:r,controlId:a.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(a.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(re,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Show in"}),/* @__PURE__ */c(le,{value:a.placement||X,onValueChange:w=>H(a.id,G=>({...G,placement:w})),children:[/* @__PURE__ */e(ie,{size:"xs",children:/* @__PURE__ */e(oe,{})}),/* @__PURE__ */e(de,{children:$.map(w=>/* @__PURE__ */e(ee,{value:w.value,children:w.label},w.value))})]})]})]}),p(a.type)?/* @__PURE__ */c(me,{children:[/* @__PURE__ */e(Aa,{type:a.type,participants:Ze(L||[],a.type).map(w=>({cardId:w.cardId,title:w.title,choiceCount:a.type==="field_selector"?w.fieldChoices.length:w.metricChoices.length})),selectedCardIds:(N==null?void 0:N[a.id])||[],onChange:w=>{const G=q({control:a,nextSelectedCardIds:w}),W=r.map(M=>M.id===a.id?G.nextControl:M);j(W,i,{type:"update",cardBindingsById:G.cardBindingsById});}}),/* @__PURE__ */e(st,{participants:L||[],selectedCardIds:(N==null?void 0:N[a.id])||[],control:a,onChange:(w,G)=>{const W=q({control:a,nextSelectedCardIds:(N==null?void 0:N[a.id])||[],matrixTargetIds:{[w]:G}});j(r.map(M=>M.id===a.id?W.nextControl:M),i,{type:"update",cardBindingsById:W.cardBindingsById});}})]}):null,/* @__PURE__ */e(Ot,{control:a,availableFieldChoices:u.fields,availableMetricChoices:u.metrics,previewControlDefinitions:r,previewControlValues:Te,controlLifecycle:"edit",onChange:w=>H(a.id,()=>w)}),a.initialValueStrategy==="saved_default"&&/* @__PURE__ */e(At,{control:a,value:v,allowNoDefault:!0,allowCardDefault:!0,previewControlDefinitions:r,previewControlValues:Te,onChange:w=>{const G=r.map(W=>W.id===a.id?{...W,defaultValue:w}:W);if(a.source.kind==="manual"&&(C.current[a.id]=w),i){const W={...i};w===void 0?delete W[a.id]:W[a.id]=w,j(G,W);return;}j(G,void 0);}}),/* @__PURE__ */c(Ea,{open:D===a.id,onOpenChange:w=>T(w?a.id:null),children:[/* @__PURE__ */e(Fa,{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===a.id?/* @__PURE__ */e(ge,{className:"h-3.5 w-3.5"}):/* @__PURE__ */e(Xe,{className:"h-3.5 w-3.5"}),"Advanced"]})}),/* @__PURE__ */c(Ia,{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(re,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Variable name"}),/* @__PURE__ */e($a,{controlId:a.id,onCommit:w=>J(a.id,w)},a.id)]}),/* @__PURE__ */c("div",{className:"flex flex-col gap-1.5",children:[/* @__PURE__ */e(re,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Initial value"}),/* @__PURE__ */c(le,{value:a.initialValueStrategy,onValueChange:w=>H(a.id,G=>({...G,initialValueStrategy:w})),children:[/* @__PURE__ */e(ie,{size:"xs",children:/* @__PURE__ */e(oe,{})}),/* @__PURE__ */e(de,{children:ga.map(w=>/* @__PURE__ */e(ee,{value:w.value,children:w.label},w.value))})]})]})]}),/* @__PURE__ */e(Va,{control:a,onChange:w=>H(a.id,()=>w)})]})]})]})]},a.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 Nr(t){const{open:r,onOpenChange:s,initialCreateFlowActive:i=!1,dismissMode:F="passive"}=t,h=r!==void 0,[k,b]=te(!1),[m,x]=te(i),L=h?r:k,N=P(y=>{!y&&m&&F==="passive"||(h||b(y),y||x(!1),s==null||s(y));},[h,m,F,s]),I=P(()=>{h||b(!1),x(!1),s==null||s(!1);},[h,s]);Me(()=>{L||x(!1);},[L]);const S=P(y=>{m&&y.preventDefault();},[m]);return{forceClose:I,handleOpenChange:N,isCreateFlowActive:m,preventPassiveDismissDuringCreate:S,resolvedOpen:L,setIsCreateFlowActive:x};}function $t(t){const{relativeMeta:r,latestValue:s,...i}=t;return i;}function qe(t,r){const s=$t(t);return r.relativeMeta?{...s,value:r.value,relativeMeta:r.relativeMeta}:{...s,value:r.value};}function Qa(t,r){const s=r==="in"||r==="not in"||r==="between"||r==="not between"?[]:r==="isNull"||r==="isNotNull"?null:"";return qe({...t,operator:r},{value:s});}function Ha(t,r){const s=xe(r.dataType)==="date";return qe({...t,field:r,operator:s?"between":"="},{value:""});}function Ya({initialFilters:t,availableFields:r,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}=_a(),m=r||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=xe(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=xe(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?$t(d):d),...f})),z=(g,C,f)=>y(g,C,()=>f),$=Zt(),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));},Y=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=kt(d.relativeMeta);if(K&&La(V)&&Dt(V,K)){const A=Ma(V,K),{label:R,range:q}=Je(K,{tz:($==null?void 0:$.tz)??"UTC",weekStart:($==null?void 0:$.weekStart)??1,anchor:($==null?void 0:$.anchor)??"now"}),j=A?qa(A):R;if(q){const[H]=Tt(V,[q.start,q.end]);return`${l} ${V} '${H.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:($==null?void 0:$.tz)??"UTC",weekStart:($==null?void 0:$.weekStart)??1,anchor:($==null?void 0:$.anchor)??"now"});return q?`${l} ${A} '${q.start.toISOString()}' AND '${q.end.toISOString()}' /* ${R}: dates update each time the card runs */`:Lt(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:Y,hasAnyFilters:n};}function Vt(t,r){const s=pe(x=>x.card.dataSource),i=pe(x=>x.card.connectionId),F=pe(x=>x.selectedConnectionId),{dataSource:h,connectionId:k}=r?nt(r):nt({dataSource:s,connectionId:i},F),b=Z(()=>({id:`card-filter-option:${t.id}`,...Ca(t,{dataSource:h,connectionId:k})}),[k,h,t]),m=Z(()=>ea({filter:b}),[b]);return ta(b,{inputContext:m,currentSelectionPolicy:"exclude"});}function Xa({field:t,source:r,selected:s,onChange:i,placeholder:F="Select values…",className:h}){const[k,b]=we.useState(!1),m=Vt(t,r),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: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,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 Ja({field:t,source:r,value:s,onChange:i,placeholder:F="Select value…",className:h}){var I,S;const[k,b]=we.useState(!1),m=Vt(t,r),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 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 Pa({value:t,operator:r,relativeMeta:s,latestValue:i,field:F,onChange:h,className:k}){const b=aa(),m=ra(),x=r==="between"||r==="not between",L=Dt(r),N=L?s:void 0,I=Z(()=>{if(!x||!s)return;const D=m(s);return{...D,tooltip:D.dates?void 0:Lt(s).dataAnchored?na:sa};},[x,s,m]),S=Z(()=>{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=Fe(t[0],b,"start"),T=Fe(t[1],b,"end");if(D&&T)return{from:D,to:T};}}},[t,x,I,b]),y=Z(()=>{if(!t||x||i)return;const D=Array.isArray(t)?t[0]:t;return Fe(D,b,"start");},[t,x,i,b]),O=D=>r==="<="||r===">"?ka(D,b):Da(D,b);return/* @__PURE__ */e(la,{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=Sa(T,r,{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=Tt(r,[D.from.toISOString(),D.to.toISOString()]);h({value:Q.length===1?Q[0]:Q,relativeMeta:T});}:void 0,relativeValue:N,comparisonValue:!x&&L?r:void 0,relativePoints:!x&&L?{operator:r}:"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:wa(F),staticTimeInputs:!1,showRelativeTab:L,className:U("min-w-0",k),buttonClassName:"h-7 text-[12px] [&>span]:text-[12px]",placeholder:"Select date…"});}const Za=t=>t.conditions.length>0||t.groups.length>0,je=["contains","startsWith","endsWith","like","not like"],er=["=","!=",">",">=","<","<=",...je,"in","not in","isNull","isNotNull"],tr=["=","!=",...je,"in","not in","isNull","isNotNull"],ar=["=","!=",">",">=","<","<=","in","not in","isNull","isNotNull"],rr=["=","!=","isNull","isNotNull"],nr=["between","=","!=","<","<=",">",">=","isNull","isNotNull"],sr={"=":"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 $e(t){return sr[t]||Ta(t);}function lr(t){switch(t){case"string":return tr;case"number":return ar;case"boolean":return rr;case"date":return nr;default:return er;}}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:r,"aria-label":s}){return/* @__PURE__ */c(le,{value:t,onValueChange:i=>r(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:r,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:O}=Et({id:t.id}),z={transform:Ft.Transform.toString(S),transition:y},$=xe(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(yt,{className:"h-3.5 w-3.5"})}),r>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(za,{value:t.field,onValueChange:T=>{x(s,t.id,Ha(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,Qa(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?$e(t.operator):""})}),/* @__PURE__ */e(de,{children:lr($).map(T=>/* @__PURE__ */e(ee,{value:T,children:$e(T)},T))})]}),X?/* @__PURE__ */e("div",{className:"min-w-0 flex-1"}):$==="string"?D?/* @__PURE__ */e(Xa,{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:`${$e(t.operator)}…`}):/* @__PURE__ */e(Ja,{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"}):$==="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"})]})]}):$==="date"?/* @__PURE__ */e(Pa,{value:t.value,operator:t.operator,relativeMeta:kt(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:r}){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"]}),r&&/* @__PURE__ */c(B,{type:"button",size:"xs",variant:"ghost",className:U("gap-1.5 text-muted-foreground hover:text-foreground",ut),onClick:r,children:[/* @__PURE__ */e(Ve,{className:"h-3 w-3"}),"Add group"]})]});}function ir({group:t,depth:r,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:O}){const{attributes:z,listeners:$,setNodeRef:X,transform:D,transition:T,isDragging:Q}=Et({id:t.id}),Y={transform:Ft.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:Y,className:U(r>0&&"mt-2 overflow-hidden rounded-[6px] border border-border/60",Q&&"z-50 opacity-50"),children:[r>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,...$,"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(yt,{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(r>0&&"p-2"),children:[/* @__PURE__ */e(ve,{sensors:_e(se(Ge),se(ze,{coordinateGetter:Re})),collisionDetection:ye,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(ve,{sensors:_e(se(Ge),se(ze,{coordinateGetter:Re})),collisionDetection:ye,onDragEnd:g,children:/* @__PURE__ */e(Ne,{items:t.groups.map(C=>C.id),strategy:Ce,children:t.groups.map(C=>S(C,r+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 Cr({filters:t,availableFields:r,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:O,replaceCondition:z,updateGroupOperator:$,updateGroupNegate:X,reorderConditions:D,reorderGroups:T,generateSQLPreview:Q,hasAnyFilters:Y}=Ya({initialFilters:t,availableFields:r,...(k?{onChange:l=>k(Za(l)?l:null)}:{})}),n=_e(se(Ge),se(ze,{coordinateGetter:Re})),[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(ve,{sensors:n,collisionDetection:ye,onDragEnd:A=>{const{active:R,over:q}=A;if(q&&R.id!==q.id){const j=l.conditions.findIndex(J=>J.id===R.id),H=l.conditions.findIndex(J=>J.id===q.id);j!==-1&&H!==-1&&D(l.id,j,H);}},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:$,availableFields:x,source:s,updateConditionFields:O,replaceCondition:z},A.id))})})}),/* @__PURE__ */e(ve,{sensors:n,collisionDetection:ye,onDragEnd:A=>{const{active:R,over:q}=A;if(q&&R.id!==q.id){const j=l.groups.findIndex(J=>J.id===R.id),H=l.groups.findIndex(J=>J.id===q.id);j!==-1&&H!==-1&&T(l.id,j,H);}},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(ir,{group:l,depth:V,parentGroupId:p,onUpdateGroupOperator:$,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=Ra(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(ia,{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(oa,{size:"xs",id:"advanced-mode",checked:g,onCheckedChange:l=>C(l)}),/* @__PURE__ */e(re,{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"})]}),Y&&!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(Y?m:null),children:"Apply filters"})]})]})]});}export{yr as C,xr as F,ja as L,vr as V,Cr as a,Nr as u};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{u as G,w as S,x as Q,y as X,z as _,A as $,B as H,C as Y}from"./resolve-dashboard-input-context-Dm4PD8Gx.js";import{canonicalizeSupportedCurrencyCode as K}from"../value-format-preferences/index.js";import{F as Z}from"./bookmark-state-DnkzIsyw.js";import{l as v}from"./validators-U8IL8djK.js";import"./matrix-operation-contract-DceN49RX.js";import"./analytics-base-schemas-DMFrDqn_.js";import{b,r as U,aI as W,i as ee,aJ as ne}from"./pivot-result-contract-expectations-D_ane7I2.js";const P=/\[\[\s*param\.([A-Za-z0-9_.-]+)\s*\]\]/g,B=/\bparam\s*\(\s*(['"])([^'"]+)\1/g;function re(e){const n=[];let t=0;for(;t<e.length;){const r=e.indexOf("{{",t),o=e.indexOf("{%",t);let a=-1,i="";if(r===-1?(a=o,i="%}"):o===-1||r<o?(a=r,i="}}"):(a=o,i="%}"),a===-1)break;const c=e.indexOf(i,a+2);if(c===-1){t=a+2;continue;}n.push(e.slice(a+2,c)),t=c+2;}return n;}function A(e){var r,o;if(!e)return[];const n=/* @__PURE__ */new Set();let t;for(P.lastIndex=0;(t=P.exec(e))!==null;){const a=(r=t[1])==null?void 0:r.trim();a&&n.add(a);}for(const a of re(e))for(B.lastIndex=0;(t=B.exec(a))!==null;){const i=(o=t[2])==null?void 0:o.trim();i&&n.add(i);}return Array.from(n);}function O(e){const n=/* @__PURE__ */new Set(),t=/* @__PURE__ */new Map();for(const r of e.controlBindings||[])n.add(r.controlId),r.target==="sql_param"&&t.set(r.paramId,r.controlId);for(const r of A(e.sql))n.add(t.get(r)??r);return Array.from(n);}function Ie(e){const n=/* @__PURE__ */new Map(),t=/* @__PURE__ */new Map();for(const r of e.controlBindings||[])r.target==="sql_param"&&t.set(r.paramId,r.controlId);for(const r of A(e.sql))n.set(r,{paramId:r,controlId:t.get(r)??r});return Array.from(n.values());}function C(e){return(e==null?void 0:e.type)==="number"||(e==null?void 0:e.type)==="currency";}function te(e){return(e==null?void 0:e.type)==="number";}function oe(e){var t;if(!te(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 ie(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?Q(n.numberFormat,{preserveOmittedProperties:!0}):{type:"number"}:void 0,o=b(e.format,{preserveOmittedProperties:!0}),a=v(e.dataType)==="number"?{type:"number"}:void 0,c=(n==null?void 0:n.inheritMetricFormat)===!1||!!(n!=null&&n.numberFormat)&&(n==null?void 0:n.inheritMetricFormat)!==!0?r:o||a||r;return{authoredFormat:c,currencyBindable:C(c)};}function ae(e,n){const t=b(n.format,{preserveOmittedProperties:!0}),r=v(n.dataType)==="number"?{type:"number"}:void 0,o=t||r;return{authoredFormat:o,source:t?"semantic":r?"inferred":void 0,currencyBindable:C(o)};}function k(e,n={}){var u,d,l;const t=n.column??((u=G(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=b(U({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?(l=(d=e.config)==null?void 0:d.metricColumns)==null?void 0:l.find(m=>m.id===t.fieldId):void 0,o=r!=null&&r.id?{kind:"metric",metricId:r.id}:void 0,a=b(r==null?void 0:r.format,{preserveOmittedProperties:!0}),i=v(r==null?void 0:r.dataType)==="number"?{type:"number"}:void 0,c=a||i;return{target:o,authoredFormat:c,...(a?{source:"stored"}:i?{source:"inferred"}:{}),currencyBindable:S(e.type)&&!!o&&C(c)};}function q(e,n,t){var o;const r=t(e,n);return((o=e.derivedField)==null?void 0:o.format)??(r==null?void 0:r.format)??(r==null?void 0:r.resolvedField.format);}function N(e,n,t){return e.kind==="calculated"?e.definition.format:q(e.field,n,t);}function Fe(e,n){const t=_(n),r=(o,a)=>Object.fromEntries(o.flatMap(i=>{const c=a(i);return c?[[i.id,c]]:[];}));return{measureFormats:r(e.measures,o=>N(o,e.source,t)),levelFormats:r([...e.rows,...e.columns],o=>q(o.field,e.source,t))};}function R(e,n=[]){const t=X(e);if(t.status!=="ready")return[];const{spec:r,presentation:o}=t.config,a=_(n);return r.measures.map(i=>{var y;const c=i.kind==="aggregate"?a(i.field,r.source):void 0,u=W(o.measureFormats[i.id],N(i,r.source,a)),d=i.kind==="calculated"?i.definition.dataType:["MIN","MAX"].includes(i.aggregate)?((y=i.field.derivedField)==null?void 0:y.dataType)??(c==null?void 0:c.resolvedField.dataType)??i.field.dataType:"number",l=v(d)==="number",m=i.kind==="calculated"||!!(c||i.field.derivedField||i.field.name==="*"),f=u&&ee(u)?u:!u&&l&&m?{type:"number"}:void 0;return{measureId:i.id,label:ne(i,o),canonical:f};});}function ce(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 se(e){return new Set(Z(e).flatMap(n=>(n.controlBindings||[]).filter($).map(t=>t.controlId)));}function ue(e,n){const t=[n.id,n.alias,n.label,n.name,n.qualifiedFieldName].filter(a=>!!a);for(const a of t)if(e[a])return e[a];const r=new Set(t.map(a=>a.trim().toLowerCase())),o=Object.entries(e).find(([a])=>r.has(a.trim().toLowerCase()));return o==null?void 0:o[1];}function h(e){return[...new Map(e.map(n=>[p(n),n])).values()];}function de(e,n=[],t){var x;const r=!!((x=e.sql)!=null&&x.trim()),o=S(e.type),a=r&&o&&e.type!=="kpi"&&e.type!=="matrixTable",i=ce(e),c=H(e),u=!r&&e.type==="kpi"?i.map(s=>k(e,{column:{kind:"field",fieldId:s.id}})):[],d=!r&&e.type==="matrixTable"?R(e,t):[],l=(r?[]:i).map(s=>({kind:"metric",metricId:s.id})),m=d.map(s=>({kind:"matrix_measure",measureId:s.measureId})),f=d.filter(s=>{var F,M;return((F=s.canonical)==null?void 0:F.type)==="number"||((M=s.canonical)==null?void 0:M.type)==="currency";}).map(s=>({kind:"matrix_measure",measureId:s.measureId})),y=e.type==="matrixTable"?[]:e.type==="kpi"?u.filter(s=>s.currencyBindable).flatMap(s=>s.target?[s.target]:[]):(r||!o?[]:i).filter(s=>(Y(e.type)?ie(s,ue(c,s)):ae(e,s)).currencyBindable).map(s=>({kind:"metric",metricId:s.id})),g=[...new Set(n)],L=(a?g:[]).map(s=>({kind:"column",columnKey:s})),z=(a?g:[]).filter(s=>oe(c[s])).map(s=>({kind:"column",columnKey:s})),T=(r&&e.type==="kpi"?g.slice(0,1):[]).map(s=>({kind:"column",columnKey:s})),I=r&&e.type==="kpi"?k(e,{resultColumnKey:g[0]}):void 0,J=o&&I!=null&&I.currencyBindable?T:[];return{knownTargets:h([...(e.type==="matrixTable"?m:l),...L,...T]),eligibleTargets:h([...y,...f,...z,...J])};}function ke(e,n){const t=k(e,{resultColumnKey:n});return t.currencyBindable?t.target:void 0;}function Te(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 le(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 w(e){const n=K(e);return typeof e=="string"&&e===n?n:void 0;}function E(e){if(e.type!=="enum"||e.source.kind!=="manual")return{diagnostic:"invalid_control_type"};const n=e.source.options.map(t=>w(t.value));if(n.length===0||n.some(t=>!t))return{diagnostic:"invalid_currency_option"};if(e.requiredAtExecution){const t=e.initialValueStrategy==="saved_default"?w(e.defaultValue):void 0;if(!t||!n.includes(t))return{diagnostic:"invalid_control_default"};}return{control:e,currencies:n};}function xe(e){return"control"in E(e);}function j(e){const n=se(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 Me(e){return j({...e,referencedControlIds:new Set(O({sql:e.filterSql,controlBindings:[]}))});}function Pe(e){var n;return j({...e,referencedControlIds:new Set(O({sql:(n=e.source)==null?void 0:n.sql,controlBindings:[]}))});}function V(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 D(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 o=le(t.presentationTarget);if(!o)return{diagnostic:{code:"missing_target",controlId:r}};const a=p(o);if(!n.knownKeys.has(a))return{diagnostic:{code:"stale_target",controlId:r}};if(!n.eligibleKeys.has(a))return{diagnostic:{code:"inapplicable_target",controlId:r}};const i=n.controlsById.get(r);if(!i)return{diagnostic:{code:"missing_control",controlId:r}};const c=E(i);return"diagnostic"in c?{diagnostic:{code:c.diagnostic,controlId:r}}:{binding:{controlId:r,presentationTarget:o,control:c.control,currencies:c.currencies}};}function Be(e){const n=V(e);return(e.bindings||[]).flatMap(t=>{const r=D(t,n);return"diagnostic"in r?[r.diagnostic]:[];});}function me(e){var o;const n=[],t=p(e.target),r=V(e);for(const a of e.bindings||[]){const i=D(a,r);if("diagnostic"in i){n.push(i.diagnostic);continue;}const c=i.binding;if(!c||p(c.presentationTarget)!==t)continue;const d=K((o=e.values)==null?void 0:o[c.control.id]);if(!(!d||!c.currencies.includes(d)))return{currency:d,diagnostics:n};}return{diagnostics:n};}function he(e,n,t,r){const o={...e,config:{...e.config,matrix:n}},a=de(o,[],r),i=R(o,r),c={...n.presentation.measureFormats};for(const u of i){const d={kind:"matrix_measure",measureId:u.measureId},{currency:l}=me({...t,...a,bindings:e.controlBindings,target:d});if(!l||!u.canonical)continue;const{locale:m,...f}=u.canonical;c[u.measureId]={...f,type:"currency",currency:l};}return{...n.presentation,measureFormats:c};}export{ie as a,R as b,k as c,de as d,Ie as e,p as f,Te as g,te as h,me as i,O as j,se as k,he as l,xe as m,Be as n,ce as o,A as p,Me as q,ae as r,ke as s,Pe as t,Fe as u};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import{jsx as t,jsxs as n,Fragment as R}from"react/jsx-runtime";import aa,{useState as F,useEffect as Ye,useMemo as K,useCallback as oe,useLayoutEffect as Mt,useRef as Ze,useContext as Ea}from"react";import{c as Ce,a0 as rt,aZ as Te,a_ as Le,b0 as Ve,B as I,X as Ue,av as Re,a2 as be,ag as se,ak as vt,bw as na,aa as xe,af as Je,g as yt,au as Nt,aY as U,aj as Ia,bC as $e,bD as je,bW as ra,bE as qe,bz as ee,bL as Ta,bH as et,bx as La,u as C,F as le,G as sa,b9 as Ct,A as Ae,a$ as wt,b1 as st,aX as Va,d as kt,at as Ba,b_ as _a,aM as Oa,aK as it,b$ as ia,c0 as Pa,c1 as za,c2 as Ne,c3 as Ra,R as oa,c4 as Ma,c5 as Ua,T as $a,c6 as ja,c7 as ge,c8 as qa,p as St,P as Ee,c9 as la,e as Ie,b as tt,ca as Wa,cb as ct,cc as Ut,cd as da,al as ca,ce as Ka,am as xt,cf as ua,cg as Qa,a4 as we,a5 as ke,a6 as Se,a7 as De,a8 as fe,ch as Ga,ci as Ha,bc as Ya,ax as Xa,bB as ha,cj as Za,ck as Ja,cl as en,cm as tn,cn as an,co as nn}from"./appearance-provider-BW022_Qu.js";import{b$ as ma,c0 as Be,br as rn,c1 as sn,c2 as on,bD as pa,m as ln,R as dn,c3 as cn,bF as Dt,bG as At,bH as Ft,bI as Et,bJ as It,bK as Tt,bL as Lt,bM as fa,c4 as un,bO as hn,bA as ut,c5 as mn,c6 as Vt,c7 as ga,aY as ot,c8 as ba,c9 as pn,aZ as fn,u as gn,E as bn,y as xa,G as xn,p as vn,ca as yn,cb as Nn,cc as Cn,cd as wn,ce as kn,cf as Sn,cg as Dn,ch as An,ci as Fn,bS as Bt,cj as $t,ck as En,cl as In,cm as Tn,cn as Ln,co as Vn,cp as Ge,cq as Bn,cr as _n,cs as On,A as Pn,aq as zn,ar as Rn,a6 as Mn,a5 as Un,a4 as $n,a3 as jn,a0 as qn,_ as Wn,ao as Kn}from"./semaphor-ready-indicator-BViyPq5k.js";import{L as Me}from"./layout-grid-Cs350bW-.js";import{n as G,kq as at,v as ht,kr as Qn,ak as va,ks as Gn,a6 as Hn,k1 as Yn,kt as Xn,ku as Zn,f5 as Jn,kv as er,a5 as _t,a2 as tr,kw as ar,kx as nr,ky as rr,kz as sr,e as Ot,cY as ir,bV as or,eL as lr,kA as dr,kB as cr,eW as ur,kC as hr,kD as jt,kE as mr}from"./resolve-dashboard-input-context-Dm4PD8Gx.js";import{U as pr}from"./validators-U8IL8djK.js";import"./matrix-operation-contract-DceN49RX.js";import"./analytics-base-schemas-DMFrDqn_.js";import"../value-format-preferences/index.js";import{s as He}from"./normalize-dashboard-for-dirty-check-ILKfqgL3.js";import{V as fr,L as gr,u as ya,C as Na,F as br,a as xr}from"./card-filter-builder-BGIVEHmJ.js";import{createPortal as vr}from"react-dom";import{bb as qt,aD as yr}from"./pivot-result-contract-expectations-D_ane7I2.js";import{F as Nr,av as Cr,L as wr,ag as nt,_ as kr}from"./bookmark-state-DnkzIsyw.js";import{p as Sr}from"./dashboard-temporal-snapshot-BSTfqT29.js";import{A as Dr,j as Ar}from"./set-q-2M4nis.js";import"zod";import"./schema-O1Y3WTGF.js";import"./index-DViPGDFj.js";import"./context-Cwj8Axgd.js";import{v as Fr}from"./filter-reach-preview-CfbwaLf4.js";import{a as Wt,d as Kt,c as Er,i as Ir,b as Tr,e as Lr,v as Qt,f as Gt,g as Vr}from"./variable-draft-DAVLIY3l.js";import{getBriefingPresentation as pe,describeBriefingSchedule as Br,getBriefingCreationIntents as _r}from"../briefings/index.js";/**
|
|
2
|
-
* @license lucide-react v0.453.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const Or=Ce("ArrowUpRight",[["path",{d:"M7 7h10v10",key:"1tivn9"}],["path",{d:"M7 17 17 7",key:"1vkiza"}]]);/**
|
|
7
|
-
* @license lucide-react v0.453.0 - ISC
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the ISC license.
|
|
10
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const Ht=Ce("Bell",[["path",{d:"M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9",key:"1qo2s2"}],["path",{d:"M10.3 21a1.94 1.94 0 0 0 3.4 0",key:"qgo35s"}]]);/**
|
|
12
|
-
* @license lucide-react v0.453.0 - ISC
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the ISC license.
|
|
15
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const Pr=Ce("CodeXml",[["path",{d:"m18 16 4-4-4-4",key:"1inbqp"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}],["path",{d:"m14.5 4-5 16",key:"e7oirm"}]]);/**
|
|
17
|
-
* @license lucide-react v0.453.0 - ISC
|
|
18
|
-
*
|
|
19
|
-
* This source code is licensed under the ISC license.
|
|
20
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const Yt=Ce("MonitorSmartphone",[["path",{d:"M18 8V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h8",key:"10dyio"}],["path",{d:"M10 19v-3.96 3.15",key:"1irgej"}],["path",{d:"M7 19h5",key:"qswx4l"}],["rect",{width:"6",height:"10",x:"16",y:"12",rx:"2",key:"1egngj"}]]);/**
|
|
22
|
-
* @license lucide-react v0.453.0 - ISC
|
|
23
|
-
*
|
|
24
|
-
* This source code is licensed under the ISC license.
|
|
25
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
-
*/const zr=Ce("MousePointer2",[["path",{d:"M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z",key:"edeuup"}]]);/**
|
|
27
|
-
* @license lucide-react v0.453.0 - ISC
|
|
28
|
-
*
|
|
29
|
-
* This source code is licensed under the ISC license.
|
|
30
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
-
*/const Rr=Ce("Newspaper",[["path",{d:"M4 22h16a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H8a2 2 0 0 0-2 2v16a2 2 0 0 1-2 2Zm0 0a2 2 0 0 1-2-2v-9c0-1.1.9-2 2-2h2",key:"7pis2x"}],["path",{d:"M18 14h-8",key:"sponae"}],["path",{d:"M15 18h-5",key:"95g1m2"}],["path",{d:"M10 6h8v4h-8V6Z",key:"smlsk5"}]]);/**
|
|
32
|
-
* @license lucide-react v0.453.0 - ISC
|
|
33
|
-
*
|
|
34
|
-
* This source code is licensed under the ISC license.
|
|
35
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
-
*/const Ca=Ce("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);/**
|
|
37
|
-
* @license lucide-react v0.453.0 - ISC
|
|
38
|
-
*
|
|
39
|
-
* This source code is licensed under the ISC license.
|
|
40
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
41
|
-
*/const Mr=Ce("Terminal",[["polyline",{points:"4 17 10 11 4 5",key:"akl6gq"}],["line",{x1:"12",x2:"20",y1:"19",y2:"19",key:"q2wloq"}]]);function Ur(){return/* @__PURE__ */t("div",{className:"space-y-1.5 py-1",children:[...Array(5)].map((e,a)=>/* @__PURE__ */n("div",{className:"flex animate-pulse items-start gap-3 rounded-xl border border-transparent px-2.5 py-2.5",children:[/* @__PURE__ */t("div",{className:"mt-0.5 h-4 w-4 flex-shrink-0 rounded bg-muted/60"}),/* @__PURE__ */n("div",{className:"flex-1 space-y-1.5",children:[/* @__PURE__ */t("div",{className:"h-4 w-3/5 rounded bg-muted/60"}),/* @__PURE__ */t("div",{className:"h-3 w-4/5 rounded bg-muted/40"})]})]},a))});}function $r({open:e,onOpenChange:a,onSubmit:s,isCreating:r}){const d=rt("interactive"),[o,i]=F(""),[h,u]=F("");Ye(()=>{e||(i(""),u(""));},[e]);const l=()=>{o.trim()&&s({title:o,description:h});},c=p=>{a(p);};return/* @__PURE__ */t(Te,{open:e,onOpenChange:c,children:/* @__PURE__ */n(Le,{showCloseButton:!1,className:"flex max-w-lg grid-cols-none flex-col gap-0 overflow-hidden rounded-card border-border/60 p-0 shadow-lg sm:rounded-card",style:d.dialogStyle,children:[/* @__PURE__ */n("div",{className:"flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-2",children:[/* @__PURE__ */t(Me,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */n("div",{className:"flex min-w-0 items-baseline gap-2",children:[/* @__PURE__ */t(Ve,{className:"truncate text-[13px] font-medium leading-none tracking-normal",children:"New library visual"}),/* @__PURE__ */t("span",{className:"shrink-0 text-[10px] font-medium uppercase leading-none tracking-[0.08em] text-muted-foreground",children:"Visual"})]})]}),/* @__PURE__ */t(I,{size:"xs",variant:"ghost",className:"w-7 px-0 text-muted-foreground hover:text-foreground",onClick:()=>c(!1),"aria-label":"Close",disabled:r,children:/* @__PURE__ */t(Ue,{className:"h-3.5 w-3.5"})})]}),/* @__PURE__ */n("div",{className:"space-y-3 px-4 py-3",children:[/* @__PURE__ */t("p",{className:"text-[12px] text-muted-foreground",children:"Create a saved visual that can be reused across dashboards."}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */t(Re,{htmlFor:"visual-title",className:"text-[12px]",children:"Name"}),/* @__PURE__ */t(be,{id:"visual-title",size:"sm",placeholder:"Untitled visual",value:o,onChange:p=>i(p.target.value),disabled:r,onKeyDown:p=>{p.key==="Enter"&&!p.shiftKey&&(p.preventDefault(),l());}})]}),/* @__PURE__ */n("div",{className:"space-y-1.5",children:[/* @__PURE__ */t(Re,{htmlFor:"visual-description",className:"text-[12px]",children:"Description"}),/* @__PURE__ */t(be,{id:"visual-description",size:"sm",placeholder:"Optional",value:h,onChange:p=>u(p.target.value),disabled:r})]})]}),/* @__PURE__ */n("div",{className:"flex shrink-0 justify-end gap-2 border-t border-border/60 px-4 py-2.5",children:[/* @__PURE__ */t(I,{size:"xs",variant:"outline",onClick:()=>c(!1),disabled:r,children:"Cancel"}),/* @__PURE__ */t(I,{size:"xs",onClick:l,disabled:!o.trim()||r,children:r?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin"}),"Creating..."]}):"Create library visual"})]})]})});}function wa(e){return e?new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Unknown";}function ka(e,a){var r;const s=(r=e.ownership.createdBy)==null?void 0:r.type;return s==="tenant"||s==="organization"&&a;}function Pt(e,a){var s,r;return ka(e,a)?((s=e.ownership.createdBy)==null?void 0:s.name)||((r=e.createdByTenantUserRel)==null?void 0:r.name)||e.lastModifiedBy||"Unknown":"Organization";}function jr(e,a){return Pt(e,a).split(/\s+/).filter(Boolean).slice(0,2).map(r=>r.charAt(0).toUpperCase()).join("")||"?";}function qr(e){const a=(e||"").toLowerCase();return a.includes("table")?vt:a.includes("pie")||a.includes("donut")?un:a.includes("line")?hn:a.includes("bar")?Ia:Me;}function Wr({visual:e}){const a=e.ownership.status==="public"?"Public":e.ownership.status==="shared"||e.ownership.sharedCount>0?"Shared":"Private";return/* @__PURE__ */t("span",{className:"inline-flex items-center rounded-[4px] border border-border/60 px-1.5 py-px text-[11px] text-muted-foreground",children:a});}function Fi({open:e,onOpenChange:a}){const s=rt("interactive"),[r,d]=F(""),[o,i]=F(/* @__PURE__ */new Set()),[h,u]=F(!1),[l,c]=F(null),[p,m]=F(null),[g,f]=F(!1),[N,w]=F(null),[T,L]=F(null),B=()=>{i(/* @__PURE__ */new Set()),c(null),m(null),f(!1),w(null);},D=()=>{a(!1),B();},{selectVisual:P}=ma(),{handleAddLibraryVisual:k,handleEditLibraryVisual:v}=Be(),{isConsoleMode:b}=rn(),{resources:_,isLoading:A,isError:H,createResource:V,updateResource:M,deleteResourceAsync:X,duplicateResource:Y,isCreating:he,isDeleting:te}=sn(void 0,y=>{u(!1),y&&(P(y),v(y),D());}),{startUpdating:me,stopUpdating:E,isUpdating:ne}=on(),Q=_,z=K(()=>{const y=r.trim().toLowerCase();return y?Q.filter(j=>{var Z,ue,ye;return((Z=j.title)==null?void 0:Z.toLowerCase().includes(y))||((ue=j.description)==null?void 0:ue.toLowerCase().includes(y))||((ye=j.kind)==null?void 0:ye.toLowerCase().includes(y));}):Q;},[r,Q]),J=K(()=>Q.filter(y=>o.has(y.id)),[o,Q]),de=J.filter(y=>y.permissions.canDelete),ce=J.filter(y=>y.permissions.canShare),ve=z.length>0&&z.every(y=>o.has(y.id)),x=z.some(y=>o.has(y.id)),O=y=>{const j=new Set(o);y(j),i(j);},$=y=>{O(j=>{j.has(y)?j.delete(y):j.add(y);});},W=()=>{i(y=>{const j=new Set(y);return ve?z.forEach(Z=>j.delete(Z.id)):z.forEach(Z=>j.add(Z.id)),j;});},re=async y=>{(await k(y)).success&&D();},_e=async()=>{const y=J;if(y.length===0)return;let j=!1;for(const Z of y)if(!(await k(Z)).success){j=!0;break;}j||D();},lt=y=>{v(y),D();},Fe=y=>{L(y),Y(y,{onSettled:()=>L(null)});},We=()=>{if(de.length===0){U.error("Select a visual you can delete");return;}w(null),f(!0);},dt=async()=>{const y=N?[N]:de;try{for(const j of y)await X(j.id);i(j=>{const Z=new Set(j);return y.forEach(ue=>Z.delete(ue.id)),Z;}),f(!1),w(null);}catch{}},Oe=()=>{if(J.length!==1){U.error("Select one visual to share");return;}const[y]=J;if(!y.permissions.canShare){U.error("You do not have permission to share this visual");return;}c(y);},Pe=({title:y,description:j})=>{if(!p)return;const Z={};if(y!==p.title&&(Z.title=y),(p.description||"")!==j&&(Z.description=j),Object.keys(Z).length===0){m(null);return;}const ue=Object.keys(Z),ye=ue.length===1?ue[0]:void 0;me(p.id,ye),M({resourceId:p.id,data:Z},{onSuccess:()=>{E(p.id,ye),m(null);},onError:()=>{E(p.id,ye);}});},ie=y=>{a(y),y||B();},ze=N?1:de.length;return/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(Te,{open:e,onOpenChange:ie,children:/* @__PURE__ */n(Le,{showCloseButton:!1,className:"flex max-h-[80vh] w-[min(72rem,calc(100vw-2rem))] max-w-none grid-cols-none flex-col gap-0 overflow-hidden rounded-card border-border/60 p-0 shadow-lg sm:rounded-card",style:s.dialogStyle,children:[/* @__PURE__ */n("div",{className:"flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-2",children:[/* @__PURE__ */t(vt,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */n("div",{className:"flex min-w-0 items-baseline gap-2",children:[/* @__PURE__ */t(Ve,{className:"truncate text-[13px] font-medium leading-none tracking-normal",children:"Visuals library"}),/* @__PURE__ */t("span",{className:"shrink-0 text-[10px] font-medium uppercase leading-none tracking-[0.08em] text-muted-foreground",children:"Add to dashboard"})]})]}),/* @__PURE__ */t(I,{size:"xs",variant:"ghost",className:"w-7 px-0 text-muted-foreground hover:text-foreground",onClick:()=>ie(!1),"aria-label":"Close visuals library",children:"×"})]}),/* @__PURE__ */n("div",{className:"flex shrink-0 items-center gap-2 border-b border-border/60 px-3 py-2",children:[/* @__PURE__ */n("div",{className:"relative min-w-[12rem] flex-1 md:max-w-md",children:[/* @__PURE__ */t(na,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),/* @__PURE__ */t("input",{autoFocus:!0,value:r,onChange:y=>d(y.target.value),placeholder:"Search visuals...",className:"h-7 w-full rounded-control border border-input bg-background pl-7 pr-2 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-ring focus:outline-none","aria-label":"Search visuals"})]}),/* @__PURE__ */n(I,{size:"xs",variant:"outline",className:"ml-auto",onClick:()=>u(!0),children:[/* @__PURE__ */t(xe,{className:"h-3.5 w-3.5"}),"New library visual"]})]}),/* @__PURE__ */t("div",{className:"min-h-0 flex-1 overflow-auto",children:A?/* @__PURE__ */t("div",{className:"p-3",children:/* @__PURE__ */t(Ur,{})}):H?/* @__PURE__ */t("div",{className:"flex flex-col items-center gap-2 px-4 py-12 text-center",children:/* @__PURE__ */t("p",{className:"text-[13px] text-destructive",children:"Failed to load visuals"})}):z.length===0?/* @__PURE__ */n("div",{className:"flex flex-col items-center gap-2 px-4 py-12 text-center",children:[/* @__PURE__ */t(Me,{className:"h-5 w-5 text-muted-foreground/60"}),/* @__PURE__ */t("p",{className:"text-[13px] font-medium",children:r?"No visuals found":"No visuals yet"}),/* @__PURE__ */t("p",{className:"text-[12px] text-muted-foreground",children:r?"Try a different search.":"Create a saved visual to add it here."})]}):/* @__PURE__ */t(Kr,{visuals:z,selectedIds:o,allFilteredSelected:ve,someFilteredSelected:x,onSelectAll:W,onToggleSelection:$,onAddVisual:re,onOpenVisual:lt,onEditDetails:m,onShareVisual:c,onDeleteVisual:y=>{w(y),f(!0);},onDuplicateVisual:Fe,duplicatingId:T,isDeleting:te,isConsoleMode:b})}),/* @__PURE__ */n("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border/60 px-3 py-2",children:[/* @__PURE__ */t("div",{className:"flex min-w-0 items-center gap-1.5",children:o.size>0&&/* @__PURE__ */n(R,{children:[/* @__PURE__ */n("span",{className:"text-[12px] text-muted-foreground",children:[/* @__PURE__ */t("span",{className:"font-medium tabular-nums text-foreground",children:o.size})," ","selected"]}),/* @__PURE__ */t(I,{size:"xs",variant:"ghost",onClick:()=>i(/* @__PURE__ */new Set()),children:"Clear"}),/* @__PURE__ */n(I,{size:"xs",variant:"outline",onClick:Oe,disabled:J.length!==1||ce.length!==1,children:[/* @__PURE__ */t(pa,{className:"h-3.5 w-3.5"}),"Share"]}),/* @__PURE__ */n(I,{size:"xs",variant:"outline",className:"text-destructive hover:text-destructive",onClick:We,disabled:de.length===0,children:[/* @__PURE__ */t(Je,{className:"h-3.5 w-3.5"}),"Delete ",de.length||o.size]})]})}),/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */t(I,{size:"xs",variant:"outline",onClick:()=>ie(!1),children:"Close"}),/* @__PURE__ */n(I,{size:"xs",onClick:_e,disabled:o.size===0,children:[/* @__PURE__ */t(yt,{className:"h-3.5 w-3.5"}),o.size===0?"Add to dashboard":`Add ${o.size} visual${o.size===1?"":"s"}`]})]})]})]})}),/* @__PURE__ */t($r,{open:h,onOpenChange:u,onSubmit:V,isCreating:he}),l&&/* @__PURE__ */t(ln,{resource:l,resourceType:dn.VISUAL,onClose:()=>c(null)}),p&&/* @__PURE__ */t(cn,{open:!!p,resourceLabel:"Visual",initialTitle:p.title||"",initialDescription:p.description||"",onClose:()=>m(null),onSave:Pe,isSaving:ne(p.id)}),/* @__PURE__ */t(Dt,{open:g,onOpenChange:y=>{!y&&te||(f(y),y||w(null));},children:/* @__PURE__ */n(At,{children:[/* @__PURE__ */n(Ft,{children:[/* @__PURE__ */n(Et,{children:["Delete ",ze," visual",ze===1?"":"s","?"]}),/* @__PURE__ */t(It,{children:"This cannot be undone. Visuals already added to dashboards may need to be removed from those dashboards separately."})]}),/* @__PURE__ */n(Tt,{children:[/* @__PURE__ */t(Lt,{disabled:te,children:"Cancel"}),/* @__PURE__ */n(fa,{onClick:y=>{y.preventDefault(),dt();},disabled:te||ze===0,children:[te?/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin"}):/* @__PURE__ */t(Je,{className:"h-3.5 w-3.5"}),te?"Deleting...":"Delete"]})]})]})})]});}function Kr({visuals:e,selectedIds:a,allFilteredSelected:s,someFilteredSelected:r,onSelectAll:d,onToggleSelection:o,onAddVisual:i,onOpenVisual:h,onEditDetails:u,onShareVisual:l,onDeleteVisual:c,onDuplicateVisual:p,duplicatingId:m,isDeleting:g,isConsoleMode:f}){return/* @__PURE__ */n("div",{className:"min-w-[48rem]",children:[/* @__PURE__ */n("div",{className:"grid h-9 grid-cols-[2.5rem_minmax(14rem,1.8fr)_minmax(10rem,1fr)_8rem_7rem_5rem_5.5rem] items-center border-b border-border/60 px-3 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:[/* @__PURE__ */t(Nt,{checked:s?!0:r?"indeterminate":!1,onCheckedChange:d,"aria-label":"Select all visuals"}),/* @__PURE__ */t("span",{children:"Name"}),/* @__PURE__ */t("span",{children:"Created by"}),/* @__PURE__ */t("span",{children:"Updated"}),/* @__PURE__ */t("span",{children:"Visibility"}),/* @__PURE__ */t("span",{className:"text-right",children:"Shared"}),/* @__PURE__ */t("span",{className:"text-right",children:"Actions"})]}),e.map(N=>/* @__PURE__ */t(Qr,{visual:N,selected:a.has(N.id),onToggleSelection:o,onAddVisual:i,onOpenVisual:h,onEditDetails:u,onShareVisual:l,onDeleteVisual:c,onDuplicateVisual:p,duplicatingId:m,isDeleting:g,isConsoleMode:f},N.id))]});}function Qr({visual:e,selected:a,onToggleSelection:s,onAddVisual:r,onOpenVisual:d,onEditDetails:o,onShareVisual:i,onDeleteVisual:h,onDuplicateVisual:u,duplicatingId:l,isDeleting:c,isConsoleMode:p}){var f;const m=qr(e.kind),g=()=>{r(e);};return/* @__PURE__ */n("div",{className:G("group grid min-h-12 grid-cols-[2.5rem_minmax(14rem,1.8fr)_minmax(10rem,1fr)_8rem_7rem_5rem_5.5rem] items-center border-b border-border/50 px-3 text-[13px] hover:bg-muted/50",a&&"bg-muted/70"),children:[/* @__PURE__ */t("div",{children:/* @__PURE__ */t(Nt,{checked:a,onCheckedChange:()=>s(e.id),"aria-label":`Select ${e.title||"visual"}`})}),/* @__PURE__ */n("button",{type:"button",className:"flex min-w-0 items-center gap-2 rounded-[4px] text-left outline-none focus-visible:ring-1 focus-visible:ring-ring",onClick:g,"aria-label":`Add ${e.title||"visual"} to dashboard`,children:[/* @__PURE__ */t(m,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */t("div",{className:"truncate font-medium text-foreground",title:e.title||"Untitled Visual",children:e.title||"Untitled Visual"}),((f=e.description)==null?void 0:f.trim())&&/* @__PURE__ */t("div",{className:"truncate text-[11px] text-muted-foreground",title:e.description,children:e.description})]})]}),/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-2",children:[/* @__PURE__ */t("div",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-muted text-[9px] font-medium text-muted-foreground",children:jr(e,p)}),/* @__PURE__ */t("span",{className:"truncate text-muted-foreground",children:Pt(e,p)})]}),/* @__PURE__ */t("span",{className:"text-muted-foreground",children:wa(e.updatedAt)}),/* @__PURE__ */t(Wr,{visual:e}),/* @__PURE__ */t("span",{className:"text-right tabular-nums text-muted-foreground",children:e.ownership.sharedCount>0?e.ownership.sharedCount:"—"}),/* @__PURE__ */t(Gr,{visual:e,onOpenVisual:d,onEditDetails:o,onShareVisual:i,onDeleteVisual:h,onDuplicateVisual:u,duplicatingId:l,isDeleting:c,isConsoleMode:p})]});}function Gr({visual:e,onOpenVisual:a,onEditDetails:s,onShareVisual:r,onDeleteVisual:d,onDuplicateVisual:o,duplicatingId:i,isDeleting:h,isConsoleMode:u}){return/* @__PURE__ */n("div",{className:"flex items-center justify-end gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",onClick:l=>l.stopPropagation(),children:[/* @__PURE__ */t(I,{size:"xs",variant:"ghost",className:"w-7 px-0",onClick:()=>a(e),"aria-label":"Edit visual",children:/* @__PURE__ */t(ut,{className:"h-3.5 w-3.5"})}),/* @__PURE__ */n($e,{modal:!1,children:[/* @__PURE__ */t(je,{asChild:!0,children:/* @__PURE__ */t(I,{size:"xs",variant:"ghost",className:"w-7 px-0","aria-label":"More actions",children:/* @__PURE__ */t(ra,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(qe,{align:"end",className:"z-[60] w-44 rounded-[6px] border-border/60 p-1 shadow-sm",children:[/* @__PURE__ */n(ee,{onClick:()=>a(e),children:[/* @__PURE__ */t(ut,{className:"h-3.5 w-3.5"}),"Edit visual"]}),/* @__PURE__ */n(ee,{onClick:()=>o(e.id),disabled:i===e.id,children:[i===e.id?/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin"}):/* @__PURE__ */t(Ta,{className:"h-3.5 w-3.5"}),i===e.id?"Duplicating...":"Duplicate"]}),e.permissions.canEdit&&/* @__PURE__ */n(ee,{onClick:()=>s(e),children:[/* @__PURE__ */t(ut,{className:"h-3.5 w-3.5"}),"Edit details"]}),e.permissions.canShare&&/* @__PURE__ */n(ee,{onClick:()=>r(e),children:[/* @__PURE__ */t(pa,{className:"h-3.5 w-3.5"}),"Share"]}),e.permissions.canDelete&&/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(et,{}),/* @__PURE__ */n(ee,{className:"text-destructive focus:bg-destructive/10 focus:text-destructive",onClick:()=>d(e),disabled:h,children:[/* @__PURE__ */t(Je,{className:"h-3.5 w-3.5"}),h?"Deleting...":"Delete"]})]}),/* @__PURE__ */t(et,{}),/* @__PURE__ */n("div",{className:"space-y-1 px-2 py-1.5 text-[11px] text-muted-foreground",children:[ka(e,u)&&/* @__PURE__ */n("div",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */t(mn,{className:"h-3 w-3"}),/* @__PURE__ */t("span",{className:"truncate",children:Pt(e,u)})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */t(La,{className:"h-3 w-3"}),/* @__PURE__ */t("span",{children:wa(e.updatedAt)})]})]})]})]})]});}function Ei(e,a,s=!1){const r=C(c=>c.dashboard),d=C(c=>c.isDashboardEditing),o=C(c=>c.isVisualEditing),i=C(c=>c.onDashboardLifecycleEvent),h=oe(()=>{const{dashboard:c,isVisualEditing:p}=C.getState();return a||!e||!c||c.id!==e.id?!1:p?!0:He(c)!==He(e);},[e,a]);Mt(()=>(C.setState({checkUnsavedDashboardChanges:h}),()=>{C.getState().checkUnsavedDashboardChanges===h&&C.setState({checkUnsavedDashboardChanges:null});}),[h]);const u=K(()=>!s||a||!r||d&&(!e||r.id!==e.id)?null:{dashboardId:r.id,dirty:d&&e?o||He(r)!==He(e):!1},[d,o,a,s,e,r]),l=Ze(null);return Mt(()=>{if(!i||!u){l.current=null;return;}const c=l.current;(c==null?void 0:c.callback)===i&&c.dashboardId===u.dashboardId&&c.dirty===u.dirty||(l.current={callback:i,dashboardId:u.dashboardId,dirty:u.dirty},i({type:"dashboard:dirty-state",dashboardId:u.dashboardId,payload:{dirty:u.dirty}}));},[u,i]),h;}function zt(e){var a;for(const s of e.cards)if(s.type==="matrixTable"&&!pr.safeParse((a=s.config)==null?void 0:a.matrix).success)return U.error("Matrix requires at least one row field, one metric, and valid settings."),!1;return!0;}function mt({className:e,variant:a="outline"}){const s=le(o=>o.onSave),{getUpdatedFrame:r}=Be();function d(){const o=r();zt(o)&&(s==null||s(o));}return/* @__PURE__ */n(I,{onClick:d,className:e,size:"xs",variant:a,children:[/* @__PURE__ */t(yt,{className:"h-3.5 w-3.5"}),"Done"]});}function Hr({className:e,variant:a="default"}){const s=Ct(),[r,d]=F(!1),{setIsVisualEditing:o}=Ae(),{getUpdatedFrame:i}=Be(),h=Vt(),u=le(p=>p.frame),l=ga();return/* @__PURE__ */t(I,{onClick:()=>{const p=i();if(!zt(p))return;const m=(u==null?void 0:u.visualId)||(h==null?void 0:h.id);if(!m){U.error("No visual to save");return;}d(!0),l.mutate({visualId:m,data:{frameObject:p}},{onSuccess:()=>{d(!1),U.success("Visual updated successfully"),s.invalidateQueries({queryKey:["resource-by-id","visual",m],exact:!0});},onError:()=>{d(!1),U.error("Failed to update visual");}});},className:e,size:"xs",variant:a,children:r?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin"}),"Saving"]}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(Ca,{className:"h-3.5 w-3.5"}),"Save to Library"]})});}function Yr({className:e}){const a=Ct(),[s,r]=F(!1),d=Vt(),o=le(f=>f.frame),i=C(f=>f.selectedSheetId),h=C(f=>f.dashboard),{updateFrame:u,setIsVisualEditing:l}=Ae(),{getUpdatedFrame:c}=Be(),p=ga(),m=ot();return/* @__PURE__ */t(I,{onClick:async()=>{if(!i){U.error("No sheet selected");return;}const f=(o==null?void 0:o.visualId)||(d==null?void 0:d.id);if(!f){U.error("No visual to update");return;}r(!0);try{const N=c();if(!zt(N)){r(!1);return;}const w={...N,visualId:f},T=at(h,w.id),L=await m(w,{previousFrame:T});await p.mutateAsync({visualId:f,data:{frameObject:N}}),u(i,w,{semanticExecutionPayload:L,origin:"editor"}),a.invalidateQueries({queryKey:["visuals"]}),a.invalidateQueries({queryKey:["visual",f]}),U.success("Saved to library and applied locally"),setTimeout(()=>{l(!1);},300);}catch(N){console.error("Failed to save and apply:",N),U.error(N instanceof Error?N.message:"Failed to save and apply changes");}finally{r(!1);}},className:e,size:"xs",variant:"default",disabled:s,children:s?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin"}),"Saving..."]}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(Ca,{className:"h-3.5 w-3.5"}),"Save & Apply"]})});}function pt({className:e}){const{setTempQueryData:a,setSqlGen:s}=sa(),r=Ct(),d=le(h=>h.tempQueryData),o=le(h=>h.onClose);function i(){if(d){const{queryKey:h,queryData:u}=d;h&&u&&r.setQueryData(h,u);}s({}),o==null||o();}return/* @__PURE__ */n(I,{onClick:i,className:e,size:"xs",variant:"outline",children:[/* @__PURE__ */t(Ue,{className:"h-3.5 w-3.5"}),"Close"]});}function Xr({open:e,onOpenChange:a,isLibraryVisual:s,currentVisualName:r,isSaving:d=!1,destinationMode:o="both",onConfirm:i}){const[h,u]=F(s&&r?`Copy of ${r}`:r||""),[l,c]=F("");aa.useEffect(()=>{e&&(u(s&&r?`Copy of ${r}`:r||""),c(""));},[e,s,r]);const p=!!h.trim(),m=o==="local"?{saveToLibrary:!1,saveToCurrentDashboard:!0,badgeType:"local",description:"Creates a local copy on the current dashboard.",actionLabel:"Add to Dashboard (Local)"}:o==="library"?{saveToLibrary:!0,saveToCurrentDashboard:!1,badgeType:"library",description:"Creates a reusable visual in Visual Library.",actionLabel:"Save as Library Visual"}:{saveToLibrary:!0,saveToCurrentDashboard:!0,badgeType:"linked",description:"Creates a new library visual and adds a linked copy to this dashboard.",actionLabel:"Save Copy as Linked Visual"},g=()=>{!p||d||i({name:h.trim(),description:l.trim()||void 0,saveToLibrary:m.saveToLibrary,saveToCurrentDashboard:m.saveToCurrentDashboard});};return/* @__PURE__ */t(Te,{open:e,onOpenChange:a,children:/* @__PURE__ */n(Le,{className:"sm:max-w-[500px]",children:[/* @__PURE__ */n(wt,{children:[/* @__PURE__ */n(Ve,{className:"flex items-center gap-2",children:[/* @__PURE__ */t("span",{children:"Save Visual As"}),m.badgeType!=="local"&&/* @__PURE__ */t(fr,{type:m.badgeType,showLabel:!0,className:"px-2 py-0.5"})]}),/* @__PURE__ */t(st,{children:m.description})]}),/* @__PURE__ */n("div",{className:"grid gap-4 py-4",children:[/* @__PURE__ */n("div",{className:"grid gap-2",children:[/* @__PURE__ */t(Re,{htmlFor:"name",children:"Name"}),/* @__PURE__ */t(be,{id:"name",value:h,onChange:f=>u(f.target.value),placeholder:"Enter visual name",disabled:d})]}),/* @__PURE__ */n("div",{className:"grid gap-2",children:[/* @__PURE__ */t(Re,{htmlFor:"description",children:"Description (optional)"}),/* @__PURE__ */t(ba,{id:"description",value:l,onChange:f=>c(f.target.value),placeholder:"Enter visual description",rows:3,disabled:d})]})]}),/* @__PURE__ */n(Va,{children:[/* @__PURE__ */t(I,{variant:"outline",onClick:()=>a(!1),disabled:d,children:"Cancel"}),/* @__PURE__ */n(I,{onClick:g,disabled:!p||d,children:[d&&/* @__PURE__ */t(se,{className:"mr-2 h-4 w-4 animate-spin"}),m.actionLabel]})]})]})});}function Zr(){const[e,a]=F(!1),[s,r]=F(!1),[d,o]=F(null),[i,h]=F(null),u=le(v=>v.frame),l=le(v=>v.card),c=Vt(),p=C(v=>v.selectedSheetId),m=C(v=>v.dashboard),{getUpdatedFrame:g}=Be(),{selectVisual:f}=ma(),{addFrame:N,checkAddFrame:w,setIsVisualEditing:T}=Ae(),L=ot(),B=!!(u!=null&&u.visualId),D=(()=>{var v,b;return((v=u==null?void 0:u.cards)==null?void 0:v.length)===1&&(b=u.cards[0])!=null&&b.title?u.cards[0].title:c!=null&&c.title?c.title:(l==null?void 0:l.title)||"Untitled Visual";})(),P=pn(v=>{v!=null&&v.id&&(f(v),s&&d&&i&&p&&(async()=>{try{const b={...d,id:ht(),visualId:v.id};N(p,b,{semanticExecutionPayload:i,withEditorFieldChanges:!0}),r(!1),o(null),h(null),T(!1);}catch(b){console.error("Failed to promote semantic metadata for saved visual:",b),U.error(b instanceof Error?b.message:"Failed to prepare semantic metadata for the saved visual");}})(),a(!1));});return{saveAsDialogOpen:e,setSaveAsDialogOpen:a,handleSaveAs:async v=>{if(!p){U.error("No sheet selected");return;}const b=g(),A=b.cards.length===1?{...b,cards:b.cards.map(H=>({...H,title:v.name}))}:b;if(v.saveToLibrary){let H=null;if(v.saveToCurrentDashboard)try{H=await L(A,{previousFrame:at(m,A.id)});}catch(M){console.error("Failed to prepare semantic metadata before saving visual:",M),U.error(M instanceof Error?M.message:"Failed to prepare semantic metadata for the saved visual");return;}if(v.saveToCurrentDashboard){const M=w(p,{...A,id:ht()},{withEditorFieldChanges:!0});if(!M.ok){U.error(M.reason);return;}}r(v.saveToCurrentDashboard),o(A),h(H);const V={title:v.name,description:v.description,frameObject:A,isPrivate:!1};P.mutate(V);}else if(v.saveToCurrentDashboard){const H={...A,id:ht(),visualId:void 0};try{const V=await L(A,{previousFrame:at(m,A.id)});N(p,H,{semanticExecutionPayload:V,withEditorFieldChanges:!0}),U.success("Visual saved to dashboard"),a(!1),T(!1);}catch(V){console.error("Failed to save visual to dashboard:",V),U.error(V instanceof Error?V.message:"Failed to prepare semantic metadata for the visual");}}},isLibraryVisual:B,currentVisualName:D,isSaving:P.isPending};}function Ii(e={}){const{isInspectionMode:a}=fn(),s=le(V=>V.frame),r=le(V=>V.editorContext),d=gn(V=>V.selectedVisual),o=C(V=>V.selectedFrameId),i=C(V=>V.selectedSheetId),h=C(V=>V.dashboard),{setIsVisualEditing:u,updateFrame:l}=Ae(),[c,p]=F(!1),[m,g]=F("both"),f=ot(),N=(r==null?void 0:r.type)==="documentSection",w=!!(s!=null&&s.visualId||d!=null&&d.id),T=!!(s!=null&&s.visualId&&o),L=w&&!T,{saveAsDialogOpen:B,setSaveAsDialogOpen:D,handleSaveAs:P,isLibraryVisual:k,currentVisualName:v,isSaving:b}=Zr(),{getUpdatedFrame:_}=Be();if(a)return/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(mt,{className:"rounded-control",variant:"default"}),/* @__PURE__ */t(pt,{})]});if(N)return/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(mt,{className:"rounded-control",variant:"default"}),/* @__PURE__ */t(pt,{})]});const A=async()=>{if(!i){U.error("No sheet selected");return;}if(c)return;p(!0);const M={..._(),visualId:void 0},X=at(h,M.id);try{const Y=await f(M,{previousFrame:X});l(i,M,{semanticExecutionPayload:Y,origin:"editor"});}catch(Y){console.error("Failed to apply local semantic metadata:",Y),p(!1),U.error(Y instanceof Error?Y.message:"Failed to prepare semantic metadata for this visual");return;}setTimeout(()=>{p(!1),U.success("Changes applied. Visual is now local to this dashboard"),u(!1);},300);},H=V=>{g(V),D(!0);};return/* @__PURE__ */n(R,{children:[/* @__PURE__ */n("div",{className:"inline-flex items-center overflow-hidden rounded-control",children:[!w&&/* @__PURE__ */t(mt,{className:"!rounded-none",variant:"default"}),w&&L&&/* @__PURE__ */t(Hr,{className:"!rounded-none",variant:"default"}),w&&T&&/* @__PURE__ */t(Yr,{className:"!rounded-none"}),/* @__PURE__ */n($e,{modal:!1,children:[/* @__PURE__ */t(je,{asChild:!0,children:/* @__PURE__ */t(I,{variant:"default",size:"xs",className:"w-7 !rounded-none border-l border-primary-foreground/20 px-0","aria-label":"Open visual save options",disabled:b||c,children:/* @__PURE__ */t(kt,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(qe,{align:"end",className:"min-w-[220px] rounded-control border border-border/60 p-1 shadow-sm",children:[T&&/* @__PURE__ */n(R,{children:[/* @__PURE__ */n(ee,{onClick:A,disabled:c,children:[/* @__PURE__ */t(yt,{className:"h-3.5 w-3.5"}),c?"Applying...":"Apply Locally"]}),/* @__PURE__ */t(et,{})]}),/* @__PURE__ */n(ee,{onClick:()=>H("local"),disabled:b,children:[/* @__PURE__ */t(xe,{className:"h-3.5 w-3.5"}),"Add to Dashboard (Local)"]}),/* @__PURE__ */n(ee,{onClick:()=>H("library"),disabled:b,children:[/* @__PURE__ */t(gr,{className:"h-3.5 w-3.5"}),"Save as Library Visual"]}),/* @__PURE__ */n(ee,{onClick:()=>H("both"),disabled:b,children:[/* @__PURE__ */t(Ba,{className:"h-3.5 w-3.5"}),"Save Copy as Linked Visual"]})]})]})]}),/* @__PURE__ */t(pt,{}),/* @__PURE__ */t(Xr,{open:B,onOpenChange:V=>{b||D(V);},isLibraryVisual:k,currentVisualName:v,isSaving:b,destinationMode:m,onConfirm:P})]});}function Ti({className:e}){const a=le(c=>c.isDevMode),s=le(c=>c.card.type),r=C(c=>c.isVisualEditing),{setIsDevMode:d}=sa(),{config:o}=Ea(_a).tokenProps,i=(o==null?void 0:o.showAdvancedMode)!==!1;if(!r||!i||!Qn(s))return null;const h=a?zr:Pr,u=a?"Visual editor":"SQL editor",l=a?"Switch to visual editor":"Switch to SQL editor";return/* @__PURE__ */n("button",{type:"button","aria-label":l,title:l,onClick:()=>d(!a),className:G("inline-flex h-7 items-center gap-1.5 rounded-control border border-input bg-background px-2 text-[12px] font-medium text-foreground transition-colors hover:bg-muted/40 focus-visible:border-ring focus-visible:outline-none",e),children:[/* @__PURE__ */t(h,{className:"h-3 w-3 text-muted-foreground"}),u]});}function Li(){const e=bn()==="sm",a=C(u=>u.isDashboardEditing),s=C(u=>u.isVisualEditing),r=C(u=>{var c;const l=((c=u.dashboard)==null?void 0:c.sheets)??[];return l.find(p=>p.id===u.selectedSheetId)??l[0];}),d=C(u=>u.actions.arrangeSheet),o=C(u=>u.actions.undoArrange);if(!a||s||!r||!va(r))return null;const i=!(r.frames??[]).length,h=u=>{const l=d(r.id,{keepOrder:u});if(!l.ok){U.error(l.reason==="not_a_grid"?"This sheet has no grid to arrange.":"The dashboard can't be arranged right now.");return;}U("Arranged",{duration:1e4,description:u?"Sizes and gaps fixed on every screen size, in your order.":"KPIs on top, charts in pairs, tables full width, on every screen size.",action:{label:"Undo",onClick:()=>{const c=o();!c.ok&&c.reason==="changed_since"&&U.info("The dashboard changed after Arrange, so it can't be undone from here.");}}});};return/* @__PURE__ */n("div",{className:"inline-flex h-7 items-stretch overflow-hidden rounded-control border border-input bg-background",children:[/* @__PURE__ */n(I,{variant:"ghost",size:"xs",disabled:i,title:i?"This sheet has no cards to arrange":"Lay out the cards by kind on every screen size",onClick:()=>h(!1),"aria-label":e?"Arrange":void 0,className:`h-full rounded-none border-0 shadow-none hover:bg-accent${e?" w-7 px-0":""}`,children:[/* @__PURE__ */t(Me,{className:"h-3.5 w-3.5"}),!e&&"Arrange"]}),/* @__PURE__ */n($e,{modal:!1,children:[/* @__PURE__ */t(je,{asChild:!0,children:/* @__PURE__ */t(I,{variant:"ghost",size:"xs",disabled:i,className:"h-full w-7 rounded-none border-0 border-l border-border/60 px-0 shadow-none hover:bg-accent","aria-label":"Open arrange options",children:/* @__PURE__ */t(kt,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */t(qe,{align:"end",className:"z-[60] w-48 rounded-[6px] border-border/60 p-1 shadow-sm",children:/* @__PURE__ */n(ee,{onClick:()=>h(!0),children:[/* @__PURE__ */t(Me,{className:"h-3.5 w-3.5"}),"Keep my order"]})})]})]});}function Vi(){const e=C(d=>d.screenSizesOpen),a=C(d=>{var h,u;const o=((h=d.dashboard)==null?void 0:h.sheets)??[],i=o.find(l=>l.id===d.selectedSheetId)??o[0];return!!i&&va(i)&&!!((u=i.frames)!=null&&u.length);}),s=C(d=>d.actions.setScreenSizesOpen),r=xa("screen-sizes","lg",a?{label:"Screen sizes",icon:/* @__PURE__ */t(Yt,{className:"h-3.5 w-3.5","aria-hidden":!0}),checked:e,order:40,onSelect:()=>s(!e)}:void 0);return!a||r.collapsed?null:/* @__PURE__ */t(I,{type:"button",size:"xs",variant:e?"secondary":"ghost","aria-pressed":e,"aria-label":"Screen sizes",title:"Screen sizes",onClick:()=>s(!e),className:"w-7 px-0",children:/* @__PURE__ */t(Yt,{className:"h-3.5 w-3.5","aria-hidden":!0})});}function Bi({dashboardId:e}){const{openDashboardId:a,access:s,printMode:r,serverIsFavorite:d,fetchedAt:o}=C(Oa(u=>{var l;return{openDashboardId:(l=u.dashboard)==null?void 0:l.id,access:u.viewer.access,printMode:u.viewer.printMode,serverIsFavorite:u.viewer.isFavorite,fetchedAt:u.viewer.fetchedAt};})),i=xn(),h=i.isFavorite(e,d,o);return a!==e||r||s==="session-only"?null:/* @__PURE__ */t(vn,{variant:"toolbar",isFavorite:h,readOnly:s==="read-only",pending:i.isPending(e),onToggle:()=>void i.setFavorite({dashboardId:e,isFavorite:!h})});}function _i(e){var u;const{authToken:a,tokenProps:s}=it(),{data:r}=yn(),{mutate:d,isPending:o}=Nn(),i=!!e&&((u=r==null?void 0:r.preference)==null?void 0:u.defaultDashboardId)===e,h=!r||o;return{available:!!e&&!!(a!=null&&a.accessToken)&&!!(s!=null&&s.apiServiceUrl),isDefault:i,disabled:h,toggle:()=>{!e||h||d({dashboardId:i?null:e});}};}function Oi({open:e,onOpenChange:a,onSave:s,onDiscard:r,isSaving:d,title:o="Unsaved changes",description:i="You have unsaved changes to this dashboard. What would you like to do?",cancelLabel:h="Cancel",discardLabel:u="Discard changes",saveLabel:l="Save"}){return/* @__PURE__ */t(Dt,{open:e,onOpenChange:p=>{!p&&d||a(p);},children:/* @__PURE__ */n(At,{children:[/* @__PURE__ */n(Ft,{children:[/* @__PURE__ */t(Et,{children:o}),/* @__PURE__ */t(It,{children:i})]}),/* @__PURE__ */n(Tt,{children:[/* @__PURE__ */t(I,{type:"button",size:"xs",onClick:r,disabled:d,variant:"outline",className:"mr-auto text-destructive hover:border-destructive/40 hover:bg-destructive/10 hover:text-destructive focus-visible:bg-destructive/10 focus-visible:text-destructive",children:u}),s?/* @__PURE__ */t(Lt,{disabled:d,children:h}):/* @__PURE__ */t(Cn,{asChild:!0,children:/* @__PURE__ */t(I,{type:"button",size:"xs",children:h})}),s&&/* @__PURE__ */t(I,{type:"button",size:"xs",onClick:s,disabled:d,children:d?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(se,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Saving..."]}):l})]})]})});}async function Pi(e){var o,i;const a=(i=(o=C.getState())==null?void 0:o.authToken)==null?void 0:i.accessToken;if(!a)return;const s=`${e}/v1/invalidate-token`,r=await fetch(s,{method:"POST",headers:{Authorization:`Bearer ${a}`}});if(!r.ok)throw new Error("Failed to invalidate token");const d=await r.json();return console.log("invalidateToken",d),d;}function Jr(e){var s;const a=e.item;return a.kind==="export"?{title:a.title,status:a.status,startedAt:a.startedAt,finishedAt:a.finishedAt,running:ja(a.stage),finishedDetail:[a.totalRows!==null?`${a.totalRows.toLocaleString("en-US")} rows`:null,a.fileSize?$a(a.fileSize):null].filter(r=>!!r),failure:((s=a.failure)==null?void 0:s.kind)==="export"?a.failure.message:a.status==="failed"?Ne.failedFallback:null,note:null}:{title:a.title,status:a.status,startedAt:a.startedAt,finishedAt:a.finishedAt,running:{text:a.stageLabel??Ne.inProgress},finishedDetail:[],failure:null,note:a.omittedAttachmentCount>0?ge.attachmentsLeftOut(a.omittedAttachmentCount):null};}function Xt({row:e,now:a,api:s}){const[r,d]=F("idle"),o=za(e,s),i=async()=>{if(!o)return;d("working");const h=await qa(s,e,o);d(h==="done"?"idle":h);};return/* @__PURE__ */t(Sa,{shown:Jr(e),now:a,longRunningHint:e.item.kind==="export",action:o?{label:ia[o],run:()=>void i()}:null,working:r==="working",problem:r==="denied"||r==="blocked"?r:null});}function es({work:e,now:a}){const s=e.stage==="preparing"?e.cancel:null;return/* @__PURE__ */t(Sa,{shown:{title:e.title,status:"running",startedAt:e.startedAt,finishedAt:null,running:Pa(e),finishedDetail:[],failure:null,note:null},now:a,longRunningHint:!1,action:s?{label:ia.cancel,run:s}:null,working:!1,problem:null});}function Sa({shown:e,now:a,longRunningHint:s,action:r,working:d,problem:o}){const i=e.status==="ready"?"bg-emerald-500":e.status==="failed"?"bg-destructive":e.status==="cancelled"?"bg-muted-foreground/40":"animate-pulse bg-muted-foreground/60",h=e.status==="ready"?Ne.ready:e.status==="failed"?Ne.failed:e.status==="cancelled"?Ne.cancelled:Ne.inProgress,u=Date.parse(e.startedAt),l=qt(Date.parse(e.finishedAt??e.startedAt),a,{addSuffix:!0}),c=e.status==="running"&&s&&a-u>=Ra,p=/* @__PURE__ */t("span",{className:"text-muted-foreground/50",children:"·"});return/* @__PURE__ */n("div",{className:"group flex items-start gap-2.5 px-3 py-2 transition-colors hover:bg-muted/40 focus-within:bg-muted/40",children:[/* @__PURE__ */t("span",{className:"flex h-5 shrink-0 items-center","aria-hidden":"true",children:/* @__PURE__ */t("span",{className:`h-1.5 w-1.5 rounded-full ${i}`})}),/* @__PURE__ */t("span",{className:"sr-only",children:h}),/* @__PURE__ */n("div",{className:"min-w-0 flex-1",children:[/* @__PURE__ */n("div",{className:"flex h-5 items-center gap-2",children:[/* @__PURE__ */t("span",{className:"min-w-0 flex-1 truncate text-[13px] font-medium leading-5",children:e.title}),r&&d&&/* @__PURE__ */t("span",{role:"status",className:"inline-flex shrink-0 items-center gap-1.5 text-[12px] text-muted-foreground",children:/* @__PURE__ */t(oa,{className:"h-3 w-3 animate-spin",strokeWidth:1.75})}),r&&!d&&/* @__PURE__ */t("button",{type:"button",onClick:r.run,className:"shrink-0 text-[12px] font-medium text-foreground/80 underline-offset-2 hover:text-foreground hover:underline focus-visible:underline focus-visible:outline-none",children:r.label})]}),e.status==="running"&&e.running&&/* @__PURE__ */n("div",{className:"text-[12px] leading-4 text-muted-foreground",children:[/* @__PURE__ */t("span",{className:"tabular-nums",children:e.running.text}),e.running.detail&&/* @__PURE__ */n(R,{children:[" ",p," ",/* @__PURE__ */t("span",{className:"tabular-nums",children:e.running.detail})]})," ",p," ",/* @__PURE__ */t("span",{children:Ne.started(qt(u,a))}),e.running.percent!==void 0&&/* @__PURE__ */t(Ma,{value:e.running.percent,className:"mt-1.5 h-1"}),c&&/* @__PURE__ */t("div",{className:"mt-1",children:Ne.longRunning})]}),e.status!=="running"&&/* @__PURE__ */n("div",{className:"flex items-center gap-1.5 text-[12px] leading-4 text-muted-foreground",children:[e.status==="ready"&&e.finishedDetail.length>0?/* @__PURE__ */n("span",{className:"hidden group-hover:contents group-focus-within:contents",children:[e.finishedDetail.map((m,g)=>/* @__PURE__ */n(aa.Fragment,{children:[g>0&&p,/* @__PURE__ */t("span",{children:m})]},g)),p]}):e.status!=="ready"?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t("span",{children:h}),p]}):null,/* @__PURE__ */t("span",{children:l})]}),e.note&&/* @__PURE__ */t("div",{className:"text-[12px] leading-4 text-muted-foreground",children:e.note}),e.status==="failed"&&e.failure&&/* @__PURE__ */t("div",{className:"mt-1 whitespace-pre-wrap break-words text-[12px] leading-4 text-destructive",children:e.failure}),o&&/* @__PURE__ */t(Ua,{problem:o,className:"mt-1"})]})]});}function zi({variant:e}){const{snapshot:a,markSeen:s}=St(),r=a.runningCount>0?a.runningCount>9?"9+":String(a.runningCount):a.hasUnseenFinished?"":null,d=xa("activity","md",{label:ge.title,icon:/* @__PURE__ */t(Ht,{className:"h-3.5 w-3.5"}),hint:r||(r===""?"New":void 0),order:30,onOpen:s});return d.collapsed?/* @__PURE__ */n(Ee,{open:d.popoverOpen,onOpenChange:o=>{d.setPopoverOpen(o),o&&s();},children:[d.anchorSlot&&vr(/* @__PURE__ */t(la,{asChild:!0,children:/* @__PURE__ */t("span",{className:"absolute right-0 top-0 h-7 w-px"})}),d.anchorSlot),/* @__PURE__ */t(Ie,{className:"w-80 p-0",align:"end",sideOffset:8,onFocusOutside:o=>o.preventDefault(),children:/* @__PURE__ */t(Zt,{})})]}):/* @__PURE__ */n(Ee,{onOpenChange:o=>{o&&s();},children:[/* @__PURE__ */t(tt,{asChild:!0,children:/* @__PURE__ */n(I,{variant:e??"ghost",size:"xs",className:"relative w-7 px-0","aria-label":ge.title,title:ge.title,children:[/* @__PURE__ */t(Ht,{className:"h-3.5 w-3.5"}),r!==null&&/* @__PURE__ */t("span",{className:`absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${r?"-right-0.5 -top-0.5 h-3.5 min-w-3.5 px-0.5 text-[9px] font-semibold":"right-1 top-1 h-1.5 w-1.5"}`,children:r})]})}),/* @__PURE__ */t(Ie,{className:"w-80 p-0",align:"end",sideOffset:8,children:/* @__PURE__ */t(Zt,{})})]});}function Zt(){const e=St(),a=Wa(),{rows:s,browserRows:r,activeTruncated:d}=e.snapshot,o=s.some(l=>ct(l.item.status)),i=[...s.filter(l=>!ct(l.item.status)).map(l=>({startedAt:l.item.startedAt,row:l})),...r.map(l=>({startedAt:l.startedAt,work:l}))].sort((l,c)=>c.startedAt.localeCompare(l.startedAt)),h=s.filter(l=>ct(l.item.status)),u=s.length+r.length;return u===0?/* @__PURE__ */n("div",{className:"flex flex-col items-center gap-1.5 px-6 py-8 text-center",children:[/* @__PURE__ */t("span",{className:"flex h-8 w-8 items-center justify-center rounded-[6px] border border-border text-muted-foreground",children:/* @__PURE__ */t(wn,{className:"h-3.5 w-3.5",strokeWidth:1.75})}),/* @__PURE__ */t("p",{className:"text-[13px] font-medium",children:ge.title}),/* @__PURE__ */t("p",{className:"text-[12px] text-muted-foreground",children:ge.empty})]}):/* @__PURE__ */n("div",{className:"flex flex-col",children:[/* @__PURE__ */n("div",{className:"flex h-8 items-center gap-2 border-b border-border px-3",children:[/* @__PURE__ */t("span",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:ge.title}),/* @__PURE__ */t("span",{className:"text-[10px] tabular-nums text-muted-foreground/70",children:u}),/* @__PURE__ */n("div",{className:"ml-auto flex items-center gap-0.5",children:[o&&/* @__PURE__ */t(I,{variant:"ghost",size:"xs",className:"h-6 px-1.5 text-[12px] text-muted-foreground hover:text-foreground",onClick:e.clearFinished,children:ge.clear}),/* @__PURE__ */t(I,{variant:"ghost",size:"xs",className:"h-6 w-6 px-0 text-muted-foreground hover:text-foreground",onClick:e.refresh,title:"Refresh status","aria-label":"Refresh status",children:/* @__PURE__ */t(oa,{strokeWidth:1.75,className:"h-3.5 w-3.5"})})]})]}),d&&/* @__PURE__ */t("p",{className:"border-b border-border px-3 py-2 text-[12px] leading-4 text-muted-foreground",children:ge.truncated}),/* @__PURE__ */t("div",{className:"max-h-[320px] overflow-y-auto",children:/* @__PURE__ */n("div",{className:"divide-y divide-border/70",children:[i.map(l=>"work"in l?/* @__PURE__ */t(es,{work:l.work,now:a},l.work.id):/* @__PURE__ */t(Xt,{row:l.row,now:a,api:e},Ut(l.row))),h.map(l=>/* @__PURE__ */t(Xt,{row:l,now:a,api:e},Ut(l)))]})})]});}function ts(e){if(e)return{renamed:e.type==="rename"?{oldId:e.oldId,newId:e.newId}:void 0,removedControlId:e.type==="remove"?e.controlId:void 0,cardBindingsById:e.type==="add"||e.type==="update"?e.cardBindingsById:void 0,affectedBindingControlIds:e.type==="add"||e.type==="update"?e.affectedBindingControlIds:void 0};}function as({open:e,onOpenChange:a,trigger:s,showTrigger:r=!0,initialMode:d="manage"}){const o=d==="create",{forceClose:i,handleOpenChange:h,isCreateFlowActive:u,preventPassiveDismissDuringCreate:l,resolvedOpen:c,setIsCreateFlowActive:p}=ya({open:e,onOpenChange:a,initialCreateFlowActive:d==="create",dismissMode:r?"passive":"explicit-only"}),m=C(b=>b.dashboard),{setDashboardControlsModel:g}=Ae(),{participants:f}=kn(Nr(m)),N=Array.from(new Map(f.flatMap(b=>b.fieldChoices.map(_=>{var A;return[_.value,{option:_,target:(A=b.fieldTargetMap)==null?void 0:A[_.value]}];}))).values()),w=Array.from(new Map(f.flatMap(b=>b.metricChoices.map(_=>{var A;return[_.value,{option:_,target:(A=b.metricTargetMap)==null?void 0:A[_.value]}];}))).values()),T=Gn({...(m||{}),controls:[]}),L=Sn(m),B=(b,_,A)=>{g(b,_,ts(A));},D=oe(()=>{if(o){i();return;}p(!1);},[o,i,p]),P=/* @__PURE__ */t(Na,{scope:"dashboard",controls:m.controls||[],reservedControlIds:T,defaultValues:m.defaultControlValues||{},usageByControlId:Dn(m),availableFieldChoices:N,availableMetricChoices:w,structuralParticipants:f,structuralParticipantIdsByControlId:L,initialCreateFlow:d==="create",onCreateFlowActiveChange:p,onCreateFlowComplete:D,onChange:B,emptyMessage:"No dashboard controls yet."}),k=u?"Add dashboard control":"Dashboard Controls",v=/* @__PURE__ */n(R,{children:[/* @__PURE__ */n("div",{className:"space-y-1",children:[/* @__PURE__ */t("h4",{className:"text-sm font-medium",children:"Dashboard Controls"}),/* @__PURE__ */t("p",{className:"text-xs text-muted-foreground",children:"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),P]});return r?/* @__PURE__ */n(Ee,{open:c,onOpenChange:h,children:[/* @__PURE__ */t(tt,{asChild:!0,children:s||/* @__PURE__ */n(I,{variant:"outline",className:"h-7 px-2",size:"sm",children:[/* @__PURE__ */t(da,{className:"mr-2 h-4 w-4"}),"Controls"]})}),/* @__PURE__ */t(Ie,{className:"w-[620px] max-w-[95vw] space-y-4",align:"end",onEscapeKeyDown:l,onPointerDownOutside:l,children:v})]}):/* @__PURE__ */t(Te,{open:c,onOpenChange:h,children:/* @__PURE__ */n(Le,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:l,onPointerDownOutside:l,children:[/* @__PURE__ */n(wt,{className:u?"space-y-0":void 0,children:[/* @__PURE__ */t(Ve,{className:"text-[15px]",children:k}),/* @__PURE__ */t(st,{className:u?"sr-only":"text-[13px]",children:u?"Configure and add a shared dashboard control.":"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),/* @__PURE__ */t("div",{className:"min-h-0 overflow-y-auto pr-1",children:P})]})});}const ns=["enum","multi_enum","text","number","boolean","date"];function rs({open:e,onOpenChange:a,initialMode:s="manage"}){var v;const r=s==="create",{forceClose:d,handleOpenChange:o,isCreateFlowActive:i,preventPassiveDismissDuringCreate:h,resolvedOpen:u,setIsCreateFlowActive:l}=ya({open:e,onOpenChange:a,initialCreateFlowActive:s==="create",dismissMode:"explicit-only"}),c=C(b=>b.dashboard),p=C(b=>b.selectedSheetId),{setDashboardInputs:m}=Ae(),g=(v=c.sheets)==null?void 0:v.find(b=>b.id===p),f=(g==null?void 0:g.kind)==="document"&&!!g.document,N=K(()=>f&&g!=null&&g.document?Hn(c,g.id):[],[c,f,g==null?void 0:g.document,g==null?void 0:g.id]),w=K(()=>N.filter(b=>b.kind==="control"),[N]),T=K(()=>w.map(b=>b.control),[w]),L=K(()=>is(T),[T]),B=K(()=>[...ss(c),...(c.variables??[]).map(b=>b.name)],[c]),D=oe(()=>{if(r){d();return;}l(!1);},[r,d,l]),P=oe((b,_,A)=>{!f||!(g!=null&&g.document)||m(ls({dashboard:c,documentSheetId:g.id,currentDocumentInputs:N,nextControls:b,nextDefaultValues:_,change:A}));},[c,N,f,g,m]);return!f||!(g!=null&&g.document)?null:/* @__PURE__ */t(Te,{open:u,onOpenChange:o,children:/* @__PURE__ */n(Le,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:h,onPointerDownOutside:h,children:[/* @__PURE__ */n(wt,{className:i?"space-y-0":void 0,children:[/* @__PURE__ */t(Ve,{className:"text-[15px]",children:i?"Add document control":"Document Controls"}),/* @__PURE__ */t(st,{className:i?"sr-only":"text-[13px]",children:i?"Configure and add a document-local control input.":"Add document-local control inputs. They are stored on this document sheet and are not dashboard controls."})]}),/* @__PURE__ */t("div",{className:"min-h-0 overflow-y-auto pr-1",children:/* @__PURE__ */t(Na,{scope:"dashboard",controls:T,reservedControlIds:B,defaultValues:L,usageByControlId:{},availableFieldChoices:[],availableMetricChoices:[],structuralParticipants:[],structuralParticipantIdsByControlId:{},allowedControlTypes:ns,initialCreateFlow:s==="create",onCreateFlowActiveChange:l,onCreateFlowComplete:D,onChange:P,emptyMessage:"No document controls yet."})})]})});}function ss(e){return(e.controls||[]).map(a=>a.id);}function is(e){const a={};for(const s of e)s.defaultValue!==void 0&&(a[s.id]=s.defaultValue);return a;}function os(e,a){return a?Object.prototype.hasOwnProperty.call(a,e.id)?{...e,defaultValue:a[e.id]}:e.defaultValue===void 0?e:{...e,defaultValue:void 0}:e.defaultValue===void 0?e:{...e,defaultValue:void 0};}function ls({dashboard:e,documentSheetId:a,currentDocumentInputs:s,nextControls:r,nextDefaultValues:d,change:o}){const i=new Map(r.map(g=>[g.id,os(g,d)])),h=(o==null?void 0:o.type)==="rename"?{oldId:o.oldId,newId:o.newId}:null,u=/* @__PURE__ */new Set(),l=[];for(const g of s){if(g.kind!=="control"){l.push(g);continue;}const f=i.get(g.control.id)||((h==null?void 0:h.oldId)===g.control.id?i.get(h.newId):void 0);if(!f)continue;u.add(f.id);const N=Yn(e,{name:f.id},{exclude:{source:"input",inputId:g.id},alsoTaken:l}),w=f.id===N?f:{...f,id:N};l.push({...g,label:w.label,variableName:N,requiredAtExecution:w.requiredAtExecution,control:w});}for(const g of i.values())u.has(g.id)||l.push(Xn({control:g,dashboard:e,alsoTaken:l,sheetId:a}));const c=new Set(s.map(g=>g.id));return[...(Array.isArray(e.inputs)?e.inputs:[]).filter(g=>!c.has(g.id)),...l];}function ds({showFilters:e,onShowFiltersChange:a,pickerContent:s,settingsContent:r,size:d="default",className:o,primaryButtonClassName:i,secondaryButtonClassName:h,pickerContentClassName:u,settingsContentClassName:l}){const c=d==="toolbar",[p,m]=F(!1),g=rt("interactive");return/* @__PURE__ */n("div",{className:G("relative inline-flex items-stretch overflow-hidden rounded-control border border-input bg-background",c?"h-8":"h-7",o),children:[/* @__PURE__ */n(Ee,{open:e,onOpenChange:a,children:[/* @__PURE__ */t(tt,{asChild:!0,children:/* @__PURE__ */n(I,{variant:"ghost",size:"xs",className:G("h-full rounded-none border-0 bg-transparent pl-2.5 pr-2 shadow-none hover:bg-accent/50 data-[state=open]:bg-accent/60",i),children:[e?/* @__PURE__ */t(br,{className:"h-3.5 w-3.5"}):/* @__PURE__ */t(ca,{className:"h-3.5 w-3.5"}),"Filter"]})}),/* @__PURE__ */t(Ie,{align:"end",sideOffset:6,className:G("w-auto rounded-card border border-border/60 p-0 shadow-[0_10px_28px_rgba(0,0,0,0.14)] dark:shadow-[0_10px_28px_rgba(0,0,0,0.5)]",u),style:g.contentStyle,children:s})]}),/* @__PURE__ */n(Ee,{open:p,onOpenChange:m,children:[/* @__PURE__ */t(tt,{asChild:!0,children:/* @__PURE__ */t(I,{variant:"ghost",size:"xs",className:G("h-full w-7 rounded-none border-0 border-l border-border/60 bg-transparent px-0 shadow-none hover:bg-accent/50 data-[state=open]:bg-accent/60",h),"aria-label":"Filter and control actions",children:/* @__PURE__ */t(kt,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */t(Ie,{align:"end",sideOffset:6,className:G("w-auto rounded-card border border-border/60 p-0 shadow-[0_10px_28px_rgba(0,0,0,0.14)] dark:shadow-[0_10px_28px_rgba(0,0,0,0.5)]",l),style:g.contentStyle,children:r(()=>m(!1))})]})]});}function cs(){const e=C(l=>l.dashboard),a=C(l=>l.semanticExecutionPayload),s=C(l=>l.actions.addFilterInput),r=C(l=>l.selectedSheetId),d=K(()=>{var c,p;const l=((c=e==null?void 0:e.sheets)==null?void 0:c.find(m=>m.id===r))??((p=e==null?void 0:e.sheets)==null?void 0:p[0]);return((l==null?void 0:l.frames)??[]).map(m=>Sr(m)).filter(m=>!!m);},[e,r]),o=Dr(d).length>0,i=K(()=>Zn(e,a),[e,a]),u=!Jn(e)&&i.hasEligibleCards;return/* @__PURE__ */n("div",{className:"flex h-[520px] w-[400px] flex-col",children:[u&&/* @__PURE__ */t("div",{className:"border-b border-border/60 p-2",children:/* @__PURE__ */n("button",{type:"button",onClick:()=>s(er(),{kind:"allSheets",sheetKinds:["dashboard"]}),title:`Applies to ${i.eligibleCardCount} of ${i.totalCardCount} date-aware cards`,className:"flex w-full items-start gap-2 rounded-control px-2 py-1.5 text-left outline-none transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-border",children:[/* @__PURE__ */t(An,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),/* @__PURE__ */n("span",{className:"flex min-w-0 flex-col",children:[/* @__PURE__ */t("span",{className:"text-[12px] font-medium text-foreground",children:"Add global date filter"}),/* @__PURE__ */t("span",{className:"text-[11px] leading-[1.4] text-muted-foreground",children:"One date range across all date-aware cards."})]})]})}),!o&&/* @__PURE__ */n("div",{className:"flex flex-1 flex-col items-center justify-center px-6 py-8 text-center",children:[/* @__PURE__ */t(Ka,{className:"mb-3 h-10 w-10 text-muted-foreground/50"}),/* @__PURE__ */t("h3",{className:"mb-1 text-[13px] font-medium text-foreground",children:"No fields configured"}),/* @__PURE__ */t("p",{className:"text-[11px] text-muted-foreground",children:"Add a card with data to this sheet to filter it."})]}),o&&/* @__PURE__ */t("div",{className:"flex flex-1 overflow-hidden",children:/* @__PURE__ */t(Fn,{cards:d,context:"filter"})})]});}function us({onAddFilter:e,onAddControl:a,onManageControls:s,onDismiss:r}){const d=C(h=>h.dashboard.filterLayout),{setFilterLayout:o}=Ae(),i=(d==null?void 0:d.toolbarWrap)??!1;return/* @__PURE__ */n("div",{className:"w-[300px]",children:[/* @__PURE__ */n("div",{className:"p-1",children:[/* @__PURE__ */t(ft,{icon:ca,label:"Add filter",onClick:()=>{e(),r();}}),/* @__PURE__ */t(ft,{icon:da,label:"Add control",onClick:()=>{a(),r();}}),/* @__PURE__ */t(ft,{icon:Bt,label:"Manage controls",onClick:()=>{s(),r();}})]}),/* @__PURE__ */t("div",{className:"border-t border-border/60"}),/* @__PURE__ */n("div",{className:"space-y-1 p-2",children:[/* @__PURE__ */t("p",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Display"}),/* @__PURE__ */t(hs,{id:"filter-display-wrap",label:"Wrap to multiple lines",checked:i,onCheckedChange:h=>o({toolbarWrap:h===!0})})]})]});}function ft({icon:e,label:a,onClick:s}){return/* @__PURE__ */n("button",{type:"button",onClick:s,className:"flex w-full items-center gap-2 rounded-control px-2 py-1.5 text-left text-[13px] text-foreground outline-none transition-colors hover:bg-muted/40 focus-visible:bg-muted/40",children:[/* @__PURE__ */t(e,{className:"h-3.5 w-3.5 text-muted-foreground"}),a]});}function hs({id:e,label:a,checked:s,onCheckedChange:r}){return/* @__PURE__ */n("div",{className:"flex items-center gap-2 rounded-control px-1 py-1 transition-colors hover:bg-muted/40 focus-within:bg-muted/40",children:[/* @__PURE__ */t(Nt,{id:e,checked:s,onCheckedChange:r}),/* @__PURE__ */t(Re,{htmlFor:e,className:"cursor-pointer text-[12px] font-normal leading-[1.3]",children:a})]});}function Ri({size:e,className:a,primaryButtonClassName:s,secondaryButtonClassName:r,pickerContentClassName:d,settingsContentClassName:o}){var P;const[i,h]=F(null),u=C(k=>k.dashboard),l=C(k=>k.selectedSheetId),c=C(k=>k.showFilters),p=C(k=>k.actions),{setDocumentPanelTarget:m,setShowFilters:g}=p,f=(P=u.sheets)==null?void 0:P.find(k=>k.id===l),N=_t(f),w=oe(k=>{window.setTimeout(()=>{h(k);},0);},[]),T=oe(k=>{if(N&&l){k&&m(l,{kind:"document",group:"inputs"});return;}g(k);},[N,l,m,g]),L=oe(()=>{T(!0);},[T]),B=oe(()=>{w("create");},[w]),D=oe(()=>{w("manage");},[w]);return/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(ds,{showFilters:N?!1:c,onShowFiltersChange:T,pickerContent:/* @__PURE__ */t(cs,{}),settingsContent:k=>/* @__PURE__ */t(us,{onAddFilter:L,onAddControl:B,onManageControls:D,onDismiss:k}),size:e,className:a,primaryButtonClassName:s,secondaryButtonClassName:r,pickerContentClassName:d,settingsContentClassName:o}),i?N?/* @__PURE__ */t(rs,{open:!0,onOpenChange:k=>{k||h(null);},initialMode:i}):/* @__PURE__ */t(as,{open:!0,onOpenChange:k=>{k||h(null);},showTrigger:!1,initialMode:i}):null]});}function ms(e,a){return(e.variables??[]).map(s=>{const r=Cr(e,s.id);return{variable:s,question:Fr(s),places:r,usedHere:!!a&&r.some(d=>d.sheetId===a)};});}function ps(e,a){const s=a?e.places.filter(d=>d.sheetId===a).length:0,r=e.places.length-s;return e.places.length?s&&r?`Used here · ${r} elsewhere`:s?"Used here":`Used in ${r} ${r===1?"place":"places"}`:"Not used yet";}function fs({dashboard:e,sheetId:a,sheetTitle:s,onOpen:r,onNew:d}){const[o,i]=F(""),h=K(()=>ms(e,a),[e,a]),u=o.trim().toLowerCase(),l=h.filter(m=>!u||m.variable.name.toLowerCase().includes(u)||(m.variable.label??"").toLowerCase().includes(u)||m.question.toLowerCase().includes(u)),c=l.filter(m=>m.usedHere),p=l.filter(m=>!m.usedHere);return/* @__PURE__ */n("div",{className:"w-[380px] max-w-[calc(100vw-24px)] overflow-hidden","data-testid":"variables-list",children:[/* @__PURE__ */n("div",{className:"flex h-11 items-center justify-between gap-2 border-b border-border/60 px-3",children:[/* @__PURE__ */n("span",{className:"flex items-center gap-2",children:[/* @__PURE__ */t(xt,{className:"h-3.5 w-3.5 text-muted-foreground","aria-hidden":!0}),/* @__PURE__ */t("span",{className:"text-[13px] font-medium",children:"Data variables"}),h.length?/* @__PURE__ */t("span",{className:"rounded-full bg-muted px-2 py-0.5 text-[10px] font-medium tabular-nums text-muted-foreground",children:h.length}):null]}),h.length?/* @__PURE__ */n(I,{size:"xs",className:"gap-1",onClick:d,children:[/* @__PURE__ */t(xe,{className:"h-3.5 w-3.5","aria-hidden":!0})," New variable"]}):null]}),h.length?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t("div",{className:"px-3 py-2",children:/* @__PURE__ */n("div",{className:"flex h-7 items-center gap-1.5 rounded-control border border-border px-2 text-[12px] text-muted-foreground",children:[/* @__PURE__ */t(na,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}),/* @__PURE__ */t("input",{value:o,onChange:m=>i(m.target.value),placeholder:"Search variables","aria-label":"Search variables",className:"w-full bg-transparent text-foreground outline-none placeholder:text-muted-foreground"})]})}),/* @__PURE__ */n("div",{className:"max-h-[360px] overflow-y-auto",children:[c.length?/* @__PURE__ */t(Jt,{children:s?`On ${s}`:"On this tab"}):null,c.map(m=>/* @__PURE__ */t(ea,{row:m,sheetId:a,onOpen:r},m.variable.id)),p.length?/* @__PURE__ */t(Jt,{children:c.length?"Elsewhere on this dashboard":"On this dashboard"}):null,p.map(m=>/* @__PURE__ */t(ea,{row:m,sheetId:a,onOpen:r,muted:!!c.length},m.variable.id)),l.length?null:/* @__PURE__ */t("p",{className:"px-4 py-6 text-center text-[12px] text-muted-foreground",children:"No variable matches."})]})]}):/* @__PURE__ */n("div",{className:"px-6 py-8 text-center",children:[/* @__PURE__ */t("span",{className:"mx-auto flex h-8 w-8 items-center justify-center rounded-full bg-muted",children:/* @__PURE__ */t(xt,{className:"h-4 w-4 text-muted-foreground","aria-hidden":!0})}),/* @__PURE__ */t("p",{className:"mt-3 text-[13px] font-medium",children:"No variables yet"}),/* @__PURE__ */t("p",{className:"mx-auto mt-1 max-w-[280px] text-[12px] leading-[1.5] text-muted-foreground",children:"A variable shows a value from your data in any text: a name or address in a header, the latest date in a footer."}),/* @__PURE__ */n(I,{size:"xs",className:"mt-4 gap-1",onClick:d,children:[/* @__PURE__ */t(xe,{className:"h-3.5 w-3.5","aria-hidden":!0})," New variable"]})]})]});}function Jt({children:e}){return/* @__PURE__ */t("p",{className:"border-y border-border/60 bg-muted/40 px-4 py-1 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground first:border-t-0",children:e});}function ea({row:e,sheetId:a,onOpen:s,muted:r}){return/* @__PURE__ */n("button",{type:"button",onClick:()=>s(e.variable.id),className:"grid w-full grid-cols-[minmax(0,1fr)_132px] items-center gap-3 border-t border-border/60 px-4 py-2 text-left first:border-t-0 hover:bg-muted/50",children:[/* @__PURE__ */n("span",{className:"min-w-0",children:[/* @__PURE__ */t("span",{className:G("block truncate text-[12px] font-medium text-foreground",!e.variable.label&&"font-mono"),children:e.variable.label||e.variable.name}),/* @__PURE__ */t("span",{className:"mt-0.5 block truncate text-[11px] text-muted-foreground",children:e.question})]}),/* @__PURE__ */t("span",{className:G("truncate text-right text-[11px]",r?"text-muted-foreground/70":"text-muted-foreground"),children:ps(e,a)})]});}function Mi(){const e=C(s=>{var r;return((r=s.dashboard.variables)==null?void 0:r.length)??0;}),a=C(s=>s.actions.setVariablesListOpen);return{label:"Data variables",count:e,open:()=>a(!0)};}function Ui(){var u;const e=C(l=>l.variablesListOpen),a=C(l=>l.actions.setVariablesListOpen),s=C(l=>l.dashboard),r=C(l=>l.selectedSheetId),d=C(l=>l.actions.openVariableEditor),o=rt("interactive"),i=(u=s.sheets)==null?void 0:u.find(l=>l.id===r),h=l=>{a(!1),d(l);};return/* @__PURE__ */n(Ee,{open:e,onOpenChange:a,children:[/* @__PURE__ */t(la,{asChild:!0,children:/* @__PURE__ */t("span",{"aria-hidden":!0,className:"pointer-events-none inline-block h-7 w-0 self-center"})}),/* @__PURE__ */t(Ie,{align:"end",sideOffset:6,collisionPadding:12,onFocusOutside:l=>l.preventDefault(),className:"z-50 w-auto rounded-card border border-border/60 p-0 shadow-[0_10px_28px_rgba(0,0,0,0.14)] dark:shadow-[0_10px_28px_rgba(0,0,0,0.5)]",style:o.contentStyle,children:/* @__PURE__ */t(fs,{dashboard:s,sheetId:r??void 0,sheetTitle:i==null?void 0:i.title,onOpen:l=>h({kind:"edit",variableId:l}),onNew:()=>h({kind:"new"})})})]});}function gs(e,a){const s=tr(e);return new Set((e.sheets??[]).map(d=>{const o={sheetId:d.id,cardId:a,sheetKind:_t(d)?"document":"dashboard"};return s.filter(i=>wr(i,o)).map(i=>i.runtimeScope==="shared"?i.id:`${i.id}@${d.id}`).join(`
|
|
42
|
-
`);})).size>1;}const bs=[];function gt(e){return Object.fromEntries(Object.entries(e).filter(([,a])=>a!=null));}function xs(e){const a=e==null?void 0:e.type;return a==="dataset"||a==="model"||nr.includes(a);}function vs(e,a){return Ar(e.map((s,r)=>{var d,o;return{target:s,columns:(d=a[r])==null?void 0:d.columns,calculatedFields:(o=a[r])==null?void 0:o.calculatedFields};})).columns;}function ys(e){const{tokenProps:a}=it(),s=C(m=>m.authToken),{connections:r}=ua(),d=e==null?void 0:e.connectionId,o=r.find(m=>m.id===d),i=K(()=>((e==null?void 0:e.selectedEntities)??[]).filter(xs),[e==null?void 0:e.selectedEntities]),h=m=>{var f;if(!(s!=null&&s.accessToken))return!1;if(m.type==="dataset"){const N=m;return!!(N.domainId&&N.name);}if(m.type==="model")return!!(d&&m.id);const g=((f=o==null?void 0:o.capabilities)==null?void 0:f.path)||[];return!(!d||!m.name||g.includes("database")&&!m.database||g.includes("schema")&&!m.schema);},u=oe(m=>{var f,N;const g=vs(i,m.map(w=>w.data));return{fields:g.length?g:bs,isLoading:m.some(w=>w.isLoading),error:(N=(f=m.find(w=>w.error))==null?void 0:f.error)==null?void 0:N.message};},[i]),{fields:l,isLoading:c,error:p}=Qa({queries:i.map(m=>({queryKey:["columns",d,m,(e==null?void 0:e.semanticDomainId)??null],queryFn:()=>ar(`${a.apiServiceUrl}/v1/columns`,(s==null?void 0:s.accessToken)||"",m.type==="model"?gt({connection_id:d,datamodel_id:m.id,database_name:"",schema_name:"",table_name:""}):m.type==="dataset"?gt({connection_id:m.connectionId??d,domain_id:m.domainId,dataset_name:m.name,database_name:m.database,schema_name:m.schema,table_name:m.table}):gt({connection_id:d,datamodel_id:"",database_name:m.database,schema_name:m.schema,table_name:m.name})),enabled:h(m),staleTime:6e4})),combine:u});return{fields:l,isLoading:c,error:p};}function Ns(e){var s;const a=((s=e.comparison)==null?void 0:s.mode)==="explicit"?e.comparison.spec:void 0;return a&&a.kind!=="target"?{mode:"period",spec:a}:{mode:"off"};}function Cs(e){return e.mode==="period"?ir(e.spec):void 0;}const Rt="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",ws={connectionId:"",connectionType:"",mode:"semanticDomain",selectedEntities:[]};function ae({label:e,hint:a,aside:s,children:r,className:d}){return/* @__PURE__ */n("div",{className:d,children:[/* @__PURE__ */n("div",{className:"mb-1 flex min-h-5 items-center justify-between gap-2",children:[/* @__PURE__ */t("p",{className:Rt,children:e}),s]}),r,a?/* @__PURE__ */t("p",{className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:a}):null]});}function bt({muted:e,onClick:a,children:s,ariaLabel:r}){return/* @__PURE__ */t("button",{type:"button",onClick:a,"aria-label":r,className:G("flex h-7 w-full items-center gap-1.5 rounded-control border border-input bg-background px-2 text-left text-[12px] hover:bg-muted/50",e?"text-muted-foreground":"text-foreground"),children:s});}function ks(e){var s;const a=(s=e==null?void 0:e.selectedEntities)==null?void 0:s[0];if(a)return a.label||a.name;}function Ss(e){const a=Ot(e);return a==="date"?"date":a==="string"?"text":a==="number"?"number":a==="boolean"?"yes/no":a;}const ta="__new_calculated_field__";function Ds({draft:e,onChange:a,handle:s,onCalculatedFieldOpenChange:r}){var Y,he,te,me,E,ne,Q,z,J,de,ce,ve;const{tokenProps:d}=it(),o=((Y=d.config)==null?void 0:Y.showAdvancedMode)!==!1,i=((he=d.config)==null?void 0:he.showDirectSource)!==!1,{connections:h}=ua(),[u,l]=F(!1),[c,p]=F(!1),[m,g]=F(!1),f=x=>{p(x),r==null||r(x);},{fields:N,isLoading:w,error:T}=ys(e.mode==="data"?e.dataSource:void 0),L=[...(e.calculatedFields??[]),...N],B=x=>x&&(L.find(O=>O.id===x.id)??L.find(O=>sr(O,x,"entity"))),D=[...L,...[e.field,e.sortField].filter(x=>!!x&&!B(x)&&!L.some(O=>O.id===x.id))],P=((te=B(e.field))==null?void 0:te.id)??((me=e.field)==null?void 0:me.id)??"",k=((E=B(e.sortField??e.field))==null?void 0:E.id)??((ne=e.sortField??e.field)==null?void 0:ne.id)??"",v=x=>a({...e,...x}),b=ks(e.dataSource),_=((Q=e.dataSource)==null?void 0:Q.mode)==="database"?vt:$t,A="mt-1 inline-flex items-center gap-1 text-[11px] font-medium text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",H={connectionId:((z=e.dataSource)==null?void 0:z.connectionId)||e.connectionId,dataSource:e.dataSource,config:e.conditions?{filters:e.conditions}:{},cardType:"text"},V=Wt(e.field),M=(J=V.find(x=>x.value===e.get))==null?void 0:J.hint,X=x=>{if(x===ta){f(!0);return;}const O=D.find(W=>W.id===x);if(!O)return;const $=Wt(O).some(W=>W.value===e.get)&&e.field!==void 0;v({field:O,get:$?e.get:Kt(O)});};return c?/* @__PURE__ */t(En,{inline:!0,open:!0,onOpenChange:f,availableFields:D,cardId:e.id,source:H,onSave:x=>{const O={...x,fieldScope:x.fieldScope??"card"};v({calculatedFields:[...(e.calculatedFields??[]).filter($=>$.id!==O.id),O],field:O,get:Kt(O)}),f(!1);}}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(ae,{label:"Name",aside:/* @__PURE__ */t(Fs,{value:e.name,placeholder:s,editing:m,onEditing:g,onChange:x=>v({name:x})}),hint:m?"The key: what you type after {{, and what links and agents use. Letters, digits and underscores.":void 0,children:/* @__PURE__ */t(be,{size:"xs",value:e.label??"",onChange:x=>v({label:x.target.value}),placeholder:((de=e.field)==null?void 0:de.label)||"Latest order date","aria-label":"Variable name"})}),e.mode==="sql"?/* @__PURE__ */n(R,{children:[/* @__PURE__ */n(ae,{label:"Connection",children:[/* @__PURE__ */n(we,{value:e.connectionId??"",onValueChange:x=>v({connectionId:x}),children:[/* @__PURE__ */t(ke,{size:"xs","aria-label":"Connection",children:/* @__PURE__ */t(Se,{placeholder:"Choose a connection"})}),/* @__PURE__ */t(De,{children:h.map(x=>/* @__PURE__ */t(fe,{value:x.id,children:x.name},x.id))})]}),/* @__PURE__ */n("button",{type:"button",onClick:()=>v({mode:"data"}),className:A,children:[/* @__PURE__ */t($t,{className:"h-3 w-3","aria-hidden":!0})," Use a dataset or table instead"]})]}),/* @__PURE__ */t(ae,{label:"SQL",hint:/* @__PURE__ */t(R,{children:"One row. Each column is a part; the first shows by default. Filters reach it where the SQL names them, as a SQL card's do."}),children:/* @__PURE__ */t(ba,{size:"xs",value:e.sql,onChange:x=>v({sql:x.target.value}),placeholder:"select max(order_date) as latest_order_date from orders",className:"min-h-[96px] font-mono","aria-label":"SQL"})}),/* @__PURE__ */t(ae,{label:"Get",children:/* @__PURE__ */n(we,{value:e.get==="first"?"first":"only",onValueChange:x=>v({get:x}),children:[/* @__PURE__ */t(ke,{size:"xs","aria-label":"Get",children:/* @__PURE__ */t(Se,{})}),/* @__PURE__ */n(De,{children:[/* @__PURE__ */t(fe,{value:"only",children:"The only row"}),/* @__PURE__ */t(fe,{value:"first",children:"The first row"})]})]})})]}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */n(ae,{label:"Source",children:[/* @__PURE__ */t(bt,{muted:!b,onClick:()=>l(!0),ariaLabel:"Source",children:b?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(_,{className:"h-3.5 w-3.5 text-muted-foreground","aria-hidden":!0})," ",b]}):i?"Choose a dataset or table":"Choose a dataset"}),o?/* @__PURE__ */n("button",{type:"button",onClick:()=>{var x;return v({mode:"sql",connectionId:((x=e.dataSource)==null?void 0:x.connectionId)||e.connectionId});},className:A,children:[/* @__PURE__ */t(Mr,{className:"h-3 w-3","aria-hidden":!0})," Write SQL instead"]}):null]}),/* @__PURE__ */t(In,{open:u,onOpenChange:l,dataSource:e.dataSource??ws,incomingSelectedEntities:((ce=e.dataSource)==null?void 0:ce.selectedEntities)??[],onDataSourceChange:x=>{var $;const O=JSON.stringify(x.selectedEntities)===JSON.stringify(($=e.dataSource)==null?void 0:$.selectedEntities);v(O?{dataSource:x}:{dataSource:x,field:void 0,sortField:void 0,conditions:null,calculatedFields:void 0});}}),/* @__PURE__ */n("div",{className:"grid grid-cols-2 gap-3",children:[/* @__PURE__ */t(ae,{label:"Field",children:b?/* @__PURE__ */n(we,{value:P,onValueChange:X,disabled:w&&!D.length,children:[/* @__PURE__ */t(ke,{size:"xs","aria-label":"Field",children:/* @__PURE__ */t(Se,{placeholder:w?"Loading fields…":T?"Fields unavailable":"Choose a field"})}),/* @__PURE__ */n(De,{children:[D.map(x=>/* @__PURE__ */t(fe,{value:x.id,children:/* @__PURE__ */n("span",{className:"flex items-center gap-2",children:[/* @__PURE__ */t("span",{children:x.label||x.name}),/* @__PURE__ */t("span",{className:"text-muted-foreground",children:Ss(x.dataType)})]})},x.id)),/* @__PURE__ */t(Ga,{}),/* @__PURE__ */t(fe,{value:ta,children:/* @__PURE__ */n("span",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */t(xe,{className:"h-3 w-3","aria-hidden":!0})," New calculated field…"]})})]})]}):/* @__PURE__ */t(bt,{muted:!0,children:"Choose a source first"})}),/* @__PURE__ */t(ae,{label:"Get",children:/* @__PURE__ */n(we,{value:e.get,onValueChange:x=>v({get:x}),disabled:!e.field,children:[/* @__PURE__ */t(ke,{size:"xs","aria-label":"Get",children:/* @__PURE__ */t(Se,{})}),/* @__PURE__ */t(De,{children:V.map(x=>/* @__PURE__ */t(fe,{value:x.value,children:x.label},x.value))})]})}),e.field&&M?/* @__PURE__ */t("p",{className:"col-span-2 -mt-1.5 text-[11px] leading-4 text-muted-foreground",children:M}):null,T?/* @__PURE__ */t("p",{className:"col-span-2 -mt-1.5 text-[11px] leading-4 text-destructive",children:T}):null,Er(e)?/* @__PURE__ */t(ae,{label:"Compare with",className:"col-span-2",children:/* @__PURE__ */t(Ha,{controlLabel:"Variable",selection:Ns(e),onChange:x=>v({comparison:Cs(x)})})}):null,e.field&&!Ir(e.get)&&e.get!=="only"?/* @__PURE__ */n("div",{className:G("col-span-2 grid gap-3",e.get==="list"?"grid-cols-3":"grid-cols-2"),children:[/* @__PURE__ */t(ae,{label:"Order by",children:/* @__PURE__ */n(we,{value:`${k}|${e.sortDirection}`,onValueChange:x=>{const O=x.lastIndexOf("|"),$=x.slice(0,O),W=x.slice(O+1);v({sortField:D.find(re=>re.id===$),sortDirection:W});},children:[/* @__PURE__ */t(ke,{size:"xs","aria-label":"Order by",children:/* @__PURE__ */t(Se,{})}),/* @__PURE__ */t(De,{children:D.flatMap(x=>["asc","desc"].map(O=>/* @__PURE__ */n(fe,{value:`${x.id}|${O}`,children:[x.label||x.name,", ",As(x,O)]},`${x.id}|${O}`)))})]})}),e.get==="list"?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(ae,{label:"Show up to",children:/* @__PURE__ */t(be,{size:"xs",type:"number",min:1,max:nt,value:e.listLimit??"",placeholder:"10",onChange:x=>{const O=Number.parseInt(x.target.value,10);v({listLimit:Number.isFinite(O)&&O>0?Math.min(O,nt):void 0});},"aria-label":"Show up to"})}),/* @__PURE__ */t(ae,{label:"Separator",children:/* @__PURE__ */t(be,{size:"xs",value:e.listSeparator??", ",maxLength:rr,onChange:x=>v({listSeparator:x.target.value}),className:"font-mono","aria-label":"Separator"})})]}):null]}):null]}),/* @__PURE__ */t(ae,{label:"Filters",children:b?/* @__PURE__ */t(xr,{filters:e.conditions??null,availableFields:D,source:H,onChange:x=>v({conditions:x})},JSON.stringify(((ve=e.dataSource)==null?void 0:ve.selectedEntities)??null)):/* @__PURE__ */t(bt,{muted:!0,children:"Choose a source first"})})]})]});}function As(e,a){const s=Ot(e.dataType);return s==="date"?a==="asc"?"earliest first":"latest first":s==="number"?a==="asc"?"lowest first":"highest first":a==="asc"?"A to Z":"Z to A";}function Fs({value:e,placeholder:a,editing:s,onEditing:r,onChange:d}){return s?/* @__PURE__ */t(be,{size:"xs",autoFocus:!0,value:e,placeholder:a,onChange:o=>d(o.target.value),onBlur:()=>r(!1),onKeyDown:o=>{(o.key==="Enter"||o.key==="Escape")&&(o.preventDefault(),o.stopPropagation(),r(!1));},className:"h-6 w-44 font-mono text-[11px]","aria-label":"Key"}):/* @__PURE__ */n("button",{type:"button",onClick:()=>r(!0),"aria-label":"Edit key",title:"The key: what you type after {{, and what links and agents use",className:"inline-flex h-5 items-center gap-1 rounded-[4px] px-1 font-mono text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:[`{{${e.trim()||a}}}`,/* @__PURE__ */t(Bt,{className:"h-3 w-3","aria-hidden":!0})]});}const Es=[{id:"data",label:"Data"},{id:"filters",label:"Dashboard filters"},{id:"display",label:"Display"}];function Is(e){const{name:a,label:s,presentation:r,emptyText:d,...o}=e;return JSON.stringify(o);}function Ts({variable:e,onClose:a,onHoldEscape:s}){var te,me;const r=C(E=>E.dashboard),d=C(E=>E.selectedSheetId),o=C(E=>E.actions.saveVariableChange),[i,h]=F(()=>e?Tr(e):Lr()),[u,l]=F("data"),[c,p]=F(!1),m=E=>{p(E),s==null||s(E);},[g,f]=F([]),[N,w]=F(null),T=!e,L=Is(i),B=K(()=>Qt({...JSON.parse(L),name:""},r),[L,r]),{name:D,label:P,presentation:k,emptyText:v}=i,b=K(()=>({...B,name:Gt(r,{id:B.id,name:D,field:i.field,mode:i.mode,label:P}),...(P!=null&&P.trim()?{label:P.trim()}:{}),...(k?{presentation:k}:{}),...(v!=null&&v.trim()?{emptyText:v}:{})}),[B,r,D,P,k,v,i.field,i.mode]),_=K(()=>({...r,variables:[...(r.variables??[]).filter(E=>E.id!==b.id),b]}),[r,b]),A=Vr(i),H=ot(),V=C(E=>E.actions.mergeSemanticExecutionPayload),[M,X]=F(!1),Y=async()=>{const E=Qt(i,r);X(!0);let ne;try{const z=ur(r,e?{kind:"update",id:e.id,patch:E}:{kind:"add",variable:E});if(!z.ok){X(!1),f(z.issues);return;}const[J]=z.queryFrames;ne=J?await H(J,e?{previousFrame:hr(r,e)}:void 0):{domainsById:{}};}catch(z){X(!1),f([{code:"queryMissing",message:z instanceof Error&&z.message?z.message:"The data source's details could not be loaded.",fix:"Try again, or choose the source again."}]);return;}const Q=o(T?{kind:"add",variable:E}:{kind:"update",id:E.id,patch:Ls(E)});if(X(!1),!Q.ok){f(Q.issues);return;}V(ne),a();},he=E=>{if(!e)return;const ne=o({kind:"remove",id:e.id,confirmed:E});if(!ne.ok){const Q=ne.issues.find(z=>z.code==="inUse");if(Q&&!E){w(Q);return;}f(ne.issues);return;}a();};return/* @__PURE__ */n("div",{className:"flex h-[600px] max-h-[85vh] w-[600px] max-w-[calc(100vw-24px)] flex-col overflow-hidden","data-testid":"variable-editor",children:[/* @__PURE__ */n("div",{className:"flex min-h-12 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3 py-1.5",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-start gap-2",children:[/* @__PURE__ */t(xt,{className:"mt-1 h-3.5 w-3.5 shrink-0 text-muted-foreground","aria-hidden":!0}),/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */n("p",{className:"flex items-center gap-2",children:[/* @__PURE__ */t("span",{className:"truncate text-[13px] font-medium text-foreground",children:T?"New variable":e.label||e.name}),/* @__PURE__ */t("span",{className:Rt,children:"Variable from data"})]}),/* @__PURE__ */t("p",{className:"mt-0.5 truncate text-[10px] leading-3 text-muted-foreground/70",children:"Available on every tab and Document of this dashboard"})]})]}),/* @__PURE__ */t("button",{type:"button",onClick:a,"aria-label":"Close",className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-control text-muted-foreground hover:bg-muted hover:text-foreground",children:/* @__PURE__ */t(Ue,{className:"h-3.5 w-3.5","aria-hidden":!0})})]}),c?null:/* @__PURE__ */t("nav",{role:"tablist","aria-label":"Variable settings sections",className:"flex h-9 shrink-0 items-stretch gap-4 border-b border-border/60 px-4",children:Es.map(E=>/* @__PURE__ */n("button",{role:"tab","aria-selected":u===E.id,onClick:()=>l(E.id),className:G("relative -mb-px inline-flex items-center text-[13px] transition-colors focus-visible:outline-none",u===E.id?"font-medium text-foreground":"text-muted-foreground hover:text-foreground"),children:[E.label,u===E.id?/* @__PURE__ */t("span",{className:"absolute inset-x-0 -bottom-px h-[2px] bg-foreground"}):null]},E.id))}),/* @__PURE__ */n("div",{className:G("min-h-0 flex-1 overflow-y-auto",u==="filters"||c?"":"space-y-4 px-4 py-4"),children:[u==="data"?/* @__PURE__ */t(Ds,{draft:i,onChange:h,handle:Gt(r,i),onCalculatedFieldOpenChange:m}):null,u==="filters"?/* @__PURE__ */t(Vs,{draft:i,draftDashboard:_}):null,u==="display"?/* @__PURE__ */t(Os,{draft:i,onChange:h}):null]}),c?null:/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(Ps,{draft:i,draftVariable:b,draftDashboard:_,blocker:A,selectedSheetId:d??void 0}),g.length?/* @__PURE__ */t("div",{className:"shrink-0 border-t border-border/60 bg-destructive/5 px-4 py-2 text-[11px] leading-4 text-destructive",role:"alert",children:g.map(E=>/* @__PURE__ */n("p",{children:[E.message," ",E.fix]},`${E.code}:${E.path??""}`))}):null,N?/* @__PURE__ */n("div",{className:"shrink-0 border-t border-border/60 bg-amber-500/10 px-4 py-2 text-[11px] leading-4 text-amber-800 dark:text-amber-300",role:"alertdialog",children:[/* @__PURE__ */n("p",{children:[N.message," Used in ",((te=N.places)==null?void 0:te.length)??0," ",((me=N.places)==null?void 0:me.length)===1?"place":"places",". Its chips then read as missing."]}),/* @__PURE__ */n("div",{className:"mt-1.5 flex gap-1.5",children:[/* @__PURE__ */t(I,{variant:"outline",size:"xs",className:"h-6 px-2 text-[11px]",onClick:()=>w(null),children:"Keep it"}),/* @__PURE__ */t(I,{size:"xs",className:"h-6 px-2 text-[11px]",onClick:()=>he(!0),children:"Remove anyway"})]})]}):null,/* @__PURE__ */n("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border/60 px-4 py-2.5",children:[T?/* @__PURE__ */t("span",{}):/* @__PURE__ */t(I,{variant:"outline",size:"xs",className:"text-destructive hover:border-destructive/40 hover:bg-destructive/10 hover:text-destructive",onClick:()=>he(!1),children:"Delete"}),/* @__PURE__ */n("span",{className:"flex items-center gap-1.5",children:[/* @__PURE__ */t(I,{variant:"outline",size:"xs",onClick:a,children:"Cancel"}),/* @__PURE__ */t(I,{size:"xs",disabled:!!A||M,title:A,onClick:()=>void Y(),children:T?"Create":"Done"})]})]})]})]});}function Ls(e){const{id:a,...s}=e;return{...s,label:s.label,presentation:s.presentation,emptyText:s.emptyText};}function Vs({draft:e,draftDashboard:a}){const s=K(()=>or(a),[a]),r=s.inputs.filter(o=>s.reachedVariables({inputId:o.input.id}).some(i=>i.variableId===e.id)),d=e.mode==="sql"&&lr(e.sql);return r.length?/* @__PURE__ */n("div",{className:"divide-y divide-border/60",children:[/* @__PURE__ */t("p",{className:"px-4 py-2 text-[11px] leading-4 text-muted-foreground",children:"How each filter applies here. Change a mapping on the filter's Cards tab, under Variables."}),r.map(o=>{var u;const i=(u=o.input.application)==null?void 0:u.cards.find(l=>l.cardId===e.id),h=d?"Subscribes in SQL":e.mode==="sql"?"Not named in the SQL":(i==null?void 0:i.kind)==="excluded"?"Don't apply":(i==null?void 0:i.kind)==="bound"?`${i.target.kind==="field"?"Field":"Path"} · ${i.target.field.name}`:"Auto";return/* @__PURE__ */n("div",{className:"flex items-center justify-between gap-3 px-4 py-2 text-[12px]",children:[/* @__PURE__ */n("span",{className:"min-w-0",children:[/* @__PURE__ */t("span",{className:"block truncate font-medium text-foreground",children:o.input.label||o.input.filter.title}),/* @__PURE__ */t("span",{className:"block truncate text-[11px] text-muted-foreground",children:Bs(o.input.scope)})]}),/* @__PURE__ */t("span",{className:G("shrink-0 text-[11px]",h==="Don't apply"||h==="Not named in the SQL"?"text-muted-foreground":"text-foreground"),children:h})]},o.input.id);})]}):/* @__PURE__ */t("p",{className:"px-4 py-6 text-center text-[12px] text-muted-foreground",children:"No filter reaches this variable. A filter on the tabs or Documents where it is used reaches it; a variable used nowhere yet follows every tab's filters."});}function Bs(e){switch(e.kind){case"allSheets":return"On every tab";case"sheets":return"On chosen tabs";case"cards":return"On chosen cards and variables";default:return e.kind;}}const _s=[{value:"auto",label:"Automatic"},{value:"short",label:"Short"},{value:"medium",label:"Medium"},{value:"long",label:"Long"},{value:"pattern",label:"Custom pattern…"}];function Os({draft:e,onChange:a}){var h,u;const s=e.mode==="sql"?"unknown":Ot((h=e.field)==null?void 0:h.dataType),r=(u=e.presentation)==null?void 0:u.temporal,d=r?r.mode==="style"?r.dateStyle:r.mode==="pattern"?"pattern":"auto":"auto",o=(r==null?void 0:r.mode)==="pattern"?yr(r.pattern):null,i=l=>a({...e,presentation:l&&Object.keys(l).length?l:void 0});return/* @__PURE__ */n(R,{children:[s==="date"||s==="unknown"?/* @__PURE__ */n(ae,{label:"Dates read as",hint:"A chip can change this for itself.",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-2",children:[/* @__PURE__ */n(we,{value:d,onValueChange:l=>i({...e.presentation,temporal:l==="auto"?void 0:l==="pattern"?{mode:"pattern",dialect:"semaphor_tokens",pattern:(r==null?void 0:r.mode)==="pattern"?r.pattern:"MMM D, YYYY"}:{mode:"style",dateStyle:l}}),children:[/* @__PURE__ */t(ke,{size:"xs",className:"w-44","aria-label":"Date style",children:/* @__PURE__ */t(Se,{})}),/* @__PURE__ */t(De,{children:_s.map(l=>/* @__PURE__ */t(fe,{value:l.value,children:l.label},l.value))})]}),(r==null?void 0:r.mode)==="pattern"?/* @__PURE__ */t(be,{size:"xs",value:r.pattern,onChange:l=>i({...e.presentation,temporal:{mode:"pattern",dialect:"semaphor_tokens",pattern:l.target.value}}),className:"w-40 font-mono","aria-label":"Date pattern"}):null]}),o?/* @__PURE__ */t("p",{className:"mt-1 text-[11px] text-destructive",children:o}):null]}):null,s==="number"||s==="unknown"?/* @__PURE__ */t(ae,{label:"Numbers read as",hint:"A chip can change any of these for itself.",children:/* @__PURE__ */t(Tn,{value:e.presentation,onChange:i})}):null,/* @__PURE__ */t(ae,{label:"When there’s no value",hint:"Readers see this when nothing matches or more than one does. Leave it empty to show nothing.",children:/* @__PURE__ */t(be,{size:"xs",value:e.emptyText??"",maxLength:dr,onChange:l=>a({...e,emptyText:l.target.value||void 0}),placeholder:"Show nothing",className:"w-72","aria-label":"Empty text"})})]});}function Ps({draft:e,draftVariable:a,draftDashboard:s,blocker:r,selectedSheetId:d}){var v;const o=s.sheets??[],i=K(()=>gs(s,a.id),[s,a.id]),[h,u]=F(void 0),l=(i?h:void 0)??d??((v=o[0])==null?void 0:v.id),c=o.find(b=>b.id===l),p=C(b=>l?b.documentSectionRuntimeBySheetId[l]:void 0),m=!!(c&&_t(c)),g=K(()=>l?m?p?{kind:"document",sheetId:l,runtime:p}:void 0:{kind:"sheet",sheetId:l}:void 0,[m,p,l]),f=K(()=>r||!g?[]:[a],[r,a,g]),w=Ln({dashboard:s,place:g??{kind:"sheet",sheetId:l??""},purpose:"preview",variables:f}).byId.get(a.id),T=Ya(),L=Xa(),B=K(()=>cr({preferences:T,calendar:L}),[L,T]);let D,P="",k=null;if(r)D=/* @__PURE__ */t("span",{className:"text-muted-foreground",children:e.mode==="sql"?"Write the SQL to see a value.":"Choose a source and a field to see a value."});else if(!g)D=/* @__PURE__ */t("span",{className:"text-muted-foreground",children:"Open this Document to preview here."});else if(!w||w.status==="loading")D=/* @__PURE__ */t("span",{className:"text-muted-foreground",children:"Loading…"});else{const b=zs(a,w,B);if(D=b.body,P=b.meta,b.unavailable){const _=(c==null?void 0:c.title)||"this tab";k=/* @__PURE__ */n("p",{className:"mt-1.5 flex gap-1.5 text-[11px] leading-4 text-amber-700 dark:text-amber-400",children:[/* @__PURE__ */t(ha,{className:"mt-px h-3 w-3 shrink-0","aria-hidden":!0}),/* @__PURE__ */n("span",{children:["No change on ",_,". ",Za(b.unavailable,"variable")]})]});}}return/* @__PURE__ */n("div",{className:"shrink-0 border-t border-border/60 bg-muted/30 px-4 py-2.5","data-testid":"variable-preview",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-3",children:[/* @__PURE__ */t("span",{className:Rt,children:i?"Preview on":"Preview"}),i?/* @__PURE__ */n(we,{value:l??"",onValueChange:u,disabled:!!r,children:[/* @__PURE__ */t(ke,{size:"xs",className:"h-6 w-auto gap-1.5 px-2 text-[12px]","aria-label":"Preview place",children:/* @__PURE__ */t(Se,{})}),/* @__PURE__ */t(De,{children:o.map(b=>/* @__PURE__ */t(fe,{value:b.id,children:b.title||b.id},b.id))})]}):null,/* @__PURE__ */t("div",{className:"min-w-0 flex-1 truncate text-right text-[13px]",children:D})]}),P?/* @__PURE__ */t("p",{className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:P}):null,k]});}function zs(e,a,s){const r=c=>/* @__PURE__ */t("span",{className:"font-medium text-foreground",children:c}),d=c=>/* @__PURE__ */n("span",{className:"inline-flex items-center gap-1.5 text-[12px] text-amber-700 dark:text-amber-400",children:[/* @__PURE__ */t(ha,{className:"h-3.5 w-3.5","aria-hidden":!0})," ",c]}),o=c=>c===void 0?"":c==="beyondCap"?`more than ${nt} match`:`${c} ${c===1?"match":"matches"}`,i="filterReach"in a?a.filterReach:[],h=i.filter(c=>c.status==="applied").length,u=i.length-h,l=i.length?` · ${h} ${h===1?"filter":"filters"} applied${u?`, ${u} skipped`:""}`:"";switch(a.status){case"answered":{const c=kr(e,Object.keys(a.parts))[0],p=c?a.parts[c]:void 0,m=p&&jt(p,e.presentation,s)||"(empty)",g=`${o(a.matched)}${l}`.replace(/^ · /,""),f=mr(e,a,s);return f&&typeof f=="object"&&"unavailable"in f?{body:r(m),meta:g,unavailable:f.unavailable}:f==="noPrevious"?{body:r(m),meta:`${g} · Nothing in the period before to compare with.`.replace(/^ · /,"")}:f?{body:/* @__PURE__ */n(R,{children:[r(f.value),/* @__PURE__ */n("span",{className:"text-muted-foreground",children:[" · was ",f.previous," · "]}),r(f.change)]}),meta:g}:{body:r(m),meta:g};}case"listed":{const c=a.items.map(m=>jt(m,e.presentation,s)),p=a.more==="beyondCap"?" and more":a.more?` and ${a.more} more`:"";return{body:r(`${c.join(e.get.kind==="list"?e.get.separator??", ":", ")}${p}`),meta:`${o(a.matched)}${l}`};}case"none":return a.why==="moreThanOne"?{body:d(`More than one matches${a.matched!==void 0?` (${a.matched==="beyondCap"?`${nt}+`:a.matched})`:""}. Readers see nothing.`),meta:"Keep a selection on a filter, add a condition, or choose First or List."}:{body:/* @__PURE__ */t("span",{className:"text-muted-foreground",children:"No rows match."}),meta:l.slice(3)};case"held":return{body:/* @__PURE__ */n("span",{className:"text-muted-foreground",children:["Waiting for ",a.missingRequired.join(", "),"."]}),meta:"A required filter has no value here."};case"broken":return{body:d("The query no longer compiles against its mapping."),meta:""};case"failed":return{body:d("The query failed."),meta:a.message};default:return{body:null,meta:""};}}function $i(){const e=C(i=>i.variableEditor),a=C(i=>i.dashboard.variables),s=C(i=>i.actions.closeVariableEditor),r=Ze(!1),d=(e==null?void 0:e.kind)==="edit"?a==null?void 0:a.find(i=>i.id===e.variableId):void 0;return!(e&&(e.kind==="new"||d))?null:/* @__PURE__ */n(Te,{modal:!1,open:!0,onOpenChange:i=>!i&&s(),children:[/* @__PURE__ */t("div",{className:"pointer-events-none fixed inset-0 z-40 bg-zinc-950/40 backdrop-blur-sm"}),/* @__PURE__ */n(Le,{className:"w-auto max-w-none gap-0 overflow-hidden p-0 [&>button:last-child]:hidden",onInteractOutside:i=>i.preventDefault(),onEscapeKeyDown:i=>{r.current?i.preventDefault():s();},children:[/* @__PURE__ */t(Ve,{className:"sr-only",children:"Variable from data"}),/* @__PURE__ */t(st,{className:"sr-only",children:"Define a value from your data to show in text."}),/* @__PURE__ */t(Ts,{variable:d,onClose:s,onHoldEscape:i=>{r.current=i;}},(e==null?void 0:e.kind)==="edit"?e.variableId:"new")]})]});}function Rs({disabled:e,briefingCount:a,className:s,onClick:r}){const d=typeof a=="number"&&a>0;return/* @__PURE__ */n(I,{type:"button",size:"xs",variant:"outline",disabled:e,className:G("gap-1.5",s),onClick:r,"aria-label":"Reports & briefings",children:[/* @__PURE__ */t(Rr,{className:"h-3.5 w-3.5"}),"Reports & briefings",d?/* @__PURE__ */t("span",{className:"ml-0.5 rounded-control bg-muted px-1 text-[10px] tabular-nums text-foreground/70",children:a}):null]});}const Ms="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",Da="inline-flex h-7 items-center gap-1.5 rounded-control px-2 text-[12px] text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-50",Xe="inline-flex h-7 items-center gap-1.5 rounded-control bg-primary px-3 text-[12px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50";function Us(e){return e==="dashboard"?"This dashboard":"Project";}function $s(e){if(!e)return"Never";const a=new Date(e);if(Number.isNaN(a.getTime()))return"Unknown";const s=Date.now()-a.getTime(),r=Math.round(s/6e4);if(r<1)return"now";if(r<60)return`${r}m ago`;const d=Math.round(r/60);if(d<24)return`${d}h ago`;const o=Math.round(d/24);if(o<7)return`${o}d ago`;const i=Math.round(o/7);return i<5?`${i}w ago`:`${Math.round(o/30)}mo ago`;}function js(e){return e.scheduleExpr?Br(e.scheduleExpr,e.timezone||"UTC")??"Invalid schedule":"On demand";}function qs(e){if(e.lastRunStatus){const a=e.lastRunStatus.toString().toUpperCase();return a==="SUCCESS"?"Last run completed.":a==="FAILED"?"Last run failed.":`Last run ${e.lastRunStatus.toString().toLowerCase()}`;}return null;}function Aa(e){return e.hasActiveRun?"Running":e.lastRunStatus?`Last run ${e.lastRunStatus.toString().toLowerCase()}`:"Idle";}function Ws(e){return e.source.type==="dashboard"?"This dashboard":"Project";}function Ks({activeView:e,onChange:a}){return/* @__PURE__ */t("div",{className:"flex shrink-0 items-center gap-1 rounded-control bg-muted p-0.5",role:"tablist","aria-label":"Briefing source view",children:["dashboard","project"].map(s=>{const r=e===s;return/* @__PURE__ */t("button",{type:"button",role:"tab","aria-selected":r,onClick:()=>a(s),className:G("h-6 rounded-[3px] px-2 text-[11px] transition-colors",r?"bg-background font-medium text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:Us(s)},s);})});}function Qs({briefings:e,dashboardLabel:a,sourceView:s,error:r,loading:d,onSourceViewChange:o,onClose:i,onEdit:h,onNew:u,canCreate:l,canCreateScheduledReport:c,analyticalBriefingsEnabled:p,onRunNow:m,onTogglePause:g,onDelete:f,selectingId:N,busyId:w,manageBriefingsHref:T,contentKind:L,hideHeader:B=!1}){const D=e.length,P=e.filter(A=>A.status==="ACTIVE").length,k=L==="reports"?D===1?"report":"reports":L==="briefings"?D===1?"briefing":"briefings":D===1?"item":"items",v=e.find(A=>A.hasActiveRun)??null,b=L??"reports & briefings",_=s==="dashboard"?a:`Project ${b}`;return/* @__PURE__ */n("section",{"aria-label":`Dashboard ${b.replace("&","and")}`,className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:[B?null:/* @__PURE__ */n("header",{className:"flex items-start justify-between gap-3 border-b border-border px-4 py-3",children:[/* @__PURE__ */n("div",{className:"min-w-0",children:[/* @__PURE__ */t("div",{className:Ms,children:b}),/* @__PURE__ */t("h2",{className:"mt-0.5 truncate text-[14px] font-semibold leading-5",children:_})]}),/* @__PURE__ */t("button",{type:"button",onClick:i,className:"rounded-control p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":`Close ${b.replace("&","and")} panel`,children:/* @__PURE__ */t(Ue,{className:"h-3.5 w-3.5"})})]}),/* @__PURE__ */n("div",{className:"flex items-center justify-between gap-3 border-b border-border px-4 py-2",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-3",children:[/* @__PURE__ */t(Ks,{activeView:s,onChange:o}),/* @__PURE__ */t("div",{className:"flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:d&&D===0?/* @__PURE__ */n("span",{children:["Loading ",b,"…"]}):D===0?/* @__PURE__ */n("span",{children:["No ",b," yet"]}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */n("span",{className:"font-medium text-foreground/80",children:[D," ",k]}),/* @__PURE__ */t("span",{className:"text-border",children:"·"}),/* @__PURE__ */n("span",{children:[P," active"]})]})})]}),/* @__PURE__ */n("div",{className:"flex items-center gap-1.5",children:[d?/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}):null,D>0&&l?p&&c?/* @__PURE__ */n($e,{children:[/* @__PURE__ */t(je,{asChild:!0,children:/* @__PURE__ */n("button",{className:Xe,children:[/* @__PURE__ */t(xe,{className:"h-3 w-3"})," New"]})}),/* @__PURE__ */n(qe,{align:"end",children:[/* @__PURE__ */t(ee,{onClick:()=>u("scheduled_report"),children:"Schedule a report"}),/* @__PURE__ */t(ee,{onClick:()=>u("analytical_briefing"),children:"Create analytical briefing"})]})]}):c?/* @__PURE__ */n("button",{onClick:()=>u("scheduled_report"),className:Xe,children:[/* @__PURE__ */t(xe,{className:"h-3 w-3"})," Schedule report"]}):p?/* @__PURE__ */n("button",{onClick:()=>u("analytical_briefing"),className:Xe,children:[/* @__PURE__ */t(xe,{className:"h-3 w-3"})," New briefing"]}):null:null]})]}),v?/* @__PURE__ */n("div",{className:"flex items-center gap-2 border-b border-border bg-muted/60 px-4 py-2 text-[12px]",children:[/* @__PURE__ */t(se,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}),/* @__PURE__ */t("span",{className:"font-medium text-foreground",children:v.name}),/* @__PURE__ */t("span",{className:"text-border",children:"·"}),/* @__PURE__ */t("span",{className:"truncate text-muted-foreground",children:Aa(v)})]}):null,/* @__PURE__ */n("div",{className:"flex-1 overflow-y-auto",children:[r?/* @__PURE__ */t("div",{className:"m-4 rounded-card border border-destructive/30 bg-destructive/10 px-3 py-2 text-[12px] text-destructive",children:r}):null,!d&&e.length===0&&!r?/* @__PURE__ */t(Gs,{onNew:u,canCreate:l,canCreateScheduledReport:c,analyticalBriefingsEnabled:p,contentKind:L}):null,e.map(A=>/* @__PURE__ */t(Ys,{briefing:A,isOpening:N===A.id,isBusy:w===A.id,onOpen:()=>h(A.id),onRunNow:()=>m(A),onTogglePause:()=>g(A),onDelete:()=>f(A)},A.id))]}),T?/* @__PURE__ */t("div",{className:"border-t border-border px-4 py-2.5",children:/* @__PURE__ */n("a",{href:T,className:G(Da,"h-6 px-1 text-[11px]"),children:["Manage all reports & briefings",/* @__PURE__ */t(Or,{className:"h-3 w-3"})]})}):null]});}function Gs({onNew:e,canCreate:a,canCreateScheduledReport:s,analyticalBriefingsEnabled:r,contentKind:d}){const o=d==="reports"?{title:"No reports yet",description:"Schedule an emailed dashboard or visual report to see it here."}:d==="briefings"?{title:"No briefings yet",description:"Create an analytical briefing to monitor this dashboard and brief your team."}:null;return/* @__PURE__ */n("div",{className:"flex h-full flex-col items-center justify-center px-8 py-12 text-center",children:[/* @__PURE__ */t(Hs,{className:"mb-5 h-[88px] w-[112px] text-border"}),/* @__PURE__ */t("div",{className:"text-[13px] font-medium text-foreground",children:(o==null?void 0:o.title)??"Have an analyst brief your team"}),/* @__PURE__ */t("p",{className:"mt-1.5 max-w-[320px] text-[12px] leading-5 text-muted-foreground",children:(o==null?void 0:o.description)??"Describe what to watch. An analyst digs into this dashboard and the data behind it, then briefs your team on the cadence you choose."}),a?/* @__PURE__ */n("div",{className:"mt-4 flex flex-wrap justify-center gap-2",children:[s?/* @__PURE__ */n("button",{onClick:()=>e("scheduled_report"),className:Xe,children:[/* @__PURE__ */t(xe,{className:"h-3 w-3"})," Schedule a report"]}):null,r?/* @__PURE__ */t("button",{onClick:()=>e("analytical_briefing"),className:Da,children:"Create analytical briefing"}):null]}):null]});}function Hs({className:e}){return/* @__PURE__ */n("svg",{viewBox:"0 0 112 88",fill:"none",xmlns:"http://www.w3.org/2000/svg",role:"presentation","aria-hidden":"true",className:e,children:[/* @__PURE__ */t("rect",{x:"22",y:"6",width:"60",height:"72",rx:"3",stroke:"currentColor",strokeWidth:"1.25"}),/* @__PURE__ */t("line",{x1:"30",y1:"16",x2:"64",y2:"16",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),/* @__PURE__ */t("line",{x1:"30",y1:"21",x2:"52",y2:"21",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round",opacity:"0.5"}),/* @__PURE__ */t("circle",{cx:"31",cy:"32",r:"1",fill:"currentColor",opacity:"0.6"}),/* @__PURE__ */t("line",{x1:"35",y1:"32",x2:"72",y2:"32",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),/* @__PURE__ */t("circle",{cx:"31",cy:"38",r:"1",fill:"currentColor",opacity:"0.6"}),/* @__PURE__ */t("line",{x1:"35",y1:"38",x2:"68",y2:"38",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),/* @__PURE__ */t("circle",{cx:"31",cy:"44",r:"1",fill:"currentColor",opacity:"0.6"}),/* @__PURE__ */t("line",{x1:"35",y1:"44",x2:"74",y2:"44",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),/* @__PURE__ */t("rect",{x:"30",y:"64",width:"5",height:"8",rx:"0.5",fill:"currentColor",opacity:"0.55"}),/* @__PURE__ */t("rect",{x:"38",y:"60",width:"5",height:"12",rx:"0.5",fill:"currentColor",opacity:"0.7"}),/* @__PURE__ */t("rect",{x:"46",y:"56",width:"5",height:"16",rx:"0.5",fill:"currentColor",opacity:"0.85"}),/* @__PURE__ */t("rect",{x:"54",y:"62",width:"5",height:"10",rx:"0.5",fill:"currentColor",opacity:"0.6"}),/* @__PURE__ */t("rect",{x:"62",y:"58",width:"5",height:"14",rx:"0.5",fill:"currentColor",opacity:"0.75"}),/* @__PURE__ */t("circle",{cx:"86",cy:"62",r:"10",className:"fill-background",stroke:"currentColor",strokeWidth:"1.25"}),/* @__PURE__ */t("line",{x1:"93.5",y1:"69.5",x2:"100",y2:"76",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]});}function Ys({briefing:e,isOpening:a,isBusy:s,onOpen:r,onRunNow:d,onTogglePause:o,onDelete:i}){const h=e.status==="PAUSED",u=e.hasActiveRun,l=qs(e),c=$s(e.lastRunAt),p=e.lastRunStatus,m=pe(e),g=p==="SUCCESS"?Ge.success.dot:p==="FAILED"?Ge.danger.dot:p?Ge.warning.dot:Ge.neutral.dot;return/* @__PURE__ */n("div",{className:G("group relative border-b border-border/60 px-4 py-3 transition-colors hover:bg-muted/60",h&&"opacity-70"),children:[/* @__PURE__ */n("div",{role:"button",tabIndex:0,onClick:r,onKeyDown:f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),r());},className:"cursor-pointer pr-8",children:[/* @__PURE__ */n("div",{className:"flex min-w-0 items-center gap-2",children:[/* @__PURE__ */t("span",{className:"truncate text-[13px] font-medium text-foreground",children:e.name}),h?/* @__PURE__ */t("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:"· Paused"}):null]}),/* @__PURE__ */n("div",{className:"mt-1 flex flex-wrap items-center gap-x-1.5 text-[11px] text-muted-foreground",children:[/* @__PURE__ */t("span",{children:m.typeLabel}),/* @__PURE__ */t("span",{className:"text-border",children:"·"}),/* @__PURE__ */t("span",{children:Ws(e)}),/* @__PURE__ */t("span",{className:"text-border",children:"·"}),/* @__PURE__ */t(Vn,{className:"h-3 w-3"}),/* @__PURE__ */t("span",{className:"truncate",children:js(e)}),e.lastRunAt?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t("span",{className:"text-border",children:"·"}),/* @__PURE__ */n("span",{children:["Last run ",c]})]}):null]}),l||u?/* @__PURE__ */n("div",{className:"mt-1.5 flex items-center gap-1.5 text-[12px] leading-[1.5] text-foreground/80",children:[u?/* @__PURE__ */t(se,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground/70"}):/* @__PURE__ */t("span",{className:G("inline-block h-1.5 w-1.5 shrink-0 rounded-full",g)}),/* @__PURE__ */t("span",{className:"truncate",children:u?Aa(e):l})]}):null]}),/* @__PURE__ */t("div",{className:"absolute right-3 top-3",children:s?/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground/70"}):a?/* @__PURE__ */t(se,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground/70"}):/* @__PURE__ */n($e,{children:[/* @__PURE__ */t(je,{asChild:!0,children:/* @__PURE__ */t("button",{type:"button",onClick:f=>f.stopPropagation(),className:"inline-flex h-6 w-6 items-center justify-center rounded-control text-muted-foreground/70 opacity-60 hover:bg-muted hover:text-foreground/80 focus-visible:opacity-100 group-hover:opacity-100","aria-label":`${m.noun==="report"?"Report":"Briefing"} actions`,children:/* @__PURE__ */t(ra,{className:"h-3.5 w-3.5"})})}),/* @__PURE__ */n(qe,{align:"end",className:"w-44",children:[/* @__PURE__ */n(ee,{onClick:r,children:[/* @__PURE__ */t(Bt,{className:"h-3.5 w-3.5"}),"Edit ",m.noun]}),/* @__PURE__ */n(ee,{onClick:f=>{f.preventDefault(),d();},children:[/* @__PURE__ */t(Bn,{className:"h-3.5 w-3.5"}),"Run now"]}),e.scheduleExpr?/* @__PURE__ */t(ee,{onClick:f=>{f.preventDefault(),o();},children:h?/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(_n,{className:"h-3.5 w-3.5"}),"Resume"]}):/* @__PURE__ */n(R,{children:[/* @__PURE__ */t(On,{className:"h-3.5 w-3.5"}),"Pause"]})}):null,/* @__PURE__ */t(et,{}),/* @__PURE__ */n(ee,{onClick:f=>{f.preventDefault(),i();},className:"text-destructive focus:bg-destructive/10 focus:text-destructive",children:[/* @__PURE__ */t(Je,{className:"h-3.5 w-3.5"}),"Delete ",m.noun]})]})]})})]});}function Xs(e){return(e==null?void 0:e.trim())||"This dashboard";}function Zs(e){return e==="This dashboard"?"Watch this dashboard":`Watch ${e}`;}function Js(e,a,s){return a!=="dashboard"?e:e.filter(r=>r.source.type==="dashboard"&&r.source.dashboardId===s);}async function ei(e){const s=[];let r=1,d=0,o=Number.POSITIVE_INFINITY;for(;d<o;){const i=await e.apiClient.listBriefings(e.apiServiceUrl,e.token,{scope:"organization",page:r,pageSize:100});if(s.push(...i.briefings),d+=i.briefings.length,o=i.total,i.briefings.length===0||d>=o)break;r+=1;}return s;}const ti={listBriefings:Wn,getBriefing:qn,pauseBriefing:jn,resumeBriefing:$n,deleteBriefing:Un,runBriefingNow:Mn};function ji(e){return/* @__PURE__ */t(Pn,{authToken:e.token?{accessToken:e.token}:void 0,children:/* @__PURE__ */t(zn,{children:/* @__PURE__ */t(ai,{...e})})});}function ai({dashboardId:e,dashboardTitle:a,apiServiceUrl:s,token:r,disabled:d,className:o,manageBriefingsHref:i,open:h,onOpenChange:u,hideTrigger:l=!1,workflowIntent:c,openRun:p,client:m}){const{authToken:g,tokenProps:f}=it(),N=Rn(),w=!c||N.canCreate&&(c==="scheduled_report"||N.analyticalBriefingsEnabled),[T,L]=F(!1),B=h??T,D=S=>{h===void 0&&L(S),u==null||u(S);},[P,k]=F(c?"author":"list"),[v,b]=F(c??"analytical_briefing"),[_,A]=F("dashboard"),[H,V]=F([]),[M,X]=F(null),Y=c&&!w&&!M?"list":P,[he,te]=F(!1),[me,E]=F(null),[ne,Q]=F(null),[z,J]=F(null),[de,ce]=F(null),ve=Ze(null),x=Ze(B);Ye(()=>{const S=B&&!x.current;x.current=B,!(!S||!c)&&(X(null),A("dashboard"),b(c),k("author"),ce(null));},[B,c]);const O=St(),$=s??(f==null?void 0:f.apiServiceUrl),W=r??(g==null?void 0:g.accessToken),re=K(()=>({...ti,...m}),[m]),[_e,lt]=F(null);Ye(()=>{if(!p||!$||!W)return;let S=!0;return re.getBriefing($,W,p.briefingId).then(({briefing:q})=>{S&&(X(q),lt(p),k("author"));},q=>{S&&U.error(q instanceof Error?q.message:"Could not open the run.");}),()=>{S=!1;};},[p,$,W,re]);const Fe=Xs(a),We=K(()=>{const S=Js(H,_,e);if(!c)return S;const q=c==="scheduled_report"?"report":"briefing";return S.filter(Ke=>pe(Ke).noun===q);},[e,H,_,c]),dt=K(()=>_==="dashboard"?{source:{type:"dashboard",dashboardId:e},label:Fe,detail:Zs(Fe)}:{source:{type:"project"},label:"This project",detail:"Use any data in this project."},[e,Fe,_]),Oe=!!($&&W),Pe=_r({canCreate:N.canCreate,analyticalBriefingsEnabled:N.analyticalBriefingsEnabled,scheduledReportAvailable:_==="dashboard"}),ie=oe(async()=>{if(!(!$||!W)){te(!0),ce(null);try{V(await ei({apiClient:re,apiServiceUrl:$,token:W}));}catch(S){ce(S instanceof Error?S.message:"Could not load briefings.");}finally{te(!1);}}},[re,$,W]);Ye(()=>{!B||Y!=="list"||!Oe||ie();},[Oe,Y,ie,B]);const ze=()=>{X(null),A("dashboard"),k("list"),D(!0);},y=S=>{X(null),b(S),k("author");},j=async S=>{if(!(!$||!W)){E(S),ce(null);try{const q=await re.getBriefing($,W,S);X(q.briefing),k("author");}catch(q){ce(q instanceof Error?q.message:"Could not open briefing.");}finally{E(null);}}},Z=async S=>{if(!(!$||!W)){Q(S.id);try{const q=await re.runBriefingNow($,W,S.id,{requestId:ni()});O.track({kind:"briefing",id:q.run.id,title:S.name,briefingId:S.id}),ie();}catch(q){U.error(q instanceof Error?q.message:"Could not start the run.");}finally{Q(null);}}},ue=async S=>{if(!$||!W)return;const{noun:q}=pe(S),Ke=q==="report"?"Report":"Briefing";Q(S.id);try{const Qe=S.status==="PAUSED"?await re.resumeBriefing($,W,S.id):await re.pauseBriefing($,W,S.id);U.success(Qe.briefing.status==="PAUSED"?`${Ke} paused`:`${Ke} resumed`),ie();}catch(Qe){U.error(Qe instanceof Error?Qe.message:`Could not update the ${q} status.`);}finally{Q(null);}},ye=async()=>{if(!z||!$||!W)return;const S=z;Q(S.id);try{await re.deleteBriefing($,W,S.id);const{noun:q}=pe(S);U.success(`${q==="report"?"Report":"Briefing"} deleted`),J(null),ie();}catch(q){U.error(q instanceof Error?q.message:"Could not delete the briefing.");}finally{Q(null);}},Fa=We.length;return N.surfaceVisible?/* @__PURE__ */n(Ja,{open:B,onOpenChange:D,children:[l?null:/* @__PURE__ */t(Rs,{disabled:d||!Oe,briefingCount:Fa,className:o,onClick:ze}),/* @__PURE__ */n(en,{ref:ve,side:"right",hideClose:!0,className:"flex h-full w-full flex-col overflow-hidden p-0 outline-none sm:max-w-[560px]",onOpenAutoFocus:S=>{var q;S.preventDefault(),(q=ve.current)==null||q.focus({preventScroll:!0});},children:[/* @__PURE__ */n(tn,{className:"sr-only",children:[/* @__PURE__ */t(an,{children:"Reports & briefings"}),/* @__PURE__ */t(nn,{children:"Manage reports and briefings for this dashboard."})]}),c?/* @__PURE__ */n("div",{className:"flex shrink-0 items-start justify-between gap-3 border-b border-border pl-4 pr-3 pt-2",children:[/* @__PURE__ */n("div",{className:"flex items-center gap-5",role:"tablist","aria-label":c==="scheduled_report"?"Email report workflow":"Analytical briefing workflow",children:[/* @__PURE__ */t("button",{type:"button",role:"tab","aria-selected":Y==="author",disabled:!w,className:G("-mb-px border-b-2 px-0.5 pb-2 text-[12px] transition-colors",Y==="author"?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground",!w&&"cursor-not-allowed opacity-50"),onClick:()=>{w&&(X(null),b(c),A("dashboard"),k("author"));},children:M?`Edit ${pe(M).noun}`:c==="scheduled_report"?"Schedule report":"Create briefing"}),/* @__PURE__ */t("button",{type:"button",role:"tab","aria-selected":Y==="list",className:G("-mb-px border-b-2 px-0.5 pb-2 text-[12px] transition-colors",Y==="list"?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),onClick:()=>k("list"),children:c==="scheduled_report"?"Manage reports":"Manage briefings"})]}),/* @__PURE__ */t("button",{type:"button",onClick:()=>D(!1),className:"rounded-control p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":c==="scheduled_report"?"Close email report workflow":"Close analytical briefing workflow",children:/* @__PURE__ */t(Ue,{className:"h-3.5 w-3.5"})})]}):null,Y==="list"?/* @__PURE__ */t(Qs,{briefings:We,dashboardLabel:Fe,sourceView:_,error:de,loading:he,onSourceViewChange:A,onClose:()=>D(!1),onEdit:S=>{j(S);},onNew:y,canCreate:!c&&Pe.length>0,canCreateScheduledReport:Pe.includes("scheduled_report"),analyticalBriefingsEnabled:Pe.includes("analytical_briefing"),onRunNow:S=>{Z(S);},onTogglePause:S=>{ue(S);},onDelete:S=>J(S),selectingId:me,busyId:ne,manageBriefingsHref:i,contentKind:c==="scheduled_report"?"reports":c==="analytical_briefing"?"briefings":void 0,hideHeader:!!c}):/* @__PURE__ */t(Kn,{apiServiceUrl:$,token:W,briefing:M,initialRunId:_e&&(M==null?void 0:M.id)===_e.briefingId?_e.runId:void 0,intent:v,sourceContext:M?void 0:dt,title:M?`Edit ${pe(M).noun}`:v==="scheduled_report"?"Schedule report":"Create analytical briefing",hideHeader:!!c,className:"h-full min-h-0 max-w-none border-0 shadow-none",onBack:c?void 0:()=>k("list"),onCancel:()=>D(!1),onDeleted:()=>{const S=M?pe(M).noun:"briefing";U.success(`${S==="report"?"Report":"Briefing"} deleted`),X(null),k("list"),ie();},onRunStarted:()=>{},onSaved:S=>{X(S),ie();},onMinimizeRun:()=>{D(!1);}})]}),/* @__PURE__ */t(Dt,{open:!!z,onOpenChange:S=>{S||J(null);},children:/* @__PURE__ */n(At,{children:[/* @__PURE__ */n(Ft,{children:[/* @__PURE__ */n(Et,{children:["Delete"," ",z?pe(z).noun:"briefing","?"]}),/* @__PURE__ */n(It,{children:["This permanently deletes ",/* @__PURE__ */t("strong",{children:z==null?void 0:z.name}),". Recipients will stop receiving it."]})]}),/* @__PURE__ */n(Tt,{children:[/* @__PURE__ */t(Lt,{children:"Cancel"}),/* @__PURE__ */n(fa,{className:"bg-destructive/90 hover:bg-destructive",onClick:ye,children:["Delete"," ",z?pe(z).noun:"briefing"]})]})]})})]}):null;}function ni(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`briefing-run-now-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;}export{Ti as A,Bi as D,Vi as S,Oi as U,Fi as V,Rs as W,Ii as a,Li as b,_i as c,zi as d,as as e,rs as f,ds as g,Ri as h,Pi as i,Ui as j,Mi as k,$i as l,ji as m,Ca as n,Ei as u};
|