'use client';
import { getTranslation } from '@payloadcms/translations';
import React, { useCallback } from 'react';
import { useConfig } from '../../../providers/Config/index.js';
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 { isFieldRTL } from '../shared.js';
import { TextareaInput } from './Input.js';
const Textarea = (props)=>{
    const { name, AfterInput, BeforeInput, Description, Error, Label: LabelFromProps, className, label, locale, localized, maxLength, minLength, path: pathFromProps, placeholder, required, rtl, style, validate, width } = props;
    const Label = LabelFromProps || /*#__PURE__*/ React.createElement(LabelComp, {
        label: label,
        required: required
    });
    const rows = 'rows' in props ? props.rows : undefined;
    const { i18n } = useTranslation();
    const { localization } = useConfig();
    const isRTL = isFieldRTL({
        fieldLocalized: localized,
        fieldRTL: rtl,
        locale,
        localizationConfig: localization || undefined
    });
    const memoizedValidate = useCallback((value, options)=>{
        if (typeof validate === 'function') return validate(value, {
            ...options,
            maxLength,
            minLength,
            required
        });
    }, [
        validate,
        required,
        maxLength,
        minLength
    ]);
    const { path, readOnly, setValue, showError, value } = useField({
        path: pathFromProps || name,
        validate: memoizedValidate
    });
    return /*#__PURE__*/ React.createElement(TextareaInput, {
        AfterInput: AfterInput,
        BeforeInput: BeforeInput,
        Description: Description,
        Error: Error,
        Label: Label,
        className: className,
        onChange: (e)=>{
            setValue(e.target.value);
        },
        path: path,
        placeholder: getTranslation(placeholder, i18n),
        readOnly: readOnly,
        required: required,
        rows: rows,
        rtl: isRTL,
        showError: showError,
        style: style,
        value: value,
        width: width
    });
};
export default withCondition(Textarea);

//# sourceMappingURL=index.js.map