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-DNBEEyYo.js";import{A as se,g as m}from"./defineProperty-9LKwahlh.js";import{M as ie,F as oe,N as ae,H as ne}from"./Project-D_38ySn9.js";import{S as re}from"./ServiceAlertList-BGZarpuB.js";import{u as le}from"./CronSchedule-C0Zd0yx3.js";import{u as ce,S as pe}from"./JobOverviewContent-zjip_UMD.js";import{N as de}from"./NotebookJobArgsCallout-D6jvm89Q.js";import{K as me}from"./KubernetesProjectEdit-CgGaVg-Q.js";import"./alertManagerConfig.selectors-6Q6ry9ha.js";import"./HumanizedCronExpression-Cc3xtXqn.js";import"./index-DivQJV92.js";import"./form-nDhxPMre.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-lQ_DaX5E.js";import"./index-Burx7Ja_.js";import"./git-BLdzamrJ.js";import"./useCopyToClipboard-BnywFRQi.js";import"./index-DilfZ0pz.js";import"./LabelValue-IAA3SRmC.js";import"./Panel-LhPx0w--.js";import"./Deprecated-DmDD0-tM.js";import"./index-bIvQJs1X.js";import"./DateValue-DxrJEAHH.js";import"./RunJobButtons-zj5UYu-m.js";import"./KubernetesProjectView-q2FZ4sWq.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};
