"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    useIsAllowToSetDefaultValue: ()=>useIsAllowToSetDefaultValue,
    DefaultValueProvider: ()=>DefaultValueProvider,
    interfacesOfUnsupportedDefaultValue: ()=>interfacesOfUnsupportedDefaultValue
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
const schema_namespaceObject = require("@tachybase/schema");
const index_js_namespaceObject = require("../../block-provider/index.js");
const useCollection_deprecated_js_namespaceObject = require("../../collection-manager/hooks/useCollection_deprecated.js");
const useCollectionManager_deprecated_js_namespaceObject = require("../../collection-manager/hooks/useCollectionManager_deprecated.js");
const external_isPatternDisabled_js_namespaceObject = require("../isPatternDisabled.js");
const external_SchemaSettings_js_namespaceObject = require("../SchemaSettings.js");
const DefaultValueContext = /*#__PURE__*/ external_react_default().createContext(null);
const DefaultValueProvider = (props)=>{
    const value = (0, external_react_namespaceObject.useMemo)(()=>({
            isAllowToSetDefaultValue: props.isAllowToSetDefaultValue
        }), [
        props.isAllowToSetDefaultValue
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.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, useCollectionManager_deprecated_js_namespaceObject.useCollectionManager_deprecated)();
    const { getField } = (0, useCollection_deprecated_js_namespaceObject.useCollection_deprecated)();
    const { form: innerForm } = (0, index_js_namespaceObject.useFormBlockContext)();
    const innerFieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { type } = (0, index_js_namespaceObject.useFormBlockType)();
    const { isAllowToSetDefaultValue = _isAllowToSetDefaultValue } = (0, external_react_namespaceObject.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, external_SchemaSettings_js_namespaceObject.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, external_isPatternDisabled_js_namespaceObject.isPatternDisabled)(fieldSchema) && !interfacesOfUnsupportedDefaultValue.includes(null == collectionField ? void 0 : collectionField.interface) && !(0, external_SchemaSettings_js_namespaceObject.isSystemField)(collectionField, getInterface);
}
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
