import{bI as U,bo as W,u as k,r as T,kg as Y,kh as K,bx as M,by as $,j as e,D as V,a as b,p as G,bt as R,a2 as L,gX as X,s as H,t as y,bg as Z,aR as z,bc as Q,ki as q,b1 as ee,W as ae,bG as te,aS as se,aH as F,aY as oe,dV as I,a3 as ie,a5 as re,aJ as D,aZ as ne,ap as le,d as pe}from"./index-_eM6l4Nf.js";import{J as ce,a as me}from"./JobEnvPopover-D63Vw6dj.js";import{z as de,P as ue,B as be,G as he,J as _,F as fe,I as je,K as xe,Q as ge}from"./Project-BTH4PZdL.js";import{A as Ne}from"./AlertForm-CPn3G8rh.js";import{N as Te}from"./NotebookJobArgsCallout-Hgrtc_nv.js";import{K as ye}from"./KubernetesProjectEdit-CZi-T2Qi.js";import"./alertManagerConfig.selectors-B-zYrdGC.js";import"./complement-CE-nEpWn.js";import"./index-B-5JhFyZ.js";import"./form-CMT9TYED.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-BIbwssIf.js";import"./git-BLdzamrJ.js";import"./useCopyToClipboard-BUvZjse8.js";import"./Anchor-JEsUSbQH.js";const Oe=()=>{const h=U(),P=W(),{id:i}=k(),[f,j]=T.useState(!1),[p,{isLoading:w}]=Y(),[c]=K(),{isLoading:C,data:m}=de(),a=async(t,o,E,r)=>{j(!0);try{await ce.getOneByName(+i,t.appName),E("appName",{message:"This name is already in use"})}catch{const n={...G(...R(L).map(s=>X(s)))(t),...t[t.type]},{name:d}=await p({pId:i,data:n,name:n.appName}).unwrap();if(d){if(o&&o.length>1){const s={items:o};await h.jobAlert.createBulk({projectId:i,jobName:t.appName,jobAlert:s})}else o&&o.length===1&&await h.jobAlert.create({projectId:i,jobName:t.appName,jobAlert:o[0]});r&&await c({pId:i,data:r,jobName:d}).unwrap(),P(H(y.project.jobs.overview,y.project.value,{id:i,jobName:d}))}}finally{j(!1)}};return M($.createJob),m?e.jsx(b,{flexDirection:"column",children:e.jsx(ue,{initialData:m,submitHandler:a,saveButtonText:"Create new job",isLoading:C,isDisabled:f||w,isSubmiting:f,jobTypeId:B,children:t=>e.jsx(Pe,{...t})})}):e.jsx(V,{})},B="job-type-placeholder",Pe=({advanceConfig:h,setAlertState:P,setAlertError:i,alertError:f,alertState:j,type:p})=>{const{id:w}=k(),{state:c}=Z(),{formState:{errors:C},register:m,setValue:a,control:t,clearErrors:o,setError:E}=z(),[r,S,x]=Q({control:t,name:["appPath","appName","schedule"]});T.useEffect(()=>{var s;if(c){const{appName:g,appPath:N,mainClass:l,schedule:u,type:v,...O}=c,J=be(v).toLocaleLowerCase(),A=(s=O[J])==null?void 0:s.environmentName;g&&setTimeout(()=>a("appName",g)),l&&setTimeout(()=>a("mainClass",l)),u&&setTimeout(()=>a("schedule",u)),N&&setTimeout(()=>a("appPath",N)),v&&setTimeout(()=>a("type",v)),A&&setTimeout(()=>a(`${J}.environmentName`,A))}},[c,a]),T.useEffect(()=>{!S&&r&&(a("appName",q(ee(r))),o("appName"))},[r,a]);const n=he(p.toUpperCase()),d=T.useMemo(()=>[p],[p]);return e.jsxs(e.Fragment,{children:[e.jsx(ae,{title:"Create new job",actions:e.jsx(me,{jobType:n}),children:e.jsxs(b,{flexDirection:"column",sx:{gap:"20px"},children:[e.jsxs(b,{flexDirection:"column",gap:"8px",children:[e.jsx(te,{children:"Type"}),e.jsx("div",{id:B})]}),_.includes(n)&&e.jsx(fe,{name:"appPath",label:"File",fileExplorerMode:se.oneFile,validExtensions:p==="spark"?[".py",".jar",".ipynb"]:[".py",".ipynb"],filePathPrefix:"hdfs://"}),e.jsx(F,{...m("appName"),placeholder:"name",label:"Name",labelProps:{width:"230px"},...oe("appName",C)}),(r??"").endsWith(".ipynb")&&n===L.PYTHON&&e.jsx(Te,{}),_.includes(n)&&e.jsx(F,{optional:!0,...m("defaultArgs"),disabled:!r,placeholder:"args",label:"Default arguments",labelProps:{width:"100%"}})]})}),e.jsxs(I,{width:"100%",title:"Configuration",children:[e.jsx(ie,{mb:"20px",type:re.neutral,content:"This job will use the default configuration. You can still override it by editing the following fields.",cta:e.jsx(D,{intent:"secondary",href:H(y.project.settings.computeConfiguration,y.project.value,{id:w}),children:"Go to default configuration"})}),h]}),e.jsx(ne,{control:t,name:"schedule",render:({field:{value:s,onChange:g},fieldState:{error:N}})=>e.jsxs(I,{width:"100%",title:"Schedule",children:[!x&&e.jsx(D,{onClick:()=>a("schedule",je),intent:"inline",loadingOnly:!0,children:"Add schedule"}),x&&e.jsxs(b,{children:[e.jsx(b,{flex:"1",grow:"1",children:e.jsx(xe,{value:x,onChange:l=>g({...s,...l}),onError:(l,u)=>u?E(`schedule.${l}`,{message:u}):o(`schedule.${l}`),error:N})}),e.jsx(le,{icon:pe.bin,color:"labels.red",sx:{cursor:"pointer",height:"fit-content"},onClick:()=>a("schedule",null)})]})]})}),e.jsx(ye,{prefix:d,enabledKueue:ge.includes(n),init:!0}),e.jsx(Ne,{type:"job",alerts:j,setAlerts:s=>{P([...s]),i(void 0)},error:f})]})};export{Oe as default};
