/**
 * @license MIT
 * author: Cube Dev Team
 * @cube-dev/ui-kit v0.0.0-canary-9f40d0e
 * Released under the MIT license.
 */

import { jsx as _jsx } from "react/jsx-runtime";
import { mergeProps } from '../../utils/react/index.js';
import { FieldWrapper } from './FieldWrapper/index.js';
export function wrapWithField(component, ref, props) {
    let { forceField, label, extra, labelPosition = 'top', labelStyles, isRequired, isDisabled, necessityIndicator, message, messageStyles, description, errorMessage, validationState, labelProps, fieldProps, fieldStyles, requiredMark = true, tooltip, isHidden, labelSuffix, } = props;
    if (!label && !forceField) {
        return component;
    }
    // Merge fieldStyles as shorthand for fieldProps.styles (fieldStyles takes priority)
    const mergedFieldProps = fieldStyles
        ? mergeProps(fieldProps, { styles: fieldStyles })
        : fieldProps;
    // Merge labelStyles as shorthand for labelProps.styles (labelStyles takes priority)
    const mergedLabelProps = labelStyles
        ? mergeProps(labelProps, { styles: labelStyles })
        : labelProps;
    // Remove id from fieldProps to avoid duplication (id should be on the input element, not the field wrapper)
    const { id: _id, ...fieldPropsWithoutId } = mergedFieldProps || {};
    return (_jsx(FieldWrapper, { label,
        extra,
        labelPosition,
        isRequired,
        isDisabled,
        necessityIndicator,
        labelProps: mergedLabelProps,
        fieldProps: fieldPropsWithoutId,
        message,
        messageStyles,
        description,
        errorMessage,
        validationState,
        requiredMark,
        tooltip,
        isHidden,
        labelSuffix,
        Component: component,
        ref }));
}

        