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_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__index_mjs__ from "../index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__ from "../block-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_action_hooks_mjs__ from "../collection-manager/action-hooks.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__flag_provider_index_mjs__ from "../flag-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__variables_index_mjs__ from "../variables/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__SchemaSettings_mjs__ from "./SchemaSettings.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__VariableInput_hooks_useBaseVariable_mjs__ from "./VariableInput/hooks/useBaseVariable.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__VariableInput_VariableInput_mjs__ from "./VariableInput/VariableInput.mjs";
const SchemaSettingsDataScope = function(props) {
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const { getFields } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_action_hooks_mjs__.useCollectionFilterOptionsV2)(props.collectionName);
    const record = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useRecord)();
    const { form } = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__.useFormBlockContext)();
    const variables = (0, __WEBPACK_EXTERNAL_MODULE__variables_index_mjs__.useVariables)();
    const localVariables = (0, __WEBPACK_EXTERNAL_MODULE__variables_index_mjs__.useLocalVariables)();
    const { getAllCollectionsInheritChain } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useCollectionManager_deprecated)();
    const { isInSubForm, isInSubTable } = (0, __WEBPACK_EXTERNAL_MODULE__flag_provider_index_mjs__.useFlag)() || {};
    const dynamicComponent = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__index_mjs__.DatePickerProvider, {
            value: {
                utc: false
            },
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__VariableInput_VariableInput_mjs__.VariableInput, {
                ...props,
                form: form,
                record: record,
                shouldChange: (0, __WEBPACK_EXTERNAL_MODULE__VariableInput_VariableInput_mjs__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__VariableInput_hooks_useBaseVariable_mjs__.BaseVariableProvider, {
                            ...props,
                            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__flag_provider_index_mjs__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__SchemaSettings_mjs__.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;
}
export { SchemaSettingsDataScope };
