import{u as S,hJ as v,r as g,j as o,d as b,ai as p,bd as N,w as y,hx as A,b6 as $,be as L,aF as M,au as F,av as w,ae as J}from"./index-CK33qGU_.js";import{N as V}from"./NoData-CuLyR2Bg.js";import{L as i}from"./LabelValue-j2PGK56O.js";import{u as P}from"./ButtonWithRole-NHXEosto.js";import{U as I,O as R,M as U,N as k,K as G}from"./Project-j3KdDsvH.js";const X=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`},O=t=>{const{id:e,jobName:n}=S(),{data:s,isLoading:r}=v({pId:e,jobName:t??n}),a=g.useMemo(()=>(s==null?void 0:s.cronExpression)??"",[s==null?void 0:s.cronExpression]);return g.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}=O(t);return n?null:e?o.jsxs(b,{flexDirection:"column",gap:"20px",opacity:e.enabled?"1":"0.6",children:[o.jsx(I,{}),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(R,{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(q,{})},q=({onAddSchedule:t})=>{const e=N(),{id:n,jobName:s}=S(),[r,a]=y(),[d,{isLoading:u}]=A(),{control:m,setError:h,clearErrors:x,handleSubmit:f,setValue:B}=z(),{isObserver:E}=P(),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(V,{mainText:"No schedule attached"}),o.jsx($,{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:f(C),isLoading:u,disabled:E},secondaryButtonProps:{children:"Cancel",onClick:a},children:o.jsx(M,{control:m,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?h(`schedule.${c}`,{message:j}):x(`schedule.${c}`),error:T})})})]})},z=(t=G)=>F({defaultValues:{schedule:t},resolver:w(J().shape({schedule:k})),reValidateMode:"onChange"});export{q as A,Y as C,z as a,X as g,O as u};
