import{bI as B,bp as k,u as I,r as b,jl as M,jm as H,bx as K,j as e,L as O,B as f,bi as U,aK as $,bc as G,jn as V,aX as W,y as Y,bG as R,aL as q,b5 as J,aR as z,aS as X,dz as S,b4 as F,au as Q,C as Z,ah as ee,ai as ae,q as L,s as w,f as te,bu as se,a0 as oe,gJ as ie,by as re}from"./index-C1DmWO_C.js";import{a as ne,J as le}from"./JobEnvPopover-VQSWpWKX.js";import{y as pe,K as ce,B as me,J as D,F as de,C as ue,G as he}from"./Project-CpwJZ-CK.js";import{A as be}from"./AlertForm-CkZ7DISl.js";import{N as fe}from"./NotebookJobArgsCallout-7tIiXwQk.js";import{K as je}from"./KubernetesProjectEdit-O522bxXP.js";import"./alertManagerConfig.selectors-B9ELaxCY.js";import"./index-Dub34MAX.js";import"./FileUploaderButton-BtxUzlTS.js";import"./zipObj-D8EtfWld.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-B3GPGppJ.js";import"./git-C8OLuEaG.js";import"./NoData-Y_e6mfNf.js";import"./useCopyToClipboard-v9FBn9Nz.js";import"./Anchor-DFXOcnPw.js";const _e=()=>{const j=B(),P=k(),{id:o}=I(),[x,g]=b.useState(!1),[n,{isLoading:E}]=M(),[c]=H(),{isLoading:T,data:m}=pe(),a=async(t,s,v,i)=>{g(!0);try{await le.getOneByName(+o,t.appName),v("appName",{message:"This name is already in use"})}catch{const l={...te(...se(oe).map(u=>ie(u)))(t),...t[t.type]},{name:d}=await n({pId:o,data:l,name:l.appName}).unwrap();if(d){if(s&&s.length>1){const u={items:s};await j.jobAlert.createBulk({projectId:o,jobName:t.appName,jobAlert:u})}else s&&s.length===1&&await j.jobAlert.create({projectId:o,jobName:t.appName,jobAlert:s[0]});i&&await c({pId:o,data:i,jobName:d}).unwrap(),P(L(w.jobs.overview,w.project.value,{id:o,jobName:d}))}}finally{g(!1)}};return K(re.createJob),m?e.jsx(f,{flexDirection:"column",children:e.jsx(ce,{initialData:m,submitHandler:a,saveButtonText:"Create new job",isLoading:T,isDisabled:x||E,isSubmiting:x,jobTypeId:_,children:t=>e.jsx(xe,{...t})})}):e.jsx(O,{})},_="job-type-placeholder",xe=({advanceConfig:j,setAlertState:P,setAlertError:o,alertError:x,alertState:g,type:n})=>{const{id:E}=I(),{state:c}=U(),{formState:{errors:T},register:m,setValue:a,control:t,clearErrors:s,setError:v}=$(),[i,A,N]=G({control:t,name:["appPath","appName","schedule"]});b.useEffect(()=>{if(c){const{appName:p,appPath:y,mainClass:C,schedule:r,type:h}=c;p&&a("appName",p),C&&a("mainClass",C),r&&setTimeout(()=>a("schedule",r)),y&&setTimeout(()=>a("appPath",y)),h&&setTimeout(()=>a("type",h))}},[c,a]),b.useEffect(()=>{!A&&i&&(a("appName",V(W(i))),s("appName"))},[i,a]);const l=me(n.toUpperCase()),d=b.useMemo(()=>[n],[n]),u=b.useMemo(()=>!0,[]);return e.jsxs(e.Fragment,{children:[e.jsx(Y,{title:"Create new job",actions:e.jsx(ne,{jobType:l}),children:e.jsxs(f,{flexDirection:"column",sx:{gap:"20px"},children:[e.jsxs(f,{flexDirection:"column",gap:"8px",children:[e.jsx(R,{children:"Type"}),e.jsx("div",{id:_})]}),D.includes(l)&&e.jsx(de,{name:"appPath",label:"File",fileExplorerMode:q.oneFile,validExtensions:n==="spark"?[".py",".jar",".ipynb"]:[".py",".ipynb"],filePathPrefix:"hdfs://"}),e.jsx(J,{...m("appName"),placeholder:"name",label:"Name",labelProps:{width:"230px"},...z("appName",T)}),(i??"").endsWith(".ipynb")&&e.jsx(fe,{}),D.includes(l)&&e.jsx(J,{optional:!0,...m("defaultArgs"),disabled:!i,placeholder:"args",label:"Default arguments",labelProps:{width:"100%"}})]})}),e.jsx(X,{control:t,name:"schedule",render:({field:{value:p,onChange:y},fieldState:{error:C}})=>e.jsxs(S,{width:"100%",title:"Schedule",children:[!N&&e.jsx(F,{onClick:()=>a("schedule",ue),intent:"inline",loadingOnly:!0,children:"Add schedule"}),N&&e.jsxs(f,{children:[e.jsx(f,{flex:"1",grow:"1",children:e.jsx(he,{value:N,onChange:r=>y({...p,...r}),onError:(r,h)=>h?v(`schedule.${r}`,{message:h}):s(`schedule.${r}`),error:C})}),e.jsx(Q,{icon:Z.bin,color:"labels.red",sx:{cursor:"pointer",height:"fit-content"},onClick:()=>a("schedule",null)})]})]})}),e.jsx(je,{prefix:d,init:u}),e.jsxs(S,{width:"100%",title:"Advanced configuration",children:[e.jsx(ee,{mb:"20px",type:ae.neutral,content:"This job will use the default configuration. You can still override it by editing the following fields.",cta:e.jsx(F,{intent:"secondary",href:L(w.project.settings.computeConfiguration,w.project.value,{id:E}),children:"Go to default configuration"})}),j]}),e.jsx(be,{type:"job",alerts:g,setAlerts:p=>{P([...p]),o(void 0)},error:x})]})};export{_e as default};
