import{r as p,c as _,Q as y,N as g,u as k}from"./index-Zr2uxkwm.js";function v(r,a,n){return new Promise((i,l)=>{const e=k(r);e.track("blueprints_run_started");const t=new Date().getTime();function s(u){var o,f;const m=(f=(o=u.payload)==null?void 0:o.mail)==null?void 0:f.some(B=>{var d;return((d=B.payload)==null?void 0:d.type)==="error"}),c={durationMs:new Date().getTime()-t};m?e.track("blueprints_run_failed",c):e.track("blueprints_run_succeeded",c),i(void 0)}r.forwardEvent(new CustomEvent("wf-builtin-run",{detail:{callback:s,handler:n?`$runBlueprintTriggerBranchById_${n}`:`$runBlueprintById_${a}`}}),null,!0).catch(u=>{e.track("blueprints_run_failed",{error:String(u)}),l(u)})})}function R(r,a){const n=p(!1);async function i(l){if(!n.value){n.value=!0;try{await v(r,g(a),l)}finally{n.value=!1}}}return{isRunning:y(n),run:i}}function h(r,a){const n=p([]);async function i({blueprintId:t,branchId:s}){if(!n.value.includes(t))try{n.value=[t,...n.value],await v(r,t,s)}finally{n.value=n.value.filter(u=>u!==t)}}async function l(){await Promise.all(g(a).map(i))}const e=_(()=>n.value.length>0);return{run:l,isRunning:e,runningBlueprintIds:y(n)}}export{h as a,R as u};
