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-dNe6i2rS.js";import{u as S}from"./useTitle-DQo_L6Ox.js";import{c as E,b as w}from"./index-DSiF_QgS.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-IlwDt_CS.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-DlAh4Ixf.js";import"./utils-C3tzOLw4.js";import"./index-dHd2aGu6.js";import"./time-utils-CQYZ5msB.js";import"./addDays-Cdit4yPz.js";import"./always-oSAuSdys.js";import"./init-Dq_gEBi9.js";import"./concat-CTXo1gGM.js";import"./formatDistance-B6o-SXVU.js";import"./join-oazOKFfj.js";import"./includes-ucXR_9jq.js";import"./add-SI0q72Q7.js";import"./lensPath-D2xKReso.js";import"./mergeRight-D1nsCm60.js";import"./project-eQY1xQe-.js";import"./index.esm-CAGtek53.js";import"./yup-XkUC3UEH.js";import"./alertUtil-rW93jnda.js";import"./fileExplorer-DEDqs5DH.js";import"./useDownload-TmtSNiQ3.js";import"./useNotifier-BGMn6HaH.js";import"./notifications-5miqOdlG.js";import"./toast-wiGcevcF.js";import"./useCurrentProject-CTMLbmkf.js";import"./useProject-BbrP3CX5.js";import"./index-DURBtSjL.js";import"./getPathAndFileName-BId4RGny.js";import"./input-DFI7JniT.js";import"./label-gPWmc6ow.js";import"./textarea-BJVuSob1.js";import"./combobox-QqI9aNup.js";import"./input-group-gxy3DSmS.js";import"./vendor-recharts-DmJlpLaF.js";import"./radio-group-CjbLFQxV.js";import"./getInputValidation-B3ahFDSx.js";import"./form-HTA58iI5.js";import"./converge-D7u3m7i4.js";import"./zipObj-C8Moen4w.js";import"./pythonUtils-DP4NidfK.js";import"./badge-UCnweWGd.js";import"./selectors-DK1_X0Cd.js";import"./index-DLI8oDiK.js";import"./index-DnLCKZiK.js";import"./uniq--Ej6WwWR.js";import"./uniqBy-6oWnYXMs.js";import"./useIsJupyterDisabled-BBwxBxqL.js";import"./useHotkeysShortcut-CVWmK5fW.js";import"./index-_Tes9c9v.js";import"./any-BVxDk2A0.js";import"./AlertForm-RAL_VVxo.js";import"./useAlertProjectConfig-DHF-bkkD.js";import"./callout-BFSXVeMz.js";import"./card-BeQtvmcJ.js";import"./icon-button-BZeFL7T7.js";import"./separator-CxqNNMXg.js";import"./CronExpression-B_Y2jRUi.js";import"./index--vO3kPD9.js";import"./slicedToArray-BHGdh4W7.js";import"./vendor-markdown-DYw41Xyj.js";import"./checkbox-BlA4MwH9.js";import"./tooltip-DFFgUYh6.js";import"./HumanizedCronExpression-BsPK2pda.js";import"./not-C0YaysLC.js";import"./CronDetails-DOXCedRS.js";import"./date-picker-K4pHuu1h.js";import"./popover-BzVbz_d3.js";import"./value-7N0Keti9.js";import"./JobsStickySummary-61Sh8wOK.js";import"./dumbPluralize-CcxDsNiu.js";import"./ButtonWithRole-ruQLmPtQ.js";import"./useProjectRole-DpUIGfh9.js";import"./form-footer-Drg8-unW.js";import"./EnvVarsField-Dpnn8U9X.js";import"./ArrayField-DnSSsYNA.js";import"./InjectedEnvVarsPreview-CPNXA8Je.js";import"./EnvVarsService-4OFfVS_Z.js";import"./useProjectId-DeuaOE3U.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};
