'use client';


import { FormItemContext } from "./FormItem.mjs";
import { createContext, useContext, useMemo } from "react";
import { jsx } from "react/jsx-runtime";
import { Controller, useFormContext } from "react-hook-form";

//#region src/components/Form/FormField.tsx
const FormFieldContext = createContext({});
const FormField = ({ ...props }) => {
	return /* @__PURE__ */ jsx(FormFieldContext, {
		value: useMemo(() => ({ name: props.name }), [props.name]),
		children: /* @__PURE__ */ jsx(Controller, { ...props })
	});
};
const useFormField = () => {
	const fieldContext = useContext(FormFieldContext);
	const itemContext = useContext(FormItemContext);
	const { getFieldState, formState } = useFormContext();
	const fieldState = getFieldState(fieldContext.name, formState);
	if (!fieldContext) throw new Error("useFormField should be used within <FormField>");
	const { id } = itemContext;
	return {
		id,
		name: fieldContext.name,
		formItemId: `${id}-form-item`,
		formDescriptionId: `${id}-form-item-description`,
		formMessageId: `${id}-form-item-message`,
		...fieldState
	};
};

//#endregion
export { FormField, useFormField };
//# sourceMappingURL=FormField.mjs.map