react-semaphor 0.1.459 → 0.1.461

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 (114) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +32 -32
  3. package/dist/brand-studio/index.cjs +1 -1
  4. package/dist/brand-studio/index.js +4 -4
  5. package/dist/briefings/index.cjs +1 -1
  6. package/dist/briefings/index.js +4 -4
  7. package/dist/chunks/{analyze-result-contract-BbRJ-C06.js → analyze-result-contract-DROq4vgY.js} +1 -1
  8. package/dist/chunks/{analyze-result-contract-LPDNldic.cjs → analyze-result-contract-DSGoFuXQ.cjs} +1 -1
  9. package/dist/chunks/canonical-result-keys-CEQefvdO.js +33 -0
  10. package/dist/chunks/canonical-result-keys-Cb96edol.cjs +1 -0
  11. package/dist/chunks/{common-types-H51FLKB7.js → common-types-BHVKgxRR.js} +1 -1
  12. package/dist/chunks/{common-types-C57kJ59w.cjs → common-types-BcV9PD9D.cjs} +1 -1
  13. package/dist/chunks/{dashboard-briefing-launcher-ClCj98sq.js → dashboard-briefing-launcher-3owMxX5K.js} +60 -61
  14. package/dist/chunks/{dashboard-briefing-launcher-DHtEouuH.cjs → dashboard-briefing-launcher-xuGrw8H3.cjs} +2 -2
  15. package/dist/chunks/{dashboard-controls-B8gsKlxc.js → dashboard-controls-B4GvjGr1.js} +44 -45
  16. package/dist/chunks/{dashboard-controls-VRShl9J0.cjs → dashboard-controls-Bpm_xOXQ.cjs} +1 -1
  17. package/dist/chunks/dashboard-filter-value-compatibility-KXIyvbhc.js +677 -0
  18. package/dist/chunks/dashboard-filter-value-compatibility-UapptYnn.cjs +1 -0
  19. package/dist/chunks/dashboard-input-contract-BkRFQ7Tq.cjs +1 -0
  20. package/dist/chunks/{dashboard-date-comparison-definition-DC3ekV2S.js → dashboard-input-contract-D5dxTWJ5.js} +41 -25
  21. package/dist/chunks/{dashboard-json-i_Auue_K.js → dashboard-json-DzyxoBp-.js} +13 -14
  22. package/dist/chunks/dashboard-json-yLM01xK4.cjs +1 -0
  23. package/dist/chunks/{edit-dashboard-visual-DWWyT55u.cjs → edit-dashboard-visual-1T278Nr_.cjs} +28 -28
  24. package/dist/chunks/{edit-dashboard-visual-B3JF0fe4.js → edit-dashboard-visual-nwSasO_j.js} +880 -894
  25. package/dist/chunks/{editor-action-buttons-BTlCsP63.cjs → editor-action-buttons-CX1Pken3.cjs} +2 -2
  26. package/dist/chunks/{editor-action-buttons-C9x3nGnb.js → editor-action-buttons-Dqw0asfA.js} +28 -28
  27. package/dist/chunks/index-B1qplNxl.cjs +1392 -0
  28. package/dist/chunks/{index-BS2-ZZGf.js → index-DazD5k0F.js} +45362 -42931
  29. package/dist/chunks/{index-BIFLI8ul.js → index-De_7nrwb.js} +10 -10
  30. package/dist/chunks/index-DjjKJPDy.cjs +4 -0
  31. package/dist/chunks/{matrix-result-contract-CofATICL.js → matrix-result-contract-BTpPuHOc.js} +88 -104
  32. package/dist/chunks/matrix-result-contract-ZRNfeIbI.cjs +1 -0
  33. package/dist/chunks/{pivot-header-presentation-B9nXXKlW.cjs → pivot-header-presentation-BijPbP33.cjs} +1 -1
  34. package/dist/chunks/{pivot-header-presentation-D-0jvUwn.js → pivot-header-presentation-DW0gKG8g.js} +2 -2
  35. package/dist/chunks/{pivot-result-identity-Bb4EixVN.cjs → pivot-result-identity-DxHtiKVj.cjs} +1 -1
  36. package/dist/chunks/{pivot-result-identity-DU1v-5Xk.js → pivot-result-identity-Z9tN2tEV.js} +1 -1
  37. package/dist/chunks/{pivot-result-lifecycle-DTLRuDEW.cjs → pivot-result-lifecycle-BXzIlQVu.cjs} +1 -1
  38. package/dist/chunks/{pivot-result-lifecycle-CHWEGU2o.js → pivot-result-lifecycle-g2U-vzQb.js} +7 -7
  39. package/dist/chunks/{raw-temporal-contract-BtjH_G-d.cjs → raw-temporal-contract-DfAvqNMo.cjs} +1 -1
  40. package/dist/chunks/{raw-temporal-contract-CxncLze5.js → raw-temporal-contract-UtAqoOZO.js} +1 -1
  41. package/dist/chunks/{report-preferences-dialog-BK0yAJnQ.cjs → report-preferences-dialog-DKPyjiCt.cjs} +1 -1
  42. package/dist/chunks/{report-preferences-dialog-BDpkcUtz.js → report-preferences-dialog-Dv3vCCFt.js} +6 -6
  43. package/dist/chunks/{report-runtime-context-DqxS4wbi.cjs → report-runtime-context-C0NfLPfc.cjs} +1 -1
  44. package/dist/chunks/{report-runtime-context-SM6YO61_.js → report-runtime-context-CNncA3VD.js} +11 -11
  45. package/dist/chunks/{saved-temporal-bucket-format-CFfWXRl9.cjs → saved-temporal-bucket-format-3QKveR3v.cjs} +1 -1
  46. package/dist/chunks/{saved-temporal-bucket-format-SGAV0ivR.js → saved-temporal-bucket-format-Dd2eixTH.js} +11 -11
  47. package/dist/chunks/switch-DBZsEV0U.cjs +138 -0
  48. package/dist/chunks/{switch-DQR-Va05.js → switch-kPUJEC1A.js} +6615 -5219
  49. package/dist/chunks/{temporal-bucket-5UYEotyQ.js → temporal-bucket-C85rmFmC.js} +4 -4
  50. package/dist/chunks/temporal-bucket-authoring-1fZuPAVb.js +653 -0
  51. package/dist/chunks/temporal-bucket-authoring-BK1UhYpD.cjs +1 -0
  52. package/dist/chunks/{temporal-bucket-contract-D5d-xEl3.js → temporal-bucket-contract-DXXNZssK.js} +1 -1
  53. package/dist/chunks/{temporal-bucket-contract-D2-93DGr.cjs → temporal-bucket-contract-xFkvboaw.cjs} +1 -1
  54. package/dist/chunks/{temporal-bucket-DHY1y9lq.cjs → temporal-bucket-pMfghsLX.cjs} +1 -1
  55. package/dist/chunks/{token-types-GbxRUozo.js → token-types-BLxc7UwR.js} +1 -1
  56. package/dist/chunks/{token-types-D7CaaI80.cjs → token-types-BYYO109W.cjs} +1 -1
  57. package/dist/chunks/{update-policy-hednMF-0.js → update-policy-CB8XJIoY.js} +1 -1
  58. package/dist/chunks/{update-policy-BmiOd0PB.cjs → update-policy-DMjjGjQY.cjs} +1 -1
  59. package/dist/chunks/{validators-DEmd8Sin.js → validators-DVd8s3qY.js} +416 -350
  60. package/dist/chunks/validators-dJlwubP4.cjs +1 -0
  61. package/dist/dashboard/index.cjs +1 -1
  62. package/dist/dashboard/index.js +2 -2
  63. package/dist/dashboard-authoring/index.cjs +3 -3
  64. package/dist/dashboard-authoring/index.js +328 -311
  65. package/dist/data-app-builder/index.cjs +1 -1
  66. package/dist/data-app-builder/index.js +2 -2
  67. package/dist/data-app-codegen/index.cjs +1 -1
  68. package/dist/data-app-codegen/index.js +2 -2
  69. package/dist/data-app-codegen-node/index.cjs +1 -1
  70. package/dist/data-app-codegen-node/index.js +3 -3
  71. package/dist/data-app-sdk/index.cjs +1 -1
  72. package/dist/data-app-sdk/index.js +55 -55
  73. package/dist/data-app-sdk-adapters/index.cjs +1 -1
  74. package/dist/data-app-sdk-adapters/index.js +61 -56
  75. package/dist/data-app-sdk-validation/index.cjs +1 -1
  76. package/dist/data-app-sdk-validation/index.js +9 -9
  77. package/dist/format-utils/index.cjs +1 -1
  78. package/dist/format-utils/index.js +15 -15
  79. package/dist/index.cjs +1 -1
  80. package/dist/index.js +154 -155
  81. package/dist/report-runtime-context/index.cjs +1 -1
  82. package/dist/report-runtime-context/index.js +2 -2
  83. package/dist/style.css +1 -1
  84. package/dist/surfboard/index.cjs +1 -1
  85. package/dist/surfboard/index.js +3 -3
  86. package/dist/types/analytics-protocol.d.ts +16 -8
  87. package/dist/types/briefings.d.ts +95 -13
  88. package/dist/types/dashboard-assistant.d.ts +11 -6
  89. package/dist/types/dashboard-authoring.d.ts +257 -19
  90. package/dist/types/dashboard.d.ts +109 -14
  91. package/dist/types/data-app-builder.d.ts +11 -6
  92. package/dist/types/data-app-codegen-node.d.ts +16 -8
  93. package/dist/types/data-app-codegen.d.ts +16 -8
  94. package/dist/types/data-app-sdk-adapters.d.ts +17 -11
  95. package/dist/types/data-app-sdk-validation.d.ts +17 -11
  96. package/dist/types/data-app-sdk.d.ts +17 -11
  97. package/dist/types/index.cjs +1 -1
  98. package/dist/types/index.js +4 -4
  99. package/dist/types/main.d.ts +225 -20
  100. package/dist/types/shared.d.ts +95 -13
  101. package/dist/types/surfboard.d.ts +109 -14
  102. package/dist/types/types.d.ts +109 -14
  103. package/package.json +1 -1
  104. package/dist/chunks/canonical-result-keys-BA0HCP4e.cjs +0 -1
  105. package/dist/chunks/canonical-result-keys-D6avdjpA.js +0 -467
  106. package/dist/chunks/dashboard-date-comparison-definition-Ces4alFm.cjs +0 -1
  107. package/dist/chunks/dashboard-json-BhvPMpZA.cjs +0 -1
  108. package/dist/chunks/index-DHF-2AqS.cjs +0 -1392
  109. package/dist/chunks/index-k8tEp0ys.cjs +0 -4
  110. package/dist/chunks/matrix-result-contract-zamd9euI.cjs +0 -1
  111. package/dist/chunks/switch-f3TuZNLr.cjs +0 -138
  112. package/dist/chunks/temporal-bucket-authoring-K1kE6R_z.js +0 -222
  113. package/dist/chunks/temporal-bucket-authoring-o3Emn05L.cjs +0 -1
  114. package/dist/chunks/validators-BDYprKI9.cjs +0 -1
@@ -1,4 +1,4 @@
1
- "use strict";const e=require("react/jsx-runtime"),x=require("react"),s=require("./index-DHF-2AqS.cjs"),n=require("./switch-f3TuZNLr.cjs"),je=require("./layout-grid-xm8pqtx0.cjs"),K=require("./x-B6ghREd2.cjs"),V=require("./editor-action-buttons-BTlCsP63.cjs"),ye=require("./saved-temporal-bucket-format-CFfWXRl9.cjs");require("./validators-BDYprKI9.cjs");require("./analyze-result-contract-LPDNldic.cjs");require("../value-format-preferences/index.cjs");const Ue=require("./search-BqqhaMx9.cjs"),Oe=require("./mouse-pointer-2-DX4A_XZw.cjs"),we=require("./pivot-header-presentation-B9nXXKlW.cjs");require("./index-ByFbacH7.cjs");require("./temporal-bucket-authoring-o3Emn05L.cjs");require("./canonical-result-keys-BA0HCP4e.cjs");require("./color-CyB5o13F.cjs");require("react-dom");const X=require("./index-k8tEp0ys.cjs");/**
1
+ "use strict";const e=require("react/jsx-runtime"),x=require("react"),s=require("./index-B1qplNxl.cjs"),n=require("./switch-DBZsEV0U.cjs"),je=require("./layout-grid-xm8pqtx0.cjs"),K=require("./x-B6ghREd2.cjs"),V=require("./editor-action-buttons-CX1Pken3.cjs"),ye=require("./saved-temporal-bucket-format-3QKveR3v.cjs");require("./validators-dJlwubP4.cjs");require("./analyze-result-contract-DSGoFuXQ.cjs");require("../value-format-preferences/index.cjs");const Ue=require("./search-BqqhaMx9.cjs"),Oe=require("./mouse-pointer-2-DX4A_XZw.cjs"),we=require("./pivot-header-presentation-BijPbP33.cjs");require("./index-ByFbacH7.cjs");require("./temporal-bucket-authoring-BK1UhYpD.cjs");require("./color-CyB5o13F.cjs");require("react-dom");const X=require("./index-DjjKJPDy.cjs");/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -23,4 +23,4 @@
23
23
  *
24
24
  * This source code is licensed under the ISC license.
25
25
  * See the LICENSE file in the root directory of this source tree.
26
- */const qe=K.createLucideIcon("Newspaper",[["path",{d:"M4 22h16a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H8a2 2 0 0 0-2 2v16a2 2 0 0 1-2 2Zm0 0a2 2 0 0 1-2-2v-9c0-1.1.9-2 2-2h2",key:"7pis2x"}],["path",{d:"M18 14h-8",key:"sponae"}],["path",{d:"M15 18h-5",key:"95g1m2"}],["path",{d:"M10 6h8v4h-8V6Z",key:"smlsk5"}]]);function He(){return e.jsx("div",{className:"space-y-1.5 py-1",children:[...Array(5)].map((t,r)=>e.jsxs("div",{className:"flex animate-pulse items-start gap-3 rounded-xl border border-transparent px-2.5 py-2.5",children:[e.jsx("div",{className:"mt-0.5 h-4 w-4 flex-shrink-0 rounded bg-muted/60"}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"h-4 w-3/5 rounded bg-muted/60"}),e.jsx("div",{className:"h-3 w-4/5 rounded bg-muted/40"})]})]},r))})}function We({open:t,onOpenChange:r,onSubmit:l,isCreating:o}){const[a,d]=x.useState(""),[h,p]=x.useState("");x.useEffect(()=>{t||(d(""),p(""))},[t]);const c=()=>{a.trim()&&l({title:a,description:h})},u=i=>{r(i)};return e.jsx(s.Dialog,{open:t,onOpenChange:u,children:e.jsxs(s.DialogContent,{showCloseButton:!1,className:"flex max-w-lg grid-cols-none flex-col gap-0 overflow-hidden rounded-[6px] border-border/60 p-0 shadow-lg",children:[e.jsxs("div",{className:"flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(je.LayoutGrid,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[e.jsx(s.DialogTitle,{className:"truncate text-[13px] font-medium leading-none tracking-normal",children:"New library visual"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium uppercase leading-none tracking-[0.08em] text-muted-foreground",children:"Visual"})]})]}),e.jsx(n.Button,{size:"xs",variant:"ghost",className:"w-7 px-0 text-muted-foreground hover:text-foreground",onClick:()=>u(!1),"aria-label":"Close",disabled:o,children:e.jsx(K.X,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"space-y-3 px-4 py-3",children:[e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Create a saved visual that can be reused across dashboards."}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(n.Label,{htmlFor:"visual-title",className:"text-[12px]",children:"Name"}),e.jsx(n.Input,{id:"visual-title",size:"sm",placeholder:"Untitled visual",value:a,onChange:i=>d(i.target.value),disabled:o,onKeyDown:i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),c())}})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(n.Label,{htmlFor:"visual-description",className:"text-[12px]",children:"Description"}),e.jsx(n.Input,{id:"visual-description",size:"sm",placeholder:"Optional",value:h,onChange:i=>p(i.target.value),disabled:o})]})]}),e.jsxs("div",{className:"flex shrink-0 justify-end gap-2 border-t border-border/60 px-4 py-2.5",children:[e.jsx(n.Button,{size:"xs",variant:"outline",onClick:()=>u(!1),disabled:o,children:"Cancel"}),e.jsx(n.Button,{size:"xs",onClick:c,disabled:!a.trim()||o,children:o?e.jsxs(e.Fragment,{children:[e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Creating..."]}):"Create library visual"})]})]})})}function Ee(t){return t?new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Unknown"}function Ae(t,r){var o;const l=(o=t.ownership.createdBy)==null?void 0:o.type;return l==="tenant"||l==="organization"&&r}function Ce(t,r){var l,o;return Ae(t,r)?((l=t.ownership.createdBy)==null?void 0:l.name)||((o=t.createdByTenantUserRel)==null?void 0:o.name)||t.lastModifiedBy||"Unknown":"Organization"}function Ge(t,r){return Ce(t,r).split(/\s+/).filter(Boolean).slice(0,2).map(o=>o.charAt(0).toUpperCase()).join("")||"?"}function Xe(t){const r=(t||"").toLowerCase();return r.includes("table")?n.Table2:r.includes("pie")||r.includes("donut")?s.ChartPie:r.includes("line")?s.ChartLine:r.includes("bar")?n.ChartColumn:je.LayoutGrid}function Ke({visual:t}){const r=t.ownership.status==="public"?"Public":t.ownership.status==="shared"||t.ownership.sharedCount>0?"Shared":"Private";return e.jsx("span",{className:"inline-flex items-center rounded-[4px] border border-border/60 px-1.5 py-px text-[11px] text-muted-foreground",children:r})}function Qe({open:t,onOpenChange:r}){const[l,o]=x.useState(""),[a,d]=x.useState(new Set),[h,p]=x.useState(!1),[c,u]=x.useState(null),[i,g]=x.useState(null),[m,f]=x.useState(!1),[w,y]=x.useState(null),[E,B]=x.useState(null),D=()=>{d(new Set),u(null),g(null),f(!1),y(null)},b=()=>{r(!1),D()},{selectVisual:S}=s.useManagementActions(),{handleAddLibraryVisual:A,handleEditLibraryVisual:T}=V.useVisualUtils(),{isConsoleMode:v}=s.useDashboardPreferences(),{resources:j,isLoading:L,isError:I,createResource:$,updateResource:k,deleteResourceAsync:M,duplicateResource:_,isCreating:oe,isDeleting:q}=s.useVisualManagement(void 0,C=>{p(!1),C&&(S(C),T(C),b())}),{startUpdating:fe,stopUpdating:ie,isUpdating:ge}=s.useResourceUpdateState(),W=j,U=x.useMemo(()=>{const C=l.trim().toLowerCase();return C?W.filter(F=>{var R,Y,J;return((R=F.title)==null?void 0:R.toLowerCase().includes(C))||((Y=F.description)==null?void 0:Y.toLowerCase().includes(C))||((J=F.kind)==null?void 0:J.toLowerCase().includes(C))}):W},[l,W]),Q=x.useMemo(()=>W.filter(C=>a.has(C.id)),[a,W]),ee=Q.filter(C=>C.permissions.canDelete),te=Q.filter(C=>C.permissions.canShare),le=U.length>0&&U.every(C=>a.has(C.id)),ue=U.some(C=>a.has(C.id)),se=C=>{const F=new Set(a);C(F),d(F)},ne=C=>{se(F=>{F.has(C)?F.delete(C):F.add(C)})},G=()=>{d(C=>{const F=new Set(C);return le?U.forEach(R=>F.delete(R.id)):U.forEach(R=>F.add(R.id)),F})},ce=async C=>{(await A(C)).success&&b()},O=async()=>{const C=Q;if(C.length===0)return;let F=!1;for(const R of C)if(!(await A(R)).success){F=!0;break}F||b()},z=C=>{T(C),b()},Z=C=>{B(C),_(C,{onSettled:()=>B(null)})},ae=()=>{if(ee.length===0){s.ue.error("Select a visual you can delete");return}y(null),f(!0)},he=async()=>{const C=w?[w]:ee;try{for(const F of C)await M(F.id);d(F=>{const R=new Set(F);return C.forEach(Y=>R.delete(Y.id)),R}),f(!1),y(null)}catch{}},be=()=>{if(Q.length!==1){s.ue.error("Select one visual to share");return}const[C]=Q;if(!C.permissions.canShare){s.ue.error("You do not have permission to share this visual");return}u(C)},de=({title:C,description:F})=>{if(!i)return;const R={};if(C!==i.title&&(R.title=C),(i.description||"")!==F&&(R.description=F),Object.keys(R).length===0){g(null);return}const Y=Object.keys(R),J=Y.length===1?Y[0]:void 0;fe(i.id,J),k({resourceId:i.id,data:R},{onSuccess:()=>{ie(i.id,J),g(null)},onError:()=>{ie(i.id,J)}})},re=C=>{r(C),C||D()},H=w?1:ee.length;return e.jsxs(e.Fragment,{children:[e.jsx(s.Dialog,{open:t,onOpenChange:re,children:e.jsxs(s.DialogContent,{showCloseButton:!1,className:"flex max-h-[80vh] w-[min(72rem,calc(100vw-2rem))] max-w-none grid-cols-none flex-col gap-0 overflow-hidden rounded-[6px] border-border/60 p-0 shadow-lg",children:[e.jsxs("div",{className:"flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(n.Table2,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[e.jsx(s.DialogTitle,{className:"truncate text-[13px] font-medium leading-none tracking-normal",children:"Visuals library"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium uppercase leading-none tracking-[0.08em] text-muted-foreground",children:"Add to dashboard"})]})]}),e.jsx(n.Button,{size:"xs",variant:"ghost",className:"w-7 px-0 text-muted-foreground hover:text-foreground",onClick:()=>re(!1),"aria-label":"Close visuals library",children:"×"})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border/60 px-3 py-2",children:[e.jsxs("div",{className:"relative min-w-[12rem] flex-1 md:max-w-md",children:[e.jsx(Ue.Search,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:l,onChange:C=>o(C.target.value),placeholder:"Search visuals...",className:"h-7 w-full rounded-control border border-input bg-background pl-7 pr-2 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-ring focus:outline-none","aria-label":"Search visuals"})]}),e.jsxs(n.Button,{size:"xs",variant:"outline",className:"ml-auto",onClick:()=>p(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"New library visual"]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:L?e.jsx("div",{className:"p-3",children:e.jsx(He,{})}):I?e.jsx("div",{className:"flex flex-col items-center gap-2 px-4 py-12 text-center",children:e.jsx("p",{className:"text-[13px] text-destructive",children:"Failed to load visuals"})}):U.length===0?e.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-12 text-center",children:[e.jsx(je.LayoutGrid,{className:"h-5 w-5 text-muted-foreground/60"}),e.jsx("p",{className:"text-[13px] font-medium",children:l?"No visuals found":"No visuals yet"}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:l?"Try a different search.":"Create a saved visual to add it here."})]}):e.jsx(Ye,{visuals:U,selectedIds:a,allFilteredSelected:le,someFilteredSelected:ue,onSelectAll:G,onToggleSelection:ne,onAddVisual:ce,onOpenVisual:z,onEditDetails:g,onShareVisual:u,onDeleteVisual:C=>{y(C),f(!0)},onDuplicateVisual:Z,duplicatingId:E,isDeleting:q,isConsoleMode:v})}),e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border/60 px-3 py-2",children:[e.jsx("div",{className:"flex min-w-0 items-center gap-1.5",children:a.size>0&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-[12px] text-muted-foreground",children:[e.jsx("span",{className:"font-medium tabular-nums text-foreground",children:a.size})," ","selected"]}),e.jsx(n.Button,{size:"xs",variant:"ghost",onClick:()=>d(new Set),children:"Clear"}),e.jsxs(n.Button,{size:"xs",variant:"outline",onClick:be,disabled:Q.length!==1||te.length!==1,children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),e.jsxs(n.Button,{size:"xs",variant:"outline",className:"text-destructive hover:text-destructive",onClick:ae,disabled:ee.length===0,children:[e.jsx(s.Trash2,{className:"h-3.5 w-3.5"}),"Delete ",ee.length||a.size]})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(n.Button,{size:"xs",variant:"outline",onClick:()=>re(!1),children:"Close"}),e.jsxs(n.Button,{size:"xs",onClick:O,disabled:a.size===0,children:[e.jsx(n.Check,{className:"h-3.5 w-3.5"}),a.size===0?"Add to dashboard":`Add ${a.size} visual${a.size===1?"":"s"}`]})]})]})]})}),e.jsx(We,{open:h,onOpenChange:p,onSubmit:$,isCreating:oe}),c&&e.jsx(s.ShareDialog,{resource:c,resourceType:s.ResourceType.VISUAL,onClose:()=>u(null)}),i&&e.jsx(s.ResourceEditDialog,{open:!!i,resourceLabel:"Visual",initialTitle:i.title||"",initialDescription:i.description||"",onClose:()=>g(null),onSave:de,isSaving:ge(i.id)}),e.jsx(s.AlertDialog,{open:m,onOpenChange:C=>{!C&&q||(f(C),C||y(null))},children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsxs(s.AlertDialogTitle,{children:["Delete ",H," visual",H===1?"":"s","?"]}),e.jsx(s.AlertDialogDescription,{children:"This cannot be undone. Visuals already added to dashboards may need to be removed from those dashboards separately."})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{disabled:q,children:"Cancel"}),e.jsxs(s.AlertDialogAction,{onClick:C=>{C.preventDefault(),he()},disabled:q||H===0,children:[q?e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(s.Trash2,{className:"h-3.5 w-3.5"}),q?"Deleting...":"Delete"]})]})]})})]})}function Ye({visuals:t,selectedIds:r,allFilteredSelected:l,someFilteredSelected:o,onSelectAll:a,onToggleSelection:d,onAddVisual:h,onOpenVisual:p,onEditDetails:c,onShareVisual:u,onDeleteVisual:i,onDuplicateVisual:g,duplicatingId:m,isDeleting:f,isConsoleMode:w}){return e.jsxs("div",{className:"min-w-[48rem]",children:[e.jsxs("div",{className:"grid h-9 grid-cols-[2.5rem_minmax(14rem,1.8fr)_minmax(10rem,1fr)_8rem_7rem_5rem_5.5rem] items-center border-b border-border/60 px-3 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:[e.jsx(s.Checkbox,{checked:l?!0:o?"indeterminate":!1,onCheckedChange:a,"aria-label":"Select all visuals"}),e.jsx("span",{children:"Name"}),e.jsx("span",{children:"Created by"}),e.jsx("span",{children:"Updated"}),e.jsx("span",{children:"Visibility"}),e.jsx("span",{className:"text-right",children:"Shared"}),e.jsx("span",{className:"text-right",children:"Actions"})]}),t.map(y=>e.jsx(Ze,{visual:y,selected:r.has(y.id),onToggleSelection:d,onAddVisual:h,onOpenVisual:p,onEditDetails:c,onShareVisual:u,onDeleteVisual:i,onDuplicateVisual:g,duplicatingId:m,isDeleting:f,isConsoleMode:w},y.id))]})}function Ze({visual:t,selected:r,onToggleSelection:l,onAddVisual:o,onOpenVisual:a,onEditDetails:d,onShareVisual:h,onDeleteVisual:p,onDuplicateVisual:c,duplicatingId:u,isDeleting:i,isConsoleMode:g}){var w;const m=Xe(t.kind),f=()=>{o(t)};return e.jsxs("div",{className:n.cn("group grid min-h-12 grid-cols-[2.5rem_minmax(14rem,1.8fr)_minmax(10rem,1fr)_8rem_7rem_5rem_5.5rem] items-center border-b border-border/50 px-3 text-[13px] hover:bg-muted/50",r&&"bg-muted/70"),children:[e.jsx("div",{children:e.jsx(s.Checkbox,{checked:r,onCheckedChange:()=>l(t.id),"aria-label":`Select ${t.title||"visual"}`})}),e.jsxs("button",{type:"button",className:"flex min-w-0 items-center gap-2 rounded-[4px] text-left outline-none focus-visible:ring-1 focus-visible:ring-ring",onClick:f,"aria-label":`Add ${t.title||"visual"} to dashboard`,children:[e.jsx(m,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate font-medium text-foreground",title:t.title||"Untitled Visual",children:t.title||"Untitled Visual"}),((w=t.description)==null?void 0:w.trim())&&e.jsx("div",{className:"truncate text-[11px] text-muted-foreground",title:t.description,children:t.description})]})]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("div",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-muted text-[9px] font-medium text-muted-foreground",children:Ge(t,g)}),e.jsx("span",{className:"truncate text-muted-foreground",children:Ce(t,g)})]}),e.jsx("span",{className:"text-muted-foreground",children:Ee(t.updatedAt)}),e.jsx(Ke,{visual:t}),e.jsx("span",{className:"text-right tabular-nums text-muted-foreground",children:t.ownership.sharedCount>0?t.ownership.sharedCount:"—"}),e.jsx(Je,{visual:t,onOpenVisual:a,onEditDetails:d,onShareVisual:h,onDeleteVisual:p,onDuplicateVisual:c,duplicatingId:u,isDeleting:i,isConsoleMode:g})]})}function Je({visual:t,onOpenVisual:r,onEditDetails:l,onShareVisual:o,onDeleteVisual:a,onDuplicateVisual:d,duplicatingId:h,isDeleting:p,isConsoleMode:c}){return e.jsxs("div",{className:"flex items-center justify-end gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",onClick:u=>u.stopPropagation(),children:[e.jsx(n.Button,{size:"xs",variant:"ghost",className:"w-7 px-0",onClick:()=>r(t),"aria-label":"Edit visual",children:e.jsx(s.PenLine,{className:"h-3.5 w-3.5"})}),e.jsxs(s.DropdownMenu,{modal:!1,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(n.Button,{size:"xs",variant:"ghost",className:"w-7 px-0","aria-label":"More actions",children:e.jsx(s.Ellipsis,{className:"h-3.5 w-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"z-[60] w-44 rounded-[6px] border-border/60 p-1 shadow-sm",children:[e.jsxs(s.DropdownMenuItem,{onClick:()=>r(t),children:[e.jsx(s.PenLine,{className:"h-3.5 w-3.5"}),"Edit visual"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>d(t.id),disabled:h===t.id,children:[h===t.id?e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(s.Copy,{className:"h-3.5 w-3.5"}),h===t.id?"Duplicating...":"Duplicate"]}),t.permissions.canEdit&&e.jsxs(s.DropdownMenuItem,{onClick:()=>l(t),children:[e.jsx(s.PenLine,{className:"h-3.5 w-3.5"}),"Edit details"]}),t.permissions.canShare&&e.jsxs(s.DropdownMenuItem,{onClick:()=>o(t),children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),t.permissions.canDelete&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{className:"text-destructive focus:bg-destructive/10 focus:text-destructive",onClick:()=>a(t),disabled:p,children:[e.jsx(s.Trash2,{className:"h-3.5 w-3.5"}),p?"Deleting...":"Delete"]})]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs("div",{className:"space-y-1 px-2 py-1.5 text-[11px] text-muted-foreground",children:[Ae(t,c)&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(s.User,{className:"h-3 w-3"}),e.jsx("span",{className:"truncate",children:Ce(t,c)})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(s.Calendar,{className:"h-3 w-3"}),e.jsx("span",{children:Ee(t.updatedAt)})]})]})]})]})]})}function et({open:t,onOpenChange:r,isLibraryVisual:l,currentVisualName:o,isSaving:a=!1,destinationMode:d="both",onConfirm:h}){const[p,c]=x.useState(l&&o?`Copy of ${o}`:o||""),[u,i]=x.useState("");x.useEffect(()=>{t&&(c(l&&o?`Copy of ${o}`:o||""),i(""))},[t,l,o]);const g=!!p.trim(),m=d==="local"?{saveToLibrary:!1,saveToCurrentDashboard:!0,badgeType:"local",description:"Creates a local copy on the current dashboard.",actionLabel:"Add to Dashboard (Local)"}:d==="library"?{saveToLibrary:!0,saveToCurrentDashboard:!1,badgeType:"library",description:"Creates a reusable visual in Visual Library.",actionLabel:"Save as Library Visual"}:{saveToLibrary:!0,saveToCurrentDashboard:!0,badgeType:"linked",description:"Creates a new library visual and adds a linked copy to this dashboard.",actionLabel:"Save Copy as Linked Visual"},f=()=>{!g||a||h({name:p.trim(),description:u.trim()||void 0,saveToLibrary:m.saveToLibrary,saveToCurrentDashboard:m.saveToCurrentDashboard})};return e.jsx(s.Dialog,{open:t,onOpenChange:r,children:e.jsxs(s.DialogContent,{className:"sm:max-w-[500px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsxs(s.DialogTitle,{className:"flex items-center gap-2",children:[e.jsx("span",{children:"Save Visual As"}),m.badgeType!=="local"&&e.jsx(V.VisualBadge,{type:m.badgeType,showLabel:!0,className:"px-2 py-0.5"})]}),e.jsx(s.DialogDescription,{children:m.description})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(n.Label,{htmlFor:"name",children:"Name"}),e.jsx(n.Input,{id:"name",value:p,onChange:w=>c(w.target.value),placeholder:"Enter visual name",disabled:a})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(n.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(s.Textarea,{id:"description",value:u,onChange:w=>i(w.target.value),placeholder:"Enter visual description",rows:3,disabled:a})]})]}),e.jsxs(s.DialogFooter,{children:[e.jsx(n.Button,{variant:"outline",onClick:()=>r(!1),disabled:a,children:"Cancel"}),e.jsxs(n.Button,{onClick:f,disabled:!g||a,children:[a&&e.jsx(n.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),m.actionLabel]})]})]})})}function tt(){const[t,r]=x.useState(!1),[l,o]=x.useState(!1),[a,d]=x.useState(null),[h,p]=x.useState(null),c=n.useEditorStore(v=>v.frame),u=n.useEditorStore(v=>v.card),i=s.useSelectedVisual(),g=n.useDashboardStore(v=>v.selectedSheetId),m=n.useDashboardStore(v=>v.dashboard),{getUpdatedFrame:f}=V.useVisualUtils(),{selectVisual:w}=s.useManagementActions(),{addFrame:y,setSelectedFrameId:E,setIsVisualEditing:B}=n.useDashboardActions(),D=s.useResolveExistingFrameSemanticExecutionPayload(),b=!!(c!=null&&c.visualId),S=(()=>{var v,j;return((v=c==null?void 0:c.cards)==null?void 0:v.length)===1&&((j=c.cards[0])!=null&&j.title)?c.cards[0].title:i!=null&&i.title?i.title:(u==null?void 0:u.title)||"Untitled Visual"})(),A=s.useCreateVisualWithFrame(v=>{v!=null&&v.id&&(w(v),l&&a&&h&&g&&(async()=>{try{const j={...a,id:ye.v4(),visualId:v.id};y(g,j,{position:"end",semanticExecutionPayload:h}),E(j.id),o(!1),d(null),p(null),B(!1)}catch(j){console.error("Failed to promote semantic metadata for saved visual:",j),s.ue.error(j instanceof Error?j.message:"Failed to prepare semantic metadata for the saved visual")}})(),r(!1))});return{saveAsDialogOpen:t,setSaveAsDialogOpen:r,handleSaveAs:async v=>{if(!g){s.ue.error("No sheet selected");return}const j=f(),L=n.getDynamicFrameSaveIssue(j);if(L){s.ue.error(L);return}const $=j.cards.length===1?{...j,cards:j.cards.map(k=>({...k,title:v.name}))}:j;if(v.saveToLibrary){let k=null;if(v.saveToCurrentDashboard)try{k=await D($,{previousFrame:n.findDashboardFrameById(m,$.id)})}catch(_){console.error("Failed to prepare semantic metadata before saving visual:",_),s.ue.error(_ instanceof Error?_.message:"Failed to prepare semantic metadata for the saved visual");return}o(v.saveToCurrentDashboard),d($),p(k);const M={title:v.name,description:v.description,frameObject:$,isPrivate:!1};A.mutate(M)}else if(v.saveToCurrentDashboard){const k={...$,id:ye.v4(),visualId:void 0};try{const M=await D($,{previousFrame:n.findDashboardFrameById(m,$.id)});y(g,k,{position:"end",semanticExecutionPayload:M}),E(k.id),s.ue.success("Visual saved to dashboard"),r(!1),B(!1)}catch(M){console.error("Failed to save visual to dashboard:",M),s.ue.error(M instanceof Error?M.message:"Failed to prepare semantic metadata for the visual")}}},isLibraryVisual:b,currentVisualName:S,isSaving:A.isPending}}function st(t={}){const{isInspectionMode:r}=s.useDashboardInteractionMode(),l=n.useEditorStore(k=>k.frame),o=n.useEditorStore(k=>k.editorContext),a=s.useManagementStore(k=>k.selectedVisual),d=n.useDashboardStore(k=>k.selectedFrameId),h=n.useDashboardStore(k=>k.selectedSheetId),p=n.useDashboardStore(k=>k.dashboard),{setIsVisualEditing:c,updateFrame:u}=n.useDashboardActions(),[i,g]=x.useState(!1),[m,f]=x.useState("both"),w=s.useResolveExistingFrameSemanticExecutionPayload(),y=(o==null?void 0:o.type)==="documentSection",E=!!(l!=null&&l.visualId||a!=null&&a.id),B=!!(l!=null&&l.visualId&&d),D=E&&!B,{saveAsDialogOpen:b,setSaveAsDialogOpen:S,handleSaveAs:A,isLibraryVisual:T,currentVisualName:v,isSaving:j}=tt(),{getUpdatedFrame:L}=V.useVisualUtils();if(r)return e.jsxs(e.Fragment,{children:[e.jsx(V.EditorAcceptButton,{className:"rounded-control",variant:"default"}),e.jsx(V.EditorCancelButton,{})]});if(y)return e.jsxs(e.Fragment,{children:[e.jsx(V.EditorAcceptButton,{className:"rounded-control",variant:"default"}),e.jsx(V.EditorCancelButton,{})]});const I=async()=>{if(!h){s.ue.error("No sheet selected");return}if(i)return;g(!0);const k=L(),M=n.getDynamicFrameSaveIssue(k);if(M){g(!1),s.ue.error(M);return}const _={...k,visualId:void 0},oe=n.findDashboardFrameById(p,_.id);try{const q=await w(_,{previousFrame:oe});u(h,_,{semanticExecutionPayload:q})}catch(q){console.error("Failed to apply local semantic metadata:",q),g(!1),s.ue.error(q instanceof Error?q.message:"Failed to prepare semantic metadata for this visual");return}setTimeout(()=>{g(!1),s.ue.success("Changes applied. Visual is now local to this dashboard"),c(!1)},300)},$=k=>{f(k),S(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"inline-flex items-center overflow-hidden rounded-control",children:[!E&&e.jsx(V.EditorAcceptButton,{className:"!rounded-none",variant:"default"}),E&&D&&e.jsx(V.VisualSaveButton,{className:"!rounded-none",variant:"default"}),E&&B&&e.jsx(V.VisualSaveAndApplyButton,{className:"!rounded-none"}),e.jsxs(s.DropdownMenu,{modal:!1,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(n.Button,{variant:"default",size:"xs",className:"w-7 !rounded-none border-l border-primary-foreground/20 px-0","aria-label":"Open visual save options",disabled:j||i,children:e.jsx(K.ChevronDown,{className:"h-3.5 w-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"min-w-[220px] rounded-control border border-border/60 p-1 shadow-sm",children:[B&&e.jsxs(e.Fragment,{children:[e.jsxs(s.DropdownMenuItem,{onClick:I,disabled:i,children:[e.jsx(n.Check,{className:"h-3.5 w-3.5"}),i?"Applying...":"Apply Locally"]}),e.jsx(s.DropdownMenuSeparator,{})]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>$("local"),disabled:j,children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Add to Dashboard (Local)"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>$("library"),disabled:j,children:[e.jsx(V.Library,{className:"h-3.5 w-3.5"}),"Save as Library Visual"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>$("both"),disabled:j,children:[e.jsx(V.Link2,{className:"h-3.5 w-3.5"}),"Save Copy as Linked Visual"]})]})]})]}),e.jsx(V.EditorCancelButton,{}),e.jsx(et,{open:b,onOpenChange:k=>{j||S(k)},isLibraryVisual:T,currentVisualName:v,isSaving:j,destinationMode:m,onConfirm:A})]})}function rt({className:t}){const r=n.useEditorStore(u=>u.isDevMode),l=n.useDashboardStore(u=>u.isVisualEditing),{setIsDevMode:o}=n.useEditorActions(),{config:a}=x.useContext(s.SemaphorContext).tokenProps,d=(a==null?void 0:a.showAdvancedMode)!==!1;if(!l||!d)return null;const h=r?Oe.MousePointer2:s.CodeXml,p=r?"Visual editor":"SQL editor",c=r?"Switch to visual editor":"Switch to SQL editor";return e.jsxs("button",{type:"button","aria-label":c,title:c,onClick:()=>o(!r),className:n.cn("inline-flex h-7 items-center gap-1.5 rounded-control border border-input bg-background px-2 text-[12px] font-medium text-foreground transition-colors hover:bg-muted/40 focus-visible:border-ring focus-visible:outline-none",t),children:[e.jsx(h,{className:"h-3 w-3 text-muted-foreground"}),p]})}function nt({open:t,onOpenChange:r,onSave:l,onDiscard:o,isSaving:a,title:d="Unsaved changes",description:h="You have unsaved changes to this dashboard. What would you like to do?",cancelLabel:p="Cancel",discardLabel:c="Discard",saveLabel:u="Save"}){const i=g=>{!g&&a||r(g)};return e.jsx(s.AlertDialog,{open:t,onOpenChange:i,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:d}),e.jsx(s.AlertDialogDescription,{children:h})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(n.Button,{type:"button",size:"xs",onClick:o,disabled:a,variant:"ghost",className:"mr-auto text-muted-foreground hover:bg-destructive/10 hover:text-destructive focus-visible:bg-destructive/10 focus-visible:text-destructive",children:c}),e.jsx(s.AlertDialogCancel,{disabled:a,children:p}),e.jsx(n.Button,{type:"button",size:"xs",onClick:l,disabled:a,children:a?e.jsxs(e.Fragment,{children:[e.jsx(n.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Saving..."]}):u})]})]})})}const at=1e4,ot=15e3,it=3e4,lt=3e4,ct=12e4,De=2*60*60*1e3;function dt(t){const r=Date.now()-t.getTime();return r<lt?at:r<ct?ot:it}function ut(){const{authToken:t,tokenProps:r}=s.useSemaphorContext(),l=s.useExportStore(m=>m.activeExports),[o,a]=x.useState(typeof document<"u"?!document.hidden:!0),d=x.useRef(null),h=x.useRef(!1),p=x.useRef(void 0),c=r==null?void 0:r.apiServiceUrl,u=t==null?void 0:t.accessToken,i=x.useCallback(()=>{const m=s.useExportStore.getState().activeExports;return Array.from(m.values()).filter(f=>s.isExportInProgress(f.status))},[]);x.useEffect(()=>{if(typeof document>"u")return;const m=()=>{a(!document.hidden)};return document.addEventListener("visibilitychange",m),()=>{document.removeEventListener("visibilitychange",m)}},[]);const g=x.useCallback(async()=>{if(!c||!u){h.current=!1;return}const m=i();if(m.length===0){h.current=!1;return}const f=Date.now(),w=m.filter(b=>f-b.startedAt.getTime()>De);if(w.length>0){const{updateExport:b}=s.useExportStore.getState().actions;for(const S of w)b(S.id,{status:"failed",error:"Export timed out. Please try again or contact support.",lastUpdatedAt:new Date})}const y=m.filter(b=>f-b.startedAt.getTime()<=De);if(y.length===0){h.current=!1;return}const E=await Promise.allSettled(y.map(async b=>{try{const S=await s.getExportStatus(c,u,b.id);let A;if(S.status==="completed")try{A=await s.getDownloadUrl(c,u,b.id)}catch(T){console.error(`[useExportPolling] Failed to get download URL for ${b.id}:`,T)}return{id:b.id,status:S.status,progress:S.progress,completedChunks:S.completedChunks,completedAt:S.completedAt?new Date(S.completedAt):void 0,lastUpdatedAt:new Date,fileSize:S.fileSize,error:S.error,downloadUrl:A}}catch(S){return console.error(`[useExportPolling] Failed to poll export ${b.id}:`,S),null}})),{updateExport:B}=s.useExportStore.getState().actions;for(const b of E)b.status==="fulfilled"&&b.value&&B(b.value.id,b.value);const D=i();if(D.length>0&&!document.hidden){const b=D.reduce((A,T)=>T.startedAt<A?T.startedAt:A,D[0].startedAt),S=dt(b);d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{var A;(A=p.current)==null||A.call(p)},S)}else h.current=!1},[c,u,i]);return x.useEffect(()=>{p.current=g},[g]),x.useEffect(()=>{var f;i().length>0&&o&&!h.current&&(h.current=!0,(f=p.current)==null||f.call(p))},[l,o,i]),x.useEffect(()=>{var f;const m=i();o&&m.length>0&&!h.current&&(h.current=!0,(f=p.current)==null||f.call(p))},[o,i]),x.useEffect(()=>{!o&&d.current&&(clearTimeout(d.current),d.current=null,h.current=!1)},[o]),x.useEffect(()=>()=>{d.current&&(clearTimeout(d.current),d.current=null)},[]),{isPolling:h.current,isTabVisible:o,inProgressCount:i().length}}function ht(){const{authToken:t,tokenProps:r}=s.useSemaphorContext(),l=s.useExportStore(p=>p.activeExports),{addExport:o}=s.useExportActions(),a=x.useRef(!1),d=r==null?void 0:r.apiServiceUrl,h=t==null?void 0:t.accessToken;x.useEffect(()=>{if(a.current||!d||!h)return;(async()=>{try{const{exports:c}=await s.getExports(d,h,{status:["pending","processing","chunking","compacting","completed","failed"],limit:20});for(const u of c){if(l.has(u.id))continue;const i=u.totalChunks?Math.round(u.completedChunks/u.totalChunks*100):0;let g;if(u.status==="completed")try{g=await s.getDownloadUrl(d,h,u.id)}catch(f){console.error(`[useExportRecovery] Failed to get download URL for ${u.id}:`,f)}const m={id:u.id,status:u.status,progress:i,title:mt(u),totalRows:u.totalRows,totalChunks:u.totalChunks,completedChunks:u.completedChunks,startedAt:new Date(u.createdAt),lastUpdatedAt:new Date,completedAt:u.completedAt?new Date(u.completedAt):void 0,fileSize:u.fileSize,error:u.error,expiresAt:new Date(u.expiresAt),downloadUrl:g};o(m)}a.current=!0}catch(c){console.error("[useExportRecovery] Failed to recover exports:",c),a.current=!0}})()},[d,h,o,l])}function mt(t){return t.title?t.title:s.isExportInProgress(t.status)?"Export in progress...":t.status==="completed"?"Export completed":t.status==="failed"?"Export failed":"Export"}function ke({export:t,onRemove:r}){const l=()=>{t.downloadUrl&&window.open(t.downloadUrl,"_blank")},o=p=>{p.stopPropagation(),r==null||r(t.id)},a=()=>{switch(t.status){case"completed":return e.jsx(s.CircleCheck,{className:"mt-0.5 h-5 w-5 shrink-0 text-green-600"});case"failed":return e.jsx($e,{className:"mt-0.5 h-5 w-5 shrink-0 text-destructive"});default:return e.jsx(n.LoaderCircle,{className:"text-foreground-muted mt-0.5 h-5 w-5 shrink-0 animate-spin"})}},d=s.isExportInProgress(t.status),h=(()=>{switch(t.status){case"pending":return"Queued...";case"processing":return"Processing...";case"chunking":return"Processing...";case"compacting":return"Finalizing...";default:return"Processing..."}})();return e.jsxs("div",{className:"group p-4 transition-colors hover:bg-muted/50",children:[e.jsxs("div",{className:"mb-2 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-3",children:[a(),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"mb-1 truncate text-sm font-medium",children:t.title}),t.status==="completed"&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("span",{children:[t.totalRows.toLocaleString()," rows"]}),t.fileSize&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsx("span",{children:s.formatFileSize(t.fileSize)})]})]}),d&&e.jsx("div",{className:"text-xs text-muted-foreground",children:h}),t.status==="failed"&&e.jsx("div",{className:"line-clamp-2 text-xs text-destructive",children:t.error||"Export failed"})]})]}),e.jsx(n.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:o,"aria-label":"Remove notification",children:e.jsx(K.X,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"ml-8",children:[t.status==="completed"&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:we.formatDistanceToNow(t.startedAt,{addSuffix:!0})}),t.downloadUrl&&e.jsxs(n.Button,{size:"sm",variant:"outline",className:"h-8 bg-transparent",onClick:l,children:[e.jsx(s.Download,{className:"mr-1.5 h-3.5 w-3.5"}),"Download"]})]}),d&&e.jsxs("div",{children:[e.jsx(s.Progress,{value:t.progress,className:"h-1.5"}),e.jsxs("span",{className:"mt-1 block text-xs text-muted-foreground",children:[t.progress,"% complete"]})]}),t.status==="failed"&&e.jsx("span",{className:"text-xs text-muted-foreground",children:we.formatDistanceToNow(t.startedAt,{addSuffix:!0})})]})]})}function Be(){const{authToken:t,tokenProps:r}=s.useSemaphorContext(),l=s.useExportStore(y=>y.activeExports),{clearCompleted:o,removeExport:a,updateExport:d}=s.useExportActions(),[h,p]=x.useState(!1),[c,u]=x.useState(!1),i=Array.from(l.values()).sort((y,E)=>E.startedAt.getTime()-y.startedAt.getTime()),g=i.some(y=>y.status==="completed"||y.status==="failed"),m=x.useCallback(async()=>{const y=r==null?void 0:r.apiServiceUrl,E=t==null?void 0:t.accessToken;if(!(!y||!E)){p(!0);try{const B=Array.from(l.values());await Promise.all(B.map(async D=>{try{const b=await s.getExportStatus(y,E,D.id);let S;if(b.status==="completed")try{S=await s.getDownloadUrl(y,E,D.id)}catch(A){console.error(`Failed to get download URL for ${D.id}:`,A)}d(D.id,{status:b.status,progress:b.progress,completedChunks:b.completedChunks,completedAt:b.completedAt?new Date(b.completedAt):void 0,lastUpdatedAt:new Date,fileSize:b.fileSize,error:b.error,downloadUrl:S})}catch(b){console.error(`Failed to refresh export ${D.id}:`,b)}}))}finally{p(!1)}}},[l,t==null?void 0:t.accessToken,r==null?void 0:r.apiServiceUrl,d]),f=x.useCallback(async()=>{const y=r==null?void 0:r.apiServiceUrl,E=t==null?void 0:t.accessToken;if(!y||!E){o();return}u(!0);try{const B=i.filter(b=>b.status==="completed"||b.status==="failed"),D=await Promise.allSettled(B.map(async b=>(await s.cancelExport(y,E,b.id),b.id)));for(const b of D)b.status==="fulfilled"?a(b.value):console.error("Failed to delete export:",b.reason)}finally{u(!1)}},[i,r==null?void 0:r.apiServiceUrl,t==null?void 0:t.accessToken,o,a]),w=x.useCallback(async y=>{const E=r==null?void 0:r.apiServiceUrl,B=t==null?void 0:t.accessToken;if(E&&B)try{await s.cancelExport(E,B,y),a(y);return}catch(D){console.error(`Failed to cancel export ${y}:`,D)}a(y)},[r==null?void 0:r.apiServiceUrl,t==null?void 0:t.accessToken,a]);return i.length===0?e.jsxs("div",{className:"p-6 text-center",children:[e.jsx(Ne,{className:"mx-auto mb-2 h-8 w-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No active exports"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Large exports will appear here"})]}):e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ne,{className:"h-5 w-5 text-muted-foreground"}),e.jsx("h4",{className:"font-semibold",children:"Exports"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(n.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:m,disabled:h,title:"Refresh status",children:e.jsx(s.RefreshCw,{className:`h-4 w-4 ${h?"animate-spin":""}`})}),g&&e.jsx(n.Button,{variant:"ghost",size:"sm",className:"h-7 px-2 text-sm",onClick:f,disabled:c,children:c?"Clearing...":"Clear all"})]})]}),e.jsx("div",{className:"max-h-[350px] overflow-y-auto",children:e.jsx("div",{className:"divide-y",children:i.map(y=>e.jsx(ke,{export:y,onRemove:w},y.id))})})]})}function xt({variant:t}){const r=s.useExportStore(c=>c.activeExports),l=s.useInProgressExportsCount(),o=r.size>0,a=Array.from(r.values()).some(c=>c.status==="completed"||c.status==="failed"),h=l>0?l>9?"9+":String(l):null,p=o;return e.jsxs(n.Popover,{children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:t??"ghost",size:"xs",className:"relative w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":"Export notifications",children:[e.jsx(s.Bell,{className:"h-3.5 w-3.5"}),p&&e.jsx("span",{className:`absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${h?"-right-0.5 -top-0.5 h-3.5 min-w-3.5 px-0.5 text-[9px] font-semibold":"right-1 top-1 h-1.5 w-1.5"}`,children:h})]})}),e.jsx(n.PopoverContent,{className:"w-80 p-0",align:"end",sideOffset:8,children:e.jsx(Be,{})})]})}function pt(t){if(t)return{renamed:t.type==="rename"?{oldId:t.oldId,newId:t.newId}:void 0,removedControlId:t.type==="remove"?t.controlId:void 0,cardBindingsById:t.type==="add"||t.type==="update"?t.cardBindingsById:void 0,affectedBindingControlIds:t.type==="add"||t.type==="update"?t.affectedBindingControlIds:void 0}}function Ie({open:t,onOpenChange:r,trigger:l,showTrigger:o=!0,initialMode:a="manage"}){const d=a==="create",{forceClose:h,handleOpenChange:p,isCreateFlowActive:c,preventPassiveDismissDuringCreate:u,resolvedOpen:i,setIsCreateFlowActive:g}=V.useCreateFlowOverlayState({open:t,onOpenChange:r,initialCreateFlowActive:a==="create",dismissMode:o?"passive":"explicit-only"}),m=n.useDashboardStore(j=>j.dashboard),{setDashboardControlsModel:f}=n.useDashboardActions(),{participants:w}=s.useDashboardStructuralParticipants(n.getDashboardCards(m)),y=Array.from(new Map(w.flatMap(j=>j.fieldChoices.map(L=>{var I;return[L.value,{option:L,target:(I=j.fieldTargetMap)==null?void 0:I[L.value]}]}))).values()),E=Array.from(new Map(w.flatMap(j=>j.metricChoices.map(L=>{var I;return[L.value,{option:L,target:(I=j.metricTargetMap)==null?void 0:I[L.value]}]}))).values()),B=n.collectDashboardControlIds({...m||{},controls:[]}),D=s.buildDashboardStructuralParticipantIdsByControlId(m),b=(j,L,I)=>{f(j,L,pt(I))},S=x.useCallback(()=>{if(d){h();return}g(!1)},[d,h,g]),A=e.jsx(V.ControlDefinitionListEditor,{scope:"dashboard",controls:m.controls||[],reservedControlIds:B,defaultValues:m.defaultControlValues||{},usageByControlId:s.buildDashboardControlUsageById(m),availableFieldChoices:y,availableMetricChoices:E,structuralParticipants:w,structuralParticipantIdsByControlId:D,initialCreateFlow:a==="create",onCreateFlowActiveChange:g,onCreateFlowComplete:S,onChange:b,emptyMessage:"No dashboard controls yet."}),T=c?"Add dashboard control":"Dashboard Controls",v=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Dashboard Controls"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),A]});return o?e.jsxs(n.Popover,{open:i,onOpenChange:p,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:l||e.jsxs(n.Button,{variant:"outline",className:"h-7 px-2",size:"sm",children:[e.jsx(n.SlidersHorizontal,{className:"mr-2 h-4 w-4"}),"Controls"]})}),e.jsx(n.PopoverContent,{className:"w-[620px] max-w-[95vw] space-y-4",align:"end",onEscapeKeyDown:u,onPointerDownOutside:u,children:v})]}):e.jsx(s.Dialog,{open:i,onOpenChange:p,children:e.jsxs(s.DialogContent,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:u,onPointerDownOutside:u,children:[e.jsxs(s.DialogHeader,{className:c?"space-y-0":void 0,children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:T}),e.jsx(s.DialogDescription,{className:c?"sr-only":"text-[13px]",children:c?"Configure and add a shared dashboard control.":"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),e.jsx("div",{className:"min-h-0 overflow-y-auto pr-1",children:A})]})})}const ft=["enum","multi_enum","text","number","boolean","date"];function Fe({open:t,onOpenChange:r,initialMode:l="manage"}){var v;const o=l==="create",{forceClose:a,handleOpenChange:d,isCreateFlowActive:h,preventPassiveDismissDuringCreate:p,resolvedOpen:c,setIsCreateFlowActive:u}=V.useCreateFlowOverlayState({open:t,onOpenChange:r,initialCreateFlowActive:l==="create",dismissMode:"explicit-only"}),i=n.useDashboardStore(j=>j.dashboard),g=n.useDashboardStore(j=>j.selectedSheetId),{setDashboardInputs:m}=n.useDashboardActions(),f=(v=i.sheets)==null?void 0:v.find(j=>j.id===g),w=(f==null?void 0:f.kind)==="document"&&!!f.document,y=x.useMemo(()=>w&&(f!=null&&f.document)?s.getDocumentSheetDashboardInputs(i,f.id):[],[i,w,f==null?void 0:f.document,f==null?void 0:f.id]),E=x.useMemo(()=>y.filter(j=>j.kind==="control"),[y]),B=x.useMemo(()=>E.map(j=>j.control),[E]),D=x.useMemo(()=>bt(B),[B]),b=x.useMemo(()=>gt(i),[i]),S=x.useCallback(()=>{if(o){a();return}u(!1)},[o,a,u]),A=x.useCallback((j,L,I)=>{!w||!(f!=null&&f.document)||m(jt({allInputs:i.inputs||[],documentSheetId:f.id,currentDocumentInputs:y,nextControls:j,nextDefaultValues:L,change:I}))},[i.inputs,y,w,f,m]);if(!w||!(f!=null&&f.document))return null;const T=h?"Add document control":"Document Controls";return e.jsx(s.Dialog,{open:c,onOpenChange:d,children:e.jsxs(s.DialogContent,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:p,onPointerDownOutside:p,children:[e.jsxs(s.DialogHeader,{className:h?"space-y-0":void 0,children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:T}),e.jsx(s.DialogDescription,{className:h?"sr-only":"text-[13px]",children:h?"Configure and add a document-local control input.":"Add document-local control inputs. They are stored on this document sheet and are not dashboard controls."})]}),e.jsx("div",{className:"min-h-0 overflow-y-auto pr-1",children:e.jsx(V.ControlDefinitionListEditor,{scope:"dashboard",controls:B,reservedControlIds:b,defaultValues:D,usageByControlId:{},availableFieldChoices:[],availableMetricChoices:[],structuralParticipants:[],structuralParticipantIdsByControlId:{},allowedControlTypes:ft,initialCreateFlow:l==="create",onCreateFlowActiveChange:u,onCreateFlowComplete:S,onChange:A,emptyMessage:"No document controls yet."})})]})})}function gt(t){return(t.controls||[]).map(r=>r.id)}function bt(t){const r={};for(const l of t)l.defaultValue!==void 0&&(r[l.id]=l.defaultValue);return r}function vt(t,r){return r?Object.prototype.hasOwnProperty.call(r,t.id)?{...t,defaultValue:r[t.id]}:t.defaultValue===void 0?t:{...t,defaultValue:void 0}:t.defaultValue===void 0?t:{...t,defaultValue:void 0}}function jt({allInputs:t,documentSheetId:r,currentDocumentInputs:l,nextControls:o,nextDefaultValues:a,change:d}){const h=new Map(o.map(m=>[m.id,vt(m,a)])),p=(d==null?void 0:d.type)==="rename"?{oldId:d.oldId,newId:d.newId}:null,c=new Set,u=[];for(const m of l){if(m.kind!=="control"){u.push(m);continue}const f=h.get(m.control.id)||((p==null?void 0:p.oldId)===m.control.id?h.get(p.newId):void 0);if(!f)continue;c.add(f.id);const w=s.createUniqueDashboardInputVariableNameFromName(f.id,[...t,...u].filter(E=>E.id!==m.id)),y=f.id===w?f:{...f,id:w};u.push({...m,label:y.label,variableName:w,requiredAtExecution:y.requiredAtExecution,control:y})}for(const m of h.values())c.has(m.id)||u.push(s.createDashboardControlInputFromControl({control:m,existingInputs:[...t,...u],sheetId:r}));const i=new Set(l.map(m=>m.id));return[...t.filter(m=>!i.has(m.id)),...u]}function Le({showFilters:t,onShowFiltersChange:r,pickerContent:l,settingsContent:o,size:a="default",className:d,primaryButtonClassName:h,secondaryButtonClassName:p,pickerContentClassName:c,settingsContentClassName:u}){const i=a==="toolbar",[g,m]=x.useState(!1),f=s.useSurfaceAppearance("interactive");return e.jsxs("div",{className:n.cn("relative inline-flex items-stretch overflow-hidden rounded-control border border-input bg-background",i?"h-8":"h-7",d),children:[e.jsxs(n.Popover,{open:t,onOpenChange:r,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"ghost",size:"xs",className:n.cn("h-full rounded-none border-0 bg-transparent pl-2.5 pr-2 shadow-none hover:bg-accent/50 data-[state=open]:bg-accent/60",h),children:[t?e.jsx(V.FilterX,{className:"h-3.5 w-3.5"}):e.jsx(s.Filter,{className:"h-3.5 w-3.5"}),"Filter"]})}),e.jsx(n.PopoverContent,{align:"end",sideOffset:6,className:n.cn("w-auto rounded-card border border-border/60 p-0 shadow-sm",c),style:f.contentStyle,children:l})]}),e.jsxs(n.Popover,{open:g,onOpenChange:m,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsx(n.Button,{variant:"ghost",size:"xs",className:n.cn("h-full w-7 rounded-none border-0 border-l border-border/60 bg-transparent px-0 shadow-none hover:bg-accent/50 data-[state=open]:bg-accent/60",p),"aria-label":"Filter and control actions",children:e.jsx(K.ChevronDown,{className:"h-3.5 w-3.5"})})}),e.jsx(n.PopoverContent,{align:"end",sideOffset:6,className:n.cn("w-auto rounded-card border border-border/60 p-0 shadow-sm",u),style:f.contentStyle,children:o(()=>m(!1))})]})]})}function Ct(){V.useSyncLegacyEditorState();const t=n.useDashboardStore(c=>c.selectedSheetId),r=n.useDashboardStore(c=>c.selectedFrameId),l=n.useDashboardStore(c=>c.dashboard),o=n.useDashboardStore(c=>c.actions.getSelectedFrame),{setSelectedFrameId:a}=n.useDashboardActions(),{setCard:d}=n.useEditorActions(),h=n.useEditorStore(c=>c.card.dataSource);return x.useEffect(()=>{var u,i;let c=o();if(!c){const g=(u=l==null?void 0:l.sheets)==null?void 0:u.find(f=>f.id===t),m=(i=g==null?void 0:g.frames)==null?void 0:i[0];m&&(a(m.id),c=m)}if(c){const g=c.cards.find(m=>m.id===c.activeCardId);g&&d(g)}},[o,t,r,l,a,d]),{hasEntities:!!(h!=null&&h.selectedEntities&&h.selectedEntities.length>0)}}function yt(){const t=n.useDashboardStore(c=>c.dashboard),r=n.useDashboardStore(c=>c.semanticExecutionPayload),l=n.useDashboardStore(c=>c.actions.addFilter),{hasEntities:o}=Ct(),{isLoading:a}=s.useFilterableFields(),d=x.useMemo(()=>n.getGlobalDateFilterCoverage(t,r),[t,r]),p=!n.getGlobalDateFilter(t.filters)&&d.hasEligibleCards&&!a;return e.jsxs("div",{className:"flex h-[520px] w-[400px] flex-col",children:[p&&e.jsx("div",{className:"border-b border-border/60 p-2",children:e.jsxs("button",{type:"button",onClick:()=>l(n.createDefaultGlobalDateFilter()),title:`Applies to ${d.eligibleCardCount} of ${d.totalCardCount} date-aware cards`,className:"flex w-full items-start gap-2 rounded-[4px] px-2 py-1.5 text-left outline-none transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-border",children:[e.jsx(_e,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"text-[12px] font-medium text-foreground",children:"Add global date filter"}),e.jsx("span",{className:"text-[11px] leading-[1.4] text-muted-foreground",children:"One date range across all date-aware cards."})]})]})}),!o&&e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-6 py-8 text-center",children:[e.jsx(s.Database,{className:"mb-3 h-10 w-10 text-muted-foreground/50"}),e.jsx("h3",{className:"mb-1 text-[13px] font-medium text-foreground",children:"No fields configured"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Configure a data source for this card to enable filtering."})]}),o&&e.jsx("div",{className:"flex flex-1 overflow-hidden",children:e.jsx(s.FilterableFieldsPanel,{context:"filter"})})]})}const Se=!1;function wt({onAddFilter:t,onAddControl:r,onManageControls:l,onDismiss:o}){const a=n.useDashboardStore(p=>p.dashboard.filterLayout),{setFilterLayout:d}=n.useDashboardActions();a!=null&&a.displayMode;const h=(a==null?void 0:a.toolbarWrap)??!1;return a==null||a.showDownloadButton,e.jsxs("div",{className:"w-[300px]",children:[e.jsxs("div",{className:"p-1",children:[e.jsx(ve,{icon:s.Filter,label:"Add filter",onClick:()=>{t(),o()}}),e.jsx(ve,{icon:n.SlidersHorizontal,label:"Add control",onClick:()=>{r(),o()}}),e.jsx(ve,{icon:s.Pencil,label:"Manage controls",onClick:()=>{l(),o()}})]}),e.jsx("div",{className:"border-t border-border/60"}),e.jsxs("div",{className:"space-y-1 p-2",children:[e.jsx("p",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Display"}),Se,e.jsx(Nt,{id:"filter-display-wrap",label:"Wrap to multiple lines",checked:h,onCheckedChange:p=>d({toolbarWrap:p===!0})}),Se]})]})}function ve({icon:t,label:r,onClick:l}){return e.jsxs("button",{type:"button",onClick:l,className:"flex w-full items-center gap-2 rounded-[4px] px-2 py-1.5 text-left text-[13px] text-foreground transition-colors hover:bg-muted/40",children:[e.jsx(t,{className:"h-3.5 w-3.5 text-muted-foreground"}),r]})}function Nt({id:t,label:r,checked:l,onCheckedChange:o}){return e.jsxs("div",{className:"flex items-center gap-2 rounded-[4px] px-1 py-1 transition-colors hover:bg-muted/40",children:[e.jsx(s.Checkbox,{id:t,checked:l,onCheckedChange:o}),e.jsx(n.Label,{htmlFor:t,className:"cursor-pointer text-[12px] font-normal leading-[1.3]",children:r})]})}function Dt({size:t,className:r,primaryButtonClassName:l,secondaryButtonClassName:o,pickerContentClassName:a,settingsContentClassName:d}){var T;const[h,p]=x.useState(null),c=n.useDashboardStore(v=>v.dashboard),u=n.useDashboardStore(v=>v.selectedSheetId),i=n.useDashboardStore(v=>v.showFilters),g=s.useAssistantLayoutStore(v=>v.setPanelOpen),m=n.useDashboardStore(v=>v.actions),{setDocumentInspectorTab:f,setShowFilters:w}=m,y=(T=c.sheets)==null?void 0:T.find(v=>v.id===u),E=n.isDocumentSheet(y),B=x.useCallback(v=>{window.setTimeout(()=>{p(v)},0)},[]),D=x.useCallback(v=>{if(E&&u){v&&f(u,"inputs");return}v&&g("dashboard",!1),w(v)},[E,u,f,g,w]),b=x.useCallback(()=>{D(!0)},[D]),S=x.useCallback(()=>{B("create")},[B]),A=x.useCallback(()=>{B("manage")},[B]);return e.jsxs(e.Fragment,{children:[e.jsx(Le,{showFilters:E?!1:i,onShowFiltersChange:D,pickerContent:e.jsx(yt,{}),settingsContent:v=>e.jsx(wt,{onAddFilter:b,onAddControl:S,onManageControls:A,onDismiss:v}),size:t,className:r,primaryButtonClassName:l,secondaryButtonClassName:o,pickerContentClassName:a,settingsContentClassName:d}),h?E?e.jsx(Fe,{open:!0,onOpenChange:v=>{v||p(null)},initialMode:h}):e.jsx(Ie,{open:!0,onOpenChange:v=>{v||p(null)},showTrigger:!1,initialMode:h}):null]})}function Te({disabled:t,briefingCount:r,className:l,onClick:o}){const a=typeof r=="number"&&r>0;return e.jsxs(n.Button,{type:"button",size:"xs",variant:"outline",disabled:t,className:n.cn("gap-1.5",l),onClick:o,"aria-label":"Reports & briefings",children:[e.jsx(qe,{className:"h-3.5 w-3.5"}),"Reports & briefings",a?e.jsx("span",{className:"ml-0.5 rounded-control bg-muted px-1 text-[10px] tabular-nums text-foreground/70",children:r}):null]})}const St="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",Me="inline-flex h-7 items-center gap-1.5 rounded-control px-2 text-[12px] text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-50",pe="inline-flex h-7 items-center gap-1.5 rounded-control bg-primary px-3 text-[12px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50";function Et(t){return t==="dashboard"?"This dashboard":"Project"}function At(t){if(!t)return"Never";const r=new Date(t);if(Number.isNaN(r.getTime()))return"Unknown";const l=Date.now()-r.getTime(),o=Math.round(l/6e4);if(o<1)return"now";if(o<60)return`${o}m ago`;const a=Math.round(o/60);if(a<24)return`${a}h ago`;const d=Math.round(a/24);if(d<7)return`${d}d ago`;const h=Math.round(d/7);return h<5?`${h}w ago`:`${Math.round(d/30)}mo ago`}function kt(t){return t.scheduleExpr?X.describeBriefingSchedule(t.scheduleExpr,t.timezone||"UTC")??"Invalid schedule":"On demand"}function Bt(t){if(t.lastRunStatus){const r=t.lastRunStatus.toString().toUpperCase();return r==="SUCCESS"?"Last run completed.":r==="FAILED"?"Last run failed.":`Last run ${t.lastRunStatus.toString().toLowerCase()}`}return null}function Pe(t){return t.hasActiveRun?"Running":t.lastRunStatus?`Last run ${t.lastRunStatus.toString().toLowerCase()}`:"Idle"}function It(t){return t.source.type==="dashboard"?"This dashboard":"Project"}function Ft({activeView:t,onChange:r}){return e.jsx("div",{className:"flex shrink-0 items-center gap-1 rounded-control bg-muted p-0.5",role:"tablist","aria-label":"Briefing source view",children:["dashboard","project"].map(l=>{const o=t===l;return e.jsx("button",{type:"button",role:"tab","aria-selected":o,onClick:()=>r(l),className:n.cn("h-6 rounded-[3px] px-2 text-[11px] transition-colors",o?"bg-background font-medium text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:Et(l)},l)})})}function Lt({briefings:t,dashboardLabel:r,sourceView:l,error:o,loading:a,onSourceViewChange:d,onClose:h,onEdit:p,onNew:c,canCreate:u,canCreateScheduledReport:i,analyticalBriefingsEnabled:g,onRunNow:m,onTogglePause:f,onDelete:w,selectingId:y,busyId:E,manageBriefingsHref:B,contentKind:D,hideHeader:b=!1}){const S=t.length,A=t.filter(I=>I.status==="ACTIVE").length,T=D==="reports"?S===1?"report":"reports":D==="briefings"?S===1?"briefing":"briefings":S===1?"item":"items",v=t.find(I=>I.hasActiveRun)??null,j=D??"reports & briefings",L=l==="dashboard"?r:`Project ${j}`;return e.jsxs("section",{"aria-label":`Dashboard ${j.replace("&","and")}`,className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:[b?null:e.jsxs("header",{className:"flex items-start justify-between gap-3 border-b border-border px-4 py-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:St,children:j}),e.jsx("h2",{className:"mt-0.5 truncate text-[14px] font-semibold leading-5",children:L})]}),e.jsx("button",{type:"button",onClick:h,className:"rounded-control p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":`Close ${j.replace("&","and")} panel`,children:e.jsx(K.X,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border px-4 py-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(Ft,{activeView:l,onChange:d}),e.jsx("div",{className:"flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:a&&S===0?e.jsxs("span",{children:["Loading ",j,"…"]}):S===0?e.jsxs("span",{children:["No ",j," yet"]}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"font-medium text-foreground/80",children:[S," ",T]}),e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{children:[A," active"]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[a?e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}):null,S>0&&u?g&&i?e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsxs("button",{className:pe,children:[e.jsx(s.Plus,{className:"h-3 w-3"})," New"]})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuItem,{onClick:()=>c("scheduled_report"),children:"Schedule a report"}),e.jsx(s.DropdownMenuItem,{onClick:()=>c("analytical_briefing"),children:"Create analytical briefing"})]})]}):i?e.jsxs("button",{onClick:()=>c("scheduled_report"),className:pe,children:[e.jsx(s.Plus,{className:"h-3 w-3"})," Schedule report"]}):g?e.jsxs("button",{onClick:()=>c("analytical_briefing"),className:pe,children:[e.jsx(s.Plus,{className:"h-3 w-3"})," New briefing"]}):null:null]})]}),v?e.jsxs("div",{className:"flex items-center gap-2 border-b border-border bg-muted/60 px-4 py-2 text-[12px]",children:[e.jsx(n.LoaderCircle,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}),e.jsx("span",{className:"font-medium text-foreground",children:v.name}),e.jsx("span",{className:"text-border",children:"·"}),e.jsx("span",{className:"truncate text-muted-foreground",children:Pe(v)})]}):null,e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[o?e.jsx("div",{className:"m-4 rounded-card border border-destructive/30 bg-destructive/10 px-3 py-2 text-[12px] text-destructive",children:o}):null,!a&&t.length===0&&!o?e.jsx(Tt,{onNew:c,canCreate:u,canCreateScheduledReport:i,analyticalBriefingsEnabled:g,contentKind:D}):null,t.map(I=>e.jsx(Pt,{briefing:I,isOpening:y===I.id,isBusy:E===I.id,onOpen:()=>p(I.id),onRunNow:()=>m(I),onTogglePause:()=>f(I),onDelete:()=>w(I)},I.id))]}),B?e.jsx("div",{className:"border-t border-border px-4 py-2.5",children:e.jsxs("a",{href:B,className:n.cn(Me,"h-6 px-1 text-[11px]"),children:["Manage all reports & briefings",e.jsx(ze,{className:"h-3 w-3"})]})}):null]})}function Tt({onNew:t,canCreate:r,canCreateScheduledReport:l,analyticalBriefingsEnabled:o,contentKind:a}){const d=a==="reports"?{title:"No reports yet",description:"Schedule an emailed dashboard or visual report to see it here."}:a==="briefings"?{title:"No briefings yet",description:"Create an analytical briefing to monitor this dashboard and brief your team."}:null;return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-8 py-12 text-center",children:[e.jsx(Mt,{className:"mb-5 h-[88px] w-[112px] text-border"}),e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:(d==null?void 0:d.title)??"Have an analyst brief your team"}),e.jsx("p",{className:"mt-1.5 max-w-[320px] text-[12px] leading-5 text-muted-foreground",children:(d==null?void 0:d.description)??"Describe what to watch. An analyst digs into this dashboard and the data behind it, then briefs your team on the cadence you choose."}),r?e.jsxs("div",{className:"mt-4 flex flex-wrap justify-center gap-2",children:[l?e.jsxs("button",{onClick:()=>t("scheduled_report"),className:pe,children:[e.jsx(s.Plus,{className:"h-3 w-3"})," Schedule a report"]}):null,o?e.jsx("button",{onClick:()=>t("analytical_briefing"),className:Me,children:"Create analytical briefing"}):null]}):null]})}function Mt({className:t}){return e.jsxs("svg",{viewBox:"0 0 112 88",fill:"none",xmlns:"http://www.w3.org/2000/svg",role:"presentation","aria-hidden":"true",className:t,children:[e.jsx("rect",{x:"22",y:"6",width:"60",height:"72",rx:"3",stroke:"currentColor",strokeWidth:"1.25"}),e.jsx("line",{x1:"30",y1:"16",x2:"64",y2:"16",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),e.jsx("line",{x1:"30",y1:"21",x2:"52",y2:"21",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round",opacity:"0.5"}),e.jsx("circle",{cx:"31",cy:"32",r:"1",fill:"currentColor",opacity:"0.6"}),e.jsx("line",{x1:"35",y1:"32",x2:"72",y2:"32",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),e.jsx("circle",{cx:"31",cy:"38",r:"1",fill:"currentColor",opacity:"0.6"}),e.jsx("line",{x1:"35",y1:"38",x2:"68",y2:"38",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),e.jsx("circle",{cx:"31",cy:"44",r:"1",fill:"currentColor",opacity:"0.6"}),e.jsx("line",{x1:"35",y1:"44",x2:"74",y2:"44",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),e.jsx("rect",{x:"30",y:"64",width:"5",height:"8",rx:"0.5",fill:"currentColor",opacity:"0.55"}),e.jsx("rect",{x:"38",y:"60",width:"5",height:"12",rx:"0.5",fill:"currentColor",opacity:"0.7"}),e.jsx("rect",{x:"46",y:"56",width:"5",height:"16",rx:"0.5",fill:"currentColor",opacity:"0.85"}),e.jsx("rect",{x:"54",y:"62",width:"5",height:"10",rx:"0.5",fill:"currentColor",opacity:"0.6"}),e.jsx("rect",{x:"62",y:"58",width:"5",height:"14",rx:"0.5",fill:"currentColor",opacity:"0.75"}),e.jsx("circle",{cx:"86",cy:"62",r:"10",fill:"var(--background, white)",stroke:"currentColor",strokeWidth:"1.25"}),e.jsx("line",{x1:"93.5",y1:"69.5",x2:"100",y2:"76",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})}function Pt({briefing:t,isOpening:r,isBusy:l,onOpen:o,onRunNow:a,onTogglePause:d,onDelete:h}){const p=t.status==="PAUSED",c=t.hasActiveRun,u=Bt(t),i=At(t.lastRunAt),g=t.lastRunStatus,m=X.getBriefingPresentation(t),f=g==="SUCCESS"?s.briefingTone.success.dot:g==="FAILED"?s.briefingTone.danger.dot:g?s.briefingTone.warning.dot:s.briefingTone.neutral.dot;return e.jsxs("div",{className:n.cn("group relative border-b border-border/60 px-4 py-3 transition-colors hover:bg-muted/60",p&&"opacity-70"),children:[e.jsxs("div",{role:"button",tabIndex:0,onClick:o,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),o())},className:"cursor-pointer pr-8",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-foreground",children:t.name}),p?e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:"· Paused"}):null]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-1.5 text-[11px] text-muted-foreground",children:[e.jsx("span",{children:m.typeLabel}),e.jsx("span",{className:"text-border",children:"·"}),e.jsx("span",{children:It(t)}),e.jsx("span",{className:"text-border",children:"·"}),e.jsx(s.Clock,{className:"h-3 w-3"}),e.jsx("span",{className:"truncate",children:kt(t)}),t.lastRunAt?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{children:["Last run ",i]})]}):null]}),u||c?e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5 text-[12px] leading-[1.5] text-foreground/80",children:[c?e.jsx(n.LoaderCircle,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground/70"}):e.jsx("span",{className:n.cn("inline-block h-1.5 w-1.5 shrink-0 rounded-full",f)}),e.jsx("span",{className:"truncate",children:c?Pe(t):u})]}):null]}),e.jsx("div",{className:"absolute right-3 top-3",children:l?e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground/70"}):r?e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground/70"}):e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx("button",{type:"button",onClick:w=>w.stopPropagation(),className:"inline-flex h-6 w-6 items-center justify-center rounded-control text-muted-foreground/70 opacity-60 hover:bg-muted hover:text-foreground/80 focus-visible:opacity-100 group-hover:opacity-100","aria-label":`${m.noun==="report"?"Report":"Briefing"} actions`,children:e.jsx(s.Ellipsis,{className:"h-3.5 w-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-44",children:[e.jsxs(s.DropdownMenuItem,{onClick:o,children:[e.jsx(s.Pencil,{className:"h-3.5 w-3.5"}),"Edit ",m.noun]}),e.jsxs(s.DropdownMenuItem,{onClick:w=>{w.preventDefault(),a()},children:[e.jsx(s.Zap,{className:"h-3.5 w-3.5"}),"Run now"]}),t.scheduleExpr?e.jsx(s.DropdownMenuItem,{onClick:w=>{w.preventDefault(),d()},children:p?e.jsxs(e.Fragment,{children:[e.jsx(s.Play,{className:"h-3.5 w-3.5"}),"Resume"]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Pause,{className:"h-3.5 w-3.5"}),"Pause"]})}):null,e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{onClick:w=>{w.preventDefault(),h()},className:"text-destructive focus:bg-destructive/10 focus:text-destructive",children:[e.jsx(s.Trash2,{className:"h-3.5 w-3.5"}),"Delete ",m.noun]})]})]})})]})}const Vt=2e3,Rt=20*6e4;function Ut(t){return(t==null?void 0:t.trim())||"This dashboard"}function Ot(t){return t==="This dashboard"?"Watch this dashboard":`Watch ${t}`}function zt(t,r,l){return r!=="dashboard"?t:t.filter(o=>o.source.type==="dashboard"&&o.source.dashboardId===l)}async function _t(t){const l=[];let o=1,a=0,d=Number.POSITIVE_INFINITY;for(;a<d;){const h=await t.apiClient.listBriefings(t.apiServiceUrl,t.token,{scope:"organization",page:o,pageSize:100});if(l.push(...h.briefings),a+=h.briefings.length,d=h.total,h.briefings.length===0||a>=d)break;o+=1}return l}const $t={listBriefings:s.listBriefings,getBriefing:s.getBriefing,pauseBriefing:s.pauseBriefing,resumeBriefing:s.resumeBriefing,deleteBriefing:s.deleteBriefing,runBriefingNow:s.runBriefingNow};function qt({briefingId:t,initialRun:r,apiServiceUrl:l,token:o,onTerminal:a,onTimeout:d,onExpand:h}){const[p,c]=x.useState(r),{startRun:u}=s.useBriefingRunPolling({apiServiceUrl:l,token:o,intervalMs:Vt,timeoutMs:Rt,fetchRun:({apiServiceUrl:g,token:m,runId:f})=>s.getBriefingRun(g,m,t,f),onRun:g=>{c(g)},onTerminalRun:g=>{a(g)},onTimeout:()=>{d()}}),i=x.useRef(!1);return x.useEffect(()=>{i.current||(i.current=!0,s.isActiveBriefingRunStatus(r.status)?u(r):s.isTerminalBriefingRunStatus(r.status)&&a(r))},[r,a,u]),e.jsx(s.BackgroundRunPill,{run:p,onExpand:h})}function Ht(t){return e.jsx(s.BriefingUiCapabilitiesBoundary,{children:e.jsx(Wt,{...t})})}function Wt({dashboardId:t,dashboardTitle:r,apiServiceUrl:l,token:o,disabled:a,className:d,manageBriefingsHref:h,open:p,onOpenChange:c,hideTrigger:u=!1,workflowIntent:i,client:g}){const{authToken:m,tokenProps:f}=s.useSemaphorContext(),w=s.useBriefingUiCapabilities(),y=!i||w.canCreate&&(i==="scheduled_report"||w.analyticalBriefingsEnabled),[E,B]=x.useState(!1),D=p??E,b=N=>{p===void 0&&B(N),c==null||c(N)},[S,A]=x.useState(i?"author":"list"),[T,v]=x.useState(i??"analytical_briefing"),[j,L]=x.useState("dashboard"),[I,$]=x.useState([]),[k,M]=x.useState(null),_=i&&!y&&!k?"list":S,[oe,q]=x.useState(!1),[fe,ie]=x.useState(null),[ge,W]=x.useState(null),[U,Q]=x.useState(null),[ee,te]=x.useState(null),le=x.useRef(null),ue=x.useRef(D);x.useEffect(()=>{const N=D&&!ue.current;ue.current=D,!(!N||!i)&&(M(null),L("dashboard"),v(i),A("author"),te(null))},[D,i]);const[se,ne]=x.useState(null),[G,ce]=x.useState(null),O=l??(f==null?void 0:f.apiServiceUrl),z=o??(m==null?void 0:m.accessToken),Z=x.useMemo(()=>({...$t,...g}),[g]),ae=Ut(r),he=x.useMemo(()=>{const N=zt(I,j,t);if(!i)return N;const P=i==="scheduled_report"?"report":"briefing";return N.filter(me=>X.getBriefingPresentation(me).noun===P)},[t,I,j,i]),be=x.useMemo(()=>j==="dashboard"?{source:{type:"dashboard",dashboardId:t},label:ae,detail:Ot(ae)}:{source:{type:"project"},label:"This project",detail:"Use any data in this project."},[t,ae,j]),de=!!(O&&z),re=X.getBriefingCreationIntents({canCreate:w.canCreate,analyticalBriefingsEnabled:w.analyticalBriefingsEnabled,scheduledReportAvailable:j==="dashboard"}),H=x.useCallback(async()=>{if(!(!O||!z)){q(!0),te(null);try{$(await _t({apiClient:Z,apiServiceUrl:O,token:z}))}catch(N){te(N instanceof Error?N.message:"Could not load briefings.")}finally{q(!1)}}},[Z,O,z]);x.useEffect(()=>{!D||_!=="list"||!de||H()},[de,_,H,D]);const C=()=>{M(null),L("dashboard"),A("list"),b(!0)},F=N=>{M(null),v(N),A("author")},R=async N=>{if(!(!O||!z)){ie(N),te(null);try{const P=await Z.getBriefing(O,z,N);M(P.briefing),A("author")}catch(P){te(P instanceof Error?P.message:"Could not open briefing.")}finally{ie(null)}}},Y=async N=>{if(!(!O||!z)){W(N.id);try{await Z.runBriefingNow(O,z,N.id,{requestId:Gt()}),H()}catch(P){s.ue.error(P instanceof Error?P.message:"Could not start the run.")}finally{W(null)}}},J=async N=>{if(!O||!z)return;const{noun:P}=X.getBriefingPresentation(N),me=P==="report"?"Report":"Briefing";W(N.id);try{const xe=N.status==="PAUSED"?await Z.resumeBriefing(O,z,N.id):await Z.pauseBriefing(O,z,N.id);s.ue.success(xe.briefing.status==="PAUSED"?`${me} paused`:`${me} resumed`),H()}catch(xe){s.ue.error(xe instanceof Error?xe.message:`Could not update the ${P} status.`)}finally{W(null)}},Ve=async()=>{if(!U||!O||!z)return;const N=U;W(N.id);try{await Z.deleteBriefing(O,z,N.id);const{noun:P}=X.getBriefingPresentation(N);s.ue.success(`${P==="report"?"Report":"Briefing"} deleted`),Q(null),H()}catch(P){s.ue.error(P instanceof Error?P.message:"Could not delete the briefing.")}finally{W(null)}},Re=he.length;return w.surfaceVisible?e.jsxs(s.Sheet,{open:D,onOpenChange:b,children:[u?null:e.jsx(Te,{disabled:a||!de,briefingCount:Re,className:d,onClick:C}),e.jsxs(s.SheetContent,{ref:le,side:"right",hideClose:!0,className:"flex h-full w-full flex-col overflow-hidden p-0 outline-none sm:max-w-[560px]",onOpenAutoFocus:N=>{var P;N.preventDefault(),(P=le.current)==null||P.focus({preventScroll:!0})},children:[e.jsxs(s.SheetHeader,{className:"sr-only",children:[e.jsx(s.SheetTitle,{children:"Reports & briefings"}),e.jsx(s.SheetDescription,{children:"Manage reports and briefings for this dashboard."})]}),i?e.jsxs("div",{className:"flex shrink-0 items-start justify-between gap-3 border-b border-border pl-4 pr-3 pt-2",children:[e.jsxs("div",{className:"flex items-center gap-5",role:"tablist","aria-label":i==="scheduled_report"?"Email report workflow":"Analytical briefing workflow",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":_==="author",disabled:!y,className:n.cn("-mb-px border-b-2 px-0.5 pb-2 text-[12px] transition-colors",_==="author"?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground",!y&&"cursor-not-allowed opacity-50"),onClick:()=>{y&&(M(null),v(i),L("dashboard"),A("author"))},children:k?`Edit ${X.getBriefingPresentation(k).noun}`:i==="scheduled_report"?"Schedule report":"Create briefing"}),e.jsx("button",{type:"button",role:"tab","aria-selected":_==="list",className:n.cn("-mb-px border-b-2 px-0.5 pb-2 text-[12px] transition-colors",_==="list"?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),onClick:()=>A("list"),children:i==="scheduled_report"?"Manage reports":"Manage briefings"})]}),e.jsx("button",{type:"button",onClick:()=>b(!1),className:"rounded-control p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":i==="scheduled_report"?"Close email report workflow":"Close analytical briefing workflow",children:e.jsx(K.X,{className:"h-3.5 w-3.5"})})]}):null,_==="list"?e.jsx(Lt,{briefings:he,dashboardLabel:ae,sourceView:j,error:ee,loading:oe,onSourceViewChange:L,onClose:()=>b(!1),onEdit:N=>{R(N)},onNew:F,canCreate:!i&&re.length>0,canCreateScheduledReport:re.includes("scheduled_report"),analyticalBriefingsEnabled:re.includes("analytical_briefing"),onRunNow:N=>{Y(N)},onTogglePause:N=>{J(N)},onDelete:N=>Q(N),selectingId:fe,busyId:ge,manageBriefingsHref:h,contentKind:i==="scheduled_report"?"reports":i==="analytical_briefing"?"briefings":void 0,hideHeader:!!i}):e.jsx(s.BriefingAuthor,{apiServiceUrl:O,token:z,briefing:k,intent:T,sourceContext:k?void 0:be,title:k?`Edit ${X.getBriefingPresentation(k).noun}`:T==="scheduled_report"?"Schedule report":"Create analytical briefing",hideHeader:!!i,className:"h-full min-h-0 max-w-none border-0 shadow-none",onBack:i?void 0:()=>A("list"),onCancel:()=>b(!1),onDeleted:()=>{const N=k?X.getBriefingPresentation(k).noun:"briefing";s.ue.success(`${N==="report"?"Report":"Briefing"} deleted`),M(null),A("list"),H()},onRunStarted:()=>{},onSaved:N=>{M(N),H()},onMinimizeRun:({briefing:N,run:P})=>{ne({briefing:N,run:P}),b(!1)}})]}),se&&O&&z?e.jsx(qt,{briefingId:se.briefing.id,initialRun:se.run,apiServiceUrl:O,token:z,onTerminal:N=>{ce({briefing:se.briefing,run:N}),ne(null),H()},onTimeout:()=>{ne(null),H()},onExpand:()=>{M(se.briefing),A("author"),ne(null),b(!0)}}):null,G?e.jsx("div",{className:"fixed bottom-4 right-4 z-50 w-[360px]",children:e.jsx(s.RunCompletionBanner,{title:G.run.status==="SUCCESS"?`${G.briefing.name} is ready`:`${G.briefing.name} run failed`,durationSeconds:G.run.startedAt&&G.run.completedAt?Math.max(0,Math.floor((new Date(G.run.completedAt).getTime()-new Date(G.run.startedAt).getTime())/1e3)):null,status:G.run.status==="SUCCESS"?"success":"failed",onView:()=>{M(G.briefing),A("author"),ce(null),b(!0)},onDismiss:()=>ce(null)})}):null,e.jsx(s.AlertDialog,{open:!!U,onOpenChange:N=>{N||Q(null)},children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsxs(s.AlertDialogTitle,{children:["Delete"," ",U?X.getBriefingPresentation(U).noun:"briefing","?"]}),e.jsxs(s.AlertDialogDescription,{children:["This permanently deletes ",e.jsx("strong",{children:U==null?void 0:U.name}),". Recipients will stop receiving it."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsxs(s.AlertDialogAction,{className:"bg-destructive/90 hover:bg-destructive",onClick:Ve,children:["Delete"," ",U?X.getBriefingPresentation(U).noun:"briefing"]})]})]})})]}):null}function Gt(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`briefing-run-now-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}exports.AdvancedModeToggle=rt;exports.DashboardBriefingLauncher=Ht;exports.DashboardControlsSettings=Ie;exports.DashboardFilterControlsButton=Le;exports.DashboardFilterControlsLauncher=Dt;exports.DocumentControlsSettings=Fe;exports.ExportNotificationItem=ke;exports.ExportNotificationList=Be;exports.NotificationBell=xt;exports.UnsavedChangesAlert=nt;exports.VisualEditingControls=st;exports.VisualsLibraryDialog=Qe;exports.WatchDashboardButton=Te;exports.useExportPolling=ut;exports.useExportRecovery=ht;
26
+ */const qe=K.createLucideIcon("Newspaper",[["path",{d:"M4 22h16a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H8a2 2 0 0 0-2 2v16a2 2 0 0 1-2 2Zm0 0a2 2 0 0 1-2-2v-9c0-1.1.9-2 2-2h2",key:"7pis2x"}],["path",{d:"M18 14h-8",key:"sponae"}],["path",{d:"M15 18h-5",key:"95g1m2"}],["path",{d:"M10 6h8v4h-8V6Z",key:"smlsk5"}]]);function He(){return e.jsx("div",{className:"space-y-1.5 py-1",children:[...Array(5)].map((t,r)=>e.jsxs("div",{className:"flex animate-pulse items-start gap-3 rounded-xl border border-transparent px-2.5 py-2.5",children:[e.jsx("div",{className:"mt-0.5 h-4 w-4 flex-shrink-0 rounded bg-muted/60"}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"h-4 w-3/5 rounded bg-muted/60"}),e.jsx("div",{className:"h-3 w-4/5 rounded bg-muted/40"})]})]},r))})}function We({open:t,onOpenChange:r,onSubmit:l,isCreating:o}){const[a,d]=x.useState(""),[h,p]=x.useState("");x.useEffect(()=>{t||(d(""),p(""))},[t]);const c=()=>{a.trim()&&l({title:a,description:h})},u=i=>{r(i)};return e.jsx(s.Dialog,{open:t,onOpenChange:u,children:e.jsxs(s.DialogContent,{showCloseButton:!1,className:"flex max-w-lg grid-cols-none flex-col gap-0 overflow-hidden rounded-[6px] border-border/60 p-0 shadow-lg",children:[e.jsxs("div",{className:"flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(je.LayoutGrid,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[e.jsx(s.DialogTitle,{className:"truncate text-[13px] font-medium leading-none tracking-normal",children:"New library visual"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium uppercase leading-none tracking-[0.08em] text-muted-foreground",children:"Visual"})]})]}),e.jsx(n.Button,{size:"xs",variant:"ghost",className:"w-7 px-0 text-muted-foreground hover:text-foreground",onClick:()=>u(!1),"aria-label":"Close",disabled:o,children:e.jsx(K.X,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"space-y-3 px-4 py-3",children:[e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Create a saved visual that can be reused across dashboards."}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(n.Label,{htmlFor:"visual-title",className:"text-[12px]",children:"Name"}),e.jsx(n.Input,{id:"visual-title",size:"sm",placeholder:"Untitled visual",value:a,onChange:i=>d(i.target.value),disabled:o,onKeyDown:i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),c())}})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(n.Label,{htmlFor:"visual-description",className:"text-[12px]",children:"Description"}),e.jsx(n.Input,{id:"visual-description",size:"sm",placeholder:"Optional",value:h,onChange:i=>p(i.target.value),disabled:o})]})]}),e.jsxs("div",{className:"flex shrink-0 justify-end gap-2 border-t border-border/60 px-4 py-2.5",children:[e.jsx(n.Button,{size:"xs",variant:"outline",onClick:()=>u(!1),disabled:o,children:"Cancel"}),e.jsx(n.Button,{size:"xs",onClick:c,disabled:!a.trim()||o,children:o?e.jsxs(e.Fragment,{children:[e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Creating..."]}):"Create library visual"})]})]})})}function Ee(t){return t?new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Unknown"}function Ae(t,r){var o;const l=(o=t.ownership.createdBy)==null?void 0:o.type;return l==="tenant"||l==="organization"&&r}function Ce(t,r){var l,o;return Ae(t,r)?((l=t.ownership.createdBy)==null?void 0:l.name)||((o=t.createdByTenantUserRel)==null?void 0:o.name)||t.lastModifiedBy||"Unknown":"Organization"}function Ge(t,r){return Ce(t,r).split(/\s+/).filter(Boolean).slice(0,2).map(o=>o.charAt(0).toUpperCase()).join("")||"?"}function Xe(t){const r=(t||"").toLowerCase();return r.includes("table")?n.Table2:r.includes("pie")||r.includes("donut")?s.ChartPie:r.includes("line")?s.ChartLine:r.includes("bar")?n.ChartColumn:je.LayoutGrid}function Ke({visual:t}){const r=t.ownership.status==="public"?"Public":t.ownership.status==="shared"||t.ownership.sharedCount>0?"Shared":"Private";return e.jsx("span",{className:"inline-flex items-center rounded-[4px] border border-border/60 px-1.5 py-px text-[11px] text-muted-foreground",children:r})}function Qe({open:t,onOpenChange:r}){const[l,o]=x.useState(""),[a,d]=x.useState(new Set),[h,p]=x.useState(!1),[c,u]=x.useState(null),[i,g]=x.useState(null),[m,f]=x.useState(!1),[w,y]=x.useState(null),[E,B]=x.useState(null),D=()=>{d(new Set),u(null),g(null),f(!1),y(null)},b=()=>{r(!1),D()},{selectVisual:S}=s.useManagementActions(),{handleAddLibraryVisual:A,handleEditLibraryVisual:T}=V.useVisualUtils(),{isConsoleMode:v}=s.useDashboardPreferences(),{resources:j,isLoading:L,isError:I,createResource:$,updateResource:k,deleteResourceAsync:M,duplicateResource:_,isCreating:oe,isDeleting:q}=s.useVisualManagement(void 0,C=>{p(!1),C&&(S(C),T(C),b())}),{startUpdating:fe,stopUpdating:ie,isUpdating:ge}=s.useResourceUpdateState(),W=j,U=x.useMemo(()=>{const C=l.trim().toLowerCase();return C?W.filter(F=>{var R,Y,J;return((R=F.title)==null?void 0:R.toLowerCase().includes(C))||((Y=F.description)==null?void 0:Y.toLowerCase().includes(C))||((J=F.kind)==null?void 0:J.toLowerCase().includes(C))}):W},[l,W]),Q=x.useMemo(()=>W.filter(C=>a.has(C.id)),[a,W]),ee=Q.filter(C=>C.permissions.canDelete),te=Q.filter(C=>C.permissions.canShare),le=U.length>0&&U.every(C=>a.has(C.id)),ue=U.some(C=>a.has(C.id)),se=C=>{const F=new Set(a);C(F),d(F)},ne=C=>{se(F=>{F.has(C)?F.delete(C):F.add(C)})},G=()=>{d(C=>{const F=new Set(C);return le?U.forEach(R=>F.delete(R.id)):U.forEach(R=>F.add(R.id)),F})},ce=async C=>{(await A(C)).success&&b()},O=async()=>{const C=Q;if(C.length===0)return;let F=!1;for(const R of C)if(!(await A(R)).success){F=!0;break}F||b()},z=C=>{T(C),b()},Z=C=>{B(C),_(C,{onSettled:()=>B(null)})},ae=()=>{if(ee.length===0){s.ue.error("Select a visual you can delete");return}y(null),f(!0)},he=async()=>{const C=w?[w]:ee;try{for(const F of C)await M(F.id);d(F=>{const R=new Set(F);return C.forEach(Y=>R.delete(Y.id)),R}),f(!1),y(null)}catch{}},be=()=>{if(Q.length!==1){s.ue.error("Select one visual to share");return}const[C]=Q;if(!C.permissions.canShare){s.ue.error("You do not have permission to share this visual");return}u(C)},de=({title:C,description:F})=>{if(!i)return;const R={};if(C!==i.title&&(R.title=C),(i.description||"")!==F&&(R.description=F),Object.keys(R).length===0){g(null);return}const Y=Object.keys(R),J=Y.length===1?Y[0]:void 0;fe(i.id,J),k({resourceId:i.id,data:R},{onSuccess:()=>{ie(i.id,J),g(null)},onError:()=>{ie(i.id,J)}})},re=C=>{r(C),C||D()},H=w?1:ee.length;return e.jsxs(e.Fragment,{children:[e.jsx(s.Dialog,{open:t,onOpenChange:re,children:e.jsxs(s.DialogContent,{showCloseButton:!1,className:"flex max-h-[80vh] w-[min(72rem,calc(100vw-2rem))] max-w-none grid-cols-none flex-col gap-0 overflow-hidden rounded-[6px] border-border/60 p-0 shadow-lg",children:[e.jsxs("div",{className:"flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(n.Table2,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[e.jsx(s.DialogTitle,{className:"truncate text-[13px] font-medium leading-none tracking-normal",children:"Visuals library"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium uppercase leading-none tracking-[0.08em] text-muted-foreground",children:"Add to dashboard"})]})]}),e.jsx(n.Button,{size:"xs",variant:"ghost",className:"w-7 px-0 text-muted-foreground hover:text-foreground",onClick:()=>re(!1),"aria-label":"Close visuals library",children:"×"})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border/60 px-3 py-2",children:[e.jsxs("div",{className:"relative min-w-[12rem] flex-1 md:max-w-md",children:[e.jsx(Ue.Search,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:l,onChange:C=>o(C.target.value),placeholder:"Search visuals...",className:"h-7 w-full rounded-control border border-input bg-background pl-7 pr-2 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-ring focus:outline-none","aria-label":"Search visuals"})]}),e.jsxs(n.Button,{size:"xs",variant:"outline",className:"ml-auto",onClick:()=>p(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"New library visual"]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:L?e.jsx("div",{className:"p-3",children:e.jsx(He,{})}):I?e.jsx("div",{className:"flex flex-col items-center gap-2 px-4 py-12 text-center",children:e.jsx("p",{className:"text-[13px] text-destructive",children:"Failed to load visuals"})}):U.length===0?e.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-12 text-center",children:[e.jsx(je.LayoutGrid,{className:"h-5 w-5 text-muted-foreground/60"}),e.jsx("p",{className:"text-[13px] font-medium",children:l?"No visuals found":"No visuals yet"}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:l?"Try a different search.":"Create a saved visual to add it here."})]}):e.jsx(Ye,{visuals:U,selectedIds:a,allFilteredSelected:le,someFilteredSelected:ue,onSelectAll:G,onToggleSelection:ne,onAddVisual:ce,onOpenVisual:z,onEditDetails:g,onShareVisual:u,onDeleteVisual:C=>{y(C),f(!0)},onDuplicateVisual:Z,duplicatingId:E,isDeleting:q,isConsoleMode:v})}),e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border/60 px-3 py-2",children:[e.jsx("div",{className:"flex min-w-0 items-center gap-1.5",children:a.size>0&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-[12px] text-muted-foreground",children:[e.jsx("span",{className:"font-medium tabular-nums text-foreground",children:a.size})," ","selected"]}),e.jsx(n.Button,{size:"xs",variant:"ghost",onClick:()=>d(new Set),children:"Clear"}),e.jsxs(n.Button,{size:"xs",variant:"outline",onClick:be,disabled:Q.length!==1||te.length!==1,children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),e.jsxs(n.Button,{size:"xs",variant:"outline",className:"text-destructive hover:text-destructive",onClick:ae,disabled:ee.length===0,children:[e.jsx(s.Trash2,{className:"h-3.5 w-3.5"}),"Delete ",ee.length||a.size]})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(n.Button,{size:"xs",variant:"outline",onClick:()=>re(!1),children:"Close"}),e.jsxs(n.Button,{size:"xs",onClick:O,disabled:a.size===0,children:[e.jsx(n.Check,{className:"h-3.5 w-3.5"}),a.size===0?"Add to dashboard":`Add ${a.size} visual${a.size===1?"":"s"}`]})]})]})]})}),e.jsx(We,{open:h,onOpenChange:p,onSubmit:$,isCreating:oe}),c&&e.jsx(s.ShareDialog,{resource:c,resourceType:s.ResourceType.VISUAL,onClose:()=>u(null)}),i&&e.jsx(s.ResourceEditDialog,{open:!!i,resourceLabel:"Visual",initialTitle:i.title||"",initialDescription:i.description||"",onClose:()=>g(null),onSave:de,isSaving:ge(i.id)}),e.jsx(s.AlertDialog,{open:m,onOpenChange:C=>{!C&&q||(f(C),C||y(null))},children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsxs(s.AlertDialogTitle,{children:["Delete ",H," visual",H===1?"":"s","?"]}),e.jsx(s.AlertDialogDescription,{children:"This cannot be undone. Visuals already added to dashboards may need to be removed from those dashboards separately."})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{disabled:q,children:"Cancel"}),e.jsxs(s.AlertDialogAction,{onClick:C=>{C.preventDefault(),he()},disabled:q||H===0,children:[q?e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(s.Trash2,{className:"h-3.5 w-3.5"}),q?"Deleting...":"Delete"]})]})]})})]})}function Ye({visuals:t,selectedIds:r,allFilteredSelected:l,someFilteredSelected:o,onSelectAll:a,onToggleSelection:d,onAddVisual:h,onOpenVisual:p,onEditDetails:c,onShareVisual:u,onDeleteVisual:i,onDuplicateVisual:g,duplicatingId:m,isDeleting:f,isConsoleMode:w}){return e.jsxs("div",{className:"min-w-[48rem]",children:[e.jsxs("div",{className:"grid h-9 grid-cols-[2.5rem_minmax(14rem,1.8fr)_minmax(10rem,1fr)_8rem_7rem_5rem_5.5rem] items-center border-b border-border/60 px-3 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:[e.jsx(s.Checkbox,{checked:l?!0:o?"indeterminate":!1,onCheckedChange:a,"aria-label":"Select all visuals"}),e.jsx("span",{children:"Name"}),e.jsx("span",{children:"Created by"}),e.jsx("span",{children:"Updated"}),e.jsx("span",{children:"Visibility"}),e.jsx("span",{className:"text-right",children:"Shared"}),e.jsx("span",{className:"text-right",children:"Actions"})]}),t.map(y=>e.jsx(Ze,{visual:y,selected:r.has(y.id),onToggleSelection:d,onAddVisual:h,onOpenVisual:p,onEditDetails:c,onShareVisual:u,onDeleteVisual:i,onDuplicateVisual:g,duplicatingId:m,isDeleting:f,isConsoleMode:w},y.id))]})}function Ze({visual:t,selected:r,onToggleSelection:l,onAddVisual:o,onOpenVisual:a,onEditDetails:d,onShareVisual:h,onDeleteVisual:p,onDuplicateVisual:c,duplicatingId:u,isDeleting:i,isConsoleMode:g}){var w;const m=Xe(t.kind),f=()=>{o(t)};return e.jsxs("div",{className:n.cn("group grid min-h-12 grid-cols-[2.5rem_minmax(14rem,1.8fr)_minmax(10rem,1fr)_8rem_7rem_5rem_5.5rem] items-center border-b border-border/50 px-3 text-[13px] hover:bg-muted/50",r&&"bg-muted/70"),children:[e.jsx("div",{children:e.jsx(s.Checkbox,{checked:r,onCheckedChange:()=>l(t.id),"aria-label":`Select ${t.title||"visual"}`})}),e.jsxs("button",{type:"button",className:"flex min-w-0 items-center gap-2 rounded-[4px] text-left outline-none focus-visible:ring-1 focus-visible:ring-ring",onClick:f,"aria-label":`Add ${t.title||"visual"} to dashboard`,children:[e.jsx(m,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate font-medium text-foreground",title:t.title||"Untitled Visual",children:t.title||"Untitled Visual"}),((w=t.description)==null?void 0:w.trim())&&e.jsx("div",{className:"truncate text-[11px] text-muted-foreground",title:t.description,children:t.description})]})]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("div",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-muted text-[9px] font-medium text-muted-foreground",children:Ge(t,g)}),e.jsx("span",{className:"truncate text-muted-foreground",children:Ce(t,g)})]}),e.jsx("span",{className:"text-muted-foreground",children:Ee(t.updatedAt)}),e.jsx(Ke,{visual:t}),e.jsx("span",{className:"text-right tabular-nums text-muted-foreground",children:t.ownership.sharedCount>0?t.ownership.sharedCount:"—"}),e.jsx(Je,{visual:t,onOpenVisual:a,onEditDetails:d,onShareVisual:h,onDeleteVisual:p,onDuplicateVisual:c,duplicatingId:u,isDeleting:i,isConsoleMode:g})]})}function Je({visual:t,onOpenVisual:r,onEditDetails:l,onShareVisual:o,onDeleteVisual:a,onDuplicateVisual:d,duplicatingId:h,isDeleting:p,isConsoleMode:c}){return e.jsxs("div",{className:"flex items-center justify-end gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",onClick:u=>u.stopPropagation(),children:[e.jsx(n.Button,{size:"xs",variant:"ghost",className:"w-7 px-0",onClick:()=>r(t),"aria-label":"Edit visual",children:e.jsx(s.PenLine,{className:"h-3.5 w-3.5"})}),e.jsxs(s.DropdownMenu,{modal:!1,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(n.Button,{size:"xs",variant:"ghost",className:"w-7 px-0","aria-label":"More actions",children:e.jsx(s.Ellipsis,{className:"h-3.5 w-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"z-[60] w-44 rounded-[6px] border-border/60 p-1 shadow-sm",children:[e.jsxs(s.DropdownMenuItem,{onClick:()=>r(t),children:[e.jsx(s.PenLine,{className:"h-3.5 w-3.5"}),"Edit visual"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>d(t.id),disabled:h===t.id,children:[h===t.id?e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(s.Copy,{className:"h-3.5 w-3.5"}),h===t.id?"Duplicating...":"Duplicate"]}),t.permissions.canEdit&&e.jsxs(s.DropdownMenuItem,{onClick:()=>l(t),children:[e.jsx(s.PenLine,{className:"h-3.5 w-3.5"}),"Edit details"]}),t.permissions.canShare&&e.jsxs(s.DropdownMenuItem,{onClick:()=>o(t),children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),t.permissions.canDelete&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{className:"text-destructive focus:bg-destructive/10 focus:text-destructive",onClick:()=>a(t),disabled:p,children:[e.jsx(s.Trash2,{className:"h-3.5 w-3.5"}),p?"Deleting...":"Delete"]})]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs("div",{className:"space-y-1 px-2 py-1.5 text-[11px] text-muted-foreground",children:[Ae(t,c)&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(s.User,{className:"h-3 w-3"}),e.jsx("span",{className:"truncate",children:Ce(t,c)})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(s.Calendar,{className:"h-3 w-3"}),e.jsx("span",{children:Ee(t.updatedAt)})]})]})]})]})]})}function et({open:t,onOpenChange:r,isLibraryVisual:l,currentVisualName:o,isSaving:a=!1,destinationMode:d="both",onConfirm:h}){const[p,c]=x.useState(l&&o?`Copy of ${o}`:o||""),[u,i]=x.useState("");x.useEffect(()=>{t&&(c(l&&o?`Copy of ${o}`:o||""),i(""))},[t,l,o]);const g=!!p.trim(),m=d==="local"?{saveToLibrary:!1,saveToCurrentDashboard:!0,badgeType:"local",description:"Creates a local copy on the current dashboard.",actionLabel:"Add to Dashboard (Local)"}:d==="library"?{saveToLibrary:!0,saveToCurrentDashboard:!1,badgeType:"library",description:"Creates a reusable visual in Visual Library.",actionLabel:"Save as Library Visual"}:{saveToLibrary:!0,saveToCurrentDashboard:!0,badgeType:"linked",description:"Creates a new library visual and adds a linked copy to this dashboard.",actionLabel:"Save Copy as Linked Visual"},f=()=>{!g||a||h({name:p.trim(),description:u.trim()||void 0,saveToLibrary:m.saveToLibrary,saveToCurrentDashboard:m.saveToCurrentDashboard})};return e.jsx(s.Dialog,{open:t,onOpenChange:r,children:e.jsxs(s.DialogContent,{className:"sm:max-w-[500px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsxs(s.DialogTitle,{className:"flex items-center gap-2",children:[e.jsx("span",{children:"Save Visual As"}),m.badgeType!=="local"&&e.jsx(V.VisualBadge,{type:m.badgeType,showLabel:!0,className:"px-2 py-0.5"})]}),e.jsx(s.DialogDescription,{children:m.description})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(n.Label,{htmlFor:"name",children:"Name"}),e.jsx(n.Input,{id:"name",value:p,onChange:w=>c(w.target.value),placeholder:"Enter visual name",disabled:a})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(n.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(s.Textarea,{id:"description",value:u,onChange:w=>i(w.target.value),placeholder:"Enter visual description",rows:3,disabled:a})]})]}),e.jsxs(s.DialogFooter,{children:[e.jsx(n.Button,{variant:"outline",onClick:()=>r(!1),disabled:a,children:"Cancel"}),e.jsxs(n.Button,{onClick:f,disabled:!g||a,children:[a&&e.jsx(n.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),m.actionLabel]})]})]})})}function tt(){const[t,r]=x.useState(!1),[l,o]=x.useState(!1),[a,d]=x.useState(null),[h,p]=x.useState(null),c=n.useEditorStore(v=>v.frame),u=n.useEditorStore(v=>v.card),i=s.useSelectedVisual(),g=n.useDashboardStore(v=>v.selectedSheetId),m=n.useDashboardStore(v=>v.dashboard),{getUpdatedFrame:f}=V.useVisualUtils(),{selectVisual:w}=s.useManagementActions(),{addFrame:y,setSelectedFrameId:E,setIsVisualEditing:B}=n.useDashboardActions(),D=s.useResolveExistingFrameSemanticExecutionPayload(),b=!!(c!=null&&c.visualId),S=(()=>{var v,j;return((v=c==null?void 0:c.cards)==null?void 0:v.length)===1&&((j=c.cards[0])!=null&&j.title)?c.cards[0].title:i!=null&&i.title?i.title:(u==null?void 0:u.title)||"Untitled Visual"})(),A=s.useCreateVisualWithFrame(v=>{v!=null&&v.id&&(w(v),l&&a&&h&&g&&(async()=>{try{const j={...a,id:ye.v4(),visualId:v.id};y(g,j,{position:"end",semanticExecutionPayload:h}),E(j.id),o(!1),d(null),p(null),B(!1)}catch(j){console.error("Failed to promote semantic metadata for saved visual:",j),s.ue.error(j instanceof Error?j.message:"Failed to prepare semantic metadata for the saved visual")}})(),r(!1))});return{saveAsDialogOpen:t,setSaveAsDialogOpen:r,handleSaveAs:async v=>{if(!g){s.ue.error("No sheet selected");return}const j=f(),L=n.getDynamicFrameSaveIssue(j);if(L){s.ue.error(L);return}const $=j.cards.length===1?{...j,cards:j.cards.map(k=>({...k,title:v.name}))}:j;if(v.saveToLibrary){let k=null;if(v.saveToCurrentDashboard)try{k=await D($,{previousFrame:n.findDashboardFrameById(m,$.id)})}catch(_){console.error("Failed to prepare semantic metadata before saving visual:",_),s.ue.error(_ instanceof Error?_.message:"Failed to prepare semantic metadata for the saved visual");return}o(v.saveToCurrentDashboard),d($),p(k);const M={title:v.name,description:v.description,frameObject:$,isPrivate:!1};A.mutate(M)}else if(v.saveToCurrentDashboard){const k={...$,id:ye.v4(),visualId:void 0};try{const M=await D($,{previousFrame:n.findDashboardFrameById(m,$.id)});y(g,k,{position:"end",semanticExecutionPayload:M}),E(k.id),s.ue.success("Visual saved to dashboard"),r(!1),B(!1)}catch(M){console.error("Failed to save visual to dashboard:",M),s.ue.error(M instanceof Error?M.message:"Failed to prepare semantic metadata for the visual")}}},isLibraryVisual:b,currentVisualName:S,isSaving:A.isPending}}function st(t={}){const{isInspectionMode:r}=s.useDashboardInteractionMode(),l=n.useEditorStore(k=>k.frame),o=n.useEditorStore(k=>k.editorContext),a=s.useManagementStore(k=>k.selectedVisual),d=n.useDashboardStore(k=>k.selectedFrameId),h=n.useDashboardStore(k=>k.selectedSheetId),p=n.useDashboardStore(k=>k.dashboard),{setIsVisualEditing:c,updateFrame:u}=n.useDashboardActions(),[i,g]=x.useState(!1),[m,f]=x.useState("both"),w=s.useResolveExistingFrameSemanticExecutionPayload(),y=(o==null?void 0:o.type)==="documentSection",E=!!(l!=null&&l.visualId||a!=null&&a.id),B=!!(l!=null&&l.visualId&&d),D=E&&!B,{saveAsDialogOpen:b,setSaveAsDialogOpen:S,handleSaveAs:A,isLibraryVisual:T,currentVisualName:v,isSaving:j}=tt(),{getUpdatedFrame:L}=V.useVisualUtils();if(r)return e.jsxs(e.Fragment,{children:[e.jsx(V.EditorAcceptButton,{className:"rounded-control",variant:"default"}),e.jsx(V.EditorCancelButton,{})]});if(y)return e.jsxs(e.Fragment,{children:[e.jsx(V.EditorAcceptButton,{className:"rounded-control",variant:"default"}),e.jsx(V.EditorCancelButton,{})]});const I=async()=>{if(!h){s.ue.error("No sheet selected");return}if(i)return;g(!0);const k=L(),M=n.getDynamicFrameSaveIssue(k);if(M){g(!1),s.ue.error(M);return}const _={...k,visualId:void 0},oe=n.findDashboardFrameById(p,_.id);try{const q=await w(_,{previousFrame:oe});u(h,_,{semanticExecutionPayload:q})}catch(q){console.error("Failed to apply local semantic metadata:",q),g(!1),s.ue.error(q instanceof Error?q.message:"Failed to prepare semantic metadata for this visual");return}setTimeout(()=>{g(!1),s.ue.success("Changes applied. Visual is now local to this dashboard"),c(!1)},300)},$=k=>{f(k),S(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"inline-flex items-center overflow-hidden rounded-control",children:[!E&&e.jsx(V.EditorAcceptButton,{className:"!rounded-none",variant:"default"}),E&&D&&e.jsx(V.VisualSaveButton,{className:"!rounded-none",variant:"default"}),E&&B&&e.jsx(V.VisualSaveAndApplyButton,{className:"!rounded-none"}),e.jsxs(s.DropdownMenu,{modal:!1,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(n.Button,{variant:"default",size:"xs",className:"w-7 !rounded-none border-l border-primary-foreground/20 px-0","aria-label":"Open visual save options",disabled:j||i,children:e.jsx(K.ChevronDown,{className:"h-3.5 w-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"min-w-[220px] rounded-control border border-border/60 p-1 shadow-sm",children:[B&&e.jsxs(e.Fragment,{children:[e.jsxs(s.DropdownMenuItem,{onClick:I,disabled:i,children:[e.jsx(n.Check,{className:"h-3.5 w-3.5"}),i?"Applying...":"Apply Locally"]}),e.jsx(s.DropdownMenuSeparator,{})]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>$("local"),disabled:j,children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Add to Dashboard (Local)"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>$("library"),disabled:j,children:[e.jsx(V.Library,{className:"h-3.5 w-3.5"}),"Save as Library Visual"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>$("both"),disabled:j,children:[e.jsx(V.Link2,{className:"h-3.5 w-3.5"}),"Save Copy as Linked Visual"]})]})]})]}),e.jsx(V.EditorCancelButton,{}),e.jsx(et,{open:b,onOpenChange:k=>{j||S(k)},isLibraryVisual:T,currentVisualName:v,isSaving:j,destinationMode:m,onConfirm:A})]})}function rt({className:t}){const r=n.useEditorStore(u=>u.isDevMode),l=n.useDashboardStore(u=>u.isVisualEditing),{setIsDevMode:o}=n.useEditorActions(),{config:a}=x.useContext(s.SemaphorContext).tokenProps,d=(a==null?void 0:a.showAdvancedMode)!==!1;if(!l||!d)return null;const h=r?Oe.MousePointer2:s.CodeXml,p=r?"Visual editor":"SQL editor",c=r?"Switch to visual editor":"Switch to SQL editor";return e.jsxs("button",{type:"button","aria-label":c,title:c,onClick:()=>o(!r),className:n.cn("inline-flex h-7 items-center gap-1.5 rounded-control border border-input bg-background px-2 text-[12px] font-medium text-foreground transition-colors hover:bg-muted/40 focus-visible:border-ring focus-visible:outline-none",t),children:[e.jsx(h,{className:"h-3 w-3 text-muted-foreground"}),p]})}function nt({open:t,onOpenChange:r,onSave:l,onDiscard:o,isSaving:a,title:d="Unsaved changes",description:h="You have unsaved changes to this dashboard. What would you like to do?",cancelLabel:p="Cancel",discardLabel:c="Discard",saveLabel:u="Save"}){const i=g=>{!g&&a||r(g)};return e.jsx(s.AlertDialog,{open:t,onOpenChange:i,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:d}),e.jsx(s.AlertDialogDescription,{children:h})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(n.Button,{type:"button",size:"xs",onClick:o,disabled:a,variant:"ghost",className:"mr-auto text-muted-foreground hover:bg-destructive/10 hover:text-destructive focus-visible:bg-destructive/10 focus-visible:text-destructive",children:c}),e.jsx(s.AlertDialogCancel,{disabled:a,children:p}),e.jsx(n.Button,{type:"button",size:"xs",onClick:l,disabled:a,children:a?e.jsxs(e.Fragment,{children:[e.jsx(n.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Saving..."]}):u})]})]})})}const at=1e4,ot=15e3,it=3e4,lt=3e4,ct=12e4,De=2*60*60*1e3;function dt(t){const r=Date.now()-t.getTime();return r<lt?at:r<ct?ot:it}function ut(){const{authToken:t,tokenProps:r}=s.useSemaphorContext(),l=s.useExportStore(m=>m.activeExports),[o,a]=x.useState(typeof document<"u"?!document.hidden:!0),d=x.useRef(null),h=x.useRef(!1),p=x.useRef(void 0),c=r==null?void 0:r.apiServiceUrl,u=t==null?void 0:t.accessToken,i=x.useCallback(()=>{const m=s.useExportStore.getState().activeExports;return Array.from(m.values()).filter(f=>s.isExportInProgress(f.status))},[]);x.useEffect(()=>{if(typeof document>"u")return;const m=()=>{a(!document.hidden)};return document.addEventListener("visibilitychange",m),()=>{document.removeEventListener("visibilitychange",m)}},[]);const g=x.useCallback(async()=>{if(!c||!u){h.current=!1;return}const m=i();if(m.length===0){h.current=!1;return}const f=Date.now(),w=m.filter(b=>f-b.startedAt.getTime()>De);if(w.length>0){const{updateExport:b}=s.useExportStore.getState().actions;for(const S of w)b(S.id,{status:"failed",error:"Export timed out. Please try again or contact support.",lastUpdatedAt:new Date})}const y=m.filter(b=>f-b.startedAt.getTime()<=De);if(y.length===0){h.current=!1;return}const E=await Promise.allSettled(y.map(async b=>{try{const S=await s.getExportStatus(c,u,b.id);let A;if(S.status==="completed")try{A=await s.getDownloadUrl(c,u,b.id)}catch(T){console.error(`[useExportPolling] Failed to get download URL for ${b.id}:`,T)}return{id:b.id,status:S.status,progress:S.progress,completedChunks:S.completedChunks,completedAt:S.completedAt?new Date(S.completedAt):void 0,lastUpdatedAt:new Date,fileSize:S.fileSize,error:S.error,downloadUrl:A}}catch(S){return console.error(`[useExportPolling] Failed to poll export ${b.id}:`,S),null}})),{updateExport:B}=s.useExportStore.getState().actions;for(const b of E)b.status==="fulfilled"&&b.value&&B(b.value.id,b.value);const D=i();if(D.length>0&&!document.hidden){const b=D.reduce((A,T)=>T.startedAt<A?T.startedAt:A,D[0].startedAt),S=dt(b);d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{var A;(A=p.current)==null||A.call(p)},S)}else h.current=!1},[c,u,i]);return x.useEffect(()=>{p.current=g},[g]),x.useEffect(()=>{var f;i().length>0&&o&&!h.current&&(h.current=!0,(f=p.current)==null||f.call(p))},[l,o,i]),x.useEffect(()=>{var f;const m=i();o&&m.length>0&&!h.current&&(h.current=!0,(f=p.current)==null||f.call(p))},[o,i]),x.useEffect(()=>{!o&&d.current&&(clearTimeout(d.current),d.current=null,h.current=!1)},[o]),x.useEffect(()=>()=>{d.current&&(clearTimeout(d.current),d.current=null)},[]),{isPolling:h.current,isTabVisible:o,inProgressCount:i().length}}function ht(){const{authToken:t,tokenProps:r}=s.useSemaphorContext(),l=s.useExportStore(p=>p.activeExports),{addExport:o}=s.useExportActions(),a=x.useRef(!1),d=r==null?void 0:r.apiServiceUrl,h=t==null?void 0:t.accessToken;x.useEffect(()=>{if(a.current||!d||!h)return;(async()=>{try{const{exports:c}=await s.getExports(d,h,{status:["pending","processing","chunking","compacting","completed","failed"],limit:20});for(const u of c){if(l.has(u.id))continue;const i=u.totalChunks?Math.round(u.completedChunks/u.totalChunks*100):0;let g;if(u.status==="completed")try{g=await s.getDownloadUrl(d,h,u.id)}catch(f){console.error(`[useExportRecovery] Failed to get download URL for ${u.id}:`,f)}const m={id:u.id,status:u.status,progress:i,title:mt(u),totalRows:u.totalRows,totalChunks:u.totalChunks,completedChunks:u.completedChunks,startedAt:new Date(u.createdAt),lastUpdatedAt:new Date,completedAt:u.completedAt?new Date(u.completedAt):void 0,fileSize:u.fileSize,error:u.error,expiresAt:new Date(u.expiresAt),downloadUrl:g};o(m)}a.current=!0}catch(c){console.error("[useExportRecovery] Failed to recover exports:",c),a.current=!0}})()},[d,h,o,l])}function mt(t){return t.title?t.title:s.isExportInProgress(t.status)?"Export in progress...":t.status==="completed"?"Export completed":t.status==="failed"?"Export failed":"Export"}function ke({export:t,onRemove:r}){const l=()=>{t.downloadUrl&&window.open(t.downloadUrl,"_blank")},o=p=>{p.stopPropagation(),r==null||r(t.id)},a=()=>{switch(t.status){case"completed":return e.jsx(s.CircleCheck,{className:"mt-0.5 h-5 w-5 shrink-0 text-green-600"});case"failed":return e.jsx($e,{className:"mt-0.5 h-5 w-5 shrink-0 text-destructive"});default:return e.jsx(n.LoaderCircle,{className:"text-foreground-muted mt-0.5 h-5 w-5 shrink-0 animate-spin"})}},d=s.isExportInProgress(t.status),h=(()=>{switch(t.status){case"pending":return"Queued...";case"processing":return"Processing...";case"chunking":return"Processing...";case"compacting":return"Finalizing...";default:return"Processing..."}})();return e.jsxs("div",{className:"group p-4 transition-colors hover:bg-muted/50",children:[e.jsxs("div",{className:"mb-2 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-3",children:[a(),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"mb-1 truncate text-sm font-medium",children:t.title}),t.status==="completed"&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("span",{children:[t.totalRows.toLocaleString()," rows"]}),t.fileSize&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsx("span",{children:s.formatFileSize(t.fileSize)})]})]}),d&&e.jsx("div",{className:"text-xs text-muted-foreground",children:h}),t.status==="failed"&&e.jsx("div",{className:"line-clamp-2 text-xs text-destructive",children:t.error||"Export failed"})]})]}),e.jsx(n.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:o,"aria-label":"Remove notification",children:e.jsx(K.X,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"ml-8",children:[t.status==="completed"&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:we.formatDistanceToNow(t.startedAt,{addSuffix:!0})}),t.downloadUrl&&e.jsxs(n.Button,{size:"sm",variant:"outline",className:"h-8 bg-transparent",onClick:l,children:[e.jsx(s.Download,{className:"mr-1.5 h-3.5 w-3.5"}),"Download"]})]}),d&&e.jsxs("div",{children:[e.jsx(s.Progress,{value:t.progress,className:"h-1.5"}),e.jsxs("span",{className:"mt-1 block text-xs text-muted-foreground",children:[t.progress,"% complete"]})]}),t.status==="failed"&&e.jsx("span",{className:"text-xs text-muted-foreground",children:we.formatDistanceToNow(t.startedAt,{addSuffix:!0})})]})]})}function Be(){const{authToken:t,tokenProps:r}=s.useSemaphorContext(),l=s.useExportStore(y=>y.activeExports),{clearCompleted:o,removeExport:a,updateExport:d}=s.useExportActions(),[h,p]=x.useState(!1),[c,u]=x.useState(!1),i=Array.from(l.values()).sort((y,E)=>E.startedAt.getTime()-y.startedAt.getTime()),g=i.some(y=>y.status==="completed"||y.status==="failed"),m=x.useCallback(async()=>{const y=r==null?void 0:r.apiServiceUrl,E=t==null?void 0:t.accessToken;if(!(!y||!E)){p(!0);try{const B=Array.from(l.values());await Promise.all(B.map(async D=>{try{const b=await s.getExportStatus(y,E,D.id);let S;if(b.status==="completed")try{S=await s.getDownloadUrl(y,E,D.id)}catch(A){console.error(`Failed to get download URL for ${D.id}:`,A)}d(D.id,{status:b.status,progress:b.progress,completedChunks:b.completedChunks,completedAt:b.completedAt?new Date(b.completedAt):void 0,lastUpdatedAt:new Date,fileSize:b.fileSize,error:b.error,downloadUrl:S})}catch(b){console.error(`Failed to refresh export ${D.id}:`,b)}}))}finally{p(!1)}}},[l,t==null?void 0:t.accessToken,r==null?void 0:r.apiServiceUrl,d]),f=x.useCallback(async()=>{const y=r==null?void 0:r.apiServiceUrl,E=t==null?void 0:t.accessToken;if(!y||!E){o();return}u(!0);try{const B=i.filter(b=>b.status==="completed"||b.status==="failed"),D=await Promise.allSettled(B.map(async b=>(await s.cancelExport(y,E,b.id),b.id)));for(const b of D)b.status==="fulfilled"?a(b.value):console.error("Failed to delete export:",b.reason)}finally{u(!1)}},[i,r==null?void 0:r.apiServiceUrl,t==null?void 0:t.accessToken,o,a]),w=x.useCallback(async y=>{const E=r==null?void 0:r.apiServiceUrl,B=t==null?void 0:t.accessToken;if(E&&B)try{await s.cancelExport(E,B,y),a(y);return}catch(D){console.error(`Failed to cancel export ${y}:`,D)}a(y)},[r==null?void 0:r.apiServiceUrl,t==null?void 0:t.accessToken,a]);return i.length===0?e.jsxs("div",{className:"p-6 text-center",children:[e.jsx(Ne,{className:"mx-auto mb-2 h-8 w-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No active exports"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Large exports will appear here"})]}):e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ne,{className:"h-5 w-5 text-muted-foreground"}),e.jsx("h4",{className:"font-semibold",children:"Exports"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(n.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:m,disabled:h,title:"Refresh status",children:e.jsx(s.RefreshCw,{className:`h-4 w-4 ${h?"animate-spin":""}`})}),g&&e.jsx(n.Button,{variant:"ghost",size:"sm",className:"h-7 px-2 text-sm",onClick:f,disabled:c,children:c?"Clearing...":"Clear all"})]})]}),e.jsx("div",{className:"max-h-[350px] overflow-y-auto",children:e.jsx("div",{className:"divide-y",children:i.map(y=>e.jsx(ke,{export:y,onRemove:w},y.id))})})]})}function xt({variant:t}){const r=s.useExportStore(c=>c.activeExports),l=s.useInProgressExportsCount(),o=r.size>0,a=Array.from(r.values()).some(c=>c.status==="completed"||c.status==="failed"),h=l>0?l>9?"9+":String(l):null,p=o;return e.jsxs(n.Popover,{children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:t??"ghost",size:"xs",className:"relative w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":"Export notifications",children:[e.jsx(s.Bell,{className:"h-3.5 w-3.5"}),p&&e.jsx("span",{className:`absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${h?"-right-0.5 -top-0.5 h-3.5 min-w-3.5 px-0.5 text-[9px] font-semibold":"right-1 top-1 h-1.5 w-1.5"}`,children:h})]})}),e.jsx(n.PopoverContent,{className:"w-80 p-0",align:"end",sideOffset:8,children:e.jsx(Be,{})})]})}function pt(t){if(t)return{renamed:t.type==="rename"?{oldId:t.oldId,newId:t.newId}:void 0,removedControlId:t.type==="remove"?t.controlId:void 0,cardBindingsById:t.type==="add"||t.type==="update"?t.cardBindingsById:void 0,affectedBindingControlIds:t.type==="add"||t.type==="update"?t.affectedBindingControlIds:void 0}}function Ie({open:t,onOpenChange:r,trigger:l,showTrigger:o=!0,initialMode:a="manage"}){const d=a==="create",{forceClose:h,handleOpenChange:p,isCreateFlowActive:c,preventPassiveDismissDuringCreate:u,resolvedOpen:i,setIsCreateFlowActive:g}=V.useCreateFlowOverlayState({open:t,onOpenChange:r,initialCreateFlowActive:a==="create",dismissMode:o?"passive":"explicit-only"}),m=n.useDashboardStore(j=>j.dashboard),{setDashboardControlsModel:f}=n.useDashboardActions(),{participants:w}=s.useDashboardStructuralParticipants(n.getDashboardCards(m)),y=Array.from(new Map(w.flatMap(j=>j.fieldChoices.map(L=>{var I;return[L.value,{option:L,target:(I=j.fieldTargetMap)==null?void 0:I[L.value]}]}))).values()),E=Array.from(new Map(w.flatMap(j=>j.metricChoices.map(L=>{var I;return[L.value,{option:L,target:(I=j.metricTargetMap)==null?void 0:I[L.value]}]}))).values()),B=n.collectDashboardControlIds({...m||{},controls:[]}),D=s.buildDashboardStructuralParticipantIdsByControlId(m),b=(j,L,I)=>{f(j,L,pt(I))},S=x.useCallback(()=>{if(d){h();return}g(!1)},[d,h,g]),A=e.jsx(V.ControlDefinitionListEditor,{scope:"dashboard",controls:m.controls||[],reservedControlIds:B,defaultValues:m.defaultControlValues||{},usageByControlId:s.buildDashboardControlUsageById(m),availableFieldChoices:y,availableMetricChoices:E,structuralParticipants:w,structuralParticipantIdsByControlId:D,initialCreateFlow:a==="create",onCreateFlowActiveChange:g,onCreateFlowComplete:S,onChange:b,emptyMessage:"No dashboard controls yet."}),T=c?"Add dashboard control":"Dashboard Controls",v=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Dashboard Controls"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),A]});return o?e.jsxs(n.Popover,{open:i,onOpenChange:p,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:l||e.jsxs(n.Button,{variant:"outline",className:"h-7 px-2",size:"sm",children:[e.jsx(n.SlidersHorizontal,{className:"mr-2 h-4 w-4"}),"Controls"]})}),e.jsx(n.PopoverContent,{className:"w-[620px] max-w-[95vw] space-y-4",align:"end",onEscapeKeyDown:u,onPointerDownOutside:u,children:v})]}):e.jsx(s.Dialog,{open:i,onOpenChange:p,children:e.jsxs(s.DialogContent,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:u,onPointerDownOutside:u,children:[e.jsxs(s.DialogHeader,{className:c?"space-y-0":void 0,children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:T}),e.jsx(s.DialogDescription,{className:c?"sr-only":"text-[13px]",children:c?"Configure and add a shared dashboard control.":"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),e.jsx("div",{className:"min-h-0 overflow-y-auto pr-1",children:A})]})})}const ft=["enum","multi_enum","text","number","boolean","date"];function Fe({open:t,onOpenChange:r,initialMode:l="manage"}){var v;const o=l==="create",{forceClose:a,handleOpenChange:d,isCreateFlowActive:h,preventPassiveDismissDuringCreate:p,resolvedOpen:c,setIsCreateFlowActive:u}=V.useCreateFlowOverlayState({open:t,onOpenChange:r,initialCreateFlowActive:l==="create",dismissMode:"explicit-only"}),i=n.useDashboardStore(j=>j.dashboard),g=n.useDashboardStore(j=>j.selectedSheetId),{setDashboardInputs:m}=n.useDashboardActions(),f=(v=i.sheets)==null?void 0:v.find(j=>j.id===g),w=(f==null?void 0:f.kind)==="document"&&!!f.document,y=x.useMemo(()=>w&&(f!=null&&f.document)?s.getDocumentSheetDashboardInputs(i,f.id):[],[i,w,f==null?void 0:f.document,f==null?void 0:f.id]),E=x.useMemo(()=>y.filter(j=>j.kind==="control"),[y]),B=x.useMemo(()=>E.map(j=>j.control),[E]),D=x.useMemo(()=>bt(B),[B]),b=x.useMemo(()=>gt(i),[i]),S=x.useCallback(()=>{if(o){a();return}u(!1)},[o,a,u]),A=x.useCallback((j,L,I)=>{!w||!(f!=null&&f.document)||m(jt({allInputs:i.inputs||[],documentSheetId:f.id,currentDocumentInputs:y,nextControls:j,nextDefaultValues:L,change:I}))},[i.inputs,y,w,f,m]);if(!w||!(f!=null&&f.document))return null;const T=h?"Add document control":"Document Controls";return e.jsx(s.Dialog,{open:c,onOpenChange:d,children:e.jsxs(s.DialogContent,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:p,onPointerDownOutside:p,children:[e.jsxs(s.DialogHeader,{className:h?"space-y-0":void 0,children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:T}),e.jsx(s.DialogDescription,{className:h?"sr-only":"text-[13px]",children:h?"Configure and add a document-local control input.":"Add document-local control inputs. They are stored on this document sheet and are not dashboard controls."})]}),e.jsx("div",{className:"min-h-0 overflow-y-auto pr-1",children:e.jsx(V.ControlDefinitionListEditor,{scope:"dashboard",controls:B,reservedControlIds:b,defaultValues:D,usageByControlId:{},availableFieldChoices:[],availableMetricChoices:[],structuralParticipants:[],structuralParticipantIdsByControlId:{},allowedControlTypes:ft,initialCreateFlow:l==="create",onCreateFlowActiveChange:u,onCreateFlowComplete:S,onChange:A,emptyMessage:"No document controls yet."})})]})})}function gt(t){return(t.controls||[]).map(r=>r.id)}function bt(t){const r={};for(const l of t)l.defaultValue!==void 0&&(r[l.id]=l.defaultValue);return r}function vt(t,r){return r?Object.prototype.hasOwnProperty.call(r,t.id)?{...t,defaultValue:r[t.id]}:t.defaultValue===void 0?t:{...t,defaultValue:void 0}:t.defaultValue===void 0?t:{...t,defaultValue:void 0}}function jt({allInputs:t,documentSheetId:r,currentDocumentInputs:l,nextControls:o,nextDefaultValues:a,change:d}){const h=new Map(o.map(m=>[m.id,vt(m,a)])),p=(d==null?void 0:d.type)==="rename"?{oldId:d.oldId,newId:d.newId}:null,c=new Set,u=[];for(const m of l){if(m.kind!=="control"){u.push(m);continue}const f=h.get(m.control.id)||((p==null?void 0:p.oldId)===m.control.id?h.get(p.newId):void 0);if(!f)continue;c.add(f.id);const w=n.createUniqueDashboardInputVariableNameFromName(f.id,[...t,...u].filter(E=>E.id!==m.id)),y=f.id===w?f:{...f,id:w};u.push({...m,label:y.label,variableName:w,requiredAtExecution:y.requiredAtExecution,control:y})}for(const m of h.values())c.has(m.id)||u.push(s.createDashboardControlInputFromControl({control:m,existingInputs:[...t,...u],sheetId:r}));const i=new Set(l.map(m=>m.id));return[...t.filter(m=>!i.has(m.id)),...u]}function Le({showFilters:t,onShowFiltersChange:r,pickerContent:l,settingsContent:o,size:a="default",className:d,primaryButtonClassName:h,secondaryButtonClassName:p,pickerContentClassName:c,settingsContentClassName:u}){const i=a==="toolbar",[g,m]=x.useState(!1),f=s.useSurfaceAppearance("interactive");return e.jsxs("div",{className:n.cn("relative inline-flex items-stretch overflow-hidden rounded-control border border-input bg-background",i?"h-8":"h-7",d),children:[e.jsxs(n.Popover,{open:t,onOpenChange:r,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"ghost",size:"xs",className:n.cn("h-full rounded-none border-0 bg-transparent pl-2.5 pr-2 shadow-none hover:bg-accent/50 data-[state=open]:bg-accent/60",h),children:[t?e.jsx(V.FilterX,{className:"h-3.5 w-3.5"}):e.jsx(s.Filter,{className:"h-3.5 w-3.5"}),"Filter"]})}),e.jsx(n.PopoverContent,{align:"end",sideOffset:6,className:n.cn("w-auto rounded-card border border-border/60 p-0 shadow-sm",c),style:f.contentStyle,children:l})]}),e.jsxs(n.Popover,{open:g,onOpenChange:m,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsx(n.Button,{variant:"ghost",size:"xs",className:n.cn("h-full w-7 rounded-none border-0 border-l border-border/60 bg-transparent px-0 shadow-none hover:bg-accent/50 data-[state=open]:bg-accent/60",p),"aria-label":"Filter and control actions",children:e.jsx(K.ChevronDown,{className:"h-3.5 w-3.5"})})}),e.jsx(n.PopoverContent,{align:"end",sideOffset:6,className:n.cn("w-auto rounded-card border border-border/60 p-0 shadow-sm",u),style:f.contentStyle,children:o(()=>m(!1))})]})]})}function Ct(){V.useSyncLegacyEditorState();const t=n.useDashboardStore(c=>c.selectedSheetId),r=n.useDashboardStore(c=>c.selectedFrameId),l=n.useDashboardStore(c=>c.dashboard),o=n.useDashboardStore(c=>c.actions.getSelectedFrame),{setSelectedFrameId:a}=n.useDashboardActions(),{setCard:d}=n.useEditorActions(),h=n.useEditorStore(c=>c.card.dataSource);return x.useEffect(()=>{var u,i;let c=o();if(!c){const g=(u=l==null?void 0:l.sheets)==null?void 0:u.find(f=>f.id===t),m=(i=g==null?void 0:g.frames)==null?void 0:i[0];m&&(a(m.id),c=m)}if(c){const g=c.cards.find(m=>m.id===c.activeCardId);g&&d(g)}},[o,t,r,l,a,d]),{hasEntities:!!(h!=null&&h.selectedEntities&&h.selectedEntities.length>0)}}function yt(){const t=n.useDashboardStore(c=>c.dashboard),r=n.useDashboardStore(c=>c.semanticExecutionPayload),l=n.useDashboardStore(c=>c.actions.addFilter),{hasEntities:o}=Ct(),{isLoading:a}=s.useFilterableFields(),d=x.useMemo(()=>n.getGlobalDateFilterCoverage(t,r),[t,r]),p=!n.getGlobalDateFilter(t.filters)&&d.hasEligibleCards&&!a;return e.jsxs("div",{className:"flex h-[520px] w-[400px] flex-col",children:[p&&e.jsx("div",{className:"border-b border-border/60 p-2",children:e.jsxs("button",{type:"button",onClick:()=>l(n.createDefaultGlobalDateFilter()),title:`Applies to ${d.eligibleCardCount} of ${d.totalCardCount} date-aware cards`,className:"flex w-full items-start gap-2 rounded-[4px] px-2 py-1.5 text-left outline-none transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-border",children:[e.jsx(_e,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"text-[12px] font-medium text-foreground",children:"Add global date filter"}),e.jsx("span",{className:"text-[11px] leading-[1.4] text-muted-foreground",children:"One date range across all date-aware cards."})]})]})}),!o&&e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-6 py-8 text-center",children:[e.jsx(s.Database,{className:"mb-3 h-10 w-10 text-muted-foreground/50"}),e.jsx("h3",{className:"mb-1 text-[13px] font-medium text-foreground",children:"No fields configured"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Configure a data source for this card to enable filtering."})]}),o&&e.jsx("div",{className:"flex flex-1 overflow-hidden",children:e.jsx(s.FilterableFieldsPanel,{context:"filter"})})]})}const Se=!1;function wt({onAddFilter:t,onAddControl:r,onManageControls:l,onDismiss:o}){const a=n.useDashboardStore(p=>p.dashboard.filterLayout),{setFilterLayout:d}=n.useDashboardActions();a!=null&&a.displayMode;const h=(a==null?void 0:a.toolbarWrap)??!1;return a==null||a.showDownloadButton,e.jsxs("div",{className:"w-[300px]",children:[e.jsxs("div",{className:"p-1",children:[e.jsx(ve,{icon:s.Filter,label:"Add filter",onClick:()=>{t(),o()}}),e.jsx(ve,{icon:n.SlidersHorizontal,label:"Add control",onClick:()=>{r(),o()}}),e.jsx(ve,{icon:s.Pencil,label:"Manage controls",onClick:()=>{l(),o()}})]}),e.jsx("div",{className:"border-t border-border/60"}),e.jsxs("div",{className:"space-y-1 p-2",children:[e.jsx("p",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Display"}),Se,e.jsx(Nt,{id:"filter-display-wrap",label:"Wrap to multiple lines",checked:h,onCheckedChange:p=>d({toolbarWrap:p===!0})}),Se]})]})}function ve({icon:t,label:r,onClick:l}){return e.jsxs("button",{type:"button",onClick:l,className:"flex w-full items-center gap-2 rounded-[4px] px-2 py-1.5 text-left text-[13px] text-foreground transition-colors hover:bg-muted/40",children:[e.jsx(t,{className:"h-3.5 w-3.5 text-muted-foreground"}),r]})}function Nt({id:t,label:r,checked:l,onCheckedChange:o}){return e.jsxs("div",{className:"flex items-center gap-2 rounded-[4px] px-1 py-1 transition-colors hover:bg-muted/40",children:[e.jsx(s.Checkbox,{id:t,checked:l,onCheckedChange:o}),e.jsx(n.Label,{htmlFor:t,className:"cursor-pointer text-[12px] font-normal leading-[1.3]",children:r})]})}function Dt({size:t,className:r,primaryButtonClassName:l,secondaryButtonClassName:o,pickerContentClassName:a,settingsContentClassName:d}){var T;const[h,p]=x.useState(null),c=n.useDashboardStore(v=>v.dashboard),u=n.useDashboardStore(v=>v.selectedSheetId),i=n.useDashboardStore(v=>v.showFilters),g=s.useAssistantLayoutStore(v=>v.setPanelOpen),m=n.useDashboardStore(v=>v.actions),{setDocumentInspectorTab:f,setShowFilters:w}=m,y=(T=c.sheets)==null?void 0:T.find(v=>v.id===u),E=n.isDocumentSheet(y),B=x.useCallback(v=>{window.setTimeout(()=>{p(v)},0)},[]),D=x.useCallback(v=>{if(E&&u){v&&f(u,"inputs");return}v&&g("dashboard",!1),w(v)},[E,u,f,g,w]),b=x.useCallback(()=>{D(!0)},[D]),S=x.useCallback(()=>{B("create")},[B]),A=x.useCallback(()=>{B("manage")},[B]);return e.jsxs(e.Fragment,{children:[e.jsx(Le,{showFilters:E?!1:i,onShowFiltersChange:D,pickerContent:e.jsx(yt,{}),settingsContent:v=>e.jsx(wt,{onAddFilter:b,onAddControl:S,onManageControls:A,onDismiss:v}),size:t,className:r,primaryButtonClassName:l,secondaryButtonClassName:o,pickerContentClassName:a,settingsContentClassName:d}),h?E?e.jsx(Fe,{open:!0,onOpenChange:v=>{v||p(null)},initialMode:h}):e.jsx(Ie,{open:!0,onOpenChange:v=>{v||p(null)},showTrigger:!1,initialMode:h}):null]})}function Te({disabled:t,briefingCount:r,className:l,onClick:o}){const a=typeof r=="number"&&r>0;return e.jsxs(n.Button,{type:"button",size:"xs",variant:"outline",disabled:t,className:n.cn("gap-1.5",l),onClick:o,"aria-label":"Reports & briefings",children:[e.jsx(qe,{className:"h-3.5 w-3.5"}),"Reports & briefings",a?e.jsx("span",{className:"ml-0.5 rounded-control bg-muted px-1 text-[10px] tabular-nums text-foreground/70",children:r}):null]})}const St="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",Me="inline-flex h-7 items-center gap-1.5 rounded-control px-2 text-[12px] text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-50",pe="inline-flex h-7 items-center gap-1.5 rounded-control bg-primary px-3 text-[12px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50";function Et(t){return t==="dashboard"?"This dashboard":"Project"}function At(t){if(!t)return"Never";const r=new Date(t);if(Number.isNaN(r.getTime()))return"Unknown";const l=Date.now()-r.getTime(),o=Math.round(l/6e4);if(o<1)return"now";if(o<60)return`${o}m ago`;const a=Math.round(o/60);if(a<24)return`${a}h ago`;const d=Math.round(a/24);if(d<7)return`${d}d ago`;const h=Math.round(d/7);return h<5?`${h}w ago`:`${Math.round(d/30)}mo ago`}function kt(t){return t.scheduleExpr?X.describeBriefingSchedule(t.scheduleExpr,t.timezone||"UTC")??"Invalid schedule":"On demand"}function Bt(t){if(t.lastRunStatus){const r=t.lastRunStatus.toString().toUpperCase();return r==="SUCCESS"?"Last run completed.":r==="FAILED"?"Last run failed.":`Last run ${t.lastRunStatus.toString().toLowerCase()}`}return null}function Pe(t){return t.hasActiveRun?"Running":t.lastRunStatus?`Last run ${t.lastRunStatus.toString().toLowerCase()}`:"Idle"}function It(t){return t.source.type==="dashboard"?"This dashboard":"Project"}function Ft({activeView:t,onChange:r}){return e.jsx("div",{className:"flex shrink-0 items-center gap-1 rounded-control bg-muted p-0.5",role:"tablist","aria-label":"Briefing source view",children:["dashboard","project"].map(l=>{const o=t===l;return e.jsx("button",{type:"button",role:"tab","aria-selected":o,onClick:()=>r(l),className:n.cn("h-6 rounded-[3px] px-2 text-[11px] transition-colors",o?"bg-background font-medium text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:Et(l)},l)})})}function Lt({briefings:t,dashboardLabel:r,sourceView:l,error:o,loading:a,onSourceViewChange:d,onClose:h,onEdit:p,onNew:c,canCreate:u,canCreateScheduledReport:i,analyticalBriefingsEnabled:g,onRunNow:m,onTogglePause:f,onDelete:w,selectingId:y,busyId:E,manageBriefingsHref:B,contentKind:D,hideHeader:b=!1}){const S=t.length,A=t.filter(I=>I.status==="ACTIVE").length,T=D==="reports"?S===1?"report":"reports":D==="briefings"?S===1?"briefing":"briefings":S===1?"item":"items",v=t.find(I=>I.hasActiveRun)??null,j=D??"reports & briefings",L=l==="dashboard"?r:`Project ${j}`;return e.jsxs("section",{"aria-label":`Dashboard ${j.replace("&","and")}`,className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:[b?null:e.jsxs("header",{className:"flex items-start justify-between gap-3 border-b border-border px-4 py-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:St,children:j}),e.jsx("h2",{className:"mt-0.5 truncate text-[14px] font-semibold leading-5",children:L})]}),e.jsx("button",{type:"button",onClick:h,className:"rounded-control p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":`Close ${j.replace("&","and")} panel`,children:e.jsx(K.X,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border px-4 py-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(Ft,{activeView:l,onChange:d}),e.jsx("div",{className:"flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:a&&S===0?e.jsxs("span",{children:["Loading ",j,"…"]}):S===0?e.jsxs("span",{children:["No ",j," yet"]}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"font-medium text-foreground/80",children:[S," ",T]}),e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{children:[A," active"]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[a?e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}):null,S>0&&u?g&&i?e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsxs("button",{className:pe,children:[e.jsx(s.Plus,{className:"h-3 w-3"})," New"]})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuItem,{onClick:()=>c("scheduled_report"),children:"Schedule a report"}),e.jsx(s.DropdownMenuItem,{onClick:()=>c("analytical_briefing"),children:"Create analytical briefing"})]})]}):i?e.jsxs("button",{onClick:()=>c("scheduled_report"),className:pe,children:[e.jsx(s.Plus,{className:"h-3 w-3"})," Schedule report"]}):g?e.jsxs("button",{onClick:()=>c("analytical_briefing"),className:pe,children:[e.jsx(s.Plus,{className:"h-3 w-3"})," New briefing"]}):null:null]})]}),v?e.jsxs("div",{className:"flex items-center gap-2 border-b border-border bg-muted/60 px-4 py-2 text-[12px]",children:[e.jsx(n.LoaderCircle,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}),e.jsx("span",{className:"font-medium text-foreground",children:v.name}),e.jsx("span",{className:"text-border",children:"·"}),e.jsx("span",{className:"truncate text-muted-foreground",children:Pe(v)})]}):null,e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[o?e.jsx("div",{className:"m-4 rounded-card border border-destructive/30 bg-destructive/10 px-3 py-2 text-[12px] text-destructive",children:o}):null,!a&&t.length===0&&!o?e.jsx(Tt,{onNew:c,canCreate:u,canCreateScheduledReport:i,analyticalBriefingsEnabled:g,contentKind:D}):null,t.map(I=>e.jsx(Pt,{briefing:I,isOpening:y===I.id,isBusy:E===I.id,onOpen:()=>p(I.id),onRunNow:()=>m(I),onTogglePause:()=>f(I),onDelete:()=>w(I)},I.id))]}),B?e.jsx("div",{className:"border-t border-border px-4 py-2.5",children:e.jsxs("a",{href:B,className:n.cn(Me,"h-6 px-1 text-[11px]"),children:["Manage all reports & briefings",e.jsx(ze,{className:"h-3 w-3"})]})}):null]})}function Tt({onNew:t,canCreate:r,canCreateScheduledReport:l,analyticalBriefingsEnabled:o,contentKind:a}){const d=a==="reports"?{title:"No reports yet",description:"Schedule an emailed dashboard or visual report to see it here."}:a==="briefings"?{title:"No briefings yet",description:"Create an analytical briefing to monitor this dashboard and brief your team."}:null;return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-8 py-12 text-center",children:[e.jsx(Mt,{className:"mb-5 h-[88px] w-[112px] text-border"}),e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:(d==null?void 0:d.title)??"Have an analyst brief your team"}),e.jsx("p",{className:"mt-1.5 max-w-[320px] text-[12px] leading-5 text-muted-foreground",children:(d==null?void 0:d.description)??"Describe what to watch. An analyst digs into this dashboard and the data behind it, then briefs your team on the cadence you choose."}),r?e.jsxs("div",{className:"mt-4 flex flex-wrap justify-center gap-2",children:[l?e.jsxs("button",{onClick:()=>t("scheduled_report"),className:pe,children:[e.jsx(s.Plus,{className:"h-3 w-3"})," Schedule a report"]}):null,o?e.jsx("button",{onClick:()=>t("analytical_briefing"),className:Me,children:"Create analytical briefing"}):null]}):null]})}function Mt({className:t}){return e.jsxs("svg",{viewBox:"0 0 112 88",fill:"none",xmlns:"http://www.w3.org/2000/svg",role:"presentation","aria-hidden":"true",className:t,children:[e.jsx("rect",{x:"22",y:"6",width:"60",height:"72",rx:"3",stroke:"currentColor",strokeWidth:"1.25"}),e.jsx("line",{x1:"30",y1:"16",x2:"64",y2:"16",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),e.jsx("line",{x1:"30",y1:"21",x2:"52",y2:"21",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round",opacity:"0.5"}),e.jsx("circle",{cx:"31",cy:"32",r:"1",fill:"currentColor",opacity:"0.6"}),e.jsx("line",{x1:"35",y1:"32",x2:"72",y2:"32",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),e.jsx("circle",{cx:"31",cy:"38",r:"1",fill:"currentColor",opacity:"0.6"}),e.jsx("line",{x1:"35",y1:"38",x2:"68",y2:"38",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),e.jsx("circle",{cx:"31",cy:"44",r:"1",fill:"currentColor",opacity:"0.6"}),e.jsx("line",{x1:"35",y1:"44",x2:"74",y2:"44",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),e.jsx("rect",{x:"30",y:"64",width:"5",height:"8",rx:"0.5",fill:"currentColor",opacity:"0.55"}),e.jsx("rect",{x:"38",y:"60",width:"5",height:"12",rx:"0.5",fill:"currentColor",opacity:"0.7"}),e.jsx("rect",{x:"46",y:"56",width:"5",height:"16",rx:"0.5",fill:"currentColor",opacity:"0.85"}),e.jsx("rect",{x:"54",y:"62",width:"5",height:"10",rx:"0.5",fill:"currentColor",opacity:"0.6"}),e.jsx("rect",{x:"62",y:"58",width:"5",height:"14",rx:"0.5",fill:"currentColor",opacity:"0.75"}),e.jsx("circle",{cx:"86",cy:"62",r:"10",fill:"var(--background, white)",stroke:"currentColor",strokeWidth:"1.25"}),e.jsx("line",{x1:"93.5",y1:"69.5",x2:"100",y2:"76",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})}function Pt({briefing:t,isOpening:r,isBusy:l,onOpen:o,onRunNow:a,onTogglePause:d,onDelete:h}){const p=t.status==="PAUSED",c=t.hasActiveRun,u=Bt(t),i=At(t.lastRunAt),g=t.lastRunStatus,m=X.getBriefingPresentation(t),f=g==="SUCCESS"?s.briefingTone.success.dot:g==="FAILED"?s.briefingTone.danger.dot:g?s.briefingTone.warning.dot:s.briefingTone.neutral.dot;return e.jsxs("div",{className:n.cn("group relative border-b border-border/60 px-4 py-3 transition-colors hover:bg-muted/60",p&&"opacity-70"),children:[e.jsxs("div",{role:"button",tabIndex:0,onClick:o,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),o())},className:"cursor-pointer pr-8",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-foreground",children:t.name}),p?e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:"· Paused"}):null]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-1.5 text-[11px] text-muted-foreground",children:[e.jsx("span",{children:m.typeLabel}),e.jsx("span",{className:"text-border",children:"·"}),e.jsx("span",{children:It(t)}),e.jsx("span",{className:"text-border",children:"·"}),e.jsx(s.Clock,{className:"h-3 w-3"}),e.jsx("span",{className:"truncate",children:kt(t)}),t.lastRunAt?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{children:["Last run ",i]})]}):null]}),u||c?e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5 text-[12px] leading-[1.5] text-foreground/80",children:[c?e.jsx(n.LoaderCircle,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground/70"}):e.jsx("span",{className:n.cn("inline-block h-1.5 w-1.5 shrink-0 rounded-full",f)}),e.jsx("span",{className:"truncate",children:c?Pe(t):u})]}):null]}),e.jsx("div",{className:"absolute right-3 top-3",children:l?e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground/70"}):r?e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground/70"}):e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx("button",{type:"button",onClick:w=>w.stopPropagation(),className:"inline-flex h-6 w-6 items-center justify-center rounded-control text-muted-foreground/70 opacity-60 hover:bg-muted hover:text-foreground/80 focus-visible:opacity-100 group-hover:opacity-100","aria-label":`${m.noun==="report"?"Report":"Briefing"} actions`,children:e.jsx(s.Ellipsis,{className:"h-3.5 w-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-44",children:[e.jsxs(s.DropdownMenuItem,{onClick:o,children:[e.jsx(s.Pencil,{className:"h-3.5 w-3.5"}),"Edit ",m.noun]}),e.jsxs(s.DropdownMenuItem,{onClick:w=>{w.preventDefault(),a()},children:[e.jsx(s.Zap,{className:"h-3.5 w-3.5"}),"Run now"]}),t.scheduleExpr?e.jsx(s.DropdownMenuItem,{onClick:w=>{w.preventDefault(),d()},children:p?e.jsxs(e.Fragment,{children:[e.jsx(s.Play,{className:"h-3.5 w-3.5"}),"Resume"]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Pause,{className:"h-3.5 w-3.5"}),"Pause"]})}):null,e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{onClick:w=>{w.preventDefault(),h()},className:"text-destructive focus:bg-destructive/10 focus:text-destructive",children:[e.jsx(s.Trash2,{className:"h-3.5 w-3.5"}),"Delete ",m.noun]})]})]})})]})}const Vt=2e3,Rt=20*6e4;function Ut(t){return(t==null?void 0:t.trim())||"This dashboard"}function Ot(t){return t==="This dashboard"?"Watch this dashboard":`Watch ${t}`}function zt(t,r,l){return r!=="dashboard"?t:t.filter(o=>o.source.type==="dashboard"&&o.source.dashboardId===l)}async function _t(t){const l=[];let o=1,a=0,d=Number.POSITIVE_INFINITY;for(;a<d;){const h=await t.apiClient.listBriefings(t.apiServiceUrl,t.token,{scope:"organization",page:o,pageSize:100});if(l.push(...h.briefings),a+=h.briefings.length,d=h.total,h.briefings.length===0||a>=d)break;o+=1}return l}const $t={listBriefings:s.listBriefings,getBriefing:s.getBriefing,pauseBriefing:s.pauseBriefing,resumeBriefing:s.resumeBriefing,deleteBriefing:s.deleteBriefing,runBriefingNow:s.runBriefingNow};function qt({briefingId:t,initialRun:r,apiServiceUrl:l,token:o,onTerminal:a,onTimeout:d,onExpand:h}){const[p,c]=x.useState(r),{startRun:u}=s.useBriefingRunPolling({apiServiceUrl:l,token:o,intervalMs:Vt,timeoutMs:Rt,fetchRun:({apiServiceUrl:g,token:m,runId:f})=>s.getBriefingRun(g,m,t,f),onRun:g=>{c(g)},onTerminalRun:g=>{a(g)},onTimeout:()=>{d()}}),i=x.useRef(!1);return x.useEffect(()=>{i.current||(i.current=!0,s.isActiveBriefingRunStatus(r.status)?u(r):s.isTerminalBriefingRunStatus(r.status)&&a(r))},[r,a,u]),e.jsx(s.BackgroundRunPill,{run:p,onExpand:h})}function Ht(t){return e.jsx(s.BriefingUiCapabilitiesBoundary,{children:e.jsx(Wt,{...t})})}function Wt({dashboardId:t,dashboardTitle:r,apiServiceUrl:l,token:o,disabled:a,className:d,manageBriefingsHref:h,open:p,onOpenChange:c,hideTrigger:u=!1,workflowIntent:i,client:g}){const{authToken:m,tokenProps:f}=s.useSemaphorContext(),w=s.useBriefingUiCapabilities(),y=!i||w.canCreate&&(i==="scheduled_report"||w.analyticalBriefingsEnabled),[E,B]=x.useState(!1),D=p??E,b=N=>{p===void 0&&B(N),c==null||c(N)},[S,A]=x.useState(i?"author":"list"),[T,v]=x.useState(i??"analytical_briefing"),[j,L]=x.useState("dashboard"),[I,$]=x.useState([]),[k,M]=x.useState(null),_=i&&!y&&!k?"list":S,[oe,q]=x.useState(!1),[fe,ie]=x.useState(null),[ge,W]=x.useState(null),[U,Q]=x.useState(null),[ee,te]=x.useState(null),le=x.useRef(null),ue=x.useRef(D);x.useEffect(()=>{const N=D&&!ue.current;ue.current=D,!(!N||!i)&&(M(null),L("dashboard"),v(i),A("author"),te(null))},[D,i]);const[se,ne]=x.useState(null),[G,ce]=x.useState(null),O=l??(f==null?void 0:f.apiServiceUrl),z=o??(m==null?void 0:m.accessToken),Z=x.useMemo(()=>({...$t,...g}),[g]),ae=Ut(r),he=x.useMemo(()=>{const N=zt(I,j,t);if(!i)return N;const P=i==="scheduled_report"?"report":"briefing";return N.filter(me=>X.getBriefingPresentation(me).noun===P)},[t,I,j,i]),be=x.useMemo(()=>j==="dashboard"?{source:{type:"dashboard",dashboardId:t},label:ae,detail:Ot(ae)}:{source:{type:"project"},label:"This project",detail:"Use any data in this project."},[t,ae,j]),de=!!(O&&z),re=X.getBriefingCreationIntents({canCreate:w.canCreate,analyticalBriefingsEnabled:w.analyticalBriefingsEnabled,scheduledReportAvailable:j==="dashboard"}),H=x.useCallback(async()=>{if(!(!O||!z)){q(!0),te(null);try{$(await _t({apiClient:Z,apiServiceUrl:O,token:z}))}catch(N){te(N instanceof Error?N.message:"Could not load briefings.")}finally{q(!1)}}},[Z,O,z]);x.useEffect(()=>{!D||_!=="list"||!de||H()},[de,_,H,D]);const C=()=>{M(null),L("dashboard"),A("list"),b(!0)},F=N=>{M(null),v(N),A("author")},R=async N=>{if(!(!O||!z)){ie(N),te(null);try{const P=await Z.getBriefing(O,z,N);M(P.briefing),A("author")}catch(P){te(P instanceof Error?P.message:"Could not open briefing.")}finally{ie(null)}}},Y=async N=>{if(!(!O||!z)){W(N.id);try{await Z.runBriefingNow(O,z,N.id,{requestId:Gt()}),H()}catch(P){s.ue.error(P instanceof Error?P.message:"Could not start the run.")}finally{W(null)}}},J=async N=>{if(!O||!z)return;const{noun:P}=X.getBriefingPresentation(N),me=P==="report"?"Report":"Briefing";W(N.id);try{const xe=N.status==="PAUSED"?await Z.resumeBriefing(O,z,N.id):await Z.pauseBriefing(O,z,N.id);s.ue.success(xe.briefing.status==="PAUSED"?`${me} paused`:`${me} resumed`),H()}catch(xe){s.ue.error(xe instanceof Error?xe.message:`Could not update the ${P} status.`)}finally{W(null)}},Ve=async()=>{if(!U||!O||!z)return;const N=U;W(N.id);try{await Z.deleteBriefing(O,z,N.id);const{noun:P}=X.getBriefingPresentation(N);s.ue.success(`${P==="report"?"Report":"Briefing"} deleted`),Q(null),H()}catch(P){s.ue.error(P instanceof Error?P.message:"Could not delete the briefing.")}finally{W(null)}},Re=he.length;return w.surfaceVisible?e.jsxs(s.Sheet,{open:D,onOpenChange:b,children:[u?null:e.jsx(Te,{disabled:a||!de,briefingCount:Re,className:d,onClick:C}),e.jsxs(s.SheetContent,{ref:le,side:"right",hideClose:!0,className:"flex h-full w-full flex-col overflow-hidden p-0 outline-none sm:max-w-[560px]",onOpenAutoFocus:N=>{var P;N.preventDefault(),(P=le.current)==null||P.focus({preventScroll:!0})},children:[e.jsxs(s.SheetHeader,{className:"sr-only",children:[e.jsx(s.SheetTitle,{children:"Reports & briefings"}),e.jsx(s.SheetDescription,{children:"Manage reports and briefings for this dashboard."})]}),i?e.jsxs("div",{className:"flex shrink-0 items-start justify-between gap-3 border-b border-border pl-4 pr-3 pt-2",children:[e.jsxs("div",{className:"flex items-center gap-5",role:"tablist","aria-label":i==="scheduled_report"?"Email report workflow":"Analytical briefing workflow",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":_==="author",disabled:!y,className:n.cn("-mb-px border-b-2 px-0.5 pb-2 text-[12px] transition-colors",_==="author"?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground",!y&&"cursor-not-allowed opacity-50"),onClick:()=>{y&&(M(null),v(i),L("dashboard"),A("author"))},children:k?`Edit ${X.getBriefingPresentation(k).noun}`:i==="scheduled_report"?"Schedule report":"Create briefing"}),e.jsx("button",{type:"button",role:"tab","aria-selected":_==="list",className:n.cn("-mb-px border-b-2 px-0.5 pb-2 text-[12px] transition-colors",_==="list"?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),onClick:()=>A("list"),children:i==="scheduled_report"?"Manage reports":"Manage briefings"})]}),e.jsx("button",{type:"button",onClick:()=>b(!1),className:"rounded-control p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":i==="scheduled_report"?"Close email report workflow":"Close analytical briefing workflow",children:e.jsx(K.X,{className:"h-3.5 w-3.5"})})]}):null,_==="list"?e.jsx(Lt,{briefings:he,dashboardLabel:ae,sourceView:j,error:ee,loading:oe,onSourceViewChange:L,onClose:()=>b(!1),onEdit:N=>{R(N)},onNew:F,canCreate:!i&&re.length>0,canCreateScheduledReport:re.includes("scheduled_report"),analyticalBriefingsEnabled:re.includes("analytical_briefing"),onRunNow:N=>{Y(N)},onTogglePause:N=>{J(N)},onDelete:N=>Q(N),selectingId:fe,busyId:ge,manageBriefingsHref:h,contentKind:i==="scheduled_report"?"reports":i==="analytical_briefing"?"briefings":void 0,hideHeader:!!i}):e.jsx(s.BriefingAuthor,{apiServiceUrl:O,token:z,briefing:k,intent:T,sourceContext:k?void 0:be,title:k?`Edit ${X.getBriefingPresentation(k).noun}`:T==="scheduled_report"?"Schedule report":"Create analytical briefing",hideHeader:!!i,className:"h-full min-h-0 max-w-none border-0 shadow-none",onBack:i?void 0:()=>A("list"),onCancel:()=>b(!1),onDeleted:()=>{const N=k?X.getBriefingPresentation(k).noun:"briefing";s.ue.success(`${N==="report"?"Report":"Briefing"} deleted`),M(null),A("list"),H()},onRunStarted:()=>{},onSaved:N=>{M(N),H()},onMinimizeRun:({briefing:N,run:P})=>{ne({briefing:N,run:P}),b(!1)}})]}),se&&O&&z?e.jsx(qt,{briefingId:se.briefing.id,initialRun:se.run,apiServiceUrl:O,token:z,onTerminal:N=>{ce({briefing:se.briefing,run:N}),ne(null),H()},onTimeout:()=>{ne(null),H()},onExpand:()=>{M(se.briefing),A("author"),ne(null),b(!0)}}):null,G?e.jsx("div",{className:"fixed bottom-4 right-4 z-50 w-[360px]",children:e.jsx(s.RunCompletionBanner,{title:G.run.status==="SUCCESS"?`${G.briefing.name} is ready`:`${G.briefing.name} run failed`,durationSeconds:G.run.startedAt&&G.run.completedAt?Math.max(0,Math.floor((new Date(G.run.completedAt).getTime()-new Date(G.run.startedAt).getTime())/1e3)):null,status:G.run.status==="SUCCESS"?"success":"failed",onView:()=>{M(G.briefing),A("author"),ce(null),b(!0)},onDismiss:()=>ce(null)})}):null,e.jsx(s.AlertDialog,{open:!!U,onOpenChange:N=>{N||Q(null)},children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsxs(s.AlertDialogTitle,{children:["Delete"," ",U?X.getBriefingPresentation(U).noun:"briefing","?"]}),e.jsxs(s.AlertDialogDescription,{children:["This permanently deletes ",e.jsx("strong",{children:U==null?void 0:U.name}),". Recipients will stop receiving it."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsxs(s.AlertDialogAction,{className:"bg-destructive/90 hover:bg-destructive",onClick:Ve,children:["Delete"," ",U?X.getBriefingPresentation(U).noun:"briefing"]})]})]})})]}):null}function Gt(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`briefing-run-now-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}exports.AdvancedModeToggle=rt;exports.DashboardBriefingLauncher=Ht;exports.DashboardControlsSettings=Ie;exports.DashboardFilterControlsButton=Le;exports.DashboardFilterControlsLauncher=Dt;exports.DocumentControlsSettings=Fe;exports.ExportNotificationItem=ke;exports.ExportNotificationList=Be;exports.NotificationBell=xt;exports.UnsavedChangesAlert=nt;exports.VisualEditingControls=st;exports.VisualsLibraryDialog=Qe;exports.WatchDashboardButton=Te;exports.useExportPolling=ut;exports.useExportRecovery=ht;