import{b9 as E,by as F,jE as O,c9 as _,ar as z,au as D,aE as W,aC as R,aD as q,bO as J,r as b,q as f,j as e,bz as h,bv as v,b2 as k,$ as x,c6 as G,aN as K,bP as X,u as Y,y as Q,jX as U,br as Z,ap as A,C as B,fN as T,jB as ee}from"./index-46ma1THH.js";import{b as I}from"./index-DoAo8g_G.js";import{N as ne}from"./NotebookJobArgsCallout-D89NQ2Z8.js";const ae=({projectId:s,isCopy:l=!1,item:n,isOpenPopup:r,handleTogglePopup:a,handleStopExecutions:m,isStop:i=!1})=>{var w,N;const o=E(),u=F(),[d,{isLoading:L}]=O(),[g,{isLoading:P}]=I(),{isObserver:S}=_(),$=z().shape({appName:W.label("Name"),defaultArgs:D()}),p=R({defaultValues:{appName:"",defaultArgs:"",...!!n&&!i&&{appName:`${n.name}_${J(new Date,"HH_mm_ss")}`}},resolver:q($),reValidateMode:"onChange",mode:"onChange"}),c=R({defaultValues:{args:((w=n.config)==null?void 0:w.defaultArgs)||""},mode:"onChange"});b.useEffect(()=>{var t;c.setValue("args",((t=n.config)==null?void 0:t.defaultArgs)||"")},[(N=n.config)==null?void 0:N.defaultArgs,c]);const{handleSubmit:j,formState:{errors:V}}=p,{handleSubmit:y}=c,H=b.useCallback(()=>j(async t=>{const{name:M}=await d({pId:s,data:{...n.config,appName:t.appName},name:t.appName}).unwrap();a(),o(f.project.jobs.overview,{jobName:M})})(),[j,d,a,n.config,o,s]),C=b.useCallback(()=>y(async t=>{s&&n&&a&&g({pId:`${s}`,name:n.name,data:t.args}).unwrap().then(()=>{u.info({title:"Info",content:"Job started"}),a(),o(f.project.jobs.executions,{jobName:n.name})})})(),[a,n,o,u,s,y,g]);return e.jsxs(e.Fragment,{children:[!l&&!i&&e.jsx(h,{title:"Run job",isOpen:r,onClose:a,secondaryButtonProps:{children:"Cancel",onClick:a},mainButtonProps:{children:"Run",type:"submit",onClick:C,isLoading:P,disabled:S},children:e.jsx("form",{onSubmit:t=>{t.preventDefault(),C()},children:e.jsxs(v,{...c,children:[(n.config.appPath??"").endsWith(".ipynb")&&e.jsx(ne,{small:!0,mb:"10px"}),e.jsx(k,{defaultValue:n.config.defaultArgs,label:"Arguments",placeholder:"enter arguments",labelProps:{width:"100%"},...c.register("args")})]})})}),l&&!i&&e.jsx(h,{title:"Make a copy",isOpen:r,onClose:a,mainButtonProps:{children:"Create copy",onClick:H,isLoading:L},secondaryButtonProps:{children:"Cancel",onClick:a},children:e.jsxs(v,{...p,children:[e.jsx(x,{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(k,{defaultValue:`${n.name}${J(new Date,X.DATE_TIME.DATE)}`,type:"text",width:"100%",height:"100%",label:"Name of the new job",labelProps:{width:"100%"},...p.register("appName"),...K("appName",V)})]})}),i&&e.jsx(h,{isOpen:r,onClose:a,title:"Stop execution",secondaryText:"Are you sure that you want to stop this execution?",mainButtonProps:{children:"Stop execution",onClick:()=>m},secondaryButtonProps:{children:"Back",onClick:a}})]})},re=({jobData:s})=>{const l=E(),n=F(),{id:r}=Y(),[a,{isLoading:m}]=I(),[i,o]=Q(),u=()=>{a({pId:r,name:s.name,data:s.config.defaultArgs}).unwrap().then(()=>{n.info({title:"Info",content:"Job started"}),l(f.project.jobs.executions,{jobName:s.name})})};return e.jsxs(e.Fragment,{children:[e.jsx(ae,{projectId:+r,item:s,isOpenPopup:i,handleTogglePopup:o}),e.jsx(x,{children:e.jsxs(U,{size:"sm",variant:"outline",spacing:"0.5",height:"30px",mt:"1px",children:[e.jsx(Z,{intent:"primary",isLoading:m,onClick:u,sx:{pr:"10px"},height:"30px",children:e.jsxs(x,{children:[e.jsx(A,{icon:B.play,color:"white",size:"sm",mr:"2px"}),"Run"]})}),e.jsx(T,{sx:{mt:"0px",height:"100%",span:{height:"100%"},":hover":{">button":{div:{bg:"primaryShade1"}}}},items:[{disabled:s.jobType===ee.FLINK,value:"Run with different arguments",onClick:o}],renderButton:({isOpen:d})=>e.jsx(A,{icon:B.arrow_down,color:"white",height:"100%",alignItems:"center",sx:{bg:d?"primaryShade1":"primary"}})})]})})]})};export{ae as J,re as R};
