import{b1 as J,aS as I,u as P,r as y,iX as T,iY as L,aY as k,j as e,a$ as H,Q as b,ca as V,aq as z,aG as B,E as M,ar as O,aH as E,ay as U,az as Y,fO as A,aU as F,ag as $,z as G,a3 as Q,a4 as _,c as D,b as j,iv as q,aZ as R}from"./index-ea7817a2.js";import{J as W}from"./JobsService-82e820b4.js";import{a as X,J as Z,F as K,D as ee,C as ae}from"./Project-80a71be4.js";import{m as te,b as se}from"./file-utils-a5f053e8.js";import"./index-43e7382e.js";import"./FileUploaderButton-495e1c87.js";import"./useDownload-09eaf3eb.js";import"./useCurrentProject-0132f110.js";import"./useProject-77619fff.js";import"./PrimaryIconButton-fe990c52.js";import"./zipObj-08c84ab1.js";import"./dumbPluralize-86a9b9d6.js";import"./git-d9965c1a.js";import"./NoData-8733f606.js";import"./index-8f672200.js";import"./alertManagerConfig.selectors-c57f191b.js";const we=()=>{const u=J(),x=I(),{id:i}=P(),[d,m]=y.useState(!1),[g,{isLoading:N}]=T(),[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(D(j.jobs.overview,j.project.value,{id:i,jobName:r}))}}finally{m(!1)}};return k(R.createJob),c?e.jsx(b,{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(H,{})},ie=({advanceConfig:u,setAlertState:x,setAlertError:i,alertError:d,alertState:m,type:g})=>{const{id:N}=P(),{state:p}=V(),{formState:{errors:w},register:c,setValue:a,control:t,clearErrors:s,setError:C}=z(),[l,S,r]=B({control:t,name:["appPath","appName","schedule"]});return y.useEffect(()=>{if(p){const{appName:o,appPath:h,mainClass:f,schedule:n}=p;o&&a("appName",o),f&&a("mainClass",f),n&&setTimeout(()=>a("schedule",n)),h&&setTimeout(()=>a("appPath",h))}},[p,a]),y.useEffect(()=>{!S&&l&&(a("appName",te(se(l))),s("appName"))},[l,a]),e.jsxs(e.Fragment,{children:[e.jsx(M,{title:"Create new job",children:e.jsxs(b,{flexDirection:"column",sx:{gap:"20px"},children:[e.jsx(K,{name:"appPath",label:"File",fileExplorerMode:O.oneFile,validExtensions:g==="spark"?[".py",".jar",".ipynb"]:[".py",".ipynb"],filePathPrefix:"hdfs://"}),e.jsx(E,{...c("appName"),placeholder:"name",label:"Name",labelProps:{width:"180px"},...U("appName",w)}),e.jsx(E,{optional:!0,...c("defaultArgs"),placeholder:"args",label:"Default arguments",labelProps:{width:"100%"}})]})}),e.jsx(Y,{control:t,name:"schedule",render:({field:{value:o,onChange:h},fieldState:{error:f}})=>e.jsxs(A,{width:"100%",title:"Schedule",children:[!r&&e.jsx(F,{onClick:()=>a("schedule",ee),intent:"inline",loadingOnly:!0,children:"Add schedule"}),r&&e.jsxs(b,{children:[e.jsx(b,{flex:"1",grow:"1",children:e.jsx(ae,{value:r,onChange:n=>h({...o,...n}),onError:(n,v)=>v?C(`schedule.${n}`,{message:v}):s(`schedule.${n}`),error:f})}),e.jsx($,{icon:G.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(Q,{mb:"20px",type:_.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(j.project.settings.computeConfiguration,j.project.value,{id:N}),children:"Go to default configuration"})}),u]}),e.jsx(q,{type:"job",alerts:m,setAlerts:o=>{x([...o]),i(void 0)},error:d})]})};export{we as default};
