/**
 * 通用字段编辑面板弹窗
 *
 * 通过 driver.getUiContribution().editPanel 渲染编辑面板，
 * 不再硬编码 AiFieldConfigPanel / FormulaFieldConfigPanel。
 */
import * as React from 'react';
import { Popup } from '@cainiaofe/cn-domain-popup';
import { getPopupContainer } from '../../../../../../../utils/floating-layer.js';
export const EditFieldPanelPopup = ({ visible, onVisibleChange, headerRef, EditPanel, fieldType, fieldLabel, columnId, columnCode, initialValue, context, onSave, onCancel, }) => {
    const virtualReference = React.useMemo(() => ({
        getBoundingClientRect: () => {
            var _a;
            const rect = (_a = headerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
            return (rect ||
                {
                    x: 0,
                    y: 0,
                    top: 0,
                    left: 0,
                    right: 0,
                    bottom: 0,
                    width: 0,
                    height: 0,
                });
        },
    }), [headerRef]);
    React.useEffect(() => {
        if (!visible) {
            return;
        }
        const handleClose = () => {
            onVisibleChange(false);
        };
        window.addEventListener('resize', handleClose);
        return () => {
            window.removeEventListener('resize', handleClose);
        };
    }, [onVisibleChange, visible]);
    if (!visible || !headerRef.current) {
        return null;
    }
    return (React.createElement(Popup, { visible: visible, onVisibleChange: onVisibleChange, virtualReference: virtualReference, align: "bl", offset: 8, canCloseByOutSideClick: false, container: getPopupContainer },
        React.createElement(EditPanel, { fieldType: fieldType, fieldLabel: fieldLabel, columnId: columnId, columnCode: columnCode, initialValue: initialValue, isEditStatus: true, context: context, onSave: onSave, onCancel: onCancel })));
};
export default EditFieldPanelPopup;
