import{b9 as F,bz as I,kg as _,ca as z,ar as O,au as W,aE as D,aC as k,aD as q,bP as J,r as h,t as f,j as e,bA as b,bw as R,aH as v,a as x,c7 as K,aY as G,bQ as Q,u as Y,y as U,ku as X,bs as Z,ap as A,d as B,fT as T,kd as ee}from"./index-_eM6l4Nf.js";import{u as E}from"./index-DUD8N5ck.js";import{N as ae}from"./NotebookJobArgsCallout-Hgrtc_nv.js";const ne=({projectId:s,isCopy:l=!1,item:a,isOpenPopup:r,handleTogglePopup:n,handleStopExecutions:m,isStop:i=!1})=>{var w,N;const o=F(),u=I(),[d,{isLoading:L}]=_(),[g,{isLoading:P}]=E(),{isObserver:S}=z(),$=O().shape({appName:D.label("Name"),defaultArgs:W()}),p=k({defaultValues:{appName:"",defaultArgs:"",...!!a&&!i&&{appName:`${a.name}_${J(new Date,"HH_mm_ss")}`}},resolver:q($),reValidateMode:"onChange",mode:"onChange"}),c=k({defaultValues:{args:((w=a.config)==null?void 0:w.defaultArgs)||""},mode:"onChange"});h.useEffect(()=>{var t;c.setValue("args",((t=a.config)==null?void 0:t.defaultArgs)||"")},[(N=a.config)==null?void 0:N.defaultArgs,c]);const{handleSubmit:j,formState:{errors:V}}=p,{handleSubmit:y}=c,H=h.useCallback(()=>j(async t=>{const{name:M}=await d({pId:s,data:{...a.config,appName:t.appName},name:t.appName}).unwrap();n(),o(f.project.jobs.overview,{jobName:M})})(),[j,d,n,a.config,o,s]),C=h.useCallback(()=>y(async t=>{s&&a&&n&&g({pId:`${s}`,name:a.name,data:t.args}).unwrap().then(()=>{u.info({title:"Info",content:"Job started"}),n(),o(f.project.jobs.executions,{jobName:a.name})})})(),[n,a,o,u,s,y,g]);return e.jsxs(e.Fragment,{children:[!l&&!i&&e.jsx(b,{title:"Run job",isOpen:r,onClose:n,secondaryButtonProps:{children:"Cancel",onClick:n},mainButtonProps:{children:"Run",type:"submit",onClick:C,isLoading:P,disabled:S},children:e.jsx("form",{onSubmit:t=>{t.preventDefault(),C()},children:e.jsxs(R,{...c,children:[(a.config.appPath??"").endsWith(".ipynb")&&e.jsx(ae,{small:!0,mb:"10px"}),e.jsx(v,{defaultValue:a.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:n,mainButtonProps:{children:"Create copy",onClick:H,isLoading:L},secondaryButtonProps:{children:"Cancel",onClick:n},children:e.jsxs(R,{...p,children:[e.jsx(x,{flexDirection:"column",children:e.jsx(K,{sx:{fontSize:"12px",fontFamily:"Inter",fontWeight:500,mb:"20px"},children:"Copy will create a new job with same file and configuration"})}),e.jsx(v,{defaultValue:`${a.name}${J(new Date,Q.DATE_TIME.DATE)}`,type:"text",width:"100%",height:"100%",label:"Name of the new job",labelProps:{width:"100%"},...p.register("appName"),...G("appName",V)})]})}),i&&e.jsx(b,{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}})]})},re=({jobData:s})=>{const l=F(),a=I(),{id:r}=Y(),[n,{isLoading:m}]=E(),[i,o]=U(),u=()=>{n({pId:r,name:s.name,data:s.config.defaultArgs}).unwrap().then(()=>{a.info({title:"Info",content:"Job started"}),l(f.project.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(X,{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{ne as J,re as R};
