import{b0 as E,u as U,aR as T,aZ as O,iY as $,je as B,jb as I,jc as R,iZ as Y,r as p,fY as _,iV as q,aX as G,aY as H,l as K,cW as Q,jd as V,g,e as i,j as a,a$ as Z,ap as z,bq as W,br as u,K as X,a as ee,aq as te,aG as P,fI as C,ha as ae,aT as ie}from"./index-d6499a22.js";import{J as oe,F as se}from"./Project-92985c5d.js";import{u as ne}from"./CronSchedule-fbc9dfa0.js";import{S as re}from"./JobOverviewContent-8579bcd1.js";import"./index-ddf2d065.js";import"./FileUploaderButton-c4f1b533.js";import"./useDownload-7167ff3b.js";import"./useCurrentProject-b23444be.js";import"./useProject-0d0fdeb3.js";import"./PrimaryIconButton-fd23494f.js";import"./zipObj-e651182a.js";import"./dumbPluralize-86a9b9d6.js";import"./git-d9965c1a.js";import"./NoData-789df290.js";import"./index-da50fbe6.js";import"./file-utils-b5704e1c.js";import"./alertManagerConfig.selectors-c57f191b.js";import"./LabelValue-a44f78b2.js";import"./index-68a12294.js";import"./FileContent-cc0a5bee.js";import"./CardActionButton-ccf1bc35.js";import"./clamp-59d13d39.js";import"./jupyter.selectors-97655dc7.js";import"./utils-945d70a6.js";import"./objectWithoutPropertiesLoose-4f48578a.js";import"./index-038a72d6.js";import"./Table-658893b7.js";import"./setPrototypeOf-8d862a7d.js";import"./index-a7bc7f2c.js";import"./useKeyPress-4de66b82.js";import"./Panel-b19e8cc0.js";import"./Deprecated-ec8916ed.js";import"./DateValue-ebd6577f.js";import"./JobsExecutionsPopup-e71ef79a.js";import"./JobsService-aa6e1c55.js";const He=()=>{const m=E(),{id:e,jobName:r}=U(),o=T(),s=O(),[j,{isLoading:y}]=$(),[f,{isLoading:h}]=B(),[x,{isLoading:F}]=I(),[S]=R(),[N]=Y(),{data:l}=ne(),{handleDelete:J}=p.useContext(_),A=y||F,{currentData:t,isFetching:b}=q({pId:e,jobName:r}),w=p.useMemo(()=>t?[t.config]:[],[t]);G(`${H.editJob} ${t==null?void 0:t.name}`);const[k,d]=K(),D=p.useCallback(async(n,de,ce,c)=>{const{name:v}=await j({pId:e,data:Q(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(V.updateQueryData("getJobSchedule",{pId:e,jobName:r},M=>{Object.assign(M,{deleted:!0})}))),!l&&c&&await N({pId:e,data:c,jobName:n.appName}),v&&o(g(i.jobs.overview,i.project.value,{id:e,jobName:v}))},[N,S,m,t==null?void 0:t.config,r,o,l,e,j,x]),L=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&&w.length>0&&a.jsx(oe,{isLoading:b,isDisabled:A||h,initialData:w,submitHandler:D,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:k,onClose:d,mainButtonProps:{"data-test":"delete-job",children:"Delete job",onClick:L,disabled:b,isLoading:h},secondaryButtonProps:{children:"Back",onClick:d,disabled:h||b}})]})},le=({advanceConfig:m,jobData:e,handleToggle:r})=>{const{register:o,setValue:s}=z();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(W,{children:[a.jsx(u,{name:i.jobAnchors.jobDetails,children:a.jsx(X,{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(P,{...o("appName"),placeholder:"name",label:"Name",labelProps:{width:"320px"},readOnly:!0}),a.jsx(P,{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{He as default};
