import{b0 as P,aR as T,u as E,r as y,iY as I,iZ as L,aX as k,j as e,a_ as M,a as j,c9 as B,ap as H,aF as V,K as Y,aq as Z,aG as v,ax as _,ay as G,fI as A,aT as D,af as K,Z as O,a3 as R,a4 as U,g as J,e as b,iw as $,aY as q}from"./index-d6499a22.js";import{J as W}from"./JobsService-aa6e1c55.js";import{a as X,J as z,F as Q,D as ee,C as ae}from"./Project-92985c5d.js";import{m as te,b as se}from"./file-utils-b5704e1c.js";import"./index-ddf2d065.js";import"./FileUploaderButton-c4f1b533.js";import"./useDownload-7167ff3b.js";import"./useCurrentProject-b23444be.js";import"./useProject-0d0fdeb3.js";import"./PrimaryIconButton-fd23494f.js";import"./zipObj-e651182a.js";import"./dumbPluralize-86a9b9d6.js";import"./git-d9965c1a.js";import"./NoData-789df290.js";import"./index-da50fbe6.js";import"./alertManagerConfig.selectors-c57f191b.js";const we=()=>{const u=P(),x=T(),{id:i}=E(),[d,m]=y.useState(!1),[g,{isLoading:N}]=I(),[p]=L(),{isLoading:w,data:c}=X(),a=async(t,s,C,l)=>{m(!0);try{await W.getOneByName(+i,t.appName),C("appName",{message:"This name is already in use"})}catch{const{name:r}=await g({pId:i,data:t,name:t.appName}).unwrap();if(r){if(s&&s.length>1){const o={items:s};await u.jobAlert.createBulk({projectId:i,jobName:t.appName,jobAlert:o})}else s&&s.length===1&&await u.jobAlert.create({projectId:i,jobName:t.appName,jobAlert:s[0]});l&&await p({pId:i,data:l,jobName:r}).unwrap(),x(J(b.jobs.overview,b.project.value,{id:i,jobName:r}))}}finally{m(!1)}};return k(q.createJob),c?e.jsx(j,{flexDirection:"column",children:e.jsx(z,{initialData:c,submitHandler:a,saveButtonText:"Create new job",isLoading:w,isDisabled:d||N,isSubmiting:d,isJupyter:!1,isDefault:!0,children:t=>e.jsx(ie,{...t})})}):e.jsx(M,{})},ie=({advanceConfig:u,setAlertState:x,setAlertError:i,alertError:d,alertState:m,type:g})=>{const{id:N}=E(),{state:p}=B(),{formState:{errors:w},register:c,setValue:a,control:t,clearErrors:s,setError:C}=H(),[l,S,r]=V({control:t,name:["appPath","appName","schedule"]});return y.useEffect(()=>{if(p){const{appName:o,appPath:f,mainClass:h,schedule:n}=p;o&&a("appName",o),h&&a("mainClass",h),n&&setTimeout(()=>a("schedule",n)),f&&setTimeout(()=>a("appPath",f))}},[p,a]),y.useEffect(()=>{!S&&l&&(a("appName",te(se(l))),s("appName"))},[l,a]),e.jsxs(e.Fragment,{children:[e.jsx(Y,{title:"Create new job",children:e.jsxs(j,{flexDirection:"column",sx:{gap:"20px"},children:[e.jsx(Q,{name:"appPath",label:"File",fileExplorerMode:Z.oneFile,validExtensions:g==="spark"?[".py",".jar",".ipynb"]:[".py",".ipynb"],filePathPrefix:"hdfs://"}),e.jsx(v,{...c("appName"),placeholder:"name",label:"Name",labelProps:{width:"180px"},..._("appName",w)}),e.jsx(v,{optional:!0,...c("defaultArgs"),placeholder:"args",label:"Default arguments",labelProps:{width:"100%"}})]})}),e.jsx(G,{control:t,name:"schedule",render:({field:{value:o,onChange:f},fieldState:{error:h}})=>e.jsxs(A,{width:"100%",title:"Schedule",children:[!r&&e.jsx(D,{onClick:()=>a("schedule",ee),intent:"inline",loadingOnly:!0,children:"Add schedule"}),r&&e.jsxs(j,{children:[e.jsx(j,{flex:"1",grow:"1",children:e.jsx(ae,{value:r,onChange:n=>f({...o,...n}),onError:(n,F)=>F?C(`schedule.${n}`,{message:F}):s(`schedule.${n}`),error:h})}),e.jsx(K,{icon:O.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(R,{mb:"20px",type:U.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:J(b.project.settings.computeConfiguration,b.project.value,{id:N}),children:"Go to default configuration"})}),u]}),e.jsx($,{type:"job",alerts:m,setAlerts:o=>{x([...o]),i(void 0)},error:d})]})};export{we as default};
