"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Form = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const getInertProps_1 = require("../../components/utils/getInertProps");
const FormProvider_1 = require("../FormProvider");
const styles_1 = require("./styles");
/**
 * Компонент, инкапсулирующий FormProvider
 * @example
 * ```tsx
 * import { Form, useForm } from '@astral/form';
 *
 * function App() {
 *   const form = useForm();
 *   const onSubmit = data => console.log(data);
 *
 *   return (
 *     <Form onSubmit={handleSubmit(onSubmit)} form={form}>
 *       <input defaultValue="test" {...form.register("example")} />
 *       <input type="submit" />
 *     </form>
 *   );
 * }
 * ```
 */
const Form = ({ form, children, isDisabled = false, ...props }) => {
    const { isSubmitting } = form?.formState || {};
    return ((0, jsx_runtime_1.jsx)(FormProvider_1.FormProvider, { ...form, children: (0, jsx_runtime_1.jsxs)(styles_1.StyledForm, { ...(0, getInertProps_1.getInertProps)(isDisabled || isSubmitting), noValidate: true, ...props, children: [(isDisabled || isSubmitting) && (0, jsx_runtime_1.jsx)(styles_1.Backdrop, {}), children] }) }));
};
exports.Form = Form;
