import{aa as m,ab as r}from"./_applist-tangy-colts-beg-36.js";import{_ as t}from"./main-tangy-colts-beg.js";import{h as l,s as p}from"./machine.-tangy-colts-beg-869.js";import{h as d,c as A}from"./apifycom-tangy-colts-beg-996.js";import{f as C,a as E,h as _}from"./machineh-tangy-colts-beg-696.js";import"./lodash-tangy-colts-beg-516.js";globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(s,e){return this.cache.has(s)?this.cache.get(s):(this.cache.set(s,e),e)}};const R=m(({helpers:s})=>({states:{components:[{componentName:s.componentName.webhook,extraComponents:[A(s),{componentName:s.componentName.select,fieldType:"config",helperText:t("Select whether to monitor an actor or a task."),id:"type",label:t("Type"),onChange:"HANDLE_TYPE",options:[{label:t("Actor"),value:"actor"},{label:t("Task"),value:"task"}],placeholder:t("Select type"),render:"IF_CONNECTION_SELECTED",required:!0,value:void 0},{componentName:s.componentName.select,fieldType:"config",helperText:t("Select an actor to run."),id:"actor-id",label:t("Actor"),onChange:"HANDLE_ACTOR_ID",onRefetch:"REFETCH_ACTORS",options:[],placeholder:t("Select an actor"),render:"IF_ACTOR_SELECTED",required:!1,value:void 0},{componentName:s.componentName.select,fieldType:"config",helperText:t("Select a task to run."),id:"task-id",label:t("Task"),onChange:"HANDLE_TASK_ID",onRefetch:"REFETCH_TASKS",options:[],placeholder:t("Select a task"),render:"IF_TASK_SELECTED",required:!1,value:void 0},{componentName:s.componentName.select,helperText:t("Filter runs by status."),id:"status",label:t("Status"),mode:"multiple",onChange:"HANDLE_STATUS",options:[{label:t("SUCCEEDED"),value:"ACTOR.RUN.SUCCEEDED"},{label:t("ABORTED"),value:"ACTOR.RUN.ABORTED"},{label:t("FAILED"),value:"ACTOR.RUN.FAILED"},{label:t("TIMED OUT"),value:"ACTOR.RUN.TIMED_OUT"},{label:t("CREATED"),value:"ACTOR.RUN.CREATED"},{label:t("RESURRECTED"),value:"ACTOR.RUN.RESURRECTED"}],render:"IF_CONNECTION_SELECTED",value:"ACTOR.RUN.SUCCEEDED"}],fieldType:"config",id:"webhook-id",label:t("Webhook"),onSave:"CLEAR_WEBHOOK_FORM_VALUES",onValidate:"HANDLE_VALIDATION",onWebhookChange:"SET_WEBHOOK",render:!0},{componentName:s.componentName.note,fieldType:"config",id:"note-id",note:[],render:!1}]},actions:{SET_WEBHOOK:({$:e,e:a})=>{l("webhookId")({$:e,e:a.id})},SET_CONNECTION:l("connectionId"),HANDLE_TYPE:async({$:e,e:a})=>{l("type")({$:e,e:a});const i=a;i==="actor"?(await E(e),e.setComponent("task-id",o=>{e.util.isSelectComponent(o)&&(o.value=void 0)})):i==="task"&&(await C(e),e.setComponent("actor-id",o=>{e.util.isSelectComponent(o)&&(o.value=void 0)}))},HANDLE_VALIDATION:({$:e})=>{var i,o,c,u,T;if(!((i=e.getComponent("connection-id"))!=null&&i.value))return e.setComponent("connection-id",n=>{e.util.isConnectionComponent(n)&&(n.status="error",n.invalidMessage=t("Please select a connection"))}),!1;const a=(o=e.getComponent("type"))==null?void 0:o.value;if(!a)return e.setComponent("type",n=>{e.util.isSelectComponent(n)&&(n.status="error",n.invalidMessage=t("Please select a type"))}),!1;if(a==="actor"&&!((c=e.getComponent("actor-id"))!=null&&c.value))return e.setComponent("actor-id",n=>{e.util.isSelectComponent(n)&&(n.status="error",n.invalidMessage=t("Please select an Actor"))}),!1;if(a==="task"&&!((u=e.getComponent("task-id"))!=null&&u.value))return e.setComponent("task-id",n=>{e.util.isSelectComponent(n)&&(n.status="error",n.invalidMessage=t("Please select a Task"))}),!1;if(!((T=e.getComponent("status"))!=null&&T.value))return e.setComponent("status",n=>{e.util.isSelectComponent(n)&&(n.status="error",n.invalidMessage=t("Please select a Status"))}),!1},CLEAR_WEBHOOK_FORM_VALUES:async({$:e,e:a})=>{await _(e,a.url),["connection-id","type","actor-id","task-id","status"].forEach(o=>{e.setComponent(o,c=>{c.value=void 0})})},CONNECTION_ADD_CHANGE:d,HANDLE_ACTOR_ID:l("actorId"),HANDLE_STATUS:l("status"),HANDLE_TASK_ID:l("taskId"),IF_CONNECTION_SELECTED:({$:e})=>{var a;return r((a=e.getComponent("connection-id"))==null?void 0:a.value)},REFETCH_ACTORS:({$:e})=>E(e),REFETCH_TASKS:({$:e})=>C(e),IF_ACTOR_SELECTED:({$:e})=>{var i,o;return((i=e.getComponent("type"))==null?void 0:i.value)==="actor"&&r((o=e.getComponent("connection-id"))==null?void 0:o.value)},IF_TASK_SELECTED:({$:e})=>{var i,o;return((i=e.getComponent("type"))==null?void 0:i.value)==="task"&&r((o=e.getComponent("connection-id"))==null?void 0:o.value)},ON_MACHINE_LOAD:async({$:e})=>{var a,i;if(p(e,[{db:"webhookId",id:"webhook-id"}]),(a=e.db)!=null&&a.connectionId){const o=(i=e.getComponent("type"))==null?void 0:i.value;o==="actor"?await E(e):o==="task"&&await C(e)}}}}));export{R as default};
