import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__block_provider_FormBlockProvider_mjs__ from "../../../block-provider/FormBlockProvider.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__context_mjs__ from "./context.mjs";
const useA = ()=>({
        async run () {}
    });
const useActionContext = ()=>{
    const ctx = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(__WEBPACK_EXTERNAL_MODULE__context_mjs__.ActionContext);
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const { modal } = __WEBPACK_EXTERNAL_MODULE_antd__.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, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(__WEBPACK_EXTERNAL_MODULE__context_mjs__.ActionContext);
    const form = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useForm)();
    return {
        async run () {
            setVisible(false);
            form.submit((values)=>{
                console.warn(values);
            });
        }
    };
};
const useLinkageAction = ()=>{
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const isRecordAction = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_FormBlockProvider_mjs__.useIsDetailBlock)();
    const isAction = [
        'Action.Link',
        'Action'
    ].includes(fieldSchema['x-component']);
    return isAction && isRecordAction;
};
export { useA, useActionContext, useCloseAction, useLinkageAction };
