import{r as g,j as e}from"./vendor-react-wBh_31cN.js";import{G as f,D as y,z as A,B as M,C as $,F as v,ar as V}from"./index-dNe6i2rS.js";import{C as w,u as z}from"./index.esm-CAGtek53.js";import{o as J}from"./yup-XkUC3UEH.js";import{u as L}from"./useNotifier-BGMn6HaH.js";import{N as q}from"./NoData-BtM2pAIA.js";import{M as c}from"./metadata-field-Uf1PM1Ss.js";import{V as d}from"./value-7N0Keti9.js";import{F as G}from"./field-grid-EHxmWjaD.js";import{a as j}from"./time-utils-CQYZ5msB.js";import{b as H,a as I}from"./index-dHd2aGu6.js";import{u as O}from"./useProjectRole-DpUIGfh9.js";import{H as R}from"./HumanizedCronExpression-BsPK2pda.js";import{U,C as k,s as B}from"./CronDetails-DOXCedRS.js";import{D as P}from"./CronExpression-B_Y2jRUi.js";import{c as S}from"./vendor-router-D1GqFWiT.js";const he=t=>{const r=t.reduce((x,p)=>p.duration+x,0)/t.length,s=Math.floor(r/1e3%60),n=Math.floor(r/(1e3*60)%60),a=Math.floor(r/(1e3*60*60)%24),l=a<10?`0${a}`:a,m=n<10?`0${n}`:n,h=s<10?`0${s}`:s;return`${l}h ${m}m ${h}s`},Q=t=>{const{id:o,jobName:r}=S(),{data:s,isLoading:n}=H({pId:o,jobName:t??r}),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:n,name:t??r}),[a,s,n,r,t])},xe=({jobName:t})=>{const{data:o,isLoading:r}=Q(t);if(r)return null;if(!o)return e.jsx(_,{});const{enabled:s}=o;return e.jsxs("div",{className:"flex flex-col gap-5",style:{opacity:s?"1":"0.6"},children:[e.jsx(U,{}),e.jsxs(G,{cols:3,children:[e.jsx(c,{label:o.doNotRepeat?"Time":"Start time",children:e.jsx(d,{children:j(o.startDateTime)??"-"})}),!o.doNotRepeat&&e.jsx(c,{label:"End time",children:e.jsx(d,{children:o!=null&&o.endDateTime?j(o.endDateTime):"-"})}),e.jsx(c,{label:"Enabled",children:e.jsx(d,{className:s?"text-quartz-primary":"text-quartz-label-red",children:s?"True":"False"})}),e.jsx(c,{label:"Frequency",children:e.jsx(d,{children:e.jsx(R,{cronExpression:o.cronExpression})})}),e.jsx(c,{label:"Next execution time",children:e.jsx(d,{style:o.nextExecutionDateTime?{color:"var(--quartz-primary)"}:void 0,children:o.nextExecutionDateTime?j(o.nextExecutionDateTime):"-"})})]})]})},_=({onAddSchedule:t})=>{const o=L(),{id:r,jobName:s}=S(),[n,a]=g.useState(!1),l=()=>a(i=>!i),[m,{isLoading:h}]=I(),{control:x,setError:p,clearErrors:C,handleSubmit:D,setValue:W}=K(),{isObserver:E}=O(),N=async({schedule:i})=>{await m({pId:r,data:i,jobName:s}).unwrap(),o.success({title:"Job Schedule",content:"Schedule is added to job successfully"}),l()};return e.jsxs("div",{className:"flex flex-col items-center gap-5 py-5",children:[e.jsx(q,{mainText:"No schedule attached"}),e.jsx(f,{onClick:t??l,className:"w-fit",children:"Add Schedule"}),e.jsx(y,{open:n,onOpenChange:a,children:e.jsxs(A,{className:"max-w-lg",showCloseButton:!1,children:[e.jsx(M,{children:e.jsx($,{children:"Add Schedule"})}),e.jsx(w,{control:x,name:"schedule",render:({field:{value:i,onChange:T},fieldState:{error:F}})=>e.jsx(k,{value:i,onChange:u=>T({...i,...u}),onError:(u,b)=>b?p(`schedule.${u}`,{message:b}):C(`schedule.${u}`),error:F})}),e.jsxs(v,{children:[e.jsx(f,{variant:"outline",onClick:l,children:"Cancel"}),e.jsx(f,{onClick:D(N),loading:h,disabled:E,children:"Add Schedule"})]})]})})]})},K=(t=P)=>z({defaultValues:{schedule:t},resolver:J(V().shape({schedule:B})),reValidateMode:"onChange"});export{_ as A,xe as C,K as a,he as g,Q as u};
