import{f as $,aA as F,el as E,aD as A,j as n,am as D,an as R,T as g,c as b,aV as j,d as h,bD as B,gg as P,aR as z,aE as I,ed as M,e as O,au as W,av as _,b6 as C,u as q,bd as J,gh as V,r as G,e_ as H,B as K,y as L}from"./index-CK33qGU_.js";import{a as Q}from"./length-fOfC3W0h.js";const T=({schema:o,data:d,onSubmit:i})=>{const r=W({defaultValues:d,resolver:_(o)});return n.jsxs(b,{width:"100%",children:[n.jsx(y,{...r,errors:r.formState.errors,...o.describe()}),i&&n.jsx(h,{width:"100%",justifyContent:"flex-end",children:n.jsx(C,{onClick:r.handleSubmit(i),children:"Save"})})]})},y=({type:o,label:d="",fields:i={},name:r="",register:l,control:t,getValues:x,watch:p,errors:u,setValue:f,meta:s,innerType:e})=>{if(s!=null&&s.hide?s.hide.when(x($(A("."),E,Q(s.hide.prop),F("."))(r))):!1)return n.jsx("span",{style:{display:"none"}});const S=s!=null&&s.info?n.jsx(D,{mainText:s.info,children:n.jsx(R,{size:"xs",icon:g.info_block})}):null,a={register:l,control:t,getValues:x,watch:p,errors:u,setValue:f};if(s!=null&&s.customRender)return s.customRender({type:o,label:d,fields:i,name:r,innerType:e,...a});if(s!=null&&s.CustomComponent)return n.jsx(s.CustomComponent,{type:o,label:d,fields:i,name:r,innerType:e,...a});if(o==="array")return n.jsx(U,{type:e.type,label:e.label,meta:e.meta,fields:e.fields??[],name:r,...a});if(o==="object")return n.jsxs(b,{sx:(s==null?void 0:s.wrapperSx)??{},children:[n.jsxs(j,{fontSize:"14px",mb:"8px",flexDirection:"row",children:[n.jsx("span",{children:d}),S]}),n.jsx(h,{width:"100%",gap:"10px",flexWrap:"wrap",sx:(s==null?void 0:s.sx)??{},children:Object.entries(i).map(([c,k])=>n.jsx(y,{name:r?`${r}.${c}`:c,...a,...k},r?`${r}.${c}`:c))})]});if(s!=null&&s.readonly){const c=x(r);return n.jsxs(h,{mb:"10px",mr:"10px",flexDirection:"column",width:"150px",children:[n.jsx(j,{color:"gray",children:d}),n.jsx(B,{mt:"4px",color:c?"black":"gray",fontWeight:c?"bold":"normal",children:c??"not defined"})]})}if(o==="boolean"){const c=x(r);return n.jsx(h,{mb:"10px",children:n.jsx(P,{colorScheme:"green",readOnly:s==null?void 0:s.disabled,isChecked:c,children:n.jsx(j,{color:c?"black":"gray",children:d})})})}return n.jsx(h,{mb:"10px",mr:"10px",sx:(s==null?void 0:s.sx)??{},children:n.jsx(z,{label:d,type:o==="number"?o:s==null?void 0:s.type,disabled:s==null?void 0:s.disabled,readonly:s==null?void 0:s.readonly,tooltipInfo:s==null?void 0:s.info,...l(r),...I(r,u)})})},U=o=>{var r;const{fields:d,append:i}=M({control:o.control,name:o.name});return n.jsxs(b,{width:"100%",children:[d.map((l,t)=>n.jsx(y,{...o,name:`${o.name}.${t}`},(l==null?void 0:l.id)??t)),((r=o.meta)==null?void 0:r.withAddButton)&&n.jsx(O,{type:"button",onClick:()=>{i(d[0])},icon:g.plus})]})},v=({configName:o,jobName:d,value:i,setValue:r,name:l,onUpdateSuccess:t})=>{const{id:x}=q(),p=J(),[u,{isLoading:f}]=V(),s=G.useCallback(e=>{e.stopPropagation(),u({pId:x,data:{doNotParse:!0,...i,enabled:!i.enabled},jobName:d}).unwrap().then(()=>{t(),r(l,{...i,enabled:!i.enabled}),p.success({duration:3e3,title:"Success",content:`Config ${o} is ${i.enabled?"paused":"resumed"} successfully`})}).catch(w=>{p.error({title:"Failure",content:`Failed to ${i.enabled?"pause":"resume"} ${o}`})})},[o,x,d,l,p,t,r,u,i]);return n.jsx(C,{onClick:s,isLoading:f,minWidth:"fit-content",intent:"secondary",sx:{color:i.enabled?"labels.red":"primary"},children:i.enabled?"Disable":"Enable"})},X=(o,d)=>{const i=l=>K("labels.green",l,{stopped:"labels.red","not-installed":"grayShade2"}),r=H`
  {
    8.33% { opacity: 1; }
    50% { opacity: 0.1; }
    58.33% { opacity: 0.1; }
    100% { opacity: 1; }
  }
`;return{bg:"transparent",width:"14px",height:"14px",borderRadius:"50%",flex:"none",backgroundColor:d?"grayShade2":i(o),left:"0px",top:"0.5px",animation:d?`${r} 1.2s infinite`:""}},N=({text:o,variant:d,isLoading:i=!1,sx:r})=>d?n.jsxs(h,{sx:r,justifyContent:"center",children:[n.jsx(b,{sx:X(d,i)}),o&&n.jsx(L,{ml:"5px",bold:!0,children:o})]}):null;export{v as E,T as F,N as S,y as a};
