import{b1 as M,u as U,aS as O,a_ as T,iX as B,jd as Q,ja as _,jb as $,iY as H,r as p,g1 as G,iU as I,aY as R,aZ as V,P as Y,cZ as Z,jc as q,c as g,b as i,j as a,b0 as z,aq as X,br as K,bs as u,E as W,Q as ee,ar as te,aH as v,fO as C,hc as ae,aU as ie}from"./index-ea7817a2.js";import{J as oe,F as se}from"./Project-80a71be4.js";import{u as ne}from"./CronSchedule-c484881b.js";import{S as re}from"./JobOverviewContent-064403df.js";import"./index-43e7382e.js";import"./FileUploaderButton-495e1c87.js";import"./useDownload-09eaf3eb.js";import"./useCurrentProject-0132f110.js";import"./useProject-77619fff.js";import"./PrimaryIconButton-fe990c52.js";import"./zipObj-08c84ab1.js";import"./dumbPluralize-86a9b9d6.js";import"./git-d9965c1a.js";import"./NoData-8733f606.js";import"./index-8f672200.js";import"./file-utils-a5f053e8.js";import"./alertManagerConfig.selectors-c57f191b.js";import"./LabelValue-bef10fa0.js";import"./index-077fa3a4.js";import"./FileContent-73ed3cd5.js";import"./CardActionButton-6aa39bc1.js";import"./clamp-298e1359.js";import"./jupyter.selectors-97655dc7.js";import"./utils-945d70a6.js";import"./index-ed9a2dda.js";import"./setPrototypeOf-c2b1cc7a.js";import"./objectWithoutPropertiesLoose-4f48578a.js";import"./index-1c428bf7.js";import"./Table-b6234bad.js";import"./memoize-one.esm-a97866ee.js";import"./useKeyPress-f1bed9d7.js";import"./index-aeb84278.js";import"./Panel-041c5d61.js";import"./Deprecated-9bfe2e44.js";import"./DateValue-1d129100.js";import"./JobsExecutionsPopup-5aad37e0.js";import"./JobsService-82e820b4.js";const Ze=()=>{const m=M(),{id:e,jobName:r}=U(),o=O(),s=T(),[j,{isLoading:y}]=B(),[f,{isLoading:h}]=Q(),[x,{isLoading:F}]=_(),[S]=$(),[N]=H(),{data:l}=ne(),{handleDelete:J}=p.useContext(G),A=y||F,{currentData:t,isFetching:b}=I({pId:e,jobName:r}),P=p.useMemo(()=>t?[t.config]:[],[t]);R(`${V.editJob} ${t==null?void 0:t.name}`);const[E,d]=Y(),k=p.useCallback(async(n,de,ce,c)=>{const{name:w}=await j({pId:e,data:Z(t.config,n),name:n.appName}).unwrap();l&&c&&await x({pId:e,data:{...l,...c},jobName:n.appName}).unwrap(),l&&!c&&(await S({pId:e,jobName:n.appName}),m(q.updateQueryData("getJobSchedule",{pId:e,jobName:r},L=>{Object.assign(L,{deleted:!0})}))),!l&&c&&await N({pId:e,data:c,jobName:n.appName}),w&&o(g(i.jobs.overview,i.project.value,{id:e,jobName:w}))},[N,S,m,t==null?void 0:t.config,r,o,l,e,j,x]),D=p.useCallback(async()=>{t&&(await f({pId:e,jobName:t.name}).unwrap(),J(g(i.jobs.overview,i.project.value,{id:e,jobName:t.name})),d(),o(g(i.jobs.list,i.project.value,{id:e})),s.success({title:"Job deleted",content:`${t.name} has been deleted`}))},[t,f,e,J,d,o,s]);return a.jsxs(a.Fragment,{children:[t&&P.length>0&&a.jsx(oe,{isLoading:b,isDisabled:A||h,initialData:P,submitHandler:k,isSubmiting:A,disabledJobTypeChange:!0,checkedAdvancedConfig:!0,isJupyter:!1,children:n=>a.jsx(le,{...n,jobData:t,handleToggle:d})}),a.jsx(z,{title:`Delete ${t==null?void 0:t.name}`,secondaryText:"Once you delete a job, there is no going back. Please be certain.",isOpen:E,onClose:d,mainButtonProps:{"data-test":"delete-job",children:"Delete job",onClick:D,disabled:b,isLoading:h},secondaryButtonProps:{children:"Back",onClick:d,disabled:h||b}})]})},le=({advanceConfig:m,jobData:e,handleToggle:r})=>{const{register:o,setValue:s}=X();return p.useEffect(()=>{s("appName",e.config.appName),setTimeout(()=>s("appPath",e.config.appPath)),s("defaultArgs",e.config.defaultArgs??"")},[e,e.appName,e.appPath,e.defaultArgs,s]),a.jsxs(K,{children:[a.jsx(u,{name:i.jobAnchors.jobDetails,children:a.jsx(W,{title:"Edit job",children:a.jsxs(ee,{flexDirection:"column",sx:{gap:"20px"},children:[a.jsx(se,{name:"appPath",label:"File",fileExplorerMode:te.oneFile,filePathPrefix:"hdfs://",disabled:!0}),a.jsx(v,{...o("appName"),placeholder:"name",label:"Name",labelProps:{width:"320px"},readOnly:!0}),a.jsx(v,{optional:!0,...o("defaultArgs"),placeholder:"args",label:"Default arguments",labelProps:{width:"100%"}})]})})}),a.jsx(u,{name:i.jobAnchors.schedule,children:a.jsx(re,{withoutSave:!0})}),a.jsx(u,{name:i.jobAnchors.config,children:a.jsx(C,{width:"100%",title:"Advanced configuration",children:m})}),a.jsx(u,{name:i.jobAnchors.alerts,children:a.jsx(ae,{type:"job",job:e,mb:"0"})}),a.jsx(C,{title:"Danger zone",children:a.jsx(ie,{intent:"alert",onClick:r,children:"Delete job"})})]})};export{Ze as default};
