import{bJ as F,bz as I,jl as z,ca as O,al as _,aG as W,an as D,aD as J,bQ as R,aE as G,r as b,s as f,j as e,bA as h,bw as v,b5 as k,B as x,c7 as q,aR as K,u as Q,w as U,jD as X,bs as Y,au as B,C as A,fN as Z,ji as T}from"./index-C1DmWO_C.js";import{b as L}from"./index-GabIfpNZ.js";import{N as ee}from"./NotebookJobArgsCallout-7tIiXwQk.js";const ne=({projectId:s,isCopy:l=!1,item:n,isOpenPopup:r,handleTogglePopup:a,handleStopExecutions:m,isStop:i=!1})=>{var C,N;const o=F(),u=I(),[d,{isLoading:P}]=z(),[g,{isLoading:S}]=L(),{isObserver:V}=O(),$=_().shape({appName:W.label("Name"),defaultArgs:D()}),p=J({defaultValues:{appName:"",defaultArgs:"",...!!n&&!i&&{appName:`${n.name}_${R(new Date,"HH_mm_ss")}`}},resolver:G($),reValidateMode:"onChange",mode:"onChange"}),c=J({defaultValues:{args:((C=n.config)==null?void 0:C.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:E}}=p,{handleSubmit:y}=c,M=b.useCallback(()=>j(async t=>{const{name:H}=await d({pId:s,data:{...n.config,appName:t.appName},name:t.appName}).unwrap();a(),o(f.jobs.overview,{jobName:H})})(),[j,d,a,n.config,o,s]),w=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.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:w,isLoading:S,disabled:V},children:e.jsx("form",{onSubmit:t=>{t.preventDefault(),w()},children:e.jsxs(v,{...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(h,{title:"Make a copy",isOpen:r,onClose:a,mainButtonProps:{children:"Create copy",onClick:M,isLoading:P},secondaryButtonProps:{children:"Cancel",onClick:a},children:e.jsxs(v,{...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",E)})]})}),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}})]})},oe=({jobData:s})=>{const l=F(),n=I(),{id:r}=Q(),[a,{isLoading:m}]=L(),[i,o]=U(),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(X,{size:"sm",variant:"outline",spacing:"0.5",height:"30px",mt:"1px",children:[e.jsx(Y,{intent:"primary",isLoading:m,onClick:u,sx:{pr:"10px"},height:"30px",children:e.jsxs(x,{children:[e.jsx(B,{icon:A.play,color:"white",size:"sm",mr:"2px"}),"Run"]})}),e.jsx(Z,{sx:{mt:"0px",height:"100%",span:{height:"100%"},":hover":{">button":{div:{bg:"primaryShade1"}}}},items:[{disabled:s.jobType===T.FLINK,value:"Run with different arguments",onClick:o}],renderButton:({isOpen:d})=>e.jsx(B,{icon:A.arrow_down,color:"white",height:"100%",alignItems:"center",sx:{bg:d?"primaryShade1":"primary"}})})]})})]})};export{ne as J,oe as R};
