import{bg as M,bd as S,hw as D,ae as H,ax as L,ag as q,au as j,bl as N,av as _,r as u,q as w,j as e,be as m,ba as k,aR as J,d as I,bD as O,aE as P}from"./index-CK33qGU_.js";import{b as W}from"./index-Cwe0XbXT.js";import{u as z}from"./ButtonWithRole-NHXEosto.js";import{N as G}from"./NotebookJobArgsCallout-BePPd6f1.js";const Y=({projectId:t,isCopy:d=!1,item:a,isOpenPopup:c,handleTogglePopup:n,handleStopExecutions:v,isStop:r=!1})=>{var C,g;const i=M(),b=S(),[f,{isLoading:A}]=D(),[p,{isLoading:R}]=W(),{isObserver:V}=z(),B=H().shape({appName:L.label("Name"),defaultArgs:q()}),l=j({defaultValues:{appName:"",defaultArgs:"",...!!a&&!r&&{appName:`${a.name}_${N(new Date,"HH_mm_ss")}`}},resolver:_(B),reValidateMode:"onChange",mode:"onChange"}),o=j({defaultValues:{args:((C=a.config)==null?void 0:C.defaultArgs)||""},mode:"onChange"});u.useEffect(()=>{var s;o.setValue("args",((s=a.config)==null?void 0:s.defaultArgs)||"")},[(g=a.config)==null?void 0:g.defaultArgs,o]);const{handleSubmit:x,formState:{errors:$}}=l,{handleSubmit:h}=o,E=u.useCallback(()=>x(async s=>{const{name:F}=await f({pId:t,data:{...a.config,appName:s.appName},name:s.appName}).unwrap();n(),i(w.jobs.overview,{jobName:F})})(),[x,f,n,a.config,i,t]),y=u.useCallback(()=>h(async s=>{t&&a&&n&&p({pId:`${t}`,name:a.name,data:s.args}).unwrap().then(()=>{b.info({title:"Info",content:"Job started"}),n(),i(w.jobs.executions,{jobName:a.name})})})(),[n,a,i,b,t,h,p]);return e.jsxs(e.Fragment,{children:[!d&&!r&&e.jsx(m,{title:"Run job",isOpen:c,onClose:n,secondaryButtonProps:{children:"Cancel",onClick:n},mainButtonProps:{children:"Run",type:"submit",onClick:y,isLoading:R,disabled:V},children:e.jsx("form",{onSubmit:s=>{s.preventDefault(),y()},children:e.jsxs(k,{...o,children:[(a.config.appPath??"").endsWith(".ipynb")&&e.jsx(G,{small:!0,mb:"10px"}),e.jsx(J,{defaultValue:a.config.defaultArgs,label:"Arguments",placeholder:"enter arguments",labelProps:{width:"100%"},...o.register("args")})]})})}),d&&!r&&e.jsx(m,{title:"Make a copy",isOpen:c,onClose:n,mainButtonProps:{children:"Create copy",onClick:E,isLoading:A},secondaryButtonProps:{children:"Cancel",onClick:n},children:e.jsxs(k,{...l,children:[e.jsx(I,{flexDirection:"column",children:e.jsx(O,{sx:{fontSize:"12px",fontFamily:"Inter",fontWeight:500,mb:"20px"},children:"Copy will create a new job with same file and configuration"})}),e.jsx(J,{defaultValue:`${a.name}${N(new Date,"dd-MM-yyyy")}`,type:"text",width:"100%",height:"100%",label:"Name of the new job",labelProps:{width:"100%"},...l.register("appName"),...P("appName",$)})]})}),r&&e.jsx(m,{isOpen:c,onClose:n,title:"Stop execution",secondaryText:"Are you sure that you want to stop this execution?",mainButtonProps:{children:"Stop execution",onClick:()=>v},secondaryButtonProps:{children:"Back",onClick:n}})]})};export{Y as J};
