import{u as g,i9 as v,r as E,j as o,B as b,an as p,aE as A,c as $,hZ as y,aG as N,bE as L,b9 as M,az as F,aA as V,aj as J}from"./index-dP1W1_bd.js";import{N as k}from"./NoData-DLZ_8GEo.js";import{L as i}from"./LabelValue-Dfx1zREE.js";import{u as w}from"./ButtonWithRole-CF64B_Or.js";import{a2 as B,a3 as I,a0 as P,a1 as R,$ as z}from"./Project-CsYwwOpN.js";const W=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`},G=t=>{const{id:e,jobName:n}=g(),{data:s,isLoading:r}=v({pId:e,jobName:t??n}),a=E.useMemo(()=>(s==null?void 0:s.cronExpression)??"",[s==null?void 0:s.cronExpression]);return E.useMemo(()=>({data:s&&!s.deleted?{...s,cronExpression:a}:void 0,isLoading:r,name:t??n}),[a,s,r,n,t])},X=({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(B,{}),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(I,{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(U,{})},U=({onAddSchedule:t})=>{const e=A(),{id:n,jobName:s}=g(),[r,a]=$(),[d,{isLoading:u}]=y(),{control:m,setError:h,clearErrors:x,handleSubmit:S,setValue:H}=q(),{isObserver:f}=w(),C=async({schedule:c})=>{await d({pId:n,data:c,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(k,{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:S(C),isLoading:u,disabled:f},secondaryButtonProps:{children:"Cancel",onClick:a},children:o.jsx(M,{control:m,name:"schedule",render:({field:{value:c,onChange:D},fieldState:{error:T}})=>o.jsx(P,{value:c,onChange:l=>D({...c,...l}),onError:(l,j)=>j?h(`schedule.${l}`,{message:j}):x(`schedule.${l}`),error:T})})})]})},q=(t=z)=>F({defaultValues:{schedule:t},resolver:V(J().shape({schedule:R})),reValidateMode:"onChange"});export{U as A,X as C,q as a,W as g,G as u};
