'use client';
import { getTranslation } from '@payloadcms/translations';
import React, { useCallback } from 'react';
import { useTranslation } from '../../../providers/Translation/index.js';
import LabelComp from '../../Label/index.js';
import useField from '../../useField/index.js';
import { withCondition } from '../../withCondition/index.js';
import { fieldBaseClass } from '../shared.js';
export const Email = (props)=>{
    const { name, AfterInput, BeforeInput, Description, Error, Label: LabelFromProps, autoComplete, className, label, path: pathFromProps, placeholder, readOnly, required, style, validate, width } = props;
    const Label = LabelFromProps || /*#__PURE__*/ React.createElement(LabelComp, {
        label: label,
        required: required
    });
    const { i18n } = useTranslation();
    const memoizedValidate = useCallback((value, options)=>{
        if (typeof validate === 'function') {
            return validate(value, {
                ...options,
                required
            });
        }
    }, [
        validate,
        required
    ]);
    const { path, setValue, showError, value } = useField({
        path: pathFromProps || name,
        validate: memoizedValidate
    });
    return /*#__PURE__*/ React.createElement("div", {
        className: [
            fieldBaseClass,
            'email',
            className,
            showError && 'error',
            readOnly && 'read-only'
        ].filter(Boolean).join(' '),
        style: {
            ...style,
            width
        }
    }, Error, Label, /*#__PURE__*/ React.createElement("div", null, BeforeInput, /*#__PURE__*/ React.createElement("input", {
        autoComplete: autoComplete,
        disabled: Boolean(readOnly),
        id: `field-${path.replace(/\./g, '__')}`,
        name: path,
        onChange: setValue,
        placeholder: getTranslation(placeholder, i18n),
        type: "email",
        value: value || ''
    }), AfterInput), Description);
};
export default withCondition(Email);

//# sourceMappingURL=index.js.map