limixbot 0.3.4 → 0.3.12

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 (133) hide show
  1. package/dist/assets/{ActivityPanel-BG18nJiz.js → ActivityPanel-CJM61CWQ.js} +1 -1
  2. package/dist/assets/{App-8heymKKb.js → App-DRnqqiJP.js} +125 -125
  3. package/dist/assets/{AppEventEditor-D5dGKlRO.js → AppEventEditor-1hupO_kL.js} +1 -1
  4. package/dist/assets/{BotSettingsDialog-Ct_Yktk8.js → BotSettingsDialog-B56-kmya.js} +4 -4
  5. package/dist/assets/{BrowserPanel-Cyws1YTJ.js → BrowserPanel-BXBygd1y.js} +1 -1
  6. package/dist/assets/{BrowserProfilesManager-BEUgS3Me.js → BrowserProfilesManager-CzzGhZGz.js} +1 -1
  7. package/dist/assets/CloudAddDialog-MMhMrVK3.js +1 -0
  8. package/dist/assets/{ComputerFilesPane-BGywdHPB.js → ComputerFilesPane-Hpxjnk2e.js} +1 -1
  9. package/dist/assets/ComputerPanel-CMce64RT.js +2 -0
  10. package/dist/assets/{DataPanel-CIvvbY5b.js → DataPanel-BQ7Ua1Oq.js} +1 -1
  11. package/dist/assets/{DesktopViewer-BNIgo9Nm.js → DesktopViewer-BRzNtGEm.js} +1 -1
  12. package/dist/assets/{FilesView-Cd5kwljm.js → FilesView-DQYXl0zm.js} +1 -1
  13. package/dist/assets/{GrokMoveDialog-B2Vgd-vB.js → GrokMoveDialog-Dk-pwczv.js} +1 -1
  14. package/dist/assets/{InspectorPanel-Bxm2bVHy.js → InspectorPanel-CvnM0TFW.js} +1 -1
  15. package/dist/assets/{KeyboardShortcutsModal-Dfcfy-EA.js → KeyboardShortcutsModal-BQ8aAw16.js} +1 -1
  16. package/dist/assets/{LiveDesktop-fbnBEFRL.js → LiveDesktop-Cr7uAFoQ.js} +1 -1
  17. package/dist/assets/LocalVmWorkspace-BJ-i68MR.js +1 -0
  18. package/dist/assets/MacLocalControl-DE8MVZkU.js +1 -0
  19. package/dist/assets/{MarkdownFilePreview--PNcCEvm.js → MarkdownFilePreview-B_6azXNT.js} +1 -1
  20. package/dist/assets/{MenuMotion-IQitGKH4.js → MenuMotion-BDYr4RxL.js} +1 -1
  21. package/dist/assets/{NewBotDialog-CZbVbamH.js → NewBotDialog-D9fUysLU.js} +1 -1
  22. package/dist/assets/PhoneAppDialog-DUv4Qx8n.js +1 -0
  23. package/dist/assets/{PlacesRail-v1XIqiBG.js → PlacesRail-yZdo57pP.js} +2 -2
  24. package/dist/assets/{PluginsPanel-Bj3Pn0Iw.js → PluginsPanel-DYuWdWZd.js} +1 -1
  25. package/dist/assets/{ProIntroduction-qFeFSzyk.js → ProIntroduction-DapZkP7I.js} +1 -1
  26. package/dist/assets/{RemoteAgentSettingsPanel-CcbUTgTg.js → RemoteAgentSettingsPanel-sNv3TbBd.js} +1 -1
  27. package/dist/assets/{RoomPanel-k0hQwspJ.js → RoomPanel-DrlyOJKZ.js} +1 -1
  28. package/dist/assets/{RoutinesPage-aANJQ--g.js → RoutinesPage-CIo30TVq.js} +2 -2
  29. package/dist/assets/SettingsModal-BpJhi2nc.js +11 -0
  30. package/dist/assets/{ShareTeamDialog-DeRaL6zM.js → ShareTeamDialog-CH1ts7Uj.js} +1 -1
  31. package/dist/assets/{SignedInSites-CfhTex9p.js → SignedInSites-CisTAQW0.js} +1 -1
  32. package/dist/assets/{TeamLibraryPanel-C7LZ7Onp.js → TeamLibraryPanel-DvnKye05.js} +1 -1
  33. package/dist/assets/TeamMapPage-JOiilgs0.js +1 -0
  34. package/dist/assets/TriggersPage-DQ3HQ6_i.js +1 -0
  35. package/dist/assets/{VisibilitySection-CCwpvTlJ.js → VisibilitySection-DXfPp0Ql.js} +6 -6
  36. package/dist/assets/{WebhookTrigger-wqj5vki5.js → WebhookTrigger-BYeOyOpX.js} +1 -1
  37. package/dist/assets/{WorksOnGrid-CenOXsZe.js → WorksOnGrid-8fCnUzpQ.js} +1 -1
  38. package/dist/assets/{abnfDiagram-YUKMZFIV-CBzJU2O6.js → abnfDiagram-YUKMZFIV-Boj-Bkbs.js} +1 -1
  39. package/dist/assets/{activity-bd7MWK8m.js → activity-MpAxS_kw.js} +1 -1
  40. package/dist/assets/{architectureDiagram-47P4ROYG-DVR1DP3v.js → architectureDiagram-47P4ROYG-Cl-ocqce.js} +1 -1
  41. package/dist/assets/{blockDiagram-E7TT5TSB-BYqUHhoh.js → blockDiagram-E7TT5TSB-0nSQiv6g.js} +1 -1
  42. package/dist/assets/{c4Diagram-CRA5TL53-BtQERHwr.js → c4Diagram-CRA5TL53-Cx9iymkb.js} +1 -1
  43. package/dist/assets/{calendar-days-YMHxUvlg.js → calendar-days-DXHDRm_4.js} +1 -1
  44. package/dist/assets/channel-BStWWrSt.js +1 -0
  45. package/dist/assets/{chunk-2Q5K7J3B-Cwf_xeHP.js → chunk-2Q5K7J3B-0rIrumUG.js} +1 -1
  46. package/dist/assets/{chunk-5VM5RSS4-Doo-zxI4.js → chunk-5VM5RSS4-w9e6iKvs.js} +1 -1
  47. package/dist/assets/{chunk-7TKQ45FW-CD2AgrRj.js → chunk-7TKQ45FW-c4KxVKkf.js} +1 -1
  48. package/dist/assets/{chunk-AW2ZBBNX-e5OuWeq_.js → chunk-AW2ZBBNX-DmaBcuOP.js} +1 -1
  49. package/dist/assets/{chunk-FVRAUYC3-C8jo43it.js → chunk-FVRAUYC3-BLzfqLHR.js} +2 -2
  50. package/dist/assets/{chunk-HTAEGDNF-DLsD4agj.js → chunk-HTAEGDNF-BN48XtBm.js} +1 -1
  51. package/dist/assets/{chunk-JWPE2WC7-UZDUbeTy.js → chunk-JWPE2WC7-D2NACa6i.js} +1 -1
  52. package/dist/assets/{chunk-KQW6MTUR-DR9SuVX3.js → chunk-KQW6MTUR-CbAfnxxG.js} +1 -1
  53. package/dist/assets/{chunk-XXDRQBXY-DwEl4815.js → chunk-XXDRQBXY-Bwg-DPP_.js} +1 -1
  54. package/dist/assets/{classDiagram-v2-K4WV4PDN-CQZho8e0.js → classDiagram-v2-K4WV4PDN-Dh3ohoZp.js} +1 -1
  55. package/dist/assets/{coins-DpzGN3sd.js → coins-Bv8-qll4.js} +1 -1
  56. package/dist/assets/{core-C_G-J8y-.js → core-DeJAGBXR.js} +1 -1
  57. package/dist/assets/{cose-bilkent-JH36ORCC-DUZ9OWzu.js → cose-bilkent-JH36ORCC-DCHadn0L.js} +1 -1
  58. package/dist/assets/{cynefin-EF2NZ3EQ-DVHnJdjN.js → cynefin-EF2NZ3EQ-ClpPPxUg.js} +1 -1
  59. package/dist/assets/{cynefinDiagram-3GCD6N5R-dYhbIkRt.js → cynefinDiagram-3GCD6N5R-DZ5l7nkL.js} +1 -1
  60. package/dist/assets/{dagre-W4DXFKR2-DqJNpw5w.js → dagre-W4DXFKR2-BagTvT62.js} +1 -1
  61. package/dist/assets/{diagram-2UJZ2QOL-DKNDqAnE.js → diagram-2UJZ2QOL-DuByootb.js} +1 -1
  62. package/dist/assets/{diagram-OVF4WLC6-DENMVM-d.js → diagram-OVF4WLC6-BQ8Cvr0D.js} +1 -1
  63. package/dist/assets/{diagram-PFPMY2P6-CrRFeR5V.js → diagram-PFPMY2P6-D_pklaf9.js} +1 -1
  64. package/dist/assets/{diagram-UMYRVEAY-B5w-desO.js → diagram-UMYRVEAY-1BuHq7tR.js} +1 -1
  65. package/dist/assets/{diagram-YEKJPTXX-C7AVX3MB.js → diagram-YEKJPTXX-CK0cPx8n.js} +1 -1
  66. package/dist/assets/{diagram-ZIFT7M5P-BgkTRwwr.js → diagram-ZIFT7M5P-DVzPho45.js} +1 -1
  67. package/dist/assets/{ebnfDiagram-VR2GEFS7-yY_2KNsK.js → ebnfDiagram-VR2GEFS7-D8UO_5sE.js} +1 -1
  68. package/dist/assets/{elk-IJKZMXRS-xWtfkoqT.js → elk-IJKZMXRS-BRigfR5V.js} +1 -1
  69. package/dist/assets/{erDiagram-O2IAPWRE-BMM4saPI.js → erDiagram-O2IAPWRE-CXHPobWj.js} +1 -1
  70. package/dist/assets/{file-up-Bl7ViNTL.js → file-up-CQezfdJk.js} +1 -1
  71. package/dist/assets/{flowDiagram-OXPTDLAJ-BCRe8i6T.js → flowDiagram-OXPTDLAJ-CqKD6jh8.js} +1 -1
  72. package/dist/assets/{ganttDiagram-R7TSEDQI-COBrcDi7.js → ganttDiagram-R7TSEDQI-C9FV3gsA.js} +1 -1
  73. package/dist/assets/{gitGraphDiagram-XJZIOB7I-Dc4RKydD.js → gitGraphDiagram-XJZIOB7I-CRu4dnr_.js} +1 -1
  74. package/dist/assets/{import-name-CKE76uoY.js → import-name-dEG0japD.js} +1 -1
  75. package/dist/assets/{index-jlMtdqfJ.js → index-B4HW_T-k.js} +1 -1
  76. package/dist/assets/{index-BBsdMDZV.js → index-COnd2OMZ.js} +2 -2
  77. package/dist/assets/{infoDiagram-5W2HQ5XZ-BV8RRI_4.js → infoDiagram-5W2HQ5XZ-CCRjb2CQ.js} +1 -1
  78. package/dist/assets/{ishikawaDiagram-K3B6WC7H-H-XILdGm.js → ishikawaDiagram-K3B6WC7H-TaNPsGZS.js} +1 -1
  79. package/dist/assets/{journeyDiagram-COXZFDF6-ChLduKEj.js → journeyDiagram-COXZFDF6-Dz7YIIc2.js} +1 -1
  80. package/dist/assets/{kanban-definition-P3RFRI5V-FSZ9F3JH.js → kanban-definition-P3RFRI5V-Cg69Fpp8.js} +1 -1
  81. package/dist/assets/{mcp-servers-DGQioE-C.js → mcp-servers-Ih6dI7Ga.js} +1 -1
  82. package/dist/assets/{mermaid.core-BRsJ02Pz.js → mermaid.core-DiG3LoLz.js} +4 -4
  83. package/dist/assets/{mindmap-definition-LZFPQGKD-TWHzZjNT.js → mindmap-definition-LZFPQGKD-nxP4f0fq.js} +1 -1
  84. package/dist/assets/{minimize-BYscOtPM.js → minimize-B_k_fmmo.js} +1 -1
  85. package/dist/assets/{monitor-DFEzCfQk.js → monitor-BfmnPU-I.js} +1 -1
  86. package/dist/assets/{new-bot-7IqfI7S4.js → new-bot-CQm0FPc5.js} +2 -2
  87. package/dist/assets/{org-library-BW4CqVd6.js → org-library-C2li0IRL.js} +1 -1
  88. package/dist/assets/{package-format-BOH5_nvi.js → package-format-B3whu9DW.js} +1 -1
  89. package/dist/assets/{pegDiagram-BGZESJAR-LQWOF7IE.js → pegDiagram-BGZESJAR-gPjpGcNH.js} +1 -1
  90. package/dist/assets/{pieDiagram-CAPJLFHJ-BRXp4qFw.js → pieDiagram-CAPJLFHJ-Cgh25Z4_.js} +1 -1
  91. package/dist/assets/{quadrantDiagram-GDMTTRAM-DyIdGBZo.js → quadrantDiagram-GDMTTRAM-DD9luyqA.js} +1 -1
  92. package/dist/assets/{rail-Du7tlPwj.js → rail-B1mj4zlo.js} +1 -1
  93. package/dist/assets/{railroadDiagram-SM67HX2B-BrL1MhW1.js → railroadDiagram-SM67HX2B-CS_TYko7.js} +1 -1
  94. package/dist/assets/{remote-desktop-panel-B9rqQRMc.js → remote-desktop-panel-DIllbP7i.js} +1 -1
  95. package/dist/assets/{requirementDiagram-X7JNWC4A-DTYjaC8j.js → requirementDiagram-X7JNWC4A-BePHia6E.js} +1 -1
  96. package/dist/assets/{sankeyDiagram-UM26HJRW-BR9dASO5.js → sankeyDiagram-UM26HJRW-24ExCXGS.js} +1 -1
  97. package/dist/assets/{sequenceDiagram-ZO4K6R2Y-BR1k8h2_.js → sequenceDiagram-ZO4K6R2Y-Dtmx27I5.js} +1 -1
  98. package/dist/assets/{sizeCapture-INFHLROL-u8zOvZVi.js → sizeCapture-INFHLROL-2LvmoT1T.js} +1 -1
  99. package/dist/assets/{stateDiagram-v2-TBUQTH76-mQ64BAFv.js → stateDiagram-v2-TBUQTH76-moL2SIo9.js} +1 -1
  100. package/dist/assets/{styles-BlayaJti.js → styles-6RbfQIY7.js} +3 -3
  101. package/dist/assets/{swimlanes-N4OXWK64-CmzC3Mu0.js → swimlanes-N4OXWK64-D95Pk8qh.js} +1 -1
  102. package/dist/assets/swimlanesDiagram-K3J5GTZL-DByi9G3i.js +8 -0
  103. package/dist/assets/{team-share-C3w1L3WL.js → team-share-0GXKeixY.js} +1 -1
  104. package/dist/assets/{timeline-definition-YOQAKGHF-9aPCRsK2.js → timeline-definition-YOQAKGHF-HM-J25k2.js} +1 -1
  105. package/dist/assets/{usecaseDiagram-VIAY4XPW--ngAouwr.js → usecaseDiagram-VIAY4XPW-C6q6bCzJ.js} +1 -1
  106. package/dist/assets/{vennDiagram-BLWOH2XV-C3zKxuAB.js → vennDiagram-BLWOH2XV-hf0dh2yT.js} +1 -1
  107. package/dist/assets/{vi-uLErku_e.js → vi-CVDyZGky.js} +3 -3
  108. package/dist/assets/{wardleyDiagram-YMQ3BMBF-CZWsQPSF.js → wardleyDiagram-YMQ3BMBF-CpT_eRn9.js} +1 -1
  109. package/dist/assets/{xychartDiagram-TAQBALBS-BTcsDP6v.js → xychartDiagram-TAQBALBS-D6g1V9DG.js} +1 -1
  110. package/dist/index.html +2 -2
  111. package/dist/rail.html +4 -4
  112. package/dist-server/index.js +2456 -2424
  113. package/dist-server/package.json +1 -1
  114. package/dist-server/server/boat-create-idempotency.js +1 -1
  115. package/dist-server/server/boat-delete-journal.js +1 -1
  116. package/dist-server/server/boat.js +10 -3
  117. package/dist-server/server/bot-api-host.js +9 -5
  118. package/dist-server/server/index.js +2 -1
  119. package/dist-server/server/limix-instabox.js +382 -0
  120. package/dist-server/server/limix-owner-lane.js +51 -0
  121. package/dist-server/shared/first-reply-rescue.js +3 -3
  122. package/package.json +1 -1
  123. package/dist/assets/CloudAddDialog-UEPtzvka.js +0 -1
  124. package/dist/assets/ComputerPanel-DLV2INTM.js +0 -2
  125. package/dist/assets/LocalVmWorkspace-CBe48xft.js +0 -1
  126. package/dist/assets/MacLocalControl-CpVqwJts.js +0 -1
  127. package/dist/assets/PhoneAppDialog-B9oozUp0.js +0 -1
  128. package/dist/assets/SettingsModal-t10M3Ahi.js +0 -11
  129. package/dist/assets/TeamMapPage-BSvk8tOC.js +0 -1
  130. package/dist/assets/TriggersPage-BdePfInC.js +0 -1
  131. package/dist/assets/channel-D6e78p3W.js +0 -1
  132. package/dist/assets/index-BXLNny-w.js +0 -1
  133. package/dist/assets/swimlanesDiagram-K3J5GTZL-Coei7rJr.js +0 -8
@@ -1,2 +1,2 @@
1
- import{c as tt,r as x,j as e,t as n,a as C,i as Le,bi as Un,ad as ln,g as dn,L as cn,X as Me,S as Yn,z as Zn}from"./styles-BlayaJti.js";import{b as Vn}from"./remote-desktop-DDRRx8uY.js";import{al as Jn,b2 as Kn,B as Ve,c as Qn,L as ze,z as Te}from"./PlacesRail-v1XIqiBG.js";import{ji as Je,cj as Xn,D as U,aP as es,jj as ts,jk as un,bh as ns,cU as ss,jl as as,jm as xn,u as nt,jn as rs,a9 as jt,jo as is,fk as X,af as os,jp as kt,jq as ee,jr as ht,gu as ls,js as qe,jt as pn,cR as mn,cO as Ye,ju as ut,jv as Xt,jw as en,jx as Re,y as Ze,jy as tn,jz as ds,jA as gt,cM as hn,ac as st,jB as Ke,jC as cs,m as us,jD as xs,br as gn,jE as ps,jF as ms,n as Ne,jG as hs,jH as gs,jI as Nt,jJ as nn,jK as bs,a7 as vs,ad as xt,x as fs,cJ as sn,cK as ys,dE as js,T as ks,jL as Ns,jM as Ue,cy as ws,bq as Ss,fT as Cs}from"./App-8heymKKb.js";import{u as Is}from"./ProIntroduction-qFeFSzyk.js";import{C as Ds}from"./MenuMotion-IQitGKH4.js";const Ts=[["path",{d:"M5 22h14",key:"ehvnwv"}],["path",{d:"M5 2h14",key:"pdyrp9"}],["path",{d:"M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22",key:"1d314k"}],["path",{d:"M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2",key:"1vvvr6"}]],Rs=tt("hourglass",Ts);const Ms=[["path",{d:"m2 9 3-3 3 3",key:"1ltn5i"}],["path",{d:"M13 18H7a2 2 0 0 1-2-2V6",key:"1r6tfw"}],["path",{d:"m22 15-3 3-3-3",key:"4rnwn2"}],["path",{d:"M11 6h6a2 2 0 0 1 2 2v10",key:"2f72bc"}]],zs=tt("repeat-2",Ms);const Ls=[["path",{d:"M2 21a8 8 0 0 1 13.292-6",key:"bjp14o"}],["circle",{cx:"10",cy:"8",r:"5",key:"o932ke"}],["path",{d:"M19 16v6",key:"tddt3s"}],["path",{d:"M22 19h-6",key:"vcuq98"}]],bt=tt("user-round-plus",Ls);const As=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],vt=tt("video",As);function Qe(t,s){if(!t.config?.team)return;const r=t.bots.find(i=>i.id===s);if(r?.defaultBot?.person)return null;const l=r&&t.activeView==="chat"&&t.selectedId===r.id?r.tasks?.find(i=>i.threadId===r.threadId):void 0;return l&&l.private!==!0&&!l.routineRunId?r.mainThreadId??null:Je}function Os(t,s,r){const l=i=>typeof i=="string"&&!!t.tasks?.some(u=>u.threadId===i&&u.private===!0);return!!t.defaultBot?.person||s===Je||l(s)||l(r)}function bn({team:t,bot:s,value:r,madeIn:l}){if(!t||!s)return null;const i=Os(s,r,l),u=i?Jn:es;return e.jsxs("p",{role:"note","data-routine-audience":i?"me":"shared",className:"mt-2 flex items-center gap-1 text-[12px] leading-4 text-ink-secondary",children:[e.jsx(u,{size:12,"aria-hidden":"true",className:"shrink-0"}),e.jsx("span",{children:i?n("team.privateHeader"):ts(t.name,s.onlyPeopleAdded)})]})}function vn({bot:t,value:s,allowCurrent:r=!1,team:l,onChange:i}){const u=x.useId(),m=Xn();if(l??m!==null)return e.jsx(Es,{id:u,bot:t,value:s,allowCurrent:r,onChange:i});const c=(t?.tasks??[]).filter(o=>!o.routineRunId),h=typeof s=="string"&&!c.some(o=>o.threadId===s),N=[...t?.projects??[],{id:"",name:n("folder.none")}];return e.jsxs("div",{className:"min-w-0 space-y-1.5",children:[e.jsx("label",{htmlFor:u,className:"block text-[12px] font-medium text-ink",children:n("routines.results.label")}),e.jsxs(U,{className:"w-full",id:u,"aria-describedby":`${u}-help`,disabled:!t,value:s??(s===null?"new":"current"),onChange:o=>i(o.target.value==="new"?null:o.target.value==="current"?void 0:o.target.value),children:[r&&e.jsx("option",{value:"current",children:n("routines.results.keep")}),e.jsx("option",{value:"new",children:n("routines.results.main")}),h&&e.jsx("option",{value:s,disabled:!0,children:n("routines.results.unavailable")}),N.map(o=>{const $=c.filter(S=>o.id?S.projectId===o.id:!t?.projects?.some(v=>v.id===S.projectId));return $.length?e.jsx("optgroup",{label:o.name,children:$.map(S=>e.jsx("option",{value:S.threadId,children:S.title},S.threadId))},o.id):null})]}),e.jsx("p",{id:`${u}-help`,className:"text-[11px] leading-relaxed text-ink-secondary",children:n("routines.results.mainHelp")})]})}function Es({id:t,bot:s,value:r,allowCurrent:l,onChange:i}){const u=typeof r=="string"&&!!s?.tasks?.some(c=>c.threadId===r&&c.private===!0),m=r===void 0&&l?"current":r===Je||u?"me":"shared";return e.jsxs("div",{className:"min-w-0 space-y-1.5",children:[e.jsx("label",{htmlFor:t,className:"block text-[12px] font-medium text-ink",children:n("routines.results.label")}),e.jsxs(U,{className:"w-full",id:t,"aria-describedby":`${t}-help`,disabled:!s,value:m,onChange:c=>i(c.target.value==="current"?void 0:c.target.value==="me"?u?r:Je:s?.mainThreadId??null),children:[m==="current"&&e.jsx("option",{value:"current",children:n("routines.results.keep")}),e.jsx("option",{value:"me",children:n("routines.results.justMe")}),e.jsx("option",{value:"shared",children:n("task.sharedChat")})]}),e.jsx("p",{id:`${t}-help`,className:"text-[11px] leading-relaxed text-ink-secondary",children:n("routines.results.teamHelp")})]})}const pt="min-w-0 rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent [color-scheme:dark]",Ps=t=>Array.from({length:12},(s,r)=>new Intl.DateTimeFormat(t,{month:"long",timeZone:"UTC"}).format(new Date(Date.UTC(2024,r,1)))),Hs=["UTC",...typeof Intl.supportedValuesOf=="function"?Intl.supportedValuesOf("timeZone"):[]];function fn({runs:t,timeZone:s,paused:r=!1}){if(!t.length)return null;const l=new Intl.DateTimeFormat(Le(),{timeZone:s,weekday:"short",year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"});return e.jsxs("div",{className:"space-y-1 text-[11px] leading-relaxed text-ink-secondary","aria-label":n(r?"routines.cron.pausedPreviewLabel":"routines.cron.nextRunsLabel"),children:[e.jsxs("div",{className:"font-medium",children:[n(r?"routines.cron.pausedPreview":"routines.cron.nextRuns")," · ",s]}),t.map(i=>e.jsx("div",{children:e.jsx("time",{dateTime:new Date(i).toISOString(),children:l.format(i)})},i)),e.jsx("div",{className:"pt-1",children:n("routines.cron.clockChanges")})]})}function $s({schedule:t,paused:s=!1}){const r=x.useMemo(()=>{try{return un(t,Date.now(),3)}catch{return[]}},[t]);return e.jsx(fn,{runs:r,timeZone:t.timeZone,paused:s})}function _s({choice:t,value:s,onChange:r,runs:l,error:i}){const u=m=>r({...s,...m});return e.jsxs("div",{className:"space-y-3",children:[t==="cron"?e.jsxs("label",{className:"block space-y-1.5 text-[12px] text-ink-secondary",children:[e.jsx("span",{children:n("routines.cron.expression")}),e.jsx("input",{value:s.expression,onChange:m=>u({expression:m.target.value}),placeholder:"0 9 1 * *",spellCheck:!1,autoComplete:"off","aria-invalid":!!i,"aria-describedby":"routine-cron-help routine-cron-error",className:C(pt,"w-full font-mono")}),e.jsx("span",{id:"routine-cron-help",className:"block text-[11px]",children:n("routines.cron.expressionHelp")})]}):e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[t==="yearly"&&e.jsxs("label",{className:"space-y-1.5 text-[12px] text-ink-secondary",children:[e.jsx("span",{className:"block",children:n("routines.cron.month")}),e.jsx(U,{value:s.month,onChange:m=>u({month:m.target.value}),children:Ps(Le()).map((m,c)=>e.jsx("option",{value:String(c+1),children:m},m))})]}),e.jsxs("label",{className:"space-y-1.5 text-[12px] text-ink-secondary",children:[e.jsx("span",{className:"block",children:n("routines.cron.dayOfMonth")}),e.jsxs(U,{value:s.day,onChange:m=>u({day:m.target.value}),children:[Array.from({length:31},(m,c)=>e.jsx("option",{value:String(c+1),children:c+1},c+1)),e.jsx("option",{value:"L",children:n("routines.cron.lastDay")})]})]}),e.jsxs("label",{className:"space-y-1.5 text-[12px] text-ink-secondary",children:[e.jsx("span",{className:"block",children:n("routines.cron.time")}),e.jsx("input",{type:"time",step:60,value:s.time,onChange:m=>u({time:m.target.value}),className:pt})]})]}),t!=="cron"&&Number(s.day)>28&&e.jsx("p",{className:"text-[11px] text-ink-secondary",children:n("routines.cron.skippedMonths")}),e.jsxs("label",{className:"block space-y-1.5 text-[12px] text-ink-secondary",children:[e.jsx("span",{children:n("routines.cron.timeZone")}),e.jsx("input",{list:"routine-time-zones",value:s.timeZone,onChange:m=>u({timeZone:m.target.value}),placeholder:"America/New_York",spellCheck:!1,autoComplete:"off","aria-invalid":!!i,"aria-describedby":"routine-cron-error",className:C(pt,"block w-full")})]}),e.jsx("datalist",{id:"routine-time-zones",children:Hs.map(m=>e.jsx("option",{value:m},m))}),i&&e.jsx("p",{id:"routine-cron-error",role:"alert",className:"text-[12px] text-danger",children:i}),!i&&e.jsx(fn,{runs:l,timeZone:s.timeZone.trim()})]})}const ge=t=>["monthly","yearly","cron"].includes(t);function yn(t){const s=t.trim().split(/\s+/);if(s.length!==5)return null;const[r,l,i,u,m]=s;return!/^\d+$/.test(r)||Number(r)>59||!/^\d+$/.test(l)||Number(l)>23||!(i==="L"||/^\d+$/.test(i)&&Number(i)>=1&&Number(i)<=31)||!(u==="*"||/^\d+$/.test(u)&&Number(u)>=1&&Number(u)<=12)||m!=="*"?null:{day:i==="L"?i:String(Number(i)),month:u,time:`${String(Number(l)).padStart(2,"0")}:${String(Number(r)).padStart(2,"0")}`}}function Fs(t){const s=yn(t.expression);return s?s.month==="*"?"monthly":"yearly":"cron"}function Bs(t,s){const r=t?.timeZone??Intl.DateTimeFormat().resolvedOptions().timeZone,l=t&&yn(t.expression);let i;try{i=new Intl.DateTimeFormat("en-US",{timeZone:r,month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(s)}catch{i=new Intl.DateTimeFormat("en-US",{timeZone:"UTC",month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(s)}const u=h=>i.find(N=>N.type===h).value,m=l?.time??`${u("hour")}:${u("minute")}`,c=l?.day??u("day");return{expression:t?.expression??`${Number(m.slice(3))} ${Number(m.slice(0,2))} ${c} * *`,timeZone:r,day:c,month:l&&l.month!=="*"?String(Number(l.month)):u("month"),time:m}}function Ws(t,s,r,l){try{if(t!=="cron"&&!/^\d{2}:\d{2}$/.test(s.time))throw new Error(n("routines.cron.chooseTime"));const[i,u]=s.time.split(":"),m=l??{type:"cron",timeZone:s.timeZone,expression:t==="cron"?s.expression:`${Number(u)} ${Number(i)} ${s.day} ${t==="yearly"?s.month:"*"} *`},c=ns(m,r);return{schedule:l??c,runs:un(c,r,3),error:""}}catch(i){return{schedule:null,runs:[],error:i instanceof Error?i.message:String(i)}}}function Gs({value:t,botEngine:s,onChange:r}){const l=ss(),i=t.engine||s||l[0]?.engine||"",u=[...new Set([...s?[s]:[],...l.map(c=>c.engine),...i?[i]:[]])],m=l.find(c=>c.engine===i)?.resetsAt??null;return e.jsxs("div",{className:"space-y-2 text-[13px] text-ink","data-testid":"limit-reset-fields",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:n("routines.limitReset.engine")}),e.jsx(U,{"aria-label":n("routines.limitReset.engine"),value:i,onChange:c=>r({...t,engine:c.target.value}),children:u.map(c=>e.jsx("option",{value:c,children:as(c)},c))}),e.jsxs(U,{"aria-label":n("routines.limitReset.repeat"),value:t.repeat,onChange:c=>r({...t,engine:i,repeat:c.target.value}),children:[e.jsx("option",{value:"once",children:n("routines.limitReset.once")}),e.jsx("option",{value:"every_reset",children:n("routines.limitReset.every")})]})]}),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:m!==null&&m>Date.now()?n("routines.limitReset.next",{time:xn(m)}):n("routines.limitReset.unknown")})]})}function qs({cloudHome:t,local:s,plan:r,ready:l,offersAllowed:i}){return t?{kind:"cloud"}:s?{kind:"local",next:null}:{kind:"server"}}function Us(){const{state:t,dispatch:s}=nt(),r=Is(),l=rs()&&window.ogb?.remoteClient?.active!==!0,i=qs({cloudHome:t.config?.cloudHome===!0,local:l,plan:null,ready:r?.account?.machine?.status==="ready",offersAllowed:Un().source!=="file"}),u="text-left underline underline-offset-2 hover:text-ink",m=()=>{window.confirm(n("routines.scheduleNote.leave"))&&window.ogb?.cloudAccount?.connectHome().catch(()=>{})};return e.jsx("p",{"data-routine-schedule-note":i.kind==="local"?i.next??"local":i.kind,className:"text-[11px] leading-relaxed text-ink-secondary",children:i.kind==="cloud"?n("routines.scheduleNote.cloud"):i.kind==="server"?n("routines.scheduleNote.server"):e.jsxs(e.Fragment,{children:[n("routines.scheduleNote.local"),i.next==="add-cloud"&&e.jsxs(e.Fragment,{children:[" ",e.jsx("button",{type:"button",className:u,onClick:()=>s({type:"openCloudAdd",source:"app_routines"}),children:n("routines.scheduleNote.addCloud")})]}),i.next==="open-cloud"&&e.jsxs(e.Fragment,{children:[" ",n("routines.scheduleNote.openCloud")," ",e.jsx("button",{type:"button",className:u,onClick:m,children:n("cloudHome.connect")})]})]})})}const Xe="application/x-openmaus-bot",we="application/x-openmaus-calendar-event",Ys=t=>t.dataTransfer.types.includes(Xe)||t.dataTransfer.types.includes(we);function Zs(t){const s=t.dataTransfer.getData(Xe);if(s)return{botId:s};try{const r=JSON.parse(t.dataTransfer.getData(we));return(r.kind==="routine"||r.kind==="call")&&typeof r.id=="string"&&typeof r.at=="number"?{event:{kind:r.kind,id:r.id,at:r.at}}:null}catch{return null}}function Vs({marker:t,hourHeight:s,onDrop:r}){const[l,i]=x.useState(!1),u=new Date(t.at),m=n("limits.marker",{engine:t.name,time:xn(t.at,t.at)});return e.jsxs("div",{"data-limit-marker":t.engine,role:"note","aria-label":m,title:n("limits.markerDrop",{engine:t.name}),className:"absolute inset-x-0 z-[25] -translate-y-1/2 py-1.5",style:{top:(u.getHours()*60+u.getMinutes())/60*s},onPointerDown:c=>c.stopPropagation(),onDragOver:c=>{!r||!Ys(c)||(c.preventDefault(),c.stopPropagation(),c.dataTransfer.dropEffect="copy",i(!0))},onDragLeave:()=>i(!1),onDrop:c=>{c.preventDefault(),c.stopPropagation(),i(!1);const h=Zs(c);h&&r?.(h)},children:[e.jsx("div",{className:C("h-0 border-t-2 border-dashed",l?"border-accent":"border-warning/80")}),e.jsxs("span",{className:C("absolute left-1 top-0 flex max-w-[calc(100%-8px)] items-center gap-1 truncate rounded-full border px-1.5 py-0.5 text-[10px] font-medium shadow-sm",l?"border-accent bg-accent text-accent-ink":"border-warning/50 bg-panel text-ink"),children:[e.jsx(Rs,{size:10,className:"shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"truncate",children:m})]})]})}const G=64;function jn(t){return t==="running"?"working":t==="waiting"?"curious":t==="completed"?"proud":t==="failed"||t==="missed"?"sad":t==="cancelled"?"sleeping":"drowsy"}function Js(t){return t>=44?"roomy":t>=22?"compact":"tiny"}function Ks({item:t,bots:s,groups:r,compact:l,layout:i,selected:u=!1,onOpen:m,onResize:c}){const h=t.kind==="call",N=t.kind==="routine"?t.routine:null,o=t.kind==="routine"?t.run:null,S=!h&&(o?.target??N?.target)==="room-goal"?o?.groupId??N?.groupId:void 0,v=S?r.find(F=>F.id===S)??{name:n("routines.group")}:void 0,L=(h?t.call.botIds:[o?.botId??N?.botId??""]).flatMap(F=>s.find(y=>y.id===F)??[]),O=L[0],_=h?t.call.name:o?.routineName??N?.name??n("routines.event.automation"),B=h?"var(--color-accent)":O?Kn[O.color]:"var(--color-ink-tertiary)",E=!!(N&&!o&&!N.enabled),[M,d]=x.useState(t.durationMinutes);x.useEffect(()=>d(t.durationMinutes),[t.durationMinutes]);const b=o?.status,T=b==="failed"||b==="missed"||b==="waiting"||t.kind==="routine"&&!o&&t.needsYou===!0,P=o?jt(o):void 0,g=h||!!(N&&!o&&!E&&N.schedule.type!=="cron"),j=h?t.call.schedule:N?.schedule,I=!!(j&&j.type!=="once"),D=j?.type==="interval"?is(j.everyMinutes):null,z=Math.max(16,M/60*G),p=Js(z),H=h?n(L.length===1?"routines.botCountOne":"routines.botCountMany",{count:L.length}):v?v.name:O?.name,w=[_,X(t.at),H,D,E?(N&&os(N))??n("routines.pausedSchedule"):P].filter(Boolean).join(" · "),R=N?.schedule.type==="cron"?n("routines.event.cronMoveHint"):"",Z=F=>{F.preventDefault(),F.stopPropagation();const y=F.clientY,de=M;let Q=de;const be=ve=>{Q=Math.max(ee,Math.min(240,Math.round((de+(ve.clientY-y)/G*60)/ee)*ee)),d(Q)},ce=()=>{if(document.removeEventListener("pointermove",be),document.removeEventListener("pointerup",ce),Q!==t.durationMinutes){if(I&&!window.confirm(n("routines.event.resizeSeries"))){d(t.durationMinutes);return}c(Q)}};document.addEventListener("pointermove",be),document.addEventListener("pointerup",ce,{once:!0})},te=!h&&e.jsx("span",{"data-event-status":E?"paused":T?"needs-you":"working",className:C("size-1.5 shrink-0 rounded-full",E?"bg-ink-tertiary":T?"bg-warning":"bg-success")}),le=F=>h?e.jsx(vt,{size:13,className:"mt-0.5 shrink-0"}):O?e.jsx(Ve,{bot:O,state:b?jn(b):E?"sleeping":"idle",size:F,animated:b==="running"||b==="waiting"}):null;return e.jsxs("button",{"data-event-card":!0,"data-event-fit":p,type:"button",draggable:g,title:R?`${w}
2
- ${R}`:w,onDragStart:F=>{if(!g)return F.preventDefault();F.dataTransfer.effectAllowed="move",F.dataTransfer.setData(we,JSON.stringify({kind:t.kind,id:h?t.call.id:N.id,at:t.at}))},onClick:F=>{F.stopPropagation(),m()},"aria-pressed":u,"aria-label":`${_}, ${X(t.at)}${E?`, ${n("routines.pausedSchedule")}`:P?`, ${P}`:""}`,className:C("group absolute z-10 overflow-hidden rounded-md border border-l-[3px] text-left transition hover:z-20 focus:z-20 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent",p==="roomy"?"px-1.5 py-1":"px-1.5 py-0",E&&"border-dashed opacity-70",b==="cancelled"&&"opacity-55",(b==="failed"||b==="missed")&&(o&&kt(o)?"border-warning/60":"border-danger/60"),u&&"z-20 ring-2 ring-accent ring-offset-1 ring-offset-app"),style:{left:`calc(${i.column/i.columns*100}% + 2px)`,width:`calc(${100/i.columns}% - 4px)`,top:`${(new Date(t.at).getHours()*60+new Date(t.at).getMinutes())/60*G}px`,height:`${z}px`,background:`color-mix(in srgb, ${B} ${E?6:16}%, var(--color-card))`,borderColor:`color-mix(in srgb, ${B} 40%, transparent)`,borderLeftColor:B,color:`color-mix(in srgb, ${B} 55%, var(--color-ink))`},children:[p==="roomy"?e.jsxs("div",{className:"flex min-w-0 items-start gap-1.5",children:[le(l?18:22),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[11px] font-semibold leading-tight",children:_}),e.jsxs("div",{className:"mt-0.5 flex min-w-0 items-center gap-1 text-[10px] opacity-80",children:[te,e.jsxs("span",{className:"truncate",children:[X(t.at)," · ",D&&!v&&!h?`${H??""} · ${D}`:H]})]})]}),L.length>1&&e.jsxs("span",{className:"rounded bg-inset/60 px-1 py-0.5 text-[8px]",children:["+",L.length-1]})]}):p==="compact"?e.jsxs("div",{className:"flex h-full min-w-0 items-center gap-1",children:[h&&e.jsx(vt,{size:11,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-semibold leading-none",children:_}),te,e.jsx("span",{className:"shrink-0 text-[10px] leading-none tabular-nums opacity-80",children:X(t.at)})]}):e.jsx("div",{className:"flex h-full min-w-0 items-center truncate text-[10px] font-semibold leading-none",children:_}),h&&e.jsx("div",{onPointerDown:Z,className:"absolute inset-x-1 bottom-0 h-1.5 cursor-ns-resize rounded-full opacity-0 transition group-hover:opacity-100","aria-label":n("routines.event.resize"),children:e.jsx("div",{className:"mx-auto mt-0.5 h-0.5 w-5 rounded-full bg-current opacity-50"})})]})}const ft=[0,1,2,3,4,5,6],et=[1,2,3,4,5],mt=[5,10,15,30,60],an=Array.from({length:240/ee},(t,s)=>(s+1)*ee);function kn(t,s){return t?t.memberIds.flatMap(r=>{const l=s.find(i=>i.id===r);return l&&!l.hidden?[l]:[]}):s.filter(r=>!r.hidden)}function Qs(t){return t.dm?!1:!(Object.prototype.hasOwnProperty.call(t,"setupCompletedAt")||Object.prototype.hasOwnProperty.call(t,"setupSkippedAt"))||t.setupCompletedAt!=null||t.setupSkippedAt!=null||(t.messages?.length??0)>0}function rn(t,s,r){const l=kn(t,s),i=t?.defaultResponder.kind==="member"?t.defaultResponder.botId:void 0;return l.find(u=>u.id===r)??l.find(u=>u.id===i)??l.find(u=>u.chiefOfStaff)??l[0]}function on(){const t=new Date(Date.now()+36e5);return t.setMinutes(0,0,0),t.getTime()}function Xs(t,s){return!!(t&&t.length===s.length&&t.every((r,l)=>r===s[l]))}function ea(t){return t.type!=="interval"||!t.weekdays||t.weekdays.length===7?"every-day":Xs(t.weekdays,et)?"weekdays":"custom"}function ta(t){const s=new Date(`${t}T00:00`);return s.setHours(23,59,59,999),s.getTime()}function na(t,s){return t.type==="once"?"none":t.type==="limit_reset"?"limit_reset":t.type==="interval"?"interval":t.type==="cron"?Fs(t):t.weekdays.length===7?"daily":t.weekdays.join(",")==="1,2,3,4,5"?"weekdays":t.weekdays.length===1&&t.weekdays[0]===new Date(s).getDay()?"weekly":"custom"}function Nn(t,s,r){if(t==="none")return{type:"once",at:s};const l=t==="daily"?ft:t==="weekdays"?et:t==="weekly"?[new Date(s).getDay()]:r;return{type:"daily",time:pn(s),weekdays:[...l].sort()}}function sa(t,s,r,l,i){return t==="interval"?{type:"interval",everyMinutes:l,...i}:Nn(t,s,r)}function wn({attachments:t,onRemove:s}){return t.length?e.jsx("div",{className:"flex flex-wrap gap-2",children:t.map(r=>e.jsxs("div",{className:"flex max-w-[260px] items-center gap-2 rounded-lg border border-hairline/50 bg-inset px-2.5 py-2 text-[12px] text-ink",children:[e.jsx(st,{size:14,className:"shrink-0 text-accent"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:r.name}),s&&e.jsx("button",{type:"button",onClick:()=>s(r.id),className:"rounded p-0.5 text-ink-secondary hover:bg-raised hover:text-ink","aria-label":n("routines.attachment.remove",{name:r.name}),children:e.jsx(Me,{size:12})})]},r.id))}):null}function yt({bots:t,selected:s,multiple:r,locked:l,onChange:i}){const[u,m]=x.useState(""),c=t.filter(h=>`${h.name} ${h.title}`.toLowerCase().includes(u.toLowerCase()));return e.jsxs("div",{className:"rounded-xl border border-hairline/50 bg-inset/60 p-2",children:[!l&&t.length>5&&e.jsxs("label",{className:"mb-2 flex items-center gap-2 rounded-lg border border-transparent bg-panel px-2.5 py-2 text-ink-secondary focus-within:border-focus",children:[e.jsx(Yn,{size:14}),e.jsx("input",{value:u,onChange:h=>m(h.target.value),placeholder:n("routines.findBot"),className:"min-w-0 flex-1 bg-transparent text-[12px] text-ink outline-none placeholder:text-ink-tertiary"})]}),e.jsx("div",{className:"grid max-h-48 grid-cols-1 gap-1 overflow-y-auto sm:grid-cols-2",children:c.map(h=>{const N=s.includes(h.id);return e.jsxs("button",{type:"button",disabled:l,onClick:()=>i(r?N?s.filter(o=>o!==h.id):[...s,h.id]:[h.id]),className:C("flex min-w-0 items-center gap-2 rounded-lg px-2 py-2 text-left transition",N?"bg-accent/12 ring-1 ring-accent/50":"hover:bg-raised",l&&"cursor-default"),children:[e.jsx(Ve,{bot:h,state:N?"happy":"idle",size:32,animated:!1}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-medium text-ink",children:h.name}),N&&e.jsx(gn,{size:14,className:"shrink-0 text-accent"})]},h.id)})})]})}function aa(t){return t.flatMap(s=>s.kind==="paste"||s.kind==="citation"?[]:[{id:s.id,kind:s.kind,name:s.name,path:s.path,size:s.size}])}function ra({seed:t,bots:s,lockedBotId:r,defaultRunOn:l,routinesOnly:i=!1,plain:u=!1,onClose:m,onSavedCall:c}){const{state:h,dispatch:N}=nt(),o=t.routine,{request:$}=ls(),S=t.call,[v,J]=x.useState(i?"routine":t.kind),[L]=x.useState(()=>Date.now()),[O,_]=x.useState(o?.name??S?.name??t.name??""),[B,E]=x.useState(o?.prompt??S?.description??t.description??""),M=o?.schedule.type==="once"?o.schedule.at:o?.schedule.type==="daily"?ht(t.at,o.schedule.time):o?.schedule.type==="interval"?o.schedule.anchorAt:S?.schedule.type==="once"?S.schedule.at:S?.schedule.type==="daily"?ht(t.at,S.schedule.time):t.at,d=o?.schedule??S?.schedule??{type:"once",at:M},[b,T]=x.useState(qe(M)),[P,g]=x.useState(pn(M)),[j,I]=x.useState(o?.durationMinutes??S?.durationMinutes??t.durationMinutes),[D,z]=x.useState(o?.timeoutMinutes??null),[p,H]=x.useState(!!o),[w,R]=x.useState(o?.overlap??"skip"),[Z,te]=x.useState(!!o?.continuity),[le,F]=x.useState(!!o?.runOnStartup),[y,de]=x.useState(t.limitReset?"limit_reset":na(d,M)),[Q,be]=x.useState(d.type==="limit_reset"?d:{engine:t.limitReset?.engine??"",repeat:"once"}),[ce,ve]=x.useState(()=>Bs(d.type==="cron"?d:void 0,M)),[at,Ae]=x.useState(!1),[fe,Oe]=x.useState(d.type==="daily"?d.weekdays:[new Date(M).getDay()]),[q,Se]=x.useState(d.type==="interval"?d.everyMinutes:15),[ne,rt]=x.useState(()=>ea(d)),[f,K]=x.useState(()=>d.type==="interval"&&d.weekdays?.length?d.weekdays:[...ft]),[pe,se]=x.useState(d.type==="interval"&&d.window?"custom":"all-day"),[Ee,Sn]=x.useState(d.type==="interval"?d.window?.start??"09:00":"09:00"),[Pe,Cn]=x.useState(d.type==="interval"?d.window?.end??"17:00":"17:00"),[He,In]=x.useState(d.type==="interval"&&d.endsAt!=null?"on-date":"never"),[wt,Dn]=x.useState(()=>d.type==="interval"&&d.endsAt!=null?qe(d.endsAt):qe(mn(Ye(Math.max(Date.now(),M)),7))),[W,St]=x.useState(r?[r]:o?[o.botId]:S?.botIds??t.botIds),[it,Ct]=x.useState(()=>(o?o.resultsThreadId:t.resultsThreadId??Qe(h,W[0]))??null),$e=a=>{a[0]!==W[0]&&Ct(Qe(h,a[0])??null),St(a)},[V,Tn]=x.useState(o?.target??"bot"),[me,ot]=x.useState(o?.groupId??""),[ye,_e]=x.useState(o?.runOn??l??"maus"),[Ce,lt]=x.useState(o?.target==="room-goal"?[]:o?.attachments??S?.attachments??[]),[It,Dt]=x.useState(!1),[Tt,Rt]=x.useState(""),[Mt,zt]=x.useState(""),[Rn,Lt]=x.useState(0),Fe=Rn>0,At=x.useRef(null),Mn=!!(h.config?.box.configured&&W.length>0&&W.every(a=>Vn(h.instances,s.find(k=>k.id===a)?.modelSelection.instanceId)?.snapshot.state==="available")),Be=h.groups.filter(Qs),ue=Be.find(a=>a.id===me),dt=ue?kn(ue,h.bots):s,ae=v==="routine"&&V==="room-goal",Ot=h.config?.cloudHome===!0,We=ut(b,P,o||S?M:void 0),zn=We+j*6e4,Ie=W.flatMap(a=>s.find(k=>k.id===a)??[]),Et=x.useRef(null),De=y==="interval"&&(!Number.isInteger(q)||q<5||q>1440),je=y==="interval"&&ne==="custom"&&f.length===0,Pt=ut("2000-01-01",Pe)-ut("2000-01-01",Ee),re=y==="interval"&&pe==="custom"&&(!Ee||!Pe||!Number.isFinite(Pt)||Pt<q*6e4),ct=o?.schedule.type==="interval"?o.schedule:void 0,Ht=Xt(L,Math.max(5,q||5),ct),ke=He==="on-date"?ta(wt):null,he=y==="interval"&&He==="on-date"&&(ke==null||!Number.isSafeInteger(ke)||ke<Ht),$t=ne==="every-day"?void 0:ne==="weekdays"?et:f,Ln=pe==="custom"?{start:Ee,end:Pe}:void 0,xe=ge(y)?Ws(y,ce,L,!at&&d.type==="cron"?d:void 0):null,_t=a=>{a==="interval"&&!p&&(z(k=>k??30),H(!0)),ge(a)&&(a==="cron"&&xe?.schedule&&ve(k=>({...k,expression:xe.schedule.expression})),Ae(!0)),de(a)},An=a=>{a==="custom"&&ne!=="custom"&&K(ne==="weekdays"?[...et]:[...ft]),rt(a)},Ft=a=>{if(Tn(a),a==="bot"){ot("");return}_e("maus"),lt([]),zt("");const k=ue??Be[0];ot(k?.id??"");const A=rn(k,h.bots,W[0]);$e(A?[A.id]:[])},On=a=>{const k=Be.find(ie=>ie.id===a);ot(a);const A=rn(k,h.bots,W[0]);$e(A?[A.id]:[])},En=async a=>{if(!(!a?.length||ae)){Lt(k=>k+1);try{const k=await cs(Array.from(a),{allowImages:!0,getPath:xs,uploadImage:us}),A=aa(k.attachments);A.length&&(lt(ie=>[...ie,...A].slice(0,20)),ye==="cloud"&&_e("maus")),k.notice&&zt(k.notice)}finally{Lt(k=>Math.max(0,k-1))}}},Pn=async()=>{if(!Fe){Dt(!0),Rt("");try{if(v==="routine"||i){const a=Date.now(),k=ps(a,q,ct);if(y==="interval"&&ke!=null&&ke<Xt(a,q,ct))throw new Error(n("routines.interval.endAfterFirstRun"));const A=Q.engine||s.find(qn=>qn.id===(r??W[0]))?.modelSelection?.instanceId||"",ie=y==="limit_reset"?{type:"limit_reset",engine:A,repeat:Q.repeat}:ge(y)?xe?.schedule:sa(y,We,fe,q,{anchorAt:k,weekdays:$t?[...$t].sort():null,window:Ln??null,endsAt:ke});if(!ie)throw new Error(xe?.error||n("routines.error.invalidSchedule"));const Wn={name:O,prompt:B,target:V,botId:r??W[0]??"",groupId:V==="room-goal"&&me?me:null,runOn:V==="room-goal"?"maus":ye,enabled:o&&(o.enabled||!ms(o,a))?void 0:!0,schedule:ie,durationMinutes:j,timeoutMinutes:D,overlap:w,continuity:V==="bot"&&y!=="none"&&Z,runOnStartup:y!=="none"&&le,attachments:V==="room-goal"?[]:Ce,...V==="bot"?{resultsThreadId:it}:{}},Gn=await $(o?`/api/routines/${o.id}`:"/api/routines",{method:o?"PATCH":"POST",body:JSON.stringify(Wn)});N({type:"routinePatched",routine:Gn.routine})}else{if(y==="interval"||y==="limit_reset"||ge(y))throw new Error(n("routines.error.callSchedule"));const a=Nn(y,We,fe),k={name:O,description:B,botIds:W,schedule:a,durationMinutes:j,attachments:Ce},A=await Ne(S?`/api/calendar-calls/${S.id}`:"/api/calendar-calls",{method:S?"PATCH":"POST",body:JSON.stringify(k)});c(A.call)}m()}catch(a){Rt(a instanceof Error?a.message:String(a))}finally{Dt(!1)}}},Hn=!!(O.trim()&&(v==="call"||B.trim())&&(!r||W[0]===r)&&(v==="call"?W.length>0:V==="room-goal"?(!me||ue)&&W[0]&&dt.some(a=>a.id===W[0]):W.length>0)&&!De&&!je&&!re&&!he&&!xe?.error),$n=!i&&!o&&!S&&!r,Y=ln()&&!u,[Ge,_n]=x.useState(()=>!["none","daily","weekdays","weekly"].includes(y)||V==="room-goal"||Ce.length>0||ye==="cloud"||D!=null||le||w==="queue");Qn(Et,m);const Bt=$n&&e.jsxs("div",{className:C(Y&&"ml-10","inline-flex rounded-lg bg-inset p-1"),children:[e.jsx("button",{type:"button",onClick:()=>{J("routine"),St(a=>a.slice(0,1))},className:C("rounded-md px-4 py-1.5 text-[13px] font-medium",v==="routine"?"bg-raised text-ink shadow":"text-ink-secondary"),children:n("routines.kind.routine")}),e.jsx("button",{type:"button",onClick:()=>{J("call"),(y==="interval"||y==="limit_reset"||ge(y))&&de("none")},className:C("rounded-md px-4 py-1.5 text-[13px] font-medium",v==="call"?"bg-raised text-ink shadow":"text-ink-secondary"),children:n("routines.kind.call")})]}),Wt=v==="routine"&&!r&&e.jsxs("div",{className:C(Y&&"ml-10"),children:[e.jsx("div",{className:"mb-2 text-[11px] font-medium uppercase tracking-wider text-ink-secondary",children:n("routines.editor.type")}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("button",{type:"button",onClick:()=>Ft("bot"),className:C("flex items-start gap-3 rounded-xl border p-3 text-left transition",V==="bot"?"border-accent/60 bg-accent/10":"border-hairline/50 bg-inset hover:bg-raised"),children:[e.jsx(bt,{size:17,className:C("mt-0.5 shrink-0",V==="bot"?"text-accent":"text-ink-secondary")}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-[13px] font-medium text-ink",children:n("routines.editor.botTask")}),e.jsx("span",{className:"mt-1 block text-[11px] leading-relaxed text-ink-secondary",children:n("routines.editor.botTaskHelp")})]})]}),e.jsxs("button",{type:"button",onClick:()=>Ft("room-goal"),className:C("flex items-start gap-3 rounded-xl border p-3 text-left transition",V==="room-goal"?"border-accent/60 bg-accent/10":"border-hairline/50 bg-inset hover:bg-raised"),children:[e.jsx(en,{size:17,className:C("mt-0.5 shrink-0",V==="room-goal"?"text-accent":"text-ink-secondary")}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-[13px] font-medium text-ink",children:n("routines.editor.teamGoal")}),e.jsx("span",{className:"mt-1 block text-[11px] leading-relaxed text-ink-secondary",children:n("routines.editor.teamGoalHelp")})]})]})]})]}),Gt=y!=="interval"&&y!=="limit_reset"&&!ge(y)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[v==="routine"&&y==="none"&&e.jsx("span",{className:"text-[12px] font-medium text-ink-secondary",children:n("routines.editor.starts")}),v==="routine"&&y==="weekly"&&e.jsx("span",{className:"text-[12px] font-medium text-ink-secondary",children:n("routines.editor.on")}),(v==="call"||y==="none"||y==="weekly")&&e.jsx("input",{type:"date",value:b,onChange:a=>T(a.target.value),className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent [color-scheme:dark]"}),e.jsx("input",{type:"time",step:ee*60,value:P,onChange:a=>g(a.target.value),className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent [color-scheme:dark]"}),v==="call"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[12px] text-ink-secondary",children:n("routines.editor.to")}),e.jsx("span",{className:"rounded-lg border border-hairline/40 bg-inset/60 px-3 py-2 text-[13px] text-ink",children:X(zn)}),e.jsx(U,{"aria-label":n("routines.editor.callDuration"),value:j,onChange:a=>I(Number(a.target.value)),children:an.map(a=>e.jsx("option",{value:a,children:Re(a)},a))})]})]}),qt=e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(zs,{size:14,className:"text-ink-secondary"}),e.jsxs(U,{"aria-label":n("routines.editor.repeat"),value:y,onChange:a=>_t(a.target.value),children:[e.jsx("option",{value:"none",children:n("routines.repeat.none")}),v==="routine"&&e.jsx("option",{value:"interval",children:n("routines.repeat.interval")}),e.jsx("option",{value:"daily",children:n("routines.repeat.dailyOption")}),e.jsx("option",{value:"weekdays",children:n("routines.repeat.weekdaysOption")}),e.jsx("option",{value:"weekly",children:n("routines.schedule.weeklyOn",{day:Ze(new Date(We).getDay())})}),e.jsx("option",{value:"custom",children:n("routines.repeat.selectedWeekdays")}),v==="routine"&&e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"monthly",children:n("routines.repeat.monthly")}),e.jsx("option",{value:"yearly",children:n("routines.repeat.yearly")}),e.jsx("option",{value:"cron",children:n("routines.repeat.customCron")})]}),v==="routine"&&e.jsx("option",{value:"limit_reset",children:n("routines.limitReset.option")})]})]}),Ut=v==="routine"&&e.jsx(Us,{}),Yt=e.jsxs(e.Fragment,{children:[y==="limit_reset"&&v==="routine"&&e.jsx(Gs,{value:Q,botEngine:s.find(a=>a.id===(r??W[0]))?.modelSelection?.instanceId,onChange:be}),ge(y)&&v==="routine"&&xe&&e.jsx(_s,{choice:y,value:ce,onChange:a=>{ve(a),Ae(!0)},runs:xe.runs,error:xe.error}),y==="custom"&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:tn.map((a,k)=>e.jsx("button",{type:"button",onClick:()=>Oe(A=>A.includes(k)?A.length===1?A:A.filter(ie=>ie!==k):[...A,k].sort()),className:C("size-8 rounded-full text-[10px] font-semibold",fe.includes(k)?"bg-accent text-white":"bg-inset text-ink-secondary hover:bg-raised hover:text-ink"),children:Ze(k).charAt(0).toLocaleUpperCase(Le())},a))}),y==="interval"&&v==="routine"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[13px] text-ink",children:[e.jsx("span",{className:"font-medium",children:n("routines.interval.runsEvery")}),e.jsxs(U,{value:mt.includes(q)?String(q):"custom",onChange:a=>Se(a.target.value==="custom"?0:Number(a.target.value)),"aria-label":n("routines.interval.howOften"),children:[mt.map(a=>e.jsx("option",{value:a,children:a},a)),e.jsx("option",{value:"custom",children:n("routines.interval.custom")})]}),!mt.includes(q)&&e.jsx("input",{type:"number",min:5,max:1440,step:1,value:q||"",onChange:a=>Se(Number(a.target.value)),"aria-label":n("routines.interval.customMinutes"),"aria-invalid":De,"aria-describedby":De?"routine-interval-error":"routine-interval-help",autoFocus:!0,className:C("w-20 rounded-lg border bg-inset px-3 py-2 text-[13px] tabular-nums text-ink outline-none focus:border-accent",De?"border-danger/70":"border-hairline/50")}),e.jsx("span",{children:n("routines.interval.minutesUnit")})]}),e.jsxs("div",{className:"grid items-center gap-2 text-[13px] text-ink sm:flex sm:flex-wrap",children:[e.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[e.jsx("span",{className:"font-medium",children:n("routines.interval.on")}),e.jsxs(U,{value:ne,onChange:a=>An(a.target.value),"aria-label":n("routines.interval.daysLabel"),"aria-invalid":je,"aria-describedby":je?"routine-interval-days-error":void 0,children:[e.jsx("option",{value:"every-day",children:n("routines.repeat.daily")}),e.jsx("option",{value:"weekdays",children:n("routines.repeat.weekdays")}),e.jsx("option",{value:"custom",children:n("routines.interval.custom")})]})]}),e.jsx("span",{"aria-hidden":"true",className:"hidden text-ink-secondary sm:inline",children:"·"}),e.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[e.jsx("span",{className:"font-medium",children:n("routines.interval.during")}),e.jsxs(U,{value:pe,onChange:a=>se(a.target.value),"aria-label":n("routines.interval.hoursLabel"),"aria-invalid":re,"aria-describedby":re?"routine-interval-window-error":void 0,children:[e.jsx("option",{value:"all-day",children:n("routines.interval.allDay")}),e.jsx("option",{value:"custom",children:n("routines.interval.customHours")})]})]}),e.jsx("span",{"aria-hidden":"true",className:"hidden text-ink-secondary sm:inline",children:"·"}),e.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[e.jsx("span",{className:"font-medium",children:n("routines.interval.ends")}),e.jsxs(U,{value:He,onChange:a=>In(a.target.value),"aria-label":n("routines.interval.endsLabel"),"aria-invalid":he,"aria-describedby":he?"routine-interval-end-error":void 0,children:[e.jsx("option",{value:"never",children:n("routines.interval.never")}),e.jsx("option",{value:"on-date",children:n("routines.interval.onDate")})]})]})]}),ne==="custom"&&e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[11px] font-medium text-ink-secondary",children:n("routines.interval.chooseDays")}),e.jsx("div",{role:"group","aria-label":n("routines.interval.customDays"),"aria-invalid":je,"aria-describedby":je?"routine-interval-days-error":void 0,className:"flex flex-wrap gap-1.5",children:tn.map((a,k)=>e.jsx("button",{type:"button",onClick:()=>K(A=>A.includes(k)?A.filter(ie=>ie!==k):[...A,k].sort()),"aria-label":n(f.includes(k)?"routines.interval.daySelected":"routines.interval.dayNotSelected",{day:Ze(k)}),"aria-pressed":f.includes(k),className:C("size-8 rounded-full text-[10px] font-semibold",f.includes(k)?"bg-accent text-white":"bg-inset text-ink-secondary hover:bg-raised hover:text-ink"),children:n("routines.interval.dayChips").split(" ")[k]},a))})]}),pe==="custom"&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[12px] text-ink",children:[e.jsx("span",{className:"font-medium text-ink-secondary",children:n("routines.interval.runBetween")}),e.jsx("input",{"aria-label":n("routines.interval.windowStart"),"aria-invalid":re,"aria-describedby":re?"routine-interval-window-error":void 0,type:"time",step:ee*60,value:Ee,onChange:a=>Sn(a.target.value),className:C("rounded-lg border bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent [color-scheme:dark]",re?"border-danger/70":"border-hairline/50")}),e.jsx("span",{className:"text-ink-secondary",children:n("routines.interval.and")}),e.jsx("input",{"aria-label":n("routines.interval.windowEnd"),"aria-invalid":re,"aria-describedby":re?"routine-interval-window-error":void 0,type:"time",step:ee*60,value:Pe,onChange:a=>Cn(a.target.value),className:C("rounded-lg border bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent [color-scheme:dark]",re?"border-danger/70":"border-hairline/50")})]}),He==="on-date"&&e.jsxs("label",{className:"flex flex-wrap items-center gap-2 text-[12px] text-ink",children:[e.jsx("span",{className:"font-medium text-ink-secondary",children:n("routines.interval.stopAfter")}),e.jsx("input",{"aria-label":n("routines.interval.endDate"),"aria-invalid":he,"aria-describedby":he?"routine-interval-end-error":void 0,type:"date",min:qe(Ht),value:wt,onChange:a=>Dn(a.target.value),className:C("rounded-lg border bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent [color-scheme:dark]",he?"border-danger/70":"border-hairline/50")})]}),De&&e.jsx("div",{id:"routine-interval-error",className:"text-[11px] text-danger",children:n("routines.interval.invalidMinutes")}),je&&e.jsx("div",{id:"routine-interval-days-error",className:"text-[11px] text-danger",children:n("routines.interval.invalidDays")}),re&&e.jsx("div",{id:"routine-interval-window-error",className:"text-[11px] text-danger",children:n("routines.interval.invalidWindow",{minutes:q||5})}),he&&e.jsx("div",{id:"routine-interval-end-error",className:"text-[11px] text-danger",children:n("routines.interval.endAfterFirstRun")}),e.jsx("div",{id:"routine-interval-help",className:"text-[11px] leading-relaxed text-ink-secondary",children:n(w==="queue"?"routines.overlapQueueHelp":"routines.overlapSkipHelp")})]})]}),Zt=v==="routine"&&e.jsxs("details",{className:"rounded-xl border border-hairline/40 bg-inset/40 px-3 py-2.5",children:[e.jsx("summary",{className:"cursor-pointer select-none text-[12px] font-medium text-ink-secondary hover:text-ink",children:D==null?n("routines.runLimit.none"):n("routines.runLimit.some",{duration:Re(D)})}),e.jsxs("div",{className:"mt-3 border-t border-hairline/35 pt-3",children:[e.jsxs("label",{className:"flex flex-wrap items-center gap-2 text-[12px] text-ink",children:[e.jsx("span",{children:n("routines.runLimit.stopAfter")}),e.jsxs(U,{"aria-label":n("routines.runLimit.label"),value:D??"",onChange:a=>z(a.target.value?Number(a.target.value):null),children:[e.jsx("option",{value:"",children:n("routines.runLimit.noLimit")}),an.map(a=>e.jsx("option",{value:a,children:Re(a)},a))]})]}),e.jsx("div",{className:"mt-1.5 text-[11px] leading-relaxed text-ink-secondary",children:n("routines.runLimit.help")}),y!=="none"&&e.jsxs("div",{className:"mt-3",children:[e.jsxs("label",{className:"flex flex-wrap items-center gap-2 text-[12px] text-ink",children:[e.jsx("span",{children:n("routines.overlapLabel")}),e.jsxs(U,{"aria-label":n("routines.overlapLabel"),value:w,onChange:a=>R(a.target.value==="queue"?"queue":"skip"),children:[e.jsx("option",{value:"skip",children:n("routines.overlapSkip")}),e.jsx("option",{value:"queue",children:n("routines.overlapQueue")})]})]}),e.jsx("p",{className:"mt-1.5 text-[11px] leading-relaxed text-ink-secondary",children:n(w==="queue"?"routines.overlapQueueHelp":"routines.overlapSkipHelp")})]}),y!=="none"&&e.jsxs("label",{className:"mt-3 flex items-start gap-2 text-[12px] text-ink",children:[e.jsx("input",{type:"checkbox","aria-label":n("routines.runOnStartupLabel"),checked:le,onChange:a=>F(a.target.checked),className:"mt-0.5 accent-accent"}),e.jsxs("span",{children:[e.jsx("span",{className:"block",children:n("routines.runOnStartupLabel")}),e.jsx("span",{className:"mt-1 block text-[11px] leading-relaxed text-ink-secondary",children:n("routines.runOnStartupHelp")})]})]})]})]}),Fn=v==="routine"&&!ae&&y!=="none"&&e.jsxs("label",{className:C("flex items-start gap-3 rounded-xl border border-hairline/40 bg-inset/40 px-3.5 py-3",Y&&"ml-8"),children:[e.jsx("input",{type:"checkbox","aria-label":n("routines.continuityLabel"),checked:Z,onChange:a=>te(a.target.checked),className:"mt-0.5 accent-accent"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-[13px] font-medium text-ink",children:n("routines.continuityLabel")}),e.jsx("span",{className:"mt-1 block text-[11px] leading-relaxed text-ink-secondary",children:n("routines.continuityHelp")})]})]}),Vt=v==="routine"&&!ae&&e.jsx("div",{className:C(Y&&"ml-8"),children:e.jsx(vn,{bot:s.find(a=>a.id===W[0]),value:it,allowCurrent:!!o,onChange:Ct})}),Jt=e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(ds,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),ae?e.jsxs("div",{className:"min-w-0 flex-1 rounded-xl border border-hairline/50 bg-inset px-3.5 py-3",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:n("routines.editor.groupContext")}),e.jsx("div",{className:"mt-1 text-[11px] leading-relaxed text-ink-secondary",children:n("routines.editor.teamGoalAttachments")})]}):e.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[e.jsx("input",{ref:At,type:"file",multiple:!0,className:"hidden",onChange:a=>{En(a.target.files),a.target.value=""}}),e.jsx("button",{type:"button",onClick:()=>At.current?.click(),className:"rounded-lg border border-hairline/50 px-3 py-2 text-[13px] font-medium text-ink hover:bg-raised",children:n("routines.attachment.add")}),e.jsx(wn,{attachments:Ce,onRemove:a=>lt(k=>k.filter(A=>A.id!==a))}),e.jsx("div",{className:"text-[11px] leading-relaxed text-ink-secondary",children:v==="routine"?n("routines.attachment.routineHelp"):Ie.length>1?n("routines.attachment.callSharedHelp"):n("routines.attachment.callKeptHelp")}),Mt&&e.jsx("div",{className:"text-[12px] text-warning",children:Mt})]})]}),Kt=v==="routine"&&e.jsxs("div",{className:"flex items-start gap-4",children:[ae?e.jsx(en,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}):ye==="cloud"?e.jsx(dn,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}):e.jsx(cn,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsx("div",{className:"min-w-0 flex-1",children:ae?e.jsxs("div",{className:"rounded-xl border border-accent/35 bg-accent/[0.07] p-3",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:n(Ot?"routines.editor.goalRunsOnCloud":"routines.editor.goalRunsOnComputer")}),e.jsx("div",{className:"mt-1 text-[11px] leading-relaxed text-ink-secondary",children:n("routines.editor.roomGoalKept")})]}):e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>_e("maus"),className:C("rounded-xl border p-3 text-left",ye==="maus"?"border-accent/60 bg-accent/10":"border-hairline/50 bg-inset hover:bg-raised"),children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:n("routines.editor.currentSetup")}),e.jsx("div",{className:"mt-1 text-[11px] text-ink-secondary",children:"Keeps its model and configured computer, including a self-hosted VPS."})]}),e.jsxs("button",{type:"button",disabled:!Mn||Ce.length>0,onClick:()=>_e("cloud"),className:C("rounded-xl border p-3 text-left disabled:cursor-not-allowed disabled:opacity-45",ye==="cloud"?"border-accent/60 bg-accent/10":"border-hairline/50 bg-inset hover:bg-raised"),children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:n("routines.runsOn.boat")}),e.jsx("div",{className:"mt-1 text-[11px] text-ink-secondary",children:n(Ot?"routines.runsOn.boatHintCloudHome":"routines.runsOn.boatHint")})]})]})})]}),Bn=!Y&&v==="routine"?n(u?o?"automations.editor.edit":"automations.editor.new":o?"routines.editor.edit":"routines.editor.new"):n(o||S?"routines.event.edit":"routines.event.new"),Qt=[["none","routines.repeat.once"],["daily","routines.repeat.daily"],["weekdays","routines.repeat.weekdays"],["weekly","routines.repeat.weekly"]];return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/65 p-3",onMouseDown:a=>a.target===a.currentTarget&&m(),children:e.jsxs("div",{ref:Et,role:"dialog","aria-modal":"true","aria-label":n(o||S?"routines.event.editLabel":"routines.event.createLabel"),tabIndex:-1,className:"max-h-[94vh] w-full max-w-[760px] overflow-y-auto rounded-2xl border border-hairline/60 bg-panel shadow-2xl",children:[e.jsxs("div",{className:"sticky top-0 z-20 flex items-center justify-between border-b border-hairline/40 bg-panel/95 px-5 py-3.5 backdrop-blur",children:[e.jsx("div",{className:"text-[15px] font-semibold text-ink",children:Bn}),e.jsx("button",{onClick:m,className:"rounded-full p-2 text-ink-secondary hover:bg-raised hover:text-ink","aria-label":n("common.close"),children:e.jsx(Me,{size:18})})]}),e.jsxs("div",{className:"space-y-5 px-5 py-5 sm:px-8",children:[Y&&Bt,Y&&Wt,e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("span",{className:"mt-3 size-4 shrink-0 rounded bg-accent"}),e.jsx("input",{autoFocus:!0,value:O,onChange:a=>_(a.target.value),"aria-label":n("routines.editor.titleLabel"),placeholder:v==="routine"?Y?n("routines.event.addTitle"):n("routines.editor.titlePlaceholder"):n("routines.event.addCallTitle"),className:"min-w-0 flex-1 border-b border-hairline/60 bg-transparent px-1 pb-2 text-[22px] font-medium text-ink outline-none placeholder:text-ink-tertiary focus:border-accent"})]}),Y?e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(gt,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-3",children:[Gt,qt,Ut,Yt,Zt]})]}):e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(gt,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-3",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:n("routines.editor.when")}),Gt,e.jsx("div",{role:"group","aria-label":n("routines.editor.repeat"),className:"flex flex-wrap gap-1.5",children:Qt.map(([a,k])=>e.jsx("button",{type:"button","aria-pressed":y===a,onClick:()=>_t(a),className:C("rounded-full border px-3 py-1.5 text-[12px] font-medium transition",y===a?"border-accent-border bg-accent/15 text-accent-text":"border-hairline/50 bg-inset text-ink-secondary hover:bg-raised hover:text-ink"),children:n(k)},a))}),!Qt.some(([a])=>a===y)&&e.jsx("div",{className:"text-[12px] text-ink-secondary",children:n("routines.editor.customRepeat")})]})]}),e.jsxs("div",{className:"flex items-start gap-4",children:[ae?e.jsx(hn,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}):e.jsx(bt,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsx("div",{className:"min-w-0 flex-1",children:ae?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"routine-goal-room",className:"mb-2 block text-[13px] font-medium text-ink",children:n("routines.editor.goalWhere")}),e.jsxs(U,{id:"routine-goal-room",value:me,onChange:a=>On(a.target.value),className:"w-full",children:[me&&!ue&&e.jsx("option",{value:me,disabled:!0,children:n("routines.editor.roomMissing")}),e.jsx("option",{value:"",children:n("routines.editor.goalOneOnOne")}),Be.map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[13px] font-medium text-ink",children:ue?n("routines.goal.chooseLead"):n("routines.editor.who")}),dt.length>0?e.jsxs(e.Fragment,{children:[e.jsx(yt,{bots:dt,selected:W,multiple:!1,onChange:$e}),e.jsx("div",{className:"mt-2 text-[12px] text-ink-secondary",children:ue?n("routines.goal.leadHelp",{name:ue.name}):n("routines.editor.goalOneOnOneHelp")})]}):e.jsx("div",{className:"rounded-xl border border-warning/30 bg-warning/10 px-3.5 py-3 text-[12px] text-warning",children:n("routines.goal.noMembers")})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mb-2 text-[13px] font-medium text-ink",children:v==="routine"?Y?n("routines.event.assignBot"):n("routines.editor.who"):n("routines.event.addGuests")}),s.length>0?e.jsxs(e.Fragment,{children:[e.jsx(yt,{bots:s,selected:W,multiple:v==="call",locked:!!r,onChange:$e}),e.jsx("div",{className:"mt-2 text-[12px] text-ink-secondary",children:v==="routine"?n("routines.event.botOwnsRuns"):n(Ie.length===0?"routines.event.invitedNone":Ie.length===1?"routines.event.invitedOne":"routines.event.invitedMany",{count:Ie.length})}),v==="routine"&&e.jsx(bn,{team:h.config?.team,bot:Ie[0],value:it,madeIn:o?.sourceThreadId})]}):e.jsxs("button",{type:"button",onClick:()=>{N({type:"newBot"}),m()},className:"w-full rounded-xl border border-dashed border-accent/45 bg-accent/[0.06] px-4 py-4 text-left hover:bg-accent/10",children:[e.jsx("div",{className:"text-[13px] font-medium text-accent",children:n("routines.event.createFirstBot")}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:n("routines.event.needsBot")})]})]})})]}),Y&&Vt,e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(st,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsx("textarea",{value:B,onChange:a=>E(a.target.value),rows:5,"aria-label":n("routines.editor.descriptionLabel"),placeholder:ae?n("routines.goal.instructionsPlaceholder"):v==="routine"?Y?n("routines.event.instructionsPlaceholder"):n("routines.editor.instructionsPlaceholder"):n("routines.event.agendaPlaceholder"),className:"min-w-0 flex-1 resize-y rounded-xl border border-hairline/50 bg-inset px-3.5 py-3 text-[13px] leading-relaxed text-ink outline-none placeholder:text-ink-tertiary focus:border-accent"})]}),Fn,Y&&Jt,Y&&Kt,!Y&&e.jsxs("div",{children:[e.jsxs("button",{type:"button","aria-expanded":Ge,"aria-controls":"routine-more-options",onClick:()=>_n(a=>!a),className:"flex items-center gap-1.5 rounded-lg px-2 py-1.5 text-[13px] font-medium text-accent-text hover:bg-raised",children:[e.jsx(Ds,{size:14,className:C("transition-transform",Ge&&"rotate-90")}),n(Ge?"routines.editor.fewer":"routines.editor.more")]}),Ge&&e.jsxs("div",{id:"routine-more-options",className:"mt-3 space-y-5 rounded-xl border border-hairline/40 bg-inset/30 p-4",children:[Bt,Wt,e.jsxs("div",{className:"space-y-3",children:[qt,Ut,Yt,Zt]}),Vt,Jt,Kt]})]}),Tt&&e.jsxs("div",{className:"ml-10 flex items-start gap-2 rounded-xl border border-danger/30 bg-danger/10 px-3 py-2.5 text-[13px] text-danger",children:[e.jsx(Ke,{size:15,className:"mt-0.5 shrink-0"}),Tt]})]}),e.jsxs("div",{className:"sticky bottom-0 flex items-center justify-end gap-2 border-t border-hairline/40 bg-panel/95 px-5 py-3.5 backdrop-blur",children:[e.jsx("button",{onClick:m,className:"rounded-lg px-4 py-2 text-[13px] text-ink-secondary hover:bg-raised hover:text-ink",children:n("common.cancel")}),e.jsxs("button",{onClick:Pn,disabled:It||Fe||!Hn,className:"flex items-center gap-2 rounded-lg bg-accent px-5 py-2 text-[13px] font-semibold text-white hover:brightness-110 disabled:opacity-40",children:[(It||Fe)&&e.jsx(ze,{size:14,className:"animate-spin"}),Fe?n("routines.attachment.attaching"):o||S||v==="routine"&&!ae?n("automations.editor.app.save"):n(v==="call"?"routines.event.scheduleCall":"routines.goal.schedule")]})]})]})})}function ha({seed:t,bots:s,routinesOnly:r=!1,onClose:l,onMore:i,onSavedRoutine:u,onSavedCall:m}){const{state:c,dispatch:h}=nt(),[N,o]=x.useState(r||t.limitReset?"routine":t.kind),[$,S]=x.useState(t.name??""),[v,J]=x.useState(t.description??""),[L,O]=x.useState(t.botIds.length?t.botIds:s[0]?[s[0].id]:[]),[_,B]=x.useState(()=>t.resultsThreadId??Qe(c,L[0])??null),E=p=>{p[0]!==L[0]&&B(Qe(c,p[0])??null),O(p)},[M,d]=x.useState(!1),[b,T]=x.useState(""),P=x.useRef(null),[g,j]=x.useState(null),I=N==="routine"?30:t.durationMinutes;x.useLayoutEffect(()=>{if(!t.anchor){j(null);return}const p=P.current;if(!p)return;const H=()=>{const R=p.getBoundingClientRect();let Z=t.anchor.x+12,te=t.anchor.y+12;Z+R.width>window.innerWidth-12&&(Z=t.anchor.x-R.width-12),te+R.height>window.innerHeight-12&&(te=t.anchor.y-R.height-12),j({left:Math.max(12,Math.min(Z,window.innerWidth-R.width-12)),top:Math.max(12,Math.min(te,window.innerHeight-R.height-12))})};return H(),window.addEventListener("resize",H),()=>window.removeEventListener("resize",H)},[N,t.anchor]);const D=async()=>{d(!0),T("");try{if(N==="routine"||r){const p=await Ne("/api/routines",{method:"POST",body:JSON.stringify({name:$,prompt:v,botId:L[0],runOn:"maus",enabled:!0,schedule:t.limitReset?{type:"limit_reset",engine:t.limitReset.engine,repeat:"once"}:{type:"once",at:t.at},durationMinutes:I,attachments:[],resultsThreadId:_})});u(p.routine)}else{const p=await Ne("/api/calendar-calls",{method:"POST",body:JSON.stringify({name:$,description:v,botIds:L,schedule:{type:"once",at:t.at},durationMinutes:I})});m(p.call)}l()}catch(p){T(p instanceof Error?p.message:String(p))}finally{d(!1)}},z=!!($.trim()&&L.length&&(N==="call"||v.trim()));return e.jsxs("div",{ref:P,role:"dialog","aria-label":n("routines.quick.label"),style:g??void 0,className:C("fixed z-50 max-h-[calc(100vh-24px)] w-[min(430px,calc(100vw-24px))] overflow-y-auto rounded-2xl border border-hairline/60 bg-panel shadow-2xl",!g&&"left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2"),children:[e.jsxs("div",{className:"flex items-center justify-between bg-raised/70 px-4 py-2.5",children:[e.jsx("div",{className:"text-[12px] font-medium text-ink-secondary",children:n("routines.quick.title")}),e.jsx("button",{onClick:l,className:"rounded-full p-1.5 text-ink-secondary hover:bg-inset hover:text-ink","aria-label":n("common.close"),children:e.jsx(Me,{size:16})})]}),e.jsxs("div",{className:"space-y-3 p-4",children:[e.jsx("input",{autoFocus:!0,value:$,onChange:p=>S(p.target.value),"aria-label":n("routines.editor.titleLabel"),placeholder:n("routines.event.addTitle"),onKeyDown:p=>{p.key==="Enter"&&z&&D()},className:"w-full border-b border-hairline/60 bg-transparent pb-2 text-[18px] font-medium text-ink outline-none placeholder:text-ink-tertiary focus:border-accent"}),!r&&!t.limitReset&&e.jsxs("div",{className:"flex items-center gap-1 border-b border-hairline/35 pb-2",children:[e.jsx("button",{type:"button",onClick:()=>{o("routine"),O(p=>p.slice(0,1))},className:C("rounded-lg px-3 py-1.5 text-[12px] font-medium",N==="routine"?"bg-accent/15 text-accent":"text-ink-secondary hover:bg-raised hover:text-ink"),children:n("routines.kind.routine")}),e.jsx("button",{type:"button",onClick:()=>o("call"),className:C("rounded-lg px-3 py-1.5 text-[12px] font-medium",N==="call"?"bg-accent/15 text-accent":"text-ink-secondary hover:bg-raised hover:text-ink"),children:n("routines.kind.call")})]}),e.jsxs("div",{className:"flex items-start gap-3 text-[13px] text-ink",children:[e.jsx(gt,{size:16,className:"mt-0.5 shrink-0 text-ink-secondary"}),t.limitReset?e.jsx("div",{"data-testid":"quick-limit-reset",children:Ns({engine:t.limitReset.engine,repeat:"once"})}):e.jsxs("div",{children:[e.jsx("div",{children:Nt(t.at)}),e.jsxs("div",{className:"mt-0.5 text-ink-secondary",children:[X(t.at),N==="call"?` – ${X(t.at+I*6e4)}`:""]})]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(bt,{size:16,className:"mt-2.5 shrink-0 text-ink-secondary"}),s.length===0?e.jsxs("button",{type:"button",onClick:()=>{h({type:"newBot"}),l()},className:"min-w-0 flex-1 rounded-xl border border-dashed border-accent/45 bg-accent/[0.06] px-3 py-3 text-left hover:bg-accent/10",children:[e.jsx("div",{className:"text-[12px] font-medium text-accent",children:n("routines.event.createFirstBot")}),e.jsx("div",{className:"mt-0.5 text-[11px] text-ink-secondary",children:n("routines.quick.comeBack")})]}):N==="routine"?e.jsxs(U,{value:L[0]??"",onChange:p=>E([p.target.value]),className:"flex-1",children:[e.jsx("option",{value:"",children:n("routines.event.assignBot")}),s.map(p=>e.jsx("option",{value:p.id,children:p.name},p.id))]}):e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(yt,{bots:s,selected:L,multiple:!0,onChange:E})})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(st,{size:16,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsx("textarea",{value:v,onChange:p=>J(p.target.value),rows:3,"aria-label":n("routines.editor.descriptionLabel"),placeholder:n(N==="routine"?"routines.quick.whatToDo":"routines.quick.description"),className:"min-w-0 flex-1 resize-none rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[13px] leading-relaxed text-ink outline-none placeholder:text-ink-tertiary focus:border-accent"})]}),N==="routine"&&e.jsx(vn,{bot:s.find(p=>p.id===L[0]),value:_,onChange:p=>B(p??null)}),N==="routine"&&e.jsx(bn,{team:c.config?.team,bot:s.find(p=>p.id===L[0]),value:_}),b&&e.jsx("div",{className:"rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:b})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-hairline/40 px-4 py-3",children:[e.jsx("button",{onClick:()=>i({...t,kind:N,botIds:L,name:$,description:v,durationMinutes:I,resultsThreadId:_}),title:n("routines.quick.moreTitle"),className:"rounded-lg px-3 py-2 text-[12px] font-medium text-accent hover:bg-accent/10",children:n("routines.editor.more")}),e.jsxs("button",{onClick:D,disabled:!z||M,className:"flex items-center gap-1.5 rounded-lg bg-accent px-4 py-2 text-[12px] font-semibold text-white hover:brightness-110 disabled:opacity-40",children:[M&&e.jsx(ze,{size:13,className:"animate-spin"}),n("common.save")]})]})]})}function ga({anchor:t,days:s,items:r,bots:l,groups:i,selectedId:u,onOpen:m,onCreate:c,onMove:h,onResize:N,markers:o=[],onDropOnReset:$}){const S=x.useRef(null),[v,J]=x.useState(null),[L,O]=x.useState(null),_=Ye(Date.now()),B=Array.from({length:s},(g,j)=>mn(t,j)),E=s===7?64:s===3?180:280,M=`64px repeat(${s}, minmax(${E}px, 1fr))`,d=64+s*E;x.useEffect(()=>{const g=S.current;if(!g)return;const j=new Date,I=B.includes(_)?Math.max(0,j.getHours()-2):7;g.scrollTo({top:I*G})},[s]);const b=(g,j)=>{if(g.button!==0||g.target.closest("[data-event-card]"))return;const I=g.currentTarget.getBoundingClientRect(),D=Ue(j,g.clientY,I.top,G);let z=D+30*6e4;J({day:j,start:D,end:z});const p=w=>{const R=Ue(j,w.clientY,I.top,G);z=Math.max(D+ee*6e4,R+ee*6e4),J({day:j,start:D,end:z})},H=w=>{document.removeEventListener("pointermove",p),document.removeEventListener("pointerup",H),J(null),c({kind:"routine",at:D,durationMinutes:Math.max(ee,Math.round((z-D)/6e4)),botIds:[],anchor:{x:w.clientX,y:w.clientY}})};document.addEventListener("pointermove",p),document.addEventListener("pointerup",H,{once:!0})},T=(g,j)=>{g.preventDefault(),O(null);const I=g.currentTarget.getBoundingClientRect(),D=Ue(j,g.clientY,I.top,G),z=g.dataTransfer.getData(Xe);if(z)return c({kind:"routine",at:D,durationMinutes:30,botIds:[z],anchor:{x:g.clientX,y:g.clientY}});const p=g.dataTransfer.getData(we);if(p)try{const H=JSON.parse(p);h(H,D)}catch{}},P=(g,j)=>{if(!g.dataTransfer.types.includes(Xe)&&!g.dataTransfer.types.includes(we))return;g.preventDefault(),g.dataTransfer.dropEffect=g.dataTransfer.types.includes(we)?"move":"copy";const I=g.currentTarget.getBoundingClientRect(),D=Ue(j,g.clientY,I.top,G);O(z=>z?.day===j&&z.at===D?z:{day:j,at:D})};return e.jsxs("div",{ref:S,className:"min-h-0 flex-1 overflow-auto border-l border-t border-hairline/40 bg-app",children:[e.jsxs("div",{className:"sticky top-0 z-30 grid bg-app/95 backdrop-blur",style:{gridTemplateColumns:M,minWidth:d},children:[e.jsx("div",{className:"border-b border-r border-hairline/40 px-2 py-3 text-center text-[9px] uppercase tracking-wider text-ink-secondary",children:hs(-new Date(t).getTimezoneOffset())}),B.map(g=>{const j=new Date(g),I=g===_;return e.jsxs("div",{role:"columnheader",className:C("border-b border-r border-hairline/40 px-2 py-2 text-center last:border-r-0",I&&"bg-accent/[0.035]"),children:[e.jsx("div",{className:C("text-[10px] font-medium uppercase tracking-[0.14em]",I?"text-accent":"text-ink-secondary"),children:Ze(j.getDay())}),e.jsx("div",{className:C("mx-auto mt-1 flex size-8 items-center justify-center rounded-full text-[15px] font-medium",I?"bg-accent text-accent-ink":"text-ink"),children:j.getDate()})]},g)})]}),e.jsxs("div",{role:"grid","aria-label":n("routines.calendar.label"),onDragEnd:()=>O(null),className:"relative grid",style:{height:G*24,gridTemplateColumns:M,minWidth:d},children:[e.jsx("div",{className:"relative border-r border-hairline/40",children:Array.from({length:24},(g,j)=>e.jsx("div",{className:"absolute right-2 -translate-y-1/2 text-[10px] tabular-nums text-ink-tertiary",style:{top:j*G},children:j===0?"":new Date(2e3,0,1,j).toLocaleTimeString(Le(),{hour:"numeric"})},j))}),B.map(g=>{const j=new Date,I=(j.getHours()*60+j.getMinutes())/60*G,D=r.filter(w=>Ye(w.at)===g),z=gs(D),p=v?.day===g?v:null,H=L?.day===g?L:null;return e.jsxs("div",{role:"gridcell","aria-label":n("routines.calendar.day",{date:Nt(g)}),onPointerDown:w=>b(w,g),onDragOver:w=>P(w,g),onDragLeave:w=>{(!(w.relatedTarget instanceof Node)||!w.currentTarget.contains(w.relatedTarget))&&O(null)},onDrop:w=>T(w,g),className:C("relative border-r border-hairline/40 last:border-r-0",g===_&&"bg-accent/[0.025]"),children:[Array.from({length:48},(w,R)=>e.jsx("div",{className:C("pointer-events-none absolute inset-x-0 border-t",R%2===0?"border-hairline/30":"border-hairline/10"),style:{top:R/2*G}},R)),g===_&&e.jsxs("div",{className:"pointer-events-none absolute inset-x-0 z-20 flex items-center",style:{top:I},children:[e.jsx("span",{className:"-ml-1 size-2 rounded-full bg-danger"}),e.jsx("span",{className:"h-px flex-1 bg-danger/80"})]}),p&&e.jsx("div",{className:"pointer-events-none absolute inset-x-1 z-10 rounded-md border border-accent/70 bg-accent/20",style:{top:(new Date(p.start).getHours()*60+new Date(p.start).getMinutes())/60*G,height:Math.max(16,(p.end-p.start)/36e5*G)}}),H&&e.jsx("div",{className:"pointer-events-none absolute inset-x-1 z-20 rounded-md border border-accent/80 bg-accent/25 shadow-sm",style:{top:(new Date(H.at).getHours()*60+new Date(H.at).getMinutes())/60*G,height:G/2},children:e.jsx("div",{className:"px-2 py-1 text-[10px] font-medium text-accent",children:X(H.at)})}),o.filter(w=>Ye(w.at)===g).map(w=>e.jsx(Vs,{marker:w,hourHeight:G,onDrop:$&&(R=>$(R,w))},w.engine)),D.map(w=>e.jsx(Ks,{item:w,bots:l,groups:i,compact:s===7,layout:z.get(w.id)??{column:0,columns:1},selected:w.id===u,onOpen:()=>m(w),onResize:R=>N(w,R)},w.id))]},g)})]})]})}function ba({item:t,bots:s,onClose:r,onEdit:l,onCallChanged:i,onOpenRoom:u,onOpenRun:m}){const{state:c,dispatch:h}=nt(),N=ln(),o=Zn(),[$,S]=x.useState(!1),v=x.useRef(!1),[J,L]=x.useState(!1),[O,_]=x.useState(void 0),[B,E]=x.useState(""),M=t.kind==="call",d=t.kind==="routine"?t.routine:null,b=O===void 0?t.kind==="routine"?t.run:null:O&&(c.routineRuns.find(f=>f.id===O.id)??O),T=t.kind==="call"?t.call:null,P=!M&&(b?.target??d?.target)==="room-goal",g=P?b?b.groupId:d?.groupId:void 0,j=c.groups.find(f=>f.id===g),I=b?.executionThreadId??b?.threadId,D=T?.botIds??[b?.botId??d?.botId??""],z=D.flatMap(f=>s.find(K=>K.id===f)??[]),p=z[0],H=P&&g?j:p,w=!!(I&&(H?.threadId===I||H?.tasks?.some(f=>f.threadId===I))),R=b?b.resultsThreadId??b.sourceThreadId:d?.resultsThreadId,Z=R??(!b&&d?.target==="bot"?p?.mainThreadId:void 0),te=Z&&[...c.bots,...c.groups].some(f=>f.threadId===Z||f.tasks?.some(K=>K.threadId===Z)),le=T?.name??b?.routineName??d?.name??"Routine",F=T?.description??b?.prompt??d?.prompt??"",y=T?.attachments??b?.attachments??d?.attachments??[],de=T?.botIds.length===1?p?.id:void 0,Q=b?b.timeoutMinutes:d?.timeoutMinutes,be=()=>{I&&(P&&g?(h({type:"switchGroupTask",groupId:g,threadId:I}),u(g)):p&&Cs(h,p,I,o),r())},ce=async(f,K="POST",pe)=>{S(!0),E("");try{const se=await Ne(f,{method:K,...pe?{body:JSON.stringify(pe)}:{}});se.routine&&h({type:"routinePatched",routine:se.routine}),se.run&&h({type:"routineRunPatched",run:se.run})}catch(se){E(se instanceof Error?se.message:String(se))}finally{S(!1)}},ve=()=>{!d||$||v.current||(v.current=!0,L(!0),_(null),S(!0),E(""),h({type:"runRoutine",routineId:d.id,onStarted:_,onError:f=>E(f instanceof Error?f.message:String(f)),onSettled:()=>{v.current=!1,L(!1),S(!1)}}))},at=async()=>{if(T){S(!0),E("");try{const{group:f}=await Ne(`/api/calendar-calls/${T.id}/room`,{method:"POST"});h({type:"groupPatched",group:f}),u(f.id)}catch(f){E(f instanceof Error?f.message:String(f))}finally{S(!1)}}},Ae=async()=>{window.confirm(n("routines.event.deleteConfirm",{title:le}))&&(T?(await Ne(`/api/calendar-calls/${T.id}`,{method:"DELETE"}),i(T.id)):d&&h({type:"deleteRoutine",routineId:d.id}),r())},fe=d?.id??b?.routineId,Oe=fe?c.routineRuns.filter(f=>f.routineId===fe).sort((f,K)=>nn(K)-nn(f)).slice(0,3):[],q=b?.runOn??d?.runOn,Se=bs({roomGoal:P,runOn:q,computer:p?.computer,cloudHome:c.config?.cloudHome===!0}),ne=R?[...c.bots,...c.groups].find(f=>f.threadId===R||f.tasks?.some(K=>K.threadId===R)):void 0,rt=R?ne?.tasks?.find(f=>f.threadId===R)?.title??ne?.name??n("routines.results.missing"):n("routines.results.main");return e.jsxs("aside",{"aria-label":n("routines.drawer.label"),className:"flex h-full w-[min(310px,100vw)] shrink-0 flex-col border-l border-hairline/40 bg-panel",children:[e.jsxs("div",{className:"flex items-start gap-3 border-b border-hairline/40 px-4 py-3.5",children:[M?e.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-full bg-accent/15 text-accent-text",children:e.jsx(vt,{size:16})}):P?e.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-full bg-accent/15 text-accent-text",children:e.jsx(hn,{size:16})}):p&&e.jsx(Ve,{bot:p,state:b?jn(b.status):d?.enabled===!1?"sleeping":"idle",size:36,animated:!1}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"break-words text-[15px] font-semibold leading-snug text-ink",children:le}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5",children:[d&&e.jsx("span",{className:C("rounded-full px-2 py-0.5 text-[11px] font-medium",d.enabled?"bg-success/15 text-success":"bg-inset text-ink-secondary"),children:vs(d)}),e.jsxs("span",{className:"text-[11px] text-ink-secondary",children:[Nt(t.at)," · ",X(t.at),M?` – ${X(t.at+t.durationMinutes*6e4)}`:""]})]})]}),e.jsx("button",{type:"button",onClick:r,className:"rounded-full p-1.5 text-ink-secondary hover:bg-raised hover:text-ink","aria-label":n("routines.drawer.close"),children:e.jsx(Me,{size:16})})]}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4",children:[b&&e.jsxs("div",{role:"status","aria-live":"polite",className:"rounded-xl border border-hairline/40 bg-inset p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[12px] font-medium text-ink",children:[b.status==="running"&&e.jsx(ze,{size:13,className:"animate-spin text-accent"}),jt(b)]}),b.output&&e.jsx("div",{className:"mt-2 max-h-48 overflow-y-auto whitespace-pre-wrap text-[12px] leading-relaxed text-ink-secondary",children:xt(b,"output")}),b.error&&e.jsx("div",{className:C("mt-2 text-[12px]",kt(b)?"text-warning":"text-danger"),children:xt(b,"error")})]}),b?.attention&&e.jsxs("div",{className:"flex items-start gap-2 rounded-xl border border-warning/30 bg-warning/10 px-3 py-2.5 text-warning",children:[e.jsx(Ke,{size:15,className:"mt-0.5 shrink-0"}),e.jsx("div",{className:"min-w-0 whitespace-pre-wrap text-[12px] leading-relaxed",children:xt(b,"attention")})]}),b?.status==="waiting"&&!b.attention&&e.jsx("div",{className:"rounded-xl border border-warning/30 bg-warning/10 px-3 py-2.5 text-[12px] text-warning",children:n("routines.drawer.runWaiting")}),e.jsx(oe,{label:M?n("routines.drawer.guests"):P?n("routines.drawer.lead"):n("routines.drawer.bot"),children:e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[z.map(f=>e.jsxs("div",{className:"flex items-center gap-1.5 rounded-full border border-hairline/50 bg-inset py-0.5 pl-0.5 pr-2.5",children:[e.jsx(Ve,{bot:f,state:"idle",size:22,animated:!1}),e.jsx("span",{className:"text-[12px] text-ink",children:f.name})]},f.id)),z.length===0&&e.jsx("span",{className:"text-[13px] text-ink-secondary",children:n("routines.unavailableBot")})]})}),P&&g&&e.jsx(oe,{label:n("routines.drawer.group"),children:e.jsx("div",{className:"text-[13px] text-ink",children:j?.name??n("routines.drawer.groupUnavailable")})}),(d||T)&&e.jsxs(oe,{label:n("routines.drawer.schedule"),children:[e.jsx("div",{className:"text-[13px] text-ink",children:fs((d??T).schedule)}),d?.schedule.type==="cron"&&e.jsx("div",{className:"mt-2",children:e.jsx($s,{schedule:d.schedule,paused:!d.enabled})})]}),F&&e.jsx(oe,{label:M?n("routines.drawer.agenda"):n("routines.drawer.what"),children:e.jsx("div",{className:"whitespace-pre-wrap text-[13px] leading-relaxed text-ink",children:F})}),!M&&e.jsxs(oe,{label:n("routines.drawer.runsOn"),children:[e.jsxs("div",{className:"flex items-start gap-2 text-[13px] text-ink",children:[q==="cloud"?e.jsx(dn,{size:14,className:"mt-0.5 shrink-0 text-ink-secondary"}):e.jsx(cn,{size:14,className:"mt-0.5 shrink-0 text-ink-secondary"}),e.jsx("span",{children:Se.label})]}),e.jsx("div",{className:"mt-0.5 text-[11px] leading-relaxed text-ink-secondary",children:Se.hint})]}),!M&&!P&&e.jsx(oe,{label:n("routines.results.label"),children:e.jsx("div",{className:"text-[13px] text-ink",children:rt})}),y.length>0&&e.jsxs(oe,{label:n("routines.drawer.attachments"),children:[e.jsx(wn,{attachments:y}),T&&e.jsx("div",{className:"mt-1.5 text-[11px] leading-relaxed text-ink-secondary",children:n(T.botIds.length>1?"routines.drawer.callSharedHelp":"routines.drawer.callKeptHelp")})]}),N&&!M&&e.jsx(oe,{label:n("routines.drawer.runLimit"),children:e.jsx("div",{className:"text-[13px] text-ink",children:Q==null?n("routines.drawer.noTimeLimit"):n("routines.drawer.stopsAfter",{duration:Re(Q)})})}),!M&&e.jsx(oe,{label:n("routines.logs"),action:d&&e.jsxs("button",{type:"button",onClick:()=>{h({type:"showRoutines",section:"logs",routineId:d.id,botId:d.botId}),r()},className:"flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[11px] text-accent-text hover:bg-raised",children:[e.jsx(st,{size:11}),n("routines.drawer.allRuns")]}),children:Oe.length===0?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:n("routines.drawer.noRuns")}):e.jsx("div",{className:"space-y-1",children:Oe.map(f=>e.jsx(oa,{run:f,current:f.id===b?.id,onOpen:()=>m?.(f)},f.id))})}),B&&e.jsx("div",{role:"alert",className:"rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:B})]}),e.jsxs("div",{className:"space-y-2 border-t border-hairline/40 px-4 py-3",children:[d&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:ve,disabled:$,className:"flex flex-1 items-center justify-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12px] font-semibold text-accent-ink hover:brightness-110 disabled:opacity-50",children:[J?e.jsx(ze,{size:13,className:"animate-spin"}):e.jsx(sn,{size:13}),J?n("routines.starting"):n("routines.runNow")]}),e.jsxs("button",{disabled:$,onClick:()=>{ce(`/api/routines/${d.id}`,"PATCH",{enabled:!d.enabled})},title:n(d.enabled?"routines.drawer.pauseRoutine":"routines.drawer.resumeRoutine"),className:"flex flex-1 items-center justify-center gap-1.5 rounded-lg border border-hairline/50 bg-control px-3 py-2 text-[12px] font-medium text-ink hover:bg-raised-hover disabled:opacity-40",children:[d.enabled?e.jsx(ys,{size:13}):e.jsx(sn,{size:13}),d.enabled?n("routines.pause"):n("routines.resume")]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[de&&e.jsxs("button",{onClick:()=>u(de),className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12px] font-semibold text-accent-ink hover:brightness-110",children:[e.jsx(Te,{size:13}),n("routines.drawer.joinGroup")]}),T&&T.botIds.length>1&&e.jsxs("button",{onClick:at,disabled:$,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12px] font-semibold text-accent-ink hover:brightness-110 disabled:opacity-50",children:[e.jsx(Te,{size:13}),n("routines.drawer.joinGroup")]}),P&&j&&!I&&e.jsxs("button",{onClick:()=>{u(j.id),r()},className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink",children:[e.jsx(Te,{size:13}),n("routines.drawer.openGroup")]}),w&&e.jsxs("button",{onClick:be,className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink",children:[e.jsx(Te,{size:13}),n(P&&g?"routines.drawer.openGroupThread":"routines.drawer.openThread")]}),te&&Z&&e.jsxs("button",{type:"button",onClick:()=>{js(h,{botId:D[0],threadId:Z},c,o),r()},className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink",children:[e.jsx(Te,{size:13}),n("routines.results.open")]}),b&&["queued","running","waiting"].includes(b.status)&&e.jsxs("button",{onClick:()=>{ce(`/api/routine-runs/${b.id}/cancel`)},disabled:$,className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-40",children:[e.jsx(Me,{size:13}),n("routines.drawer.cancelRun")]}),e.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[(d||T)&&e.jsx("button",{onClick:l,className:"rounded-lg px-2.5 py-1.5 text-[12px] font-medium text-ink hover:bg-raised",children:n("routines.edit")}),(d||T)&&e.jsx("button",{onClick:()=>{Ae()},className:"rounded-lg p-2 text-ink-secondary hover:bg-danger/10 hover:text-danger",title:n("routines.delete"),"aria-label":n("routines.delete"),children:e.jsx(ks,{size:14})})]})]})]})]})}function oe({label:t,action:s,children:r}){return e.jsxs("section",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between gap-2",children:[e.jsx("h3",{className:"text-[11px] font-semibold uppercase tracking-wider text-ink-tertiary",children:t}),s]}),r]})}function ia(t){if(t.startedAt==null||t.finishedAt==null||t.finishedAt<t.startedAt)return null;const s=Math.round((t.finishedAt-t.startedAt)/1e3);return s<60?`${s}s`:Re(Math.round(s/60))}function oa({run:t,current:s,onOpen:r}){const l=t.startedAt??t.scheduledFor,i=ia(t),u=t.status==="completed"&&(!t.goalStatus||t.goalStatus==="completed"),m=ws(t)||t.goalStatus==="failed"||t.goalStatus==="blocked",c=["queued","running","waiting"].includes(t.status);return e.jsxs("button",{type:"button",onClick:r,"aria-label":n("routines.openRun",{name:t.routineName,status:jt(t)}),"aria-current":s||void 0,className:C("flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left hover:bg-raised",s&&"bg-raised"),children:[u?e.jsx(gn,{size:14,className:"shrink-0 text-success","aria-hidden":"true"}):m?kt(t)?e.jsx(Ke,{size:14,className:"shrink-0 text-warning","aria-hidden":"true"}):e.jsx(Ss,{size:14,className:"shrink-0 text-danger","aria-hidden":"true"}):c?e.jsx(ze,{size:14,className:"shrink-0 animate-spin text-accent","aria-hidden":"true"}):e.jsx(Ke,{size:14,className:"shrink-0 text-ink-tertiary","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] text-ink",children:new Date(l).toLocaleDateString(Le(),{month:"short",day:"numeric"})}),e.jsxs("span",{className:"shrink-0 text-[11px] tabular-nums text-ink-secondary",children:[X(l),i?` · ${i}`:""]})]})}function la({routine:t,bots:s,lockedBotId:r,initialBotId:l,defaultRunOn:i,plain:u,onClose:m}){const c=t?.schedule.type==="once"?t.schedule.at:t?.schedule.type==="daily"?ht(Date.now(),t.schedule.time):t?.schedule.type==="interval"?t.schedule.anchorAt:t?.schedule.type==="cron"?t.nextRunAt??on():on();return e.jsx(ra,{seed:{kind:"routine",at:c,durationMinutes:t?.durationMinutes??30,botIds:r?[r]:t?[t.botId]:l?[l]:s.length===1?[s[0].id]:[],routine:t},bots:s,lockedBotId:r,defaultRunOn:i,plain:u,onClose:m,onSavedCall:()=>{}})}const va=Object.freeze(Object.defineProperty({__proto__:null,RoutineEditor:la},Symbol.toStringTag,{value:"Module"}));export{ga as C,ba as E,Rs as H,ha as Q,la as R,zs as a,ra as b,va as c};
1
+ import{c as tt,r as x,j as e,t as n,a as C,i as Le,bh as Un,ac as ln,g as dn,L as cn,X as ze,S as Yn,z as Zn}from"./styles-6RbfQIY7.js";import{b as Vn}from"./remote-desktop-DDRRx8uY.js";import{b6 as Kn,b1 as Jn,B as Ve,c as Qn,L as Me,z as Te}from"./PlacesRail-yZdo57pP.js";import{ji as Ke,ck as Xn,D as U,aQ as es,jj as ts,jk as un,bi as ns,cV as ss,jl as as,jm as xn,u as nt,jn as rs,aa as jt,jo as is,fl as X,ag as os,jp as kt,jq as ee,jr as ht,gv as ls,js as qe,jt as pn,cS as mn,cP as Ye,ju as ut,jv as Xt,jw as en,jx as Re,y as Ze,jy as tn,jz as ds,jA as gt,cN as hn,ad as st,jB as Je,jC as cs,m as us,jD as xs,bs as gn,jE as ps,jF as ms,n as Ne,jG as hs,jH as gs,jI as Nt,jJ as nn,jK as bs,a8 as vs,ae as xt,x as fs,cK as sn,cL as ys,dF as js,T as ks,jL as Ns,jM as Ue,cz as ws,br as Ss,fU as Cs}from"./App-DRnqqiJP.js";import{u as Is}from"./ProIntroduction-DapZkP7I.js";import{C as Ds}from"./MenuMotion-BDYr4RxL.js";const Ts=[["path",{d:"M5 22h14",key:"ehvnwv"}],["path",{d:"M5 2h14",key:"pdyrp9"}],["path",{d:"M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22",key:"1d314k"}],["path",{d:"M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2",key:"1vvvr6"}]],Rs=tt("hourglass",Ts);const zs=[["path",{d:"m2 9 3-3 3 3",key:"1ltn5i"}],["path",{d:"M13 18H7a2 2 0 0 1-2-2V6",key:"1r6tfw"}],["path",{d:"m22 15-3 3-3-3",key:"4rnwn2"}],["path",{d:"M11 6h6a2 2 0 0 1 2 2v10",key:"2f72bc"}]],Ms=tt("repeat-2",zs);const Ls=[["path",{d:"M2 21a8 8 0 0 1 13.292-6",key:"bjp14o"}],["circle",{cx:"10",cy:"8",r:"5",key:"o932ke"}],["path",{d:"M19 16v6",key:"tddt3s"}],["path",{d:"M22 19h-6",key:"vcuq98"}]],bt=tt("user-round-plus",Ls);const As=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],vt=tt("video",As);function Qe(t,s){if(!t.config?.team)return;const r=t.bots.find(i=>i.id===s);if(r?.defaultBot?.person)return null;const l=r&&t.activeView==="chat"&&t.selectedId===r.id?r.tasks?.find(i=>i.threadId===r.threadId):void 0;return l&&l.private!==!0&&!l.routineRunId?r.mainThreadId??null:Ke}function Os(t,s,r){const l=i=>typeof i=="string"&&!!t.tasks?.some(u=>u.threadId===i&&u.private===!0);return!!t.defaultBot?.person||s===Ke||l(s)||l(r)}function bn({team:t,bot:s,value:r,madeIn:l}){if(!t||!s)return null;const i=Os(s,r,l),u=i?Kn:es;return e.jsxs("p",{role:"note","data-routine-audience":i?"me":"shared",className:"mt-2 flex items-center gap-1 text-[12px] leading-4 text-ink-secondary",children:[e.jsx(u,{size:12,"aria-hidden":"true",className:"shrink-0"}),e.jsx("span",{children:i?n("team.privateHeader"):ts(t.name,s.onlyPeopleAdded)})]})}function vn({bot:t,value:s,allowCurrent:r=!1,team:l,onChange:i}){const u=x.useId(),m=Xn();if(l??m!==null)return e.jsx(Es,{id:u,bot:t,value:s,allowCurrent:r,onChange:i});const c=(t?.tasks??[]).filter(o=>!o.routineRunId),h=typeof s=="string"&&!c.some(o=>o.threadId===s),N=[...t?.projects??[],{id:"",name:n("folder.none")}];return e.jsxs("div",{className:"min-w-0 space-y-1.5",children:[e.jsx("label",{htmlFor:u,className:"block text-[12px] font-medium text-ink",children:n("routines.results.label")}),e.jsxs(U,{className:"w-full",id:u,"aria-describedby":`${u}-help`,disabled:!t,value:s??(s===null?"new":"current"),onChange:o=>i(o.target.value==="new"?null:o.target.value==="current"?void 0:o.target.value),children:[r&&e.jsx("option",{value:"current",children:n("routines.results.keep")}),e.jsx("option",{value:"new",children:n("routines.results.main")}),h&&e.jsx("option",{value:s,disabled:!0,children:n("routines.results.unavailable")}),N.map(o=>{const $=c.filter(S=>o.id?S.projectId===o.id:!t?.projects?.some(v=>v.id===S.projectId));return $.length?e.jsx("optgroup",{label:o.name,children:$.map(S=>e.jsx("option",{value:S.threadId,children:S.title},S.threadId))},o.id):null})]}),e.jsx("p",{id:`${u}-help`,className:"text-[11px] leading-relaxed text-ink-secondary",children:n("routines.results.mainHelp")})]})}function Es({id:t,bot:s,value:r,allowCurrent:l,onChange:i}){const u=typeof r=="string"&&!!s?.tasks?.some(c=>c.threadId===r&&c.private===!0),m=r===void 0&&l?"current":r===Ke||u?"me":"shared";return e.jsxs("div",{className:"min-w-0 space-y-1.5",children:[e.jsx("label",{htmlFor:t,className:"block text-[12px] font-medium text-ink",children:n("routines.results.label")}),e.jsxs(U,{className:"w-full",id:t,"aria-describedby":`${t}-help`,disabled:!s,value:m,onChange:c=>i(c.target.value==="current"?void 0:c.target.value==="me"?u?r:Ke:s?.mainThreadId??null),children:[m==="current"&&e.jsx("option",{value:"current",children:n("routines.results.keep")}),e.jsx("option",{value:"me",children:n("routines.results.justMe")}),e.jsx("option",{value:"shared",children:n("task.sharedChat")})]}),e.jsx("p",{id:`${t}-help`,className:"text-[11px] leading-relaxed text-ink-secondary",children:n("routines.results.teamHelp")})]})}const pt="min-w-0 rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent [color-scheme:dark]",Ps=t=>Array.from({length:12},(s,r)=>new Intl.DateTimeFormat(t,{month:"long",timeZone:"UTC"}).format(new Date(Date.UTC(2024,r,1)))),Hs=["UTC",...typeof Intl.supportedValuesOf=="function"?Intl.supportedValuesOf("timeZone"):[]];function fn({runs:t,timeZone:s,paused:r=!1}){if(!t.length)return null;const l=new Intl.DateTimeFormat(Le(),{timeZone:s,weekday:"short",year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"});return e.jsxs("div",{className:"space-y-1 text-[11px] leading-relaxed text-ink-secondary","aria-label":n(r?"routines.cron.pausedPreviewLabel":"routines.cron.nextRunsLabel"),children:[e.jsxs("div",{className:"font-medium",children:[n(r?"routines.cron.pausedPreview":"routines.cron.nextRuns")," · ",s]}),t.map(i=>e.jsx("div",{children:e.jsx("time",{dateTime:new Date(i).toISOString(),children:l.format(i)})},i)),e.jsx("div",{className:"pt-1",children:n("routines.cron.clockChanges")})]})}function $s({schedule:t,paused:s=!1}){const r=x.useMemo(()=>{try{return un(t,Date.now(),3)}catch{return[]}},[t]);return e.jsx(fn,{runs:r,timeZone:t.timeZone,paused:s})}function _s({choice:t,value:s,onChange:r,runs:l,error:i}){const u=m=>r({...s,...m});return e.jsxs("div",{className:"space-y-3",children:[t==="cron"?e.jsxs("label",{className:"block space-y-1.5 text-[12px] text-ink-secondary",children:[e.jsx("span",{children:n("routines.cron.expression")}),e.jsx("input",{value:s.expression,onChange:m=>u({expression:m.target.value}),placeholder:"0 9 1 * *",spellCheck:!1,autoComplete:"off","aria-invalid":!!i,"aria-describedby":"routine-cron-help routine-cron-error",className:C(pt,"w-full font-mono")}),e.jsx("span",{id:"routine-cron-help",className:"block text-[11px]",children:n("routines.cron.expressionHelp")})]}):e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[t==="yearly"&&e.jsxs("label",{className:"space-y-1.5 text-[12px] text-ink-secondary",children:[e.jsx("span",{className:"block",children:n("routines.cron.month")}),e.jsx(U,{value:s.month,onChange:m=>u({month:m.target.value}),children:Ps(Le()).map((m,c)=>e.jsx("option",{value:String(c+1),children:m},m))})]}),e.jsxs("label",{className:"space-y-1.5 text-[12px] text-ink-secondary",children:[e.jsx("span",{className:"block",children:n("routines.cron.dayOfMonth")}),e.jsxs(U,{value:s.day,onChange:m=>u({day:m.target.value}),children:[Array.from({length:31},(m,c)=>e.jsx("option",{value:String(c+1),children:c+1},c+1)),e.jsx("option",{value:"L",children:n("routines.cron.lastDay")})]})]}),e.jsxs("label",{className:"space-y-1.5 text-[12px] text-ink-secondary",children:[e.jsx("span",{className:"block",children:n("routines.cron.time")}),e.jsx("input",{type:"time",step:60,value:s.time,onChange:m=>u({time:m.target.value}),className:pt})]})]}),t!=="cron"&&Number(s.day)>28&&e.jsx("p",{className:"text-[11px] text-ink-secondary",children:n("routines.cron.skippedMonths")}),e.jsxs("label",{className:"block space-y-1.5 text-[12px] text-ink-secondary",children:[e.jsx("span",{children:n("routines.cron.timeZone")}),e.jsx("input",{list:"routine-time-zones",value:s.timeZone,onChange:m=>u({timeZone:m.target.value}),placeholder:"America/New_York",spellCheck:!1,autoComplete:"off","aria-invalid":!!i,"aria-describedby":"routine-cron-error",className:C(pt,"block w-full")})]}),e.jsx("datalist",{id:"routine-time-zones",children:Hs.map(m=>e.jsx("option",{value:m},m))}),i&&e.jsx("p",{id:"routine-cron-error",role:"alert",className:"text-[12px] text-danger",children:i}),!i&&e.jsx(fn,{runs:l,timeZone:s.timeZone.trim()})]})}const ge=t=>["monthly","yearly","cron"].includes(t);function yn(t){const s=t.trim().split(/\s+/);if(s.length!==5)return null;const[r,l,i,u,m]=s;return!/^\d+$/.test(r)||Number(r)>59||!/^\d+$/.test(l)||Number(l)>23||!(i==="L"||/^\d+$/.test(i)&&Number(i)>=1&&Number(i)<=31)||!(u==="*"||/^\d+$/.test(u)&&Number(u)>=1&&Number(u)<=12)||m!=="*"?null:{day:i==="L"?i:String(Number(i)),month:u,time:`${String(Number(l)).padStart(2,"0")}:${String(Number(r)).padStart(2,"0")}`}}function Fs(t){const s=yn(t.expression);return s?s.month==="*"?"monthly":"yearly":"cron"}function Bs(t,s){const r=t?.timeZone??Intl.DateTimeFormat().resolvedOptions().timeZone,l=t&&yn(t.expression);let i;try{i=new Intl.DateTimeFormat("en-US",{timeZone:r,month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(s)}catch{i=new Intl.DateTimeFormat("en-US",{timeZone:"UTC",month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(s)}const u=h=>i.find(N=>N.type===h).value,m=l?.time??`${u("hour")}:${u("minute")}`,c=l?.day??u("day");return{expression:t?.expression??`${Number(m.slice(3))} ${Number(m.slice(0,2))} ${c} * *`,timeZone:r,day:c,month:l&&l.month!=="*"?String(Number(l.month)):u("month"),time:m}}function Ws(t,s,r,l){try{if(t!=="cron"&&!/^\d{2}:\d{2}$/.test(s.time))throw new Error(n("routines.cron.chooseTime"));const[i,u]=s.time.split(":"),m=l??{type:"cron",timeZone:s.timeZone,expression:t==="cron"?s.expression:`${Number(u)} ${Number(i)} ${s.day} ${t==="yearly"?s.month:"*"} *`},c=ns(m,r);return{schedule:l??c,runs:un(c,r,3),error:""}}catch(i){return{schedule:null,runs:[],error:i instanceof Error?i.message:String(i)}}}function Gs({value:t,botEngine:s,onChange:r}){const l=ss(),i=t.engine||s||l[0]?.engine||"",u=[...new Set([...s?[s]:[],...l.map(c=>c.engine),...i?[i]:[]])],m=l.find(c=>c.engine===i)?.resetsAt??null;return e.jsxs("div",{className:"space-y-2 text-[13px] text-ink","data-testid":"limit-reset-fields",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:n("routines.limitReset.engine")}),e.jsx(U,{"aria-label":n("routines.limitReset.engine"),value:i,onChange:c=>r({...t,engine:c.target.value}),children:u.map(c=>e.jsx("option",{value:c,children:as(c)},c))}),e.jsxs(U,{"aria-label":n("routines.limitReset.repeat"),value:t.repeat,onChange:c=>r({...t,engine:i,repeat:c.target.value}),children:[e.jsx("option",{value:"once",children:n("routines.limitReset.once")}),e.jsx("option",{value:"every_reset",children:n("routines.limitReset.every")})]})]}),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:m!==null&&m>Date.now()?n("routines.limitReset.next",{time:xn(m)}):n("routines.limitReset.unknown")})]})}function qs({cloudHome:t,local:s,plan:r,ready:l,offersAllowed:i}){return t?{kind:"cloud"}:s?{kind:"local",next:null}:{kind:"server"}}function Us(){const{state:t,dispatch:s}=nt(),r=Is(),l=rs()&&window.ogb?.remoteClient?.active!==!0,i=qs({cloudHome:t.config?.cloudHome===!0,local:l,plan:null,ready:r?.account?.machine?.status==="ready",offersAllowed:Un().source!=="file"}),u="text-left underline underline-offset-2 hover:text-ink",m=()=>{window.confirm(n("routines.scheduleNote.leave"))&&window.ogb?.cloudAccount?.connectHome().catch(()=>{})};return e.jsx("p",{"data-routine-schedule-note":i.kind==="local"?i.next??"local":i.kind,className:"text-[11px] leading-relaxed text-ink-secondary",children:i.kind==="cloud"?n("routines.scheduleNote.cloud"):i.kind==="server"?n("routines.scheduleNote.server"):e.jsxs(e.Fragment,{children:[n("routines.scheduleNote.local"),i.next==="add-cloud"&&e.jsxs(e.Fragment,{children:[" ",e.jsx("button",{type:"button",className:u,onClick:()=>s({type:"openCloudAdd",source:"app_routines"}),children:n("routines.scheduleNote.addCloud")})]}),i.next==="open-cloud"&&e.jsxs(e.Fragment,{children:[" ",n("routines.scheduleNote.openCloud")," ",e.jsx("button",{type:"button",className:u,onClick:m,children:n("cloudHome.connect")})]})]})})}const Xe="application/x-openmaus-bot",we="application/x-openmaus-calendar-event",Ys=t=>t.dataTransfer.types.includes(Xe)||t.dataTransfer.types.includes(we);function Zs(t){const s=t.dataTransfer.getData(Xe);if(s)return{botId:s};try{const r=JSON.parse(t.dataTransfer.getData(we));return(r.kind==="routine"||r.kind==="call")&&typeof r.id=="string"&&typeof r.at=="number"?{event:{kind:r.kind,id:r.id,at:r.at}}:null}catch{return null}}function Vs({marker:t,hourHeight:s,onDrop:r}){const[l,i]=x.useState(!1),u=new Date(t.at),m=n("limits.marker",{engine:t.name,time:xn(t.at,t.at)});return e.jsxs("div",{"data-limit-marker":t.engine,role:"note","aria-label":m,title:n("limits.markerDrop",{engine:t.name}),className:"absolute inset-x-0 z-[25] -translate-y-1/2 py-1.5",style:{top:(u.getHours()*60+u.getMinutes())/60*s},onPointerDown:c=>c.stopPropagation(),onDragOver:c=>{!r||!Ys(c)||(c.preventDefault(),c.stopPropagation(),c.dataTransfer.dropEffect="copy",i(!0))},onDragLeave:()=>i(!1),onDrop:c=>{c.preventDefault(),c.stopPropagation(),i(!1);const h=Zs(c);h&&r?.(h)},children:[e.jsx("div",{className:C("h-0 border-t-2 border-dashed",l?"border-accent":"border-warning/80")}),e.jsxs("span",{className:C("absolute left-1 top-0 flex max-w-[calc(100%-8px)] items-center gap-1 truncate rounded-full border px-1.5 py-0.5 text-[10px] font-medium shadow-sm",l?"border-accent bg-accent text-accent-ink":"border-warning/50 bg-panel text-ink"),children:[e.jsx(Rs,{size:10,className:"shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"truncate",children:m})]})]})}const G=64;function jn(t){return t==="running"?"working":t==="waiting"?"curious":t==="completed"?"proud":t==="failed"||t==="missed"?"sad":t==="cancelled"?"sleeping":"drowsy"}function Ks(t){return t>=44?"roomy":t>=22?"compact":"tiny"}function Js({item:t,bots:s,groups:r,compact:l,layout:i,selected:u=!1,onOpen:m,onResize:c}){const h=t.kind==="call",N=t.kind==="routine"?t.routine:null,o=t.kind==="routine"?t.run:null,S=!h&&(o?.target??N?.target)==="room-goal"?o?.groupId??N?.groupId:void 0,v=S?r.find(F=>F.id===S)??{name:n("routines.group")}:void 0,L=(h?t.call.botIds:[o?.botId??N?.botId??""]).flatMap(F=>s.find(y=>y.id===F)??[]),O=L[0],_=h?t.call.name:o?.routineName??N?.name??n("routines.event.automation"),B=h?"var(--color-accent)":O?Jn[O.color]:"var(--color-ink-tertiary)",E=!!(N&&!o&&!N.enabled),[z,d]=x.useState(t.durationMinutes);x.useEffect(()=>d(t.durationMinutes),[t.durationMinutes]);const b=o?.status,T=b==="failed"||b==="missed"||b==="waiting"||t.kind==="routine"&&!o&&t.needsYou===!0,P=o?jt(o):void 0,g=h||!!(N&&!o&&!E&&N.schedule.type!=="cron"),j=h?t.call.schedule:N?.schedule,I=!!(j&&j.type!=="once"),D=j?.type==="interval"?is(j.everyMinutes):null,M=Math.max(16,z/60*G),p=Ks(M),H=h?n(L.length===1?"routines.botCountOne":"routines.botCountMany",{count:L.length}):v?v.name:O?.name,w=[_,X(t.at),H,D,E?(N&&os(N))??n("routines.pausedSchedule"):P].filter(Boolean).join(" · "),R=N?.schedule.type==="cron"?n("routines.event.cronMoveHint"):"",Z=F=>{F.preventDefault(),F.stopPropagation();const y=F.clientY,de=z;let Q=de;const be=ve=>{Q=Math.max(ee,Math.min(240,Math.round((de+(ve.clientY-y)/G*60)/ee)*ee)),d(Q)},ce=()=>{if(document.removeEventListener("pointermove",be),document.removeEventListener("pointerup",ce),Q!==t.durationMinutes){if(I&&!window.confirm(n("routines.event.resizeSeries"))){d(t.durationMinutes);return}c(Q)}};document.addEventListener("pointermove",be),document.addEventListener("pointerup",ce,{once:!0})},te=!h&&e.jsx("span",{"data-event-status":E?"paused":T?"needs-you":"working",className:C("size-1.5 shrink-0 rounded-full",E?"bg-ink-tertiary":T?"bg-warning":"bg-success")}),le=F=>h?e.jsx(vt,{size:13,className:"mt-0.5 shrink-0"}):O?e.jsx(Ve,{bot:O,state:b?jn(b):E?"sleeping":"idle",size:F,animated:b==="running"||b==="waiting"}):null;return e.jsxs("button",{"data-event-card":!0,"data-event-fit":p,type:"button",draggable:g,title:R?`${w}
2
+ ${R}`:w,onDragStart:F=>{if(!g)return F.preventDefault();F.dataTransfer.effectAllowed="move",F.dataTransfer.setData(we,JSON.stringify({kind:t.kind,id:h?t.call.id:N.id,at:t.at}))},onClick:F=>{F.stopPropagation(),m()},"aria-pressed":u,"aria-label":`${_}, ${X(t.at)}${E?`, ${n("routines.pausedSchedule")}`:P?`, ${P}`:""}`,className:C("group absolute z-10 overflow-hidden rounded-md border border-l-[3px] text-left transition hover:z-20 focus:z-20 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent",p==="roomy"?"px-1.5 py-1":"px-1.5 py-0",E&&"border-dashed opacity-70",b==="cancelled"&&"opacity-55",(b==="failed"||b==="missed")&&(o&&kt(o)?"border-warning/60":"border-danger/60"),u&&"z-20 ring-2 ring-accent ring-offset-1 ring-offset-app"),style:{left:`calc(${i.column/i.columns*100}% + 2px)`,width:`calc(${100/i.columns}% - 4px)`,top:`${(new Date(t.at).getHours()*60+new Date(t.at).getMinutes())/60*G}px`,height:`${M}px`,background:`color-mix(in srgb, ${B} ${E?6:16}%, var(--color-card))`,borderColor:`color-mix(in srgb, ${B} 40%, transparent)`,borderLeftColor:B,color:`color-mix(in srgb, ${B} 55%, var(--color-ink))`},children:[p==="roomy"?e.jsxs("div",{className:"flex min-w-0 items-start gap-1.5",children:[le(l?18:22),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[11px] font-semibold leading-tight",children:_}),e.jsxs("div",{className:"mt-0.5 flex min-w-0 items-center gap-1 text-[10px] opacity-80",children:[te,e.jsxs("span",{className:"truncate",children:[X(t.at)," · ",D&&!v&&!h?`${H??""} · ${D}`:H]})]})]}),L.length>1&&e.jsxs("span",{className:"rounded bg-inset/60 px-1 py-0.5 text-[8px]",children:["+",L.length-1]})]}):p==="compact"?e.jsxs("div",{className:"flex h-full min-w-0 items-center gap-1",children:[h&&e.jsx(vt,{size:11,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-semibold leading-none",children:_}),te,e.jsx("span",{className:"shrink-0 text-[10px] leading-none tabular-nums opacity-80",children:X(t.at)})]}):e.jsx("div",{className:"flex h-full min-w-0 items-center truncate text-[10px] font-semibold leading-none",children:_}),h&&e.jsx("div",{onPointerDown:Z,className:"absolute inset-x-1 bottom-0 h-1.5 cursor-ns-resize rounded-full opacity-0 transition group-hover:opacity-100","aria-label":n("routines.event.resize"),children:e.jsx("div",{className:"mx-auto mt-0.5 h-0.5 w-5 rounded-full bg-current opacity-50"})})]})}const ft=[0,1,2,3,4,5,6],et=[1,2,3,4,5],mt=[5,10,15,30,60],an=Array.from({length:240/ee},(t,s)=>(s+1)*ee);function kn(t,s){return t?t.memberIds.flatMap(r=>{const l=s.find(i=>i.id===r);return l&&!l.hidden?[l]:[]}):s.filter(r=>!r.hidden)}function Qs(t){return t.dm?!1:!(Object.prototype.hasOwnProperty.call(t,"setupCompletedAt")||Object.prototype.hasOwnProperty.call(t,"setupSkippedAt"))||t.setupCompletedAt!=null||t.setupSkippedAt!=null||(t.messages?.length??0)>0}function rn(t,s,r){const l=kn(t,s),i=t?.defaultResponder.kind==="member"?t.defaultResponder.botId:void 0;return l.find(u=>u.id===r)??l.find(u=>u.id===i)??l.find(u=>u.chiefOfStaff)??l[0]}function on(){const t=new Date(Date.now()+36e5);return t.setMinutes(0,0,0),t.getTime()}function Xs(t,s){return!!(t&&t.length===s.length&&t.every((r,l)=>r===s[l]))}function ea(t){return t.type!=="interval"||!t.weekdays||t.weekdays.length===7?"every-day":Xs(t.weekdays,et)?"weekdays":"custom"}function ta(t){const s=new Date(`${t}T00:00`);return s.setHours(23,59,59,999),s.getTime()}function na(t,s){return t.type==="once"?"none":t.type==="limit_reset"?"limit_reset":t.type==="interval"?"interval":t.type==="cron"?Fs(t):t.weekdays.length===7?"daily":t.weekdays.join(",")==="1,2,3,4,5"?"weekdays":t.weekdays.length===1&&t.weekdays[0]===new Date(s).getDay()?"weekly":"custom"}function Nn(t,s,r){if(t==="none")return{type:"once",at:s};const l=t==="daily"?ft:t==="weekdays"?et:t==="weekly"?[new Date(s).getDay()]:r;return{type:"daily",time:pn(s),weekdays:[...l].sort()}}function sa(t,s,r,l,i){return t==="interval"?{type:"interval",everyMinutes:l,...i}:Nn(t,s,r)}function wn({attachments:t,onRemove:s}){return t.length?e.jsx("div",{className:"flex flex-wrap gap-2",children:t.map(r=>e.jsxs("div",{className:"flex max-w-[260px] items-center gap-2 rounded-lg border border-hairline/50 bg-inset px-2.5 py-2 text-[12px] text-ink",children:[e.jsx(st,{size:14,className:"shrink-0 text-accent"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:r.name}),s&&e.jsx("button",{type:"button",onClick:()=>s(r.id),className:"rounded p-0.5 text-ink-secondary hover:bg-raised hover:text-ink","aria-label":n("routines.attachment.remove",{name:r.name}),children:e.jsx(ze,{size:12})})]},r.id))}):null}function yt({bots:t,selected:s,multiple:r,locked:l,onChange:i}){const[u,m]=x.useState(""),c=t.filter(h=>`${h.name} ${h.title}`.toLowerCase().includes(u.toLowerCase()));return e.jsxs("div",{className:"rounded-xl border border-hairline/50 bg-inset/60 p-2",children:[!l&&t.length>5&&e.jsxs("label",{className:"mb-2 flex items-center gap-2 rounded-lg border border-transparent bg-panel px-2.5 py-2 text-ink-secondary focus-within:border-focus",children:[e.jsx(Yn,{size:14}),e.jsx("input",{value:u,onChange:h=>m(h.target.value),placeholder:n("routines.findBot"),className:"min-w-0 flex-1 bg-transparent text-[12px] text-ink outline-none placeholder:text-ink-tertiary"})]}),e.jsx("div",{className:"grid max-h-48 grid-cols-1 gap-1 overflow-y-auto sm:grid-cols-2",children:c.map(h=>{const N=s.includes(h.id);return e.jsxs("button",{type:"button",disabled:l,onClick:()=>i(r?N?s.filter(o=>o!==h.id):[...s,h.id]:[h.id]),className:C("flex min-w-0 items-center gap-2 rounded-lg px-2 py-2 text-left transition",N?"bg-accent/12 ring-1 ring-accent/50":"hover:bg-raised",l&&"cursor-default"),children:[e.jsx(Ve,{bot:h,state:N?"happy":"idle",size:32,animated:!1}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-medium text-ink",children:h.name}),N&&e.jsx(gn,{size:14,className:"shrink-0 text-accent"})]},h.id)})})]})}function aa(t){return t.flatMap(s=>s.kind==="paste"||s.kind==="citation"?[]:[{id:s.id,kind:s.kind,name:s.name,path:s.path,size:s.size}])}function ra({seed:t,bots:s,lockedBotId:r,defaultRunOn:l,routinesOnly:i=!1,plain:u=!1,onClose:m,onSavedCall:c}){const{state:h,dispatch:N}=nt(),o=t.routine,{request:$}=ls(),S=t.call,[v,K]=x.useState(i?"routine":t.kind),[L]=x.useState(()=>Date.now()),[O,_]=x.useState(o?.name??S?.name??t.name??""),[B,E]=x.useState(o?.prompt??S?.description??t.description??""),z=o?.schedule.type==="once"?o.schedule.at:o?.schedule.type==="daily"?ht(t.at,o.schedule.time):o?.schedule.type==="interval"?o.schedule.anchorAt:S?.schedule.type==="once"?S.schedule.at:S?.schedule.type==="daily"?ht(t.at,S.schedule.time):t.at,d=o?.schedule??S?.schedule??{type:"once",at:z},[b,T]=x.useState(qe(z)),[P,g]=x.useState(pn(z)),[j,I]=x.useState(o?.durationMinutes??S?.durationMinutes??t.durationMinutes),[D,M]=x.useState(o?.timeoutMinutes??null),[p,H]=x.useState(!!o),[w,R]=x.useState(o?.overlap??"skip"),[Z,te]=x.useState(!!o?.continuity),[le,F]=x.useState(!!o?.runOnStartup),[y,de]=x.useState(t.limitReset?"limit_reset":na(d,z)),[Q,be]=x.useState(d.type==="limit_reset"?d:{engine:t.limitReset?.engine??"",repeat:"once"}),[ce,ve]=x.useState(()=>Bs(d.type==="cron"?d:void 0,z)),[at,Ae]=x.useState(!1),[fe,Oe]=x.useState(d.type==="daily"?d.weekdays:[new Date(z).getDay()]),[q,Se]=x.useState(d.type==="interval"?d.everyMinutes:15),[ne,rt]=x.useState(()=>ea(d)),[f,J]=x.useState(()=>d.type==="interval"&&d.weekdays?.length?d.weekdays:[...ft]),[pe,se]=x.useState(d.type==="interval"&&d.window?"custom":"all-day"),[Ee,Sn]=x.useState(d.type==="interval"?d.window?.start??"09:00":"09:00"),[Pe,Cn]=x.useState(d.type==="interval"?d.window?.end??"17:00":"17:00"),[He,In]=x.useState(d.type==="interval"&&d.endsAt!=null?"on-date":"never"),[wt,Dn]=x.useState(()=>d.type==="interval"&&d.endsAt!=null?qe(d.endsAt):qe(mn(Ye(Math.max(Date.now(),z)),7))),[W,St]=x.useState(r?[r]:o?[o.botId]:S?.botIds??t.botIds),[it,Ct]=x.useState(()=>(o?o.resultsThreadId:t.resultsThreadId??Qe(h,W[0]))??null),$e=a=>{a[0]!==W[0]&&Ct(Qe(h,a[0])??null),St(a)},[V,Tn]=x.useState(o?.target??"bot"),[me,ot]=x.useState(o?.groupId??""),[ye,_e]=x.useState(o?.runOn??l??"maus"),[Ce,lt]=x.useState(o?.target==="room-goal"?[]:o?.attachments??S?.attachments??[]),[It,Dt]=x.useState(!1),[Tt,Rt]=x.useState(""),[zt,Mt]=x.useState(""),[Rn,Lt]=x.useState(0),Fe=Rn>0,At=x.useRef(null),zn=!!(h.config?.box.configured&&W.length>0&&W.every(a=>Vn(h.instances,s.find(k=>k.id===a)?.modelSelection.instanceId)?.snapshot.state==="available")),Be=h.groups.filter(Qs),ue=Be.find(a=>a.id===me),dt=ue?kn(ue,h.bots):s,ae=v==="routine"&&V==="room-goal",Ot=h.config?.cloudHome===!0,We=ut(b,P,o||S?z:void 0),Mn=We+j*6e4,Ie=W.flatMap(a=>s.find(k=>k.id===a)??[]),Et=x.useRef(null),De=y==="interval"&&(!Number.isInteger(q)||q<5||q>1440),je=y==="interval"&&ne==="custom"&&f.length===0,Pt=ut("2000-01-01",Pe)-ut("2000-01-01",Ee),re=y==="interval"&&pe==="custom"&&(!Ee||!Pe||!Number.isFinite(Pt)||Pt<q*6e4),ct=o?.schedule.type==="interval"?o.schedule:void 0,Ht=Xt(L,Math.max(5,q||5),ct),ke=He==="on-date"?ta(wt):null,he=y==="interval"&&He==="on-date"&&(ke==null||!Number.isSafeInteger(ke)||ke<Ht),$t=ne==="every-day"?void 0:ne==="weekdays"?et:f,Ln=pe==="custom"?{start:Ee,end:Pe}:void 0,xe=ge(y)?Ws(y,ce,L,!at&&d.type==="cron"?d:void 0):null,_t=a=>{a==="interval"&&!p&&(M(k=>k??30),H(!0)),ge(a)&&(a==="cron"&&xe?.schedule&&ve(k=>({...k,expression:xe.schedule.expression})),Ae(!0)),de(a)},An=a=>{a==="custom"&&ne!=="custom"&&J(ne==="weekdays"?[...et]:[...ft]),rt(a)},Ft=a=>{if(Tn(a),a==="bot"){ot("");return}_e("maus"),lt([]),Mt("");const k=ue??Be[0];ot(k?.id??"");const A=rn(k,h.bots,W[0]);$e(A?[A.id]:[])},On=a=>{const k=Be.find(ie=>ie.id===a);ot(a);const A=rn(k,h.bots,W[0]);$e(A?[A.id]:[])},En=async a=>{if(!(!a?.length||ae)){Lt(k=>k+1);try{const k=await cs(Array.from(a),{allowImages:!0,getPath:xs,uploadImage:us}),A=aa(k.attachments);A.length&&(lt(ie=>[...ie,...A].slice(0,20)),ye==="cloud"&&_e("maus")),k.notice&&Mt(k.notice)}finally{Lt(k=>Math.max(0,k-1))}}},Pn=async()=>{if(!Fe){Dt(!0),Rt("");try{if(v==="routine"||i){const a=Date.now(),k=ps(a,q,ct);if(y==="interval"&&ke!=null&&ke<Xt(a,q,ct))throw new Error(n("routines.interval.endAfterFirstRun"));const A=Q.engine||s.find(qn=>qn.id===(r??W[0]))?.modelSelection?.instanceId||"",ie=y==="limit_reset"?{type:"limit_reset",engine:A,repeat:Q.repeat}:ge(y)?xe?.schedule:sa(y,We,fe,q,{anchorAt:k,weekdays:$t?[...$t].sort():null,window:Ln??null,endsAt:ke});if(!ie)throw new Error(xe?.error||n("routines.error.invalidSchedule"));const Wn={name:O,prompt:B,target:V,botId:r??W[0]??"",groupId:V==="room-goal"&&me?me:null,runOn:V==="room-goal"?"maus":ye,enabled:o&&(o.enabled||!ms(o,a))?void 0:!0,schedule:ie,durationMinutes:j,timeoutMinutes:D,overlap:w,continuity:V==="bot"&&y!=="none"&&Z,runOnStartup:y!=="none"&&le,attachments:V==="room-goal"?[]:Ce,...V==="bot"?{resultsThreadId:it}:{}},Gn=await $(o?`/api/routines/${o.id}`:"/api/routines",{method:o?"PATCH":"POST",body:JSON.stringify(Wn)});N({type:"routinePatched",routine:Gn.routine})}else{if(y==="interval"||y==="limit_reset"||ge(y))throw new Error(n("routines.error.callSchedule"));const a=Nn(y,We,fe),k={name:O,description:B,botIds:W,schedule:a,durationMinutes:j,attachments:Ce},A=await Ne(S?`/api/calendar-calls/${S.id}`:"/api/calendar-calls",{method:S?"PATCH":"POST",body:JSON.stringify(k)});c(A.call)}m()}catch(a){Rt(a instanceof Error?a.message:String(a))}finally{Dt(!1)}}},Hn=!!(O.trim()&&(v==="call"||B.trim())&&(!r||W[0]===r)&&(v==="call"?W.length>0:V==="room-goal"?(!me||ue)&&W[0]&&dt.some(a=>a.id===W[0]):W.length>0)&&!De&&!je&&!re&&!he&&!xe?.error),$n=!i&&!o&&!S&&!r,Y=ln()&&!u,[Ge,_n]=x.useState(()=>!["none","daily","weekdays","weekly"].includes(y)||V==="room-goal"||Ce.length>0||ye==="cloud"||D!=null||le||w==="queue");Qn(Et,m);const Bt=$n&&e.jsxs("div",{className:C(Y&&"ml-10","inline-flex rounded-lg bg-inset p-1"),children:[e.jsx("button",{type:"button",onClick:()=>{K("routine"),St(a=>a.slice(0,1))},className:C("rounded-md px-4 py-1.5 text-[13px] font-medium",v==="routine"?"bg-raised text-ink shadow":"text-ink-secondary"),children:n("routines.kind.routine")}),e.jsx("button",{type:"button",onClick:()=>{K("call"),(y==="interval"||y==="limit_reset"||ge(y))&&de("none")},className:C("rounded-md px-4 py-1.5 text-[13px] font-medium",v==="call"?"bg-raised text-ink shadow":"text-ink-secondary"),children:n("routines.kind.call")})]}),Wt=v==="routine"&&!r&&e.jsxs("div",{className:C(Y&&"ml-10"),children:[e.jsx("div",{className:"mb-2 text-[11px] font-medium uppercase tracking-wider text-ink-secondary",children:n("routines.editor.type")}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("button",{type:"button",onClick:()=>Ft("bot"),className:C("flex items-start gap-3 rounded-xl border p-3 text-left transition",V==="bot"?"border-accent/60 bg-accent/10":"border-hairline/50 bg-inset hover:bg-raised"),children:[e.jsx(bt,{size:17,className:C("mt-0.5 shrink-0",V==="bot"?"text-accent":"text-ink-secondary")}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-[13px] font-medium text-ink",children:n("routines.editor.botTask")}),e.jsx("span",{className:"mt-1 block text-[11px] leading-relaxed text-ink-secondary",children:n("routines.editor.botTaskHelp")})]})]}),e.jsxs("button",{type:"button",onClick:()=>Ft("room-goal"),className:C("flex items-start gap-3 rounded-xl border p-3 text-left transition",V==="room-goal"?"border-accent/60 bg-accent/10":"border-hairline/50 bg-inset hover:bg-raised"),children:[e.jsx(en,{size:17,className:C("mt-0.5 shrink-0",V==="room-goal"?"text-accent":"text-ink-secondary")}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-[13px] font-medium text-ink",children:n("routines.editor.teamGoal")}),e.jsx("span",{className:"mt-1 block text-[11px] leading-relaxed text-ink-secondary",children:n("routines.editor.teamGoalHelp")})]})]})]})]}),Gt=y!=="interval"&&y!=="limit_reset"&&!ge(y)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[v==="routine"&&y==="none"&&e.jsx("span",{className:"text-[12px] font-medium text-ink-secondary",children:n("routines.editor.starts")}),v==="routine"&&y==="weekly"&&e.jsx("span",{className:"text-[12px] font-medium text-ink-secondary",children:n("routines.editor.on")}),(v==="call"||y==="none"||y==="weekly")&&e.jsx("input",{type:"date",value:b,onChange:a=>T(a.target.value),className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent [color-scheme:dark]"}),e.jsx("input",{type:"time",step:ee*60,value:P,onChange:a=>g(a.target.value),className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent [color-scheme:dark]"}),v==="call"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[12px] text-ink-secondary",children:n("routines.editor.to")}),e.jsx("span",{className:"rounded-lg border border-hairline/40 bg-inset/60 px-3 py-2 text-[13px] text-ink",children:X(Mn)}),e.jsx(U,{"aria-label":n("routines.editor.callDuration"),value:j,onChange:a=>I(Number(a.target.value)),children:an.map(a=>e.jsx("option",{value:a,children:Re(a)},a))})]})]}),qt=e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Ms,{size:14,className:"text-ink-secondary"}),e.jsxs(U,{"aria-label":n("routines.editor.repeat"),value:y,onChange:a=>_t(a.target.value),children:[e.jsx("option",{value:"none",children:n("routines.repeat.none")}),v==="routine"&&e.jsx("option",{value:"interval",children:n("routines.repeat.interval")}),e.jsx("option",{value:"daily",children:n("routines.repeat.dailyOption")}),e.jsx("option",{value:"weekdays",children:n("routines.repeat.weekdaysOption")}),e.jsx("option",{value:"weekly",children:n("routines.schedule.weeklyOn",{day:Ze(new Date(We).getDay())})}),e.jsx("option",{value:"custom",children:n("routines.repeat.selectedWeekdays")}),v==="routine"&&e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"monthly",children:n("routines.repeat.monthly")}),e.jsx("option",{value:"yearly",children:n("routines.repeat.yearly")}),e.jsx("option",{value:"cron",children:n("routines.repeat.customCron")})]}),v==="routine"&&e.jsx("option",{value:"limit_reset",children:n("routines.limitReset.option")})]})]}),Ut=v==="routine"&&e.jsx(Us,{}),Yt=e.jsxs(e.Fragment,{children:[y==="limit_reset"&&v==="routine"&&e.jsx(Gs,{value:Q,botEngine:s.find(a=>a.id===(r??W[0]))?.modelSelection?.instanceId,onChange:be}),ge(y)&&v==="routine"&&xe&&e.jsx(_s,{choice:y,value:ce,onChange:a=>{ve(a),Ae(!0)},runs:xe.runs,error:xe.error}),y==="custom"&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:tn.map((a,k)=>e.jsx("button",{type:"button",onClick:()=>Oe(A=>A.includes(k)?A.length===1?A:A.filter(ie=>ie!==k):[...A,k].sort()),className:C("size-8 rounded-full text-[10px] font-semibold",fe.includes(k)?"bg-accent text-white":"bg-inset text-ink-secondary hover:bg-raised hover:text-ink"),children:Ze(k).charAt(0).toLocaleUpperCase(Le())},a))}),y==="interval"&&v==="routine"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[13px] text-ink",children:[e.jsx("span",{className:"font-medium",children:n("routines.interval.runsEvery")}),e.jsxs(U,{value:mt.includes(q)?String(q):"custom",onChange:a=>Se(a.target.value==="custom"?0:Number(a.target.value)),"aria-label":n("routines.interval.howOften"),children:[mt.map(a=>e.jsx("option",{value:a,children:a},a)),e.jsx("option",{value:"custom",children:n("routines.interval.custom")})]}),!mt.includes(q)&&e.jsx("input",{type:"number",min:5,max:1440,step:1,value:q||"",onChange:a=>Se(Number(a.target.value)),"aria-label":n("routines.interval.customMinutes"),"aria-invalid":De,"aria-describedby":De?"routine-interval-error":"routine-interval-help",autoFocus:!0,className:C("w-20 rounded-lg border bg-inset px-3 py-2 text-[13px] tabular-nums text-ink outline-none focus:border-accent",De?"border-danger/70":"border-hairline/50")}),e.jsx("span",{children:n("routines.interval.minutesUnit")})]}),e.jsxs("div",{className:"grid items-center gap-2 text-[13px] text-ink sm:flex sm:flex-wrap",children:[e.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[e.jsx("span",{className:"font-medium",children:n("routines.interval.on")}),e.jsxs(U,{value:ne,onChange:a=>An(a.target.value),"aria-label":n("routines.interval.daysLabel"),"aria-invalid":je,"aria-describedby":je?"routine-interval-days-error":void 0,children:[e.jsx("option",{value:"every-day",children:n("routines.repeat.daily")}),e.jsx("option",{value:"weekdays",children:n("routines.repeat.weekdays")}),e.jsx("option",{value:"custom",children:n("routines.interval.custom")})]})]}),e.jsx("span",{"aria-hidden":"true",className:"hidden text-ink-secondary sm:inline",children:"·"}),e.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[e.jsx("span",{className:"font-medium",children:n("routines.interval.during")}),e.jsxs(U,{value:pe,onChange:a=>se(a.target.value),"aria-label":n("routines.interval.hoursLabel"),"aria-invalid":re,"aria-describedby":re?"routine-interval-window-error":void 0,children:[e.jsx("option",{value:"all-day",children:n("routines.interval.allDay")}),e.jsx("option",{value:"custom",children:n("routines.interval.customHours")})]})]}),e.jsx("span",{"aria-hidden":"true",className:"hidden text-ink-secondary sm:inline",children:"·"}),e.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[e.jsx("span",{className:"font-medium",children:n("routines.interval.ends")}),e.jsxs(U,{value:He,onChange:a=>In(a.target.value),"aria-label":n("routines.interval.endsLabel"),"aria-invalid":he,"aria-describedby":he?"routine-interval-end-error":void 0,children:[e.jsx("option",{value:"never",children:n("routines.interval.never")}),e.jsx("option",{value:"on-date",children:n("routines.interval.onDate")})]})]})]}),ne==="custom"&&e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[11px] font-medium text-ink-secondary",children:n("routines.interval.chooseDays")}),e.jsx("div",{role:"group","aria-label":n("routines.interval.customDays"),"aria-invalid":je,"aria-describedby":je?"routine-interval-days-error":void 0,className:"flex flex-wrap gap-1.5",children:tn.map((a,k)=>e.jsx("button",{type:"button",onClick:()=>J(A=>A.includes(k)?A.filter(ie=>ie!==k):[...A,k].sort()),"aria-label":n(f.includes(k)?"routines.interval.daySelected":"routines.interval.dayNotSelected",{day:Ze(k)}),"aria-pressed":f.includes(k),className:C("size-8 rounded-full text-[10px] font-semibold",f.includes(k)?"bg-accent text-white":"bg-inset text-ink-secondary hover:bg-raised hover:text-ink"),children:n("routines.interval.dayChips").split(" ")[k]},a))})]}),pe==="custom"&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[12px] text-ink",children:[e.jsx("span",{className:"font-medium text-ink-secondary",children:n("routines.interval.runBetween")}),e.jsx("input",{"aria-label":n("routines.interval.windowStart"),"aria-invalid":re,"aria-describedby":re?"routine-interval-window-error":void 0,type:"time",step:ee*60,value:Ee,onChange:a=>Sn(a.target.value),className:C("rounded-lg border bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent [color-scheme:dark]",re?"border-danger/70":"border-hairline/50")}),e.jsx("span",{className:"text-ink-secondary",children:n("routines.interval.and")}),e.jsx("input",{"aria-label":n("routines.interval.windowEnd"),"aria-invalid":re,"aria-describedby":re?"routine-interval-window-error":void 0,type:"time",step:ee*60,value:Pe,onChange:a=>Cn(a.target.value),className:C("rounded-lg border bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent [color-scheme:dark]",re?"border-danger/70":"border-hairline/50")})]}),He==="on-date"&&e.jsxs("label",{className:"flex flex-wrap items-center gap-2 text-[12px] text-ink",children:[e.jsx("span",{className:"font-medium text-ink-secondary",children:n("routines.interval.stopAfter")}),e.jsx("input",{"aria-label":n("routines.interval.endDate"),"aria-invalid":he,"aria-describedby":he?"routine-interval-end-error":void 0,type:"date",min:qe(Ht),value:wt,onChange:a=>Dn(a.target.value),className:C("rounded-lg border bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent [color-scheme:dark]",he?"border-danger/70":"border-hairline/50")})]}),De&&e.jsx("div",{id:"routine-interval-error",className:"text-[11px] text-danger",children:n("routines.interval.invalidMinutes")}),je&&e.jsx("div",{id:"routine-interval-days-error",className:"text-[11px] text-danger",children:n("routines.interval.invalidDays")}),re&&e.jsx("div",{id:"routine-interval-window-error",className:"text-[11px] text-danger",children:n("routines.interval.invalidWindow",{minutes:q||5})}),he&&e.jsx("div",{id:"routine-interval-end-error",className:"text-[11px] text-danger",children:n("routines.interval.endAfterFirstRun")}),e.jsx("div",{id:"routine-interval-help",className:"text-[11px] leading-relaxed text-ink-secondary",children:n(w==="queue"?"routines.overlapQueueHelp":"routines.overlapSkipHelp")})]})]}),Zt=v==="routine"&&e.jsxs("details",{className:"rounded-xl border border-hairline/40 bg-inset/40 px-3 py-2.5",children:[e.jsx("summary",{className:"cursor-pointer select-none text-[12px] font-medium text-ink-secondary hover:text-ink",children:D==null?n("routines.runLimit.none"):n("routines.runLimit.some",{duration:Re(D)})}),e.jsxs("div",{className:"mt-3 border-t border-hairline/35 pt-3",children:[e.jsxs("label",{className:"flex flex-wrap items-center gap-2 text-[12px] text-ink",children:[e.jsx("span",{children:n("routines.runLimit.stopAfter")}),e.jsxs(U,{"aria-label":n("routines.runLimit.label"),value:D??"",onChange:a=>M(a.target.value?Number(a.target.value):null),children:[e.jsx("option",{value:"",children:n("routines.runLimit.noLimit")}),an.map(a=>e.jsx("option",{value:a,children:Re(a)},a))]})]}),e.jsx("div",{className:"mt-1.5 text-[11px] leading-relaxed text-ink-secondary",children:n("routines.runLimit.help")}),y!=="none"&&e.jsxs("div",{className:"mt-3",children:[e.jsxs("label",{className:"flex flex-wrap items-center gap-2 text-[12px] text-ink",children:[e.jsx("span",{children:n("routines.overlapLabel")}),e.jsxs(U,{"aria-label":n("routines.overlapLabel"),value:w,onChange:a=>R(a.target.value==="queue"?"queue":"skip"),children:[e.jsx("option",{value:"skip",children:n("routines.overlapSkip")}),e.jsx("option",{value:"queue",children:n("routines.overlapQueue")})]})]}),e.jsx("p",{className:"mt-1.5 text-[11px] leading-relaxed text-ink-secondary",children:n(w==="queue"?"routines.overlapQueueHelp":"routines.overlapSkipHelp")})]}),y!=="none"&&e.jsxs("label",{className:"mt-3 flex items-start gap-2 text-[12px] text-ink",children:[e.jsx("input",{type:"checkbox","aria-label":n("routines.runOnStartupLabel"),checked:le,onChange:a=>F(a.target.checked),className:"mt-0.5 accent-accent"}),e.jsxs("span",{children:[e.jsx("span",{className:"block",children:n("routines.runOnStartupLabel")}),e.jsx("span",{className:"mt-1 block text-[11px] leading-relaxed text-ink-secondary",children:n("routines.runOnStartupHelp")})]})]})]})]}),Fn=v==="routine"&&!ae&&y!=="none"&&e.jsxs("label",{className:C("flex items-start gap-3 rounded-xl border border-hairline/40 bg-inset/40 px-3.5 py-3",Y&&"ml-8"),children:[e.jsx("input",{type:"checkbox","aria-label":n("routines.continuityLabel"),checked:Z,onChange:a=>te(a.target.checked),className:"mt-0.5 accent-accent"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-[13px] font-medium text-ink",children:n("routines.continuityLabel")}),e.jsx("span",{className:"mt-1 block text-[11px] leading-relaxed text-ink-secondary",children:n("routines.continuityHelp")})]})]}),Vt=v==="routine"&&!ae&&e.jsx("div",{className:C(Y&&"ml-8"),children:e.jsx(vn,{bot:s.find(a=>a.id===W[0]),value:it,allowCurrent:!!o,onChange:Ct})}),Kt=e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(ds,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),ae?e.jsxs("div",{className:"min-w-0 flex-1 rounded-xl border border-hairline/50 bg-inset px-3.5 py-3",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:n("routines.editor.groupContext")}),e.jsx("div",{className:"mt-1 text-[11px] leading-relaxed text-ink-secondary",children:n("routines.editor.teamGoalAttachments")})]}):e.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[e.jsx("input",{ref:At,type:"file",multiple:!0,className:"hidden",onChange:a=>{En(a.target.files),a.target.value=""}}),e.jsx("button",{type:"button",onClick:()=>At.current?.click(),className:"rounded-lg border border-hairline/50 px-3 py-2 text-[13px] font-medium text-ink hover:bg-raised",children:n("routines.attachment.add")}),e.jsx(wn,{attachments:Ce,onRemove:a=>lt(k=>k.filter(A=>A.id!==a))}),e.jsx("div",{className:"text-[11px] leading-relaxed text-ink-secondary",children:v==="routine"?n("routines.attachment.routineHelp"):Ie.length>1?n("routines.attachment.callSharedHelp"):n("routines.attachment.callKeptHelp")}),zt&&e.jsx("div",{className:"text-[12px] text-warning",children:zt})]})]}),Jt=v==="routine"&&e.jsxs("div",{className:"flex items-start gap-4",children:[ae?e.jsx(en,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}):ye==="cloud"?e.jsx(dn,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}):e.jsx(cn,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsx("div",{className:"min-w-0 flex-1",children:ae?e.jsxs("div",{className:"rounded-xl border border-accent/35 bg-accent/[0.07] p-3",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:n(Ot?"routines.editor.goalRunsOnCloud":"routines.editor.goalRunsOnComputer")}),e.jsx("div",{className:"mt-1 text-[11px] leading-relaxed text-ink-secondary",children:n("routines.editor.roomGoalKept")})]}):e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>_e("maus"),className:C("rounded-xl border p-3 text-left",ye==="maus"?"border-accent/60 bg-accent/10":"border-hairline/50 bg-inset hover:bg-raised"),children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:n("routines.editor.currentSetup")}),e.jsx("div",{className:"mt-1 text-[11px] text-ink-secondary",children:"Keeps its model and configured computer, including a self-hosted VPS."})]}),e.jsxs("button",{type:"button",disabled:!zn||Ce.length>0,onClick:()=>_e("cloud"),className:C("rounded-xl border p-3 text-left disabled:cursor-not-allowed disabled:opacity-45",ye==="cloud"?"border-accent/60 bg-accent/10":"border-hairline/50 bg-inset hover:bg-raised"),children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:n("routines.runsOn.boat")}),e.jsx("div",{className:"mt-1 text-[11px] text-ink-secondary",children:n(Ot?"routines.runsOn.boatHintCloudHome":"routines.runsOn.boatHint")})]})]})})]}),Bn=!Y&&v==="routine"?n(u?o?"automations.editor.edit":"automations.editor.new":o?"routines.editor.edit":"routines.editor.new"):n(o||S?"routines.event.edit":"routines.event.new"),Qt=[["none","routines.repeat.once"],["daily","routines.repeat.daily"],["weekdays","routines.repeat.weekdays"],["weekly","routines.repeat.weekly"]];return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/65 p-3",onMouseDown:a=>a.target===a.currentTarget&&m(),children:e.jsxs("div",{ref:Et,role:"dialog","aria-modal":"true","aria-label":n(o||S?"routines.event.editLabel":"routines.event.createLabel"),tabIndex:-1,className:"max-h-[94vh] w-full max-w-[760px] overflow-y-auto rounded-2xl border border-hairline/60 bg-panel shadow-2xl",children:[e.jsxs("div",{className:"sticky top-0 z-20 flex items-center justify-between border-b border-hairline/40 bg-panel/95 px-5 py-3.5 backdrop-blur",children:[e.jsx("div",{className:"text-[15px] font-semibold text-ink",children:Bn}),e.jsx("button",{onClick:m,className:"rounded-full p-2 text-ink-secondary hover:bg-raised hover:text-ink","aria-label":n("common.close"),children:e.jsx(ze,{size:18})})]}),e.jsxs("div",{className:"space-y-5 px-5 py-5 sm:px-8",children:[Y&&Bt,Y&&Wt,e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("span",{className:"mt-3 size-4 shrink-0 rounded bg-accent"}),e.jsx("input",{autoFocus:!0,value:O,onChange:a=>_(a.target.value),"aria-label":n("routines.editor.titleLabel"),placeholder:v==="routine"?Y?n("routines.event.addTitle"):n("routines.editor.titlePlaceholder"):n("routines.event.addCallTitle"),className:"min-w-0 flex-1 border-b border-hairline/60 bg-transparent px-1 pb-2 text-[22px] font-medium text-ink outline-none placeholder:text-ink-tertiary focus:border-accent"})]}),Y?e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(gt,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-3",children:[Gt,qt,Ut,Yt,Zt]})]}):e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(gt,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-3",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:n("routines.editor.when")}),Gt,e.jsx("div",{role:"group","aria-label":n("routines.editor.repeat"),className:"flex flex-wrap gap-1.5",children:Qt.map(([a,k])=>e.jsx("button",{type:"button","aria-pressed":y===a,onClick:()=>_t(a),className:C("rounded-full border px-3 py-1.5 text-[12px] font-medium transition",y===a?"border-accent-border bg-accent/15 text-accent-text":"border-hairline/50 bg-inset text-ink-secondary hover:bg-raised hover:text-ink"),children:n(k)},a))}),!Qt.some(([a])=>a===y)&&e.jsx("div",{className:"text-[12px] text-ink-secondary",children:n("routines.editor.customRepeat")})]})]}),e.jsxs("div",{className:"flex items-start gap-4",children:[ae?e.jsx(hn,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}):e.jsx(bt,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsx("div",{className:"min-w-0 flex-1",children:ae?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"routine-goal-room",className:"mb-2 block text-[13px] font-medium text-ink",children:n("routines.editor.goalWhere")}),e.jsxs(U,{id:"routine-goal-room",value:me,onChange:a=>On(a.target.value),className:"w-full",children:[me&&!ue&&e.jsx("option",{value:me,disabled:!0,children:n("routines.editor.roomMissing")}),e.jsx("option",{value:"",children:n("routines.editor.goalOneOnOne")}),Be.map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[13px] font-medium text-ink",children:ue?n("routines.goal.chooseLead"):n("routines.editor.who")}),dt.length>0?e.jsxs(e.Fragment,{children:[e.jsx(yt,{bots:dt,selected:W,multiple:!1,onChange:$e}),e.jsx("div",{className:"mt-2 text-[12px] text-ink-secondary",children:ue?n("routines.goal.leadHelp",{name:ue.name}):n("routines.editor.goalOneOnOneHelp")})]}):e.jsx("div",{className:"rounded-xl border border-warning/30 bg-warning/10 px-3.5 py-3 text-[12px] text-warning",children:n("routines.goal.noMembers")})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mb-2 text-[13px] font-medium text-ink",children:v==="routine"?Y?n("routines.event.assignBot"):n("routines.editor.who"):n("routines.event.addGuests")}),s.length>0?e.jsxs(e.Fragment,{children:[e.jsx(yt,{bots:s,selected:W,multiple:v==="call",locked:!!r,onChange:$e}),e.jsx("div",{className:"mt-2 text-[12px] text-ink-secondary",children:v==="routine"?n("routines.event.botOwnsRuns"):n(Ie.length===0?"routines.event.invitedNone":Ie.length===1?"routines.event.invitedOne":"routines.event.invitedMany",{count:Ie.length})}),v==="routine"&&e.jsx(bn,{team:h.config?.team,bot:Ie[0],value:it,madeIn:o?.sourceThreadId})]}):e.jsxs("button",{type:"button",onClick:()=>{N({type:"newBot"}),m()},className:"w-full rounded-xl border border-dashed border-accent/45 bg-accent/[0.06] px-4 py-4 text-left hover:bg-accent/10",children:[e.jsx("div",{className:"text-[13px] font-medium text-accent",children:n("routines.event.createFirstBot")}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:n("routines.event.needsBot")})]})]})})]}),Y&&Vt,e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(st,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsx("textarea",{value:B,onChange:a=>E(a.target.value),rows:5,"aria-label":n("routines.editor.descriptionLabel"),placeholder:ae?n("routines.goal.instructionsPlaceholder"):v==="routine"?Y?n("routines.event.instructionsPlaceholder"):n("routines.editor.instructionsPlaceholder"):n("routines.event.agendaPlaceholder"),className:"min-w-0 flex-1 resize-y rounded-xl border border-hairline/50 bg-inset px-3.5 py-3 text-[13px] leading-relaxed text-ink outline-none placeholder:text-ink-tertiary focus:border-accent"})]}),Fn,Y&&Kt,Y&&Jt,!Y&&e.jsxs("div",{children:[e.jsxs("button",{type:"button","aria-expanded":Ge,"aria-controls":"routine-more-options",onClick:()=>_n(a=>!a),className:"flex items-center gap-1.5 rounded-lg px-2 py-1.5 text-[13px] font-medium text-accent-text hover:bg-raised",children:[e.jsx(Ds,{size:14,className:C("transition-transform",Ge&&"rotate-90")}),n(Ge?"routines.editor.fewer":"routines.editor.more")]}),Ge&&e.jsxs("div",{id:"routine-more-options",className:"mt-3 space-y-5 rounded-xl border border-hairline/40 bg-inset/30 p-4",children:[Bt,Wt,e.jsxs("div",{className:"space-y-3",children:[qt,Ut,Yt,Zt]}),Vt,Kt,Jt]})]}),Tt&&e.jsxs("div",{className:"ml-10 flex items-start gap-2 rounded-xl border border-danger/30 bg-danger/10 px-3 py-2.5 text-[13px] text-danger",children:[e.jsx(Je,{size:15,className:"mt-0.5 shrink-0"}),Tt]})]}),e.jsxs("div",{className:"sticky bottom-0 flex items-center justify-end gap-2 border-t border-hairline/40 bg-panel/95 px-5 py-3.5 backdrop-blur",children:[e.jsx("button",{onClick:m,className:"rounded-lg px-4 py-2 text-[13px] text-ink-secondary hover:bg-raised hover:text-ink",children:n("common.cancel")}),e.jsxs("button",{onClick:Pn,disabled:It||Fe||!Hn,className:"flex items-center gap-2 rounded-lg bg-accent px-5 py-2 text-[13px] font-semibold text-white hover:brightness-110 disabled:opacity-40",children:[(It||Fe)&&e.jsx(Me,{size:14,className:"animate-spin"}),Fe?n("routines.attachment.attaching"):o||S||v==="routine"&&!ae?n("automations.editor.app.save"):n(v==="call"?"routines.event.scheduleCall":"routines.goal.schedule")]})]})]})})}function ha({seed:t,bots:s,routinesOnly:r=!1,onClose:l,onMore:i,onSavedRoutine:u,onSavedCall:m}){const{state:c,dispatch:h}=nt(),[N,o]=x.useState(r||t.limitReset?"routine":t.kind),[$,S]=x.useState(t.name??""),[v,K]=x.useState(t.description??""),[L,O]=x.useState(t.botIds.length?t.botIds:s[0]?[s[0].id]:[]),[_,B]=x.useState(()=>t.resultsThreadId??Qe(c,L[0])??null),E=p=>{p[0]!==L[0]&&B(Qe(c,p[0])??null),O(p)},[z,d]=x.useState(!1),[b,T]=x.useState(""),P=x.useRef(null),[g,j]=x.useState(null),I=N==="routine"?30:t.durationMinutes;x.useLayoutEffect(()=>{if(!t.anchor){j(null);return}const p=P.current;if(!p)return;const H=()=>{const R=p.getBoundingClientRect();let Z=t.anchor.x+12,te=t.anchor.y+12;Z+R.width>window.innerWidth-12&&(Z=t.anchor.x-R.width-12),te+R.height>window.innerHeight-12&&(te=t.anchor.y-R.height-12),j({left:Math.max(12,Math.min(Z,window.innerWidth-R.width-12)),top:Math.max(12,Math.min(te,window.innerHeight-R.height-12))})};return H(),window.addEventListener("resize",H),()=>window.removeEventListener("resize",H)},[N,t.anchor]);const D=async()=>{d(!0),T("");try{if(N==="routine"||r){const p=await Ne("/api/routines",{method:"POST",body:JSON.stringify({name:$,prompt:v,botId:L[0],runOn:"maus",enabled:!0,schedule:t.limitReset?{type:"limit_reset",engine:t.limitReset.engine,repeat:"once"}:{type:"once",at:t.at},durationMinutes:I,attachments:[],resultsThreadId:_})});u(p.routine)}else{const p=await Ne("/api/calendar-calls",{method:"POST",body:JSON.stringify({name:$,description:v,botIds:L,schedule:{type:"once",at:t.at},durationMinutes:I})});m(p.call)}l()}catch(p){T(p instanceof Error?p.message:String(p))}finally{d(!1)}},M=!!($.trim()&&L.length&&(N==="call"||v.trim()));return e.jsxs("div",{ref:P,role:"dialog","aria-label":n("routines.quick.label"),style:g??void 0,className:C("fixed z-50 max-h-[calc(100vh-24px)] w-[min(430px,calc(100vw-24px))] overflow-y-auto rounded-2xl border border-hairline/60 bg-panel shadow-2xl",!g&&"left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2"),children:[e.jsxs("div",{className:"flex items-center justify-between bg-raised/70 px-4 py-2.5",children:[e.jsx("div",{className:"text-[12px] font-medium text-ink-secondary",children:n("routines.quick.title")}),e.jsx("button",{onClick:l,className:"rounded-full p-1.5 text-ink-secondary hover:bg-inset hover:text-ink","aria-label":n("common.close"),children:e.jsx(ze,{size:16})})]}),e.jsxs("div",{className:"space-y-3 p-4",children:[e.jsx("input",{autoFocus:!0,value:$,onChange:p=>S(p.target.value),"aria-label":n("routines.editor.titleLabel"),placeholder:n("routines.event.addTitle"),onKeyDown:p=>{p.key==="Enter"&&M&&D()},className:"w-full border-b border-hairline/60 bg-transparent pb-2 text-[18px] font-medium text-ink outline-none placeholder:text-ink-tertiary focus:border-accent"}),!r&&!t.limitReset&&e.jsxs("div",{className:"flex items-center gap-1 border-b border-hairline/35 pb-2",children:[e.jsx("button",{type:"button",onClick:()=>{o("routine"),O(p=>p.slice(0,1))},className:C("rounded-lg px-3 py-1.5 text-[12px] font-medium",N==="routine"?"bg-accent/15 text-accent":"text-ink-secondary hover:bg-raised hover:text-ink"),children:n("routines.kind.routine")}),e.jsx("button",{type:"button",onClick:()=>o("call"),className:C("rounded-lg px-3 py-1.5 text-[12px] font-medium",N==="call"?"bg-accent/15 text-accent":"text-ink-secondary hover:bg-raised hover:text-ink"),children:n("routines.kind.call")})]}),e.jsxs("div",{className:"flex items-start gap-3 text-[13px] text-ink",children:[e.jsx(gt,{size:16,className:"mt-0.5 shrink-0 text-ink-secondary"}),t.limitReset?e.jsx("div",{"data-testid":"quick-limit-reset",children:Ns({engine:t.limitReset.engine,repeat:"once"})}):e.jsxs("div",{children:[e.jsx("div",{children:Nt(t.at)}),e.jsxs("div",{className:"mt-0.5 text-ink-secondary",children:[X(t.at),N==="call"?` – ${X(t.at+I*6e4)}`:""]})]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(bt,{size:16,className:"mt-2.5 shrink-0 text-ink-secondary"}),s.length===0?e.jsxs("button",{type:"button",onClick:()=>{h({type:"newBot"}),l()},className:"min-w-0 flex-1 rounded-xl border border-dashed border-accent/45 bg-accent/[0.06] px-3 py-3 text-left hover:bg-accent/10",children:[e.jsx("div",{className:"text-[12px] font-medium text-accent",children:n("routines.event.createFirstBot")}),e.jsx("div",{className:"mt-0.5 text-[11px] text-ink-secondary",children:n("routines.quick.comeBack")})]}):N==="routine"?e.jsxs(U,{value:L[0]??"",onChange:p=>E([p.target.value]),className:"flex-1",children:[e.jsx("option",{value:"",children:n("routines.event.assignBot")}),s.map(p=>e.jsx("option",{value:p.id,children:p.name},p.id))]}):e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(yt,{bots:s,selected:L,multiple:!0,onChange:E})})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(st,{size:16,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsx("textarea",{value:v,onChange:p=>K(p.target.value),rows:3,"aria-label":n("routines.editor.descriptionLabel"),placeholder:n(N==="routine"?"routines.quick.whatToDo":"routines.quick.description"),className:"min-w-0 flex-1 resize-none rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[13px] leading-relaxed text-ink outline-none placeholder:text-ink-tertiary focus:border-accent"})]}),N==="routine"&&e.jsx(vn,{bot:s.find(p=>p.id===L[0]),value:_,onChange:p=>B(p??null)}),N==="routine"&&e.jsx(bn,{team:c.config?.team,bot:s.find(p=>p.id===L[0]),value:_}),b&&e.jsx("div",{className:"rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:b})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-hairline/40 px-4 py-3",children:[e.jsx("button",{onClick:()=>i({...t,kind:N,botIds:L,name:$,description:v,durationMinutes:I,resultsThreadId:_}),title:n("routines.quick.moreTitle"),className:"rounded-lg px-3 py-2 text-[12px] font-medium text-accent hover:bg-accent/10",children:n("routines.editor.more")}),e.jsxs("button",{onClick:D,disabled:!M||z,className:"flex items-center gap-1.5 rounded-lg bg-accent px-4 py-2 text-[12px] font-semibold text-white hover:brightness-110 disabled:opacity-40",children:[z&&e.jsx(Me,{size:13,className:"animate-spin"}),n("common.save")]})]})]})}function ga({anchor:t,days:s,items:r,bots:l,groups:i,selectedId:u,onOpen:m,onCreate:c,onMove:h,onResize:N,markers:o=[],onDropOnReset:$}){const S=x.useRef(null),[v,K]=x.useState(null),[L,O]=x.useState(null),_=Ye(Date.now()),B=Array.from({length:s},(g,j)=>mn(t,j)),E=s===7?64:s===3?180:280,z=`64px repeat(${s}, minmax(${E}px, 1fr))`,d=64+s*E;x.useEffect(()=>{const g=S.current;if(!g)return;const j=new Date,I=B.includes(_)?Math.max(0,j.getHours()-2):7;g.scrollTo({top:I*G})},[s]);const b=(g,j)=>{if(g.button!==0||g.target.closest("[data-event-card]"))return;const I=g.currentTarget.getBoundingClientRect(),D=Ue(j,g.clientY,I.top,G);let M=D+30*6e4;K({day:j,start:D,end:M});const p=w=>{const R=Ue(j,w.clientY,I.top,G);M=Math.max(D+ee*6e4,R+ee*6e4),K({day:j,start:D,end:M})},H=w=>{document.removeEventListener("pointermove",p),document.removeEventListener("pointerup",H),K(null),c({kind:"routine",at:D,durationMinutes:Math.max(ee,Math.round((M-D)/6e4)),botIds:[],anchor:{x:w.clientX,y:w.clientY}})};document.addEventListener("pointermove",p),document.addEventListener("pointerup",H,{once:!0})},T=(g,j)=>{g.preventDefault(),O(null);const I=g.currentTarget.getBoundingClientRect(),D=Ue(j,g.clientY,I.top,G),M=g.dataTransfer.getData(Xe);if(M)return c({kind:"routine",at:D,durationMinutes:30,botIds:[M],anchor:{x:g.clientX,y:g.clientY}});const p=g.dataTransfer.getData(we);if(p)try{const H=JSON.parse(p);h(H,D)}catch{}},P=(g,j)=>{if(!g.dataTransfer.types.includes(Xe)&&!g.dataTransfer.types.includes(we))return;g.preventDefault(),g.dataTransfer.dropEffect=g.dataTransfer.types.includes(we)?"move":"copy";const I=g.currentTarget.getBoundingClientRect(),D=Ue(j,g.clientY,I.top,G);O(M=>M?.day===j&&M.at===D?M:{day:j,at:D})};return e.jsxs("div",{ref:S,className:"min-h-0 flex-1 overflow-auto border-l border-t border-hairline/40 bg-app",children:[e.jsxs("div",{className:"sticky top-0 z-30 grid bg-app/95 backdrop-blur",style:{gridTemplateColumns:z,minWidth:d},children:[e.jsx("div",{className:"border-b border-r border-hairline/40 px-2 py-3 text-center text-[9px] uppercase tracking-wider text-ink-secondary",children:hs(-new Date(t).getTimezoneOffset())}),B.map(g=>{const j=new Date(g),I=g===_;return e.jsxs("div",{role:"columnheader",className:C("border-b border-r border-hairline/40 px-2 py-2 text-center last:border-r-0",I&&"bg-accent/[0.035]"),children:[e.jsx("div",{className:C("text-[10px] font-medium uppercase tracking-[0.14em]",I?"text-accent":"text-ink-secondary"),children:Ze(j.getDay())}),e.jsx("div",{className:C("mx-auto mt-1 flex size-8 items-center justify-center rounded-full text-[15px] font-medium",I?"bg-accent text-accent-ink":"text-ink"),children:j.getDate()})]},g)})]}),e.jsxs("div",{role:"grid","aria-label":n("routines.calendar.label"),onDragEnd:()=>O(null),className:"relative grid",style:{height:G*24,gridTemplateColumns:z,minWidth:d},children:[e.jsx("div",{className:"relative border-r border-hairline/40",children:Array.from({length:24},(g,j)=>e.jsx("div",{className:"absolute right-2 -translate-y-1/2 text-[10px] tabular-nums text-ink-tertiary",style:{top:j*G},children:j===0?"":new Date(2e3,0,1,j).toLocaleTimeString(Le(),{hour:"numeric"})},j))}),B.map(g=>{const j=new Date,I=(j.getHours()*60+j.getMinutes())/60*G,D=r.filter(w=>Ye(w.at)===g),M=gs(D),p=v?.day===g?v:null,H=L?.day===g?L:null;return e.jsxs("div",{role:"gridcell","aria-label":n("routines.calendar.day",{date:Nt(g)}),onPointerDown:w=>b(w,g),onDragOver:w=>P(w,g),onDragLeave:w=>{(!(w.relatedTarget instanceof Node)||!w.currentTarget.contains(w.relatedTarget))&&O(null)},onDrop:w=>T(w,g),className:C("relative border-r border-hairline/40 last:border-r-0",g===_&&"bg-accent/[0.025]"),children:[Array.from({length:48},(w,R)=>e.jsx("div",{className:C("pointer-events-none absolute inset-x-0 border-t",R%2===0?"border-hairline/30":"border-hairline/10"),style:{top:R/2*G}},R)),g===_&&e.jsxs("div",{className:"pointer-events-none absolute inset-x-0 z-20 flex items-center",style:{top:I},children:[e.jsx("span",{className:"-ml-1 size-2 rounded-full bg-danger"}),e.jsx("span",{className:"h-px flex-1 bg-danger/80"})]}),p&&e.jsx("div",{className:"pointer-events-none absolute inset-x-1 z-10 rounded-md border border-accent/70 bg-accent/20",style:{top:(new Date(p.start).getHours()*60+new Date(p.start).getMinutes())/60*G,height:Math.max(16,(p.end-p.start)/36e5*G)}}),H&&e.jsx("div",{className:"pointer-events-none absolute inset-x-1 z-20 rounded-md border border-accent/80 bg-accent/25 shadow-sm",style:{top:(new Date(H.at).getHours()*60+new Date(H.at).getMinutes())/60*G,height:G/2},children:e.jsx("div",{className:"px-2 py-1 text-[10px] font-medium text-accent",children:X(H.at)})}),o.filter(w=>Ye(w.at)===g).map(w=>e.jsx(Vs,{marker:w,hourHeight:G,onDrop:$&&(R=>$(R,w))},w.engine)),D.map(w=>e.jsx(Js,{item:w,bots:l,groups:i,compact:s===7,layout:M.get(w.id)??{column:0,columns:1},selected:w.id===u,onOpen:()=>m(w),onResize:R=>N(w,R)},w.id))]},g)})]})]})}function ba({item:t,bots:s,onClose:r,onEdit:l,onCallChanged:i,onOpenRoom:u,onOpenRun:m}){const{state:c,dispatch:h}=nt(),N=ln(),o=Zn(),[$,S]=x.useState(!1),v=x.useRef(!1),[K,L]=x.useState(!1),[O,_]=x.useState(void 0),[B,E]=x.useState(""),z=t.kind==="call",d=t.kind==="routine"?t.routine:null,b=O===void 0?t.kind==="routine"?t.run:null:O&&(c.routineRuns.find(f=>f.id===O.id)??O),T=t.kind==="call"?t.call:null,P=!z&&(b?.target??d?.target)==="room-goal",g=P?b?b.groupId:d?.groupId:void 0,j=c.groups.find(f=>f.id===g),I=b?.executionThreadId??b?.threadId,D=T?.botIds??[b?.botId??d?.botId??""],M=D.flatMap(f=>s.find(J=>J.id===f)??[]),p=M[0],H=P&&g?j:p,w=!!(I&&(H?.threadId===I||H?.tasks?.some(f=>f.threadId===I))),R=b?b.resultsThreadId??b.sourceThreadId:d?.resultsThreadId,Z=R??(!b&&d?.target==="bot"?p?.mainThreadId:void 0),te=Z&&[...c.bots,...c.groups].some(f=>f.threadId===Z||f.tasks?.some(J=>J.threadId===Z)),le=T?.name??b?.routineName??d?.name??"Routine",F=T?.description??b?.prompt??d?.prompt??"",y=T?.attachments??b?.attachments??d?.attachments??[],de=T?.botIds.length===1?p?.id:void 0,Q=b?b.timeoutMinutes:d?.timeoutMinutes,be=()=>{I&&(P&&g?(h({type:"switchGroupTask",groupId:g,threadId:I}),u(g)):p&&Cs(h,p,I,o),r())},ce=async(f,J="POST",pe)=>{S(!0),E("");try{const se=await Ne(f,{method:J,...pe?{body:JSON.stringify(pe)}:{}});se.routine&&h({type:"routinePatched",routine:se.routine}),se.run&&h({type:"routineRunPatched",run:se.run})}catch(se){E(se instanceof Error?se.message:String(se))}finally{S(!1)}},ve=()=>{!d||$||v.current||(v.current=!0,L(!0),_(null),S(!0),E(""),h({type:"runRoutine",routineId:d.id,onStarted:_,onError:f=>E(f instanceof Error?f.message:String(f)),onSettled:()=>{v.current=!1,L(!1),S(!1)}}))},at=async()=>{if(T){S(!0),E("");try{const{group:f}=await Ne(`/api/calendar-calls/${T.id}/room`,{method:"POST"});h({type:"groupPatched",group:f}),u(f.id)}catch(f){E(f instanceof Error?f.message:String(f))}finally{S(!1)}}},Ae=async()=>{window.confirm(n("routines.event.deleteConfirm",{title:le}))&&(T?(await Ne(`/api/calendar-calls/${T.id}`,{method:"DELETE"}),i(T.id)):d&&h({type:"deleteRoutine",routineId:d.id}),r())},fe=d?.id??b?.routineId,Oe=fe?c.routineRuns.filter(f=>f.routineId===fe).sort((f,J)=>nn(J)-nn(f)).slice(0,3):[],q=b?.runOn??d?.runOn,Se=bs({roomGoal:P,runOn:q,computer:p?.computer,cloudHome:c.config?.cloudHome===!0}),ne=R?[...c.bots,...c.groups].find(f=>f.threadId===R||f.tasks?.some(J=>J.threadId===R)):void 0,rt=R?ne?.tasks?.find(f=>f.threadId===R)?.title??ne?.name??n("routines.results.missing"):n("routines.results.main");return e.jsxs("aside",{"aria-label":n("routines.drawer.label"),className:"flex h-full w-[min(310px,100vw)] shrink-0 flex-col border-l border-hairline/40 bg-panel",children:[e.jsxs("div",{className:"flex items-start gap-3 border-b border-hairline/40 px-4 py-3.5",children:[z?e.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-full bg-accent/15 text-accent-text",children:e.jsx(vt,{size:16})}):P?e.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-full bg-accent/15 text-accent-text",children:e.jsx(hn,{size:16})}):p&&e.jsx(Ve,{bot:p,state:b?jn(b.status):d?.enabled===!1?"sleeping":"idle",size:36,animated:!1}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"break-words text-[15px] font-semibold leading-snug text-ink",children:le}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5",children:[d&&e.jsx("span",{className:C("rounded-full px-2 py-0.5 text-[11px] font-medium",d.enabled?"bg-success/15 text-success":"bg-inset text-ink-secondary"),children:vs(d)}),e.jsxs("span",{className:"text-[11px] text-ink-secondary",children:[Nt(t.at)," · ",X(t.at),z?` – ${X(t.at+t.durationMinutes*6e4)}`:""]})]})]}),e.jsx("button",{type:"button",onClick:r,className:"rounded-full p-1.5 text-ink-secondary hover:bg-raised hover:text-ink","aria-label":n("routines.drawer.close"),children:e.jsx(ze,{size:16})})]}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4",children:[b&&e.jsxs("div",{role:"status","aria-live":"polite",className:"rounded-xl border border-hairline/40 bg-inset p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[12px] font-medium text-ink",children:[b.status==="running"&&e.jsx(Me,{size:13,className:"animate-spin text-accent"}),jt(b)]}),b.output&&e.jsx("div",{className:"mt-2 max-h-48 overflow-y-auto whitespace-pre-wrap text-[12px] leading-relaxed text-ink-secondary",children:xt(b,"output")}),b.error&&e.jsx("div",{className:C("mt-2 text-[12px]",kt(b)?"text-warning":"text-danger"),children:xt(b,"error")})]}),b?.attention&&e.jsxs("div",{className:"flex items-start gap-2 rounded-xl border border-warning/30 bg-warning/10 px-3 py-2.5 text-warning",children:[e.jsx(Je,{size:15,className:"mt-0.5 shrink-0"}),e.jsx("div",{className:"min-w-0 whitespace-pre-wrap text-[12px] leading-relaxed",children:xt(b,"attention")})]}),b?.status==="waiting"&&!b.attention&&e.jsx("div",{className:"rounded-xl border border-warning/30 bg-warning/10 px-3 py-2.5 text-[12px] text-warning",children:n("routines.drawer.runWaiting")}),e.jsx(oe,{label:z?n("routines.drawer.guests"):P?n("routines.drawer.lead"):n("routines.drawer.bot"),children:e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[M.map(f=>e.jsxs("div",{className:"flex items-center gap-1.5 rounded-full border border-hairline/50 bg-inset py-0.5 pl-0.5 pr-2.5",children:[e.jsx(Ve,{bot:f,state:"idle",size:22,animated:!1}),e.jsx("span",{className:"text-[12px] text-ink",children:f.name})]},f.id)),M.length===0&&e.jsx("span",{className:"text-[13px] text-ink-secondary",children:n("routines.unavailableBot")})]})}),P&&g&&e.jsx(oe,{label:n("routines.drawer.group"),children:e.jsx("div",{className:"text-[13px] text-ink",children:j?.name??n("routines.drawer.groupUnavailable")})}),(d||T)&&e.jsxs(oe,{label:n("routines.drawer.schedule"),children:[e.jsx("div",{className:"text-[13px] text-ink",children:fs((d??T).schedule)}),d?.schedule.type==="cron"&&e.jsx("div",{className:"mt-2",children:e.jsx($s,{schedule:d.schedule,paused:!d.enabled})})]}),F&&e.jsx(oe,{label:z?n("routines.drawer.agenda"):n("routines.drawer.what"),children:e.jsx("div",{className:"whitespace-pre-wrap text-[13px] leading-relaxed text-ink",children:F})}),!z&&e.jsxs(oe,{label:n("routines.drawer.runsOn"),children:[e.jsxs("div",{className:"flex items-start gap-2 text-[13px] text-ink",children:[q==="cloud"?e.jsx(dn,{size:14,className:"mt-0.5 shrink-0 text-ink-secondary"}):e.jsx(cn,{size:14,className:"mt-0.5 shrink-0 text-ink-secondary"}),e.jsx("span",{children:Se.label})]}),e.jsx("div",{className:"mt-0.5 text-[11px] leading-relaxed text-ink-secondary",children:Se.hint})]}),!z&&!P&&e.jsx(oe,{label:n("routines.results.label"),children:e.jsx("div",{className:"text-[13px] text-ink",children:rt})}),y.length>0&&e.jsxs(oe,{label:n("routines.drawer.attachments"),children:[e.jsx(wn,{attachments:y}),T&&e.jsx("div",{className:"mt-1.5 text-[11px] leading-relaxed text-ink-secondary",children:n(T.botIds.length>1?"routines.drawer.callSharedHelp":"routines.drawer.callKeptHelp")})]}),N&&!z&&e.jsx(oe,{label:n("routines.drawer.runLimit"),children:e.jsx("div",{className:"text-[13px] text-ink",children:Q==null?n("routines.drawer.noTimeLimit"):n("routines.drawer.stopsAfter",{duration:Re(Q)})})}),!z&&e.jsx(oe,{label:n("routines.logs"),action:d&&e.jsxs("button",{type:"button",onClick:()=>{h({type:"showRoutines",section:"logs",routineId:d.id,botId:d.botId}),r()},className:"flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[11px] text-accent-text hover:bg-raised",children:[e.jsx(st,{size:11}),n("routines.drawer.allRuns")]}),children:Oe.length===0?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:n("routines.drawer.noRuns")}):e.jsx("div",{className:"space-y-1",children:Oe.map(f=>e.jsx(oa,{run:f,current:f.id===b?.id,onOpen:()=>m?.(f)},f.id))})}),B&&e.jsx("div",{role:"alert",className:"rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:B})]}),e.jsxs("div",{className:"space-y-2 border-t border-hairline/40 px-4 py-3",children:[d&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:ve,disabled:$,className:"flex flex-1 items-center justify-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12px] font-semibold text-accent-ink hover:brightness-110 disabled:opacity-50",children:[K?e.jsx(Me,{size:13,className:"animate-spin"}):e.jsx(sn,{size:13}),K?n("routines.starting"):n("routines.runNow")]}),e.jsxs("button",{disabled:$,onClick:()=>{ce(`/api/routines/${d.id}`,"PATCH",{enabled:!d.enabled})},title:n(d.enabled?"routines.drawer.pauseRoutine":"routines.drawer.resumeRoutine"),className:"flex flex-1 items-center justify-center gap-1.5 rounded-lg border border-hairline/50 bg-control px-3 py-2 text-[12px] font-medium text-ink hover:bg-raised-hover disabled:opacity-40",children:[d.enabled?e.jsx(ys,{size:13}):e.jsx(sn,{size:13}),d.enabled?n("routines.pause"):n("routines.resume")]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[de&&e.jsxs("button",{onClick:()=>u(de),className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12px] font-semibold text-accent-ink hover:brightness-110",children:[e.jsx(Te,{size:13}),n("routines.drawer.joinGroup")]}),T&&T.botIds.length>1&&e.jsxs("button",{onClick:at,disabled:$,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12px] font-semibold text-accent-ink hover:brightness-110 disabled:opacity-50",children:[e.jsx(Te,{size:13}),n("routines.drawer.joinGroup")]}),P&&j&&!I&&e.jsxs("button",{onClick:()=>{u(j.id),r()},className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink",children:[e.jsx(Te,{size:13}),n("routines.drawer.openGroup")]}),w&&e.jsxs("button",{onClick:be,className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink",children:[e.jsx(Te,{size:13}),n(P&&g?"routines.drawer.openGroupThread":"routines.drawer.openThread")]}),te&&Z&&e.jsxs("button",{type:"button",onClick:()=>{js(h,{botId:D[0],threadId:Z},c,o),r()},className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink",children:[e.jsx(Te,{size:13}),n("routines.results.open")]}),b&&["queued","running","waiting"].includes(b.status)&&e.jsxs("button",{onClick:()=>{ce(`/api/routine-runs/${b.id}/cancel`)},disabled:$,className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-40",children:[e.jsx(ze,{size:13}),n("routines.drawer.cancelRun")]}),e.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[(d||T)&&e.jsx("button",{onClick:l,className:"rounded-lg px-2.5 py-1.5 text-[12px] font-medium text-ink hover:bg-raised",children:n("routines.edit")}),(d||T)&&e.jsx("button",{onClick:()=>{Ae()},className:"rounded-lg p-2 text-ink-secondary hover:bg-danger/10 hover:text-danger",title:n("routines.delete"),"aria-label":n("routines.delete"),children:e.jsx(ks,{size:14})})]})]})]})]})}function oe({label:t,action:s,children:r}){return e.jsxs("section",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between gap-2",children:[e.jsx("h3",{className:"text-[11px] font-semibold uppercase tracking-wider text-ink-tertiary",children:t}),s]}),r]})}function ia(t){if(t.startedAt==null||t.finishedAt==null||t.finishedAt<t.startedAt)return null;const s=Math.round((t.finishedAt-t.startedAt)/1e3);return s<60?`${s}s`:Re(Math.round(s/60))}function oa({run:t,current:s,onOpen:r}){const l=t.startedAt??t.scheduledFor,i=ia(t),u=t.status==="completed"&&(!t.goalStatus||t.goalStatus==="completed"),m=ws(t)||t.goalStatus==="failed"||t.goalStatus==="blocked",c=["queued","running","waiting"].includes(t.status);return e.jsxs("button",{type:"button",onClick:r,"aria-label":n("routines.openRun",{name:t.routineName,status:jt(t)}),"aria-current":s||void 0,className:C("flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left hover:bg-raised",s&&"bg-raised"),children:[u?e.jsx(gn,{size:14,className:"shrink-0 text-success","aria-hidden":"true"}):m?kt(t)?e.jsx(Je,{size:14,className:"shrink-0 text-warning","aria-hidden":"true"}):e.jsx(Ss,{size:14,className:"shrink-0 text-danger","aria-hidden":"true"}):c?e.jsx(Me,{size:14,className:"shrink-0 animate-spin text-accent","aria-hidden":"true"}):e.jsx(Je,{size:14,className:"shrink-0 text-ink-tertiary","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] text-ink",children:new Date(l).toLocaleDateString(Le(),{month:"short",day:"numeric"})}),e.jsxs("span",{className:"shrink-0 text-[11px] tabular-nums text-ink-secondary",children:[X(l),i?` · ${i}`:""]})]})}function la({routine:t,bots:s,lockedBotId:r,initialBotId:l,defaultRunOn:i,plain:u,onClose:m}){const c=t?.schedule.type==="once"?t.schedule.at:t?.schedule.type==="daily"?ht(Date.now(),t.schedule.time):t?.schedule.type==="interval"?t.schedule.anchorAt:t?.schedule.type==="cron"?t.nextRunAt??on():on();return e.jsx(ra,{seed:{kind:"routine",at:c,durationMinutes:t?.durationMinutes??30,botIds:r?[r]:t?[t.botId]:l?[l]:s.length===1?[s[0].id]:[],routine:t},bots:s,lockedBotId:r,defaultRunOn:i,plain:u,onClose:m,onSavedCall:()=>{}})}const va=Object.freeze(Object.defineProperty({__proto__:null,RoutineEditor:la},Symbol.toStringTag,{value:"Module"}));export{ga as C,ba as E,Rs as H,ha as Q,la as R,Ms as a,ra as b,va as c};