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__block_provider_index_mjs__ from "../../block-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_hooks_useCollection_deprecated_mjs__ from "../../collection-manager/hooks/useCollection_deprecated.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_hooks_useCollectionManager_deprecated_mjs__ from "../../collection-manager/hooks/useCollectionManager_deprecated.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__isPatternDisabled_mjs__ from "../isPatternDisabled.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__SchemaSettings_mjs__ from "../SchemaSettings.mjs";
const DefaultValueContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext(null);
const DefaultValueProvider = (props)=>{
    const value = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            isAllowToSetDefaultValue: props.isAllowToSetDefaultValue
        }), [
        props.isAllowToSetDefaultValue
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(DefaultValueContext.Provider, {
        value: value,
        children: props.children
    });
};
const useIsAllowToSetDefaultValue = function() {
    let { form, fieldSchema, collectionField } = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
    const { getInterface, getCollectionJoinField } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_hooks_useCollectionManager_deprecated_mjs__.useCollectionManager_deprecated)();
    const { getField } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_hooks_useCollection_deprecated_mjs__.useCollection_deprecated)();
    const { form: innerForm } = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__.useFormBlockContext)();
    const innerFieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const { type } = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__.useFormBlockType)();
    const { isAllowToSetDefaultValue = _isAllowToSetDefaultValue } = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(DefaultValueContext) || {};
    const innerCollectionField = getField(innerFieldSchema['name']) || getCollectionJoinField(innerFieldSchema['x-collection-field']);
    return {
        isAllowToSetDefaultValue: (isSubTableColumn)=>isAllowToSetDefaultValue({
                collectionField: collectionField || innerCollectionField,
                getInterface,
                form: form || innerForm,
                formBlockType: type,
                fieldSchema: fieldSchema || innerFieldSchema,
                isSubTableColumn
            })
    };
};
const interfacesOfUnsupportedDefaultValue = [
    'o2o',
    'oho',
    'obo',
    'o2m',
    'attachment',
    'expression',
    'point',
    'lineString',
    'circle',
    'polygon',
    'sequence',
    'formula'
];
function _isAllowToSetDefaultValue(param) {
    let { collectionField, getInterface, formBlockType, form, fieldSchema, isSubTableColumn } = param;
    var _fieldSchema_xcomponentprops;
    if (isSubTableColumn) return !interfacesOfUnsupportedDefaultValue.includes(null == collectionField ? void 0 : collectionField.interface) && !(0, __WEBPACK_EXTERNAL_MODULE__SchemaSettings_mjs__.isSystemField)(collectionField, getInterface);
    if (!collectionField) return false;
    if (collectionField.target && (null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.mode) && ![
        'Picker',
        'Select'
    ].includes(fieldSchema['x-component-props'].mode)) return false;
    if ('create' !== formBlockType) return false;
    return !(null == form ? void 0 : form.readPretty) && !(0, __WEBPACK_EXTERNAL_MODULE__isPatternDisabled_mjs__.isPatternDisabled)(fieldSchema) && !interfacesOfUnsupportedDefaultValue.includes(null == collectionField ? void 0 : collectionField.interface) && !(0, __WEBPACK_EXTERNAL_MODULE__SchemaSettings_mjs__.isSystemField)(collectionField, getInterface);
}
export { DefaultValueProvider, interfacesOfUnsupportedDefaultValue, useIsAllowToSetDefaultValue };
