import createDecorator from "./final-form-scroll/createDecorator.mjs";
import { c } from "react-compiler-runtime";
import React, { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
import { Form } from "react-final-form";
import { formRegistry } from "udp-react-stencil-component-library";
//#region src/utilities/form/Form.tsx
const scrollToError = createDecorator();
const FormBody = (t0) => {
	const $ = c(10);
	const { params, formRef, id, render, outerRef } = t0;
	let t1;
	if ($[0] !== params) {
		t1 = () => ({ ...params });
		$[0] = params;
		$[1] = t1;
	} else t1 = $[1];
	useImperativeHandle(outerRef, t1);
	let t2;
	if ($[2] !== params || $[3] !== render) {
		t2 = typeof render === "function" ? render(params) : render;
		$[2] = params;
		$[3] = render;
		$[4] = t2;
	} else t2 = $[4];
	let t3;
	if ($[5] !== formRef || $[6] !== id || $[7] !== params.handleSubmit || $[8] !== t2) {
		t3 = /* @__PURE__ */ React.createElement("form", {
			ref: formRef,
			onSubmit: params.handleSubmit,
			noValidate: true,
			id
		}, t2);
		$[5] = formRef;
		$[6] = id;
		$[7] = params.handleSubmit;
		$[8] = t2;
		$[9] = t3;
	} else t3 = $[9];
	return t3;
};
const FormInner = (t0, ref) => {
	const $ = c(17);
	let children;
	let id;
	let props;
	let renderProp;
	if ($[0] !== t0) {
		({render: renderProp, children, id, ...props} = t0);
		$[0] = t0;
		$[1] = children;
		$[2] = id;
		$[3] = props;
		$[4] = renderProp;
	} else {
		children = $[1];
		id = $[2];
		props = $[3];
		renderProp = $[4];
	}
	const render = renderProp || children;
	const formRef = useRef(null);
	let t1;
	let t2;
	if ($[5] !== id) {
		t1 = () => {
			if (id && formRef.current) {
				formRegistry.register(id, formRef.current);
				return () => formRegistry.unregister(id);
			}
		};
		t2 = [id];
		$[5] = id;
		$[6] = t1;
		$[7] = t2;
	} else {
		t1 = $[6];
		t2 = $[7];
	}
	useEffect(t1, t2);
	let t3;
	if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
		t3 = [scrollToError];
		$[8] = t3;
	} else t3 = $[8];
	let t4;
	if ($[9] !== id || $[10] !== ref || $[11] !== render) {
		t4 = (params) => /* @__PURE__ */ React.createElement(FormBody, {
			params,
			formRef,
			id,
			render,
			outerRef: ref
		});
		$[9] = id;
		$[10] = ref;
		$[11] = render;
		$[12] = t4;
	} else t4 = $[12];
	let t5;
	if ($[13] !== props || $[14] !== ref || $[15] !== t4) {
		t5 = /* @__PURE__ */ React.createElement(Form, {
			ref,
			decorators: t3,
			...props
		}, t4);
		$[13] = props;
		$[14] = ref;
		$[15] = t4;
		$[16] = t5;
	} else t5 = $[16];
	return t5;
};
const Form$1 = forwardRef(FormInner);
//#endregion
export { Form$1 as Form };

//# sourceMappingURL=Form.mjs.map