import { c } from "react-compiler-runtime";
import React, { forwardRef } from "react";
import { Field } from "react-final-form";
//#region src/utilities/form/Field.tsx
/**
* Check if a value is considered empty for required validation.
* Handles: undefined, null, empty string, empty arrays.
* Note: 0 is considered a valid value (not empty).
*/
function isEmpty(value) {
	if (value === void 0 || value === null || value === "") return true;
	if (Array.isArray(value) && value.length === 0) return true;
	return false;
}
/**
* Final Form Field wrapper that supports both Material UI and Fluent UI components.
*
* UDP Fluent components automatically detect and convert error props,
* so you can use the same Field component for both MUI and Fluent components.
*
* @example
* // MUI component
* <Field component={TextField} name="email" required />
*
* @example
* // UDP Fluent component (auto-detects error style)
* <Field component={UdpTextInput} name="email" required />
*/
const Field$1 = forwardRef((props, ref) => {
	const $ = c(55);
	let Component;
	let ComponentProps;
	let afterSubmit;
	let allowNull;
	let beforeSubmit;
	let componentProps;
	let defaultValue;
	let format;
	let formatOnBlur;
	let helperText;
	let initialValue;
	let isEqual;
	let name;
	let onChangeProp;
	let parse;
	let required;
	let subscription;
	let type;
	let validate;
	let validateFields;
	let value;
	let valueForChange;
	if ($[0] !== props) {
		const { component: t0, afterSubmit: t1, allowNull: t2, beforeSubmit: t3, defaultValue: t4, format: t5, formatOnBlur: t6, initialValue: t7, isEqual: t8, name: t9, parse: t10, render, subscription: t11, validate: t12, validateFields: t13, value: t14, helperText: t15, valueForChange: t16, required: t17, ComponentProps: t18, type: t19, onChange: t20, ...t21 } = props;
		Component = t0;
		afterSubmit = t1;
		allowNull = t2;
		beforeSubmit = t3;
		defaultValue = t4;
		format = t5;
		formatOnBlur = t6;
		initialValue = t7;
		isEqual = t8;
		name = t9;
		parse = t10;
		subscription = t11;
		validate = t12;
		validateFields = t13;
		value = t14;
		helperText = t15;
		valueForChange = t16;
		required = t17;
		ComponentProps = t18;
		type = t19;
		onChangeProp = t20;
		componentProps = t21;
		$[0] = props;
		$[1] = Component;
		$[2] = ComponentProps;
		$[3] = afterSubmit;
		$[4] = allowNull;
		$[5] = beforeSubmit;
		$[6] = componentProps;
		$[7] = defaultValue;
		$[8] = format;
		$[9] = formatOnBlur;
		$[10] = helperText;
		$[11] = initialValue;
		$[12] = isEqual;
		$[13] = name;
		$[14] = onChangeProp;
		$[15] = parse;
		$[16] = required;
		$[17] = subscription;
		$[18] = type;
		$[19] = validate;
		$[20] = validateFields;
		$[21] = value;
		$[22] = valueForChange;
	} else {
		Component = $[1];
		ComponentProps = $[2];
		afterSubmit = $[3];
		allowNull = $[4];
		beforeSubmit = $[5];
		componentProps = $[6];
		defaultValue = $[7];
		format = $[8];
		formatOnBlur = $[9];
		helperText = $[10];
		initialValue = $[11];
		isEqual = $[12];
		name = $[13];
		onChangeProp = $[14];
		parse = $[15];
		required = $[16];
		subscription = $[17];
		type = $[18];
		validate = $[19];
		validateFields = $[20];
		value = $[21];
		valueForChange = $[22];
	}
	let t0;
	if ($[23] !== afterSubmit || $[24] !== allowNull || $[25] !== beforeSubmit || $[26] !== defaultValue || $[27] !== format || $[28] !== formatOnBlur || $[29] !== initialValue || $[30] !== isEqual || $[31] !== name || $[32] !== parse || $[33] !== subscription || $[34] !== type || $[35] !== validate || $[36] !== validateFields || $[37] !== value) {
		t0 = {
			afterSubmit,
			allowNull,
			beforeSubmit,
			defaultValue,
			format,
			formatOnBlur,
			initialValue,
			isEqual,
			name,
			parse,
			subscription,
			validate,
			validateFields,
			value,
			type
		};
		$[23] = afterSubmit;
		$[24] = allowNull;
		$[25] = beforeSubmit;
		$[26] = defaultValue;
		$[27] = format;
		$[28] = formatOnBlur;
		$[29] = initialValue;
		$[30] = isEqual;
		$[31] = name;
		$[32] = parse;
		$[33] = subscription;
		$[34] = type;
		$[35] = validate;
		$[36] = validateFields;
		$[37] = value;
		$[38] = t0;
	} else t0 = $[38];
	const fieldProps = t0;
	let t1;
	if ($[39] !== required || $[40] !== validate) {
		t1 = (value_0, allValues, meta) => {
			if (required && typeof value_0 !== "number" && isEmpty(value_0)) return "Required";
			if (validate) return validate(value_0, allValues, meta);
		};
		$[39] = required;
		$[40] = validate;
		$[41] = t1;
	} else t1 = $[41];
	const makeValidation = t1;
	let t2;
	if ($[42] !== Component || $[43] !== ComponentProps || $[44] !== componentProps || $[45] !== helperText || $[46] !== onChangeProp || $[47] !== ref || $[48] !== required || $[49] !== valueForChange) {
		t2 = (params) => {
			const { input, meta: meta_0 } = params;
			const { name: fieldName, onChange, ...inputProps } = input;
			const metaError = meta_0.error;
			const metaSubmitError = meta_0.submitError;
			const hasError = Boolean(meta_0.touched && (metaSubmitError && !meta_0.dirtySinceLastSubmit || metaError));
			const errorProps = {
				error: hasError,
				helperText: hasError ? metaError ?? metaSubmitError : helperText
			};
			const handleChange = (...t3) => {
				const args = t3;
				if (onChangeProp) onChangeProp(...args);
				if (valueForChange) onChange(valueForChange(args[0]));
				else onChange(...args);
			};
			return /* @__PURE__ */ React.createElement(Component, {
				ref,
				required,
				...componentProps,
				...ComponentProps,
				...errorProps,
				onChange: handleChange,
				name: fieldName,
				...inputProps
			});
		};
		$[42] = Component;
		$[43] = ComponentProps;
		$[44] = componentProps;
		$[45] = helperText;
		$[46] = onChangeProp;
		$[47] = ref;
		$[48] = required;
		$[49] = valueForChange;
		$[50] = t2;
	} else t2 = $[50];
	let t3;
	if ($[51] !== fieldProps || $[52] !== makeValidation || $[53] !== t2) {
		t3 = /* @__PURE__ */ React.createElement(Field, {
			...fieldProps,
			validate: makeValidation
		}, t2);
		$[51] = fieldProps;
		$[52] = makeValidation;
		$[53] = t2;
		$[54] = t3;
	} else t3 = $[54];
	return t3;
});
Field$1.displayName = "Field";
//#endregion
export { Field$1 as Field };

//# sourceMappingURL=Field.mjs.map