import { c } from "react-compiler-runtime";
import { useEffect } from "react";
import { useForm } from "react-final-form";
//#region src/utilities/form/useFieldChangeListener.ts
/**
* Form helper hook that runs a callback when the value of a field has changed
* Usefull for creating effects where changes to one field affect the value of another field imperatively
*/
function useFieldChangeListener(name, cb) {
	const $ = c(5);
	const form = useForm();
	let t0;
	let t1;
	if ($[0] !== cb || $[1] !== form || $[2] !== name) {
		t0 = () => {
			let lastValue = form.getFieldState(name)?.value;
			return form.subscribe((t2) => {
				const { values } = t2;
				const value = values[name];
				if (value !== lastValue) cb(form, value, lastValue);
				lastValue = values[name];
			}, { values: true });
		};
		t1 = [
			form,
			name,
			cb
		];
		$[0] = cb;
		$[1] = form;
		$[2] = name;
		$[3] = t0;
		$[4] = t1;
	} else {
		t0 = $[3];
		t1 = $[4];
	}
	useEffect(t0, t1);
}
//#endregion
export { useFieldChangeListener };

//# sourceMappingURL=useFieldChangeListener.mjs.map