import{bW as U,u as v,ba as B,kA as O,iq as _,lc as L,kB as H,l2 as R,r as u,bG as $,bH as I,w as K,cl as W,bC as q,a3 as z,dI as G,ld as Q,x as n,j as e,bJ as V,aR as Y,lg as D,f as X,q as Z,aS as ee,aH as A,bk as J,bB as te}from"./index-Cox3ZWL0.js";import{A as se,g as m}from"./defineProperty-Bl0iR0r2.js";import{M as ie,F as oe,N as ae,H as ne}from"./Project-CBPFwDml.js";import{S as re}from"./ServiceAlertList-VvuXq15t.js";import{u as le}from"./CronSchedule-BX_J5ybN.js";import{u as ce,S as pe}from"./JobOverviewContent-Bn12bVpb.js";import{N as de}from"./NotebookJobArgsCallout-RotJDH-K.js";import{K as me}from"./KubernetesProjectEdit-fVArwJ6F.js";import"./alertManagerConfig.selectors-D5v0uPxO.js";import"./HumanizedCronExpression-CCEBWMyY.js";import"./index-CvEisYn5.js";import"./form-_K_-Blw_.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-DM6mun8f.js";import"./index-uwkRD1BL.js";import"./git-BLdzamrJ.js";import"./useCopyToClipboard-C9cjFU4I.js";import"./index-C7Rz9Es-.js";import"./LabelValue-BkTpmDa_.js";import"./Panel-Cu-mlmB5.js";import"./Deprecated-g8R65bmH.js";import"./index-B_EdXPH-.js";import"./DateValue-CuTPLbUr.js";import"./RunJobButtons-C-tcX_qk.js";import"./KubernetesProjectView-CST_ZK0x.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]);$(`${I.editJob} ${s==null?void 0:s.name}`);const[C,p]=K(),k=u.useCallback(async(i,he,be,d)=>{const E=W(q(z))(i),F={...i[i.type],...E},{name:y}=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}),y&&o(n.project.jobs.overview,{jobName:y})},[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(A,{...l("appName"),placeholder:"name",label:"Name",labelProps:{width:"320px"},readOnly:!0}),(t.config.appPath??"").endsWith(".ipynb")&&o==="python"&&e.jsx(de,{}),e.jsx(A,{optional:!0,...l("defaultArgs"),placeholder:"args",label:"Default arguments",labelProps:{width:"100%"}})]})})}),e.jsx(m,{name:n.jobAnchors.config,children:e.jsx(J,{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(J,{title:"Danger zone",children:e.jsx(te,{intent:"alert",onClick:r,children:"Delete job"})})]})};export{$e as default};
