import { FormElementHeader as e } from "./FormElementHeader.js";
import t from "./FormBody.js";
import { useEffect as n } from "react";
import { jsx as r, jsxs as i } from "react/jsx-runtime";
import { FormProvider as a } from "react-hook-form";
//#region src/components/dynamic-form/Form.tsx
function o(e) {
	if (e.default !== void 0) return e.default;
	if (e.properties) {
		let t = {}, n = !1;
		for (let [r, i] of Object.entries(e.properties)) if (i.default !== void 0) t[r] = i.default, n = !0;
		else if (i.type === "object" && i.properties) {
			let e = o(i);
			e !== void 0 && (t[r] = e, n = !0);
		}
		return n ? t : void 0;
	}
}
var s = ({ form: s, schema: c, ui: l, mimeType: u, disabled: d, viewOnly: f, actions: p }) => {
	let m = l, h = c;
	return n(() => {
		let e = o(h);
		if (e) {
			let t = s.getValues(), n = { ...e };
			for (let [e, r] of Object.entries(t)) r !== void 0 && r !== "" && r !== null && (n[e] = r);
			s.reset(n);
		}
	}, [c]), /* @__PURE__ */ r(a, {
		...s,
		children: /* @__PURE__ */ i("div", {
			className: "container mx-auto",
			children: [/* @__PURE__ */ r(e, {
				title: m?.form?.title,
				description: m?.form?.description,
				disabled: d
			}), /* @__PURE__ */ i("form", { children: [/* @__PURE__ */ r(t, {
				form: s,
				mimeType: u,
				schema: c,
				ui: l?.form,
				disabled: d,
				viewOnly: f
			}), !f && !!p && /* @__PURE__ */ r("div", {
				className: "mt-4 flex w-full justify-end",
				children: p
			})] })]
		})
	});
};
//#endregion
export { s as default };
