"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__, {
    useA: ()=>useA,
    useCloseAction: ()=>useCloseAction,
    useActionContext: ()=>useActionContext,
    useLinkageAction: ()=>useLinkageAction
});
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_namespaceObject = require("antd");
const external_react_i18next_namespaceObject = require("react-i18next");
const FormBlockProvider_js_namespaceObject = require("../../../block-provider/FormBlockProvider.js");
const external_context_js_namespaceObject = require("./context.js");
const useA = ()=>({
        async run () {}
    });
const useActionContext = ()=>{
    const ctx = (0, external_react_namespaceObject.useContext)(external_context_js_namespaceObject.ActionContext);
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { modal } = external_antd_namespaceObject.App.useApp();
    return {
        ...ctx,
        setVisible (visible) {
            let confirm = arguments.length > 1 && void 0 !== arguments[1] && arguments[1];
            if ((null == ctx ? void 0 : ctx.openMode) !== 'page') {
                if (visible) {
                    var _ctx_setVisible1;
                    null == ctx || null === (_ctx_setVisible1 = ctx.setVisible) || void 0 === _ctx_setVisible1 || _ctx_setVisible1.call(ctx, visible);
                } else if (confirm && ctx.formValueChanged) modal.confirm({
                    title: t('Unsaved changes'),
                    content: t("Are you sure you don't want to save?"),
                    async onOk () {
                        var _ctx_setVisible;
                        ctx.setFormValueChanged(false);
                        null === (_ctx_setVisible = ctx.setVisible) || void 0 === _ctx_setVisible || _ctx_setVisible.call(ctx, false);
                    }
                });
                else {
                    var _ctx_setVisible;
                    null == ctx || null === (_ctx_setVisible = ctx.setVisible) || void 0 === _ctx_setVisible || _ctx_setVisible.call(ctx, false);
                }
            }
        }
    };
};
const useCloseAction = ()=>{
    const { setVisible } = (0, external_react_namespaceObject.useContext)(external_context_js_namespaceObject.ActionContext);
    const form = (0, schema_namespaceObject.useForm)();
    return {
        async run () {
            setVisible(false);
            form.submit((values)=>{
                console.warn(values);
            });
        }
    };
};
const useLinkageAction = ()=>{
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const isRecordAction = (0, FormBlockProvider_js_namespaceObject.useIsDetailBlock)();
    const isAction = [
        'Action.Link',
        'Action'
    ].includes(fieldSchema['x-component']);
    return isAction && isRecordAction;
};
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
});
