import{W as R,as as k,f7 as E,f6 as I,aw as P,j as o,af as g,ag as M,z as $,o as e,b4 as F,Q as p,bx as z,ae as B,aH as D,ay as O,fs as S,A as _,an as Q,ao as W,aU as y,u as H,a_ as J,r as L}from"./index-ea7817a2.js";import{b as U}from"./index-5603a2a4.js";const V=({schema:n,data:i,onSubmit:d})=>{const r=Q({defaultValues:i,resolver:W(n)});return o.jsxs(e,{width:"100%",children:[o.jsx(a,{...r,errors:r.formState.errors,...n.describe()}),d&&o.jsx(p,{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:f,errors:h,setValue:j,meta:s,innerType:l})=>{if(s!=null&&s.hide?s.hide.when(u(R(P("."),I,E(s.hide.prop),k("."))(r))):!1)return o.jsx("span",{style:{display:"none"}});const C=s!=null&&s.info?o.jsx(g,{mainText:s.info,children:o.jsx(M,{size:"xs",icon:$.info_block})}):null,t={register:c,control:x,getValues:u,watch:f,errors:h,setValue:j};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}),C]}),o.jsx(p,{width:"100%",flexWrap:"wrap",sx:(s==null?void 0:s.sx)??{},children:Object.entries(d).map(([b,A])=>o.jsx(a,{name:r?`${r}.${b}`:b,...t,...A},r?`${r}.${b}`:b))})]}):s!=null&&s.readonly?o.jsxs(p,{mb:"10px",mr:"10px",flexDirection:"column",width:"150px",children:[o.jsx(F,{children:i}),o.jsx(z,{mt:"4px",color:"gray",children:u(r)})]}):n==="boolean"?o.jsx(p,{mb:"10px",mr:"10px",children:o.jsx(B,{label:i,tooltipProps:{mainText:(s==null?void 0:s.info)??""},disabled:s==null?void 0:s.disabled,...c(r)})}):o.jsx(p,{mb:"10px",mr:"10px",sx:(s==null?void 0:s.sx)??{},children:o.jsx(D,{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),...O(r,h)})})},q=n=>{var r;const{fields:i,append:d}=S({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(_,{type:"button",onClick:()=>{d(i[0])},icon:$.plus})]})},X=({name:n,configName:i,configId:d,value:r,setValue:c})=>{const{id:x,fgId:u,fsId:f}=H(),h=J(),[j,{isLoading:s}]=U(),l=L.useCallback(w=>{w.stopPropagation(),j({pId:x,fsId:f,fgId:u,configId:d,enable:!r}).unwrap().then(()=>{c(n,!r),h.success({duration:3e3,title:"Success",content:`Config ${i} is ${r?"paused":"resumed"} successfully`})}).catch(C=>{h.error({title:"Failure",content:`Failed to ${r?"pause":"resume"} ${i}`})})},[d,i,u,f,x,n,h,j,c,r]);return o.jsx(y,{onClick:l,isLoading:s,variant:r?"alert":"primary",children:r?"Disable":"Enable"})};export{X as E,V as F,a};
