import{W as B,ar as D,f2 as E,f1 as O,av as R,j as o,ae as A,af as I,Z as $,O as e,b3 as F,a as h,bw as M,ad as P,aG as g,ax as S,fo as Z,V as L,am as W,an as _,aT as y,u as z,aZ as G,r as J}from"./index-d6499a22.js";import{b as V}from"./index-e8147ca4.js";const Q=({schema:n,data:i,onSubmit:d})=>{const r=W({defaultValues:i,resolver:_(n)});return o.jsxs(e,{width:"100%",children:[o.jsx(a,{...r,errors:r.formState.errors,...n.describe()}),d&&o.jsx(h,{width:"100%",justifyContent:"flex-end",children:o.jsx(y,{onClick:r.handleSubmit(d),children:"Save"})})]})},a=({type:n,label:i="",fields:d={},name:r="",register:c,control:x,getValues:u,watch:j,errors:p,setValue:f,meta:s,innerType:l})=>{if(s!=null&&s.hide?s.hide.when(u(B(R("."),O,E(s.hide.prop),D("."))(r))):!1)return o.jsx("span",{style:{display:"none"}});const w=s!=null&&s.info?o.jsx(A,{mainText:s.info,children:o.jsx(I,{size:"xs",icon:$.info_block})}):null,t={register:c,control:x,getValues:u,watch:j,errors:p,setValue:f};return s!=null&&s.customRender?s.customRender({type:n,label:i,fields:d,name:r,innerType:l,...t}):s!=null&&s.CustomComponent?o.jsx(s.CustomComponent,{type:n,label:i,fields:d,name:r,innerType:l,...t}):n==="array"?o.jsx(q,{type:l.type,label:l.label,meta:l.meta,fields:l.fields??[],name:r,...t}):n==="object"?o.jsxs(e,{mb:"10px",children:[o.jsxs(F,{mb:"8px",flexDirection:"row",children:[o.jsx("span",{children:i}),w]}),o.jsx(h,{width:"100%",flexWrap:"wrap",sx:(s==null?void 0:s.sx)??{},children:Object.entries(d).map(([b,k])=>o.jsx(a,{name:r?`${r}.${b}`:b,...t,...k},r?`${r}.${b}`:b))})]}):s!=null&&s.readonly?o.jsxs(h,{mb:"10px",mr:"10px",flexDirection:"column",width:"150px",children:[o.jsx(F,{children:i}),o.jsx(M,{mt:"4px",color:"gray",children:u(r)})]}):n==="boolean"?o.jsx(h,{mb:"10px",mr:"10px",children:o.jsx(P,{label:i,tooltipProps:{mainText:(s==null?void 0:s.info)??""},disabled:s==null?void 0:s.disabled,...c(r)})}):o.jsx(h,{mb:"10px",mr:"10px",sx:(s==null?void 0:s.sx)??{},children:o.jsx(g,{label:i,type:n==="number"?n: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,...c(r),...S(r,p)})})},q=n=>{var r;const{fields:i,append:d}=Z({control:n.control,name:n.name});return o.jsxs(e,{width:"100%",children:[i.map((c,x)=>o.jsx(a,{...n,name:`${n.name}.${x}`},(c==null?void 0:c.id)??x)),((r=n.meta)==null?void 0:r.withAddButton)&&o.jsx(L,{type:"button",onClick:()=>{d(i[0])},icon:$.plus})]})},U=({name:n,configName:i,configId:d,value:r,setValue:c})=>{const{id:x,fgId:u,fsId:j}=z(),p=G(),[f,{isLoading:s}]=V(),l=J.useCallback(C=>{C.stopPropagation(),f({pId:x,fsId:j,fgId:u,configId:d,enable:!r}).unwrap().then(()=>{c(n,!r),p.success({duration:3e3,title:"Success",content:`Config ${i} is ${r?"paused":"resumed"} successfully`})}).catch(w=>{p.error({title:"Failure",content:`Failed to ${r?"pause":"resume"} ${i}`})})},[d,i,u,j,x,n,p,f,c,r]);return o.jsx(y,{onClick:l,isLoading:s,variant:r?"alert":"primary",children:r?"Disable":"Enable"})};export{U as E,Q as F,a};
