import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE__ant_design_icons__ from "@ant-design/icons";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_nanoid__ from "nanoid";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__data_source_collection_field_CollectionFieldProvider_mjs__ from "../../../data-source/collection-field/CollectionFieldProvider.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__input_index_mjs__ from "../input/index.mjs";
const NanoIDInput = Object.assign((0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.connect)(__WEBPACK_EXTERNAL_MODULE_antd__.Input, (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.mapProps)((props, field)=>{
    const { size, customAlphabet } = (0, __WEBPACK_EXTERNAL_MODULE__data_source_collection_field_CollectionFieldProvider_mjs__.useCollectionField)() || {};
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const form = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useForm)();
    function isValidNanoid(value) {
        if ((null == value ? void 0 : value.length) !== size) return t('Field value size is') + " ".concat(size || 21);
        for(let i = 0; i < value.length; i++)if ((null == customAlphabet ? void 0 : customAlphabet.indexOf(value[i])) === -1) return t("Field value do not meet the requirements");
    }
    (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
        if (!field.initialValue && customAlphabet) field.setInitialValue((0, __WEBPACK_EXTERNAL_MODULE_nanoid__.customAlphabet)(customAlphabet, size)());
        form.setFieldState(field.props.name, (state)=>{
            state.validator = isValidNanoid;
        });
    }, []);
    return {
        ...props,
        suffix: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("span", {
            children: (null == field ? void 0 : field['loading']) || (null == field ? void 0 : field['validating']) ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.LoadingOutlined, {}) : props.suffix
        })
    };
}), (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.mapReadPretty)(__WEBPACK_EXTERNAL_MODULE__input_index_mjs__.ReadPretty.Input)), {
    ReadPretty: __WEBPACK_EXTERNAL_MODULE__input_index_mjs__.ReadPretty.Input
});
export { NanoIDInput };
