import{aD as B,u as M,bL as L,hY as O,gN as U,ia as Q,hZ as D,hX as R,r as m,bC as _,bD as $,c as z,c3 as I,bz as K,a3 as V,d0 as W,ib as G,s as n,j as e,bE as H,b3 as X,ig as Y,m as Z,B as q,b4 as ee,aM as J,ds as y}from"./index-dP1W1_bd.js";import{A as te,a as d}from"./Anchor-B_lGyhCa.js";import{a4 as ie,C as oe}from"./Project-CsYwwOpN.js";import{B as se}from"./ButtonWithRole-CF64B_Or.js";import{S as ae}from"./ServiceAlertList-DlanmsKI.js";import{u as ne}from"./CronSchedule-DOmhKR6R.js";import{u as re,S as le}from"./JobOverviewContent-D1L8tVMu.js";import{N as ce}from"./NotebookJobArgsCallout-CuWfLFRW.js";import{K as pe}from"./KubernetesProjectEdit-CcUpiV79.js";import"./alertManagerConfig.selectors-B_R5cvew.js";import"./__-BIxbRvwe.js";import"./useDownload-C3yCvYJa.js";import"./useProject-CXVt1xnE.js";import"./length-BzpOfCdE.js";import"./complement-D_Q2yZKt.js";import"./index-MHdXqM53.js";import"./FileUploaderButton-frSujVRY.js";import"./uniq-98MdbBvs.js";import"./uniqBy-6mvKp2Ip.js";import"./dumbPluralize-CcxDsNiu.js";import"./CardActionButton-BtCnEqTK.js";import"./utils-UGwNsahk.js";import"./useKeyPress-OcDHupLZ.js";import"./zipObj-DEkcXp9d.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-mJT60wVA.js";import"./git-C8OLuEaG.js";import"./NoData-DLZ_8GEo.js";import"./useCopyToClipboard-DTBM3H3Z.js";import"./index-DOE28Q4t.js";import"./LabelValue-Dfx1zREE.js";import"./Panel-M9AVvYdm.js";import"./Deprecated-ClfPkp7s.js";import"./index-DqSuv-hx.js";import"./DateValue-CtaZM5mK.js";import"./RunJobButtons-DSvxdWvu.js";import"./KubernetesProjectView-BmUKZjhj.js";const Ye=()=>{const u=B(),{id:t,jobName:r}=M(),s=L(),[a,{isLoading:h}]=O(),[f,{isLoading:C}]=U(),[x]=Q(),[j]=D(),{data:l}=ne(),N=h||C,{currentData:i,isFetching:b}=R({pId:t,jobName:r}),{handleDeleteJob:S,isDeleting:g}=re(),A=m.useMemo(()=>i?[i.config]:[],[i]);_(`${$.editJob} ${i==null?void 0:i.name}`);const[w,c]=z(),k=m.useCallback(async(o,me,ue,p)=>{const E=I(K(V))(o),F={...o[o.type],...E},{name:P}=await a({pId:t,data:W(i==null?void 0:i.config,F),name:o.appName}).unwrap();l&&p&&await f({pId:t,data:{...l,...p},jobName:o.appName}).unwrap(),l&&!p&&(await x({pId:t,jobName:o.appName}),u(G.updateQueryData("getJobSchedule",{pId:t,jobName:r},T=>{Object.assign(T,{deleted:!0})}))),!l&&p&&await j({pId:t,data:p,jobName:o.appName}),P&&s(n.jobs.overview,{jobName:P})},[j,x,u,i==null?void 0:i.config,r,s,l,t,a,f]),v=m.useCallback(async()=>{i&&(await S(i.name),c(),s(n.jobs.list))},[i,S,c,s]);return e.jsxs(e.Fragment,{children:[i&&A.length>0&&e.jsx(ie,{isLoading:b,isDisabled:N||g,initialData:A,submitHandler:k,isSubmiting:N,disabledJobTypeChange:!0,checkedAdvancedConfig:!0,isEdit:!0,children:o=>e.jsx(de,{...o,jobData:i,handleToggle:c})}),e.jsx(H,{title:`Delete ${i==null?void 0:i.name}`,secondaryText:"Once you delete a job, there is no going back. Please be certain.",isOpen:w,onClose:c,mainButtonProps:{"data-test":"delete-job",children:"Delete job",onClick:v,disabled:b,isLoading:g},secondaryButtonProps:{children:"Back",onClick:c,disabled:g||b}})]})},de=({advanceConfig:u,jobData:t,handleToggle:r})=>{const{register:s,setValue:a}=X();m.useEffect(()=>{a("appName",t.config.appName),setTimeout(()=>a("appPath",t.config.appPath)),a("defaultArgs",t.config.defaultArgs??"")},[t,t.appName,t.appPath,t.defaultArgs,t.config.schedulingConfig,a]);const h=m.useMemo(()=>[Y[t.jobType]??""],[t]);return e.jsxs(te,{children:[e.jsx(d,{name:n.jobAnchors.jobDetails,children:e.jsx(Z,{title:"Edit job",children:e.jsxs(q,{flexDirection:"column",sx:{gap:"20px"},children:[e.jsx(oe,{name:"appPath",label:"File",fileExplorerMode:ee.oneFile,filePathPrefix:"hdfs://",disabled:!0}),e.jsx(J,{...s("appName"),placeholder:"name",label:"Name",labelProps:{width:"320px"},readOnly:!0}),(t.config.appPath??"").endsWith(".ipynb")&&e.jsx(ce,{}),e.jsx(J,{optional:!0,...s("defaultArgs"),placeholder:"args",label:"Default arguments",labelProps:{width:"100%"}})]})})}),e.jsx(d,{name:n.jobAnchors.schedule,children:e.jsx(le,{withoutSave:!0})}),e.jsx(d,{name:n.jobAnchors.kubernetesScheduler,children:e.jsx(pe,{prefix:h,init:!1})}),e.jsx(d,{name:n.jobAnchors.config,children:e.jsx(y,{width:"100%",title:"Advanced configuration",children:u})}),e.jsx(d,{name:n.jobAnchors.alerts,children:e.jsx(ae,{type:"job",job:t,mb:"0"})}),e.jsx(y,{title:"Danger zone",children:e.jsx(se,{intent:"alert",onClick:r,children:"Delete job"})})]})};export{Ye as default};
