import{u as g,j8 as T,r as S,j as o,Q as b,ab as p,a_ as v,P as y,iY as A,aU as N,b0 as L,az as $,an as M,ao as F,a7 as J}from"./index-ea7817a2.js";import{N as P}from"./NoData-8733f606.js";import{L as i}from"./LabelValue-bef10fa0.js";import{U as V,H as U,C as w,s as I,D as k}from"./Project-80a71be4.js";const O=t=>{const n=t.reduce((h,x)=>x.duration+h,0)/t.length,s=Math.floor(n/1e3%60),r=Math.floor(n/(1e3*60)%60),a=Math.floor(n/(1e3*60*60)%24),d=a<10?`0${a}`:a,u=r<10?`0${r}`:r,m=s<10?`0${s}`:s;return`${d}h ${u}m ${m}s`},z=t=>{const{id:e,jobName:n}=g(),{data:s,isLoading:r}=T({pId:e,jobName:t??n}),a=S.useMemo(()=>(s==null?void 0:s.cronExpression)??"",[s==null?void 0:s.cronExpression]);return S.useMemo(()=>({data:s&&!s.deleted?{...s,cronExpression:a}:void 0,isLoading:r,name:t??n}),[a,s,r,n,t])},Y=({jobName:t})=>{const{data:e,isLoading:n}=z(t);return n?null:e?o.jsxs(b,{flexDirection:"column",gap:"20px",opacity:e.enabled?"1":"0.6",children:[o.jsx(V,{}),o.jsxs(b,{width:"100%",gap:"20px",children:[o.jsx(i,{label:e.doNotRepeat?"Time":"Start time",value:p(e.startDateTime)}),!e.doNotRepeat&&o.jsx(i,{label:"End time",value:e!=null&&e.endDateTime?p(e.endDateTime):void 0}),o.jsx(i,{label:"Enabled",value:e.enabled?"True":"False",color:e.enabled?"primary":"labels.red"})]}),o.jsx(i,{label:"Frequency",value:o.jsx(U,{cronExpression:e.cronExpression})}),o.jsx(i,{label:"Next execution time",value:e.nextExecutionDateTime?p(e.nextExecutionDateTime):void 0,color:e.nextExecutionDateTime?"primary":"none"})]}):o.jsx(G,{})},G=({onAddSchedule:t})=>{const e=v(),{id:n,jobName:s}=g(),[r,a]=y(),[d,{isLoading:u}]=A(),{control:m,setError:h,clearErrors:x,handleSubmit:E,setValue:Q}=H(),f=async({schedule:l})=>{await d({pId:n,data:l,jobName:s}).unwrap(),e.success({title:"Job Schedule",content:"Schedule is added to job successfully"}),a()};return o.jsxs(b,{gap:"20px",py:"20px",flexDirection:"column",alignItems:"center",children:[o.jsx(P,{mainText:"No schedule attached"}),o.jsx(N,{onClick:t??a,width:"fit-content",children:"Add Schedule"}),o.jsx(L,{size:"lg",isOpen:r,onClose:a,title:"Add Schedule",mainButtonProps:{children:"Add Schedule",onClick:E(f),isLoading:u},secondaryButtonProps:{children:"Cancel",onClick:a},children:o.jsx($,{control:m,name:"schedule",render:({field:{value:l,onChange:C},fieldState:{error:D}})=>o.jsx(w,{value:l,onChange:c=>C({...l,...c}),onError:(c,j)=>j?h(`schedule.${c}`,{message:j}):x(`schedule.${c}`),error:D})})})]})},H=(t=k)=>M({defaultValues:{schedule:t},resolver:F(J().shape({schedule:I})),reValidateMode:"onChange"});export{G as A,Y as C,H as a,O as g,z as u};
