'use client';
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
import { getTranslation } from '@payloadcms/translations';
import React, { useCallback, useMemo } from 'react';
import { RenderCustomComponent } from '../../elements/RenderCustomComponent/index.js';
import { FieldDescription } from '../../fields/FieldDescription/index.js';
import { FieldError } from '../../fields/FieldError/index.js';
import { useField } from '../../forms/useField/index.js';
import { withCondition } from '../../forms/withCondition/index.js';
import { useTranslation } from '../../providers/Translation/index.js';
import { FieldLabel } from '../FieldLabel/index.js';
import { mergeFieldStyles } from '../mergeFieldStyles.js';
import { fieldBaseClass } from '../shared/index.js';
import './index.scss';
const EmailFieldComponent = (props)=>{
    const { field, field: { admin: { autoComplete, className, description, placeholder } = {}, label, localized, required } = {}, path: pathFromProps, readOnly, validate } = props;
    const { i18n } = useTranslation();
    const memoizedValidate = useCallback((value, options)=>{
        if (typeof validate === 'function') {
            return validate(value, {
                ...options,
                required
            });
        }
    }, [
        validate,
        required
    ]);
    const { customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {}, disabled, path, setValue, showError, value } = useField({
        potentiallyStalePath: pathFromProps,
        validate: memoizedValidate
    });
    const styles = useMemo(()=>mergeFieldStyles(field), [
        field
    ]);
    return /*#__PURE__*/ _jsxDEV("div", {
        className: [
            fieldBaseClass,
            'email',
            className,
            showError && 'error',
            (readOnly || disabled) && 'read-only'
        ].filter(Boolean).join(' '),
        style: styles,
        children: [
            /*#__PURE__*/ _jsxDEV(RenderCustomComponent, {
                CustomComponent: Label,
                Fallback: /*#__PURE__*/ _jsxDEV(FieldLabel, {
                    label: label,
                    localized: localized,
                    path: path,
                    required: required
                }, void 0, false, {
                    fileName: "src/fields/Email/index.tsx",
                    lineNumber: 82,
                    columnNumber: 11
                }, void 0)
            }, void 0, false, {
                fileName: "src/fields/Email/index.tsx",
                lineNumber: 79,
                columnNumber: 7
            }, this),
            /*#__PURE__*/ _jsxDEV("div", {
                className: `${fieldBaseClass}__wrap`,
                children: [
                    /*#__PURE__*/ _jsxDEV(RenderCustomComponent, {
                        CustomComponent: Error,
                        Fallback: /*#__PURE__*/ _jsxDEV(FieldError, {
                            path: path,
                            showError: showError
                        }, void 0, false, {
                            fileName: "src/fields/Email/index.tsx",
                            lineNumber: 88,
                            columnNumber: 21
                        }, void 0)
                    }, void 0, false, {
                        fileName: "src/fields/Email/index.tsx",
                        lineNumber: 86,
                        columnNumber: 9
                    }, this),
                    BeforeInput,
                    /* disable eslint here because the label is dynamic */ /* eslint-disable-next-line jsx-a11y/control-has-associated-label */ /*#__PURE__*/ _jsxDEV("input", {
                        autoComplete: autoComplete,
                        disabled: readOnly || disabled,
                        id: `field-${path.replace(/\./g, '__')}`,
                        name: path,
                        onChange: setValue,
                        placeholder: getTranslation(placeholder, i18n),
                        required: required,
                        type: "email",
                        value: value || ''
                    }, void 0, false, {
                        fileName: "src/fields/Email/index.tsx",
                        lineNumber: 93,
                        columnNumber: 9
                    }, this),
                    AfterInput
                ]
            }, void 0, true, {
                fileName: "src/fields/Email/index.tsx",
                lineNumber: 85,
                columnNumber: 7
            }, this),
            /*#__PURE__*/ _jsxDEV(RenderCustomComponent, {
                CustomComponent: Description,
                Fallback: /*#__PURE__*/ _jsxDEV(FieldDescription, {
                    description: description,
                    path: path
                }, void 0, false, {
                    fileName: "src/fields/Email/index.tsx",
                    lineNumber: 108,
                    columnNumber: 19
                }, void 0)
            }, void 0, false, {
                fileName: "src/fields/Email/index.tsx",
                lineNumber: 106,
                columnNumber: 7
            }, this)
        ]
    }, void 0, true, {
        fileName: "src/fields/Email/index.tsx",
        lineNumber: 67,
        columnNumber: 5
    }, this);
};
export const EmailField = withCondition(EmailFieldComponent);

//# sourceMappingURL=index.js.map