import{bI as v,u as M,b9 as O,kg as _,ht as B,kr as L,kh as I,ke as R,r as u,bx as W,by as K,y as $,c8 as G,bt as H,a2 as Q,dp as V,ks as z,t as n,j as e,bA as Y,aR as Z,kw as q,W as D,a as X,aS as ee,aH as A,dV as J,bs as te}from"./index-_eM6l4Nf.js";import{A as se,a as m}from"./Anchor-JEsUSbQH.js";import{P as ae,F as ie,Q as oe,G as ne}from"./Project-BTH4PZdL.js";import{S as re}from"./ServiceAlertList-BHObHhAU.js";import{u as le}from"./CronSchedule-NEAzex5S.js";import{u as ce,S as pe}from"./JobOverviewContent-C2qLvj1L.js";import{N as de}from"./NotebookJobArgsCallout-Hgrtc_nv.js";import{K as me}from"./KubernetesProjectEdit-CZi-T2Qi.js";import"./alertManagerConfig.selectors-B-zYrdGC.js";import"./complement-CE-nEpWn.js";import"./index-B-5JhFyZ.js";import"./form-CMT9TYED.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-BIbwssIf.js";import"./git-BLdzamrJ.js";import"./useCopyToClipboard-BUvZjse8.js";import"./index-CpvNjjPQ.js";import"./LabelValue-CRG5UPNe.js";import"./Panel-BNKhRIJO.js";import"./Deprecated-Cn0z8EIY.js";import"./index-DUD8N5ck.js";import"./DateValue-83vgkOK-.js";import"./RunJobButtons-COeFEBke.js";import"./KubernetesProjectView-XdEEUXJt.js";const Re=()=>{const h=v(),{id:t,jobName:r}=M(),i=O(),[l,{isLoading:o}]=_(),[b,{isLoading:k}]=B(),[x]=L(),[j]=I(),{data:c}=le(),y=o||k,{currentData:s,isFetching:g}=R({pId:t,jobName:r}),{handleDeleteJob:S,isDeleting:f}=ce(),P=u.useMemo(()=>s?[s.config]:[],[s]);W(`${K.editJob} ${s==null?void 0:s.name}`);const[w,p]=$(),C=u.useCallback(async(a,he,be,d)=>{const E=G(H(Q))(a),F={...a[a.type],...E},{name:N}=await l({pId:t,data:V(s==null?void 0:s.config,F),name:a.appName}).unwrap();c&&d&&await b({pId:t,data:{...c,...d},jobName:a.appName}).unwrap(),c&&!d&&(await x({pId:t,jobName:a.appName}),h(z.updateQueryData("getJobSchedule",{pId:t,jobName:r},U=>{Object.assign(U,{deleted:!0})}))),!c&&d&&await j({pId:t,data:d,jobName:a.appName}),N&&i(n.project.jobs.overview,{jobName:N})},[j,x,h,s==null?void 0:s.config,r,i,c,t,l,b]),T=u.useCallback(async()=>{s&&(await S(s.name),p(),i(n.project.jobs.list))},[s,S,p,i]);return e.jsxs(e.Fragment,{children:[s&&P.length>0&&e.jsx(ae,{isLoading:g,isDisabled:y||f,initialData:P,submitHandler:C,isSubmiting:y,disabledJobTypeChange:!0,isEdit:!0,children:a=>e.jsx(ue,{...a,jobData:s,handleToggle:p})}),e.jsx(Y,{title:`Delete ${s==null?void 0:s.name}`,secondaryText:"Once you delete a job, there is no going back. Please be certain.",isOpen:w,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:i})=>{const{register:l,setValue:o}=Z();u.useEffect(()=>{setTimeout(()=>{o("appName",t.config.appName),o("appPath",t.config.appPath),o("defaultArgs",t.config.defaultArgs??""),o("type",t.config.type)})},[t,t.appName,t.appPath,t.defaultArgs,t.config.schedulingConfig,o]);const b=u.useMemo(()=>[q[t.jobType]??""],[t]);return e.jsxs(se,{children:[e.jsx(m,{name:n.jobAnchors.jobDetails,children:e.jsx(D,{title:"Edit job",children:e.jsxs(X,{flexDirection:"column",sx:{gap:"20px"},children:[e.jsx(ie,{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")&&i==="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:oe.includes(ne(i.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{Re as default};
