"use strict";
var __webpack_require__ = {};
(()=>{
    __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__, {
    SchemaSettingsDataScope: ()=>SchemaSettingsDataScope
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const external_react_i18next_namespaceObject = require("react-i18next");
const external_index_js_namespaceObject = require("../index.js");
const index_js_namespaceObject = require("../block-provider/index.js");
const action_hooks_js_namespaceObject = require("../collection-manager/action-hooks.js");
const external_flag_provider_index_js_namespaceObject = require("../flag-provider/index.js");
const external_variables_index_js_namespaceObject = require("../variables/index.js");
const external_SchemaSettings_js_namespaceObject = require("./SchemaSettings.js");
const useBaseVariable_js_namespaceObject = require("./VariableInput/hooks/useBaseVariable.js");
const VariableInput_js_namespaceObject = require("./VariableInput/VariableInput.js");
const SchemaSettingsDataScope = function(props) {
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { getFields } = (0, action_hooks_js_namespaceObject.useCollectionFilterOptionsV2)(props.collectionName);
    const record = (0, external_index_js_namespaceObject.useRecord)();
    const { form } = (0, index_js_namespaceObject.useFormBlockContext)();
    const variables = (0, external_variables_index_js_namespaceObject.useVariables)();
    const localVariables = (0, external_variables_index_js_namespaceObject.useLocalVariables)();
    const { getAllCollectionsInheritChain } = (0, external_index_js_namespaceObject.useCollectionManager_deprecated)();
    const { isInSubForm, isInSubTable } = (0, external_flag_provider_index_js_namespaceObject.useFlag)() || {};
    const dynamicComponent = (0, external_react_namespaceObject.useCallback)((props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.DatePickerProvider, {
            value: {
                utc: false
            },
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(VariableInput_js_namespaceObject.VariableInput, {
                ...props,
                form: form,
                record: record,
                shouldChange: (0, VariableInput_js_namespaceObject.getShouldChange)({
                    collectionField: props.collectionField,
                    variables,
                    localVariables,
                    getAllCollectionsInheritChain
                })
            })
        }), [
        form,
        getAllCollectionsInheritChain,
        localVariables,
        record,
        variables
    ]);
    const getSchema = ()=>({
            type: 'object',
            title: t('Set the data scope'),
            properties: {
                filter: {
                    enum: props.collectionFilterOption || getFields(),
                    'x-decorator': (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(useBaseVariable_js_namespaceObject.BaseVariableProvider, {
                            ...props,
                            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_flag_provider_index_js_namespaceObject.FlagProvider, {
                                isInSubForm: isInSubForm,
                                isInSubTable: isInSubTable,
                                children: props.children
                            })
                        }),
                    'x-decorator-props': {
                        isDisabled
                    },
                    'x-component': 'Filter',
                    'x-component-props': {
                        collectionName: props.collectionName,
                        dynamicComponent: props.dynamicComponent || dynamicComponent
                    }
                }
            }
        });
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_SchemaSettings_js_namespaceObject.SchemaSettingsModalItem, {
        title: t('Set the data scope'),
        initialValues: {
            filter: props.defaultFilter
        },
        schema: getSchema,
        onSubmit: props.onSubmit
    });
};
function isDisabled(params) {
    var _option_schema;
    const { option, collectionField, uiSchema } = params;
    if (!uiSchema || !collectionField) return true;
    if ('json' === collectionField.interface) return false;
    if (option.target) return false;
    if ([
        'input',
        'markdown',
        'richText',
        'textarea',
        'username'
    ].includes(collectionField.interface)) {
        var _option_schema1;
        return ![
            'string',
            'number'
        ].includes(null === (_option_schema1 = option.schema) || void 0 === _option_schema1 ? void 0 : _option_schema1.type);
    }
    if (collectionField.interface && option.interface) return collectionField.interface !== option.interface;
    if ((null == uiSchema ? void 0 : uiSchema['x-component']) !== (null === (_option_schema = option.schema) || void 0 === _option_schema ? void 0 : _option_schema['x-component'])) return true;
    return false;
}
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
});
