import{j as t,y as b,r as w,h as x}from"./vendor-tanstack-BpuysabX.js";import{D as _,B as A,g as j,h as d,bD as v,bQ as k,bS as S,cE as g,e4 as E,y as p,e5 as N}from"./index-CREafGO4.js";import{A as I}from"./automation-wizard-B6t3MhGq.js";import{U as n}from"./automation-schema-DnZvg-v_.js";import"./vendor-radix-DIu41Ss_.js";import"./vendor-recharts-C2XeLr4O.js";import"./vendor-forms-Buh7U8Ay.js";import"./vendor-date-C1t37jsh.js";import"./zod-CtcMvSO9.js";import"./form-DC8L1tSC.js";import"./use-stepper-C-n__du8.js";import"./textarea-Bxh8agz9.js";import"./index-DVVSN4AL.js";import"./radio-group-B1MsDBBw.js";import"./collapsible-B3ULeOqx.js";import"./tags-input-Bd-BicQ9.js";const q=()=>t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx(T,{}),t.jsx(_,{label:"Documentation",id:"automations-guide"})]}),T=()=>t.jsx("div",{className:"flex items-center gap-2",children:t.jsx(A,{children:t.jsxs(j,{children:[t.jsx(d,{children:t.jsx(v,{to:"/automations",className:"text-xl font-semibold",children:"Automations"})}),t.jsx(k,{}),t.jsx(d,{className:"text-xl font-semibold",children:t.jsx(S,{children:"Edit Automation"})})]})})});function V(e){switch(e.type){case"run-deployment":return{type:"run-deployment",deployment_id:e.deployment_id??n,parameters:e.parameters??void 0,job_variables:e.job_variables??void 0};case"pause-deployment":case"resume-deployment":return{type:e.type,deployment_id:e.deployment_id??n};case"pause-work-queue":case"resume-work-queue":return{type:e.type,work_queue_id:e.work_queue_id??n};case"pause-work-pool":case"resume-work-pool":return{type:e.type,work_pool_id:e.work_pool_id??n};case"pause-automation":case"resume-automation":return{type:e.type,automation_id:e.automation_id??n};case"cancel-flow-run":case"suspend-flow-run":case"resume-flow-run":return{type:e.type};case"change-flow-run-state":return{type:"change-flow-run-state",state:e.state,name:e.name??void 0,message:e.message??void 0};case"send-notification":return{type:"send-notification",block_document_id:e.block_document_id,body:e.body,subject:e.subject};case"do-nothing":return{type:"do-nothing"};case"call-webhook":return{type:"do-nothing"};default:return{type:"do-nothing"}}}function c(e){switch(e.type){case"event":return{type:"event",posture:e.posture,threshold:e.threshold,within:e.within,match:e.match,match_related:Array.isArray(e.match_related)?e.match_related[0]:e.match_related,for_each:e.for_each,after:e.after,expect:e.expect};case"compound":return{type:"compound",triggers:e.triggers.map(c),require:e.require,within:e.within??void 0};case"sequence":return{type:"sequence",triggers:e.triggers.map(c),within:e.within??void 0};default:return{type:"event",posture:"Reactive",threshold:1,within:0}}}function B(e){if(e.type!=="event")return"custom";const o=e.match?.["prefect.resource.id"];if(!o)return"custom";const r=Array.isArray(o)?o[0]:o;return r?.startsWith("prefect.flow-run.")?"flow-run-state":r?.startsWith("prefect.deployment.")?"deployment-status":r?.startsWith("prefect.work-pool.")?"work-pool-status":r?.startsWith("prefect.work-queue.")?"work-queue-status":"custom"}function F(e){return{name:e.name,description:e.description||void 0,triggerTemplate:B(e.trigger),trigger:c(e.trigger),actions:e.actions.map(V)}}function P(e){return{name:e.name,description:e.description??"",trigger:e.trigger,actions:e.actions}}const D=e=>{const{automationId:o,onSuccess:r,onError:u}=e,{data:s,isLoading:i}=b(g(o)),a=w.useMemo(()=>{if(s)return F(s)},[s]),{replaceAutomation:l,isPending:f}=E();return{defaultValues:a,isLoading:i,updateAutomation:h=>{const y=P(h);l({id:o,enabled:s?.enabled??!0,...y},{onSuccess:()=>{r?.()},onError:m=>{u?.(m instanceof Error?m:new Error(String(m)))}})},isPending:f}},L=({id:e})=>{const o=x(),{defaultValues:r,updateAutomation:u,isPending:s}=D({automationId:e,onSuccess:()=>{p.success("Automation updated successfully"),o({to:"/automations"})},onError:a=>{p.error(`Failed to update automation: ${a.message}`,{duration:Number.POSITIVE_INFINITY})}}),i=a=>{u(a)};return t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx(q,{}),t.jsx(I,{defaultValues:r,onSubmit:i,submitLabel:"Save",isSubmitting:s})]})},te=function(){const{id:o}=N.useParams();return t.jsx(L,{id:o})};export{te as component};
//# sourceMappingURL=automation_._id.edit-6UjrVLj4.js.map
