'use client';
import React from 'react';
import { Tooltip } from '../../elements/Tooltip/index.js';
import { useFieldPath } from '../FieldPathProvider/index.js';
import { useFormFields, useFormSubmitted } from '../Form/context.js';
const baseClass = 'field-error';
const Error = (props)=>{
    const { alignCaret = 'right', message: messageFromProps, path: pathFromProps, showError: showErrorFromProps } = props;
    const { path: pathFromContext } = useFieldPath();
    const path = pathFromProps || pathFromContext;
    const hasSubmitted = useFormSubmitted();
    const field = useFormFields(([fields])=>fields && fields?.[path] || null);
    const { errorMessage, valid } = field || {};
    const message = messageFromProps || errorMessage;
    const showMessage = showErrorFromProps || hasSubmitted && !valid;
    if (showMessage) {
        return /*#__PURE__*/ React.createElement(Tooltip, {
            alignCaret: alignCaret,
            className: baseClass,
            delay: 0
        }, message);
    }
    return null;
};
export default Error;

//# sourceMappingURL=index.js.map