import{bH as U,bo as $,u as H,r as T,jE as M,jF as Y,bw as G,bx as K,j as e,D as W,$ as b,p as V,bs as q,a2 as L,gI as R,o as k,q as y,bg as z,aG as Q,bc as X,jG as Z,aT as ee,b as ae,bF as te,aH as se,b2 as A,aN as oe,dS as D,a3 as ie,a5 as re,b1 as _,aO as ne,ap as le,C as pe}from"./index-46ma1THH.js";import{J as ce,a as me}from"./JobEnvPopover-CNs9Spps.js";import{y as ue,M as de,z as be,B as he,J as I,F as fe,G as je,H as xe,N as ge}from"./Project-DqNODNns.js";import{A as Ne}from"./AlertForm-BcJ4dT7r.js";import{N as Te}from"./NotebookJobArgsCallout-D89NQ2Z8.js";import{K as ye}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"./Anchor-VqM1KJ3L.js";const Oe=()=>{const h=U(),C=$(),{id:i}=H(),[f,j]=T.useState(!1),[p,{isLoading:P}]=M(),[c]=Y(),{isLoading:w,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={...V(...q(L).map(s=>R(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(),C(k(y.project.jobs.overview,y.project.value,{id:i,jobName:u}))}}finally{j(!1)}};return G(K.createJob),m?e.jsx(b,{flexDirection:"column",children:e.jsx(de,{initialData:m,submitHandler:a,saveButtonText:"Create new job",isLoading:w,isDisabled:f||P,isSubmiting:f,jobTypeId:O,children:t=>e.jsx(Ce,{...t})})}):e.jsx(W,{})},O="job-type-placeholder",Ce=({advanceConfig:h,setAlertState:C,setAlertError:i,alertError:f,alertState:j,type:p})=>{const{id:P}=H(),{state:c}=z(),{formState:{errors:w},register:m,setValue:a,control:t,clearErrors:o,setError:E}=Q(),[r,S,x]=X({control:t,name:["appPath","appName","schedule"]});T.useEffect(()=>{var s;if(c){const{appName:g,appPath:N,mainClass:l,schedule:d,type:v,...B}=c,F=be(v).toLocaleLowerCase(),J=(s=B[F])==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)),J&&setTimeout(()=>a(`${F}.environmentName`,J))}},[c,a]),T.useEffect(()=>{!S&&r&&(a("appName",Z(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:O})]}),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(A,{...m("appName"),placeholder:"name",label:"Name",labelProps:{width:"230px"},...oe("appName",w)}),(r??"").endsWith(".ipynb")&&n===L.PYTHON&&e.jsx(Te,{}),I.includes(n)&&e.jsx(A,{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:k(y.project.settings.computeConfiguration,y.project.value,{id:P}),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(ye,{prefix:u,enabledKueue:ge.includes(n),init:!0}),e.jsx(Ne,{type:"job",alerts:j,setAlerts:s=>{C([...s]),i(void 0)},error:f})]})};export{Oe as default};
