import{bI as v,u as M,b9 as _,jG as B,he as O,jW as L,jH as $,jE as I,r as m,bx as G,by as H,y as K,c8 as R,bt as W,a2 as Q,dp as q,jX as z,q as n,j as e,bA as V,aG as X,j$ as Y,b as D,$ as Z,aH as ee,b2 as A,dT as J,bs as te}from"./index-ljTaFLaB.js";import{A as se,a as u}from"./Anchor-Cg_B9iW8.js";import{M as ie,F as oe,N as ae,B as ne}from"./Project-BXqiQm5O.js";import{S as re}from"./ServiceAlertList-DPC1ApKd.js";import{u as le}from"./CronSchedule-CCaI0mbZ.js";import{u as ce,S as de}from"./JobOverviewContent-Dwb72ko0.js";import{N as pe}from"./NotebookJobArgsCallout-CfSfee8D.js";import{K as ue}from"./KubernetesProjectEdit-DCx9MFvC.js";import"./alertManagerConfig.selectors-DirIHxFq.js";import"./complement-DcmnDjwS.js";import"./index-WyeuJRlK.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-Chhazvqc.js";import"./git-BLdzamrJ.js";import"./useCopyToClipboard-CNgp2sLY.js";import"./index-CFrWJVZR.js";import"./LabelValue-DruUvpiO.js";import"./Panel-mILL570q.js";import"./Deprecated-D_iwBiXP.js";import"./index-Bqq8CaP2.js";import"./DateValue-Bx_QCfE0.js";import"./RunJobButtons-BsCa9nZJ.js";import"./KubernetesProjectView-Dg2B5_rl.js";const $e=()=>{const h=v(),{id:t,jobName:r}=M(),o=_(),[l,{isLoading:a}]=B(),[b,{isLoading:w}]=O(),[j]=L(),[x]=$(),{data:c}=le(),S=a||w,{currentData:s,isFetching:g}=I({pId:t,jobName:r}),{handleDeleteJob:y,isDeleting:f}=ce(),N=m.useMemo(()=>s?[s.config]:[],[s]);G(`${H.editJob} ${s==null?void 0:s.name}`);const[C,d]=K(),T=m.useCallback(async(i,he,be,p)=>{const F=R(W(Q))(i),k={...i[i.type],...F},{name:P}=await l({pId:t,data:q(s==null?void 0:s.config,k),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(z.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]),E=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(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:d,mainButtonProps:{"data-test":"delete-job",children:"Delete job",onClick:E,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}=X();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(()=>[Y[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{$e as default};
