"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__, {
    WorkflowConfig: ()=>WorkflowConfig,
    IsDownLoad: ()=>IsDownLoad,
    actionSettings: ()=>actionSettings,
    ShowData: ()=>ShowData,
    RequestSettings: ()=>RequestSettings,
    findSchema: ()=>findSchema,
    ActionDesigner: ()=>ActionDesigner,
    AfterSuccess: ()=>AfterSuccess,
    actionSettingsItems: ()=>actionSettingsItems,
    SecondConFirm: ()=>SecondConFirm,
    SettingDownTitle: ()=>SettingDownTitle,
    SkipValidation: ()=>SkipValidation,
    useSetFilterScopeVisible: ()=>useSetFilterScopeVisible,
    AssignedFieldValues: ()=>AssignedFieldValues,
    RemoveButton: ()=>RemoveButton,
    WorkflowSelect: ()=>WorkflowSelect,
    ButtonEditor: ()=>ButtonEditor,
    SetFilterScope: ()=>SetFilterScope
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const components_namespaceObject = require("@tachybase/components");
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_namespaceObject = require("antd");
const external_react_i18next_namespaceObject = require("react-i18next");
const external_index_js_namespaceObject = require("../../index.js");
const index_js_namespaceObject = require("../../../application/index.js");
const withDynamicSchemaProps_js_namespaceObject = require("../../../application/hoc/withDynamicSchemaProps.js");
const hooks_index_js_namespaceObject = require("../../../application/hooks/index.js");
const schema_settings_index_js_namespaceObject = require("../../../application/schema-settings/index.js");
const schema_toolbar_index_js_namespaceObject = require("../../../application/schema-toolbar/index.js");
const external_block_provider_index_js_namespaceObject = require("../../../block-provider/index.js");
const external_collection_manager_index_js_namespaceObject = require("../../../collection-manager/index.js");
const external_data_source_index_js_namespaceObject = require("../../../data-source/index.js");
const external_flag_provider_index_js_namespaceObject = require("../../../flag-provider/index.js");
const createSubmitActionSettings_js_namespaceObject = require("../../../modules/actions/submit/createSubmitActionSettings.js");
const external_record_provider_index_js_namespaceObject = require("../../../record-provider/index.js");
const external_schema_items_index_js_namespaceObject = require("../../../schema-items/index.js");
const FormFilterScope_js_namespaceObject = require("../../../schema-settings/filter-form/FormFilterScope.js");
const GeneralSchemaDesigner_js_namespaceObject = require("../../../schema-settings/GeneralSchemaDesigner.js");
const useIsAllowToSetDefaultValue_js_namespaceObject = require("../../../schema-settings/hooks/useIsAllowToSetDefaultValue.js");
const SchemaSettings_js_namespaceObject = require("../../../schema-settings/SchemaSettings.js");
const external_schema_templates_index_js_namespaceObject = require("../../../schema-templates/index.js");
const external_variables_index_js_namespaceObject = require("../../../variables/index.js");
const external_hooks_js_namespaceObject = require("./hooks.js");
const external_utils_js_namespaceObject = require("./utils.js");
const MenuGroup = (props)=>props.children;
function ButtonEditor(props) {
    var _fieldSchema_xcomponentprops, _fieldSchema_xcomponentprops1, _fieldSchema_xcomponentprops2;
    const field = (0, schema_namespaceObject.useField)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const isLink = (null == props ? void 0 : props.isLink) || 'Action.Link' === fieldSchema['x-component'];
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsModalItem, {
        title: t('Edit button'),
        schema: {
            type: 'object',
            title: t('Edit button'),
            properties: {
                title: {
                    'x-decorator': 'FormItem',
                    'x-component': 'Input',
                    title: t('Button title'),
                    default: fieldSchema.title,
                    'x-component-props': {}
                },
                icon: {
                    'x-decorator': 'FormItem',
                    'x-component': 'IconPicker',
                    title: t('Button icon'),
                    default: null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.icon,
                    'x-component-props': {},
                    'x-visible': !isLink
                },
                type: {
                    'x-decorator': 'FormItem',
                    'x-component': 'Radio.Group',
                    title: t('Button background color'),
                    default: (null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops1 = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops1 ? void 0 : _fieldSchema_xcomponentprops1.danger) ? 'danger' : (null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops2 = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops2 ? void 0 : _fieldSchema_xcomponentprops2.type) === 'primary' ? 'primary' : 'default',
                    enum: [
                        {
                            value: 'default',
                            label: '{{t("Default")}}'
                        },
                        {
                            value: 'primary',
                            label: '{{t("Highlight")}}'
                        },
                        {
                            value: 'danger',
                            label: '{{t("Danger red")}}'
                        }
                    ],
                    'x-visible': !isLink
                }
            }
        },
        onSubmit: (param)=>{
            let { title, icon, type } = param;
            fieldSchema.title = title;
            field.title = title;
            field.componentProps.icon = icon;
            field.componentProps.danger = 'danger' === type;
            field.componentProps.type = type || field.componentProps.type;
            fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
            fieldSchema['x-component-props'].icon = icon;
            fieldSchema['x-component-props'].danger = 'danger' === type;
            fieldSchema['x-component-props'].type = type || field.componentProps.type;
            dn.emit('patch', {
                schema: {
                    ['x-uid']: fieldSchema['x-uid'],
                    title,
                    'x-component-props': {
                        ...fieldSchema['x-component-props']
                    }
                }
            });
            dn.refresh();
        }
    });
}
function AssignedFieldValues() {
    var _fieldSchema_xactionsettings, _fieldSchema_xactionsettings1;
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const initialSchema = {
        type: 'void',
        'x-uid': (0, schema_namespaceObject.uid)(),
        'x-component': 'Grid',
        'x-initializer': 'assignFieldValuesForm:configureFields'
    };
    const tips = {
        'customize:update': t('After clicking the custom button, the following fields of the current record will be saved according to the following form.'),
        'customize:save': t('After clicking the custom button, the following fields of the current record will be saved according to the following form.')
    };
    var _fieldSchema_xaction;
    const actionType = null !== (_fieldSchema_xaction = fieldSchema['x-action']) && void 0 !== _fieldSchema_xaction ? _fieldSchema_xaction : '';
    const onSubmit = (0, external_react_namespaceObject.useCallback)((assignedValues)=>{
        fieldSchema['x-action-settings']['assignedValues'] = assignedValues;
        dn.emit('patch', {
            schema: {
                ['x-uid']: fieldSchema['x-uid'],
                'x-action-settings': fieldSchema['x-action-settings']
            }
        });
    }, [
        dn,
        fieldSchema
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_flag_provider_index_js_namespaceObject.FlagProvider, {
        isInAssignFieldValues: true,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(useIsAllowToSetDefaultValue_js_namespaceObject.DefaultValueProvider, {
            isAllowToSetDefaultValue: ()=>false,
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsActionModalItem, {
                title: t('Assign field values'),
                initialSchema: initialSchema,
                initialValues: null == fieldSchema ? void 0 : null === (_fieldSchema_xactionsettings = fieldSchema['x-action-settings']) || void 0 === _fieldSchema_xactionsettings ? void 0 : _fieldSchema_xactionsettings.assignedValues,
                modalTip: tips[actionType],
                uid: null == fieldSchema ? void 0 : null === (_fieldSchema_xactionsettings1 = fieldSchema['x-action-settings']) || void 0 === _fieldSchema_xactionsettings1 ? void 0 : _fieldSchema_xactionsettings1.schemaUid,
                onSubmit: onSubmit
            })
        })
    });
}
function RequestSettings() {
    var _fieldSchema_xactionsettings;
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsActionModalItem, {
        title: t('Request settings'),
        schema: external_utils_js_namespaceObject.requestSettingsSchema,
        initialValues: null == fieldSchema ? void 0 : null === (_fieldSchema_xactionsettings = fieldSchema['x-action-settings']) || void 0 === _fieldSchema_xactionsettings ? void 0 : _fieldSchema_xactionsettings.requestSettings,
        onSubmit: (requestSettings)=>{
            fieldSchema['x-action-settings']['requestSettings'] = requestSettings;
            dn.emit('patch', {
                schema: {
                    ['x-uid']: fieldSchema['x-uid'],
                    'x-action-settings': fieldSchema['x-action-settings']
                }
            });
            dn.refresh();
        }
    });
}
function SkipValidation() {
    var _fieldSchema_xactionsettings;
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsSwitchItem, {
        title: t('Skip required validation'),
        checked: !!(null == fieldSchema ? void 0 : null === (_fieldSchema_xactionsettings = fieldSchema['x-action-settings']) || void 0 === _fieldSchema_xactionsettings ? void 0 : _fieldSchema_xactionsettings.skipValidator),
        onChange: (value)=>{
            fieldSchema['x-action-settings'].skipValidator = value;
            dn.emit('patch', {
                schema: {
                    ['x-uid']: fieldSchema['x-uid'],
                    'x-action-settings': {
                        ...fieldSchema['x-action-settings']
                    }
                }
            });
        }
    });
}
const findSchema = (schema)=>{
    if (!schema) return;
    if ('ACLActionProvider' === schema['x-decorator']) {
        var _schema_xcomponentprops;
        return null === (_schema_xcomponentprops = schema['x-component-props']) || void 0 === _schema_xcomponentprops ? void 0 : _schema_xcomponentprops.openMode;
    }
    return findSchema(null == schema ? void 0 : schema.parent);
};
function AfterSuccess() {
    var _fieldSchema_xactionsettings;
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const ctx = (0, external_hooks_js_namespaceObject.useActionContext)();
    const openMode = findSchema(ctx.fieldSchema);
    const component = fieldSchema.parent.parent['x-component'];
    const schema = {
        ...(0, external_utils_js_namespaceObject.afterSuccessSchema)(t)
    };
    if ((!openMode || 'page' === openMode) && component.includes('Form') || !component.includes('Form')) delete schema.properties.popupClose;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsModalItem, {
        title: t('After successful submission'),
        initialValues: null == fieldSchema ? void 0 : null === (_fieldSchema_xactionsettings = fieldSchema['x-action-settings']) || void 0 === _fieldSchema_xactionsettings ? void 0 : _fieldSchema_xactionsettings['onSuccess'],
        schema: {
            ...schema
        },
        onSubmit: (onSuccess)=>{
            fieldSchema['x-action-settings']['onSuccess'] = onSuccess;
            dn.emit('patch', {
                schema: {
                    ['x-uid']: fieldSchema['x-uid'],
                    'x-action-settings': fieldSchema['x-action-settings']
                }
            });
        }
    });
}
function RemoveButton() {
    let props = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const isDeletable = (null == fieldSchema ? void 0 : fieldSchema.parent['x-component']) === 'CollectionField';
    return !isDeletable && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsDivider, {}),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsRemove, {
                removeParentsIfNoChildren: true,
                breakRemoveOn: (s)=>'Space' === s['x-component'] || s['x-component'].endsWith('ActionBar'),
                confirm: {
                    title: t('Delete action'),
                    onOk: props.onConfirmOk
                }
            })
        ]
    });
}
function WorkflowSelectComponent(param) {
    let { formAction, buttonAction, actionType, direct = false, noCollection = false, ...props } = param;
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const index = components_namespaceObject.ArrayTable.useIndex();
    const { setValuesIn } = (0, schema_namespaceObject.useForm)();
    const baseCollection = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
    const { getCollection } = (0, external_collection_manager_index_js_namespaceObject.useCollectionManager_deprecated)();
    const dataSourceKey = (0, external_data_source_index_js_namespaceObject.useDataSourceKey)();
    const [workflowCollection, setWorkflowCollection] = (0, external_react_namespaceObject.useState)((0, external_collection_manager_index_js_namespaceObject.joinCollectionName)(dataSourceKey, baseCollection.name));
    const compile = (0, external_index_js_namespaceObject.useCompile)();
    const workflowPlugin = (0, hooks_index_js_namespaceObject.usePlugin)('workflow');
    (0, external_react_namespaceObject.useMemo)(()=>workflowPlugin.getTriggersOptions().filter((item)=>'function' == typeof item.options.isActionTriggerable || true === item.options.isActionTriggerable).map((item)=>item.value), [
        workflowPlugin
    ]);
    (0, schema_namespaceObject.useFormEffects)(()=>{
        (0, schema_namespaceObject.onFieldValueChange)("group[".concat(index, "].context"), (field)=>{
            let collection = baseCollection;
            if (field.value) {
                const paths = field.value.split('.');
                for(let i = 0; i < paths.length && collection; i++){
                    const path = paths[i];
                    const associationField = collection.fields.find((f)=>f.name === path);
                    if (associationField) collection = getCollection(associationField.target, dataSourceKey);
                }
            }
            setWorkflowCollection((0, external_collection_manager_index_js_namespaceObject.joinCollectionName)(dataSourceKey, collection.name));
            setValuesIn("group[".concat(index, "].workflowKey"), null);
        });
    });
    const optionFilter = (0, external_react_namespaceObject.useCallback)((param)=>{
        let { key, type, config } = param;
        if (key === props.value) return true;
        const trigger = workflowPlugin.triggers.get(type);
        if (true === trigger.isActionTriggerable) return true;
        if ('function' == typeof trigger.isActionTriggerable) return trigger.isActionTriggerable(config, {
            action: actionType,
            formAction,
            buttonAction,
            direct: 'customize:triggerWorkflows' === buttonAction
        });
        return false;
    }, [
        props.value,
        workflowPlugin.triggers,
        actionType,
        formAction,
        buttonAction
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_data_source_index_js_namespaceObject.DataSourceProvider, {
        dataSource: "main",
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.RemoteSelect, {
            manual: false,
            placeholder: t('Select workflow', {
                ns: 'workflow'
            }),
            fieldNames: {
                label: 'title',
                value: 'key'
            },
            service: {
                resource: 'workflows',
                action: 'list',
                params: {
                    filter: {
                        type: void 0 === props.filterType ? void 0 : props.filterType,
                        enabled: void 0 === props.filterEnabled || props.filterEnabled,
                        'config.collection': noCollection ? void 0 : workflowCollection,
                        sync: void 0 === props.filterSync ? void 0 : props.filterSync,
                        key: void 0 === props.filterKey ? void 0 : props.filterKey
                    },
                    sort: [
                        '-updatedAt'
                    ]
                }
            },
            optionFilter: optionFilter,
            optionRender: (param)=>{
                let { label, data } = param;
                const typeOption = workflowPlugin.getTriggersOptions().find((item)=>item.value === data.type);
                return typeOption ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_antd_namespaceObject.Flex, {
                    justify: "space-between",
                    children: [
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                            children: label
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Tag, {
                            color: typeOption.color,
                            children: compile(typeOption.label)
                        })
                    ]
                }) : label;
            },
            ...props
        })
    });
}
const WorkflowSelect = (0, withDynamicSchemaProps_js_namespaceObject.withDynamicSchemaProps)(WorkflowSelectComponent);
function WorkflowConfig() {
    var _fieldSchema_xactionsettings;
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const collection = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
    const formBlock = (0, external_block_provider_index_js_namespaceObject.useFormBlockContext)();
    const actionType = (null == formBlock ? void 0 : formBlock.type) || fieldSchema['x-action'];
    const formAction = null == formBlock ? void 0 : formBlock.type;
    const buttonAction = fieldSchema['x-action'];
    const description = {
        submit: t('Workflow will be triggered before or after submitting succeeded.', {
            ns: 'workflow'
        }),
        'customize:save': t('Workflow will be triggered before or after submitting succeeded.', {
            ns: 'workflow'
        }),
        'customize:triggerWorkflows': t('Workflow will be triggered directly once the button clicked, without data saving.', {
            ns: 'workflow'
        }),
        destroy: t('Workflow will be triggered before or after submitting succeeded.', {
            ns: 'workflow'
        })
    }[null == fieldSchema ? void 0 : fieldSchema['x-action']];
    let orderColumn = {};
    if ([
        'submit',
        'customize:save',
        'destroy'
    ].includes(null == fieldSchema ? void 0 : fieldSchema['x-action'])) orderColumn = {
        order: {
            type: 'void',
            'x-component': 'ArrayTable.Column',
            'x-component-props': {
                title: t('Sequentially', {
                    ns: 'workflow'
                })
            },
            properties: {
                order: {
                    type: 'string',
                    'x-decorator': 'FormItem',
                    'x-component': 'Select',
                    default: 'after',
                    enum: [
                        {
                            label: t('After'),
                            value: 'after'
                        },
                        {
                            label: t('Before'),
                            value: 'before'
                        }
                    ]
                }
            }
        }
    };
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsActionModalItem, {
        title: t('Bind workflows', {
            ns: 'workflow'
        }),
        scope: {
            fieldFilter (field) {
                return [
                    'belongsTo',
                    'hasOne'
                ].includes(field.type);
            }
        },
        components: {
            Alert: external_antd_namespaceObject.Alert,
            ArrayTable: components_namespaceObject.ArrayTable,
            WorkflowSelect
        },
        schema: {
            type: 'void',
            title: t('Bind workflows', {
                ns: 'workflow'
            }),
            properties: {
                description: description && {
                    type: 'void',
                    'x-component': 'Alert',
                    'x-component-props': {
                        message: description,
                        style: {
                            marginBottom: '1em'
                        }
                    }
                },
                group: {
                    type: 'array',
                    'x-component': 'ArrayTable',
                    'x-decorator': 'FormItem',
                    items: {
                        type: 'object',
                        properties: {
                            context: {
                                type: 'void',
                                'x-component': 'ArrayTable.Column',
                                'x-component-props': {
                                    title: t('Trigger data context', {
                                        ns: 'workflow'
                                    }),
                                    width: 200
                                },
                                properties: {
                                    context: {
                                        type: 'string',
                                        'x-decorator': 'FormItem',
                                        'x-component': 'AppendsTreeSelect',
                                        'x-component-props': {
                                            placeholder: t('Select context', {
                                                ns: 'workflow'
                                            }),
                                            popupMatchSelectWidth: false,
                                            collection: "".concat(collection.dataSource && 'main' !== collection.dataSource ? "".concat(collection.dataSource, ":") : '').concat(collection.name),
                                            filter: '{{ fieldFilter }}',
                                            rootOption: {
                                                label: t('Full form data', {
                                                    ns: 'workflow'
                                                }),
                                                value: ''
                                            },
                                            allowClear: false,
                                            loadData: 'destroy' === buttonAction ? null : void 0
                                        },
                                        default: ''
                                    }
                                }
                            },
                            workflowKey: {
                                type: 'void',
                                'x-component': 'ArrayTable.Column',
                                'x-component-props': {
                                    title: t('Workflow', {
                                        ns: 'workflow'
                                    })
                                },
                                properties: {
                                    workflowKey: {
                                        type: 'number',
                                        'x-decorator': 'FormItem',
                                        'x-component': 'WorkflowSelect',
                                        'x-component-props': {
                                            placeholder: t('Select workflow', {
                                                ns: 'workflow'
                                            }),
                                            actionType,
                                            formAction,
                                            buttonAction,
                                            direct: 'customize:triggerWorkflows' === fieldSchema['x-action']
                                        },
                                        required: true
                                    }
                                }
                            },
                            ...orderColumn,
                            operations: {
                                type: 'void',
                                'x-component': 'ArrayTable.Column',
                                'x-component-props': {
                                    width: 32
                                },
                                properties: {
                                    remove: {
                                        type: 'void',
                                        'x-component': 'ArrayTable.Remove'
                                    }
                                }
                            }
                        }
                    },
                    properties: {
                        add: {
                            type: 'void',
                            title: t('Add workflow', {
                                ns: 'workflow'
                            }),
                            'x-component': 'ArrayTable.Addition'
                        }
                    }
                }
            }
        },
        initialValues: {
            group: null == fieldSchema ? void 0 : null === (_fieldSchema_xactionsettings = fieldSchema['x-action-settings']) || void 0 === _fieldSchema_xactionsettings ? void 0 : _fieldSchema_xactionsettings.triggerWorkflows
        },
        onSubmit: (param)=>{
            let { group } = param;
            fieldSchema['x-action-settings']['triggerWorkflows'] = group;
            dn.emit('patch', {
                schema: {
                    ['x-uid']: fieldSchema['x-uid'],
                    'x-action-settings': fieldSchema['x-action-settings']
                }
            });
        }
    });
}
const findGridSchema = (fieldSchema)=>fieldSchema.reduceProperties((buf, s)=>{
        if ('FormV2' === s['x-component']) {
            const f = s.reduceProperties((buf, s)=>{
                if ('Grid' === s['x-component'] || 'BlockTemplate' === s['x-component']) return s;
                return buf;
            }, null);
            if (f) return f;
        }
        return buf;
    }, null);
const useSetFilterScopeVisible = ()=>{
    var _fieldSchema_xcomponentprops;
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    return (null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.useProps) === '{{ useFilterBlockActionProps }}' || 'useFilterBlockActionProps' === fieldSchema['x-use-component-props'];
};
const SetFilterScope = (props)=>{
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { collectionName } = props;
    const gridSchema = findGridSchema(fieldSchema) || fieldSchema;
    const { form } = (0, external_block_provider_index_js_namespaceObject.useFormBlockContext)();
    const type = (null == props ? void 0 : props.type) || [
        'Action',
        'Action.Link'
    ].includes(fieldSchema['x-component']) ? 'button' : 'field';
    const variables = (0, external_variables_index_js_namespaceObject.useVariables)();
    const localVariables = (0, external_variables_index_js_namespaceObject.useLocalVariables)();
    const record = (0, external_record_provider_index_js_namespaceObject.useRecord)();
    const { type: formBlockType } = (0, external_block_provider_index_js_namespaceObject.useFormBlockType)();
    const schema = (0, external_react_namespaceObject.useMemo)(()=>({
            type: 'object',
            title: t('Custom filter'),
            properties: {
                fieldReaction: {
                    'x-component': FormFilterScope_js_namespaceObject.FormFilterScope,
                    'x-component-props': {
                        useProps: ()=>{
                            const options = (0, external_collection_manager_index_js_namespaceObject.useCollectionFilterOptions)(collectionName);
                            return {
                                options,
                                defaultValues: (null == gridSchema ? void 0 : gridSchema['x-filter-rules']) || (null == fieldSchema ? void 0 : fieldSchema['x-filter-rules']),
                                type,
                                collectionName,
                                form,
                                variables,
                                localVariables,
                                record,
                                formBlockType
                            };
                        }
                    }
                }
            }
        }), []);
    const { getTemplateById } = (0, external_schema_templates_index_js_namespaceObject.useSchemaTemplateManager)();
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const onSubmit = (0, external_react_namespaceObject.useCallback)((v)=>{
        const rules = v.fieldReaction.condition;
        const templateId = 'BlockTemplate' === gridSchema['x-component'] && gridSchema['x-component-props'].templateId;
        const uid = templateId && getTemplateById(templateId).uid || gridSchema['x-uid'];
        const schema = {
            ['x-uid']: uid
        };
        gridSchema['x-filter-rules'] = rules;
        schema['x-filter-rules'] = rules;
        dn.emit('patch', {
            schema
        });
        dn.refresh();
    }, [
        dn,
        getTemplateById,
        gridSchema
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsModalItem, {
        title: t('Custom filter'),
        width: 770,
        schema: schema,
        onSubmit: onSubmit
    });
};
const actionSettingsItems = [
    {
        name: 'Customize',
        Component: MenuGroup,
        children: [
            {
                name: 'editButton',
                Component: ButtonEditor,
                useComponentProps () {
                    const { buttonEditorProps } = (0, schema_toolbar_index_js_namespaceObject.useSchemaToolbar)();
                    return buttonEditorProps;
                }
            },
            {
                name: 'linkageRules',
                Component: (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsLinkageRules, {
                        ...props
                    }),
                useVisible () {
                    const isAction = (0, external_hooks_js_namespaceObject.useLinkageAction)();
                    const { linkageAction } = (0, schema_toolbar_index_js_namespaceObject.useSchemaToolbar)();
                    return linkageAction || isAction;
                },
                useComponentProps () {
                    const { name } = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
                    const { linkageRulesProps } = (0, schema_toolbar_index_js_namespaceObject.useSchemaToolbar)();
                    return {
                        ...linkageRulesProps,
                        collectionName: name
                    };
                }
            },
            {
                name: 'openMode',
                Component: external_schema_items_index_js_namespaceObject.SchemaSettingOpenModeSchemaItems,
                useComponentProps () {
                    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                    const isPopupAction = [
                        'create',
                        'update',
                        'view',
                        'customize:popup',
                        'duplicate',
                        'customize:create'
                    ].includes(fieldSchema['x-action'] || '');
                    return {
                        openMode: isPopupAction,
                        openSize: isPopupAction
                    };
                }
            },
            {
                name: 'secondConFirm',
                Component: SecondConFirm,
                useVisible () {
                    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                    const isPopupAction = [
                        'create',
                        'update',
                        'view',
                        'customize:popup',
                        'duplicate',
                        'customize:create'
                    ].includes(fieldSchema['x-action'] || '');
                    return !isPopupAction;
                }
            },
            {
                name: 'assignFieldValues',
                Component: AssignedFieldValues,
                useVisible () {
                    var _fieldSchema_xactionsettings;
                    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                    return (0, schema_namespaceObject.isValid)(null == fieldSchema ? void 0 : null === (_fieldSchema_xactionsettings = fieldSchema['x-action-settings']) || void 0 === _fieldSchema_xactionsettings ? void 0 : _fieldSchema_xactionsettings.assignedValues);
                }
            },
            {
                name: 'requestSettings',
                Component: RequestSettings,
                useVisible () {
                    var _fieldSchema_xactionsettings;
                    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                    return (0, schema_namespaceObject.isValid)(null == fieldSchema ? void 0 : null === (_fieldSchema_xactionsettings = fieldSchema['x-action-settings']) || void 0 === _fieldSchema_xactionsettings ? void 0 : _fieldSchema_xactionsettings.requestSettings);
                }
            },
            {
                name: 'skipValidator',
                Component: SkipValidation,
                useVisible () {
                    var _fieldSchema_xactionsettings;
                    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                    return (0, schema_namespaceObject.isValid)(null == fieldSchema ? void 0 : null === (_fieldSchema_xactionsettings = fieldSchema['x-action-settings']) || void 0 === _fieldSchema_xactionsettings ? void 0 : _fieldSchema_xactionsettings.skipValidator);
                }
            },
            {
                name: 'afterSuccess',
                Component: AfterSuccess,
                useVisible () {
                    var _fieldSchema_xactionsettings;
                    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                    return (0, schema_namespaceObject.isValid)(null == fieldSchema ? void 0 : null === (_fieldSchema_xactionsettings = fieldSchema['x-action-settings']) || void 0 === _fieldSchema_xactionsettings ? void 0 : _fieldSchema_xactionsettings.onSuccess);
                }
            },
            {
                name: 'workflowConfig',
                Component: WorkflowConfig,
                useVisible () {
                    var _fieldSchema_xactionsettings;
                    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                    return (0, schema_namespaceObject.isValid)(null == fieldSchema ? void 0 : null === (_fieldSchema_xactionsettings = fieldSchema['x-action-settings']) || void 0 === _fieldSchema_xactionsettings ? void 0 : _fieldSchema_xactionsettings.triggerWorkflows);
                }
            },
            {
                name: 'saveMode',
                Component: createSubmitActionSettings_js_namespaceObject.SaveMode,
                useVisible () {
                    var _fieldSchema_parent;
                    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                    return 'submit' === fieldSchema['x-action'] && (null === (_fieldSchema_parent = fieldSchema.parent) || void 0 === _fieldSchema_parent ? void 0 : _fieldSchema_parent['x-initializer']) === 'createForm:configureActions';
                }
            },
            {
                name: 'enableChildCollections',
                Component: SchemaSettings_js_namespaceObject.SchemaSettingsEnableChildCollections,
                useVisible () {
                    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                    const { name } = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
                    const { getChildrenCollections } = (0, external_collection_manager_index_js_namespaceObject.useCollectionManager_deprecated)();
                    const isChildCollectionAction = getChildrenCollections(name).length > 0 && 'create' === fieldSchema['x-action'];
                    return isChildCollectionAction;
                },
                useComponentProps () {
                    const { name } = (0, external_collection_manager_index_js_namespaceObject.useCollection_deprecated)();
                    return {
                        collectionName: name
                    };
                }
            },
            {
                name: 'Customize.setFilterScope',
                Component: SetFilterScope,
                useVisible: useSetFilterScopeVisible,
                useComponentProps () {
                    const collection = (0, external_data_source_index_js_namespaceObject.useCollection)();
                    return {
                        collectionName: collection.name
                    };
                }
            },
            {
                name: 'remove',
                sort: 100,
                Component: RemoveButton,
                useComponentProps () {
                    const { removeButtonProps } = (0, schema_toolbar_index_js_namespaceObject.useSchemaToolbar)();
                    return removeButtonProps;
                },
                useVisible () {
                    var _fieldSchema_xactionsettings;
                    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
                    return (null == fieldSchema ? void 0 : null === (_fieldSchema_xactionsettings = fieldSchema['x-action-settings']) || void 0 === _fieldSchema_xactionsettings ? void 0 : _fieldSchema_xactionsettings.removable) !== false;
                }
            }
        ]
    }
];
function SecondConFirm() {
    var _fieldSchema_xcomponentprops_confirm, _fieldSchema_xcomponentprops;
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const field = (0, schema_namespaceObject.useField)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsSwitchItem, {
        title: t('Secondary confirmation'),
        checked: !!(null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : null === (_fieldSchema_xcomponentprops_confirm = _fieldSchema_xcomponentprops.confirm) || void 0 === _fieldSchema_xcomponentprops_confirm ? void 0 : _fieldSchema_xcomponentprops_confirm.content),
        onChange: (value)=>{
            var _fieldSchema_xcomponentprops;
            if (!fieldSchema['x-component-props']) fieldSchema['x-component-props'] = {};
            if (value) fieldSchema['x-component-props'].confirm = value ? {
                title: 'Perform the {{title}}',
                content: 'Are you sure you want to perform the {{title}} action?'
            } : {};
            else fieldSchema['x-component-props'].confirm = {};
            field.componentProps.confirm = {
                ...null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.confirm
            };
            dn.emit('patch', {
                schema: {
                    ['x-uid']: fieldSchema['x-uid'],
                    'x-component-props': {
                        ...fieldSchema['x-component-props']
                    }
                }
            });
        }
    });
}
function IsDownLoad() {
    var _fieldSchema_xactionsettings_onSuccess, _fieldSchema_xactionsettings;
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsSwitchItem, {
        title: t('Is DownLoad'),
        checked: !!(null == fieldSchema ? void 0 : null === (_fieldSchema_xactionsettings = fieldSchema['x-action-settings']) || void 0 === _fieldSchema_xactionsettings ? void 0 : null === (_fieldSchema_xactionsettings_onSuccess = _fieldSchema_xactionsettings.onSuccess) || void 0 === _fieldSchema_xactionsettings_onSuccess ? void 0 : _fieldSchema_xactionsettings_onSuccess.down),
        onChange: (value)=>{
            var _fieldSchema_xactionsettings;
            if (!(null == fieldSchema ? void 0 : null === (_fieldSchema_xactionsettings = fieldSchema['x-action-settings']) || void 0 === _fieldSchema_xactionsettings ? void 0 : _fieldSchema_xactionsettings.onSuccess)) fieldSchema['x-action-settings'] = {
                ...null == fieldSchema ? void 0 : fieldSchema['x-action-settings'],
                onSuccess: {
                    down: false
                }
            };
            fieldSchema['x-action-settings'].onSuccess.down = value;
            dn.emit('patch', {
                schema: {
                    ['x-uid']: fieldSchema['x-uid'],
                    'x-action-settings': {
                        ...fieldSchema['x-action-settings']
                    }
                }
            });
        }
    });
}
function ShowData() {
    var _fieldSchema_xcomponentprops;
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const field = (0, schema_namespaceObject.useField)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsSwitchItem, {
        title: t('Show Data'),
        checked: !!(null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.showData),
        onChange: (value)=>{
            if (!(null == fieldSchema ? void 0 : fieldSchema['x-component-props'])) fieldSchema['x-component-props'] = {
                showData: false
            };
            fieldSchema['x-component-props'].showData = value;
            field.componentProps = fieldSchema['x-component-props'];
            dn.emit('patch', {
                schema: {
                    ['x-uid']: fieldSchema['x-uid'],
                    'x-component-props': {
                        ...fieldSchema['x-component-props']
                    }
                }
            });
        }
    });
}
function SettingDownTitle() {
    var _fieldSchema_xactionsettings_onSuccess, _fieldSchema_xactionsettings;
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaSettings_js_namespaceObject.SchemaSettingsModalItem, {
        title: t('Setting Down Title'),
        onSubmit: (param)=>{
            let { title } = param;
            if (null == fieldSchema ? void 0 : fieldSchema['x-action-settings']) {
                var _fieldSchema_xactionsettings;
                fieldSchema['x-action-settings']['onSuccess'] = {
                    ...null === (_fieldSchema_xactionsettings = fieldSchema['x-action-settings']) || void 0 === _fieldSchema_xactionsettings ? void 0 : _fieldSchema_xactionsettings['onSuccess'],
                    downTitle: title
                };
            } else fieldSchema['x-action-settings'] = {
                onSussess: {
                    downTitle: title
                }
            };
            dn.emit('patch', {
                schema: {
                    ['x-uid']: fieldSchema['x-uid'],
                    'x-action-settings': {
                        ...fieldSchema['x-action-settings']
                    }
                }
            });
        },
        schema: {
            type: 'item',
            title: t('Setting Down Title'),
            properties: {
                title: {
                    'x-component': 'Input',
                    default: (null === (_fieldSchema_xactionsettings = fieldSchema['x-action-settings']) || void 0 === _fieldSchema_xactionsettings ? void 0 : null === (_fieldSchema_xactionsettings_onSuccess = _fieldSchema_xactionsettings['onSuccess']) || void 0 === _fieldSchema_xactionsettings_onSuccess ? void 0 : _fieldSchema_xactionsettings_onSuccess.downTitle) || 'document.docx'
                }
            }
        }
    });
}
const actionSettings = new schema_settings_index_js_namespaceObject.SchemaSettings({
    name: 'ActionSettings',
    items: actionSettingsItems
});
const ActionDesigner = (props)=>{
    const { modalTip, linkageAction, removeButtonProps, buttonEditorProps, linkageRulesProps, schemaSettings, ...restProps } = props;
    const app = (0, index_js_namespaceObject.useApp)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const isDraggable = (null == fieldSchema ? void 0 : fieldSchema.parent['x-component']) !== 'CollectionField';
    const settingsName = "ActionSettings:".concat(fieldSchema['x-action']);
    const defaultActionSettings = schemaSettings || 'ActionSettings';
    const hasAction = app.schemaSettingsManager.has(settingsName);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(GeneralSchemaDesigner_js_namespaceObject.GeneralSchemaDesigner, {
        schemaSettings: hasAction ? settingsName : defaultActionSettings,
        contextValue: {
            modalTip,
            linkageAction,
            removeButtonProps,
            buttonEditorProps,
            linkageRulesProps
        },
        ...restProps,
        disableInitializer: true,
        draggable: isDraggable
    });
};
ActionDesigner.ButtonEditor = ButtonEditor;
ActionDesigner.RemoveButton = RemoveButton;
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
});
