import{bL as F,aE as L,hY as H,aj as O,aC as _,al as W,az as J,aV as R,aA as Z,r as h,s as f,j as e,bE as b,bB as B,aM as k,B as x,c2 as q,b8 as K,u as Y,c as D,id as G,as as v,Z as A,fJ as Q,hV as U}from"./index-dP1W1_bd.js";import{b as V}from"./index-DqSuv-hx.js";import{u as X,B as T}from"./ButtonWithRole-CF64B_Or.js";import{N as ee}from"./NotebookJobArgsCallout-CuWfLFRW.js";const ne=({projectId:s,isCopy:l=!1,item:n,isOpenPopup:r,handleTogglePopup:a,handleStopExecutions:m,isStop:i=!1})=>{var w,N;const o=F(),u=L(),[d,{isLoading:E}]=H(),[g,{isLoading:I}]=V(),{isObserver:P}=X(),S=O().shape({appName:_.label("Name"),defaultArgs:W()}),p=J({defaultValues:{appName:"",defaultArgs:"",...!!n&&!i&&{appName:`${n.name}_${R(new Date,"HH_mm_ss")}`}},resolver:Z(S),reValidateMode:"onChange",mode:"onChange"}),c=J({defaultValues:{args:((w=n.config)==null?void 0:w.defaultArgs)||""},mode:"onChange"});h.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:M}}=p,{handleSubmit:y}=c,$=h.useCallback(()=>j(async t=>{const{name:z}=await d({pId:s,data:{...n.config,appName:t.appName},name:t.appName}).unwrap();a(),o(f.jobs.overview,{jobName:z})})(),[j,d,a,n.config,o,s]),C=h.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.jobs.executions,{jobName:n.name})})})(),[a,n,o,u,s,y,g]);return e.jsxs(e.Fragment,{children:[!l&&!i&&e.jsx(b,{title:"Run job",isOpen:r,onClose:a,secondaryButtonProps:{children:"Cancel",onClick:a},mainButtonProps:{children:"Run",type:"submit",onClick:C,isLoading:I,disabled:P},children:e.jsx("form",{onSubmit:t=>{t.preventDefault(),C()},children:e.jsxs(B,{...c,children:[(n.config.appPath??"").endsWith(".ipynb")&&e.jsx(ee,{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(b,{title:"Make a copy",isOpen:r,onClose:a,mainButtonProps:{children:"Create copy",onClick:$,isLoading:E},secondaryButtonProps:{children:"Cancel",onClick:a},children:e.jsxs(B,{...p,children:[e.jsx(x,{flexDirection:"column",children:e.jsx(q,{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}${R(new Date,"dd-MM-yyyy")}`,type:"text",width:"100%",height:"100%",label:"Name of the new job",labelProps:{width:"100%"},...p.register("appName"),...K("appName",M)})]})}),i&&e.jsx(b,{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=F(),n=L(),{id:r}=Y(),[a,{isLoading:m}]=V(),[i,o]=D(),u=()=>{a({pId:r,name:s.name,data:s.config.defaultArgs}).unwrap().then(()=>{n.info({title:"Info",content:"Job started"}),l(f.jobs.executions,{jobName:s.name})})};return e.jsxs(e.Fragment,{children:[e.jsx(ne,{projectId:+r,item:s,isOpenPopup:i,handleTogglePopup:o}),e.jsx(x,{children:e.jsxs(G,{size:"sm",variant:"outline",spacing:"0.5",height:"30px",mt:"1px",children:[e.jsx(T,{intent:"primary",isLoading:m,onClick:u,sx:{pr:"10px"},height:"30px",children:e.jsxs(x,{children:[e.jsx(v,{icon:A.play,color:"white",size:"sm",mr:"2px"}),"Run"]})}),e.jsx(Q,{sx:{mt:"0px",height:"100%",span:{height:"100%"},":hover":{">button":{div:{bg:"primaryShade1"}}}},items:[{disabled:s.jobType===U.FLINK,value:"Run with different arguments",onClick:o}],renderButton:({isOpen:d})=>e.jsx(v,{icon:A.arrow_down,color:"white",height:"100%",alignItems:"center",sx:{bg:d?"primaryShade1":"primary"}})})]})})]})};export{ne as J,re as R};
