"use strict";
var __webpack_require__ = {};
(()=>{
    __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__, {
    default: ()=>Action_rslib_entry_,
    Action: ()=>Action
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const client_namespaceObject = require("@tachybase/utils/client");
const external_antd_namespaceObject = require("antd");
const external_classnames_namespaceObject = require("classnames");
var external_classnames_default = /*#__PURE__*/ __webpack_require__.n(external_classnames_namespaceObject);
const external_lodash_namespaceObject = require("lodash");
var external_lodash_default = /*#__PURE__*/ __webpack_require__.n(external_lodash_namespaceObject);
const external_react_i18next_namespaceObject = require("react-i18next");
const external_react_router_dom_namespaceObject = require("react-router-dom");
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 acl_index_js_namespaceObject = require("../../../built-in/acl/index.js");
const utils_js_namespaceObject = require("../../../built-in/dynamic-page/utils.js");
const external_data_source_index_js_namespaceObject = require("../../../data-source/index.js");
const external_icon_index_js_namespaceObject = require("../../../icon/index.js");
const external_record_provider_index_js_namespaceObject = require("../../../record-provider/index.js");
const external_variables_index_js_namespaceObject = require("../../../variables/index.js");
const external_common_index_js_namespaceObject = require("../../common/index.js");
const external_hooks_index_js_namespaceObject = require("../../hooks/index.js");
const useProps_js_namespaceObject = require("../../hooks/useProps.js");
const external_Action_Area_js_namespaceObject = require("./Action.Area.js");
const external_Action_Container_js_namespaceObject = require("./Action.Container.js");
var external_Action_Container_js_default = /*#__PURE__*/ __webpack_require__.n(external_Action_Container_js_namespaceObject);
const external_Action_Designer_js_namespaceObject = require("./Action.Designer.js");
const external_Action_Drawer_js_namespaceObject = require("./Action.Drawer.js");
const external_Action_Link_js_namespaceObject = require("./Action.Link.js");
const external_Action_Modal_js_namespaceObject = require("./Action.Modal.js");
const external_Action_Page_js_namespaceObject = require("./Action.Page.js");
const external_Action_style_js_namespaceObject = require("./Action.style.js");
var external_Action_style_js_default = /*#__PURE__*/ __webpack_require__.n(external_Action_style_js_namespaceObject);
const external_context_js_namespaceObject = require("./context.js");
const external_hooks_js_namespaceObject = require("./hooks.js");
const useGetAriaLabelOfAction_js_namespaceObject = require("./hooks/useGetAriaLabelOfAction.js");
const external_utils_js_namespaceObject = require("./utils.js");
const Action = (0, withDynamicSchemaProps_js_namespaceObject.withDynamicSchemaProps)((0, schema_namespaceObject.observer)((props)=>{
    var _fieldSchema_xcomponentprops, _fieldSchema_xcomponentprops1, _field_data, _field_data1;
    const { isShow = true, popover, confirm, openMode: om, containerRefKey, component, useAction = external_hooks_js_namespaceObject.useA, className, icon, title, onClick, style, openSize: os, disabled: propsDisabled, actionCallback, addChild, ...others } = (0, useProps_js_namespaceObject.useProps)(props);
    const aclCtx = (0, acl_index_js_namespaceObject.useACLActionParamsContext)();
    const navigate = (0, external_react_router_dom_namespaceObject.useNavigate)();
    const { wrapSSR, componentCls, hashId } = external_Action_style_js_default()();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const [visible, setVisible] = (0, external_react_namespaceObject.useState)(false);
    const [formValueChanged, setFormValueChanged] = (0, external_react_namespaceObject.useState)(false);
    const Designer = (0, external_hooks_index_js_namespaceObject.useDesigner)();
    const field = (0, schema_namespaceObject.useField)();
    const app = (0, index_js_namespaceObject.useApp)();
    const pageMode = app.usePageMode();
    const { run, element } = useAction(actionCallback);
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const compile = (0, external_hooks_index_js_namespaceObject.useCompile)();
    const form = (0, schema_namespaceObject.useForm)();
    const record = (0, external_data_source_index_js_namespaceObject.useCollectionRecordData)();
    const collection = (0, external_data_source_index_js_namespaceObject.useCollection)();
    const designerProps = fieldSchema['x-designer-props'];
    const openMode = null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops['openMode'];
    const openSize = null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops1 = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops1 ? void 0 : _fieldSchema_xcomponentprops1['openSize'];
    const disabled = form.disabled || field.disabled || (null === (_field_data = field.data) || void 0 === _field_data ? void 0 : _field_data.disabled) || propsDisabled;
    const linkageRules = (0, external_react_namespaceObject.useMemo)(()=>(null == fieldSchema ? void 0 : fieldSchema['x-linkage-rules']) || [], [
        fieldSchema
    ]);
    const { designable } = (0, external_index_js_namespaceObject.useDesignable)();
    const tarComponent = (0, external_hooks_index_js_namespaceObject.useComponent)(component) || component;
    const { modal } = external_antd_namespaceObject.App.useApp();
    const variables = (0, external_variables_index_js_namespaceObject.useVariables)();
    const localVariables = (0, external_variables_index_js_namespaceObject.useLocalVariables)({
        currentForm: {
            values: record
        }
    });
    const { getAriaLabel } = (0, useGetAriaLabelOfAction_js_namespaceObject.useGetAriaLabelOfAction)(title);
    let actionTitle = title || compile(fieldSchema.title);
    actionTitle = external_lodash_default().isString(actionTitle) ? t(actionTitle) : actionTitle;
    (0, external_react_namespaceObject.useEffect)(()=>{
        field.stateOfLinkageRules = {};
        linkageRules.filter((k)=>!k.disabled).forEach((v)=>{
            var _v_actions;
            null === (_v_actions = v.actions) || void 0 === _v_actions || _v_actions.forEach((h)=>{
                (0, external_utils_js_namespaceObject.linkageAction)({
                    operator: h.operator,
                    field,
                    condition: v.condition,
                    variables,
                    localVariables
                });
            });
        });
    }, [
        field,
        linkageRules,
        localVariables,
        record,
        variables
    ]);
    const handleButtonClick = (0, external_react_namespaceObject.useCallback)((e)=>{
        if ((0, client_namespaceObject.isPortalInBody)(e.target)) return;
        e.preventDefault();
        e.stopPropagation();
        if (!disabled && aclCtx) {
            const onOk = ()=>{
                null == onClick || onClick(e);
                const containerSchema = fieldSchema.reduceProperties((buf, s)=>'Action.Container' === s['x-component'] ? s : buf);
                if ((null == pageMode ? void 0 : pageMode.enable) && containerSchema) {
                    const target = utils_js_namespaceObject.PathHandler.getInstance().toWildcardPath({
                        collection: collection.name,
                        filterByTk: record[collection.getPrimaryKey()]
                    });
                    navigate('../' + containerSchema['x-uid'] + '/' + target);
                } else setVisible(true);
                run();
            };
            if (null == confirm ? void 0 : confirm.content) modal.confirm({
                title: t(confirm.title, {
                    title: actionTitle
                }),
                content: t(confirm.content, {
                    title: actionTitle
                }),
                onOk
            });
            else onOk();
        }
    }, [
        confirm,
        disabled,
        modal,
        onClick,
        run
    ]);
    const buttonStyle = (0, external_react_namespaceObject.useMemo)(()=>{
        var _field_data;
        return {
            ...style,
            opacity: designable && ((null == field ? void 0 : null === (_field_data = field.data) || void 0 === _field_data ? void 0 : _field_data.hidden) || !aclCtx) && 0.1
        };
    }, [
        designable,
        null == field ? void 0 : null === (_field_data1 = field.data) || void 0 === _field_data1 ? void 0 : _field_data1.hidden,
        style
    ]);
    const renderButton = ()=>{
        var _field_data, _field_data1;
        if (!designable && ((null == field ? void 0 : null === (_field_data = field.data) || void 0 === _field_data ? void 0 : _field_data.hidden) || !aclCtx)) return null;
        return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_common_index_js_namespaceObject.SortableItem, {
            role: "button",
            "aria-label": getAriaLabel(),
            ...others,
            loading: null == field ? void 0 : null === (_field_data1 = field.data) || void 0 === _field_data1 ? void 0 : _field_data1.loading,
            icon: icon ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_icon_index_js_namespaceObject.Icon, {
                type: icon
            }) : null,
            disabled: disabled,
            style: buttonStyle,
            onClick: handleButtonClick,
            component: tarComponent || external_antd_namespaceObject.Button,
            className: external_classnames_default()(componentCls, hashId, className, 'tb-action'),
            type: 'danger' === props.type ? void 0 : props.type,
            children: [
                actionTitle,
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Designer, {
                    ...designerProps
                })
            ]
        });
    };
    const result = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_context_js_namespaceObject.ActionContextProvider, {
        button: renderButton(),
        visible: visible,
        setVisible: setVisible,
        formValueChanged: formValueChanged,
        setFormValueChanged: setFormValueChanged,
        openMode: openMode,
        openSize: openSize,
        containerRefKey: containerRefKey,
        fieldSchema: fieldSchema,
        children: [
            popover && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(schema_namespaceObject.RecursionField, {
                basePath: field.address,
                onlyRenderProperties: true,
                schema: fieldSchema
            }),
            !popover && renderButton(),
            !popover && props.children,
            element
        ]
    });
    if (!isShow) return null;
    if (addChild) return wrapSSR(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_record_provider_index_js_namespaceObject.RecordProvider, {
        record: null,
        parent: record,
        children: result
    }));
    return wrapSSR(result);
}), {
    displayName: 'Action'
});
Action.Popover = (0, schema_namespaceObject.observer)((props)=>{
    const { button, visible, setVisible } = (0, external_index_js_namespaceObject.useActionContext)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.StablePopover, {
        ...props,
        destroyTooltipOnHide: true,
        open: visible,
        onOpenChange: (visible)=>{
            setVisible(visible);
        },
        content: props.children,
        children: button
    });
}, {
    displayName: 'Action.Popover'
});
Action.Popover.Footer = (0, schema_namespaceObject.observer)((props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
        style: {
            display: 'flex',
            justifyContent: 'flex-end',
            width: '100%'
        },
        children: props.children
    }), {
    displayName: 'Action.Popover.Footer'
});
Action.Link = external_Action_Link_js_namespaceObject.ActionLink;
Action.Designer = external_Action_Designer_js_namespaceObject.ActionDesigner;
Action.Drawer = external_Action_Drawer_js_namespaceObject.ActionDrawer;
Action.Modal = external_Action_Modal_js_namespaceObject.ActionModal;
Action.Container = external_Action_Container_js_default();
Action.Page = external_Action_Page_js_namespaceObject.ActionPage;
Action.Area = external_Action_Area_js_namespaceObject.ActionArea;
const Action_rslib_entry_ = Action;
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
});
