"use strict";
var __webpack_modules__ = {
    "../../api-client": function(module) {
        module.exports = require("../../api-client/index.js");
    },
    "../../built-in/dynamic-page/utils": function(module) {
        module.exports = require("../../built-in/dynamic-page/utils.js");
    },
    "../../collection-manager": function(module) {
        module.exports = require("../../collection-manager/index.js");
    },
    "../../filter-provider/FilterProvider": function(module) {
        module.exports = require("../../filter-provider/FilterProvider.js");
    },
    "../../filter-provider/utils": function(module) {
        module.exports = require("../../filter-provider/utils.js");
    },
    "../..": function(module) {
        module.exports = require("../../index.js");
    },
    "../../record-provider": function(module) {
        module.exports = require("../../record-provider/index.js");
    },
    "../../schema-component/antd/association-field/util": function(module) {
        module.exports = require("../../schema-component/antd/association-field/util.js");
    },
    "../../schema-component": function(module) {
        module.exports = require("../../schema-component/index.js");
    },
    "../../user": function(module) {
        module.exports = require("../../user/index.js");
    },
    "../../variables": function(module) {
        module.exports = require("../../variables/index.js");
    },
    "../../variables/utils/isVariable": function(module) {
        module.exports = require("../../variables/utils/isVariable.js");
    },
    "../../variables/utils/transformVariableValue": function(module) {
        module.exports = require("../../variables/utils/transformVariableValue.js");
    },
    "../BlockProvider": function(module) {
        module.exports = require("../BlockProvider.js");
    },
    "../DetailsBlockProvider": function(module) {
        module.exports = require("../DetailsBlockProvider.js");
    },
    "../TableFieldProvider": function(module) {
        module.exports = require("../TableFieldProvider.js");
    },
    "./useDataBlockSourceId": function(module) {
        module.exports = require("./useDataBlockSourceId.js");
    },
    "./useFormActiveFields": function(module) {
        module.exports = require("./useFormActiveFields.js");
    },
    "./useIsMobile": function(module) {
        module.exports = require("./useIsMobile.js");
    },
    "./useParsedFilter": function(module) {
        module.exports = require("./useParsedFilter.js");
    },
    "@tachybase/schema": function(module) {
        module.exports = require("@tachybase/schema");
    },
    "@tachybase/utils/client": function(module) {
        module.exports = require("@tachybase/utils/client");
    },
    antd: function(module) {
        module.exports = require("antd");
    },
    flat: function(module) {
        module.exports = require("flat");
    },
    lodash: function(module) {
        module.exports = require("lodash");
    },
    "lodash/get": function(module) {
        module.exports = require("lodash/get");
    },
    "lodash/omit": function(module) {
        module.exports = require("lodash/omit");
    },
    react: function(module) {
        module.exports = require("react");
    },
    "react-i18next": function(module) {
        module.exports = require("react-i18next");
    },
    "react-router-dom": function(module) {
        module.exports = require("react-router-dom");
    },
    "react-to-print": function(module) {
        module.exports = require("react-to-print");
    }
};
var __webpack_module_cache__ = {};
function __webpack_require__(moduleId) {
    var cachedModule = __webpack_module_cache__[moduleId];
    if (void 0 !== cachedModule) return cachedModule.exports;
    var module = __webpack_module_cache__[moduleId] = {
        exports: {}
    };
    __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
    return module.exports;
}
(()=>{
    __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__, {
    filterByCleanedFields: function() {
        return filterByCleanedFields;
    },
    findFilterTargets: function() {
        return findFilterTargets;
    },
    getAfterWorkflows: function() {
        return getAfterWorkflows;
    },
    getAssociationPath: function() {
        return getAssociationPath;
    },
    getBeforeWorkflows: function() {
        return getBeforeWorkflows;
    },
    getFormValues: function() {
        return getFormValues;
    },
    updateFilterTargets: function() {
        return updateFilterTargets;
    },
    useAssociationCreateActionProps: function() {
        return useAssociationCreateActionProps;
    },
    useAssociationFilterBlockProps: function() {
        return useAssociationFilterBlockProps;
    },
    useAssociationFilterProps: function() {
        return useAssociationFilterProps;
    },
    useAssociationNames: function() {
        return useAssociationNames;
    },
    useBulkDestroyActionProps: function() {
        return useBulkDestroyActionProps;
    },
    useCancelActionProps: function() {
        return useCancelActionProps;
    },
    useCollectValuesToSubmit: function() {
        return useCollectValuesToSubmit;
    },
    useCreateActionProps: function() {
        return useCreateActionProps;
    },
    useCustomizeRequestActionProps: function() {
        return useCustomizeRequestActionProps;
    },
    useCustomizeUpdateActionProps: function() {
        return useCustomizeUpdateActionProps;
    },
    useDestroyActionProps: function() {
        return useDestroyActionProps;
    },
    useDetailPrintActionProps: function() {
        return useDetailPrintActionProps;
    },
    useDetailsPaginationProps: function() {
        return useDetailsPaginationProps;
    },
    useDisassociateActionProps: function() {
        return useDisassociateActionProps;
    },
    useFilterBlockActionProps: function() {
        return useFilterBlockActionProps;
    },
    useInsertSchema: function() {
        return useInsertSchema;
    },
    useOptionalFieldList: function() {
        return useOptionalFieldList;
    },
    useRefreshActionProps: function() {
        return useRefreshActionProps;
    },
    useRemoveActionProps: function() {
        return useRemoveActionProps;
    },
    useResetBlockActionProps: function() {
        return useResetBlockActionProps;
    },
    useUpdateActionProps: function() {
        return useUpdateActionProps;
    }
});
var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("react");
var _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("@tachybase/schema");
var _tachybase_utils_client__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("@tachybase/utils/client");
var antd__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("antd");
var flat__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("flat");
var flat__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/ __webpack_require__.n(flat__WEBPACK_IMPORTED_MODULE_4__);
var lodash__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("lodash");
var lodash__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/ __webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_5__);
var lodash_get__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__("lodash/get");
var lodash_get__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/ __webpack_require__.n(lodash_get__WEBPACK_IMPORTED_MODULE_6__);
var lodash_omit__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__("lodash/omit");
var lodash_omit__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/ __webpack_require__.n(lodash_omit__WEBPACK_IMPORTED_MODULE_7__);
var react_i18next__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__("react-i18next");
var react_router_dom__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__("react-router-dom");
var react_to_print__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__("react-to-print");
var ___WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__("../..");
var _api_client__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__("../../api-client");
var _built_in_dynamic_page_utils__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__("../../built-in/dynamic-page/utils");
var _collection_manager__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__("../../collection-manager");
var _filter_provider_FilterProvider__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__("../../filter-provider/FilterProvider");
var _filter_provider_utils__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__("../../filter-provider/utils");
var _record_provider__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__("../../record-provider");
var _schema_component__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__("../../schema-component");
var _schema_component_antd_association_field_util__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__("../../schema-component/antd/association-field/util");
var _user__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__("../../user");
var _variables__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__("../../variables");
var _variables_utils_isVariable__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__("../../variables/utils/isVariable");
var _variables_utils_transformVariableValue__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__("../../variables/utils/transformVariableValue");
var _BlockProvider__WEBPACK_IMPORTED_MODULE_24__ = __webpack_require__("../BlockProvider");
var _DetailsBlockProvider__WEBPACK_IMPORTED_MODULE_25__ = __webpack_require__("../DetailsBlockProvider");
var _TableFieldProvider__WEBPACK_IMPORTED_MODULE_26__ = __webpack_require__("../TableFieldProvider");
var _useFormActiveFields__WEBPACK_IMPORTED_MODULE_27__ = __webpack_require__("./useFormActiveFields");
var __WEBPACK_REEXPORT_OBJECT__ = {};
for(var __WEBPACK_IMPORT_KEY__ in _useFormActiveFields__WEBPACK_IMPORTED_MODULE_27__)if ([
    "useAssociationCreateActionProps",
    "useResetBlockActionProps",
    "findFilterTargets",
    "useInsertSchema",
    "filterByCleanedFields",
    "useOptionalFieldList",
    "useCollectValuesToSubmit",
    "useCreateActionProps",
    "useRemoveActionProps",
    "useCustomizeUpdateActionProps",
    "useRefreshActionProps",
    "useAssociationFilterProps",
    "default",
    "useAssociationFilterBlockProps",
    "useFilterBlockActionProps",
    "getAfterWorkflows",
    "updateFilterTargets",
    "useUpdateActionProps",
    "getFormValues",
    "useDisassociateActionProps",
    "useDetailPrintActionProps",
    "useCustomizeRequestActionProps",
    "useCancelActionProps",
    "getBeforeWorkflows",
    "useAssociationNames",
    "useDetailsPaginationProps",
    "useDestroyActionProps",
    "useBulkDestroyActionProps",
    "getAssociationPath"
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
    return _useFormActiveFields__WEBPACK_IMPORTED_MODULE_27__[key];
}).bind(0, __WEBPACK_IMPORT_KEY__);
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
var _useParsedFilter__WEBPACK_IMPORTED_MODULE_28__ = __webpack_require__("./useParsedFilter");
var __WEBPACK_REEXPORT_OBJECT__ = {};
for(var __WEBPACK_IMPORT_KEY__ in _useParsedFilter__WEBPACK_IMPORTED_MODULE_28__)if ([
    "useAssociationCreateActionProps",
    "useResetBlockActionProps",
    "findFilterTargets",
    "useInsertSchema",
    "filterByCleanedFields",
    "useOptionalFieldList",
    "useCollectValuesToSubmit",
    "useCreateActionProps",
    "useRemoveActionProps",
    "useCustomizeUpdateActionProps",
    "useRefreshActionProps",
    "useAssociationFilterProps",
    "default",
    "useAssociationFilterBlockProps",
    "useFilterBlockActionProps",
    "getAfterWorkflows",
    "updateFilterTargets",
    "useUpdateActionProps",
    "getFormValues",
    "useDisassociateActionProps",
    "useDetailPrintActionProps",
    "useCustomizeRequestActionProps",
    "useCancelActionProps",
    "getBeforeWorkflows",
    "useAssociationNames",
    "useDetailsPaginationProps",
    "useDestroyActionProps",
    "useBulkDestroyActionProps",
    "getAssociationPath"
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
    return _useParsedFilter__WEBPACK_IMPORTED_MODULE_28__[key];
}).bind(0, __WEBPACK_IMPORT_KEY__);
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
var _useDataBlockSourceId__WEBPACK_IMPORTED_MODULE_29__ = __webpack_require__("./useDataBlockSourceId");
var __WEBPACK_REEXPORT_OBJECT__ = {};
for(var __WEBPACK_IMPORT_KEY__ in _useDataBlockSourceId__WEBPACK_IMPORTED_MODULE_29__)if ([
    "useAssociationCreateActionProps",
    "useResetBlockActionProps",
    "findFilterTargets",
    "useInsertSchema",
    "filterByCleanedFields",
    "useOptionalFieldList",
    "useCollectValuesToSubmit",
    "useCreateActionProps",
    "useRemoveActionProps",
    "useCustomizeUpdateActionProps",
    "useRefreshActionProps",
    "useAssociationFilterProps",
    "default",
    "useAssociationFilterBlockProps",
    "useFilterBlockActionProps",
    "getAfterWorkflows",
    "updateFilterTargets",
    "useUpdateActionProps",
    "getFormValues",
    "useDisassociateActionProps",
    "useDetailPrintActionProps",
    "useCustomizeRequestActionProps",
    "useCancelActionProps",
    "getBeforeWorkflows",
    "useAssociationNames",
    "useDetailsPaginationProps",
    "useDestroyActionProps",
    "useBulkDestroyActionProps",
    "getAssociationPath"
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
    return _useDataBlockSourceId__WEBPACK_IMPORTED_MODULE_29__[key];
}).bind(0, __WEBPACK_IMPORT_KEY__);
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
var _useIsMobile__WEBPACK_IMPORTED_MODULE_30__ = __webpack_require__("./useIsMobile");
var __WEBPACK_REEXPORT_OBJECT__ = {};
for(var __WEBPACK_IMPORT_KEY__ in _useIsMobile__WEBPACK_IMPORTED_MODULE_30__)if ([
    "useAssociationCreateActionProps",
    "useResetBlockActionProps",
    "findFilterTargets",
    "useInsertSchema",
    "filterByCleanedFields",
    "useOptionalFieldList",
    "useCollectValuesToSubmit",
    "useCreateActionProps",
    "useRemoveActionProps",
    "useCustomizeUpdateActionProps",
    "useRefreshActionProps",
    "useAssociationFilterProps",
    "default",
    "useAssociationFilterBlockProps",
    "useFilterBlockActionProps",
    "getAfterWorkflows",
    "updateFilterTargets",
    "useUpdateActionProps",
    "getFormValues",
    "useDisassociateActionProps",
    "useDetailPrintActionProps",
    "useCustomizeRequestActionProps",
    "useCancelActionProps",
    "getBeforeWorkflows",
    "useAssociationNames",
    "useDetailsPaginationProps",
    "useDestroyActionProps",
    "useBulkDestroyActionProps",
    "getAssociationPath"
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
    return _useIsMobile__WEBPACK_IMPORTED_MODULE_30__[key];
}).bind(0, __WEBPACK_IMPORT_KEY__);
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
function renderTemplate(str, data) {
    const re = /\{\{\s*((\w+\.?)+)\s*\}\}/g;
    return str.replace(re, function(_, key) {
        return lodash_get__WEBPACK_IMPORTED_MODULE_6___default()(data, key) || '';
    });
}
function filterByCleanedFields(mergeFilter) {
    const items = flat__WEBPACK_IMPORTED_MODULE_4___default()(mergeFilter);
    const result = {};
    const seen = new Set();
    for(const key in items){
        const value = items[key];
        if (void 0 === value) continue;
        const pathParts = key.split('.');
        const filteredParts = pathParts.filter((p)=>!/^\d+$/.test(p) && ![
                '$and',
                '$or'
            ].includes(p));
        const fieldPath = filteredParts.join('.');
        const uniqueKey = "".concat(fieldPath, "|").concat(JSON.stringify(value));
        if (!seen.has(uniqueKey)) {
            seen.add(uniqueKey);
            result[key] = value;
        }
    }
    return flat__WEBPACK_IMPORTED_MODULE_4___default().unflatten(result);
}
function getFormValues(param) {
    let { filterByTk, field, form, fieldNames, getField, resource, actionFields } = param;
    if (filterByTk) {
        if (actionFields) {
            const keys = Object.keys(form.values).filter((key)=>{
                const f = getField(key);
                return !actionFields.includes(key) && [
                    'hasOne',
                    'hasMany',
                    'belongsTo',
                    'belongsToMany'
                ].includes(null == f ? void 0 : f.type);
            });
            return lodash_omit__WEBPACK_IMPORTED_MODULE_7___default()({
                ...form.values
            }, keys);
        }
    }
    return form.values;
}
function useCollectValuesToSubmit() {
    const form = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useForm)();
    const filterByTk = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useFilterByTk)();
    const { field, resource } = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useBlockRequestContext)();
    const { fields, getField, getTreeParentField, name } = (0, _collection_manager__WEBPACK_IMPORTED_MODULE_14__.useCollection_deprecated)();
    const fieldNames = fields.map((field)=>field.name);
    const { fieldSchema } = (0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.useActionContext)();
    const { getActiveFieldsName } = (0, ___WEBPACK_IMPORTED_MODULE_11__.useFormActiveFields)() || {};
    const variables = (0, _variables__WEBPACK_IMPORTED_MODULE_21__.useVariables)();
    const localVariables = (0, _variables__WEBPACK_IMPORTED_MODULE_21__.useLocalVariables)({
        currentForm: form
    });
    const actionSchema = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useFieldSchema)();
    const currentRecord = (0, _record_provider__WEBPACK_IMPORTED_MODULE_17__.useRecord)();
    return (0, react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(async ()=>{
        var _fieldSchema_xcomponentprops;
        var _actionSchema_xactionsettings;
        const { assignedValues: originalAssignedValues = {}, overwriteValues } = null !== (_actionSchema_xactionsettings = null == actionSchema ? void 0 : actionSchema['x-action-settings']) && void 0 !== _actionSchema_xactionsettings ? _actionSchema_xactionsettings : {};
        const values = getFormValues({
            filterByTk,
            field,
            form,
            fieldNames,
            getField,
            resource,
            actionFields: (null == getActiveFieldsName ? void 0 : getActiveFieldsName('form')) || []
        });
        const assignedValues = {};
        const waitList = Object.keys(originalAssignedValues).map(async (key)=>{
            const value = originalAssignedValues[key];
            const collectionField = getField(key);
            if ((0, _variables_utils_isVariable__WEBPACK_IMPORTED_MODULE_22__.isVariable)(value)) {
                const result = await (null == variables ? void 0 : variables.parseVariable(value, localVariables));
                if (result) assignedValues[key] = (0, _variables_utils_transformVariableValue__WEBPACK_IMPORTED_MODULE_23__.transformVariableValue)(result, {
                    targetCollectionField: collectionField
                });
            } else if (null != value && '' !== value) assignedValues[key] = value;
        });
        await Promise.all(waitList);
        const addChild = null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.addChild;
        if (addChild) {
            var _currentRecord___parent;
            const treeParentField = getTreeParentField();
            var _treeParentField_name;
            values[null !== (_treeParentField_name = null == treeParentField ? void 0 : treeParentField.name) && void 0 !== _treeParentField_name ? _treeParentField_name : 'parent'] = lodash_omit__WEBPACK_IMPORTED_MODULE_7___default()(null == currentRecord ? void 0 : currentRecord.__parent, [
                'children'
            ]);
            var _treeParentField_foreignKey;
            values[null !== (_treeParentField_foreignKey = null == treeParentField ? void 0 : treeParentField.foreignKey) && void 0 !== _treeParentField_foreignKey ? _treeParentField_foreignKey : 'parentId'] = null == currentRecord ? void 0 : null === (_currentRecord___parent = currentRecord.__parent) || void 0 === _currentRecord___parent ? void 0 : _currentRecord___parent.id;
        }
        return {
            ...values,
            ...overwriteValues,
            ...assignedValues
        };
    }, [
        actionSchema,
        null == currentRecord ? void 0 : currentRecord.__parent,
        field,
        fieldNames,
        fieldSchema,
        filterByTk,
        form,
        getActiveFieldsName,
        getField,
        getTreeParentField,
        localVariables,
        name,
        resource,
        variables
    ]);
}
const pageDetailsViewer = 'Action.Container';
const viewerSchema = {
    type: 'void',
    title: '{{t("View record")}}',
    'x-component': 'Action.Container',
    'x-component-props': {
        className: 'tb-action-popup'
    },
    properties: {
        page: {
            type: 'void',
            title: '{{t("Detail page")}}',
            'x-designer': 'Page.Designer',
            'x-component': 'Page',
            'x-component-props': {
                disablePageHeader: true
            },
            properties: {
                grid: {
                    type: 'void',
                    'x-component': 'Grid',
                    'x-initializer': 'popup:common:addBlock',
                    properties: {}
                }
            }
        }
    }
};
const useInsertSchema = ()=>{
    const fieldSchema = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useFieldSchema)();
    const { insertAfterBegin } = (0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.useDesignable)();
    const insert = (0, react__WEBPACK_IMPORTED_MODULE_0__.useCallback)((ss)=>{
        const schema = fieldSchema.reduceProperties((buf, s)=>{
            if (s['x-component'] === pageDetailsViewer) return s;
            return buf;
        }, null);
        if (!schema) insertAfterBegin(lodash__WEBPACK_IMPORTED_MODULE_5___default().cloneDeep(ss));
    }, [
        pageDetailsViewer
    ]);
    return insert;
};
const useCancelActionProps = ()=>{
    const form = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useForm)();
    const ctx = (0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.useActionContext)();
    return {
        async onClick () {
            ctx.setVisible(false);
            form.reset();
        }
    };
};
const useJumpDetails = ()=>{
    const collection = (0, ___WEBPACK_IMPORTED_MODULE_11__.useCollection)();
    const fieldSchema = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useFieldSchema)();
    const dn = (0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.useDesignable)();
    const insert = useInsertSchema();
    const navigate = (0, react_router_dom__WEBPACK_IMPORTED_MODULE_9__.useNavigate)();
    return (filterByTk)=>{
        if (dn.designable) insert(viewerSchema);
        const targetSchema = fieldSchema.reduceProperties((buf, s)=>{
            if (s['x-component'] === pageDetailsViewer) return s;
            return buf;
        });
        if (targetSchema) navigate("../".concat(targetSchema['x-uid'], "/").concat(_built_in_dynamic_page_utils__WEBPACK_IMPORTED_MODULE_13__.PathHandler.getInstance().toWildcardPath({
            collection: collection.name,
            filterByTk
        })));
    };
};
function getAfterWorkflows(triggerWorkflows) {
    if (!(null == triggerWorkflows ? void 0 : triggerWorkflows.length)) return;
    return triggerWorkflows.filter((row)=>row && 'before' !== row.order).map((row)=>[
            row.workflowKey,
            row.context
        ].join('!')).join(',');
}
function getBeforeWorkflows(triggerWorkflows) {
    if (!(null == triggerWorkflows ? void 0 : triggerWorkflows.length)) return;
    return triggerWorkflows.filter((row)=>row && 'before' === row.order).map((row)=>[
            row.workflowKey,
            row.context
        ].join('!')).join(',');
}
const useCreateActionProps = ()=>{
    var _actionField_componentProps_filterKeys;
    const record = (0, ___WEBPACK_IMPORTED_MODULE_11__.useCollectionRecord)();
    const form = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useForm)();
    const { field, resource, __parent } = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useBlockRequestContext)();
    const jumpDetails = useJumpDetails();
    const { setVisible } = (0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.useActionContext)();
    const navigate = (0, react_router_dom__WEBPACK_IMPORTED_MODULE_9__.useNavigate)();
    const actionSchema = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useFieldSchema)();
    const actionField = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useField)();
    const compile = (0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.useCompile)();
    const { modal, message } = antd__WEBPACK_IMPORTED_MODULE_3__.App.useApp();
    const { t } = (0, react_i18next__WEBPACK_IMPORTED_MODULE_8__.useTranslation)();
    const { updateAssociationValues } = (0, ___WEBPACK_IMPORTED_MODULE_11__.useFormBlockContext)();
    const collectValues = useCollectValuesToSubmit();
    const action = record.isNew ? actionField.componentProps.saveMode || 'create' : 'update';
    const filterKeys = (null === (_actionField_componentProps_filterKeys = actionField.componentProps.filterKeys) || void 0 === _actionField_componentProps_filterKeys ? void 0 : _actionField_componentProps_filterKeys.checked) || [];
    return {
        async onClick () {
            var _actionSchema_xactionsettings;
            const { onSuccess, skipValidator, triggerWorkflows, pageMode } = null !== (_actionSchema_xactionsettings = null == actionSchema ? void 0 : actionSchema['x-action-settings']) && void 0 !== _actionSchema_xactionsettings ? _actionSchema_xactionsettings : {};
            if (!skipValidator) await form.submit();
            actionField.data = field.data || {};
            actionField.data.loading = true;
            try {
                var __parent_service_refresh, __parent_service;
                const data = await resource[action]({
                    values: await collectValues(),
                    filterKeys: filterKeys,
                    triggerWorkflows: getAfterWorkflows(triggerWorkflows),
                    beforeWorkflows: getBeforeWorkflows(triggerWorkflows),
                    updateAssociationValues
                });
                actionField.data.loading = false;
                actionField.data.data = data;
                null == __parent || null === (__parent_service = __parent.service) || void 0 === __parent_service || null === (__parent_service_refresh = __parent_service.refresh) || void 0 === __parent_service_refresh || __parent_service_refresh.call(__parent_service);
                if (pageMode) {
                    var _data_data_data, _data_data;
                    await resetFormCorrectly(form);
                    jumpDetails(null == data ? void 0 : null === (_data_data = data.data) || void 0 === _data_data ? void 0 : null === (_data_data_data = _data_data.data) || void 0 === _data_data_data ? void 0 : _data_data_data.id);
                    return;
                }
                const successMessage = (null == onSuccess ? void 0 : onSuccess.successMessage) ? compile(null == onSuccess ? void 0 : onSuccess.successMessage) : t('Saved successfully');
                if (null == onSuccess ? void 0 : onSuccess.manualClose) modal.success({
                    title: successMessage,
                    onOk: async ()=>{
                        await resetFormCorrectly(form);
                        if ((null == onSuccess ? void 0 : onSuccess.redirecting) && (null == onSuccess ? void 0 : onSuccess.redirectTo)) {
                            if ((0, _tachybase_utils_client__WEBPACK_IMPORTED_MODULE_2__.isURL)(onSuccess.redirectTo)) window.location.href = onSuccess.redirectTo;
                            else navigate(onSuccess.redirectTo);
                        }
                    }
                });
                else {
                    message.success(successMessage);
                    await resetFormCorrectly(form);
                    if ((null == onSuccess ? void 0 : onSuccess.redirecting) && (null == onSuccess ? void 0 : onSuccess.redirectTo)) {
                        if ((0, _tachybase_utils_client__WEBPACK_IMPORTED_MODULE_2__.isURL)(onSuccess.redirectTo)) window.location.href = onSuccess.redirectTo;
                        else navigate(onSuccess.redirectTo);
                    }
                }
                if (!(null == onSuccess ? void 0 : onSuccess.popupClose)) {
                    await resetFormCorrectly(form);
                    null == setVisible || setVisible(false);
                }
                if (!onSuccess) null == setVisible || setVisible(false);
            } catch (error) {
                actionField.data.loading = false;
            }
        }
    };
};
const useAssociationCreateActionProps = ()=>{
    var _actionField_componentProps_filterKeys;
    const form = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useForm)();
    const { field, resource, __parent } = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useBlockRequestContext)();
    const { setVisible, fieldSchema } = (0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.useActionContext)();
    const actionSchema = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useFieldSchema)();
    const actionField = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useField)();
    const { message } = antd__WEBPACK_IMPORTED_MODULE_3__.App.useApp();
    const { fields, getField, getTreeParentField, name } = (0, _collection_manager__WEBPACK_IMPORTED_MODULE_14__.useCollection_deprecated)();
    const compile = (0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.useCompile)();
    const filterByTk = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useFilterByTk)();
    const currentRecord = (0, _record_provider__WEBPACK_IMPORTED_MODULE_17__.useRecord)();
    const variables = (0, _variables__WEBPACK_IMPORTED_MODULE_21__.useVariables)();
    const localVariables = (0, _variables__WEBPACK_IMPORTED_MODULE_21__.useLocalVariables)({
        currentForm: form
    });
    const { getActiveFieldsName } = (0, ___WEBPACK_IMPORTED_MODULE_11__.useFormActiveFields)() || {};
    const action = actionField.componentProps.saveMode || 'create';
    const filterKeys = (null === (_actionField_componentProps_filterKeys = actionField.componentProps.filterKeys) || void 0 === _actionField_componentProps_filterKeys ? void 0 : _actionField_componentProps_filterKeys.checked) || [];
    return {
        async onClick () {
            var _fieldSchema_xcomponentprops;
            const fieldNames = fields.map((field)=>field.name);
            var _actionSchema_xactionsettings;
            const { assignedValues: originalAssignedValues = {}, onSuccess, overwriteValues, skipValidator, triggerWorkflows } = null !== (_actionSchema_xactionsettings = null == actionSchema ? void 0 : actionSchema['x-action-settings']) && void 0 !== _actionSchema_xactionsettings ? _actionSchema_xactionsettings : {};
            const addChild = null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.addChild;
            const assignedValues = {};
            const waitList = Object.keys(originalAssignedValues).map(async (key)=>{
                const value = originalAssignedValues[key];
                const collectionField = getField(key);
                if ((0, _variables_utils_isVariable__WEBPACK_IMPORTED_MODULE_22__.isVariable)(value)) {
                    const result = await (null == variables ? void 0 : variables.parseVariable(value, localVariables));
                    if (result) assignedValues[key] = (0, _variables_utils_transformVariableValue__WEBPACK_IMPORTED_MODULE_23__.transformVariableValue)(result, {
                        targetCollectionField: collectionField
                    });
                } else if (null != value && '' !== value) assignedValues[key] = value;
            });
            await Promise.all(waitList);
            if (!skipValidator) await form.submit();
            const values = getFormValues({
                filterByTk,
                field,
                form,
                fieldNames,
                getField,
                resource,
                actionFields: (null == getActiveFieldsName ? void 0 : getActiveFieldsName('form')) || []
            });
            if (addChild) {
                const treeParentField = getTreeParentField();
                var _treeParentField_name;
                values[null !== (_treeParentField_name = null == treeParentField ? void 0 : treeParentField.name) && void 0 !== _treeParentField_name ? _treeParentField_name : 'parent'] = currentRecord;
                var _treeParentField_foreignKey;
                values[null !== (_treeParentField_foreignKey = null == treeParentField ? void 0 : treeParentField.foreignKey) && void 0 !== _treeParentField_foreignKey ? _treeParentField_foreignKey : 'parentId'] = currentRecord.id;
            }
            actionField.data = field.data || {};
            actionField.data.loading = true;
            try {
                var __parent_service_refresh, __parent_service;
                const data = await resource[action]({
                    values: {
                        ...values,
                        ...overwriteValues,
                        ...assignedValues
                    },
                    filterKeys: filterKeys,
                    triggerWorkflows: getAfterWorkflows(triggerWorkflows),
                    beforeWorkflows: getBeforeWorkflows(triggerWorkflows)
                });
                actionField.data.loading = false;
                actionField.data.data = data;
                null == __parent || null === (__parent_service = __parent.service) || void 0 === __parent_service || null === (__parent_service_refresh = __parent_service.refresh) || void 0 === __parent_service_refresh || __parent_service_refresh.call(__parent_service);
                null == setVisible || setVisible(false);
                if (!(null == onSuccess ? void 0 : onSuccess.successMessage)) return;
                message.success(compile(null == onSuccess ? void 0 : onSuccess.successMessage));
            } catch (error) {
                actionField.data.data = null;
                actionField.data.loading = false;
            }
        }
    };
};
const findFilterTargets = (fieldSchema)=>{
    while(fieldSchema){
        if (fieldSchema['x-filter-targets']) return {
            targets: fieldSchema['x-filter-targets'],
            uid: fieldSchema['x-uid']
        };
        fieldSchema = fieldSchema.parent;
    }
    return {};
};
const updateFilterTargets = (fieldSchema, targets)=>{
    while(fieldSchema){
        if (fieldSchema['x-filter-targets']) {
            fieldSchema['x-filter-targets'] = targets;
            return;
        }
        fieldSchema = fieldSchema.parent;
    }
};
const useFilterBlockActionProps = ()=>{
    const form = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useForm)();
    const actionField = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useField)();
    const fieldSchema = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useFieldSchema)();
    const { getDataBlocks } = (0, _filter_provider_FilterProvider__WEBPACK_IMPORTED_MODULE_15__.useFilterBlock)();
    const { name } = (0, _collection_manager__WEBPACK_IMPORTED_MODULE_14__.useCollection_deprecated)();
    const { getCollectionJoinField } = (0, _collection_manager__WEBPACK_IMPORTED_MODULE_14__.useCollectionManager_deprecated)();
    actionField.data = actionField.data || {};
    return {
        async onClick () {
            const { targets = [], uid } = findFilterTargets(fieldSchema);
            actionField.data.loading = true;
            let prevMergedFilter = {};
            try {
                await Promise.all(getDataBlocks().map(async (block)=>{
                    var _block_service_params, _block_service_params_, _block_service_params1, _Object_keys;
                    const target = targets.find((target)=>target.uid === block.uid);
                    if (!target) return;
                    const param = (null === (_block_service_params = block.service.params) || void 0 === _block_service_params ? void 0 : _block_service_params[0]) || {};
                    for(const key in form.values)if ('object' == typeof form.values[key] && ('{}' === JSON.stringify(form.values[key]) || '[]' === JSON.stringify(form.values[key])) || !form.values[key]) delete form.values[key];
                    const storedFilter = (null === (_block_service_params1 = block.service.params) || void 0 === _block_service_params1 ? void 0 : null === (_block_service_params_ = _block_service_params1[1]) || void 0 === _block_service_params_ ? void 0 : _block_service_params_.filters) || {};
                    const filter = {
                        formValues: {
                            ...form.values
                        },
                        customValues: {},
                        customFilter: {}
                    };
                    if (null === (_Object_keys = Object.keys(filter.formValues)) || void 0 === _Object_keys ? void 0 : _Object_keys.includes('__custom')) {
                        const values = {
                            ...form.values
                        };
                        delete values['__custom'];
                        filter.formValues = {
                            ...values
                        };
                        for(const key in form.values['__custom'])if (form.values['__custom'][key]) filter.customValues[key] = form.values['__custom'][key];
                        filter.customFilter = (0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.getCustomCondition)(filter.customValues, fieldSchema);
                    }
                    storedFilter[uid] = (0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.removeNullCondition)((0, _filter_provider_utils__WEBPACK_IMPORTED_MODULE_16__.transformToFilter)(filter.formValues, fieldSchema, getCollectionJoinField, name));
                    const mergedFilter = (0, _filter_provider_utils__WEBPACK_IMPORTED_MODULE_16__.mergeFilter)([
                        ...Object.values(storedFilter).map((filter)=>(0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.removeNullCondition)(filter)),
                        block.defaultFilter,
                        filter.customFilter,
                        prevMergedFilter
                    ]);
                    const currFilter = filterByCleanedFields(mergedFilter);
                    prevMergedFilter = currFilter;
                    if ('manual' === block.dataLoadingMode && lodash__WEBPACK_IMPORTED_MODULE_5___default().isEmpty(currFilter)) return block.clearData();
                    return block.doFilter({
                        ...param,
                        page: 1,
                        filter: currFilter
                    }, {
                        filters: storedFilter
                    });
                }));
            } catch (error) {
                console.error(error);
            }
            actionField.data.loading = false;
        }
    };
};
const useResetBlockActionProps = ()=>{
    const form = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useForm)();
    const actionField = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useField)();
    const fieldSchema = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useFieldSchema)();
    const { getDataBlocks } = (0, _filter_provider_FilterProvider__WEBPACK_IMPORTED_MODULE_15__.useFilterBlock)();
    actionField.data = actionField.data || {};
    return {
        async onClick () {
            const { targets, uid } = findFilterTargets(fieldSchema);
            form.reset();
            actionField.data.loading = true;
            let prevMergedFilter = {};
            try {
                await Promise.all(getDataBlocks().map(async (block)=>{
                    var _block_service_params, _block_service_params_, _block_service_params1;
                    const target = targets.find((target)=>target.uid === block.uid);
                    if (!target) return;
                    if ('manual' === block.dataLoadingMode) return block.clearData();
                    const param = (null === (_block_service_params = block.service.params) || void 0 === _block_service_params ? void 0 : _block_service_params[0]) || {};
                    const storedFilter = (null === (_block_service_params1 = block.service.params) || void 0 === _block_service_params1 ? void 0 : null === (_block_service_params_ = _block_service_params1[1]) || void 0 === _block_service_params_ ? void 0 : _block_service_params_.filters) || {};
                    delete storedFilter[uid];
                    const currFilter = (0, _filter_provider_utils__WEBPACK_IMPORTED_MODULE_16__.mergeFilter)([
                        ...Object.values(storedFilter),
                        block.defaultFilter,
                        prevMergedFilter
                    ]);
                    const mergedFilter = filterByCleanedFields(currFilter);
                    prevMergedFilter = mergedFilter;
                    return block.doFilter({
                        ...param,
                        page: 1,
                        filter: mergedFilter
                    }, {
                        filters: storedFilter
                    });
                }));
                actionField.data.loading = false;
            } catch (error) {
                actionField.data.loading = false;
            }
        }
    };
};
const useCustomizeUpdateActionProps = ()=>{
    const { resource, __parent, service } = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useBlockRequestContext)();
    const filterByTk = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useFilterByTk)();
    const actionSchema = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useFieldSchema)();
    const navigate = (0, react_router_dom__WEBPACK_IMPORTED_MODULE_9__.useNavigate)();
    const compile = (0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.useCompile)();
    const form = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useForm)();
    const { modal, message } = antd__WEBPACK_IMPORTED_MODULE_3__.App.useApp();
    const variables = (0, _variables__WEBPACK_IMPORTED_MODULE_21__.useVariables)();
    const localVariables = (0, _variables__WEBPACK_IMPORTED_MODULE_21__.useLocalVariables)({
        currentForm: form
    });
    const { name, getField } = (0, _collection_manager__WEBPACK_IMPORTED_MODULE_14__.useCollection_deprecated)();
    return {
        async onClick () {
            var _service_refresh;
            var _actionSchema_xactionsettings;
            const { assignedValues: originalAssignedValues = {}, onSuccess, skipValidator, triggerWorkflows } = null !== (_actionSchema_xactionsettings = null == actionSchema ? void 0 : actionSchema['x-action-settings']) && void 0 !== _actionSchema_xactionsettings ? _actionSchema_xactionsettings : {};
            const assignedValues = {};
            const waitList = Object.keys(originalAssignedValues).map(async (key)=>{
                const value = originalAssignedValues[key];
                const collectionField = getField(key);
                if ((0, _variables_utils_isVariable__WEBPACK_IMPORTED_MODULE_22__.isVariable)(value)) {
                    const result = await (null == variables ? void 0 : variables.parseVariable(value, localVariables));
                    if (result) assignedValues[key] = (0, _variables_utils_transformVariableValue__WEBPACK_IMPORTED_MODULE_23__.transformVariableValue)(result, {
                        targetCollectionField: collectionField
                    });
                } else if (null != value && '' !== value) assignedValues[key] = value;
            });
            await Promise.all(waitList);
            if (false === skipValidator) await form.submit();
            await resource.update({
                filterByTk,
                values: {
                    ...assignedValues
                },
                triggerWorkflows: getAfterWorkflows(triggerWorkflows),
                beforeWorkflows: getBeforeWorkflows(triggerWorkflows)
            });
            null == service || null === (_service_refresh = service.refresh) || void 0 === _service_refresh || _service_refresh.call(service);
            if (!(resource instanceof _TableFieldProvider__WEBPACK_IMPORTED_MODULE_26__.TableFieldResource)) {
                var __parent_service_refresh, __parent_service;
                null == __parent || null === (__parent_service = __parent.service) || void 0 === __parent_service || null === (__parent_service_refresh = __parent_service.refresh) || void 0 === __parent_service_refresh || __parent_service_refresh.call(__parent_service);
            }
            if (!(null == onSuccess ? void 0 : onSuccess.successMessage)) return;
            if (null == onSuccess ? void 0 : onSuccess.manualClose) modal.success({
                title: compile(null == onSuccess ? void 0 : onSuccess.successMessage),
                onOk: async ()=>{
                    if ((null == onSuccess ? void 0 : onSuccess.redirecting) && (null == onSuccess ? void 0 : onSuccess.redirectTo)) {
                        if ((0, _tachybase_utils_client__WEBPACK_IMPORTED_MODULE_2__.isURL)(onSuccess.redirectTo)) window.location.href = onSuccess.redirectTo;
                        else navigate(onSuccess.redirectTo);
                    }
                }
            });
            else {
                message.success(compile(null == onSuccess ? void 0 : onSuccess.successMessage));
                if ((null == onSuccess ? void 0 : onSuccess.redirecting) && (null == onSuccess ? void 0 : onSuccess.redirectTo)) {
                    if ((0, _tachybase_utils_client__WEBPACK_IMPORTED_MODULE_2__.isURL)(onSuccess.redirectTo)) window.location.href = onSuccess.redirectTo;
                    else navigate(onSuccess.redirectTo);
                }
            }
        }
    };
};
const useCustomizeRequestActionProps = ()=>{
    var _currentUserContext_data;
    const apiClient = (0, _api_client__WEBPACK_IMPORTED_MODULE_12__.useAPIClient)();
    const navigate = (0, react_router_dom__WEBPACK_IMPORTED_MODULE_9__.useNavigate)();
    const filterByTk = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useFilterByTk)();
    const actionSchema = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useFieldSchema)();
    const compile = (0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.useCompile)();
    const form = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useForm)();
    const { fields, getField } = (0, _collection_manager__WEBPACK_IMPORTED_MODULE_14__.useCollection_deprecated)();
    const { field, resource, __parent, service } = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useBlockRequestContext)();
    const currentRecord = (0, _record_provider__WEBPACK_IMPORTED_MODULE_17__.useRecord)();
    const currentUserContext = (0, _user__WEBPACK_IMPORTED_MODULE_20__.useCurrentUserContext)();
    const currentUser = null == currentUserContext ? void 0 : null === (_currentUserContext_data = currentUserContext.data) || void 0 === _currentUserContext_data ? void 0 : _currentUserContext_data.data;
    const actionField = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useField)();
    const { setVisible } = (0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.useActionContext)();
    const { modal, message } = antd__WEBPACK_IMPORTED_MODULE_3__.App.useApp();
    const { getActiveFieldsName } = (0, ___WEBPACK_IMPORTED_MODULE_11__.useFormActiveFields)() || {};
    return {
        async onClick () {
            var _actionSchema_xactionsettings;
            const { skipValidator, onSuccess, requestSettings } = null !== (_actionSchema_xactionsettings = null == actionSchema ? void 0 : actionSchema['x-action-settings']) && void 0 !== _actionSchema_xactionsettings ? _actionSchema_xactionsettings : {};
            const xAction = null == actionSchema ? void 0 : actionSchema['x-action'];
            if (!requestSettings['url']) return;
            if (true !== skipValidator && 'customize:form:request' === xAction) await form.submit();
            const headers = requestSettings['headers'] ? JSON.parse(requestSettings['headers']) : {};
            const params = requestSettings['params'] ? JSON.parse(requestSettings['params']) : {};
            const data = requestSettings['data'] ? JSON.parse(requestSettings['data']) : {};
            const methods = [
                'POST',
                'PUT',
                'PATCH'
            ];
            if ('customize:form:request' === xAction && methods.includes(requestSettings['method'])) {
                const fieldNames = fields.map((field)=>field.name);
                const values = getFormValues({
                    filterByTk,
                    field,
                    form,
                    fieldNames,
                    getField,
                    resource,
                    actionFields: (null == getActiveFieldsName ? void 0 : getActiveFieldsName('form')) || []
                });
                Object.assign(data, values);
            }
            const requestBody = {
                url: renderTemplate(requestSettings['url'], {
                    currentRecord,
                    currentUser
                }),
                method: requestSettings['method'],
                headers: (0, _tachybase_utils_client__WEBPACK_IMPORTED_MODULE_2__.parse)(headers)({
                    currentRecord,
                    currentUser
                }),
                params: (0, _tachybase_utils_client__WEBPACK_IMPORTED_MODULE_2__.parse)(params)({
                    currentRecord,
                    currentUser
                }),
                data: (0, _tachybase_utils_client__WEBPACK_IMPORTED_MODULE_2__.parse)(data)({
                    currentRecord,
                    currentUser
                })
            };
            actionField.data = field.data || {};
            actionField.data.loading = true;
            try {
                var _service_refresh;
                await apiClient.request({
                    ...requestBody
                });
                actionField.data.loading = false;
                if (!(resource instanceof _TableFieldProvider__WEBPACK_IMPORTED_MODULE_26__.TableFieldResource)) {
                    var __parent_service_refresh, __parent_service;
                    null == __parent || null === (__parent_service = __parent.service) || void 0 === __parent_service || null === (__parent_service_refresh = __parent_service.refresh) || void 0 === __parent_service_refresh || __parent_service_refresh.call(__parent_service);
                }
                null == service || null === (_service_refresh = service.refresh) || void 0 === _service_refresh || _service_refresh.call(service);
                if ('customize:form:request' === xAction) null == setVisible || setVisible(false);
                if (!(null == onSuccess ? void 0 : onSuccess.successMessage)) return;
                if (null == onSuccess ? void 0 : onSuccess.manualClose) modal.success({
                    title: compile(null == onSuccess ? void 0 : onSuccess.successMessage),
                    onOk: async ()=>{
                        if ((null == onSuccess ? void 0 : onSuccess.redirecting) && (null == onSuccess ? void 0 : onSuccess.redirectTo)) {
                            if ((0, _tachybase_utils_client__WEBPACK_IMPORTED_MODULE_2__.isURL)(onSuccess.redirectTo)) window.location.href = onSuccess.redirectTo;
                            else navigate(onSuccess.redirectTo);
                        }
                    }
                });
                else message.success(compile(null == onSuccess ? void 0 : onSuccess.successMessage));
            } finally{
                actionField.data.loading = false;
            }
        }
    };
};
const useUpdateActionProps = ()=>{
    const form = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useForm)();
    const filterByTk = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useFilterByTk)();
    const { field, resource, __parent } = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useBlockRequestContext)();
    const { setVisible } = (0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.useActionContext)();
    const actionSchema = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useFieldSchema)();
    const navigate = (0, react_router_dom__WEBPACK_IMPORTED_MODULE_9__.useNavigate)();
    const { fields, getField, name } = (0, _collection_manager__WEBPACK_IMPORTED_MODULE_14__.useCollection_deprecated)();
    const compile = (0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.useCompile)();
    const actionField = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useField)();
    const { updateAssociationValues } = (0, ___WEBPACK_IMPORTED_MODULE_11__.useFormBlockContext)();
    const { modal, message } = antd__WEBPACK_IMPORTED_MODULE_3__.App.useApp();
    const data = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useParamsFromRecord)();
    const variables = (0, _variables__WEBPACK_IMPORTED_MODULE_21__.useVariables)();
    const localVariables = (0, _variables__WEBPACK_IMPORTED_MODULE_21__.useLocalVariables)({
        currentForm: form
    });
    const { getActiveFieldsName } = (0, ___WEBPACK_IMPORTED_MODULE_11__.useFormActiveFields)() || {};
    return {
        async onClick () {
            var _actionSchema_xactionsettings;
            const { assignedValues: originalAssignedValues = {}, onSuccess, overwriteValues, skipValidator, triggerWorkflows, isDeltaChanged } = null !== (_actionSchema_xactionsettings = null == actionSchema ? void 0 : actionSchema['x-action-settings']) && void 0 !== _actionSchema_xactionsettings ? _actionSchema_xactionsettings : {};
            const assignedValues = {};
            const waitList = Object.keys(originalAssignedValues).map(async (key)=>{
                const value = originalAssignedValues[key];
                const collectionField = getField(key);
                if ((0, _variables_utils_isVariable__WEBPACK_IMPORTED_MODULE_22__.isVariable)(value)) {
                    const result = await (null == variables ? void 0 : variables.parseVariable(value, localVariables));
                    if (result) assignedValues[key] = (0, _variables_utils_transformVariableValue__WEBPACK_IMPORTED_MODULE_23__.transformVariableValue)(result, {
                        targetCollectionField: collectionField
                    });
                } else if (null != value && '' !== value) assignedValues[key] = value;
            });
            await Promise.all(waitList);
            if (!skipValidator) await form.submit();
            const fieldNames = fields.map((field)=>field.name);
            const actionFields = (null == getActiveFieldsName ? void 0 : getActiveFieldsName('form')) || [];
            const values = getFormValues({
                filterByTk,
                field,
                form,
                fieldNames,
                getField,
                resource,
                actionFields
            });
            actionField.data = field.data || {};
            actionField.data.loading = true;
            const rawValues = {
                ...values,
                ...overwriteValues,
                ...assignedValues
            };
            const filterValues = (srcValues)=>Object.entries(srcValues).reduce((obj, keyValuePair)=>{
                    const [key, value] = keyValuePair;
                    if (actionFields.includes(key)) obj = {
                        ...obj,
                        [key]: value
                    };
                    return obj;
                }, {});
            try {
                var __parent_service_refresh, __parent_service;
                await resource.update({
                    filterByTk,
                    values: isDeltaChanged ? filterValues(rawValues) : rawValues,
                    ...data,
                    updateAssociationValues,
                    triggerWorkflows: getAfterWorkflows(triggerWorkflows),
                    beforeWorkflows: getBeforeWorkflows(triggerWorkflows)
                });
                actionField.data.loading = false;
                null == __parent || null === (__parent_service = __parent.service) || void 0 === __parent_service || null === (__parent_service_refresh = __parent_service.refresh) || void 0 === __parent_service_refresh || __parent_service_refresh.call(__parent_service);
                null == setVisible || setVisible(false);
                if (!(null == onSuccess ? void 0 : onSuccess.successMessage)) return;
                if (null == onSuccess ? void 0 : onSuccess.manualClose) modal.success({
                    title: compile(null == onSuccess ? void 0 : onSuccess.successMessage),
                    onOk: async ()=>{
                        await form.reset();
                        if ((null == onSuccess ? void 0 : onSuccess.redirecting) && (null == onSuccess ? void 0 : onSuccess.redirectTo)) {
                            if ((0, _tachybase_utils_client__WEBPACK_IMPORTED_MODULE_2__.isURL)(onSuccess.redirectTo)) window.location.href = onSuccess.redirectTo;
                            else navigate(onSuccess.redirectTo);
                        }
                    }
                });
                else {
                    message.success(compile(null == onSuccess ? void 0 : onSuccess.successMessage));
                    if ((null == onSuccess ? void 0 : onSuccess.redirecting) && (null == onSuccess ? void 0 : onSuccess.redirectTo)) {
                        if ((0, _tachybase_utils_client__WEBPACK_IMPORTED_MODULE_2__.isURL)(onSuccess.redirectTo)) window.location.href = onSuccess.redirectTo;
                        else navigate(onSuccess.redirectTo);
                    }
                }
            } catch (error) {
                actionField.data.loading = false;
            }
        }
    };
};
const useDestroyActionProps = ()=>{
    const filterByTk = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useFilterByTk)();
    const { resource, service, block, __parent } = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useBlockRequestContext)();
    const { setVisible } = (0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.useActionContext)();
    const data = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useParamsFromRecord)();
    const actionSchema = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useFieldSchema)();
    return {
        async onClick () {
            var _service_data;
            var _actionSchema_xactionsettings;
            const { triggerWorkflows } = null !== (_actionSchema_xactionsettings = null == actionSchema ? void 0 : actionSchema['x-action-settings']) && void 0 !== _actionSchema_xactionsettings ? _actionSchema_xactionsettings : {};
            await resource.destroy({
                filterByTk,
                triggerWorkflows: getAfterWorkflows(triggerWorkflows),
                beforeWorkflows: getBeforeWorkflows(triggerWorkflows),
                ...data
            });
            const { count = 0, page = 0, pageSize = 0 } = (null == service ? void 0 : null === (_service_data = service.data) || void 0 === _service_data ? void 0 : _service_data.meta) || {};
            if (count % pageSize === 1 && 1 !== page) {
                var _service_params;
                service.run({
                    ...null == service ? void 0 : null === (_service_params = service.params) || void 0 === _service_params ? void 0 : _service_params[0],
                    page: page - 1
                });
            } else {
                var _service_refresh;
                null == service || null === (_service_refresh = service.refresh) || void 0 === _service_refresh || _service_refresh.call(service);
            }
            if (block && 'TableField' !== block) {
                var __parent_service_refresh, __parent_service;
                null == __parent || null === (__parent_service = __parent.service) || void 0 === __parent_service || null === (__parent_service_refresh = __parent_service.refresh) || void 0 === __parent_service_refresh || __parent_service_refresh.call(__parent_service);
                null == setVisible || setVisible(false);
            }
        }
    };
};
const useRemoveActionProps = (associationName)=>{
    const filterByTk = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useFilterByTk)();
    const api = (0, _api_client__WEBPACK_IMPORTED_MODULE_12__.useAPIClient)();
    const resource = api.resource(associationName, filterByTk);
    return {
        async onClick (value) {
            await resource.remove({
                values: [
                    value.id
                ]
            });
        }
    };
};
const useDisassociateActionProps = ()=>{
    const filterByTk = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useFilterByTk)();
    const { resource, service, block, __parent } = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useBlockRequestContext)();
    const { setVisible } = (0, _schema_component__WEBPACK_IMPORTED_MODULE_18__.useActionContext)();
    return {
        async onClick () {
            var _service_data;
            await resource.remove({
                values: [
                    filterByTk
                ]
            });
            const { count = 0, page = 0, pageSize = 0 } = (null == service ? void 0 : null === (_service_data = service.data) || void 0 === _service_data ? void 0 : _service_data.meta) || {};
            if (count % pageSize === 1 && 1 !== page) {
                var _service_params;
                service.run({
                    ...null == service ? void 0 : null === (_service_params = service.params) || void 0 === _service_params ? void 0 : _service_params[0],
                    page: page - 1
                });
            } else {
                var _service_refresh;
                null == service || null === (_service_refresh = service.refresh) || void 0 === _service_refresh || _service_refresh.call(service);
            }
            if (block && 'TableField' !== block) {
                var __parent_service_refresh, __parent_service;
                null == __parent || null === (__parent_service = __parent.service) || void 0 === __parent_service || null === (__parent_service_refresh = __parent_service.refresh) || void 0 === __parent_service_refresh || __parent_service_refresh.call(__parent_service);
                null == setVisible || setVisible(false);
            }
        }
    };
};
const useDetailPrintActionProps = ()=>{
    const { formBlockRef } = (0, ___WEBPACK_IMPORTED_MODULE_11__.useFormBlockContext)();
    const printHandler = (0, react_to_print__WEBPACK_IMPORTED_MODULE_10__.useReactToPrint)({
        content: ()=>formBlockRef.current,
        pageStyle: "@media print {\n      * {\n        margin: 0;\n      }\n      :not(.ant-formily-item-control-content-component) > div.ant-formily-layout>div:first-child {\n        overflow: hidden; height: 0;\n      }\n    }"
    });
    return {
        async onClick () {
            printHandler();
        }
    };
};
const useBulkDestroyActionProps = ()=>{
    const { field } = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useBlockRequestContext)();
    const { resource, service } = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useBlockRequestContext)();
    return {
        async onClick () {
            var _field_data_selectedRowKeys, _field_data, _field_data1, _service_params_, _service_data_meta, _service_data, _service_refresh;
            if (!(null == field ? void 0 : null === (_field_data = field.data) || void 0 === _field_data ? void 0 : null === (_field_data_selectedRowKeys = _field_data.selectedRowKeys) || void 0 === _field_data_selectedRowKeys ? void 0 : _field_data_selectedRowKeys.length)) return;
            await resource.destroy({
                filterByTk: null === (_field_data1 = field.data) || void 0 === _field_data1 ? void 0 : _field_data1.selectedRowKeys
            });
            field.data.selectedRowKeys = [];
            const currentPage = null === (_service_params_ = service.params[0]) || void 0 === _service_params_ ? void 0 : _service_params_.page;
            const totalPage = null === (_service_data = service.data) || void 0 === _service_data ? void 0 : null === (_service_data_meta = _service_data.meta) || void 0 === _service_data_meta ? void 0 : _service_data_meta.totalPage;
            if (currentPage === totalPage) service.params[0].page = currentPage - 1;
            null == service || null === (_service_refresh = service.refresh) || void 0 === _service_refresh || _service_refresh.call(service);
        }
    };
};
const useRefreshActionProps = ()=>{
    const { service } = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useBlockRequestContext)();
    return {
        async onClick () {
            var _service_refresh;
            null == service || null === (_service_refresh = service.refresh) || void 0 === _service_refresh || _service_refresh.call(service);
        }
    };
};
const useDetailsPaginationProps = ()=>{
    var _ctx_service_data_meta, _ctx_service_data, _ctx_service, _ctx_service_data_meta1, _ctx_service_data1, _ctx_service1;
    const ctx = (0, _DetailsBlockProvider__WEBPACK_IMPORTED_MODULE_25__.useDetailsBlockContext)();
    const count = (null === (_ctx_service = ctx.service) || void 0 === _ctx_service ? void 0 : null === (_ctx_service_data = _ctx_service.data) || void 0 === _ctx_service_data ? void 0 : null === (_ctx_service_data_meta = _ctx_service_data.meta) || void 0 === _ctx_service_data_meta ? void 0 : _ctx_service_data_meta.count) || 0;
    return {
        simple: true,
        hidden: count <= 1,
        current: (null === (_ctx_service1 = ctx.service) || void 0 === _ctx_service1 ? void 0 : null === (_ctx_service_data1 = _ctx_service1.data) || void 0 === _ctx_service_data1 ? void 0 : null === (_ctx_service_data_meta1 = _ctx_service_data1.meta) || void 0 === _ctx_service_data_meta1 ? void 0 : _ctx_service_data_meta1.page) || 1,
        total: count,
        pageSize: 1,
        showSizeChanger: false,
        async onChange (page) {
            var _ctx_service_params, _ctx_service;
            const params = null === (_ctx_service = ctx.service) || void 0 === _ctx_service ? void 0 : null === (_ctx_service_params = _ctx_service.params) || void 0 === _ctx_service_params ? void 0 : _ctx_service_params[0];
            ctx.service.run({
                ...params,
                page
            });
        },
        style: {
            marginTop: 24,
            textAlign: 'center'
        }
    };
};
const useAssociationFilterProps = ()=>{
    var _cm_getCollection, _fieldSchema_xcomponentprops_fieldNames, _fieldSchema_xcomponentprops, _field_componentProps, _field_componentProps1;
    const collectionField = ___WEBPACK_IMPORTED_MODULE_11__.AssociationFilter.useAssociationField();
    const { service, props: blockProps } = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useBlockRequestContext)();
    const fieldSchema = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useFieldSchema)();
    const cm = (0, _collection_manager__WEBPACK_IMPORTED_MODULE_14__.useCollectionManager_deprecated)();
    const valueKey = (null == collectionField ? void 0 : collectionField.target) ? null === (_cm_getCollection = cm.getCollection(collectionField.target)) || void 0 === _cm_getCollection ? void 0 : _cm_getCollection.getPrimaryKey() : 'id';
    const labelKey = (null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : null === (_fieldSchema_xcomponentprops_fieldNames = _fieldSchema_xcomponentprops.fieldNames) || void 0 === _fieldSchema_xcomponentprops_fieldNames ? void 0 : _fieldSchema_xcomponentprops_fieldNames.label) || valueKey;
    const field = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useField)();
    const collectionFieldName = collectionField.name;
    const headers = (0, ___WEBPACK_IMPORTED_MODULE_11__.useDataSourceHeaders)(null == blockProps ? void 0 : blockProps.dataSource);
    const { data, params, run } = (0, _api_client__WEBPACK_IMPORTED_MODULE_12__.useRequest)({
        headers,
        resource: collectionField.target,
        action: 'list',
        params: {
            fields: [
                labelKey,
                valueKey
            ],
            pageSize: 200,
            page: 1,
            ...null === (_field_componentProps = field.componentProps) || void 0 === _field_componentProps ? void 0 : _field_componentProps.params
        }
    }, {
        refreshDeps: [
            labelKey,
            valueKey,
            JSON.stringify((null === (_field_componentProps1 = field.componentProps) || void 0 === _field_componentProps1 ? void 0 : _field_componentProps1.params) || {})
        ],
        debounceWait: 300
    });
    const list = (null == data ? void 0 : data.data) || [];
    const onSelected = (value)=>{
        var _service_params_, _service_params, _service_params1, _blockProps_params;
        const filters = (null === (_service_params = service.params) || void 0 === _service_params ? void 0 : null === (_service_params_ = _service_params[1]) || void 0 === _service_params_ ? void 0 : _service_params_.filters) || {};
        if (value.length) filters["af.".concat(collectionFieldName)] = {
            ["".concat(collectionFieldName, ".").concat(valueKey, ".$in")]: value
        };
        else delete filters["af.".concat(collectionFieldName)];
        service.run({
            ...null === (_service_params1 = service.params) || void 0 === _service_params1 ? void 0 : _service_params1[0],
            pageSize: 200,
            page: 1,
            filter: (0, _filter_provider_utils__WEBPACK_IMPORTED_MODULE_16__.mergeFilter)([
                ...Object.values(filters),
                null == blockProps ? void 0 : null === (_blockProps_params = blockProps.params) || void 0 === _blockProps_params ? void 0 : _blockProps_params.filter
            ])
        }, {
            filters
        });
    };
    const handleSearchInput = (e)=>{
        run({
            ...null == params ? void 0 : params[0],
            filter: {
                ["".concat(labelKey, ".$includes")]: e.target.value
            }
        });
    };
    return {
        list,
        onSelected,
        handleSearchInput,
        params,
        run
    };
};
const useOptionalFieldList = ()=>{
    const { currentFields = [] } = (0, _collection_manager__WEBPACK_IMPORTED_MODULE_14__.useCollection_deprecated)();
    return currentFields.filter((field)=>isOptionalField(field) && field.uiSchema.enum);
};
const isOptionalField = (field)=>{
    const optionalInterfaces = [
        'select',
        'multipleSelect',
        'checkbox',
        'checkboxGroup',
        'chinaRegion'
    ];
    return optionalInterfaces.includes(field.interface);
};
const useAssociationFilterBlockProps = ()=>{
    var _cm_getCollection, _fieldSchema_xcomponentprops_fieldNames, _fieldSchema_xcomponentprops, _field_componentProps, _field_componentProps1;
    const collectionField = ___WEBPACK_IMPORTED_MODULE_11__.AssociationFilter.useAssociationField();
    const fieldSchema = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useFieldSchema)();
    const optionalFieldList = useOptionalFieldList();
    const { getDataBlocks } = (0, _filter_provider_FilterProvider__WEBPACK_IMPORTED_MODULE_15__.useFilterBlock)();
    const collectionFieldName = null == collectionField ? void 0 : collectionField.name;
    const field = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useField)();
    const { props: blockProps } = (0, _BlockProvider__WEBPACK_IMPORTED_MODULE_24__.useBlockRequestContext)();
    const headers = (0, ___WEBPACK_IMPORTED_MODULE_11__.useDataSourceHeaders)(null == blockProps ? void 0 : blockProps.dataSource);
    const cm = (0, _collection_manager__WEBPACK_IMPORTED_MODULE_14__.useCollectionManager_deprecated)();
    let list, handleSearchInput, params, run, data, valueKey, labelKey, filterKey;
    valueKey = (null == collectionField ? void 0 : collectionField.target) ? null === (_cm_getCollection = cm.getCollection(collectionField.target)) || void 0 === _cm_getCollection ? void 0 : _cm_getCollection.getPrimaryKey() : 'id';
    labelKey = (null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : null === (_fieldSchema_xcomponentprops_fieldNames = _fieldSchema_xcomponentprops.fieldNames) || void 0 === _fieldSchema_xcomponentprops_fieldNames ? void 0 : _fieldSchema_xcomponentprops_fieldNames.label) || valueKey;
    ({ data, params, run } = (0, _api_client__WEBPACK_IMPORTED_MODULE_12__.useRequest)({
        headers,
        resource: null == collectionField ? void 0 : collectionField.target,
        action: 'list',
        params: {
            fields: [
                labelKey,
                valueKey
            ],
            pageSize: 200,
            page: 1,
            ...null === (_field_componentProps = field.componentProps) || void 0 === _field_componentProps ? void 0 : _field_componentProps.params
        }
    }, {
        manual: true,
        debounceWait: 300
    }));
    (0, react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(()=>{
        if (!isOptionalField(fieldSchema)) run();
    }, [
        labelKey,
        valueKey,
        JSON.stringify((null === (_field_componentProps1 = field.componentProps) || void 0 === _field_componentProps1 ? void 0 : _field_componentProps1.params) || {}),
        isOptionalField(fieldSchema)
    ]);
    if (!collectionField) return {};
    if (isOptionalField(fieldSchema)) {
        var _field_uiSchema;
        const field = optionalFieldList.find((field)=>field.name === fieldSchema.name);
        const operatorMap = {
            select: '$in',
            multipleSelect: '$anyOf',
            checkbox: '$in',
            checkboxGroup: '$anyOf'
        };
        const _list = (null == field ? void 0 : null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : _field_uiSchema.enum) || [];
        valueKey = 'value';
        labelKey = 'label';
        list = _list;
        params = {};
        run = ()=>{};
        filterKey = "".concat(field.name, ".").concat(operatorMap[field.interface]);
        handleSearchInput = (e)=>{
            const value = e.target.value;
            if (!value) {
                list = _list;
                return;
            }
            list = _list.filter((item)=>item.label.includes(value));
        };
    } else {
        filterKey = "".concat(collectionFieldName, ".").concat(valueKey, ".$in");
        list = (null == data ? void 0 : data.data) || [];
        handleSearchInput = (e)=>{
            run({
                ...null == params ? void 0 : params[0],
                filter: {
                    ["".concat(labelKey, ".$includes")]: e.target.value
                }
            });
        };
    }
    const onSelected = (value)=>{
        const { targets, uid } = findFilterTargets(fieldSchema);
        getDataBlocks().forEach((block)=>{
            var _block_service_params, _block_service_params_, _block_service_params1;
            const target = targets.find((target)=>target.uid === block.uid);
            if (!target) return;
            const key = "".concat(uid).concat(fieldSchema.name);
            const param = (null === (_block_service_params = block.service.params) || void 0 === _block_service_params ? void 0 : _block_service_params[0]) || {};
            const storedFilter = (null === (_block_service_params1 = block.service.params) || void 0 === _block_service_params1 ? void 0 : null === (_block_service_params_ = _block_service_params1[1]) || void 0 === _block_service_params_ ? void 0 : _block_service_params_.filters) || {};
            if (value.length) storedFilter[key] = {
                [filterKey]: value
            };
            else {
                if ('manual' === block.dataLoadingMode) return block.clearData();
                delete storedFilter[key];
            }
            const mergedFilter = (0, _filter_provider_utils__WEBPACK_IMPORTED_MODULE_16__.mergeFilter)([
                ...Object.values(storedFilter),
                block.defaultFilter
            ]);
            return block.doFilter({
                ...param,
                page: 1,
                filter: mergedFilter
            }, {
                filters: storedFilter
            });
        });
    };
    return {
        list,
        onSelected,
        handleSearchInput,
        params,
        run,
        valueKey,
        labelKey
    };
};
function getAssociationPath(str) {
    const lastIndex = str.lastIndexOf('.');
    if (-1 !== lastIndex) return str.substring(0, lastIndex);
    return str;
}
const useAssociationNames = (dataSource)=>{
    let updateAssociationValues = new Set([]);
    let appends = new Set([]);
    const { getCollectionJoinField, getCollection } = (0, _collection_manager__WEBPACK_IMPORTED_MODULE_14__.useCollectionManager_deprecated)(dataSource);
    const fieldSchema = (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.useFieldSchema)();
    const _getAssociationAppends = (schema, str)=>{
        schema.reduceProperties((pre, s)=>{
            var _s_xcomponentprops, _s_xcomponentprops_fieldNames, _s_xcomponentprops1, _s_xcomponentprops2, _getCollection;
            const prefix = pre || str;
            const collectionField = s['x-collection-field'] && getCollectionJoinField(s['x-collection-field'], dataSource);
            const isAssociationSubfield = s.name.includes('.');
            const isAssociationField = collectionField && [
                'hasOne',
                'hasMany',
                'belongsTo',
                'belongsToMany'
            ].includes(collectionField.type);
            if (null === (_s_xcomponentprops = s['x-component-props']) || void 0 === _s_xcomponentprops ? void 0 : _s_xcomponentprops['appends']) {
                var _s_xcomponentprops3;
                lodash__WEBPACK_IMPORTED_MODULE_5___default().forEach(null === (_s_xcomponentprops3 = s['x-component-props']) || void 0 === _s_xcomponentprops3 ? void 0 : _s_xcomponentprops3['appends'], (append)=>{
                    appends.add(append);
                });
            }
            if (null === (_s_xcomponentprops1 = s['x-component-props']) || void 0 === _s_xcomponentprops1 ? void 0 : null === (_s_xcomponentprops_fieldNames = _s_xcomponentprops1.fieldNames) || void 0 === _s_xcomponentprops_fieldNames ? void 0 : _s_xcomponentprops_fieldNames.formula) {
                var _s_xcomponentprops_fieldNames1, _s_xcomponentprops4;
                appends.add(s['name']);
                const regex = /{{(.*?)}}/g;
                const formula = null === (_s_xcomponentprops4 = s['x-component-props']) || void 0 === _s_xcomponentprops4 ? void 0 : null === (_s_xcomponentprops_fieldNames1 = _s_xcomponentprops4.fieldNames) || void 0 === _s_xcomponentprops_fieldNames1 ? void 0 : _s_xcomponentprops_fieldNames1.formula;
                let match;
                while(match = regex.exec(formula))if (match[1].includes('.')) {
                    const matchList = match[1].split('.');
                    let appendsValue = s['name'];
                    matchList.forEach((item, index)=>{
                        if (index === matchList.length - 1) return;
                        appendsValue += '.' + item;
                        appends.add(appendsValue);
                    });
                }
            }
            if (s['x-linkage-rules']) {
                const collectAppends = (obj)=>{
                    const type = Object.keys(obj)[0] || '$and';
                    const list = obj[type];
                    list.forEach((item)=>{
                        if ('$and' in item || '$or' in item) return collectAppends(item);
                        const fieldNames = getTargetField(item);
                        if (fieldNames.length > 1) appends.add(fieldNames.join('.'));
                    });
                };
                const rules = s['x-linkage-rules'];
                rules.forEach((param)=>{
                    let { condition } = param;
                    collectAppends(condition);
                });
            }
            if (null === (_s_xcomponentprops2 = s['x-component-props']) || void 0 === _s_xcomponentprops2 ? void 0 : _s_xcomponentprops2['x-next-title']) {
                const pre = prefix && '' !== prefix ? prefix + '.' + s.name : s.name;
                const title = s['x-component-props']['x-next-title'];
                const path = pre + '.' + title.label;
                appends.add(path);
            }
            const isTreeCollection = isAssociationField && (null === (_getCollection = getCollection(collectionField.target, dataSource)) || void 0 === _getCollection ? void 0 : _getCollection.template) === 'tree';
            if (collectionField && (isAssociationField || isAssociationSubfield) && 'TableField' !== s['x-component']) {
                var _s_xcomponentprops5;
                const fieldPath = !isAssociationField && isAssociationSubfield ? getAssociationPath(s.name) : s.name;
                const path = '' !== prefix && prefix ? prefix + '.' + fieldPath : fieldPath;
                if (isTreeCollection) {
                    appends.add(path);
                    appends.add("".concat(path, ".parent") + '(recursively=true)');
                } else appends.add(path);
                if ([
                    'Nester',
                    'SubTable',
                    'PopoverNester'
                ].includes(null === (_s_xcomponentprops5 = s['x-component-props']) || void 0 === _s_xcomponentprops5 ? void 0 : _s_xcomponentprops5.mode)) {
                    updateAssociationValues.add(path);
                    const bufPrefix = prefix && '' !== prefix ? prefix + '.' + s.name : s.name;
                    _getAssociationAppends(s, bufPrefix);
                }
            } else if (![
                'ActionBar',
                'Action',
                'Action.Link',
                'Action.Modal',
                'Selector',
                'Viewer',
                'AddNewer',
                'AssociationField.Selector',
                'AssociationField.AddNewer',
                'TableField'
            ].includes(s['x-component'])) _getAssociationAppends(s, str);
        }, str);
    };
    const getAssociationAppends = ()=>{
        updateAssociationValues = new Set([]);
        appends = new Set([]);
        _getAssociationAppends(fieldSchema, '');
        return {
            appends: [
                ...appends
            ],
            updateAssociationValues: [
                ...updateAssociationValues
            ]
        };
    };
    return {
        getAssociationAppends
    };
};
function getTargetField(obj) {
    function getAllKeys(obj) {
        const keys = [];
        function traverse(o) {
            Object.keys(o).sort().forEach(function(key) {
                keys.push(key);
                if (o[key] && 'object' == typeof o[key]) traverse(o[key]);
            });
        }
        traverse(obj);
        return keys;
    }
    const keys = getAllKeys(obj);
    const index = lodash__WEBPACK_IMPORTED_MODULE_5___default().findIndex(keys, (key, index)=>{
        if (key.includes('$') && index > 0) return true;
    });
    const result = keys.slice(0, index);
    return result;
}
async function resetFormCorrectly(form) {
    (0, _tachybase_schema__WEBPACK_IMPORTED_MODULE_1__.untracked)(()=>{
        Object.keys(form.fields).forEach((key)=>{
            if ((0, _schema_component_antd_association_field_util__WEBPACK_IMPORTED_MODULE_19__.isSubMode)(form.fields[key])) form.fields[key].initialValue = null;
        });
    });
    await form.reset();
}
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
});
