import{r as s,j as a}from"./vendor-react-wBh_31cN.js";import{j as y,u as f}from"./vendor-redux-CJZrIb6x.js";import{g as I,r as A,aq as J}from"./index-BKr2rJhV.js";import{u as S}from"./useTitle-DQo_L6Ox.js";import{c as E,b as w}from"./index-LWIqX2n6.js";import{E as T,y as L}from"./alertManagerConfUtil-D4yp8Ca8.js";import{s as M,a as k}from"./jobAlert.selectors-DIpkTg6b.js";import{A as B}from"./AgentJobForm-D3vp09Ud.js";import{u as D,c as C}from"./vendor-router-D1GqFWiT.js";import"./vendor-utils-OeoE2qq_.js";import"./vendor-icons-BUUmD6ht.js";import"./vendor-radix-BRyWS4bQ.js";import"./vendor-grid-CeFlDWv4.js";import"./index-CHdS1Zyb.js";import"./utils-C3tzOLw4.js";import"./index-DdhqPQ_t.js";import"./time-utils-tK1noPML.js";import"./addDays-DjM7nKyN.js";import"./always-CtAmwIxm.js";import"./init-BDcDHUTz.js";import"./concat-AxOj0lUI.js";import"./formatDistance-qDinyJzC.js";import"./join-DatdAzSt.js";import"./includes-D04d5Ytc.js";import"./add-DCChD-X4.js";import"./lensPath-CdufhmA3.js";import"./mergeRight-Cv2eiGXV.js";import"./project-eQY1xQe-.js";import"./index.esm-CAGtek53.js";import"./yup-XkUC3UEH.js";import"./alertUtil-MS8PGQKV.js";import"./fileExplorer-BRS7UOt9.js";import"./useDownload-YBz540B0.js";import"./useNotifier-BCEAoFCf.js";import"./notifications-x-pTFTQl.js";import"./toast-3g7Fh-a0.js";import"./useCurrentProject-C6qZaZgv.js";import"./useProject-FSnHbCQX.js";import"./index-BeaoFlb1.js";import"./getPathAndFileName-BId4RGny.js";import"./input-H6_qmzms.js";import"./label-Dnebucx5.js";import"./textarea-Co48BFy3.js";import"./combobox-CcK1PxyF.js";import"./input-group-Z3Qmt3PL.js";import"./vendor-recharts-DmJlpLaF.js";import"./radio-group-D7-g0sv3.js";import"./getInputValidation-CUi6Oel7.js";import"./form-BGlJWZp2.js";import"./converge-BDz-h6lA.js";import"./zipObj-BpJhvpTB.js";import"./pythonUtils-Ci3XE0w8.js";import"./badge-nyizWwTN.js";import"./selectors-CMD4o3wq.js";import"./index-DkvW68Om.js";import"./index-DJIjy7qt.js";import"./uniq-Cy5NeM3Y.js";import"./uniqBy-qYjau2JN.js";import"./useIsJupyterDisabled-W-gx_pSy.js";import"./useHotkeysShortcut-BupQRiR8.js";import"./index-B5BaAmTQ.js";import"./any-Db6pVWyk.js";import"./AlertForm-DTCsNJT8.js";import"./useAlertProjectConfig-BiyOl1hl.js";import"./callout-Dd8FkTQe.js";import"./card-DISTA6Ay.js";import"./icon-button-FETOk6q1.js";import"./separator-2OqrG5Vy.js";import"./CronExpression-D3O-UlpN.js";import"./index--vO3kPD9.js";import"./slicedToArray-BHGdh4W7.js";import"./vendor-markdown-DYw41Xyj.js";import"./checkbox-DbZXziG0.js";import"./tooltip-Da8-EbK8.js";import"./HumanizedCronExpression-D34G4jQt.js";import"./not-CZjOXJzQ.js";import"./CronDetails-DuLrEPPy.js";import"./date-picker-DuYl6sUN.js";import"./popover-DNRIgB96.js";import"./value-76ihWpF6.js";import"./JobsStickySummary-BdQ0UjxJ.js";import"./dumbPluralize-CcxDsNiu.js";import"./ButtonWithRole-BINnbeGr.js";import"./useProjectRole-UlQXu1Cp.js";import"./form-footer-CprMCGDT.js";import"./EnvVarsField-DuIE3Krh.js";import"./ArrayField-DU-w4GBF.js";import"./InjectedEnvVarsPreview-DGEjLZXG.js";import"./EnvVarsService-BrhQRBBu.js";import"./useProjectId-Ck57b-tn.js";const ho=()=>{const n=D(),e=y(),{id:o,jobName:m}=C(),[g,c]=s.useState(!1),{data:l,isLoading:u}=E({pId:o,jobName:m}),[d]=w();s.useEffect(()=>{m&&e.jobAlert.fetch({projectId:+o,jobName:m})},[e.jobAlert,o,m]);const r=f(M),h=f(k),v=s.useMemo(()=>r!=null&&r.jobAlerts?r.jobAlerts.map(t=>{const i=T(t.status)??"",j=t.passToAgent?"credentials":"alert";return{status:i,severity:L[t.severity]??"",receiver:t.receiver??"",threshold:t.threshold??0,passToAgent:!!t.passToAgent,alertMode:j}}):[],[r]),b=s.useMemo(()=>{var t;return((t=r==null?void 0:r.jobAlerts)==null?void 0:t.map(i=>i.id))??[]},[r]);S(`Edit ${m}`);const x=s.useCallback(async(t,i,j)=>{c(!0);try{const{name:p}=await d({pId:o,data:t,name:t.appName}).unwrap();if(p){if(await Promise.all(b.map(N=>e.jobAlert.remove({projectId:+o,jobName:p,id:N}).catch(()=>{}))),i.length>0)try{i.length>1?await e.jobAlert.createBulk({projectId:+o,jobName:p,jobAlert:{items:i},bulk:!0}):await e.jobAlert.create({projectId:+o,jobName:p,jobAlert:i[0]})}catch{}n(I(A.project.agentJobs.overview,A.project.value,{id:o,jobName:p}))}}finally{c(!1)}},[o,d,b,e.jobAlert,n]);return u||!l||h?a.jsx(J,{}):a.jsx("div",{className:"flex flex-col",children:a.jsx(B,{initialData:l.config,initialAlerts:v,isEdit:!0,onSubmit:x,isSubmitting:g,isLoading:u,saveButtonText:"Save changes"})})};export{ho as default};
