"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__, {
    afterSuccessSchema: ()=>afterSuccessSchema,
    linkageAction: ()=>linkageAction,
    requestSettingsSchema: ()=>requestSettingsSchema
});
const external_lodash_namespaceObject = require("lodash");
const type_js_namespaceObject = require("../../../schema-settings/LinkageRules/type.js");
const uitls_js_namespaceObject = require("../../common/utils/uitls.js");
const validateJSON = {
    validator: "{{(value, rule)=> {\n    if (!value) {\n      return '';\n    }\n    try {\n      const val = JSON.parse(value);\n      if(!isNaN(val)) {\n        return false;\n      }\n      return true;\n    } catch(error) {\n      console.error(error);\n      return false;\n    }\n  }}}",
    message: '{{t("Invalid JSON format")}}'
};
const requestSettingsSchema = {
    type: 'object',
    properties: {
        url: {
            type: 'string',
            title: '{{t("Request URL")}}',
            required: true,
            'x-decorator': 'FormItem',
            'x-component': 'Input'
        },
        method: {
            type: 'string',
            title: '{{t("Request method")}}',
            'x-decorator': 'FormItem',
            'x-component': 'Select',
            default: 'POST',
            enum: [
                {
                    label: 'POST',
                    value: 'POST'
                },
                {
                    label: 'GET',
                    value: 'GET'
                },
                {
                    label: 'PUT',
                    value: 'PUT'
                },
                {
                    label: 'PATCH',
                    value: 'PATCH'
                },
                {
                    label: 'DELETE',
                    value: 'DELETE'
                }
            ]
        },
        headers: {
            type: 'string',
            title: '{{t("Request headers")}}',
            'x-decorator': 'FormItem',
            'x-component': 'Input.TextArea',
            'x-validator': validateJSON
        },
        params: {
            type: 'string',
            title: '{{t("Request query parameters")}}',
            'x-decorator': 'FormItem',
            'x-component': 'Input.TextArea',
            'x-validator': validateJSON
        },
        data: {
            type: 'string',
            title: '{{t("Request body")}}',
            'x-decorator': 'FormItem',
            'x-component': 'Input.TextArea',
            'x-validator': validateJSON
        }
    }
};
const linkageAction = async (param)=>{
    let { operator, field, condition, variables, localVariables } = param;
    var _field_stateOfLinkageRules, _field_stateOfLinkageRules1;
    const disableResult = (null == field ? void 0 : null === (_field_stateOfLinkageRules = field.stateOfLinkageRules) || void 0 === _field_stateOfLinkageRules ? void 0 : _field_stateOfLinkageRules.disabled) || [
        false
    ];
    const displayResult = (null == field ? void 0 : null === (_field_stateOfLinkageRules1 = field.stateOfLinkageRules) || void 0 === _field_stateOfLinkageRules1 ? void 0 : _field_stateOfLinkageRules1.display) || [
        'visible'
    ];
    switch(operator){
        case type_js_namespaceObject.ActionType.Visible:
            if (await (0, uitls_js_namespaceObject.conditionAnalyses)({
                ruleGroup: condition,
                variables,
                localVariables
            })) {
                displayResult.push(operator);
                field.data = field.data || {};
                field.data.hidden = false;
            }
            field.stateOfLinkageRules = {
                ...field.stateOfLinkageRules,
                display: displayResult
            };
            field.display = (0, external_lodash_namespaceObject.last)(displayResult);
            break;
        case type_js_namespaceObject.ActionType.Hidden:
            if (await (0, uitls_js_namespaceObject.conditionAnalyses)({
                ruleGroup: condition,
                variables,
                localVariables
            })) {
                field.data = field.data || {};
                field.data.hidden = true;
            } else {
                field.data = field.data || {};
                field.data.hidden = false;
            }
            break;
        case type_js_namespaceObject.ActionType.Disabled:
            if (await (0, uitls_js_namespaceObject.conditionAnalyses)({
                ruleGroup: condition,
                variables,
                localVariables
            })) disableResult.push(true);
            field.stateOfLinkageRules = {
                ...field.stateOfLinkageRules,
                disabled: disableResult
            };
            field.disabled = (0, external_lodash_namespaceObject.last)(disableResult);
            field.componentProps['disabled'] = (0, external_lodash_namespaceObject.last)(disableResult);
            break;
        case type_js_namespaceObject.ActionType.Active:
            if (await (0, uitls_js_namespaceObject.conditionAnalyses)({
                ruleGroup: condition,
                variables,
                localVariables
            })) disableResult.push(false);
            field.stateOfLinkageRules = {
                ...field.stateOfLinkageRules,
                disabled: disableResult
            };
            field.disabled = (0, external_lodash_namespaceObject.last)(disableResult);
            field.componentProps['disabled'] = (0, external_lodash_namespaceObject.last)(disableResult);
            break;
        default:
            return null;
    }
};
const afterSuccessSchema = (t)=>({
        type: 'object',
        title: t('After successful submission'),
        properties: {
            successMessage: {
                title: '{{t("Popup message")}}',
                'x-decorator': 'FormItem',
                'x-component': 'Input.TextArea',
                'x-component-props': {}
            },
            popupClose: {
                title: '{{t("Popup close method")}}',
                enum: [
                    {
                        label: '{{t("Automatic close")}}',
                        value: false
                    },
                    {
                        label: '{{t("Manually close")}}',
                        value: true
                    }
                ],
                'x-decorator': 'FormItem',
                'x-component': 'Radio.Group',
                'x-component-props': {}
            },
            manualClose: {
                title: '{{t("Message clear metchod")}}',
                enum: [
                    {
                        label: '{{t("Automatic close")}}',
                        value: false
                    },
                    {
                        label: '{{t("Manually close")}}',
                        value: true
                    }
                ],
                'x-decorator': 'FormItem',
                'x-component': 'Radio.Group',
                'x-component-props': {}
            },
            redirecting: {
                title: '{{t("Then")}}',
                enum: [
                    {
                        label: '{{t("Stay on current page")}}',
                        value: false
                    },
                    {
                        label: '{{t("Redirect to")}}',
                        value: true
                    }
                ],
                'x-decorator': 'FormItem',
                'x-component': 'Radio.Group',
                'x-component-props': {},
                'x-reactions': {
                    target: 'redirectTo',
                    fulfill: {
                        state: {
                            visible: '{{!!$self.value}}'
                        }
                    }
                }
            },
            redirectTo: {
                title: '{{t("Link")}}',
                'x-decorator': 'FormItem',
                'x-component': 'Input',
                'x-component-props': {}
            }
        }
    });
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
});
