import{bH as v,u as M,b9 as _,jE as B,hb as O,jU as L,jF as $,jC as H,r as m,bw as I,bx as K,y as R,c7 as G,bs as Q,a2 as W,dn as q,jV as z,q as n,j as e,bz as V,aG as Y,jZ as Z,b as D,$ as X,aH as ee,b2 as J,dS as A,br as te}from"./index-46ma1THH.js";import{A as se,a as u}from"./Anchor-VqM1KJ3L.js";import{M as ie,F as oe,N as ae,B as ne}from"./Project-DqNODNns.js";import{S as re}from"./ServiceAlertList-BRlmr1Cp.js";import{u as le}from"./CronSchedule-DN0xG5ja.js";import{u as ce,S as de}from"./JobOverviewContent-B92TNQIf.js";import{N as pe}from"./NotebookJobArgsCallout-D89NQ2Z8.js";import{K as ue}from"./KubernetesProjectEdit-DOgOIrBH.js";import"./alertManagerConfig.selectors-ByceE4ck.js";import"./complement-Cl658Mix.js";import"./index-CcWUz40c.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-Bbf2VNbK.js";import"./git-BLdzamrJ.js";import"./useCopyToClipboard-B8vQLvqE.js";import"./index-BOKQPbnb.js";import"./LabelValue-BwjawF6m.js";import"./Panel-CnxQ3Lqy.js";import"./Deprecated-CcWZugSq.js";import"./index-DoAo8g_G.js";import"./DateValue-DZGUc2od.js";import"./RunJobButtons-BrwusW96.js";import"./KubernetesProjectView-C1axEtBt.js";const $e=()=>{const h=v(),{id:t,jobName:r}=M(),o=_(),[l,{isLoading:a}]=B(),[b,{isLoading:w}]=O(),[j]=L(),[x]=$(),{data:c}=le(),S=a||w,{currentData:s,isFetching:g}=H({pId:t,jobName:r}),{handleDeleteJob:y,isDeleting:f}=ce(),N=m.useMemo(()=>s?[s.config]:[],[s]);I(`${K.editJob} ${s==null?void 0:s.name}`);const[C,d]=R(),T=m.useCallback(async(i,he,be,p)=>{const F=G(Q(W))(i),k={...i[i.type],...F},{name:P}=await l({pId:t,data:q(s==null?void 0:s.config,k),name:i.appName}).unwrap();c&&p&&await b({pId:t,data:{...c,...p},jobName:i.appName}).unwrap(),c&&!p&&(await j({pId:t,jobName:i.appName}),h(z.updateQueryData("getJobSchedule",{pId:t,jobName:r},U=>{Object.assign(U,{deleted:!0})}))),!c&&p&&await x({pId:t,data:p,jobName:i.appName}),P&&o(n.project.jobs.overview,{jobName:P})},[x,j,h,s==null?void 0:s.config,r,o,c,t,l,b]),E=m.useCallback(async()=>{s&&(await y(s.name),d(),o(n.project.jobs.list))},[s,y,d,o]);return e.jsxs(e.Fragment,{children:[s&&N.length>0&&e.jsx(ie,{isLoading:g,isDisabled:S||f,initialData:N,submitHandler:T,isSubmiting:S,disabledJobTypeChange:!0,isEdit:!0,children:i=>e.jsx(me,{...i,jobData:s,handleToggle:d})}),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:d,mainButtonProps:{"data-test":"delete-job",children:"Delete job",onClick:E,disabled:g,isLoading:f},secondaryButtonProps:{children:"Back",onClick:d,disabled:f||g}})]})},me=({advanceConfig:h,jobData:t,handleToggle:r,type:o})=>{const{register:l,setValue:a}=Y();m.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=m.useMemo(()=>[Z[t.jobType]??""],[t]);return e.jsxs(se,{children:[e.jsx(u,{name:n.jobAnchors.jobDetails,children:e.jsx(D,{title:"Edit job",children:e.jsxs(X,{flexDirection:"column",sx:{gap:"20px"},children:[e.jsx(oe,{name:"appPath",label:"File",fileExplorerMode:ee.oneFile,filePathPrefix:"hdfs://",disabled:!0}),e.jsx(J,{...l("appName"),placeholder:"name",label:"Name",labelProps:{width:"320px"},readOnly:!0}),(t.config.appPath??"").endsWith(".ipynb")&&o==="python"&&e.jsx(pe,{}),e.jsx(J,{optional:!0,...l("defaultArgs"),placeholder:"args",label:"Default arguments",labelProps:{width:"100%"}})]})})}),e.jsx(u,{name:n.jobAnchors.config,children:e.jsx(A,{width:"100%",title:"Configuration",children:h})}),e.jsx(u,{name:n.jobAnchors.schedule,children:e.jsx(de,{withoutSave:!0})}),e.jsx(u,{name:n.jobAnchors.kubernetesScheduler,children:e.jsx(ue,{prefix:b,init:!1,enabledKueue:ae.includes(ne(o.toUpperCase()))})}),e.jsx(u,{name:n.jobAnchors.alerts,children:e.jsx(re,{type:"job",job:t,mb:"0"})}),e.jsx(A,{title:"Danger zone",children:e.jsx(te,{intent:"alert",onClick:r,children:"Delete job"})})]})};export{$e as default};
