import{bW as U,u as v,ba as B,kz as O,ip as _,lb as L,kA as H,l1 as R,r as u,bG as $,bH as K,w as W,cl as z,bC as I,a3 as q,dJ as G,lc as Q,x as n,j as e,bJ as V,aR as Y,lf as D,f as X,q as Z,aS as ee,aH as y,bk as A,bB as te}from"./index-DHiyXWqE.js";import{A as se,g as m}from"./defineProperty-C28_3XcK.js";import{M as ie,F as oe,N as ae,H as ne}from"./Project-DwrxbZJj.js";import{S as re}from"./ServiceAlertList-DMbEJyHm.js";import{u as le}from"./CronSchedule-NRBbl145.js";import{u as ce,S as pe}from"./JobOverviewContent-BG9EcuQ1.js";import{N as de}from"./NotebookJobArgsCallout-WRTW2zEE.js";import{K as me}from"./KubernetesProjectEdit-Dg3mVF7r.js";import"./alertManagerConfig.selectors-0se_RTtj.js";import"./HumanizedCronExpression-FxwdMNJF.js";import"./index-5hEKE-oe.js";import"./form-CrZPXKpD.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-BqIFhGVd.js";import"./index-C52WzLFZ.js";import"./git-BLdzamrJ.js";import"./useCopyToClipboard-D6oq-fy9.js";import"./index-5xepsXs7.js";import"./LabelValue-BXwn8NCm.js";import"./Panel-VWoblIge.js";import"./Deprecated-C23Jh13V.js";import"./index-DFvCs-SP.js";import"./DateValue-DZ395D7A.js";import"./RunJobButtons-D0JthD_K.js";import"./KubernetesProjectView-B86L_C2V.js";const $e=()=>{const h=U(),{id:t,jobName:r}=v(),o=B(),[l,{isLoading:a}]=O(),[b,{isLoading:w}]=_(),[x]=L(),[j]=H(),{data:c}=le(),S=a||w,{currentData:s,isFetching:g}=R({pId:t,jobName:r}),{handleDeleteJob:N,isDeleting:f}=ce(),P=u.useMemo(()=>s?[s.config]:[],[s]);$(`${K.editJob} ${s==null?void 0:s.name}`);const[C,p]=W(),k=u.useCallback(async(i,he,be,d)=>{const E=z(I(q))(i),F={...i[i.type],...E},{name:J}=await l({pId:t,data:G(s==null?void 0:s.config,F),name:i.appName}).unwrap();c&&d&&await b({pId:t,data:{...c,...d},jobName:i.appName}).unwrap(),c&&!d&&(await x({pId:t,jobName:i.appName}),h(Q.updateQueryData("getJobSchedule",{pId:t,jobName:r},M=>{Object.assign(M,{deleted:!0})}))),!c&&d&&await j({pId:t,data:d,jobName:i.appName}),J&&o(n.project.jobs.overview,{jobName:J})},[j,x,h,s==null?void 0:s.config,r,o,c,t,l,b]),T=u.useCallback(async()=>{s&&(await N(s.name),p(),o(n.project.jobs.list))},[s,N,p,o]);return e.jsxs(e.Fragment,{children:[s&&P.length>0&&e.jsx(ie,{isLoading:g,isDisabled:S||f,initialData:P,submitHandler:k,isSubmiting:S,disabledJobTypeChange:!0,isEdit:!0,children:i=>e.jsx(ue,{...i,jobData:s,handleToggle:p})}),e.jsx(V,{title:`Delete ${s==null?void 0:s.name}`,secondaryText:"Once you delete a job, there is no going back. Please be certain.",isOpen:C,onClose:p,mainButtonProps:{"data-test":"delete-job",children:"Delete job",onClick:T,disabled:g,isLoading:f},secondaryButtonProps:{children:"Back",onClick:p,disabled:f||g}})]})},ue=({advanceConfig:h,jobData:t,handleToggle:r,type:o})=>{const{register:l,setValue:a}=Y();u.useEffect(()=>{setTimeout(()=>{a("appName",t.config.appName),a("appPath",t.config.appPath),a("defaultArgs",t.config.defaultArgs??""),a("type",t.config.type)})},[t,t.appName,t.appPath,t.defaultArgs,t.config.schedulingConfig,a]);const b=u.useMemo(()=>[D[t.jobType]??""],[t]);return e.jsxs(se,{children:[e.jsx(m,{name:n.jobAnchors.jobDetails,children:e.jsx(X,{title:"Edit job",children:e.jsxs(Z,{flexDirection:"column",sx:{gap:"20px"},children:[e.jsx(oe,{name:"appPath",label:"File",fileExplorerMode:ee.oneFile,filePathPrefix:"hdfs://",disabled:!0}),e.jsx(y,{...l("appName"),placeholder:"name",label:"Name",labelProps:{width:"320px"},readOnly:!0}),(t.config.appPath??"").endsWith(".ipynb")&&o==="python"&&e.jsx(de,{}),e.jsx(y,{optional:!0,...l("defaultArgs"),placeholder:"args",label:"Default arguments",labelProps:{width:"100%"}})]})})}),e.jsx(m,{name:n.jobAnchors.config,children:e.jsx(A,{width:"100%",title:"Configuration",children:h})}),e.jsx(m,{name:n.jobAnchors.schedule,children:e.jsx(pe,{withoutSave:!0})}),e.jsx(m,{name:n.jobAnchors.kubernetesScheduler,children:e.jsx(me,{prefix:b,init:!1,enabledKueue:ae.includes(ne(o.toUpperCase()))})}),e.jsx(m,{name:n.jobAnchors.alerts,children:e.jsx(re,{type:"job",job:t,mb:"0"})}),e.jsx(A,{title:"Danger zone",children:e.jsx(te,{intent:"alert",onClick:r,children:"Delete job"})})]})};export{$e as default};
