import{bI as v,u as M,b9 as _,jH as B,hf as O,jX as I,jI as L,jF as $,r as m,bx as H,by as K,y as R,c8 as G,bt as Q,a2 as W,dp as q,jY as Y,q as n,j as e,bA as z,aG as V,k0 as X,b as D,$ as Z,aH as ee,b2 as A,dT as J,bs as te}from"./index-Cc-6WbPt.js";import{A as se,a as u}from"./Anchor-BpzIF9LH.js";import{M as ie,F as oe,N as ae,B as ne}from"./Project-BB6nGAyP.js";import{S as re}from"./ServiceAlertList-HPDSpEcK.js";import{u as le}from"./CronSchedule-B6d05Q3A.js";import{u as ce,S as de}from"./JobOverviewContent-BaCdRc0k.js";import{N as pe}from"./NotebookJobArgsCallout-BwGNRHMW.js";import{K as ue}from"./KubernetesProjectEdit-BWf57EkW.js";import"./alertManagerConfig.selectors-ob2Z93Rq.js";import"./complement-BOrTcrWV.js";import"./index-DeWhk8_Z.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-FE3v46aY.js";import"./git-BLdzamrJ.js";import"./useCopyToClipboard-CGP_51ct.js";import"./index-k6JxR6O9.js";import"./LabelValue-rs3xYf5e.js";import"./Panel-BCZwmXoJ.js";import"./Deprecated-BleiYoSW.js";import"./index-CC3RRZaQ.js";import"./DateValue-COYy-MTL.js";import"./RunJobButtons-DS_YaKDh.js";import"./KubernetesProjectView-DZZIzK02.js";const Le=()=>{const h=v(),{id:t,jobName:r}=M(),o=_(),[l,{isLoading:a}]=B(),[b,{isLoading:w}]=O(),[j]=I(),[x]=L(),{data:c}=le(),S=a||w,{currentData:s,isFetching:g}=$({pId:t,jobName:r}),{handleDeleteJob:y,isDeleting:f}=ce(),N=m.useMemo(()=>s?[s.config]:[],[s]);H(`${K.editJob} ${s==null?void 0:s.name}`);const[C,d]=R(),T=m.useCallback(async(i,he,be,p)=>{const k=G(Q(W))(i),E={...i[i.type],...k},{name:P}=await l({pId:t,data:q(s==null?void 0:s.config,E),name:i.appName}).unwrap();c&&p&&await b({pId:t,data:{...c,...p},jobName:i.appName}).unwrap(),c&&!p&&(await j({pId:t,jobName:i.appName}),h(Y.updateQueryData("getJobSchedule",{pId:t,jobName:r},U=>{Object.assign(U,{deleted:!0})}))),!c&&p&&await x({pId:t,data:p,jobName:i.appName}),P&&o(n.project.jobs.overview,{jobName:P})},[x,j,h,s==null?void 0:s.config,r,o,c,t,l,b]),F=m.useCallback(async()=>{s&&(await y(s.name),d(),o(n.project.jobs.list))},[s,y,d,o]);return e.jsxs(e.Fragment,{children:[s&&N.length>0&&e.jsx(ie,{isLoading:g,isDisabled:S||f,initialData:N,submitHandler:T,isSubmiting:S,disabledJobTypeChange:!0,isEdit:!0,children:i=>e.jsx(me,{...i,jobData:s,handleToggle:d})}),e.jsx(z,{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:d,mainButtonProps:{"data-test":"delete-job",children:"Delete job",onClick:F,disabled:g,isLoading:f},secondaryButtonProps:{children:"Back",onClick:d,disabled:f||g}})]})},me=({advanceConfig:h,jobData:t,handleToggle:r,type:o})=>{const{register:l,setValue:a}=V();m.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=m.useMemo(()=>[X[t.jobType]??""],[t]);return e.jsxs(se,{children:[e.jsx(u,{name:n.jobAnchors.jobDetails,children:e.jsx(D,{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(A,{...l("appName"),placeholder:"name",label:"Name",labelProps:{width:"320px"},readOnly:!0}),(t.config.appPath??"").endsWith(".ipynb")&&o==="python"&&e.jsx(pe,{}),e.jsx(A,{optional:!0,...l("defaultArgs"),placeholder:"args",label:"Default arguments",labelProps:{width:"100%"}})]})})}),e.jsx(u,{name:n.jobAnchors.config,children:e.jsx(J,{width:"100%",title:"Configuration",children:h})}),e.jsx(u,{name:n.jobAnchors.schedule,children:e.jsx(de,{withoutSave:!0})}),e.jsx(u,{name:n.jobAnchors.kubernetesScheduler,children:e.jsx(ue,{prefix:b,init:!1,enabledKueue:ae.includes(ne(o.toUpperCase()))})}),e.jsx(u,{name:n.jobAnchors.alerts,children:e.jsx(re,{type:"job",job:t,mb:"0"})}),e.jsx(J,{title:"Danger zone",children:e.jsx(te,{intent:"alert",onClick:r,children:"Delete job"})})]})};export{Le as default};
