'use client';
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
import React from 'react';
import { Tooltip } from '../../elements/Tooltip/index.js';
import { useFormFields, useFormSubmitted } from '../../forms/Form/context.js';
import './index.scss';
const baseClass = 'field-error';
export const FieldError = (props)=>{
    const { alignCaret = 'right', message: messageFromProps, path, showError: showErrorFromProps } = props;
    const hasSubmitted = useFormSubmitted();
    const field = useFormFields(([fields])=>fields && fields?.[path] || null);
    const { errorMessage, valid } = field || {};
    const message = messageFromProps || errorMessage;
    const showMessage = showErrorFromProps || hasSubmitted && valid === false;
    if (showMessage && message?.length) {
        return /*#__PURE__*/ _jsxDEV(Tooltip, {
            alignCaret: alignCaret,
            className: baseClass,
            delay: 0,
            staticPositioning: true,
            children: message
        }, void 0, false, {
            fileName: "src/fields/FieldError/index.tsx",
            lineNumber: 31,
            columnNumber: 7
        }, this);
    }
    return null;
};

//# sourceMappingURL=index.js.map