'use client';


import { jsx } from "react/jsx-runtime";
import { FormProvider, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod/v4";

//#region src/components/Form/elements/FormElementWrapper.tsx
const Schema = z.object({ test: z.string().min(3, "test error") });
const FormElementWrapper = (props) => {
	const objectFormSchema = props.schema ?? Schema;
	const form = useForm({
		resolver: zodResolver(objectFormSchema),
		values: props.values
	});
	const { children, onSubmit,...rest } = props;
	const onSubmitForm = (values, event) => {
		if (objectFormSchema.safeParse(values).success) onSubmit?.(event);
	};
	return /* @__PURE__ */ jsx(FormProvider, {
		...form,
		children: /* @__PURE__ */ jsx("form", {
			...rest,
			onSubmit: (e) => {
				e.preventDefault();
				form.handleSubmit((values) => onSubmitForm(values, e));
			},
			children
		})
	});
};

//#endregion
export { FormElementWrapper };
//# sourceMappingURL=FormElementWrapper.mjs.map