import{bf as _,b4 as L,u as S,r as C,hw as k,hx as V,bb as B,j as e,L as H,d as u,aY as M,ay as O,aO as Y,Q as U,aV as $,az as W,aR as v,aE as G,aF as Q,d0 as A,b6 as F,an as R,T as q,aa as z,ab as K,o as D,q as N,f as X,b8 as Z,Y as ee,fU as ae,bc as te}from"./index-CK33qGU_.js";import{a as se,J as oe}from"./JobEnvPopover-CwcceIHS.js";import{G as ie,P as re,I as ne,J,F as le,K as pe,M as ce}from"./Project-j3KdDsvH.js";import{E as me,d as de}from"./useDownload-hrjXceJg.js";import{A as ue}from"./AlertForm-BWXdFIuw.js";import{N as he}from"./NotebookJobArgsCallout-BePPd6f1.js";import"./ButtonWithRole-NHXEosto.js";import"./alertManagerConfig.selectors-BX2JGYEL.js";import"./__-BIxbRvwe.js";import"./complement-M2aUPqXA.js";import"./FileUploaderButton-Bppadu35.js";import"./dumbPluralize-CcxDsNiu.js";import"./PrimaryIconButton-DQUEhx3G.js";import"./zipObj-DQ8OxaYj.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./git-C8OLuEaG.js";import"./NoData-CuLyR2Bg.js";import"./useCopyToClipboard-_4vnCVip.js";import"./Anchor-HBBcGDu5.js";import"./useProject-BzBQtp4J.js";import"./length-fOfC3W0h.js";const Ve=()=>{const h=_(),y=L(),{id:i}=S(),[b,f]=C.useState(!1),[j,{isLoading:w}]=k(),[c]=V(),{isLoading:E,data:m}=ie(),a=async(t,o,T,r)=>{f(!0);try{await oe.getOneByName(+i,t.appName),T("appName",{message:"This name is already in use"})}catch{const p={...X(...Z(ee).map(n=>ae(n)))(t),...t[t.type]},{name:s}=await j({pId:i,data:p,name:p.appName}).unwrap();if(s){if(o&&o.length>1){const n={items:o};await h.jobAlert.createBulk({projectId:i,jobName:t.appName,jobAlert:n})}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:s}).unwrap(),y(D(N.jobs.overview,N.project.value,{id:i,jobName:s}))}}finally{f(!1)}};return B(te.createJob),m?e.jsx(u,{flexDirection:"column",children:e.jsx(re,{initialData:m,submitHandler:a,saveButtonText:"Create new job",isLoading:E,isDisabled:b||w,isSubmiting:b,jobTypeId:I,children:t=>e.jsx(be,{...t})})}):e.jsx(H,{})},I="job-type-placeholder",be=({advanceConfig:h,setAlertState:y,setAlertError:i,alertError:b,alertState:f,type:j})=>{const{id:w}=S(),{state:c}=M(),{formState:{errors:E},register:m,setValue:a,control:t,clearErrors:o,setError:T}=O(),[r,P,x]=Y({control:t,name:["appPath","appName","schedule"]});C.useEffect(()=>{if(c){const{appName:s,appPath:n,mainClass:g,schedule:l,type:d}=c;s&&a("appName",s),g&&a("mainClass",g),l&&setTimeout(()=>a("schedule",l)),n&&setTimeout(()=>a("appPath",n)),d&&setTimeout(()=>a("type",d))}},[c,a]),C.useEffect(()=>{!P&&r&&(a("appName",me(de(r))),o("appName"))},[r,a]);const p=ne(j.toUpperCase());return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Create new job",actions:e.jsx(se,{jobType:p}),children:e.jsxs(u,{flexDirection:"column",sx:{gap:"20px"},children:[e.jsxs(u,{flexDirection:"column",gap:"8px",children:[e.jsx($,{children:"Type"}),e.jsx("div",{id:I})]}),J.includes(p)&&e.jsx(le,{name:"appPath",label:"File",fileExplorerMode:W.oneFile,validExtensions:j==="spark"?[".py",".jar",".ipynb"]:[".py",".ipynb"],filePathPrefix:"hdfs://"}),e.jsx(v,{...m("appName"),placeholder:"name",label:"Name",labelProps:{width:"230px"},...G("appName",E)}),(r??"").endsWith(".ipynb")&&e.jsx(he,{}),J.includes(p)&&e.jsx(v,{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:n},fieldState:{error:g}})=>e.jsxs(A,{width:"100%",title:"Schedule",children:[!x&&e.jsx(F,{onClick:()=>a("schedule",pe),intent:"inline",loadingOnly:!0,children:"Add schedule"}),x&&e.jsxs(u,{children:[e.jsx(u,{flex:"1",grow:"1",children:e.jsx(ce,{value:x,onChange:l=>n({...s,...l}),onError:(l,d)=>d?T(`schedule.${l}`,{message:d}):o(`schedule.${l}`),error:g})}),e.jsx(R,{icon:q.bin,color:"labels.red",sx:{cursor:"pointer",height:"fit-content"},onClick:()=>a("schedule",null)})]})]})}),e.jsxs(A,{width:"100%",title:"Advanced configuration",children:[e.jsx(z,{mb:"20px",type:K.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:D(N.project.settings.computeConfiguration,N.project.value,{id:w}),children:"Go to default configuration"})}),h]}),e.jsx(ue,{type:"job",alerts:f,setAlerts:s=>{y([...s]),i(void 0)},error:b})]})};export{Ve as default};
