import{bW as O,bx as U,u as k,r as T,kz as Y,kA as W,bG as $,bH as K,j as e,L as G,q as b,p as R,bC as V,a3 as H,hS as q,t as L,x as P,bp as Z,aR as z,bd as Q,l3 as X,b3 as ee,f as ae,bl as te,aS as se,aH as J,aY as oe,bk as D,a4 as ie,a5 as re,aJ as _,aZ as ne,ao as le,v as pe}from"./index-DNBEEyYo.js";import{J as ce,a as me}from"./JobEnvPopover-Dl0Ly-Br.js";import{B as ue,M as de,G as be,H as he,J as I,F as fe,w as je,x as xe,N as ge}from"./Project-D_38ySn9.js";import{A as Ne}from"./AlertForm-BOLtC7QE.js";import{N as Te}from"./NotebookJobArgsCallout-D6jvm89Q.js";import{K as Pe}from"./KubernetesProjectEdit-CgGaVg-Q.js";import"./alertManagerConfig.selectors-6Q6ry9ha.js";import"./defineProperty-9LKwahlh.js";import"./HumanizedCronExpression-Cc3xtXqn.js";import"./index-DivQJV92.js";import"./form-nDhxPMre.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-lQ_DaX5E.js";import"./index-Burx7Ja_.js";import"./git-BLdzamrJ.js";import"./useCopyToClipboard-BnywFRQi.js";const Oe=()=>{const h=O(),w=U(),{id:i}=k(),[f,j]=T.useState(!1),[p,{isLoading:y}]=Y(),[c]=W(),{isLoading:C,data:m}=ue(),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={...R(...V(H).map(s=>q(s)))(t),...t[t.type]},{name:u}=await p({pId:i,data:n,name:n.appName}).unwrap();if(u){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:u}).unwrap(),w(L(P.project.jobs.overview,P.project.value,{id:i,jobName:u}))}}finally{j(!1)}};return $(K.createJob),m?e.jsx(b,{flexDirection:"column",children:e.jsx(de,{initialData:m,submitHandler:a,saveButtonText:"Create new job",isLoading:C,isDisabled:f||y,isSubmiting:f,jobTypeId:B,children:t=>e.jsx(we,{...t})})}):e.jsx(G,{})},B="job-type-placeholder",we=({advanceConfig:h,setAlertState:w,setAlertError:i,alertError:f,alertState:j,type:p})=>{const{id:y}=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:d,type:v,...M}=c,A=be(v).toLocaleLowerCase(),F=(s=M[A])==null?void 0:s.environmentName;g&&setTimeout(()=>a("appName",g)),l&&setTimeout(()=>a("mainClass",l)),d&&setTimeout(()=>a("schedule",d)),N&&setTimeout(()=>a("appPath",N)),v&&setTimeout(()=>a("type",v)),F&&setTimeout(()=>a(`${A}.environmentName`,F))}},[c,a]),T.useEffect(()=>{!S&&r&&(a("appName",X(ee(r))),o("appName"))},[r,a]);const n=he(p.toUpperCase()),u=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})]}),I.includes(n)&&e.jsx(fe,{name:"appPath",label:"File",fileExplorerMode:se.oneFile,validExtensions:p==="spark"?[".py",".jar",".ipynb"]:[".py",".ipynb"],filePathPrefix:"hdfs://"}),e.jsx(J,{...m("appName"),placeholder:"name",label:"Name",labelProps:{width:"230px"},...oe("appName",C)}),(r??"").endsWith(".ipynb")&&n===H.PYTHON&&e.jsx(Te,{}),I.includes(n)&&e.jsx(J,{optional:!0,...m("defaultArgs"),disabled:!r,placeholder:"args",label:"Default arguments",labelProps:{width:"100%"}})]})}),e.jsxs(D,{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(_,{intent:"secondary",href:L(P.project.settings.computeConfiguration,P.project.value,{id:y}),children:"Go to default configuration"})}),h]}),e.jsx(ne,{control:t,name:"schedule",render:({field:{value:s,onChange:g},fieldState:{error:N}})=>e.jsxs(D,{width:"100%",title:"Schedule",children:[!x&&e.jsx(_,{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,d)=>d?E(`schedule.${l}`,{message:d}):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(Pe,{prefix:u,enabledKueue:ge.includes(n),init:!0}),e.jsx(Ne,{type:"job",alerts:j,setAlerts:s=>{w([...s]),i(void 0)},error:f})]})};export{Oe as default};
