import{j as r}from"./vendor-react-wBh_31cN.js";import{o as w}from"./yup-XkUC3UEH.js";import{u as C,F as $,c as g}from"./index.esm-CAGtek53.js";import{G as z,h as I,aP as V,d as k}from"./index-BKr2rJhV.js";import{C as y}from"./checkbox-DbZXziG0.js";import{I as B}from"./icon-button-FETOk6q1.js";import{I as M}from"./input-H6_qmzms.js";import{L as t}from"./label-Dnebucx5.js";import{M as q}from"./metadata-field-B_vcklh-.js";import{V as A}from"./value-76ihWpF6.js";import{T as O}from"./tooltip-Da8-EbK8.js";import{g as P}from"./getInputValidation-CUi6Oel7.js";import{j as R}from"./join-DatdAzSt.js";import{a as L}from"./append-Bu8TTG0x.js";import{i as S}from"./init-BDcDHUTz.js";import{O as E,az as G}from"./vendor-icons-BUUmD6ht.js";const ns=({schema:i,data:l,children:d,onSubmit:o})=>{const n=C({defaultValues:l,resolver:w(i)}),{register:c,control:x,getValues:u,watch:e,setValue:p,formState:s}=n;return r.jsx("div",{className:"w-full",children:r.jsxs($,{...n,children:[r.jsx(N,{register:c,control:x,getValues:u,watch:e,setValue:p,errors:s.errors,...i.describe()}),o&&r.jsx("div",{className:"flex w-full justify-end",children:r.jsx(z,{onClick:n.handleSubmit(o),children:"Save"})}),d]})})},N=({type:i,label:l="",fields:d={},name:o="",register:n,control:c,getValues:x,watch:u,errors:e,setValue:p,meta:s,innerType:f})=>{if(s!=null&&s.hide?s.hide.when(x(I(V("."),S,L(s.hide.prop),R("."))(o))):!1)return r.jsx("div",{className:"hidden"});const b=s!=null&&s.info?r.jsx(O,{content:s.info,children:r.jsx(E,{className:"ml-1 inline size-3"})}):null,j={register:n,control:c,getValues:x,watch:u,errors:e,setValue:p},a=u(o);if(s!=null&&s.customRender)return s.customRender({type:i,label:l,fields:d,name:o,innerType:f,...j});if(s!=null&&s.CustomComponent)return r.jsx(s.CustomComponent,{type:i,label:l,fields:d,name:o,innerType:f,...j});if(i==="array")return r.jsx(D,{type:f.type,label:f.label,meta:f.meta,fields:f.fields??[],name:o,...j});if(i==="object")return r.jsxs("div",{className:s==null?void 0:s.wrapperClassName,children:[l&&r.jsxs(t,{className:"mb-2 flex flex-row text-sm",children:[r.jsx("span",{children:l}),b]}),r.jsx("div",{className:`flex w-full flex-wrap gap-2.5 ${(s==null?void 0:s.className)??""}`,children:Object.entries(d).map(([h,F])=>r.jsx(N,{name:o?`${o}.${h}`:h,...j,...F},o?`${o}.${h}`:h))})]});if(s!=null&&s.readonly)return r.jsx(q,{label:l,className:"mb-2.5 mr-2.5 w-[150px]",children:r.jsx(A,{className:k(a?"font-bold":"text-quartz-gray"),children:a??(s==null?void 0:s.noValueText)??"not defined"})});if(i==="boolean")return r.jsxs("div",{className:"mb-2.5 flex items-center gap-2",children:[r.jsx(y,{disabled:s==null?void 0:s.disabled,checked:a,...n(o)}),r.jsx(t,{className:a?"text-quartz-black":"text-quartz-gray",children:l})]});const v=P(o,e);return r.jsxs("div",{className:`mb-2.5 mr-2.5 ${(s==null?void 0:s.className)??""}`,children:[l&&r.jsxs(t,{className:"mb-1.5 flex items-center",children:[l,b]}),r.jsx(M,{type:i==="number"?i:s==null?void 0:s.type,disabled:s==null?void 0:s.disabled,readOnly:s==null?void 0:s.readonly,...n(o),...v})]})},D=i=>{var o;const{fields:l,append:d}=g({control:i.control,name:i.name});return r.jsxs("div",{className:"w-full",children:[l.map((n,c)=>r.jsx(N,{...i,name:`${i.name}.${c}`},(n==null?void 0:n.id)??c)),((o=i.meta)==null?void 0:o.withAddButton)&&r.jsx(B,{type:"button",variant:"ghost",onClick:()=>{d(l[0])},children:r.jsx(G,{className:"size-4"})})]})};export{ns as F,N as a};
