import{aD as k,bw as L,u as J,r as C,hY as B,hZ as M,bC as H,j as e,L as Y,B as h,bq as O,b3 as V,bk as W,m as Z,bK as $,b4 as K,aM as A,b8 as U,b9 as q,ds as D,aG as S,as as G,Z as Q,af as z,ag as R,q as I,s as w,p as X,bz as ee,a3 as ae,gp as te,bD as se}from"./index-dP1W1_bd.js";import{a as oe,J as ie}from"./JobEnvPopover-C860_kHJ.js";import{W as re,a4 as ne,Y as le,Z as F,C as pe,$ as ce,a0 as me}from"./Project-CsYwwOpN.js";import{D as de,d as ue}from"./useDownload-C3yCvYJa.js";import{A as he}from"./AlertForm-DGh3QYA7.js";import{N as be}from"./NotebookJobArgsCallout-CuWfLFRW.js";import{K as fe}from"./KubernetesProjectEdit-CcUpiV79.js";import"./ButtonWithRole-CF64B_Or.js";import"./alertManagerConfig.selectors-B_R5cvew.js";import"./__-BIxbRvwe.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"./length-BzpOfCdE.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"./Anchor-B_lGyhCa.js";import"./useProject-CXVt1xnE.js";const Ke=()=>{const b=k(),y=L(),{id:i}=J(),[f,j]=C.useState(!1),[l,{isLoading:E}]=B(),[c]=M(),{isLoading:P,data:m}=re(),a=async(t,o,v,r)=>{j(!0);try{await ie.getOneByName(+i,t.appName),v("appName",{message:"This name is already in use"})}catch{const p={...X(...ee(ae).map(s=>te(s)))(t),...t[t.type]},{name:d}=await l({pId:i,data:p,name:p.appName}).unwrap();if(d){if(o&&o.length>1){const s={items:o};await b.jobAlert.createBulk({projectId:i,jobName:t.appName,jobAlert:s})}else o&&o.length===1&&await b.jobAlert.create({projectId:i,jobName:t.appName,jobAlert:o[0]});r&&await c({pId:i,data:r,jobName:d}).unwrap(),y(I(w.jobs.overview,w.project.value,{id:i,jobName:d}))}}finally{j(!1)}};return H(se.createJob),m?e.jsx(h,{flexDirection:"column",children:e.jsx(ne,{initialData:m,submitHandler:a,saveButtonText:"Create new job",isLoading:P,isDisabled:f||E,isSubmiting:f,jobTypeId:_,children:t=>e.jsx(je,{...t})})}):e.jsx(Y,{})},_="job-type-placeholder",je=({advanceConfig:b,setAlertState:y,setAlertError:i,alertError:f,alertState:j,type:l})=>{const{id:E}=J(),{state:c}=O(),{formState:{errors:P},register:m,setValue:a,control:t,clearErrors:o,setError:v}=V(),[r,T,x]=W({control:t,name:["appPath","appName","schedule"]});C.useEffect(()=>{if(c){const{appName:s,appPath:g,mainClass:N,schedule:n,type:u}=c;s&&a("appName",s),N&&a("mainClass",N),n&&setTimeout(()=>a("schedule",n)),g&&setTimeout(()=>a("appPath",g)),u&&setTimeout(()=>a("type",u))}},[c,a]),C.useEffect(()=>{!T&&r&&(a("appName",de(ue(r))),o("appName"))},[r,a]);const p=le(l.toUpperCase()),d=C.useMemo(()=>[l],[l]);return e.jsxs(e.Fragment,{children:[e.jsx(Z,{title:"Create new job",actions:e.jsx(oe,{jobType:p}),children:e.jsxs(h,{flexDirection:"column",sx:{gap:"20px"},children:[e.jsxs(h,{flexDirection:"column",gap:"8px",children:[e.jsx($,{children:"Type"}),e.jsx("div",{id:_})]}),F.includes(p)&&e.jsx(pe,{name:"appPath",label:"File",fileExplorerMode:K.oneFile,validExtensions:l==="spark"?[".py",".jar",".ipynb"]:[".py",".ipynb"],filePathPrefix:"hdfs://"}),e.jsx(A,{...m("appName"),placeholder:"name",label:"Name",labelProps:{width:"230px"},...U("appName",P)}),(r??"").endsWith(".ipynb")&&e.jsx(be,{}),F.includes(p)&&e.jsx(A,{optional:!0,...m("defaultArgs"),disabled:!r,placeholder:"args",label:"Default arguments",labelProps:{width:"100%"}})]})}),e.jsx(q,{control:t,name:"schedule",render:({field:{value:s,onChange:g},fieldState:{error:N}})=>e.jsxs(D,{width:"100%",title:"Schedule",children:[!x&&e.jsx(S,{onClick:()=>a("schedule",ce),intent:"inline",loadingOnly:!0,children:"Add schedule"}),x&&e.jsxs(h,{children:[e.jsx(h,{flex:"1",grow:"1",children:e.jsx(me,{value:x,onChange:n=>g({...s,...n}),onError:(n,u)=>u?v(`schedule.${n}`,{message:u}):o(`schedule.${n}`),error:N})}),e.jsx(G,{icon:Q.bin,color:"labels.red",sx:{cursor:"pointer",height:"fit-content"},onClick:()=>a("schedule",null)})]})]})}),e.jsx(fe,{prefix:d,init:!0}),e.jsxs(D,{width:"100%",title:"Advanced configuration",children:[e.jsx(z,{mb:"20px",type:R.neutral,content:"This job will use the default configuration. You can still override it by editing the following fields.",cta:e.jsx(S,{intent:"secondary",href:I(w.project.settings.computeConfiguration,w.project.value,{id:E}),children:"Go to default configuration"})}),b]}),e.jsx(he,{type:"job",alerts:j,setAlerts:s=>{y([...s]),i(void 0)},error:f})]})};export{Ke as default};
