import{ba as L,bI as P,kA as q,cn as W,av as D,as as J,Z as Y,aA as k,aB as Z,c1 as A,r as x,x as b,j as e,bJ as f,bF as B,aH as I,q as g,ck as G,aY as K,c2 as Q,u as U,w as X,fI as T,bB as ee,ao as E,v as F,gN as ae,kE as ne}from"./index-C6OVXshM.js";import{u as S}from"./index-CU_u1Yy3.js";import{N as se}from"./NotebookJobArgsCallout-a6FvBxXj.js";const te=({projectId:s,isCopy:l=!1,item:a,isOpenPopup:r,handleTogglePopup:n,handleStopExecutions:m,isStop:i=!1})=>{var R,v;const o=L(),u=P(),[d,{isLoading:V}]=q(),[j,{isLoading:$}]=S(),{isObserver:H}=W(),{data:p}=D(),y=J().required().max(63).label("Name"),M=Y().shape({appName:p?y.matches(new RegExp(p),{message:`Invalid job name format, must match: ${p}`,excludeEmptyString:!1}):y,defaultArgs:J()}),h=k({defaultValues:{appName:"",defaultArgs:"",...!!a&&!i&&{appName:`${a.name}_${A(new Date,"HH_mm_ss")}`}},resolver:Z(M),reValidateMode:"onChange",mode:"onChange"}),c=k({defaultValues:{args:((R=a.config)==null?void 0:R.defaultArgs)||""},mode:"onChange"});x.useEffect(()=>{var t;c.setValue("args",((t=a.config)==null?void 0:t.defaultArgs)||"")},[(v=a.config)==null?void 0:v.defaultArgs,c]);const{handleSubmit:w,formState:{errors:_}}=h,{handleSubmit:N}=c,z=x.useCallback(()=>w(async t=>{const{name:O}=await d({pId:s,data:{...a.config,appName:t.appName},name:t.appName}).unwrap();n(),o(b.project.jobs.overview,{jobName:O})})(),[w,d,n,a.config,o,s]),C=x.useCallback(()=>N(async t=>{s&&a&&n&&j({pId:`${s}`,name:a.name,data:t.args}).unwrap().then(()=>{u.info({title:"Info",content:"Job started"}),n(),o(b.project.jobs.executions,{jobName:a.name})})})(),[n,a,o,u,s,N,j]);return e.jsxs(e.Fragment,{children:[!l&&!i&&e.jsx(f,{title:"Run job",isOpen:r,onClose:n,secondaryButtonProps:{children:"Cancel",onClick:n},mainButtonProps:{children:"Run",type:"submit",onClick:C,isLoading:$,disabled:H},children:e.jsx("form",{onSubmit:t=>{t.preventDefault(),C()},children:e.jsxs(B,{...c,children:[(a.config.appPath??"").endsWith(".ipynb")&&e.jsx(se,{small:!0,mb:"10px"}),e.jsx(I,{defaultValue:a.config.defaultArgs,label:"Arguments",placeholder:"enter arguments",labelProps:{width:"100%"},...c.register("args")})]})})}),l&&!i&&e.jsx(f,{title:"Make a copy",isOpen:r,onClose:n,mainButtonProps:{children:"Create copy",onClick:z,isLoading:V},secondaryButtonProps:{children:"Cancel",onClick:n},children:e.jsxs(B,{...h,children:[e.jsx(g,{flexDirection:"column",children:e.jsx(G,{sx:{fontSize:"12px",fontFamily:"Inter",fontWeight:500,mb:"20px"},children:"Copy will create a new job with same file and configuration"})}),e.jsx(I,{defaultValue:`${a.name}${A(new Date,Q.DATE_TIME.DATE)}`,type:"text",width:"100%",height:"100%",label:"Name of the new job",labelProps:{width:"100%"},...h.register("appName"),...K("appName",_)})]})}),i&&e.jsx(f,{isOpen:r,onClose:n,title:"Stop execution",secondaryText:"Are you sure that you want to stop this execution?",mainButtonProps:{children:"Stop execution",onClick:()=>m},secondaryButtonProps:{children:"Back",onClick:n}})]})},ce=({jobData:s})=>{const l=L(),a=P(),{id:r}=U(),[n,{isLoading:m}]=S(),[i,o]=X(),u=()=>{n({pId:r,name:s.name,data:s.config.defaultArgs}).unwrap().then(()=>{a.info({title:"Info",content:"Job started"}),l(b.project.jobs.executions,{jobName:s.name})})};return e.jsxs(e.Fragment,{children:[e.jsx(te,{projectId:+r,item:s,isOpenPopup:i,handleTogglePopup:o}),e.jsx(g,{children:e.jsxs(T,{size:"sm",variant:"outline",spacing:"0.5",height:"30px",mt:"1px",children:[e.jsx(ee,{intent:"primary",isLoading:m,onClick:u,sx:{pr:"10px"},height:"30px",children:e.jsxs(g,{children:[e.jsx(E,{icon:F.play,color:"white",size:"sm",mr:"2px"}),"Run"]})}),e.jsx(ae,{sx:{mt:"0px",height:"100%",span:{height:"100%"},":hover":{">button":{div:{bg:"primaryShade1"}}}},items:[{disabled:s.jobType===ne.FLINK,value:"Run with different arguments",onClick:o}],renderButton:({isOpen:d})=>e.jsx(E,{icon:F.arrow_down,color:"white",height:"100%",alignItems:"center",sx:{bg:d?"primaryShade1":"primary"}})})]})})]})};export{te as J,ce as R};
