import{u as g,kl as v,r as S,j as o,a as b,at as p,bz as y,y as A,kh as $,aC as N,ca as L,bT as M,aJ as F,bA as I,aZ as J,aD as k,ar as V}from"./index-_eM6l4Nf.js";import{L as i}from"./LabelValue-CRG5UPNe.js";import{U as w,N as P,I as R,K as U,M as z}from"./Project-BTH4PZdL.js";const Z=t=>{const n=t.reduce((m,x)=>x.duration+m,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,h=s<10?`0${s}`:s;return`${d}h ${u}m ${h}s`},G=t=>{const{id:e,jobName:n}=g(),{data:s,isLoading:r}=v({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])},_=({jobName:t})=>{const{data:e,isLoading:n}=G(t);return n?null:e?o.jsxs(b,{flexDirection:"column",gap:"20px",opacity:e.enabled?"1":"0.6",children:[o.jsx(w,{}),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(P,{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(B,{})},B=({onAddSchedule:t})=>{const e=y(),{id:n,jobName:s}=g(),[r,a]=A(),[d,{isLoading:u}]=$(),{control:h,setError:m,clearErrors:x,handleSubmit:E,setValue:O}=H(),{isObserver:f}=L(),C=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(M,{mainText:"No schedule attached"}),o.jsx(F,{onClick:t??a,width:"fit-content",children:"Add Schedule"}),o.jsx(I,{size:"lg",isOpen:r,onClose:a,title:"Add Schedule",mainButtonProps:{children:"Add Schedule",onClick:E(C),isLoading:u,disabled:f},secondaryButtonProps:{children:"Cancel",onClick:a},children:o.jsx(J,{control:h,name:"schedule",render:({field:{value:l,onChange:D},fieldState:{error:T}})=>o.jsx(U,{value:l,onChange:c=>D({...l,...c}),onError:(c,j)=>j?m(`schedule.${c}`,{message:j}):x(`schedule.${c}`),error:T})})})]})},H=(t=R)=>N({defaultValues:{schedule:t},resolver:k(V().shape({schedule:z})),reValidateMode:"onChange"});export{B as A,_ as C,H as a,Z as g,G as u};
