react-semaphor 0.1.311 → 0.1.314

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/brand-studio/index.cjs +1 -1
  2. package/dist/brand-studio/index.js +4 -4
  3. package/dist/chunks/{braces-CSECDaJQ.js → braces-CWi8x9ww.js} +1 -1
  4. package/dist/chunks/{braces-DwaAt32i.js → braces-NfG5hX2c.js} +1 -1
  5. package/dist/chunks/calendar-preferences-dialog-BzpQ5u4h.js +1 -0
  6. package/dist/chunks/calendar-preferences-dialog-D70CuT-1.js +456 -0
  7. package/dist/chunks/{chevrons-up-down-DJhB8JNW.js → chevrons-up-down-B2viXO2I.js} +1 -1
  8. package/dist/chunks/{chevrons-up-down-3vBEM7eI.js → chevrons-up-down-DiWloubI.js} +1 -1
  9. package/dist/chunks/dashboard-controls-BS_aZcxs.js +57 -0
  10. package/dist/chunks/dashboard-controls-DbKtbw1V.js +2021 -0
  11. package/dist/chunks/dashboard-filter-controls-launcher-C8Wm2Smj.js +1540 -0
  12. package/dist/chunks/dashboard-filter-controls-launcher-CMXpudFJ.js +11 -0
  13. package/dist/chunks/{dashboard-json-GL_IXTCk.js → dashboard-json-CJCAen1R.js} +2 -2
  14. package/dist/chunks/{dashboard-json-B_rQbUUz.js → dashboard-json-v2C6Tmqf.js} +1 -1
  15. package/dist/chunks/{edit-dashboard-visual-nGSsSTYx.js → edit-dashboard-visual-DljWvnMy.js} +4758 -4694
  16. package/dist/chunks/edit-dashboard-visual-lRn3FeaP.js +183 -0
  17. package/dist/chunks/{index-9v7DehZd.js → index-P5hPTTzm.js} +33681 -33108
  18. package/dist/chunks/{index-CGCrm-dj.js → index-XYIIY48z.js} +228 -228
  19. package/dist/chunks/{palette-CI2J34i6.js → palette-CIuwlEiG.js} +1 -1
  20. package/dist/chunks/{palette-C5o9bLo6.js → palette-CJTdBzJB.js} +1 -1
  21. package/dist/chunks/{resource-management-panel-CNmVHnCz.js → resource-management-panel-CAxXzMdi.js} +1 -1
  22. package/dist/chunks/{resource-management-panel-DTg9_DI9.js → resource-management-panel-Dk0DzgVm.js} +18 -18
  23. package/dist/chunks/{save-CMv91_Hz.js → save-B8x5Vi0W.js} +1 -1
  24. package/dist/chunks/{save-Cpz6BWx9.js → save-_ALpoMy6.js} +1 -1
  25. package/dist/chunks/{switch-Dhoqe3OE.js → switch-B6fh8nb-.js} +139 -138
  26. package/dist/chunks/{switch-otrSiyjH.js → switch-DPaKnsb8.js} +14 -14
  27. package/dist/chunks/{use-create-flow-overlay-state-C8WGfC8T.js → use-create-flow-overlay-state-Cqf7GaFm.js} +511 -483
  28. package/dist/chunks/use-create-flow-overlay-state-DMZTflFt.js +16 -0
  29. package/dist/chunks/{use-visual-utils-RkPa2gqQ.js → use-visual-utils-CPMQLBYR.js} +12 -12
  30. package/dist/chunks/{use-visual-utils-BeJ73yvV.js → use-visual-utils-CQQ3jvDn.js} +1 -1
  31. package/dist/dashboard/index.cjs +1 -1
  32. package/dist/dashboard/index.js +1 -1
  33. package/dist/index.cjs +1 -1
  34. package/dist/index.js +118 -117
  35. package/dist/style.css +1 -1
  36. package/dist/surfboard/index.cjs +1 -1
  37. package/dist/surfboard/index.js +7 -8
  38. package/dist/types/dashboard.d.ts +1 -1
  39. package/dist/types/main.d.ts +76 -34
  40. package/dist/types/shared.d.ts +1 -1
  41. package/dist/types/surfboard.d.ts +1 -11
  42. package/dist/types/types.d.ts +1 -1
  43. package/package.json +1 -1
  44. package/dist/chunks/dashboard-controls-CeKjYa7s.js +0 -2274
  45. package/dist/chunks/dashboard-controls-Ds8Hmo3Q.js +0 -57
  46. package/dist/chunks/dashboard-filter-controls-button-CWL2jJcu.js +0 -11
  47. package/dist/chunks/dashboard-filter-controls-button-Tk5lhwVV.js +0 -1116
  48. package/dist/chunks/dashboard-summary-settings-dialog-CcszMc1A.js +0 -545
  49. package/dist/chunks/dashboard-summary-settings-dialog-DgqFlYl9.js +0 -1
  50. package/dist/chunks/edit-dashboard-visual-Bu2rxJjm.js +0 -183
  51. package/dist/chunks/use-create-flow-overlay-state-DiH6M1Cd.js +0 -16
@@ -0,0 +1,16 @@
1
+ "use strict";const s=require("./switch-DPaKnsb8.js"),v=require("react"),p=require("./index-XYIIY48z.js"),e=require("react/jsx-runtime"),re=require("./use-visual-utils-CQQ3jvDn.js"),he=require("./save-B8x5Vi0W.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 Ne=s.createLucideIcon("CircleX",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/**
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 ge=s.createLucideIcon("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"}]]);/**
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 be=s.createLucideIcon("Link2",[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]);function De(){const l=s.useEditorStore(h=>h.card.dataSource),{setSelectedConnectionId:a,setSelectedDatabaseName:i,setSelectedSchemaName:d,setSelectedTableName:x,setSelectedDatamodelId:u}=s.useEditorActions();v.useEffect(()=>{var D;if(!l)return;const{tableName:h,schemaName:y,databaseName:g,connectionId:j}=p.extractTableMetadata(l),b=(D=l.selectedEntities)==null?void 0:D[0],C=(b==null?void 0:b.type)==="model"&&"id"in b?b.id:"";a(j||""),i(g||""),d(y||""),x(h||""),u(C)},[l,a,i,d,x,u])}function ae(){var g,j;const l=s.useEditorStore(b=>b.card),a=s.useEditorStore(b=>b.frame),i=v.useMemo(()=>p.findCustomVisualConfigCard(a,l),[a,l]),{manifest:d}=p.useCustomVisual(((g=i==null?void 0:i.customCardPreferences)==null?void 0:g.url)||""),x=v.useMemo(()=>{var b;return(b=d==null?void 0:d.visuals)==null?void 0:b.find(m=>{var C;return m.name===((C=i==null?void 0:i.customCardPreferences)==null?void 0:C.componentName)})},[d,(j=i==null?void 0:i.customCardPreferences)==null?void 0:j.componentName]),u=p.resolveMultiInputType(i,x),h=v.useMemo(()=>p.getCustomVisualInputCards({frame:a,configCard:i,isMultiInputVisual:u==="multiple"}),[a,i,u]),y=v.useMemo(()=>{const b=h.findIndex(m=>(m==null?void 0:m.id)===l.id);return b<0?-1:p.getSlotIndexForCard(l,b)},[h,l]);return v.useMemo(()=>!i||u!=="multiple"||y<0?l.type:p.getEffectiveCardTypeForSlot(l,y,x==null?void 0:x.slots)??l.type,[i,u,y,l,x==null?void 0:x.slots])}function Ee({type:l,isLinked:a,className:i,showLabel:d=!1,showLocal:x=!1}){const u=s.useDashboardStore(E=>E.selectedFrameId),h=p.useManagementStore(E=>E.selectedVisual),y=s.useEditorStore(E=>E.frame);let g;if(l)g=l;else if(a!==void 0)g=a?"linked":"library";else if(!!!(y!=null&&y.visualId||h!=null&&h.id)&&u)g="local";else if(h&&!u)g="library";else if(y!=null&&y.visualId&&u)g="linked";else if(h!=null&&h.id&&u)g="library";else return null;if(g==="local"&&!x)return null;const j={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"},b={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."},m={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"},C={local:"fill-slate-50 dark:fill-slate-900",linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},D={local:e.jsx("span",{className:"h-2 w-2 rounded-full bg-current/70"}),linked:e.jsx(be,{className:"h-3.5 w-3.5"}),library:e.jsx(ge,{className:"h-3.5 w-3.5"})},N={local:"Local",linked:"Linked",library:"Library"};return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:300,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(p.Badge,{variant:"outline",className:s.cn("cursor-help select-none transition-all",j[g],i),children:[D[g],d&&e.jsx("span",{className:"ml-1 text-xs font-medium leading-none",children:N[g]})]})}),e.jsxs(s.TooltipContent,{side:"bottom",className:s.cn("max-w-xs",m[g]),children:[e.jsx(s.TooltipArrow,{className:C[g]}),e.jsx("p",{children:b[g]})]})]})})}function we(l,a){return{...l,sql:"",python:"",config:void 0,customCfg:"",preferences:{},interactionConfig:void 0,linkedInteractionTargetOverrides:void 0,dynamicCardPreferences:void 0,customCardPreferences:a?l.customCardPreferences:void 0,visualizationMode:"builtin",type:a?l.type:"bar"}}function le(l){const a=s.getDynamicFrameSaveIssue(l);return a?(p.ue.error(a),!1):!0}function Ve({className:l,variant:a="outline"}){const i=s.useEditorStore(u=>u.onSave),{getUpdatedFrame:d}=re.useVisualUtils();function x(){const u=d();le(u)&&(i==null||i(u))}return e.jsxs(s.Button,{onClick:x,className:l,size:"xs",variant:a,children:[e.jsx(s.Check,{className:"h-3.5 w-3.5"}),"Accept"]})}function Te({className:l,variant:a="default"}){const i=p.useQueryClient(),[d,x]=v.useState(!1),u=s.useDashboardStore(C=>C.actions.setIsDashboardPanelOpen),{setIsVisualEditing:h}=s.useDashboardActions(),{getUpdatedFrame:y}=re.useVisualUtils(),g=p.useSelectedVisual(),j=s.useEditorStore(C=>C.frame),b=p.useUpdateVisualMutation(),m=()=>{const C=y();if(!le(C))return;const D=(j==null?void 0:j.visualId)||(g==null?void 0:g.id);if(!D){p.ue.error("No visual to save");return}x(!0),b.mutate({visualId:D,data:{frameObject:C}},{onSuccess:()=>{x(!1),u(!0),p.ue.success("Visual updated successfully"),i.invalidateQueries({queryKey:["resource-by-id","visual",D],exact:!0})},onError:()=>{x(!1),p.ue.error("Failed to update visual")}})};return e.jsx(s.Button,{onClick:m,className:l,size:"xs",variant:a,children:d?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving"]}):e.jsxs(e.Fragment,{children:[e.jsx(he.Save,{className:"h-3.5 w-3.5"}),"Save to Library"]})})}function Ie({className:l}){const a=p.useQueryClient(),[i,d]=v.useState(!1),x=p.useSelectedVisual(),u=s.useEditorStore(N=>N.frame),h=s.useDashboardStore(N=>N.selectedSheetId),y=s.useDashboardStore(N=>N.dashboard),{updateFrame:g,setIsVisualEditing:j}=s.useDashboardActions(),{getUpdatedFrame:b}=re.useVisualUtils(),m=p.useUpdateVisualMutation(),C=p.useResolveExistingFrameSemanticExecutionPayload(),D=async()=>{if(!h){p.ue.error("No sheet selected");return}const N=(u==null?void 0:u.visualId)||(x==null?void 0:x.id);if(!N){p.ue.error("No visual to update");return}d(!0);try{const E=b();if(!le(E)){d(!1);return}const F={...E,visualId:N},R=p.findDashboardFrameById(y,F.id),U=await C(F,{previousFrame:R});await m.mutateAsync({visualId:N,data:{frameObject:E}}),g(h,F,{semanticExecutionPayload:U}),a.invalidateQueries({queryKey:["visuals"]}),a.invalidateQueries({queryKey:["visual",N]}),p.ue.success("Saved to library and applied locally"),setTimeout(()=>{j(!1)},300)}catch(E){console.error("Failed to save and apply:",E),p.ue.error(E instanceof Error?E.message:"Failed to save and apply changes")}finally{d(!1)}};return e.jsx(s.Button,{onClick:D,className:l,size:"xs",variant:"default",disabled:i,children:i?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(he.Save,{className:"h-3.5 w-3.5"}),"Save & Apply"]})})}function Le({className:l}){const{setTempQueryData:a,setSqlGen:i}=s.useEditorActions(),d=p.useQueryClient(),x=s.useEditorStore(m=>m.tempQueryData),u=s.useEditorStore(m=>m.onClose),h=s.useEditorStore(m=>m.card),y=ae(),g=v.useMemo(()=>y!==h.type?{...h,type:y}:h,[h,y]),{queryKey:j}=p.useEditorCardQuery(g);function b(){if(x){const{queryKey:m,queryData:C}=x;m&&C&&d.setQueryData(m,C)}i({}),u==null||u()}return e.jsxs(s.Button,{onClick:b,className:l,size:"xs",variant:"outline",children:[e.jsx(s.X,{className:"h-3.5 w-3.5"}),"Close"]})}function Fe({label:l="Clear",variant:a="secondary",className:i}={}){const{setTempQueryData:d}=s.useEditorActions(),x=p.useQueryClient(),u=s.useEditorStore(q=>q.tempQueryData),h=s.useEditorStore(q=>q.card),y=ae(),g=v.useMemo(()=>y!==h.type?{...h,type:y}:h,[h,y]),{queryKey:j}=p.useEditorCardQuery(g),{setCardSql:b,setSqlGen:m,setCardPython:C,setCardCustomCfg:D,setCardPreferences:N,clearQueryConfig:E,setCardConfig:F,setCardType:R,setFrame:U,setCard:G,setActiveTabCardId:P}=s.useEditorActions();function W(){var Y,H,L,K;const q=x.getQueryData(j);u!=null&&u.queryData||d({queryKey:j,queryData:q}),x.setQueryData(j,null),x.removeQueries({queryKey:j,exact:!0}),b(""),m({}),E(),F(void 0),C(""),D(""),N({});const r=s.useEditorStore.getState().frame,T=s.useEditorStore.getState().card,I=p.findCustomVisualConfigCard(r,T),A=((Y=I==null?void 0:I.customCardPreferences)==null?void 0:Y.visualType)==="multiple"||!!((H=I==null?void 0:I.customCardPreferences)!=null&&H.dataInputCardIds)||(((L=I==null?void 0:I.customCardPreferences)==null?void 0:L.minInputs)||0)>1||(((K=I==null?void 0:I.customCardPreferences)==null?void 0:K.maxInputs)||0)>1,M=we(T,A);U({...r,cards:r.cards.map(O=>O.id===M.id?M:O)}),P(M.id),G(M),A||R("bar")}return e.jsxs(s.Button,{onClick:W,className:i,size:"xs",variant:a,children:[e.jsx(s.X,{className:"h-3.5 w-3.5"}),l]})}function ye(l){const{control:a,onChange:i}=l;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(s.Input,{size:"xs",value:a.label,placeholder:"Control label",onChange:d=>i(d.target.value)})]})}function _e(l){const{currentStep:a,labels:i}=l;return e.jsx("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:e.jsx("div",{className:"flex flex-wrap items-center gap-2 sm:gap-2.5",children:i.map((d,x)=>{const u=x+1,h=u===a,y=u<a;return e.jsxs(v.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:s.cn("flex h-5 w-5 items-center justify-center rounded-full border text-[10px] font-medium tabular-nums",h?"border-foreground bg-foreground text-background":y?"border-foreground/30 bg-foreground/10 text-foreground":"border-border/60 bg-background text-muted-foreground"),children:u}),e.jsx("span",{className:s.cn("text-[12px]",h?"font-medium text-foreground":"text-muted-foreground"),children:d})]}),x<i.length-1?e.jsx("span",{className:"h-px w-4 bg-border/60 sm:w-6","aria-hidden":"true"}):null]},d)})})})}function J(l){const{secondary:a,tertiary:i,primary:d}=l;return e.jsxs("div",{className:"sticky bottom-0 z-10 -mx-1 flex justify-end gap-2 border-t bg-background/95 px-1 pb-1 pt-3 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:[a,i,d]})}function Be(l){const{control:a,scope:i,detail:d}=l;return e.jsxs("div",{className:"flex items-start gap-2.5 rounded-control border border-border/60 bg-muted/30 px-3 py-2.5",children:[e.jsx(p.CircleCheck,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground"}),e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:a.label}),e.jsxs("div",{className:"text-[12px] text-muted-foreground",children:[s.getFriendlyTypeOption(a.type).label," ·"," ",s.getControlOptionPreview(a)," ·"," ",s.getPlacementLabel(i,a.placement)]}),d?e.jsx("div",{className:"text-[12px] text-muted-foreground",children:d}):null]})]})}function me(l){const{control:a,defaultValue:i,availableFieldChoices:d,availableMetricChoices:x,previewControlDefinitions:u,previewControlValues:h,onControlChange:y,onLabelChange:g,onDefaultValueChange:j,onBack:b,onNext:m,nextDisabled:C}=l;return e.jsxs("div",{className:"space-y-3",children:[e.jsx(ye,{control:a,onChange:g}),e.jsx(p.ControlDefinitionOptionsEditor,{control:a,availableFieldChoices:d,availableMetricChoices:x,previewControlDefinitions:u,previewControlValues:h,controlLifecycle:"create",onChange:y}),e.jsx(p.ControlDefaultValueEditor,{control:a,value:i,onChange:j,allowNoDefault:!0,allowCardDefault:!0,hint:"This is the value viewers will see first.",previewControlDefinitions:u,previewControlValues:h}),e.jsx(J,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:b,children:"Back"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:m,disabled:C,children:"Next"})})]})}const qe=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]);function xe(l){const{text:a,ariaLabel:i}=l,[d,x]=v.useState(!1);return e.jsxs("button",{type:"button","aria-label":i,onClick:async()=>{try{await navigator.clipboard.writeText(a),x(!0),setTimeout(()=>x(!1),1200)}catch(u){console.error("Failed to copy",u)}},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:[e.jsx("code",{className:"min-w-0 truncate font-mono text-[12px] text-foreground",children:a}),e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:d?"Copied":"Click to copy"})]})}function fe(l){const{control:a,scope:i,createdReference:d,explorerContent:x,sqlDescription:u,summaryDetail:h,onBack:y,onCancel:g,onDone:j}=l,b=qe.has(a.type),m=d.match(/\[\[param\.(.+?)\]\]/),C=m?`{{ param('${m[1]}') }}`:"";return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Be,{control:a,scope:i,detail:h}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-foreground",children:"How cards use this control"}),e.jsxs("div",{className:"divide-y divide-border/60 overflow-hidden rounded-control border border-border/60",children:[b?e.jsxs("div",{className:"space-y-1 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Explorer cards"}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:x})]}):null,e.jsxs("div",{className:"space-y-1.5 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"SQL cards"}),e.jsx(xe,{text:d,ariaLabel:"Copy SQL control reference"}),C?e.jsx(xe,{text:C,ariaLabel:"Copy Jinja control reference"}):null,e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[u," ",e.jsx("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"}),"."]})]})]})]}),e.jsx(J,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:y,children:"Back"}),tertiary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:g,children:"Cancel"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:j,children:"Done"})})]})}function Ae(l){const a=s.createBlankControl(l.scope,l.existingControls,l.reservedIds),i=l.type===a.type?{...a,label:s.DEFAULT_LABEL_BY_TYPE[l.type]}:{...s.applyControlTypeChange({controls:[{...a,label:s.DEFAULT_LABEL_BY_TYPE[l.type]}],controlId:a.id,nextType:l.type}).controls[0],label:s.DEFAULT_LABEL_BY_TYPE[l.type]};return{step:2,control:i,defaultValue:s.getDefaultValueForType(i,void 0)}}function Me({scope:l,controls:a,reservedControlIds:i,defaultValues:d,onChange:x,emptyMessage:u,initialCreateFlow:h=!1,usageByControlId:y,availableFieldChoices:g,availableMetricChoices:j,structuralParticipants:b,structuralParticipantIdsByControlId:m,card:C,allowedControlTypes:D,onCreateFlowActiveChange:N,onCreateFlowComplete:E}){const F=v.useMemo(()=>new Set(i||[]),[i]),R=s.getPlacementOptionsForScope(l),U=s.getDefaultPlacement(l),[G,P]=v.useState(null),[W,q]=v.useState(null),[r,T]=v.useState(()=>h?{step:1,control:s.createBlankControl(l,a,Array.from(F))}:null),I=v.useRef({}),A=v.useRef(void 0),M=v.useRef(h),Y=v.useMemo(()=>{const t=s.getFriendlyControlTypeOptions({scope:l,card:C});if(!D)return t;const o=new Set(D);return t.filter(n=>o.has(n.value))},[D,C,l]),H=v.useCallback(t=>{const o=s.getFriendlyControlTypeOptions({scope:l,card:C,includeType:D?void 0:t});if(!D)return o;const n=new Set(D);return o.filter(c=>n.has(c.value))},[D,C,l]),L=v.useCallback(t=>l==="dashboard"&&(t==="field_selector"||t==="metric_selector"),[l]),K=v.useMemo(()=>r?s.getEligibleParticipantsForStructuralControl(b||[],r.control.type):[],[r,b]),O=v.useMemo(()=>{if(!r)return{fields:g||[],metrics:j||[]};if(!L(r.control.type))return{fields:g||[],metrics:j||[]};const t=r.selectedCardIds||[],o=s.getCompatibleStructuralChoiceCatalog({controlType:r.control.type,participants:b||[],selectedCardIds:t});return{fields:r.control.type==="field_selector"?o.choices.map(n=>({option:n,target:o.fieldTargetMap[n.value]})):[],metrics:r.control.type==="metric_selector"?o.choices.map(n=>({option:n,target:o.metricTargetMap[n.value]})):[]}},[g,j,r,L,b]);v.useEffect(()=>{N==null||N(!!r)},[r,N]),v.useEffect(()=>{const t=h&&!M.current;M.current=h,t&&(T({step:1,control:s.createBlankControl(l,a,Array.from(F))}),q(null),P(null))},[a,h,F,l]);const ve=t=>{if(!L(t.type))return{fields:g||[],metrics:j||[]};const o=(m==null?void 0:m[t.id])||[];if(o.length===0)return{fields:g||[],metrics:j||[]};const n=s.getCompatibleStructuralChoiceCatalog({controlType:t.type,participants:b||[],selectedCardIds:o});return{fields:t.type==="field_selector"?n.choices.map(c=>({option:c,target:n.fieldTargetMap[c.value]})):[],metrics:t.type==="metric_selector"?n.choices.map(c=>({option:c,target:n.metricTargetMap[c.value]})):[]}},ne=t=>{if(!L(t.control.type))return{nextControl:t.control,cardBindingsById:void 0};const o=(m==null?void 0:m[t.control.id])||[],n=s.getCompatibleStructuralChoiceCatalog({controlType:t.control.type,participants:b||[],selectedCardIds:t.nextSelectedCardIds}),c=s.reconcileStructuralControlChoices({control:t.control,choices:n.choices}),S=Object.fromEntries(o.filter(k=>!t.nextSelectedCardIds.includes(k)).map(k=>[k,void 0]));return t.nextSelectedCardIds.length>0&&c.source.kind==="manual"&&c.source.options.length>0&&Object.assign(S,s.buildStructuralControlBindingsForParticipants({control:c,participants:b||[],selectedCardIds:t.nextSelectedCardIds})),{nextControl:c,cardBindingsById:S}},B=v.useCallback((t,o=d,n={type:"update"})=>{const c=t.map(S=>(s.resolveAuthoringControlDefaultValue({control:S,defaultValues:o}),s.syncSqlQueryControlExecutionRequirement(S)));x(c,o,n)},[d,x]),$=(t,o)=>{const n=a.find(V=>V.id===t);let c=a.map(V=>V.id!==t?V:o(V));const S=c.find(V=>V.id===t);let k,f;if(S&&l==="dashboard"&&(S.type==="field_selector"||S.type==="metric_selector")){const V=(m==null?void 0:m[S.id])||[],Q=ne({control:S,nextSelectedCardIds:V});c=c.map(z=>z.id===t?Q.nextControl:z),k=Q.cardBindingsById,f=[S.id]}else if(n&&l==="dashboard"&&(n.type==="field_selector"||n.type==="metric_selector")){const V=(m==null?void 0:m[n.id])||[];k=Object.fromEntries(V.map(Q=>[Q,void 0])),f=[n.id]}const w=c.find(V=>V.id===t);let _=d;if(n&&w){const V=s.resolveAuthoringControlDefaultValue({control:n,defaultValues:d});n.source.kind==="manual"&&w.source.kind==="sql_query"&&(I.current[t]=V);const Q=V===void 0&&n.source.kind==="sql_query"&&w.source.kind==="manual"?I.current[t]:V,z=s.getNextEditedControlDefaultValue({previousControl:n,nextControl:w,currentDefaultValue:Q});w.source.kind==="manual"&&(I.current[t]=z),d&&(_={...d},z===void 0?delete _[t]:_[t]=z),c=c.map(pe=>pe.id===t?{...w,defaultValue:z}:pe)}B(c,_,{type:"update",cardBindingsById:k,affectedBindingControlIds:f})},Ce=(t,o)=>{if(!o.trim())return;const n=p.normalizeDashboardInputVariableName(o);if(n===t||F.has(n)||a.some(k=>k.id===n&&k.id!==t))return;const c=a.map(k=>k.id===t?{...k,id:n}:k);if(!d){B(c,void 0,{type:"rename",oldId:t,newId:n});return}const S={...d};Object.prototype.hasOwnProperty.call(S,t)&&(S[n]=S[t],delete S[t]),B(c,S,{type:"rename",oldId:t,newId:n})},je=t=>{const o=a.filter(c=>c.id!==t);if(!d){B(o,void 0,{type:"remove",controlId:t});return}const n={...d};delete n[t],B(o,n,{type:"remove",controlId:t})},Se=v.useCallback(()=>{A.current=void 0,T({step:1,control:s.createBlankControl(l,a,Array.from(F))}),q(null),P(null)},[a,F,l]),X=t=>{T(o=>o&&(()=>{const n=t(o.control);o.control.source.kind==="manual"&&n.source.kind==="sql_query"&&(A.current=o.defaultValue);const c=o.defaultValue===void 0&&o.control.source.kind==="sql_query"&&n.source.kind==="manual"?A.current:o.defaultValue,S=s.getNextEditedControlDefaultValue({previousControl:o.control,nextControl:n,currentDefaultValue:c});return n.source.kind==="manual"&&(A.current=S),{...o,control:n,defaultValue:S}})())},oe=t=>{T(o=>o&&(o.control.source.kind==="manual"&&(A.current=t),{...o,defaultValue:t}))},Z=(()=>{if(!r)return!1;if(r.step===2&&L(r.control.type))return(r.selectedCardIds||[]).length>0;if(r.step!==2&&r.step!==3||!r.control.label.trim())return!1;const o=r.control.source.kind==="sql_query"?r.control:s.ensureManualSource(r.control);if(o.source.kind==="manual"&&(s.needsManualOptions(o)&&o.source.options.length===0||o.source.options.some(c=>c.label.trim().length===0||c.value.trim().length===0)))return!1;if(o.source.kind==="sql_query"){const{connectionId:n,sql:c,valueColumn:S}=o.source;return n.trim().length>0&&c.trim().length>0&&S.trim().length>0}return s.hasConcreteDefaultValue(s.getDefaultValueForType(o,r.defaultValue))})(),ie=()=>{var k;if(!r)return;const t=s.ensureManualSource(r.control),o=s.deriveUniqueControlId({label:t.label,fallbackId:t.id,existingControls:a,reservedIds:Array.from(F)}),n={...t,id:o},c=l==="dashboard"&&(n.type==="field_selector"||n.type==="metric_selector")&&((k=r.selectedCardIds)!=null&&k.length)?s.buildStructuralControlBindingsForParticipants({control:n,participants:b||[],selectedCardIds:r.selectedCardIds}):void 0,S=s.getDefaultValueForType(n,r.defaultValue);T({step:l==="dashboard"&&(n.type==="field_selector"||n.type==="metric_selector")?4:3,control:n,defaultValue:S,createdControlId:o,selectedCardIds:r.selectedCardIds,cardBindingsById:c})},ee=v.useCallback(()=>{T(null)},[]),de=v.useCallback(()=>{if(!(r!=null&&r.createdControlId)){T(null);return}const t=r.control,o=r.createdControlId,n=s.getDefaultValueForType(t,r.defaultValue);if(d){const c={...d};n===void 0?delete c[o]:c[o]=n,B([...a,{...t,defaultValue:n}],c,{type:"add",cardBindingsById:r.cardBindingsById})}else B([...a,{...t,defaultValue:n}],void 0,{type:"add",cardBindingsById:r.cardBindingsById});q(o),T(null),E==null||E()},[a,r,d,B,E]),ke=r?L(r.control.type)?["Choose type","Select cards","Configure","Finish"]:["Choose type","Configure","Finish"]:[],ce=r!=null&&r.createdControlId?`[[param.${r.createdControlId}]]`:r?`[[param.${s.slugifyControlValue(r.control.label)||r.control.id}]]`:"",te=s.buildAuthoringPreviewControlValues({controls:a,defaultValues:d}),se=r?[...a,r.control]:a,ue=r?s.buildAuthoringPreviewControlValues({controls:se,defaultValues:d,overrides:[{controlId:r.control.id,value:r.defaultValue}]}):te;return e.jsxs("div",{className:"space-y-4",children:[r?e.jsxs("div",{className:"space-y-4 pb-1",children:[e.jsx(_e,{currentStep:r.step,labels:ke}),r.step===1&&(()=>{const t=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]),o=new Set(["date","text"]),n=Y.filter(k=>!t.has(k.value)&&!o.has(k.value)),c=Y.filter(k=>t.has(k.value)),S=k=>e.jsxs("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:()=>T(Ae({scope:l,existingControls:a,reservedIds:Array.from(F),type:k.value})),children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:k.label}),e.jsx("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:k.description})]},k.value);return e.jsxs("div",{className:"space-y-4",children:[l==="card"&&(C==null?void 0:C.sql)==null?e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Explorer cards support displayed metric, group by field, aggregation, and time grain controls here."}):null,n.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Input controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:n.map(S)})]}),c.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Data-driven controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:c.map(S)})]}),e.jsx(J,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:ee,children:"Back to controls"})})]})})(),r.step===2&&L(r.control.type)&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(ye,{control:r.control,onChange:t=>X(o=>({...o,label:t}))}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Choose which cards should respond to this shared control."})]}),K.length===0?e.jsx("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."}):e.jsx("div",{className:"space-y-1 rounded-control border border-border/60 bg-background p-2",children:K.map(t=>{const o=(r.selectedCardIds||[]).includes(t.cardId);return e.jsxs("label",{className:"flex items-start gap-2 rounded-control px-1.5 py-1 text-[13px] hover:bg-muted/40",children:[e.jsx(p.Checkbox,{checked:o,onCheckedChange:n=>T(c=>c&&{...c,selectedCardIds:n===!0?[...c.selectedCardIds||[],t.cardId]:(c.selectedCardIds||[]).filter(S=>S!==t.cardId)})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-foreground",children:t.title}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:r.control.type==="field_selector"?`${t.fieldChoices.length} compatible group-by fields`:`${t.metricChoices.length} compatible metrics`})]})]},t.cardId)})}),e.jsx(J,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:()=>T(t=>t&&{...t,step:1,selectedCardIds:[]}),children:"Back"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:()=>T(t=>t&&{...t,step:3}),disabled:!Z,children:"Next"})})]}),r.step===2&&!L(r.control.type)&&e.jsx(me,{control:r.control,defaultValue:r.defaultValue,availableFieldChoices:O.fields,availableMetricChoices:O.metrics,previewControlDefinitions:se,previewControlValues:ue,onControlChange:t=>X(()=>t),onLabelChange:t=>X(o=>({...o,label:t})),onDefaultValueChange:oe,onBack:()=>T(t=>t&&{...t,step:1}),onNext:ie,nextDisabled:!Z}),r.step===3&&L(r.control.type)&&e.jsx(me,{control:r.control,defaultValue:r.defaultValue,availableFieldChoices:O.fields,availableMetricChoices:O.metrics,previewControlDefinitions:se,previewControlValues:ue,onControlChange:t=>X(()=>t),onLabelChange:t=>X(o=>({...o,label:t})),onDefaultValueChange:oe,onBack:()=>T(t=>t&&{...t,step:2}),onNext:ie,nextDisabled:!Z}),r.step===3&&!L(r.control.type)&&e.jsx(fe,{control:r.control,scope:l,createdReference:ce,explorerContent:e.jsxs(e.Fragment,{children:["Open the card and use"," ",e.jsx("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:()=>T(t=>t&&{...t,step:2}),onCancel:ee,onDone:de}),r.step===4&&L(r.control.type)&&e.jsx(fe,{control:r.control,scope:l,createdReference:ce,summaryDetail:e.jsxs(e.Fragment,{children:["Used by ",(r.selectedCardIds||[]).length," selected card",(r.selectedCardIds||[]).length===1?"":"s"]}),explorerContent:e.jsx(e.Fragment,{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:()=>T(t=>t&&{...t,step:3}),onCancel:ee,onDone:de})]}):null,!r&&a.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:u}):null,!r&&a.map(t=>{const o=ve(t),n=y==null?void 0:y[t.id],c=s.resolveAuthoringControlDefaultValue({control:t,defaultValues:d}),S=W===t.id,k="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 e.jsxs("div",{className:"rounded-control border border-border/60",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsxs("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:()=>q(f=>f===t.id?null:t.id),children:[S?e.jsx(s.ChevronDown,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(p.ChevronRight,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-foreground",children:t.label||"Untitled control"}),e.jsx("span",{className:k,children:s.getFriendlyTypeOption(t.type).label}),e.jsx("span",{className:k,children:s.getPlacementLabel(l,t.placement)})]}),e.jsxs("div",{className:"mt-0.5 text-[12px] text-muted-foreground",children:[s.getControlOptionPreview(t),n!=null&&n.status?` · ${n.status}`:""]})]})]}),e.jsx(s.Button,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground",onClick:()=>je(t.id),"aria-label":`Remove ${t.label}`,children:e.jsx(p.Trash2,{className:"h-3.5 w-3.5"})})]}),S&&e.jsxs("div",{className:"space-y-4 border-t border-border/60 px-3 py-3",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(s.Input,{size:"xs",value:t.label,placeholder:"Control label",onChange:f=>$(t.id,w=>({...w,label:f.target.value}))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Type"}),e.jsxs(s.Select,{value:t.type,onValueChange:f=>{const w=s.applyControlTypeChange({controls:a,controlId:t.id,nextType:f,defaultValues:d});B(w.controls,w.defaultValues)},children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:H(t.type).map(f=>e.jsx(s.SelectItem,{value:f.value,children:f.label},f.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Show in"}),e.jsxs(s.Select,{value:t.placement||U,onValueChange:f=>$(t.id,w=>({...w,placement:f})),children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:R.map(f=>e.jsx(s.SelectItem,{value:f.value,children:f.label},f.value))})]})]})]}),L(t.type)?e.jsx(p.StructuralParticipantSelector,{type:t.type,participants:s.getEligibleParticipantsForStructuralControl(b||[],t.type).map(f=>({cardId:f.cardId,title:f.title,choiceCount:t.type==="field_selector"?f.fieldChoices.length:f.metricChoices.length})),selectedCardIds:(m==null?void 0:m[t.id])||[],onChange:f=>{const w=ne({control:t,nextSelectedCardIds:f}),_=a.map(V=>V.id===t.id?w.nextControl:V);B(_,d,{type:"update",cardBindingsById:w.cardBindingsById})}}):null,e.jsx(p.ControlDefinitionOptionsEditor,{control:t,availableFieldChoices:o.fields,availableMetricChoices:o.metrics,previewControlDefinitions:a,previewControlValues:te,controlLifecycle:"edit",onChange:f=>$(t.id,()=>f)}),t.initialValueStrategy==="saved_default"&&e.jsx(p.ControlDefaultValueEditor,{control:t,value:c,allowNoDefault:!0,allowCardDefault:!0,previewControlDefinitions:a,previewControlValues:te,onChange:f=>{const w=a.map(_=>_.id===t.id?{..._,defaultValue:f}:_);if(t.source.kind==="manual"&&(I.current[t.id]=f),d){const _={...d};f===void 0?delete _[t.id]:_[t.id]=f,B(w,_);return}B(w,void 0)}}),e.jsxs(p.Collapsible,{open:G===t.id,onOpenChange:f=>P(f?t.id:null),children:[e.jsx(p.CollapsibleTrigger,{asChild:!0,children:e.jsxs(s.Button,{type:"button",variant:"ghost",size:"xs",className:"-ml-2 gap-1 text-muted-foreground hover:text-foreground",children:[G===t.id?e.jsx(s.ChevronDown,{className:"h-3.5 w-3.5"}):e.jsx(p.ChevronRight,{className:"h-3.5 w-3.5"}),"Advanced"]})}),e.jsxs(p.CollapsibleContent,{className:"space-y-3 pt-2",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Variable name"}),e.jsx(p.ControlIdInput,{controlId:t.id,onCommit:f=>Ce(t.id,f)},t.id)]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Initial value"}),e.jsxs(s.Select,{value:t.initialValueStrategy,onValueChange:f=>$(t.id,w=>({...w,initialValueStrategy:f})),children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:s.INITIAL_VALUE_STRATEGY_OPTIONS.map(f=>e.jsx(s.SelectItem,{value:f.value,children:f.label},f.value))})]})]})]}),e.jsx(p.ControlVisibilitySettings,{control:t,onChange:f=>$(t.id,()=>f)})]})]})]})]},t.id)}),!r&&e.jsxs(s.Button,{type:"button",variant:"outline",size:"xs",onClick:Se,children:[e.jsx(p.Plus,{className:"h-3.5 w-3.5"}),"Add control"]})]})}function Oe(l){const{open:a,onOpenChange:i,initialCreateFlowActive:d=!1,dismissMode:x="passive"}=l,u=a!==void 0,[h,y]=v.useState(!1),[g,j]=v.useState(d),b=u?a:h,m=v.useCallback(N=>{!N&&g&&x==="passive"||(u||y(N),N||j(!1),i==null||i(N))},[u,g,x,i]),C=v.useCallback(()=>{u||y(!1),j(!1),i==null||i(!1)},[u,i]);v.useEffect(()=>{b||j(!1)},[b]);const D=v.useCallback(N=>{g&&N.preventDefault()},[g]);return{forceClose:C,handleOpenChange:m,isCreateFlowActive:g,preventPassiveDismissDuringCreate:D,resolvedOpen:b,setIsCreateFlowActive:j}}exports.CircleX=Ne;exports.ControlDefinitionListEditor=Me;exports.EditorAcceptButton=Ve;exports.EditorCancelButton=Le;exports.EditorClearButton=Fe;exports.Library=ge;exports.Link2=be;exports.VisualBadge=Ee;exports.VisualSaveAndApplyButton=Ie;exports.VisualSaveButton=Te;exports.useCreateFlowOverlayState=Oe;exports.useEffectiveEditorCardType=ae;exports.useSyncLegacyEditorState=De;
@@ -1,5 +1,5 @@
1
- import { p as X, u as Y, q as Z, r as ee, s as te, t as re, v as se, w as ae, o as V, x as oe } from "./index-9v7DehZd.js";
2
- import { l as ne, m as ie, u as b, n as z, o as ce } from "./switch-Dhoqe3OE.js";
1
+ import { p as X, u as Y, q as Z, r as ee, s as te, t as re, v as se, w as ae, o as V, x as oe } from "./index-P5hPTTzm.js";
2
+ import { g as ne, h as ie, u as b, i as z, j as ce } from "./switch-B6fh8nb-.js";
3
3
  import { useState as H, useEffect as de, useCallback as A } from "react";
4
4
  function le(e) {
5
5
  const [a, s] = H(null), [r, t] = H(null), o = X();
@@ -193,12 +193,12 @@ function be() {
193
193
  setSelectedTableName: p,
194
194
  setSelectedDatamodelId: g,
195
195
  setFilterValues: P,
196
- setInlineFilterValuesMap: D,
197
- setApplyFilters: L,
198
- clearEditorContext: T
196
+ setInlineFilterValuesMap: j,
197
+ setApplyFilters: D,
198
+ clearEditorContext: L
199
199
  } = ne(), {
200
200
  setIsDashboardEditing: v,
201
- setIsVisualEditing: j,
201
+ setIsVisualEditing: T,
202
202
  setSelectedFrameId: k,
203
203
  clearSelectedFrameId: N,
204
204
  setIsDashboardPanelOpen: W
@@ -209,7 +209,7 @@ function be() {
209
209
  }), G = A(
210
210
  async (c) => {
211
211
  try {
212
- o(c), N(), T();
212
+ o(c), N(), L();
213
213
  const { data: u, fromCache: U } = await Q(
214
214
  a.apiServiceUrl,
215
215
  (e == null ? void 0 : e.accessToken) || "",
@@ -230,10 +230,10 @@ function be() {
230
230
  setSelectedTableName: p,
231
231
  setSelectedDatamodelId: g,
232
232
  setFilterValues: P,
233
- setInlineFilterValuesMap: D,
234
- setApplyFilters: L,
233
+ setInlineFilterValuesMap: j,
234
+ setApplyFilters: D,
235
235
  setIsDashboardEditing: v,
236
- setIsVisualEditing: j,
236
+ setIsVisualEditing: T,
237
237
  dashboard: x,
238
238
  selectedSheetId: S,
239
239
  selectedFrameId: $,
@@ -254,7 +254,7 @@ function be() {
254
254
  l,
255
255
  n,
256
256
  v,
257
- j,
257
+ T,
258
258
  i,
259
259
  f,
260
260
  h,
@@ -266,9 +266,9 @@ function be() {
266
266
  p,
267
267
  g,
268
268
  P,
269
+ j,
269
270
  D,
270
271
  L,
271
- T,
272
272
  N,
273
273
  x,
274
274
  S,
@@ -1 +1 @@
1
- "use strict";const u=require("./index-CGCrm-dj.js"),f=require("./switch-otrSiyjH.js"),S=require("react");function K(e){const[a,s]=S.useState(null),[r,t]=S.useState(null),o=u.useEnsureReactGlobals();return S.useEffect(()=>{if(!e||e.trim()===""){s(null),t(null);return}if(!o)return;(async()=>{try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid URL format: ${e}`);try{new URL(e)}catch{throw new Error(`Invalid URL: ${e}`)}const i=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(i,{method:"HEAD"})).ok)throw new Error(`Module not found at ${i}`)}catch{}const m=await import(i);if(typeof m.useChartStore!="function")throw new Error("useChartStore is not a function");s(()=>m.useChartStore),t(null)}catch(n){const i=n instanceof Error?n.message:"Unknown error";console.error("Failed to load remote chart store:",i),t(i),s(null)}})()},[e,o]),a}function X(e,a){if(e.length===0)return"";const s=e.find(r=>{var t,o;return((t=r.customCardPreferences)==null?void 0:t.visualType)==="multiple"||!!((o=r.customCardPreferences)!=null&&o.dataInputCardIds)});if(s)return s.id;if(a){const r=e.find(t=>t.id===a);if(r){const t=r.tabTitle;if(t=="All__Header")return e[0].id;if(t&&t.endsWith("__Header")){const l=t.split("__")[0],n=e.find(i=>i.tabTitle===l);return n?n.id:e[0].id}return a}}return e[0].id}const A=new Set;function Y(e){return A.add(e),()=>{A.delete(e)}}function z(){A.forEach(e=>{e()})}const Z=e=>{if(!e||!("detailTableBackup"in e))return e;const{detailTableBackup:a,...s}=e;return s};async function B(e,a,s,r){if(!a||!s)throw new Error("Missing auth token or visual ID");const t=["resource-by-id","visual",s],o=r.getQueryData(t);if(o)return console.log("Using cached visual data for:",s),{data:o,fromCache:!0};console.log("Fetching visual data from network for:",s);const l=u.ue.loading("Loading visual...",{position:"top-center"});try{const n=await fetch(`${e}/management/v1/visuals/${s}`,{headers:{Authorization:`Bearer ${a}`}});if(!n.ok)throw new Error("Failed to load visual");const i=await n.json();return r.setQueryData(t,i),u.ue.dismiss(l),{data:i,fromCache:!1}}catch(n){throw u.ue.dismiss(l),n}}function H(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function ee(e,a){var o,l;const s=(e==null?void 0:e.frameObject)??((o=e==null?void 0:e.visual)==null?void 0:o.frameObject);if(!s)return!1;const r=H(s);if(!(r!=null&&r.cards)||r.cards.length===0)return!1;const t=(l=r.cards)==null?void 0:l.find(n=>n.id===r.activeCardId);return t?(u.setupEditorWithCard({...a,frame:r,card:t,visualId:(e==null?void 0:e.id)||r.visualId}),!0):!1}function te(){const e=f.useEditorStore(r=>{var t;return((t=r.card.customCardPreferences)==null?void 0:t.url)||""}),a=K(e);return{getUpdatedFrame:S.useCallback(()=>{var b;z();const{frame:r,card:t,isDevMode:o,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y}=f.useEditorStore.getState(),I=t.sql,U=(b=a==null?void 0:a.getState())==null?void 0:b.settings,V=f.buildSavedEditorCard(t,{isDevMode:o,cardSql:I,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y,remoteChartSettings:U,stripConfig:Z}),g=r.cards.map(E=>E.id===t.id?V:E);return{...r,cards:g,activeCardId:X(g,r.activeCardId)}},[a])}}function re(){const{authToken:e,tokenProps:a}=u.useSemaphorContext(),s=u.useQueryClient(),r=u.useAddFrameWithFreshSemanticExecutionPayload(),t=u.useSelectedVisual(),{selectVisual:o}=u.useManagementActions(),{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,clearEditorContext:L}=f.useEditorActions(),{setIsDashboardEditing:v,setIsVisualEditing:T,setSelectedFrameId:j,clearSelectedFrameId:N,setIsDashboardPanelOpen:R}=f.useDashboardActions(),w=f.useDashboardStore(c=>c.selectedSheetId),W=f.useDashboardStore(c=>c.selectedFrameId),$=f.useDashboardStore(c=>c.dashboard),_=f.useDashboardStore(c=>c.filterValues),x=f.useDashboardStore(c=>c.inlineFilterValuesMap),F=u.useVisualById((t==null?void 0:t.id)||"",{enabled:!!(t!=null&&t.id)&&!!(e!=null&&e.accessToken)}),Q=S.useCallback(async c=>{try{o(c),N(),L();const{data:h,fromCache:D}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s);if(!ee(h,{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,setIsDashboardEditing:v,setIsVisualEditing:T,dashboard:$,selectedSheetId:w,selectedFrameId:W,filterValues:_,inlineFilterValuesMap:x}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:D}}catch(h){return console.error("Error editing visual:",h),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,l,n,v,T,i,m,p,y,I,U,V,g,b,E,P,M,k,L,N,$,w,W,_,x]),G=S.useCallback(async c=>{var D;const h=d=>(u.ue.error(d),{success:!1,error:d});try{if(o(c),!w)return h("No sheet selected. Please select a sheet first.");const{data:d,fromCache:J}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s),O=(d==null?void 0:d.frameObject)??((D=d==null?void 0:d.visual)==null?void 0:D.frameObject);if(!O)return h("Visual has no frame data");const C=H(O);if(!(C!=null&&C.cards)||C.cards.length===0)return h("Visual frame is malformed");const q={...u.cloneLinkedFrameWithSourceMapping(C),visualId:c.id};return await r(w,q,"end"),v(!0),j(q.id),R(!1),{success:!0,fromCache:J}}catch(d){return console.error("Error adding visual:",d),h(d instanceof Error?d.message:"Failed to add visual to dashboard")}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,w,v,j,R,r]);return{visual:F.data,isLoading:F.isLoading,isError:F.isError,error:F.error,handleEditLibraryVisual:Q,handleAddLibraryVisual:G,getUpdatedFrame:te().getUpdatedFrame,refetch:F.refetch}}exports.flushPendingEditorDrafts=z;exports.registerPendingEditorDraftFlusher=Y;exports.useVisualUtils=re;
1
+ "use strict";const u=require("./index-XYIIY48z.js"),f=require("./switch-DPaKnsb8.js"),S=require("react");function K(e){const[a,s]=S.useState(null),[r,t]=S.useState(null),o=u.useEnsureReactGlobals();return S.useEffect(()=>{if(!e||e.trim()===""){s(null),t(null);return}if(!o)return;(async()=>{try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid URL format: ${e}`);try{new URL(e)}catch{throw new Error(`Invalid URL: ${e}`)}const i=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(i,{method:"HEAD"})).ok)throw new Error(`Module not found at ${i}`)}catch{}const m=await import(i);if(typeof m.useChartStore!="function")throw new Error("useChartStore is not a function");s(()=>m.useChartStore),t(null)}catch(n){const i=n instanceof Error?n.message:"Unknown error";console.error("Failed to load remote chart store:",i),t(i),s(null)}})()},[e,o]),a}function X(e,a){if(e.length===0)return"";const s=e.find(r=>{var t,o;return((t=r.customCardPreferences)==null?void 0:t.visualType)==="multiple"||!!((o=r.customCardPreferences)!=null&&o.dataInputCardIds)});if(s)return s.id;if(a){const r=e.find(t=>t.id===a);if(r){const t=r.tabTitle;if(t=="All__Header")return e[0].id;if(t&&t.endsWith("__Header")){const l=t.split("__")[0],n=e.find(i=>i.tabTitle===l);return n?n.id:e[0].id}return a}}return e[0].id}const A=new Set;function Y(e){return A.add(e),()=>{A.delete(e)}}function z(){A.forEach(e=>{e()})}const Z=e=>{if(!e||!("detailTableBackup"in e))return e;const{detailTableBackup:a,...s}=e;return s};async function B(e,a,s,r){if(!a||!s)throw new Error("Missing auth token or visual ID");const t=["resource-by-id","visual",s],o=r.getQueryData(t);if(o)return console.log("Using cached visual data for:",s),{data:o,fromCache:!0};console.log("Fetching visual data from network for:",s);const l=u.ue.loading("Loading visual...",{position:"top-center"});try{const n=await fetch(`${e}/management/v1/visuals/${s}`,{headers:{Authorization:`Bearer ${a}`}});if(!n.ok)throw new Error("Failed to load visual");const i=await n.json();return r.setQueryData(t,i),u.ue.dismiss(l),{data:i,fromCache:!1}}catch(n){throw u.ue.dismiss(l),n}}function H(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function ee(e,a){var o,l;const s=(e==null?void 0:e.frameObject)??((o=e==null?void 0:e.visual)==null?void 0:o.frameObject);if(!s)return!1;const r=H(s);if(!(r!=null&&r.cards)||r.cards.length===0)return!1;const t=(l=r.cards)==null?void 0:l.find(n=>n.id===r.activeCardId);return t?(u.setupEditorWithCard({...a,frame:r,card:t,visualId:(e==null?void 0:e.id)||r.visualId}),!0):!1}function te(){const e=f.useEditorStore(r=>{var t;return((t=r.card.customCardPreferences)==null?void 0:t.url)||""}),a=K(e);return{getUpdatedFrame:S.useCallback(()=>{var b;z();const{frame:r,card:t,isDevMode:o,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y}=f.useEditorStore.getState(),I=t.sql,U=(b=a==null?void 0:a.getState())==null?void 0:b.settings,V=f.buildSavedEditorCard(t,{isDevMode:o,cardSql:I,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y,remoteChartSettings:U,stripConfig:Z}),g=r.cards.map(E=>E.id===t.id?V:E);return{...r,cards:g,activeCardId:X(g,r.activeCardId)}},[a])}}function re(){const{authToken:e,tokenProps:a}=u.useSemaphorContext(),s=u.useQueryClient(),r=u.useAddFrameWithFreshSemanticExecutionPayload(),t=u.useSelectedVisual(),{selectVisual:o}=u.useManagementActions(),{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,clearEditorContext:L}=f.useEditorActions(),{setIsDashboardEditing:v,setIsVisualEditing:T,setSelectedFrameId:j,clearSelectedFrameId:N,setIsDashboardPanelOpen:R}=f.useDashboardActions(),w=f.useDashboardStore(c=>c.selectedSheetId),W=f.useDashboardStore(c=>c.selectedFrameId),$=f.useDashboardStore(c=>c.dashboard),_=f.useDashboardStore(c=>c.filterValues),x=f.useDashboardStore(c=>c.inlineFilterValuesMap),F=u.useVisualById((t==null?void 0:t.id)||"",{enabled:!!(t!=null&&t.id)&&!!(e!=null&&e.accessToken)}),Q=S.useCallback(async c=>{try{o(c),N(),L();const{data:h,fromCache:D}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s);if(!ee(h,{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,setIsDashboardEditing:v,setIsVisualEditing:T,dashboard:$,selectedSheetId:w,selectedFrameId:W,filterValues:_,inlineFilterValuesMap:x}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:D}}catch(h){return console.error("Error editing visual:",h),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,l,n,v,T,i,m,p,y,I,U,V,g,b,E,P,M,k,L,N,$,w,W,_,x]),G=S.useCallback(async c=>{var D;const h=d=>(u.ue.error(d),{success:!1,error:d});try{if(o(c),!w)return h("No sheet selected. Please select a sheet first.");const{data:d,fromCache:J}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s),O=(d==null?void 0:d.frameObject)??((D=d==null?void 0:d.visual)==null?void 0:D.frameObject);if(!O)return h("Visual has no frame data");const C=H(O);if(!(C!=null&&C.cards)||C.cards.length===0)return h("Visual frame is malformed");const q={...u.cloneLinkedFrameWithSourceMapping(C),visualId:c.id};return await r(w,q,"end"),v(!0),j(q.id),R(!1),{success:!0,fromCache:J}}catch(d){return console.error("Error adding visual:",d),h(d instanceof Error?d.message:"Failed to add visual to dashboard")}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,w,v,j,R,r]);return{visual:F.data,isLoading:F.isLoading,isError:F.isError,error:F.error,handleEditLibraryVisual:Q,handleAddLibraryVisual:G,getUpdatedFrame:te().getUpdatedFrame,refetch:F.refetch}}exports.flushPendingEditorDrafts=z;exports.registerPendingEditorDraftFlusher=Y;exports.useVisualUtils=re;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../chunks/index-CGCrm-dj.js"),e=require("../chunks/common-types-C73-Ud1-.js");exports.Dashboard=o.Dashboard;exports.CONTROL_CARD_DEFAULT_VALUE=e.CONTROL_CARD_DEFAULT_VALUE;exports.EMPTY_SELECTION=e.EMPTY_SELECTION;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../chunks/index-XYIIY48z.js"),e=require("../chunks/common-types-C73-Ud1-.js");exports.Dashboard=o.Dashboard;exports.CONTROL_CARD_DEFAULT_VALUE=e.CONTROL_CARD_DEFAULT_VALUE;exports.EMPTY_SELECTION=e.EMPTY_SELECTION;
@@ -1,4 +1,4 @@
1
- import { D as o } from "../chunks/index-9v7DehZd.js";
1
+ import { D as o } from "../chunks/index-P5hPTTzm.js";
2
2
  import { C as s, E as C } from "../chunks/common-types-4bjoIgvm.js";
3
3
  export {
4
4
  s as CONTROL_CARD_DEFAULT_VALUE,
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/index-CGCrm-dj.js"),C=require("./chunks/common-types-C73-Ud1-.js"),L=require("./chunks/dashboard-summary-settings-dialog-DgqFlYl9.js"),t=require("react/jsx-runtime"),r=require("./chunks/switch-otrSiyjH.js"),m=require("react"),z=require("./chunks/resource-management-panel-CNmVHnCz.js"),B=require("./types/index.cjs"),q=require("./chunks/use-debounced-dirty-check-XHSwAefL.js");require("react-dom");require("./chunks/index-DRlMUglg.js");const D=require("./chunks/dashboard-filter-controls-button-CWL2jJcu.js"),O=require("./chunks/normalize-dashboard-for-dirty-check-BXRUMVb2.js");function Q(s){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const o in s)if(o!=="default"){const l=Object.getOwnPropertyDescriptor(s,o);Object.defineProperty(a,o,l.get?l:{enumerable:!0,get:()=>s[o]})}}return a.default=s,Object.freeze(a)}const P=Q(m);function V(s){const{displayPreferences:a,cardId:o,...l}=s,i={...l,id:s.dashboardId};return t.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:t.jsxs(e.SemaphorContextProvider,{dashboardProps:i,children:[t.jsx(e.SemaphorReadyIndicator,{componentType:"visual",componentId:s.cardId}),t.jsx(e.UXProvider,{appearance:s.appearance,children:t.jsx(e.DisplayPreferencesProvider,{displayPreferences:a,children:t.jsx(e.Container,{type:"visual",cardId:o,...i,children:t.jsx(W,{cardId:o})})})})]})})}function W({cardId:s}){const a=r.useDashboardStore(i=>{var u;return(u=i.dashboard)==null?void 0:u.sheets}),{card:o,frame:l}=m.useMemo(()=>{const i=a==null?void 0:a.flatMap(d=>d.frames),u=i==null?void 0:i.flatMap(d=>d==null?void 0:d.cards),h=u==null?void 0:u.find(d=>(d==null?void 0:d.id)===s),n=i==null?void 0:i.find(d=>{var x;return(x=d==null?void 0:d.cards)==null?void 0:x.find(A=>(A==null?void 0:A.id)===s)});return{card:h,frame:n}},[a,s]);return!o||!l?t.jsx(e.FallbackVisual,{error:new Error("Card not found"),resetErrorBoundary:()=>{},customerFacingMessage:`Card not found with ID: ${s}`}):t.jsx("main",{className:"flex h-full grow flex-col",children:t.jsx(e.ErrorBoundary,{FallbackComponent:({error:i,resetErrorBoundary:u})=>t.jsx(e.FallbackVisual,{error:i,resetErrorBoundary:u,customerFacingMessage:"Error creating visual. Please try again."}),children:t.jsx(e.DashboardCard,{card:o,frame:l})})})}function H(s,a,o,l){m.useEffect(()=>{s&&!o&&a&&l(e.cloneDeep(a))},[s,o,a,l])}function $({name:s,items:a,value:o,onChange:l,isLoading:i,isError:u,refetch:h,className:n,icon:d,showNone:x=!1}){const A=P.useRef(null),[j,y]=P.useState(!1),[N,v]=P.useState("100%"),S=x?[...a||[],{id:"none",name:"None"}]:a;P.useLayoutEffect(()=>{A.current&&v(A.current.offsetWidth)},[]);function _(){var p;return i?"Loading...":u?"Error":o?(p=a==null?void 0:a.find(b=>b.id===o))==null?void 0:p.name:`Select ${s}`}function F(p,b){l(b),y(!1)}return t.jsxs(r.Popover,{open:j,onOpenChange:y,children:[t.jsx(r.PopoverTrigger,{asChild:!0,children:t.jsxs(r.Button,{ref:A,variant:"outline",role:"combobox","aria-expanded":j,className:r.cn("flex h-9 w-full justify-between",n),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[d&&t.jsx("div",{className:"mr-2",children:d}),t.jsx("span",{className:"max-w-[150px] overflow-hidden truncate text-ellipsis whitespace-nowrap",children:_()})]}),t.jsx(r.ChevronDown,{className:"size-4 opacity-50"})]})}),t.jsx(r.PopoverContent,{className:"w-full p-0",style:{minWidth:N},children:t.jsxs(e.Command,{children:[t.jsxs("div",{className:"flex h-9 items-center justify-between border-b pr-1",children:[t.jsx(e.CommandInput,{className:"h-9",placeholder:"Search..."}),t.jsx(e.IconButton,{className:"h-7",onClick:h,children:t.jsx(e.RefreshCw,{className:r.cn("size-3.5 opacity-50",i&&"animate-spin")})})]}),t.jsxs(e.CommandList,{children:[t.jsxs(e.CommandEmpty,{children:["No ",s==null?void 0:s.toLowerCase()," found."]}),t.jsx(e.CommandGroup,{children:S==null?void 0:S.map(p=>t.jsx(e.CommandItem,{className:"overflow-x-auto",value:p.name,onSelect:b=>F(b,p.id),children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(r.Check,{className:r.cn("size-4",o===p.id?"opacity-100":"opacity-0")}),t.jsx("div",{title:p.name,children:p.name})]})},p.id))})]})]})})]})}function G({triggerButtonClassName:s,variant:a="ghost"}){const[o,l]=m.useState(!1),i=r.useDashboardStore(h=>{var n;return(n=h.dashboard)==null?void 0:n.id}),u=r.useDashboardStore(h=>{var n;return(n=h.dashboard)==null?void 0:n.title});return i?t.jsxs(t.Fragment,{children:[t.jsx(e.IconButton,{tooltip:"Schedule Dashboard",className:r.cn("h-7 p-2",s),buttonProps:{variant:a},onClick:()=>l(!0),children:t.jsx(e.Clock,{className:"size-4"})}),t.jsx(e.EmailScheduleDialog,{open:o,onOpenChange:l,dashboardId:i,dashboardName:u})]}):null}function K(s){const{authToken:a,tokenProps:o}=e.useSemaphorContext();return e.useMutation({mutationFn:async l=>e.backtestAlert(o.apiServiceUrl,a.accessToken,s,l)})}function Y(s,a){m.useEffect(()=>(s&&a&&(window.__SEMAPHOR_PRINT_STATE__={...a}),()=>{s&&window.__SEMAPHOR_PRINT_STATE__&&delete window.__SEMAPHOR_PRINT_STATE__}),[s,a])}function I(s){if(!s)return"--";const a=new Date(s);return Number.isNaN(a.getTime())?"--":a.toLocaleString()}function X(s){var a;return((a=s.alertState)==null?void 0:a.currentState)==="FIRING"?"Signal surfaced":s.status==="ACTIVE"?"Watching":s.status==="PAUSED"?"Paused":s.status}function J({alertId:s,onBack:a}){var p,b,w,k;const{authToken:o,tokenProps:l}=e.useSemaphorContext(),{data:i,isLoading:u,refetch:h}=e.useAlertDetail(s),n=(i==null?void 0:i.alert)??null,[d,x]=m.useState([]),[A,j]=m.useState([]),[y,N]=m.useState(null),v=m.useCallback(async()=>{var f;const c=l==null?void 0:l.apiServiceUrl,g=o==null?void 0:o.accessToken;if(!c||!g||!s)return null;try{const T=await fetch(`${c}/v1/alerts/${s}/runs?limit=20`,{headers:{Authorization:`Bearer ${g}`}});if(T.ok){const R=await T.json(),E=Array.isArray(R.runs)?R.runs:[],M=y&&E.some(U=>U.id===y)?y:((f=E[0])==null?void 0:f.id)??null;return j(E),N(M),M}j([]),N(null)}catch{return j([]),N(null),null}return null},[s,o,y,l]),S=m.useCallback(async c=>{const g=l==null?void 0:l.apiServiceUrl,f=o==null?void 0:o.accessToken,T=c??y;if(!g||!f||!s||!T){x([]);return}try{const R=await fetch(`${g}/v1/alerts/${s}/runs/${T}/deliveries`,{headers:{Authorization:`Bearer ${f}`}});if(R.ok){const E=await R.json();x(Array.isArray(E.attempts)?E.attempts:[])}else x([])}catch{x([])}},[s,o,y,l]),_=m.useCallback(async()=>{await h();const c=await v();await S(c)},[S,v,h]);m.useEffect(()=>{v().catch(()=>{})},[v]),m.useEffect(()=>{S().catch(()=>{})},[S]);const F=m.useMemo(()=>{const c={};for(const g of d)c[g.channel]||(c[g.channel]=[]),c[g.channel].push(g);return c},[d]);return u?t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading signal detail..."}):n?t.jsxs("div",{className:"space-y-4 p-4",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[a&&t.jsx(r.Button,{variant:"outline",size:"sm",onClick:a,children:"Back"}),t.jsx("h2",{className:"text-lg font-semibold",children:n.name}),t.jsx(e.Badge,{variant:n.status==="ACTIVE"?"default":"secondary",children:X(n)}),((p=n.alertState)==null?void 0:p.currentState)&&t.jsx(e.Badge,{variant:n.alertState.currentState==="FIRING"?"destructive":"outline",children:n.alertState.currentState==="FIRING"?"Signal surfaced":"Stable"})]}),t.jsx(r.Button,{variant:"outline",size:"sm",onClick:()=>void _(),children:"Refresh"})]}),n.description&&t.jsx("p",{className:"text-sm text-muted-foreground",children:n.description}),t.jsxs("div",{className:"rounded-md border bg-muted/30 p-4 text-sm",children:[t.jsx("p",{className:"font-medium",children:"What changed"}),t.jsx("p",{className:"mt-1 text-muted-foreground",children:"Review the latest signal activity, then investigate the underlying dashboard context if you need more detail."})]}),t.jsxs("div",{className:"rounded-md border bg-background p-4 space-y-2",children:[t.jsx("h3",{className:"text-sm font-semibold",children:"Signal Watch"}),t.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:"Watching for:"})," ",e.formatSignalCondition(n.jobConfig.operator,n.jobConfig.threshold)]}),t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:"Severity:"})," ",n.jobConfig.severity]}),t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:"Last Evaluated:"})," ",I((b=n.alertState)==null?void 0:b.lastEvaluatedAt)]}),t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:"Last Surfaced:"})," ",I((w=n.alertState)==null?void 0:w.lastTriggeredAt)]})]})]}),((k=n.deliveryConfig)==null?void 0:k.channels)&&n.deliveryConfig.channels.length>0&&t.jsxs("div",{className:"rounded-md border bg-background p-4 space-y-2",children:[t.jsx("h3",{className:"text-sm font-semibold",children:"Where It Surfaces"}),t.jsx("div",{className:"flex flex-wrap gap-2",children:n.deliveryConfig.channels.map(c=>t.jsx(e.Badge,{variant:"outline",children:c},c))})]}),A.length>0&&t.jsxs("div",{className:"rounded-md border bg-background p-4 space-y-3",children:[t.jsx("h3",{className:"text-sm font-semibold",children:"Recent Delivery Activity"}),A.length>1&&t.jsx("div",{className:"flex flex-wrap gap-2",children:A.map(c=>t.jsx(r.Button,{variant:c.id===y?"default":"outline",size:"sm",onClick:()=>N(c.id),children:I(c.scheduledFor)},c.id))}),Object.keys(F).length===0?t.jsx("p",{className:"text-sm text-muted-foreground",children:"No delivery attempts were recorded for this run."}):Object.entries(F).map(([c,g])=>t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"flex items-center gap-2",children:t.jsx(e.Badge,{variant:"secondary",className:"text-xs",children:c})}),t.jsx("div",{className:"overflow-hidden rounded border",children:t.jsxs("table",{className:"w-full text-xs",children:[t.jsx("thead",{className:"bg-muted/40",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Recipient"}),t.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Status"}),t.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Time"}),t.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Error"})]})}),t.jsx("tbody",{children:g.map(f=>t.jsxs("tr",{className:"border-t",children:[t.jsx("td",{className:"px-2 py-1",children:f.recipient}),t.jsx("td",{className:"px-2 py-1",children:t.jsx(e.Badge,{variant:f.status==="SENT"?"default":"destructive",className:"text-[10px]",children:f.status})}),t.jsx("td",{className:"px-2 py-1",children:I(f.createdAt)}),t.jsx("td",{className:"px-2 py-1 text-muted-foreground",children:f.error||"--"})]},f.id))})]})})]},c))]})]}):t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Signal not found."})}function Z(){var u,h;const{quotasQuery:s,usageQuery:a}=e.useAlertQuotas(),o=((u=s.data)==null?void 0:u.quotas)||[],l=((h=a.data)==null?void 0:h.usage)||[],i=new Map(l.map(n=>[n.tenantId||"org",n]));return t.jsxs("div",{className:"space-y-4 p-4",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h2",{className:"text-xl font-semibold",children:"Alert Quotas"}),t.jsx(r.Button,{variant:"outline",size:"sm",onClick:()=>{s.refetch(),a.refetch()},children:"Refresh"})]}),s.isLoading||a.isLoading?t.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading quota usage..."}):null,t.jsx("div",{className:"overflow-hidden rounded-lg border",children:t.jsxs("table",{className:"w-full text-sm",children:[t.jsx("thead",{className:"bg-muted/40",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Tenant"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Active Alerts"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Max Active"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Min Cadence"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Max Context Sources"})]})}),t.jsx("tbody",{children:o.map(n=>{const d=n.tenantId||"org",x=i.get(d);return t.jsxs("tr",{className:"border-t",children:[t.jsx("td",{className:"px-3 py-2",children:d}),t.jsx("td",{className:"px-3 py-2",children:(x==null?void 0:x.activeAlerts)??0}),t.jsx("td",{className:"px-3 py-2",children:n.policy.maxActiveAlerts}),t.jsxs("td",{className:"px-3 py-2",children:[n.policy.minCadenceMinutes," min"]}),t.jsx("td",{className:"px-3 py-2",children:n.policy.maxContextSources})]},d)})})]})})]})}exports.AlertManagementPage=e.AlertManagementPage;exports.AlertWizardDialog=e.AlertWizardDialog;exports.AlertsApiError=e.AlertsApiError;exports.CardAlertIndicator=e.CardAlertIndicator;exports.CardSummary=e.CardSummary;exports.Dashboard=e.Dashboard;exports.DashboardExportDialog=e.DashboardExportDialog;exports.DashboardWC=e.DashboardWC;exports.EmailScheduleDialog=e.EmailScheduleDialog;exports.ExportError=e.ExportError;exports.ResourceType=e.ResourceType;exports.SemaphorContextProvider=e.SemaphorContextProvider;exports.SemaphorDataProvider=e.SemaphorQueryClient;exports.SemaphorQueryClient=e.SemaphorQueryClient;exports.ShareDialog=e.ShareDialog;exports.SummaryCard=e.SummaryCard;exports.Surfboard=e.DashboardPlus;exports.backtestAlert=e.backtestAlert;exports.cancelExport=e.cancelExport;exports.cloneDeep=e.cloneDeep;exports.createAlert=e.createAlert;exports.createExport=e.createExport;exports.deleteAlert=e.deleteAlert;exports.downloadDocumentPdf=e.downloadDocumentPdf;exports.downloadPdf=e.downloadPdf;exports.formatFileSize=e.formatFileSize;exports.getAlert=e.getAlert;exports.getAlertContextSources=e.getAlertContextSources;exports.getAlertHistory=e.getAlertHistory;exports.getAlertQuotaUsage=e.getAlertQuotaUsage;exports.getAlertRunDeliveries=e.getAlertRunDeliveries;exports.getAlertRunSteps=e.getAlertRunSteps;exports.getAlertRuns=e.getAlertRuns;exports.getAlertState=e.getAlertState;exports.getDownloadUrl=e.getDownloadUrl;exports.getExportStatus=e.getExportStatus;exports.getExports=e.getExports;exports.isExportComplete=e.isExportComplete;exports.isExportInProgress=e.isExportInProgress;exports.listAlertQuotas=e.listAlertQuotas;exports.listAlerts=e.listAlerts;exports.previewAlertDeliverable=e.previewAlertDeliverable;exports.triggerAlertNow=e.triggerAlertNow;exports.updateAlert=e.updateAlert;exports.updateAlertContextSources=e.updateAlertContextSources;exports.updateAlertQuota=e.updateAlertQuota;exports.useActiveExports=e.useActiveExports;exports.useAddNewFrame=e.useAddNewFrame;exports.useAlertActions=e.useAlertActions;exports.useAlertDeliveries=e.useAlertDeliveries;exports.useAlertDetail=e.useAlertDetail;exports.useAlertDraft=e.useAlertDraft;exports.useAlertFilters=e.useAlertFilters;exports.useAlertHistory=e.useAlertHistory;exports.useAlertQuotas=e.useAlertQuotas;exports.useAlertRuns=e.useAlertRuns;exports.useAlertState=e.useAlertState;exports.useAlertStore=e.useAlertStore;exports.useAlertWizard=e.useAlertWizard;exports.useAlerts=e.useAlerts;exports.useAlertsBootstrap=e.useAlertsBootstrap;exports.useAlertsById=e.useAlertsById;exports.useAlertsForCard=e.useAlertsForCard;exports.useCard=e.useCard;exports.useCardAlertMap=e.useCardAlertMap;exports.useCardSummary=e.useCardSummary;exports.useDashboardById=e.useDashboardById;exports.useDashboardQuery=e.useDashboardQuery;exports.useDashboardSummary=e.useDashboardSummary;exports.useDataColumns=e.useDataColumns;exports.useDateFilterHook=e.useDateFilterHook;exports.useEditorAside=e.useEditorAside;exports.useExportActions=e.useExportActions;exports.useExportStore=e.useExportStore;exports.useInProgressExportsCount=e.useInProgressExportsCount;exports.useManagementStore=e.useManagementStore;exports.useResourceManagement=e.useResourceManagement;exports.useSelectedAlertId=e.useSelectedAlertId;exports.useTextFilterHook=e.useTextFilterHook;exports.CALCULATED_FIELD_ENTITY_MARKER=C.CALCULATED_FIELD_ENTITY_MARKER;exports.CONTROL_CARD_DEFAULT_VALUE=C.CONTROL_CARD_DEFAULT_VALUE;exports.DATE_FORMAT_VALUES=C.DATE_FORMAT_VALUES;exports.EMPTY_SELECTION=C.EMPTY_SELECTION;exports.PivotMarkerEnum=C.PivotMarkerEnum;exports.getFieldRuntimeColumnName=C.getFieldRuntimeColumnName;exports.hasCalculatedFieldMarker=C.hasCalculatedFieldMarker;exports.hasCalculatedFormulaInputs=C.hasCalculatedFormulaInputs;exports.isCalculatedDimension=C.isCalculatedDimension;exports.isCalculatedField=C.isCalculatedField;exports.isCalculatedMetric=C.isCalculatedMetric;exports.CalendarPreferencesDialog=L.CalendarPreferencesDialog;exports.DashboardSummarySettingsDialog=L.DashboardSummarySettingsDialog;exports.createEmptyKpiConfig=r.createEmptyKpiConfig;exports.createSqlGenConfig=r.createSqlGenConfig;exports.emitDashboardLoad=r.emitDashboardLoad;exports.emitDashboardUnload=r.emitDashboardUnload;exports.fmt=r.fmt;exports.getColumnDataType=r.getColumnDataType;exports.getFilterValueType=r.getFilterValueType;exports.getFormattedTableNameForQuery=r.getFormattedTableNameForQuery;exports.getQualifiedTableName=r.getQualifiedTableName;exports.getSql=r.getSql;exports.invalidateToken=r.invalidateToken;exports.isBooleanDataType=r.isBooleanDataType;exports.isColumnInSqlGen=r.isColumnInSqlGen;exports.isDateDataType=r.isDateDataType;exports.isNumberDataType=r.isNumberDataType;exports.isTextDataType=r.isTextDataType;exports.resolveDataType=r.resolveDataType;exports.resolveDatamodelName=r.resolveDatamodelName;exports.useCurrentActiveCard=r.useCurrentActiveCard;exports.useCurrentCardConfig=r.useCurrentCardConfig;exports.useCurrentSheetActiveCards=r.useCurrentSheetActiveCards;exports.useDashboardActions=r.useDashboardActions;exports.useDashboardStore=r.useDashboardStore;exports.useEditorActions=r.useEditorActions;exports.useEditorStore=r.useEditorStore;exports.ResourceManagementPanel=z.ResourceManagementPanel;exports.DEFAULT_CALENDAR_CONTEXT=B.DEFAULT_CALENDAR_CONTEXT;exports.DEFAULT_SEMANTIC_DOMAIN_ACCESS=B.DEFAULT_SEMANTIC_DOMAIN_ACCESS;exports.useDebouncedDirtyCheck=q.useDebouncedDirtyCheck;exports.AdvancedModeToggle=D.AdvancedModeToggle;exports.DashboardControlsSettings=D.DashboardControlsSettings;exports.DashboardFilterControlsButton=D.DashboardFilterControlsButton;exports.ExportNotificationItem=D.ExportNotificationItem;exports.ExportNotificationList=D.ExportNotificationList;exports.NotificationBell=D.NotificationBell;exports.UnsavedChangesAlert=D.UnsavedChangesAlert;exports.VisualEditingControls=D.VisualEditingControls;exports.useExportPolling=D.useExportPolling;exports.useExportRecovery=D.useExportRecovery;exports.normalizeDashboardForDirtyCheck=O.normalizeDashboardForDirtyCheck;exports.serializeDashboardForDirtyCheck=O.serializeDashboardForDirtyCheck;exports.AlertDetailPageEmbedded=J;exports.Combobox=$;exports.ScheduleDashboard=G;exports.TenantQuotaPage=Z;exports.Visual=V;exports.useAlertBacktest=K;exports.useExposePrintState=Y;exports.usePristineSnapshotInitializer=H;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/index-XYIIY48z.js"),y=require("./chunks/common-types-C73-Ud1-.js"),U=require("./chunks/calendar-preferences-dialog-BzpQ5u4h.js"),t=require("react/jsx-runtime"),r=require("./chunks/switch-DPaKnsb8.js"),m=require("react"),z=require("./chunks/resource-management-panel-CAxXzMdi.js"),L=require("./types/index.cjs"),q=require("./chunks/use-debounced-dirty-check-XHSwAefL.js");require("react-dom");require("./chunks/index-DRlMUglg.js");const A=require("./chunks/dashboard-filter-controls-launcher-CMXpudFJ.js"),B=require("./chunks/normalize-dashboard-for-dirty-check-BXRUMVb2.js");function Q(s){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const o in s)if(o!=="default"){const l=Object.getOwnPropertyDescriptor(s,o);Object.defineProperty(a,o,l.get?l:{enumerable:!0,get:()=>s[o]})}}return a.default=s,Object.freeze(a)}const P=Q(m);function V(s){const{displayPreferences:a,cardId:o,...l}=s,i={...l,id:s.dashboardId};return t.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:t.jsxs(e.SemaphorContextProvider,{dashboardProps:i,children:[t.jsx(e.SemaphorReadyIndicator,{componentType:"visual",componentId:s.cardId}),t.jsx(e.UXProvider,{appearance:s.appearance,children:t.jsx(e.DisplayPreferencesProvider,{displayPreferences:a,children:t.jsx(e.Container,{type:"visual",cardId:o,...i,children:t.jsx(W,{cardId:o})})})})]})})}function W({cardId:s}){const a=r.useDashboardStore(i=>{var u;return(u=i.dashboard)==null?void 0:u.sheets}),{card:o,frame:l}=m.useMemo(()=>{const i=a==null?void 0:a.flatMap(d=>d.frames),u=i==null?void 0:i.flatMap(d=>d==null?void 0:d.cards),h=u==null?void 0:u.find(d=>(d==null?void 0:d.id)===s),n=i==null?void 0:i.find(d=>{var x;return(x=d==null?void 0:d.cards)==null?void 0:x.find(C=>(C==null?void 0:C.id)===s)});return{card:h,frame:n}},[a,s]);return!o||!l?t.jsx(e.FallbackVisual,{error:new Error("Card not found"),resetErrorBoundary:()=>{},customerFacingMessage:`Card not found with ID: ${s}`}):t.jsx("main",{className:"flex h-full grow flex-col",children:t.jsx(e.ErrorBoundary,{FallbackComponent:({error:i,resetErrorBoundary:u})=>t.jsx(e.FallbackVisual,{error:i,resetErrorBoundary:u,customerFacingMessage:"Error creating visual. Please try again."}),children:t.jsx(e.DashboardCard,{card:o,frame:l})})})}function H(s,a,o,l){m.useEffect(()=>{s&&!o&&a&&l(e.cloneDeep(a))},[s,o,a,l])}function $({name:s,items:a,value:o,onChange:l,isLoading:i,isError:u,refetch:h,className:n,icon:d,showNone:x=!1}){const C=P.useRef(null),[b,D]=P.useState(!1),[N,v]=P.useState("100%"),S=x?[...a||[],{id:"none",name:"None"}]:a;P.useLayoutEffect(()=>{C.current&&v(C.current.offsetWidth)},[]);function _(){var p;return i?"Loading...":u?"Error":o?(p=a==null?void 0:a.find(j=>j.id===o))==null?void 0:p.name:`Select ${s}`}function R(p,j){l(j),D(!1)}return t.jsxs(r.Popover,{open:b,onOpenChange:D,children:[t.jsx(r.PopoverTrigger,{asChild:!0,children:t.jsxs(r.Button,{ref:C,variant:"outline",role:"combobox","aria-expanded":b,className:r.cn("flex h-9 w-full justify-between",n),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[d&&t.jsx("div",{className:"mr-2",children:d}),t.jsx("span",{className:"max-w-[150px] overflow-hidden truncate text-ellipsis whitespace-nowrap",children:_()})]}),t.jsx(r.ChevronDown,{className:"size-4 opacity-50"})]})}),t.jsx(r.PopoverContent,{className:"w-full p-0",style:{minWidth:N},children:t.jsxs(e.Command,{children:[t.jsxs("div",{className:"flex h-9 items-center justify-between border-b pr-1",children:[t.jsx(e.CommandInput,{className:"h-9",placeholder:"Search..."}),t.jsx(e.IconButton,{className:"h-7",onClick:h,children:t.jsx(e.RefreshCw,{className:r.cn("size-3.5 opacity-50",i&&"animate-spin")})})]}),t.jsxs(e.CommandList,{children:[t.jsxs(e.CommandEmpty,{children:["No ",s==null?void 0:s.toLowerCase()," found."]}),t.jsx(e.CommandGroup,{children:S==null?void 0:S.map(p=>t.jsx(e.CommandItem,{className:"overflow-x-auto",value:p.name,onSelect:j=>R(j,p.id),children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(r.Check,{className:r.cn("size-4",o===p.id?"opacity-100":"opacity-0")}),t.jsx("div",{title:p.name,children:p.name})]})},p.id))})]})]})})]})}function G({triggerButtonClassName:s,variant:a="ghost"}){const[o,l]=m.useState(!1),i=r.useDashboardStore(h=>{var n;return(n=h.dashboard)==null?void 0:n.id}),u=r.useDashboardStore(h=>{var n;return(n=h.dashboard)==null?void 0:n.title});return i?t.jsxs(t.Fragment,{children:[t.jsx(e.IconButton,{tooltip:"Schedule Dashboard",className:r.cn("h-7 p-2",s),buttonProps:{variant:a},onClick:()=>l(!0),children:t.jsx(e.Clock,{className:"size-4"})}),t.jsx(e.EmailScheduleDialog,{open:o,onOpenChange:l,dashboardId:i,dashboardName:u})]}):null}function K(s){const{authToken:a,tokenProps:o}=e.useSemaphorContext();return e.useMutation({mutationFn:async l=>e.backtestAlert(o.apiServiceUrl,a.accessToken,s,l)})}function Y(s,a){m.useEffect(()=>(s&&a&&(window.__SEMAPHOR_PRINT_STATE__={...a}),()=>{s&&window.__SEMAPHOR_PRINT_STATE__&&delete window.__SEMAPHOR_PRINT_STATE__}),[s,a])}function I(s){if(!s)return"--";const a=new Date(s);return Number.isNaN(a.getTime())?"--":a.toLocaleString()}function X(s){var a;return((a=s.alertState)==null?void 0:a.currentState)==="FIRING"?"Signal surfaced":s.status==="ACTIVE"?"Watching":s.status==="PAUSED"?"Paused":s.status}function J({alertId:s,onBack:a}){var p,j,w,k;const{authToken:o,tokenProps:l}=e.useSemaphorContext(),{data:i,isLoading:u,refetch:h}=e.useAlertDetail(s),n=(i==null?void 0:i.alert)??null,[d,x]=m.useState([]),[C,b]=m.useState([]),[D,N]=m.useState(null),v=m.useCallback(async()=>{var g;const c=l==null?void 0:l.apiServiceUrl,f=o==null?void 0:o.accessToken;if(!c||!f||!s)return null;try{const T=await fetch(`${c}/v1/alerts/${s}/runs?limit=20`,{headers:{Authorization:`Bearer ${f}`}});if(T.ok){const F=await T.json(),E=Array.isArray(F.runs)?F.runs:[],M=D&&E.some(O=>O.id===D)?D:((g=E[0])==null?void 0:g.id)??null;return b(E),N(M),M}b([]),N(null)}catch{return b([]),N(null),null}return null},[s,o,D,l]),S=m.useCallback(async c=>{const f=l==null?void 0:l.apiServiceUrl,g=o==null?void 0:o.accessToken,T=c??D;if(!f||!g||!s||!T){x([]);return}try{const F=await fetch(`${f}/v1/alerts/${s}/runs/${T}/deliveries`,{headers:{Authorization:`Bearer ${g}`}});if(F.ok){const E=await F.json();x(Array.isArray(E.attempts)?E.attempts:[])}else x([])}catch{x([])}},[s,o,D,l]),_=m.useCallback(async()=>{await h();const c=await v();await S(c)},[S,v,h]);m.useEffect(()=>{v().catch(()=>{})},[v]),m.useEffect(()=>{S().catch(()=>{})},[S]);const R=m.useMemo(()=>{const c={};for(const f of d)c[f.channel]||(c[f.channel]=[]),c[f.channel].push(f);return c},[d]);return u?t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading signal detail..."}):n?t.jsxs("div",{className:"space-y-4 p-4",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[a&&t.jsx(r.Button,{variant:"outline",size:"sm",onClick:a,children:"Back"}),t.jsx("h2",{className:"text-lg font-semibold",children:n.name}),t.jsx(e.Badge,{variant:n.status==="ACTIVE"?"default":"secondary",children:X(n)}),((p=n.alertState)==null?void 0:p.currentState)&&t.jsx(e.Badge,{variant:n.alertState.currentState==="FIRING"?"destructive":"outline",children:n.alertState.currentState==="FIRING"?"Signal surfaced":"Stable"})]}),t.jsx(r.Button,{variant:"outline",size:"sm",onClick:()=>void _(),children:"Refresh"})]}),n.description&&t.jsx("p",{className:"text-sm text-muted-foreground",children:n.description}),t.jsxs("div",{className:"rounded-md border bg-muted/30 p-4 text-sm",children:[t.jsx("p",{className:"font-medium",children:"What changed"}),t.jsx("p",{className:"mt-1 text-muted-foreground",children:"Review the latest signal activity, then investigate the underlying dashboard context if you need more detail."})]}),t.jsxs("div",{className:"rounded-md border bg-background p-4 space-y-2",children:[t.jsx("h3",{className:"text-sm font-semibold",children:"Signal Watch"}),t.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:"Watching for:"})," ",e.formatSignalCondition(n.jobConfig.operator,n.jobConfig.threshold)]}),t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:"Severity:"})," ",n.jobConfig.severity]}),t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:"Last Evaluated:"})," ",I((j=n.alertState)==null?void 0:j.lastEvaluatedAt)]}),t.jsxs("div",{children:[t.jsx("span",{className:"text-muted-foreground",children:"Last Surfaced:"})," ",I((w=n.alertState)==null?void 0:w.lastTriggeredAt)]})]})]}),((k=n.deliveryConfig)==null?void 0:k.channels)&&n.deliveryConfig.channels.length>0&&t.jsxs("div",{className:"rounded-md border bg-background p-4 space-y-2",children:[t.jsx("h3",{className:"text-sm font-semibold",children:"Where It Surfaces"}),t.jsx("div",{className:"flex flex-wrap gap-2",children:n.deliveryConfig.channels.map(c=>t.jsx(e.Badge,{variant:"outline",children:c},c))})]}),C.length>0&&t.jsxs("div",{className:"rounded-md border bg-background p-4 space-y-3",children:[t.jsx("h3",{className:"text-sm font-semibold",children:"Recent Delivery Activity"}),C.length>1&&t.jsx("div",{className:"flex flex-wrap gap-2",children:C.map(c=>t.jsx(r.Button,{variant:c.id===D?"default":"outline",size:"sm",onClick:()=>N(c.id),children:I(c.scheduledFor)},c.id))}),Object.keys(R).length===0?t.jsx("p",{className:"text-sm text-muted-foreground",children:"No delivery attempts were recorded for this run."}):Object.entries(R).map(([c,f])=>t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"flex items-center gap-2",children:t.jsx(e.Badge,{variant:"secondary",className:"text-xs",children:c})}),t.jsx("div",{className:"overflow-hidden rounded border",children:t.jsxs("table",{className:"w-full text-xs",children:[t.jsx("thead",{className:"bg-muted/40",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Recipient"}),t.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Status"}),t.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Time"}),t.jsx("th",{className:"px-2 py-1 text-left font-medium",children:"Error"})]})}),t.jsx("tbody",{children:f.map(g=>t.jsxs("tr",{className:"border-t",children:[t.jsx("td",{className:"px-2 py-1",children:g.recipient}),t.jsx("td",{className:"px-2 py-1",children:t.jsx(e.Badge,{variant:g.status==="SENT"?"default":"destructive",className:"text-[10px]",children:g.status})}),t.jsx("td",{className:"px-2 py-1",children:I(g.createdAt)}),t.jsx("td",{className:"px-2 py-1 text-muted-foreground",children:g.error||"--"})]},g.id))})]})})]},c))]})]}):t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Signal not found."})}function Z(){var u,h;const{quotasQuery:s,usageQuery:a}=e.useAlertQuotas(),o=((u=s.data)==null?void 0:u.quotas)||[],l=((h=a.data)==null?void 0:h.usage)||[],i=new Map(l.map(n=>[n.tenantId||"org",n]));return t.jsxs("div",{className:"space-y-4 p-4",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h2",{className:"text-xl font-semibold",children:"Alert Quotas"}),t.jsx(r.Button,{variant:"outline",size:"sm",onClick:()=>{s.refetch(),a.refetch()},children:"Refresh"})]}),s.isLoading||a.isLoading?t.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading quota usage..."}):null,t.jsx("div",{className:"overflow-hidden rounded-lg border",children:t.jsxs("table",{className:"w-full text-sm",children:[t.jsx("thead",{className:"bg-muted/40",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Tenant"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Active Alerts"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Max Active"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Min Cadence"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Max Context Sources"})]})}),t.jsx("tbody",{children:o.map(n=>{const d=n.tenantId||"org",x=i.get(d);return t.jsxs("tr",{className:"border-t",children:[t.jsx("td",{className:"px-3 py-2",children:d}),t.jsx("td",{className:"px-3 py-2",children:(x==null?void 0:x.activeAlerts)??0}),t.jsx("td",{className:"px-3 py-2",children:n.policy.maxActiveAlerts}),t.jsxs("td",{className:"px-3 py-2",children:[n.policy.minCadenceMinutes," min"]}),t.jsx("td",{className:"px-3 py-2",children:n.policy.maxContextSources})]},d)})})]})})]})}exports.AlertManagementPage=e.AlertManagementPage;exports.AlertWizardDialog=e.AlertWizardDialog;exports.AlertsApiError=e.AlertsApiError;exports.CardAlertIndicator=e.CardAlertIndicator;exports.CardSummary=e.CardSummary;exports.Dashboard=e.Dashboard;exports.DashboardExportDialog=e.DashboardExportDialog;exports.DashboardWC=e.DashboardWC;exports.EmailScheduleDialog=e.EmailScheduleDialog;exports.ExportError=e.ExportError;exports.ResourceType=e.ResourceType;exports.SemaphorContextProvider=e.SemaphorContextProvider;exports.SemaphorDataProvider=e.SemaphorQueryClient;exports.SemaphorQueryClient=e.SemaphorQueryClient;exports.ShareDialog=e.ShareDialog;exports.SummaryCard=e.SummaryCard;exports.Surfboard=e.DashboardPlus;exports.backtestAlert=e.backtestAlert;exports.cancelExport=e.cancelExport;exports.cloneDeep=e.cloneDeep;exports.createAlert=e.createAlert;exports.createExport=e.createExport;exports.deleteAlert=e.deleteAlert;exports.downloadDocumentPdf=e.downloadDocumentPdf;exports.downloadPdf=e.downloadPdf;exports.formatFileSize=e.formatFileSize;exports.getAlert=e.getAlert;exports.getAlertContextSources=e.getAlertContextSources;exports.getAlertHistory=e.getAlertHistory;exports.getAlertQuotaUsage=e.getAlertQuotaUsage;exports.getAlertRunDeliveries=e.getAlertRunDeliveries;exports.getAlertRunSteps=e.getAlertRunSteps;exports.getAlertRuns=e.getAlertRuns;exports.getAlertState=e.getAlertState;exports.getDownloadUrl=e.getDownloadUrl;exports.getExportStatus=e.getExportStatus;exports.getExports=e.getExports;exports.isExportComplete=e.isExportComplete;exports.isExportInProgress=e.isExportInProgress;exports.listAlertQuotas=e.listAlertQuotas;exports.listAlerts=e.listAlerts;exports.previewAlertDeliverable=e.previewAlertDeliverable;exports.triggerAlertNow=e.triggerAlertNow;exports.updateAlert=e.updateAlert;exports.updateAlertContextSources=e.updateAlertContextSources;exports.updateAlertQuota=e.updateAlertQuota;exports.useActiveExports=e.useActiveExports;exports.useAddNewFrame=e.useAddNewFrame;exports.useAlertActions=e.useAlertActions;exports.useAlertDeliveries=e.useAlertDeliveries;exports.useAlertDetail=e.useAlertDetail;exports.useAlertDraft=e.useAlertDraft;exports.useAlertFilters=e.useAlertFilters;exports.useAlertHistory=e.useAlertHistory;exports.useAlertQuotas=e.useAlertQuotas;exports.useAlertRuns=e.useAlertRuns;exports.useAlertState=e.useAlertState;exports.useAlertStore=e.useAlertStore;exports.useAlertWizard=e.useAlertWizard;exports.useAlerts=e.useAlerts;exports.useAlertsBootstrap=e.useAlertsBootstrap;exports.useAlertsById=e.useAlertsById;exports.useAlertsForCard=e.useAlertsForCard;exports.useCard=e.useCard;exports.useCardAlertMap=e.useCardAlertMap;exports.useCardSummary=e.useCardSummary;exports.useDashboardById=e.useDashboardById;exports.useDashboardQuery=e.useDashboardQuery;exports.useDashboardSummary=e.useDashboardSummary;exports.useDataColumns=e.useDataColumns;exports.useDateFilterHook=e.useDateFilterHook;exports.useEditorAside=e.useEditorAside;exports.useExportActions=e.useExportActions;exports.useExportStore=e.useExportStore;exports.useInProgressExportsCount=e.useInProgressExportsCount;exports.useManagementStore=e.useManagementStore;exports.useResourceManagement=e.useResourceManagement;exports.useSelectedAlertId=e.useSelectedAlertId;exports.useTextFilterHook=e.useTextFilterHook;exports.CALCULATED_FIELD_ENTITY_MARKER=y.CALCULATED_FIELD_ENTITY_MARKER;exports.CONTROL_CARD_DEFAULT_VALUE=y.CONTROL_CARD_DEFAULT_VALUE;exports.DATE_FORMAT_VALUES=y.DATE_FORMAT_VALUES;exports.EMPTY_SELECTION=y.EMPTY_SELECTION;exports.PivotMarkerEnum=y.PivotMarkerEnum;exports.getFieldRuntimeColumnName=y.getFieldRuntimeColumnName;exports.hasCalculatedFieldMarker=y.hasCalculatedFieldMarker;exports.hasCalculatedFormulaInputs=y.hasCalculatedFormulaInputs;exports.isCalculatedDimension=y.isCalculatedDimension;exports.isCalculatedField=y.isCalculatedField;exports.isCalculatedMetric=y.isCalculatedMetric;exports.CalendarPreferencesDialog=U.CalendarPreferencesDialog;exports.createEmptyKpiConfig=r.createEmptyKpiConfig;exports.createSqlGenConfig=r.createSqlGenConfig;exports.emitDashboardLoad=r.emitDashboardLoad;exports.emitDashboardUnload=r.emitDashboardUnload;exports.fmt=r.fmt;exports.getColumnDataType=r.getColumnDataType;exports.getFilterValueType=r.getFilterValueType;exports.getFormattedTableNameForQuery=r.getFormattedTableNameForQuery;exports.getQualifiedTableName=r.getQualifiedTableName;exports.getSql=r.getSql;exports.invalidateToken=r.invalidateToken;exports.isBooleanDataType=r.isBooleanDataType;exports.isColumnInSqlGen=r.isColumnInSqlGen;exports.isDateDataType=r.isDateDataType;exports.isNumberDataType=r.isNumberDataType;exports.isTextDataType=r.isTextDataType;exports.resolveDataType=r.resolveDataType;exports.resolveDatamodelName=r.resolveDatamodelName;exports.useCurrentActiveCard=r.useCurrentActiveCard;exports.useCurrentCardConfig=r.useCurrentCardConfig;exports.useCurrentSheetActiveCards=r.useCurrentSheetActiveCards;exports.useDashboardActions=r.useDashboardActions;exports.useDashboardStore=r.useDashboardStore;exports.useEditorActions=r.useEditorActions;exports.useEditorStore=r.useEditorStore;exports.ResourceManagementPanel=z.ResourceManagementPanel;exports.DEFAULT_CALENDAR_CONTEXT=L.DEFAULT_CALENDAR_CONTEXT;exports.DEFAULT_SEMANTIC_DOMAIN_ACCESS=L.DEFAULT_SEMANTIC_DOMAIN_ACCESS;exports.useDebouncedDirtyCheck=q.useDebouncedDirtyCheck;exports.AdvancedModeToggle=A.AdvancedModeToggle;exports.DashboardControlsSettings=A.DashboardControlsSettings;exports.DashboardFilterControlsButton=A.DashboardFilterControlsButton;exports.DashboardFilterControlsLauncher=A.DashboardFilterControlsLauncher;exports.DocumentControlsSettings=A.DocumentControlsSettings;exports.ExportNotificationItem=A.ExportNotificationItem;exports.ExportNotificationList=A.ExportNotificationList;exports.NotificationBell=A.NotificationBell;exports.UnsavedChangesAlert=A.UnsavedChangesAlert;exports.VisualEditingControls=A.VisualEditingControls;exports.useExportPolling=A.useExportPolling;exports.useExportRecovery=A.useExportRecovery;exports.normalizeDashboardForDirtyCheck=B.normalizeDashboardForDirtyCheck;exports.serializeDashboardForDirtyCheck=B.serializeDashboardForDirtyCheck;exports.AlertDetailPageEmbedded=J;exports.Combobox=$;exports.ScheduleDashboard=G;exports.TenantQuotaPage=Z;exports.Visual=V;exports.useAlertBacktest=K;exports.useExposePrintState=Y;exports.usePristineSnapshotInitializer=H;